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

View file

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

View file

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

View file

@ -3719,7 +3719,15 @@ static void Command_Delfile(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)

View file

@ -456,7 +456,6 @@ INT32 CL_CheckFiles(void)
// Modified game handling -- check for an identical file list
// must be identical in files loaded AND in order
// Return 2 on failure -- disconnect from server
if (modifiedgame)
{
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);
}
void F_ReloadTitleScreenGraphics(void)
{
if (curttmode == TTMODE_ALACROIX)
{
activettscale = 0;
F_FigureActiveTtScale();
}
else
F_CacheTitleScreen();
}
// (no longer) De-Demo'd Title Screen
void F_TitleScreenDrawer(void)
{

View file

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

View file

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

View file

@ -187,8 +187,8 @@ static tic_t keydown = 0;
//
static void M_GoBack(INT32 choice);
static void M_StopMessage(INT32 choice);
static boolean stopstopmessage = false;
boolean stopstopmessage = false;
#ifndef NONET
static void M_HandleServerPage(INT32 choice);
@ -299,7 +299,6 @@ static void M_ServerOptions(INT32 choice);
#ifndef NONET
static void M_StartServerMenu(INT32 choice);
static void M_ConnectMenu(INT32 choice);
static void M_ConnectMenuModChecks(INT32 choice);
static void M_Refresh(INT32 choice);
static void M_Connect(INT32 choice);
static void M_ChooseRoom(INT32 choice);
@ -943,7 +942,7 @@ static menuitem_t MP_SplitServerMenu[] =
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_CALL, NULL, "Server browser...", M_ConnectMenu, 12},
{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},
@ -6268,7 +6267,7 @@ static void M_DrawMessageMenu(void)
}
// default message handler
static void M_StopMessage(INT32 choice)
void M_StopMessage(INT32 choice)
{
(void)choice;
if (menuactive)
@ -11506,20 +11505,6 @@ static void M_ConnectMenu(INT32 choice)
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];
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
// and routine is void routine(event_t *) (ex: set control)
} menumessagetype_t;
extern boolean stopstopmessage;
void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtype);
void M_StopMessage(INT32 choice);
typedef enum
{

View file

@ -1256,6 +1256,29 @@ void W_UnloadWadFile(UINT16 num)
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.
* 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.
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_CheckNameForNum(lumpnum_t lumpnum);