public static MessageWrapper UnWrapMessage(string wrappedJsonStr) { var wrapper = Messaging <MessageWrapper> .Deserialize(wrappedJsonStr); return(wrapper); }
void HandleWebSocketMessage(string message) { var msg = MessageWrapper.UnWrapMessage(message); switch (msg.type) { case "register": Register register = Messaging <Register> .Deserialize(message); gameSession.sessionId = register.sessionId; gameSession.playerId = register.playerId; EdgeMultiplayCallbacks.registerEvent(); break; case "notification": Notification notification = Messaging <Notification> .Deserialize(message); switch (notification.notificationText) { case "left-room": gameSession.roomId = ""; EdgeMultiplayCallbacks.leftRoom(); break; case "join-room-faliure": EdgeMultiplayCallbacks.joinRoomFaliure(); break; case "new-room-created-in-lobby": EdgeMultiplayCallbacks.newRoomCreatedInLobby(); break; case "room-removed-from-lobby": EdgeMultiplayCallbacks.roomRemovedFromLobby(); break; } EdgeMultiplayCallbacks.notificationEvent(notification); break; case "roomsList": RoomsList roomsList = Messaging <RoomsList> .Deserialize(message); EdgeMultiplayCallbacks.roomsList(roomsList.rooms); break; case "roomCreated": RoomCreated roomCreated = Messaging <RoomCreated> .Deserialize(message); gameSession.roomId = roomCreated.room.roomId; EdgeMultiplayCallbacks.roomCreated(roomCreated.room); break; case "roomJoin": RoomJoin roomJoin = Messaging <RoomJoin> .Deserialize(message); gameSession.roomId = roomJoin.room.roomId; EdgeMultiplayCallbacks.roomJoin(roomJoin.room); break; case "playerJoinedRoom": PlayerJoinedRoom playerJoinedRoom = Messaging <PlayerJoinedRoom> .Deserialize(message); EdgeMultiplayCallbacks.playerRoomJoined(playerJoinedRoom.room); break; case "gameStart": GameStart gameStart = Messaging <GameStart> .Deserialize(message); gameSession.currentPlayers = gameStart.room.roomMembers.ToArray(); foreach (Player player in gameStart.room.roomMembers) { if (player.playerId == gameSession.playerId) { gameSession.playerIndex = player.playerIndex; } } CreatePlayers(gameSession.currentPlayers); gameStarted = true; EdgeMultiplayCallbacks.gameStart(); if (useLocalHostServer) { udpClient = new MobiledgeXUDPClient(hostIPAddress, defaultEdgeMultiplayServerUDPPort); } else { udpClient = new MobiledgeXUDPClient(integration.GetHost(), integration.GetAppPort(LProto.L_PROTO_UDP).public_port); } SendUDPMessage(new GamePlayEvent() { eventName = "Start" }); break; case "GamePlayEvent": GamePlayEvent gamePlayEvent = Messaging <GamePlayEvent> .Deserialize(message); switch (gamePlayEvent.eventName) { case "NewObservableCreated": CreateObservableObject(gamePlayEvent); break; case "ObservableOwnershipChange": UpdateObserverOwnership(gamePlayEvent); break; case "TakeOverObservable": TakeOverObservable(gamePlayEvent); break; case "OwnershipRequest": OwnershipRequestReceived(gamePlayEvent); break; default: ReflectEvent(gamePlayEvent); break; } break; case "memberLeft": RoomMemberLeft playerLeft = Messaging <RoomMemberLeft> .Deserialize(message); EdgeMultiplayCallbacks.playerLeft(playerLeft); break; default: Debug.LogError("Unknown WebSocket message arrived: " + msg.type + ", message: " + message); break; } }
/// <summary> /// Exit the current room you are in /// </summary> public static void ExitRoom() { ExitRoomRequest exitRoomRequest = new ExitRoomRequest(); wsClient.Send(Messaging <ExitRoomRequest> .Serialize(exitRoomRequest)); }
public void SendGamePlayEvent(GamePlayEvent mobiledgexEvent) { mobiledgexEvent.roomId = gameSession.roomId; mobiledgexEvent.senderId = gameSession.playerId; wsClient.Send(Messaging <GamePlayEvent> .Serialize(mobiledgexEvent)); }
/// <summary> /// Sends a request to the server to get a full list of rooms on the servers /// <para> /// use <b>public override void OnRoomsListReceived</b> to get the server response /// </para> /// </summary> public static void GetAvailableRooms() { GetAvailableRoomsRequest getAvailableRoomsRequest = new GetAvailableRoomsRequest(); wsClient.Send(Messaging <GetAvailableRoomsRequest> .Serialize(getAvailableRoomsRequest)); }