Index: binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/Telnet.cs
===================================================================
--- binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/Telnet.cs	(revision 142)
+++ binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/Telnet.cs	(revision 182)
@@ -9,13 +9,19 @@
 	public class Telnet : IServer
 	{
-		private static Thread telnetThread = null;
-		private static TcpListener listener = null;
-		private static bool closed = false;
-		private static bool authEnabled = false;
-		private static List<TelnetConnection> connections = new List<TelnetConnection> ();
+		private Thread telnetThread = null;
+		private TcpListener listener = null;
+		private bool closed = false;
+		private bool authEnabled = false;
+		private List<TelnetConnection> connections = new List<TelnetConnection> ();
 
-		public Telnet (int port)
+		public Telnet ()
 		{
 			try {
+				if (!GamePrefs.GetBool (EnumGamePrefs.TelnetEnabled)) {
+					return;
+				}
+
+				int port = GamePrefs.GetInt (EnumGamePrefs.TelnetPort);
+
 				authEnabled = GamePrefs.GetString (EnumGamePrefs.TelnetPassword).Length != 0;
 				if (authEnabled)
@@ -25,5 +31,8 @@
 				telnetThread = ThreadMaster.Create ("thread TelnetListenThread", new ThreadStart (telnetListenThread));
 				telnetThread.Start ();
-				Log.Out ("Started Telnet thread on " + port);
+
+				NetTelnetServer.RegisterServer (this);
+
+				Log.Out ("Started Telnet on " + port);
 			} catch (Exception e) {
 				Log.Out ("Error in Telnet.ctor: " + e);
@@ -34,88 +43,17 @@
 		{
 			try {
-				Log.Out ("Started thread_TelnetListenThread()");
 				listener.Start ();
-				while (!closed) {
-					Thread.Sleep (10);
-					if (listener.Pending ()) {
+				try {
+					while (!closed) {
 						TelnetConnection c = new TelnetConnection (listener.AcceptTcpClient (), authEnabled);
 						connections.Add (c);
-						Log.Out ("Telnet connection from: " + c.GetEndPoint ());
-						if (authEnabled) {
-							c.WriteLine ("Please enter password:");
-						} else {
-							LoginMessage (c);
-						}
 					}
-
-					foreach (TelnetConnection c in connections) {
-						if (c.IsClosed ()) {
-							c.Close ();
-							connections.Remove (c);
-							break;
-						}
-						if (c.Read ()) {
-							string line = lineCorrecter (c.GetLine ());
-							if (!c.IsAuthenticated ()) {
-								if (line.Equals (GamePrefs.GetString (EnumGamePrefs.TelnetPassword))) {
-									c.SetAuthenticated ();
-									c.WriteLine ("Logon successful.");
-									c.WriteLine (string.Empty);
-									c.WriteLine (string.Empty);
-									c.WriteLine (string.Empty);
-									LoginMessage (c);
-								} else {
-									c.WriteLine ("Password incorrect, please enter password:");
-								}
-							} else {
-								if (line.ToLower ().Equals ("exit")) {
-									Log.Out ("Telnet connection closed by client: " + c.GetEndPoint ());
-									c.Close ();
-									connections.Remove (c);
-									break;
-								}
-								Log.Out ("Telnet executed \"" + line + "\" from: " + c.GetEndPoint ());
-								ConsoleOutputSeparator.QueueNetCommand (line, c);
-							}
-						}
-					}
+				} catch (SocketException) {
+				} catch (ThreadInterruptedException) {
 				}
-				Log.Out ("Exited thread_TelnetListenThread()");
 				ThreadMaster.Remove (Thread.CurrentThread.Name);
 			} catch (Exception ex) {
-				Log.Out ("Error in TelnetListenThread: " + ex.Message);
-				Log.Out ("Stack Trace: " + ex.StackTrace);
+				Log.Out ("Error in TelnetListenThread: " + ex);
 			}
-		}
-
-		private void LoginMessage (TelnetConnection c)
-		{
-			c.WriteLine ("*** Connected with 7DTD server.");
-			c.WriteLine ("*** Dedicated server only build");
-			c.WriteLine ("*** Allocs server fixes loaded");
-			c.WriteLine (string.Empty);
-			c.WriteLine ("Server IP:   " + 
-				((GamePrefs.GetString (EnumGamePrefs.ServerIP) != null && GamePrefs.GetString (EnumGamePrefs.ServerIP).Length != 0) ? GamePrefs.GetString (EnumGamePrefs.ServerIP) : "Any")
-			);
-			c.WriteLine ("Server port: " + GamePrefs.GetInt (EnumGamePrefs.ServerPort));
-			c.WriteLine ("Max players: " + GamePrefs.GetInt (EnumGamePrefs.ServerMaxPlayerCount));
-			c.WriteLine ("Game mode:   " + GamePrefs.GetString (EnumGamePrefs.GameMode));
-			c.WriteLine ("World:       " + GamePrefs.GetString (EnumGamePrefs.GameWorld));
-			c.WriteLine ("Game name:   " + GamePrefs.GetString (EnumGamePrefs.GameName));
-			c.WriteLine ("Difficulty:  " + GamePrefs.GetInt (EnumGamePrefs.GameDifficulty));
-			c.WriteLine (string.Empty);
-			c.WriteLine ("Press 'help' to get a list of all commands. Press 'exit' to end session.");
-			c.WriteLine (string.Empty);
-		}
-
-		private string lineCorrecter (string line)
-		{
-			string res = "";
-			for (int i = 0; i < line.Length; i++) {
-				if (line [i] >= ' ' && line [i] != '\'') {
-					res += line [i];
-				}
-			}
-			return res.Trim ();
 		}
 
@@ -126,4 +64,5 @@
 				if (listener != null) {
 					listener.Stop ();
+					listener = null;
 				}
 				foreach (TelnetConnection c in connections) {
@@ -131,4 +70,7 @@
 				}
 				Thread.Sleep (100);
+				if (telnetThread != null) {
+					telnetThread.Interrupt ();
+				}
 			} catch (Exception e) {
 				Log.Out ("Error in Telnet.Disconnect: " + e);
@@ -139,8 +81,11 @@
 		{
 			try {
+				List<TelnetConnection> toRemove = new List<TelnetConnection> ();
 				foreach (TelnetConnection c in connections) {
-					if (c.IsClosed ()) {
-						c.Close ();
-					}
+					if (c.IsClosed ())
+						toRemove.Add (c);
+				}
+				foreach (TelnetConnection c in toRemove) {
+					connections.Remove (c);
 				}
 			} catch (Exception e) {
