From: <Blu...@us...> - 2010-01-03 16:04:18
|
Revision: 331 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=331&view=rev Author: BlueWolf_ Date: 2010-01-03 16:04:11 +0000 (Sun, 03 Jan 2010) Log Message: ----------- [Server-core] It will now save the client app/version, protocolversion and client position. On login, it also will send a list of all connected clients with position (if allowed). When going offline, it will notify all other clients too Modified Paths: -------------- trunk/server/core/callback.py trunk/server/core/parser.py trunk/server/core/server.py Modified: trunk/server/core/callback.py =================================================================== --- trunk/server/core/callback.py 2009-12-23 13:17:00 UTC (rev 330) +++ trunk/server/core/callback.py 2010-01-03 16:04:11 UTC (rev 331) @@ -202,3 +202,11 @@ overwrite this in your own callback. """ return True + + def enters_vp(self, client): + """ + Called when a client is logged in and enters VP. + + client: + Same as server.clients[cid] + """ Modified: trunk/server/core/parser.py =================================================================== --- trunk/server/core/parser.py 2009-12-23 13:17:00 UTC (rev 330) +++ trunk/server/core/parser.py 2010-01-03 16:04:11 UTC (rev 331) @@ -67,7 +67,32 @@ return True + def _is_client_visible(self, client1, client2): + """ + Checks is client1 can see client2 + """ + + client1 = client1['pos'] + client2 = client2['pos'] + + # Check height + if client1[2] != client2[2]: return False + + # Check horizontal + if client1[0]-client2[0] > self.sh['config']['viewport'][0]/2 \ + or client1[0]-client2[0] < -self.sh['config']['viewport'][0]/2: + return False + + # Check vertical + if client1[1]-client2[1] > self.sh['config']['viewport'][1]/2 \ + or client1[1]-client2[1] < -self.sh['config']['viewport'][1]/2: + return False + + # Clients see each other! + return True + + def login(self, cid, msg): """ Send when the users wants to log in @@ -77,6 +102,7 @@ for - For what services it's logging in "VP" - VP client client - list with [app_name, app_version] + version - string with (protocol) version (xx.xx.xx) """ client = self.clients[cid] @@ -108,8 +134,8 @@ bots = [] for id, cl in self.clients.items(): if cl['status'] == 'VP' and \ - cl['owner'] == username and \ - cl['bot'] == True: + cl['bot'] == True and \ + cl['owner'] == username: bots.append(id) # Get screenname @@ -132,40 +158,107 @@ + # Check for double logins if msg['bot'] == False: # Just an ordinary user - if self._check_double_user(False, username, data) == False: return - - - # Log the user in - client['user'] = screenname + + else: # Client is a bot + if self._check_double_user(True, screenname, + data) == False: + return + + + # Log the client in + + client['user'] = screenname + client['app'] = tuple(msg['client']) + client['version'] = str(msg['version']) + client['pos'] = [0, 0, 0] # XYZ + client['status'] = "VP" + + if msg['bot'] == False: client['bot'] = False - client['status'] = "VP" data.send("login", { "username": username, "cid": cid }) - else: # Client is bot - - if self._check_double_user(True, screenname, - data) == False: - return - - - # log the bot in - client['user'] = screenname + else: client['bot'] = True client['owner'] = username - client['status'] = "VP" data.send("login", { "username": screenname, "owner": username, "cid": cid }) + + + # TODO: Send world + + + + user = {} # This will be send to others + user['cid'] = cid + user['user'] = client['user'] + user['app'] = client['app'] + user['version'] = client['version'] + user['bot'] = client['bot'] + if client['bot']: user['owner'] = client['owner'] + + # Send online clients + userlist = [] + + for cid_o, client_o in self.clients.items(): + if client_o['status'] != "VP": continue + # To clear some things up: + # client = local user info + # cid = local user cid + # client_o = other user info + # cid_o = other user cid + # + # user = local user info that will send to + # client_o + # user_o = other user info that will send to + # client + + user_o = {} + + user_o['cid'] = cid_o + user_o['user'] = client_o['user'] + user_o['app'] = client_o['app'] + user_o['version'] = client_o['version'] + + user_o['bot'] = client_o['bot'] + if client_o['bot']: + user_o['owner'] = client_o['owner'] + + # Positions + # Is this user visible for this client? + if self._is_client_visible(client, client_o): + user_o['pos'] = client_o['pos'] + user['pos'] = client['pos'] + else: + user_o['pos'] = None + user['pos'] = None + + + # Send data to other user + if cid != cid_o: + client_o['con'].send("useronline", user) + + # Send data to this user + userlist.append(user_o) + + + # Send list + data.send("userlist", userlist) + + + self.call.enters_vp(client) + Modified: trunk/server/core/server.py =================================================================== --- trunk/server/core/server.py 2009-12-23 13:17:00 UTC (rev 330) +++ trunk/server/core/server.py 2010-01-03 16:04:11 UTC (rev 331) @@ -72,6 +72,12 @@ logs in as "test", it will be displayed as "[test]". Choose something that won't interfere with existing users. + + -viewport + A tuple of the client's viewport in pixels. This is very + important because it's used to calculate which objects + and people the client is able to see. By default, this + is (1000, 700). """ @@ -79,7 +85,7 @@ self.__sock = None self.__call = callback_class - # This will be available ([sh]ared) to al modules in the core + # This will be available ([sh]ared) to all modules in the core self.__sh = {} self.__sh['call'] = callback_class @@ -104,6 +110,7 @@ config.get('max_connections', 0)) config['rsa_bits'] = int(config.get('rsa_bits', 64)) config['bot_names'] = str(config.get('bot_names', "[%s]")) + config['viewport'] = tuple(config.get('viewport', (1000,700))) def start_server(self): @@ -248,7 +255,29 @@ traceback += ev.__class__.__name__ + ': ' + str(ev) self.__call.debug_crash(traceback) + + def __notify_offline(self, reason): + """ + Used by close and close_msg to notify other users this client + has gone offline. + """ + if reason == "gone offline": return # Server is going offline + + # Was this user already online? + client = self.__clients[self.__cid] + if client['status'] == 'VP': + + # Tell other users this one has gone offline + for cid, cl in self.__clients.items(): + if cid == self.__cid: continue + + cl['con'].send("useroffline", { + "cid": self.__cid, + "reason": reason + }) + + def run(self): """ Used by threading, not for external usage. @@ -311,6 +340,8 @@ self.__call.connection_closed(self.__cid, reason) + self.__notify_offline(reason) + del self.__clients[self.__cid] def close_msg(self, reason): @@ -329,6 +360,9 @@ self.__sock.close() self.__call.connection_closed(self.__cid, reason) + + self.__notify_offline(reason) + del self.__clients[self.__cid] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |