Example #1
0
        // Handle command written in chat
        public static void HandleCommand(string command, ClientGame game)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                ListCommands(game);
                return;
            }

            int commandDelimiter = command.IndexOf(" ");
            var cmd = commandDelimiter > 0 ? command.Substring(0, commandDelimiter).ToLower() : command;

            switch (commands.FirstOrDefault(x => x.StartsWith(cmd)))
            {
            case "game":
                game.Chat.SetActiveChat(ChatTypes.Game);
                if (commandDelimiter > 0)
                {
                    game.SendChatMessage(command.Substring(commandDelimiter).Trim(), ChatTypes.Game);
                }
                break;

            case "global":
                game.Chat.SetActiveChat(ChatTypes.Global);
                if (commandDelimiter > 0)
                {
                    game.SendChatMessage(command.Substring(commandDelimiter).Trim(), ChatTypes.Global);
                }
                break;

            case "help":
                ListCommands(game);
                break;

            case "whisper":
                HandleWhisperCommand(game, commandDelimiter > 0 ? command.Substring(commandDelimiter).Trim() : "");
                break;

            default:
                WriteInvalidCommand(game);
                break;
            }
        }
Example #2
0
        // Sends whisper message to server
        private static void HandleWhisperCommand(ClientGame game, string arg)
        {
            int commandDelimiter = arg.IndexOf(" ");

            if (string.IsNullOrWhiteSpace(arg) || (commandDelimiter <= 0))
            {
                FormatSyntaxError(game, "/whisper [name] [message]");
                return;
            }

            string receiverName = arg.Substring(0, commandDelimiter);
            string message      = arg.Substring(commandDelimiter).Trim();

            if (!message.Any())
            {
                FormatSyntaxError(game, "/whisper [name] [message]");
                return;
            }

            game.SendChatMessage(message, ChatTypes.Whisper, receiverName);
        }