Un ami m'a fait découvrir purebasic et cette après midi j'ai commencer a programmer en purebasic.
Alors voila c'est simplement un programme qui se connecte a un serveur Counter Strike en UDP et qui récupère les informations du serveur (joueurs,nom,etc)
Il se met a jours a toute les deux secondes grace a un timer
J'aimerais avoir tout vos commentaires, améliorations et critiques

Code : Tout sélectionner
Global i,ip.s,port,*Buffer,String$,CRLF.s,ConnectionID
Declare Populate()
Declare ForceRefresh()
*Buffer = AllocateMemory(10000)
CRLF.s = Chr(13)+Chr(10)
ip.s = "e3b.org"
ip.s = "69.9.47.28"
port = 27015
If InitNetwork() = 0
MessageRequester("Erreur!!", "Impossible d'initialisé la couche réseau!", 0) : End
EndIf
If OpenWindow(0, 300, 300, 420, 160, "PureCSS",#PB_Window_MinimizeGadget)
AddSysTrayIcon(0, WindowID(0), LoadImage(0, "aa.ico"))
StickyWindow(0,1)
SysTrayIconToolTip(0,"Counter Strike: Source Monitor")
EndIf
CreateGadgetList(WindowID(0))
TextGadget(1, 10, 8, 100, 140, "Serveur non connecté")
TextGadget(2, 120, 8, 400, 140, "Serveur non connecté")
SetTimer_(WindowID(0), 0, 2000, @ForceRefresh())
ConnectionID=OpenNetworkConnection(ip.s, port, #PB_Network_UDP)
ForceRefresh()
Repeat
WEvent = WindowEvent()
CEvent = NetworkClientEvent(ConnectionID)
If CEvent=2
Populate()
Else
Delay(20)
EndIf
If WEvent=#PB_Event_SysTray
SetWindowState(0,#PB_Window_Normal)
HideWindow(0,0)
ElseIf WindowY(0)<0
HideWindow(0,1)
ElseIf WEvent=256 And (GetAsyncKeyState_(#VK_ESCAPE) & 32768)
HideWindow(0,1)
EndIf
Until WEvent = #PB_Event_CloseWindow
CloseNetworkConnection(ConnectionID)
End
Procedure NextString()
While ((PeekB(*Buffer+i)<>0))
i=i+1
Wend
String$=PeekS(*Buffer+i+1,300)
i=i+1
EndProcedure
Procedure Populate()
length=ReceiveNetworkData(ConnectionID,*Buffer,2000)
String$=PeekS(*Buffer,length)
i=0
If (Mid(String$,0,4)=Chr(255)+Chr(255)+Chr(255)+Chr(255))
NomServeur.s=Mid(String$,7,Len(String$)) ;Nom serveur
NextString()
NomMap.s=String$ ;La map
NextString()
Repertoire.s=String$ ;repertoire
NextString()
NomJeu.s=String$ ;Nom du jeu
NextString()
; SkipShort:
i=i+2 ;On saute le appID pas besoin
NumPlayer=PeekB(*Buffer+i) ;Nombre de joueurs
i=i+1
MaxPlayer=PeekB(*Buffer+i) ;Nombre de joueurs maximum
i=i+1
NumBot=PeekB(*Buffer+i) ;Nombre de bots
i=i+1
Select Chr(PeekB(*Buffer+i)) ;Type de serveur
Case "l"
ServerType.s="Listen"
Case "d"
ServerType.s="Dédié"
Case "p"
ServerType.s="SourceTV"
EndSelect
i=i+1
Select Chr(PeekB(*Buffer+i)) ;Systeme d'exploitation du serveur
Case "w"
ServerOS.s="Windows"
Case "l"
ServerOS.s="Linux"
EndSelect
i=i+1
text$ = text$ + "Nom du serveur: " + CRLF + "Nom de la Carte: " + CRLF
text$ = text$ + "Repertoire: " + CRLF + "Nom du jeu: " + CRLF
text$ = text$ + "Joueurs: " + CRLF + "Bots: " + CRLF
text$ = text$+"Type: " + CRLF + "Systeme: " + CRLF
SetGadgetText(1,text$ + CRLF + "Timer: " + CRLF)
text$ = NomServeur+CRLF + NomMap+CRLF
text$ = text$ + Repertoire+CRLF + NomJeu+CRLF
text$ = text$ + Str(NumPlayer)+"/"+Str(MaxPlayer)+CRLF
text$ = text$ + Str(NumBot)+CRLF+ServerType.s+CRLF+ServerOS.s+CRLF
SetGadgetText(2,text$ + CRLF+ Str(ElapsedMilliseconds()))
EndIf
EndProcedure
Procedure ForceRefresh()
If ConnectionID
PokeL(*Buffer, -1)
PokeS(*Buffer+4,"TSource Engine Query" ,20)
SendNetworkData(ConnectionID,*Buffer,24)
EndIf
EndProcedure