void SendIDToClient(NetworkConnection c)
    {
        RequestIDMsg m = new RequestIDMsg();

        m.ID = c.InternalId.ToString();
        SendToClient(JsonUtility.ToJson(m), c);
    }
Exemple #2
0
    void OnData(DataStreamReader stream)
    {
        NativeArray <byte> bytes = new NativeArray <byte>(stream.Length, Allocator.Temp);

        stream.ReadBytes(bytes);
        string        recMsg = Encoding.ASCII.GetString(bytes.ToArray());
        NetworkHeader header = JsonUtility.FromJson <NetworkHeader>(recMsg);

        switch (header.cmd)
        {
        case Commands.HANDSHAKE:
            HandshakeMsg hsMsg = JsonUtility.FromJson <HandshakeMsg>(recMsg);
            //Debug.Log("Handshake message received!");
            break;

        case Commands.PLAYER_UPDATE:
            PlayerUpdateMsg puMsg = JsonUtility.FromJson <PlayerUpdateMsg>(recMsg);
            Debug.Log("Player update message received!");
            break;

        case Commands.SERVER_UPDATE:
            ServerUpdateMsg suMsg = JsonUtility.FromJson <ServerUpdateMsg>(recMsg);
            Debug.Log("Server update message received!");
            break;

        case Commands.REQUEST_ID:
            RequestIDMsg riMsg = JsonUtility.FromJson <RequestIDMsg>(recMsg);
            playerInfo.serverID = riMsg.ID;
            Debug.Log("Request ID message received!");
            break;

        case Commands.PLAYER_SPAWN:
            PlayerSpawnMsg psMsg = JsonUtility.FromJson <PlayerSpawnMsg>(recMsg);
            SpawnOtherPlayer(psMsg);
            break;

        case Commands.UPDATE_STATS:
            UpdateStatsMsg usMsg = JsonUtility.FromJson <UpdateStatsMsg>(recMsg);
            UpdateOtherPlayer(usMsg);
            break;

        case Commands.PLAYER_DC:
            PlayerDCMsg pdMsg = JsonUtility.FromJson <PlayerDCMsg>(recMsg);
            KillPlayer(pdMsg);
            break;

        default:
            Debug.Log("Unrecognized message received!");
            break;
        }
    }
Exemple #3
0
    void OnData(DataStreamReader stream)
    {
        NativeArray <byte> bytes = new NativeArray <byte>(stream.Length, Allocator.Temp);

        stream.ReadBytes(bytes);
        string        recMsg = Encoding.ASCII.GetString(bytes.ToArray());
        NetworkHeader header = JsonUtility.FromJson <NetworkHeader>(recMsg);

        switch (header.cmd)
        {
        case Commands.HANDSHAKE:
            HandshakeMsg hsMsg = JsonUtility.FromJson <HandshakeMsg>(recMsg);
            //Debug.Log("Handshake message received!");
            break;

        case Commands.PLAYER_UPDATE:
            PlayerUpdateMsg puMsg = JsonUtility.FromJson <PlayerUpdateMsg>(recMsg);
            Debug.Log("Player update message received!");
            break;

        case Commands.SERVER_UPDATE:
            ServerUpdateMsg suMsg = JsonUtility.FromJson <ServerUpdateMsg>(recMsg);
            Debug.Log("Server update message received!");
            break;

        case Commands.REQUEST_ID:
            RequestIDMsg riMsg = JsonUtility.FromJson <RequestIDMsg>(recMsg);
            //playerInfo.serverID = riMsg.ID;
            Debug.Log("Request ID message received!");
            break;

        case Commands.PLAYER_SPAWN:
            PlayerSpawnMsg psMsg = JsonUtility.FromJson <PlayerSpawnMsg>(recMsg);
            SpawnOtherPlayer(psMsg);
            break;

        case Commands.UPDATE_STATS:
            UpdateStatsMsg usMsg = JsonUtility.FromJson <UpdateStatsMsg>(recMsg);
            UpdateOtherPlayer(usMsg);
            break;

        case Commands.GAME_RESULT:
            GameEndMsg geMsg = JsonUtility.FromJson <GameEndMsg>(recMsg);

            P1Diff.text = (int.Parse(geMsg.p1.points) - int.Parse(clientScript.AllPlayers[0].points)).ToString();
            P2Diff.text = (int.Parse(geMsg.p2.points) - int.Parse(clientScript.AllPlayers[1].points)).ToString();
            P3Diff.text = (int.Parse(geMsg.p3.points) - int.Parse(clientScript.AllPlayers[2].points)).ToString();

            clientScript.AllPlayers[0] = geMsg.p1;
            clientScript.AllPlayers[1] = geMsg.p2;
            clientScript.AllPlayers[2] = geMsg.p3;

            File.WriteAllText(logPath, geMsg.LogData);
            break;

        case Commands.PLAYER_DC:
            PlayerDCMsg pdMsg = JsonUtility.FromJson <PlayerDCMsg>(recMsg);
            KillPlayer(pdMsg);
            break;

        default:
            Debug.Log("Unrecognized message received!");
            break;
        }
    }