Beispiel #1
0
        public ErrorCode OnGc2BsAskLogin(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            Protos.GC2BS_AskLogin login    = (Protos.GC2BS_AskLogin)message;
            Protos.BS2GC_LoginRet loginRet = ProtoCreator.R_GC2BS_AskLogin(login.Opts.Pid);

            //验证并登陆
            BSUser user = BS.instance.userMgr.Online(login.SessionID, session.id);

            if (user != null)
            {
                ClientSession gcSession = ( ClientSession )session;
                //设置该Session为受信任的连接
                gcSession.accredited = true;
                //把战场的初始状态下发到GC
                loginRet.PlayerID     = user.gcNID;
                loginRet.RndSeed      = user.battle.rndSeed;
                loginRet.FrameRate    = user.battle.frameRate;
                loginRet.KeyframeStep = user.battle.keyframeStep;
                loginRet.SnapshotStep = user.battle.snapshotStep;
                loginRet.BattleTime   = user.battle.battleTime;
                loginRet.MapID        = user.battle.mapID;
                loginRet.CurFrame     = user.battle.frame;
                int c1 = user.battle.battleEntry.users.Length;
                for (int i = 0; i < c1; i++)
                {
                    var team     = user.battle.battleEntry.users[i];
                    int c2       = team.Length;
                    var teamInfo = new Protos.CS2BS_TeamInfo();
                    loginRet.TeamInfos.Add(teamInfo);
                    for (int j = 0; j < c2; j++)
                    {
                        BSUser player = team[j];
                        Protos.CS2BS_PlayerInfo playerInfo = new Protos.CS2BS_PlayerInfo
                        {
                            GcNID    = player.gcNID,
                            ActorID  = player.actorID,
                            Nickname = player.nickname,
                            Avatar   = player.avatar,
                            Gender   = player.gender,
                            Rank     = player.rank,
                            Exp      = player.exp
                        };
                        teamInfo.PlayerInfos.Add(playerInfo);
                    }
                }

                loginRet.Result = Protos.Global.Types.ECommon.Success;
                session.Send(loginRet);
            }
            else
            {
                loginRet.Result = Protos.Global.Types.ECommon.Failed;
                session.Send(loginRet);
                session.Close(true, "client login failed");
            }
            return(ErrorCode.Success);
        }
Beispiel #2
0
        public ErrorCode OnGc2LsAskSmartLogin(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            uint   sid    = session.id;
            string remote = session.connection.remoteEndPoint.ToString();

            Protos.GC2LS_AskSmartLogin login      = (Protos.GC2LS_AskSmartLogin)message;
            Protos.LS2GC_AskLoginRet   gcLoginRet = ProtoCreator.R_GC2LS_AskLogin(login.Opts.Pid);

            Logger.Log($"GC {login.Id}, {session.connection.remoteEndPoint} ask login");

            //检测用户名的合法性
            if (!CheckUsername(login.Id))
            {
                gcLoginRet.Result = Protos.LS2GC_AskLoginRet.Types.EResult.InvalidUname;
                session.Send(gcLoginRet);
                session.Close(true, "login failed");
                return(ErrorCode.Success);
            }

            LoginContext context = new LoginContext();

            context.id       = login.Id;
            context.channel  = login.Channel;
            context.browser  = login.Browser;
            context.platform = login.Platform;

            //查询数据库
            //若查询失败则自动注册
            Protos.LS2DB_QueryLogin queryLogin = ProtoCreator.Q_LS2DB_QueryLogin();
            queryLogin.Name     = login.Id;
            queryLogin.Nickname = login.Id;
            queryLogin.VertPwd  = false;
            queryLogin.Time     = TimeUtils.utcTime;
            queryLogin.Ip       = remote;
            queryLogin.Channel  = login.Channel;
            queryLogin.Browser  = login.Browser;
            queryLogin.Platform = login.Platform;
            queryLogin.Money    = LS.instance.config.initMoney;
            queryLogin.Diamoned = LS.instance.config.initDiamoned;
            queryLogin.Rank     = LS.instance.config.initRank;
            LS.instance.netSessionMgr.Send(SessionType.ServerL2DB, queryLogin,
                                           RPCEntry.Pop(OnSmartQueryLoginRet, gcLoginRet, sid, context));
            return(ErrorCode.Success);
        }
