Make the game offer unloading all addons before joining a server

This commit is contained in:
Lactozilla 2023-07-28 13:54:58 -03:00
parent f54ac26c5a
commit 1e26d7f86b
12 changed files with 180 additions and 123 deletions

View file

@ -1994,11 +1994,45 @@ void CL_UpdateServerList(boolean internetsearch, INT32 room)
#endif // ifndef NONET #endif // ifndef NONET
static void CL_LoadFiles(void)
{
cl_mode = CL_LOADFILES;
}
static void M_ConfirmAddonWarning(event_t *ev)
{
#ifndef NONET
if (ev->type != ev_keydown)
return;
if (ev->key == ' ' || ev->key == 'y' || ev->key == KEY_ENTER || ev->key == KEY_JOY1)
{
D_RestartGame(false);
F_ReloadTitleScreenGraphics();
M_StopMessage(0);
menuactive = false;
stopstopmessage = true;
cl_mode = CL_CHECKFILES;
}
else if (ev->key == 'n' || ev->key == KEY_ESCAPE || ev->key == KEY_JOY1 + 3)
{
cl_mode = CL_ABORTED;
M_ClearMenus(true);
}
#else
(void)ev;
#endif
}
static void M_ConfirmConnect(event_t *ev) static void M_ConfirmConnect(event_t *ev)
{ {
#ifndef NONET #ifndef NONET
if (ev->type == ev_keydown) if (ev->type != ev_keydown)
{ return;
if (ev->key == ' ' || ev->key == 'y' || ev->key == KEY_ENTER || ev->key == KEY_JOY1) if (ev->key == ' ' || ev->key == 'y' || ev->key == KEY_ENTER || ev->key == KEY_JOY1)
{ {
if (totalfilesrequestednum > 0) if (totalfilesrequestednum > 0)
@ -2010,7 +2044,7 @@ static void M_ConfirmConnect(event_t *ev)
} }
} }
else else
cl_mode = CL_LOADFILES; CL_LoadFiles();
M_ClearMenus(true); M_ClearMenus(true);
} }
@ -2019,67 +2053,90 @@ static void M_ConfirmConnect(event_t *ev)
cl_mode = CL_ABORTED; cl_mode = CL_ABORTED;
M_ClearMenus(true); M_ClearMenus(true);
} }
}
#else #else
(void)ev; (void)ev;
#endif #endif
} }
static boolean CL_FinishedFileList(void) static void M_ShowFileConsentMessage(void)
{ {
INT32 i; #ifndef NONET
char *downloadsize = NULL; char *downloadsize = NULL;
//CONS_Printf(M_GetText("Checking files...\n")); if (totalfilesrequestedsize>>20 >= 100)
i = CL_CheckFiles(); downloadsize = Z_StrDup(va("%uM",totalfilesrequestedsize>>20));
else
downloadsize = Z_StrDup(va("%uK",totalfilesrequestedsize>>10));
if (serverisfull)
M_StartMessage(va(M_GetText(
"This server is full!\n"
"Download of %s additional content\nis required to join.\n"
"\n"
"You may download, load server addons,\nand wait for a slot.\n"
"\n"
"Press ENTER to continue\nor ESC to cancel.\n"
), downloadsize), M_ConfirmConnect, MM_EVENTHANDLER);
else
M_StartMessage(va(M_GetText(
"Download of %s additional content\nis required to join.\n"
"\n"
"Press ENTER to continue\nor ESC to cancel.\n"
), downloadsize), M_ConfirmConnect, MM_EVENTHANDLER);
Z_Free(downloadsize);
#endif
}
static boolean CL_FinishedFileList(void)
{
INT32 i = CL_CheckFiles();
if (i == 4) // still checking ... if (i == 4) // still checking ...
{ {
return true; return true;
} }
else if (i == 3) // too many files else if (i == 3 || i == 2) // too many files, or the wrong addons are loaded
{ {
D_QuitNetGame(); const char *message;
CL_Reset(); if (i == 3)
D_StartTitle(); {
M_StartMessage(M_GetText( message = M_GetText(
"You have too many WAD files loaded\n" "You have too many addons loaded\n"
"to add ones the server is using.\n" "to add ones the server is using.\n\n"
"Please restart SRB2 before connecting.\n\n" "To play on this server, the game\n"
"Press ESC\n" "will unload your current\n"
), NULL, MM_NOTHING); "addons before you join.\n\n"
return false; "Press ENTER to continue\nor ESC to cancel\n"
);
} }
else if (i == 2) // cannot join for some reason else
{ {
D_QuitNetGame(); message = M_GetText(
CL_Reset();
D_StartTitle();
M_StartMessage(M_GetText(
"You have the wrong addons loaded.\n\n" "You have the wrong addons loaded.\n\n"
"To play on this server, restart\n" "To play on this server, the game\n"
"the game and don't load any addons.\n" "will unload your current\n"
"SRB2 will automatically add\n" "addons before you join.\n\n"
"everything you need when you join.\n\n" "Press ENTER to continue\nor ESC to cancel\n"
"Press ESC\n" );
), NULL, MM_NOTHING); }
return false; M_StartMessage(message, M_ConfirmAddonWarning, MM_EVENTHANDLER);
cl_mode = CL_CONFIRMCONNECT;
curfadevalue = 0;
} }
else if (i == 1) else if (i == 1)
{ {
if (serverisfull) if (serverisfull)
{ {
M_StartMessage(M_GetText( M_StartMessage(M_GetText(
"This server is full!\n" "This server is full!\n\n"
"\n" "You may load server addons (if any), and wait for a slot.\n\n"
"You may load server addons (if any), and wait for a slot.\n" "Press ENTER to continue\nor ESC to cancel\n"
"\n"
"Press ENTER to continue\nor ESC to cancel.\n\n"
), M_ConfirmConnect, MM_EVENTHANDLER); ), M_ConfirmConnect, MM_EVENTHANDLER);
cl_mode = CL_CONFIRMCONNECT; cl_mode = CL_CONFIRMCONNECT;
curfadevalue = 0; curfadevalue = 0;
} }
else else
cl_mode = CL_LOADFILES; CL_LoadFiles();
} }
else else
{ {
@ -2118,29 +2175,9 @@ static boolean CL_FinishedFileList(void)
totalfilesrequestedsize += fileneeded[i].totalsize; totalfilesrequestedsize += fileneeded[i].totalsize;
} }
if (totalfilesrequestedsize>>20 >= 100) M_ShowFileConsentMessage();
downloadsize = Z_StrDup(va("%uM",totalfilesrequestedsize>>20));
else
downloadsize = Z_StrDup(va("%uK",totalfilesrequestedsize>>10));
#endif #endif
if (serverisfull)
M_StartMessage(va(M_GetText(
"This server is full!\n"
"Download of %s additional content\nis required to join.\n"
"\n"
"You may download, load server addons,\nand wait for a slot.\n"
"\n"
"Press ENTER to continue\nor ESC to cancel.\n"
), downloadsize), M_ConfirmConnect, MM_EVENTHANDLER);
else
M_StartMessage(va(M_GetText(
"Download of %s additional content\nis required to join.\n"
"\n"
"Press ENTER to continue\nor ESC to cancel.\n"
), downloadsize), M_ConfirmConnect, MM_EVENTHANDLER);
Z_Free(downloadsize);
cl_mode = CL_CONFIRMCONNECT; cl_mode = CL_CONFIRMCONNECT;
curfadevalue = 0; curfadevalue = 0;
} }
@ -2364,7 +2401,7 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic
} }
#endif #endif
cl_mode = CL_LOADFILES; CL_LoadFiles();
break; break;
case CL_LOADFILES: case CL_LOADFILES:
if (CL_LoadServerFiles()) if (CL_LoadServerFiles())

