Ignore:
Timestamp:
Jul 31, 2023, 4:06:13 PM (16 months ago)
Author:
alloc
Message:

25_30_44

  • Got rid (mostly) of custom JSON serialization
  • Some code cleanup
File:
1 edited

Legend:

Unmodified
Added
Removed
  • binary-improvements/7dtd-server-fixes/src/API.cs

    r446 r455  
    11using System.Collections.Generic;
    22using AllocsFixes.PersistentData;
     3using JetBrains.Annotations;
    34using Platform.Steam;
    45
    56namespace AllocsFixes {
     7        [UsedImplicitly]
    68        public class API : IModApi {
    79                public void InitMod (Mod _modInstance) {
    810                        ModEvents.GameStartDone.RegisterHandler (GameAwake);
    9                         ModEvents.GameShutdown.RegisterHandler (GameShutdown);
    1011                        ModEvents.SavePlayerData.RegisterHandler (SavePlayerData);
    1112                        ModEvents.PlayerSpawning.RegisterHandler (PlayerSpawning);
     
    1516                }
    1617
    17                 public void GameAwake () {
     18                private static void GameAwake () {
    1819                        PersistentContainer.Load ();
    1920                }
    2021
    21                 public void GameShutdown () {
    22                 }
    23 
    24                 public void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) {
     22                private static void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) {
    2523                        PersistentContainer.Instance.Players.GetOrCreate (_cInfo.InternalId, _cInfo.PlatformId, _cInfo.CrossplatformId).Update (_cInfo, _playerDataFile);
    2624                }
    2725
    28                 public void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) {
     26                private static void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) {
    2927                        string owner = null;
    3028                        if (_cInfo.PlatformId is UserIdentifierSteam identifierSteam) {
     
    3230                        }
    3331
    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
     32                        Log.Out (
     33                                $"Player connected, entityid={_cInfo.entityId}, name={_cInfo.playerName}, pltfmid={_cInfo.PlatformId?.CombinedString ?? "<unknown>"}, crossid={_cInfo.CrossplatformId?.CombinedString ?? "<unknown/none>"}, steamOwner={owner ?? "<unknown/none>"}, ip={_cInfo.ip}"
    4134                        );
    4235                }
    4336
    44                 public void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) {
     37                private static void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) {
    4538                        Player p = PersistentContainer.Instance.Players.GetByInternalId (_cInfo.InternalId);
    4639                        if (p != null) {
     
    5346                }
    5447
    55                 public void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) {
     48                private static void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) {
    5649                        PersistentContainer.Instance.Players.GetOrCreate (_cInfo.InternalId, _cInfo.PlatformId, _cInfo.CrossplatformId).SetOnline (_cInfo);
    5750                        PersistentContainer.Instance.Save ();
    5851                }
    5952
    60                 private const string ANSWER =
    61                         "     [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]";
     53                private const string ANSWER = "     [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]";
    6254
    63                 public bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName,
     55                private static bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName,
    6456                        bool _localizeMain, List<int> _recipientEntityIds) {
    6557                        if (string.IsNullOrEmpty (_msg) || !_msg.EqualsCaseInsensitive ("/alloc")) {
     
    6860
    6961                        if (_cInfo != null) {
    70                                 Log.Out ("Sent chat hook reply to {0}", _cInfo.InternalId);
     62                                Log.Out ($"Sent chat hook reply to {_cInfo.InternalId}");
    7163                                _cInfo.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, ANSWER, "", false, null));
    7264                        } else {
    73                                 Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _msg);
     65                                Log.Error ($"ChatHookExample: Argument _cInfo null on message: {_msg}");
    7466                        }
    7567
Note: See TracChangeset for help on using the changeset viewer.