コード例 #1
0
        protected override async void Run(Session session, C2G_GetUserInfo_Req message, Action <G2C_GetUserInfo_Back> reply)
        {
            G2C_GetUserInfo_Back response = new G2C_GetUserInfo_Back();

            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    //Log.Debug("登陆错误");
                    reply(response);
                    return;
                }

                //查询用户信息
                //需要给Gate服务器添加数据库代理组件
                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo         = await dbProxyComponent.Query <UserInfo>(message.UserID);

                //Log.Debug("玩家信息:" + JsonHelper.ToJson(userInfo));

                response.NickName = userInfo.UserName;
                response.Money    = userInfo.Money;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #2
0
        protected override void Run(Session session, C2G_DDZPlayCard_Req message, Action <G2C_DDZPlayCard_Res> reply)
        {
            G2C_DDZPlayCard_Res response = new G2C_DDZPlayCard_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 当前的session已经断开  !!!";
                    reply(response);
                    return;
                }

                response = (G2C_DDZPlayCard_Res)RoomHelper.PlayCard(message.GameId, message.AreaId, message.RoomId, message);

                response.UserId = message.UserId;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #3
0
        protected override void Run(Session session, C2G_IsBoltback_Req message, Action <G2C_IsBoltback_Res> reply)
        {
            G2C_IsBoltback_Res response = new G2C_IsBoltback_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 非法的 siesson 链接请求";
                    return;
                }

                var userInfo = Game.Scene.GetComponent <PlayerManagerComponent>().Get(message.UserId);

                if (userInfo == null)
                {
                    response.Error   = ErrorCode.ERR_IsBoltBackError;
                    response.Message = "玩家不在线。";
                    return;
                }

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #4
0
        protected override async void Run(Session session, C2G_ReturnLobby_Ntt message)
        {
            //验证Session
            if (!GateHelper.SignSession(session))
            {
                return;
            }

            User user = session.GetComponent <SessionUserComponent>().User;
            //StartConfigComponent config = Game.Scene.GetComponent<StartConfigComponent>();
            ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();

            //正在匹配中发送玩家退出匹配请求
            //if (user.IsMatching)
            //{
            //    IPEndPoint matchIPEndPoint = config.MatchConfig.GetComponent<InnerConfig>().IPEndPoint;
            //    Session matchSession = Game.Scene.GetComponent<NetInnerComponent>().Get(matchIPEndPoint);
            //    await matchSession.Call(new G2M_PlayerExitMatch_Req() { UserID = user.UserID });

            //    user.IsMatching = false;
            //}

            //正在游戏中发送玩家退出房间请求
            if (user.ActorID != 0)
            {
                ActorMessageSender actorProxy = actorProxyComponent.Get(user.ActorID);
                await actorProxy.Call(new Actor_PlayerExitRoom_Req()
                {
                    UserID = user.UserID
                });

                user.ActorID = 0;
            }
        }
