Exemplo n.º 1
0
        public static (string msg, Bitmap img) HandelCommand(string cmd, SocketUser user)
        {
            if (!cmd.StartsWith("~"))
            {
                return(null, null);
            }


            UpdateWorld(); //every time a message of any kind command or not i sent in normal chat on the server tick the update
            File.WriteAllText("state.json", JsonConvert.SerializeObject(Program.WorldState, Formatting.Indented));

            cmd = cmd.Remove(0, 1);

            var segs = Utils.ParseCmd(cmd);

            var name = segs[0];

            if (TextHandlers.ContainsKey(name))
            {
                return(TextHandlers[name](cmd, user), null);
            }

            else if (ImageHandlers.ContainsKey(name))
            {
                return("", ImageHandlers[name](cmd, user));
            }
            else
            {
                return("404. Handler Not Found.", null);
            }
        }
Exemplo n.º 2
0
        static GameBotEngine()
        {
            foreach (var type in typeof(GameBotEngine).Assembly.GetTypes())
            {
                if (type.GetCustomAttribute <HandlerAttribute>() != null)
                {
                    foreach (var method in type.GetMethods())
                    {
                        var att = method.GetCustomAttribute <HandlerAttribute>();

                        if (att != null)
                        {
                            if (!method.IsStatic)
                            {
                                Logger.Error($"The Method {method.Name} is not static");
                                continue;
                            }

                            if (method.ReturnType == typeof(string))
                            {
                                TextHandlers.Add(att.Cmd, (x, u) =>
                                {
                                    return((string)method.Invoke(null, BindingFlags.Static, null, new object[] { x, u },
                                                                 CultureInfo.CurrentCulture));
                                });
                            }
                            else if (method.ReturnType == typeof(Bitmap))
                            {
                                ImageHandlers.Add(att.Cmd, (x, u) =>
                                {
                                    return((Bitmap)method.Invoke(null, BindingFlags.Static, null, new object[] { x, u },
                                                                 CultureInfo.CurrentCulture));
                                });
                            }
                        }
                    }
                }
            }
        }