Beispiel #1
0
    public static void Send(int hostId, int connectionId, int channelId, MessageBase message, short messageType)
    {
        NetworkWriter writer = new NetworkWriter();

        writer.StartMessage(messageType);
        message.Serialize(writer);
        writer.FinishMessage();
        byte[] writerData   = writer.ToArray();
        int    bufferLength = P2PController.bufferLength;

        bufferLength = writerData.Length;
        //Debug.Log("Send packet with size: " + bufferLength);

        NetworkTransport.Send(hostId, connectionId, channelId, writerData, bufferLength, out P2PController.error);
        P2PController.CheckError("Send");


        if (Recorder.session != null)
        {
            Recorder.session.messagesSent++;
            Recorder.session.AddLeavingBandwidth(bufferLength);
            if (channelId == P2PChannels.ReliableChannelId)
            {
                Recorder.session.importantMessagesSent++;
            }
        }
    }
Beispiel #2
0
    public static void OnJoinAnswer(int hostId, int connectionId, JoinAnswerMessage message)
    {
        if (p2PController.GameStarted() || JoinAnswerReceived)
        {
            return;
        }

        Debug.Log("JoinAnswer received, lane: " + message.lane + ", playersCount: " + message.successfulConnections.Count);
        if (!(message.lane >= 0 && message.lane < 4))
        {
            Debug.Log("Game is full");
            p2PController.myLane = -1;
            p2PController.DisplayError("Game is full");
            return;
        }
        else
        {
            Debug.Log("allowed to join the game! Now need to connect to all players");
            JoinAnswerReceived = true;

            p2PController.myLane = message.lane;

            P2PController.gameColor = new Color(message.r / 255.0f, message.g / 255.0f, message.b / 255.0f);
            GameObject.FindObjectOfType <UIController>().UpdateGameColor(P2PController.gameColor);

            foreach (P2PConnection connection in message.successfulConnections)
            {
                connections.Add(connection);
                NetworkTransport.Connect(myHostId, connection.ip, connection.port, 0, out P2PController.error);
                P2PController.CheckError("Connect");
            }

            P2PConnectionManager.GetConnection(hostId, connectionId).SuccessfullyConnect();

            CheckConnectionsStatus();
        }
    }
Beispiel #3
0
 public void Disconnect()
 {
     NetworkTransport.Disconnect(hostId, connectionId, out P2PController.error);
     P2PController.CheckError("Disconnect");
 }