Skip to content

Commit

Permalink
Make various game managers more tolerant of errors, rather than just …
Browse files Browse the repository at this point in the history
…straight disconnecting the client on error that are not neccessarily their fault.
  • Loading branch information
TLeonardUK committed Mar 19, 2024
1 parent aee02dd commit c2966f4
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ MessageHandleResult DS2_BloodMessageManager::Handle_RequestCreateBloodMessage(Ga
}
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to create blood message.");
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Failed to create blood message.");
}

std::string TypeStatisticKey = StringFormat("BloodMessage/TotalCreated");
Expand Down Expand Up @@ -365,8 +364,7 @@ MessageHandleResult DS2_BloodMessageManager::Handle_RequestEvaluateBloodMessage(
// If we can't find it, just return 0 evaluation, this shouldn't happen in practice.
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as attempted to evaluate unknown unknown message id '%u'.", Request->message_id());
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Client as attempted to evaluate unknown unknown message id '%u'.", Request->message_id());
}

if (ActiveMessage != nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ MessageHandleResult DS2_BloodstainManager::Handle_RequestCreateBloodstain(GameCl
}
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to create blood stain.");
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Failed to create blood stain.");
}

std::string TypeStatisticKey = StringFormat("Bloodstain/TotalCreated");
Expand Down Expand Up @@ -250,15 +249,22 @@ MessageHandleResult DS2_BloodstainManager::Handle_RequestGetDeadingGhost(GameCli
// Doesn't exist, no go.
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to retrieve bloodstain '%i'", Request->bloodstain_id());
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Failed to retrieve bloodstain '%i'", Request->bloodstain_id());
}

DS2_Frpg2RequestMessage::RequestGetDeadingGhostResponse Response;
Response.set_online_area_id(Request->online_area_id());
Response.set_cell_id(Request->cell_id());
Response.set_bloodstain_id(Request->bloodstain_id());
Response.set_data(ActiveStain->GhostData.data(), ActiveStain->GhostData.size());

if (ActiveStain == nullptr)
{
Response.mutable_data();
}
else
{
Response.set_data(ActiveStain->GhostData.data(), ActiveStain->GhostData.size());
}

if (!Client->MessageStream->Send(&Response, &Message))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ MessageHandleResult DS2_GhostManager::Handle_RequestCreateGhostData(GameClient*
}
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to create ghost.");
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Failed to create ghost.");
}

std::string TypeStatisticKey = StringFormat("Ghosts/TotalGhostsCreated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ MessageHandleResult DS2_RankingManager::Handle_RequestRegisterPowerStoneData(Gam
if (!Database.RegisterScore(0, Player.GetPlayerId(), Request->character_id(), score, Data))
{
WarningS(Client->GetName().c_str(), "Failed to register score in database.");
return MessageHandleResult::Error;
}

std::string TypeStatisticKey = StringFormat("Ranking/TotalRegistrations");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,15 @@ MessageHandleResult DS2_SignManager::Handle_RequestRemoveSign(GameClient* Client
if (auto Iter = std::find(Client->ActiveSummonSigns.begin(), Client->ActiveSummonSigns.end(), Sign); Iter != Client->ActiveSummonSigns.end())
{
Client->ActiveSummonSigns.erase(Iter);

// Tell anyone who is aware of this sign that its been removed.
RemoveSignAndNotifyAware(Sign);
}
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as attempted to remove summon sign that didn't belong to them, %i.", Request->sign_id());
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Client attempted to remove summon sign that didn't belong to them, %i.", Request->sign_id());
}

// Tell anyone who is aware of this sign that its been removed.
RemoveSignAndNotifyAware(Sign);

// Empty response, not sure what purpose this serves really other than saying message-recieved. Client
// doesn't work without it though.
DS2_Frpg2RequestMessage::RequestRemoveSignResponse Response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ MessageHandleResult DS3_BloodMessageManager::Handle_RequestCreateBloodMessage(Ga
}
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to create blood message.");
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Failed to create blood message.");
}

std::string TypeStatisticKey = StringFormat("BloodMessage/TotalCreated");
Expand Down Expand Up @@ -389,8 +388,7 @@ MessageHandleResult DS3_BloodMessageManager::Handle_RequestEvaluateBloodMessage(
// If we can't find it, just return 0 evaluation, this shouldn't happen in practice.
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as attempted to evaluate unknown unknown message id '%u'.", Request->message_id());
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Client attempted to evaluate unknown unknown message id '%u'.", Request->message_id());
}

if (ActiveMessage != nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ MessageHandleResult DS3_BloodstainManager::Handle_RequestCreateBloodstain(GameCl
}
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to create blood stain.");
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Failed to create bloodstain for client.");
}

