コード例 #1
0
        public int InitializeClient(KuaFuClientContext clientInfo)
        {
            int result;

            try
            {
                if (clientInfo.ServerId != 0)
                {
                    bool bFirstInit = false;
                    int  ret        = ClientAgentManager.Instance().InitializeClient(clientInfo, out bFirstInit);
                    if (ret > 0)
                    {
                        if (clientInfo.MapClientCountDict != null && clientInfo.MapClientCountDict.Count > 0)
                        {
                            KuaFuServerManager.UpdateKuaFuLineData(clientInfo.ServerId, clientInfo.MapClientCountDict);
                            ClientAgentManager.Instance().SetMainlinePayload(clientInfo.ServerId, clientInfo.MapClientCountDict.Values.ToList <int>().Sum());
                        }
                    }
                    result = ret;
                }
                else
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("InitializeClient时GameType错误,禁止连接.ServerId:{0},GameType:{1}", clientInfo.ServerId, clientInfo.GameType), null, true);
                    result = -4003;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1},info:{2}", clientInfo.ServerId, clientInfo.ClientId, clientInfo.Token));
                result = -11003;
            }
            return(result);
        }
コード例 #2
0
ファイル: ClientAgentManager.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 初始化GameServer代理
        /// 同一个GameServer的Service与ClientAgent是一个N:1的关系
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="clientInfo"></param>
        /// <param name="bFistInit">是否是首次初始化该client</param>
        /// <returns></returns>
        public int InitializeClient(IKuaFuClient callback, KuaFuClientContext clientInfo, out bool bFistInit)
        {
            bFistInit = false;
            lock (Mutex)
            {
                ClientAgent agent = null;
                if (!ServerId2ClientAgent.TryGetValue(clientInfo.ServerId, out agent) ||
                    !agent.IsAlive)
                {
                    // clientInfo.ServerId 上的任意service都未连接过来,或者已连接,但是agent已超时死亡,需要重设agent
                    LogManager.WriteLog(LogTypes.Info,
                                        string.Format("InitializeClient服务器连接1.ServerId:{0},ClientId:{1},info:{2},GameType:{3} [Service首次连接过来]",
                                                      clientInfo.ServerId, clientInfo.ClientId, clientInfo.Token, (GameTypes)clientInfo.GameType));
                    bFistInit           = true;
                    clientInfo.ClientId = KuaFuServerManager.GetUniqueClientId();
                    agent = new ClientAgent(clientInfo, callback);
                    ServerId2ClientAgent[clientInfo.ServerId] = agent;
                }
                else
                {
                    // clientInfo.ServerId 上的至少有一个service已经连接过来了

                    // token 不一致,重复 ServerId重复!!!
                    if (clientInfo.Token != agent.ClientInfo.Token)
                    {
                        LogManager.WriteLog(LogTypes.Info,
                                            string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1},info:{2},GameType:{3}",
                                                          clientInfo.ServerId, clientInfo.ClientId, clientInfo.Token, (GameTypes)clientInfo.GameType));
                        return(StdErrorCode.Error_Duplicate_Key_ServerId);
                    }

                    // clientInfo.ServerId 这个GameType的Service首次连接过来
                    if (clientInfo.ClientId <= 0)
                    {
                        bFistInit = true;
                        LogManager.WriteLog(LogTypes.Info,
                                            string.Format("InitializeClient服务器连接2.ServerId:{0},ClientId:{1},info:{2},GameType:{3} [Service非首次连接过来]",
                                                          clientInfo.ServerId, clientInfo.ClientId, clientInfo.Token, (GameTypes)clientInfo.GameType));
                    }
                    else if (clientInfo.ClientId != agent.ClientInfo.ClientId)
                    {
                        // GameServer不重启,中心重启后,从第二个连过来的service开始会走到这里
                        // tcp的虚拟连接能够使Gameserver感知不到中心的重启,这里需要修改clientInfo.ClientId
                        bFistInit = true;
                        LogManager.WriteLog(LogTypes.Info,
                                            string.Format("InitializeClient服务器连接3.ServerId:{0},ClientId:{1},info:{2},GameType:{3} [中心重启]",
                                                          clientInfo.ServerId, clientInfo.ClientId, clientInfo.Token, (GameTypes)clientInfo.GameType));
                    }
                }

                if (agent != null)
                {
                    clientInfo.ClientId = agent.ClientInfo.ClientId;
                    agent.ClientHeartTick();
                    agent.TryInitGameType(clientInfo.GameType);
                }

                return(clientInfo.ClientId);
            }
        }
