Ejemplo n.º 1
0
    /// <summary>
    /// Décode le message ClientServerDetail
    /// </summary>
    /// <param name="message">Message a décoder</param>
    /// <returns>Instance de l'endpoint</returns>
    public static GameNetworkEndpoint DecodeClientServerDetail(string message)
    {
        // On décode la chaine

        string[] data = GameNetworkParser.Parse(message);

        if (data == null || data.Length != 3)
        {
            return(null);
        }

        // Décodage

        int port;

        if (!int.TryParse(data[2], out port))
        {
            return(null);
        }

        GameNetworkEndpoint endpoint = new GameNetworkEndpoint(data[1], port);

        // On renvoi l'endpoint

        return(endpoint);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Récupère le type du message
    /// </summary>
    /// <param name="message">Message a décoder</param>
    /// <returns>Type du message</returns>
    public static GameMessageTypes FindType(string message)
    {
        // On décode la chaine

        string[] data = GameNetworkParser.Parse(message);

        if (data == null)
        {
            return(GameMessageTypes.Unknow);
        }

        // On détermine le type

        int type;

        if (!int.TryParse(data[0], out type))
        {
            return(GameMessageTypes.Unknow);
        }

        // On filtre le type

        if (type == 1)
        {
            return(GameMessageTypes.ClientServerDetail);
        }
        else if (type == 2)
        {
            return(GameMessageTypes.SendObjectInMailbox);
        }

        // Message inconnu

        return(GameMessageTypes.Unknow);
    }
 private void OnMessageReceived(object sender, GameNetworkMessageArgs e)
 {
     if (GameNetworkParser.FindType(e.Message) == GameMessageTypes.SendObjectInMailbox)
     {
         _item = GameNetworkParser.DecodeSendObjectInMailbox(e.Message);
     }
 }
Ejemplo n.º 4
0
    /// <summary>
    /// Décode le message SendObjectInMailbox
    /// </summary>
    /// <param name="message">Message a décoder</param>
    /// <returns>Objet en transit</returns>
    public static MailboxItems DecodeSendObjectInMailbox(string message)
    {
        // On décode la chaine

        string[] data = GameNetworkParser.Parse(message);

        if (data == null || data.Length != 2)
        {
            return(MailboxItems.None);
        }

        // Décodage

        int itemId;

        if (!int.TryParse(data[1], out itemId))
        {
            return(MailboxItems.None);
        }

        // On renvoi l'item

        if (itemId == 1)
        {
            return(MailboxItems.Menu);
        }
        else if (itemId == 2)
        {
            return(MailboxItems.Screeen);
        }
        else if (itemId == 3)
        {
            return(MailboxItems.Key1);
        }
        else if (itemId == 4)
        {
            return(MailboxItems.UsbKey);
        }
        else if (itemId == 5)
        {
            return(MailboxItems.Key2);
        }
        else if (itemId == 6)
        {
            return(MailboxItems.DoorHandle);
        }

        return(MailboxItems.None);
    }
 public void SendColorMessage()
 {
     if (Menu)
     {
         GameNetworkManager.Instance.SendToHololens(GameNetworkParser.CreateMessageSendObjectInMailbox(MailboxItems.Menu));
         Debug.Log("Menu Envoyé");
     }
     if (Blue)
     {
         GameNetworkManager.Instance.SendToHololens(GameNetworkParser.CreateMessageSendObjectInMailbox(MailboxItems.Key1));
         Debug.Log("Key1 Envoyé");
     }
     if (Yellow)
     {
         GameNetworkManager.Instance.SendToHololens(GameNetworkParser.CreateMessageSendObjectInMailbox(MailboxItems.Key2));
         Debug.Log("Key2 Envoyé");
     }
 }
    /// <summary>
    /// Détermine le message et envoi l'information
    /// </summary>
    /// <param name="response">Réponse à traiter</param>
    private void ParseAndSend(string response)
    {
        try
        {
            // Vérification

            if (string.IsNullOrEmpty(response))
            {
                return;
            }

            // Extraction des différents message

            string[] split = response.Split('#');

            if (split.Length > 0)
            {
                foreach (string item in split)
                {
                    if (GameNetworkParser.FindType(item) != GameMessageTypes.Unknow)
                    {
                        if (this.MessageReceived != null)
                        {
                            this.MessageReceived(this, new GameNetworkMessageArgs(item));
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            if (this.ErrorRaised != null)
            {
                this.ErrorRaised(this, new GameNetworkErrorArgs(ex));
            }
        }
    }