std::string TypeStatisticKey = StringFormat("Bloodstain/TotalCreated");
Expand Down Expand Up @@ -205,14 +204,21 @@ MessageHandleResult DS3_BloodstainManager::Handle_RequestGetDeadingGhost(GameCli
// Doesn't exist, no go.
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to retrieve bloodstain '%i'", Request->bloodstain_id());
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Failed to retrieve bloodstain '%i', returning empty ghost data.", Request->bloodstain_id());
}

DS3_Frpg2RequestMessage::RequestGetDeadingGhostResponse Response;
Response.set_online_area_id(Request->online_area_id());
Response.set_bloodstain_id(Request->bloodstain_id());
Response.set_data(ActiveStain->GhostData.data(), ActiveStain->GhostData.size());

if (ActiveStain == nullptr)
{
Response.mutable_data();
}
else
{
Response.set_data(ActiveStain->GhostData.data(), ActiveStain->GhostData.size());
}

if (!Client->MessageStream->Send(&Response, &Message))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ MessageHandleResult DS3_GhostManager::Handle_RequestCreateGhostData(GameClient*
}
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to create ghost.");
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Failed to create ghost.");
}

std::string TypeStatisticKey = StringFormat("Ghosts/TotalGhostsCreated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,67 +499,68 @@ MessageHandleResult DS3_QuickMatchManager::Handle_RequestSendQuickMatchResult(Ga
std::shared_ptr<Character> Character = Database.FindCharacter(State.GetPlayerId(), State.GetCharacterId());
if (!Character)
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to find current character during QuickMatchResult.");
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Failed to find current character during QuickMatchResult.");
}
else
{
// Increase and return rank.
bool IsDuel = (Request->mode() == DS3_Frpg2RequestMessage::QuickMatchGameMode::Duel);

// Increase and return rank.
bool IsDuel = (Request->mode() == DS3_Frpg2RequestMessage::QuickMatchGameMode::Duel);

uint32_t OriginalRank = IsDuel ? Character->QuickMatchDuelRank : Character->QuickMatchBrawlRank;
uint32_t OriginalXP = IsDuel ? Character->QuickMatchDuelXp : Character->QuickMatchBrawlXp;
uint32_t OriginalRank = IsDuel ? Character->QuickMatchDuelRank : Character->QuickMatchBrawlRank;
uint32_t OriginalXP = IsDuel ? Character->QuickMatchDuelXp : Character->QuickMatchBrawlXp;

uint32_t& Rank = IsDuel ? Character->QuickMatchDuelRank : Character->QuickMatchBrawlRank;
uint32_t& XP = IsDuel ? Character->QuickMatchDuelXp : Character->QuickMatchBrawlXp;
uint32_t& Rank = IsDuel ? Character->QuickMatchDuelRank : Character->QuickMatchBrawlRank;
uint32_t& XP = IsDuel ? Character->QuickMatchDuelXp : Character->QuickMatchBrawlXp;

switch (Request->result())
{
case DS3_Frpg2RequestMessage::QuickMatchResult::QuickMatchResult_Win:
{
XP += Config.QuickMatchWinXp;
break;
}
case DS3_Frpg2RequestMessage::QuickMatchResult::QuickMatchResult_Draw:
{
XP += Config.QuickMatchDrawXp;
break;
}
case DS3_Frpg2RequestMessage::QuickMatchResult::QuickMatchResult_Lose:
switch (Request->result())
{
XP += Config.QuickMatchLoseXp;
break;
}
case DS3_Frpg2RequestMessage::QuickMatchResult::QuickMatchResult_Disconnect:
{
// No XP gained.
break;
case DS3_Frpg2RequestMessage::QuickMatchResult::QuickMatchResult_Win:
{
XP += Config.QuickMatchWinXp;
break;
}
case DS3_Frpg2RequestMessage::QuickMatchResult::QuickMatchResult_Draw:
{
XP += Config.QuickMatchDrawXp;
break;
}
case DS3_Frpg2RequestMessage::QuickMatchResult::QuickMatchResult_Lose:
{
XP += Config.QuickMatchLoseXp;
break;
}
case DS3_Frpg2RequestMessage::QuickMatchResult::QuickMatchResult_Disconnect:
{
// No XP gained.
break;
}
}
}

while (Rank < Config.QuickMatchRankXp.size() - 1)
{
uint32_t NextRankXP = Config.QuickMatchRankXp[Rank + 1];
if (XP > NextRankXP)
while (Rank < Config.QuickMatchRankXp.size() - 1)
{
Rank++;
XP -= NextRankXP;
}
else
{
break;
uint32_t NextRankXP = Config.QuickMatchRankXp[Rank + 1];
if (XP > NextRankXP)
{
Rank++;
XP -= NextRankXP;
}
else
{
break;
}
}
}

Response.mutable_new_local_rank()->set_rank(Rank);
Response.mutable_new_local_rank()->set_xp(XP);
Response.mutable_new_local_rank()->set_rank(Rank);
Response.mutable_new_local_rank()->set_xp(XP);

LogS(Client->GetName().c_str(), "Player finished undead match, ranked up to: rank=%i xp=%i (from rank=%i xp=%i)", Rank, XP, OriginalRank, OriginalXP);
LogS(Client->GetName().c_str(), "Player finished undead match, ranked up to: rank=%i xp=%i (from rank=%i xp=%i)", Rank, XP, OriginalRank, OriginalXP);

// Update character state.
if (!Database.UpdateCharacterQuickMatchRank(State.GetPlayerId(), State.GetCharacterId(), Character->QuickMatchDuelRank, Character->QuickMatchDuelXp, Character->QuickMatchBrawlRank, Character->QuickMatchBrawlXp))
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to update their quick match result.");
return MessageHandleResult::Error;
// Update character state.
if (!Database.UpdateCharacterQuickMatchRank(State.GetPlayerId(), State.GetCharacterId(), Character->QuickMatchDuelRank, Character->QuickMatchDuelXp, Character->QuickMatchBrawlRank, Character->QuickMatchBrawlXp))
{
WarningS(Client->GetName().c_str(), "Disconnecting client as failed to update their quick match result.");
return MessageHandleResult::Error;
}
}

