Пример #1
0
        private void Chat_MessageReceived(string author, string message, ChatMessage.Data original)
        {
            var commandInfo = MessageUtilities.getCommandInfo(message);

            if (commandInfo.matches && commandInfo.commandName.ToLower() == "plugin")
            {
                printClient();
            }

            if (!GeneralUtilities.isHost())
            {
                addMessageFromRemote(original);
                chatReplicationManager.AddPublic(original.message_);
                return;
            }

            Cmd cmd = commandInfo.matches ? Cmd.all.getCommand(commandInfo.commandName) : null;

            string logMessage = "";

            var client = GeneralUtilities.clientFromName(author);

            var showRegularChat = !LogCmd.localClientCommands || !commandInfo.matches || commandInfo.forceVisible || (cmd != null && client != null && cmd.showChatPublic(client)) || commandInfo.local;

            if (showRegularChat)
            {
                chatReplicationManager.AddPublic(original.message_);
                addMessageFromRemote(original);
                logMessage = message;
            }

            if (client == null)
            {
                Console.WriteLine($"Error: client can't be found for name: {author}");
                return;
            }

            if (!commandInfo.matches || commandInfo.commandName.ToLower() == "plugin" || commandInfo.local)
            {
                return;
            }

            if (!showRegularChat)
            {
                logMessage = $"[00FFFF]{message}[-]";
                MessageUtilities.sendMessage(client, logMessage);
                chatReplicationManager.MarkAllForReplication();
                if (LogCmd.showHostAllCommands)
                {
                    var hostClient = GeneralUtilities.localClient();
                    if (hostClient == null)
                    {
                        Console.WriteLine("Error: Local client can't be found !");
                        return;
                    }
                    string usedCmd;
                    if (cmd == null || cmd.perm != PermType.ALL)
                    {
                        usedCmd = MessageUtilities.closeTags(client.GetChatName()) + " tried to use " + logMessage;
                    }
                    else
                    {
                        usedCmd = MessageUtilities.closeTags(client.GetChatName()) + " used " + logMessage;
                    }
                    MessageUtilities.sendMessage(hostClient, usedCmd);
                }
            }

            MessageStateOptionLog cmdLog = new MessageStateOptionLog(new List <string>());

            MessageUtilities.pushMessageOption(cmdLog);


            if (LogCmd.showHostAllResults)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionShowToHost(true));
            }

            if (LogCmd.localClientResults)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(client));
            }
            else
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer());
            }

            if (cmd == null)
            {
                MessageUtilities.sendMessage(client, "The command '" + commandInfo.commandName + "' doesn't exist.");
                chatReplicationManager.MarkForReplication(client.NetworkPlayer_);
                chatReplicationManager.ReplicateNeeded();
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popAllMessageOptions();
                return;
            }

            if (cmd.perm != PermType.ALL)
            {
                MessageUtilities.sendMessage(client, "You don't have permission to do that!");
                chatReplicationManager.MarkForReplication(client.NetworkPlayer_);
                chatReplicationManager.ReplicateNeeded();
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popAllMessageOptions();
                return;
            }

            MessageUtilities.popMessageOptions();

            if (commandInfo.forceVisible || !LogCmd.localClientResults)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer());
            }

            exec(cmd, client, commandInfo.commandParams);

            chatReplicationManager.ReplicateNeeded();
            LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
            MessageUtilities.popAllMessageOptions();
        }
Пример #2
0
        private void Chat_MessageSent(ChatSubmitMessage.Data messageData)
        {
            // by doing the below instead, we preserver formatting symbols.
            string message = UIExInputGeneric <string> .current_.Value_; //messageData.message_;

            var commandInfo = MessageUtilities.getCommandInfo(message);
            Cmd cmd         = commandInfo.matches ? Cmd.all.getCommand(commandInfo.commandName) : null;

            string logMessage = "";

            var client = GeneralUtilities.localClient();

            var showRegularChat = (!commandInfo.local && !GeneralUtilities.isHost()) || !LogCmd.localHostCommands ||
                                  !commandInfo.matches || commandInfo.forceVisible || (cmd != null && client != null && cmd.showChatPublic(client));

            if (showRegularChat)
            {
                sendingLocalChat = true;
                replicateLocalChatFunc?.Invoke(messageData);
                if (!commandInfo.matches)
                {
                    return;
                }
                logMessage = message;
            }

            if (client == null)
            {
                Console.WriteLine("Error: Local client can't be found !");
                return;
            }

            if (!showRegularChat)
            {
                MessageUtilities.sendMessage(client, $"[00FFFF]{message}[-]");
                logMessage = $"[00FFFF]{message}[-]";
            }

            MessageStateOptionLog cmdLog = new MessageStateOptionLog(new List <string>());

            MessageUtilities.pushMessageOption(cmdLog);

            if (LogCmd.localHostResults)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(client));
            }
            else
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer());
            }

            if (!commandInfo.local && commandInfo.commandName.ToLower() == "plugin")
            {
                printClient();
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popMessageOptions(2);
                return;
            }

            if (GeneralUtilities.isHost() && commandInfo.local)
            {
                MessageUtilities.sendMessage(client, "Cannot use local commands as host");
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popMessageOptions(2);
                return;
            }
            else if (!GeneralUtilities.isHost() && !commandInfo.local)
            {
                MessageUtilities.popMessageOptions(2);
                return;
            }

            if (cmd == null)
            {
                MessageUtilities.sendMessage(client, "The command '" + commandInfo.commandName + "' doesn't exist.");
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popMessageOptions(2);
                return;
            }

            if (commandInfo.local && !cmd.canUseLocal && cmd.perm != PermType.LOCAL)
            {
                MessageUtilities.sendMessage(client, "You can't use that command as client");
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popMessageOptions(2);
                return;
            }

            MessageUtilities.popMessageOptions();                                       // remove local/non-local only option

            bool renderToPublic = commandInfo.forceVisible || !LogCmd.localHostResults; // log settings may change if cmd changes them

            if (renderToPublic)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer());
            }
            exec(cmd, client, commandInfo.commandParams);
            if (renderToPublic)
            {
                MessageUtilities.popMessageOptions();
            }
            LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
            MessageUtilities.popAllMessageOptions();
        }