Player name, pwa & branding
This commit is contained in:
@@ -25,18 +25,19 @@ public class GameManager implements IGameManager {
|
||||
Game game;
|
||||
|
||||
@Override
|
||||
public void login(WebSocketSession session) throws InterruptedException, IOException {
|
||||
public void login(WebSocketSession session, String name) throws InterruptedException, IOException {
|
||||
if (game.getSessions().containsKey(session.getId())) {
|
||||
SocketUtils.sendMessage(session, "error", "cant login twice");
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = initPlayer(new Player());
|
||||
player.setName(name);
|
||||
|
||||
game.getSessions().put(session.getId(), session);
|
||||
game.getPlayers().put(session.getId(), player);
|
||||
|
||||
System.out.println("[GAME] Player " + session.getId() + " logged in | status: " + player.getX() + " " + player.getY() + " " + player.getColor());
|
||||
System.out.println("[GAME] Player " + name + " (" + session.getId() + ") logged in | status: " + player.getX() + " " + player.getY() + " " + player.getColor());
|
||||
|
||||
SocketUtils.sendObject(session, "login", new ObjectMapper().writeValueAsString(player));
|
||||
SocketUtils.sendObject(session, "gameSettings", new ObjectMapper().writeValueAsString(game.getSettings()));
|
||||
@@ -129,7 +130,7 @@ public class GameManager implements IGameManager {
|
||||
private void killPlayer(String id) {
|
||||
Player player = game.getPlayers().get(id);
|
||||
initPlayer(player);
|
||||
System.out.println("[GAME] Player " + id + " is dead | status: " + player.getX() + " " + player.getY() + " " + player.getColor());
|
||||
System.out.println("[GAME] Player " + player.getName() + " (" + id + ") is dead | status: " + player.getX() + " " + player.getY() + " " + player.getColor());
|
||||
try {
|
||||
SocketUtils.sendObject(game.getSessions().get(id), "gamePlayerDead",
|
||||
new ObjectMapper().writeValueAsString(player));
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.springframework.web.socket.WebSocketSession;
|
||||
import gltronic.tronio.model.Player;
|
||||
|
||||
public interface IGameManager {
|
||||
void login(WebSocketSession session) throws InterruptedException, IOException;
|
||||
void login(WebSocketSession session, String name) throws InterruptedException, IOException;
|
||||
void leave(WebSocketSession session) throws InterruptedException, IOException;
|
||||
void updatePlayer(WebSocketSession session, Player player) throws InterruptedException, IOException;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import lombok.Setter;
|
||||
@NoArgsConstructor
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Player {
|
||||
private String name;
|
||||
|
||||
private String color;
|
||||
|
||||
|
||||
@@ -32,9 +32,11 @@ public class SocketHandler extends TextWebSocketHandler {
|
||||
|
||||
String type = rootObject.getString("type");
|
||||
switch (type) {
|
||||
case "login":
|
||||
gameManager.login(session, rootObject.getString("message"));
|
||||
break;
|
||||
case "update":
|
||||
Player player = new ObjectMapper().readValue(rootObject.get("message").toString(), Player.class);
|
||||
|
||||
gameManager.updatePlayer(session, player);
|
||||
break;
|
||||
default:
|
||||
@@ -45,7 +47,7 @@ public class SocketHandler extends TextWebSocketHandler {
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||
System.err.println("[WS] new connection " + this);
|
||||
gameManager.login(session);
|
||||
// gameManager.login(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user