コード例 #5
0
        protected override async void Run(Session session, C2G_UpdateAchievement message, Action <G2C_UpdateAchievement> reply)
        {
            G2C_UpdateAchievement response = new G2C_UpdateAchievement();

            try
            {
                User user = GateHelper.GetUserBySession(session);
                //验证Session
                if (user == null)
                {
                    response.Error = ProtocolErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }

                if (message.Info.Progress == 0)
                {
                    response.Error = ProtocolErrorCode.ERR_InputParams;
                    reply(response);
                    return;
                }

                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                DB_UserInfo      userInfo         = await dbProxyComponent.Query <DB_UserInfo>(user.UserID, false);

                UpdateAchievement(userInfo, message.Info);
                await dbProxyComponent.Save(userInfo, false);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #6
0
        protected override void Run(Session session, C2G_GetRoomInfo_Req message, Action <G2C_GetRoomInfo_Res> reply)
        {
            G2C_GetRoomInfo_Res response = new G2C_GetRoomInfo_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 当前的session已经断开  !!!";
                    reply(response);
                    return;
                }

                response.RoomData = (RoomData)RoomHelper.GetRoomInfo(message.GameId, message.AreaId, message.UserId, message.RoomId);

                if (response.RoomData == null)
                {
                    response.Error   = ErrorCode.ERR_GetRoomInfoError;
                    response.Message = " 获取房间信息失败  !!!";
                    reply(response);
                    return;
                }

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #7
0
        protected override async ETTask Run(Session session, GetCharacter_C2G request, CharacterMessage_G2C response, Action reply)
        {
            try
            {
                // 验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = MMOErrorCode.ERR_UserNotOnline;
                    reply();
                    return;
                }

                // 获取用户对象
                User user = session.GetComponent <SessionUserComponent>().User;

                DBProxyComponent dbProxy    = Game.Scene.GetComponent <DBProxyComponent>();
                List <Component> characters = await dbProxy.Query2 <Character>($"{{UserId:{request.UserId},CharaId:{request.CharaId}}}");

                Character character = characters[0] as Character;

                response.Character = GateHelper.CharacterInfoByData(character);


                reply();
                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #8
0
        protected override async ETTask Run(Session session, A1001_SetUserInfo_REQ request, A1001_SetUserInfo_ACK response, Action reply)
        {
            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_UserNotOnline;
                    reply();
                    return;
                }

                //获取玩家对象
                User             user             = session.GetComponent <SessionUserComponent>().User;
                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo         = await dbProxyComponent.Query <UserInfo>(user.UserID);

                response.Userinfo.Username = userInfo.UserName;
                response.Userinfo.Money    = userInfo.Money;
                response.Userinfo.Level    = userInfo.Level;

                reply();
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #9
0
        protected override async void Run(Session session, C2G_JoinRoom message, Action <G2C_JoinRoom> reply)
        {
            G2C_JoinRoom response = new G2C_JoinRoom();

            try
            {
                //验证合法性
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }
                //获取房间信息
                Room room = Game.Scene.GetComponent <RoomComponent>().Get(message.RoomId);
                if (room == null)
                {
                    Log.Info($"房间不存在:{message.RoomId}");
                    response.Error = ErrorCode.ERR_NotFoundRoom;
                    reply(response);
                    return;
                }
                if (room.IsCanAddPlayer())
                {
                    Log.Info($"房间已经满人:{message.RoomId}");
                    response.Error = ErrorCode.ERR_RoomIsFull;
                    reply(response);
                    return;
                }

                //设置用户的房间ID
                User user = session.GetUser();
                user.RoomID = room.RoomId;
                //返回参数设置
                response.Room = new RoomInfo
                {
                    PlayerCount = room.roomConfig.PlayerCount,
                    GameCount   = room.roomConfig.GameCount,
                    GameScore   = room.roomConfig.GameScore
                };
                response.RoomId  = room.RoomId;
                response.ChairID = room.GetNullChair();
                reply(response);
                Log.Info("成功申请加入房间!!!");


                //向游戏服务器发送玩家进入请求
                ActorMessageSender actorProxy = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(room.Id);
                actorProxy.Send(new Actor_PlayerEnterRoom_Ntt()
                {
                    PlayerID  = user.Id,
                    UserID    = user.UserID,
                    SessionID = session.Id,
                });
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #10
0
        protected async override void Run(Session session, C2G_QuitRoom_Req message, Action <G2C_QuitRoom_Res> reply)
        {
            G2C_QuitRoom_Res response = new G2C_QuitRoom_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 当前的session已经断开  !!!";
                    reply(response);
                    return;
                }

                var Result = await RoomHelper.QuitRoom(message.GameId, message.AreaId, message.UserId, message.RoomId);

                if (Result != "0" && Result != "1")
                {
                    response.Error   = ErrorCode.ERR_QuitRoomError;
                    response.Message = Result;
                    reply(response);
                    return;
                }

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #11
0
        protected override void Run(Session session, C2G_DDZPrepare_Req message, Action <G2C_DDZPrepare_Res> reply)
        {
            G2C_DDZPrepare_Res response = new G2C_DDZPrepare_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 当前的session已经断开  !!!";
                    reply(response);
                    return;
                }

                int restul = RoomHelper.Prepare(message.GameId, message.AreaId, message.RoomId, message.UserId);
                if (restul == -1)
                {
                    response.Error   = ErrorCode.ERR_DDZPrepareError;
                    response.Message = " 准备失败  !!!";
                    reply(response);
                    return;
                }

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #12
0
ファイル: RoomSystem.cs プロジェクト: yudada-xy/ETLandlords
        /// <summary>
        /// 斗地主游戏开始
        /// </summary>
        public static void GameStart(this Room self)
        {
            //更改房间状态 从空闲房间移除 添加到游戏中房间列表
            LandMatchComponent Match = Game.Scene.GetComponent <LandMatchComponent>();

            Match.FreeLandlordsRooms.Remove(self.Id);
            Match.GamingLandlordsRooms.Add(self.Id, self);
            //出牌控制组件
            self.AddComponent <OrderControllerComponent>();

            //更该玩家状态
            for (int i = 0; i < self.gamers.Length; i++)
            {
                Gamer gamer = self.gamers[i];
                Match.Waiting.Remove(gamer.UserID);
                Match.Playing.Add(gamer.UserID, self);
            }
            //添加开始斗地主游戏需要的组件
            //牌库组件
            self.AddComponent <DeckComponent>();

            //添加开始斗地主游戏需要的组件
            self.AddComponent <GameControllerComponent, RoomConfig>(GateHelper.GetLandlordsConfig(RoomLevel.Lv100));

            //开始游戏
            self.GetComponent <GameControllerComponent>().StartGame();
        }
コード例 #13
0
        protected override async void Run(Session session, C2G_Unlock message, Action <G2C_Unlock> reply)
        {
            G2C_Unlock response = new G2C_Unlock();

            try
            {
                User user = GateHelper.GetUserBySession(session);
                //验证Session
                if (user == null)
                {
                    response.Error = ProtocolErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }

                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                DB_UserInfo      userInfo         = await dbProxyComponent.Query <DB_UserInfo>(user.UserID, false);

                userInfo.UnlockPoint = message.DataId;
                await dbProxyComponent.Save(userInfo, false);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #14
0
        protected override async ETTask Run(Session session, C2G_GetUserInfoInRoom_Req request, G2C_GetUserInfoInRoom_Back response, Action reply)
        {
            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    //Log.Debug("登陆错误");
                    reply();
                    return;
                }

                //查询用户信息
                //需要给Gate服务器添加数据库代理组件
                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo         = await dbProxyComponent.Query <UserInfo>(request.UserID);

                //Log.Debug("玩家信息:" + JsonHelper.ToJson(userInfo));

                response.UserName = userInfo.UserName;


                reply();

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #15
0
        protected override async void Run(Session session, A1001_GetUserInfo_C2G message, Action <A1001_GetUserInfo_G2C> reply)
        {
            A1001_GetUserInfo_G2C response = new A1001_GetUserInfo_G2C();

            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_UserNotOnline;
                    reply(response);
                    return;
                }

                //获取玩家对象
                User user = session.GetComponent <SessionUserComponent>().User;

                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo         = await dbProxyComponent.Query <UserInfo>(user.UserID);

                response.UserName  = userInfo.UserName;
                response.UserLevel = userInfo.UserLevel;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #16
0
        protected override async void Run(Session session, C2G_GameStart message, Action <G2C_GameStart> reply)
        {
            G2C_GameStart response = new G2C_GameStart();

            try
            {
                User user = GateHelper.GetUserBySession(session);
                //验证Session
                if (user == null)
                {
                    response.Error = ProtocolErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }

                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                DB_UserInfo      userInfo         = await dbProxyComponent.Query <DB_UserInfo>(user.UserID, false);

                userInfo.LastGameStartTime = DateTime.UtcNow.Ticks;
                await dbProxyComponent.Save(userInfo, false);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #17
0
        protected override async void Run(Session session, C2G_GetUserInfo_Req message, Action <G2C_GetUserInfo_Ack> reply)
        {
            G2C_GetUserInfo_Ack response = new G2C_GetUserInfo_Ack();

            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }

                //查询用户信息
                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo         = await dbProxyComponent.Query <UserInfo>(message.UserID, false);

                response.NickName = userInfo.NickName;
                response.Wins     = userInfo.Wins;
                response.Loses    = userInfo.Loses;
                response.Money    = userInfo.Money;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #18
0
        protected override async void Run(Session session, C2G_UpdateCollection message, Action <G2C_UpdateCollection> reply)
        {
            G2C_UpdateCollection response = new G2C_UpdateCollection();

            try
            {
                User user = GateHelper.GetUserBySession(session);
                //验证Session
                if (user == null)
                {
                    response.Error = ProtocolErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }


                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                DB_UserInfo      userInfo         = await dbProxyComponent.Query <DB_UserInfo>(user.UserID, false);

                bool change = false;
                switch (message.Type)
                {
                case 1:
                    if (addToList(userInfo.MonsterList, message.DataId))
                    {
                        change = true;
                    }
                    break;

                case 2:
                    if (addToList(userInfo.HadOwnItemList, message.DataId))
                    {
                        change = true;
                    }
                    break;

                case 3:
                    if (addToList(userInfo.UnSeeOwnItemList, message.DataId))
                    {
                        change = true;
                    }
                    break;
                }

                if (change)
                {
                    await dbProxyComponent.Save(userInfo, false);
                }
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #19
0
        protected override async void Run(Session session, C2G_StartMatch_Req message, Action <G2C_StartMatch_Ack> reply)
        {
            G2C_StartMatch_Ack response = new G2C_StartMatch_Ack();

            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }

                User user = session.GetComponent <SessionUserComponent>().User;

                //验证玩家是否符合进入房间要求,默认为100底分局
                RoomConfig roomConfig = RoomHelper.GetConfig(RoomLevel.Lv100);
                UserInfo   userInfo   = await Game.Scene.GetComponent <DBProxyComponent>().Query <UserInfo>(user.UserID, false);

                if (userInfo.Money < roomConfig.MinThreshold)
                {
                    response.Error = ErrorCode.ERR_UserMoneyLessError;
                    reply(response);
                    return;
                }

                //这里先发送响应,让客户端收到后切换房间界面,否则可能会出现重连消息在切换到房间界面之前发送导致重连异常
                reply(response);

                //向匹配服务器发送匹配请求
                StartConfigComponent config          = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           matchIPEndPoint = config.MatchConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session matchSession = Game.Scene.GetComponent <NetInnerComponent>().Get(matchIPEndPoint);
                M2G_PlayerEnterMatch_Ack m2G_PlayerEnterMatch_Ack = await matchSession.Call(new G2M_PlayerEnterMatch_Req()
                {
                    PlayerID  = user.InstanceId,
                    UserID    = user.UserID,
                    SessionID = session.InstanceId,
                }) as M2G_PlayerEnterMatch_Ack;

                user.IsMatching = true;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #20
0
        protected async override void Run(Session session, C2G_ChangerRoom_Req message, Action <G2C_ChangerRoom_Res> reply)
        {
            G2C_ChangerRoom_Res response = new G2C_ChangerRoom_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 当前的session已经断开  !!!";
                    reply(response);
                    return;
                }

                int[] restul = RoomHelper.ChangerRoom(message.GameId, message.AreaId, message.RoomId, session.Id);

                if (restul[0] == -1)
                {
                    response.Error   = ErrorCode.ERR_ChangerRoomError;
                    response.Message = "换桌失败";
                    reply(response);
                    return;
                }

                var myLastRoomInfo = Game.Scene.GetComponent <PlayerManagerComponent>().Get(message.UserId).GetComponent <MyLastJionRoom>().MyLastJionRoomList;

                if (myLastRoomInfo.Count == 0)
                {
                    myLastRoomInfo.Add(new MyLastJionRoomData());
                }

                myLastRoomInfo.First().GameId = message.GameId;
                myLastRoomInfo.First().AreaId = message.AreaId;
                myLastRoomInfo.First().RoomId = restul[0];


                response.GameId = message.GameId;
                response.AreaId = message.AreaId;
                response.RoomId = restul[0];
                response.Index  = restul[1];

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #21
0
        protected override async void Run(Session session, C2G_GetUserInfo message, Action <G2C_GetUserInfo> reply)
        {
            G2C_GetUserInfo response = new G2C_GetUserInfo();

            try
            {
                User user = GateHelper.GetUserBySession(session);
                //验证Session
                if (user == null)
                {
                    response.Error = ProtocolErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }

                //查询用户信息
                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                DB_UserInfo userInfo = await dbProxyComponent.Query <DB_UserInfo>(user.UserID, false);

                response.Crystal          = userInfo.Crystal;
                response.CurrRoleDataId   = userInfo.CurrRoleDataId;
                response.RoleDataList     = userInfo.RoleDataList;
                response.UnlockedTechList = userInfo.UnlockedTechList;
                response.UnlockPoint      = userInfo.UnlockPoint;
                response.MonsterList      = userInfo.MonsterList;
                response.HadOwnItemList   = userInfo.HadOwnItemList;
                response.SeeOwnItemList   = userInfo.UnSeeOwnItemList;
                List <AchievementInfo> list = new List <AchievementInfo>(userInfo.AchievementList.Count);
                for (int i = 0; i < userInfo.AchievementList.Count; i++)
                {
                    DB_AchievementInfo info = userInfo.AchievementList[i];

                    AchievementInfo achievementInfo = new AchievementInfo()
                    {
                        DataId = info.DataId, Progress = info.Progress
                    };
                    list.Add(achievementInfo);
                }
                response.AchievementList = list;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #22
0
        protected async override void Run(Session session, C2G_JionRoom_Req message, Action <G2C_JionRoom_Res> reply)
        {
            G2C_JionRoom_Res response = new G2C_JionRoom_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 当前的session已经断开  !!!";
                    reply(response);
                    return;
                }

                int RoomId = RoomHelper.JionRoom(message.GameId, message.AreaId, message.UserId, session.Id, message.RoomId, out string errMsg);

                if (RoomId == -1)
                {
                    response.Error   = ErrorCode.ERR_JionRoomError;
                    response.Message = errMsg;
                    reply(response);
                    return;
                }

                var myLastRoomInfo = Game.Scene.GetComponent <PlayerManagerComponent>().Get(message.UserId).GetComponent <MyLastJionRoom>().MyLastJionRoomList;

                myLastRoomInfo.Clear();

                MyLastJionRoomData myLast = new MyLastJionRoomData()
                {
                    GameId = message.GameId,
                    AreaId = message.AreaId,
                    RoomId = RoomId
                };

                myLastRoomInfo.Add(myLast);

                response.RoomId = RoomId;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #23
0
        protected override void Run(Session session, C2G_GetAreaList_Req message, Action <G2C_GetAreaList_Res> reply)
        {
            G2C_GetAreaList_Res response = new G2C_GetAreaList_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 当前的session已经断开  !!!";
                    reply(response);
                    return;
                }

                foreach (var Area in Game.Scene.GetComponent <LobbyManagerCpt>().GetComponent <AreaManagerCpt>().areaList)
                {
                    if (Area.GameId != message.GameId)
                    {
                        continue;
                    }

                    AreaInfo areaInfo = new AreaInfo()
                    {
                        GameId   = Area.GameId,
                        AreaId   = Area.AreaId,
                        Score    = Area.Score,
                        AreaType = Area.AreaType
                    };

                    response.AreaInfo.Add(areaInfo);
                }

                if (response.AreaInfo.count == 0)
                {
                    response.Error   = ErrorCode.ERR_GetAreaError;
                    response.Message = "获取场信息失败 !!!";
                    reply(response);
                }

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #24
0
        protected override async void Run(Session session, C2G_ResetPassword_Req message, Action <G2C_ResetPassword_Res> reply)
        {
            G2C_ResetPassword_Res response = new G2C_ResetPassword_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 非法的 siesson 链接请求";
                    reply(response);
                    return;
                }

                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                List <ComponentWithId> result = await dbProxy.Query <AccountInfo>(_account => _account.Id == message.UserId);

                AccountInfo account = result[0] as AccountInfo;

                if (account.Password != message.OldPassword)
                {
                    response.Error   = ErrorCode.ERR_ResetPasswordPError;
                    response.Message = "您的原始密码有误,请重新输入 !!!";
                    reply(response);
                    return;
                }
                if (message.NewPassword == account.Password)
                {
                    response.Error   = ErrorCode.ERR_ResetPasswordPError;
                    response.Message = "不能与原始密码相同 !!!";
                    reply(response);
                    return;
                }

                account.Password = message.NewPassword;
                await dbProxy.Save(account);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #25
0
        protected override async void Run(Session session, C2G_StartMatch_Landlords_Req message, Action <G2C_StartMatch_Landlords_Back> reply)
        {
            G2C_StartMatch_Landlords_Back response = new G2C_StartMatch_Landlords_Back();

            try
            {
                Log.Debug("玩家开始匹配");
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }

                User user = session.GetComponent <SessionUserComponent>().User;

                //验证玩家是否符合进入房间要求,默认为100底分局
                RoomConfig roomConfig = GateHelper.GetLandlordsConfig(RoomLevel.Lv100);
                UserInfo   userInfo   = await Game.Scene.GetComponent <DBProxyComponent>().Query <UserInfo>(user.UserID);

                if (userInfo.Money < roomConfig.MinThreshold)
                {
                    response.Error = ErrorCode.ERR_UserMoneyLessError;
                    reply(response);
                    return;
                }

                reply(response);

                //获取斗地主专用Map服务器的Session
                //通知Map服务器创建新的Gamer
                Session LandlordsSession = GateHelper.GetLandlordsSession();
                LandlordsSession.Send(new G2M_EnterMatch_Landords()
                {
                    UserID          = user.UserID,
                    ActorIDofUser   = user.InstanceId,
                    ActorIDofClient = user.SelfGateSessionID
                });
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #26
0
        protected override async ETTask Run(Session session, C2G_StartMatch_Req request, G2C_StartMatch_Back response, Action reply)
        {
            try
            {
                Log.Debug("玩家开始匹配");
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    reply();
                    return;
                }
                //获取Gate服务器上绑定的User对象
                User user = session.GetComponent <SessionUserComponent>().User;
                //验证玩家是否符合进入房间要求,默认为100底分局
                RoomConfig roomConfig = GateHelper.GetLandlordsConfig(RoomLevel.Lv100);
                //获取User对象的UserInfo(用户信息)数据
                UserInfo userInfo = await Game.Scene.GetComponent <DBProxyComponent>().Query <UserInfo>(user.UserID);

                //判断此对象的金币是否符合准备要求
                if (userInfo.Douzi < roomConfig.MinThreshold)
                {
                    response.Error = ErrorCode.ERR_UserMoneyLessError;
                    reply();
                    return;
                }
                reply();

                //获取斗地主Map服务器的Session
                //通知Map服务器创建地图上的Gamer,发送请求匹配通知
                Session mapSession = GateHelper.GetMapSession();
                mapSession.Send(new EnterMatchs_G2M()
                {
                    UserID   = user.UserID,
                    GActorID = user.InstanceId,
                    CActorID = user.GateSessionID
                });

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #27
0
        public static async ETVoid InitWorldMapRoom(this RoomComponent self)
        {
            // 获取所有世界地图map数据列表
            // 这样可以在另一个循环,异步的创建所有的世界地图房间,完成怪物,世界boss,Npc,世界任务,场景中产物的刷新。
            // foreach(MapInfo map in mapInfos){
            //     self.worldMapQueue.Enqueue(map.id);
            // }

            // 这里暂时只初始化 黎明镇的地图房间
            RoomConfig config   = GateHelper.GetMapConfig(1001);
            Room       daybreak = ComponentFactory.Create <Room, RoomConfig>(config);

            await daybreak.AddComponent <MailBoxComponent>().AddLocation();

            self.mapRooms.Add(daybreak.roomId, daybreak);

            // 本地图刷新
            // await daybreak.RefreshMap().Coroutine();
        }
コード例 #28
0
        protected override async void Run(Session session, C2G_CostCrystal message, Action <G2C_CostCrystal> reply)
        {
            G2C_CostCrystal response = new G2C_CostCrystal();

            try
            {
                User user = GateHelper.GetUserBySession(session);
                //验证Session
                if (user == null)
                {
                    response.Error = ProtocolErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }

                short crystal = getCost(message.Type, message.DataId);
                if (crystal <= 0)
                {
                    response.Error = ProtocolErrorCode.ERR_InputParams;
                    reply(response);
                    return;
                }

                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                DB_UserInfo      userInfo         = await dbProxyComponent.Query <DB_UserInfo>(user.UserID, false);

                if (userInfo.Crystal < crystal)
                {
                    response.Error = ProtocolErrorCode.ERR_CostCrystalFail;
                    reply(response);
                    return;
                }
                userInfo.Crystal -= crystal;
                await dbProxyComponent.Save(userInfo, false);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #29
0
        protected override async void Run(Session session, C2G_GetUserInfo_Req message, Action <G2C_GetUserInfo_Res> reply)
        {
            G2C_GetUserInfo_Res response = new G2C_GetUserInfo_Res();

            try
            {
                if (!GateHelper.SingSession(session))
                {
                    response.Error   = ErrorCode.ERR_SessionError;
                    response.Message = " 非法的 siesson 链接请求";
                    return;
                }

                ETModel.UserInfo userInfo = Game.Scene.GetComponent <PlayerManagerComponent>().Get(message.UserId);

                if (userInfo == null)
                {
                    response.Error   = ErrorCode.ERR_GetUserInfoError;
                    response.Message = $"查询用户信息失败,用户名{message.UserId}";
                    reply(response);
                    return;
                }

                response.UserInfo = new UserInfo()
                {
                    Account   = userInfo.Account,
                    PlayerId  = userInfo.PlayerId,
                    Nickname  = userInfo.Nickname,
                    HeadId    = userInfo.HeadId,
                    Gold      = userInfo.Gold,
                    Gender    = userInfo.Gender,
                    IsTourist = userInfo.IsTourist,
                };

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #30
0
        protected override async void Run(Session session, C2G_GameOver message, Action <G2C_GameOver> reply)
        {
            G2C_GameOver response = new G2C_GameOver();

            try
            {
                User user = GateHelper.GetUserBySession(session);
                //验证Session
                if (user == null)
                {
                    response.Error = ProtocolErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }
                if (message.CrystalReward <= 0)
                {
                    response.Error = ProtocolErrorCode.ERR_InputParams;
                    reply(response);
                    return;
                }
                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                DB_UserInfo      userInfo         = await dbProxyComponent.Query <DB_UserInfo>(user.UserID, false);

                long gameUseMin = (DateTime.UtcNow.Ticks - userInfo.LastGameStartTime) / 1000 / 60; //花费分钟数
                long average    = message.CrystalReward / gameUseMin;
                if (average > 20)                                                                   //每分钟允许获得至多20个海钻
                {
                    response.Error = ProtocolErrorCode.ERR_GameOverError;
                    reply(response);
                    return;
                }
                userInfo.Crystal += message.CrystalReward;
                await dbProxyComponent.Save(userInfo, false);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }