Index: binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
===================================================================
--- binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj	(revision 180)
+++ binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj	(revision 182)
@@ -119,4 +119,5 @@
     <Compile Include="src\NetConnections\Servers\Web\API\GetPlayerInventory.cs" />
     <Compile Include="src\NetConnections\Servers\Web\API\GetLandClaims.cs" />
+    <Compile Include="src\BlockingQueue.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Index: binary-improvements/7dtd-server-fixes/src/AssemblyInfo.cs
===================================================================
--- binary-improvements/7dtd-server-fixes/src/AssemblyInfo.cs	(revision 180)
+++ binary-improvements/7dtd-server-fixes/src/AssemblyInfo.cs	(revision 182)
@@ -18,5 +18,5 @@
 // and "{Major}.{Minor}.{Build}.*" will update just the revision.
 
-[assembly: AssemblyVersion("0.092.*")]
+[assembly: AssemblyVersion("0.093.*")]
 
 // The following attributes are used to specify the signing key for the assembly, 
Index: binary-improvements/7dtd-server-fixes/src/BlockingQueue.cs
===================================================================
--- binary-improvements/7dtd-server-fixes/src/BlockingQueue.cs	(revision 182)
+++ binary-improvements/7dtd-server-fixes/src/BlockingQueue.cs	(revision 182)
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+
+namespace AllocsFixes
+{
+	public class BlockingQueue<T>
+	{
+		private Queue<T> queue = new Queue<T> ();
+
+		public void Enqueue (T item)
+		{
+			lock (queue) {
+				queue.Enqueue (item);
+				Monitor.PulseAll (queue);
+			}
+		}
+
+		public T Dequeue ()
+		{
+			lock (queue) {
+				while (queue.Count == 0) {
+					Monitor.Wait (queue);
+				}
+				return queue.Dequeue ();
+			}
+		}
+
+
+	}
+}
+
Index: binary-improvements/7dtd-server-fixes/src/NetConnections/NetTelnetServer.cs
===================================================================
--- binary-improvements/7dtd-server-fixes/src/NetConnections/NetTelnetServer.cs	(revision 180)
+++ binary-improvements/7dtd-server-fixes/src/NetConnections/NetTelnetServer.cs	(revision 182)
@@ -4,5 +4,4 @@
 using System.Net;
 using System.Net.Sockets;
-using System.Reflection;
 using System.Threading;
 using UnityEngine;
@@ -17,16 +16,12 @@
 		{
 			try {
-				Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly ().GetName ().Version);
-				servers.Add (new Servers.Telnet.Telnet (port));
-
-				int webPort = GamePrefs.GetInt (EnumGamePrefs.ControlPanelPort);
-				if (GamePrefs.GetBool (EnumGamePrefs.ControlPanelEnabled) && webPort > 0 && webPort < 65534) {
-					if (Directory.Exists (Application.dataPath + "/../webserver")) {
-						servers.Add (new Servers.Web.Web (webPort + 2));
-					}
-				}
 			} catch (Exception e) {
 				Log.Out ("Error in NetTelnetServer.init: " + e);
 			}
+		}
+
+		public static void RegisterServer (IServer serv)
+		{
+			servers.Add (serv);
 		}
 
Index: binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/Telnet.cs
===================================================================
--- binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/Telnet.cs	(revision 180)
+++ 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) {
Index: binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/TelnetConnection.cs
===================================================================
--- binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/TelnetConnection.cs	(revision 180)
+++ binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/TelnetConnection.cs	(revision 182)
@@ -1,6 +1,9 @@
 using System;
+using System.Collections.Generic;
+using System.IO;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
+using System.Threading;
 
 namespace AllocsFixes.NetConnections.Servers.Telnet
@@ -8,10 +11,11 @@
 	public class TelnetConnection : IConnection
 	{
+		BlockingQueue<string> toClientQueue = new BlockingQueue<string> ();
+		private Thread receiveThread = null;
+		private Thread sendThread = null;
 		private bool authenticated = false;
 		private bool authEnabled;
 		private TcpClient client;
 		private NetworkStream stream;
-		private int lineBufferLength = 0;
-		private byte[] lineBuffer = new byte[200];
 		private EndPoint endpoint;
 
@@ -22,34 +26,120 @@
 			this.stream = client.GetStream ();
 			this.endpoint = client.Client.RemoteEndPoint;
+
+			Log.Out ("Telnet connection from: " + endpoint);
+
+			receiveThread = ThreadMaster.Create ("TelnetClientReceive", new ThreadStart (ReceiveThread));
+			receiveThread.Start ();
+			sendThread = ThreadMaster.Create ("TelnetClientSend", new ThreadStart (SendThread));
+			sendThread.Start ();
+
+			if (authEnabled) {
+				WriteLine ("Please enter password:");
+			} else {
+				LoginMessage ();
+			}
 		}
 
-		public EndPoint GetEndPoint ()
+		private void LoginMessage ()
 		{
-			return endpoint;
+			WriteLine ("*** Connected with 7DTD server.");
+			WriteLine ("*** Dedicated server only build");
+			WriteLine ("*** Allocs server fixes loaded");
+			WriteLine (string.Empty);
+			WriteLine ("Server IP:   " + 
+				((GamePrefs.GetString (EnumGamePrefs.ServerIP) != null && GamePrefs.GetString (EnumGamePrefs.ServerIP).Length != 0) ? GamePrefs.GetString (EnumGamePrefs.ServerIP) : "Any")
+			);
+			WriteLine ("Server port: " + GamePrefs.GetInt (EnumGamePrefs.ServerPort));
+			WriteLine ("Max players: " + GamePrefs.GetInt (EnumGamePrefs.ServerMaxPlayerCount));
+			WriteLine ("Game mode:   " + GamePrefs.GetString (EnumGamePrefs.GameMode));
+			WriteLine ("World:       " + GamePrefs.GetString (EnumGamePrefs.GameWorld));
+			WriteLine ("Game name:   " + GamePrefs.GetString (EnumGamePrefs.GameName));
+			WriteLine ("Difficulty:  " + GamePrefs.GetInt (EnumGamePrefs.GameDifficulty));
+			WriteLine (string.Empty);
+			WriteLine ("Press 'help' to get a list of all commands. Press 'exit' to end session.");
+			WriteLine (string.Empty);
 		}
 
-		private void WriteByte (byte v)
+		private void ReceiveThread ()
 		{
-			if (!IsClosed () && stream.CanWrite) {
-				stream.WriteByte (v);
+			try {
+				StreamReader reader = new StreamReader (stream);
+				try {
+					while (!IsClosed()) {
+						string line = reader.ReadLine ();
+						if (line != null) {
+							line = line.Trim ();
+
+							if (!IsAuthenticated ()) {
+								if (line.Equals (GamePrefs.GetString (EnumGamePrefs.TelnetPassword))) {
+									authenticated = true;
+									WriteLine ("Logon successful.");
+									WriteLine (string.Empty);
+									WriteLine (string.Empty);
+									WriteLine (string.Empty);
+									LoginMessage ();
+								} else {
+									WriteLine ("Password incorrect, please enter password:");
+								}
+							} else {
+								if (line.ToLower ().Equals ("exit")) {
+									Log.Out ("Telnet connection closed by client: " + endpoint);
+									Close ();
+									break;
+								}
+								Log.Out ("Telnet executed \"" + line + "\" from: " + endpoint);
+								ConsoleOutputSeparator.QueueNetCommand (line, this);
+							}
+						}
+					}
+				} catch (IOException) {
+				} catch (ThreadInterruptedException) {
+				}
+				ThreadMaster.Remove (Thread.CurrentThread.Name);
+			} catch (Exception ex) {
+				Log.Out ("Error in TelnetClientReceive: " + ex);
 			}
+
+		}
+
+		private void SendThread ()
+		{
+			try {
+				while (!IsClosed() && stream.CanWrite) {
+					try {
+						string line = toClientQueue.Dequeue ();
+						if (!IsClosed () && stream.CanWrite) {
+							byte[] utfData = Encoding.UTF8.GetBytes (line);
+							stream.Write (utfData, 0, utfData.Length);
+							stream.WriteByte (13);
+							stream.WriteByte (10);
+						}
+					} catch (IOException) {
+					} catch (ThreadInterruptedException) {
+					} catch (Exception e) {
+						Log.Out ("Error writing to client: " + e);
+					}
+				}
+
+				ThreadMaster.Remove (Thread.CurrentThread.Name);
+			} catch (Exception ex) {
+				Log.Out ("Error in TelnetClientSend: " + ex);
+			}
+
 		}
 
 		public void WriteLine (string s)
 		{
-			try {
-				if (!IsClosed () && stream.CanWrite) {
-					byte[] utfData = Encoding.UTF8.GetBytes (s);
-					stream.Write (utfData, 0, utfData.Length);
-					WriteByte (13);
-					WriteByte (10);
-				}
-			} catch (Exception e) {
-				Log.Out ("Error writing to client: " + e);
-			}
+			toClientQueue.Enqueue (s);
 		}
 
 		public void Close ()
 		{
+			if (receiveThread != null) {
+				receiveThread.Interrupt ();
+			}
+			if (sendThread != null) {
+				sendThread.Interrupt ();
+			}
 			if (client != null)
 				client.Close ();
@@ -61,4 +151,5 @@
 			if (client != null && !client.Connected) {
 				Log.Out ("Telnet connection interrupted: " + endpoint);
+				Close ();
 			}
 			return (client == null) || (!client.Connected);
@@ -70,32 +161,4 @@
 		}
 
-		public void SetAuthenticated ()
-		{
-			authenticated = true;
-		}
-
-		public bool Read ()
-		{
-			while (!IsClosed() && stream.CanRead && stream.DataAvailable) {
-				int b = stream.ReadByte ();
-				if (b == '\r' || b == '\n') {
-					if (lineBufferLength > 0) {
-						return true;
-					}
-				} else if (b >= 0) {
-					lineBuffer [lineBufferLength] = (byte)b;
-					lineBufferLength++;
-				}
-			}
-			return false;
-		}
-
-		public string GetLine ()
-		{
-			string res = Encoding.UTF8.GetString (lineBuffer, 0, lineBufferLength);
-			lineBufferLength = 0;
-			return res;
-		}
-
 	}
 }
