Changeset 324 for binary-improvements/7dtd-server-fixes/src
- Timestamp:
- Sep 3, 2018, 7:11:10 PM (6 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/API.cs
r267 r324 1 1 using System; 2 using System.Collections.Generic; 2 3 3 4 namespace AllocsFixes 4 5 { 5 public class API : ModApiAbstract{6 public class API : IModApi { 6 7 7 public overridevoid GameAwake () {8 public void GameAwake () { 8 9 StateManager.Awake (); 9 10 } 10 11 11 public overridevoid GameShutdown () {12 public void GameShutdown () { 12 13 StateManager.Shutdown (); 13 14 } 14 15 15 public overridevoid SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) {16 public void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 16 17 PlayerDataStuff.GM_SavePlayerData (_cInfo, _playerDataFile); 17 18 } 18 19 19 public override void PlayerLogin (ClientInfo _cInfo, string _compatibilityVersion) { 20 } 21 22 public override void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) { 20 public void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) { 23 21 AllocsLogFunctions.RequestToSpawnPlayer (_cInfo, _chunkViewDim, _playerProfile); 24 22 } 25 23 26 public overridevoid PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) {24 public void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) { 27 25 AllocsLogFunctions.PlayerDisconnected (_cInfo, _bShutdown); 28 26 } 29 27 30 public override bool ChatMessage (ClientInfo _cInfo, EnumGameMessages _type, string _msg, string _mainName, bool _localizeMain, string _secondaryName, bool _localizeSecondary) {28 public bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName, bool _localizeMain, List<int> _recipientEntityIds) { 31 29 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); 32 39 } 33 40 } -
binary-improvements/7dtd-server-fixes/src/ChatHookExample.cs
r276 r324 6 6 private const string ANSWER = " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]"; 7 7 8 public static bool Hook (ClientInfo _cInfo, E numGameMessages_type, string _message, string _playerName) {9 if ( _type == EnumGameMessages.Chat &&!string.IsNullOrEmpty (_message)) {10 if (_message. ToLower () == "/alloc") {8 public static bool Hook (ClientInfo _cInfo, EChatType _type, string _message, string _playerName) { 9 if (!string.IsNullOrEmpty (_message)) { 10 if (_message.EqualsCaseInsensitive ("/alloc")) { 11 11 if (_cInfo != null) { 12 12 Log.Out ("Sent chat hook reply to {0}", _cInfo.playerId); 13 _cInfo.SendPackage (new NetPackageGameMessage (EnumGameMessages.Chat, ANSWER, "", false, "", false)); 14 GameManager.Instance.GameMessageServer (_cInfo, EnumGameMessages.Chat, string.Format("!{0}", _message), _playerName, false, "", false); 13 _cInfo.SendPackage (new NetPackageChat(EChatType.Whisper, -1, ANSWER, "", false, null)); 15 14 } else { 16 15 Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _message); -
binary-improvements/7dtd-server-fixes/src/FileCache/AbstractCache.cs
r199 r324 1 using System; 2 using System.Collections.Generic; 1 namespace AllocsFixes.FileCache { 2 public abstract class AbstractCache { 3 public AbstractCache () { 4 } 3 5 4 namespace AllocsFixes.FileCache 5 { 6 public abstract class AbstractCache 7 { 8 9 public AbstractCache () 10 { 11 } 12 13 public abstract byte[] GetFileContent (string filename); 14 15 } 6 public abstract byte[] GetFileContent (string filename); 7 } 16 8 } 17 -
binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r269 r324 1 1 using System; 2 using System.Collections.Generic;3 2 using System.IO; 3 using UnityEngine; 4 4 5 5 namespace AllocsFixes.FileCache … … 21 21 public MapTileCache (int _tileSize) 22 22 { 23 UnityEngine.Texture2D tex = new UnityEngine.Texture2D (_tileSize, _tileSize);24 UnityEngine.Color nullColor = new UnityEngine.Color (0, 0, 0, 0);23 Texture2D tex = new Texture2D (_tileSize, _tileSize); 24 Color nullColor = new Color (0, 0, 0, 0); 25 25 for (int x = 0; x < _tileSize; x++) { 26 26 for (int y = 0; y < _tileSize; y++) { -
binary-improvements/7dtd-server-fixes/src/JSON/JSONNumber.cs
r309 r324 86 86 } else { 87 87 double number; 88 if (! Utils.TryParseDouble(sbNum.ToString (), out number)) {88 if (!StringParsers.TryParseDouble(sbNum.ToString (), out number)) { 89 89 throw new MalformedJSONException ("Mantissa is not a valid decimal (\"" + sbNum.ToString () + "\")"); 90 90 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r287 r324 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Runtime.Serialization;4 using System.Threading;5 3 6 namespace AllocsFixes.PersistentData 7 { 8 [Serializable] 9 public class Inventory { 10 public List<InvItem> bag; 11 public List<InvItem> belt; 12 public InvItem[] equipment; 4 namespace AllocsFixes.PersistentData { 5 [Serializable] 6 public class Inventory { 7 public List<InvItem> bag; 8 public List<InvItem> belt; 9 public InvItem[] equipment; 13 10 14 15 16 17 18 11 public Inventory () { 12 bag = new List<InvItem> (); 13 belt = new List<InvItem> (); 14 equipment = null; 15 } 19 16 20 21 22 23 24 25 26 27 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 } 28 25 29 private void ProcessInv (List<InvItem> target, ItemStack[] sourceFields, int id) { 30 target.Clear (); 31 for (int i = 0; i < sourceFields.Length; i++) { 32 InvItem item = CreateInvItem (sourceFields [i].itemValue, sourceFields [i].count, id); 33 if (item != null && sourceFields [i].itemValue.Parts != null) { 34 ProcessParts (sourceFields [i].itemValue.Parts, item, id); 35 } 36 target.Add (item); 37 } 38 } 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 } 39 33 40 private void ProcessEqu (Equipment sourceEquipment, int _playerId) { 41 equipment = new InvItem[sourceEquipment.GetSlotCount ()]; 42 for (int i = 0; i < sourceEquipment.GetSlotCount (); i++) { 43 equipment [i] = CreateInvItem (sourceEquipment.GetSlotItem (i), 1, _playerId); 44 } 45 } 34 target.Add (item); 35 } 36 } 46 37 47 private void ProcessParts (ItemValue[] _parts, InvItem _item, int _playerId) { 48 InvItem[] itemParts = new InvItem[_parts.Length]; 49 for (int i = 0; i < _parts.Length; i++) { 50 InvItem partItem = CreateInvItem (_parts [i], 1, _playerId); 51 if (partItem != null && _parts [i].Parts != null) { 52 ProcessParts (_parts [i].Parts, partItem, _playerId); 53 } 54 itemParts [i] = partItem; 55 } 56 _item.parts = itemParts; 57 } 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 } 58 44 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 (); 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 } 64 52 65 if (_count > maxAllowed) { 66 Log.Out ("Player with ID " + _playerId + " has stack for \"" + name + "\" greater than allowed (" + _count + " > " + maxAllowed + ")"); 67 } 53 itemParts [i] = partItem; 54 } 68 55 69 InvItem item = null; 70 if (_itemValue.HasQuality) { 71 item = new InvItem (name, _count, _itemValue.Quality, _itemValue.MaxUseTimes, _itemValue.UseTimes); 72 } else { 73 item = new InvItem (name, _count, -1, _itemValue.MaxUseTimes, _itemValue.UseTimes); 74 } 56 _item.parts = itemParts; 57 } 75 58 76 item.icon = itemClass.GetIconName (); 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 (); 77 64 78 item.iconcolor = AllocsUtils.ColorToHex (itemClass.GetIconTint ()); 79 80 return item; 81 } else { 82 return null; 83 } 84 } 85 } 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; 82 } else { 83 return null; 84 } 85 } 86 } 86 87 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs
r301 r324 3 3 using UnityEngine; 4 4 5 namespace AllocsFixes.PersistentData 6 { 7 [Serializable] 8 public class Player 9 { 10 private readonly string steamId; 11 private int entityId; 12 private string name; 13 private string ip; 14 private long totalPlayTime; 15 [OptionalField] 16 private DateTime 17 lastOnline; 18 private Inventory inventory; 19 [OptionalField] 20 private int 21 lastPositionX, lastPositionY, lastPositionZ; 22 [OptionalField][Obsolete("experience no longer available, use level and expToNextLevel instead")] 23 private uint experience; 24 [OptionalField] 25 private bool chatMuted; 26 [OptionalField] 27 private int maxChatLength; 28 [OptionalField] 29 private string chatColor; 30 [OptionalField] 31 private bool chatName; 32 [OptionalField] 33 private uint expToNextLevel; 34 [OptionalField] 35 private int level; 36 37 [NonSerialized] 38 private ClientInfo 39 clientInfo; 40 41 public string SteamID { 42 get { return steamId; } 43 } 44 45 public int EntityID { 46 get { return entityId; } 47 } 48 49 public string Name { 50 get { return name == null ? string.Empty : name; } 51 } 52 53 public string IP { 54 get { return ip == null ? string.Empty : ip; } 55 } 56 57 public Inventory Inventory { 58 get { 59 if (inventory == null) 60 inventory = new Inventory (); 61 return inventory; 62 } 63 } 64 65 public bool IsOnline { 66 get { return clientInfo != null; } 67 } 68 69 public ClientInfo ClientInfo { 70 get { return clientInfo; } 71 } 72 73 public EntityPlayer Entity { 74 get { 75 if (IsOnline) { 76 return GameManager.Instance.World.Players.dict [clientInfo.entityId]; 77 } else { 78 return null; 79 } 80 } 81 } 82 83 public long TotalPlayTime { 84 get { 85 if (IsOnline) { 86 return totalPlayTime + (long)(DateTime.Now - lastOnline).TotalSeconds; 87 } else { 88 return totalPlayTime; 89 } 90 } 91 } 92 93 public DateTime LastOnline { 94 get { 95 if (IsOnline) 96 return DateTime.Now; 97 else 98 return lastOnline; 99 } 100 } 101 102 public Vector3i LastPosition { 103 get { 104 if (IsOnline) 105 return new Vector3i (Entity.GetPosition ()); 106 else 107 return new Vector3i (lastPositionX, lastPositionY, lastPositionZ); 108 } 109 } 110 111 public bool LandProtectionActive { 112 get { 113 return GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance.GetPersistentPlayerList ().GetPlayerData (SteamID)); 114 } 115 } 116 117 public float LandProtectionMultiplier { 118 get { 119 return GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance.GetPersistentPlayerList ().GetPlayerData (SteamID)); 120 } 121 } 122 123 124 [Obsolete("Experience no longer available, use Level instead")] 125 public uint Experience { 126 get { 127 return 0; 128 } 129 } 130 131 public float Level { 132 get { 133 float expForNextLevel = (int)Math.Min ((Progression.BaseExpToLevel * Mathf.Pow (Progression.ExpMultiplier, level + 1)), int.MaxValue); 134 float fLevel = level + 1f - ((float)expToNextLevel / expForNextLevel); 135 return fLevel; 136 } 137 } 138 139 public bool IsChatMuted{ 140 get { 141 return chatMuted; 142 } 143 set { 144 chatMuted = value; 145 } 146 } 147 148 public int MaxChatLength { 149 get { 150 if (maxChatLength == 0 ) { 151 maxChatLength = 255; 152 } 153 return maxChatLength; 154 } 155 set { 156 maxChatLength = value; 157 } 158 } 159 160 public string ChatColor { 161 get { 162 if (chatColor == null || chatColor == "") { 163 chatColor = ""; 164 } 165 return chatColor; 166 } 167 168 set { 169 chatColor = value; 170 } 171 } 172 173 public bool ChatName { 174 get { 175 return chatName; 176 } 177 178 set { 179 chatName = value; 180 } 181 } 182 183 public void SetOffline () 184 { 185 if (clientInfo != null) { 186 Log.Out ("Player set to offline: " + steamId); 187 lastOnline = DateTime.Now; 188 try { 189 Vector3i lastPos = new Vector3i (Entity.GetPosition ()); 190 lastPositionX = lastPos.x; 191 lastPositionY = lastPos.y; 192 lastPositionZ = lastPos.z; 193 totalPlayTime += (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad); 194 } catch (NullReferenceException) { 195 Log.Out ("Entity not available. Something seems to be wrong here..."); 196 } 197 clientInfo = null; 198 } 199 } 200 201 public void SetOnline (ClientInfo ci) 202 { 203 Log.Out ("Player set to online: " + steamId); 204 clientInfo = ci; 205 entityId = ci.entityId; 206 name = ci.playerName; 207 ip = ci.ip; 208 lastOnline = DateTime.Now; 209 } 210 211 public void Update (PlayerDataFile _pdf) { 212 experience = 0; 213 expToNextLevel = _pdf.experience; 214 level = _pdf.level; 215 inventory.Update (_pdf); 216 } 217 218 public Player (string steamId) 219 { 220 this.steamId = steamId; 221 this.inventory = new Inventory (); 222 } 223 224 225 } 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 } 38 39 public int EntityID { 40 get { return entityId; } 41 } 42 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; 190 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 } 226 217 }
Note:
See TracChangeset
for help on using the changeset viewer.