Changeset 325 for binary-improvements/7dtd-server-fixes/src
- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/API.cs
r324 r325 1 using System;2 1 using System.Collections.Generic; 3 2 4 namespace AllocsFixes 5 { 3 namespace AllocsFixes { 6 4 public class API : IModApi { 5 public void InitMod () { 6 ModEvents.GameAwake.RegisterHandler (GameAwake); 7 ModEvents.GameShutdown.RegisterHandler (GameShutdown); 8 ModEvents.SavePlayerData.RegisterHandler (SavePlayerData); 9 ModEvents.PlayerSpawning.RegisterHandler (PlayerSpawning); 10 ModEvents.PlayerDisconnected.RegisterHandler (PlayerDisconnected); 11 ModEvents.ChatMessage.RegisterHandler (ChatMessage); 12 } 7 13 8 14 public void GameAwake () { … … 13 19 StateManager.Shutdown (); 14 20 } 15 21 16 22 public void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 17 23 PlayerDataStuff.GM_SavePlayerData (_cInfo, _playerDataFile); … … 21 27 AllocsLogFunctions.RequestToSpawnPlayer (_cInfo, _chunkViewDim, _playerProfile); 22 28 } 23 29 24 30 public void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) { 25 31 AllocsLogFunctions.PlayerDisconnected (_cInfo, _bShutdown); 26 32 } 27 33 28 public bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName, bool _localizeMain, List<int> _recipientEntityIds) { 34 public bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName, 35 bool _localizeMain, List<int> _recipientEntityIds) { 29 36 return ChatHookExample.Hook (_cInfo, _type, _msg, _mainName); 30 }31 32 public void InitMod () {33 ModEvents.GameAwake.RegisterHandler (GameAwake);34 ModEvents.GameShutdown.RegisterHandler (GameShutdown);35 ModEvents.SavePlayerData.RegisterHandler (SavePlayerData);36 ModEvents.PlayerSpawning.RegisterHandler (PlayerSpawning);37 ModEvents.PlayerDisconnected.RegisterHandler (PlayerDisconnected);38 ModEvents.ChatMessage.RegisterHandler (ChatMessage);39 37 } 40 38 } 41 39 } 42 -
binary-improvements/7dtd-server-fixes/src/AllocsLogFunctions.cs
r273 r325 1 using System; 1 2 using AllocsFixes.PersistentData; 2 using System;3 using System.Collections.Generic;4 using UnityEngine;5 3 6 namespace AllocsFixes 7 { 8 public class AllocsLogFunctions 9 { 10 public static void RequestToSpawnPlayer (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) 11 { 4 namespace AllocsFixes { 5 public class AllocsLogFunctions { 6 public static void RequestToSpawnPlayer (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) { 12 7 try { 13 8 Log.Out ("Player connected" + 14 15 16 17 18 9 ", entityid=" + _cInfo.entityId + 10 ", name=" + _cInfo.playerName + 11 ", steamid=" + _cInfo.playerId + 12 ", steamOwner=" + _cInfo.ownerId + 13 ", ip=" + _cInfo.ip 19 14 ); 20 15 21 16 PersistentContainer.Instance.Players [_cInfo.playerId, true].SetOnline (_cInfo); 22 Persistent Data.PersistentContainer.Instance.Save ();17 PersistentContainer.Instance.Save (); 23 18 } catch (Exception e) { 24 19 Log.Out ("Error in AllocsLogFunctions.RequestToSpawnPlayer: " + e); … … 26 21 } 27 22 28 public static void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) 29 { 23 public static void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) { 30 24 try { 31 25 Player p = PersistentContainer.Instance.Players [_cInfo.playerId, true]; … … 35 29 Log.Out ("Disconnected player not found in client list..."); 36 30 } 37 PersistentData.PersistentContainer.Instance.Save (); 31 32 PersistentContainer.Instance.Save (); 38 33 } catch (Exception e) { 39 34 Log.Out ("Error in AllocsLogFunctions.PlayerDisconnected: " + e); -
binary-improvements/7dtd-server-fixes/src/AllocsUtils.cs
r253 r325 1 using System;1 using UnityEngine; 2 2 3 namespace AllocsFixes 4 { 3 namespace AllocsFixes { 5 4 public static class AllocsUtils { 6 7 public static string ColorToHex (UnityEngine.Color _color) {8 return string.Format ("{0:X02}{1:X02}{2:X02}", (int)(_color.r * 255), (int)(_color.g * 255), (int)(_color.b * 255));5 public static string ColorToHex (Color _color) { 6 return string.Format ("{0:X02}{1:X02}{2:X02}", (int) (_color.r * 255), (int) (_color.g * 255), 7 (int) (_color.b * 255)); 9 8 } 10 11 9 } 12 10 } 13 -
binary-improvements/7dtd-server-fixes/src/AssemblyInfo.cs
r244 r325 1 1 using System.Reflection; 2 using System.Runtime.CompilerServices;3 2 4 3 // Information about this assembly is defined by the following attributes. 5 4 // Change them to the values specific to your project. 6 5 7 [assembly: AssemblyTitle ("7dtd-server-fixes")]8 [assembly: AssemblyDescription ("")]9 [assembly: AssemblyConfiguration ("")]10 [assembly: AssemblyCompany ("")]11 [assembly: AssemblyProduct ("")]12 [assembly: AssemblyCopyright ("Alloc")]13 [assembly: AssemblyTrademark ("")]14 [assembly: AssemblyCulture ("")]6 [assembly: AssemblyTitle ("7dtd-server-fixes")] 7 [assembly: AssemblyDescription ("")] 8 [assembly: AssemblyConfiguration ("")] 9 [assembly: AssemblyCompany ("")] 10 [assembly: AssemblyProduct ("")] 11 [assembly: AssemblyCopyright ("Alloc")] 12 [assembly: AssemblyTrademark ("")] 13 [assembly: AssemblyCulture ("")] 15 14 16 15 // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". … … 18 17 // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 18 20 [assembly: AssemblyVersion ("0.0.0.0")]19 [assembly: AssemblyVersion ("0.0.0.0")] 21 20 22 21 // The following attributes are used to specify the signing key for the assembly, … … 25 24 //[assembly: AssemblyDelaySign(false)] 26 25 //[assembly: AssemblyKeyFile("")] 27 -
binary-improvements/7dtd-server-fixes/src/BlockingQueue.cs
r190 r325 1 using System;2 1 using System.Collections.Generic; 3 2 using System.Threading; 4 3 5 namespace AllocsFixes 6 { 7 public class BlockingQueue<T> 8 { 9 private bool closing = false; 10 private Queue<T> queue = new Queue<T> (); 4 namespace AllocsFixes { 5 public class BlockingQueue<T> { 6 private readonly Queue<T> queue = new Queue<T> (); 7 private bool closing; 11 8 12 public void Enqueue (T item) 13 { 9 public void Enqueue (T item) { 14 10 lock (queue) { 15 11 queue.Enqueue (item); … … 18 14 } 19 15 20 public T Dequeue () 21 { 16 public T Dequeue () { 22 17 lock (queue) { 23 18 while (queue.Count == 0) { 24 19 if (closing) { 25 return default (T);20 return default (T); 26 21 } 22 27 23 Monitor.Wait (queue); 28 24 } 25 29 26 return queue.Dequeue (); 30 27 } 31 28 } 32 29 33 public void Close () 34 { 30 public void Close () { 35 31 lock (queue) { 36 32 closing = true; … … 38 34 } 39 35 } 40 41 36 } 42 37 } 43 -
binary-improvements/7dtd-server-fixes/src/ChatHookExample.cs
r324 r325 1 using System; 2 3 namespace AllocsFixes 4 { 1 namespace AllocsFixes { 5 2 public class ChatHookExample { 6 private const string ANSWER = " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]"; 3 private const string ANSWER = 4 " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]"; 7 5 8 6 public static bool Hook (ClientInfo _cInfo, EChatType _type, string _message, string _playerName) { … … 11 9 if (_cInfo != null) { 12 10 Log.Out ("Sent chat hook reply to {0}", _cInfo.playerId); 13 _cInfo.SendPackage (new NetPackageChat (EChatType.Whisper, -1, ANSWER, "", false, null));11 _cInfo.SendPackage (new NetPackageChat (EChatType.Whisper, -1, ANSWER, "", false, null)); 14 12 } else { 15 13 Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _message); 16 14 } 15 17 16 return false; 18 17 } … … 21 20 return true; 22 21 } 23 24 22 } 25 23 } -
binary-improvements/7dtd-server-fixes/src/FileCache/AbstractCache.cs
r324 r325 1 1 namespace AllocsFixes.FileCache { 2 public abstract class AbstractCache { 3 public AbstractCache () { 4 } 5 6 public abstract byte[] GetFileContent (string filename); 7 } 2 public abstract class AbstractCache { 3 public abstract byte[] GetFileContent (string filename); 4 } 8 5 } -
binary-improvements/7dtd-server-fixes/src/FileCache/DirectAccess.cs
r199 r325 1 1 using System; 2 using System.Collections.Generic;3 2 using System.IO; 4 3 5 namespace AllocsFixes.FileCache 6 { 4 namespace AllocsFixes.FileCache { 7 5 // Not caching at all, simply reading from disk on each request 8 public class DirectAccess : AbstractCache 9 { 10 11 public DirectAccess () 12 { 13 } 14 15 public override byte[] GetFileContent (string filename) 16 { 6 public class DirectAccess : AbstractCache { 7 public override byte[] GetFileContent (string filename) { 17 8 try { 18 9 if (!File.Exists (filename)) { … … 24 15 Log.Out ("Error in DirectAccess.GetFileContent: " + e); 25 16 } 17 26 18 return null; 27 19 } 28 29 20 } 30 21 } 31 -
binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r324 r325 2 2 using System.IO; 3 3 using UnityEngine; 4 using Object = UnityEngine.Object; 4 5 5 namespace AllocsFixes.FileCache 6 { 6 namespace AllocsFixes.FileCache { 7 7 // Special "cache" for map tile folder as both map rendering and webserver access files in there. 8 8 // Only map rendering tiles are cached. Writing is done by WriteThrough. 9 public class MapTileCache : AbstractCache 10 { 11 private struct CurrentZoomFile 12 { 13 public string filename; 14 public byte[] data; 15 } 16 9 public class MapTileCache : AbstractCache { 10 private readonly byte[] transparentTile; 17 11 private CurrentZoomFile[] cache; 18 12 19 private byte[] transparentTile; 20 21 public MapTileCache (int _tileSize) 22 { 13 public MapTileCache (int _tileSize) { 23 14 Texture2D tex = new Texture2D (_tileSize, _tileSize); 24 15 Color nullColor = new Color (0, 0, 0, 0); … … 28 19 } 29 20 } 21 30 22 transparentTile = tex.EncodeToPNG (); 31 UnityEngine.Object.Destroy (tex);23 Object.Destroy (tex); 32 24 } 33 25 34 public void SetZoomCount (int count) 35 { 26 public void SetZoomCount (int count) { 36 27 cache = new CurrentZoomFile[count]; 37 28 } 38 29 39 public byte[] LoadTile (int zoomlevel, string filename) 40 { 30 public byte[] LoadTile (int zoomlevel, string filename) { 41 31 try { 42 32 lock (cache) { … … 51 41 cache [zoomlevel].data = File.ReadAllBytes (filename); 52 42 } 43 53 44 return cache [zoomlevel].data; 54 45 } … … 56 47 Log.Out ("Error in MapTileCache.LoadTile: " + e); 57 48 } 49 58 50 return null; 59 51 } 60 52 61 public void SaveTile (int zoomlevel, byte[] content) 62 { 53 public void SaveTile (int zoomlevel, byte[] content) { 63 54 try { 64 55 lock (cache) { … … 73 64 } 74 65 75 public override byte[] GetFileContent (string filename) 76 { 66 public override byte[] GetFileContent (string filename) { 77 67 try { 78 68 lock (cache) { 79 69 foreach (CurrentZoomFile czf in cache) { 80 if (czf.filename != null && czf.filename.Equals (filename)) 70 if (czf.filename != null && czf.filename.Equals (filename)) { 81 71 return czf.data; 72 } 82 73 } 83 74 … … 85 76 return transparentTile; 86 77 } 78 87 79 return File.ReadAllBytes (filename); 88 80 } … … 90 82 Log.Out ("Error in MapTileCache.GetFileContent: " + e); 91 83 } 84 92 85 return null; 93 86 } 94 87 88 private struct CurrentZoomFile { 89 public string filename; 90 public byte[] data; 91 } 95 92 } 96 93 } 97 -
binary-improvements/7dtd-server-fixes/src/FileCache/SimpleCache.cs
r199 r325 3 3 using System.IO; 4 4 5 namespace AllocsFixes.FileCache 6 { 5 namespace AllocsFixes.FileCache { 7 6 // Caching all files, useful for completely static folders only 8 public class SimpleCache : AbstractCache 9 {7 public class SimpleCache : AbstractCache { 8 private readonly Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> (); 10 9 11 private Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> (); 12 13 public SimpleCache () 14 { 15 } 16 17 public override byte[] GetFileContent (string filename) 18 { 10 public override byte[] GetFileContent (string filename) { 19 11 try { 20 12 lock (fileCache) { … … 32 24 Log.Out ("Error in SimpleCache.GetFileContent: " + e); 33 25 } 26 34 27 return null; 35 28 } 36 37 29 } 38 30 } 39 -
binary-improvements/7dtd-server-fixes/src/JSON/JSONArray.cs
r315 r325 1 using System;2 1 using System.Collections.Generic; 3 2 using System.Text; 4 3 5 namespace AllocsFixes.JSON 6 { 7 public class JSONArray : JSONNode 8 { 9 private List<JSONNode> nodes = new List<JSONNode> (); 4 namespace AllocsFixes.JSON { 5 public class JSONArray : JSONNode { 6 private readonly List<JSONNode> nodes = new List<JSONNode> (); 10 7 11 8 public JSONNode this [int index] { … … 18 15 } 19 16 20 public void Add (JSONNode node) 21 { 17 public void Add (JSONNode node) { 22 18 nodes.Add (node); 23 19 } 24 20 25 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) 26 { 21 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) { 27 22 stringBuilder.Append ("["); 28 if (prettyPrint) 23 if (prettyPrint) { 29 24 stringBuilder.Append ('\n'); 25 } 26 30 27 foreach (JSONNode n in nodes) { 31 if (prettyPrint) 32 stringBuilder.Append (new String ('\t', currentLevel + 1)); 28 if (prettyPrint) { 29 stringBuilder.Append (new string ('\t', currentLevel + 1)); 30 } 31 33 32 n.ToString (stringBuilder, prettyPrint, currentLevel + 1); 34 33 stringBuilder.Append (","); 35 if (prettyPrint) 34 if (prettyPrint) { 36 35 stringBuilder.Append ('\n'); 36 } 37 37 } 38 if (nodes.Count > 0) 38 39 if (nodes.Count > 0) { 39 40 stringBuilder.Remove (stringBuilder.Length - (prettyPrint ? 2 : 1), 1); 40 if (prettyPrint) 41 stringBuilder.Append (new String ('\t', currentLevel)); 41 } 42 43 if (prettyPrint) { 44 stringBuilder.Append (new string ('\t', currentLevel)); 45 } 46 42 47 stringBuilder.Append ("]"); 43 48 } 44 49 45 public static JSONArray Parse (string json, ref int offset) 46 { 50 public static JSONArray Parse (string json, ref int offset) { 47 51 //Log.Out ("ParseArray enter (" + offset + ")"); 48 52 JSONArray arr = new JSONArray (); … … 58 62 nextElemAllowed = true; 59 63 offset++; 60 } else 61 throw new MalformedJSONException ("Could not parse array, found a comma without a value first"); 64 } else { 65 throw new MalformedJSONException ( 66 "Could not parse array, found a comma without a value first"); 67 } 68 62 69 break; 63 70 case ']': 64 71 offset++; 72 65 73 //Log.Out ("JSON:Parsed Array: " + arr.ToString ()); 66 74 return arr; … … 72 80 } 73 81 } 74 75 82 } 76 83 } 77 -
binary-improvements/7dtd-server-fixes/src/JSON/JSONBoolean.cs
r309 r325 1 using System;2 1 using System.Text; 3 2 4 namespace AllocsFixes.JSON 5 { 6 public class JSONBoolean : JSONValue 7 { 8 private bool value; 3 namespace AllocsFixes.JSON { 4 public class JSONBoolean : JSONValue { 5 private readonly bool value; 9 6 10 public JSONBoolean (bool value) 11 { 7 public JSONBoolean (bool value) { 12 8 this.value = value; 13 9 } 14 10 15 public bool GetBool () 16 { 11 public bool GetBool () { 17 12 return value; 18 13 } 19 14 20 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) 21 { 15 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) { 22 16 stringBuilder.Append (value ? "true" : "false"); 23 17 } 24 18 25 public static JSONBoolean Parse (string json, ref int offset) 26 { 19 public static JSONBoolean Parse (string json, ref int offset) { 27 20 //Log.Out ("ParseBool enter (" + offset + ")"); 28 21 … … 31 24 offset += 4; 32 25 return new JSONBoolean (true); 33 } else if (json.Substring (offset, 5).Equals ("false")) { 26 } 27 28 if (json.Substring (offset, 5).Equals ("false")) { 34 29 //Log.Out ("JSON:Parsed Bool: false"); 35 30 offset += 5; 36 31 return new JSONBoolean (false); 37 } else {38 throw new MalformedJSONException ("No valid boolean found");39 32 } 33 34 throw new MalformedJSONException ("No valid boolean found"); 40 35 } 41 42 36 } 43 37 } 44 -
binary-improvements/7dtd-server-fixes/src/JSON/JSONNode.cs
r309 r325 1 using System;2 1 using System.Text; 3 2 4 namespace AllocsFixes.JSON 5 { 6 public abstract class JSONNode 7 { 8 public abstract void ToString(StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0); 3 namespace AllocsFixes.JSON { 4 public abstract class JSONNode { 5 public abstract void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0); 9 6 10 7 public override string ToString () { -
binary-improvements/7dtd-server-fixes/src/JSON/JSONNull.cs
r309 r325 1 using System;2 1 using System.Text; 3 2 4 namespace AllocsFixes.JSON 5 { 6 public class JSONNull : JSONValue 7 { 8 public JSONNull () 9 { 10 } 11 12 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) 13 { 3 namespace AllocsFixes.JSON { 4 public class JSONNull : JSONValue { 5 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) { 14 6 stringBuilder.Append ("null"); 15 7 } 16 8 17 public static JSONNull Parse (string json, ref int offset) 18 { 9 public static JSONNull Parse (string json, ref int offset) { 19 10 //Log.Out ("ParseNull enter (" + offset + ")"); 20 11 … … 23 14 offset += 4; 24 15 return new JSONNull (); 25 } else {26 throw new MalformedJSONException ("No valid null value found");27 16 } 17 18 throw new MalformedJSONException ("No valid null value found"); 28 19 } 29 30 20 } 31 21 } 32 -
binary-improvements/7dtd-server-fixes/src/JSON/JSONNumber.cs
r324 r325 2 2 using System.Text; 3 3 4 namespace AllocsFixes.JSON 5 { 6 public class JSONNumber : JSONValue 7 { 8 private double value; 4 namespace AllocsFixes.JSON { 5 public class JSONNumber : JSONValue { 6 private readonly double value; 9 7 10 public JSONNumber (double value) 11 { 8 public JSONNumber (double value) { 12 9 this.value = value; 13 10 } 14 11 15 public double GetDouble () 16 { 12 public double GetDouble () { 17 13 return value; 18 14 } 19 15 20 public int GetInt () 21 { 22 return (int)Math.Round(value); 16 public int GetInt () { 17 return (int) Math.Round (value); 23 18 } 24 19 25 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) 26 { 20 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) { 27 21 stringBuilder.Append (value.ToCultureInvariantString ()); 28 22 } 29 23 30 public static JSONNumber Parse (string json, ref int offset) 31 { 24 public static JSONNumber Parse (string json, ref int offset) { 32 25 //Log.Out ("ParseNumber enter (" + offset + ")"); 33 26 StringBuilder sbNum = new StringBuilder (); … … 37 30 while (offset < json.Length) { 38 31 if (json [offset] >= '0' && json [offset] <= '9') { 39 if (hasExp) 32 if (hasExp) { 40 33 sbExp.Append (json [offset]); 41 else34 } else { 42 35 sbNum.Append (json [offset]); 36 } 43 37 } else if (json [offset] == '.') { 44 38 if (hasExp) { 45 39 throw new MalformedJSONException ("Decimal separator in exponent"); 40 } 41 42 if (hasDec) { 43 throw new MalformedJSONException ("Multiple decimal separators in number found"); 44 } 45 46 if (sbNum.Length == 0) { 47 throw new MalformedJSONException ("No leading digits before decimal separator found"); 48 } 49 50 sbNum.Append ('.'); 51 hasDec = true; 52 } else if (json [offset] == '-') { 53 if (hasExp) { 54 if (sbExp.Length > 0) { 55 throw new MalformedJSONException ("Negative sign in exponent after digits"); 56 } 57 58 sbExp.Append (json [offset]); 46 59 } else { 47 if (hasDec) 48 throw new MalformedJSONException ("Multiple decimal separators in number found"); 49 else if (sbNum.Length == 0) { 50 throw new MalformedJSONException ("No leading digits before decimal separator found"); 51 } else { 52 sbNum.Append ('.'); 53 hasDec = true; 60 if (sbNum.Length > 0) { 61 throw new MalformedJSONException ("Negative sign in mantissa after digits"); 54 62 } 55 } 56 } else if (json [offset] == '-') { 57 if (hasExp) { 58 if (sbExp.Length > 0) 59 throw new MalformedJSONException ("Negative sign in exponent after digits"); 60 else 61 sbExp.Append (json [offset]); 62 } else { 63 if (sbNum.Length > 0) 64 throw new MalformedJSONException ("Negative sign in mantissa after digits"); 65 else 66 sbNum.Append (json [offset]); 63 64 sbNum.Append (json [offset]); 67 65 } 68 66 } else if (json [offset] == 'e' || json [offset] == 'E') { 69 if (hasExp) 67 if (hasExp) { 70 68 throw new MalformedJSONException ("Multiple exponential markers in number found"); 71 else if (sbNum.Length == 0) { 69 } 70 71 if (sbNum.Length == 0) { 72 72 throw new MalformedJSONException ("No leading digits before exponential marker found"); 73 } else {74 sbExp = new StringBuilder ();75 hasExp = true;76 73 } 74 75 sbExp = new StringBuilder (); 76 hasExp = true; 77 77 } else if (json [offset] == '+') { 78 78 if (hasExp) { 79 if (sbExp.Length > 0) 79 if (sbExp.Length > 0) { 80 80 throw new MalformedJSONException ("Positive sign in exponent after digits"); 81 else 82 sbExp.Append (json [offset]); 81 } 82 83 sbExp.Append (json [offset]); 83 84 } else { 84 85 throw new MalformedJSONException ("Positive sign in mantissa found"); … … 86 87 } else { 87 88 double number; 88 if (!StringParsers.TryParseDouble (sbNum.ToString (), out number)) {89 throw new MalformedJSONException ("Mantissa is not a valid decimal (\"" + sbNum .ToString ()+ "\")");89 if (!StringParsers.TryParseDouble (sbNum.ToString (), out number)) { 90 throw new MalformedJSONException ("Mantissa is not a valid decimal (\"" + sbNum + "\")"); 90 91 } 91 92 … … 93 94 int exp; 94 95 if (!int.TryParse (sbExp.ToString (), out exp)) { 95 throw new MalformedJSONException ("Exponent is not a valid integer (\"" + sbExp .ToString ()+ "\")");96 throw new MalformedJSONException ("Exponent is not a valid integer (\"" + sbExp + "\")"); 96 97 } 97 98 … … 102 103 return new JSONNumber (number); 103 104 } 105 104 106 offset++; 105 107 } 108 106 109 throw new MalformedJSONException ("End of JSON reached before parsing number finished"); 107 110 } 108 109 111 } 110 112 } 111 -
binary-improvements/7dtd-server-fixes/src/JSON/JSONObject.cs
r315 r325 1 using System;2 1 using System.Collections.Generic; 3 2 using System.Text; 4 3 5 namespace AllocsFixes.JSON 6 { 7 public class JSONObject : JSONNode 8 { 9 private Dictionary<string, JSONNode> nodes = new Dictionary<string, JSONNode> (); 4 namespace AllocsFixes.JSON { 5 public class JSONObject : JSONNode { 6 private readonly Dictionary<string, JSONNode> nodes = new Dictionary<string, JSONNode> (); 10 7 11 8 public JSONNode this [string name] { … … 22 19 } 23 20 24 public bool ContainsKey (string name) 25 { 21 public bool ContainsKey (string name) { 26 22 return nodes.ContainsKey (name); 27 23 } 28 24 29 public void Add (string name, JSONNode node) 30 { 25 public void Add (string name, JSONNode node) { 31 26 nodes.Add (name, node); 32 27 } 33 28 34 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) 35 { 29 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) { 36 30 stringBuilder.Append ("{"); 37 if (prettyPrint) 31 if (prettyPrint) { 38 32 stringBuilder.Append ('\n'); 33 } 34 39 35 foreach (KeyValuePair<string, JSONNode> kvp in nodes) { 40 if (prettyPrint) 41 stringBuilder.Append (new String ('\t', currentLevel + 1)); 42 stringBuilder.Append (String.Format ("\"{0}\":", kvp.Key)); 43 if (prettyPrint) 36 if (prettyPrint) { 37 stringBuilder.Append (new string ('\t', currentLevel + 1)); 38 } 39 40 stringBuilder.Append (string.Format ("\"{0}\":", kvp.Key)); 41 if (prettyPrint) { 44 42 stringBuilder.Append (" "); 43 } 44 45 45 kvp.Value.ToString (stringBuilder, prettyPrint, currentLevel + 1); 46 46 stringBuilder.Append (","); 47 if (prettyPrint) 47 if (prettyPrint) { 48 48 stringBuilder.Append ('\n'); 49 } 49 50 } 50 if (nodes.Count > 0) 51 52 if (nodes.Count > 0) { 51 53 stringBuilder.Remove (stringBuilder.Length - (prettyPrint ? 2 : 1), 1); 52 if (prettyPrint) 53 stringBuilder.Append (new String ('\t', currentLevel)); 54 } 55 56 if (prettyPrint) { 57 stringBuilder.Append (new string ('\t', currentLevel)); 58 } 59 54 60 stringBuilder.Append ("}"); 55 61 } 56 62 57 public static JSONObject Parse (string json, ref int offset) 58 { 63 public static JSONObject Parse (string json, ref int offset) { 59 64 //Log.Out ("ParseObject enter (" + offset + ")"); 60 65 JSONObject obj = new JSONObject (); … … 70 75 Parser.SkipWhitespace (json, ref offset); 71 76 if (json [offset] != ':') { 72 throw new MalformedJSONException ("Could not parse object, missing colon (\":\") after key"); 77 throw new MalformedJSONException ( 78 "Could not parse object, missing colon (\":\") after key"); 73 79 } 80 74 81 offset++; 75 82 JSONNode val = Parser.ParseInternal (json, ref offset); … … 77 84 nextElemAllowed = false; 78 85 } else { 79 throw new MalformedJSONException ("Could not parse object, found new key without a separating comma"); 86 throw new MalformedJSONException ( 87 "Could not parse object, found new key without a separating comma"); 80 88 } 89 81 90 break; 82 91 case ',': … … 84 93 nextElemAllowed = true; 85 94 offset++; 86 } else 87 throw new MalformedJSONException ("Could not parse object, found a comma without a key/value pair first"); 95 } else { 96 throw new MalformedJSONException ( 97 "Could not parse object, found a comma without a key/value pair first"); 98 } 99 88 100 break; 89 101 case '}': 90 102 offset++; 103 91 104 //Log.Out ("JSON:Parsed Object: " + obj.ToString ()); 92 105 return obj; … … 94 107 } 95 108 } 96 97 109 } 98 110 } 99 -
binary-improvements/7dtd-server-fixes/src/JSON/JSONString.cs
r309 r325 1 using System;2 1 using System.Text; 3 2 4 namespace AllocsFixes.JSON 5 { 6 public class JSONString : JSONValue 7 { 8 private string value; 3 namespace AllocsFixes.JSON { 4 public class JSONString : JSONValue { 5 private readonly string value; 9 6 10 public JSONString (string value) 11 { 7 public JSONString (string value) { 12 8 this.value = value; 13 9 } 14 10 15 public string GetString () 16 { 11 public string GetString () { 17 12 return value; 18 13 } 19 14 20 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) 21 { 15 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) { 22 16 if (value == null || value.Length == 0) { 23 17 stringBuilder.Append ("\"\""); … … 27 21 int len = value.Length; 28 22 29 stringBuilder.EnsureCapacity (stringBuilder.Length + 2*len); 30 String t; 23 stringBuilder.EnsureCapacity (stringBuilder.Length + 2 * len); 31 24 32 25 stringBuilder.Append ('"'); … … 36 29 case '\\': 37 30 case '"': 31 38 32 // case '/': 39 33 stringBuilder.Append ('\\'); … … 58 52 if (c < ' ') { 59 53 stringBuilder.Append ("\\u"); 60 stringBuilder.Append (((int) c).ToString ("X4"));54 stringBuilder.Append (((int) c).ToString ("X4")); 61 55 } else { 62 56 stringBuilder.Append (c); 63 57 } 58 64 59 break; 65 60 } … … 69 64 } 70 65 71 public static JSONString Parse (string json, ref int offset) 72 { 66 public static JSONString Parse (string json, ref int offset) { 73 67 //Log.Out ("ParseString enter (" + offset + ")"); 74 68 StringBuilder sb = new StringBuilder (); … … 103 97 break; 104 98 } 99 105 100 offset++; 106 101 break; 107 102 case '"': 108 103 offset++; 104 109 105 //Log.Out ("JSON:Parsed String: " + sb.ToString ()); 110 106 return new JSONString (sb.ToString ()); … … 115 111 } 116 112 } 113 117 114 throw new MalformedJSONException ("End of JSON reached before parsing string finished"); 118 115 } 119 120 116 } 121 117 } 122 -
binary-improvements/7dtd-server-fixes/src/JSON/JSONValue.cs
r279 r325 1 using System; 2 3 namespace AllocsFixes.JSON 4 { 1 namespace AllocsFixes.JSON { 5 2 public abstract class JSONValue : JSONNode { 6 3 } 7 4 } 8 -
binary-improvements/7dtd-server-fixes/src/JSON/MalformedJSONException.cs
r188 r325 2 2 using System.Runtime.Serialization; 3 3 4 namespace AllocsFixes.JSON 5 { 6 public class MalformedJSONException : ApplicationException 7 { 8 public MalformedJSONException () 9 { 4 namespace AllocsFixes.JSON { 5 public class MalformedJSONException : ApplicationException { 6 public MalformedJSONException () { 10 7 } 11 8 12 public MalformedJSONException (string message) : base(message) 13 { 9 public MalformedJSONException (string message) : base (message) { 14 10 } 15 11 16 public MalformedJSONException (string message, System.Exception inner) : base(message, inner) 17 { 12 public MalformedJSONException (string message, Exception inner) : base (message, inner) { 18 13 } 19 20 protected MalformedJSONException (SerializationInfo info, StreamingContext context) : base(info, context) 21 { 14 15 protected MalformedJSONException (SerializationInfo info, StreamingContext context) : base (info, context) { 22 16 } 23 17 } 24 18 } 25 -
binary-improvements/7dtd-server-fixes/src/JSON/Parser.cs
r188 r325 1 using System; 2 using System.Text; 3 4 namespace AllocsFixes.JSON 5 { 6 public class Parser 7 { 8 9 public static JSONNode Parse (string json) 10 { 1 namespace AllocsFixes.JSON { 2 public class Parser { 3 public static JSONNode Parse (string json) { 11 4 int offset = 0; 12 5 return ParseInternal (json, ref offset); 13 6 } 14 7 15 public static JSONNode ParseInternal (string json, ref int offset) 16 { 8 public static JSONNode ParseInternal (string json, ref int offset) { 17 9 SkipWhitespace (json, ref offset); 10 18 11 //Log.Out ("ParseInternal (" + offset + "): Decide on: '" + json [offset] + "'"); 19 12 switch (json [offset]) { … … 34 27 } 35 28 36 public static void SkipWhitespace (string json, ref int offset) 37 { 29 public static void SkipWhitespace (string json, ref int offset) { 38 30 //Log.Out ("SkipWhitespace (" + offset + "): '" + json [offset] + "'"); 39 31 while (offset < json.Length) { … … 49 41 } 50 42 } 43 51 44 throw new MalformedJSONException ("End of JSON reached before parsing finished"); 52 45 } 53 54 55 46 } 56 47 } 57 -
binary-improvements/7dtd-server-fixes/src/LandClaimList.cs
r253 r325 1 1 using System; 2 2 using System.Collections.Generic; 3 4 3 using AllocsFixes.PersistentData; 5 4 6 namespace AllocsFixes 7 { 5 namespace AllocsFixes { 8 6 public class LandClaimList { 9 7 public delegate bool OwnerFilter (Player owner); … … 11 9 public delegate bool PositionFilter (Vector3i position); 12 10 13 public static Dictionary<Player, List<Vector3i>> GetLandClaims (OwnerFilter[] _ownerFilters, PositionFilter[] _positionFilters) { 11 public static Dictionary<Player, List<Vector3i>> GetLandClaims (OwnerFilter[] _ownerFilters, 12 PositionFilter[] _positionFilters) { 14 13 Dictionary<Vector3i, PersistentPlayerData> d = GameManager.Instance.GetPersistentPlayerList ().m_lpBlockMap; 15 14 Dictionary<Player, List<Vector3i>> result = new Dictionary<Player, List<Vector3i>> (); 16 15 17 16 if (d != null) { 18 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> (); 17 Dictionary<PersistentPlayerData, List<Vector3i>> owners = 18 new Dictionary<PersistentPlayerData, List<Vector3i>> (); 19 19 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) { 20 20 bool allowed = true; … … 27 27 } 28 28 } 29 29 30 if (allowed) { 30 31 if (!owners.ContainsKey (kvp.Value)) { 31 32 owners.Add (kvp.Value, new List<Vector3i> ()); 32 33 } 34 33 35 owners [kvp.Value].Add (kvp.Key); 34 36 } … … 36 38 37 39 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 38 Player p = Persistent Data.PersistentContainer.Instance.Players [kvp.Key.PlayerId, false];40 Player p = PersistentContainer.Instance.Players [kvp.Key.PlayerId, false]; 39 41 if (p == null) { 40 42 p = new Player (kvp.Key.PlayerId); … … 59 61 } 60 62 } 63 61 64 return result; 62 65 } … … 73 76 return p => _f1 (p) || _f2 (p); 74 77 } 75 76 78 } 77 79 } 78 -
binary-improvements/7dtd-server-fixes/src/LiveData/Animals.cs
r312 r325 1 using System; 2 using System.Collections.Generic; 3 4 namespace AllocsFixes.LiveData 5 { 6 public class Animals : EntityFilterList<EntityAnimal> 7 { 8 1 namespace AllocsFixes.LiveData { 2 public class Animals : EntityFilterList<EntityAnimal> { 9 3 public static readonly Animals Instance = new Animals (); 10 4 11 5 protected override EntityAnimal predicate (Entity _e) { 12 6 if (_e is EntityAnimal) { 13 EntityAnimal ea = (EntityAnimal) _e;7 EntityAnimal ea = (EntityAnimal) _e; 14 8 15 9 if (ea.IsAlive ()) { … … 17 11 } 18 12 } 13 19 14 return null; 20 15 } 21 22 } 16 } 23 17 } 24 -
binary-improvements/7dtd-server-fixes/src/LiveData/EntityFilterList.cs
r312 r325 2 2 using System.Collections.Generic; 3 3 4 namespace AllocsFixes.LiveData 5 { 6 public abstract class EntityFilterList<T> where T: Entity 7 { 4 namespace AllocsFixes.LiveData { 5 public abstract class EntityFilterList<T> where T : Entity { 8 6 public void Get (List<T> _list) { 9 7 _list.Clear (); … … 18 16 } 19 17 } 20 } 21 catch (Exception e) { 18 } catch (Exception e) { 22 19 Log.Exception (e); 23 20 } … … 35 32 } 36 33 } 37 } 38 catch (Exception e) { 34 } catch (Exception e) { 39 35 Log.Exception (e); 40 36 } 37 41 38 return count; 42 39 } 43 40 44 41 protected abstract T predicate (Entity _e); 45 46 } 42 } 47 43 } 48 -
binary-improvements/7dtd-server-fixes/src/LiveData/Hostiles.cs
r312 r325 1 using System; 2 using System.Collections.Generic; 3 4 namespace AllocsFixes.LiveData 5 { 6 public class Hostiles : EntityFilterList<EntityEnemy> 7 { 8 1 namespace AllocsFixes.LiveData { 2 public class Hostiles : EntityFilterList<EntityEnemy> { 9 3 public static readonly Hostiles Instance = new Hostiles (); 10 4 11 override protectedEntityEnemy predicate (Entity _e) {5 protected override EntityEnemy predicate (Entity _e) { 12 6 if (_e is EntityEnemy) { 13 7 if (_e.IsAlive ()) { … … 15 9 } 16 10 } 11 17 12 return null; 18 13 } 19 20 14 } 21 15 } 22 -
binary-improvements/7dtd-server-fixes/src/PersistentData/Attributes.cs
r273 r325 1 1 using System; 2 using System.Collections.Generic;3 using System.Runtime.Serialization;4 using System.Text.RegularExpressions;5 2 6 namespace AllocsFixes.PersistentData 7 { 3 namespace AllocsFixes.PersistentData { 8 4 [Serializable] 9 public class Attributes 10 { 5 public class Attributes { 11 6 private bool hideChatCommands; 12 7 private String hideChatCommandPrefix; 13 8 14 9 public bool HideChatCommands { 15 get { 16 return hideChatCommands; 17 } 18 set { 19 hideChatCommands = value; 20 } 10 get { return hideChatCommands; } 11 set { hideChatCommands = value; } 21 12 } 22 13 … … 26 17 hideChatCommandPrefix = ""; 27 18 } 19 28 20 return hideChatCommandPrefix; 29 21 } 30 set { 31 hideChatCommandPrefix = value; 32 } 22 set { hideChatCommandPrefix = value; } 33 23 } 34 35 24 } 36 25 } 37 -
binary-improvements/7dtd-server-fixes/src/PersistentData/InvItem.cs
r287 r325 2 2 using System.Runtime.Serialization; 3 3 4 namespace AllocsFixes.PersistentData 5 { 4 namespace AllocsFixes.PersistentData { 6 5 [Serializable] 7 6 public class InvItem { … … 26 25 } 27 26 } 28 -
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r324 r325 3 3 4 4 namespace AllocsFixes.PersistentData { 5 6 7 8 9 5 [Serializable] 6 public class Inventory { 7 public List<InvItem> bag; 8 public List<InvItem> belt; 9 public InvItem[] equipment; 10 10 11 12 13 14 15 11 public Inventory () { 12 bag = new List<InvItem> (); 13 belt = new List<InvItem> (); 14 equipment = null; 15 } 16 16 17 18 19 20 21 22 23 24 17 public void Update (PlayerDataFile pdf) { 18 lock (this) { 19 //Log.Out ("Updating player inventory - player id: " + pdf.id); 20 ProcessInv (bag, pdf.bag, pdf.id); 21 ProcessInv (belt, pdf.inventory, pdf.id); 22 ProcessEqu (pdf.equipment, pdf.id); 23 } 24 } 25 25 26 27 28 29 30 31 32 26 private void ProcessInv (List<InvItem> target, ItemStack[] sourceFields, int id) { 27 target.Clear (); 28 for (int i = 0; i < sourceFields.Length; i++) { 29 InvItem item = CreateInvItem (sourceFields [i].itemValue, sourceFields [i].count, id); 30 if (item != null && sourceFields [i].itemValue.Modifications != null) { 31 ProcessParts (sourceFields [i].itemValue.Modifications, item, id); 32 } 33 33 34 35 36 34 target.Add (item); 35 } 36 } 37 37 38 39 40 41 42 43 38 private void ProcessEqu (Equipment sourceEquipment, int _playerId) { 39 equipment = new InvItem[sourceEquipment.GetSlotCount ()]; 40 for (int i = 0; i < sourceEquipment.GetSlotCount (); i++) { 41 equipment [i] = CreateInvItem (sourceEquipment.GetSlotItem (i), 1, _playerId); 42 } 43 } 44 44 45 46 47 48 49 50 51 45 private void ProcessParts (ItemValue[] _parts, InvItem _item, int _playerId) { 46 InvItem[] itemParts = new InvItem[_parts.Length]; 47 for (int i = 0; i < _parts.Length; i++) { 48 InvItem partItem = CreateInvItem (_parts [i], 1, _playerId); 49 if (partItem != null && _parts [i].Modifications != null) { 50 ProcessParts (_parts [i].Modifications, partItem, _playerId); 51 } 52 52 53 54 53 itemParts [i] = partItem; 54 } 55 55 56 57 56 _item.parts = itemParts; 57 } 58 58 59 60 61 62 63 59 private InvItem CreateInvItem (ItemValue _itemValue, int _count, int _playerId) { 60 if (_count > 0 && _itemValue != null && !_itemValue.Equals (ItemValue.None)) { 61 ItemClass itemClass = ItemClass.list [_itemValue.type]; 62 int maxAllowed = itemClass.Stacknumber.Value; 63 string name = itemClass.GetItemName (); 64 64 65 66 67 68 65 if (_count > maxAllowed) { 66 Log.Out ("Player with ID " + _playerId + " has stack for \"" + name + "\" greater than allowed (" + 67 _count + " > " + maxAllowed + ")"); 68 } 69 69 70 71 72 73 74 75 70 InvItem item = null; 71 if (_itemValue.HasQuality) { 72 item = new InvItem (name, _count, _itemValue.Quality, _itemValue.MaxUseTimes, _itemValue.UseTimes); 73 } else { 74 item = new InvItem (name, _count, -1, _itemValue.MaxUseTimes, _itemValue.UseTimes); 75 } 76 76 77 77 item.icon = itemClass.GetIconName (); 78 78 79 79 item.iconcolor = AllocsUtils.ColorToHex (itemClass.GetIconTint ()); 80 80 81 82 } else { 83 return null; 84 } 85 86 81 return item; 82 } 83 84 return null; 85 } 86 } 87 87 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs
r273 r325 4 4 using System.Runtime.Serialization.Formatters.Binary; 5 5 6 namespace AllocsFixes.PersistentData 7 { 6 namespace AllocsFixes.PersistentData { 8 7 [Serializable] 9 public class PersistentContainer 10 { 8 public class PersistentContainer { 11 9 private Players players; 12 [OptionalField] 13 private Attributes attributes; 10 [OptionalField] private Attributes attributes; 14 11 15 12 public Players Players { 16 13 get { 17 if (players == null) 14 if (players == null) { 18 15 players = new Players (); 16 } 17 19 18 return players; 20 19 } 21 20 } 22 21 23 public Attributes Attributes 24 { 22 public Attributes Attributes { 25 23 get { 26 24 if (attributes == null) { 27 attributes = new Attributes ();25 attributes = new Attributes (); 28 26 } 27 29 28 return attributes; 30 29 } … … 38 37 instance = new PersistentContainer (); 39 38 } 39 40 40 return instance; 41 41 } 42 42 } 43 43 44 private PersistentContainer () 45 { 44 private PersistentContainer () { 46 45 } 47 46 48 public void Save () 49 { 47 public void Save () { 50 48 Stream stream = File.Open (GameUtils.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Create); 51 49 BinaryFormatter bFormatter = new BinaryFormatter (); … … 54 52 } 55 53 56 public static bool Load () 57 { 54 public static bool Load () { 58 55 if (File.Exists (GameUtils.GetSaveGameDir () + "/AllocsPeristentData.bin")) { 59 56 try { … … 61 58 Stream stream = File.Open (GameUtils.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open); 62 59 BinaryFormatter bFormatter = new BinaryFormatter (); 63 obj = (PersistentContainer) bFormatter.Deserialize (stream);60 obj = (PersistentContainer) bFormatter.Deserialize (stream); 64 61 stream.Close (); 65 62 instance = obj; … … 70 67 } 71 68 } 69 72 70 return false; 73 71 } 74 75 72 } 76 73 } 77 -
binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs
r324 r325 4 4 5 5 namespace AllocsFixes.PersistentData { 6 [Serializable] 7 public class Player { 8 private readonly string steamId; 9 private int entityId; 10 private string name; 11 private string ip; 12 private long totalPlayTime; 13 14 [OptionalField] private DateTime 15 lastOnline; 16 17 private Inventory inventory; 18 19 [OptionalField] private int 20 lastPositionX, lastPositionY, lastPositionZ; 21 22 [OptionalField] [Obsolete ("experience no longer available, use level and expToNextLevel instead")] 23 private uint experience; 24 25 [OptionalField] private bool chatMuted; 26 [OptionalField] private int maxChatLength; 27 [OptionalField] private string chatColor; 28 [OptionalField] private bool chatName; 29 [OptionalField] private uint expToNextLevel; 30 [OptionalField] private int level; 31 32 [NonSerialized] private ClientInfo 33 clientInfo; 34 35 public string SteamID { 36 get { return steamId; } 37 } 6 [Serializable] 7 public class Player { 8 private readonly string steamId; 9 private int entityId; 10 private string name; 11 private string ip; 12 private long totalPlayTime; 13 14 [OptionalField] private DateTime lastOnline; 15 16 private Inventory inventory; 17 18 [OptionalField] private int lastPositionX, lastPositionY, lastPositionZ; 19 20 [OptionalField] [Obsolete ("experience no longer available, use level and expToNextLevel instead")] 21 private uint experience; 22 23 [OptionalField] private bool chatMuted; 24 [OptionalField] private int maxChatLength; 25 [OptionalField] private string chatColor; 26 [OptionalField] private bool chatName; 27 [OptionalField] private uint expToNextLevel; 28 [OptionalField] private int level; 29 30 [NonSerialized] private ClientInfo clientInfo; 31 32 public string SteamID { 33 get { return steamId; } 34 } 38 35 39 36 public int EntityID { … … 41 38 } 42 39 43 public string Name { 44 get { return name == null ? string.Empty : name; } 45 } 46 47 public string IP { 48 get { return ip == null ? string.Empty : ip; } 49 } 50 51 public Inventory Inventory { 52 get { 53 if (inventory == null) 54 inventory = new Inventory (); 55 return inventory; 56 } 57 } 58 59 public bool IsOnline { 60 get { return clientInfo != null; } 61 } 62 63 public ClientInfo ClientInfo { 64 get { return clientInfo; } 65 } 66 67 public EntityPlayer Entity { 68 get { 69 if (IsOnline) { 70 return GameManager.Instance.World.Players.dict [clientInfo.entityId]; 71 } else { 72 return null; 73 } 74 } 75 } 76 77 public long TotalPlayTime { 78 get { 79 if (IsOnline) { 80 return totalPlayTime + (long) (DateTime.Now - lastOnline).TotalSeconds; 81 } else { 82 return totalPlayTime; 83 } 84 } 85 } 86 87 public DateTime LastOnline { 88 get { 89 if (IsOnline) 90 return DateTime.Now; 91 else 92 return lastOnline; 93 } 94 } 95 96 public Vector3i LastPosition { 97 get { 98 if (IsOnline) 99 return new Vector3i (Entity.GetPosition ()); 100 else 101 return new Vector3i (lastPositionX, lastPositionY, lastPositionZ); 102 } 103 } 104 105 public bool LandProtectionActive { 106 get { 107 return GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance 108 .GetPersistentPlayerList ().GetPlayerData (SteamID)); 109 } 110 } 111 112 public float LandProtectionMultiplier { 113 get { 114 return GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance 115 .GetPersistentPlayerList ().GetPlayerData (SteamID)); 116 } 117 } 118 119 120 [Obsolete ("Experience no longer available, use Level instead")] 121 public uint Experience { 122 get { return 0; } 123 } 124 125 public float Level { 126 get { 127 float expForNextLevel = 128 (int) Math.Min ((Progression.BaseExpToLevel * Mathf.Pow (Progression.ExpMultiplier, level + 1)), 129 int.MaxValue); 130 float fLevel = level + 1f - ((float) expToNextLevel / expForNextLevel); 131 return fLevel; 132 } 133 } 134 135 public bool IsChatMuted { 136 get { return chatMuted; } 137 set { chatMuted = value; } 138 } 139 140 public int MaxChatLength { 141 get { 142 if (maxChatLength == 0) { 143 maxChatLength = 255; 144 } 145 146 return maxChatLength; 147 } 148 set { maxChatLength = value; } 149 } 150 151 public string ChatColor { 152 get { 153 if (chatColor == null || chatColor == "") { 154 chatColor = ""; 155 } 156 157 return chatColor; 158 } 159 160 set { chatColor = value; } 161 } 162 163 public bool ChatName { 164 get { return chatName; } 165 166 set { chatName = value; } 167 } 168 169 public void SetOffline () { 170 if (clientInfo != null) { 171 Log.Out ("Player set to offline: " + steamId); 172 lastOnline = DateTime.Now; 173 try { 174 Vector3i lastPos = new Vector3i (Entity.GetPosition ()); 175 lastPositionX = lastPos.x; 176 lastPositionY = lastPos.y; 177 lastPositionZ = lastPos.z; 178 totalPlayTime += (long) (Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad); 179 } catch (NullReferenceException) { 180 Log.Out ("Entity not available. Something seems to be wrong here..."); 181 } 182 183 clientInfo = null; 184 } 185 } 186 187 public void SetOnline (ClientInfo ci) { 188 Log.Out ("Player set to online: " + steamId); 189 clientInfo = ci; 40 public string Name { 41 get { return name == null ? string.Empty : name; } 42 } 43 44 public string IP { 45 get { return ip == null ? string.Empty : ip; } 46 } 47 48 public Inventory Inventory { 49 get { 50 if (inventory == null) { 51 inventory = new Inventory (); 52 } 53 54 return inventory; 55 } 56 } 57 58 public bool IsOnline { 59 get { return clientInfo != null; } 60 } 61 62 public ClientInfo ClientInfo { 63 get { return clientInfo; } 64 } 65 66 public EntityPlayer Entity { 67 get { 68 if (IsOnline) { 69 return GameManager.Instance.World.Players.dict [clientInfo.entityId]; 70 } 71 72 return null; 73 } 74 } 75 76 public long TotalPlayTime { 77 get { 78 if (IsOnline) { 79 return totalPlayTime + (long) (DateTime.Now - lastOnline).TotalSeconds; 80 } 81 82 return totalPlayTime; 83 } 84 } 85 86 public DateTime LastOnline { 87 get { 88 if (IsOnline) { 89 return DateTime.Now; 90 } 91 92 return lastOnline; 93 } 94 } 95 96 public Vector3i LastPosition { 97 get { 98 if (IsOnline) { 99 return new Vector3i (Entity.GetPosition ()); 100 } 101 102 return new Vector3i (lastPositionX, lastPositionY, lastPositionZ); 103 } 104 } 105 106 public bool LandProtectionActive { 107 get { 108 return GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance 109 .GetPersistentPlayerList ().GetPlayerData (SteamID)); 110 } 111 } 112 113 public float LandProtectionMultiplier { 114 get { 115 return GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance 116 .GetPersistentPlayerList ().GetPlayerData (SteamID)); 117 } 118 } 119 120 121 [Obsolete ("Experience no longer available, use Level instead")] 122 public uint Experience { 123 get { return 0; } 124 } 125 126 public float Level { 127 get { 128 float expForNextLevel = 129 (int) Math.Min (Progression.BaseExpToLevel * Mathf.Pow (Progression.ExpMultiplier, level + 1), 130 int.MaxValue); 131 float fLevel = level + 1f - expToNextLevel / expForNextLevel; 132 return fLevel; 133 } 134 } 135 136 public bool IsChatMuted { 137 get { return chatMuted; } 138 set { chatMuted = value; } 139 } 140 141 public int MaxChatLength { 142 get { 143 if (maxChatLength == 0) { 144 maxChatLength = 255; 145 } 146 147 return maxChatLength; 148 } 149 set { maxChatLength = value; } 150 } 151 152 public string ChatColor { 153 get { 154 if (chatColor == null || chatColor == "") { 155 chatColor = ""; 156 } 157 158 return chatColor; 159 } 160 161 set { chatColor = value; } 162 } 163 164 public bool ChatName { 165 get { return chatName; } 166 167 set { chatName = value; } 168 } 169 170 public Player (string steamId) { 171 this.steamId = steamId; 172 inventory = new Inventory (); 173 } 174 175 public void SetOffline () { 176 if (clientInfo != null) { 177 Log.Out ("Player set to offline: " + steamId); 178 lastOnline = DateTime.Now; 179 try { 180 Vector3i lastPos = new Vector3i (Entity.GetPosition ()); 181 lastPositionX = lastPos.x; 182 lastPositionY = lastPos.y; 183 lastPositionZ = lastPos.z; 184 totalPlayTime += (long) (Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad); 185 } catch (NullReferenceException) { 186 Log.Out ("Entity not available. Something seems to be wrong here..."); 187 } 188 189 clientInfo = null; 190 } 191 } 192 193 public void SetOnline (ClientInfo ci) { 194 Log.Out ("Player set to online: " + steamId); 195 clientInfo = ci; 190 196 entityId = ci.entityId; 191 name = ci.playerName; 192 ip = ci.ip; 193 lastOnline = DateTime.Now; 194 } 195 196 public void Update (PlayerDataFile _pdf) { 197 UpdateProgression (_pdf); 198 inventory.Update (_pdf); 199 } 200 201 private void UpdateProgression (PlayerDataFile _pdf) { 202 if (_pdf.progressionData.Length > 0) { 203 using (PooledBinaryReader pbr = MemoryPools.poolBinaryReader.AllocSync (false)) { 204 pbr.SetBaseStream (_pdf.progressionData); 205 Progression p = Progression.Read (pbr, null); 206 expToNextLevel = (uint) p.ExpToNextLevel; 207 level = p.Level; 208 } 209 } 210 } 211 212 public Player (string steamId) { 213 this.steamId = steamId; 214 this.inventory = new Inventory (); 215 } 216 } 197 name = ci.playerName; 198 ip = ci.ip; 199 lastOnline = DateTime.Now; 200 } 201 202 public void Update (PlayerDataFile _pdf) { 203 UpdateProgression (_pdf); 204 inventory.Update (_pdf); 205 } 206 207 private void UpdateProgression (PlayerDataFile _pdf) { 208 if (_pdf.progressionData.Length > 0) { 209 using (PooledBinaryReader pbr = MemoryPools.poolBinaryReader.AllocSync (false)) { 210 pbr.SetBaseStream (_pdf.progressionData); 211 Progression p = Progression.Read (pbr, null); 212 expToNextLevel = (uint) p.ExpToNextLevel; 213 level = p.Level; 214 } 215 } 216 } 217 } 217 218 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r276 r325 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Runtime.Serialization;4 3 using System.Text.RegularExpressions; 5 4 6 namespace AllocsFixes.PersistentData 7 { 5 namespace AllocsFixes.PersistentData { 8 6 [Serializable] 9 7 public class Players { 10 private Dictionary<string, Player> players = new Dictionary<string, Player> ();8 private readonly Dictionary<string, Player> players = new Dictionary<string, Player> (); 11 9 12 10 public Player this [string steamId, bool create] { … … 14 12 if (string.IsNullOrEmpty (steamId)) { 15 13 return null; 16 } else if (players.ContainsKey (steamId)) { 14 } 15 16 if (players.ContainsKey (steamId)) { 17 17 return players [steamId]; 18 } else {19 if (create && steamId != null && steamId.Length == 17) {20 Log.Out ("Created new player entry for ID: " + steamId);21 Player p = new Player (steamId);22 players.Add (steamId, p);23 return p;24 }25 return null;26 18 } 19 20 if (create && steamId != null && steamId.Length == 17) { 21 Log.Out ("Created new player entry for ID: " + steamId); 22 Player p = new Player (steamId); 23 players.Add (steamId, p); 24 return p; 25 } 26 27 return null; 27 28 } 28 29 } … … 53 54 if (_nameOrId.Length == 17 && long.TryParse (_nameOrId, out tempLong)) { 54 55 return _nameOrId; 55 } else { 56 int entityId = -1; 57 if (int.TryParse (_nameOrId, out entityId)) { 58 foreach (KeyValuePair<string, Player> kvp in players) { 59 if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) { 60 return kvp.Key; 61 } 62 } 63 } 56 } 64 57 65 _nameOrId = _nameOrId.ToLower (); 58 int entityId = -1; 59 if (int.TryParse (_nameOrId, out entityId)) { 66 60 foreach (KeyValuePair<string, Player> kvp in players) { 67 string name = kvp.Value.Name.ToLower (); 68 if (_ignoreColorCodes) { 69 name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", ""); 70 } 71 if (kvp.Value.IsOnline && name.Equals (_nameOrId)) { 61 if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) { 72 62 return kvp.Key; 73 63 } 74 64 } 75 65 } 66 67 _nameOrId = _nameOrId.ToLower (); 68 foreach (KeyValuePair<string, Player> kvp in players) { 69 string name = kvp.Value.Name.ToLower (); 70 if (_ignoreColorCodes) { 71 name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", ""); 72 } 73 74 if (kvp.Value.IsOnline && name.Equals (_nameOrId)) { 75 return kvp.Key; 76 } 77 } 78 76 79 return null; 77 80 } 78 81 } 79 82 } 80 -
binary-improvements/7dtd-server-fixes/src/PlayerDataStuff.cs
r233 r325 1 using System; 1 2 using AllocsFixes.PersistentData; 2 using System;3 using System.Collections.Generic;4 3 5 namespace AllocsFixes 6 { 7 public class PlayerDataStuff 8 { 9 10 public static void GM_SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) 11 { 4 namespace AllocsFixes { 5 public class PlayerDataStuff { 6 public static void GM_SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 12 7 try { 13 PersistentContainer.Instance.Players [_cInfo.playerId, true].Update (_playerDataFile);8 PersistentContainer.Instance.Players [_cInfo.playerId, true].Update (_playerDataFile); 14 9 } catch (Exception e) { 15 10 Log.Out ("Error in GM_SavePlayerData: " + e); 16 11 } 17 12 } 18 19 20 13 } 21 14 } -
binary-improvements/7dtd-server-fixes/src/StateManager.cs
r306 r325 1 1 using System; 2 using System.Reflection;2 using AllocsFixes.PersistentData; 3 3 4 namespace AllocsFixes 5 { 6 public class StateManager 7 { 8 public static void Awake () 9 { 4 namespace AllocsFixes { 5 public class StateManager { 6 public static void Awake () { 10 7 try { 11 Persistent Data.PersistentContainer.Load ();8 PersistentContainer.Load (); 12 9 } catch (Exception e) { 13 10 Log.Out ("Error in StateManager.Awake: " + e); … … 15 12 } 16 13 17 public static void Shutdown () 18 { 14 public static void Shutdown () { 19 15 try { 20 16 Log.Out ("Server shutting down!"); 21 Persistent Data.PersistentContainer.Instance.Save ();17 PersistentContainer.Instance.Save (); 22 18 } catch (Exception e) { 23 19 Log.Out ("Error in StateManager.Shutdown: " + e); … … 26 22 } 27 23 } 28
Note:
See TracChangeset
for help on using the changeset viewer.