Beispiel #1
0
 public static bool RemoveSession(AuthClient client)
 {
     try
     {
         if (client == null || client.SessionId == 0)
         {
             return(false);
         }
         if (SocketSessions.ContainsKey(client.SessionId) && SocketSessions.TryGetValue(client.SessionId, out client))
         {
             return(SocketSessions.TryRemove(client.SessionId, out client));
         }
         client = null;
     }
     catch (Exception ex)
     {
         Logger.Exception(ex);
     }
     return(false);
 }
Beispiel #2
0
 public static void AddSession(Socket handler)
 {
     try
     {
         string   address = GetIPAddress(handler);
         DateTime date    = DateTime.Now;
         if (!SocketConnections.ContainsKey(address) && SocketConnections.TryAdd(address, date) || SocketConnections.TryGetValue(address, out DateTime getDate) && (date - getDate).TotalSeconds >= Settings.AuthConnectionIntervalSeconds && SocketConnections.TryUpdate(address, date, getDate))
         {
             AuthClient client = new AuthClient(handler);
             for (int idx = 1; idx < 100000; idx++)
             {
                 if (!SocketSessions.ContainsKey(idx) && SocketSessions.TryAdd(idx, client))
                 {
                     client.SessionId   = idx;
                     client.SessionDate = date;
                     client.StartSession();
                     return;
                 }
             }
             client.Close(50);
             Logger.Error($" [AuthManager] [AddSession] Não foi possivel adicionar a lista de sessões. IPAddress ({address}) Date: {date}");
         }
         else
         {
             if ((date - Logger.LastSaveLogTcpAuth2).Minutes >= 1)
             {
                 Logger.Attacks($" [AuthManager] Está conexão está bloqueada por {Settings.AuthConnectionIntervalSeconds} segundos. IP ({address}) Date ({date})");
                 Logger.LastSaveLogTcpAuth2 = date;
             }
             handler.Close(50);
         }
     }
     catch (Exception ex)
     {
         Logger.Exception(ex);
     }
 }