public Connection(string ipAddress, int port, string password, ILogger log, IRConParserConfiguration config) { Endpoint = new IPEndPoint(IPAddress.Parse(ipAddress), port); defaultEncoding = Encoding.GetEncoding("windows-1252"); RConPassword = password; Log = log; Config = config; }
public void SetConfiguration(IRConParserConfiguration config) { Config = config; }
public void SetConfiguration(IRConParser parser) { this.parser = parser; config = parser.Configuration; }
public string BuildFormattedMessage(IRConParserConfiguration config, EFPenalty currentPenalty, EFPenalty originalPenalty = null) { var isNewLineSeparator = config.NoticeLineSeparator == Environment.NewLine; var penalty = originalPenalty ?? currentPenalty; var builder = new StringBuilder(); // build the top level header var header = _transLookup[$"SERVER_{penalty.Type.ToString().ToUpper()}_TEXT"]; builder.Append(header); builder.Append(config.NoticeLineSeparator); // build the reason var reason = _transLookup["GAME_MESSAGE_PENALTY_REASON"].FormatExt(penalty.Offense); if (isNewLineSeparator) { foreach (var splitReason in SplitOverMaxLength(reason, config.NoticeMaxCharactersPerLine)) { builder.Append(splitReason); builder.Append(config.NoticeLineSeparator); } } else { builder.Append(reason); builder.Append(config.NoticeLineSeparator); } if (penalty.Type == EFPenalty.PenaltyType.TempBan) { // build the time remaining if temporary var timeRemainingValue = penalty.Expires.HasValue ? (penalty.Expires - DateTime.UtcNow).Value.HumanizeForCurrentCulture() : "--"; var timeRemaining = _transLookup["GAME_MESSAGE_PENALTY_TIME_REMAINING"].FormatExt(timeRemainingValue); if (isNewLineSeparator) { foreach (var splitReason in SplitOverMaxLength(timeRemaining, config.NoticeMaxCharactersPerLine)) { builder.Append(splitReason); builder.Append(config.NoticeLineSeparator); } } else { builder.Append(timeRemaining); } } if (penalty.Type == EFPenalty.PenaltyType.Ban) { // provide a place to appeal the ban (should always be specified but including a placeholder just incase) builder.Append(_transLookup["GAME_MESSAGE_PENALTY_APPEAL"].FormatExt(_appConfig.ContactUri ?? "--")); } // final format looks something like: /* * You are permanently banned * Reason - toxic behavior * Visit example.com to appeal */ return(builder.ToString()); }