View file

@ -1801,34 +1801,20 @@ void D_ReloadFiles(void)
ST_ReloadSkinFaceGraphics(); ST_ReloadSkinFaceGraphics();
} }
void D_RestartGame(void) void D_RestartGame(boolean remove_all_addons)
{ {
if (netgame) // Save the current configuration file, and the gamedata
{
CONS_Printf(M_GetText("You can't restart the game while in a netgame.\n"));
return;
}
// Save the current configuration file, and the gamedata.
D_SaveUserPrefs(); D_SaveUserPrefs();
// We're deleting some files // Remove all addons
while (numwadfiles > mainwads + 1) // don't delete music.dta W_UnloadAddons(remove_all_addons);
{
W_UnloadFile(wadfiles[numwadfiles - 1]);
wadfiles[numwadfiles - 1] = NULL;
numwadfiles--;
}
// Put everything back on its place // Put everything back on its place
D_ReloadFiles(); D_ReloadFiles();
// Load the default game data. // Load the default game data
G_LoadGameData(clientGamedata); G_LoadGameData(clientGamedata);
M_CopyGameData(serverGamedata, clientGamedata); M_CopyGameData(serverGamedata, clientGamedata);
// Done. Start the intro.
F_StartIntro();
} }
// Save the current configuration file, and the gamedata. // Save the current configuration file, and the gamedata.

