예제 #1
0
        /// <summary>
        /// Process authorize, check token and configure connection
        /// </summary>
        /// <param name="client"></param>
        /// <param name="token"></param>
        public void AuthProcess(ClientConnection client, string token)
        {
            using (var db = _dbFactory.OpenSession())
            {
                var model = db.QueryOver<AccountData>().Where(p => p.Token == token).Take(1).SingleOrDefault(); //get account data by token
                if (model == null) //if data is null, database not contains token
                {
                    Log.Info($"Cannot find account by token: {token}");
                    client.CloseConnection();
                    return;
                }

                if (model.ExpireTime < DateTime.Now) //if token time has expire, close connection
                {
                    Log.Info($"Token time has expired, account id {model.Id}, close connection");
                    client.CloseConnection();
                    return;
                }

                client.AccountInfo = model;

                var gameToken = RndExt.RandomString(7);

                db.CreateSQLQuery($"UPDATE bd_accounts SET a_game_hash=? WHERE a_id={model.Id} ").SetString(0, gameToken).ExecuteUpdate();

                new SpSetHash(gameToken).Send(client);
            }
        }
예제 #2
0
 public void Disconnect(ClientConnection connection)
 {
     try
     {
         connection.Socket.BeginDisconnect(false, EndDisconect, connection);
     }
     catch (Exception e)
     {
         Debug.Print("Exception occured on begin disconnect, {0}", e);
     }
 }