コード例 #3
0
        public int InitializeClient(KuaFuClientContext clientInfo)
        {
            int result;

            try
            {
                if (clientInfo.ServerId != 0)
                {
                    bool bFirstInit = false;
                    int  ret        = ClientAgentManager.Instance().InitializeClient(clientInfo, out bFirstInit);
                    if (ret > 0)
                    {
                    }
                    result = ret;
                }
                else
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("InitializeClient时GameType错误,禁止连接.ServerId:{0},GameType:{1}", clientInfo.ServerId, clientInfo.GameType), null, true);
                    result = -4003;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1},info:{2}", clientInfo.ServerId, clientInfo.ClientId, clientInfo.Token));
                result = -11003;
            }
            return(result);
        }
コード例 #4
0
ファイル: ClientAgent.cs プロジェクト: qiuhoude/mu_server
 public void Reset(KuaFuClientContext clientInfo)
 {
     lock (this.Mutex)
     {
         this.ClientInfo = clientInfo;
         this.ClientHeartTick();
         this.AlivedGameDict.Clear();
         this.TotalFubenRolePayLoad    = 0L;
         this.TotalMainlineRolePayLoad = 0L;
     }
 }
コード例 #5
0
        private static void NewKFClient(string host, int port)
        {
            AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = new AutoCSer.Net.TcpInternalServer.ServerAttribute();
            attribute.IsAutoClient            = true;
            attribute.Host                    = host;
            attribute.Port                    = port;
            attribute.ServerSendBufferMaxSize = 33554432;
            attribute.ClientSendBufferMaxSize = 4194304;
            KuaFuClientContext clientInfo = new KuaFuClientContext();

            clientInfo.ServerId      = GameManager.ServerId;
            clientInfo.Token         = GameCoreInterface.getinstance().GetLocalAddressIPs();
            KFCallManager.Host       = host;
            KFCallManager.Port       = port;
            KFCallManager.ClientInfo = clientInfo;
            AutoCSer.Net.TcpStaticServer.Client tcpClient = KfCall.NewTcpClient(attribute, null, MyLogAdapter.GetILog(), new Func <AutoCSer.Net.TcpInternalServer.ClientSocketSender, bool>(KFCallManager.verifyMethod));
            KFCallManager.Current = new KFCallManager.KFClient(tcpClient, attribute, clientInfo, new Action <KFCallManager.KFClient>(KFCallManager.OnSetSocket));
            tcpClient.TryCreateSocket();
        }
コード例 #6
0
 /// <summary>
 /// 初始化跨服客户端回调对象
 /// </summary>
 public int InitializeClient(IKuaFuClient callback, KuaFuClientContext clientInfo)
 {
     try
     {
         if (clientInfo.GameType == (int)GameTypes.Spread && clientInfo.ServerId != 0)
         {
             return(ClientAgentManager.Instance().InitializeClient(callback, clientInfo));
         }
         else
         {
             LogManager.WriteLog(LogTypes.Warning, string.Format("InitializeClient时GameType错误,禁止连接.ServerId:{0},GameType:{1}", clientInfo.ServerId, clientInfo.GameType));
             return(StdErrorCode.Error_Invalid_GameType);
         }
     }
     catch (System.Exception ex)
     {
         LogManager.WriteExceptionUseCache(string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1}", clientInfo.ServerId, clientInfo.ClientId));
         return(StdErrorCode.Error_Server_Internal_Error);
     }
 }
コード例 #7
0
        public int InitializeClient(KuaFuClientContext clientInfo)
        {
            int result;

            try
            {
                if (clientInfo.GameType == (int)this.GameType && clientInfo.ServerId != 0)
                {
                    result = ClientAgentManager.Instance().InitializeClient(clientInfo);
                }
                else
                {
                    LogManager.WriteLog(LogTypes.Warning, string.Format("InitializeClient时GameType错误,禁止连接.ServerId:{0},GameType:{1}", clientInfo.ServerId, clientInfo.GameType), null, true);
                    result = -4003;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1}", clientInfo.ServerId, clientInfo.ClientId));
                result = -11003;
            }
            return(result);
        }
