Exemplo n.º 1
0
        /// <summary>
        /// 玩家请求加入房间
        /// </summary>
        public ErrorCode OnGc2CsJoinRoom(NetSessionBase session, IMessage message)
        {
            Protos.GC2CS_JoinRoom    request  = (Protos.GC2CS_JoinRoom)message;
            Protos.CS2GC_JoinRoomRet response = ProtoCreator.R_GC2CS_JoinRoom(request.Opts.Pid);

            ulong  gcNID = request.Opts.Transid;
            CSUser user  = CS.instance.userMgr.GetUser(gcNID);

            if (user == null)
            {
                response.Result = Protos.Global.Types.ECommon.Failed;
            }
            else
            {
                CS.instance.roomMgr.Join(user, request.RoomID, () =>
                {
                    response.Result = Protos.Global.Types.ECommon.Success;
                    user.Send(response);
                }, () =>
                {
                    response.Result = Protos.Global.Types.ECommon.Failed;
                    user.Send(response);
                });
            }

            return(ErrorCode.Success);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 销毁战场
        /// 主线程调用
        /// </summary>
        private void EndBattle(Battle battle)
        {
            battle.Stop();
            int count = battle.numChampions;

            //通知CS战场结束
            Protos.BS2CS_BattleEnd battleEnd = ProtoCreator.Q_BS2CS_BattleEnd();
            battleEnd.Bid = battle.id;
            for (int i = 0; i < count; ++i)
            {
                Champion champion = battle.GetChampionAt(i);
                var      info     = new Protos.BS2CS_BattleEndInfo
                {
                    Result       = (Protos.BS2CS_BattleEndInfo.Types.Result)champion.result,
                    Team         = champion.team,
                    Damage       = champion.damage,
                    Hurt         = champion.hurt,
                    Heal         = champion.heal,
                    OccupyTime   = champion.occupyTime,
                    Skill0Used   = champion.skill0Used,
                    Skill0Damage = champion.skill0Damage,
                    Skill1Used   = champion.skill1Used,
                    Skill1Damage = champion.skill1Damage,
                };
                battleEnd.Infos.Add(champion.user.gcNID, info);
            }
            BS.instance.netSessionMgr.Send(SessionType.ServerB2CS, battleEnd, RPCEntry.Pop(this.OnCSBattleEndRet, battle));
        }
Exemplo n.º 3
0
        public ErrorCode OnCs2DbQueryRanking(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            Protos.CS2DB_QueryRanking request = (Protos.CS2DB_QueryRanking)message;
            int @from = request.From;
            int count = request.Count;

            Protos.DB2CS_QueryRankingRet resp = ProtoCreator.R_CS2DB_QueryRanking(request.Opts.Pid);
            string    str       = $"SELECT id,uname,nickname,avatar,gender,last_login_time,ranking,exp FROM account_user ORDER BY ranking DESC LIMIT {@from}, {count}";
            ErrorCode errorCode = DB.instance.accountDB.SqlExecQuery(str, dataReader =>
            {
                while (dataReader.Read())
                {
                    Protos.DB2CS_RankingInfo rankingInfo = new Protos.DB2CS_RankingInfo();
                    rankingInfo.Ukey          = dataReader.GetUInt32("id");
                    rankingInfo.Name          = dataReader.GetString("nickname");
                    rankingInfo.Avatar        = dataReader.GetString("avatar");
                    rankingInfo.Gender        = dataReader.GetByte("gender");
                    rankingInfo.LastLoginTime = dataReader.GetInt64("last_login_time");
                    rankingInfo.Rank          = dataReader.GetInt32("ranking");
                    rankingInfo.Exp           = dataReader.GetInt32("exp");
                    resp.RankingInfos.Add(rankingInfo);
                }
                return(ErrorCode.Success);
            });

            session.Send(resp);
            return(ErrorCode.Success);
        }
Exemplo n.º 4
0
        private static void HandleLoginSuccess(Protos.LS2GC_AskLoginRet gcLoginRet, uint sid, LoginContext context)
        {
            ulong gcNID = GuidHash.GetUInt64();

            //通知cs,客户端登陆成功
            Protos.LS2CS_GCLogin csLogin = ProtoCreator.Q_LS2CS_GCLogin();
            csLogin.GcNID      = gcNID;
            csLogin.Id         = context.id;
            csLogin.Ukey       = context.ukey;
            csLogin.Channel    = context.channel;
            csLogin.Browser    = context.browser;
            csLogin.Platform   = context.platform;
            csLogin.SessionKey = context.sessionKey;
            csLogin.UnionID    = context.unionID;
            csLogin.Nickname   = context.nickname;
            csLogin.Avatar     = context.avatar;
            csLogin.Gender     = context.gender;
            csLogin.Money      = context.money;
            csLogin.Diamoned   = context.diamoned;
            csLogin.Rank       = context.rank;
            csLogin.Exp        = context.exp;
            csLogin.Champions  = context.champions;
            csLogin.ActorID    = context.actorID;
            LS.instance.netSessionMgr.Send(SessionType.ServerL2CS, csLogin,
                                           RPCEntry.Pop(OnGCLoginCSRet, gcLoginRet, sid, gcNID));
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 玩家请求创建房间
        /// </summary>
        public ErrorCode OnGc2CsCreateRoom(NetSessionBase session, IMessage message)
        {
            Protos.GC2CS_CreateRoom    request  = (Protos.GC2CS_CreateRoom)message;
            Protos.CS2GC_CreateRoomRet response = ProtoCreator.R_GC2CS_CreateRoom(request.Opts.Pid);

            ulong  gcNID = request.Opts.Transid;
            CSUser user  = CS.instance.userMgr.GetUser(gcNID);

            if (user == null)
            {
                response.Result = Protos.Global.Types.ECommon.Failed;
            }
            else
            {
                if (user.isInBattle)
                {
                    response.Result = Protos.Global.Types.ECommon.Failed;
                }
                else
                {
                    response.Result = CS.instance.roomMgr.Create(user, request.NumTeam, request.NumPlayerPerTeam, out uint roomID) ?
                                      Protos.Global.Types.ECommon.Success :
                                      Protos.Global.Types.ECommon.Failed;
                    response.RoomID = roomID;
                }
            }
            user.Send(response);
            return(ErrorCode.Success);
        }
Exemplo n.º 7
0
 public ErrorCode OnBSAskPing(NetSessionBase session, Google.Protobuf.IMessage message)
 {
     Protos.G_AskPing    askPing    = (Protos.G_AskPing)message;
     Protos.G_AskPingRet askPingRet = ProtoCreator.R_G_AskPing(askPing.Opts.Pid);
     askPingRet.Stime = askPing.Time;
     askPingRet.Time  = TimeUtils.utcTime;
     session.Send(askPingRet);
     return(ErrorCode.Success);
 }
Exemplo n.º 8
0
        /// <summary>
        /// 客户端请求购买英雄
        /// </summary>
        public ErrorCode OnGc2CsBuyChampion(NetSessionBase session, IMessage message)
        {
            Protos.GC2CS_BuyChampion    request  = (Protos.GC2CS_BuyChampion)message;
            Protos.CS2GC_BuyChampionRet response = ProtoCreator.R_GC2CS_BuyChampion(request.Opts.Pid);
            int    id    = request.Cid;
            ulong  gcNID = request.Opts.Transid;
            CSUser user  = CS.instance.userMgr.GetUser(gcNID);

            if (user == null)
            {
                return(ErrorCode.Success);
            }

            if (user.champions.Contains(id))                //已存在该英雄
            {
                response.Result = Protos.CS2GC_BuyChampionRet.Types.Result.Failed;
                user.Send(response);
                return(ErrorCode.Success);
            }
            Hashtable defs        = GoodsDefs.GetChampion(id);
            int       priceNeeded = ( int )(defs.GetInt("price") * (1 + defs.GetFloat("p_discount")));

            if (user.money < priceNeeded)              //没有足够金钱
            {
                response.Result = Protos.CS2GC_BuyChampionRet.Types.Result.NotEnoughMoney;
                user.Send(response);
                return(ErrorCode.Success);
            }
            int diamonedNeeded = ( int )(defs.GetInt("diamoned") * (1 + defs.GetFloat("d_discount")));

            if (user.diamoned < diamonedNeeded)
            {
                response.Result = Protos.CS2GC_BuyChampionRet.Types.Result.NotEnoughDiamoned;
                user.Send(response);
                return(ErrorCode.Success);
            }
            int expNeeded = defs.GetInt("exp");

            if (user.exp < expNeeded)
            {
                response.Result = Protos.CS2GC_BuyChampionRet.Types.Result.NotEnoughExp;
                user.Send(response);
                return(ErrorCode.Success);
            }

            int moneyResult    = user.money - priceNeeded;
            int diamonedResult = user.diamoned - diamonedNeeded;

            Protos.CS2DB_BuyChampion request2 = ProtoCreator.Q_CS2DB_BuyChampion();
            request2.Ukey     = user.ukey;
            request2.Money    = moneyResult;
            request2.Diamoned = diamonedResult;
            request2.Cids.Add(request.Cid);
            CS.instance.netSessionMgr.Send(SessionType.ServerC2DB, request2, RPCEntry.Pop(OnBuyChampion, user, moneyResult, diamonedResult, request.Cid, response));

            return(ErrorCode.Success);
        }
Exemplo n.º 9
0
 public ErrorCode OnGSAskPing(NetSessionBase session, IMessage message)
 {
     Protos.G_AskPing    request  = (Protos.G_AskPing)message;
     Protos.G_AskPingRet response = ProtoCreator.R_G_AskPing(request.Opts.Pid);
     response.Stime = request.Time;
     response.Time  = TimeUtils.utcTime;
     session.Send(response);
     return(ErrorCode.Success);
 }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 internal void KickUser(CSUser user, Protos.CS2GS_KickGC.Types.EReason reason)
 {
     //通知gs玩家被踢下线
     Protos.CS2GS_KickGC kickGc = ProtoCreator.Q_CS2GS_KickGC();
     kickGc.GcNID  = user.gcNID;
     kickGc.Reason = reason;
     CS.instance.netSessionMgr.Send(user.gsSID, kickGc);
     this.Offline(user);
 }
Exemplo n.º 12
0
        public ErrorCode OnLs2DbExec(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            Protos.LS2DB_Exec    exec      = (Protos.LS2DB_Exec)message;
            Protos.DB2LS_ExecRet execRet   = ProtoCreator.R_LS2DB_Exec(exec.Opts.Pid);
            ErrorCode            errorCode = DB.instance.accountDB.SqlExecNonQuery(exec.Cmd, out int row, out uint id);

            execRet.Row    = row;
            execRet.Id     = id;
            execRet.Result = errorCode == ErrorCode.Success ? Protos.Global.Types.ECommon.Success : Protos.Global.Types.ECommon.Failed;
            session.Send(execRet);
            return(ErrorCode.Success);
        }
Exemplo n.º 13
0
        /// <summary>
        /// BS通知战场结束
        /// </summary>
        public ErrorCode OnBs2CsBattleEnd(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            Protos.BS2CS_BattleEnd battleEnd = (Protos.BS2CS_BattleEnd)message;
            //评分
            Dictionary <int, int> ratings = this.ComputeElorating(battleEnd.Infos);

            //数据库
            Protos.CS2DB_UpdateRank dbRequest = ProtoCreator.Q_CS2DB_UpdateRank();
            //通知客户端战场结束
            Protos.CS2GC_BattleEnd gcBattleEnd = ProtoCreator.Q_CS2GC_BattleEnd();
            foreach (var kv in battleEnd.Infos)
            {
                CSUser user = CS.instance.battleStaging.GetUser(kv.Key);

                Protos.BS2CS_BattleEndInfo info = kv.Value;
                gcBattleEnd.Result    = (Protos.CS2GC_BattleEnd.Types.Result)info.Result;
                gcBattleEnd.GMoney    = info.Result == Protos.BS2CS_BattleEndInfo.Types.Result.Win ? ( int )(0.01f * user.rank) : 0;
                gcBattleEnd.GDiamoned = 0;
                gcBattleEnd.GRank     = ratings[info.Team];
                gcBattleEnd.GExp      = info.Result == Protos.BS2CS_BattleEndInfo.Types.Result.Win ? 10u : 0u;

                user.money    += gcBattleEnd.GMoney;
                user.diamoned += gcBattleEnd.GDiamoned;
                user.rank     += gcBattleEnd.GRank;
                user.exp      += gcBattleEnd.GExp;

                gcBattleEnd.Money    = user.rank;
                gcBattleEnd.Diamoned = user.diamoned;
                gcBattleEnd.Rank     = user.rank;
                gcBattleEnd.Exp      = user.exp;

                CS.instance.netSessionMgr.Send(user.gsSID, gcBattleEnd, null, Protos.MsgOpts.Types.TransTarget.Gc, user.gcNID);

                //数据库
                Protos.CS2DB_Gain gain = new Protos.CS2DB_Gain();
                gain.Ukey     = user.ukey;
                gain.Money    = user.money;
                gain.Diamoned = user.diamoned;
                gain.Rank     = user.rank;
                gain.Exp      = user.exp;
                dbRequest.Gains.Add(gain);
            }
            //数据库
            CS.instance.netSessionMgr.Send(SessionType.ServerC2DB, dbRequest);
            //移除指定BS里指定战场里的所有玩家
            CS.instance.battleStaging.Remove(session.logicID, battleEnd.Bid);

            //回应
            Protos.CS2BS_BattleEndRet battleEndRet = ProtoCreator.R_BS2CS_BattleEnd(battleEnd.Opts.Pid);
            session.Send(battleEndRet);

            return(ErrorCode.Success);
        }
Exemplo n.º 14
0
        /// <summary>
        /// LS通知CS有客户端登录成功
        /// </summary>
        public ErrorCode OnLs2CsGclogin(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            Protos.LS2CS_GCLogin gcLogin = (Protos.LS2CS_GCLogin)message;
            CSUser user = CS.instance.userMgr.CreateUser(gcLogin);

            Protos.CS2LS_GCLoginRet gcLoginRet = ProtoCreator.R_LS2CS_GCLogin(gcLogin.Opts.Pid);
            gcLoginRet.Result = user != null
                                                                        ? Protos.CS2LS_GCLoginRet.Types.EResult.Success
                                                                        : Protos.CS2LS_GCLoginRet.Types.EResult.Failed;
            session.Send(gcLoginRet);
            return(ErrorCode.Success);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        public ErrorCode OnGc2BsRequestFrameActions(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            BSUser user = BS.instance.userMgr.GetUser(session.id);

            if (user != null)
            {
                Protos.GC2BS_RequestFrameActions    request = (Protos.GC2BS_RequestFrameActions)message;
                Protos.BS2GC_RequestFrameActionsRet ret     = ProtoCreator.R_GC2BS_RequestFrameActions(request.Opts.Pid);
                BS.instance.battleMgr.HandleRequestFrameActions(user.battle, request.From, request.To, ret);
                BS.instance.netSessionMgr.Send(user.gcSID, ret);
            }
            return(ErrorCode.Success);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 客户端请求查询英雄
        /// </summary>
        public ErrorCode OnGc2CsQueryChampions(NetSessionBase session, IMessage message)
        {
            Protos.GC2CS_QueryChampions request = (Protos.GC2CS_QueryChampions)message;
            ulong  gcNID = request.Opts.Transid;
            CSUser user  = CS.instance.userMgr.GetUser(gcNID);

            if (user != null)
            {
                Protos.CS2GC_QueryChampionsRet response = ProtoCreator.R_GC2CS_QueryChampions(request.Opts.Pid);
                response.Cids.AddRange(user.champions);
                user.Send(response);
            }
            return(ErrorCode.Success);
        }
Exemplo n.º 18
0
        public void ReportStateToCS(NetSessionBase session)
        {
            Protos.BS2CS_ReportState reportState = ProtoCreator.Q_BS2CS_ReportState();
            BSConfig config = BS.instance.config;

            reportState.BsInfo = new Protos.BSInfo
            {
                Id    = config.id,
                Ip    = config.externalIP,
                Port  = config.externalPort,
                State = (Protos.BSInfo.Types.State)BS.instance.state
            };
            session.Send(reportState);
        }
Exemplo n.º 19
0
        /// <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);
        }
Exemplo n.º 20
0
 public void OnCSSessionClosed(NetSessionBase session)
 {
     uint[] gcSIDs = GS.instance.userMgr.GetClients();
     //广播到客户端CS丢失
     Protos.GS2GC_CSLost csLost = ProtoCreator.Q_GS2GC_CSLost();
     GS.instance.netSessionMgr.Broadcast(gcSIDs, csLost);
     //断开所有客户端
     foreach (uint gcSID in gcSIDs)
     {
         GS.instance.netSessionMgr.CloseSession(gcSID, "CS Closed");
     }
     //清空客户端信息
     GS.instance.userMgr.ClearClients();
 }
Exemplo n.º 21
0
        public void BeginBattle(BattleUser[] users, BattleUser[][] tUsers)
        {
            BSInfo appropriateBSInfo = CS.instance.appropriateBSInfo;

            //没有找到合适的bs,通知客户端匹配失败
            if (appropriateBSInfo == null)
            {
                this.NotifyGCEnterBattleFailed(users, Protos.CS2GC_EnterBattle.Types.Result.BsnotFound);
                return;
            }

            //todo 现在先随机一张地图
            Random rnd      = new Random();
            int    mapCount = Defs.GetMapCount();
            int    mapID    = rnd.Next(0, mapCount);

            Protos.CS2BS_BattleInfo battleInfo = ProtoCreator.Q_CS2BS_BattleInfo();
            battleInfo.MapID       = mapID;
            battleInfo.ConnTimeout = ( int )Consts.WAITING_ROOM_TIME_OUT;
            int c1 = tUsers.Length;

            for (int i = 0; i < c1; i++)
            {
                Protos.CS2BS_TeamInfo ti = new Protos.CS2BS_TeamInfo();
                battleInfo.TeamInfos.Add(ti);
                BattleUser[] roomUsers = tUsers[i];
                int          c2        = roomUsers.Length;
                for (int j = 0; j < c2; j++)
                {
                    BattleUser roomUser        = roomUsers[j];
                    CSUser     user            = CS.instance.userMgr.GetUser(roomUser.id);
                    Protos.CS2BS_PlayerInfo pi = new Protos.CS2BS_PlayerInfo
                    {
                        GcNID        = user.ukey | ( ulong )appropriateBSInfo.lid << 32,
                            ActorID  = user.actorID,
                            Avatar   = user.avatar,
                            Nickname = user.nickname,
                            Gender   = user.gender,
                            Money    = user.money,
                            Diamoned = user.diamoned,
                            Rank     = user.rank,
                            Exp      = user.exp
                    };
                    ti.PlayerInfos.Add(pi);
                }
            }
            CS.instance.netSessionMgr.Send(appropriateBSInfo.sessionID, battleInfo, RPCEntry.Pop(this.OnBattleInfoRet, users, tUsers,
                                                                                                 appropriateBSInfo.ip, appropriateBSInfo.port,
                                                                                                 appropriateBSInfo.sessionID, appropriateBSInfo.lid));
        }
Exemplo n.º 22
0
        public void ReportStateToCS(NetSessionBase session)
        {
            Protos.GS2CS_ReportState reportState = ProtoCreator.Q_GS2CS_ReportState();
            GSConfig config = GS.instance.config;

            reportState.GsInfo = new Protos.GSInfo
            {
                Id       = config.gsID,
                Name     = config.name,
                Ip       = config.externalIP,
                Port     = config.externalPort,
                Password = config.password,
                State    = (Protos.GSInfo.Types.State)GS.instance.state
            };
            session.Send(reportState);
        }
Exemplo n.º 23
0
        public void OnGSSessionClosed(NetSessionBase session)
        {
            //更新GS列表
            CS.instance.lIDToGSInfos.Remove(session.logicID);
            CS.instance.UpdateAppropriateGSInfo();

            //踢出所有连接到该GS的玩家
            CS.instance.userMgr.OnGSDisconnect(session.logicID);

            //通知LS有GS断开连接了
            Protos.CS2LS_GSLost message = ProtoCreator.Q_CS2LS_GSLost();
            message.Gsid = session.logicID;
            CS.instance.netSessionMgr.Send(SessionType.ServerLS, message);

            session.logicID = 0;
        }
Exemplo n.º 24
0
        /// <summary>
        /// 处理cs通知开始战斗
        /// </summary>
        public ErrorCode OnCs2BsBattleInfo(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            Protos.CS2BS_BattleInfo battleInfo = (Protos.CS2BS_BattleInfo)message;

            BS.instance.battleMgr.CreateBattle(battleInfo, (bid, success) =>
            {
                Protos.BS2CS_BattleInfoRet battleInfoRet = ProtoCreator.R_CS2BS_BattleInfo(battleInfo.Opts.Pid);
                battleInfoRet.Bid    = bid;
                battleInfoRet.Result = success
                                                                                   ? Protos.Global.Types.ECommon.Success
                                                                                   : Protos.Global.Types.ECommon.Failed;
                session.Send(battleInfoRet);
            });

            return(ErrorCode.Success);
        }
Exemplo n.º 25
0
        public ErrorCode OnECs2GsKickGc(NetSessionBase session, IMessage message)
        {
            Protos.CS2GS_KickGC kickGC = (Protos.CS2GS_KickGC)message;

            //可能在收到消息前,客户端就断开了,这里必须容错
            if (GS.instance.userMgr.GetSID(kickGC.GcNID, out uint sid_))
            {
                //通知客户端被踢下线
                Protos.GS2GC_Kick kick = ProtoCreator.Q_GS2GC_Kick();
                kick.Reason = kickGC.Reason;
                GS.instance.netSessionMgr.Send(sid_, kick);

                //强制断开客户端
                GS.instance.netSessionMgr.CloseSession(sid_, "CS Kick");
            }
            return(ErrorCode.Success);
        }
Exemplo n.º 26
0
        private static void OnCS2GSAskLoginRet(NetSessionBase session, Google.Protobuf.IMessage message, object[] args)
        {
            uint sid = ( uint )args[0];

            Protos.GC2GS_AskLogin login = (Protos.GC2GS_AskLogin)args[1];

            Protos.CS2GS_GCLoginRet csLoginRet = (Protos.CS2GS_GCLoginRet)message;
            Protos.GS2GC_LoginRet   gsLoginRet = ProtoCreator.R_GC2GS_AskLogin(login.Opts.Pid);
            switch (csLoginRet.Result)
            {
            case Protos.CS2GS_GCLoginRet.Types.EResult.Success:
                //检测客户端是否断线了
                ClientSession gcSession = GS.instance.netSessionMgr.GetSession(sid) as ClientSession;
                if (gcSession == null)
                {
                    //通知CS客户端断开了
                    Protos.GS2CS_GCLost gcLost = ProtoCreator.Q_GS2CS_GCLost();
                    gcLost.SessionID = login.SessionID;
                    GS.instance.netSessionMgr.Send(SessionType.ServerG2CS, gcLost);
                    return;
                }

                //添加到管理器
                GS.instance.userMgr.AddClient(login.SessionID, sid);

                //设置该Session为受信任的连接
                gcSession.accredited = true;

                gsLoginRet.Result   = Protos.GS2GC_LoginRet.Types.EResult.Success;
                gsLoginRet.GcNID    = csLoginRet.GcNID;
                gsLoginRet.GcState  = (Protos.GS2GC_LoginRet.Types.EGCCState)csLoginRet.GcState;
                gsLoginRet.UserInfo = csLoginRet.UserInfo;
                gsLoginRet.BsIP     = csLoginRet.BsIP;
                gsLoginRet.BsPort   = csLoginRet.BsPort;
                gsLoginRet.Defs     = Defs.binary;
                GS.instance.netSessionMgr.Send(sid, gsLoginRet);
                break;

            case Protos.CS2GS_GCLoginRet.Types.EResult.IllegalLogin:
                gsLoginRet.Result = Protos.GS2GC_LoginRet.Types.EResult.SessionExpire;
                GS.instance.netSessionMgr.Send(sid, gsLoginRet);
                GS.instance.netSessionMgr.CloseSession(sid, "client login failed");
                break;
            }
        }
Exemplo n.º 27
0
        public ErrorCode OnLs2DbQueryAccount(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            Protos.LS2DB_QueryAccount    queryUser    = (Protos.LS2DB_QueryAccount)message;
            Protos.DB2LS_QueryAccountRet queryUserRet = ProtoCreator.R_LS2DB_QueryAccount(queryUser.Opts.Pid);
            ErrorCode errorCode = DB.instance.accountDB.SqlExecQuery($"select id from account_user where uname=\'{queryUser.Name}\'",
                                                                     dataReader =>
            {
                if (dataReader.HasRows)
                {
                    return(ErrorCode.UsernameExists);
                }
                return(ErrorCode.Success);
            });

            queryUserRet.Result = errorCode == ErrorCode.Success ? Protos.Global.Types.ECommon.Success : Protos.Global.Types.ECommon.Failed;
            session.Send(queryUserRet);
            return(ErrorCode.Success);
        }
Exemplo n.º 28
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);
        }
Exemplo n.º 29
0
        public ErrorCode OnGc2BsRequestSnapShot(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            Protos.GC2BS_RequestSnapshot    request = (Protos.GC2BS_RequestSnapshot)message;
            Protos.BS2GC_RequestSnapshotRet ret     = ProtoCreator.R_GC2BS_RequestSnapshot(request.Opts.Pid);

            BSUser user = BS.instance.userMgr.GetUser(session.id);

            if (user == null)
            {
                ret.Result = Protos.BS2GC_RequestSnapshotRet.Types.EResult.InvalidUser;
            }
            else
            {
                BS.instance.battleMgr.HandleRequestSnapshot(user.battle, request, ret);
            }
            BS.instance.netSessionMgr.Send(session.id, ret);

            return(ErrorCode.Success);
        }
Exemplo n.º 30
0
        /// <summary>
        /// 玩家请求查询排行榜
        /// </summary>
        public ErrorCode OnGc2CsQueryRanking(NetSessionBase session, IMessage message)
        {
            Protos.GC2CS_QueryRanking request = (Protos.GC2CS_QueryRanking)message;
            ulong  gcNID = request.Opts.Transid;
            CSUser user  = CS.instance.userMgr.GetUser(gcNID);

            if (user != null)
            {
                Protos.CS2GC_QueryRankingRet resp         = ProtoCreator.R_GC2CS_QueryRanking(request.Opts.Pid);
                Protos.CS2DB_QueryRanking    queryRanking = ProtoCreator.Q_CS2DB_QueryRanking();
                queryRanking.SortType = (Protos.CS2DB_QueryRanking.Types.SortType)request.SortType;
                queryRanking.From     = request.From;
                queryRanking.Count    = request.Count;

                CS.instance.netSessionMgr.Send(SessionType.ServerC2DB, queryRanking, RPCEntry.Pop(OnQueryRankingRet, user, resp));
            }

            return(ErrorCode.Success);
        }