wm: glendy

Download patch

ref: 5addf5da4126128525f84f359a35c0d54012426a
parent: c72db2f4e5d5ad6eafc6a4b662c831c7d2d3c9df
author: mkf <mkf@cloud9p.org>
date: Thu Apr 25 05:01:29 EDT 2024

srv: handle failure more gracefully, don't shutdown the server once a client leaves.

also few other stablity fixes

--- a/srv.c
+++ b/srv.c
@@ -321,7 +321,7 @@
  * > q
  * quits the game
  */
-void
+int
 proc(char *s)
 {
 	char *t;
@@ -350,17 +350,21 @@
 			break;
 		/*
 		case 'u':
-			undo();
+			print(playersock, "ERR not implmented\n");
 			break;
 		*/
 		case 'r':
 			/* maybe we need to put a confirm message here */
-			restart();
+			print(playersock, "ERR not implmented\n");
 			break;
 		case 'q':
 		case '\0':
 			/* should we end the game at this point? XXX important */
-			break;
+			print(playersock, "DIE disconnected\n");
+			print(sockfd[!(turn % 2)], "DIE other client have been disconnected\n");
+			close(sockfd[0]);
+			close(sockfd[1]);
+			return Err;
 		default:
 			print(playersock, "ERR invalidinput %c\n", *s);
 	}
@@ -371,6 +375,7 @@
 			drawlevel();
 		sendlevel();
 	}
+	return Ok;
 }
 
 int
@@ -395,8 +400,7 @@
 	}
 	dprint("got input: %s\n", s);
 
-	proc(s);
-	return Ok;
+	return proc(s);
 }
 
 int 
@@ -415,7 +419,7 @@
 		fprintf(stderr, "usage: %s <port>\n", argv[0]);
 		exit(1);
 	}
-	port = atoi(argv[1]);
+	port = 1768;
 	
 	listenfd = setuplistener(port);
 	pthread_mutex_init(&pcount_mutex, NULL);
@@ -425,8 +429,7 @@
 	/* OpenBSD ignores this */
 	srand(time(nil));
 	
-	getclients(listenfd);
-	initlevel();
+
 	
 /*	result = pthread_create(&thread, NULL, (void*)input, NULL);
 //	if(result){
@@ -434,14 +437,18 @@
 //                exit(-1);
 //	}
 */
+	for(;;)
+	{
+		getclients(listenfd);
+		initlevel();
+
+		if(debug)
+			drawlevel();
 	
-	if(debug)
-		drawlevel();
-	
-	sendlevel();
-	while(input() != Err)
-		;
-	
+		sendlevel();
+		while(input() != Err)
+			;
+	}
 	close(listenfd);
 	pthread_mutex_destroy(&pcount_mutex);
 //	pthread_mutex_destroy(&print_mutex);