Changeset 75 for binary-improvements/7dtd-server-fixes
- Timestamp:
- Jul 16, 2014, 7:36:46 PM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes
- Files:
-
- 5 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
r74 r75 8 8 <ProjectGuid>{81DA7F87-1A66-4920-AADA-6EAF1971F8D0}</ProjectGuid> 9 9 <OutputType>Library</OutputType> 10 <RootNamespace>dtdserverfixes</RootNamespace>11 10 <AssemblyName>7dtd-server-fixes</AssemblyName> 12 11 </PropertyGroup> … … 38 37 <Compile Include="src\AllocsNetTelnetServer.cs" /> 39 38 <Compile Include="src\AssemblyInfo.cs" /> 39 <Compile Include="src\AllocsTelnetConnection.cs" /> 40 <Compile Include="src\TelnetCommands\GetTime.cs" /> 41 <Compile Include="src\AllocsRequestToSpawnPlayer.cs" /> 42 <Compile Include="src\TelnetCommands\ListPlayersExtended.cs" /> 40 43 </ItemGroup> 41 44 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 42 45 <ItemGroup> 43 46 <Folder Include="src\" /> 47 <Folder Include="src\TelnetCommands\" /> 44 48 </ItemGroup> 45 49 </Project> -
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.userprefs
r74 r75 1 1 <Properties> 2 2 <MonoDevelop.Ide.Workspace ActiveConfiguration="Release" /> 3 <MonoDevelop.Ide.Workbench ActiveDocument="src/Allocs NetTelnetServer.cs">3 <MonoDevelop.Ide.Workbench ActiveDocument="src/AllocsTelnetCommand.cs"> 4 4 <Files> 5 5 <File FileName="src/AssemblyInfo.cs" Line="1" Column="1" /> 6 <File FileName="src/AllocsNetTelnetServer.cs" Line="37" Column="5" /> 6 <File FileName="src/AllocsNetTelnetServer.cs" Line="40" Column="101" /> 7 <File FileName="src/AllocsTelnetConnection.cs" Line="16" Column="34" /> 8 <File FileName="src/AllocsTelnetCommand.cs" Line="3" Column="4" /> 7 9 </Files> 8 10 </MonoDevelop.Ide.Workbench> -
binary-improvements/7dtd-server-fixes/src/AllocsNetTelnetServer.cs
r74 r75 9 9 public class AllocsNetTelnetServer 10 10 { 11 private class Connection 12 { 13 private bool authenticated = false; 14 private TcpClient client; 15 private NetworkStream stream; 16 private string lineBuffer = string.Empty; 17 private EndPoint endpoint; 18 19 public Connection (TcpClient client) 20 { 21 this.client = client; 22 this.stream = client.GetStream (); 23 this.endpoint = client.Client.RemoteEndPoint; 24 } 25 26 public EndPoint GetEndPoint () 27 { 28 return endpoint; 29 } 30 31 private void WriteByte (byte v) 32 { 33 if (!IsClosed () && stream.CanWrite) { 34 stream.WriteByte (v); 35 } 36 } 37 38 public void WriteLine (string s) 39 { 40 if (!IsClosed () && stream.CanWrite) { 41 for (int i = 0; i < s.Length; i++) { 42 WriteByte ((byte)s [i]); 43 } 44 WriteByte (10); 45 } 46 } 47 48 public void Close () 49 { 50 if (client != null) 51 client.Close (); 52 client = null; 53 } 54 55 public bool IsClosed () 56 { 57 if (client != null && !client.Connected) { 58 Log.Out ("Telnet connection interrupted: " + endpoint); 59 } 60 return (client == null) || (!client.Connected); 61 } 62 63 public bool IsAuthenticated () 64 { 65 return !authEnabled || authenticated; 66 } 67 68 public void SetAuthenticated () 69 { 70 authenticated = true; 71 } 72 73 public bool Read () 74 { 75 while (!IsClosed() && stream.CanRead && stream.DataAvailable) { 76 int b = stream.ReadByte (); 77 if (b == '\r' || b == '\n') { 78 if (lineBuffer.Length > 0) 79 return true; 80 } else { 81 lineBuffer += (char)b; 82 } 83 } 84 return false; 85 } 86 87 public string GetLine () 88 { 89 string res = lineBuffer; 90 lineBuffer = string.Empty; 91 return res; 92 } 93 } 94 95 private static cl004c console = null; 11 private static ConsoleSdtd console = null; 96 12 private static Thread telnetThread = null; 97 13 private static TcpListener listener = null; 98 14 private static bool closed = false; 99 15 private static bool authEnabled = false; 100 private static List< Connection> conns = new List<Connection> ();16 private static List<AllocsTelnetConnection> conns = new List<AllocsTelnetConnection> (); 101 17 102 18 public static void init (int port) 103 19 { 104 Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly ().GetName().Version);20 Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly ().GetName ().Version); 105 21 authEnabled = GamePrefs.GetString (EnumGamePrefs.TelnetPassword).Length != 0; 106 22 if (authEnabled) … … 121 37 Thread.Sleep (10); 122 38 if (listener.Pending ()) { 123 Connection c = new Connection (listener.AcceptTcpClient ());39 AllocsTelnetConnection c = new AllocsTelnetConnection (listener.AcceptTcpClient (), authEnabled); 124 40 conns.Add (c); 125 41 Log.Out ("Telnet connection from: " + c.GetEndPoint ()); … … 131 47 } 132 48 133 foreach ( Connection c in conns) {49 foreach (AllocsTelnetConnection c in conns) { 134 50 if (c.IsClosed ()) { 135 51 c.Close (); … … 157 73 break; 158 74 } 159 160 75 Log.Out ("Telnet executed \"" + line + "\" from: " + c.GetEndPoint ()); 161 76 console.md000f (line); … … 172 87 } 173 88 174 private static void LoginMessage ( Connection c)89 private static void LoginMessage (AllocsTelnetConnection c) 175 90 { 176 91 c.WriteLine ("*** Connected with 7DTD server."); … … 208 123 listener.Stop (); 209 124 } 210 foreach ( Connection c in conns) {125 foreach (AllocsTelnetConnection c in conns) { 211 126 c.Close (); 212 127 } … … 214 129 } 215 130 216 public static void SetConsole ( cl004cconsole)131 public static void SetConsole (ConsoleSdtd console) 217 132 { 133 Log.Out("Telnet SetConsole called"); 218 134 AllocsNetTelnetServer.console = console; 135 console.AddCommand(new GetTime(console)); 136 console.AddCommand(new ListPlayersExtended(console)); 219 137 } 220 138 221 139 private static void RemoveClosedConnections () 222 140 { 223 foreach ( Connection c in conns) {141 foreach (AllocsTelnetConnection c in conns) { 224 142 if (c.IsClosed ()) { 225 143 c.Close (); … … 234 152 } 235 153 RemoveClosedConnections (); 236 foreach ( Connection c in conns) {237 if (c.IsAuthenticated ())154 foreach (AllocsTelnetConnection c in conns) { 155 if (c.IsAuthenticated ()) 238 156 c.WriteLine (line); 239 157 }
Note:
See TracChangeset
for help on using the changeset viewer.