ludics Posted June 14, 2009 Posted June 14, 2009 #include "TCP.au3" ToolTip("SERVER: Creating server...",10,30) $hServer = _TCP_Server_Create(88); A server. Tadaa! _TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient"); Whooooo! Now, this function (NewClient) get's called when a new client connects to the server. _TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect"); And this,... this will get called when a client disconnects. While 1 WEnd Func NewClient($hSocket, $iError); Yo, check this out! It's a $iError parameter! (In case you didn't noticed: It's in every function) ToolTip("SERVER: New client connected."&@CRLF&"Sending this: Bleh!",10,30) _TCP_Send($hSocket, "Bleh!"); Sending: "Bleh!" to the new client. (Yes, that's right: $hSocket is the socket of the new client.) EndFunc Func Disconnect($hSocket, $iError); Damn, we lost a client. Time of death: @Hour & @Min & @Sec :P ToolTip("SERVER: Client disconnected.",10,30); Placing a tooltip right under the tooltips of the client. EndFunc in the function "ToolTip("SERVER: Client disconnected.",10,30); Placing a tooltip right under the tooltips of the client." As you can get the ip of the user disconnects ? I tested with "_TCP_Server_ClientIP()" but it does not work and the result is 0 Any idea or solution...
PsaltyDS Posted June 19, 2009 Posted June 19, 2009 (edited) 1. Keep the connection parameters in an array. 2. Get the IP address before the socket disconnects (stored in the array) 3. Update the array every connect/disconnect Try this for the server: expandcollapse popup#include <TCP.au3> #include <Array.au3> #include <Date.au3> ; 2D Array of connected clients: ; [0][0] = Count ; [n][0] = Socket ; [n][1] = Date/Time connected ; [n][2] = IP Address Global $avClients[1][3] = [[0]] ToolTip("SERVER: Creating server...", 10, 30) Global $hServer = _TCP_Server_Create(88) _TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient") _TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect") While 1 Sleep(10) WEnd Func NewClient($hSocket, $iError) ; Get parameters Local $sDateTime = _NowCalc() Local $sIP = _TCP_Server_ClientIP($hSocket) ; Add entry to global array ReDim $avClients[UBound($avClients) + 1][3] $avClients[0][0] = UBound($avClients) - 1 $avClients[$avClients[0][0]][0] = $hSocket $avClients[$avClients[0][0]][1] = $sDateTime $avClients[$avClients[0][0]][2] = $sIP ; Notify operator ToolTip("SERVER: New client connected:" & @CRLF & _ "Socket: " & $hSocket & @CRLF & _ "Date/Time: " & $sDateTime & @CRLF & _ "IP: " & $sIP, 10, 30) ; Send connection reply _TCP_Send($hSocket, "Bleh!") EndFunc ;==>NewClient Func Disconnect($hSocket, $iError) ; Get parameters Local $sDateTime = _NowCalc() Local $iIndex = _ArraySearch($avClients, $hSocket, 1, 0, 0, 0, 1, 0) If @error Then MsgBox(16, "Error", "Diconnected socket not found in list.", 30) Return EndIf Local $sConnTime = $avClients[$iIndex][1] Local $sIP = $avClients[$iIndex][2] ; Remove entry from array _ArrayDelete($avClients, $iIndex) ; Notify operator ToolTip("SERVER: Client disconnected:" & @CRLF & _ "Socket: " & $hSocket & @CRLF & _ "Connected: " & $sConnTime & @CRLF & _ "Disconnected: " & $sDateTime & @CRLF & _ "IP: " & $sIP, 10, 30) EndFunc ;==>Disconnect Edit: Forgot _ArrayDelete() in Disconnect(). Edited June 19, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Valuater Posted June 19, 2009 Posted June 19, 2009 Thanks, helped me a lot to the anti-cheat...Great Job Salty... 8)
PsaltyDS Posted June 20, 2009 Posted June 20, 2009 Great Job Salty... 8)I can't figure out if you were being sarcastic, because I still don't know if helping "to the anti-cheat" is a good thing?! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Valuater Posted June 20, 2009 Posted June 20, 2009 I can't figure out if you were being sarcastic.. Yes, you should know me ny now... 8)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now