def onSessionReq(sessionid, cmd, body): print('onSessionReq', sessionid, cmd, body) ip = h2ext.getSessionIp(sessionid) h2ext.gateBroadcastMsg( cmd, '服务器收到消息,sessionid:%d,ip:%s,cmd:%d,data:%s' % (sessionid, ip, cmd, body)) return
def onSessionReq(sessionid, cmd, body): print('onSessionReq', sessionid, cmd, body) ip = h2ext.getSessionIp(sessionid) h2ext.sessionSendMsg( sessionid, cmd, '服务器收到消息,sessionid:%d,ip:%s,cmd:%d,data:%s' % (sessionid, ip, cmd, body)) return player = objMgr.allocPlayer(sessionid) if cmd == CMD_LOGIN: name = body oldPlayer = objMgr.findPlayerByName(name) if oldPlayer: h2ext.sessionClose(oldPlayer.sessionid) objMgr.delPlayer(sessionid) player.name = name print('player.name', player.name) allPlayerList = [] def getAllPlayer(eachPlayer): allPlayerList.append(eachPlayer.name) objMgr.foreach(getAllPlayer) def notifyOnline(eachPlayer): eachPlayer.sendChat('[%s] online ip=[%s]' % (name, h2ext.getSessionIp(sessionid))) eachPlayer.sendChat('current online list:%s' % (str(allPlayerList))) objMgr.foreach(notifyOnline) elif cmd == CMD_CHAT: msg = '[%s] say:%s' % (player.name, body) def notifyOnline(eachPlayer): eachPlayer.sendChat(msg) objMgr.foreach(notifyOnline)
def notifyOnline(eachPlayer): eachPlayer.sendChat('[%s] online ip=[%s]' % (name, h2ext.getSessionIp(sessionid))) eachPlayer.sendChat('current online list:%s' % (str(allPlayerList)))