Esempio n. 1
0
 def OnClientSceneMsg(self, connect_id, str_msg):
     logger.GetLog().debug('gateway on client scene msg : connect id = %s' % (connect_id, ))
     connect_info = ModObjFac.CreateApp().get_connect_info(connect_id)
     if connect_info and connect_info.has_bind_user():
         # 直接转发,gateway 不做逻辑处理,交给具体业务服处理
         ModObjFac.CreateApp().get_gateway_2_scene_proxy_rpc().OnSceneMsg(connect_info.server_group_id, connect_info.server_user_id, str_msg)
     else:
         # 还未登录,返回失败
         logger.GetLog().warn('connect send msg but has not bind user : %s' % connect_id)
         ret_msg = CGCommonErrorResponse()
         ret_msg.return_code = excp.ExceptionNeedLogin.code
         ModObjFac.CreateApp().send_msg_to_client(connect_id, ModTopo.PROTO_TYPE.COMMON, msgpack.packb(ret_msg.dump()))
Esempio n. 2
0
 def handle_get_online_num(self, connect_id):
     connect_info = ModObjFac.CreateApp().get_connect_info(connect_id)
     if connect_info and connect_info.server_group_id:
         res_obj = CGGetOnlineNumResponse()
         res_obj.online_num = self.get_server_online_num(
             connect_info.server_group_id)
         logger.GetLog().debug(
             'server %s online num %s' %
             (connect_info.server_group_id, res_obj.online_num))
         # 返回信息给客户端
         ModObjFac.CreateApp().send_msg_to_client(
             connect_id, ModTopo.PROTO_TYPE.COMMON,
             msgpack.packb(res_obj.dump()))
Esempio n. 3
0
 def OnClientChatMsg(self, connect_id, str_msg):
     logger.GetLog().debug('gateway on client chat msg : connect id = %s' % (connect_id, ))
     connect_info = ModObjFac.CreateApp().get_connect_info(connect_id)
     if connect_info and connect_info.has_bind_user():
         # 直接转发,gateway 不做逻辑处理,交给具体业务服处理
         ModObjFac.CreateApp().get_gateway_2_chat_proxy_rpc().OnChatMsg(connect_info.server_group_id, connect_info.server_user_id, str_msg)
     elif ModObjFac.CreateApp().is_game_server_connect(connect_id):
         # 游戏服发来的直接转发,gateway 不做逻辑处理,交给具体业务服处理
         ModObjFac.CreateApp().get_gateway_2_chat_proxy_rpc().OnGameNotice(str_msg)
     else:
         # 还未登录,返回失败
         logger.GetLog().warn('connect send msg but has not bind user : %s' % connect_id)
         ret_msg = CGSendChatMsgResponse()
         ret_msg.return_code = excp.ExceptionNeedLogin.code
         ModObjFac.CreateApp().send_msg_to_client(connect_id, ModTopo.PROTO_TYPE.CHAT, msgpack.packb(ret_msg.dump()))
Esempio n. 4
0
 def handle_game_server_register(self, connect_id, msg_obj):
     logger.GetLog().info('game server register: %s, %s, %s' %
                          (connect_id, msg_obj.rk_zone, msg_obj.sign))
     res_obj = CGGameServerRegisterResponse()
     res_obj.return_code = excp.ExceptionSuccess.code
     if not self.check_game_server_register(msg_obj.rk_zone, msg_obj.sign):
         # 校验失败
         res_obj.return_code = excp.ExceptionCheckLoginFailed.code
     else:
         ModObjFac.CreateApp().add_game_server_connect(
             connect_id, msg_obj.rk_zone)
     res_msg = res_obj.dump()
     logger.GetLog().debug('game server login server res : %s' % res_msg)
     # 返回信息给游戏服
     ModObjFac.CreateApp().send_msg_to_client(connect_id,
                                              ModTopo.PROTO_TYPE.COMMON,
                                              msgpack.packb(res_msg))
