Skip to content

Commit

Permalink
Bots: Replace chat upload to lobby with simple info logging (#12741)
Browse files Browse the repository at this point in the history
Commentary:
  - Drawback: bot chat history will no longer be readily available
    to moderators. That was useful when deciding "he-said-she-said"
    style disputes.
  - Benefits: fixes potential infinite loop that would crash
    the bot & simplifies.

Fix details:
  - Any warn/error message is sent as a chat message. Any
    chat message in turn is sent to the lobby. If there is
    an error sending a message to the lobby, it can yield
    an error message, which in turn triggers a chat message,
    which in turn yields another upload to the lobby thereby
    starting an infinite cycle.
    If we do not send messages up to the lobby, then this is
    no longer a problem.

Future plans:
  - Overall, ideally we can invest efforts in "network relay"
    rather than bot hosts, and remove all of the headless-game
    code entirely.
  • Loading branch information
DanVanAtta committed Jul 21, 2024
1 parent 1aa85c6 commit dcda979
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package games.strategy.engine.chat;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.triplea.domain.data.UserName;
import org.triplea.game.chat.ChatModel;

/** Headless version of ChatPanel. */
@Slf4j
public class HeadlessChat implements ChatMessageListener, ChatModel {
@Getter(onMethod_ = @Override)
private final Chat chat;
Expand All @@ -17,7 +19,9 @@ public HeadlessChat(final Chat chat) {
public void eventReceived(final String eventText) {}

@Override
public void messageReceived(final UserName fromPlayer, final String chatMessage) {}
public void messageReceived(final UserName fromPlayer, final String chatMessage) {
log.info(String.format("Chat Message {Player: %s, Message: %s}", fromPlayer, chatMessage));
}

@Override
public void slapped(final UserName from) {}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,6 @@ private GameHostingResponse createServerMessenger(final ServerConnectionProps pr
chatModel =
launchAction.createChatModel(CHAT_NAME, messengers, ClientNetworkBridge.NO_OP_SENDER);

if (gameToLobbyConnection != null && lobbyWatcherThread != null) {
chatModel
.getChat()
.addChatListener(
ServerChatUpload.builder()
.gameToLobbyConnection(gameToLobbyConnection)
.hostName(messengers.getLocalNode().getPlayerName())
.gameIdSupplier(() -> lobbyWatcherThread.getGameId().orElse(null))
.build());
}

serverMessenger.setAcceptNewConnections(true);
gameDataChanged();
return gameHostingResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public interface LobbyWatcherClient {
String REMOVE_GAME_PATH = "/lobby/games/remove-game";
String PLAYER_JOINED_PATH = "/lobby/games/player-joined";
String PLAYER_LEFT_PATH = "/lobby/games/player-left";
String UPLOAD_CHAT_PATH = "/lobby/chat/upload";

static LobbyWatcherClient newClient(final URI serverUri, final ApiKey apiKey) {
return HttpClient.newClient(
Expand All @@ -43,13 +42,6 @@ default void updateGame(final String gameId, final LobbyGame lobbyGame) {
@RequestLine("POST " + LobbyWatcherClient.REMOVE_GAME_PATH)
void removeGame(String gameId);

@RequestLine("POST " + LobbyWatcherClient.UPLOAD_CHAT_PATH)
String uploadChatMessage(ChatMessageUpload chatMessageUpload);

default void uploadChatMessage(final ChatUploadParams uploadChatMessageParams) {
uploadChatMessage(uploadChatMessageParams.toChatMessageUpload());
}

@RequestLine("POST " + LobbyWatcherClient.PLAYER_JOINED_PATH)
String playerJoined(PlayerJoinedNotification playerJoinedNotification);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.triplea.http.client.LobbyHttpClientConfig;
import org.triplea.http.client.lobby.HttpLobbyClient;
import org.triplea.http.client.lobby.game.hosting.request.GameHostingResponse;
import org.triplea.http.client.lobby.game.lobby.watcher.ChatUploadParams;
import org.triplea.http.client.lobby.game.lobby.watcher.GamePostingRequest;
import org.triplea.http.client.lobby.game.lobby.watcher.GamePostingResponse;
import org.triplea.http.client.lobby.game.lobby.watcher.LobbyWatcherClient;
Expand Down Expand Up @@ -92,10 +91,6 @@ public void close() {
webSocket.close();
}

public void sendChatMessageToLobby(final ChatUploadParams chatUploadParams) {
lobbyWatcherClient.uploadChatMessage(chatUploadParams);
}

public void playerJoined(final String gameId, final UserName playerName) {
AsyncRunner.runAsync(() -> lobbyWatcherClient.playerJoined(gameId, playerName))
.exceptionally(e -> log.info("Failed to notify lobby a player connected", e));
Expand Down

0 comments on commit dcda979

Please sign in to comment.