shithub: musw

Download patch

ref: b69fdfbf30beb998c1817784e748ae78806becf8
parent: c69fa66f609925a98acf8dc7f645b9b50ce3a8ba
author: rodri <rgl@antares-labs.eu>
date: Wed Jun 15 15:57:31 EDT 2022

some corrections to frame processing and nomenclatures.

--- a/dat.h
+++ b/dat.h
@@ -24,7 +24,8 @@
 };
 
 enum {
-	Framesize = 4+4+4+2,
+	Framehdrsize	= 4+4+4+2,
+	MTU		= 1024
 };
 
 typedef struct VModel VModel;
--- a/musw.c
+++ b/musw.c
@@ -33,7 +33,7 @@
 
 RFrame screenrf;
 Universe *universe;
-VModel *needlemdl;
+VModel *needlemdl, *wedgemdl;
 Image *skymap;
 Channel *kchan;
 char winspec[32];
@@ -217,7 +217,7 @@
 void
 threadnetsend(void *arg)
 {
-	uchar buf[1024];
+	uchar buf[MTU];
 	int fd, n;
 	ulong kdown;
 	Frame *frame;
@@ -225,17 +225,18 @@
 	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 @@
 	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();
--- a/muswd.c
+++ b/muswd.c
@@ -15,12 +15,11 @@
 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 @@
 	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 @@
 
 		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",
--- a/pack.c
+++ b/pack.c
@@ -74,7 +74,7 @@
 		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 @@
 
 			break;
 		case 'F':
-			if(p+Udphdrsize+Framesize > e)
+			if(p+Udphdrsize+Framehdrsize > e)
 				goto err;
 
 			F = va_arg(a, Frame*);