Public Class Connect
Public port As Integer
Public client As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Public Evento As New ManualResetEvent(False)
Public Delegate Sub arrivo(ByVal listener As user, ByVal copia As String)
Dim chiamata As New arrivo(AddressOf Form1.dataarrival)
Dim chiamata2 As New arrivo(AddressOf Form1.processdata)
Public Function bannaipbassolivello(ByVal ip As String, ByRef client As Socket) As Boolean
If IMPOSTAZIONI.arraysyn.Contains(ip) Then
Dim c As New firewall
c.ip = ip
client.Close()
If IMPOSTAZIONI.sottoattacco Then
c.manda = False
End If
c.banna()
protocol.connessionirifiutate += 1
Return True
Else
IMPOSTAZIONI.arraysyn.Add(ip)
End If
Return False
End Function
Public Sub bannasub(ByVal ip As String, ByRef chi As Socket)
Dim c As New firewall
c.ip = ip
chi.Close()
If IMPOSTAZIONI.sottoattacco Then
c.manda = False
End If
c.banna()
protocol.connessionirifiutate += 1
End Sub
Public Sub accetta(ByVal ar As IAsyncResult)
Evento.Set()
Try
Dim client As Socket = CType(ar.AsyncState, Socket).EndAccept(ar)
Dim ip As String
Try
ip = CType(client.RemoteEndPoint, IPEndPoint).Address.ToString
If (client.Available - 5) Mod 7 <> 0 And client.Available <> 0 Then
IMPOSTAZIONI.accettaint += 1
If IMPOSTAZIONI.arrayset(28) = False Then GoTo nulla
If IMPOSTAZIONI.accettaint > protezione.spoofing Then
If IMPOSTAZIONI.sottoattacco = False Then
IMPOSTAZIONI.sottoattacco = True
Dim b As New spoofing
b.porta = port
Dim thr As New Thread(AddressOf b.parti)
thr.Start()
End If
End If
bannasub(ip, client)
nulla:
Exit Sub
Else
If IMPOSTAZIONI.arrayset(29) Then
If bannaipbassolivello(ip, client) Then
Exit Sub
End If
End If
Dim us As New user
us.ip = ip
us.client = client
If IMPOSTAZIONI.banip Then
If Form1.controllasebannato(ip, us) Then
Form1.mandabot("Your IP Is Banned", us)
protocol.connessionirifiutate += 1
Form1.disconnettiuser(us)
Exit Sub
End If
End If
If IMPOSTAZIONI.arrayset(3) Then
If IMPOSTAZIONI.arrayprotected.Contains(us.ip) = False Then
Dim arr As New ArrayList
arr = IMPOSTAZIONI.users
Dim conto As Integer
For Each asd As user In arr
If asd.ip = us.ip Then
conto += 1
End If
Next
If conto > protezione.ip Then
Form1.mandabot("Il tuo IP č gia Presente in HUB", us)
Form1.altrobanip(us.ip)
Form1.mandaopchat("L'ip: " & us.ip & " č stato bannato, Double IP Control", us)
protocol.connessionirifiutate += 1
Form1.disconnettiuser(us)
Exit Sub
End If
End If
End If
If IMPOSTAZIONI.arrayset(12) Then
If IMPOSTAZIONI.arraysocks.Contains(us.ip) Then
Form1.mandabot("Non č Permesso l'uso dei Socks", us)
Form1.altrobanip(us.ip)
Form1.mandaopchat("L'ip: " & us.ip & " č stato bannato, Socks", us)
protocol.connessionirifiutate += 1
Form1.disconnettiuser(us)
Exit Sub
End If
End If
protocol.connessioniaccettate += 1
us.cod = creacodice()
Form1.send(us, "$Lock EXTENDEDPROTOCOL::This_hub_was_written_by_TeNeBrA::CTRL[NoKey] Pk=Colossus|")
Form1.send(us, "$Supports NoHello NoGetINFO UserIP2 BotINFO Feed MCTo|")
us.client.BeginReceive(us.ReadBuffer, 0, us.ReadBuffer.Length, SocketFlags.None, New AsyncCallback(AddressOf ricevi), us)
End If
Catch
protocol.connessionirifiutate += 1
client.Close()
End Try
Catch
protocol.connessionirifiutate += 1
client.Close()
End Try
End Sub
Public Function creacodice() As String
accapo: Randomize()
'da 65 a 90
Dim finale As String
For a As Integer = 0 To 3
ancora: Dim num As Integer = Math.Round(Rnd() * 90)
If num < 65 Then GoTo ancora
finale &= Chr(num)
Next
For Each controllo As user In IMPOSTAZIONI.users
If controllo.cod = finale Then GoTo accapo
Next
Return finale
End Function
Public Sub ricevi(ByVal ar As IAsyncResult)
Dim listener As user = CType(ar.AsyncState, user)
Try
Dim bytesRead As Integer = listener.client.EndReceive(ar)
If bytesRead > 0 Then
If listener.adc Then
listener.temp &= Encoding.UTF8.GetString(listener.ReadBuffer, 0, bytesRead)
Else
listener.temp &= Encoding.Default.GetString(listener.ReadBuffer, 0, bytesRead)
End If
If listener.temp.Contains("$MyNick") And listener.nick = "" Then
protocol.connessionirifiutate += 1
protocol.connessioniaccettate -= 1
Form1.disconnettiuser(listener)
IMPOSTAZIONI.accettaint += 1
bannasub(listener.ip, listener.client)
Exit Sub
End If
If listener.temp.StartsWith("HSUP ") And listener.temp.EndsWith(Chr(10)) Then
listener.adc = True
End If
If listener.adc Then
If listener.temp.EndsWith(Chr(10)) Then
IMPOSTAZIONI.bandaricevuta += bytesRead
protocol.bytericevuti += bytesRead
Dim copia As String = listener.temp.Clone
listener.temp = ""
chiamata2.BeginInvoke(listener, copia, New AsyncCallback(AddressOf nulla), chiamata)
End If
Else
If listener.temp.EndsWith("|") Then
IMPOSTAZIONI.bandaricevuta += bytesRead
protocol.bytericevuti += bytesRead
Dim copia As String = listener.temp.Clone
listener.temp = ""
chiamata.BeginInvoke(listener, copia, New AsyncCallback(AddressOf nulla), chiamata)
End If
End If
Else
Form1.disconnettiuser(listener)
Exit Sub
End If
prosegui: Threading.Thread.Sleep(10)
listener.client.BeginReceive(listener.ReadBuffer, 0, listener.ReadBuffer.Length, SocketFlags.None, New AsyncCallback(AddressOf ricevi), listener)
Catch
Form1.disconnettiuser(listener)
End Try
End Sub
Public Sub nulla()
End Sub
Public Function parti() As Boolean
Try
client.Bind(New IPEndPoint(IPAddress.Parse(IMPOSTAZIONI.ipparse), port))
client.Listen(IMPOSTAZIONI.nmrsockets)
Dim thr As New Thread(AddressOf circola)
thr.Start()
Return True
Catch
Return False
End Try
End Function
Public Sub circola()
On Error Resume Next
While (IMPOSTAZIONI.avviato)
Evento.Reset()
If Not IMPOSTAZIONI.avviato Then Exit While
If Not IMPOSTAZIONI.arrayporte.Contains(port.ToString) Then Exit While
client.BeginAccept(New AsyncCallback(AddressOf accetta), client)
Evento.WaitOne()
End While
client.Close()
Evento.Close()
End Sub
End Class