Index: binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs
===================================================================
--- binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs	(revision 180)
+++ binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs	(revision 182)
@@ -16,7 +16,17 @@
 		private string realm = "7dtd Admin Panel";
 
-		public Web (int port)
+		public Web ()
 		{
 			try {
+				int webPort = GamePrefs.GetInt (EnumGamePrefs.ControlPanelPort);
+				if (!GamePrefs.GetBool (EnumGamePrefs.ControlPanelEnabled) || webPort < 1 || webPort > 65533) {
+					Log.Out ("Webserver not started (ControlPanel not enabled or ControlPanelPort not within 1-65534)");
+					return;
+				}
+				if (!Directory.Exists (Application.dataPath + "/../webserver")) {
+					Log.Out ("Webserver not started (folder \"webserver\" not found in game folder)");
+					return;
+				}
+
 				if (!HttpListener.IsSupported)
 					throw new NotSupportedException ("Needs Windows XP SP2, Server 2003 or later.");
@@ -27,5 +37,5 @@
 				handlers.Add ("/api/", new ApiHandler ("/api/"));
 
-				_listener.Prefixes.Add (String.Format ("http://*:{0}/", port));
+				_listener.Prefixes.Add (String.Format ("http://*:{0}/", webPort + 2));
 				authEnabled = File.Exists (Application.dataPath + "/../webserver/protect");
 				if (authEnabled)
@@ -49,5 +59,8 @@
 				);
 
-				Log.Out ("Started Webserver on " + port + " (authentication " + (authEnabled ? "enabled" : "disabled") + ")");
+				NetTelnetServer.RegisterServer(this);
+
+
+				Log.Out ("Started Webserver on " + (webPort + 2) + " (authentication " + (authEnabled ? "enabled" : "disabled") + ")");
 			} catch (Exception e) {
 				Log.Out ("Error in Web.ctor: " + e);
Index: binary-improvements/7dtd-server-fixes/src/StateManager.cs
===================================================================
--- binary-improvements/7dtd-server-fixes/src/StateManager.cs	(revision 180)
+++ binary-improvements/7dtd-server-fixes/src/StateManager.cs	(revision 182)
@@ -1,3 +1,6 @@
+using AllocsFixes.NetConnections.Servers.Telnet;
+using AllocsFixes.NetConnections.Servers.Web;
 using System;
+using System.Reflection;
 
 namespace AllocsFixes
@@ -8,5 +11,10 @@
 		{
 			try {
+				Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly ().GetName ().Version);
+				new Web();
+				new Telnet();
+
 				CommandExtensions.InitCommandExtensions (manager);
+
 				PersistentData.PersistentContainer.Load ();
 			} catch (Exception e) {
Index: binary-improvements/bin/Release/7dtd-server-fixes_version.txt
===================================================================
--- binary-improvements/bin/Release/7dtd-server-fixes_version.txt	(revision 180)
+++ binary-improvements/bin/Release/7dtd-server-fixes_version.txt	(revision 182)
@@ -1,1 +1,1 @@
-Version:       0.92.5364.31430
+Version:       0.92.5365.35778
