Exemple #1
0
        private ErrorCode MsgHandleInit(byte[] data, int offset, int size, int msgid)
        {
            SSToCS.AskRegiste aAskRegiste = new SSToCS.AskRegiste();
            aAskRegiste.MergeFrom(data, offset, size);

            uint     ssPos    = ( uint )aAskRegiste.Ssid - CS.instance.csKernelCfg.un32SSBaseIdx;
            CSSSInfo pcSSInfo = CS.instance.GetSSInfoBySSID(( uint )aAskRegiste.Ssid);

            if (null == pcSSInfo)
            {
                return(ErrorCode.InvalidSSID);
            }

            if (pcSSInfo.m_szUserPwd != aAskRegiste.Userpwd)
            {
                this.Close();
                return(ErrorCode.InvalidUserPwd);
            }

            // 加入SS
            pcSSInfo.m_eSSNetState     = ServerNetState.Connecting;
            pcSSInfo.m_n32NSID         = ( int )this.id;
            this.logicID               = pcSSInfo.m_n32SSID;
            pcSSInfo.m_tLastConnMilsec = TimeUtils.utcTime;
            pcSSInfo.m_sListenIP       = aAskRegiste.Ip;
            pcSSInfo.m_n32ListenPort   = aAskRegiste.Port;
            CS.instance.ssNetInfoList[ssPos].pcSSInfo = pcSSInfo;
            pcSSInfo.m_un32ConnTimes++;
            pcSSInfo.m_tLastConnMilsec = TimeUtils.utcTime;
            pcSSInfo.m_tLastPingMilSec = pcSSInfo.m_tLastConnMilsec;

            this.SetInited(true, true);

            return(ErrorCode.Success);
        }
Exemple #2
0
        protected override void OnRealEstablish()
        {
            CSSSInfo pcSSInfo = CS.instance.GetSSInfoByNSID(this.id);

            if (pcSSInfo != null)
            {
                Logger.Info($"SS({ pcSSInfo.m_n32SSID}) Connected");
            }
        }
Exemple #3
0
        protected override void OnClose()
        {
            CSSSInfo pcSSInfo = CS.instance.GetSSInfoByNSID(this.id);

            if (pcSSInfo != null)
            {
                Logger.Info($"SS({pcSSInfo.m_n32SSID}) DisConnected");
                int pos = pcSSInfo.m_n32SSID - ( int )CS.instance.csKernelCfg.un32SSBaseIdx;
                pcSSInfo.m_eSSNetState     = ServerNetState.Closed;
                pcSSInfo.m_n32NSID         = 0;
                pcSSInfo.m_tLastConnMilsec = 0;
                pcSSInfo.m_un32ConnTimes   = 0;
                CS.instance.ssNetInfoList[pos].tConnMilsec = 0;
                CS.instance.ssNetInfoList[pos].pcSSInfo    = null;
            }
        }