std::string TypeStatisticKey = StringFormat("QuickMatch/TotalMatches");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ MessageHandleResult DS3_RankingManager::Handle_RequestRegisterRankingData(GameCl
if (!Database.RegisterScore(Request->board_id(), Player.GetPlayerId(), Request->character_id(), Request->score(), Data))
{
WarningS(Client->GetName().c_str(), "Failed to register score in database.");
return MessageHandleResult::Error;
}

std::string TypeStatisticKey = StringFormat("Ranking/TotalRegistrations");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,15 @@ MessageHandleResult DS3_SignManager::Handle_RequestRemoveSign(GameClient* Client
if (auto Iter = std::find(Client->ActiveSummonSigns.begin(), Client->ActiveSummonSigns.end(), Sign); Iter != Client->ActiveSummonSigns.end())
{
Client->ActiveSummonSigns.erase(Iter);

// Tell anyone who is aware of this sign that its been removed.
RemoveSignAndNotifyAware(Sign);
}
else
{
WarningS(Client->GetName().c_str(), "Disconnecting client as attempted to remove summon sign that didn't belong to them, %i.", Request->sign_id());
return MessageHandleResult::Error;
WarningS(Client->GetName().c_str(), "Client attempted to remove summon sign that didn't belong to them, %i.", Request->sign_id());
}

// Tell anyone who is aware of this sign that its been removed.
RemoveSignAndNotifyAware(Sign);

// Empty response, not sure what purpose this serves really other than saying message-recieved. Client
// doesn't work without it though.
DS3_Frpg2RequestMessage::RequestRemoveSignResponse Response;
Expand Down
8 changes: 5 additions & 3 deletions Source/Server/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ bool Server::Init()
}

// Patch old server ip.
#ifdef _DEBUG
#if 1//def _DEBUG
//Config.MasterServerIp = "127.0.0.1";
Config.MasterServerIp = "ds3os-master.timleonard.uk";
Config.ServerName = "Debugging Server";
Config.ServerDescription = "Used for debugging by Infini, don't use.";
//Config.ServerName = "Debugging Server";
//Config.ServerDescription = "Used for debugging by Infini, don't use.";
#else
if (Config.MasterServerIp == "timleonard.uk")
{
Expand Down Expand Up @@ -304,6 +304,7 @@ bool Server::Init()
}
}

#if 0
#define WriteState(State, bEnabled) WriteLog(false, bEnabled ? ConsoleColor::Green : ConsoleColor::Red, "", "Log", "%-25s: %s", State, bEnabled ? "Enabled" : "Disabled");
WriteState("Blood Messages", !Config.DisableBloodMessages);
WriteState("Blood Stains", !Config.DisableBloodStains);
Expand All @@ -313,6 +314,7 @@ bool Server::Init()
WriteState("Coop (Auto Summon)", !Config.DisableCoopAutoSummon);
WriteState("Coop", !Config.DisableCoop);
#undef WriteState
#endif

return true;
}
Expand Down

0 comments on commit c2966f4

Please sign in to comment.