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