added RRD Stats Module
[PHP-P10.git] / Uplink / P10_Channel.class.php
index a15548166c719916e28ea5ffaf2e9140bfc38aac..bc8c152f690d086ca9dd36c634643296d14655d8 100644 (file)
@@ -48,8 +48,17 @@ class P10_Channel {
        
        public static function getChannels() {
                return self::$static_channels;
-       }       
+       }
        
+       public static function getChannelCount() {
+               return count(self::$static_channels);
+       }
+       
+       public static function recheckAllChannels() {
+               foreach(self::$static_channels as $channel) {
+                       $channel->checkChannel();
+               }
+       }       
        
        private $name;
        private $topic;
@@ -103,11 +112,18 @@ class P10_Channel {
                $user->addChannel($this);
        }
        
+       private function checkChannel() {
+               if(count($this->users) == 0 && !$this->modes->hasMode('z')) {
+                       unset(self::$static_channels[strtolower($name)]); //drop empty channel
+               }
+       }
+       
        public function quitUser($user) {
                if(array_key_exists($user->getNumeric(), $this->users)) {
                        unset($this->users[$user->getNumeric()]);
                        unset($this->userPrivs[$user->getNumeric()]);
                        //$user->delChannel($this)  is not necessary because the user quits (the whole Object gets removed later)
+                       $this->checkChannel();
                } else {
                        trigger_error("Tried to quit a User from a Channel it is not joined.", E_USER_WARNING);
                }
@@ -118,6 +134,7 @@ class P10_Channel {
                        unset($this->users[$user->getNumeric()]);
                        unset($this->userPrivs[$user->getNumeric()]);
                        $user->delChannel($this);
+                       $this->checkChannel();
                } else {
                        trigger_error("Tried to part a User from a Channel it is not joined.", E_USER_WARNING);
                }