コード例 #1
0
ファイル: Form1.cs プロジェクト: fos83/MuEmu
        private async Task ServerList(string path)
        {
            var content = await File.ReadAllBytesAsync(path);

            byte[] block, block2;
            string additionalInfo;

            for (var i = 0; i < content.Length;)
            {
                block  = content.Skip(i).ToArray();
                block2 = block.Take(39).ToArray();
                BuxDecode.Decode(block2);
                using (var br = new MemoryStream(block))
                {
                    br.Seek(0, SeekOrigin.Begin);
                    br.Write(block2);
                    br.Seek(0, SeekOrigin.Begin);

                    var result = Serializer.Deserialize <ServerList>(br);
                    if (result.descriptionLength > 0)
                    {
                        block = new byte[result.descriptionLength];
                        br.Read(block);
                        BuxDecode.Decode(block);
                        additionalInfo = block.MakeString();
                    }
                    i += (int)br.Position;
                }
            }
        }
コード例 #2
0
ファイル: AuthServices.cs プロジェクト: tbs005/MuEmu
        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));
        }
コード例 #3
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 });
        }
コード例 #4
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));
        }