コード例 #8
0
        /// <summary>
        /// 初始化跨服客户端回调对象
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="age"></param>
        /// <param name="version"></param>
        /// <returns>clientId</returns>
        public int InitializeClient(IKuaFuClient callback, KuaFuClientContext clientInfo)
        {
            int  clientId  = -1;
            bool firstInit = false;

            try
            {
                if (clientInfo.GameType == (int)GameTypes.HuanYingSiYuan && clientInfo.ServerId != 0)
                {
                    //如果是第一次初始化,需要清空原始的
                    if (clientInfo.ClientId == 0)
                    {
                        firstInit = true;
                    }

                    Lazy <HuanYingSiYuanAgent> lazy = new Lazy <HuanYingSiYuanAgent>(() =>
                    {
                        clientInfo.ClientId = Persistence.GetUniqueClientId(clientInfo.ServerId);
                        return(new HuanYingSiYuanAgent(clientInfo, callback));
                    });

                    HuanYingSiYuanAgent huanYingSiYuanAgent = ServerId2KuaFuClientAgent.GetOrAdd(clientInfo.ServerId, (x) => { return(lazy.Value); });
                    if (clientInfo.ClientId != huanYingSiYuanAgent.ClientInfo.ClientId)
                    {
                        if (clientInfo.ClientId > 0)
                        {
                            if (huanYingSiYuanAgent.IsClientAlive())
                            {
                                LogManager.WriteLog(LogTypes.Error, string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1}", clientInfo.ServerId, clientInfo.ClientId));
                                return(StdErrorCode.Error_Duplicate_Key_ServerId);
                            }
                        }

                        clientId = huanYingSiYuanAgent.ClientInfo.ClientId;
                    }
                    else
                    {
                        clientId = clientInfo.ClientId;
                    }

                    if (firstInit)
                    {
                        huanYingSiYuanAgent.Reset();
                        List <int> list = huanYingSiYuanAgent.GetAliveGameFuBenList();
                        if (null != list && list.Count > 0)
                        {
                            foreach (var id in list)
                            {
                                HuanYingSiYuanFuBenData fuBenData;
                                if (HuanYingSiYuanFuBenDataDict.TryGetValue(id, out fuBenData))
                                {
                                    RemoveGameFuBen(fuBenData, huanYingSiYuanAgent);
                                }
                                else
                                {
                                    huanYingSiYuanAgent.RemoveGameFuBen(id);
                                }
                            }
                        }
                    }
                }
                else
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("InitializeClient时GameType错误,禁止连接.ServerId:{0},GameType:{1}", clientInfo.ServerId, clientInfo.GameType));
                    return(StdErrorCode.Error_Invalid_GameType);
                }
            }
            catch (System.Exception ex)
            {
                LogManager.WriteExceptionUseCache(string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1}", clientInfo.ServerId, clientInfo.ClientId));
                return(StdErrorCode.Error_Server_Internal_Error);
            }

            return(clientId);
        }
コード例 #9
0
        public int InitializeClient(KuaFuClientContext clientInfo)
        {
            bool bPlaceHolder = false;

            return(this.InitializeClient(clientInfo, out bPlaceHolder));
        }
コード例 #10
0
ファイル: KFServiceBase.cs プロジェクト: qiuhoude/mu_server
        public static bool InitializeClient(AutoCSer.Net.TcpInternalServer.ServerSocketSender socket, KuaFuClientContext clientInfo)
        {
            bool isLogin = false;

            try
            {
                if (clientInfo.ServerId != 0)
                {
                    bool bFirstInit = false;
                    int  ret        = ClientAgentManager.Instance().InitializeClient(clientInfo, out bFirstInit);
                    if (ret > 0)
                    {
                        isLogin             = true;
                        socket.ClientObject = ClientAgentManager.Instance().GetCurrentClientAgent(clientInfo.ServerId);
                        if (clientInfo.MapClientCountDict != null && clientInfo.MapClientCountDict.Count > 0)
                        {
                            KuaFuServerManager.UpdateKuaFuLineData(clientInfo.ServerId, clientInfo.MapClientCountDict);
                            ClientAgentManager.Instance().SetMainlinePayload(clientInfo.ServerId, clientInfo.MapClientCountDict.Values.ToList <int>().Sum());
                        }
                    }
                }
                else
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("InitializeClient时GameType错误,禁止连接.ServerId:{0},GameType:{1}", clientInfo.ServerId, clientInfo.GameType), null, true);
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1},info:{2}", clientInfo.ServerId, clientInfo.ClientId, clientInfo.Token));
            }
            return(isLogin);
        }
コード例 #11
0
ファイル: ClientAgent.cs プロジェクト: chenchungit/ky
 public ClientAgent(KuaFuClientContext clientInfo, IKuaFuClient callback)
 {
     ClientInfo  = clientInfo;
     KuaFuClient = callback;
     ClientHeartTick();
 }
