Пример #1
0
        public async Task CServerMove(GSSession session, CServerMove message)
        {
            Logger.ForAccount(session).Information("Server move recv");
            BuxDecode.Decode(message.btAccount);

            if (Program.server.ClientVersion != message.ClientVersion)
            {
                Logger.Error("Bad client version {0} != {1}", Program.server.ClientVersion, message.ClientVersion);
                await session.SendAsync(new SLoginResult(LoginResult.OldVersion));

                session.Disconnect();
                return;
            }

            if (Program.server.ClientSerial != message.ClientSerial)
            {
                Logger.Error("Bad client serial {0} != {1}", Program.server.ClientSerial, message.ClientSerial);
                await session.SendAsync(new SLoginResult(LoginResult.OldVersion));

                session.Disconnect();
                return;
            }

            using (var db = new GameContext())
            {
                var acc = (from account in db.Accounts
                           where string.Equals(account.Account, message.Account, StringComparison.InvariantCultureIgnoreCase)
                           select account)
                          .FirstOrDefault();

                var token = $"{message.AuthCode1:X8}{message.AuthCode2:X8}{message.AuthCode3:X8}{message.AuthCode4:X8}";

                if (acc.AuthToken != token)
                {
                    await session.SendAsync(new SLoginResult(LoginResult.ConnectionError));

                    return;
                }

                session.PreviousCode = (ushort)acc.ServerCode;
                acc.ServerCode       = Program.ServerCode;
                acc.IsConnected      = true;
                acc.LastConnection   = DateTime.Now;
                db.Accounts.Update(acc);
                db.SaveChanges();

                byte y = 0;
                session.Player.SetAccount(acc);
                var _acc = session.Player.Account;
                _acc.Characters = (from @char in db.Characters
                                   where @char.AccountId == acc.AccountId
                                   select @char).ToDictionary(x => y++);

                foreach (var @char in _acc.Characters)
                {
                    @char.Value.Items = (from item in db.Items
                                         where item.CharacterId == @char.Value.CharacterId
                                         select item).ToList();
                }
            }

            await CCharacterMapJoin2(session, new CCharacterMapJoin2 { Name = message.Character });
        }
Пример #2
0
        public async Task CIDAndPass(GSSession session, CIDAndPass message)
        {
            BuxDecode.Decode(message.btAccount);
            BuxDecode.Decode(message.btPassword);

            if (session.TryLoginCount > 2)
            {
                await session.SendAsync(new SLoginResult(LoginResult.ConnectionClosed3Fail));

                return;
            }

            if (Program.server.ClientVersion != message.ClientVersion)
            {
                Logger.Error("Bad client version {0} != {1}", Program.server.ClientVersion, message.ClientVersion);
                await session.SendAsync(new SLoginResult(LoginResult.OldVersion));

                session.Disconnect();
                return;
            }

            if (Program.server.ClientSerial != message.ClientSerial)
            {
                Logger.Error("Bad client serial {0} != {1}", Program.server.ClientSerial, message.ClientSerial);
                await session.SendAsync(new SLoginResult(LoginResult.OldVersion));

                session.Disconnect();
                return;
            }

            if (string.IsNullOrWhiteSpace(message.Account) || string.IsNullOrWhiteSpace(message.Password))
            {
                await session.SendAsync(new SLoginResult(LoginResult.AccountError));

                return;
            }

            using (var db = new GameContext())
            {
                var acc = (from account in db.Accounts
                           where account.Account.ToLower() == message.Account.ToLower()
                           select account)
                          .SingleOrDefault();

                if (acc == null)
                {
                    Logger.Information("Account {0} Don't exists", message.Account);
                    if (!Program.AutoRegistre)
                    {
                        await session.SendAsync(new SLoginResult(LoginResult.AccountError));

                        return;
                    }
                    else
                    {
                        acc = new MU.DataBase.AccountDto
                        {
                            Account = message.Account,
                            //Password = Convert.ToBase64String(hash),
                            //Salt = Convert.ToBase64String(newSalt),
                            Characters     = new List <MU.DataBase.CharacterDto>(),
                            VaultCount     = 1,
                            VaultMoney     = 0,
                            LastConnection = DateTime.Now,
                            IsConnected    = false,
                            ServerCode     = 0,
                        };

                        string Salt = "";
                        acc.Password = GetHashPassword(message.Password, ref Salt);
                        acc.Salt     = Salt;
                        db.Accounts.Add(acc);
                        db.SaveChanges();
                        Logger.Information("Account Created");
                    }
                }


                var salt = acc.Salt;
                if (string.IsNullOrEmpty(salt))
                {
                    acc.Password = GetHashPassword(acc.Password, ref salt);
                    acc.Salt     = salt;
                }

                if (acc.Password != GetHashPassword(message.Password, ref salt))
                {
                    await session.SendAsync(new SLoginResult(LoginResult.PasswordError));

                    session.TryLoginCount++;
                    return;
                }

                if (acc.IsConnected == true)
                {
                    await session.SendAsync(new SLoginResult(LoginResult.IsConnected));

                    return;
                }

                session.PreviousCode = 0xffff;
                acc.ServerCode       = Program.ServerCode;
                acc.IsConnected      = true;
                acc.LastConnection   = DateTime.Now;
                db.Accounts.Update(acc);
                db.SaveChanges();

                session.Player.SetAccount(acc);
            }

            await session.SendAsync(new SLoginResult(LoginResult.Ok));
        }