[VB.NET] Extraire infos d'un tableau de byte()
Bonjour tout le monde,voila j'ai encore besoin de vous lool:
Je recois un tableau de byte() contenant des informations sur des joueurs d'un serveur, le tableau est constituer comme ceci:
Un entete contenant :
-byte Should be equal to 'D' (0x44)
-byte The number of players reported in this response
Ensuite pour chaque joueur est retourné:
-L'index du jouer en Byte
-Nom du joueur en string
-Nombre de kill du joueur en long
-Temps de connection en float
Je reussis à extraire une partie du nom du joueur ^^ (il y a des caractere bizarre devant le nom)ainsi que ses kill voici le code utiliser il est pas terrible mais bon :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Function ParsePlayer(ByVal receivedata() As Byte)
Dim index As Integer = 6
Dim phase As Integer = 1
Dim decoder As New ASCIIEncoding
For index = 6 To receivedata.Length
If phase = 1 Then
MessageBox.Show(Convert.ToInt32(receivedata(index)))
phase = 2
index = index + 1
End If
If phase = 2 Then
MessageBox.Show(decoder.GetString(receivedata, index, getNextIndex(receivedata, index) - index))
phase = 3
index = index + getNextIndex(receivedata, index) - index
End If
If phase = 3 Then
MessageBox.Show(Convert.ToUInt32(receivedata(index)))
phase = 4
index = index + 1
End If
If phase = 4 Then
MessageBox.Show(Convert.ToChar(receivedata(index)))
phase = 1
index = index + 1
End If
Next
Return TAB() |
A noter que jutiliser des messagebox pour mieux visualiser mais apres jutiliserai un tableau pour contenir tout ces infos.
Merci beaucoup :)