plugindiagmenuserver.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // For modding, see PluginDiagMenuModding.c
  2. // !!! MODDING DISCLAIMER: These are debug functionality files, if you are thinking about modding the vanilla ones, do so at your own risk
  3. // These files will not be maintained with the thought of "what if a modder modded this" (Excluding the modding functionality of course)
  4. // Which is why the modding functionality was developed with the thought of the modded ones having their own isolated safe space
  5. class PluginDiagMenuServer : PluginDiagMenu
  6. {
  7. #ifdef DIAG_DEVELOPER
  8. static ref map<Man, int> m_Subscribers = new map<Man, int>;
  9. // A bit of a hack, because SP creates both Client and Server Plugins
  10. override private void RegisterDiags()
  11. {
  12. if (GetGame().IsMultiplayer())
  13. {
  14. super.RegisterDiags();
  15. }
  16. }
  17. //---------------------------------------------
  18. override void OnRPC(PlayerBase player, int rpc_type, ParamsReadContext ctx)
  19. {
  20. super.OnRPC(player, rpc_type, ctx);
  21. switch (rpc_type)
  22. {
  23. case ERPCs.DEV_DIAGMENU_SUBSCRIBE:
  24. {
  25. if (ctx.Read(CachedObjectsParams.PARAM1_INT))
  26. {
  27. int newMask = CachedObjectsParams.PARAM1_INT.param1;
  28. int currentMask = m_Subscribers.Get(player);
  29. if (newMask != currentMask)
  30. {
  31. if (newMask == 0)
  32. {
  33. m_Subscribers.Remove(player);
  34. }
  35. else
  36. {
  37. m_Subscribers.Set(player, newMask);
  38. }
  39. }
  40. }
  41. break;
  42. }
  43. }
  44. }
  45. //---------------------------------------------
  46. static void SendDataToSubscribersServer(Object target, ESubscriberSystems system, int rpc_type, Param data, bool guaranteed = true)
  47. {
  48. for (int i = 0; i < m_Subscribers.Count(); ++i)
  49. {
  50. Man man = m_Subscribers.GetKey(i);
  51. if (man)
  52. {
  53. int subscribedSystems = m_Subscribers.Get(man);
  54. if (system & subscribedSystems)
  55. {
  56. GetGame().RPCSingleParam( target, rpc_type, data, guaranteed, man.GetIdentity() );
  57. }
  58. }
  59. else
  60. {
  61. m_Subscribers.RemoveElement(i);
  62. i--;
  63. }
  64. }
  65. }
  66. #endif
  67. }