diff options
-rw-r--r-- | dat.h | 18 | ||||
-rw-r--r-- | lobby.c | 1 | ||||
-rw-r--r-- | musw.c | 14 | ||||
-rw-r--r-- | muswd.c | 29 | ||||
-rw-r--r-- | pack.c | 49 | ||||
-rw-r--r-- | party.c | 1 | ||||
-rw-r--r-- | physics.c | 1 | ||||
-rw-r--r-- | sprite.c | 1 | ||||
-rw-r--r-- | universe.c | 1 |
9 files changed, 102 insertions, 13 deletions
@@ -23,6 +23,10 @@ enum { SCRHB = SCRH+2*Borderwidth }; +enum { + Framesize = 4+4+4+2, +}; + typedef struct VModel VModel; typedef struct Sprite Sprite; typedef struct Particle Particle; @@ -31,9 +35,11 @@ typedef struct Ship Ship; typedef struct Star Star; typedef struct Universe Universe; typedef struct Derivative Derivative; + +typedef struct Frame Frame; typedef struct Conn Conn; -typedef struct Player Player; typedef struct PInput PInput; +typedef struct Player Player; typedef struct Lobby Lobby; typedef struct Party Party; @@ -111,6 +117,16 @@ struct Derivative Point2 dv; /* a */ }; +struct Frame +{ + Udphdr *udp; + uint seq; + uint ack; + uint id; + ushort len; + uchar data[]; +}; + struct Conn { char dir[40]; @@ -1,5 +1,6 @@ #include <u.h> #include <libc.h> +#include <ip.h> #include <draw.h> #include "libgeometry/geometry.h" #include "dat.h" @@ -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"); } @@ -20,26 +20,33 @@ threadlisten(void *arg) ushort rport, lport; ulong kdown; Ioproc *io; - Udphdr *udp; +// Udphdr *udp; + Frame *frame; fd = *(int*)arg; io = ioproc(); + frame = emalloc(sizeof(Frame)); while((n = ioread(io, fd, buf, sizeof buf)) > 0){ - if(n < Udphdrsize) - continue; - - udp = (Udphdr*)buf; - p = buf+Udphdrsize; +// if(n < Udphdrsize) +// continue; +// +// udp = (Udphdr*)buf; + p = buf; e = buf+n; - rport = udp->rport[0]<<8 | udp->rport[1]; - lport = udp->lport[0]<<8 | udp->lport[1]; + unpack(p, e-p, "F", frame); + + 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(p, e-p, "k", &kdown); if(debug) - fprint(2, "%I!%d → %I!%d | %d (%d) rcvd %.*lub\n", - udp->raddr, rport, udp->laddr, lport, threadid(), getpid(), sizeof(kdown)*8, kdown); + fprint(2, "%I!%d → %I!%d | %d (%d) rcvd seq %ud ack %ud id %ud len %ud %.*lub\n", + frame->udp->raddr, rport, frame->udp->laddr, lport, threadid(), getpid(), frame->seq, frame->ack, frame->id, frame->len, sizeof(kdown)*8, kdown); } closeioproc(io); } @@ -1,10 +1,23 @@ #include <u.h> #include <libc.h> +#include <ip.h> #include <draw.h> #include "libgeometry/geometry.h" #include "dat.h" #include "fns.h" +static ushort +get2(uchar *p) +{ + return p[0]<<8 | p[1]; +} + +static void +put2(uchar *p, ushort u) +{ + p[0] = u>>8, p[1] = u; +} + static ulong get4(uchar *p) { @@ -24,6 +37,7 @@ vpack(uchar *p, int n, char *fmt, va_list a) ulong k; FPdbleword d; Point2 P; + Frame *F; for(;;){ switch(*fmt++){ @@ -57,6 +71,19 @@ vpack(uchar *p, int n, char *fmt, va_list a) put4(p, k), p += 4; break; + case 'F': + F = va_arg(a, Frame*); + + if(p+Framesize+F->len > e) + goto err; + + put4(p, F->seq), p += 4; + put4(p, F->ack), p += 4; + put4(p, F->id), p += 4; + put2(p, F->len), p += 2; + memmove(p, F->data, F->len), p += F->len; + + break; } } err: @@ -70,6 +97,7 @@ vunpack(uchar *p, int n, char *fmt, va_list a) ulong k; FPdbleword d; Point2 P; + Frame *F; for(;;){ switch(*fmt++){ @@ -100,6 +128,27 @@ vunpack(uchar *p, int n, char *fmt, va_list a) *va_arg(a, ulong*) = k; break; + case 'F': + if(p+Udphdrsize+Framesize > e) + goto err; + + F = va_arg(a, Frame*); + + F->udp = (Udphdr*)p, p += Udphdrsize; + F->seq = get4(p), p += 4; + F->ack = get4(p), p += 4; + F->id = get4(p), p += 4; + F->len = get2(p), p += 2; + + /* XXX: I'm not happy with this. */ + if(p+F->len > e) + goto err; + + F = erealloc(F, sizeof(Frame)+F->len); + memmove(F->data, p, F->len); + p += F->len; + + break; } } err: @@ -1,5 +1,6 @@ #include <u.h> #include <libc.h> +#include <ip.h> #include <draw.h> #include "libgeometry/geometry.h" #include "dat.h" @@ -1,5 +1,6 @@ #include <u.h> #include <libc.h> +#include <ip.h> #include <draw.h> #include "libgeometry/geometry.h" #include "dat.h" @@ -1,5 +1,6 @@ #include <u.h> #include <libc.h> +#include <ip.h> #include <draw.h> #include "libgeometry/geometry.h" #include "dat.h" @@ -1,5 +1,6 @@ #include <u.h> #include <libc.h> +#include <ip.h> #include <draw.h> #include "libgeometry/geometry.h" #include "dat.h" |