Exemplo n.º 1
0
 /// <summary>
 /// Closes the connection with a client, logs a reason, and updates the queue.
 /// </summary>
 /// <param name="reason">Reason to disconnect the client</param>
 public void Close(string reason = "unknown")
 {
     Logging.Log(Logging.LogSeverity.Warning, $"Closing {UserName}({this.User?.ToString() ?? "n/a"}) due to {reason}");
     try
     {
         this.User.Connection = null;
     } catch { }
     try
     {
         Client.Close();
     }
     catch { }
     Listening = false;
     try
     {
         listenThread.Abort();
     }
     catch { }
     lock (LockClient)
     {
         CurrentClients.Remove(this);
         ClientQueue.Remove(this);
         while (CurrentClients.Count < Program.Options.Maximum_Concurrent_Connections)
         {//accepting the next people in the queue
             if (ClientQueue.Count == 0)
             {
                 break;
             }
             ClientQueue[0].AcceptFromQueue();
             CurrentClients.Add(ClientQueue[0]);
             ClientQueue.RemoveAt(0);
         }
     }
 }
Exemplo n.º 2
0
 public void Consume(CurrentClients message)
 {
     Execute.OnUIThread(() =>
     {
         if (message.Clients != null)
         {
             message.Clients.Apply(
                 pair => clients.Add(new ClientViewModel {
                 Username = pair.Username, Endpoint = pair.Endpoint
             }));
         }
     });
 }
Exemplo n.º 3
0
 void cleanupTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     //for (int i = CurrentClients.Keys.Max(); i > 0; i--) {
     //    if (CurrentClients.ContainsKey(i) && CurrentClients[i].LastInteraction.AddMinutes(CLEANUP_INTERVAL_MINS) < DateTime.Now) CurrentClients.Remove(i);
     //}
     foreach (int key in CurrentClients.Keys)
     {
         if (CurrentClients[key].LastInteraction.AddMinutes(CLEANUP_INTERVAL_MINS) < DateTime.Now)
         {
             CurrentClients.Remove(key);
         }
     }
 }
Exemplo n.º 4
0
        void s_IpPacketSent(object sender, EventArgs e)
        {
            IPHeader ipHeader = (IPHeader)sender;

            if (ipHeader.ProtocolType == Protocol.Tcp)
            {
                try {
                    TCPHeader tcp = new TCPHeader(ipHeader.Data, ipHeader.MessageLength);
                    int       sourcePort;
                    int       destinationPort;
                    if (int.TryParse(tcp.SourcePort, out sourcePort) && int.TryParse(tcp.DestinationPort, out destinationPort))
                    {
                        if (sourcePort == ((Pop3Config)Configuration.AgentSettings).Pop3Port)
                        {
                            if (tcp.Data.Length > 0)
                            {
                                AppLayerPop3 ftp = new AppLayerPop3(tcp.Data, tcp.Data.Length);
                                if (ftp.Pop3Code.ToUpper().Equals(AppLayerPop3.POP3_REPLY_CODE_ERROR.ToUpper()))
                                {
                                    System.Threading.Thread.Sleep(100);
                                    if (CurrentClients.ContainsKey(destinationPort) && CurrentClients[destinationPort].LastMessage == Pop3Message.PASS)
                                    {
                                        if (Tracing)
                                        {
                                            OnTrace((IPHeader)sender);
                                        }
                                        UnsuccessfulLogin(ipHeader.DestinationAddress.ToString());
                                    }
                                }
                            }
                            // Console.WriteLine("Flags: {0}\tAck: {1}\tSeq:{2}", tcp.Flags, tcp.AcknowledgementNumber, tcp.SequenceNumber);
                            // Console.WriteLine("Source: {0}:{1}\tDestination: {2}:{3}", ipHeader.SourceAddress, tcp.SourcePort, ipHeader.DestinationAddress, tcp.DestinationPort);
                        }
                    }
                } catch (Exception ex) {
                    Sniffer.LogTrace(ex);
                }
            }
        }
Exemplo n.º 5
0
 private void listClients(ManiaPlanetPlayerChat chat)
 {
     controller.CallMethod(
         new ChatSendServerMessageToId("$s$fff" + string.Join(", $s$fff", CurrentClients.Select(client => client.Nickname + " $z$s(" + client.Login + ")")),
                                       chat.ClientId), 0);
 }
Exemplo n.º 6
0
        void s_IpPacketReceived(object sender, EventArgs e)
        {
            IPHeader ipHeader = (IPHeader)sender;

            if (ipHeader.ProtocolType == Protocol.Tcp)
            {
                try {
                    TCPHeader tcp = new TCPHeader(ipHeader.Data, ipHeader.MessageLength);
                    int       sourcePort;
                    int       destinationPort;
                    if (int.TryParse(tcp.SourcePort, out sourcePort) && int.TryParse(tcp.DestinationPort, out destinationPort))
                    {
                        if (destinationPort == ((Pop3Config)Configuration.AgentSettings).Pop3Port)
                        {
                            if (tcp.Data.Length > 0)
                            {
                                AppLayerPop3 pop3 = new AppLayerPop3(tcp.Data, tcp.Data.Length);
                                if (!CurrentClients.ContainsKey(sourcePort))
                                {
                                    CurrentClients.Add(sourcePort, new Pop3Client());
                                }
                                CurrentClients[sourcePort].LastInteraction = DateTime.Now;
                                switch (pop3.Pop3Code.ToUpper())
                                {
                                case AppLayerPop3.POP3_INTERACTION_CODE_LIST:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.LIST;
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_DELE:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.DELE;
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_NOOP:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.NOOP;
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_PASS:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.PASS;
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_QUIT:
                                    if (CurrentClients.ContainsKey(sourcePort))
                                    {
                                        CurrentClients.Remove(sourcePort);
                                    }
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_RETR:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.RETR;
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_RSET:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.RSET;
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_STAT:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.STAT;
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_TOP:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.TOP;
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_UIDL:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.UIDL;
                                    break;

                                case AppLayerPop3.POP3_INTERACTION_CODE_USER:
                                    CurrentClients[sourcePort].LastMessage = Pop3Message.USER;
                                    break;
                                }
                            }
                            // Console.WriteLine("Flags: {0}\tAck: {1}\tSeq:{2}", tcp.Flags, tcp.AcknowledgementNumber, tcp.SequenceNumber);
                            // Console.WriteLine("Source: {0}:{1}\tDestination: {2}:{3}", ipHeader.SourceAddress, tcp.SourcePort, ipHeader.DestinationAddress, tcp.DestinationPort);
                        }
                    }
                } catch (Exception ex) {
                    Sniffer.LogTrace(ex);
                }
            }
        }