Ejemplo n.º 1
0
        protected override async ETTask Run(Session session, A0001_Register_C2R request, A0001_Register_R2C response, Action reply)
        {
            try
            {
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                //验证假定的账号和密码
                if (request.Account.Length <= 0 || request.Password.Length <= 0)
                {
                    Log.Error("账号密码为空 account:" + request.Account + "passwd:" + request.Password);
                    reply();
                    return;
                }
                List <ComponentWithId> result = await dbProxy.Query <AccountInfo>($"{{Account:'{request.Account}'}}");

                if (result.Count == 1)
                {
                    response.Error = ErrorCode.ERR_AccountAlreadyRegisted;
                    reply();
                    return;
                }
                else if (result.Count > 1)
                {
                    response.Error = ErrorCode.ERR_RepeatedAccountExist;
                    Log.Error("出现重复账号:" + request.Account);
                    reply();
                    return;
                }
                //生成玩家帐号 这里随机生成区号
                AccountInfo newAccount = ComponentFactory.CreateWithId <AccountInfo>(RealmHelper.GenerateId());
                newAccount.Account  = request.Account;
                newAccount.Password = request.Password;
                await dbProxy.Save(newAccount);

                //生成玩家的用户信息 用户名在消息中提供
                UserInfo newUser = ComponentFactory.CreateWithId <UserInfo, string>(newAccount.Id, request.Account);
                await dbProxy.Save(newUser);

                reply();

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Ejemplo n.º 2
0
        protected override async ETTask Run(Session session, Register_C2R request, Register_R2C response, Action reply)
        {
            try
            {
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                //验证假定的账号和密码
                List <ComponentWithId> result = await dbProxy.Query <AccountInfo>($"{{Account:'{request.Account}'}}");

                if (result.Count >= 1)
                {
                    response.Error = MMOErrorCode.ERR_AccountAlreadyRegisted;
                    reply();
                    return;
                }

                // 前端请求有分区号,生成指定分区账号ID,否则生成随机分区账号ID
                AccountInfo newAccount;
                if (request.Partition > 0)
                {
                    newAccount = ComponentFactory.CreateWithId <AccountInfo>(RealmHelper.GenerateId(request.Partition));
                }
                else
                {
                    newAccount = ComponentFactory.CreateWithId <AccountInfo>(RealmHelper.GenerateId());
                };

                newAccount.Account  = request.Account;
                newAccount.Password = request.Password;
                await dbProxy.Save(newAccount);

                // 生成玩家的用户信息
                UserInfo newUser = ComponentFactory.CreateWithId <UserInfo, string>(newAccount.Id, request.Account);
                await dbProxy.Save(newUser);

                reply();

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Ejemplo n.º 3
0
        protected override async void Run(Session session, A0001_Register_C2R message, Action <A0001_Register_R2C> reply)
        {
            A0001_Register_R2C response = new A0001_Register_R2C();

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

                //验证假定的账号和密码
                List <ComponentWithId> result = await dbProxy.Query <AccountInfo>($"{{Account:'{message.Account}'}}");

                if (result.Count == 1)
                {
                    response.Error = ErrorCode.ERR_AccountAlreadyRegisted;
                    reply(response);
                    return;
                }
                else if (result.Count > 1)
                {
                    response.Error = ErrorCode.ERR_RepeatedAccountExist;
                    Log.Error("出现重复账号:" + message.Account);
                    reply(response);
                    return;
                }

                //生成玩家帐号 这里随机生成区号
                AccountInfo newAccount = ComponentFactory.CreateWithId <AccountInfo>(RealmHelper.GenerateId());
                newAccount.Account  = message.Account;
                newAccount.Password = message.Password;
                await dbProxy.Save(newAccount);

                //生成玩家的用户信息 用户名在消息中提供
                UserInfo newUser = ComponentFactory.CreateWithId <UserInfo, string>(newAccount.Id, message.Account);
                await dbProxy.Save(newUser);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Ejemplo n.º 4
0
        protected override async ETTask Run(Session session, A0001_Register_C2R request, A0001_Register_R2C response, Action reply)
        {
            try
            {
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                //验证假定的账号和密码
                List <ComponentWithId> result = await dbProxy.Query <AccountInfo>($"{{Account:'{request.Account}'}}");

                if (result.Count == 1)
                {
                    response.Error = ErrorCode.ERR_AccountAlreadyRegisted;
                    reply();
                    return;
                }
                else if (result.Count > 1)
                {
                    response.Error = ErrorCode.ERR_RepeatedAccountExist;
                    Log.Error("出现重复账号:" + request.Account);
                    reply();
                    return;
                }

                //随机生成区号做为主键和前端输入的账号和密码在AccountInfo里存储一个newAccount
                AccountInfo newAccount = ComponentFactory.CreateWithId <AccountInfo>(RealmHelper.GenerateId());
                newAccount.Account  = request.Account;
                newAccount.Password = request.Password;
                await dbProxy.Save(newAccount);

                //以newAccount.Id(区号)为主键在UserInfo存入Id、Phone等数据
                UserInfo newUser = ComponentFactory.CreateWithId <UserInfo, string>(newAccount.Id, request.Account);
                await dbProxy.Save(newUser);

                reply();

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Ejemplo n.º 5
0
        protected override async void Run(Session session, A0009_CreateNewCharacter_C2G message, Action <A0009_CreateNewCharacter_G2C> reply)
        {
            A0009_CreateNewCharacter_G2C response = new A0009_CreateNewCharacter_G2C();

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

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

                //获取玩家所在大区编号
                DBProxyComponent dbProxy  = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo = await dbProxy.Query <UserInfo>(user.UserID);

                int GateAppId = RealmHelper.GetGateAppIdFromUserId(userInfo.Id);

                //检查角色名是否可用
                //会得到全部大区的同名角色 需遍历排除
                List <ComponentWithId> result = await dbProxy.Query <Character>($"{{Name:'{message.Name}'}}");

                foreach (var a in result)
                {
                    if (RealmHelper.GetGateAppIdFromUserId(((Character)a).UserID) == GateAppId)
                    {
                        //出现同名角色
                        response.Error = ErrorCode.ERR_CreateNewCharacter;
                        reply(response);
                        return;
                    }
                }

                //检查玩家是否有资格创建新角色
                bool canCreate     = false;
                int  characterSeat = message.Seat; //玩家请求创建的角色位置
                switch (characterSeat)
                {
                case 1:
                    if (userInfo.CharacterID1 == 0)
                    {
                        canCreate = true;
                    }
                    break;

                case 2:
                    if (userInfo.CharacterID2 == 0)
                    {
                        canCreate = true;
                    }
                    break;

                case 3:
                    if (userInfo.CharacterID3 == 0)
                    {
                        canCreate = true;
                    }
                    break;

                default:
                    break;
                }

                //判定为无法创建角色时返回错误消息
                if (!canCreate)
                {
                    //理应不该出现这个错误
                    //当玩家位置满时 点击创建角色按钮应有提示 无法进入创建角色界面
                    Log.Error("玩家当前位置已有角色");
                    response.Error = ErrorCode.ERR_CreateNewCharacter;
                    reply(response);
                    return;
                }

                //新建角色数据 角色可以通过UserID来识别区号 可以不使用CreateWithId方法
                Character character = ComponentFactory.CreateWithId <Character, long>(RealmHelper.GenerateId(), userInfo.Id);
                character.Name     = message.Name;
                character.Level    = 1;
                character.Career   = message.Career;
                character.Pet      = PetType.NonePet;
                character.Skeleton = message.Skeleton;
                switch (character.Career) //初始装备是绑定职业的
                {
                case CareerType.Warror:
                    character.Weapon = WeaponType.Sword;
                    character.Head   = HeadType.Head1;
                    character.Chest  = ChestType.Chest1;
                    character.Hand   = HandType.Hand1;
                    character.Feet   = FeetType.Feet1;
                    break;

                case CareerType.Mage:
                    character.Weapon = WeaponType.Wand;
                    character.Head   = HeadType.Head2;
                    character.Chest  = ChestType.Chest2;
                    character.Hand   = HandType.Hand2;
                    character.Feet   = FeetType.Feet2;
                    break;
                }
                character.Region = RegionType.Village; //初始地图为村庄
                character.X      = 1;                  //设置初始坐标
                character.Y      = 2;
                character.Z      = 3;
                character.Money  = 10;
                character.Mail   = 0;

                //存储数据
                switch (characterSeat)
                {
                case 1:
                    userInfo.CharacterID1 = character.Id;
                    userInfo.LastPlay     = 1;
                    break;

                case 2:
                    userInfo.CharacterID2 = character.Id;
                    userInfo.LastPlay     = 2;
                    break;

                case 3:
                    userInfo.CharacterID3 = character.Id;
                    userInfo.LastPlay     = 3;
                    break;

                default:
                    throw new Exception($"创建新角色错误:{userInfo.Id}");
                }

                await dbProxy.Save(character);

                await dbProxy.Save(userInfo);

                Log.Debug($"新增一个角色{character.Id}");
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }