Example #1
0
    /// <summary>
    /// Handler that processes the current state message received from the server
    /// after AskCurrentState is called.
    /// </summary>
    /// <param name="msg">Message.</param>
    public override void OnCurrentStateReceived(NetworkMessage msg)
    {
        StateMessage sm = msg.ReadMessage <StateMessage>();

        Debug.Log("state message received " + sm.ToString() + " " + gameObject.name);
        Color c = (Color)sm.GetValue("color");

        Debug.Log("color " + sm.ToString() + " " + gameObject.name);
        view.SetColor(c);
    }
Example #2
0
    private void HandleStateMessage(string stateMessage)
    {
        Debug.Log("P2PConnection: Handling state msessage!" + stateMessage);
        JObject jObj            = JObject.Parse(stateMessage);
        JToken  blockPositions  = jObj.GetValue("blockPositions");
        JToken  playerPositions = jObj.GetValue("playerPositions");

        Debug.Log("parsing block positions " + blockPositions.ToString());
        Dictionary <string, int> dictionaryBlockPositions = JsonConvert.DeserializeObject <Dictionary <string, int> >(blockPositions.ToString());

        Debug.Log("parsing player positions " + playerPositions.ToString());
        Dictionary <string, string> dictionaryPlayerPositions = JsonConvert.DeserializeObject <Dictionary <string, string> >(playerPositions.ToString());

        Dictionary <Vector3, int> actualBlocks = new Dictionary <Vector3, int>();

        Debug.Log("Serialization done!");

        //StateMessage stateMessageInstance = JsonUtility.FromJson<StateMessage>(stateMessage);
        StateMessage stateMessageInstance = new StateMessage(dictionaryPlayerPositions, dictionaryBlockPositions);

        Debug.Log("P2PConnection: State message content = " + stateMessageInstance.ToString());

        peerToPeerManager.AddIncommingMessage(stateMessageInstance);

        //JArray a = JArray.Parse(stateMessageObject.GetValue("positions").ToString());
        //Debug.Log(a.ToString());

        //TODO handle state! -> push data to Multiplayer System
    }
Example #3
0
    public void CmdAskCurrentState(short msgId, GameObject requester)
    {
        Log("askCurState message received from client (msgId:" + msgId + ")");
        int connectionId = connectionToClient.connectionId;

        Log("sending message to " + connectionId);
        HLAPINetworkSync nets = requester.GetComponent <HLAPINetworkSync> ();
        StateMessage     msg  = nets.GetCurrentState();

        NetworkServer.SendToClient(connectionId,
                                   msgId,
                                   msg);
        Log("message sent: " + msg.ToString());
    }