コード例 #12
0
        public int InitializeClient(KuaFuClientContext clientInfo, out bool bFistInit)
        {
            bFistInit = false;
            if (KuaFuServerManager.LimitIP)
            {
                bool            denied     = true;
                KuaFuServerInfo serverInfo = KuaFuServerManager.GetKuaFuServerInfo(clientInfo.ServerId);
                if (null == serverInfo)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("非法连接,无效的服务器编号#serverid={0},ip={1},gametype={2}", clientInfo.ServerId, clientInfo.Token, (GameTypes)clientInfo.GameType), null, true);
                    return(-1);
                }
                if (serverInfo != null && !string.IsNullOrEmpty(clientInfo.Token))
                {
                    if (!string.IsNullOrEmpty(serverInfo.LanIp) && clientInfo.Token.Contains(serverInfo.LanIp))
                    {
                        denied = false;
                    }
                    else if (clientInfo.Token.Contains(serverInfo.Ip))
                    {
                        denied = false;
                    }
                }
                if (denied)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("非法连接#serverid={0},ip={1},ip={2},lanip={3},gametype={4}", new object[]
                    {
                        clientInfo.ServerId,
                        clientInfo.Token,
                        serverInfo.Ip,
                        serverInfo.LanIp,
                        (GameTypes)clientInfo.GameType
                    }), null, true);
                    return(-1);
                }
            }
            int clientId;

            lock (this.Mutex)
            {
                ClientAgent agent = null;
                if (!this.ServerId2ClientAgent.TryGetValue(clientInfo.ServerId, out agent))
                {
                    LogManager.WriteLog(LogTypes.Info, string.Format("InitializeClient服务器连接1.ServerId:{0},ClientId:{1},info:{2},GameType:{3} [Service首次连接过来]", new object[]
                    {
                        clientInfo.ServerId,
                        clientInfo.ClientId,
                        clientInfo.Token,
                        (GameTypes)clientInfo.GameType
                    }), null, true);
                    bFistInit           = true;
                    clientInfo.ClientId = KuaFuServerManager.GetUniqueClientId();
                    agent = new ClientAgent(clientInfo);
                    this.ServerId2ClientAgent[clientInfo.ServerId] = agent;
                }
                else if (clientInfo.Token != agent.ClientInfo.Token)
                {
                    if (clientInfo.ClientId == agent.ClientInfo.ClientId)
                    {
                        LogManager.WriteLog(LogTypes.Info, string.Format("InitializeClient服务器IP变化.ServerId:{0},ClientId:{1},info:{2},GameType:{3}", new object[]
                        {
                            clientInfo.ServerId,
                            clientInfo.ClientId,
                            clientInfo.Token,
                            (GameTypes)clientInfo.GameType
                        }), null, true);
                    }
                    else
                    {
                        if (agent.IsAlive)
                        {
                            LogManager.WriteLog(LogTypes.Info, string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1},info:{2},GameType:{3}", new object[]
                            {
                                clientInfo.ServerId,
                                clientInfo.ClientId,
                                clientInfo.Token,
                                (GameTypes)clientInfo.GameType
                            }), null, true);
                            return(-11002);
                        }
                        bFistInit           = true;
                        clientInfo.ClientId = KuaFuServerManager.GetUniqueClientId();
                        agent.Reset(clientInfo);
                        LogManager.WriteLog(LogTypes.Info, string.Format("InitializeClient服务器IP变化.ServerId:{0},ClientId:{1},info:{2},GameType:{3}", new object[]
                        {
                            clientInfo.ServerId,
                            clientInfo.ClientId,
                            clientInfo.Token,
                            (GameTypes)clientInfo.GameType
                        }), null, true);
                    }
                }
                else if (clientInfo.ClientId != agent.ClientInfo.ClientId)
                {
                    if (clientInfo.ClientId <= 0)
                    {
                        clientInfo.ClientId = agent.ClientInfo.ClientId;
                        agent.Reset(clientInfo);
                        LogManager.WriteLog(LogTypes.Info, string.Format("InitializeClient服务器重连.ServerId:{0},ClientId:{1},info:{2},GameType:{3} [首次连接过来]", new object[]
                        {
                            clientInfo.ServerId,
                            clientInfo.ClientId,
                            clientInfo.Token,
                            (GameTypes)clientInfo.GameType
                        }), null, true);
                    }
                    else
                    {
                        LogManager.WriteLog(LogTypes.Info, string.Format("InitializeClient服务器重连.ServerId:{0},ClientId:{1},info:{2},GameType:{3} [非首次连接过来]", new object[]
                        {
                            clientInfo.ServerId,
                            clientInfo.ClientId,
                            clientInfo.Token,
                            (GameTypes)clientInfo.GameType
                        }), null, true);
                    }
                }
                else if (!Global.TestMode && !agent.IsAlive)
                {
                    LogManager.WriteLog(LogTypes.Info, string.Format("InitializeClient服务器连接和上次心跳时间间隔过长.ServerId:{0},ClientId:{1},info:{2},GameType:{3},time={4}", new object[]
                    {
                        clientInfo.ServerId,
                        clientInfo.ClientId,
                        clientInfo.Token,
                        (GameTypes)clientInfo.GameType,
                        agent.DeltaTime
                    }), null, true);
                }
                if (agent != null)
                {
                    clientInfo.ClientId = agent.ClientInfo.ClientId;
                    agent.ClientHeartTick();
                    agent.TryInitGameType(clientInfo.GameType);
                }
                clientId = clientInfo.ClientId;
            }
            return(clientId);
        }
