diff options
author | rodri <rgl@antares-labs.eu> | 2022-06-11 22:37:59 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2022-06-11 22:37:59 +0000 |
commit | c69fa66f609925a98acf8dc7f645b9b50ce3a8ba (patch) | |
tree | 0246842728a85938e2ff074a160f11cabba3c049 /musw.c | |
parent | 0a15926abc589c372acf404765862bb22febd64d (diff) | |
download | musw-c69fa66f609925a98acf8dc7f645b9b50ce3a8ba.tar.gz musw-c69fa66f609925a98acf8dc7f645b9b50ce3a8ba.tar.bz2 musw-c69fa66f609925a98acf8dc7f645b9b50ce3a8ba.zip |
implemented a custom PDU/frame structure on top of UDP for game networking.
Diffstat (limited to 'musw.c')
-rw-r--r-- | musw.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -1,5 +1,6 @@ #include <u.h> #include <libc.h> +#include <ip.h> #include <bio.h> #include <thread.h> #include <draw.h> @@ -219,12 +220,23 @@ threadnetsend(void *arg) uchar buf[1024]; int fd, n; ulong kdown; + Frame *frame; fd = *(int*)arg; + frame = emalloc(sizeof(Frame)+sizeof(kdown)); + frame->udp = nil; + frame->seq = 223; + frame->ack = 222; + frame->id = ntruerand(100); + frame->len = sizeof(kdown); for(;;){ kdown = recvul(kchan); - n = pack(buf, sizeof buf, "k", kdown); + frame->data[0] = kdown>>24; + frame->data[1] = kdown>>16; + frame->data[2] = kdown>>8; + frame->data[3] = kdown; + n = pack(buf, sizeof buf, "F", frame); if(write(fd, buf, n) != n) sysfatal("write: %r"); } |