Bonjour tout le monde,
Je travaille actuellement sur un bot total socket/MITM et j'ai un problème lors de la connexion au serveur de jeu (après avoir sélectionné le serveur).
Voici la class Network :
Cliquez pour révéler
Cliquez pour masquer
Imports System
Imports System.Collections.Generic
Imports System.Net.Sockets
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports System.Threading
Imports SafnCueAPI
Imports SafnCueAPI.Network
Imports System.Text
Imports System.Net
Imports SafnCueAPI.Dofus.Network.Messages.Connection
Public Class Network
Implements INetwork
Public Property mAccount As AccountFrm
Public Property MITM As Boolean = False
Public Sub New(ByVal Account As AccountFrm)
mAccount = Account
End Sub
Public Sub New(ByVal Account As AccountFrm, ByVal Socket_Client As Socket)
mAccount = Account
MITM = True
mSocket_Client = Socket_Client
StartReception()
End Sub
Private Sub Reception()
Try
While Is_Connected_Account ' On reçoit les données tant qu'on est connecté.
If Socket_Server.Connected And Socket_Server.Available <> 0 Then 'Si des données doivent être envoyées
ParseData(Socket_Server, Events.PACKET_ORIGIN.SERVER)
End If
If MITM Then 'Si le client dofus est connecté
If mSocket_Client.Connected And mSocket_Client.Available <> 0 Then 'Si des données doivent être envoyées
ParseData(mSocket_Client, Events.PACKET_ORIGIN.CLIENT)
End If
End If
End While
Catch Ex As Exception
mAccount.Log(Ex.ToString, LogType.ERREUR)
End Try
Is_Connected_Account = False
mAccount.Log("Compte déconnecté", LogType.ALERTE)
Me.Socket_Server.Dispose()
If MITM Then
Me.mSocket_Client.Dispose()
End If
Try
mAccount.Invoke(New DelegNothing(AddressOf mAccount.ReEnabledConnexion))
Catch ex As Exception
End Try
End Sub
Private Function ArrayByteConcatenation(ByVal t1 As Byte(), ByVal t2 As Byte()) As Byte()
Dim t3(t1.Length + t2.Length - 1) As Byte
Array.Copy(t1, 0, t3, 0, t1.Length)
Array.Copy(t2, 0, t3, t1.Length, t2.Length)
Return t3
End Function
Private Sub ParseData(DataSocket As Socket, ByVal Origin As Events.PACKET_ORIGIN)
' Déclaration des variables qui seront utilisées
Dim packet_header As Short
Dim packet_id As Short
Dim packet_lenght_type As Byte
Dim packet_lenght As Int32 = 0
Dim packet_content As Byte()
Dim DataToSend As Byte() = New Byte() {}
' Décodage du header
Dim buffer As Byte() = New Byte(2 - 1) {}
DataSocket.Receive(buffer, 2, SocketFlags.None)
DataToSend = ArrayByteConcatenation(DataToSend, buffer)
Dim content As New DataReader(buffer)
packet_header = content.readShort()
' Récupérer l'ID du paquet
packet_id = CShort(packet_header >> 2)
packet_lenght_type = CShort(packet_header And 3)
' Récupération de la taille du paquet
Select Case packet_lenght_type
Case 0
packet_lenght = 0
Exit Select
Case 1
buffer = New Byte(1 - 1) {}
DataSocket.Receive(buffer, 1, SocketFlags.None)
DataToSend = ArrayByteConcatenation(DataToSend, buffer)
content = New DataReader(buffer)
packet_lenght = content.readByte
Exit Select
Case 2
buffer = New Byte(2 - 1) {}
DataSocket.Receive(buffer, 2, SocketFlags.None)
DataToSend = ArrayByteConcatenation(DataToSend, buffer)
content = New DataReader(buffer)
packet_lenght = content.readShort()
Exit Select
Case 3
buffer = New Byte(3 - 1) {}
DataSocket.Receive(buffer, 3, SocketFlags.None)
DataToSend = ArrayByteConcatenation(DataToSend, buffer)
content = New DataReader(buffer)
packet_lenght = content.readShort()
Exit Select
End Select
' Récupération du contenu du paquet
packet_content = New Byte(packet_lenght - 1) {}
DataSocket.Receive(packet_content, packet_lenght, SocketFlags.None)
DataToSend = ArrayByteConcatenation(DataToSend, packet_content)
' Jounalisation
If Origin = Events.PACKET_ORIGIN.CLIENT Then
mAccount.Log("<CLIENT →BOT>" & "[" & packet_id & "] " & mAccount.mBot.GetClasseName(packet_id), LogType.DEBUG)
Else
mAccount.Log("<SERVEUR→BOT>" & "[" & packet_id & "] " & mAccount.mBot.GetClasseName(packet_id), LogType.DEBUG)
End If
' Traitement du paquet
Dim IsCancelled As Boolean = False
For Each [RegisterFunction] In GetListFunctionOrderRegister(packet_id)
Dim e As New PacketTransition
e.v_Id = packet_id
e.v_Packet = New DataReader(packet_content)
e.v_Origin = Origin
e.v_IsCancelled = False
mAccount.Invoke(New DelegDouble(AddressOf [RegisterFunction].Invoke), Me, e)
If e.IsCancelled Then
IsCancelled = True
End If
Next
If Not IsCancelled Then 'Si on ne doit pas annuler le traitement du message
TransfertPacket(Origin, DataToSend)
For Each [MonitorFunction] In GetListFunctionOrderMonitor(packet_id)
Dim e As New PacketTransition
e.v_Id = packet_id
e.v_Packet = New DataReader(packet_content)
e.v_Origin = Origin
e.v_IsCancelled = False
mAccount.Invoke(New DelegDouble(AddressOf [MonitorFunction].Invoke), Me, e)
Next
End If
End Sub
Private Sub TransfertPacket(ByVal Origin As Events.PACKET_ORIGIN, ByVal DataToParse As Byte())
If MITM Then 'On fait communiquer le client et le serveur ici ↓
If Origin = Events.PACKET_ORIGIN.CLIENT Then
Socket_Server.Send(DataToParse)
Else
mSocket_Client.Send(DataToParse)
End If
End If
End Sub
Public Sub RestartReception(ByVal IP As String, ByVal Port As Integer)
Me.Socket_Server.Disconnect(True)
Me.Socket_Server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Me.Socket_Server.Connect(IP, Port)
End Sub
Public Sub RestartReceptionMITM(ByVal SelectedServerDataMessage As SelectedServerDataMessage)
mAccount.Log("Déconnexion du serveur de connexion.", LogType.INFO)
Me.Socket_Server.Disconnect(True)
Me.Socket_Server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Me.Socket_Server.Connect(SelectedServerDataMessage.Address, SelectedServerDataMessage.Port)
mAccount.Log("Connexion au serveur de jeu effectuée.", LogType.INFO)
Dim pack As New SelectedServerDataMessage
pack.Address = "127.0.0.2"
pack.Port = 5555
pack.CanCreateNewCharacter = SelectedServerDataMessage.CanCreateNewCharacter
pack.ServerId = SelectedServerDataMessage.ServerId
pack.Ticket = SelectedServerDataMessage.Ticket
SendMessageToClient(pack)
mAccount.Log("Déconnexion du client.", LogType.INFO)
Me.mSocket_Client.Disconnect(True)
Dim DofusClientListener As New TcpListener(IPAddress.Parse("127.0.0.2"), 5555)
DofusClientListener.Start()
For i As Integer = 0 To 500 'On attend 5 sec que le client se reconnecte, si il ne le fait pas, on abandonne
If DofusClientListener.Pending Then
mSocket_Client = DofusClientListener.AcceptSocket
DofusClientListener.Stop()
mAccount.Log("Connexion au client effectuée.", LogType.INFO)
Exit For
End If
Thread.Sleep(10)
Next
End Sub
Public Sub SendMessageToServer(<Dynamic()> ByVal Pack As Object) Implements INetwork.SendMessageToServer
If Is_Connected_Account Then
Dim writer As New DataWriter
Pack.Serialize(writer)
mAccount.Log("<BOT→SERVEUR>[" & Convert.ToInt32(Pack.GetType.GetField("ProtocolID").GetValue(Pack)).ToString & "] " & Convert.ToString(Pack.GetType.GetField("ProtocolName").GetValue(Pack)).ToString, LogType.DEBUG)
Try
Me.Socket_Server.Send(writer.Pack(Convert.ToInt32(Pack.GetType.GetField("ProtocolID").GetValue(Pack))))
Catch
StopReception()
End Try
End If
End Sub
Public Sub SendMessageToClient(<Dynamic()> ByVal Pack As Object) Implements INetwork.SendMessageToClient
If Is_Connected_Account And MITM Then
Dim writer As New DataWriter
Pack.Serialize(writer)
mAccount.Log("<BOT→ CLIENT>[" & Convert.ToInt32(Pack.GetType.GetField("ProtocolID").GetValue(Pack)).ToString & "] " & Convert.ToString(Pack.GetType.GetField("ProtocolName").GetValue(Pack)).ToString, LogType.DEBUG)
Try
Me.mSocket_Client.Send(writer.Pack(Convert.ToInt32(Pack.GetType.GetField("ProtocolID").GetValue(Pack))))
Catch
StopReception()
End Try
End If
End Sub
Public Sub StartReception()
Me.Socket_Server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Me.Socket_Server.Connect("213.248.126.180", 5555)
Is_Connected_Account = Socket_Server.Connected
Thread_Account = New Thread(New ThreadStart(Sub() Reception()))
Thread_Account.Start()
End Sub
Public Sub StopReception() Implements INetwork.StopReception
Is_Connected_Account = False
Socket_Server.Disconnect(True)
Thread.Sleep(50)
End Sub
Private Function GetListFunctionOrderMonitor(ByVal IdPaquet As Integer) As List(Of Events.DelegPacketTransition) 'Classe les fonction
Dim ListeFonction As New List(Of Events.DelegPacketTransition)
Dim ListePriorite As New List(Of Events.Priority)
Dim index As Integer = 0
For Each id In mAccount.v_Network.MonitorListId 'Vérification de l'ID
If id = IdPaquet Then
ListeFonction.Add(mAccount.v_Network.MonitorListFunction(index))
ListePriorite.Add(mAccount.v_Network.MonitorListPriority(index))
End If
index += 1
Next
Dim ListeFonctionRangee As New List(Of Events.DelegPacketTransition)
For i As Integer = Events.Priority.VERY_HIGH To Events.Priority.VERY_LOW Step -1 'Trie en fonction des priorité
For j As Integer = 0 To ListeFonction.Count - 1
If i = ListePriorite(j) Then
ListeFonctionRangee.Add(ListeFonction(j))
End If
Next
Next
Return ListeFonctionRangee
End Function
Private Function GetListFunctionOrderRegister(ByVal IdPaquet As Integer) As List(Of Events.DelegPacketTransition) 'Classe les fonction
Dim ListeFonction As New List(Of Events.DelegPacketTransition)
Dim ListePriorite As New List(Of Events.Priority)
Dim index As Integer = 0
For Each id In mAccount.v_Network.RegisterListId 'Vérification de l'ID
If id = IdPaquet Then
ListeFonction.Add(mAccount.v_Network.RegisterListFunction(index))
ListePriorite.Add(mAccount.v_Network.RegisterListPriority(index))
End If
index += 1
Next
Dim ListeFonctionRangee As New List(Of Events.DelegPacketTransition)
For i As Integer = Events.Priority.VERY_HIGH To Events.Priority.VERY_LOW Step -1 'Trie en fonction des priorité
For j As Integer = 0 To ListeFonction.Count - 1
If i = ListePriorite(j) Then
ListeFonctionRangee.Add(ListeFonction(j))
End If
Next
Next
Return ListeFonctionRangee
End Function
' Fields
Private Property Socket_Server As Socket
Private Property mSocket_Client As Socket
Private Property Thread_Account As Thread
Public Property Is_Connected_Account As Boolean
Private Delegate Sub DelegDouble(ByVal arg As Object, ByVal arg2 As Object)
Private Delegate Sub DelegNothing()
End Class
Voici la seul fonction des RegisterFonctions :
Cliquez pour révéler
Cliquez pour masquer
Private Sub OnReceive_SelectedServerDataMessageMITM(ByVal sender As Object, ByVal e As IPacketTransition)
Dim SelectedServerDataMessage As New SelectedServerDataMessage() '42
SelectedServerDataMessage.Deserialize(e.Packet)
v_Network.v_ServerSocket.RestartReceptionMITM(SelectedServerDataMessage)
e.IsCancelled = True
End Sub
Comme vous le constatez, après la reconnexion, le client n'envoie pas le message d'autentification...
Merci d'avance pour votre aide :)
Edit : Résolu, voir mon dernier post pour plus d'info