示例#1
0
        private void HandleCommand(User user, string value)
        {
            // Default return message
            string response = "ERROR Unknown command";

            value = value.Trim();
            string instruction = value;
            string args        = null;

            // Check if we got parameters with the instruction
            if (value.IndexOf(' ') > -1)
            {
                instruction = value.SplitCommand()[0];
                args        = value.SplitCommand()[1];
            }

            IServerRequest request = CommandRegistry.GetCommand(instruction);

            if (request != null)
            {
                request.Run(user, args);
            }
            else
            {
                // Unknown command, inform client
                user.WriteLine(response);
            }
        }
示例#2
0
        public void RegisterCommands()
        {
            Logger.Info("Registering protocol commands...");

            CommandRegistry.RegisterCommand("TIME", new ProtocolRequests.Time());
            CommandRegistry.RegisterCommand("QUIT", new ProtocolRequests.Quit());
            CommandRegistry.RegisterCommand("JOIN", new ProtocolRequests.Join());
            CommandRegistry.RegisterCommand("PART", new ProtocolRequests.Part());
            CommandRegistry.RegisterCommand("PRIVMSG", new ProtocolRequests.PrivMsg());
            CommandRegistry.RegisterCommand("NICK", new ProtocolRequests.Nick());

            Logger.Info("Protocol commands registered.");
        }