Changeset 189 for binary-improvements/7dtd-server-fixes/src
- Timestamp:
- Sep 12, 2014, 11:14:11 AM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/CustomCommands/TeleportPlayer.cs
r174 r189 2 2 using System; 3 3 using System.Collections.Generic; 4 using UnityEngine; 4 5 5 6 namespace AllocsFixes.CustomCommands … … 24 25 { 25 26 try { 26 if (_params.Length != 4 ) {27 if (_params.Length != 4 && _params.Length != 2) { 27 28 m_Console.SendResult ("Usage: teleportplayer <entityid|playername|steamid> <x> <y> <z>"); 29 m_Console.SendResult (" or: teleportplayer <entityid|playername|steamid> <target entityid|playername|steamid>"); 28 30 } else { 29 string steamid = PersistentContainer.Instance.Players.GetSteamID(_params [0], true);30 if ( steamid== null) {31 Player p1 = PersistentContainer.Instance.Players.GetPlayerByNameOrId (_params [0], true); 32 if (p1 == null) { 31 33 m_Console.SendResult ("Playername or entity/steamid id not found."); 32 34 return; 33 35 } 34 35 Player p = PersistentContainer.Instance.Players [steamid]; 36 if (!p.IsOnline) { 36 if (!p1.IsOnline) { 37 37 m_Console.SendResult ("Player not online."); 38 38 return; 39 39 } 40 40 41 int x = int.MinValue; 42 int.TryParse (_params [1], out x); 43 int y = int.MinValue; 44 int.TryParse (_params [2], out y); 45 int z = int.MinValue; 46 int.TryParse (_params [3], out z); 41 if (_params.Length == 4) { 42 int x = int.MinValue; 43 int y = int.MinValue; 44 int z = int.MinValue; 47 45 48 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) { 49 m_Console.SendResult ("At least one of the given coordinates is not a valid integer"); 50 return; 46 int.TryParse (_params [1], out x); 47 int.TryParse (_params [2], out y); 48 int.TryParse (_params [3], out z); 49 50 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) { 51 m_Console.SendResult ("At least one of the given coordinates is not a valid integer"); 52 return; 53 } 54 55 p1.Entity.position.x = x; 56 p1.Entity.position.y = y; 57 p1.Entity.position.z = z; 58 } else { 59 Player p2 = PersistentContainer.Instance.Players.GetPlayerByNameOrId (_params [1], true); 60 if (p2 == null) { 61 m_Console.SendResult ("Target playername or entity/steamid id not found."); 62 return; 63 } 64 if (!p2.IsOnline) { 65 m_Console.SendResult ("Target player not online."); 66 return; 67 } 68 69 p1.Entity.position = p2.Entity.GetPosition(); 51 70 } 52 71 53 p.Entity.position.x = x; 54 p.Entity.position.y = y; 55 p.Entity.position.z = z; 56 NetPackage_EntityPosAndRot pkg = new NetPackage_EntityPosAndRot (p.Entity); 72 NetPackage_EntityPosAndRot pkg = new NetPackage_EntityPosAndRot (p1.Entity); 57 73 58 p .ClientInfo.netConnection [0].Send (pkg);74 p1.ClientInfo.netConnection [0].Send (pkg); 59 75 } 60 76 } catch (Exception e) { -
binary-improvements/7dtd-server-fixes/src/MapRendering/MapRenderBlockBuffer.cs
r168 r189 37 37 { 38 38 bool res = false; 39 Monitor.Enter (blockMap); 40 try { 39 lock (blockMap) { 41 40 string folder = Constants.MAP_DIRECTORY + "/" + (zoomLevel) + "/" + block.x; 42 41 string fileName = folder + "/" + block.y + ".png"; … … 48 47 } 49 48 currentBlockMap = fileName; 50 } finally {51 Monitor.Exit (blockMap);52 49 } 53 50 return res; -
binary-improvements/7dtd-server-fixes/src/MapRendering/MapRendering.cs
r187 r189 55 55 try { 56 56 if (!Instance.renderingFullMap) { 57 Monitor.Enter (Instance.zoomLevelBuffers); 58 try { 57 lock (Instance.zoomLevelBuffers) { 59 58 Chunk c = (Chunk)o; 60 59 Vector3i cPos = c.GetWorldPos (); … … 72 71 Instance.chunkSaveTimer.Start (); 73 72 } 74 } finally {75 Monitor.Exit (Instance.zoomLevelBuffers);76 73 } 77 74 } … … 103 100 ); 104 101 105 Monitor.Enter (Instance.zoomLevelBuffers); 106 try { 102 lock (Instance.zoomLevelBuffers) { 107 103 for (int i = 0; i < Constants.ZOOMLEVELS; i++) { 108 104 zoomLevelBuffers [i].ResetBlock (); … … 152 148 Log.Out (String.Format ("RenderMap: {0}/{1} ({2}%)", curFullMapPos.x, widthPix, (int)((float)curFullMapPos.x / widthPix * 100))); 153 149 } 154 } finally {155 Monitor.Exit (Instance.zoomLevelBuffers);156 150 } 157 151 … … 178 172 private void TimedRendering (object source, System.Timers.ElapsedEventArgs e) 179 173 { 180 Monitor.Enter (zoomLevelBuffers); 181 try { 174 lock (zoomLevelBuffers) { 182 175 RenderDirtyChunks (); 183 176 if (dirtyChunks.Count > 0) 184 177 Instance.chunkSaveTimer.Start (); 185 } finally {186 Monitor.Exit (zoomLevelBuffers);187 178 } 188 179 } -
binary-improvements/7dtd-server-fixes/src/NetConnections/ConsoleOutputSeparator.cs
r132 r189 28 28 Log.Out ("Executed command \"" + _command + "\" from player \"" + _playerID + "\""); 29 29 30 object obj = netCommandQueue; 31 Monitor.Enter (obj); 32 try { 30 lock (netCommandQueue) { 33 31 isCurrentCommandFromClient = true; 34 32 console.issuerOfCurrentClientCommand = _networkPlayer; 35 33 console.ExecuteClientCmdInternal (_playerID, _command); 36 34 isCurrentCommandFromClient = false; 37 } finally {38 Monitor.Exit (obj);39 35 } 40 36 … … 61 57 { 62 58 if (netCommandQueue.Count > 0) { 63 object obj = netCommandQueue; 64 Monitor.Enter (obj); 65 try { 59 lock (netCommandQueue) { 66 60 issuerOfCurrentCommand = netCommandQueue [0].client; 67 console.ExecuteRemoteCmdInternal (netCommandQueue [0].command, false); 61 try { 62 console.ExecuteRemoteCmdInternal (netCommandQueue [0].command, false); 63 } catch (Exception e) { 64 Log.Out("Exception while executing command: " + e); 65 } 68 66 netCommandQueue.RemoveAt (0); 69 67 issuerOfCurrentCommand = null; 70 } finally {71 Monitor.Exit (obj);72 68 } 73 69 } … … 76 72 public static void QueueNetCommand (string _line, IConnection _con) 77 73 { 78 object obj = netCommandQueue; 79 Monitor.Enter (obj); 80 try { 74 lock (netCommandQueue) { 81 75 netCommandQueue.Add (new NetCommand (_line, _con)); 82 } finally {83 Monitor.Exit (obj);84 76 } 85 77 } -
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/TelnetConnection.cs
r187 r189 38 38 39 39 if (endpoint is IPEndPoint) { 40 endpointAddressHash = ((IPEndPoint)endpoint).Address.GetHashCode ();40 endpointAddressHash = ((IPEndPoint)endpoint).Address.GetHashCode (); 41 41 //Log.Out ("Hash: " + endpointAddressHash); 42 42 } else { 43 Log.Out ("EndPoint is not an IPEndPoint but: " + endpoint.GetType ().ToString());43 Log.Out ("EndPoint is not an IPEndPoint but: " + endpoint.GetType ().ToString ()); 44 44 } 45 45 … … 78 78 while (!IsClosed()) { 79 79 string line = reader.ReadLine (); 80 if (line != null ) {80 if (line != null && line.Length > 0) { 81 81 line = line.Trim (); 82 83 if (!IsAuthenticated ()) { 84 if (line.Equals (GamePrefs.GetString (EnumGamePrefs.TelnetPassword))) { 85 authenticated = true; 86 WriteLine ("Logon successful."); 87 WriteLine (string.Empty); 88 WriteLine (string.Empty); 89 WriteLine (string.Empty); 90 LoginMessage (); 82 if (line.Length > 0) { 83 if (!IsAuthenticated ()) { 84 if (line.Equals (GamePrefs.GetString (EnumGamePrefs.TelnetPassword))) { 85 authenticated = true; 86 WriteLine ("Logon successful."); 87 WriteLine (string.Empty); 88 WriteLine (string.Empty); 89 WriteLine (string.Empty); 90 LoginMessage (); 91 } else { 92 if (owner.RegisterFailedLogin (endpointAddressHash)) { 93 WriteLine ("Password incorrect, please enter password:"); 94 } else { 95 WriteLine ("Too many failed login attempts!"); 96 Thread.Sleep (100); 97 Close (); 98 Log.Out ("Telnet connection closed for too many login attempts: " + endpoint); 99 break; 100 } 101 } 91 102 } else { 92 if (owner.RegisterFailedLogin(endpointAddressHash)) { 93 WriteLine ("Password incorrect, please enter password:"); 94 } else { 95 WriteLine ("Too many failed login attempts!"); 96 Thread.Sleep(100); 103 if (line.ToLower ().Equals ("exit")) { 104 Log.Out ("Telnet connection closed by client: " + endpoint); 97 105 Close (); 98 Log.Out ("Telnet connection closed for too many login attempts: " + endpoint);99 106 break; 100 107 } 108 Log.Out ("Telnet executed \"" + line + "\" from: " + endpoint); 109 ConsoleOutputSeparator.QueueNetCommand (line, this); 101 110 } 102 } else {103 if (line.ToLower ().Equals ("exit")) {104 Log.Out ("Telnet connection closed by client: " + endpoint);105 Close ();106 break;107 }108 Log.Out ("Telnet executed \"" + line + "\" from: " + endpoint);109 ConsoleOutputSeparator.QueueNetCommand (line, this);110 111 } 111 112 } -
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs
r154 r189 30 30 byte[] content; 31 31 if (cache) { 32 Monitor.Enter (fileCache); 33 try { 32 lock (fileCache) { 34 33 if (!fileCache.ContainsKey (fn)) { 35 34 if (!File.Exists (datapath + "/" + fn)) { … … 41 40 42 41 content = fileCache [fn]; 43 } finally {44 Monitor.Exit (fileCache);45 42 } 46 43 } else { … … 55 52 resp.ContentLength64 = content.Length; 56 53 resp.OutputStream.Write (content, 0, content.Length); 57 } catch (FileNotFoundException e) {54 } catch (FileNotFoundException) { 58 55 resp.StatusCode = (int)HttpStatusCode.NotFound; 59 56 if (logMissingFiles) -
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r163 r189 27 27 private void ProcessInv (List<InvItem> target, InventoryField[] sourceFields) 28 28 { 29 Monitor.Enter (target); 30 try { 29 lock (target) { 31 30 target.Clear (); 32 31 for (int i = 0; i < sourceFields.Length; i++) { … … 40 39 } 41 40 } 42 } finally {43 Monitor.Exit (target);44 41 } 45 42 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r159 r189 45 45 } 46 46 47 public Player GetPlayerByNameOrId (string _nameOrId, bool _ignoreColorCodes) 48 { 49 string sid = GetSteamID(_nameOrId, _ignoreColorCodes); 50 if (sid != null) 51 return this[sid]; 52 else 53 return null; 54 } 55 47 56 public string GetSteamID (string _nameOrId, bool _ignoreColorCodes) 48 57 {
Note:
See TracChangeset
for help on using the changeset viewer.