示例#1
0
 public void ApplyConsent(ConsentMessage consentMessage, bool wasMyRequest = false)
 {
     //Debug.Log("Applying for consent " + consentMessage.consentAction);
     if (consentMessage.consentAction == ConsentAction.SpawnRocket)
     {
         if (NetworkServer.active)
         {
             bool cheating = !gameController.lanes[consentMessage.parameters[1]].spawnManager.ValidIndex(consentMessage.result);
             if (!cheating)
             {
                 NetworkServer.Spawn(gameController.lanes[consentMessage.parameters[1]].spawnManager.Spawn(consentMessage.result));
             }
             else
             {
                 Debug.Log("Cheat! wrong rocket infos");
             }
         }
     }
     else if (consentMessage.consentAction == ConsentAction.CastShield)
     {
         if (NetworkServer.active)
         {
             Lane lane = gameController.lanes[consentMessage.parameters[0]];
             if (lane.player.ShieldReady())
             {
                 lane.player.CastShield();
             }
             else
             {
                 Debug.Log("Cheat! Shield not ready");
             }
         }
     }
 }
示例#2
0
    public static void OnJoinRequest(int hostId, int connectionId, JoinRequestMessage message)
    {
        Debug.Log("JoinRequest received");

        if (!GameController.gameStarted)
        {
            return;
        }

        //ask others if a player can join to that lane
        ConsentMessage consentMessage = new ConsentMessage();

        consentMessage.consentAction = ConsentAction.JoinGame;
        Lane freeLane = p2PController.GetGameController().GetFirstUnoccupiedLane();

        consentMessage.result = 10;
        if (freeLane != null)
        {
            consentMessage.result = freeLane.id;
        }

        consentMessage.parameters.Add(hostId);
        consentMessage.parameters.Add(connectionId);

        p2PController.AskForConsent(consentMessage);
    }
    public void SendRocket(int playerId, int neighbourPlayerId)
    {
        if (lanes[playerId].player.Health <= 0)        //dead players cant send rockets
        {
            return;
        }

        ConsentMessage consentMessage = new ConsentMessage();

        consentMessage.timestampSendMs = System.Convert.ToInt32(Time.time * 1000.0f);
        consentMessage.consentAction   = ConsentAction.SpawnRocket;
        consentMessage.parameters.Add(playerId);
        consentMessage.parameters.Add(neighbourPlayerId);
        consentMessage.result = lanes[neighbourPlayerId].spawnManager.GetRandomSpawnerIndex();

        //Cheating only implemented in P2PController

        /*//will I cheat?
         * int randomInt = Random.Range(0, 100);
         * if(randomInt < cheaterProfileContainer.cheaterProfile.cheatingRate)
         * {
         *      if(Recorder.session != null)
         *              Recorder.session.cheatsTried ++;
         *
         *      //sending a wrong spawner index
         *      consentMessage.result = 100;
         * }*/

        networkController.AskForConsent(consentMessage);
    }
    public void CastShield(int playerId)
    {
        if (lanes[playerId].player.Health <= 0)        //dead players cant cast shields
        {
            return;
        }

        ConsentMessage consentMessage = new ConsentMessage();

        consentMessage.timestampSendMs = System.Convert.ToInt32(Time.time * 1000.0f);
        consentMessage.consentAction   = ConsentAction.CastShield;
        consentMessage.parameters.Add(playerId);
        consentMessage.result = 1;         //1 = allowed, 0 = not allowed

        //are we cheating? if so, count it
        Lane lane = lanes[consentMessage.parameters[0]];

        if (!lane.player.ShieldReady())
        {
            if (Recorder.session != null)
            {
                Recorder.session.cheatsTried++;
            }
        }

        networkController.AskForConsent(consentMessage);
    }
