Changeset 326 for binary-improvements/7dtd-server-fixes/src/PersistentData
- Timestamp:
- Sep 4, 2018, 2:33:52 PM (6 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src/PersistentData
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
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.