Merge branch 'joinedip-fixes' into 'master'

Joined IP fixes

Closes #287 and #288

See merge request KartKrew/Kart!694
This commit is contained in:
Sal 2022-09-27 18:10:19 +00:00
commit be0b700b76
5 changed files with 71 additions and 67 deletions

View file

@ -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....? // @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. // It works... sometimes but not always which is weird.
if (*joinedIP && strlen(joinedIP)) // false if we have "" which is \0 tmpsave[0] = '\0'; // TEMPORARY -- connectedservername is currently only set for YOUR server
M_AddToJoinedIPs(joinedIP, netbuffer->u.serverinfo.servername); 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: // 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) if (COM_Argc() < 2 || *COM_Argv(1) == 0)
{ {
@ -2424,7 +2425,7 @@ static void Command_connect(void)
// Last IPs joined: // Last IPs joined:
// Keep the address we typed in memory so that we can save it if we *succesfully* join the server // 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 else
{ {
@ -3846,7 +3847,7 @@ void SV_StartSinglePlayerServer(void)
server = true; server = true;
netgame = false; netgame = false;
multiplayer = 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)) if ((modeattacking == ATTACKING_CAPSULES) || (bossinfo.boss == true))
{ {

View file

@ -2359,7 +2359,7 @@ void M_DrawMPHost(void)
case IT_CV_STRING: case IT_CV_STRING:
V_DrawThinString(xp + 96, yp, V_ALLOWLOWERCASE|V_6WIDTHSPACE, cv->string); V_DrawThinString(xp + 96, yp, V_ALLOWLOWERCASE|V_6WIDTHSPACE, cv->string);
if (skullAnimCounter < 4 && i == itemOn) 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; break;
@ -2417,22 +2417,27 @@ void M_DrawMPJoinIP(void)
case IT_STRING: case IT_STRING:
{ {
char str[MAXSTRINGLENGTH]; char str[MAX_LOGIP];
strcpy(str, currentMenu->menuitems[i].text); strcpy(str, currentMenu->menuitems[i].text);
// The last 3 options of this menu are to be the joined IP addresses... // The last 3 options of this menu are to be the joined IP addresses...
if (currentMenu->numitems - i <= NUMLOGIP) if (currentMenu->numitems - i <= NUMLOGIP)
{ {
UINT8 index = NUMLOGIP - (currentMenu->numitems - i); UINT8 index = NUMLOGIP - (currentMenu->numitems - i);
if (strlen(joinedIPlist[index][1])) // Try drawing server name if (index == 0)
strcpy(str, joinedIPlist[index][1]); {
else if (strlen(joinedIPlist[index][0])) // If that fails, get the address xp += 8;
strcpy(str, joinedIPlist[index][0]); }
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 else
strcpy(str, "---"); // If that fails too then there's nothing! 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 // Cvar specific handling
switch (currentMenu->menuitems[i].status & IT_TYPE) switch (currentMenu->menuitems[i].status & IT_TYPE)
@ -2447,10 +2452,10 @@ void M_DrawMPJoinIP(void)
//colormap = R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_MOSS, GTC_CACHE); //colormap = R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_MOSS, GTC_CACHE);
colormapc = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_PLAGUE, GTC_CACHE); colormapc = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_PLAGUE, GTC_CACHE);
V_DrawFixedPatch((xp + 20)<<FRACBITS, (yp-3)<<FRACBITS, FRACUNIT, 0, typebar, colormapc); // Always consider that this is selected otherwise it clashes. V_DrawFixedPatch((xp + 12)<<FRACBITS, (yp-2)<<FRACBITS, FRACUNIT, 0, typebar, colormapc); // Always consider that this is selected otherwise it clashes.
V_DrawThinString(xp + 26, yp-1, V_ALLOWLOWERCASE, cv->string); V_DrawThinString(xp + 18, yp, V_ALLOWLOWERCASE|V_6WIDTHSPACE, cv->string);
if (skullAnimCounter < 4 && i == itemOn) 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. /*// 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) // Draw the small GO button here (and the text which is a separate graphic)

View file

@ -3875,7 +3875,7 @@ boolean M_JoinIPInputs(INT32 ch)
M_SetMenuDelay(pid); M_SetMenuDelay(pid);
// Is there an address at this part of the table? // Is there an address at this part of the table?
if (strlen(joinedIPlist[index][0])) if (*joinedIPlist[index][0])
M_JoinIP(joinedIPlist[index][0]); M_JoinIP(joinedIPlist[index][0]);
else else
S_StartSound(NULL, sfx_lose); S_StartSound(NULL, sfx_lose);

View file

@ -179,8 +179,8 @@ boolean takescreenshot = false; // Take a screenshot this tic
moviemode_t moviemode = MM_OFF; moviemode_t moviemode = MM_OFF;
char joinedIPlist[NUMLOGIP][2][255]; char joinedIPlist[NUMLOGIP][2][MAX_LOGIP];
char joinedIP[255]; char joinedIP[MAX_LOGIP];
// This initializes the above array to have NULL evrywhere it should. // This initializes the above array to have NULL evrywhere it should.
void M_InitJoinedIPArray(void) void M_InitJoinedIPArray(void)
@ -188,40 +188,37 @@ void M_InitJoinedIPArray(void)
UINT8 i; UINT8 i;
for (i=0; i < NUMLOGIP; i++) for (i=0; i < NUMLOGIP; i++)
{ {
strcpy(joinedIPlist[i][0], ""); joinedIPlist[i][0][0] = joinedIPlist[i][1][0] = '\0';
strcpy(joinedIPlist[i][1], "");
} }
} }
// This adds an entry to the above array // This adds an entry to the above array
void M_AddToJoinedIPs(char *address, char *servname) void M_AddToJoinedIPs(char *address, char *servname)
{ {
UINT8 i = 0; UINT8 i = 0;
UINT8 dupeindex = 0;
// Check for dupes... // 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) if (strcmp(joinedIPlist[i][0], address) == 0)
dupeindex = i; {
break;
}
} }
CONS_Printf("Adding %s (%s) to list of manually joined IPs\n", servname, address); 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) // 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--) for (; i; i--)
{ {
strcpy(joinedIPlist[i][0], joinedIPlist[i-1][0]); strlcpy(joinedIPlist[i][0], joinedIPlist[i-1][0], MAX_LOGIP);
strcpy(joinedIPlist[i][1], joinedIPlist[i-1][1]); strlcpy(joinedIPlist[i][1], joinedIPlist[i-1][1], MAX_LOGIP);
} }
// and add the new IP at the start of the table! // and add the new IP at the start of the table!
strcpy(joinedIPlist[0][0], address); strlcpy(joinedIPlist[0][0], address, MAX_LOGIP);
strcpy(joinedIPlist[0][1], servname); strlcpy(joinedIPlist[0][1], servname, MAX_LOGIP);
} }
// ========================================================================== // ==========================================================================
@ -474,34 +471,24 @@ void M_SaveJoinedIPs(void)
{ {
FILE *f = NULL; FILE *f = NULL;
UINT8 i; 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. 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"); f = fopen(filepath, "w");
if (f == NULL) if (!f)
return; // Uh I guess you don't have disk space?????????
for (i=0; i < NUMLOGIP; i++)
{ {
if (strlen(joinedIPlist[i][0])) CONS_Alert(CONS_WARNING, "Could not save recent IP list into %s\n", IPLOGFILE);
{ return;
char savestring[MAXSTRINGLENGTH]; }
strcpy(savestring, joinedIPlist[i][0]);
strcat(savestring, IPLOGFILESEP);
strcat(savestring, joinedIPlist[i][1]);
fputs(savestring, f); for (i = 0; i < NUMLOGIP; i++)
fputs("\n", f); // Because this won't do it automatically now will it... {
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; UINT8 i = 0;
char *filepath; char *filepath;
char *s; char *s;
char content[255]; // 255 is more than long enough! char buffer[2*(MAX_LOGIP+1)];
filepath = va("%s"PATHSEP"%s", srb2home, IPLOGFILE); filepath = va("%s"PATHSEP"%s", srb2home, IPLOGFILE);
f = fopen(filepath, "r"); f = fopen(filepath, "r");
@ -524,22 +511,33 @@ void M_LoadJoinedIPs(void)
if (f == NULL) if (f == NULL)
return; // File doesn't exist? sure, just do nothing then. 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" if (!*buffer || *buffer == '\n')
// 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? break;
// ...Well that's not my problem lol.
s = strtok(content, IPLOGFILESEP); // We got the address s = strtok(buffer, IPLOGFILESEP); // We got the address
strcpy(joinedIPlist[i][0], s); strlcpy(joinedIPlist[i][0], s, MAX_LOGIP);
s = strtok(NULL, IPLOGFILESEP); // Let's get rid of this awful \n while we're here! s = strtok(NULL, IPLOGFILESEP); // Let's get rid of this awful \n while we're here!
if (strlen(s)) if (s)
s[strlen(s)-1] = '\0'; // Remove the \n {
UINT16 j = 1;
strcpy(joinedIPlist[i][1], s); //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++; i++;
} }

View file

@ -46,15 +46,15 @@ void M_StopMovie(void);
#define IPLOGFILE "ringsavedips.txt" #define IPLOGFILE "ringsavedips.txt"
#define IPLOGFILESEP ";" #define IPLOGFILESEP ";"
#define NUMLOGIP 3 #define NUMLOGIP 3
#define MAX_LOGIP 255
// Array where we'll store addresses to display for last servers joined // Array where we'll store addresses to display for last servers joined
// {address, servame} // {address, servame}
// 255 is long enough to store the text extern char joinedIPlist[NUMLOGIP][2][MAX_LOGIP];
extern char joinedIPlist[NUMLOGIP][2][255];
// Keep the address we're joining in mind until we've finished joining. // 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. // 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_InitJoinedIPArray(void);
void M_AddToJoinedIPs(char *address, char *servname); void M_AddToJoinedIPs(char *address, char *servname);