View file

@ -39,7 +39,7 @@ void D_SRB2Loop(void) FUNCNORETURN;
void D_SRB2Main(void); void D_SRB2Main(void);
// Restart the game // Restart the game
void D_RestartGame(void); void D_RestartGame(boolean remove_all_addons);
// Set the initial state and reload files. // Set the initial state and reload files.
void D_ReloadFiles(void); void D_ReloadFiles(void);

View file

@ -3719,7 +3719,15 @@ static void Command_Delfile(void)
static void Command_Restartgame(void) static void Command_Restartgame(void)
{ {
D_RestartGame(); if (netgame)
{
CONS_Printf(M_GetText("You can't restart the game while in a netgame.\n"));
return;
}
D_RestartGame(true);
F_StartIntro();
} }
static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum) static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum)

View file

@ -456,7 +456,6 @@ INT32 CL_CheckFiles(void)
// Modified game handling -- check for an identical file list // Modified game handling -- check for an identical file list
// must be identical in files loaded AND in order // must be identical in files loaded AND in order
// Return 2 on failure -- disconnect from server
if (modifiedgame) if (modifiedgame)
{ {
CONS_Debug(DBG_NETPLAY, "game is modified; only doing basic checks\n"); CONS_Debug(DBG_NETPLAY, "game is modified; only doing basic checks\n");

View file

@ -2630,6 +2630,17 @@ static void F_FigureActiveTtScale(void)
F_LoadAlacroixGraphics(activettscale); F_LoadAlacroixGraphics(activettscale);
} }
void F_ReloadTitleScreenGraphics(void)
{
if (curttmode == TTMODE_ALACROIX)
{
activettscale = 0;
F_FigureActiveTtScale();
}
else
F_CacheTitleScreen();
}
// (no longer) De-Demo'd Title Screen // (no longer) De-Demo'd Title Screen
void F_TitleScreenDrawer(void) void F_TitleScreenDrawer(void)
{ {

View file

@ -42,6 +42,7 @@ void F_IntroDrawer(void);
void F_TitleScreenDrawer(void); void F_TitleScreenDrawer(void);
void F_SkyScroll(const char *patchname); void F_SkyScroll(const char *patchname);
void F_CacheTitleScreen(void); void F_CacheTitleScreen(void);
void F_ReloadTitleScreenGraphics(void);
void F_GameEvaluationDrawer(void); void F_GameEvaluationDrawer(void);
void F_StartGameEvaluation(void); void F_StartGameEvaluation(void);

View file

@ -4407,8 +4407,8 @@ void G_AfterFileDeletion(void)
if (!Playing()) if (!Playing())
{ {
if (gamestate == GS_TITLESCREEN) if (gamestate == GS_TITLESCREEN || gamestate == GS_WAITINGPLAYERS)
F_CacheTitleScreen(); F_ReloadTitleScreenGraphics();
return; return;
} }

View file

@ -187,8 +187,8 @@ static tic_t keydown = 0;
// //
static void M_GoBack(INT32 choice); static void M_GoBack(INT32 choice);
static void M_StopMessage(INT32 choice);
static boolean stopstopmessage = false; boolean stopstopmessage = false;
#ifndef NONET #ifndef NONET
static void M_HandleServerPage(INT32 choice); static void M_HandleServerPage(INT32 choice);
@ -299,7 +299,6 @@ static void M_ServerOptions(INT32 choice);
#ifndef NONET #ifndef NONET
static void M_StartServerMenu(INT32 choice); static void M_StartServerMenu(INT32 choice);
static void M_ConnectMenu(INT32 choice); static void M_ConnectMenu(INT32 choice);
static void M_ConnectMenuModChecks(INT32 choice);
static void M_Refresh(INT32 choice); static void M_Refresh(INT32 choice);
static void M_Connect(INT32 choice); static void M_Connect(INT32 choice);
static void M_ChooseRoom(INT32 choice); static void M_ChooseRoom(INT32 choice);
@ -943,7 +942,7 @@ static menuitem_t MP_SplitServerMenu[] =
static menuitem_t MP_MainMenu[] = static menuitem_t MP_MainMenu[] =
{ {
{IT_HEADER, NULL, "Join a game", NULL, 0}, {IT_HEADER, NULL, "Join a game", NULL, 0},
{IT_STRING|IT_CALL, NULL, "Server browser...", M_ConnectMenuModChecks, 12}, {IT_STRING|IT_CALL, NULL, "Server browser...", M_ConnectMenu, 12},
{IT_STRING|IT_KEYHANDLER, NULL, "Specify server address:", M_HandleConnectIP, 22}, {IT_STRING|IT_KEYHANDLER, NULL, "Specify server address:", M_HandleConnectIP, 22},
{IT_HEADER, NULL, "Host a game", NULL, 54}, {IT_HEADER, NULL, "Host a game", NULL, 54},
{IT_STRING|IT_CALL, NULL, "Internet/LAN...", M_StartServerMenu, 66}, {IT_STRING|IT_CALL, NULL, "Internet/LAN...", M_StartServerMenu, 66},
@ -6268,7 +6267,7 @@ static void M_DrawMessageMenu(void)
} }
// default message handler // default message handler
static void M_StopMessage(INT32 choice) void M_StopMessage(INT32 choice)
{ {
(void)choice; (void)choice;
if (menuactive) if (menuactive)
@ -11506,20 +11505,6 @@ static void M_ConnectMenu(INT32 choice)
M_Refresh(0); M_Refresh(0);
} }
static void M_ConnectMenuModChecks(INT32 choice)
{
(void)choice;
// okay never mind we want to COMMUNICATE to the player pre-emptively instead of letting them try and then get confused when it doesn't work
if (modifiedgame)
{
M_StartMessage(M_GetText("You have add-ons loaded.\nYou won't be able to join netgames!\n\nTo play online, restart the game\nand don't load any addons.\nSRB2 will automatically add\neverything you need when you join.\n\n(Press a key)\n"),M_ConnectMenu,MM_EVENTHANDLER);
return;
}
M_ConnectMenu(-1);
}
UINT32 roomIds[NUM_LIST_ROOMS]; UINT32 roomIds[NUM_LIST_ROOMS];
static void M_RoomMenu(INT32 choice) static void M_RoomMenu(INT32 choice)

View file

@ -226,7 +226,11 @@ typedef enum
MM_EVENTHANDLER // the same of above but without 'y' or 'n' restriction MM_EVENTHANDLER // the same of above but without 'y' or 'n' restriction
// and routine is void routine(event_t *) (ex: set control) // and routine is void routine(event_t *) (ex: set control)
} menumessagetype_t; } menumessagetype_t;
extern boolean stopstopmessage;
void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtype); void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtype);
void M_StopMessage(INT32 choice);
typedef enum typedef enum
{ {

View file

@ -1256,6 +1256,29 @@ void W_UnloadWadFile(UINT16 num)
G_AfterFileDeletion(); G_AfterFileDeletion();
} }
void W_UnloadAddons(boolean remove_all_addons)
{
for (UINT16 i = mainwads + 1; i < numwadfiles;)
{
if (wadfiles[i])
{
if (!remove_all_addons && !wadfiles[i]->important)
{
i++;
continue;
}
W_UnloadFile(wadfiles[i]);
wadfiles[i] = NULL;
}
numwadfiles--;
for (UINT16 j = i; j < numwadfiles; j++)
wadfiles[j] = wadfiles[j + 1];
}
}
/** Make sure a lump number is valid. /** Make sure a lump number is valid.
* Compiles away to nothing if PARANOIA is not defined. * Compiles away to nothing if PARANOIA is not defined.
*/ */

View file

@ -179,6 +179,9 @@ void W_LoadFileScripts(UINT16 wadfilenum, boolean mainfile);
// Unloads a file. // Unloads a file.
void W_UnloadWadFile(UINT16 num); void W_UnloadWadFile(UINT16 num);
// Unloads all addons.
void W_UnloadAddons(boolean remove_all_addons);
const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump); const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump);
const char *W_CheckNameForNum(lumpnum_t lumpnum); const char *W_CheckNameForNum(lumpnum_t lumpnum);