changed file headers & added AUTHORS file
[PHP-P10.git] / Uplink / P10_Channel.class.php
index efe960de62b9f407f823241485cbcb766f099a49..4fe3a205ae27552f402a1d6e735e675d4f66d983 100644 (file)
@@ -1,22 +1,19 @@
 <?php
-/********************************* PHP-P10 ******************************
- *    P10 uplink class by pk910   (c)2011 pk910                         *
- ************************************************************************
- *                          Version 2 (OOP)                             *
+/******************************* PHP-P10 v2 *****************************
+ * Copyright (C) 2011  Philipp Kreil (pk910)                            *
  *                                                                      *
- * PHP-P10 is free software; you can redistribute it and/or modify      *
+ * This program is free software: you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or    *
+ * the Free Software Foundation, either version 3 of the License, or    *
  * (at your option) any later version.                                  *
- *                                                                      *
+ *                                                                      * 
  * This program is distributed in the hope that it will be useful,      *
  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
  * GNU General Public License for more details.                         *
  *                                                                      *
  * You should have received a copy of the GNU General Public License    *
- * along with PHP-P10; if not, write to the Free Software Foundation,   *
- * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.       *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  *                                                                      *
  ************************************************************************
  * 
  *
  * This class represents a IRC Channel
  *
- ************************************************************************
- * accessable methods:
- *
- * static P10_User getChannelByName(String $name) 
- *     searches and returns the Channel with the provided name
- *
- * __construct(String $name)
- *     *** nothing to say here ***
- *
  */
 
 class P10_Channel {
@@ -46,10 +34,24 @@ class P10_Channel {
                return NULL;
        }
        
+       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;
        private $modes;
+       private $create_time;
        private $users = array();
        const USERPRIV_OPED  = 0x0001;
        const USERPRIV_VOICE = 0x0002;
@@ -58,6 +60,7 @@ class P10_Channel {
        public function __construct($name) {
                $this->name = $name;
                $this->modes = new P10_ChannelModeSet($this);
+               $this->create_time = time();
                self::$static_channels[strtolower($name)] = $this;
        }
        
@@ -77,6 +80,14 @@ class P10_Channel {
                return $this->topic;
        }
        
+       public function setCreateTime($time) {
+               $this->create_time = $time;
+       }
+       
+       public function getCreateTime() {
+               return $this->create_time;
+       }
+       
        public function joinUser($user) {
                $this->users[$user->getNumeric()] = $user;
                $this->userPrivs[$user->getNumeric()] = 0;
@@ -89,11 +100,18 @@ class P10_Channel {
                $user->addChannel($this);
        }
        
+       private function checkChannel() {
+               if(count($this->users) == 0 && !$this->modes->hasMode('z')) {
+                       unset(self::$static_channels[strtolower($this->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);
                }
@@ -104,6 +122,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);
                }
@@ -122,6 +141,14 @@ class P10_Channel {
                }
        }
        
+       public function getUserCount() {
+               return count($this->users);
+       }
+       
+       public function getUsers() {
+               return $this->users;
+       }
+       
 }
 
 ?>
\ No newline at end of file