Alright, since I have often wondered about the potential dangers of people connecting with a different client to my game to hack it, I decided to come up with a way for the server to check whether the player was using a proper client.
Basically, what this does is sends a packet & a string to the client as an 'acknowledgment' packet and a string attached to it, to make sure the client isn't just sending back a wrong 'received' packet.
The server gives the client 15 seconds to reply (15 seconds for reasons such as lag, slower computers, etc.) and if isn't received, it boots the player!
So basically, add this to your AccountRec :
Code:
LoginTimer as double
In the local non-saved variables section.
In modConstants, add this :
Code:
Public Const ACK_KEY as String = "6594sdfsd9r3"
REMEBMER TO CHANGE THE KEY TO YOUR OWN!Add this to the ClearPlayer sub :
Code:
Player(index).LoginTimer = 0
Now, in modGeneral, in the GameAI Sub add this :
Optimization Tip : Add the High Index to speed up the loop ;)Code:
For i = 1 To MAX_PLAYERS
If GetTickCountNew > (Player(i).LoginTimer + 15000) And Player(i).LoginTimer <> 0 And Player(i).Login <> "" Then
Call HackingAttempt(i, "Invalid Client!")
End If
Next i
Now, in modHandleData, in sub HandleData, add this anywhere (preferably near the top) :
Code:
' :::::::::::::::::::::::::::::::::::
' :: Acknowledge has been received ::
' :::::::::::::::::::::::::::::::::::
If LCase$(Parse(0)) = "ackrc" Then
if trim(parse(1)) <> ACK_KEY then
Call HackingAttempt(i, "Invalid Client!")
Exit Sub
end if
Player(index).LoginTimer = 0
Exit Sub
End If
As you can see, this checks to make sure you got the right key, if not invalids you. Now, look for the "login" packet, and near the end of the if case, right under :
Code:
Call SendChars(index)
Add this :
Code:
' Show the player up on the socket status
Call SendDataTo(index, "ackps" & SEP_CHAR & ACK_KEY & SEP_CHAR & END_CHAR)
Player(index).LoginTimer = GetTickCount
Now, that's it for the server code! Very simple code on the client side. Near the top of sub HandleData, just add this :
Code:
' ::::::::::::::::::::::::
' :: Acknowledge Packet ::
' ::::::::::::::::::::::::
If LCase(Parse(0)) = "ackps" Then
Call SendData("ackrc" & SEP_CHAR & trim(parse(1)) & SEP_CHAR & END_CHAR)
Exit Sub
End If
And there you go

Should work perfectly ^_^ If you have any questions or comments, just say/ask