コード例 #13
0
ファイル: KFServiceBase.cs プロジェクト: qiuhoude/mu_server
 public static bool _M13(AutoCSer.Net.TcpInternalServer.ServerSocketSender _sender_, KuaFuClientContext clientInfo)
 {
     return(KFServiceBase.InitializeClient(_sender_, clientInfo));
 }
コード例 #14
0
 public HuanYingSiYuanAgent(KuaFuClientContext clientInfo, IKuaFuClient callback)
     : base(clientInfo, callback)
 {
 }
コード例 #15
0
ファイル: ClientAgent.cs プロジェクト: qiuhoude/mu_server
 public ClientAgent(KuaFuClientContext clientInfo)
 {
     this.ClientInfo = clientInfo;
     this.ClientHeartTick();
 }
コード例 #16
0
 public int InitializeClient(KuaFuClientContext clientInfo)
 {
     return(TSingleton <KuaFuWorldManager> .getInstance().InitializeClient(clientInfo));
 }
コード例 #17
0
ファイル: TcpCall.cs プロジェクト: songxiaopeng/mu_server
            public static ReturnValue <bool> InitializeClient(AutoCSer.Net.TcpInternalServer.ClientSocketSender _sender_, KuaFuClientContext clientInfo)
            {
                AutoWaitReturnValue <KfCall._p10> _wait_ = AutoWaitReturnValue <KfCall._p10> .Pop();

                try
                {
                    if (_sender_ != null)
                    {
                        KfCall._p20 _inputParameter_ = new KfCall._p20
                        {
                            p0 = clientInfo
                        };
                        KfCall._p10 _outputParameter_ = default(KfCall._p10);
                        ReturnType  _returnType_      = _sender_.WaitGet <KfCall._p20, KfCall._p10>(TcpCall.KFServiceBase._c13, ref _wait_, ref _inputParameter_, ref _outputParameter_);
                        return(new ReturnValue <bool>
                        {
                            Type = _returnType_,
                            Value = _outputParameter_.Return
                        });
                    }
                }
                finally
                {
                    if (_wait_ != null)
                    {
                        AutoWaitReturnValue <KfCall._p10> .PushNotNull(_wait_);
                    }
                }
                return(new ReturnValue <bool>
                {
                    Type = ReturnType.ClientException
                });
            }
コード例 #18
0
ファイル: ClientAgentManager.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 初始化GameServer代理
        /// 同一个GameServer的Service与ClientAgent是一个N:1的关系
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="clientInfo"></param>
        /// <returns></returns>
        public int InitializeClient(IKuaFuClient callback, KuaFuClientContext clientInfo)
        {
            bool bPlaceHolder = false;

            return(InitializeClient(callback, clientInfo, out bPlaceHolder));
        }
コード例 #19
0
 public KFClient(AutoCSer.Net.TcpStaticServer.Client client, AutoCSer.Net.TcpInternalServer.ServerAttribute attribute, KuaFuClientContext clientInfo, Action <KFCallManager.KFClient> onSetSocket)
 {
     this._Attribute  = attribute;
     this.OnSetSocket = onSetSocket;
     this.tcpClient   = client;
     this.tcpClient.OnSetSocket(delegate(ClientSocketBase socket)
     {
         if (socket.IsSocketVersion(ref this._Socket))
         {
             this.OnSetSocket(this);
         }
     });
 }