diff options
author | rodri <rgl@antares-labs.eu> | 2022-06-15 19:57:31 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2022-06-15 19:57:31 +0000 |
commit | b69fdfbf30beb998c1817784e748ae78806becf8 (patch) | |
tree | 51e27ffc4cad89924c73e1e82d8b0dc6102f7a53 | |
parent | c69fa66f609925a98acf8dc7f645b9b50ce3a8ba (diff) | |
download | musw-b69fdfbf30beb998c1817784e748ae78806becf8.tar.gz musw-b69fdfbf30beb998c1817784e748ae78806becf8.tar.bz2 musw-b69fdfbf30beb998c1817784e748ae78806becf8.zip |
some corrections to frame processing and nomenclatures.
-rw-r--r-- | dat.h | 3 | ||||
-rw-r--r-- | musw.c | 24 | ||||
-rw-r--r-- | muswd.c | 13 | ||||
-rw-r--r-- | pack.c | 4 |
4 files changed, 21 insertions, 23 deletions
@@ -24,7 +24,8 @@ enum { }; enum { - Framesize = 4+4+4+2, + Framehdrsize = 4+4+4+2, + MTU = 1024 }; typedef struct VModel VModel; @@ -33,7 +33,7 @@ ulong kdown; RFrame screenrf; Universe *universe; -VModel *needlemdl; +VModel *needlemdl, *wedgemdl; Image *skymap; Channel *kchan; char winspec[32]; @@ -217,7 +217,7 @@ threadnetrecv(void *arg) void threadnetsend(void *arg) { - uchar buf[1024]; + uchar buf[MTU]; int fd, n; ulong kdown; Frame *frame; @@ -225,17 +225,18 @@ threadnetsend(void *arg) fd = *(int*)arg; frame = emalloc(sizeof(Frame)+sizeof(kdown)); frame->udp = nil; - frame->seq = 223; - frame->ack = 222; - frame->id = ntruerand(100); + frame->seq = ntruerand(1000)>>1; + frame->ack = 0; + frame->id = truerand(); frame->len = sizeof(kdown); for(;;){ kdown = recvul(kchan); - frame->data[0] = kdown>>24; - frame->data[1] = kdown>>16; - frame->data[2] = kdown>>8; - frame->data[3] = kdown; + + frame->seq++; + + pack(frame->data, frame->len, "k", kdown); + n = pack(buf, sizeof buf, "F", frame); if(write(fd, buf, n) != n) sysfatal("write: %r"); @@ -376,8 +377,11 @@ threadmain(int argc, char *argv[]) needlemdl = readvmodel("assets/mdl/needle.vmdl"); if(needlemdl == nil) sysfatal("readvmodel: %r"); + wedgemdl = readvmodel("assets/mdl/wedge.vmdl"); + if(wedgemdl == nil) + sysfatal("readvmodel: %r"); universe->ships[0].mdl = needlemdl; - universe->ships[1].mdl = needlemdl; + universe->ships[1].mdl = wedgemdl; universe->star.spr = readsprite("assets/spr/earth.pic", ZP, Rect(0,0,32,32), 5, 20e3); initskymap(); @@ -15,12 +15,11 @@ Lobby *lobby; void threadlisten(void *arg) { - uchar buf[1024], *p, *e; + uchar buf[MTU], *p, *e; int fd, n; ushort rport, lport; ulong kdown; Ioproc *io; -// Udphdr *udp; Frame *frame; fd = *(int*)arg; @@ -28,10 +27,6 @@ threadlisten(void *arg) frame = emalloc(sizeof(Frame)); while((n = ioread(io, fd, buf, sizeof buf)) > 0){ -// if(n < Udphdrsize) -// continue; -// -// udp = (Udphdr*)buf; p = buf; e = buf+n; @@ -39,10 +34,8 @@ threadlisten(void *arg) rport = frame->udp->rport[0]<<8 | frame->udp->rport[1]; lport = frame->udp->lport[0]<<8 | frame->udp->lport[1]; - kdown = frame->data[0]<<24| - frame->data[1]<<16| - frame->data[2]<<8| - frame->data[3]; + + unpack(frame->data, frame->len, "k", &kdown); if(debug) fprint(2, "%I!%d → %I!%d | %d (%d) rcvd seq %ud ack %ud id %ud len %ud %.*lub\n", @@ -74,7 +74,7 @@ vpack(uchar *p, int n, char *fmt, va_list a) case 'F': F = va_arg(a, Frame*); - if(p+Framesize+F->len > e) + if(p+Framehdrsize+F->len > e) goto err; put4(p, F->seq), p += 4; @@ -129,7 +129,7 @@ vunpack(uchar *p, int n, char *fmt, va_list a) break; case 'F': - if(p+Udphdrsize+Framesize > e) + if(p+Udphdrsize+Framehdrsize > e) goto err; F = va_arg(a, Frame*); |