Beispiel #3
0
        public ErrorCode OnGc2LsAskWxlogin(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            uint   sid    = session.id;
            string remote = session.connection.remoteEndPoint.ToString();

            Protos.GC2LS_AskWXLogin  login      = (Protos.GC2LS_AskWXLogin)message;
            Protos.LS2GC_AskLoginRet gcLoginRet = ProtoCreator.R_GC2LS_AskLogin(login.Opts.Pid);
            string    reqUrl = string.Format(LS.instance.config.code2sessionUrl, LS.instance.config.wxAppID, LS.instance.config.wxAppSecret, login.Code);
            WebClient client = new WebClient();

            client.DownloadStringTaskAsync(reqUrl).ContinueWith((t, o) =>
            {
                Hashtable json = ( Hashtable )MiniJSON.JsonDecode(t.Result);
                int errorCode  = json.GetInt("errcode");
                if (errorCode != 0)
                {
                    //错误码,参考 https://developers.weixin.qq.com/minigame/dev/api/code2Session.html
                    switch (errorCode)
                    {
                    case -1:
                        gcLoginRet.Result = Protos.LS2GC_AskLoginRet.Types.EResult.Busy;
                        break;

                    case 40029:
                        gcLoginRet.Result = Protos.LS2GC_AskLoginRet.Types.EResult.InvalidCode;
                        break;

                    case 45011:
                        gcLoginRet.Result = Protos.LS2GC_AskLoginRet.Types.EResult.Frequent;
                        break;
                    }
                    session.Send(gcLoginRet);
                    session.Close(true, $"login fail:{errorCode}");
                }
                else
                {
                    string openID     = json.GetString("openid");
                    string sessionKey = json.GetString("session_key");
                    string unionID    = json.GetString("unionid");

                    Logger.Log($"wxLogin success, id:{openID}, sessionKey:{sessionKey}, unionID:{unionID}");

                    LoginContext context = new LoginContext();
                    context.id           = openID;
                    context.channel      = Protos.Global.Types.Channel.Wxmini;
                    context.browser      = login.Browser;
                    context.platform     = login.Platform;
                    context.sessionKey   = sessionKey;
                    context.unionID      = unionID;
                    context.nickname     = login.Nickname;
                    context.avatar       = login.Avatar;
                    context.gender       = ( byte )login.Gender;

                    //查询数据库
                    //若查询失败则自动注册
                    Protos.LS2DB_QueryLogin queryLogin = ProtoCreator.Q_LS2DB_QueryLogin();
                    queryLogin.Name     = openID;
                    queryLogin.VertPwd  = false;
                    queryLogin.Time     = TimeUtils.utcTime;
                    queryLogin.Ip       = remote;
                    queryLogin.Channel  = Protos.Global.Types.Channel.Wxmini;
                    queryLogin.Browser  = login.Browser;
                    queryLogin.Platform = login.Platform;
                    queryLogin.UnionID  = unionID;
                    queryLogin.Nickname = login.Nickname;
                    queryLogin.Avatar   = login.Avatar;
                    queryLogin.Gender   = login.Gender;
                    queryLogin.Money    = LS.instance.config.initMoney;
                    queryLogin.Diamoned = LS.instance.config.initDiamoned;
                    queryLogin.Rank     = LS.instance.config.initRank;
                    LS.instance.netSessionMgr.Send(SessionType.ServerL2DB, queryLogin,
                                                   RPCEntry.Pop(OnSmartQueryLoginRet, gcLoginRet, sid, context));
                }
            }, null, CancellationToken.None);
            return(ErrorCode.Success);
        }