Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. <?php
  2. class poke_adminsmc
  3. {
  4. private static $eventName = 'poke_adminsmc';
  5. private static $config;
  6. private static $simpleConfig = [];
  7. private static $cacheNames = ['help_clients' => 'messaged_client'];
  8.  
  9. private static function loadConfig()
  10. {
  11. global $lang;
  12.  
  13. $cfg = getEventConfigValue(self::$eventName);
  14. if ($cfg != false)
  15. {
  16. self::$config = $cfg;
  17. }
  18. else
  19. {
  20. self::$config = self::$simpleConfig;
  21. echo ": > [".self::$eventName."]: ".$lang->getConsoleLanguage('SIMPLE_CONFIGURATION')."\n";
  22. }
  23. return true;
  24. }
  25.  
  26. public static function onRegister()
  27. {
  28. global $cache;
  29.  
  30. self::loadConfig();
  31. $cache->setCache(self::$cacheNames['help_clients'], []);
  32. return true;
  33. }
  34.  
  35. private static function checkGroups($invokerid, $cid)
  36. {
  37. if (isset(self::$config['groups_poke'][$cid]))
  38. {
  39. $clientGroups = explode(',',$invokerid['client_servergroups']);
  40. foreach ($clientGroups as $clientGroup)
  41. {
  42. if (in_array($clientGroup, self::$config['groups_poke'][$cid]) == true)
  43. {
  44. return true;
  45. }
  46. }
  47. }
  48. return false;
  49. }
  50.  
  51. private static function isClientInGroup($group, $clientGroups)
  52. {
  53. foreach ($clientGroups as $checkGroup)
  54. {
  55. if ($group == $checkGroup)
  56. {
  57. return $group;
  58. }
  59. }
  60. return false;
  61. }
  62.  
  63.  
  64. public static function adminsData($config)
  65. {
  66. global $ts;
  67.  
  68. $i = 0;
  69. $admins = [];
  70.  
  71. $servergroups = $ts->getElement($ts->getServerGroupList(),'data');
  72. foreach ($ts->getElement($ts->getClientList('-groups -uid -away -voice -times'),'data') as $client)
  73. {
  74. $clientGroups = explode(',',$client['client_servergroups']);
  75. foreach ($config as $checkThisGroup)
  76. {
  77. if(in_array($checkThisGroup, $clientGroups))
  78. {
  79. $admins[] = '[URL=client://' . $client['clid'] . '/' . $client['client_unique_identifier'] . '~'.urlencode($client['client_nickname']).']' . $client['client_nickname'] . '[/URL]';
  80. $i++;
  81. }
  82. }
  83. }
  84.  
  85. return ['admins' => implode(',', $admins), 'count' => $i];
  86. }
  87.  
  88. private static function isAdminOnChannel($clientsData)
  89. {
  90. foreach ($clientsData as $user)
  91. {
  92. if (self::checkGroups($user, $user['cid']) == true && in_array($user['cid'], self::$config['onClientAreOnChannel']) == true)
  93. {
  94. return true;
  95. }
  96. }
  97. return false;
  98. }
  99.  
  100. public static function onClientAreOnChannel($clid = null, $cid = null, $invokerid = null, $clientsData = null)
  101. {
  102. global $ts, $kernel, $lang, $cache;
  103.  
  104. $client = $ts->getElement($ts->getClientInfo($clid),'data');
  105. if (self::checkGroups($client, $client['cid']) == false && $client['client_is_talker'] == 0 && self::isAdminOnChannel($clientsData) == false)
  106. {
  107. if ($client['client_away'] != 0 or $client['client_input_muted'] != 0 or $client['client_output_muted'] != 0 or $client['client_output_hardware'] != 1)
  108. {
  109. $ts->sendMessage(1, $clid, $lang->getLanguage('PA_KICK_MSG'));
  110. $ts->kickClient($clid, $lang->getLanguage('PA_KICK_MSG'), 'channel');
  111. return true;
  112. }
  113.  
  114. $pokes = 0;
  115. foreach ($clientsData as $aclient)
  116. {
  117. if (self::checkGroups($aclient, $client['cid']) == true && $aclient['client_away'] == 0)
  118. {
  119. if (!in_array($aclient['cid'], self::$config['ignored_channel']))
  120. {
  121. if(self::$config['type'] == 'poke')
  122. {
  123. $ts->pokeClient($aclient['clid'],$lang->langReplace('[USER_NAME]',$client['client_nickname'], 'PA_POKE_MSG'));
  124. $pokes++;
  125. }
  126. else if(self::$config['type'] == 'pw')
  127. {
  128. $ts->sendMessage(1,$aclient['clid'],$lang->langReplace('[USER_NAME]',$client['client_nickname'], 'PA_POKE_MSG'));
  129. $pokes++;
  130. }
  131. }
  132. }
  133. }
  134.  
  135. $informations = self::adminsData(self::$config['groups_poke'][$cid]);
  136. $channelInfo = $ts->getElement($ts->getChannelInfo($client['cid']), 'data');
  137.  
  138. if ($pokes > 0)
  139. {
  140. $ts->sendMessage(1, $clid, $lang->langReplace(["[COUNT]", "[ADMINS]", "[CH_ID]", "[CH_NAME]"], [$informations['count'], $informations['admins'], $cid, $channelInfo['channel_name']], 'PA_USER_MSG'));
  141. }
  142. else
  143. {
  144. $ts->sendMessage(1, $clid, $lang->getLanguage('PA_USER_MSG_NOADMINS'));
  145. }
  146.  
  147. }
  148.  
  149. return true;
  150. }
  151. }
  152. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement