Changeset 132 for binary-improvements/7dtd-server-fixes/src
- Timestamp:
- Aug 26, 2014, 7:29:11 PM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src
- Files:
-
- 6 added
- 1 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/MapRendering/MapRendering.cs
r130 r132 24 24 private MapRenderBlockBuffer[] zoomLevelBuffers = new MapRenderBlockBuffer[Constants.ZOOMLEVELS]; 25 25 private Color[] chunkColors = new Color[Constants.MAP_CHUNK_SIZE * Constants.MAP_CHUNK_SIZE]; 26 private System.Timers.Timer chunkSaveTimer = new System.Timers.Timer ( 100);26 private System.Timers.Timer chunkSaveTimer = new System.Timers.Timer (500); 27 27 private bool renderingFullMap = false; 28 28 29 29 private MapRendering () 30 30 { 31 string regionSaveDir = StaticDirectories.GetSaveGameRegionDir ();32 rfm = new RegionFileManager (regionSaveDir, regionSaveDir, 1, false);33 31 Constants.MAP_DIRECTORY = StaticDirectories.GetSaveGameDir () + "/map"; 34 32 … … 64 62 MicroStopwatch microStopwatch = new MicroStopwatch (); 65 63 64 string regionSaveDir = StaticDirectories.GetSaveGameRegionDir (); 65 rfm = new RegionFileManager (regionSaveDir, regionSaveDir, 1, false); 66 66 67 if (Directory.Exists (Constants.MAP_DIRECTORY)) 67 68 Directory.Delete (Constants.MAP_DIRECTORY, true); … … 88 89 } 89 90 SaveAllBlockMaps (null, null); 91 92 rfm = null; 90 93 91 94 byte[] array = fullMapTexture.EncodeToPNG (); -
binary-improvements/7dtd-server-fixes/src/NetConnections/ConsoleOutputSeparator.cs
r130 r132 4 4 using UnityEngine; 5 5 6 namespace AllocsFixes 6 namespace AllocsFixes.NetConnections 7 7 { 8 8 public class ConsoleOutputSeparator 9 9 { 10 public struct AllocsTelnetCommand10 public struct NetCommand 11 11 { 12 12 public string command; 13 public AllocsTelnetConnection client;13 public IConnection client; 14 14 15 public AllocsTelnetCommand (string _cmd, AllocsTelnetConnection _client)15 public NetCommand (string _cmd, IConnection _client) 16 16 { 17 17 command = _cmd; … … 20 20 } 21 21 22 private static List< AllocsTelnetCommand> telnetCommandQueue = new List<AllocsTelnetCommand> ();22 private static List<NetCommand> netCommandQueue = new List<NetCommand> (); 23 23 private static bool isCurrentCommandFromClient = false; 24 private static AllocsTelnetConnection issuerOfCurrentTelnetCommand;24 private static IConnection issuerOfCurrentCommand; 25 25 26 26 public static void C_ExecuteCmdFromClient (ConsoleSdtd console, NetworkPlayer _networkPlayer, string _playerID, string _command) … … 28 28 Log.Out ("Executed command \"" + _command + "\" from player \"" + _playerID + "\""); 29 29 30 object obj = telnetCommandQueue;30 object obj = netCommandQueue; 31 31 Monitor.Enter (obj); 32 32 try { … … 51 51 ); 52 52 } else { 53 if (console.telnetServer != null && issuerOfCurrent TelnetCommand != null)54 AllocsNetTelnetServer.WriteToClient_Single (_line, issuerOfCurrentTelnetCommand);53 if (console.telnetServer != null && issuerOfCurrentCommand != null) 54 NetTelnetServer.WriteToClient_Single (_line, issuerOfCurrentCommand); 55 55 else if (ControlPanel.IsStarted ()) 56 56 ControlPanel.AddTextToOutputBuffer (_line); … … 60 60 public static void C_Run (ConsoleSdtd console) 61 61 { 62 if ( telnetCommandQueue.Count > 0) {63 object obj = telnetCommandQueue;62 if (netCommandQueue.Count > 0) { 63 object obj = netCommandQueue; 64 64 Monitor.Enter (obj); 65 65 try { 66 issuerOfCurrent TelnetCommand = telnetCommandQueue [0].client;67 console.ExecuteRemoteCmdInternal ( telnetCommandQueue [0].command, false);68 telnetCommandQueue.RemoveAt (0);69 issuerOfCurrent TelnetCommand = null;66 issuerOfCurrentCommand = netCommandQueue [0].client; 67 console.ExecuteRemoteCmdInternal (netCommandQueue [0].command, false); 68 netCommandQueue.RemoveAt (0); 69 issuerOfCurrentCommand = null; 70 70 } finally { 71 71 Monitor.Exit (obj); … … 74 74 } 75 75 76 public static void Queue TelnetCommand (string _line, AllocsTelnetConnection _con)76 public static void QueueNetCommand (string _line, IConnection _con) 77 77 { 78 object obj = telnetCommandQueue;78 object obj = netCommandQueue; 79 79 Monitor.Enter (obj); 80 80 try { 81 telnetCommandQueue.Add (new AllocsTelnetCommand (_line, _con));81 netCommandQueue.Add (new NetCommand (_line, _con)); 82 82 } finally { 83 83 Monitor.Exit (obj); -
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 -
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/TelnetConnection.cs
r130 r132 3 3 using System.Net.Sockets; 4 4 5 namespace AllocsFixes 5 namespace AllocsFixes.NetConnections.Servers.Telnet 6 6 { 7 public class AllocsTelnetConnection8 {9 private bool authenticated = false;10 private bool authEnabled;11 private TcpClient client;12 private NetworkStream stream;13 private string lineBuffer = string.Empty;14 private EndPoint endpoint;7 public class TelnetConnection : IConnection 8 { 9 private bool authenticated = false; 10 private bool authEnabled; 11 private TcpClient client; 12 private NetworkStream stream; 13 private string lineBuffer = string.Empty; 14 private EndPoint endpoint; 15 15 16 public AllocsTelnetConnection (TcpClient client, bool authEnabled)17 {18 this.authEnabled = authEnabled;19 this.client = client;20 this.stream = client.GetStream ();21 this.endpoint = client.Client.RemoteEndPoint;22 }16 public TelnetConnection (TcpClient client, bool authEnabled) 17 { 18 this.authEnabled = authEnabled; 19 this.client = client; 20 this.stream = client.GetStream (); 21 this.endpoint = client.Client.RemoteEndPoint; 22 } 23 23 24 public EndPoint GetEndPoint ()25 {26 return endpoint;27 }24 public EndPoint GetEndPoint () 25 { 26 return endpoint; 27 } 28 28 29 private void WriteByte (byte v) 30 { 31 if (!IsClosed () && stream.CanWrite) { 32 stream.WriteByte (v); 33 } 34 } 35 36 public void WriteLine (string s) 37 { 38 try { 29 private void WriteByte (byte v) 30 { 39 31 if (!IsClosed () && stream.CanWrite) { 40 for (int i = 0; i < s.Length; i++) { 41 WriteByte ((byte)s [i]); 42 } 43 WriteByte(13); 44 WriteByte (10); 45 } 46 } catch (Exception e) { 47 Log.Out("Error writing to client: " + e); 48 } 49 } 50 51 public void Close () 52 { 53 if (client != null) 54 client.Close (); 55 client = null; 56 } 57 58 public bool IsClosed () 59 { 60 if (client != null && !client.Connected) { 61 Log.Out ("Telnet connection interrupted: " + endpoint); 62 } 63 return (client == null) || (!client.Connected); 64 } 65 66 public bool IsAuthenticated () 67 { 68 return !authEnabled || authenticated; 69 } 70 71 public void SetAuthenticated () 72 { 73 authenticated = true; 74 } 75 76 public bool Read () 77 { 78 while (!IsClosed() && stream.CanRead && stream.DataAvailable) { 79 int b = stream.ReadByte (); 80 if (b == '\r' || b == '\n') { 81 if (lineBuffer.Length > 0) 82 return true; 83 } else { 84 lineBuffer += (char)b; 32 stream.WriteByte (v); 85 33 } 86 34 } 87 return false;88 }89 35 90 public string GetLine () 91 { 92 string res = lineBuffer; 93 lineBuffer = string.Empty; 94 return res; 36 public void WriteLine (string s) 37 { 38 try { 39 if (!IsClosed () && stream.CanWrite) { 40 for (int i = 0; i < s.Length; i++) { 41 WriteByte ((byte)s [i]); 42 } 43 WriteByte (13); 44 WriteByte (10); 45 } 46 } catch (Exception e) { 47 Log.Out ("Error writing to client: " + e); 48 } 49 } 50 51 public void Close () 52 { 53 if (client != null) 54 client.Close (); 55 client = null; 56 } 57 58 public bool IsClosed () 59 { 60 if (client != null && !client.Connected) { 61 Log.Out ("Telnet connection interrupted: " + endpoint); 62 } 63 return (client == null) || (!client.Connected); 64 } 65 66 public bool IsAuthenticated () 67 { 68 return !authEnabled || authenticated; 69 } 70 71 public void SetAuthenticated () 72 { 73 authenticated = true; 74 } 75 76 public bool Read () 77 { 78 while (!IsClosed() && stream.CanRead && stream.DataAvailable) { 79 int b = stream.ReadByte (); 80 if (b == '\r' || b == '\n') { 81 if (lineBuffer.Length > 0) 82 return true; 83 } else { 84 lineBuffer += (char)b; 85 } 86 } 87 return false; 88 } 89 90 public string GetLine () 91 { 92 string res = lineBuffer; 93 lineBuffer = string.Empty; 94 return res; 95 } 96 95 97 } 96 98 } 97 }
Note:
See TracChangeset
for help on using the changeset viewer.