Skip to content

Commit

Permalink
encode player name before sending to game (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy1wu authored Apr 12, 2023
1 parent 66b89ae commit 7631c33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion services/client/src/hooks/useGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const useGame = (gameSocketURL: string, durationInSeconds: number) => {
if (gameState === GameState.NotStarted) {
setPlayerName(playerName);
setGameMode(gameMode);
sendMessage(Event.Start, [playerName, gameMode].join(","));
sendMessage(Event.Start, [encodeURIComponent(playerName), gameMode].join(","));
setGameState(GameState.InGame);
startTimer();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 IBM Corporation and others.
* Copyright (c) 2022, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -11,6 +11,9 @@
package io.openliberty.spacerover.game.websocket.server;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -143,6 +146,12 @@ private String getErrorMessage(final String errorText) {

private void startGame(final String[] properties) {
String playerId = properties[0];
try {
playerId = URLDecoder.decode(playerId, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// utf-8 always supported
}

int gameMode = Integer.parseInt(properties[1]);
LOGGER.log(Level.INFO, "Start Game received for player ID: {0}, GameMode: {1}",
new Object[] { playerId, gameMode });
Expand Down

0 comments on commit 7631c33

Please sign in to comment.