コード例 #1
0
        private static void HandleServerRequest(string value)
        {
            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];
            }

            // Is request registered?
            IServerRequest request = ServerRequestRegistry.GetHandler(instruction);

            if (request != null)
            {
                request.Run(args);
            }
            else
            {
                // Protocol request unknown, inform client
                ClientMessage.Info($"Unknown protocol value: {value}");
            }
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: jsvensson/SU15-IrcServer
        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);
            }
        }