Example #1
0
    public string m_szMessageContent;              //Contenido del mensaje

    public Message(byte[] in_receivedBytes)
    {
        if (CGlobals.m_bIsEncrypted)           //If the Encryption flag is active, then Decrypt the message before constructing it.
        {
            in_receivedBytes = CGlobals.CesarCipherDecrypt(in_receivedBytes);
        }
        string tmpString = Encoding.UTF8.GetString(in_receivedBytes);

        //Debug.Log("Constructing a Message with: " + tmpString);
        string[] tmpValuesArray = tmpString.Split("\t".ToCharArray(), 6);  //Gives us 6 parts so we can use each one as one of the variables of this object.
        if (tmpValuesArray.Length != 6)
        {
            //Then, the received bytes did not have the correct format (which is, containing 4 tabs '\t' to adequately make the split).
            Debug.LogError("A message was constructed without the correct information. it was:  " + tmpString);
            m_cIsForServer         = '0';
            m_szSenderID           = null;
            m_szTargetAddress      = null;
            m_szMessageType        = null;
            m_szDestinationAddress = null;
            m_szMessageContent     = null;
            return; //return to exit the constructor.
        }

        //Else, everything is formated correctly, so we can create our message object easily.
        m_cIsForServer         = tmpValuesArray[0].ToCharArray()[0]; //By convention, this is where we will store this information.
        m_szSenderID           = tmpValuesArray[1];
        m_szTargetAddress      = tmpValuesArray[2];
        m_szMessageType        = tmpValuesArray[3];
        m_szDestinationAddress = tmpValuesArray[4];
        m_szMessageContent     = tmpValuesArray[5];

        //Debug.Log("A message was created, and it has the values: " + ToString());//Debug to see what does it say.
    }