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

Last change on this file since 347 was 345, checked in by alloc, 6 years ago

Player storing fixes, webmap inventory layout fix

File size: 3.1 KB
RevLine 
[324]1using System.Collections.Generic;
[345]2using AllocsFixes.PersistentData;
3using System;
[230]4
[325]5namespace AllocsFixes {
[324]6 public class API : IModApi {
[325]7 public void InitMod () {
[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 () {
[345]18 try {
19 PersistentContainer.Load ();
20 } catch (Exception e) {
21 Log.Out ("Error in StateManager.Awake: " + e);
22 }
[230]23 }
24
[324]25 public void GameShutdown () {
[345]26 try {
27 Log.Out ("Server shutting down!");
28 PersistentContainer.Instance.Save ();
29 } catch (Exception e) {
30 Log.Out ("Error in StateManager.Shutdown: " + e);
31 }
[230]32 }
[325]33
[324]34 public void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) {
[345]35 try {
36 PersistentContainer.Instance.Players [_cInfo.playerId, true].Update (_playerDataFile);
37 } catch (Exception e) {
38 Log.Out ("Error in GM_SavePlayerData: " + e);
39 }
[230]40 }
41
[324]42 public void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) {
[345]43 try {
44 Log.Out ("Player connected" +
45 ", entityid=" + _cInfo.entityId +
46 ", name=" + _cInfo.playerName +
47 ", steamid=" + _cInfo.playerId +
48 ", steamOwner=" + _cInfo.ownerId +
49 ", ip=" + _cInfo.ip
50 );
51 } catch (Exception e) {
52 Log.Out ("Error in AllocsLogFunctions.RequestToSpawnPlayer: " + e);
53 }
[230]54 }
[325]55
[324]56 public void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) {
[345]57 try {
58 Player p = PersistentContainer.Instance.Players [_cInfo.playerId, false];
59 if (p != null) {
60 p.SetOffline ();
61 } else {
62 Log.Out ("Disconnected player not found in client list...");
63 }
64
65 PersistentContainer.Instance.Save ();
66 } catch (Exception e) {
67 Log.Out ("Error in AllocsLogFunctions.PlayerDisconnected: " + e);
68 }
[230]69 }
70
[345]71 public void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) {
72 try {
73 PersistentContainer.Instance.Players [_cInfo.playerId, true].SetOnline (_cInfo);
74 PersistentContainer.Instance.Save ();
75 } catch (Exception e) {
76 Log.Out ("Error in AllocsLogFunctions.PlayerSpawnedInWorld: " + e);
77 }
78 }
79
80 private const string ANSWER =
81 " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]";
82
[325]83 public bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName,
84 bool _localizeMain, List<int> _recipientEntityIds) {
[345]85 if (string.IsNullOrEmpty (_msg) || !_msg.EqualsCaseInsensitive ("/alloc")) {
86 return true;
87 }
88
89 if (_cInfo != null) {
90 Log.Out ("Sent chat hook reply to {0}", _cInfo.playerId);
91 _cInfo.SendPackage (new NetPackageChat (EChatType.Whisper, -1, ANSWER, "", false, null));
92 } else {
93 Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _msg);
94 }
95
96 return false;
[238]97 }
[230]98 }
[325]99}
Note: See TracBrowser for help on using the repository browser.