Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various small refactorings / tweaks #3428

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 50 additions & 6 deletions lib/netplay/netplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ class PlayerManagementRecord
// Variables

NETPLAY NetPlay;
static bool allow_joining = false;
static bool server_not_there = false;
static bool allow_joining = false;
static bool server_not_there = false;
static bool lobby_disabled = false;
static std::string lobby_disabled_info_link_url;
static GAMESTRUCT gamestruct;

static std::vector<WZFile> DownloadingWzFiles;
Expand Down Expand Up @@ -417,6 +419,22 @@ bool NETGameIsLocked()
return NetPlay.GamePassworded;
}

bool NET_getLobbyDisabled()
{
return lobby_disabled;
}

const std::string& NET_getLobbyDisabledInfoLinkURL()
{
return lobby_disabled_info_link_url;
}

void NET_setLobbyDisabled(const std::string& infoLinkURL)
{
lobby_disabled = true;
lobby_disabled_info_link_url = infoLinkURL;
}

// Sets if the game is password protected or not
void NETGameLocked(bool flag)
{
Expand Down Expand Up @@ -3409,6 +3427,14 @@ bool LobbyServerConnectionHandler::connect()
{
return false;
}
if (lobby_disabled)
{
debug(LOG_ERROR, "Multiplayer lobby support unavailable. Please update your client.");
wz_command_interface_output("WZEVENT: lobbyerror: Client support disabled / unavailable\n");
gamestruct.gameId = 0;
server_not_there = true;
return true; // return true once, so that NETallowJoining processes the "first time connect" branch
}
if (currentState == LobbyConnectionState::Connecting_WaitingForResponse || currentState == LobbyConnectionState::Connected)
{
return false; // already connecting or connected
Expand Down Expand Up @@ -3519,14 +3545,20 @@ bool LobbyServerConnectionHandler::disconnect()

queuedServerUpdate = false;

ActivityManager::instance().hostGameLobbyServerDisconnect();

currentState = LobbyConnectionState::Disconnected;
return true;
}

void LobbyServerConnectionHandler::sendUpdate()
{
if (server_not_there)
if (lobby_disabled || server_not_there)
{
if (currentState != LobbyConnectionState::Disconnected)
{
disconnect();
}
return;
}

Expand All @@ -3545,18 +3577,25 @@ void LobbyServerConnectionHandler::sendUpdate()
void LobbyServerConnectionHandler::sendUpdateNow()
{
ASSERT_OR_RETURN(, rs_socket != nullptr, "Null socket");
if (lobby_disabled)
{
if (currentState != LobbyConnectionState::Disconnected)
{
disconnect();
}
return;
}

if (!NETsendGAMESTRUCT(rs_socket, &gamestruct))
{
disconnect();
ActivityManager::instance().hostGameLobbyServerDisconnect();
}
lastServerUpdate = realTime;
queuedServerUpdate = false;
// newer lobby server will return a lobby response / status after each update call
if (rs_socket && readLobbyResponse(rs_socket, NET_TIMEOUT_DELAY) == SOCKET_ERROR)
{
disconnect();
ActivityManager::instance().hostGameLobbyServerDisconnect();
}
}

Expand All @@ -3567,7 +3606,6 @@ void LobbyServerConnectionHandler::sendKeepAlive()
{
// The socket has been invalidated, so get rid of it. (using them now may cause SIGPIPE).
disconnect();
ActivityManager::instance().hostGameLobbyServerDisconnect();
}
lastServerUpdate = realTime;
}
Expand Down Expand Up @@ -4585,6 +4623,12 @@ bool NETfindGames(std::vector<GAMESTRUCT>& results, size_t startingIndex, size_t
{
size_t gamecount = 0;
results.clear();

if (lobby_disabled)
{
return true;
}

bool success = NETenumerateGames([&results, &gamecount, startingIndex, resultsLimit, onlyMatchingLocalVersion](const GAMESTRUCT &lobbyGame) -> bool {
if (gamecount++ < startingIndex)
{
Expand Down
4 changes: 4 additions & 0 deletions lib/netplay/netplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ const std::vector<WZFile>& NET_getDownloadingWzFiles();
void NET_addDownloadingWZFile(WZFile&& newFile);
void NET_clearDownloadingWZFiles();

bool NET_getLobbyDisabled();
const std::string& NET_getLobbyDisabledInfoLinkURL();
void NET_setLobbyDisabled(const std::string& infoLinkURL);

bool NETGameIsLocked();
void NETGameLocked(bool flag);
void NETresetGamePassword();
Expand Down
10 changes: 5 additions & 5 deletions src/clparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ static std::string specialGetBaseDir(const std::string& platformSpecificPath, st
* set up first.
* \param argc number of arguments given
* \param argv string array of the arguments
* \return Returns true on success, false on error */
bool ParseCommandLineEarly(int argc, const char * const *argv)
* \return See ParseCLIEarlyResult enum */
ParseCLIEarlyResult ParseCommandLineEarly(int argc, const char * const *argv)
{
poptContext poptCon = poptGetContext(nullptr, argc, argv, getOptionsTable(), 0);
int iOption;
Expand Down Expand Up @@ -615,11 +615,11 @@ bool ParseCommandLineEarly(int argc, const char * const *argv)

case CLI_HELP:
poptPrintHelp(poptCon, stdout);
return false;
return ParseCLIEarlyResult::HANDLED_QUIT_EARLY_COMMAND;

case CLI_VERSION:
printf("Warzone 2100 - %s\n", version_getFormattedVersionString());
return false;
return ParseCLIEarlyResult::HANDLED_QUIT_EARLY_COMMAND;

#if defined(WZ_OS_WIN)
case CLI_WIN_ENABLE_CONSOLE:
Expand Down Expand Up @@ -693,7 +693,7 @@ bool ParseCommandLineEarly(int argc, const char * const *argv)
};
}

return true;
return ParseCLIEarlyResult::OK_CONTINUE;
}

//! second half of parsing the commandline
Expand Down
8 changes: 7 additions & 1 deletion src/clparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@

// parse the commandline
bool ParseCommandLine(int argc, const char * const *argv);
bool ParseCommandLineEarly(int argc, const char * const *argv);

enum class ParseCLIEarlyResult
{
OK_CONTINUE,
HANDLED_QUIT_EARLY_COMMAND
};
ParseCLIEarlyResult ParseCommandLineEarly(int argc, const char * const *argv);
bool ParseCommandLineDebugFlags(int argc, const char * const *argv);

bool autogame_enabled();
Expand Down
38 changes: 36 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,38 @@ static void cleanupOldLogFiles()
});
}

static void mainProcessCompatCheckResults(CompatCheckResults results)
{
// Since this may be called from any thread, use wzAsyncExecOnMainThread
wzAsyncExecOnMainThread([results]() {
if (!results.successfulCheck)
{
return;
}
if (!results.hasIssue())
{
return;
}

// supported_terrain
auto& configFlags = results.issue.value().configFlags;
if (configFlags.supportedTerrain.count(getTerrainShaderQuality()) == 0)
{
// current terrain mode is not in supported list
// if not in a game, change the terrain shader quality back to default
if (GetGameMode() != GS_NORMAL)
{
setTerrainShaderQuality(TerrainShaderQuality::MEDIUM);
}
}
// multilobby
if (!configFlags.multilobby)
{
NET_setLobbyDisabled(results.issue.value().infoLink);
}
});
}

// for backend detection
extern const char *BACKEND;

Expand Down Expand Up @@ -1861,9 +1893,10 @@ int realmain(int argc, char *argv[])
urlRequestInit();

// find early boot info
if (!ParseCommandLineEarly(utfargc, utfargv))
ParseCLIEarlyResult earlyCommandLineParsingResult = ParseCommandLineEarly(utfargc, utfargv);
if (earlyCommandLineParsingResult != ParseCLIEarlyResult::OK_CONTINUE)
{
return EXIT_FAILURE;
return (earlyCommandLineParsingResult == ParseCLIEarlyResult::HANDLED_QUIT_EARLY_COMMAND) ? 0 : EXIT_FAILURE;
}

/* Initialize the write/config directory for PhysicsFS.
Expand Down Expand Up @@ -2157,6 +2190,7 @@ int realmain(int argc, char *argv[])
break;
}

asyncGetCompatCheckResults(mainProcessCompatCheckResults);
WzInfoManager::initialize();
#if defined(ENABLE_DISCORD)
discordRPCInitialize();
Expand Down
38 changes: 38 additions & 0 deletions src/multiint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@
#include "faction.h"
#include "multilobbycommands.h"
#include "stdinreader.h"
#include "urlhelpers.h"
#include "hci/quickchat.h"

#include "activity.h"
#include <algorithm>
#include "3rdparty/gsl_finally.h"

#define MAP_PREVIEW_DISPLAY_TIME 2500 // number of milliseconds to show map in preview
#define LOBBY_DISABLED_TAG "lobbyDisabled"
#define VOTE_TAG "voting"
#define KICK_REASON_TAG "kickReason"
#define SLOTTYPE_TAG_PREFIX "slotType"
Expand Down Expand Up @@ -6034,6 +6036,34 @@ static void randomizeOptions()
}
}

void displayLobbyDisabledNotification()
{
if (!hasNotificationsWithTag(LOBBY_DISABLED_TAG))
{
WZ_Notification notification;
notification.duration = 0;
notification.contentTitle = _("Multiplayer Lobby Support Unavailable");

notification.contentText = _("Your client cannot connect to the mutiplayer lobby.");
notification.contentText += "\n\n";
notification.contentText += _("Please click the button below for more information on how to fix it.");

std::string infoLink = NET_getLobbyDisabledInfoLinkURL();
notification.action = WZ_Notification_Action(_("More Information"), [infoLink](const WZ_Notification&) {
// Open the infoLink url
wzAsyncExecOnMainThread([infoLink]{
if (!openURLInBrowser(infoLink.c_str()))
{
debug(LOG_ERROR, "Failed to open url in browser: \"%s\"", infoLink.c_str());
}
});
});
notification.tag = LOBBY_DISABLED_TAG;

addNotification(notification, WZ_Notification_Trigger::Immediate());
}
}

bool WzMultiplayerOptionsTitleUI::startHost()
{
resetReadyStatus(false);
Expand All @@ -6055,6 +6085,11 @@ bool WzMultiplayerOptionsTitleUI::startHost()
return false;
}

if (NET_getLobbyDisabled())
{
displayLobbyDisabledNotification();
}

bInActualHostedLobby = true;

widgDelete(psWScreen, MULTIOP_REFRESH);
Expand Down Expand Up @@ -6372,6 +6407,7 @@ void startMultiplayerGame()
wz_command_interface_output("WZEVENT: startMultiplayerGame\n");
debug(LOG_INFO, "startMultiplayerGame");

cancelOrDismissNotificationsWithTag(LOBBY_DISABLED_TAG);
cancelOrDismissNotificationIfTag([](const std::string& tag) {
return (tag.rfind(SLOTTYPE_TAG_PREFIX, 0) == 0);
});
Expand Down Expand Up @@ -6900,6 +6936,7 @@ void WzMultiplayerOptionsTitleUI::frontendMultiMessages(bool running)
}
case NET_FIREUP: // campaign game started.. can fire the whole shebang up...
cancelOrDismissNotificationsWithTag(VOTE_TAG); // don't need vote notifications anymore
cancelOrDismissNotificationsWithTag(LOBBY_DISABLED_TAG);
cancelOrDismissNotificationIfTag([](const std::string& tag) {
return (tag.rfind(SLOTTYPE_TAG_PREFIX, 0) == 0);
});
Expand Down Expand Up @@ -7326,6 +7363,7 @@ TITLECODE WzMultiplayerOptionsTitleUI::run()
if (!NetPlay.isHostAlive && ingame.side == InGameSide::MULTIPLAYER_CLIENT)
{
cancelOrDismissNotificationsWithTag(VOTE_TAG);
cancelOrDismissNotificationsWithTag(LOBBY_DISABLED_TAG);
cancelOrDismissNotificationIfTag([](const std::string& tag) {
return (tag.rfind(SLOTTYPE_TAG_PREFIX, 0) == 0);
});
Expand Down
1 change: 1 addition & 0 deletions src/multiint.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void sendRoomNotifyMessage(char const *text);
void sendRoomSystemMessageToSingleReceiver(char const *text, uint32_t receiver);
void displayRoomSystemMessage(char const *text);
void displayRoomNotifyMessage(char const *text);
void displayLobbyDisabledNotification();

void handleAutoReadyRequest();

Expand Down
16 changes: 14 additions & 2 deletions src/titleui/gamefind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ void WzGameFindTitleUI::start()
pie_LoadBackDrop(SCREEN_RANDOMBDROP);
}

if (NET_getLobbyDisabled())
{
displayLobbyDisabledNotification();
}

addGames(); // now add games.
displayConsoleMessages();
}
Expand Down Expand Up @@ -224,7 +229,14 @@ void WzGameFindTitleUI::addConsoleBox()
setConsolePermanence(true, true);
setConsoleLineInfo(3); // use x lines on chat window

addConsoleMessage(_("Connecting to the lobby server..."), DEFAULT_JUSTIFY, NOTIFY_MESSAGE);
if (!NET_getLobbyDisabled())
{
addConsoleMessage(_("Connecting to the lobby server..."), DEFAULT_JUSTIFY, NOTIFY_MESSAGE);
}
else
{
addConsoleMessage(_("Multiplayer Lobby Support Unavailable"), DEFAULT_JUSTIFY, SYSTEM_MESSAGE, false, MAX_CONSOLE_MESSAGE_DURATION);
}
displayConsoleMessages();
return;
}
Expand Down Expand Up @@ -675,7 +687,7 @@ void WzGameFindTitleUI::addGames()
switch (getLobbyError())
{
case ERROR_NOERROR:
if (NetPlay.HaveUpgrade)
if (NetPlay.HaveUpgrade || NET_getLobbyDisabled())
{
txt = _("There appears to be a game update available!");
}
Expand Down
Loading
Loading