public static void StartLotto() { System.Random rnd = new System.Random(); int _random = rnd.Next(0, LottoEntries.Count + 1); ClientInfo _winner = LottoEntries[_random]; int _winnings; if (LottoEntries.Count == 10) { _winnings = LottoValue * LottoEntries.Count + Bonus; } else { _winnings = LottoValue * LottoEntries.Count; } OpenLotto = false; LottoValue = 0; LottoEntries.Clear(); Wallet.AddCoinsToWallet(_winner.playerId, _winnings); Phrases.Dict.TryGetValue(230, out string _phrase230); _phrase230 = _phrase230.Replace("{PlayerName}", _winner.playerName); _phrase230 = _phrase230.Replace("{Value}", _winnings.ToString()); _phrase230 = _phrase230.Replace("{CoinName}", Wallet.Coin_Name); ChatHook.ChatMessage(null, Config.Chat_Response_Color + _phrase230 + "[-]", -1, Config.Server_Response_Name, EChatType.Global, null); }
public static void StartLotto() { System.Random rnd = new System.Random(); int _random = rnd.Next(0, LottoEntries.Count + 1); ClientInfo _winner = LottoEntries[_random]; int _winnings; if (LottoEntries.Count == 10) { _winnings = LottoValue * LottoEntries.Count + Bonus; } else { _winnings = LottoValue * LottoEntries.Count; } OpenLotto = false; LottoValue = 0; LottoEntries.Clear(); Wallet.AddCoinsToWallet(_winner.playerId, _winnings); string _phrase544; if (!Phrases.Dict.TryGetValue(544, out _phrase544)) { _phrase544 = "Winner! {PlayerName} has won the lottery and received {Value} {CoinName}."; } _phrase544 = _phrase544.Replace("{PlayerName}", _winner.playerName); _phrase544 = _phrase544.Replace("{Value}", _winnings.ToString()); _phrase544 = _phrase544.Replace("{CoinName}", Wallet.Coin_Name); ChatHook.ChatMessage(null, LoadConfig.Chat_Response_Color + _phrase544 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Global, null); }
private static void EntityKilled(Entity _entity1, Entity _entity2) { try { if (_entity1 != null && _entity2 != null && _entity2.IsClientControlled()) { if (Wallet.IsEnabled && Wallet.Zombie_Kills > 0) { string _tags = _entity1.EntityClass.Tags.ToString(); if (_tags.Contains("zombie") || (_tags.Contains("hostile") && _tags.Contains("animal"))) { ClientInfo _cInfo = ConnectionManager.Instance.Clients.ForEntityId(_entity2.entityId); if (_cInfo != null) { Wallet.AddCoinsToWallet(_cInfo.playerId, Wallet.Zombie_Kills); } } } if (BloodmoonWarrior.IsEnabled && BloodmoonWarrior.BloodmoonStarted && BloodmoonWarrior.WarriorList.Contains(_entity2.entityId)) { int _killedZ; BloodmoonWarrior.KilledZombies.TryGetValue(_entity2.entityId, out _killedZ); BloodmoonWarrior.KilledZombies[_entity2.entityId] = _killedZ + 1; } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in API.EntityKilled: {0}.", e.Message)); } }
public static void BankToWalletWithdraw(ClientInfo _cInfo, string _amount) { int _value; if (int.TryParse(_amount, out _value)) { int _bank = GetCurrentBank(_cInfo.playerId); if (_bank >= _value) { Wallet.AddCoinsToWallet(_cInfo.playerId, _value); SubtractCoinsFromBank(_cInfo.playerId, _value); string _message = " you have received the {Name} from your bank. It has gone to your wallet."; _message = _message.Replace("{Name}", Wallet.Coin_Name); ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + _message + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); using (StreamWriter sw = new StreamWriter(filepath, true)) { sw.WriteLine(string.Format("{0}: {1} has removed {2} from their bank account and it has been placed into their wallet.", DateTime.Now, _cInfo.playerName, _value)); sw.WriteLine(); sw.Flush(); sw.Close(); } } else { ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + " your bank account does not have enough to withdraw that value.[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } } else { ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + " you input an invalid integer. Type " + ChatHook.Command_Private + Command98 + " #.", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } }
public static void BuyAuction(ClientInfo _cInfo, int _purchase, int _price) { if (AuctionItems.TryGetValue(_purchase, out string _steamId)) { if (PersistentContainer.Instance.Players[_steamId].Auction != null && PersistentContainer.Instance.Players[_steamId].Auction.Count > 0) { PersistentContainer.Instance.Players[_steamId].Auction.TryGetValue(_purchase, out ItemDataSerializable _itemData); ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_itemData.name, false).type, false); if (_itemValue != null) { _itemValue.UseTimes = _itemData.useTimes; _itemValue.Quality = _itemData.quality; World world = GameManager.Instance.World; EntityItem entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData { entityClass = EntityClass.FromString("item"), id = EntityFactory.nextEntityID++, itemStack = new ItemStack(_itemValue, _itemData.count), pos = world.Players.dict[_cInfo.entityId].position, rot = new Vector3(20f, 0f, 20f), lifetime = 60f, belongsPlayerId = _cInfo.entityId }); world.SpawnEntityInWorld(entityItem); _cInfo.SendPackage(NetPackageManager.GetPackage <NetPackageEntityCollect>().Setup(entityItem.entityId, _cInfo.entityId)); world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Despawned); AuctionItems.Remove(_purchase); PersistentContainer.Instance.Players[_steamId].Auction.Remove(_purchase); PersistentContainer.Instance.AuctionPrices.Remove(_purchase); PersistentContainer.DataChange = true; Wallet.SubtractCoinsFromWallet(_cInfo.playerId, _price); float _fee = _price * ((float)Tax / 100); int _adjustedPrice = _price - (int)_fee; Wallet.AddCoinsToWallet(_steamId, _adjustedPrice); string _playerName = PersistentOperations.GetPlayerDataFileFromSteamId(_steamId).ecd.entityName; using (StreamWriter sw = new StreamWriter(filepath, true, Encoding.UTF8)) { sw.WriteLine(string.Format("{0}: {1} {2} has purchased auction entry {3}, profits went to steam id {4} {5}", DateTime.Now, _cInfo.playerId, _cInfo.playerName, _purchase, _steamId, _playerName)); sw.WriteLine(); sw.Flush(); sw.Close(); } Phrases.Dict.TryGetValue(629, out string _phrase629); _phrase629 = _phrase629.Replace("{Count}", _itemData.count.ToString()); _phrase629 = _phrase629.Replace("{ItemName}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.GetItemName()); _phrase629 = _phrase629.Replace("{Value}", _price.ToString()); _phrase629 = _phrase629.Replace("{CoinName}", Wallet.Coin_Name); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase629 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); ClientInfo _cInfo2 = ConnectionManager.Instance.Clients.ForPlayerId(_steamId); if (_cInfo2 != null) { Phrases.Dict.TryGetValue(630, out string _phrase630); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase630 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); } } } } }
public static void BankToWalletWithdraw(ClientInfo _cInfo, string _amount) { try { int _value; if (int.TryParse(_amount, out _value)) { int _bank = GetCurrentBank(_cInfo.playerId); if (_bank >= _value) { Wallet.AddCoinsToWallet(_cInfo.playerId, _value); SubtractCoinsFromBank(_cInfo.playerId, _value); using (StreamWriter sw = new StreamWriter(filepath, true)) { sw.WriteLine(string.Format("{0}: {1} has removed {2} from their bank account and it has been placed into their wallet.", DateTime.Now, _cInfo.playerName, _value)); sw.WriteLine(); sw.Flush(); sw.Close(); } Phrases.Dict.TryGetValue(657, out string _phrase657); _phrase657 = _phrase657.Replace("{Name}", Wallet.Coin_Name); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase657 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); } else { Phrases.Dict.TryGetValue(658, out string _phrase658); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase658 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); } } else { Phrases.Dict.TryGetValue(659, out string _phrase659); _phrase659 = _phrase659.Replace("{CommandPrivate}", ChatHook.Command_Private); _phrase659 = _phrase659.Replace("{Command98}", Command98); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase659 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in Bank.BankToWalletWithdraw: {0}", e.Message)); } }
public static void PlayerDisconnected(ClientInfo _cInfo, bool _bShutdown) { try { Log.Out("[SERVERTOOLS] Player detected disconnecting"); if (_cInfo != null && !string.IsNullOrEmpty(_cInfo.playerId) && _cInfo.entityId != -1) { if (BattleLogger.IsEnabled && BattleLogger.LogFound && !_bShutdown && !StopServer.StopServerCountingDown && !StopServer.Shutdown && BattleLogger.Players.ContainsKey(_cInfo.playerId)) { BattleLogger.BattleLog(_cInfo); } if (FriendTeleport.Dict.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict.Remove(_cInfo.entityId); FriendTeleport.Dict1.Remove(_cInfo.entityId); } if (Zones.ZoneExit.ContainsKey(_cInfo.entityId)) { Zones.ZoneExit.Remove(_cInfo.entityId); } if (Zones.Forgive.ContainsKey(_cInfo.entityId)) { Zones.Forgive.Remove(_cInfo.entityId); } if (Zones.Victim.ContainsKey(_cInfo.entityId)) { Zones.Victim.Remove(_cInfo.entityId); } if (FriendTeleport.Dict.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict.Remove(_cInfo.entityId); } if (FriendTeleport.Dict1.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict1.Remove(_cInfo.entityId); } if (Travel.Flag.Contains(_cInfo.entityId)) { Travel.Flag.Remove(_cInfo.entityId); } if (Wallet.IsEnabled && Wallet.Session_Bonus > 0) { DateTime _time; if (PersistentOperations.Session.TryGetValue(_cInfo.playerId, out _time)) { TimeSpan varTime = DateTime.Now - _time; double fractionalMinutes = varTime.TotalMinutes; int _timepassed = (int)fractionalMinutes; if (_timepassed > 60) { int _sessionBonus = _timepassed / 60 * Wallet.Session_Bonus; if (_sessionBonus > 0) { Wallet.AddCoinsToWallet(_cInfo.playerId, _sessionBonus); } } int _timePlayed = PersistentContainer.Instance.Players[_cInfo.playerId].TotalTimePlayed; PersistentContainer.Instance.Players[_cInfo.playerId].TotalTimePlayed = _timePlayed + _timepassed; PersistentContainer.Instance.Save(); } } if (PersistentOperations.Session.ContainsKey(_cInfo.playerId)) { PersistentOperations.Session.Remove(_cInfo.playerId); } if (Bank.TransferId.ContainsKey(_cInfo.playerId)) { Bank.TransferId.Remove(_cInfo.playerId); } if (Zones.reminder.ContainsKey(_cInfo.entityId)) { Zones.reminder.Remove(_cInfo.entityId); } if (BloodmoonWarrior.WarriorList.Contains(_cInfo.entityId)) { BloodmoonWarrior.WarriorList.Remove(_cInfo.entityId); } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in API.PlayerDisconnected: {0}.", e.Message)); } }
private static bool GameMessage(ClientInfo _cInfo, EnumGameMessages _type, string _msg, string _mainName, bool _localizeMain, string _secondaryName, bool _localizeSecondary) { try { if (_type == EnumGameMessages.EntityWasKilled && _cInfo != null) { EntityPlayer _player1 = GameManager.Instance.World.Players.dict[_cInfo.entityId]; if (_player1 != null) { bool _notice = false; if (!string.IsNullOrEmpty(_secondaryName) && _mainName != _secondaryName) { ClientInfo _cInfo2 = ConsoleHelper.ParseParamIdOrName(_secondaryName); if (_cInfo2 != null) { EntityPlayer _player2 = GameManager.Instance.World.Players.dict[_cInfo2.entityId]; if (_player2 != null) { if (KillNotice.IsEnabled && _player2.IsAlive()) { string _holdingItem = _player2.inventory.holdingItem.Name; if (!string.IsNullOrEmpty(_holdingItem)) { ItemValue _itemValue = ItemClass.GetItem(_holdingItem, true); if (_itemValue.type != ItemValue.None.type) { _holdingItem = _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.GetItemName(); KillNotice.Notice(_cInfo, _cInfo2, _holdingItem); _notice = true; } } } if (Zones.IsEnabled) { Zones.Check(_cInfo, _cInfo2); } if (Bounties.IsEnabled) { Bounties.PlayerKilled(_player1, _player2, _cInfo, _cInfo2); } if (Wallet.IsEnabled) { if (Wallet.PVP && Wallet.Player_Kills > 0) { Wallet.AddCoinsToWallet(_cInfo2.playerId, Wallet.Player_Kills); } else if (Wallet.Player_Kills > 0) { Wallet.SubtractCoinsFromWallet(_cInfo2.playerId, Wallet.Player_Kills); } } } } } if (DeathSpot.IsEnabled) { DeathSpot.PlayerKilled(_player1); } if (Event.Open && Event.PlayersTeam.ContainsKey(_cInfo.playerId)) { string _sql = string.Format("UPDATE Players SET eventReturn = 'true' WHERE steamid = '{0}'", _cInfo.playerId); SQL.FastQuery(_sql, "Players"); } if (_notice) { return(false); } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in API.GameMessage: {0}.", e.Message)); } return(true); }
public static void PlayerDisconnected(ClientInfo _cInfo, bool _bShutdown) { try { if (_cInfo != null) { if (_bShutdown) { Log.Out("[SERVERTOOLS] Server shutdown, player disconnected."); } else if (BattleLogger.IsEnabled && BattleLogger.Exit.Contains(_cInfo.playerId)) { string _ip = _cInfo.ip; if (_ip.Contains(":")) { _ip = _ip.Split(':').First(); } Timers.BattleLogDelay(_cInfo, _ip); Log.Out("[SERVERTOOLS] Player disconnected"); } else { Log.Out("[SERVERTOOLS] Player disconnected"); } if (!string.IsNullOrEmpty(_cInfo.playerId) && _cInfo.entityId != -1) { if (FriendTeleport.Dict.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict.Remove(_cInfo.entityId); FriendTeleport.Dict1.Remove(_cInfo.entityId); } if (FriendTeleport.Dict.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict.Remove(_cInfo.entityId); } if (FriendTeleport.Dict1.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict1.Remove(_cInfo.entityId); } if (Wallet.IsEnabled && Wallet.Session_Bonus > 0) { if (PersistentOperations.Session.TryGetValue(_cInfo.playerId, out DateTime _time)) { TimeSpan varTime = DateTime.Now - _time; double fractionalMinutes = varTime.TotalMinutes; int _timepassed = (int)fractionalMinutes; if (_timepassed > 60) { int _sessionBonus = _timepassed / 60 * Wallet.Session_Bonus; if (_sessionBonus > 0) { Wallet.AddCoinsToWallet(_cInfo.playerId, _sessionBonus); } } int _timePlayed = PersistentContainer.Instance.Players[_cInfo.playerId].TotalTimePlayed; PersistentContainer.Instance.Players[_cInfo.playerId].TotalTimePlayed = _timePlayed + _timepassed; PersistentContainer.Instance.Save(); } } if (PersistentOperations.Session.ContainsKey(_cInfo.playerId)) { PersistentOperations.Session.Remove(_cInfo.playerId); } if (PersistentOperations.PvEViolations.ContainsKey(_cInfo.entityId)) { PersistentOperations.PvEViolations.Remove(_cInfo.entityId); } if (Bank.TransferId.ContainsKey(_cInfo.playerId)) { Bank.TransferId.Remove(_cInfo.playerId); } if (Zones.ZoneInfo.ContainsKey(_cInfo.entityId)) { Zones.ZoneInfo.Remove(_cInfo.entityId); } if (Zones.Forgive.ContainsKey(_cInfo.entityId)) { Zones.Forgive.Remove(_cInfo.entityId); } if (Zones.Victim.ContainsKey(_cInfo.entityId)) { Zones.Victim.Remove(_cInfo.entityId); } if (Zones.Reminder.ContainsKey(_cInfo.entityId)) { Zones.Reminder.Remove(_cInfo.entityId); } if (Zones.ZonePvE.Contains(_cInfo.entityId)) { Zones.ZonePvE.Remove(_cInfo.entityId); } if (BloodmoonWarrior.WarriorList.Contains(_cInfo.playerId)) { BloodmoonWarrior.WarriorList.Remove(_cInfo.playerId); } if (BattleLogger.Exit.Contains(_cInfo.playerId)) { BattleLogger.Exit.Remove(_cInfo.playerId); } if (BattleLogger.ExitPos.ContainsKey(_cInfo.playerId)) { BattleLogger.ExitPos.Remove(_cInfo.playerId); } if (KillNotice.Damage.ContainsKey(_cInfo.entityId)) { KillNotice.Damage.Remove(_cInfo.entityId); } if (PlayerChecks.Flag.ContainsKey(_cInfo.entityId)) { PlayerChecks.Flag.Remove(_cInfo.entityId); } if (Teleportation.Teleporting.Contains(_cInfo.entityId)) { Teleportation.Teleporting.Remove(_cInfo.entityId); } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in API.PlayerDisconnected: {0}", e.Message)); } }
private static bool GameMessage(ClientInfo _cInfo, EnumGameMessages _type, string _msg, string _mainName, bool _localizeMain, string _secondaryName, bool _localizeSecondary) { try { if (_type == EnumGameMessages.EntityWasKilled && _cInfo != null && GameManager.Instance.World.Players.dict.ContainsKey(_cInfo.entityId)) { EntityPlayer _player = GameManager.Instance.World.Players.dict[_cInfo.entityId]; if (_player != null) { if (DeathSpot.IsEnabled) { DeathSpot.PlayerKilled(_player); } if (!string.IsNullOrEmpty(_secondaryName) && !string.IsNullOrEmpty(_mainName) && _mainName != _secondaryName) { ClientInfo _cInfo2 = ConsoleHelper.ParseParamIdOrName(_secondaryName); if (_cInfo2 != null && GameManager.Instance.World.Players.dict.ContainsKey(_cInfo2.entityId)) { EntityPlayer _player2 = GameManager.Instance.World.Players.dict[_cInfo2.entityId]; if (_player2 != null) { if (Bounties.IsEnabled) { Bounties.PlayerKilled(_player, _player2, _cInfo, _cInfo2); } if (Wallet.IsEnabled) { if (Wallet.PVP && Wallet.Player_Kills > 0) { Wallet.AddCoinsToWallet(_cInfo2.playerId, Wallet.Player_Kills); } else if (Wallet.Player_Kills > 0) { Wallet.SubtractCoinsFromWallet(_cInfo2.playerId, Wallet.Player_Kills); } } if (KillNotice.IsEnabled && _player2.IsAlive()) { string _holdingItem = _player2.inventory.holdingItem.Name; if (!string.IsNullOrEmpty(_holdingItem)) { ItemValue _itemValue = ItemClass.GetItem(_holdingItem, true); if (_itemValue.type != ItemValue.None.type) { _holdingItem = _itemValue.ItemClass.GetItemName(); KillNotice.Exec(_cInfo, _player, _cInfo2, _player2, _holdingItem); return(false); } } } } } } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in API.GameMessage: {0}", e.Message)); } return(true); }
public override void Execute(List <string> _params, CommandSenderInfo _senderInfo) { try { if (_params.Count < 1 || _params.Count > 2) { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Wrong number of arguments, expected 1 or 2, found {0}", _params.Count)); return; } if (_params[0].ToLower().Equals("off")) { if (Wallet.IsEnabled) { Wallet.IsEnabled = false; Config.WriteXml(); SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Wallet has been set to off")); return; } else { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Wallet is already off")); return; } } else if (_params[0].ToLower().Equals("on")) { if (!Wallet.IsEnabled) { Wallet.IsEnabled = true; Config.WriteXml(); SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Wallet has been set to on")); return; } else { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Wallet is already on")); return; } } else if (_params[0].ToLower().Equals("all")) { if (!int.TryParse(_params[1], out int _adjustCoins)) { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Can not adjust wallet. Value {0} is invalid", _params[1])); } else { List <ClientInfo> _cInfoList = PersistentOperations.ClientList(); for (int i = 0; i < _cInfoList.Count; i++) { ClientInfo _cInfo = _cInfoList[i]; if (_cInfo != null) { if (_adjustCoins >= 0) { Wallet.AddCoinsToWallet(_cInfo.playerId, _adjustCoins); SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Added {0} {1} to player id {2} wallet", _params[1], Wallet.Coin_Name, _params[0])); } else { Wallet.SubtractCoinsFromWallet(_cInfo.playerId, _adjustCoins); SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Subtracted {0} {1} from player id {2} wallet", _params[1], Wallet.Coin_Name, _params[0])); } } } } } else if (_params.Count == 2) { if (_params[0].Length < 1 || _params[0].Length > 17) { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Can not adjust wallet: Invalid Id {0}", _params[0])); return; } if (_params[1].Length < 1 || _params[1].Length > 5) { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Can not adjust wallet. Value {0} is invalid", _params[1])); return; } if (!int.TryParse(_params[1], out int _adjustCoins)) { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Can not adjust wallet. Value {0} is invalid", _params[1])); } else { PersistentPlayer p = PersistentContainer.Instance.Players[_params[0]]; if (p != null) { Wallet.AddCoinsToWallet(_params[0], _adjustCoins); if (_adjustCoins >= 0) { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Added {0} {1} to player id {2} wallet", _params[1], Wallet.Coin_Name, _params[0])); } else { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Subtracted {0} {1} from player id {2} wallet", _params[1], Wallet.Coin_Name, _params[0])); } } else { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Player id not found: {0}", _params[0])); } } } else if (_params.Count == 1) { if (_params[0].Length < 1 || _params[0].Length > 17) { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Can not check wallet value: Invalid Id {0}", _params[0])); return; } int _currentWallet = Wallet.GetCurrentCoins(_params[0]); string _playerName = PersistentContainer.Instance.Players[_params[0]].PlayerName; if (string.IsNullOrEmpty(_playerName)) { _playerName = "Unknown"; } SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Player with id {0}, named {1}, has a wallet value of: {2}", _params[0], _playerName, _currentWallet)); } else { SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] Invalid argument {0}", _params[0])); } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in WalletConsole.Execute: {0}", e.Message)); } }
private static bool GameMessage(ClientInfo _cInfo, EnumGameMessages _type, string _msg, string _mainName, bool _localizeMain, string _secondaryName, bool _localizeSecondary) { try { if (_type == EnumGameMessages.EntityWasKilled && _cInfo != null && GameManager.Instance.World.Players.dict.ContainsKey(_cInfo.entityId)) { EntityPlayer _player = GameManager.Instance.World.Players.dict[_cInfo.entityId]; if (_player != null) { if (PlayerChecks.FlyEnabled && PlayerChecks.Movement.ContainsKey(_cInfo.entityId)) { PlayerChecks.Movement.Remove(_cInfo.entityId); } if (Died.IsEnabled) { Died.PlayerKilled(_player); } if (KillNotice.IsEnabled) { if (KillNotice.Zombie_Kills && string.IsNullOrEmpty(_secondaryName)) { List <Entity> Entities = GameManager.Instance.World.Entities.list; for (int i = 0; i < Entities.Count; i++) { EntityAlive _entityAlive = Entities[i] as EntityAlive; if (_entityAlive != null && _entityAlive.GetAttackTarget() == _player && _entityAlive.entityId != _player.entityId) { if (KillNotice.Show_Level) { Phrases.Dict.TryGetValue(545, out string _phrase545); _phrase545 = _phrase545.Replace("{PlayerName}", _cInfo.playerName); _phrase545 = _phrase545.Replace("{Level}", _player.Progression.Level.ToString()); _phrase545 = _phrase545.Replace("{ZombieName}", _entityAlive.EntityName); ChatHook.ChatMessage(null, Config.Chat_Response_Color + _phrase545 + "[-]", -1, Config.Server_Response_Name, EChatType.Global, null); } else { Phrases.Dict.TryGetValue(546, out string _phrase546); _phrase546 = _phrase546.Replace("{PlayerName}", _cInfo.playerName); _phrase546 = _phrase546.Replace("{ZombieName}", _entityAlive.EntityName); ChatHook.ChatMessage(null, Config.Chat_Response_Color + _phrase546 + "[-]", -1, Config.Server_Response_Name, EChatType.Global, null); } } } } else if (KillNotice.PvP && !string.IsNullOrEmpty(_secondaryName) && _mainName != _secondaryName) { ClientInfo _cInfo2 = ConsoleHelper.ParseParamIdOrName(_secondaryName); if (_cInfo2 != null && GameManager.Instance.World.Players.dict.ContainsKey(_cInfo2.entityId)) { EntityPlayer _player2 = GameManager.Instance.World.Players.dict[_cInfo2.entityId]; if (_player2 != null) { if (KillNotice.IsEnabled && _player2.IsAlive()) { string _holdingItem = _player2.inventory.holdingItem.GetItemName(); if (!string.IsNullOrEmpty(_holdingItem)) { ItemValue _itemValue = ItemClass.GetItem(_holdingItem, true); if (_itemValue.type != ItemValue.None.type) { KillNotice.Exec(_cInfo, _player, _cInfo2, _player2, _holdingItem); return(false); } } } if (Wallet.IsEnabled) { if (Wallet.PVP && Wallet.Player_Kills > 0) { Wallet.AddCoinsToWallet(_cInfo2.playerId, Wallet.Player_Kills); } else if (Wallet.Player_Kills > 0) { Wallet.SubtractCoinsFromWallet(_cInfo2.playerId, Wallet.Player_Kills); } } if (Bounties.IsEnabled) { Bounties.PlayerKilled(_player, _player2, _cInfo, _cInfo2); } } } } } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in API.GameMessage: {0}", e.Message)); } return(true); }
public static void BuyAuction(ClientInfo _cInfo, int _purchase) { string _steamId; if (AuctionItems.TryGetValue(_purchase, out _steamId)) { int _auctionCount = PersistentContainer.Instance.Players[_steamId].AuctionItemCount; string _auctionName = PersistentContainer.Instance.Players[_steamId].AuctionItemName; int _auctionQuality = PersistentContainer.Instance.Players[_steamId].AuctionItemQuality; int _auctionPrice = PersistentContainer.Instance.Players[_steamId].AuctionItemPrice; ItemValue itemValue = ItemClass.GetItem(_auctionName, false); if (itemValue.type == ItemValue.None.type) { Log.Out(string.Format("Could not find itemValue for {0}", _auctionName)); return; } else { itemValue = new ItemValue(ItemClass.GetItem(_auctionName).type, _auctionQuality, _auctionQuality, false, null, 0); } World world = GameManager.Instance.World; var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData { entityClass = EntityClass.FromString("item"), id = EntityFactory.nextEntityID++, itemStack = new ItemStack(itemValue, _auctionCount), pos = world.Players.dict[_cInfo.entityId].position, rot = new Vector3(20f, 0f, 20f), lifetime = 60f, belongsPlayerId = _cInfo.entityId }); world.SpawnEntityInWorld(entityItem); _cInfo.SendPackage(NetPackageManager.GetPackage <NetPackageEntityCollect>().Setup(entityItem.entityId, _cInfo.entityId)); world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Killed); Wallet.SubtractCoinsFromWallet(_cInfo.playerId, _auctionPrice); string _message = " you have purchased {Count} {ItemName} from the auction for {Value} {CoinName}."; _message = _message.Replace("{Count}", _auctionCount.ToString()); _message = _message.Replace("{ItemName}", _auctionName); _message = _message.Replace("{Value}", _auctionPrice.ToString()); _message = _message.Replace("{CoinName}", Wallet.Coin_Name); ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + _message + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); double _percent = _auctionPrice * 0.05; int _newCoin2 = _auctionPrice - (int)_percent; AuctionItems.Remove(_purchase); PersistentContainer.Instance.Players[_steamId].AuctionId = 0; PersistentContainer.Instance.Players[_steamId].AuctionItemName = ""; PersistentContainer.Instance.Players[_steamId].AuctionItemCount = 0; PersistentContainer.Instance.Players[_steamId].AuctionItemQuality = 0; PersistentContainer.Instance.Players[_steamId].AuctionItemPrice = 0; PersistentContainer.Instance.Players[_steamId].AuctionSellDate = DateTime.Now; PersistentContainer.Instance.Save(); Wallet.AddCoinsToWallet(_steamId, _newCoin2); ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + " seller has received the funds in their wallet.[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); ClientInfo _cInfo2 = ConnectionManager.Instance.Clients.ForPlayerId(_steamId); if (_cInfo2 != null) { ChatHook.ChatMessage(_cInfo2, LoadConfig.Chat_Response_Color + _cInfo2.playerName + LoadConfig.Chat_Response_Color + " your auction item was purchased and the value placed in your wallet.[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } using (StreamWriter sw = new StreamWriter(filepath, true)) { sw.WriteLine(string.Format("{0}: {1} has purchased auction entry {2}, profits went to steam id {3}", DateTime.Now, _cInfo.playerName, _purchase, _steamId)); sw.WriteLine(); sw.Flush(); sw.Close(); } } }
public override void Execute(List <string> _params, CommandSenderInfo _senderInfo) { try { if (_params.Count < 1 || _params.Count > 2) { SdtdConsole.Instance.Output(string.Format("Wrong number of arguments, expected 1 or 2, found {0}", _params.Count)); return; } if (_params[0].ToLower().Equals("off")) { Wallet.IsEnabled = false; LoadConfig.WriteXml(); SdtdConsole.Instance.Output(string.Format("Wallet has been set to off")); return; } else if (_params[0].ToLower().Equals("on")) { Wallet.IsEnabled = true; LoadConfig.WriteXml(); SdtdConsole.Instance.Output(string.Format("Wallet has been set to on")); return; } else if (_params.Count == 2) { if (_params[1].Length < 1 || _params[1].Length > 5) { SdtdConsole.Instance.Output(string.Format("Can not adjust wallet. Value {0} is invalid", _params[1])); return; } int _adjustCoins; if (!int.TryParse(_params[1], out _adjustCoins)) { SdtdConsole.Instance.Output(string.Format("Can not adjust wallet. Value {0} is invalid", _params[1])); return; } else { string _steamid = SQL.EscapeString(_params[0]); string _sql = string.Format("SELECT playerSpentCoins FROM Players WHERE steamid = '{0}'", _steamid); DataTable _result = SQL.TQuery(_sql); if (_result.Rows.Count != 0) { Wallet.AddCoinsToWallet(_steamid, _adjustCoins); if (_adjustCoins >= 0) { SdtdConsole.Instance.Output(string.Format("Added {0} {1} to player id {2} wallet", _params[1], Wallet.Coin_Name, _steamid)); } else { SdtdConsole.Instance.Output(string.Format("Subtracted {0} {1} from player id {2} wallet", _params[1], Wallet.Coin_Name, _steamid)); } } else { SdtdConsole.Instance.Output(string.Format("Player id not found: {0}", _steamid)); } _result.Dispose(); } } else if (_params.Count == 1) { string _steamid = SQL.EscapeString(_params[0]); string _sql = string.Format("SELECT playerSpentCoins, zkills, kills, deaths FROM Players WHERE steamid = '{0}'", _steamid); DataTable _result = SQL.TQuery(_sql); if (_result.Rows.Count != 0) { int currentCoins; World world = GameManager.Instance.World; int _playerSpentCoins; int _zkills; int _kills; int _deaths; int.TryParse(_result.Rows[0].ItemArray.GetValue(0).ToString(), out _playerSpentCoins); int.TryParse(_result.Rows[0].ItemArray.GetValue(1).ToString(), out _zkills); int.TryParse(_result.Rows[0].ItemArray.GetValue(2).ToString(), out _kills); int.TryParse(_result.Rows[0].ItemArray.GetValue(3).ToString(), out _deaths); int gameMode = world.GetGameMode(); if (gameMode == 7) { currentCoins = (_zkills * Wallet.Zombie_Kills) + (_kills * Wallet.Player_Kills) - (_deaths * Wallet.Deaths) + _playerSpentCoins; } else { currentCoins = (_zkills * Wallet.Zombie_Kills) - (_deaths * Wallet.Deaths) + _playerSpentCoins; } SdtdConsole.Instance.Output(string.Format("Wallet for id {0}: {1} {2}", _params[0], currentCoins, Wallet.Coin_Name)); return; } else { SdtdConsole.Instance.Output(string.Format("Player id not found: {0}", _steamid)); } _result.Dispose(); } else { SdtdConsole.Instance.Output(string.Format("Invalid argument {0}.", _params[0])); } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in WalletConsole.Run: {0}.", e)); } }
public static void BuyAuction(ClientInfo _cInfo, int _purchase) { string _sql = string.Format("SELECT * FROM Auction WHERE auctionid = {0}", _purchase); DataTable _result = SQL.TQuery(_sql); string _steamid = _result.Rows[0].ItemArray.GetValue(1).ToString(); string _itemName = _result.Rows[0].ItemArray.GetValue(2).ToString(); int _itemCount; int.TryParse(_result.Rows[0].ItemArray.GetValue(3).ToString(), out _itemCount); int _quality; int.TryParse(_result.Rows[0].ItemArray.GetValue(4).ToString(), out _quality); int _itemPrice; int.TryParse(_result.Rows[0].ItemArray.GetValue(5).ToString(), out _itemPrice); ItemValue itemValue = ItemClass.GetItem(_itemName, true); if (itemValue.type == ItemValue.None.type) { Log.Out(string.Format("Could not find itemValue for {0}", _itemName)); return; } else { itemValue = new ItemValue(ItemClass.GetItem(_itemName).type, _quality, _quality, true); } World world = GameManager.Instance.World; var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData { entityClass = EntityClass.FromString("item"), id = EntityFactory.nextEntityID++, itemStack = new ItemStack(itemValue, _itemCount), pos = world.Players.dict[_cInfo.entityId].position, rot = new Vector3(20f, 0f, 20f), lifetime = 60f, belongsPlayerId = _cInfo.entityId }); world.SpawnEntityInWorld(entityItem); _cInfo.SendPackage(new NetPackageEntityCollect(entityItem.entityId, _cInfo.entityId)); world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Killed); Wallet.SubtractCoinsFromWallet(_cInfo.playerId, _itemPrice); string _message = "you have purchased {Count} {ItemName} from the auction for {Value} {CoinName}."; _message = _message.Replace("{Count}", _itemCount.ToString()); _message = _message.Replace("{ItemName}", _itemName); _message = _message.Replace("{Value}", _itemPrice.ToString()); _message = _message.Replace("{CoinName}", Wallet.Coin_Name); ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + _message + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null); double _percent = _itemPrice * 0.05; int _newCoin2 = _itemPrice - (int)_percent; _sql = string.Format("DELETE FROM Auction WHERE auctionid = {0}", _purchase); SQL.FastQuery(_sql); Wallet.AddCoinsToWallet(_steamid, _newCoin2); ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + ", seller has received the funds in their wallet.[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null); ClientInfo _cInfo1 = ConnectionManager.Instance.Clients.ForPlayerId(_steamid); if (_cInfo1 != null) { ChatHook.ChatMessage(_cInfo1, LoadConfig.Chat_Response_Color + _cInfo1.playerName + ", your auction item was purchased and the value placed in your wallet.[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } using (StreamWriter sw = new StreamWriter(filepath, true)) { sw.WriteLine(string.Format("{0}: {1} has purchased auction entry {2}, profits went to steam id {3}", DateTime.Now, _cInfo.playerName, _purchase, _steamid)); sw.WriteLine(); sw.Flush(); sw.Close(); } }
public void PlayerDisconnected(ClientInfo _cInfo, bool _bShutdown) { if (_cInfo != null) { if (GameManager.Instance.World.Players.dict.ContainsKey(_cInfo.entityId)) { EntityPlayer _player = GameManager.Instance.World.Players.dict[_cInfo.entityId]; if (_player != null) { string _sql = string.Format("UPDATE Players SET zkills = {0}, kills = {1}, deaths = {2} WHERE steamid = '{3}'", XUiM_Player.GetZombieKills(_player), XUiM_Player.GetPlayerKills(_player), XUiM_Player.GetDeaths(_player), _cInfo.playerId); SQL.FastQuery(_sql); if (Wallet.IsEnabled) { int _currentCoins = Wallet.GetcurrentCoins(_cInfo); _sql = string.Format("UPDATE Players SET wallet = {0} WHERE steamid = '{1}'", _currentCoins, _cInfo.playerId); SQL.FastQuery(_sql); } } } if (HatchElevator.LastPositionY.ContainsKey(_cInfo.entityId)) { HatchElevator.LastPositionY.Remove(_cInfo.entityId); } if (FriendTeleport.Dict.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict.Remove(_cInfo.entityId); FriendTeleport.Dict1.Remove(_cInfo.entityId); } if (Players.ZoneExit.ContainsKey(_cInfo.entityId)) { Players.ZoneExit.Remove(_cInfo.entityId); Players.Forgive.Remove(_cInfo.entityId); Players.Victim.Remove(_cInfo.entityId); } if (FlightCheck.Flag.ContainsKey(_cInfo.entityId)) { FlightCheck.Flag.Remove(_cInfo.entityId); } if (FlightCheck.fLastPositionXZ.ContainsKey(_cInfo.entityId)) { FlightCheck.fLastPositionXZ.Remove(_cInfo.entityId); } if (FlightCheck.fLastPositionY.ContainsKey(_cInfo.entityId)) { FlightCheck.fLastPositionY.Remove(_cInfo.entityId); } if (FriendTeleport.Dict.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict.Remove(_cInfo.entityId); } if (FriendTeleport.Dict1.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict1.Remove(_cInfo.entityId); } if (Travel.Flag.Contains(_cInfo.entityId)) { Travel.Flag.Remove(_cInfo.entityId); } if (UndergroundCheck.Flag.ContainsKey(_cInfo.entityId)) { UndergroundCheck.Flag.Remove(_cInfo.entityId); } if (UndergroundCheck.uLastPositionXZ.ContainsKey(_cInfo.entityId)) { UndergroundCheck.uLastPositionXZ.Remove(_cInfo.entityId); } if (Wallet.IsEnabled) { string _sql2 = string.Format("SELECT steamid FROM Players WHERE steamid = '{0}'", _cInfo.playerId); DataTable _result2 = SQL.TQuery(_sql2); if (_result2.Rows.Count > 0) { DateTime _time; if (Players.Session.TryGetValue(_cInfo.playerId, out _time)) { TimeSpan varTime = DateTime.Now - _time; double fractionalMinutes = varTime.TotalMinutes; int _timepassed = (int)fractionalMinutes; if (_timepassed > 60) { int _hours = _timepassed / 60 * 10; Wallet.AddCoinsToWallet(_cInfo.playerId, _hours); } string _sql1 = string.Format("SELECT sessionTime FROM Players WHERE steamid = '{0}'", _cInfo.playerId); DataTable _result1 = SQL.TQuery(_sql1); int _sessionTime; int.TryParse(_result1.Rows[0].ItemArray.GetValue(0).ToString(), out _sessionTime); _result1.Dispose(); _sql1 = string.Format("UPDATE Players SET sessionTime = {0} WHERE steamid = '{1}'", _sessionTime + _timepassed, _cInfo.playerId); SQL.FastQuery(_sql1); } } _result2.Dispose(); } if (Players.Session.ContainsKey(_cInfo.playerId)) { Players.Session.Remove(_cInfo.playerId); } if (Bank.TransferId.ContainsKey(_cInfo.playerId)) { Bank.TransferId.Remove(_cInfo.playerId); } if (Zones.reminder.ContainsKey(_cInfo.entityId)) { Zones.reminder.Remove(_cInfo.entityId); } } }
public static void PlayerDisconnected(ClientInfo _cInfo, bool _bShutdown) { try { if (_cInfo != null) { if (!string.IsNullOrEmpty(_cInfo.playerId) && _cInfo.entityId != -1) { Log.Out(string.Format("[SERVERTOOLS] Player {0} disconnected", _cInfo.playerId)); if (ExitCommand.IsEnabled && ExitCommand.Players.ContainsKey(_cInfo.entityId) && !_bShutdown) { Timers.ExitWithoutCommand(_cInfo, _cInfo.ip); } if (FriendTeleport.Dict.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict.Remove(_cInfo.entityId); FriendTeleport.Dict1.Remove(_cInfo.entityId); } if (FriendTeleport.Dict.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict.Remove(_cInfo.entityId); } if (FriendTeleport.Dict1.ContainsKey(_cInfo.entityId)) { FriendTeleport.Dict1.Remove(_cInfo.entityId); } if (Wallet.IsEnabled && Wallet.Session_Bonus > 0) { if (PersistentOperations.Session.TryGetValue(_cInfo.playerId, out DateTime _time)) { TimeSpan varTime = DateTime.Now - _time; double fractionalMinutes = varTime.TotalMinutes; int _timepassed = (int)fractionalMinutes; if (_timepassed > 60) { int _sessionBonus = _timepassed / 60 * Wallet.Session_Bonus; if (_sessionBonus > 0) { Wallet.AddCoinsToWallet(_cInfo.playerId, _sessionBonus); } } int _timePlayed = PersistentContainer.Instance.Players[_cInfo.playerId].TotalTimePlayed; PersistentContainer.Instance.Players[_cInfo.playerId].TotalTimePlayed = _timePlayed + _timepassed; PersistentContainer.DataChange = true; } } if (PersistentOperations.Session.ContainsKey(_cInfo.playerId)) { PersistentOperations.Session.Remove(_cInfo.playerId); } if (PersistentOperations.PvEViolations.ContainsKey(_cInfo.entityId)) { PersistentOperations.PvEViolations.Remove(_cInfo.entityId); } if (Bank.TransferId.ContainsKey(_cInfo.playerId)) { Bank.TransferId.Remove(_cInfo.playerId); } if (Zones.ZoneInfo.ContainsKey(_cInfo.entityId)) { Zones.ZoneInfo.Remove(_cInfo.entityId); } if (Zones.Forgive.ContainsKey(_cInfo.entityId)) { Zones.Forgive.Remove(_cInfo.entityId); } if (Zones.Victim.ContainsKey(_cInfo.entityId)) { Zones.Victim.Remove(_cInfo.entityId); } if (Zones.Reminder.ContainsKey(_cInfo.entityId)) { Zones.Reminder.Remove(_cInfo.entityId); } if (Zones.ZonePvE.Contains(_cInfo.entityId)) { Zones.ZonePvE.Remove(_cInfo.entityId); } if (BloodmoonWarrior.WarriorList.Contains(_cInfo.playerId)) { BloodmoonWarrior.WarriorList.Remove(_cInfo.playerId); } if (KillNotice.Damage.ContainsKey(_cInfo.entityId)) { KillNotice.Damage.Remove(_cInfo.entityId); } if (PlayerChecks.Flag.ContainsKey(_cInfo.entityId)) { PlayerChecks.Flag.Remove(_cInfo.entityId); } if (Teleportation.Teleporting.Contains(_cInfo.entityId)) { Teleportation.Teleporting.Remove(_cInfo.entityId); } if (PlayerChecks.Movement.ContainsKey(_cInfo.entityId)) { PlayerChecks.Movement.Remove(_cInfo.entityId); } } else { Log.Out("[SERVERTOOLS] Player disconnected"); } } else { Log.Out("[SERVERTOOLS] Amorphous blob with no client information disconnected"); } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in API.PlayerDisconnected: {0}", e.Message)); } }