Changeset 326 for binary-improvements/7dtd-server-fixes/src
- Timestamp:
- Sep 4, 2018, 2:33:52 PM (6 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/ChatHookExample.cs
r325 r326 5 5 6 6 public static bool Hook (ClientInfo _cInfo, EChatType _type, string _message, string _playerName) { 7 if (!string.IsNullOrEmpty (_message)) { 8 if (_message.EqualsCaseInsensitive ("/alloc")) { 9 if (_cInfo != null) { 10 Log.Out ("Sent chat hook reply to {0}", _cInfo.playerId); 11 _cInfo.SendPackage (new NetPackageChat (EChatType.Whisper, -1, ANSWER, "", false, null)); 12 } else { 13 Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _message); 14 } 15 16 return false; 17 } 7 if (string.IsNullOrEmpty (_message) || !_message.EqualsCaseInsensitive ("/alloc")) { 8 return true; 18 9 } 19 10 20 return true; 11 if (_cInfo != null) { 12 Log.Out ("Sent chat hook reply to {0}", _cInfo.playerId); 13 _cInfo.SendPackage (new NetPackageChat (EChatType.Whisper, -1, ANSWER, "", false, null)); 14 } else { 15 Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _message); 16 } 17 18 return false; 19 21 20 } 22 21 } -
binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r325 r326 54 54 try { 55 55 lock (cache) { 56 if (cache [zoomlevel].filename != null) { 57 cache [zoomlevel].data = content; 58 File.WriteAllBytes (cache [zoomlevel].filename, content); 56 if (cache [zoomlevel].filename == null) { 57 return; 59 58 } 59 60 cache [zoomlevel].data = content; 61 File.WriteAllBytes (cache [zoomlevel].filename, content); 60 62 } 61 63 } catch (Exception e) { -
binary-improvements/7dtd-server-fixes/src/JSON/JSONNull.cs
r325 r326 10 10 //Log.Out ("ParseNull enter (" + offset + ")"); 11 11 12 if (json.Substring (offset, 4).Equals ("null")) { 13 //Log.Out ("JSON:Parsed Null"); 14 offset += 4; 15 return new JSONNull (); 12 if (!json.Substring (offset, 4).Equals ("null")) { 13 throw new MalformedJSONException ("No valid null value found"); 16 14 } 17 15 18 throw new MalformedJSONException ("No valid null value found"); 16 //Log.Out ("JSON:Parsed Null"); 17 offset += 4; 18 return new JSONNull (); 19 19 } 20 20 } -
binary-improvements/7dtd-server-fixes/src/JSON/JSONObject.cs
r325 r326 104 104 //Log.Out ("JSON:Parsed Object: " + obj.ToString ()); 105 105 return obj; 106 default: 107 break; 106 108 } 107 109 } -
binary-improvements/7dtd-server-fixes/src/LandClaimList.cs
r325 r326 14 14 Dictionary<Player, List<Vector3i>> result = new Dictionary<Player, List<Vector3i>> (); 15 15 16 if (d != null) { 17 Dictionary<PersistentPlayerData, List<Vector3i>> owners = 18 new Dictionary<PersistentPlayerData, List<Vector3i>> (); 19 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) { 20 bool allowed = true; 21 if (_positionFilters != null) { 22 foreach (PositionFilter pf in _positionFilters) { 23 if (!pf (kvp.Key)) { 24 allowed = false; 25 break; 26 } 16 if (d == null) { 17 return result; 18 } 19 20 Dictionary<PersistentPlayerData, List<Vector3i>> owners = 21 new Dictionary<PersistentPlayerData, List<Vector3i>> (); 22 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) { 23 bool allowed = true; 24 if (_positionFilters != null) { 25 foreach (PositionFilter pf in _positionFilters) { 26 if (!pf (kvp.Key)) { 27 allowed = false; 28 break; 27 29 } 28 }29 30 if (allowed) {31 if (!owners.ContainsKey (kvp.Value)) {32 owners.Add (kvp.Value, new List<Vector3i> ());33 }34 35 owners [kvp.Value].Add (kvp.Key);36 30 } 37 31 } 38 32 39 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 40 Player p = PersistentContainer.Instance.Players [kvp.Key.PlayerId, false]; 41 if (p == null) { 42 p = new Player (kvp.Key.PlayerId); 33 if (allowed) { 34 if (!owners.ContainsKey (kvp.Value)) { 35 owners.Add (kvp.Value, new List<Vector3i> ()); 43 36 } 44 37 45 bool allowed = true; 46 if (_ownerFilters != null) { 47 foreach (OwnerFilter of in _ownerFilters) { 48 if (!of (p)) { 49 allowed = false; 50 break; 51 } 38 owners [kvp.Value].Add (kvp.Key); 39 } 40 } 41 42 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 43 Player p = PersistentContainer.Instance.Players [kvp.Key.PlayerId, false]; 44 if (p == null) { 45 p = new Player (kvp.Key.PlayerId); 46 } 47 48 bool allowed = true; 49 if (_ownerFilters != null) { 50 foreach (OwnerFilter of in _ownerFilters) { 51 if (!of (p)) { 52 allowed = false; 53 break; 52 54 } 53 55 } 56 } 54 57 55 if (allowed) { 56 result.Add (p, new List<Vector3i> ()); 57 foreach (Vector3i v in kvp.Value) { 58 result [p].Add (v); 59 } 58 if (allowed) { 59 result.Add (p, new List<Vector3i> ()); 60 foreach (Vector3i v in kvp.Value) { 61 result [p].Add (v); 60 62 } 61 63 } -
binary-improvements/7dtd-server-fixes/src/LiveData/Animals.cs
r325 r326 4 4 5 5 protected override EntityAnimal predicate (Entity _e) { 6 if (_e is EntityAnimal) { 7 EntityAnimal ea = (EntityAnimal) _e; 8 9 if (ea.IsAlive ()) { 10 return ea; 11 } 6 EntityAnimal ea = _e as EntityAnimal; 7 if (ea != null && ea.IsAlive ()) { 8 return ea; 12 9 } 13 10 -
binary-improvements/7dtd-server-fixes/src/LiveData/Hostiles.cs
r325 r326 4 4 5 5 protected override EntityEnemy predicate (Entity _e) { 6 if (_e is EntityEnemy) { 7 if (_e.IsAlive ()) { 8 return _e as EntityEnemy; 9 } 6 EntityEnemy enemy = _e as EntityEnemy; 7 if (enemy != null && enemy.IsAlive ()) { 8 return enemy; 10 9 } 11 10 -
binary-improvements/7dtd-server-fixes/src/PersistentData/Attributes.cs
r325 r326 5 5 public class Attributes { 6 6 private bool hideChatCommands; 7 private String hideChatCommandPrefix;7 private string hideChatCommandPrefix; 8 8 9 9 public bool HideChatCommands { -
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r325 r326 58 58 59 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 65 if (_count > maxAllowed) { 66 Log.Out ("Player with ID " + _playerId + " has stack for \"" + name + "\" greater than allowed (" + 67 _count + " > " + maxAllowed + ")"); 68 } 69 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 77 item.icon = itemClass.GetIconName (); 78 79 item.iconcolor = AllocsUtils.ColorToHex (itemClass.GetIconTint ()); 80 81 return item; 60 if (_count <= 0 || _itemValue == null || _itemValue.Equals (ItemValue.None)) { 61 return null; 82 62 } 83 63 84 return null; 64 ItemClass itemClass = ItemClass.list [_itemValue.type]; 65 int maxAllowed = itemClass.Stacknumber.Value; 66 string name = itemClass.GetItemName (); 67 68 if (_count > maxAllowed) { 69 Log.Out ("Player with ID " + _playerId + " has stack for \"" + name + "\" greater than allowed (" + 70 _count + " > " + maxAllowed + ")"); 71 } 72 73 InvItem item; 74 if (_itemValue.HasQuality) { 75 item = new InvItem (name, _count, _itemValue.Quality, _itemValue.MaxUseTimes, _itemValue.UseTimes); 76 } else { 77 item = new InvItem (name, _count, -1, _itemValue.MaxUseTimes, _itemValue.UseTimes); 78 } 79 80 item.icon = itemClass.GetIconName (); 81 82 item.iconcolor = AllocsUtils.ColorToHex (itemClass.GetIconTint ()); 83 84 return item; 85 85 } 86 86 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs
r325 r326 53 53 54 54 public static bool Load () { 55 if (File.Exists (GameUtils.GetSaveGameDir () + "/AllocsPeristentData.bin")) { 56 try { 57 PersistentContainer obj; 58 Stream stream = File.Open (GameUtils.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open); 59 BinaryFormatter bFormatter = new BinaryFormatter (); 60 obj = (PersistentContainer) bFormatter.Deserialize (stream); 61 stream.Close (); 62 instance = obj; 63 return true; 64 } catch (Exception e) { 65 Log.Error ("Exception in PersistentContainer.Load"); 66 Log.Exception (e); 67 } 55 if (!File.Exists (GameUtils.GetSaveGameDir () + "/AllocsPeristentData.bin")) { 56 return false; 57 } 58 59 try { 60 PersistentContainer obj; 61 Stream stream = File.Open (GameUtils.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open); 62 BinaryFormatter bFormatter = new BinaryFormatter (); 63 obj = (PersistentContainer) bFormatter.Deserialize (stream); 64 stream.Close (); 65 instance = obj; 66 return true; 67 } catch (Exception e) { 68 Log.Error ("Exception in PersistentContainer.Load"); 69 Log.Exception (e); 68 70 } 69 71 -
binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs
r325 r326 174 174 175 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 } 176 if (clientInfo == null) { 177 return; 178 } 179 180 Log.Out ("Player set to offline: " + steamId); 181 lastOnline = DateTime.Now; 182 try { 183 Vector3i lastPos = new Vector3i (Entity.GetPosition ()); 184 lastPositionX = lastPos.x; 185 lastPositionY = lastPos.y; 186 lastPositionZ = lastPos.z; 187 totalPlayTime += (long) (Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad); 188 } catch (NullReferenceException) { 189 Log.Out ("Entity not available. Something seems to be wrong here..."); 190 } 191 192 clientInfo = null; 191 193 } 192 194 … … 206 208 207 209 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 } 210 if (_pdf.progressionData.Length <= 0) { 211 return; 212 } 213 214 using (PooledBinaryReader pbr = MemoryPools.poolBinaryReader.AllocSync (false)) { 215 pbr.SetBaseStream (_pdf.progressionData); 216 Progression p = Progression.Read (pbr, null); 217 expToNextLevel = (uint) p.ExpToNextLevel; 218 level = p.Level; 215 219 } 216 220 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r325 r326 6 6 [Serializable] 7 7 public class Players { 8 private readonly Dictionary<string, Player> players = new Dictionary<string,Player> ();8 private readonly Dictionary<string, Player> players = new CaseInsensitiveStringDictionary<Player> (); 9 9 10 10 public Player this [string steamId, bool create] { … … 18 18 } 19 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; 20 if (!create || steamId.Length != 17) { 21 return null; 25 22 } 26 23 27 return null; 24 Log.Out ("Created new player entry for ID: " + steamId); 25 Player p = new Player (steamId); 26 players.Add (steamId, p); 27 return p; 28 28 } 29 29 } … … 56 56 } 57 57 58 int entityId = -1;58 int entityId; 59 59 if (int.TryParse (_nameOrId, out entityId)) { 60 60 foreach (KeyValuePair<string, Player> kvp in players) { … … 65 65 } 66 66 67 _nameOrId = _nameOrId.ToLower ();68 67 foreach (KeyValuePair<string, Player> kvp in players) { 69 string name = kvp.Value.Name .ToLower ();68 string name = kvp.Value.Name; 70 69 if (_ignoreColorCodes) { 71 70 name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", ""); 72 71 } 73 72 74 if (kvp.Value.IsOnline && name.Equals (_nameOrId)) {73 if (kvp.Value.IsOnline && name.EqualsCaseInsensitive (_nameOrId)) { 75 74 return kvp.Key; 76 75 }
Note:
See TracChangeset
for help on using the changeset viewer.