Exemplo n.º 1
0
 public void OutWaitInfo(LoginWaitLogic.UserType userType, int index)
 {
     try
     {
         lock (this.m_Mutex)
         {
             if (index < 0 || index >= this.GetWaitingCount(userType))
             {
                 LogManager.WriteLog(LogTypes.Error, string.Format("OutWaitInfo Index Was Outside ", new object[0]), null, true);
             }
             else
             {
                 LoginWaitLogic.UserInfo userInfo = this.m_UserList[(int)userType][index];
                 LogManager.WriteLog(LogTypes.Error, string.Format("OutWaitInfo:userID={0} zoneID={1} startTick={2} updateTick={3} firstTick={4} overTick={5}", new object[]
                 {
                     userInfo.userID,
                     userInfo.zoneID,
                     userInfo.startTick,
                     userInfo.updateTick,
                     userInfo.firstTick,
                     userInfo.overTick
                 }), null, true);
             }
         }
     }
     catch (Exception ex)
     {
         DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::PopTopWaiting", new object[0]));
     }
 }
Exemplo n.º 2
0
        public bool NotifyUserEnter(LoginWaitLogic.UserInfo userInfo)
        {
            try
            {
                if (null == userInfo)
                {
                    return(true);
                }
                if (userInfo.socket == null || !userInfo.socket.Connected)
                {
                    return(true);
                }
                this.AddToAllow(userInfo.userID, this.GetConfig(LoginWaitLogic.UserType.Normal, LoginWaitLogic.ConfigType.AllowMSeconds));
                if (!userInfo.socket.IsKuaFuLogin)
                {
                    ChangeNameInfo info = SingletonTemplate <NameManager> .Instance().GetChangeNameInfo(userInfo.userID, userInfo.zoneID, userInfo.socket.ServerId);

                    if (info != null)
                    {
                        Global._TCPManager.MySocketListener.SendData(userInfo.socket, DataHelper.ObjectToTCPOutPacket <ChangeNameInfo>(info, Global._TCPManager.TcpOutPacketPool, 14002), true);
                    }
                }
            }
            catch (Exception ex)
            {
                DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyUserEnter userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID));
                return(false);
            }
            string strData = "";

            try
            {
                string strcmd    = string.Format("{0}:{1}", userInfo.userID, userInfo.zoneID);
                byte[] bytesData = Global.SendAndRecvData <string>(101, strcmd, userInfo.socket.ServerId, 0);
                int    length    = BitConverter.ToInt32(bytesData, 0);
                strData = new UTF8Encoding().GetString(bytesData, 6, length - 2);
            }
            catch (Exception ex)
            {
                DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyUserEnter 向db请求角色列表 faild! userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID));
                strData = "-1:";
            }
            try
            {
                TCPOutPacket tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(Global._TCPManager.TcpOutPacketPool, strData, 101);
                Global._TCPManager.MySocketListener.SendData(userInfo.socket, tcpOutPacket, true);
                this.m_LastEnterSecs          = (TimeUtil.NOW() - userInfo.startTick) / 1000L;
                this.m_LastEnterFromFirstSecs = (TimeUtil.NOW() - userInfo.firstTick) / 1000L;
            }
            catch (Exception ex)
            {
                DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyUserEnter 发送角色列表Faild userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID));
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
 public void NotifyWaitingInfo(LoginWaitLogic.UserInfo userInfo, int count, long seconds)
 {
     try
     {
         if (null != userInfo)
         {
             if (userInfo.socket != null && userInfo.socket.Connected)
             {
                 string       strcmd       = string.Format("{0}:{1}", count, seconds);
                 TCPOutPacket tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(Global._TCPManager.TcpOutPacketPool, strcmd, 971);
                 Global._TCPManager.MySocketListener.SendData(userInfo.socket, tcpOutPacket, true);
             }
         }
     }
     catch (Exception ex)
     {
         DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyWaitingInfo userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID));
     }
 }
Exemplo n.º 4
0
 public LoginWaitLogic.UserInfo TopWaiting(LoginWaitLogic.UserType userType)
 {
     LoginWaitLogic.UserInfo userInfo = null;
     try
     {
         lock (this.m_Mutex)
         {
             if (this.GetWaitingCount(userType) <= 0)
             {
                 return(null);
             }
             userInfo = this.m_UserList[(int)userType][0];
         }
     }
     catch (Exception ex)
     {
         DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::TopWaiting", new object[0]));
     }
     return(userInfo);
 }
Exemplo n.º 5
0
 public void ProcessWaitingList(LoginWaitLogic.UserType userType)
 {
     try
     {
         long currTick = TimeUtil.NOW();
         if (this.GetWaitingCount(userType) > 0)
         {
             int currClientCount = this.GetUserCount();
             lock (this.m_Mutex)
             {
                 int  i                = 0;
                 long lastOverTick     = 0L;
                 long firstWaitSeconds = 0L;
                 foreach (LoginWaitLogic.UserInfo userInfo in this.m_UserList[(int)userType])
                 {
                     i++;
                     if (1 == i && 0L == userInfo.firstTick)
                     {
                         userInfo.firstTick = TimeUtil.NOW();
                     }
                     long leftSeconds;
                     if (currClientCount + i <= this.GetConfig(userType, LoginWaitLogic.ConfigType.MaxServerNum))
                     {
                         if (0L == userInfo.overTick)
                         {
                             userInfo.overTick = ((0L == lastOverTick) ? currTick : lastOverTick) + (long)this.GetConfig(userType, LoginWaitLogic.ConfigType.WaitUpdateInt);
                         }
                         leftSeconds  = Global.GMax(1L, (userInfo.overTick - currTick) / 1000L);
                         leftSeconds  = Global.GMin(leftSeconds, (long)(this.GetConfig(userType, LoginWaitLogic.ConfigType.WaitUpdateInt) / 1000 * i));
                         lastOverTick = userInfo.overTick;
                     }
                     else if (1 == i)
                     {
                         leftSeconds      = Global.GMax(this.m_LastEnterFromFirstSecs, (TimeUtil.NOW() - userInfo.firstTick) / 1000L);
                         leftSeconds      = Global.GMax(1L, leftSeconds);
                         firstWaitSeconds = leftSeconds;
                     }
                     else
                     {
                         leftSeconds = (long)i * firstWaitSeconds;
                     }
                     if (currTick - userInfo.updateTick <= (long)this.m_UserUpdateInt)
                     {
                         lastOverTick = userInfo.overTick;
                     }
                     else
                     {
                         userInfo.updateTick = currTick;
                         this.NotifyWaitingInfo(userInfo, i, leftSeconds);
                     }
                 }
             }
             if (currClientCount < this.GetConfig(userType, LoginWaitLogic.ConfigType.NeedWaitNum))
             {
                 for (int i = 0; i < 5; i++)
                 {
                     LoginWaitLogic.UserInfo userInfo = this.PopTopWaiting(userType);
                     if (null != userInfo)
                     {
                         this.NotifyUserEnter(userInfo);
                     }
                 }
             }
             else if (currClientCount < this.GetConfig(userType, LoginWaitLogic.ConfigType.MaxServerNum))
             {
                 LoginWaitLogic.UserInfo userInfo = this.TopWaiting(userType);
                 if (null != userInfo)
                 {
                     if (userInfo.overTick > 0L)
                     {
                         if (currTick >= userInfo.overTick)
                         {
                             userInfo = this.PopTopWaiting(userType);
                             this.NotifyUserEnter(userInfo);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::Tick", new object[0]));
     }
 }