public ErrorCode OnGC2GSAskLogin(NetSessionBase session, Google.Protobuf.IMessage message) { Protos.GC2GS_AskLogin login = (Protos.GC2GS_AskLogin)message; Protos.GS2CS_GCAskLogin gcAskLogin = ProtoCreator.Q_GS2CS_GCAskLogin(); gcAskLogin.SessionID = login.SessionID; Logger.Log($"client:{gcAskLogin.SessionID} ask login"); //向CS请求客户端登陆 GS.instance.netSessionMgr.Send(SessionType.ServerG2CS, gcAskLogin, RPCEntry.Pop(OnCS2GSAskLoginRet, session.id, login)); return(ErrorCode.Success); }
/// <summary> /// GS请求CS,验证GC登陆的合法性 /// </summary> public ErrorCode OnGs2CsGcaskLogin(NetSessionBase session, IMessage message) { Protos.GS2CS_GCAskLogin request = (Protos.GS2CS_GCAskLogin)message; Protos.CS2GS_GCLoginRet response = ProtoCreator.R_GS2CS_GCAskLogin(request.Opts.Pid); //创建玩家并上线 CSUser user = CS.instance.userMgr.Online(request.SessionID, session.id, session.logicID); if (user == null) { //非法登陆 response.Result = Protos.CS2GS_GCLoginRet.Types.EResult.IllegalLogin; } else { response.UserInfo = new Protos.G_UserInfo { Ukey = user.ukey, GcNID = user.gcNID, OpenID = user.openID, Nickname = user.nickname, Avatar = user.avatar, Gender = user.gender, Rank = user.rank, Money = user.money, Diamoned = user.diamoned, Exp = user.exp, }; response.UserInfo.Champions.AddRange(user.champions); //检查玩家是否在战场 if (user.isInBattle) { //检查是否存在BS信息(可能当玩家上线时,BS已丢失) //这里理应不会成功断言,因为BS丢失时会把玩家从战场暂存器里移除 INetSession bsSession = CS.instance.netSessionMgr.GetSession(user.bsSID); System.Diagnostics.Debug.Assert(bsSession != null, $"can not find BS:{user.bsSID}"); CS.instance.lIDToBSInfos.TryGetValue((( BattleSession )bsSession).logicID, out BSInfo bsInfo); System.Diagnostics.Debug.Assert(bsInfo != null, $"can not find BS:{( ( BattleSession )bsSession ).logicID}"); response.GcState = Protos.CS2GS_GCLoginRet.Types.EGCCState.Battle; response.GcNID = user.ukey | ( ulong )bsInfo.lid << 32; response.BsIP = bsInfo.ip; response.BsPort = bsInfo.port; } response.Result = Protos.CS2GS_GCLoginRet.Types.EResult.Success; } session.Send(response); return(ErrorCode.Success); }