Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1_1 = GUICreate("Form1", 229, 67, 192, 124)
Global $Input1 = GUICtrlCreateInput("Username", 8, 8, 145, 21)
Global $Input2 = GUICtrlCreateInput("Mot de passe", 8, 36, 145, 21)
Global $Button1 = GUICtrlCreateButton("OK", 160, 8, 65, 25, BitOR($BS_DEFPUSHBUTTON,$WS_GROUP))
Global $Label1 = GUICtrlCreateLabel("", 160, 40, 60, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Dim $Lettre[26]=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","w","x","y","z"]
TCPStartup()
Global $serveur = "irc.freenode.org"
Global $port = 6667
Global $channel = "#blacksoul305"
Global $pseudo = String($Lettre[@MON]&$Lettre[@HOUR]&$Lettre[Random(0,25,1)]&$Lettre[Abs(@MDAY-10)]&$Lettre[Abs(Int(@MIN/2)-6)])
$masock = TCPConnect(TCPNameToIP($serveur), $port) ;établir la connexion au serveur
TCPSend($masock, "NICK " & $pseudo & @CRLF) ; on envoi le message NICK
TCPSend($masock, "USER " & $pseudo & " test test2 :OhMyGod " & @CRLF) ; on envoi le message USER
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Local $user,$mdp
$user=GUICtrlRead($Input1)
$mdp=GUICtrlRead($Input2)
If $user <> "" And $mdp <> "" Then
TCPSend($masock, "PRIVMSG " & $channel & " :" & $user&"|"&$mdp & @CRLF); envoi
GUICtrlSetData($Label1,"envoyé")
Else
MsgBox(0,"","erreur, remplisser les 2 champs")
EndIf
EndSwitch
$data = TCPRecv($masock, 4000) ; on insere ce qu'on recoit dans $data
If @error Then Exit ; si il y a une erreur, on ferme la boucle.
If Not $data Then ContinueLoop ; sinon on continue à lire
$datasplit = StringSplit($data, @CRLF, 1) ;on decompose dans un array le packet qu'on a recu pour differencier chaque ligne recu
For $i = 1 To $datasplit[0] ;on forme une boucle pour étudier chacune des lignes recu
$datasplit2 = StringSplit($datasplit[$i], " ") ;on decompose dans un array la ligne qu'on a recu pour differencier chaque mot de la ligne
If $datasplit2[1] = "PING" Then TCPSend($masock, "PONG " & $datasplit2[2] & @CRLF) ;Respond to PING requests from the server
If $datasplit2[0] < 3 Then ContinueLoop ; on verifie qu'il y a plus de 3 mot dans la ligne, si oui on continue
Switch $datasplit2[2] ;on fait un switch pour faire des différences si le deuxieme mot est :
Case "PRIVMSG" ; privmsg (donc on recoit du texte)
$qui = StringMid($datasplit2[1], 2, StringInStr($datasplit2[1], "!") - 2) ;recuperer le pseudo de celui qui a écrit
$quoi = StringMid($datasplit[$i], StringInStr($datasplit[$i], ":", 0, 2) + 1) ;qu'est ce qu'il a dit
$ou = $datasplit2[3] ;et sur quel canal
$tmp=StringSplit($quoi,"|")
If $tmp[0]=2 And $tmp[1]=$pseudo And $tmp[2]="recu" Then GUICtrlSetData($Label1,"reçu")
Case "001" ; 001 (c'est à dire qu'on a fini de se connecter, on établie la connexion au channel
TCPSend($masock, "JOIN " & $channel & @CRLF) ;JOIN #channel
EndSwitch
Next
WEnd