Changeset 142 for binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/TelnetConnection.cs
- Timestamp:
- Aug 29, 2014, 4:18:16 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/TelnetConnection.cs
r132 r142 2 2 using System.Net; 3 3 using System.Net.Sockets; 4 using System.Text; 4 5 5 6 namespace AllocsFixes.NetConnections.Servers.Telnet … … 11 12 private TcpClient client; 12 13 private NetworkStream stream; 13 private string lineBuffer = string.Empty; 14 private int lineBufferLength = 0; 15 private byte[] lineBuffer = new byte[200]; 14 16 private EndPoint endpoint; 15 17 … … 38 40 try { 39 41 if (!IsClosed () && stream.CanWrite) { 40 for (int i = 0; i < s.Length; i++) { 41 WriteByte ((byte)s [i]); 42 } 42 byte[] utfData = Encoding.UTF8.GetBytes (s); 43 stream.Write(utfData, 0, utfData.Length); 43 44 WriteByte (13); 44 45 WriteByte (10); … … 79 80 int b = stream.ReadByte (); 80 81 if (b == '\r' || b == '\n') { 81 if (lineBuffer .Length > 0)82 if (lineBufferLength > 0) 82 83 return true; 83 } else { 84 lineBuffer += (char)b; 84 } else if (b >= 0) { 85 lineBuffer[lineBufferLength] = (byte)b; 86 lineBufferLength++; 85 87 } 86 88 } … … 90 92 public string GetLine () 91 93 { 92 string res = lineBuffer;93 lineBuffer = string.Empty;94 string res = Encoding.UTF8.GetString(lineBuffer, 0, lineBufferLength);; 95 lineBufferLength = 0; 94 96 return res; 95 97 }
Note:
See TracChangeset
for help on using the changeset viewer.