Index: /binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
===================================================================
--- /binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj	(revision 73)
+++ /binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj	(revision 74)
@@ -32,5 +32,5 @@
     <Reference Include="System" />
     <Reference Include="Assembly-CSharp">
-      <HintPath>Assembly-CSharp.dll</HintPath>
+      <HintPath>..\..\..\..\..\sdtd\engine\7DaysToDie_Data\Managed\Assembly-CSharp.dll</HintPath>
     </Reference>
   </ItemGroup>
Index: /binary-improvements/7dtd-server-fixes/7dtd-server-fixes.userprefs
===================================================================
--- /binary-improvements/7dtd-server-fixes/7dtd-server-fixes.userprefs	(revision 73)
+++ /binary-improvements/7dtd-server-fixes/7dtd-server-fixes.userprefs	(revision 74)
@@ -1,7 +1,8 @@
 ﻿<Properties>
   <MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
-  <MonoDevelop.Ide.Workbench ActiveDocument="src/AssemblyInfo.cs">
+  <MonoDevelop.Ide.Workbench ActiveDocument="src/AllocsNetTelnetServer.cs">
     <Files>
       <File FileName="src/AssemblyInfo.cs" Line="1" Column="1" />
+      <File FileName="src/AllocsNetTelnetServer.cs" Line="37" Column="5" />
     </Files>
   </MonoDevelop.Ide.Workbench>
Index: /binary-improvements/7dtd-server-fixes/src/AllocsNetTelnetServer.cs
===================================================================
--- /binary-improvements/7dtd-server-fixes/src/AllocsNetTelnetServer.cs	(revision 73)
+++ /binary-improvements/7dtd-server-fixes/src/AllocsNetTelnetServer.cs	(revision 74)
@@ -4,124 +4,200 @@
 using System.Net;
 using System.Net.Sockets;
