Changeset 144 for binary-improvements/7dtd-server-fixes
- Timestamp:
- Aug 30, 2014, 6:11:18 PM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes
- Files:
-
- 4 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
r142 r144 94 94 <Compile Include="src\CustomCommands\EnableRendering.cs" /> 95 95 <Compile Include="src\PersistentData\PersistentContainer.cs" /> 96 <Compile Include="src\PersistentData\KnownPlayers.cs" />97 96 <Compile Include="src\StateManager.cs" /> 97 <Compile Include="src\PersistentData\InvItem.cs" /> 98 <Compile Include="src\PersistentData\Inventory.cs" /> 99 <Compile Include="src\PersistentData\Players.cs" /> 100 <Compile Include="src\PersistentData\Player.cs" /> 98 101 </ItemGroup> 99 102 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -
binary-improvements/7dtd-server-fixes/src/AllocsLogFunctions.cs
r130 r144 1 using AllocsFixes.PersistentData; 1 2 using System; 2 3 using System.Collections.Generic; … … 13 14 int entityId = CommonMappingFunctions.GetEntityID (ci); 14 15 EntityPlayer ep = CommonMappingFunctions.GetEntityPlayer (ci); 16 string steamId = CommonMappingFunctions.GetSteamID (ci); 15 17 16 18 string ip = ci.networkPlayer.ipAddress; … … 23 25 ", entityid=" + entityId + 24 26 ", name=" + name + 25 ", steamid=" + CommonMappingFunctions.GetSteamID (ci)+27 ", steamid=" + steamId + 26 28 ", ip=" + ip 27 29 ); 30 31 PersistentContainer.Instance.Players[steamId].SetOnline(ci); 28 32 } catch (Exception e) { 29 Log.Out ("Error in RequestToSpawnPlayer: " + e); 33 Log.Out ("Error in AllocsLogFunctions.RequestToSpawnPlayer: " + e); 34 } 35 } 36 37 public static void PlayerDisconnected (GameManager manager, int _clientId) { 38 try { 39 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromClientID (_clientId); 40 string steamId = CommonMappingFunctions.GetSteamID (ci); 41 Players players = PersistentContainer.Instance.Players; 42 if (players.SteamIDs.Contains(steamId)) 43 players[steamId].SetOffline(); 44 } catch (Exception e) { 45 Log.Out ("Error in AllocsLogFunctions.PlayerDisconnected: " + e); 30 46 } 31 47 } -
binary-improvements/7dtd-server-fixes/src/CommonMappingFunctions.cs
r130 r144 136 136 { 137 137 try { 138 int entityId = -1; 139 if (int.TryParse (_nameOrId, out entityId)) { 140 ClientInfo ci = GetClientInfoFromEntityID (entityId); 141 if (ci != null) 142 return ci; 138 long tempLong; 139 if (_nameOrId.Length == 17 && long.TryParse (_nameOrId, out tempLong)) { 140 return GetClientInfoFromSteamID (_nameOrId); 141 } else { 142 int entityId = -1; 143 if (int.TryParse (_nameOrId, out entityId)) { 144 ClientInfo ci = GetClientInfoFromEntityID (entityId); 145 if (ci != null) 146 return ci; 147 } 148 149 return GetClientInfoFromPlayerName (_nameOrId, ignoreColorcodes); 143 150 } 144 145 return GetClientInfoFromPlayerName (_nameOrId, ignoreColorcodes);146 151 } catch (Exception e) { 147 Log.Out ("Error getting ClientInfo for entity ID or player name: " + e);152 Log.Out ("Error getting ClientInfo for steam ID / entity ID / player name \"" + _nameOrId + "\": " + e); 148 153 } 149 154 return null; -
binary-improvements/7dtd-server-fixes/src/CustomCommands/ListPlayersExtended.cs
r130 r144 32 32 } 33 33 m_Console.SendResult (string.Concat (new object[] 34 {35 string.Empty,36 ++num,37 ". id=",38 current.Value.fd008f,39 ", ",40 current.Value.EntityName,41 ", pos=",42 current.Value.GetPosition (),43 ", rot=",44 current.Value.rotation,45 ", remote=",46 current.Value.fd00b2,47 ", health=",48 current.Value.Health,49 ", deaths=",50 current.Value.Died,51 ", zombies=",52 current.Value.KilledZombies,53 ", players=",54 current.Value.KilledPlayers,55 ", score=",56 current.Value.Score,57 ", steamid=",58 CommonMappingFunctions.GetSteamID (ci),59 ", ip=",60 ip,61 ", ping=",62 current.Value.pingToServer63 }34 { 35 string.Empty, 36 ++num, 37 ". id=", 38 current.Value.fd008f, 39 ", ", 40 current.Value.EntityName, 41 ", pos=", 42 current.Value.GetPosition (), 43 ", rot=", 44 current.Value.rotation, 45 ", remote=", 46 current.Value.fd00b2, 47 ", health=", 48 current.Value.Health, 49 ", deaths=", 50 current.Value.Died, 51 ", zombies=", 52 current.Value.KilledZombies, 53 ", players=", 54 current.Value.KilledPlayers, 55 ", score=", 56 current.Value.Score, 57 ", steamid=", 58 CommonMappingFunctions.GetSteamID (ci), 59 ", ip=", 60 ip, 61 ", ping=", 62 current.Value.pingToServer 63 } 64 64 ) 65 65 ); -
binary-improvements/7dtd-server-fixes/src/CustomCommands/ShowInventory.cs
r130 r144 1 using AllocsFixes.PersistentData; 1 2 using System; 2 3 using System.Collections.Generic; … … 6 7 public class ShowInventory : ConsoleCommand 7 8 { 8 private GameManager manager;9 10 9 public ShowInventory (ConsoleSdtd cons) : base(cons) 11 10 { 12 manager = m_Console.gameManager;13 11 } 14 12 15 13 public override string Description () 16 14 { 17 return "list inventory of a given player ( entity id or name)";15 return "list inventory of a given player (steam id, entity id or name)"; 18 16 } 19 17 … … 27 25 try { 28 26 if (_params.Length < 1) { 29 m_Console.SendResult ("Usage: showinventory < playername|entityid>");27 m_Console.SendResult ("Usage: showinventory <steamid|playername|entityid>"); 30 28 return; 31 29 } 32 30 33 int entityId = -1; 34 PlayerDataStuff.PlayerItems items = null; 35 if (int.TryParse (_params [0], out entityId)) { 36 items = PlayerDataStuff.GetPlayerItems (entityId); 37 } 38 39 if (items == null) { 40 string playerName = _params [0].ToLower (); 41 foreach (KeyValuePair<int, EntityPlayer> kvp in manager.World.playerEntities.dict) { 42 if (kvp.Value.EntityName.ToLower ().Equals (playerName)) { 43 entityId = kvp.Key; 44 break; 45 } 46 } 47 } 48 items = PlayerDataStuff.GetPlayerItems (entityId); 49 50 if (items == null) { 51 m_Console.SendResult ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s)."); 31 string steamid = PersistentContainer.Instance.Players.GetSteamID(_params[0], true); 32 if (steamid == null) { 33 m_Console.SendResult ("Playername or entity/steamid id not found or no inventory saved (first saved after a player has been online for 30s)."); 52 34 return; 53 35 } 54 36 37 Log.Out ( "SteamID: " + steamid); 38 39 Player p = PersistentContainer.Instance.Players[steamid]; 40 41 Log.Out ("Player"); 42 43 PersistentData.Inventory inv = p.Inventory; 44 45 Log.Out ("Inv"); 46 55 47 m_Console.SendResult ("Belt of player:"); 56 for each (KeyValuePair<string, int> kvp in items.belt) {57 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));48 for (int i = 0; i < inv.belt.Count; i++) { 49 m_Console.SendResult (string.Format (" Slot {0}: {1:000} * {2}", i, inv.belt[i].count, inv.belt[i].itemName)); 58 50 } 59 51 m_Console.SendResult (string.Empty); 60 52 m_Console.SendResult ("Bagpack of player:"); 61 for each (KeyValuePair<string, int> kvp in items.bag) {62 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));53 for (int i = 0; i < inv.bag.Count; i++) { 54 m_Console.SendResult (string.Format (" Slot {0}: {1:000} * {2}", i, inv.bag[i].count, inv.bag[i].itemName)); 63 55 } 64 56 m_Console.SendResult (string.Empty); -
binary-improvements/7dtd-server-fixes/src/MapRendering/Constants.cs
r143 r144 3 3 namespace AllocsFixes.MapRendering 4 4 { 5 public class Constants5 public static class Constants 6 6 { 7 7 public const int MAP_BLOCK_SIZE = 128; -
binary-improvements/7dtd-server-fixes/src/MapRendering/MapRendering.cs
r143 r144 36 36 37 37 chunkSaveTimer.AutoReset = false; 38 chunkSaveTimer.Elapsed += new System.Timers.ElapsedEventHandler ( RenderDirtyChunks);38 chunkSaveTimer.Elapsed += new System.Timers.ElapsedEventHandler (TimedRendering); 39 39 } 40 40 … … 130 130 } 131 131 } 132 133 while (dirtyChunks.Count > 0) { 134 RenderDirtyChunks (); 135 } 136 132 137 Log.Out (String.Format ("RenderMap: {0}/{1} ({2}%)", curFullMapPos.x, widthPix, (int)((float)curFullMapPos.x / widthPix * 100))); 133 138 } 134 139 } finally { 135 140 Monitor.Exit (Instance.zoomLevelBuffers); 136 }137 int totalDirtyCount = dirtyChunks.Count;138 Log.Out (String.Format ("Rendering chunks: {0}/{1} ({2}%)", totalDirtyCount - dirtyChunks.Count, totalDirtyCount, (int)((float)(totalDirtyCount - dirtyChunks.Count) / totalDirtyCount * 100)));139 while (dirtyChunks.Count > 0) {140 RenderDirtyChunks (null, null);141 Log.Out (String.Format ("Rendering chunks: {0}/{1} ({2}%)", totalDirtyCount - dirtyChunks.Count, totalDirtyCount, (int)((float)(totalDirtyCount - dirtyChunks.Count) / totalDirtyCount * 100)));142 141 } 143 142 … … 162 161 } 163 162 164 private void RenderDirtyChunks(object source, System.Timers.ElapsedEventArgs e)163 private void TimedRendering (object source, System.Timers.ElapsedEventArgs e) 165 164 { 166 165 Monitor.Enter (zoomLevelBuffers); 167 166 try { 168 msw.ResetAndRestart (); 169 170 if (dirtyChunks.Count > 0) { 171 List<Vector2i> keys = new List<Vector2i> (dirtyChunks.Keys); 172 List<Vector2i> chunksDone = new List<Vector2i> (); 173 174 Vector2i chunkPos = keys [0]; 175 chunksDone.Add (chunkPos); 176 177 //Log.Out ("Start Dirty: " + chunkPos); 178 179 Vector2i block, blockOffset; 180 getBlockNumber (chunkPos, out block, out blockOffset, Constants.MAP_BLOCK_TO_CHUNK_DIV, Constants.MAP_CHUNK_SIZE); 181 182 zoomLevelBuffers [Constants.ZOOMLEVELS - 1].LoadBlock (block); 183 184 Vector2i v_block, v_blockOffset; 185 foreach (Vector2i v in keys) { 186 getBlockNumber (v, out v_block, out v_blockOffset, Constants.MAP_BLOCK_TO_CHUNK_DIV, Constants.MAP_CHUNK_SIZE); 187 if (v_block.Equals (block)) { 188 //Log.Out ("Dirty: " + v + " render: true"); 189 chunksDone.Add (v); 190 zoomLevelBuffers [Constants.ZOOMLEVELS - 1].SetPart (v_blockOffset, Constants.MAP_CHUNK_SIZE, dirtyChunks [v]); 191 } else { 192 //Log.Out ("Dirty: " + v + " render: false"); 193 } 194 } 195 196 foreach (Vector2i v in chunksDone) 197 dirtyChunks.Remove (v); 198 199 RenderZoomLevel (Constants.ZOOMLEVELS - 1, block); 200 201 SaveAllBlockMaps (null, null); 202 } 203 204 if (e != null) 167 RenderDirtyChunks (); 205 168 if (dirtyChunks.Count > 0) 206 169 Instance.chunkSaveTimer.Start (); 207 170 } finally { 208 171 Monitor.Exit (zoomLevelBuffers); 172 } 173 } 174 175 private void RenderDirtyChunks () 176 { 177 msw.ResetAndRestart (); 178 179 if (dirtyChunks.Count > 0) { 180 List<Vector2i> keys = new List<Vector2i> (dirtyChunks.Keys); 181 List<Vector2i> chunksDone = new List<Vector2i> (); 182 183 Vector2i chunkPos = keys [0]; 184 chunksDone.Add (chunkPos); 185 186 //Log.Out ("Start Dirty: " + chunkPos); 187 188 Vector2i block, blockOffset; 189 getBlockNumber (chunkPos, out block, out blockOffset, Constants.MAP_BLOCK_TO_CHUNK_DIV, Constants.MAP_CHUNK_SIZE); 190 191 zoomLevelBuffers [Constants.ZOOMLEVELS - 1].LoadBlock (block); 192 193 Vector2i v_block, v_blockOffset; 194 foreach (Vector2i v in keys) { 195 getBlockNumber (v, out v_block, out v_blockOffset, Constants.MAP_BLOCK_TO_CHUNK_DIV, Constants.MAP_CHUNK_SIZE); 196 if (v_block.Equals (block)) { 197 //Log.Out ("Dirty: " + v + " render: true"); 198 chunksDone.Add (v); 199 zoomLevelBuffers [Constants.ZOOMLEVELS - 1].SetPart (v_blockOffset, Constants.MAP_CHUNK_SIZE, dirtyChunks [v]); 200 } else { 201 //Log.Out ("Dirty: " + v + " render: false"); 202 } 203 } 204 205 foreach (Vector2i v in chunksDone) 206 dirtyChunks.Remove (v); 207 208 RenderZoomLevel (Constants.ZOOMLEVELS - 1, block); 209 210 SaveAllBlockMaps (null, null); 209 211 } 210 212 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs
r143 r144 1 1 using System; 2 using System.Collections.Generic;3 2 using System.IO; 4 3 using System.Runtime.Serialization; … … 10 9 public class PersistentContainer 11 10 { 12 public Dictionary<string, KnownPlayers> players = new Dictionary<string, KnownPlayers> (); 11 private Players players; 12 13 public Players Players { 14 get { 15 if (players == null) 16 players = new Players (); 17 return players; 18 } 19 } 20 13 21 private static PersistentContainer instance; 14 22 … … 24 32 private PersistentContainer () 25 33 { 26 Log.Out ("new PersistentContainer()");27 34 } 28 35 -
binary-improvements/7dtd-server-fixes/src/PlayerDataStuff.cs
r130 r144 1 using AllocsFixes.PersistentData; 1 2 using System; 2 3 using System.Collections.Generic; … … 6 7 public class PlayerDataStuff 7 8 { 8 public class PlayerItems9 {10 public SortedList<string, int> belt = new SortedList<string, int> ();11 public SortedList<string, int> bag = new SortedList<string, int> ();12 13 public PlayerItems (InventoryField[] _belt, InventoryField[] _bag)14 {15 foreach (InventoryField item in _belt) {16 if (item.count > 0) {17 string name = getInvFieldName (item);18 if (belt.ContainsKey (name)) {19 belt [name] += item.count;20 } else {21 belt.Add (name, item.count);22 }23 }24 }25 26 foreach (InventoryField item in _bag) {27 if (item.count > 0) {28 string name = getInvFieldName (item);29 if (bag.ContainsKey (name)) {30 bag [name] += item.count;31 } else {32 bag.Add (name, item.count);33 }34 }35 }36 }37 };38 39 private static Dictionary<int, PlayerItems> itemsPerEntityId = new Dictionary<int, PlayerItems> ();40 41 public static PlayerItems GetPlayerItems (int entityId)42 {43 if (itemsPerEntityId.ContainsKey (entityId))44 return itemsPerEntityId [entityId];45 else46 return null;47 }48 9 49 10 public static void GM_SavePlayerData (GameManager manager, int _clientId, PlayerDataFile _playerDataFile) 50 11 { 51 12 try { 52 int entityId = CommonMappingFunctions.GetEntityID (CommonMappingFunctions.GetClientInfoFromClientID (_clientId)); 53 if (entityId >= 0) { 54 Log.Out ("Saving playerData for entity id: " + entityId); 55 56 if (itemsPerEntityId.ContainsKey (entityId)) 57 itemsPerEntityId.Remove (entityId); 58 itemsPerEntityId.Add (entityId, new PlayerItems (_playerDataFile.inventory, _playerDataFile.bag)); 59 } 13 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromClientID(_clientId); 14 string steamId = CommonMappingFunctions.GetSteamID(ci); 15 PersistentContainer.Instance.Players[steamId].Inventory.Update(_playerDataFile); 60 16 } catch (Exception e) { 61 17 Log.Out ("Error in GM_SavePlayerData: " + e); 62 18 } 63 64 // Log.Out ("Inventory of player:");65 // for (int i = 0; i < _playerDataFile.inventory.Length; i++) {66 // InventoryField item = _playerDataFile.inventory [i];67 // printItem (item, i);68 // }69 //70 // Log.Out ("Bag of player:");71 // for (int i = 0; i < _playerDataFile.bag.Length; i++) {72 // InventoryField item = _playerDataFile.bag [i];73 // printItem (item, i);74 // }75 19 } 76 20 77 private static string getInvFieldName (InventoryField item)78 {79 ItemBase iBase = ItemBase.list [item.itemValue.type];80 string name = iBase.name;81 if (iBase.IsBlock ()) {82 ItemBlock iBlock = (ItemBlock)iBase;83 name = iBlock.GetItemName (item.itemValue);84 }85 return name;86 }87 21 88 private static void printItem (InventoryField item, int slot)89 {90 if (item.count > 0) {91 ItemBase iBase = ItemBase.list [item.itemValue.type];92 string name = iBase.name;93 if (iBase.IsBlock ()) {94 ItemBlock iBlock = (ItemBlock)iBase;95 name = iBlock.GetItemName (item.itemValue);96 }97 Log.Out (string.Format ("Slot {0:00}: {1:00} * {2}, blockinst={3}, meta={4}, type={5}, usetimes={6}",98 slot, item.count, name, item.itemValue.blockinst, item.itemValue.meta, item.itemValue.type, item.itemValue.usetimes)99 );100 }101 }102 22 } 103 23 } -
binary-improvements/7dtd-server-fixes/src/StateManager.cs
r142 r144 10 10 CommandExtensions.InitCommandExtensions (manager); 11 11 PersistentData.PersistentContainer.Load (); 12 PersistentData.PersistentContainer.Instance.players.Add("123", new AllocsFixes.PersistentData.KnownPlayers());13 12 } catch (Exception e) { 14 13 Log.Out ("Error in StateManager.Awake: " + e);
Note:
See TracChangeset
for help on using the changeset viewer.