def ClientMessage(playerid, msg): """ Sends a message to the player associates with the clientid using a deferred call. """ player = objmgr.GetObject(playerid) response = Response(player.clientid, msg) deferred.Call(gameserver.ID_SERVER, 'respond', (response, ))
def Logout(clientid): """ Remove the Player from the game. """ player = objmgr.GetPlayerByClientId(clientid) objmgr.UnregisterPlayer(clientid, player.id) objmgr.RemoveObject(player) deferred.Call(gameserver.ID_SERVER, 'pre_close_client', (clientid, )) return Response(clientid, 'Goodbye, %s. Hope you had fun!' % (player.name, ))
def Handle(self, clientid, request): """ Decipher a request into a command and arguments. clientid - id of the client making the request request - request string to be parsed """ # remove leading and trailing whitespace request = string.strip(request) # first token is command; remainder is argument string try: actionlist = self.sepRE.split(request, 1) except ValueError: print 'Invalid request: %s' % (request, ) return # parse argstring into arg list try: action, argstr = actionlist except ValueError: action = actionlist[0] argstr = '' args = self.sepRE.split(argstr) # convert to tuple if args == ['']: args = () # no args else: args = tuple(args) retval = _ExecuteCommand(action, clientid, args) # notify client of response via deferred call to server deferred.Call(gameserver.ID_SERVER, 'respond', (retval, ))
def PostGameEvent(self, key, delay, *args): kArgs = (key,) + args deferred.Call(self.id, 'Dispatch', kArgs, delay, None, None)
def request(self, id, data): #print 'GameServer.request( %s )' % (data,) requester = self.clients[id] # deferred call to request handler deferred.Call(request.ID_REQUEST, 'Handle', (id, data))