<?php
-/********************************* PHP-P10 ******************************
- * P10 uplink class by pk910 (c)2011 pk910 *
- ************************************************************************
- * Version 2 (OOP) *
+/******************************* PHP-P10 v2 *****************************
+ * Copyright (C) 2011-2012 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, *
* 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/>. *
* *
************************************************************************
- *
+ *
* Uplink/P10_ModeSets.class.php
*
* classes to parse and store channel or user modes
"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
}
$this->channel = $channel;
}
-
+
public function parseModes($modes) {
$args = explode(" ",$modes);
$c = 1;
}
return $c-1;
}
-
+
public function setModes($modes, $returndiff = false) {
$args = explode(" ",$modes);
$c = 1;
$add = true;
continue;
}
- if($mode == "-") {
+ if($mode == "-") {
$add = false;
continue;
}
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;
}
}
continue;
+ } else if($mode == "b") {
+ if($this->handleBan($add, $mode, $args[$c++])) {
+ if($returndiff && $add) {
+ $modestradd .= $mode;
+ $paramstradd .= " ".$args[$c-1];
+ } else if($returndiff && !$add) {
+ $modestrdel .= $mode;
+ $paramstrdel .= " ".$args[$c-1];
+ }
+ }
+ continue;
}
$flag = self::$modevalues[$mode];
if($add) {
return $modediff;
}
}
-
+
+ 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) {
$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 = "";
}
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);
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 {
private static $modevalues = null;
private $modeflags = 0;
private $modeparams = array();
-
+
public function __construct($modes) {
if(self::$modevalues == null) {
//build modevalues array
}
$this->parseModes($modes);
}
-
+
public function parseModes($modes) {
$args = explode(" ",$modes);
$c = 1;
}
}
}
-
+
public function setModes($modes, $returndiff = false) {
$args = explode(" ",$modes);
$c = 1;
$add = true;
continue;
}
- if($mode == "-") {
+ if($mode == "-") {
$add = false;
continue;
}
return $modediff;
}
}
-
+
public function getModeString() {
$modestr = "+";
$paramstr = "";
}
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);
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