private void OnMessageReveived(long conn_idx, ushort header, ByteArray data)
        {
            PacketBase packet = PacketPools.Get(header);

            packet.Read(data);
            ConnAppProc app_server = null;

            if (!m_app_servers.TryGetValue(conn_idx, out app_server))
            {
                if (packet.header == inner.msg.REQ_LOGIN)
                {
                    if (!m_app_servers.ContainsKey(conn_idx))
                    {
                        //创建新连接
                        inner.ReqLogin msg = packet as inner.ReqLogin;
                        Log.Info("收到内部服务器连接请求:" + msg.srv_info.srv_type);

                        app_server                        = CreateConnApp(msg.srv_info.srv_type);
                        app_server.conn_idx               = conn_idx;
                        app_server.srv_info.srv_type      = msg.srv_info.srv_type;
                        app_server.srv_info.srv_status    = eConnAppStatus.CONNECTED;
                        app_server.srv_info.srv_realm_idx = msg.srv_info.srv_realm_idx;
                        app_server.srv_info.srv_uid       = msg.srv_info.srv_uid;
                        app_server.srv_info.srv_endpoint  = msg.srv_info.srv_endpoint;
                        m_app_servers.Add(conn_idx, app_server);
                        OnConnAppEnter(app_server);

                        //响应
                        inner.RepLogin rep_msg = PacketPools.Get(inner.msg.REP_LOGIN) as inner.RepLogin;
                        rep_msg.result                 = inner.RepLogin.eResult.SUCCESS;
                        rep_msg.srv_info.srv_type      = eServerType.FIGHT;
                        rep_msg.srv_info.srv_realm_idx = app_server.srv_info.srv_realm_idx;
                        rep_msg.srv_info.srv_uid       = app_server.srv_info.srv_uid;
                        this.Send(conn_idx, rep_msg);
                    }
                }
            }
            if (app_server != null)
            {
                if (!app_server.HandleMsg(conn_idx, packet))
                {
                    //switch (packet.header)
                    //{
                    //    case inner.msg.APPSERVER_SHUTDOWN:
                    //        app_server.is_res_loaded = true;
                    //        break;

                    //}
                }
            }
            PacketPools.Recover(packet);
        }
        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~事件~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
        private void OnConnected(long conn_idx)
        {
            Log.Info("open conn session:" + conn_idx);

            ConnAppProc app_server;

            if (m_app_servers.TryGetValue(conn_idx, out app_server))
            {
                if (app_server.srv_info.srv_type == eServerType.WORLD)
                {//连接世界服
                    inner.ReqLogin msg = PacketPools.Get(inner.msg.REQ_LOGIN) as inner.ReqLogin;
                    msg.srv_info.srv_type          = eServerType.DB;
                    msg.srv_info.srv_uid           = m_srv_uid;
                    msg.srv_info.srv_endpoint.ip   = app_server.srv_info.srv_endpoint.ip;
                    msg.srv_info.srv_endpoint.port = app_server.srv_info.srv_endpoint.port;
                    this.Send(conn_idx, msg);
                }
            }
        }
示例#3
0
        private void OnConnected(long conn_idx)
        {
            Log.Info("open conn session:" + conn_idx);

            ConnAppProc app_server;

            if (m_app_servers.TryGetValue(conn_idx, out app_server))
            {
                Log.Info("发送内部服务器连接请求:" + app_server.srv_info.srv_type);
                inner.ReqLogin msg = PacketPools.Get(inner.msg.REQ_LOGIN) as inner.ReqLogin;
                msg.srv_info.srv_type          = eServerType.FIGHT;
                msg.srv_info.srv_uid           = m_srv_uid;
                msg.srv_info.srv_endpoint.ip   = SocketUtils.IpToInt(ServerConfig.net_info.ip_for_server);//告诉其他服,战斗服的ip和端口
                msg.srv_info.srv_endpoint.port = ServerConfig.net_info.port_for_server;
                this.Send(conn_idx, msg);
            }
            else
            {
                Log.Warning("未找到连接:" + conn_idx);
            }
        }
示例#4
0
        private void OnConnected(long conn_idx)
        {
            Log.Info("Open session:" + conn_idx);

            ConnAppProc app_server;

            if (m_app_servers.TryGetValue(conn_idx, out app_server))
            {
                Log.Info("发送内部服务器连接请求:" + app_server.srv_info.srv_type);
                inner.ReqLogin msg = PacketPools.Get(inner.msg.REQ_LOGIN) as inner.ReqLogin;
                msg.srv_info.srv_type          = eServerType.SERVER;
                msg.srv_info.srv_realm_idx     = m_srv_realm_idx;
                msg.srv_info.srv_uid           = m_srv_uid;
                msg.srv_info.srv_endpoint.ip   = 0;//逻辑服只连接其他服,不需要设置
                msg.srv_info.srv_endpoint.port = 0;
                this.Send(conn_idx, msg);
            }
            else
            {
                Log.Warning("未找到连接:" + conn_idx);
            }
        }
