Skip to content

Commit

Permalink
Prevented re-sending chat from the local server if server tags are hi…
Browse files Browse the repository at this point in the history
…dden
  • Loading branch information
Zachar543 committed Aug 5, 2018
1 parent 654d8e8 commit 9f9bcd2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
7 changes: 4 additions & 3 deletions ArkCrossServerChat/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool ChatMessageCallback(AShooterPlayerController* _AShooterPlayerController, FS
std::wstring msg;
if (_AShooterPlayerController && Message && Mode == EChatSendMode::Type::GlobalChat)
{
lastChatMessageTime = _AShooterPlayerController->LastChatMessageTimeField()();
lastChatMessageTime = _AShooterPlayerController->LastChatMessageTimeField();
msg = std::wstring(ArkApi::Tools::ConvertToWideStr(Message->ToString()));

auto steamId = static_cast<int64>(ArkApi::GetApiUtils().GetSteamIdFromController(_AShooterPlayerController));
Expand All @@ -22,7 +22,7 @@ bool ChatMessageCallback(AShooterPlayerController* _AShooterPlayerController, FS
auto tribeName = GetTribeName(_AShooterPlayerController);

auto icon = playerControllerEx->bIsAdminField()()
&& !_AShooterPlayerController->bSuppressAdminIconField()()
&& !_AShooterPlayerController->bSuppressAdminIconField()
? ChatIcon::Admin
: ChatIcon::None;

Expand Down Expand Up @@ -53,7 +53,8 @@ bool ChatMessageCallback(AShooterPlayerController* _AShooterPlayerController, FS
Log::GetLog()->error("({} {}) Unexpected DB error {}", __FILE__, __FUNCTION__, e.what());
}

return true;
// To prevent duplicate chat messages when other chat-based plugins are in use, return false if we don't intent to modify locally-sent global chat.
return !plugin.hideServerTagOnLocal;
}

return false;
Expand Down
15 changes: 9 additions & 6 deletions ArkCrossServerChat/MessageHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ void HandleMessageFromDatabase(
auto &plugin = Plugin::Get();
auto isLocal = serverKey.compare(plugin.serverKey) == 0;

// If we get a local, non-rcon chat message and we don't want to modify the server tag, don't let OnChatMessageCallback get in the way of other plugins doing the same chat modifications.
if (rcon == 0 && isLocal && plugin.hideServerTagOnLocal) return;

//send chat message to users
if (rcon == 0)
{
Expand All @@ -109,12 +112,12 @@ void HandleMessageFromDatabase(
if (chatIcon == ChatIcon::Admin)
{
auto engine = Globals::GEngine()();
auto primalglobals = engine->GameSingletonField()();
auto gamedata = primalglobals->PrimalGameDataOverrideField()();
if (!gamedata) gamedata = primalglobals->PrimalGameDataField()();
auto primalglobals = engine->GameSingletonField();
auto gamedata = primalglobals->PrimalGameDataOverrideField();
if (!gamedata) gamedata = primalglobals->PrimalGameDataField();

auto texture = gamedata->NameTagServerAdminField()();
if (texture) iconTexture = gamedata->NameTagServerAdminField()();
auto texture = gamedata->NameTagServerAdminField();
if (texture) iconTexture = gamedata->NameTagServerAdminField();
}

auto name = FString(FromUTF16(characterName).c_str());
Expand All @@ -135,7 +138,7 @@ void HandleMessageFromDatabase(
if (player_controller)
{
auto player_character = player_controller->GetPlayerCharacter();
if (player_character) linkedPlayerDataID = player_character->LinkedPlayerDataIDField()();
if (player_character) linkedPlayerDataID = player_character->LinkedPlayerDataIDField();
}
}

Expand Down
14 changes: 7 additions & 7 deletions ArkCrossServerChat/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void SendRconChatMessageToAll(std::wstring message)

FString msg(message.c_str());

auto playerControllers = world->PlayerControllerListField()();
auto playerControllers = world->PlayerControllerListField();
for (auto playerController : playerControllers)
{
auto aShooterPC = static_cast<AShooterPlayerController*>(playerController.Get());
Expand Down Expand Up @@ -40,7 +40,7 @@ void SendChatMessageToAll(
auto world = ArkApi::GetApiUtils().GetWorld();
if (!world) return;

auto playerControllers = world->PlayerControllerListField()();
auto playerControllers = world->PlayerControllerListField();
for (auto playerController : playerControllers)
{
AShooterPlayerController* aShooterPC = static_cast<AShooterPlayerController*>(playerController.Get());
Expand All @@ -52,8 +52,8 @@ std::string GetPlayerName(AShooterPlayerController* playerController)
{
std::string playerName;

auto playerState = playerController->PlayerStateField()();
if (playerState) playerName = ToUTF8(*playerState->PlayerNameField()());
auto playerState = playerController->PlayerStateField();
if (playerState) playerName = ToUTF8(*playerState->PlayerNameField());

return playerName;
}
Expand All @@ -69,11 +69,11 @@ std::string GetTribeName(AShooterPlayerController* playerController)
{
std::string tribeName;

auto playerState = reinterpret_cast<AShooterPlayerState*>(playerController->PlayerStateField()());
auto playerState = reinterpret_cast<AShooterPlayerState*>(playerController->PlayerStateField());
if (playerState)
{
auto tribeData = playerState->MyTribeDataField()();
tribeName = tribeData->TribeNameField()().ToString();
auto tribeData = playerState->MyTribeDataField();
tribeName = tribeData->TribeNameField().ToString();
}

return tribeName;
Expand Down

0 comments on commit 9f9bcd2

Please sign in to comment.