Ejemplo n.º 1
0
        private ErrorCode GStateReportHandler(NetSessionBase session, Protos.GSInfo GSInfoRecv)
        {
            session.logicID = GSInfoRecv.Id;
            bool hasRecord = CS.instance.lIDToGSInfos.TryGetValue(session.logicID, out GSInfo gsInfo);

            if (!hasRecord)
            {
                gsInfo = new GSInfo();
                CS.instance.lIDToGSInfos[session.logicID] = gsInfo;
            }
            //更新GS信息
            gsInfo.lid       = session.logicID;
            gsInfo.sessionID = session.id;
            gsInfo.name      = GSInfoRecv.Name;
            gsInfo.ip        = GSInfoRecv.Ip;
            gsInfo.port      = GSInfoRecv.Port;
            gsInfo.password  = GSInfoRecv.Password;
            gsInfo.state     = (GSInfo.State)GSInfoRecv.State;
            //Logger.Log( $"report from GS:{gsInfo}" );

            //转发到LS
            Protos.CS2LS_GSInfo nGSInfo = ProtoCreator.Q_CS2LS_GSInfo();
            nGSInfo.GsInfo = new Protos.GSInfo
            {
                Id       = gsInfo.lid,
                Name     = gsInfo.name,
                Ip       = gsInfo.ip,
                Port     = gsInfo.port,
                Password = gsInfo.password,
                State    = (Protos.GSInfo.Types.State)gsInfo.state
            };
            CS.instance.netSessionMgr.Send(SessionType.ServerLS, nGSInfo);
            return(ErrorCode.Success);
        }
Ejemplo n.º 2
0
        private static void OnGCLoginCSRet(NetSessionBase session, Google.Protobuf.IMessage message, object[] args)
        {
            Protos.LS2GC_AskLoginRet gcLoginRet = (Protos.LS2GC_AskLoginRet)args[0];
            uint  sid   = ( uint )args[1];
            ulong gcNID = ( ulong )args[2];

            Protos.CS2LS_GCLoginRet csLoginRet = (Protos.CS2LS_GCLoginRet)message;
            if (csLoginRet.Result == Protos.CS2LS_GCLoginRet.Types.EResult.Success)
            {
                gcLoginRet.Result    = Protos.LS2GC_AskLoginRet.Types.EResult.Success;
                gcLoginRet.SessionID = gcNID;
                foreach (KeyValuePair <uint, GSInfo> kv in LS.instance.gsInfos)
                {
                    GSInfo        info   = kv.Value;
                    Protos.GSInfo gsInfo = new Protos.GSInfo {
                        Name = info.name, Ip = info.ip, Port = info.port, Password = info.password, State = (Protos.GSInfo.Types.State)info.state
                    };
                    gcLoginRet.GsInfos.Add(gsInfo);
                }

                Logger.Log($"client:{gcNID} login success");

                //通知客户端登陆结果
                LS.instance.netSessionMgr.Send(sid, gcLoginRet);
                LS.instance.netSessionMgr.CloseSession(sid, "login complete");
            }
            else
            {
                Logger.Log($"client:{gcNID} login failed");

                gcLoginRet.Result = Protos.LS2GC_AskLoginRet.Types.EResult.Failed;
                //通知客户端登陆结果
                LS.instance.netSessionMgr.Send(sid, gcLoginRet);
                LS.instance.netSessionMgr.CloseSession(sid, "login failed");
            }
        }