示例#5
0
        private void OnMessageReveived(long conn_idx, ushort header, ByteArray data)
        {
            PacketBase packet = PacketPools.Get(header);

            packet.Read(data);
            do
            {
                ConnAppProc app_server = null;
                if (!m_app_servers.TryGetValue(conn_idx, out app_server))
                {
                    if (packet.header == inner.msg.REQ_LOGIN)
                    {
                        if (!m_app_servers.ContainsKey(conn_idx))
                        {
                            inner.ReqLogin msg = packet as inner.ReqLogin;

                            //检测是否相同id的服务器以及连接
                            if (m_srv_servers.ContainsKey(msg.srv_info.srv_uid))
                            {
                                Log.Warning("相同服务器以及连接 sid:" + msg.srv_info.srv_uid);
                                m_net_socket.CloseConn(conn_idx);
                                break;
                            }
                            Log.Info("收到内部服务器连接请求:" + msg.srv_info.srv_type);
                            //创建新连接
                            app_server                            = CreateConnApp(msg.srv_info.srv_type);
                            app_server.conn_idx                   = conn_idx;
                            app_server.srv_info.srv_type          = msg.srv_info.srv_type;
                            app_server.srv_info.srv_status        = eConnAppStatus.CONNECTED;
                            app_server.srv_info.srv_realm_idx     = ServerConfig.net_info.server_realm;
                            app_server.srv_info.srv_uid           = msg.srv_info.srv_uid;
                            app_server.srv_info.srv_endpoint.ip   = msg.srv_info.srv_endpoint.ip;
                            app_server.srv_info.srv_endpoint.port = msg.srv_info.srv_endpoint.port;
                            m_app_servers.Add(conn_idx, app_server);
                            OnConnAppEnter(app_server);

                            //响应
                            inner.RepLogin rep_msg = PacketPools.Get(inner.msg.REP_LOGIN) as inner.RepLogin;
                            rep_msg.result                 = inner.RepLogin.eResult.SUCCESS;
                            rep_msg.srv_info.srv_type      = eServerType.WORLD;
                            rep_msg.srv_info.srv_realm_idx = ServerConfig.net_info.server_realm;
                            rep_msg.srv_info.srv_uid       = ServerConfig.net_info.server_uid;
                            rep_msg.ws_time                = GameTimeManager.Instance.server_time;
                            this.Send(conn_idx, rep_msg);

                            //告诉启动次数
                            IdSharedManager.Instance.SendStartCount(conn_idx);

                            //告诉当前存在的服务器
                            List <ConnAppProc> list_app = new List <ConnAppProc>();
                            GetConnAppList(list_app, eServerType.GATE);
                            GetConnAppList(list_app, eServerType.SERVER);
                            GetConnAppList(list_app, eServerType.FIGHT);

                            //发送当前存在的服务器列表
                            while (list_app.Count > 0)
                            {
                                inner.AppServerList list_msg = PacketPools.Get(inner.msg.APPSERVER_LIST) as inner.AppServerList;
                                for (int i = 0; i < 10 && list_app.Count > 0; ++i)
                                {
                                    ConnAppProc tmp_app = list_app[list_app.Count - 1];
                                    if (tmp_app.srv_info.srv_uid == app_server.srv_info.srv_uid)
                                    {//不发送自己
                                        list_app.RemoveAt(list_app.Count - 1);
                                        continue;
                                    }

                                    AppServerItem item = new AppServerItem();
                                    item.srv_uid  = tmp_app.srv_info.srv_uid;
                                    item.srv_type = tmp_app.srv_info.srv_type;
                                    item.srv_ip   = tmp_app.srv_info.srv_endpoint.ip;
                                    item.srv_port = tmp_app.srv_info.srv_endpoint.port;
                                    list_msg.list.Add(item);

                                    list_app.RemoveAt(list_app.Count - 1);
                                }
                                if (list_msg.list.Count > 0)
                                {
                                    app_server.Send(list_msg);
                                }
                                else
                                {
                                    PacketPools.Recover(list_msg);
                                }
                            }

                            //广播新服务器加入
                            inner.AppServerAdd add_msg = PacketPools.Get(inner.msg.APPSERVER_ADD) as inner.AppServerAdd;
                            add_msg.app_info.srv_uid  = app_server.srv_info.srv_uid;
                            add_msg.app_info.srv_type = app_server.srv_info.srv_type;
                            add_msg.app_info.srv_ip   = app_server.srv_info.srv_endpoint.ip;
                            add_msg.app_info.srv_port = app_server.srv_info.srv_endpoint.port;
                            this.BroadcastMsgWithout(add_msg, app_server.conn_idx);
                        }
                    }
                }
                if (app_server != null)
                {
                    if (!app_server.HandleMsg(conn_idx, packet))
                    {
                        switch (packet.header)
                        {
                        case inner.msg.APPSERVER_SHUTDOWN:
                            break;
                        }
                    }
                }
            } while (false);
            PacketPools.Recover(packet);
        }