source: binary-improvements/7dtd-server-fixes/src/API.cs@ 446

Last change on this file since 446 was 446, checked in by alloc, 17 months ago

24_27_41

File size: 2.9 KB
RevLine 
[324]1using System.Collections.Generic;
[345]2using AllocsFixes.PersistentData;
[369]3using Platform.Steam;
[230]4
[325]5namespace AllocsFixes {
[324]6 public class API : IModApi {
[369]7 public void InitMod (Mod _modInstance) {
[337]8 ModEvents.GameStartDone.RegisterHandler (GameAwake);
[325]9 ModEvents.GameShutdown.RegisterHandler (GameShutdown);
10 ModEvents.SavePlayerData.RegisterHandler (SavePlayerData);
11 ModEvents.PlayerSpawning.RegisterHandler (PlayerSpawning);
12 ModEvents.PlayerDisconnected.RegisterHandler (PlayerDisconnected);
[345]13 ModEvents.PlayerSpawnedInWorld.RegisterHandler (PlayerSpawned);
[325]14 ModEvents.ChatMessage.RegisterHandler (ChatMessage);
15 }
[230]16
[324]17 public void GameAwake () {
[369]18 PersistentContainer.Load ();
[230]19 }
20
[324]21 public void GameShutdown () {
[230]22 }
[325]23
[324]24 public void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) {
[446]25 PersistentContainer.Instance.Players.GetOrCreate (_cInfo.InternalId, _cInfo.PlatformId, _cInfo.CrossplatformId).Update (_cInfo, _playerDataFile);
[230]26 }
27
[324]28 public void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) {
[369]29 string owner = null;
30 if (_cInfo.PlatformId is UserIdentifierSteam identifierSteam) {
31 owner = identifierSteam.OwnerId.ToString ();
[345]32 }
[369]33
34 Log.Out ("Player connected" +
35 ", entityid=" + _cInfo.entityId +
36 ", name=" + _cInfo.playerName +
37 ", pltfmid=" + (_cInfo.PlatformId?.CombinedString ?? "<unknown>") +
38 ", crossid=" + (_cInfo.CrossplatformId?.CombinedString ?? "<unknown/none>") +
39 ", steamOwner=" + (owner ?? "<unknown/none>") +
40 ", ip=" + _cInfo.ip
41 );
[230]42 }
[325]43
[324]44 public void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) {
[446]45 Player p = PersistentContainer.Instance.Players.GetByInternalId (_cInfo.InternalId);
[369]46 if (p != null) {
47 p.SetOffline ();
48 } else {
49 Log.Out ("Disconnected player not found in client list...");
50 }
[345]51
[369]52 PersistentContainer.Instance.Save ();
[230]53 }
54
[345]55 public void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) {
[446]56 PersistentContainer.Instance.Players.GetOrCreate (_cInfo.InternalId, _cInfo.PlatformId, _cInfo.CrossplatformId).SetOnline (_cInfo);
[369]57 PersistentContainer.Instance.Save ();
[345]58 }
59
60 private const string ANSWER =
61 " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]";
62
[325]63 public bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName,
64 bool _localizeMain, List<int> _recipientEntityIds) {
[345]65 if (string.IsNullOrEmpty (_msg) || !_msg.EqualsCaseInsensitive ("/alloc")) {
66 return true;
67 }
68
69 if (_cInfo != null) {
[369]70 Log.Out ("Sent chat hook reply to {0}", _cInfo.InternalId);
[354]71 _cInfo.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, ANSWER, "", false, null));
[345]72 } else {
73 Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _msg);
74 }
75
76 return false;
[238]77 }
[230]78 }
[325]79}
Note: See TracBrowser for help on using the repository browser.