public void ServerEvent_PlayerDisconnected(Client client, DisconnectionType disconnectionType, string reason) { if (client.HasData("CharacterId")) { try { string characterId = client.GetData("CharacterId").ToString(); var character = _characterStorage.Get(characterId); if (character != null) { character.Model = client.Model; character.Health = client.Health; character.Armor = client.Armor; character.Hunger = client.GetHunger(); character.Thirst = client.GetThirst(); character.Stress = client.GetStress(); _characterStorage.Update(character); Logging.Log($"{client.SocialClubName} ({client.Address}): Saved (characterId: {characterId})"); } else { Logging.Log($"{client.SocialClubName} ({client.Address}): Unsaved (characterId: {characterId})"); } } catch (Exception ex) { Logging.Log($"{client.SocialClubName} ({client.Address}) (PlayerDisconnected): {ex.Message}"); } } var disconnectionString = "DROPPED"; if (disconnectionType == DisconnectionType.Left) { disconnectionString = "LEFT"; } else if (disconnectionType == DisconnectionType.Timeout) { disconnectionString = "TIMEOUT"; } else if (disconnectionType == DisconnectionType.Kicked) { disconnectionString = "KICKED"; } if (!string.IsNullOrEmpty(reason)) { Logging.Log($"{client.SocialClubName} ({client.Address}): Disconnected ({disconnectionString}) - {reason}"); } else { Logging.Log($"{client.SocialClubName} ({client.Address}): Disconnected ({disconnectionString})"); } }
public void CMD_Balances(Client client) { if (!client.HasData("CharacterId")) { return; } var characterId = (string)client.GetData("CharacterId"); var character = _characterStorage.Get(characterId); if (character != null) { Logging.Log($"{client.SocialClubName} ({client.Address}): Balances"); Logging.Log($" Bank: {character.Bank}"); Logging.Log($" Cash: {character.Cash}"); client.SendChatMessage($" Bank: {character.Bank}"); client.SendChatMessage($" Cash: {character.Cash}"); } }
public void ResourceStart() { _accountStorage = new StorageDB <Account>(); _characterStorage = new StorageDB <Character>(); NAPI.Server.SetAutoSpawnOnConnect(true); NAPI.Server.SetAutoRespawnAfterDeath(false); NAPI.Server.SetDefaultSpawnLocation(new Vector3(224.1551f, -859.2976f, 30.11921f), 342.6247f); var accounts = _accountStorage.Get(); var characters = _characterStorage.Get(); Logging.Log($" Accounts: {accounts.Count}"); Logging.Log($" Characters: {characters.Count}"); accounts = null; characters = null; }