Exemplo n.º 1
0
    void SendUDPMessage(string message)
    {
        udpClient = new MobiledgeXUDPClient(udpHost, udpSendPort);
        udpClient.Send(message);

        //You can send binary also
        //byte[] messageBinary = Encoding.ASCII.GetBytes(message);
        //udpClient.Send(messageBinary);
    }
Exemplo n.º 2
0
 /// <summary>
 /// Kill the connection to your EdgeMultiplay server
 /// </summary>
 public static void Disconnect()
 {
     wsClient  = null;
     udpClient = null;
     foreach (NetworkedPlayer player in currentRoomPlayers)
     {
         Destroy(player.gameObject);
     }
     currentRoomPlayers = new List <NetworkedPlayer>();
     gameSession        = new Session();
     gameStarted        = false;
     MessageSender      = null;
     localPlayer        = null;
     observers          = new List <EdgeMultiplayObserver>();
 }
Exemplo n.º 3
0
        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;
                }
                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":
                    CreateObserverableObject(gamePlayEvent);
                    break;

                case "ObservableOwnershipChange":
                    UpdateObserverOwnership(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;
            }
        }