Phoenix84

registerhandler

Jul 25th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1.     [MySessionComponentDescriptor(Sandbox.Common.MyUpdateOrder.BeforeSimulation)]
  2.     class MissionComponent : Sandbox.Common.MySessionComponentBase
  3.     {
  4.         private bool m_init = false;
  5.  
  6.         public override void LoadData()
  7.         {
  8.             Logger.Instance.Init("FTL");
  9.         }
  10.  
  11.         private void Init()
  12.         {
  13.             if (m_init)
  14.                 return;
  15.  
  16.             m_init = true;
  17.  
  18.             MyAPIGateway.Multiplayer.RegisterMessageHandler(Globals.RegisteredMessage, FTLExtensions.ReceiveNetworkMessage);
  19.         }
  20.  
  21.         protected override void UnloadData()
  22.         {
  23.             try
  24.             {
  25.                 MyAPIGateway.Multiplayer.UnregisterMessageHandler(Globals.RegisteredMessage, FTLExtensions.ReceiveNetworkMessage);
  26.                 Logger.Instance.Close();
  27.             }
  28.             catch { }
  29.         }
  30.  
  31.         public override void UpdateBeforeSimulation()
  32.         {
  33.             Init();                 // First run code
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment