- Timestamp:
- Aug 26, 2014, 7:29:11 PM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src/NetConnections
- Files:
-
- 3 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/Telnet.cs
r130 r132 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.IO;4 3 using System.Net; 5 4 using System.Net.Sockets; 6 using System.Reflection;7 5 using System.Threading; 8 6 9 namespace AllocsFixes 7 namespace AllocsFixes.NetConnections.Servers.Telnet 10 8 { 11 public class AllocsNetTelnetServer9 public class Telnet : IServer 12 10 { 13 11 private static Thread telnetThread = null; … … 15 13 private static bool closed = false; 16 14 private static bool authEnabled = false; 17 private static List< AllocsTelnetConnection> connections = new List<AllocsTelnetConnection> ();15 private static List<TelnetConnection> connections = new List<TelnetConnection> (); 18 16 19 public static void init (int port)17 public Telnet (int port) 20 18 { 21 19 try { 22 Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly ().GetName ().Version);23 20 authEnabled = GamePrefs.GetString (EnumGamePrefs.TelnetPassword).Length != 0; 24 21 if (authEnabled) … … 26 23 else 27 24 listener = new TcpListener (IPAddress.Loopback, port); 28 telnetThread = ThreadMaster.Create ("thread AllocsTelnetListenThread", new ThreadStart (telnetListenThread));25 telnetThread = ThreadMaster.Create ("thread TelnetListenThread", new ThreadStart (telnetListenThread)); 29 26 telnetThread.Start (); 30 Log.Out ("Started Allocs NetTelnetServerthread on " + port);27 Log.Out ("Started Telnet thread on " + port); 31 28 } catch (Exception e) { 32 Log.Out ("Error in AllocsTelnetServer.init: " + e);29 Log.Out ("Error in Telnet.ctor: " + e); 33 30 } 34 31 } 35 32 36 private staticvoid telnetListenThread ()33 private void telnetListenThread () 37 34 { 38 35 try { 39 Log.Out ("Started thread_ Allocs_TelnetListenThread()");36 Log.Out ("Started thread_TelnetListenThread()"); 40 37 listener.Start (); 41 38 while (!closed) { 42 39 Thread.Sleep (10); 43 40 if (listener.Pending ()) { 44 AllocsTelnetConnection c = new AllocsTelnetConnection (listener.AcceptTcpClient (), authEnabled);41 TelnetConnection c = new TelnetConnection (listener.AcceptTcpClient (), authEnabled); 45 42 connections.Add (c); 46 43 Log.Out ("Telnet connection from: " + c.GetEndPoint ()); … … 52 49 } 53 50 54 foreach ( AllocsTelnetConnection c in connections) {51 foreach (TelnetConnection c in connections) { 55 52 if (c.IsClosed ()) { 56 53 c.Close (); … … 79 76 } 80 77 Log.Out ("Telnet executed \"" + line + "\" from: " + c.GetEndPoint ()); 81 ConsoleOutputSeparator.Queue TelnetCommand (line, c);78 ConsoleOutputSeparator.QueueNetCommand (line, c); 82 79 } 83 80 } 84 81 } 85 82 } 86 Log.Out ("Exited thread_ Allocs_TelnetListenThread()");83 Log.Out ("Exited thread_TelnetListenThread()"); 87 84 ThreadMaster.Remove (Thread.CurrentThread.Name); 88 85 } catch (Exception ex) { 89 Log.Out ("Error in Allocs telnetListenThread: " + ex.Message);86 Log.Out ("Error in TelnetListenThread: " + ex.Message); 90 87 Log.Out ("Stack Trace: " + ex.StackTrace); 91 88 } 92 89 } 93 90 94 private static void LoginMessage (AllocsTelnetConnection c)91 private void LoginMessage (TelnetConnection c) 95 92 { 96 93 c.WriteLine ("*** Connected with 7DTD server."); … … 112 109 } 113 110 114 private st atic string lineCorrecter (string line)111 private string lineCorrecter (string line) 115 112 { 116 113 string res = ""; … … 123 120 } 124 121 125 public staticvoid Disconnect ()122 public void Disconnect () 126 123 { 127 124 try { … … 130 127 listener.Stop (); 131 128 } 132 foreach ( AllocsTelnetConnection c in connections) {129 foreach (TelnetConnection c in connections) { 133 130 c.Close (); 134 131 } 135 132 Thread.Sleep (100); 136 133 } catch (Exception e) { 137 Log.Out ("Error in AllocsTelnetServer.Disconnect: " + e);134 Log.Out ("Error in Telnet.Disconnect: " + e); 138 135 } 139 136 } 140 137 141 public static void SetConsole (ConsoleSdtd console) 142 { 143 } 144 145 private static void RemoveClosedConnections () 138 private void RemoveClosedConnections () 146 139 { 147 140 try { 148 foreach ( AllocsTelnetConnection c in connections) {141 foreach (TelnetConnection c in connections) { 149 142 if (c.IsClosed ()) { 150 143 c.Close (); … … 152 145 } 153 146 } catch (Exception e) { 154 Log.Out ("Error in AllocsTelnetServer.RemoveClosedConnections: " + e);147 Log.Out ("Error in Telnet.RemoveClosedConnections: " + e); 155 148 } 156 149 } 157 150 158 public staticvoid WriteToClient (string line)151 public void WriteToClient (string line) 159 152 { 160 153 if (line == null) { … … 162 155 } 163 156 RemoveClosedConnections (); 164 foreach ( AllocsTelnetConnection c in connections) {157 foreach (TelnetConnection c in connections) { 165 158 if (c.IsAuthenticated ()) 166 159 c.WriteLine (line); … … 168 161 } 169 162 170 public static void WriteToClient_Single (string line, AllocsTelnetConnection client)163 public void WriteToClient_Single (string line, IConnection client) 171 164 { 172 165 if (line == null) { … … 174 167 } 175 168 RemoveClosedConnections (); 176 foreach (AllocsTelnetConnection c in connections) { 177 if (c.IsAuthenticated () && (c == client)) 178 c.WriteLine (line); 169 foreach (TelnetConnection con in connections) { 170 if (con == client) { 171 if (con.IsAuthenticated ()) 172 con.WriteLine (line); 173 } 179 174 } 180 175 } 176 181 177 } 182 178 } 179
Note:
See TracChangeset
for help on using the changeset viewer.