Support connecting by IPv6 address in the menu

Font will shrink once exceeding a certain number of
characters.
This commit is contained in:
James R 2021-09-01 18:32:18 -07:00
parent 7976d0476d
commit 31943f30a1

View file

@ -968,7 +968,7 @@ static menuitem_t MP_MainMenu[] =
{
{IT_HEADER, NULL, "Join a game", NULL, 0},
{IT_STRING|IT_CALL, NULL, "Server browser...", M_ConnectMenuModChecks, 12},
{IT_STRING|IT_KEYHANDLER, NULL, "Specify IPv4 address:", M_HandleConnectIP, 22},
{IT_STRING|IT_KEYHANDLER, NULL, "Specify server address:", M_HandleConnectIP, 22},
{IT_HEADER, NULL, "Host a game", NULL, 54},
{IT_STRING|IT_CALL, NULL, "Internet/LAN...", M_StartServerMenu, 66},
{IT_STRING|IT_CALL, NULL, "Splitscreen...", M_StartSplitServerMenu, 76},
@ -11605,7 +11605,35 @@ static void M_StartServerMenu(INT32 choice)
// CONNECT VIA IP
// ==============
static char setupm_ip[28];
static char setupm_ip[sizeof "[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:65535"];
static void M_DrawConnectIP(void)
{
INT32 x = currentMenu->x;
INT32 y = currentMenu->y + 22;
INT32 opt = V_ALLOWLOWERCASE;
INT32 width;
V_DrawFill(x+5, y+4+5, /*16*8 + 6,*/ BASEVIDWIDTH - 2*(x+5), 8+6, 159);
// draw name string
if (strlen(setupm_ip) > 30)/* w stands for wide boi */
{
V_DrawThinString(x+8,y+12, opt, setupm_ip);
width = V_ThinStringWidth(setupm_ip, opt);
}
else
{
V_DrawString(x+8,y+12, opt, setupm_ip);
width = V_StringWidth(setupm_ip, opt);
}
// draw text cursor for name
if (itemOn == 2 //0
&& skullAnimCounter < 4) //blink cursor
V_DrawCharacter(x+8+width,y+12,'_',false);
}
// Draw the funky Connect IP menu. Tails 11-19-2002
// So much work for such a little thing!
@ -11626,17 +11654,7 @@ static void M_DrawMPMainMenu(void)
V_DrawRightAlignedString(BASEVIDWIDTH-x, y+116,
((itemOn == 8) ? V_YELLOWMAP : 0), "(splitscreen)");
y += 22;
V_DrawFill(x+5, y+4+5, /*16*8 + 6,*/ BASEVIDWIDTH - 2*(x+5), 8+6, 159);
// draw name string
V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip);
// draw text cursor for name
if (itemOn == 2 //0
&& skullAnimCounter < 4) //blink cursor
V_DrawCharacter(x+8+V_StringWidth(setupm_ip, V_ALLOWLOWERCASE),y+12,'_',false);
M_DrawConnectIP();
}
// Tails 11-19-2002
@ -11719,7 +11737,7 @@ static void M_HandleConnectIP(INT32 choice)
const char *paste = I_ClipboardPaste();
if (paste != NULL) {
strncat(setupm_ip, paste, 28-1 - l); // Concat the ip field with clipboard
strncat(setupm_ip, paste, (sizeof setupm_ip)-1 - l); // Concat the ip field with clipboard
if (strlen(paste) != 0) // Don't play sound if nothing was pasted
S_StartSound(NULL,sfx_menu1); // Tails
}
@ -11753,7 +11771,7 @@ static void M_HandleConnectIP(INT32 choice)
const char *paste = I_ClipboardPaste();
if (paste != NULL) {
strncat(setupm_ip, paste, 28-1 - l); // Concat the ip field with clipboard
strncat(setupm_ip, paste, (sizeof setupm_ip)-1 - l); // Concat the ip field with clipboard
if (strlen(paste) != 0) // Don't play sound if nothing was pasted
S_StartSound(NULL,sfx_menu1); // Tails
}
@ -11770,11 +11788,15 @@ static void M_HandleConnectIP(INT32 choice)
}
}
if (l >= 28-1)
if (l >= (sizeof setupm_ip)-1)
break;
// Rudimentary number and period enforcing - also allows letters so hostnames can be used instead
if ((choice >= '-' && choice <= ':') || (choice >= 'A' && choice <= 'Z') || (choice >= 'a' && choice <= 'z'))
// and square brackets for RFC 2732 IPv6 addresses
if ((choice >= '-' && choice <= ':') ||
(choice == '[' || choice == ']') ||
(choice >= 'A' && choice <= 'Z') ||
(choice >= 'a' && choice <= 'z'))
{
S_StartSound(NULL,sfx_menu1); // Tails
setupm_ip[l] = (char)choice;