From af2d3cfd16a59c385f25cb06f6717502ccbc9b2e Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 3 Aug 2019 13:27:57 -0700 Subject: [PATCH 1/7] Let MS_Connect use -bindaddr And so now you really can host from multiple IP addresses. (cherry picked from commit e56bf12537700af7b7fcd0d3b0e8586e41edddd1) --- src/mserv.c | 94 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/src/mserv.c b/src/mserv.c index ddabdb6c0..1052de80c 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -323,7 +323,7 @@ static INT32 GetServersList(void) // // MS_Connect() // -static INT32 MS_Connect(const char *ip_addr, const char *str_port, INT32 async) +static INT32 MS_SubConnect(const char *ip_addr, const char *str_port, INT32 async, struct sockaddr *bindaddr, socklen_t bindaddrlen) { #ifdef NONET (void)ip_addr; @@ -356,44 +356,48 @@ static INT32 MS_Connect(const char *ip_addr, const char *str_port, INT32 async) socket_fd = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol); if (socket_fd != (SOCKET_TYPE)ERRSOCKET) { - if (async) // do asynchronous connection + if (!bindaddr || bind(socket_fd, bindaddr, bindaddrlen) == 0) { + if (async) // do asynchronous connection + { #ifdef FIONBIO #ifdef WATTCP - char res = 1; + char res = 1; #else - unsigned long res = 1; + unsigned long res = 1; #endif - ioctl(socket_fd, FIONBIO, &res); + ioctl(socket_fd, FIONBIO, &res); #endif - if (connect(socket_fd, runp->ai_addr, (socklen_t)runp->ai_addrlen) == ERRSOCKET) - { -#ifdef _WIN32 // humm, on win32/win64 it doesn't work with EINPROGRESS (stupid windows) - if (WSAGetLastError() != WSAEWOULDBLOCK) -#else - if (errno != EINPROGRESS) -#endif + if (connect(socket_fd, runp->ai_addr, (socklen_t)runp->ai_addrlen) == ERRSOCKET) { - con_state = MSCS_FAILED; - CloseConnection(); - I_freeaddrinfo(ai); - return MS_CONNECT_ERROR; +#ifdef _WIN32 // humm, on win32/win64 it doesn't work with EINPROGRESS (stupid windows) + if (WSAGetLastError() != WSAEWOULDBLOCK) +#else + if (errno != EINPROGRESS) +#endif + { + con_state = MSCS_FAILED; + CloseConnection(); + I_freeaddrinfo(ai); + return MS_CONNECT_ERROR; + } } + con_state = MSCS_WAITING; + FD_ZERO(&wset); + FD_SET(socket_fd, &wset); + select_timeout.tv_sec = 0, select_timeout.tv_usec = 0; + I_freeaddrinfo(ai); + return 0; + } + else if (connect(socket_fd, runp->ai_addr, (socklen_t)runp->ai_addrlen) != ERRSOCKET) + { + I_freeaddrinfo(ai); + return 0; } - con_state = MSCS_WAITING; - FD_ZERO(&wset); - FD_SET(socket_fd, &wset); - select_timeout.tv_sec = 0, select_timeout.tv_usec = 0; - I_freeaddrinfo(ai); - return 0; - } - else if (connect(socket_fd, runp->ai_addr, (socklen_t)runp->ai_addrlen) != ERRSOCKET) - { - I_freeaddrinfo(ai); - return 0; } + close(socket_fd); } runp = runp->ai_next; } @@ -402,6 +406,42 @@ static INT32 MS_Connect(const char *ip_addr, const char *str_port, INT32 async) return MS_CONNECT_ERROR; } +static INT32 MS_Connect(const char *ip_addr, const char *str_port, INT32 async) +{ + const char *lhost; + struct my_addrinfo hints; + struct my_addrinfo *ai, *aip; + int c; + if (M_CheckParm("-bindaddr") && ( lhost = M_GetNextParm() )) + { + memset (&hints, 0x00, sizeof(hints)); +#ifdef AI_ADDRCONFIG + hints.ai_flags = AI_ADDRCONFIG; +#endif + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + if (( c = I_getaddrinfo(lhost, 0, &hints, &ai) ) != 0) + { + CONS_Printf( + "mserv.c: bind to %s: %s\n", + lhost, + gai_strerror(c)); + return MS_GETHOSTBYNAME_ERROR; + } + for (aip = ai; aip; aip = aip->ai_next) + { + c = MS_SubConnect(ip_addr, str_port, async, aip->ai_addr, aip->ai_addrlen); + if (c == 0) + return 0; + } + I_freeaddrinfo(ai); + return c; + } + else + return MS_SubConnect(ip_addr, str_port, async, 0, 0); +} + #define NUM_LIST_SERVER MAXSERVERLIST const msg_server_t *GetShortServersList(INT32 room) { From 619efb3d4ecf89b242784d17bbec70a8f7ef6ed6 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 3 Aug 2019 13:30:22 -0700 Subject: [PATCH 2/7] And free addrinfo (cherry picked from commit 986c80fb13e7ae6900792de5b4b43327af7ca76c) --- src/mserv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mserv.c b/src/mserv.c index 1052de80c..a842e92e9 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -433,7 +433,10 @@ static INT32 MS_Connect(const char *ip_addr, const char *str_port, INT32 async) { c = MS_SubConnect(ip_addr, str_port, async, aip->ai_addr, aip->ai_addrlen); if (c == 0) + { + I_freeaddrinfo(ai); return 0; + } } I_freeaddrinfo(ai); return c; From 708ab6ff907cb77bdd05813eefde1f6d81d41a5e Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 14 Jan 2020 21:40:58 -0800 Subject: [PATCH 3/7] Update buffer for SendNameAndColor --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 723748448..23ec00b2e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1174,7 +1174,7 @@ static INT32 snacpending = 0, snac2pending = 0, chmappending = 0; // static void SendNameAndColor(void) { - char buf[MAXPLAYERNAME+2]; + char buf[MAXPLAYERNAME+6]; char *p; p = buf; From 9504ba96da07ec9ec6f4eb4d41bde87024130fd0 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Wed, 15 Jan 2020 15:36:11 +0100 Subject: [PATCH 4/7] Increase maximum and default chat width --- src/g_game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index eba53627d..a80d0f40a 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -352,8 +352,8 @@ static CV_PossibleValue_t chattime_cons_t[] = {{5, "MIN"}, {999, "MAX"}, {0, NUL consvar_t cv_chattime = {"chattime", "8", CV_SAVE, chattime_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // chatwidth -static CV_PossibleValue_t chatwidth_cons_t[] = {{64, "MIN"}, {150, "MAX"}, {0, NULL}}; -consvar_t cv_chatwidth = {"chatwidth", "128", CV_SAVE, chatwidth_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t chatwidth_cons_t[] = {{64, "MIN"}, {300, "MAX"}, {0, NULL}}; +consvar_t cv_chatwidth = {"chatwidth", "150", CV_SAVE, chatwidth_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // chatheight static CV_PossibleValue_t chatheight_cons_t[] = {{6, "MIN"}, {22, "MAX"}, {0, NULL}}; From ec5db89e550e842ab7a0ebb24415f39c4e31ab15 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Wed, 15 Jan 2020 15:48:03 +0100 Subject: [PATCH 5/7] Cleanup chat code a little --- src/hu_stuff.c | 54 ++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 14cb481b0..9e708e1cf 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -501,37 +501,31 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) // what we're gonna do now is check if the player exists // with that logic, characters 4 and 5 are our numbers: const char *newmsg; - char *playernum = (char*) malloc(3); + char playernum[3]; INT32 spc = 1; // used if playernum[1] is a space. strncpy(playernum, msg+3, 3); // check for undesirable characters in our "number" - if (((playernum[0] < '0') || (playernum[0] > '9')) || ((playernum[1] < '0') || (playernum[1] > '9'))) + if (((playernum[0] < '0') || (playernum[0] > '9')) || ((playernum[1] < '0') || (playernum[1] > '9'))) { // check if playernum[1] is a space if (playernum[1] == ' ') spc = 0; - // let it slide + // let it slide else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(playernum); return; } } // I'm very bad at C, I swear I am, additional checks eww! - if (spc != 0) - { - if (msg[5] != ' ') - { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(playernum); - return; - } - } + if (spc != 0 && msg[5] != ' ') + { + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + return; + } - target = atoi((const char*) playernum); // turn that into a number - free(playernum); + target = atoi(playernum); // turn that into a number //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -1021,9 +1015,6 @@ void HU_Ticker(void) #ifndef NONET static boolean teamtalk = false; -/*static char chatchars[QUEUESIZE]; -static INT32 head = 0, tail = 0;*/ -// WHY DO YOU OVERCOMPLICATE EVERYTHING????????? // Clear spaces so we don't end up with messages only made out of emptiness static boolean HU_clearChatSpaces(void) @@ -1083,7 +1074,7 @@ static void HU_queueChatChar(char c) if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { INT32 spc = 1; // used if nodenum[1] is a space. - char *nodenum = (char*) malloc(3); + char nodenum[3]; const char *newmsg; // what we're gonna do now is check if the node exists @@ -1098,7 +1089,7 @@ static void HU_queueChatChar(char c) strncpy(nodenum, msg+3, 3); // check for undesirable characters in our "number" - if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) + if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) { // check if nodenum[1] is a space if (nodenum[1] == ' ') @@ -1107,7 +1098,6 @@ static void HU_queueChatChar(char c) else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } @@ -1117,13 +1107,11 @@ static void HU_queueChatChar(char c) if (msg[5] != ' ') { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } - target = atoi((const char*) nodenum); // turn that into a number - free(nodenum); + target = atoi(nodenum); // turn that into a number //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -1648,12 +1636,9 @@ static void HU_drawChatLog(INT32 offset) } chat_scrollmedown = false; - // getmaxscroll through a lazy hack. We do all these loops, so let's not do more loops that are gonna lag the game more. :P - chat_maxscroll = (dy/charheight); // welcome to C, we don't know what min() and max() are. - if (chat_maxscroll <= (UINT32)cv_chatheight.value) - chat_maxscroll = 0; - else - chat_maxscroll -= cv_chatheight.value; + // getmaxscroll through a lazy hack. We do all these loops, + // so let's not do more loops that are gonna lag the game more. :P + chat_maxscroll = max(dy / charheight - cv_chatheight.value, 0); // if we're not bound by the time, autoscroll for next frame: if (atbottom) @@ -1794,21 +1779,17 @@ static void HU_DrawChat(void) i = 0; for(i=0; (i '9'))) || ((w_chat[4] != 0) && (((w_chat[4] < '0') || (w_chat[4] > '9'))))) && (w_chat[4] != ' ')) break; - - nodenum = (char*) malloc(3); strncpy(nodenum, w_chat+3, 3); - n = atoi((const char*) nodenum); // turn that into a number - free(nodenum); + n = atoi(nodenum); // turn that into a number // special cases: if ((n == 0) && !(w_chat[4] == '0')) @@ -1855,7 +1836,6 @@ static void HU_DrawChat(void) } HU_drawChatLog(typelines-1); // typelines is the # of lines we're typing. If there's more than 1 then the log should scroll up to give us more space. - } From 0197a83db7f80dc8a412ee41200989322fca1c5b Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Wed, 15 Jan 2020 15:57:38 +0100 Subject: [PATCH 6/7] bruh --- src/hu_stuff.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 9e708e1cf..87e888eeb 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1073,11 +1073,11 @@ static void HU_queueChatChar(char c) if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { - INT32 spc = 1; // used if nodenum[1] is a space. - char nodenum[3]; + INT32 spc = 1; // used if playernum[1] is a space. + char playernum[3]; const char *newmsg; - // what we're gonna do now is check if the node exists + // what we're gonna do now is check if the player exists // with that logic, characters 4 and 5 are our numbers: // teamtalk can't send PMs, just don't send it, else everyone would be able to see it, and no one wants to see your sex RP sicko. @@ -1087,17 +1087,17 @@ static void HU_queueChatChar(char c) return; } - strncpy(nodenum, msg+3, 3); + strncpy(playernum, msg+3, 3); // check for undesirable characters in our "number" - if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) + if (((playernum[0] < '0') || (playernum[0] > '9')) || ((playernum[1] < '0') || (playernum[1] > '9'))) { - // check if nodenum[1] is a space - if (nodenum[1] == ' ') + // check if playernum[1] is a space + if (playernum[1] == ' ') spc = 0; // let it slide else { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); return; } } @@ -1106,12 +1106,12 @@ static void HU_queueChatChar(char c) { if (msg[5] != ' ') { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); return; } } - target = atoi(nodenum); // turn that into a number + target = atoi(playernum); // turn that into a number //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -1123,7 +1123,7 @@ static void HU_queueChatChar(char c) return; } - // we need to get rid of the /pm + // we need to get rid of the /pm newmsg = msg+5+spc; strlcpy(msg, newmsg, 255); } @@ -1782,14 +1782,14 @@ static void HU_DrawChat(void) // filter: (code needs optimization pls help I'm bad with C) if (w_chat[3]) { - char nodenum[3]; + char playernum[3]; UINT32 n; // right, that's half important: (w_chat[4] may be a space since /pm0 msg is perfectly acceptable!) if ( ( ((w_chat[3] != 0) && ((w_chat[3] < '0') || (w_chat[3] > '9'))) || ((w_chat[4] != 0) && (((w_chat[4] < '0') || (w_chat[4] > '9'))))) && (w_chat[4] != ' ')) break; - strncpy(nodenum, w_chat+3, 3); - n = atoi(nodenum); // turn that into a number + strncpy(playernum, w_chat+3, 3); + n = atoi(playernum); // turn that into a number // special cases: if ((n == 0) && !(w_chat[4] == '0')) From e4f0fa46f58c4a2236d48f9774ba5eeb65d021e4 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 16 Jan 2020 18:07:28 -0800 Subject: [PATCH 7/7] Dumbass NONET stuff... --- src/mserv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/mserv.c b/src/mserv.c index a842e92e9..4ddab05b9 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -323,13 +323,9 @@ static INT32 GetServersList(void) // // MS_Connect() // +#ifndef NONET static INT32 MS_SubConnect(const char *ip_addr, const char *str_port, INT32 async, struct sockaddr *bindaddr, socklen_t bindaddrlen) { -#ifdef NONET - (void)ip_addr; - (void)str_port; - (void)async; -#else struct my_addrinfo *ai, *runp, hints; int gaie; @@ -402,12 +398,18 @@ static INT32 MS_SubConnect(const char *ip_addr, const char *str_port, INT32 asyn runp = runp->ai_next; } I_freeaddrinfo(ai); -#endif return MS_CONNECT_ERROR; } +#endif/*NONET xd*/ static INT32 MS_Connect(const char *ip_addr, const char *str_port, INT32 async) { +#ifdef NONET + (void)ip_addr; + (void)str_port; + (void)async; + return MS_CONNECT_ERROR; +#else const char *lhost; struct my_addrinfo hints; struct my_addrinfo *ai, *aip; @@ -443,6 +445,7 @@ static INT32 MS_Connect(const char *ip_addr, const char *str_port, INT32 async) } else return MS_SubConnect(ip_addr, str_port, async, 0, 0); +#endif/*NONET xd*/ } #define NUM_LIST_SERVER MAXSERVERLIST