Example #1
0
 public int ReceiveInGameMessage()
 {
     receiveBuffer = new StringBuilder(recvBufferSize);
     PhaNetworkingAPI.ReceiveFrom(PhaNetworkingAPI.mainSocket, receiveBuffer, recvBufferSize);
     if (receiveBuffer.Length > 0)
     {
         return((int)char.GetNumericValue(receiveBuffer[0]));
     }
     return(-1);
 }
Example #2
0
    ///returns the value of damage taken.
    public int ReceiveHealthUpdate()
    {
        PhaNetworkingAPI.ReceiveFrom(PhaNetworkingAPI.mainSocket, receiveBuffer, recvBufferSize);

        if (receiveBuffer.ToString().StartsWith(((int)MessageType.HealthUpdate).ToString()))
        {
            return(int.Parse(receiveBuffer.ToString().Split()[1]));
        }
        return(0);
    }
Example #3
0
    public int ReceiveLoadLevelMessage()
    {
        StringBuilder LevelReceiveBuffer = new StringBuilder(recvBufferSize);

        PhaNetworkingAPI.ReceiveFrom(PhaNetworkingAPI.mainSocket, LevelReceiveBuffer, recvBufferSize);
        if (LevelReceiveBuffer.ToString().StartsWith(((int)MessageType.LoadLevel).ToString()))
        {
            return(1);
        }
        return(0);
    }
Example #4
0
    //Receive information that the other player is online.
    public int ReceiveConnectionMessage()
    {
        StringBuilder recBuffer     = new StringBuilder(recvBufferSize);
        int           bytesReceived = PhaNetworkingAPI.ReceiveFrom(PhaNetworkingAPI.mainSocket, recBuffer, recvBufferSize);

        if (recBuffer.ToString().StartsWith(((int)MessageType.Connection).ToString()))
        {
            return(1);
        }
        //Debug.Log("buffer received: " + recBuffer);
        return(0);
    }
Example #5
0
    void SpawnPlayer(Scene _scene1, Scene _scene2)
    {
        if (_scene2.name != "Menu")
        {
            if (characterSelection == 0)
            {
                Ishost                 = true;
                AgentSpawned           = GameObject.Instantiate(AgentPrefab);       //Local player is agent.
                AgentHealth            = AgentSpawned.GetComponent <Health>();
                AgentRigidBody         = AgentSpawned.GetComponent <Rigidbody>();
                previousPlayerVelocity = new Vector3(AgentRigidBody.velocity.x, AgentRigidBody.velocity.y, AgentRigidBody.velocity.z);
                previousPlayerRotation = new Quaternion(AgentSpawned.transform.rotation.x, AgentSpawned.transform.rotation.y, AgentSpawned.transform.rotation.z, AgentSpawned.transform.rotation.w);

                SpawnedHacker = GameObject.Instantiate(RemoteHackerPrefab);
            }
            else if (characterSelection == 1)
            {
                Ishost       = false;
                AgentSpawned = GameObject.Instantiate(RemoteAgentPrefab);
                AgentHealth  = AgentSpawned.GetComponent <Health>();
                Vector3 startPosition = FindObjectOfType <PlayerStartLocation>().transform.position;
                AgentSpawned.transform.position = new Vector3(startPosition.x, startPosition.y, startPosition.z);
                AgentSpawned.GetComponent <NetworkedMovement>().receivedPosition = new Vector3(startPosition.x, startPosition.y, startPosition.z);
                AgentRigidBody  = AgentSpawned.GetComponent <Rigidbody>();
                AgentPrediction = AgentSpawned.GetComponent <NetworkedBehaviour>();
                SpawnedHacker   = GameObject.Instantiate(HackerPrefab);               //Local Player is Hacker. The order of instantiation here is important!
            }

            phantomManager = FindObjectOfType(typeof(PhantomManager)) as PhantomManager;
            if (phantomManager == null)
            {
                Debug.LogError("phantomManager not found. F**k.");
            }

            //skipeManager.startSkipe();
        }
        else
        {
            int bytesreceived = 0;
            do
            {
                bytesreceived = PhaNetworkingAPI.ReceiveFrom(PhaNetworkingAPI.mainSocket, receiveBuffer, recvBufferSize);
                Debug.Log("Continuing to flush the f*****g buffer, bytes: " + bytesreceived);
            } while (bytesreceived != 10035);
            //skipeManager.closeSkipe();
        }
    }
Example #6
0
    //Receive a message that tells you what character the other player has chosen.
    public int ReceiveCharacterLockMessage()
    {
        StringBuilder characterLockMessage = new StringBuilder(recvBufferSize);

        PhaNetworkingAPI.ReceiveFrom(PhaNetworkingAPI.mainSocket, characterLockMessage, recvBufferSize);
        if (characterLockMessage.ToString().StartsWith(((int)MessageType.CharacterLock).ToString()))
        {
            string[] message = characterLockMessage.ToString().Split(' ');
            Debug.Log(message);
            if (message.Length > 0)
            {
                int result;
                result = int.Parse(message[1]);
                return(result);
            }
        }
        return(-1);
    }
Example #7
0
    public void ReceivePlayerUpdate(Transform playerTransform)
    {
        StringBuilder PlayerReceiveBuffer = new StringBuilder(recvBufferSize);

        PhaNetworkingAPI.ReceiveFrom(PhaNetworkingAPI.mainSocket, PlayerReceiveBuffer, recvBufferSize);
        if (PlayerReceiveBuffer.ToString().StartsWith(((int)MessageType.PlayerUpdate).ToString()))
        {
            string[]   message = PlayerReceiveBuffer.ToString().Split(' ');
            Vector3    position;
            Quaternion orientation;

            position.x = float.Parse(message[1]);
            position.y = float.Parse(message[2]);
            position.z = float.Parse(message[3]);

            orientation.w = float.Parse(message[4]);
            orientation.x = float.Parse(message[5]);
            orientation.y = float.Parse(message[6]);
            orientation.z = float.Parse(message[7]);

            playerTransform.position = position;
            playerTransform.rotation = orientation;
        }
    }