+using System.Reflection;
 using System.Threading;
 
 public class AllocsNetTelnetServer
 {
-	private static ឦ console;
-	private static Thread telnetThread;
-	private static Dictionary<EndPoint, bool> endpointsAuthed;
-	private static TcpListener listener;
-	private static NetworkStream stream;
-	private static bool closed;
-	private static string lineRead = string.Empty;
+	private class Connection
+	{
+		private bool authenticated = false;
+		private TcpClient client;
+		private NetworkStream stream;
+		private string lineBuffer = string.Empty;
+		private EndPoint endpoint;
+
+		public Connection (TcpClient client)
+		{
+			this.client = client;
+			this.stream = client.GetStream ();
+			this.endpoint = client.Client.RemoteEndPoint;
+		}
+
+		public EndPoint GetEndPoint ()
+		{
+			return endpoint;
+		}
+
+		private void WriteByte (byte v)
+		{
+			if (!IsClosed () && stream.CanWrite) {
+				stream.WriteByte (v);
+			}
+		}
+
+		public void WriteLine (string s)
+		{
+			if (!IsClosed () && stream.CanWrite) {
+				for (int i = 0; i < s.Length; i++) {
+					WriteByte ((byte)s [i]);
+				}
+				WriteByte (10);
+			}
+		}
+
+		public void Close ()
+		{
+			if (client != null)
+				client.Close ();
+			client = null;
+		}
+
+		public bool IsClosed ()
+		{
+			if (client != null && !client.Connected) {
+				Log.Out ("Telnet connection interrupted: " + endpoint);
+			}
+			return (client == null) || (!client.Connected);
+		}
+
+		public bool IsAuthenticated ()
+		{
+			return !authEnabled || authenticated;
+		}
+
+		public void SetAuthenticated ()
+		{
+			authenticated = true;
+		}
+
+		public bool Read ()
+		{
+			while (!IsClosed() && stream.CanRead && stream.DataAvailable) {
+				int b = stream.ReadByte ();
+				if (b == '\r' || b == '\n') {
+					if (lineBuffer.Length > 0)
+						return true;
+				} else {
+					lineBuffer += (char)b;
+				}
+			}
+			return false;
+		}
+
+		public string GetLine ()
+		{
+			string res = lineBuffer;
+			lineBuffer = string.Empty;
+			return res;
+		}
+	}
+
+	private static cl004c console = null;
+	private static Thread telnetThread = null;
+	private static TcpListener listener = null;
+	private static bool closed = false;
+	private static bool authEnabled = false;
+	private static List<Connection> conns = new List<Connection> ();
 
 	public static void init (int port)
 	{
-		listener = new TcpListener (IPAddress.Any, port);
+		Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly().GetName().Version);
+		authEnabled = GamePrefs.GetString (EnumGamePrefs.TelnetPassword).Length != 0;
+		if (authEnabled)
+			listener = new TcpListener (IPAddress.Any, port);
+		else
+			listener = new TcpListener (IPAddress.Loopback, port);
 		telnetThread = ThreadMaster.Create ("thread Allocs TelnetListenThread", new ThreadStart (telnetListenThread));
 		telnetThread.Start ();
-		endpointsAuthed = new Dictionary<EndPoint, bool> ();
-		Console.Out.WriteLine ("Started Allocs NetTelnetServer thread on " + port);
-//		Log.Out ("Started Allocs NetTelnetServer thread on " + port);
+		Log.Out ("Started Allocs NetTelnetServer thread on " + port);
 	}
 
 	private static void telnetListenThread ()
 	{
-		Console.Out.WriteLine ("Started thread_Allocs_TelnetListenThread()");
-		//Log.Out ("Started thread_Allocs_TelnetListenThread()");
-		listener.Start ();
-		while (!closed) {
-			Thread.Sleep (10);
-			TcpClient tcpClient = listener.AcceptTcpClient ();
-			if (tcpClient != null) {
-				try {
-					Console.Out.WriteLine ("Someone connected to telnet!");
-					endpointsAuthed.Add (tcpClient.Client.RemoteEndPoint, false);
-					stream = tcpClient.GetStream ();
-					StreamReader streamReader = new StreamReader (stream);
-					WriteToClient ("Please enter password:");
-					while (!closed && !endpointsAuthed[tcpClient.Client.RemoteEndPoint]) {
-						lineRead = streamReader.ReadLine ();
-						string text = string.Empty;
-						lineCorrecter (ref text);
-						text = text.Trim ();
-						if (text.Equals (GamePrefs.GetString (EnumGamePrefs.TelnetPassword))) {
-							endpointsAuthed [tcpClient.Client.RemoteEndPoint] = true;
-							WriteToClient ("Logon successful.");
-							WriteToClient (string.Empty);
-							WriteToClient (string.Empty);
-							WriteToClient (string.Empty);
+		try {
+			Log.Out ("Started thread_Allocs_TelnetListenThread()");
+			listener.Start ();
+			while (!closed) {
+				Thread.Sleep (10);
+				if (listener.Pending ()) {
+					Connection c = new Connection (listener.AcceptTcpClient ());
+					conns.Add (c);
+					Log.Out ("Telnet connection from: " + c.GetEndPoint ());
+					if (authEnabled) {
+						c.WriteLine ("Please enter password:");
+					} else {
+						LoginMessage (c);
+					}
+				}
+
+				foreach (Connection c in conns) {
+					if (c.IsClosed ()) {
+						c.Close ();
+						conns.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 {
-							WriteToClient ("Password incorrect, please enter password:");
+							if (line.ToLower ().Equals ("exit")) {
+								Log.Out ("Telnet connection closed by client: " + c.GetEndPoint ());
+								c.Close ();
+								conns.Remove (c);
+								break;
+							}
+
+							Log.Out ("Telnet executed \"" + line + "\" from: " + c.GetEndPoint ());
+							console.md000f (line);
 						}
 					}
-					WriteToClient ("*** Connected with 7DTD server.");
-					WriteToClient ("*** Server version: Alpha 8.7 (b29) Compatibility Version: Alpha 8.7");
-					WriteToClient (string.Empty);
-					WriteToClient ("Server IP:   " + 
-						((GamePrefs.GetString (EnumGamePrefs.ServerIP) != null && GamePrefs.GetString (EnumGamePrefs.ServerIP).Length != 0) ? GamePrefs.GetString (EnumGamePrefs.ServerIP) : "Any")
-					);
-					WriteToClient ("Server port: " + GamePrefs.GetInt (EnumGamePrefs.ServerPort));
-					WriteToClient ("Max players: " + GamePrefs.GetInt (EnumGamePrefs.ServerMaxPlayerCount));
-					WriteToClient ("Game mode:   " + GamePrefs.GetString (EnumGamePrefs.GameMode));
-					WriteToClient ("World:       " + GamePrefs.GetString (EnumGamePrefs.GameWorld));
-					WriteToClient ("Game name:   " + GamePrefs.GetString (EnumGamePrefs.GameName));
-					WriteToClient ("Difficulty:  " + GamePrefs.GetInt (EnumGamePrefs.GameDifficulty));
-					WriteToClient (string.Empty);
-					WriteToClient ("Press 'help' to get a list of all commands. Press 'exit' to end session.");
-					WriteToClient (string.Empty);
-					while (!closed) {
-						lineRead = streamReader.ReadLine ();
-						string text2 = string.Empty;
-						lineCorrecter (ref text2);
-						text2 = text2.Trim ();
-						if (text2.Equals ("exit")) {
-							endpointsAuthed [tcpClient.Client.RemoteEndPoint] = false;
-							break;
-						}
-
-						if (text2.Length != 0) {
-							Console.WriteLine ("Telnet executed \"" + text2 + "\" by " + tcpClient.Client.RemoteEndPoint);
-//							console.᝚ᙂ (text2);
-							lineRead = string.Empty;
-						}
-						Thread.Sleep (50);
-					}
-					if (stream != null) {
-						endpointsAuthed [tcpClient.Client.RemoteEndPoint] = false;
-						stream.Close ();
-						stream = null;
-					}
-				} catch (Exception ex) {
-					Console.Out.WriteLine ("Error in Allocs telnetListenThread: " + ex.Message);
-					//Log.Out ("Error in Allocs telnetListenThread: " + ex.Message);
-					Console.Out.WriteLine ("Stack Trace: " + ex.StackTrace);
-					//Log.Out ("Stack Trace: " + ex.StackTrace);
-				}
-				if (stream != null) {
-					endpointsAuthed [tcpClient.Client.RemoteEndPoint] = false;
-					stream.Close ();
-					stream = null;
-				}
-			}
-		}
-		Console.Out.WriteLine ("Exited thread_Allocs_TelnetListenThread()");
-		//Log.Out ("Exited thread_Allocs_TelnetListenThread()");
-		ThreadMaster.Remove (Thread.CurrentThread.Name);
-	}
-
-	private static void lineCorrecter (ref string line)
-	{
-		if (lineRead == null) {
-			return;
-		}
-		for (int i = 0; i < lineRead.Length; i++) {
-			if ((lineRead [i] == '\b' || lineRead [i] == '~') && line.Length > 0) {
-				line = line.Substring (0, line.Length);
-			}
-			if (lineRead [i] >= ' ' && lineRead [i] != '\'' && lineRead [i] <= '~') {
-				line += lineRead [i];
-			}
-		}
+				}
+			}
+			Log.Out ("Exited thread_Allocs_TelnetListenThread()");
+			ThreadMaster.Remove (Thread.CurrentThread.Name);
+		} catch (Exception ex) {
+			Log.Out ("Error in Allocs telnetListenThread: " + ex.Message);
+			Log.Out ("Stack Trace: " + ex.StackTrace);
+		}
+	}
+
+	private static void LoginMessage (Connection c)
+	{
+		c.WriteLine ("*** Connected with 7DTD server.");
+		c.WriteLine ("*** Server version: Alpha 8.7 (b29) Compatibility Version: Alpha 8.7");
+		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 static string lineCorrecter (string line)
+	{
+		string res = "";
+		for (int i = 0; i < line.Length; i++) {
+			if (line [i] >= ' ' && line [i] != '\'' && line [i] <= '~') {
+				res += line [i];
+			}
+		}
+		return res.Trim ();
 	}
 
@@ -132,13 +208,22 @@
 			listener.Stop ();
 		}
-		if (stream != null) {
-			stream.Close ();
+		foreach (Connection c in conns) {
+			c.Close ();
 		}
 		Thread.Sleep (100);
 	}
 
-	public static void SetConsole (ឦ console)
+	public static void SetConsole (cl004c console)
 	{
 		AllocsNetTelnetServer.console = console;
+	}
+
+	private static void RemoveClosedConnections ()
+	{
+		foreach (Connection c in conns) {
+			if (c.IsClosed ()) {
+				c.Close ();
+			}
+		}
 	}
 
@@ -148,10 +233,8 @@
 			return;
 		}
-		if (stream != null) {
-			for (int i = 0; i < line.Length; i++) {
-				stream.WriteByte ((byte)line [i]);
-			}
-			stream.WriteByte (13);
-			stream.WriteByte (10);
+		RemoveClosedConnections ();
+		foreach (Connection c in conns) {
+			if (c.IsAuthenticated())
+				c.WriteLine (line);
 		}
 	}
Index: /binary-improvements/assembly-patcher/Assembly-Patcher.userprefs
===================================================================
--- /binary-improvements/assembly-patcher/Assembly-Patcher.userprefs	(revision 73)
+++ /binary-improvements/assembly-patcher/Assembly-Patcher.userprefs	(revision 74)
@@ -1,7 +1,7 @@
 ﻿<Properties>
   <MonoDevelop.Ide.Workspace ActiveConfiguration="Release|x86" />
-  <MonoDevelop.Ide.Workbench ActiveDocument="AssemblyInfo.cs">
+  <MonoDevelop.Ide.Workbench ActiveDocument="Main.cs">
     <Files>
-      <File FileName="Main.cs" Line="47" Column="45" />
+      <File FileName="Main.cs" Line="19" Column="4" />
       <File FileName="AssemblyInfo.cs" Line="7" Column="36" />
     </Files>
