Advertisement
Guest User

Untitled

a guest
Jan 28th, 2016
1,707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. <?php
  2.  
  3. class adminsOnline {
  4.  
  5. private static $eventName = 'adminsOnline';
  6. private static $config;
  7. private static $simpleConfig = array(
  8. 'write_channel' => 0,
  9. 'groups' => array()
  10. );
  11.  
  12. private static function loadConfig() {
  13. global $lang;
  14. $cfg = getEventConfigValue(self::$eventName);
  15. if ($cfg != false) {
  16. self::$config = $cfg;
  17. } else {
  18. self::$config = self::$simpleConfig;
  19. echo ": > [".self::$eventName."]: ".$lang->getConsoleLanguage('SIMPLE_CONFIGURATION')."\n";
  20. }
  21. return true;
  22. }
  23.  
  24. public static function onRegister()
  25. {
  26. self::loadConfig();
  27. return true;
  28. }
  29.  
  30. private static function isClientInGroup($group,$clientGroups) {
  31. foreach ($clientGroups as $checkGroup) {
  32. if ($group == $checkGroup) {
  33. return $group;
  34. }
  35. }
  36. return false;
  37. }
  38. private static function format_seconds($seconds)
  39. {
  40.  
  41. $uptime = array();
  42. $uptime['days']=floor($seconds / 86400);
  43. $uptime['hours']=floor(($seconds - ($uptime['days'] * 86400)) / 3600);
  44. $uptime['minutes']=floor(($seconds - (($uptime['days'] * 86400)+($uptime['hours']*3600))) / 60);
  45. $uptime['seconds']=floor(($seconds - (($uptime['days'] * 86400)+($uptime['hours']*3600)+($uptime['minutes'] * 60))));
  46.  
  47. $uptime_text = '';
  48.  
  49. if ($uptime['days'] > 0) {
  50. $uptime_text .= $uptime['days'] . ' ' . ($uptime['days'] == 1 ? 'dnia ' : 'dni ');
  51. }
  52.  
  53. if ($uptime['hours'] > 0) {
  54. $uptime_text .= $uptime['hours'] . ' ' . ($uptime['hours'] == 1 ? 'godziny ' : 'godzin ');
  55. }
  56.  
  57. if ($uptime['minutes'] > 0) {
  58. $uptime_text .= $uptime['minutes'] . ' ' . ($uptime['minutes'] == 1 ? 'minuty' : 'minut');
  59. }
  60.  
  61. if ($uptime_text == '') {
  62. $uptime_text .= $uptime['seconds'] . ' sekund';
  63. }
  64.  
  65. return $uptime_text;
  66. }
  67.  
  68. public static function onThink()
  69. {
  70. global $lang, $ts, $whoami;
  71. $desc = '[center][b][size=15]SpeakCenter.pl[/size][/b]\n[size=10]Status Administracji[/size][/center]\n';
  72.  
  73. $i=1;
  74. $admins = array();
  75. $channel = $ts->getElement($ts->getChannelList(),'data');
  76. $servergroups = $ts->getElement($ts->getServerGroupList(),'data');
  77. foreach ($ts->getElement($ts->getClientList('-groups -uid -away -voice -times'),'data') as $client) {
  78. $client_info = $ts->getElement($ts->getClientInfo($client['clid']),'data');
  79. $clientinfos[$client["clid"]] = $client_info['connection_connected_time'];
  80. if ($client['clid'] != $whoami['client_id']) {
  81. $clientGroups = explode(',',$client['client_servergroups']);
  82. foreach (self::$config['groups'] as $checkThisGroup) {
  83. $group = self::isClientInGroup($checkThisGroup,$clientGroups);
  84. if (is_numeric($group) == true && in_array($group,self::$config['groups']) == true) {
  85. $admins[$client['client_nickname']] = array('group' => $group, 'cid' => $client['cid'], 'clid' => $client['clid'], 'unique_id' => $client['client_unique_identifier'], 'idle' => $client['client_idle_time'], 'last_connect'=> $client['client_lastconnected'], 'away' => $client['client_away'], 'mute' => $client['client_output_muted']);
  86.  
  87. }
  88. }
  89. }
  90. }
  91. foreach($channel as $channels){
  92. $channelname[$channels['cid']] = $channels['channel_name'];
  93. }
  94. foreach ($servergroups as $group) {
  95. if (in_array($group['sgid'],self::$config['groups']) == true) {
  96. foreach ($admins as $nickname => $values) {
  97. $status = '[color=green]Online[/color]';
  98. if ($values['away'] == 1 || $values['mute'] == 1) {
  99. $status = '[color=orange]Away[/color]';
  100. }
  101. if ($values['group'] == $group['sgid']) {
  102. $desc .= '[center][size=9][color=red][b]'.$group['name'].'[/b][/color] [b]:[/b] [URL=client://' . $values['clid'] . '/' . $values['unique_id'] . '][color=black]' . $nickname . '[/color][/URL]\n Status: [b]'.$status.'[/b]\n Kanał: [b][url=channelID://'.$values['cid'].']'.str_replace('[cspacer]', '', $channelname[$values['cid']]).'[/url][/b]\n Aktywny/a od: [b]'.self::format_seconds(time() - $values['last_connect']).'[/b] [/size][/center]\n\n';
  103. $i++;
  104. }
  105. }
  106. $desc .= '';
  107. }
  108. }
  109. $desc .= '\n[right][size=9][i]Ostatnia aktualizacja:[/i] [b]'.date('H:i', time()).'[/right]';
  110.  
  111. $ts->editChannel(512, array(
  112. 'channel_name' => '[cspacer]Administracja Online: '.($i - 1 ).''
  113. )
  114. );
  115. $ts->editChannel(self::$config['write_channel'], array(
  116. 'channel_description' => $desc
  117. )
  118. );
  119. }
  120.  
  121. }
  122.  
  123. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement