def login_player(self, sockfd, data): Logger.LogDebug("login_player") uniqid = data['id'] # 判断是不是relogin if self._check_relogin(uniqid): Logger.LogDebug("relogin error: uniqid,%d"%uniqid) self._kick_player(uniqid) clientproxy = ClientProxy(sockfd, uniqid) ClientProxyManager().set_client_proxy(clientproxy) PlayerMgr().LoadObj(uniqid, self._login_callback, clientproxy)
def after_load(self, success): """Load完player之后Load其他存盘对象""" Logger.LogDebug("after_load,%d,%s,%s" % (self.id(), self.name(), str(self.data()))) GameServerRepo.g_chat_room.add_player_2_channel( self._channel, self._uniqid)
def OnFdClosed(sockfd): """关闭socket,删除player""" Logger.LogDebug("Py OnFdClosed:%d" % sockfd) LoginMgr().player_sockfd_close(sockfd) return 0, "success"
def OnTimer(timerid): Logger.LogDebug("Py OnTimer:%d" % timerid) from common import Timer Timer.onTimer(timerid) return 0, "success"
def create_player(self, sockfd, data): Logger.LogDebug("create_player") uniqid = int(data['id']) clientproxy = ClientProxy(sockfd, uniqid) ClientProxyManager().set_client_proxy(clientproxy) player = PlayerMgr().CreateObj(uniqid, clientproxy) #player.init_channel(1) result = {"result":1} player.send_data(COMMAND_ID_LOGIN, SUB_LOGIN_CREATE, result)
def __init__(self, uniqid, clientproxy=None): super(Player, self).__init__(DATABASE["player"]) self._uniqid = uniqid self._clientproxy = clientproxy if clientproxy is not None: self._clientproxy.uniqid = uniqid self.setId(uniqid) self._data = {} self._channel = 0 self._pos = 0 Logger.LogDebug("player init")
def dispatch_protocol(uniqid, command_id, sub_id, data): path = proto_2_path.get(command_id, None) if path is None: Logger.LogError("Dispatch_Protocol error:command_id:%d" % command_id) return try: module_name = __import__('logic.%s.zprotocol' % path, fromlist=['']) attr = getattr(module_name, 'proto_%d_%d' % (command_id, sub_id)) attr(uniqid, data) except: import traceback traceback.print_exc() return Logger.LogDebug("Dispatch_Protocol finish")
def _login_callback(self, uniqid, player): Logger.LogDebug("login_callback") if player is None: Logger.LogError("login_callback error,not exists") #TODO,登陆失败后清理数据 clientproxy = ClientProxyManager().get_client_proxy_by_uniqid(uniqid) if clientproxy: result = {"result": -1} clientproxy.send_data(COMMAND_ID_LOGIN,SUB_LOGIN_LOGIN, result) ClientProxyManager().remove_client_proxy(clientproxy) else: PlayerMgr().AddObj(uniqid, player) result = {"result": 1, "name": player.name(), "sex": player.sex()} player.send_data(COMMAND_ID_LOGIN, SUB_LOGIN_LOGIN, result)
def loadFromDb(self, data, callback): Logger.LogDebug("saveobj.loadFromDb:%s" % str(data)) for attr, d in data.iteritems(): if self._cols[attr] == "bld": d = loads(d) elif self._cols[attr] == "int": d = int(d) print attr, self._loadfuncs[attr] func = getattr(self, self._loadfuncs[attr]) func(d) bSuccess = (True if data else False) if bSuccess: callback(self.id(), self) self.after_load(bSuccess) else: callback(self.id(), None)
def OnServer(uniqid, command_id, sub_id, data): """接收协议数据""" Logger.LogDebug("OnServer:%d,%d,%d,%s" % (uniqid, command_id, sub_id, data)) dict = None try: dict = json.loads(data) print dict.keys() except: import traceback traceback.print_exc() if dict is None: Logger.LogError("OnServer Error: dict is None:%d,%d,%d,%s" % (uniqid, command_id, sub_id, data)) return dispatch_protocol(uniqid, command_id, sub_id, dict) return 0, "success"
def OnConnector(command_id, sub_id, data): """游戏服作为客户端连接的服务器返回的数据""" Logger.LogDebug("OnConnector: %d,%d,%s" % (command_id, sub_id, data)) dict = None try: dict = json.loads(data) print dict.keys() except: import traceback traceback.print_exc() if dict is None: Logger.LogError("CallMethod Error: dict is None:%d,%d" % (command_id, sub_id, data)) return from common import SqlExec SqlExec.OnExecCallback(sub_id, dict) return 0, "success"
def _saveToDb(self): Logger.LogDebug("saveobj.saveToDb:%s" % self.getSqlUpdate()) self._dirty = False SqlExec.SqlExec(self.getSqlUpdate())
def proto_2_3(uniqid, player, data): Logger.LogDebug("proto_2_3") g_chat_room.talk(player, data)
def proto_2_1(uniqid, player, data): Logger.LogDebug("proto_1_1%d,%s" % (uniqid, str(data))) player.set_channel()
def __init__(self): Logger.LogDebug("GameServer init") GameServerRepo.g_chat_room = ChatRoom()
def queryDb(self, callback): Logger.LogDebug("saveobj.querydb:%s" % self.getSqlSelect()) func = lambda data: self.loadFromDb(data, callback) SqlExec.SqlExec(self.getSqlSelect(), func)
def player_process(self, sockfd, data): Logger.LogDebug("player_process")