public static void CreateNewCharacter(Connection connection, CharacterData playerData) { var cached = new Player { AccountId = connection.AccountInfo.Id, CharacterData = playerData }; lock (PlayersLock) { if (Players.Exists(s => s.CharacterData.Name == playerData.Name)) { new SpFailCreateCharacter().Send(connection); return; } cached.PlayerId = GUIDGenerator.NextGUID(); cached.Level = 1; Players.Add(cached); } new SpCreateCharacter(cached, connection).Send(connection, 1); Log.Info("New character created!"); }
public static string SetTokenForAccount(string account, string passwd) { var acc = _accounts.FirstOrDefault(ai => ai.Value.Login == account && ai.Value.Password == Funcs.CalculateMd5Hash(passwd)).Value; if (acc == null) { if (_accounts.Values.Any(inf => inf.Login.ToLower() == account.ToLower())) { return(null); } lock (AccountsLock) { acc = new AccountData { Id = GUIDGenerator.NextGUID(), Login = account, Password = Funcs.CalculateMd5Hash(passwd) }; _accounts.Add(acc.Id, acc); AccountDB.Insert(acc); Log.Info("Account '{0}' created", account); } } string token = TokenGenerator.GenerateByAccount(acc); int gameHash = TokenGenerator.GenerateSessionHash(); if (_gameHashes.ContainsKey(acc.Id)) { _gameHashes.Remove(acc.Id); } _gameHashes.Add(acc.Id, gameHash); _tokens.Add(token, acc); Log.Info("Set token '{0}' from account: {1}", token, account); Log.Info("Set GameHash '{0}' from account: {1}", gameHash, account); return(token); }