Party Fix (#690)

This commit is contained in:
Edo 2023-01-01 11:47:50 +00:00 committed by GitHub
parent dcf701562f
commit 165681f393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 121 additions and 147 deletions

View File

@ -400,31 +400,19 @@ namespace Components
{
const Utils::InfoString info(data);
const auto _0 = gsl::finally([&]
{
ServerList::Insert(address, info);
Friends::UpdateServer(address, info.get("hostname"), info.get("mapname"));
});
// Handle connection
if (!Container.valid)
if (Party::Container.valid)
{
return;
}
if (Container.target == address)
if (Party::Container.target == address)
{
return;
}
// Invalidate handler for future packets
Container.valid = false;
Container.info = info;
Party::Container.valid = false;
Party::Container.info = info;
Container.matchType = atoi(info.get("matchtype").data());
const auto securityLevel = static_cast<uint32_t>(std::strtol(info.get("securityLevel").data(), nullptr, 10));
Party::Container.matchType = atoi(info.get("matchtype").data());
auto securityLevel = static_cast<std::uint32_t>(atoi(info.get("securityLevel").data()));
bool isUsermap = !info.get("usermaphash").empty();
const auto usermapHash = static_cast<uint32_t>(std::strtol(info.get("usermaphash").data(), nullptr, 10));
auto usermapHash = static_cast<std::uint32_t>(atoi(info.get("usermaphash").data()));
std::string mod = (*Game::fs_gameDirVar)->current.string;
@ -440,59 +428,42 @@ namespace Components
Download::SV_wwwBaseUrl.set("");
}
if (info.get("challenge") != Container.challenge)
if (info.get("challenge") != Party::Container.challenge)
{
ConnectError("Invalid join response: Challenge mismatch.");
return;
Party::ConnectError("Invalid join response: Challenge mismatch.");
}
if (securityLevel > Auth::GetSecurityLevel())
else if (securityLevel > Auth::GetSecurityLevel())
{
Command::Execute("closemenu popup_reconnectingtoparty");
Auth::IncreaseSecurityLevel(securityLevel, "reconnect");
return;
}
if (!Container.matchType)
else if (!Party::Container.matchType)
{
ConnectError("Server is not hosting a match.");
return;
Party::ConnectError("Server is not hosting a match.");
}
if (Container.matchType > 2 || Container.matchType < 0)
else if (Party::Container.matchType > 2 || Party::Container.matchType < 0)
{
ConnectError("Invalid join response: Unknown matchtype");
return;
Party::ConnectError("Invalid join response: Unknown matchtype");
}
if (Container.info.get("mapname").empty() || Container.info.get("gametype").empty())
else if (Party::Container.info.get("mapname").empty() || Party::Container.info.get("gametype").empty())
{
ConnectError("Invalid map or gametype.");
return;
Party::ConnectError("Invalid map or gametype.");
}
if (Container.info.get("isPrivate") == "1"s && !Dvar::Var("password").get<std::string>().empty())
else if (Party::Container.info.get("isPrivate") == "1"s && !Dvar::Var("password").get<std::string>().length())
{
ConnectError("A password is required to join this server! Set it at the bottom of the serverlist.");
return;
Party::ConnectError("A password is required to join this server! Set it at the bottom of the serverlist.");
}
if (isUsermap && usermapHash != Maps::GetUsermapHash(info.get("mapname")))
else if (isUsermap && usermapHash != Maps::GetUsermapHash(info.get("mapname")))
{
Command::Execute("closemenu popup_reconnectingtoparty");
Download::InitiateMapDownload(info.get("mapname"), info.get("isPrivate") == "1"s);
return;
Download::InitiateMapDownload(info.get("mapname"), info.get("isPrivate") == "1");
}
if (!info.get("fs_game").empty() && Utils::String::ToLower(mod) != Utils::String::ToLower(info.get("fs_game")))
else if (!info.get("fs_game").empty() && Utils::String::ToLower(mod) != Utils::String::ToLower(info.get("fs_game")))
{
Command::Execute("closemenu popup_reconnectingtoparty");
Download::InitiateClientDownload(info.get("fs_game"), info.get("isPrivate") == "1"s);
return;
}
if (*(*Game::fs_gameDirVar)->current.string && info.get("fs_game").empty())
else if (!Dvar::Var("fs_game").get<std::string>().empty() && info.get("fs_game").empty())
{
Game::Dvar_SetString(*Game::fs_gameDirVar, "");
@ -502,21 +473,18 @@ namespace Components
}
Command::Execute("reconnect", false);
return;
}
if (!Maps::CheckMapInstalled(Container.info.get("mapname"), true))
else
{
return;
}
if (!Maps::CheckMapInstalled(Party::Container.info.get("mapname"), true)) return;
Container.motd = info.get("sv_motd");
Party::Container.motd = info.get("sv_motd");
if (Container.matchType == 1) // Party
if (Party::Container.matchType == 1) // Party
{
// Send playlist request
Container.requestTime = Game::Sys_Milliseconds();
Container.awaitingPlaylist = true;
Party::Container.requestTime = Game::Sys_Milliseconds();
Party::Container.awaitingPlaylist = true;
Network::SendCommand(Party::Container.target, "getplaylist", Dvar::Var("password").get<std::string>());
// This is not a safe method
@ -526,7 +494,7 @@ namespace Components
Command::Execute("disconnect", true);
}
}
else if (Container.matchType == 2) // Match
else if (Party::Container.matchType == 2) // Match
{
int clients;
int maxClients;
@ -544,7 +512,7 @@ namespace Components
if (clients >= maxClients)
{
ConnectError("@EXE_SERVERISFULL");
Party::ConnectError("@EXE_SERVERISFULL");
}
else
{
@ -553,9 +521,15 @@ namespace Components
Game::Menus_CloseAll(Game::uiContext);
Game::_XSESSION_INFO hostInfo;
Game::CL_ConnectFromParty(0, &hostInfo, *Container.target.get(), 0, 0, Container.info.get("mapname").data(), Container.info.get("gametype").data());
Game::CL_ConnectFromParty(0, &hostInfo, *Party::Container.target.get(), 0, 0, Party::Container.info.get("mapname").data(), Party::Container.info.get("gametype").data());
}
}
}
}
}
ServerList::Insert(address, info);
Friends::UpdateServer(address, info.get("hostname"), info.get("mapname"));
});
}
}