Esempio n. 1
0
        public async Task CIDAndPass(GSSession session, CIDAndPass message)
        {
            BuxDecode.Decode(message.btAccount);
            BuxDecode.Decode(message.btPassword);

            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();

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

                        return;
                    }
                    else
                    {
                        acc = new MU.DataBase.AccountDto
                        {
                            Account    = message.Account,
                            Password   = message.Password,
                            Characters = new List <MU.DataBase.CharacterDto>(),
                            VaultCount = 1,
                            VaultMoney = 0
                        };
                        db.Accounts.Add(acc);
                        db.SaveChanges();
                        Logger.Information("Account Created");
                    }
                }

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

                    return;
                }

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

                    return;
                }

                acc.ServerCode  = Program.ServerCode;
                acc.IsConnected = true;
                db.Accounts.Update(acc);
                db.SaveChanges();

                //acc.Characters = (from @char in db.Characters
                //                  where @char.AccountId == acc.AccountId
                //                  select @char).ToList();

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

                session.Player.SetAccount(acc);
            }

            await session.SendAsync(new SLoginResult(LoginResult.Ok));
        }
Esempio n. 2
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 Auth.CCharacterMapJoin2 {
                Name = message.Character
            });
        }