Exemplo n.º 1
0
        private Task <bool> ProcessFragment(string Xml)
        {
            Task <bool>      Result;
            TextEventHandler h = this.OnReceived;

            if (h is null)
            {
                Result = Task.FromResult <bool>(false);
            }
            else
            {
                try
                {
                    Result = h(this, Xml);
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                    Result = Task.FromResult <bool>(false);
                }

                //if (Result && this.callbacks != null)
                //	this.CallCallbacks();
            }

            return(Result);
        }
Exemplo n.º 2
0
        private bool ProcessFragment(string Xml)
        {
            TextEventHandler h = this.OnReceived;

            if (h != null)
            {
                bool Result;

                try
                {
                    Result = h(this, Xml);
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                    Result = false;
                }

                //if (Result && this.callbacks != null)
                //	this.CallCallbacks();

                return(Result);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        TextEvents = GetComponent <TextEventHandler>();

        TextEvents.onWordEnter.AddListener(OnWordEnter);
        TextEvents.onWordLeave.AddListener(OnWordLeave);
        TextEvents.onLinkEnter.AddListener(OnLinkEnter);
        TextEvents.onLinkLeave.AddListener(OnLinkLeave);
    }
Exemplo n.º 4
0
        private async void Handle(Player player, string text)
        {
            var rt    = RTVar.Parse(text);
            var world = await Database.GetWorld(player.CurrentWorld);

            if (!rt.IsValid())
            {
                return;
            }

            var instance = new TextEventHandler()
            {
                Player = player,
                World  = world,
                Data   = text,
                Rt     = rt
            };

            var method = instance.GetType()
                         .GetMethods()
                         .FirstOrDefault(x =>
            {
                var attribute = x.GetCustomAttribute(typeof(TextPacketAttribute));

                if (attribute == null)
                {
                    return(false);
                }

                var type         = attribute?.GetType();
                var textProperty = type?.GetProperty("TextName");
                var textValue    = textProperty?.GetValue(attribute).ToString();

                var lobbyProperty = type?.GetProperty("RequireLobby");
                var lobbyValue    = (bool)lobbyProperty?.GetValue(attribute);

                var defaultProperty = type?.GetProperty("DefaultLobby");
                var defaultValue    = (bool)defaultProperty?.GetValue(attribute);

                if (!defaultValue)
                {
                    if (lobbyValue != player.InLobby)
                    {
                        return(false);
                    }
                }

                return(textValue != null && text.StartsWith(textValue));
            });

            //instance.GetType().GetProperty("Rt").SetValue(instance, rt);
            //instance.GetType().GetProperty("World").SetValue(instance, world);
            //instance.GetType().GetProperty("Player").SetValue(instance, player);

            method?.Invoke(instance, null);
        }
Exemplo n.º 5
0
        private void RaiseOnReceived(string Payload)
        {
            TextEventHandler h = this.OnReceived;

            if (h != null)
            {
                try
                {
                    h(this, Payload);
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }
        }
Exemplo n.º 6
0
        private void Peer_OnSent(object Sender, byte[] Packet)
        {
            TextEventHandler h = this.OnSent;

            if (h != null)
            {
                try
                {
                    string s = this.encoding.GetString(Packet);
                    h(this, s);
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }
        }
Exemplo n.º 7
0
        private async Task <bool> RaiseOnReceived(string Payload)
        {
            TextEventHandler h      = this.OnReceived;
            bool             Result = true;

            if (!(h is null))
            {
                try
                {
                    Result = await h(this, Payload);
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }

            return(Result);
        }
Exemplo n.º 8
0
        private Task Peer_OnSent(object Sender, byte[] Buffer, int Offset, int Count)
        {
            TextEventHandler h = this.OnSent;

            if (h != null)
            {
                try
                {
                    string s = this.encoding.GetString(Buffer, Offset, Count);
                    h(this, s);
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }

            return(Task.FromResult <bool>(true));
        }
 private void Awake()
 {
     textEventHandler = GetComponent <TextEventHandler>();
 }