aboutsummaryrefslogtreecommitdiff
path: root/musw.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2022-06-11 22:37:59 +0000
committerrodri <rgl@antares-labs.eu>2022-06-11 22:37:59 +0000
commitc69fa66f609925a98acf8dc7f645b9b50ce3a8ba (patch)
tree0246842728a85938e2ff074a160f11cabba3c049 /musw.c
parent0a15926abc589c372acf404765862bb22febd64d (diff)
downloadmusw-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.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/musw.c b/musw.c
index 70a8a4b..10ca01b 100644
--- a/musw.c
+++ b/musw.c
@@ -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");
}