public ServerMessenger(ResponseType targetResponseType, Connection connection, string message, string hideResponseLike = null) { this.connection = connection; ExpectedResponseType = targetResponseType; connection.RconWebSocketMutex.WaitOne(); connection.RconWebSocket.OnMessage += OnMessage; connection.RconWebSocketMutex.ReleaseMutex(); connection.RconCommandQueue.Enqueue( RconCommand.ConsoleLogCommand( message, message, "Server Messenger" ) ); }
public void RunCommands(Connection.ChatEventArgs e = null) { foreach (string command in CommandStrings) { string formatted = command.Trim(); formatted = ParseResult.ReplaceDynamicReferences(formatted, Connection); if (command.Trim().StartsWith("!") || command.Trim().StartsWith("%")) { if (command.Trim().StartsWith("!!")) { formatted = formatted.TrimStart("@".ToCharArray()); // I don't remember why this is necessary } else { // Remove the command-enclosing '%' characters formatted = command.RemoveFirst('%', 2); } while (formatted.StartsWith("!")) { // Remove '!' characters formatted = formatted.Remove(0, 1); } if (RuntimeCommand.StringStartsWithCommandName(formatted)) { RuntimeCommand.TryRunCommand($"!{formatted}", null, Connection); } else { Connection.RconCommandQueue.Enqueue( RconCommand.ConsoleLogCommand( formatted, formatted, e?.SendingPlayer?.Name ?? "SERVER" ) ); } } else { if (formatted.StartsWith("!")) { if (RuntimeCommand.StringStartsWithCommandName(formatted.TrimStart(1))) { RuntimeCommand.TryRunCommand(formatted, null, Connection); } else { Connection.RconCommandQueue.Enqueue( RconCommand.ConsoleLogCommand( formatted, formatted, e?.SendingPlayer?.Name ?? "SERVER" ) ); } } else { if (RuntimeCommand.StringStartsWithCommandName(formatted)) { RuntimeCommand.TryRunCommand($"!{formatted}", null, Connection); } else { Connection.RconCommandQueue.Enqueue( RconCommand.ConsoleLogCommand( formatted, formatted, e?.SendingPlayer?.Name ?? "SERVER" ) ); } } } } }