r/love2d • u/yughiro_destroyer • 4d ago
Securing an love2d-enet server?
Hello!
I'm writing a multiplayer game right now using enet. I have no library on top of it, I'm using basic, raw messages and I'm using the data pack functions all with a byte prefix to identify the type of message that's being sent/received.
So far, I can see some problems that might occur if I were to deploy the server on cloud VPS...
Here are some of them :
->Hackers polluting the server with tons of requests that are going to lag it or even increase my server costs because of the consumed resources.
->Hackers opening the client code and trying to bug or crash the server by sending wrong message identifiers.
About the first problem, I am expecting the VPS provider to block some suspicious activities (like mass attempts of connection) whilst I will enforce a limit of requests per second, else the server will kick the client for suspicious activity.
The second problem can be fixed by writing additional server code that makes sure wrong identifiers go through an exceptions check and that players don't skip any steps they shouldn't (else, instantly kicked).
Cheating wouldn't be a problem as the server will be fully authoritative, so the clients are ever sending are inputs and nothing more. Also the server will not give more information than necessary for the player to know in that moment.
Still, I expect to miss some edge cases.
Any suggestions?
2
u/HiIExists 3d ago edited 3d ago
If you are adding accounts be aware that you need encryptiom otherwise everyone can read passwords and personel data. Use a library for encryption for example lua-openssl (https://github.com/pixel-rider3467/lua-openssl).
1
u/QueasyPrior6654 4d ago
The edge case I'd check first is the unpack call itself. love.data.unpack throws a Lua error when a packet is shorter than the format expects, it doesn't return nil. So a truncated packet with a perfectly valid type byte gets past your identifier check and can take the whole server down.
I'd decode and validate each message inside
pcallbefore it touches any game state, and kick the peer if that step fails. Errors after that point are more likely your own bugs, so I'd log those rather than kick. Worth fuzzing it locally with random bytes after each valid prefix too.