public int CheckEnterWorldKuaFuSign(string worldRoleID, string token, out string signKey, out string[] ips, out int[] ports)
        {
            int result = -100;

            signKey = null;
            ips     = null;
            ports   = null;
            long utcTicks = TimeUtil.UTCTicks();

            lock (this.Mutex)
            {
                KuaFuServerLoginData data;
                if (this.WorldRoleIDDict.TryGetValue(worldRoleID, out data) && token == data.SignToken)
                {
                    if (utcTicks > data.EndTicks)
                    {
                        return(result);
                    }
                    result  = 0;
                    signKey = data.SignKey;
                }
                KuaFuServerInfo serverInfo = KuaFuServerManager.GetKuaFuServerInfo(data.ServerId);
                if (null != serverInfo)
                {
                    ips = new string[]
                    {
                        serverInfo.DbIp,
                        serverInfo.DbIp
                    };
                    ports = new int[]
                    {
                        serverInfo.DbPort,
                        serverInfo.LogDbPort
                    };
                }
            }
            return(result);
        }
Beispiel #2
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);
        }
        public int EnterPTKuaFuMap(int serverID, int roleId, int ptid, int mapCode, int kuaFuLine, out string signToken, out string signKey, out int kuaFuServerID, out string[] ips, out int[] ports)
        {
            ips           = null;
            ports         = null;
            signToken     = null;
            signKey       = null;
            kuaFuServerID = 0;
            string             worldRoleID = ConstData.FormatWorldRoleID(roleId, ptid);
            KuaFuWorldRoleData roleData    = this.LoadKuaFuWorldRoleData(roleId, ptid, worldRoleID);
            int result;

            if (null == roleData)
            {
                result = -4010;
            }
            else
            {
                kuaFuServerID = KuaFuServerManager.EnterKuaFuMapLine(kuaFuLine, mapCode);
                if (kuaFuServerID <= 0)
                {
                    result = -100;
                }
                else
                {
                    KuaFuServerInfo serverInfo = KuaFuServerManager.GetKuaFuServerInfo(kuaFuServerID);
                    if (null != serverInfo)
                    {
                        ips = new string[]
                        {
                            serverInfo.Ip
                        };
                        ports = new int[]
                        {
                            serverInfo.Port
                        };
                    }
                    signToken = Guid.NewGuid().ToString("N");
                    signKey   = Guid.NewGuid().ToString("N");
                    long utcTicks = TimeUtil.UTCTicks();
                    lock (this.Mutex)
                    {
                        KuaFuServerLoginData loginData;
                        if (!this.WorldRoleIDDict.TryGetValue(worldRoleID, out loginData))
                        {
                            loginData            = new KuaFuServerLoginData();
                            loginData.TempRoleID = roleData.TempRoleID;
                            this.WorldRoleIDDict[worldRoleID] = loginData;
                        }
                        loginData.SignKey        = signKey;
                        loginData.SignToken      = signToken;
                        loginData.EndTicks       = utcTicks + 86400000L;
                        loginData.TargetServerID = kuaFuServerID;
                        loginData.ServerId       = ConstData.ConvertToKuaFuServerID(serverID, ptid);
                        loginData.RoleId         = roleId;
                        loginData.PTID           = ptid;
                        loginData.GameId         = (long)mapCode;
                        result = loginData.TempRoleID;
                    }
                }
            }
            return(result);
        }