Esempio n. 5
0
 def OnClientCommonMsg(self, connect_id, str_msg):
     msg = msgpack.unpackb(str_msg)
     logger.GetLog().debug('gateway on client common msg : connect id = %s, msg = %s' % (connect_id, msg))
     cmd = msg.get(proto_def.field_name_cmd, None)
     if cmd is None:
         logger.GetLog().warn('gateway on client common msg unexpected cmd : %s' % cmd)
     else:
         if cmd == proto_def.cg_login_server:
             # 登录服务器
             msg_obj = CGLoginServerRequest.new_from_data(msg)
             ModObjFac.CreateApp().get_msg_manager().handle_user_login_server(connect_id, msg_obj)
         elif cmd == proto_def.cg_get_online_num:
             ModObjFac.CreateApp().get_msg_manager().handle_get_online_num(connect_id)
         elif cmd == proto_def.cg_game_server_register:
             # 游戏服登录
             msg_obj = CGGameServerRegisterRequest.new_from_data(msg)
             ModObjFac.CreateApp().get_msg_manager().handle_game_server_register(connect_id, msg_obj)
         else:
             logger.GetLog().warn('gateway on client common msg unexpected cmd : %s' % cmd)
Esempio n. 6
0
    def handle_user_logout(self, connect_id):
        connect_info = ModObjFac.CreateApp().get_connect_info(connect_id)
        logger.GetLog().debug(
            'client disconnect: connect id = %s, has info = %s' %
            (connect_id, connect_info is not None))
        if connect_info:
            if connect_info.has_bind_user():
                logger.GetLog().debug(
                    'user logout : %s, %s, %s' %
                    (connect_id, connect_info.server_group_id,
                     connect_info.server_user_id))
                # 推送玩家下线消息给chat server, 更新在线人数
                ModObjFac.CreateApp().get_gateway_2_chat_proxy_rpc(
                ).OnUserOnlineStatusUpdate(connect_info.server_group_id,
                                           connect_info.server_user_id,
                                           connect_id, False)
                # 推送玩家下线消息给team server
                ModObjFac.CreateApp().get_gateway_2_team_proxy_rpc(
                ).OnUserOnlineStatusUpdate(connect_info.server_group_id,
                                           connect_info.server_user_id, False)
                # 推送给战斗服battle server
                ModObjFac.CreateApp().get_gateway_2_fight_proxy_rpc(
                ).OnUserOffline(connect_info.server_group_id,
                                connect_info.server_user_id)
                # 推送玩家在线状态给scene server
                ModObjFac.CreateApp().get_gateway_2_scene_proxy_rpc(
                ).OnUserLogout(connect_info.server_group_id,
                               connect_info.server_user_id)

            ModObjFac.CreateApp().del_connect(connect_info.server_group_id,
                                              connect_info.server_user_id,
                                              connect_id)
Esempio n. 7
0
    def handle_user_login_server(self, connect_id, msg_obj):
        logger.GetLog().info('user login server : %s, %s, %s, %s' %
                             (connect_id, msg_obj.server_user_id,
                              msg_obj.server_id, msg_obj.sign))
        res_obj = CGLoginServerResponse()
        res_obj.return_code = excp.ExceptionSuccess.code
        gateway_app = ModObjFac.CreateApp()
        # 校验登录参数
        if not self.check_login_sign(msg_obj.server_user_id, msg_obj.server_id,
                                     msg_obj.sign):
            # 校验失败
            res_obj.return_code = excp.ExceptionCheckLoginFailed.code
        else:
            # 校验成功
            server_group_id = get_server_group_id(msg_obj.server_id)
            # TODO: 先将现有连接主动断掉?
            # 移除旧连接
            old_connect_id = gateway_app.get_conn_id_by_char_id(
                msg_obj.server_user_id)
            if old_connect_id != -1:
                gateway_app.del_connect(server_group_id,
                                        msg_obj.server_user_id, old_connect_id)

            # 增加连接信息
            gateway_app.add_connect(server_group_id, msg_obj.server_user_id,
                                    connect_id)
            # 同步玩家在线状态到各个chat server,更新在线人数
            gateway_app.get_gateway_2_chat_proxy_rpc(
            ).OnUserOnlineStatusUpdate(
                server_group_id, msg_obj.server_user_id, connect_id, True,
                gateway_app.get_client_connect_ip(connect_id))
            # 推送玩家在线状态给team server
            gateway_app.get_gateway_2_team_proxy_rpc(
            ).OnUserOnlineStatusUpdate(server_group_id, msg_obj.server_user_id,
                                       True)
            # # 推送玩家在线状态给scene server
            # gateway_app.get_gateway_2_scene_proxy_rpc().OnUserOnlineStatusUpdate(server_group_id, msg_obj.server_user_id, True)
        res_msg = res_obj.dump()
        logger.GetLog().debug('user login server res : %s' % res_msg)
        # 返回信息给客户端
        gateway_app.send_msg_to_client(connect_id, ModTopo.PROTO_TYPE.COMMON,
                                       msgpack.packb(res_msg))