format
[PHP-P10.git] / Uplink / P10_ModeSets.class.php
index 96f8e7213e40afc4b4e58e2420bbfaedf582e82c..aaaf8e73fb2e8c23a9bfe00052f4341ddb7d6fd0 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 /******************************* PHP-P10 v2 *****************************
- * Copyright (C) 2011  Philipp Kreil (pk910)                            *
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)                       *
  *                                                                      *
  * 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 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        *
@@ -16,7 +16,7 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  *                                                                      *
  ************************************************************************
- * 
+ *
  *  Uplink/P10_ModeSets.class.php
  *
  * classes to parse and store channel or user modes
@@ -67,16 +67,18 @@ class P10_ChannelModeSet {
                "d" => self::MODE_TYPE_D,
                "R" => self::MODE_TYPE_D,
                "z" => self::MODE_TYPE_D,
-               
-               //special behavior
+               "S" => self::MODE_TYPE_D,
+
+       //special behavior
                "o" => self::MODE_TYPE_B,
+        "h" => self::MODE_TYPE_B,
                "v" => self::MODE_TYPE_B
        );
        private static $modevalues = null;
        private $modeflags = 0;
        private $modeparams = array();
        private $channel;
-       
+
        public function __construct($channel) {
                if(self::$modevalues == null) {
                        //build modevalues array
@@ -89,7 +91,7 @@ class P10_ChannelModeSet {
                }
                $this->channel = $channel;
        }
-       
+
        public function parseModes($modes) {
                $args = explode(" ",$modes);
                $c = 1;
@@ -113,7 +115,7 @@ class P10_ChannelModeSet {
                }
                return $c-1;
        }
-       
+
        public function setModes($modes, $returndiff = false) {
                $args = explode(" ",$modes);
                $c = 1;
@@ -128,7 +130,7 @@ class P10_ChannelModeSet {
                                $add = true;
                                continue;
                        }
-                       if($mode == "-") { 
+                       if($mode == "-") {
                                $add = false;
                                continue;
                        }
@@ -136,7 +138,7 @@ class P10_ChannelModeSet {
                                trigger_error("unknown mode (".$mode.") on setModes (".$modes.").", E_USER_WARNING);
                                continue;
                        }
-                       if($mode == "o" || $mode == "v") {
+                       if($mode == "o" || $mode == "h" || $mode == "v") {
                                if($this->setPrivs($add, $mode, $args[$c++])) {
                                        if($returndiff && $add) {
                                                $modestradd .= $mode;
@@ -148,7 +150,7 @@ class P10_ChannelModeSet {
                                }
                                continue;
                        } else if($mode == "b") {
-                if($this->handleBan($add, $mode, $args[$c++])) {
+                               if($this->handleBan($add, $mode, $args[$c++])) {
                                        if($returndiff && $add) {
                                                $modestradd .= $mode;
                                                $paramstradd .= " ".$args[$c-1];
@@ -157,8 +159,8 @@ class P10_ChannelModeSet {
                                                $paramstrdel .= " ".$args[$c-1];
                                        }
                                }
-                continue;
-            }
+                               continue;
+                       }
                        $flag = self::$modevalues[$mode];
                        if($add) {
                                if($returndiff && !($this->modeflags & $flag)) {
@@ -192,12 +194,12 @@ class P10_ChannelModeSet {
                        return $modediff;
                }
        }
-       
-    private function handleBan($add, $mode, $mask) {
-        //no ban management right now...
-        return true;
-    }
-    
+
+       private function handleBan($add, $mode, $mask) {
+               //no ban management right now...
+               return true;
+       }
+
        private function setPrivs($add, $mode, $user) {
                $user = P10_User::getUserByNum($user);
                if($user == null) {
@@ -207,16 +209,17 @@ class P10_ChannelModeSet {
                $privs = $this->channel->getUserPrivs($user);
                $privFlag = 0;
                if($mode == "o") $privFlag = P10_Channel::USERPRIV_OPED;
+               if($mode == "h") $privFlag = P10_Channel::USERPRIV_HALFOP;
                if($mode == "v") $privFlag = P10_Channel::USERPRIV_VOICE;
                if(!($add xor ($privs & $privFlag)))
-                       return false;
+               return false;
                if($add) $privs |= $privFlag;
                else $privs &= ~$privFlag;
                $this->channel->setUserPrivs($user, $privs);
                return true;
-               
+
        }
-       
+
        public function getModeString() {
                $modestr = "+";
                $paramstr = "";
@@ -230,7 +233,7 @@ class P10_ChannelModeSet {
                }
                return $modestr.$paramstr;
        }
-       
+
        public function hasMode($mode) {
                if(!array_key_exists($mode, self::$modevalues)) {
                        trigger_error("unknown mode (".$mode.") on setModes (".$modes.").", E_USER_WARNING);
@@ -240,9 +243,9 @@ class P10_ChannelModeSet {
                if(self::$modes[$mode] == self::MODE_TYPE_B || self::$modes[$mode] == self::MODE_TYPE_C) {
                        return (($this->modeflags & $flag) ? $this->modeparams[$mode] : false);
                } else
-                       return ($this->modeflags & $flag);
+               return ($this->modeflags & $flag);
        }
-       
+
 }
 
 class P10_UserModeSet {
@@ -272,7 +275,7 @@ class P10_UserModeSet {
        private static $modevalues = null;
        private $modeflags = 0;
        private $modeparams = array();
-       
+
        public function __construct($modes) {
                if(self::$modevalues == null) {
                        //build modevalues array
@@ -285,7 +288,7 @@ class P10_UserModeSet {
                }
                $this->parseModes($modes);
        }
-       
+
        public function parseModes($modes) {
                $args = explode(" ",$modes);
                $c = 1;
@@ -307,7 +310,7 @@ class P10_UserModeSet {
                        }
                }
        }
-       
+
        public function setModes($modes, $returndiff = false) {
                $args = explode(" ",$modes);
                $c = 1;
@@ -321,7 +324,7 @@ class P10_UserModeSet {
                                $add = true;
                                continue;
                        }
-                       if($mode == "-") { 
+                       if($mode == "-") {
                                $add = false;
                                continue;
                        }
@@ -355,7 +358,7 @@ class P10_UserModeSet {
                        return $modediff;
                }
        }
-       
+
        public function getModeString() {
                $modestr = "+";
                $paramstr = "";
@@ -369,7 +372,7 @@ class P10_UserModeSet {
                }
                return $modestr.$paramstr;
        }
-       
+
        public function hasMode($mode) {
                if(!array_key_exists($mode, self::$modevalues)) {
                        trigger_error("unknown mode (".$mode.") on setModes (".$modes.").", E_USER_WARNING);
@@ -379,9 +382,9 @@ class P10_UserModeSet {
                if(self::$modes[$mode] == self::MODE_WITH_PARAMETER) {
                        return (($this->modeflags & $flag) ? $this->modeparams[$mode] : false);
                } else
-                       return ($this->modeflags & $flag);
+               return ($this->modeflags & $flag);
        }
-       
+
 }
 
 ?>
\ No newline at end of file