Ejemplo n.º 1
0
        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);
        }