Example #1
0
 public static void Remove(string key, Action <string> callback)
 {
     if (instance.stringSubscribers.ContainsKey(key))
     {
         instance.stringSubscribers.Remove(key);
     }
     else
     {
         DreamLogs.LogWarning("<color=#FFFF00>There's no callback subscribed to '{0}'</color>", key);
     }
 }
Example #2
0
    private void SerializeMessage(string message)
    {
        try
        {
            string[] chain = message.Split(' ');
            string   key   = chain[0];
            float    value = 0;

            if (float.TryParse(chain[1], out value))
            {
                Action <float> callback = null;
                if (floatSubscribers.TryGetValue(key, out callback))
                {
                    callback(value);
                }
                else
                {
                    if (!logException.Contains(key))
                    {
                        DreamLogs.LogWarning("<color=#FFFF00>There's no callback subscribed to '{0}'</color>", key);
                    }
                }
            }
            else
            {
                Action <string> callback = null;
                if (stringSubscribers.TryGetValue(key, out callback))
                {
                    callback(chain[1]);
                }
                else
                {
                    if (!logException.Contains(key))
                    {
                        DreamLogs.LogWarning("<color=#FFFF00>There's no callback subscribed to '{0}'</color>", key);
                    }
                }
            }

            if (!logException.Contains(key))
            {
                DreamLogs.Log("<color=green>Receive data: {0}</color>", message);
            }
        }
        catch (Exception e)
        {
            DreamLogs.LogWarning("<color=#FFFF00>Cannot deserialize message '{0}', reason: {1}</color>", message, e.Message);
        }
    }
Example #3
0
    private void ReceiveDataListener()
    {
        while (true)
        {
            try
            {
                byte[] data = receiveClient.Receive(ref receiveEndPoint);
                string text = Encoding.UTF8.GetString(data);

                SerializeMessage(text);
            }
            catch (Exception ex)
            {
                DreamLogs.LogWarning(ex.ToString());
            }
        }
    }