示例#5
0
    public void AskForConsent(ConsentMessage consentMessage)
    {
        networkClient = NetworkClient.allClients[0];
        networkClient.Send(NetworkMessages.AskForConsentMsg, consentMessage);

        if (Recorder.session != null)
        {
            Recorder.session.importantMessagesSent++;
            Recorder.session.messagesSent++;
        }
    }
示例#6
0
    void OnApplyConsentMsg(NetworkMessage netMsg)
    {
        ConsentMessage msg = netMsg.ReadMessage <ConsentMessage>();

        if (Recorder.session != null)
        {
            Recorder.session.AddSentAndAppliedConsent(msg.timestampSendMs);

            //Receive consent apply
            Recorder.session.messagesReceived++;
            Recorder.session.importantMessagesReceived++;
        }
    }
 public void ApplyConsent(ConsentMessage consentMessage)
 {
     if (consentMessage.consentAction == ConsentAction.SpawnRocket)
     {
         bool cheating = !gameController.lanes[consentMessage.parameters[1]].spawnManager.ValidIndex(consentMessage.result);
         if (!cheating)
         {
             gameController.lanes[consentMessage.parameters[1]].spawnManager.Spawn(consentMessage.result);
         }
         else
         {
             Debug.Log("Cheat!");
         }
     }
 }
示例#8
0
    void OnAskForConsentMsg(NetworkMessage netMsg)
    {
        ConsentMessage msg = netMsg.ReadMessage <ConsentMessage>();

        if (msg.consentAction == ConsentAction.SpawnRocket)
        {
            gameController.lanes[msg.parameters[1]].spawnManager.GetRandomSpawnerIndex();
        }
        ApplyConsent(msg);
        Debug.Log("Received OnAskForConsentMsg " + msg.consentAction);

        if (Recorder.session != null)
        {
            Recorder.session.messagesReceived++;
            Recorder.session.importantMessagesReceived++;
        }
    }
示例#9
0
    public void AskForConsent(ConsentMessage consentMessage)
    {
        AskConsentMessage message = new AskConsentMessage();

        message.consentId     = P2PConsentManager.GetNextConsentIdAndIncrement();
        message.consentAction = consentMessage.consentAction;
        message.result        = consentMessage.result;
        message.parameters.AddRange(consentMessage.parameters);
        if (consensusAlgorithm && P2PConnectionManager.SuccessfulConnectionsCount() > 0)
        {
            Debug.Log("P2P: Asking consent for: " + consentMessage.consentAction);
            P2PConsentManager.AddPendingConsent(message);
            P2PSender.SendToAll(P2PChannels.ReliableChannelId, message, MessageTypes.AskConsent);
        }
        else
        {
            Debug.Log("P2P: Imposing consent for: " + consentMessage.consentAction);
            P2PConsentManager.ApplyAndSpreadConsentResult(OnAskForConsentMsg(-1, -1, message));
        }
    }
示例#10
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");
            }
        }
    }
示例#11
0
    void OnAskForConsentMsg(NetworkMessage netMsg)
    {
        ConsentMessage msg = netMsg.ReadMessage <ConsentMessage>();

        if (msg.consentAction == ConsentAction.SpawnRocket)
        {
            gameController.lanes[msg.parameters[1]].spawnManager.GetRandomSpawnerIndex();
        }
        ApplyConsent(msg);

        //send apply consent confirmation
        NetworkServer.SendToClient(netMsg.conn.connectionId, NetworkMessages.ApplyConsentMsg, msg);

        if (Recorder.session != null)
        {
            Recorder.session.messagesReceived++;
            Recorder.session.importantMessagesReceived++;

            //Send consent apply to each client in theory
            int clientsCount = GameObject.FindObjectsOfType <Player>().Length - 1;
            Recorder.session.importantMessagesSent += clientsCount;
            Recorder.session.messagesSent          += clientsCount;
        }
    }
 public void AskForConsent(ConsentMessage consentMessage)
 {
     ApplyConsent(consentMessage);
 }