aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dat.h3
-rw-r--r--musw.c24
-rw-r--r--muswd.c13
-rw-r--r--pack.c4
4 files changed, 21 insertions, 23 deletions
diff --git a/dat.h b/dat.h
index b4f7147..6525c3c 100644
--- a/dat.h
+++ b/dat.h
@@ -24,7 +24,8 @@ enum {
};
enum {
- Framesize = 4+4+4+2,
+ Framehdrsize = 4+4+4+2,
+ MTU = 1024
};
typedef struct VModel VModel;
diff --git a/musw.c b/musw.c
index 10ca01b..106a83a 100644
--- a/musw.c
+++ b/musw.c
@@ -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();
diff --git a/muswd.c b/muswd.c
index 4ebd7e9..ce69c8d 100644
--- a/muswd.c
+++ b/muswd.c
@@ -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",
diff --git a/pack.c b/pack.c
index 1096f6b..85d71ac 100644
--- a/pack.c
+++ b/pack.c
@@ -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*);