JSON serial change & working basic gameplay
This commit is contained in:
@@ -2,6 +2,8 @@ package gltronic.tronio.web;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -23,15 +25,17 @@ public class SocketHandler extends TextWebSocketHandler {
|
||||
@Override
|
||||
public void handleTextMessage(WebSocketSession session, TextMessage message)
|
||||
throws InterruptedException, IOException {
|
||||
System.err.println("[WS] message :" + message.getPayload());
|
||||
// System.err.println("[WS] message :" + message.getPayload());
|
||||
|
||||
String payload = message.getPayload();
|
||||
JSONObject jsonObject = new JSONObject(payload);
|
||||
JSONObject rootObject = new JSONObject(payload);
|
||||
|
||||
String type = (String) jsonObject.get("type");
|
||||
String type = rootObject.getString("type");
|
||||
switch (type) {
|
||||
case "update":
|
||||
gameManager.updatePlayer(session, (Player) jsonObject.get("message"));
|
||||
Player player = new ObjectMapper().readValue(rootObject.get("message").toString(), Player.class);
|
||||
|
||||
gameManager.updatePlayer(session, player);
|
||||
break;
|
||||
default:
|
||||
SocketUtils.sendMessage(session, "error", "unknow command");
|
||||
|
||||
Reference in New Issue
Block a user