iamgreaser / iceball

Open-source rewrite of the VOXLAP version of Ace of Spades.
http://iceball.build
GNU General Public License v3.0
114 stars 32 forks source link

Make netcode more sensible #3

Closed rakiru closed 11 years ago

rakiru commented 11 years ago

Right now, sending data looks like this:

common.net_send(nil, common.net_pack("BBB", 0x13, hurt_idx, hurt_part_idx))

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:

common.net_send_hit(hurt_idx, hurt_part_idx)

but even if the magic values were replaced with enums/constants, it would make the code a lot more readable.

iamgreaser commented 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.

BR- commented 11 years ago

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.

iamgreaser commented 11 years ago

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.