Closed rakiru closed 11 years ago
It would be better to make a bunch of functions which sends the packets on the Lua side, using the API that's in place, rather than to change the C-side API.
The C-side API itself is perfectly fine, I just need to fix net_pack / net_unpack so that they don't crash if someone deliberately drops dodgy packets down the line.
It'd be best if we had a register_packet function which took the direction (c->s, s->c) and (for c->s) a callback, and returned (for s->c) a lambda that you could call to send the packet. This way plugins can define their own packets without risk of collision, and we can remember SET_HEALTH_PACKET instead of 0x14.
OK, so we have a couple of stages refactored. I did say "finally finished" but you might want to consider declaring stuff like "function network.scratch_your_balls(x, y, z, speed)" and moving stuff to that. Having said that, it's pretty damn moddable now :)
Also, PKT_PLR_DAMAGE is what's used for setting the health. If the name isn't sane, grep and :%s/PLR_DAMAGE/SHIT_THAT_HURTS/g everything.
As this refactor doesn't answer the "define functions for sending stuff" side of things, I will leave this issue open.
Right now, sending data looks like this:
But what is "BBB"? What is 0x13? What data is supposed to be in that packet? Why must I pack it and send it manually rather than just sending it? What's that nil parameter for? Ideally, something like this would be best:
but even if the magic values were replaced with enums/constants, it would make the code a lot more readable.