Exemplo n.º 1
0
    public static void OnJoinAnnounce(int hostId, int connectionId, JoinAnnounceMessage message)
    {
        Debug.Log("OnJoinAnnounce received");
        P2PConnection connection = P2PConnectionManager.GetConnection(hostId, connectionId);

        connection.SuccessfullyConnect();
    }
Exemplo n.º 2
0
    public static void ConnectEvent(int hostId, int connectionId)
    {
        int    port;
        string ip;

        UnityEngine.Networking.Types.NetworkID netId;
        UnityEngine.Networking.Types.NodeID    nodeId;
        NetworkTransport.GetConnectionInfo(hostId, connectionId, out ip, out port, out netId, out nodeId, out P2PController.error);

        P2PConnection connection = P2PConnectionManager.GetConnection(ip, port);

        if (connection == null)
        {
            //new connection from targeted ip or new player
            connection      = new P2PConnection(hostId, connectionId);
            connection.ip   = ip;
            connection.port = port;
            connections.Add(connection);
            Debug.Log("New connection with " + connection);

            if (!JoinRequestSend)            //I'm wanting to join
            {
                Debug.Log("Sending Join Request");
                JoinRequestSend = true;
                JoinRequestMessage message = new JoinRequestMessage();
                P2PSender.Send(hostId, connectionId, P2PChannels.ReliableChannelId, message, MessageTypes.JoinRequest);
            }
            else if (JoinAnswerReceived && !p2PController.GameStarted())
            {
                connection.SuccessfullyConnect();
            }
        }
        else if (!connection.ConnectionSuccessful())
        {
            //successfully connect to an existing player. Connection requested previously
            connection.hostId       = hostId;
            connection.connectionId = connectionId;
            connection.SuccessfullyConnect();

            JoinAnnounceMessage announceMessage = new JoinAnnounceMessage();
            P2PSender.Send(hostId, connectionId, P2PChannels.ReliableChannelId, announceMessage, MessageTypes.JoinAnnounce);
        }

        if (!p2PController.GameStarted())
        {
            if (JoinAnswerReceived)
            {
                CheckConnectionsStatus();
            }
        }
    }
Exemplo n.º 3
0
    public void ApplyConsent(ConsentMessage message)
    {
        Debug.Log("P2P: Applying consent for: " + message.consentAction);
        if (message.consentAction == ConsentAction.SpawnRocket)
        {
            bool cheating = !gameController.lanes[message.parameters[1]].spawnManager.ValidIndex(message.result);
            if (!cheating)
            {
                gameController.lanes[message.parameters[1]].spawnManager.Spawn(message.result);
            }
            else
            {
                Debug.Log("Cheat!");
                if (Recorder.session != null)
                {
                    Recorder.session.cheatsPassed++;
                }
            }
        }
        else if (message.consentAction == ConsentAction.JoinGame)
        {
            P2PConnection connection = P2PConnectionManager.GetConnection(message.parameters[0], message.parameters[1]);
            if (connection != null)
            {
                JoinAnswerMessage answerMessage = new JoinAnswerMessage();
                answerMessage.lane = message.result;
                answerMessage.successfulConnections = P2PConnectionManager.GetSuccessfulConnections();
                answerMessage.r = Convert.ToInt32(gameColor.r * 255);
                answerMessage.g = Convert.ToInt32(gameColor.g * 255);
                answerMessage.b = Convert.ToInt32(gameColor.b * 255);

                P2PSender.Send(message.parameters[0], message.parameters[1], P2PChannels.ReliableChannelId, answerMessage, MessageTypes.JoinAnswer);

                connection.SuccessfullyConnect();

                Debug.Log("Sending JoinAnswer with lane: " + answerMessage.lane + "and " + answerMessage.successfulConnections.Count + " connections");
            }
        }
    }