Facebook
From Gracious Eider, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 741
  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.         public static function getNameByNumber($i){
  68.                 $osoba = 'osób';
  69.                 if($i == 1){
  70.                         $osoba = 'osoba';
  71.                 }
  72.                 if($i == 2 || $i == 3 || $i == 4){
  73.                         $osoba = 'osoby';
  74.                 }else if($i > 4){
  75.                         $osoba = 'osób';
  76.                 }
  77.                 return $osoba;
  78.         }
  79.     public static function onThink()
  80.         {
  81.                 global $lang, $ts, $whoami;            
  82.         $desc = self::$config['up_description'];
  83.         $name = '';
  84.         $i=0;
  85.         $admins = array();             
  86.                 $channel = $ts->getElement($ts->getChannelList(),'data');
  87.         $servergroups = $ts->getElement($ts->getServerGroupList(),'data');             
  88.                 foreach ($ts->getElement($ts->getClientList('-groups -uid -away -voice -times'),'data') as $client) {
  89.                         if($client['client_type'] == 0)
  90.                         {
  91.                                 $client_info = $ts->getElement($ts->getClientInfo($client['clid']),'data');
  92.                                 $clientinfos[$client["clid"]] = $client_info["connection_connected_time"];
  93.                                 if ($client['clid'] != $whoami['client_id']) {
  94.                                         $clientGroups = explode(',',$client['client_servergroups']);
  95.                                         foreach (self::$config['groups'] as $checkThisGroup) {
  96.                                                 $group = self::isClientInGroup($checkThisGroup,$clientGroups);
  97.                                                 if (is_numeric($group) == true && in_array($group,self::$config['groups']) == true) {
  98.                                                         $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']);
  99.                                                                
  100.                                                 }
  101.                                         }
  102.                                 }
  103.                         }
  104.         }
  105.                 foreach($channel as $channels){
  106.                         $channelname[$channels['cid']] = $channels['channel_name'];
  107.                 }
  108.         foreach ($servergroups as $group) {
  109.                         if (in_array($group['sgid'],self::$config['groups']) == true) {
  110.                                 foreach ($admins as $nickname => $values) {
  111.                                         $iconid = $group['iconid'];
  112.                                         if($iconid<0){
  113.                                                 $iconid = sprintf('%u', $iconid & 0xffffffff);
  114.                                         }
  115.                                                 if ($values['away'] == 1 || $values['mute'] == 1) {
  116.                                                                 $status = '[color=blue]Away[/color]';
  117.                                                 }
  118.                                                 else
  119.                                                 {
  120.                                                         if ($values['group'] == $group['sgid']) {
  121.                                                                 $desc .= '['.$group['name'].'] - [size=9][URL=client://' . $values['clid'] . '/' . $values['unique_id'] . ']' . $nickname . '[/URL] zalogowany od: [b]'.self::format_seconds(time() - $values['last_connect']).'[/b] na kanale [b][url=channelID://'.$values['cid'].']'.str_replace('[cspacer]', '', $channelname[$values['cid']]).'[/url][/b].[/size]\n';
  122.                                                                 $i++;
  123.                                                         }
  124.                                                 }
  125.  
  126.                                         }                                              
  127.                                         $desc .= '';
  128.                                 }
  129.                 }
  130.                 $desc .= self::$config['lower_description'];
  131.                
  132.                 if($i == 0){
  133.                          $desc = self::$config['up_description'];
  134.                          $desc .= '\n Aktualnie nikt z administratorów nie jest dostępny\n';
  135.                          $desc .= self::$config['lower_description'];
  136.                 }
  137.                
  138.                
  139.         $ts->editChannel(self::$config['write_channel'], array(
  140.                 'channel_description' => $desc
  141.             )
  142.         );
  143.                
  144.                
  145.                 $ts->editChannel(self::$config['write_channel'], array(
  146.                 'channel_name' => self::$config['channel_name'].' '.$i.' '.self::getNameByNumber($i)
  147.             )
  148.         );
  149.     }
  150.    
  151. }
  152.  
  153. ?>
  154.  
  155.