Exemplo n.º 1
0
        bool HandleCommandCommon <T>(string msg, SteamID sender,
                                     SendChatDelegate sendChat, out T cmd) where T : struct
        {
            msg = msg.Trim();
            cmd = default(T);

            string[] commands = msg.Split(' ');
            if (commands.Length == 0)
            {
                return(false);
            }

            string command   = commands[0];
            bool   isNumeric = Regex.IsMatch(command, @"^\d+$");

            if (isNumeric || !BotCommand.TryParse(command, true, out cmd))
            {
                sendChat(sender, EChatEntryType.ChatMsg, "Unknown bot command.");
                return(false);
            }

            if (!CheckPermission(sender, cmd))
            {
                sendChat(sender, EChatEntryType.ChatMsg,
                         "You do not have permission for this command.");
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        void HandleCommand(string msg, SteamID sender, SendChatDelegate sendChat)
        {
            BotCommand cmd;

            if (!HandleCommandCommon(msg, sender, sendChat, out cmd))
            {
                return;
            }

            var messageMap = new Dictionary <BotCommand, Action <string, SteamID> >
            {
                { BotCommand.Help, HandleHelpCommand },
                { BotCommand.ListTrades, HandleListTradesCommand },
                { BotCommand.Trade, HandleTradeCommand },
                // Idler commands
                { BotCommand.ListIdlers, HandleListIdlersCommand },
                { BotCommand.SpawnIdler, HandleSpawnIdlerCommand },
                { BotCommand.StopIdler, HandleStopIdlerCommand },
                // Admin commands
                { BotCommand.Craft, HandleCraftCommand },
                { BotCommand.AutoCraft, HandleAutoCraftCommand },
                { BotCommand.Paint, HandlePaintCommand },
                { BotCommand.Items, HandleItemsCommand },
                { BotCommand.RefreshInventory, HandleRefreshInventoryCommand },
                { BotCommand.RefreshSchema, HandleRefreshSchemaCommand },
                // Owner commands
                { BotCommand.ConnectGC, HandleConnectGC },
                { BotCommand.DisconnectGC, HandleDisconnectGC },
                { BotCommand.Exit, HandleExitCommand },
            };

            Action <string, SteamID> func;

            if (!messageMap.TryGetValue(cmd, out func))
            {
                Logger.WriteLine("Unhandled command: {0}", cmd);
                return;
            }

            func(msg, sender);
        }
Exemplo n.º 3
0
        void HandleTradeTextCommand(TradeSession trade, TradeEvent @event)
        {
            SendChatDelegate sendDelegate = (sender, entry, text) =>
            {
                trade.SendChatMessage(text);
            };

            TradeCommand cmd;

            if (!HandleCommandCommon(
                    @event.message, @event.sender, sendDelegate, out cmd))
            {
                return;
            }

            var messageMap = new Dictionary <TradeCommand, Action <string, TradeSession> >
            {
                { TradeCommand.Help, HandleTradeHelpCommand },
                { TradeCommand.Ready, HandleTradeReadyCommand },
                { TradeCommand.Add, HandleTradeAddCommand },
                { TradeCommand.Remove, HandleTradeRemoveCommand },
                { TradeCommand.Confirm, HandleTradeConfirmCommand },
                { TradeCommand.Items, HandleTradeItemsCommand },
                { TradeCommand.Cancel, HandleTradeCancelCommand },
            };

            Action <string, TradeSession> func;

            if (!messageMap.TryGetValue(cmd, out func))
            {
                Logger.WriteLine("Unhandled trade command: {0}", cmd);
                return;
            }

            func(@event.message, trade);
        }