Exemple #4
0
        protected override void SendInitData()
        {
            long tCurMilSec = TimeUtils.utcTime;

            CSToSS.AskRegisteRet aAskRegisteRet = new CSToSS.AskRegisteRet();
            aAskRegisteRet.Ret      = ( int )ErrorCode.Success;
            aAskRegisteRet.Time     = tCurMilSec;
            aAskRegisteRet.Basegsid = ( int )CS.instance.csKernelCfg.un32GSBaseIdx;
            for (uint i = 0; i < CS.instance.csKernelCfg.un32MaxGSNum; i++)
            {
                CSToSS.AskRegisteRet.Types.GSInfo pGSInfo =
                    new CSToSS.AskRegisteRet.Types.GSInfo
                {
                    Gsid    = CS.instance.csKernelCfg.gsInfoList[i].m_n32GSID,
                    Userpwd = CS.instance.csKernelCfg.gsInfoList[i].m_szUserPwd
                };
                aAskRegisteRet.Gsinfo.Add(pGSInfo);
            }
            this.owner.SendMsgToSession(this.id, aAskRegisteRet, ( int )CSToSS.MsgId.EMsgToSsfromCsAskRegisteRet);

            //////////////////////////////////////////////////////////////////////////
            CSSSInfo pcSSInfo = CS.instance.GetSSInfoByNSID(this.id);

            CSToGS.OneSSConnected sOneSSConnected = new CSToGS.OneSSConnected
            {
                State    = ( int )ErrorCode.Success,
                Time     = tCurMilSec,
                Ssid     = pcSSInfo.m_n32SSID,
                Ip       = pcSSInfo.m_sListenIP,
                Port     = pcSSInfo.m_n32ListenPort,
                Netstate = ( int )pcSSInfo.m_eSSNetState,
                Basessid = ( int )CS.instance.csKernelCfg.un32SSBaseIdx
            };

            CS.instance.BroadCastMsgToGS(sOneSSConnected, ( int )CSToGS.MsgID.EMsgToGsfromCsOneSsconnected);
        }
        private ErrorCode OnMsgFromGSAskRegiste(CSGSInfo csgsInfo, byte[] data, int offset, int size)
        {
            GSToCS.AskRegiste sMsg = new GSToCS.AskRegiste();
            sMsg.MergeFrom(data, offset, size);

            // 找到位置号
            int      gsPos    = -1;
            CSGSInfo pcGSInfo = null;

            for (int i = 0; i < CS.instance.csKernelCfg.un32MaxGSNum; i++)
            {
                if (sMsg.Gsid != CS.instance.csKernelCfg.gsInfoList[i].m_n32GSID)
                {
                    continue;
                }
                pcGSInfo = CS.instance.csKernelCfg.gsInfoList[i];
                gsPos    = i;
                break;
            }

            ErrorCode n32Registe = ErrorCode.Success;

            if (null == pcGSInfo)
            {
                n32Registe = ErrorCode.InvalidGSID;
            }

            if (ErrorCode.Success == n32Registe)
            {
                if (pcGSInfo.m_szUserPwd != sMsg.Usepwd)
                {
                    n32Registe = ErrorCode.InvalidUserPwd;
                }
            }

            long tCurUTCMilsec = TimeUtils.utcTime;

            if (ErrorCode.Success == n32Registe)
            {
                pcGSInfo.m_eGSNetState     = ServerNetState.Free;
                pcGSInfo.m_n32NSID         = csgsInfo.m_n32NSID;
                pcGSInfo.m_tLastConnMilsec = tCurUTCMilsec;
                pcGSInfo.m_sListenIP       = sMsg.Ip;
                pcGSInfo.m_n32ListenPort   = sMsg.Port;
                CS.instance.gsNetInfoList[gsPos].pcGSInfo = pcGSInfo;

                pcGSInfo.m_n64MsgReceived++;
                pcGSInfo.m_n64DataReceived += sMsg.CalculateSize();
                pcGSInfo.m_un32ConnTimes++;
                pcGSInfo.m_tLastConnMilsec = tCurUTCMilsec;
                pcGSInfo.m_tLastPingMilSec = tCurUTCMilsec;
                Logger.Info($"Gate Server with GSID {pcGSInfo.m_n32GSID} registed at net session {gsPos}, total conn times {pcGSInfo.m_un32ConnTimes}");
            }

            CSToGS.AskRegisteRet sAskRegisteRet = new CSToGS.AskRegisteRet();
            sAskRegisteRet.Registe = ( int )n32Registe;
            sAskRegisteRet.Curtime = tCurUTCMilsec;
            if (ErrorCode.Success == n32Registe)
            {
                sAskRegisteRet.Ssbaseid = CS.instance.csKernelCfg.un32SSBaseIdx;
                for (int i = 0; i < CS.instance.csKernelCfg.un32MaxSSNum; i++)
                {
                    CSSSInfo csssInfo = CS.instance.csKernelCfg.ssInfoList[i];
                    CSToGS.AskRegisteRet.Types.SSInfo pSSInfo =
                        new CSToGS.AskRegisteRet.Types.SSInfo
                    {
                        Ssid     = csssInfo.m_n32SSID,
                        Ip       = csssInfo.m_sListenIP,
                        Port     = csssInfo.m_n32ListenPort,
                        Netstate = ( int )csssInfo.m_eSSNetState
                    };
                    sAskRegisteRet.Ssinfo.Add(pSSInfo);
                }
            }

            CS.instance.PostMsgToGS(csgsInfo, sAskRegisteRet, ( int )CSToGS.MsgID.EMsgToGsfromCsAskRegisteRet, 0);

            if (ErrorCode.Success != n32Registe)
            {
                CS.instance.netSessionMgr.DisconnectOne(csgsInfo.m_n32NSID);
            }

            return(ErrorCode.Success);
        }