using System.Collections.Generic; using AllocsFixes.PersistentData; using JetBrains.Annotations; using Platform.Steam; namespace AllocsFixes { [UsedImplicitly] public class ModApi : IModApi { public void InitMod (Mod _modInstance) { ModEvents.GameStartDone.RegisterHandler (GameAwake); ModEvents.SavePlayerData.RegisterHandler (SavePlayerData); ModEvents.PlayerSpawning.RegisterHandler (PlayerSpawning); ModEvents.PlayerDisconnected.RegisterHandler (PlayerDisconnected); ModEvents.PlayerSpawnedInWorld.RegisterHandler (PlayerSpawned); ModEvents.ChatMessage.RegisterHandler (ChatMessage); } private void GameAwake () { PersistentContainer.Load (); } private void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { PersistentContainer.Instance.Players [_cInfo.InternalId, true].Update (_playerDataFile); } private void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) { string owner = null; if (_cInfo.PlatformId is UserIdentifierSteam identifierSteam) { owner = identifierSteam.OwnerId.ToString (); } Log.Out ("Player connected" + ", entityid=" + _cInfo.entityId + ", name=" + _cInfo.playerName + ", pltfmid=" + (_cInfo.PlatformId?.CombinedString ?? "") + ", crossid=" + (_cInfo.CrossplatformId?.CombinedString ?? "") + ", steamOwner=" + (owner ?? "") + ", ip=" + _cInfo.ip ); } private void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) { Player p = PersistentContainer.Instance.Players [_cInfo.InternalId, false]; if (p != null) { p.SetOffline (); } else { Log.Out ("Disconnected player not found in client list..."); } PersistentContainer.Instance.Save (); } private void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) { PersistentContainer.Instance.Players [_cInfo.InternalId, true].SetOnline (_cInfo); PersistentContainer.Instance.Save (); } private const string testChatAnswer = " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]"; private bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName, bool _localizeMain, List _recipientEntityIds) { if (string.IsNullOrEmpty (_msg) || !_msg.EqualsCaseInsensitive ("/alloc")) { return true; } if (_cInfo != null) { Log.Out ("Sent chat hook reply to {0}", _cInfo.InternalId); _cInfo.SendPackage (NetPackageManager.GetPackage ().Setup (EChatType.Whisper, -1, testChatAnswer, "", false, null)); } else { Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _msg); } return false; } } }