All pastes #343232 Raw Edit

Stuff

public text v1 · immutable
·published 2007-02-06 22:02 UTC
rendered paste body
		function akick(&$pars, &$u, &$c, &$status) {
			global $hs, $ns, $ng, $i;
			if ($this->access_check($c->ci->levels->akick,$status,$u)) return;
			if (!$ns or !$ng)
				$hs->helpnotice($u,$this->source,"CHAN_AKICK_DISABLED");
			$cmd = strtolower(firstword($pars,$pars));
			switch ($cmd) {
				case 'add':
					$tmp = fr(q("SELECT MAX(`idx`) AS `m`, COUNT(*) AS `c` FROM `cs_akick` WHERE `cid` = {$c->ci->cid}"));
					list($idx, $count) = $tmp;
					if ($count >= 100) {
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_REACHED_LIMIT",'d',100);
						return;
					}
					$idx = 1 + (int)$idx;
					$target = firstword($pars,$pars);
					if ($ns->valid_nick($target)) {
						if (!ake(strtolower($target),$ng)) {
							$hs->helpnotice($u,$this->source,"NICK_X_NOT_REGISTERED",'s',$target);
							return;
						}
						$mask = '';
						$target = $ng[strtolower($target)]->ngi->mainnick->nick;
						$ngi =& $ng[strtolower($target)]->ngi->ngi;
						if ($ngi == $c->ci->founder or (ake($ngi,$c->ci->access_by_ngi)
						and $c->ci->access_by_ngi[$ngi]->level >= $status)) {
							$hs->helpnotice($u,$this->source,'ACCESS_DENIED');
							return;
						}
					} elseif ($target and ereg('.+!.+@.+',$target)) {
						$mask = $target;
						$ngi = 'NULL';
					} else {
						$hs->helpnotice($u,$this->source,"BAD_SYNTAX",'c','AKICK');
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_SYNTAX");
						return;
					}
					$pars = substr(trim($pars),0,100);
					q("INSERT INTO `cs_akick` SET `cid`={$c->ci->cid}, `idx`={$idx}, `mask`='".
						es($mask)."', `ngi`={$ngi}, `reason`='".es($pars)."', `by`='".
						es($u->nick)."', `at`=UNIX_TIMESTAMP( NOW() );",true);
					if (mysql_errno() == 1062)
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_ALREADY_EXISTS",'n',
							($ngi ? $target : $mask),'c',$c->name);
					else {
						$c->ci->akick[$idx] = new ci_akick($c->ci, $mask, $ngi);
						$c->ci->akick[$idx]->by = $u->nick;
						$c->ci->akick[$idx]->at = time();
						$c->ci->akick[$idx]->reason = $pars;
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_ADDED",'n',
							($ngi ? $target : $mask),'c',$c->name);
					}
					break;
				case 'del':
					$target = firstword($pars);
					if ($ns->valid_nick($target)) {
						if (!ake(strtolower($target),$ng)) {
							$hs->helpnotice($u,$this->source,"NICK_X_NOT_REGISTERED",'s',$target);
							return;
						}
						$mask = '';
						//$target = $ng[strtolower($target)]->ngi->mainnick->nick."!*@*";
						$ngi = $ng[strtolower($target)]->ngi->ngi;
					} elseif ($target and ereg('![^@]+@',$target)) {
						$mask = $target;
						$ngi = 'NULL';
					} else {
						$hs->helpnotice($u,$this->source,"BAD_SYNTAX",'c','AKICK');
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_SYNTAX");
						return;
					}
					$r = q("DELETE FROM `cs_akick` WHERE `cid`={$c->ci->cid} AND (`ngi`=$ngi AND `mask`='$mask' LIMIT 1",true);
					if (mysql_affected_rows()) {
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_DELETED",'n',
							($ngi ? $target : $mask),'c',$c->name);
						if ((int) $ngi and ake($ngi,$c->ci->akick_by_ngi)) {
							unset($c->ci->akick_by_ngi[$ngi]);
						}
						foreach ($c->ci->akick as $key => &$ak) {
							if ($ak->id !== $ngi and $ak->wildcard != $mask) continue;
							unset($c->ci->akick[$key]);
							break;
						}
					}
					else
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_NO_MATCH",'s',$c->name);
					break;
				case 'view':
					if (empty($c->ci->akick))
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_LIST_EMPTY",'s',$c->name);
					else {
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_LIST_HEADER",'s',$c->name);
						foreach ($c->ci->akick as $idx => &$ak) {
							$hs->helpnotice($u,$this->source,'CHAN_AKICK_VIEW_'.(!$ak->last_used ? 'UNUSED_' : '').'FORMAT','u',(!$ak->last_used ? '' : $hs->duration_short($ak->last_used,$u)),'i',$idx,'m',($ak->id > 0 ? (ake($ak->id,$ng) ? $ng[$ak->id]->mainnick->nick : '[Unknown]') : $ak->wildcard),'s',$ak->by,'t',$hs->date_with_ago($ak->at,$u),'r',($ak->reason ? $ak->reason : '(No reason specified)'));
						}
					}
					break;
				case 'list':
					if (empty($c->ci->akick))
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_LIST_EMPTY",'s',$c->name);
					else {
						$hs->helpnotice($u,$this->source,"CHAN_AKICK_LIST_HEADER",'s',$c->name);
						foreach ($c->ci->akick as $idx => &$ak) {
							if ($ak->id > 0)
								$i->send(":{$this->source} B {$u->nick} :$idx ".(ake($ak->id,$ng) ?
								$ng[$ak->id]->mainnick->nick : '[Unknown]')." ({$ak->reason})");
							else
								$i->send(":{$this->source} B {$u->nick} :$idx {$ak->wildcard} ".
								($ak->reason ? "({$ak->reason})" : ''));
						}
					}
					break;
				case 'count':
					$hs->helpnotice($u,$this->source,"CHAN_AKICK_COUNT",'s',$c->name,'d',count($c->ci->akick));
					break;
			}
		}