/// <summary>Sends string data to the connection</summary> /// <param name="data">data to send.</param> /// <param name="bypassDataFormatter">Indicates whether the data formatter should be bypassed (for a quicker send).</param> /// <param name="sendAllData">Indicates if paging should be allowed</param> public void Send(string data, bool bypassDataFormatter, bool sendAllData) { if (!bypassDataFormatter) { data = DataFormatter.FormatData(data, this, sendAllData); } byte[] bytes; // Check for MCCP (its not worth using for short strings as the overhead is quite high). if (this.Terminal.UseMCCP && data.Length > MCCPThreshold) { // Compress the data bytes = MCCPHandler.Compress(data); // Send the sub request to say that the next load of data // is compressed. The sub request is IAC SE COMPRESS2 IAC SB this.Send(new byte[] { 255, 250, 86, 255, 240 }); } else { // Line below commented out by JFed 11/28/2011. We lose the 8th bit with this encoding, which breaks special characters like ASCII art // bytes = ASCIIEncoding.ASCII.GetBytes(data); // Encoding using code page 437 (old 8bit default ascii). bytes = Encoding.GetEncoding(437).GetBytes(data); } // Send the data. this.Send(bytes); }
/// <summary>Sends string data to the connection</summary> /// <param name="data">The string to send.</param> /// <param name="sendAllData">If true, send all data without letting the paging system pause the output.</param> public void Send(string data, bool sendAllData = false) { // TODO: Eventually, certain large blocks of text might be good candidates for caching the final result due to high frequency of sending to clients (such as welcome // messages or the most popular room descriptions and so on), so here might be a good place to perform an options-sensitive cache lookup of the source data to // the final (potentially word-wrapped, potentially compressed) data. This could reduce total word-wrapping and compression work. (Such a potential improvement // should be carefully measured for whether it is worth the complexity and potential bugs.) As such, it may make sense to coalesce the honored word wrap widths // when formatting data below, into common groupings (such as rounding down to nearest multiple of 20 and enforcing a max) to increase those cache hits at the // trade-off of not printing to the right-most characters of some terminal sizes. (This would probably look fine, generally.) // Check if the client wants to use compression (MCCP) and whether data is long enough to bother (as the overhead is quite high). byte[] bytes; if (TerminalOptions.UseMCCP && data.Length > MCCPThreshold) { // Compress the data. bytes = MCCPHandler.Compress(data); // Send the sub request to say that the next load of data // is compressed. The sub request is IAC SE COMPRESS2 IAC SB Send(new byte[] { 255, 250, 86, 255, 240 }); } else { bytes = CurrentEncoding.GetBytes(data); } // Send the data. Send(bytes); // Track whether we've finished with a NewLine, so we can avoid new lines of output going to the same one. AtNewLine = data.EndsWith(AnsiSequences.NewLine); }
/// <summary>Sends string data to the connection</summary> /// <param name="data">data to send.</param> /// <param name="bypassDataFormatter">Indicates whether the data formatter should be bypassed (for a quicker send).</param> /// <param name="sendAllData">Indicates if paging should be allowed</param> public void Send(string data, bool bypassDataFormatter, bool sendAllData) { if (!bypassDataFormatter) { data = DataFormatter.FormatData(data, this, sendAllData); } byte[] bytes; // Check for MCCP (its not worth using for short strings as the overhead is quite high). if (this.Terminal.UseMCCP && data.Length > MCCPThreshold) { // Compress the data bytes = MCCPHandler.Compress(data); // Send the sub request to say that the next load of data // is compressed. The sub request is IAC SE COMPRESS2 IAC SB this.Send(new byte[] { 255, 250, 86, 255, 240 }); } else { bytes = CurrentEncoding.GetBytes(data); } // Send the data. this.Send(bytes); }