diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1f1ac5e6b..0613ba13d 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2045,10 +2045,11 @@ static void CL_ConnectToServer(void) // @TODO: Save the proper server name, right now it doesn't seem like we can consistently retrieve it from the serverlist....? // It works... sometimes but not always which is weird. - if (*joinedIP && strlen(joinedIP)) // false if we have "" which is \0 - M_AddToJoinedIPs(joinedIP, netbuffer->u.serverinfo.servername); + tmpsave[0] = '\0'; // TEMPORARY -- connectedservername is currently only set for YOUR server + if (joinedIP[0]) // false if we have "" which is \0 + M_AddToJoinedIPs(joinedIP, tmpsave); //connectedservername); -- as above - strcpy(joinedIP, ""); // And empty this for good measure regardless of whether or not we actually used it. + joinedIP[0] = '\0'; // And empty this for good measure regardless of whether or not we actually used it. } @@ -2337,7 +2338,7 @@ static void Command_connect(void) { // By default, clear the saved address that we'd save after succesfully joining just to be sure: - strcpy(joinedIP, ""); + joinedIP[0] = '\0'; if (COM_Argc() < 2 || *COM_Argv(1) == 0) { @@ -2424,7 +2425,7 @@ static void Command_connect(void) // Last IPs joined: // Keep the address we typed in memory so that we can save it if we *succesfully* join the server - strcpy(joinedIP, COM_Argv(1)); + strlcpy(joinedIP, COM_Argv(1), MAX_LOGIP); } else { @@ -3846,7 +3847,7 @@ void SV_StartSinglePlayerServer(void) server = true; netgame = false; multiplayer = false; - strcpy(joinedIP, ""); // Make sure to empty this so that we don't save garbage when we start our own game. (because yes we use this for netgames too....) + joinedIP[0] = '\0'; // Make sure to empty this so that we don't save garbage when we start our own game. (because yes we use this for netgames too....) if ((modeattacking == ATTACKING_CAPSULES) || (bossinfo.boss == true)) { diff --git a/src/k_menudraw.c b/src/k_menudraw.c index b83728ed3..92e47cb2f 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -2359,7 +2359,7 @@ void M_DrawMPHost(void) case IT_CV_STRING: V_DrawThinString(xp + 96, yp, V_ALLOWLOWERCASE|V_6WIDTHSPACE, cv->string); if (skullAnimCounter < 4 && i == itemOn) - V_DrawString(xp + 94 + V_ThinStringWidth(cv->string, V_6WIDTHSPACE), yp+1, 0, "_"); + V_DrawString(xp + 96 + V_ThinStringWidth(cv->string, V_ALLOWLOWERCASE|V_6WIDTHSPACE), yp+1, 0, "_"); break; @@ -2417,22 +2417,27 @@ void M_DrawMPJoinIP(void) case IT_STRING: { - char str[MAXSTRINGLENGTH]; + char str[MAX_LOGIP]; strcpy(str, currentMenu->menuitems[i].text); // The last 3 options of this menu are to be the joined IP addresses... if (currentMenu->numitems - i <= NUMLOGIP) { UINT8 index = NUMLOGIP - (currentMenu->numitems - i); - if (strlen(joinedIPlist[index][1])) // Try drawing server name - strcpy(str, joinedIPlist[index][1]); - else if (strlen(joinedIPlist[index][0])) // If that fails, get the address - strcpy(str, joinedIPlist[index][0]); + if (index == 0) + { + xp += 8; + } + + if (joinedIPlist[index][1][0]) // Try drawing server name + strlcpy(str, joinedIPlist[index][1], MAX_LOGIP); + else if (joinedIPlist[index][0][0]) // If that fails, get the address + strlcpy(str, joinedIPlist[index][0], MAX_LOGIP); else strcpy(str, "---"); // If that fails too then there's nothing! } - V_DrawString(xp, yp, V_ALLOWLOWERCASE | ((i == itemOn || currentMenu->menuitems[i].status & IT_SPACE) ? highlightflags : 0), str); + V_DrawThinString(xp, yp, V_ALLOWLOWERCASE | ((i == itemOn || currentMenu->menuitems[i].status & IT_SPACE) ? highlightflags : 0)|V_ALLOWLOWERCASE|V_6WIDTHSPACE, str); // Cvar specific handling switch (currentMenu->menuitems[i].status & IT_TYPE) @@ -2447,10 +2452,10 @@ void M_DrawMPJoinIP(void) //colormap = R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_MOSS, GTC_CACHE); colormapc = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_PLAGUE, GTC_CACHE); - V_DrawFixedPatch((xp + 20)<string); + V_DrawFixedPatch((xp + 12)<string); if (skullAnimCounter < 4 && i == itemOn) - V_DrawCharacter(xp + 24 + V_ThinStringWidth(cv->string, 0), yp, '_' | 0x80, false); + V_DrawString(xp + 18 + V_ThinStringWidth(cv->string, V_ALLOWLOWERCASE|V_6WIDTHSPACE), yp+1, 0, "_"); /*// On this specific menu the only time we'll ever see this is for the connect by IP typefield. // Draw the small GO button here (and the text which is a separate graphic) diff --git a/src/k_menufunc.c b/src/k_menufunc.c index b37d7b57b..e143d5670 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -3875,7 +3875,7 @@ boolean M_JoinIPInputs(INT32 ch) M_SetMenuDelay(pid); // Is there an address at this part of the table? - if (strlen(joinedIPlist[index][0])) + if (*joinedIPlist[index][0]) M_JoinIP(joinedIPlist[index][0]); else S_StartSound(NULL, sfx_lose); diff --git a/src/m_misc.c b/src/m_misc.c index 0c4f05b70..c6aaceab5 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -179,8 +179,8 @@ boolean takescreenshot = false; // Take a screenshot this tic moviemode_t moviemode = MM_OFF; -char joinedIPlist[NUMLOGIP][2][255]; -char joinedIP[255]; +char joinedIPlist[NUMLOGIP][2][MAX_LOGIP]; +char joinedIP[MAX_LOGIP]; // This initializes the above array to have NULL evrywhere it should. void M_InitJoinedIPArray(void) @@ -188,40 +188,37 @@ void M_InitJoinedIPArray(void) UINT8 i; for (i=0; i < NUMLOGIP; i++) { - strcpy(joinedIPlist[i][0], ""); - strcpy(joinedIPlist[i][1], ""); + joinedIPlist[i][0][0] = joinedIPlist[i][1][0] = '\0'; } } // This adds an entry to the above array void M_AddToJoinedIPs(char *address, char *servname) { - UINT8 i = 0; - UINT8 dupeindex = 0; // Check for dupes... - for (; i < NUMLOGIP && !dupeindex; i++) + for (i = 0; i < NUMLOGIP-1; i++) // intentionally not < NUMLOGIP { - // I don't care about the server name (this is broken anyway...) but definitely check the addresses + // Check the addresses if (strcmp(joinedIPlist[i][0], address) == 0) - dupeindex = i; + { + break; + } } CONS_Printf("Adding %s (%s) to list of manually joined IPs\n", servname, address); // Start by moving every IP up 1 slot (dropping the last IP in the table) - // If we found duplicates, start here instead and pull the rest up. - i = dupeindex ? dupeindex : NUMLOGIP; for (; i; i--) { - strcpy(joinedIPlist[i][0], joinedIPlist[i-1][0]); - strcpy(joinedIPlist[i][1], joinedIPlist[i-1][1]); + strlcpy(joinedIPlist[i][0], joinedIPlist[i-1][0], MAX_LOGIP); + strlcpy(joinedIPlist[i][1], joinedIPlist[i-1][1], MAX_LOGIP); } // and add the new IP at the start of the table! - strcpy(joinedIPlist[0][0], address); - strcpy(joinedIPlist[0][1], servname); + strlcpy(joinedIPlist[0][0], address, MAX_LOGIP); + strlcpy(joinedIPlist[0][1], servname, MAX_LOGIP); } // ========================================================================== @@ -474,34 +471,24 @@ void M_SaveJoinedIPs(void) { FILE *f = NULL; UINT8 i; - char *filepath; + const char *filepath = va("%s"PATHSEP"%s", srb2home, IPLOGFILE); - if (!strlen(joinedIPlist[0][0])) + if (!*joinedIPlist[0][0]) return; // Don't bother, there's nothing to save. - // append srb2home to beginning of filename - // but check if srb2home isn't already there, first - if (!strstr(IPLOGFILE, srb2home)) - filepath = va(pandf,srb2home, IPLOGFILE); - else - filepath = Z_StrDup(IPLOGFILE); - f = fopen(filepath, "w"); - if (f == NULL) - return; // Uh I guess you don't have disk space????????? - - for (i=0; i < NUMLOGIP; i++) + if (!f) { - if (strlen(joinedIPlist[i][0])) - { - char savestring[MAXSTRINGLENGTH]; - strcpy(savestring, joinedIPlist[i][0]); - strcat(savestring, IPLOGFILESEP); - strcat(savestring, joinedIPlist[i][1]); + CONS_Alert(CONS_WARNING, "Could not save recent IP list into %s\n", IPLOGFILE); + return; + } - fputs(savestring, f); - fputs("\n", f); // Because this won't do it automatically now will it... + for (i = 0; i < NUMLOGIP; i++) + { + if (*joinedIPlist[i][0]) + { + fprintf(f, "%s%s%s\n", joinedIPlist[i][0], IPLOGFILESEP, joinedIPlist[i][1]); } } @@ -516,7 +503,7 @@ void M_LoadJoinedIPs(void) UINT8 i = 0; char *filepath; char *s; - char content[255]; // 255 is more than long enough! + char buffer[2*(MAX_LOGIP+1)]; filepath = va("%s"PATHSEP"%s", srb2home, IPLOGFILE); f = fopen(filepath, "r"); @@ -524,22 +511,33 @@ void M_LoadJoinedIPs(void) if (f == NULL) return; // File doesn't exist? sure, just do nothing then. - while (fgets(content, 255, f) && i < NUMLOGIP && content[0] && content[0] != '\n') // Don't let us write more than we can chew! + for (i = 0; fgets(buffer, (int)sizeof(buffer), f); i++) // Don't let us write more than we can chew! { + if (i >= NUMLOGIP) + break; - // Now we have garbage under the form of "address;string" - // Now you might ask yourself, but what do we do if the player fucked with their file and now there's a bunch of garbage? - // ...Well that's not my problem lol. + if (!*buffer || *buffer == '\n') + break; - s = strtok(content, IPLOGFILESEP); // We got the address - strcpy(joinedIPlist[i][0], s); + s = strtok(buffer, IPLOGFILESEP); // We got the address + strlcpy(joinedIPlist[i][0], s, MAX_LOGIP); s = strtok(NULL, IPLOGFILESEP); // Let's get rid of this awful \n while we're here! - if (strlen(s)) - s[strlen(s)-1] = '\0'; // Remove the \n - - strcpy(joinedIPlist[i][1], s); + if (s) + { + UINT16 j = 1; + //strcpy(joinedIPlist[i][1], s); -- get rid of \n too... + char *c = joinedIPlist[i][1]; + while (*s && *s != '\n' && j < MAX_LOGIP) + { + *c = *s; + s++; + c++; + j++; + } + *c = '\0'; + } i++; } diff --git a/src/m_misc.h b/src/m_misc.h index 12f51edcf..f4beb8501 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -46,15 +46,15 @@ void M_StopMovie(void); #define IPLOGFILE "ringsavedips.txt" #define IPLOGFILESEP ";" #define NUMLOGIP 3 +#define MAX_LOGIP 255 // Array where we'll store addresses to display for last servers joined // {address, servame} -// 255 is long enough to store the text -extern char joinedIPlist[NUMLOGIP][2][255]; +extern char joinedIPlist[NUMLOGIP][2][MAX_LOGIP]; // Keep the address we're joining in mind until we've finished joining. // Since we don't wanna add an IP address we aren't even sure worked out. -extern char joinedIP[255]; +extern char joinedIP[MAX_LOGIP]; void M_InitJoinedIPArray(void); void M_AddToJoinedIPs(char *address, char *servname);