ref: 79d63451ba564d3d51f6bddf81d031b941c4beda
parent: 5d13a50ba5f8139cdd625c9eb0aa3d771c9d146f
author: mkf <mkf@cloud9p.org>
date: Tue May 21 16:16:41 EDT 2024
fix overlapping sockfds it was casued by setting sockfd on the fly, which could lead to hijacking(?) of a socket many game internals still use shared sockfd, we can't do much about it right now. should fix some bugs.
--- a/srv4.c
+++ b/srv4.c
@@ -23,6 +23,7 @@
int port = 1768;
int debug = 1;
char syncmsg[8];
+
int sockfd[2];
int gcount = 0;
@@ -386,7 +387,7 @@
games[n].sockfd[0] = sockfd[0];
games[n].sockfd[1] = sockfd[1];
-
+
memcpy(games[n].grid, grid, sizeof(grid));
}
@@ -426,7 +427,7 @@
void
srv(int listenfd)
{
- int res[2];
+ int clientfd[2], res[2];
socklen_t clilen;
struct sockaddr_in servaddr, clientaddr;
int tdata[2][2];
@@ -439,24 +440,26 @@
memset(&clientaddr, 0, sizeof(clientaddr));
clilen = sizeof(clientaddr);
- sockfd[conns] = accept(listenfd, (struct sockaddr *) &clientaddr, &clilen);
+ clientfd[conns] = accept(listenfd, (struct sockaddr *) &clientaddr, &clilen);
- if(sockfd[conns] < 0)
+ if(clientfd[conns] < 0)
error("srv(): failed to accept connection");
- fprint(sockfd[conns], "CONN %d\n", conns);
+ fprint(clientfd[conns], "CONN %d\n", conns);
dprint("srv(): client %d connected\n", conns);
if(conns == 0)
- fprint(sockfd[conns], "WAIT\n");
+ fprint(clientfd[conns], "WAIT\n");
}
-
- gcount++;
pthread_mutex_lock(&game_lock);
-
+ gcount++;
+
+ sockfd[0] = clientfd[0];
+ sockfd[1] = clientfd[1];
+
initlevel();
setgame(gcount);
-
+
if(debug)
drawlevel();