public static void Disconnect(ClientInfo _cInfo) { try { EntityPlayer entityPlayer = (EntityPlayer)GameManager.Instance.World.GetEntity(_cInfo.entityId); if (entityPlayer != null) { if (_cInfo.entityId != -1) { Log.Out("Player {0} disconnected after {1} minutes", new object[] { GameUtils.SafeStringFormat(entityPlayer.EntityName), ((Time.timeSinceLevelLoad - entityPlayer.CreationTimeSinceLevelLoad) / 60f).ToCultureInvariantString("0.0") }); } } GC.Collect(); MemoryPools.Cleanup(); PersistentPlayerData persistentPlayerData = PersistentOperations.GetPersistentPlayerDataFromSteamId(_cInfo.playerId); if (persistentPlayerData != null) { persistentPlayerData.LastLogin = DateTime.Now; persistentPlayerData.EntityId = -1; } PersistentOperations.SavePersistentPlayerDataXML(); ConnectionManager.Instance.DisconnectClient(_cInfo, false); GameManager.Instance.World.aiDirector.RemoveEntity(entityPlayer); } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in BattleLogger.Disconnect: {0}.", e.Message)); } }
public override void Execute(List <string> _params, CommandSenderInfo _senderInfo) { try { if (_params.Count != 1) { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Wrong number of arguments, expected 1, found {0}", _params.Count)); return; } ClientInfo _cInfo = ConsoleHelper.ParseParamIdOrName(_params[0]); if (_cInfo != null) { string _phrase400; if (!Phrases.Dict.TryGetValue(400, out _phrase400)) { _phrase400 = "Reseting players profile."; } SdtdConsole.Instance.ExecuteSync(string.Format("kick {0} \"{1}\"", _cInfo.entityId, _phrase400), null); GameManager.Instance.World.aiDirector.RemoveEntity(PersistentOperations.GetEntityPlayer(_cInfo.playerId)); GC.Collect(); MemoryPools.Cleanup(); ResetProfileExec(_cInfo.playerId); } else if (_params[0].Length == 17) { int _id; if (int.TryParse(_params[0], out _id)) { if (PersistentOperations.GetPersistentPlayerDataFromSteamId(_params[0]) != null) { GC.Collect(); MemoryPools.Cleanup(); ResetProfileExec(_params[0]); } } else { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Player id {0} is not a valid integer", _params[0])); return; } } else { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Player id {0} is not a valid length. Offline players require using their 17 digit steam id", _params[0])); return; } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in ResetPlayerConsole.Execute: {0}", e.Message)); } }
public override void Execute(List <string> _params, CommandSenderInfo _senderInfo) { try { if (_params.Count != 1) { SingletonMonoBehaviour <SdtdConsole> .Instance.Output(string.Format("[SERVERTOOLS] Wrong number of arguments, expected 1, found '{0}'", _params.Count)); return; } ClientInfo cInfo = PersistentOperations.GetClientInfoFromNameOrId(_params[0]); if (cInfo != null) { Phrases.Dict.TryGetValue("ResetPlayer1", out string phrase); SingletonMonoBehaviour <SdtdConsole> .Instance.ExecuteSync(string.Format("kick {0} \"{1}\"", cInfo.CrossplatformId.CombinedString, phrase), null); GameManager.Instance.World.aiDirector.RemoveEntity(PersistentOperations.GetEntityPlayer(cInfo.entityId)); GC.Collect(); MemoryPools.Cleanup(); ResetProfileExec(cInfo.CrossplatformId.CombinedString); } else if (_params[0].Contains("_")) { PersistentPlayerData ppd = PersistentOperations.GetPersistentPlayerDataFromId(_params[0]); if (ppd != null) { GC.Collect(); MemoryPools.Cleanup(); ResetProfileExec(ppd.UserIdentifier.ReadablePlatformUserIdentifier); } else { Log.Out(string.Format("[SERVERTOOLS] Unable to find player data for id '{0}'", _params[0])); } } else { Log.Out(string.Format("[SERVERTOOLS] Unable to find player data for id '{0}'", _params[0])); } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in ResetPlayerConsole.Execute: {0}", e.Message)); } }
private static void Penalty(string _id) { try { PlayerDataFile _playerDataFile = PersistentOperations.GetPlayerDataFileFromSteamId(_id); if (_playerDataFile != null) { PersistentPlayerData _persistentPlayerData = PersistentOperations.GetPersistentPlayerDataFromSteamId(_id); if (_persistentPlayerData != null) { GC.Collect(); MemoryPools.Cleanup(); EntityBackpack entityBackpack = new EntityBackpack(); entityBackpack = EntityFactory.CreateEntity("Backpack".GetHashCode(), _playerDataFile.ecd.pos + Vector3.up * 2f) as EntityBackpack; entityBackpack.RefPlayerId = _playerDataFile.ecd.clientEntityId; entityBackpack.lootContainer = new TileEntityLootContainer(null); entityBackpack.lootContainer.SetUserAccessing(true); entityBackpack.lootContainer.SetEmpty(); entityBackpack.lootContainer.lootListIndex = entityBackpack.GetLootList(); entityBackpack.lootContainer.SetContainerSize(LootContainer.lootList[entityBackpack.GetLootList()].size, true); if (All || Bag) { for (int i = 0; i < _playerDataFile.bag.Length; i++) { if (!_playerDataFile.bag[i].IsEmpty()) { entityBackpack.lootContainer.AddItem(_playerDataFile.bag[i]); _playerDataFile.bag[i] = ItemStack.Empty.Clone(); } } } if (All || Belt) { for (int i = 0; i < _playerDataFile.inventory.Length; i++) { if (!_playerDataFile.inventory[i].IsEmpty()) { entityBackpack.lootContainer.AddItem(_playerDataFile.inventory[i]); _playerDataFile.inventory[i] = ItemStack.Empty.Clone(); } } } if (All || Equipment) { ItemValue[] _equipmentValues = _playerDataFile.equipment.GetItems(); for (int i = 0; i < _equipmentValues.Length; i++) { if (!_equipmentValues[i].IsEmpty()) { entityBackpack.lootContainer.AddItem(new ItemStack(_equipmentValues[i], 1)); } } if (!_playerDataFile.equipment.HasAnyItems()) { _playerDataFile.equipment = new Equipment(); } } _playerDataFile.droppedBackpackPosition = new Vector3i(_playerDataFile.ecd.pos); entityBackpack.lootContainer.bPlayerBackpack = true; entityBackpack.lootContainer.SetUserAccessing(false); entityBackpack.lootContainer.SetModified(); entityBackpack.entityId = -1; entityBackpack.RefPlayerId = _playerDataFile.ecd.clientEntityId; EntityCreationData entityCreationData = new EntityCreationData(entityBackpack); entityCreationData.entityName = string.Format(Localization.Get("playersBackpack", ""), _playerDataFile.ecd.entityName); entityCreationData.id = -1; entityCreationData.lootContainer = entityBackpack.lootContainer.Clone(); PersistentOperations.SavePlayerDataFile(_id, _playerDataFile); GameManager.Instance.RequestToSpawnEntityServer(entityCreationData); entityBackpack.OnEntityUnload(); BattleLogger.Players.Remove(_id); } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in BattleLogger.Penalty: {0}.", e.Message)); } }
public static bool FullServer(string _playerId, string _playerName, string _compatibilityVersion) { try { ulong _num; if (!Steam.Masterserver.Server.GameServerInitialized || !GameManager.Instance.gameStateManager.IsGameStarted() || GameStats.GetInt(EnumGameStats.GameState) == 2 || string.IsNullOrEmpty(_playerName) || string.IsNullOrEmpty(_playerId) || string.IsNullOrEmpty(_playerId) || !ulong.TryParse(_playerId, out _num) || !string.Equals(Constants.cCompatibilityVersion, _compatibilityVersion, StringComparison.Ordinal)) { return(true); } List <ClientInfo> list = PersistentOperations.ClientList(); for (int i = 0; i < list.Count; i++) { ClientInfo clientInfo = list[i]; if (clientInfo != null && clientInfo.playerId == _playerId) { return(true); } } ClientInfo _cInfoClientToKick = null; if (ReservedSlots.AdminCheck(_playerId)) { ClientInfo _cInfoReservedToKick = null; int _clientSession = int.MinValue; int _reservedSession = int.MinValue; List <string> _sessionList = new List <string>(PersistentOperations.Session.Keys); if (_sessionList == null) { return(true); } for (int i = 0; i < _sessionList.Count; i++) { string _player = _sessionList[i]; ClientInfo _cInfo2 = ConnectionManager.Instance.Clients.ForPlayerId(_player); if (_cInfo2 != null && _playerId != _cInfo2.playerId) { if (ReservedSlots.AdminCheck(_cInfo2.playerId)) { continue; } else if (ReservedSlots.ReservedCheck(_cInfo2.playerId)) { DateTime _dateTime; if (PersistentOperations.Session.TryGetValue(_cInfo2.playerId, out _dateTime)) { TimeSpan varTime = DateTime.Now - _dateTime; double fractionalMinutes = varTime.TotalMinutes; int _timepassed = (int)fractionalMinutes; if (_timepassed > _reservedSession) { _reservedSession = _timepassed; _cInfoReservedToKick = _cInfo2; } } } else { DateTime _dateTime; if (PersistentOperations.Session.TryGetValue(_cInfo2.playerId, out _dateTime)) { TimeSpan varTime = DateTime.Now - _dateTime; double fractionalMinutes = varTime.TotalMinutes; int _timepassed = (int)fractionalMinutes; if (_timepassed > _clientSession) { _clientSession = _timepassed; _cInfoClientToKick = _cInfo2; } } } } } if (_cInfoClientToKick != null) { API.PlayerDisconnected(_cInfoClientToKick, true); string _phrase20; if (!Phrases.Dict.TryGetValue(20, out _phrase20)) { _phrase20 = "{ServerResponseName}- The server is full. You were kicked by the reservation system to open a slot"; } _phrase20 = _phrase20.Replace("{ServerResponseName}", LoadConfig.Server_Response_Name); SdtdConsole.Instance.ExecuteSync(string.Format("kick {0} \"{1}\"", _cInfoClientToKick.playerId, _phrase20), (ClientInfo)null); EntityPlayer entityPlayer = (EntityPlayer)GameManager.Instance.World.GetEntity(_cInfoClientToKick.entityId); if (entityPlayer != null) { if (_cInfoClientToKick.entityId != -1) { Log.Out("Player {0} disconnected after {1} minutes", new object[] { GameUtils.SafeStringFormat(entityPlayer.EntityName), ((Time.timeSinceLevelLoad - entityPlayer.CreationTimeSinceLevelLoad) / 60f).ToCultureInvariantString("0.0") }); } entityPlayer.OnEntityUnload(); } GC.Collect(); MemoryPools.Cleanup(); PersistentPlayerData persistentPlayerData = PersistentOperations.GetPersistentPlayerData(_cInfoClientToKick.playerId); if (persistentPlayerData != null) { persistentPlayerData.LastLogin = DateTime.Now; persistentPlayerData.EntityId = -1; } PersistentOperations.SavePersistentPlayerDataXML(); GameManager.Instance.World.aiDirector.RemoveEntity(entityPlayer); GameManager.Instance.World.RemoveEntity(entityPlayer.entityId, EnumRemoveEntityReason.Unloaded); ConnectionManager.Instance.Clients.Remove(_cInfoClientToKick); return(true); } else if (_cInfoReservedToKick != null) { API.PlayerDisconnected(_cInfoReservedToKick, true); string _phrase20; if (!Phrases.Dict.TryGetValue(20, out _phrase20)) { _phrase20 = "{ServerResponseName}- The server is full. You were kicked by the reservation system to open a slot"; } _phrase20 = _phrase20.Replace("{ServerResponseName}", LoadConfig.Server_Response_Name); SdtdConsole.Instance.ExecuteSync(string.Format("kick {0} \"{1}\"", _cInfoReservedToKick.playerId, _phrase20), (ClientInfo)null); EntityPlayer entityPlayer = (EntityPlayer)GameManager.Instance.World.GetEntity(_cInfoReservedToKick.entityId); if (entityPlayer != null) { if (_cInfoReservedToKick.entityId != -1) { Log.Out("Player {0} disconnected after {1} minutes", new object[] { GameUtils.SafeStringFormat(entityPlayer.EntityName), ((Time.timeSinceLevelLoad - entityPlayer.CreationTimeSinceLevelLoad) / 60f).ToCultureInvariantString("0.0") }); } entityPlayer.OnEntityUnload(); } GC.Collect(); MemoryPools.Cleanup(); PersistentPlayerData persistentPlayerData = PersistentOperations.GetPersistentPlayerData(_cInfoReservedToKick.playerId); if (persistentPlayerData != null) { persistentPlayerData.LastLogin = DateTime.Now; persistentPlayerData.EntityId = -1; } PersistentOperations.SavePersistentPlayerDataXML(); GameManager.Instance.World.aiDirector.RemoveEntity(entityPlayer); GameManager.Instance.World.RemoveEntity(entityPlayer.entityId, EnumRemoveEntityReason.Unloaded); ConnectionManager.Instance.Clients.Remove(_cInfoReservedToKick); return(true); } } else if (ReservedSlots.ReservedCheck(_playerId)) { int _clientSession = int.MinValue; List <string> _sessionList = new List <string>(PersistentOperations.Session.Keys); if (_sessionList == null) { return(true); } for (int i = 0; i < _sessionList.Count; i++) { string _player = _sessionList[i]; ClientInfo _cInfo2 = ConnectionManager.Instance.Clients.ForPlayerId(_player); if (_cInfo2 != null && _playerId != _cInfo2.playerId) { if (ReservedSlots.AdminCheck(_cInfo2.playerId)) { continue; } else if (ReservedSlots.ReservedCheck(_cInfo2.playerId)) { continue; } else { DateTime _dateTime; if (PersistentOperations.Session.TryGetValue(_cInfo2.playerId, out _dateTime)) { TimeSpan varTime = DateTime.Now - _dateTime; double fractionalMinutes = varTime.TotalMinutes; int _timepassed = (int)fractionalMinutes; if (_timepassed > _clientSession) { _clientSession = _timepassed; _cInfoClientToKick = _cInfo2; } } } } } if (_cInfoClientToKick != null) { API.PlayerDisconnected(_cInfoClientToKick, true); string _phrase20; if (!Phrases.Dict.TryGetValue(20, out _phrase20)) { _phrase20 = "{ServerResponseName}- The server is full. You were kicked by the reservation system to open a slot"; } _phrase20 = _phrase20.Replace("{ServerResponseName}", LoadConfig.Server_Response_Name); SdtdConsole.Instance.ExecuteSync(string.Format("kick {0} \"{1}\"", _cInfoClientToKick.playerId, _phrase20), (ClientInfo)null); EntityPlayer entityPlayer = (EntityPlayer)GameManager.Instance.World.GetEntity(_cInfoClientToKick.entityId); if (entityPlayer != null) { if (_cInfoClientToKick.entityId != -1) { Log.Out("Player {0} disconnected after {1} minutes", new object[] { GameUtils.SafeStringFormat(entityPlayer.EntityName), ((Time.timeSinceLevelLoad - entityPlayer.CreationTimeSinceLevelLoad) / 60f).ToCultureInvariantString("0.0") }); } entityPlayer.OnEntityUnload(); } GC.Collect(); MemoryPools.Cleanup(); PersistentPlayerData persistentPlayerData = PersistentOperations.GetPersistentPlayerData(_cInfoClientToKick.playerId); if (persistentPlayerData != null) { persistentPlayerData.LastLogin = DateTime.Now; persistentPlayerData.EntityId = -1; } PersistentOperations.SavePersistentPlayerDataXML(); GameManager.Instance.World.aiDirector.RemoveEntity(entityPlayer); GameManager.Instance.World.RemoveEntity(entityPlayer.entityId, EnumRemoveEntityReason.Unloaded); ConnectionManager.Instance.Clients.Remove(_cInfoClientToKick); return(true); } } else if (ReservedSlots.Session_Time > 0) { int _session = int.MinValue; List <string> _sessionList = new List <string>(PersistentOperations.Session.Keys); if (_sessionList == null) { return(true); } for (int i = 0; i < _sessionList.Count; i++) { string _player = _sessionList[i]; ClientInfo _cInfo2 = ConnectionManager.Instance.Clients.ForPlayerId(_player); if (_cInfo2 != null && _playerId != _cInfo2.playerId) { if (ReservedSlots.AdminCheck(_cInfo2.playerId)) { continue; } else if (ReservedSlots.ReservedCheck(_cInfo2.playerId)) { continue; } else { DateTime _dateTime; if (PersistentOperations.Session.TryGetValue(_cInfo2.playerId, out _dateTime)) { TimeSpan varTime = DateTime.Now - _dateTime; double fractionalMinutes = varTime.TotalMinutes; int _timepassed = (int)fractionalMinutes; if (_timepassed >= ReservedSlots.Session_Time && _timepassed > _session) { _session = _timepassed; _cInfoClientToKick = _cInfo2; } } } } } if (_session > int.MinValue) { ReservedSlots.Kicked.Add(_cInfoClientToKick.playerId, DateTime.Now); API.PlayerDisconnected(_cInfoClientToKick, true); string _phrase20; if (!Phrases.Dict.TryGetValue(20, out _phrase20)) { _phrase20 = "{ServerResponseName}- The server is full. You were kicked by the reservation system to open a slot"; } _phrase20 = _phrase20.Replace("{ServerResponseName}", LoadConfig.Server_Response_Name); SdtdConsole.Instance.ExecuteSync(string.Format("kick {0} \"{1}\"", _cInfoClientToKick.playerId, _phrase20), (ClientInfo)null); EntityPlayer entityPlayer = (EntityPlayer)GameManager.Instance.World.GetEntity(_cInfoClientToKick.entityId); if (entityPlayer != null) { if (_cInfoClientToKick.entityId != -1) { Log.Out("Player {0} disconnected after {1} minutes", new object[] { GameUtils.SafeStringFormat(entityPlayer.EntityName), ((Time.timeSinceLevelLoad - entityPlayer.CreationTimeSinceLevelLoad) / 60f).ToCultureInvariantString("0.0") }); } entityPlayer.OnEntityUnload(); } GC.Collect(); MemoryPools.Cleanup(); PersistentPlayerData persistentPlayerData = PersistentOperations.GetPersistentPlayerData(_cInfoClientToKick.playerId); if (persistentPlayerData != null) { persistentPlayerData.LastLogin = DateTime.Now; persistentPlayerData.EntityId = -1; } PersistentOperations.SavePersistentPlayerDataXML(); GameManager.Instance.World.aiDirector.RemoveEntity(entityPlayer); GameManager.Instance.World.RemoveEntity(entityPlayer.entityId, EnumRemoveEntityReason.Unloaded); ConnectionManager.Instance.Clients.Remove(_cInfoClientToKick); return(true); } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in ReservedSlots.FullServer: {0}.", e.Message)); } return(true); }