wm: glendy

Download patch

ref: 7adbe130298503afd9f2ea86a2a9c691a73eb5c1
parent: 1f5ba20d4c1c828815f58c058d11666a3f6cf3f6
author: mkf <mkf@cloud9p.org>
date: Tue May 7 08:04:06 EDT 2024

srv: manually parse put message and just write the numbers into the syncmsg

old method casued a bug which proc_put(), accepted "10  1", but some clients did not,
we now are a bit more strict about this.
in long term this generic parsing may be moved into a seprate function.

--- a/srv.c
+++ b/srv.c
@@ -240,11 +240,30 @@
 void
 proc_put(char *s)
 {
-	unsigned int x, y, r;
+	char *xpos, *ypos;
+	unsigned int x, y;
 
-	sscanf(s, "%u %n", &x, &r);
-	sscanf(s+r, "%u", &y);
+	xpos = strtok(s, " ");
+	ypos = strtok(nil, " ");
 	
+	if(xpos == nil || ypos == nil)
+	{
+		print(playersock, "ERR invalidinput proc_put():"
+		"not enough arguments or malformed string\n");
+		return;
+	}
+	
+	if(!isnum(xpos) || !isnum(num))
+	{
+		print(playersock, "ERR invalidinput proc_put():"
+		"expected string in %s and %s\n", xpos, ypos);
+		
+		return;
+	}
+	
+	x = atoi(xpos);
+	y = atoi(ypos);
+	
 	dprint("put %d %d\n", x, y);
 
 	if(x >= SzX || x < 0 || y >= SzY || y < 0)
@@ -260,7 +279,7 @@
 		print(playersock, "GLND %d %d\n", x, y);
 	else
 	{
-		strncpy(syncmsg, s, 7);
+		sprintf("%u %u", x, y);
 		/* better be safe than sorry */
 		syncmsg[7] = '\0';
 		dprint("syncmsg = %s\n", syncmsg);