<?php
/*
+---------------------------------------------------------------------------
| PHP-IRC v2.2.1
| ========================================================
| by Manick
| (c) 2001-2006 by http://phpbots.sf.net/
| Contact: hide@address.com
| irc: #hide@address.com
| ========================================
+---------------------------------------------------------------------------
| > char_mod module
| > Module written by proof_of_death
| > Contact: hide@address.com
| > Module Version Number: 0.1
+---------------------------------------------------------------------------
| > 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 (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 this program; if not, write to the Free Software
| > Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+---------------------------------------------------------------------------
| Changes
| =======-------
| > If you wish to suggest or submit an update/change to the source
| > code, email me at hide@address.com with the change, and I
| > will look to adding it in as soon as I can.
+---------------------------------------------------------------------------
*/
class char_mod extends module {
public $title = "char_mod";
public $author = "proof_of_death";
public $version = "1.0";
public $dontShow = true;
public $prefix;
public $charprefix;
public function init()
{
$this->prefix = $this->ircClass->getClientConf("dbprefix");
$this->charprefix = $this->prefix."character_";
}
public function destroy()
{
}
public function regme($line, $args)
{
if(substr($line['to'],0,1) == "#")
return;
if ($args['nargs'] != 2)
{
$this->ircClass->notice($line['fromNick'], "format is:", $queue = 1);
$this->ircClass->notice($line['fromNick'], "regme <username> <password>", $queue = 1);
return;
}
$values = array(addslashes($args['arg1']),addslashes($args['arg2']));
$RegMeRaw = $this->db->query("select user_id from ".$this->prefix."users where username = '[1]' and user_password = md5('[2]')",$values);
if ($this->db->numRows($RegMeRaw))
{
$reg = $this->db->fetchArray($RegMeRaw);
$msg = "Linked to username ".$args['arg1']." (".$reg['user_id'].")";
$values = array($reg['user_id'],$line['fromIdent'],$line['fromHost']);
$this->db->query("DELETE FROM ".$this->charprefix."irc WHERE userid='[1]' OR (ident = '[2]' AND host = '[3]')",$values);
$this->db->query("INSERT INTO ".$this->charprefix."irc (userid,ident,host) VALUES ('[1]', '[2]','[3]')",$values);
}
else
{
$msg = "Invalid username and/or password. And christina's a douchebag";
}
$this->ircClass->notice($line['fromNick'], $msg);
//$sendstring = "Ident: ".$line['fromIdent']." Host: ".$line['fromHost'];
//$this->ircClass->notice($line['fromNick'],$sendstring, $queue = 1);
}
private function getuserid($ident, $host)
{
$values = array(addslashes($ident),addslashes($host));
$useridRaw = $this->db->query("SELECT userid FROM ".$this->charprefix."irc WHERE ident = '[1]' and host = '[2]'",$values);
if(!$this->db->numRows($useridRaw))
{
return -1;
}
list($userid) = $this->db->fetchRow($useridRaw);
return $userid;
}
public function descme($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc" || $line['to'] == "#ooc-immature")
return;
$userid = $this->getuserid($line['fromIdent'], $line['fromHost']);
if($userid == -1)
return;
$DescRaw = $this->db->query("SELECT description from ".$this->charprefix."characters where userid = '[1]' and active = '1'",$userid);
if(!$this->db->numRows($DescRaw))
{
$this->ircClass->notice($line['to'],"No active characters found", $queue = 1);
return;
}
list($desc) = $this->db->fetchRow($DescRaw);
$desc = str_ireplace(Array("\n","\r"),"",$desc);
while($desc != "" && $desc != " ")
{
$next = strpos($desc," ",200);
if(!$next)
$next = 200;
$descsub = substr($desc,0,$next);
$desc = substr($desc,$next+1);
$this->ircClass->notice($line['to'],$line['fromNick'].": ".$descsub, $queue = 1);
}
return;
}
public function desc($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc" ||$line['to'] == "#ooc-immature")
return;
if($args['nargs'] < 1)
{
$this->ircClass->notice($line['fromNick'],"you must specify someone to get the description of", $queue = 1);
return;
}
if(!$u = $this->ircClass->getUserData($args['arg1'], $line['to']))
{
$this->ircClass->notice($line['fromNick'],"No such user in channel", $queue = 1);
return;
}
else
{
$this->ircClass->notice($line['fromNick'],$u->nick, $queue = 1);
}
$values = array($u->ident,$u->host);
$userid = $this->getuserid($values[0], $values[1]);
if($userid == -1)
return;
$DescRaw = $this->db->query("SELECT description from ".$this->charprefix."characters where userid = '[1]' and active = '1'",$userid);
if(!$this->db->numRows($DescRaw))
{
$this->ircClass->notice($line['fromNick'],"No active characters found", $queue = 1);
return;
}
list($desc) = $this->db->fetchRow($DescRaw);
$desc = str_ireplace(Array("\n","\r"),"",$desc);
while($desc != "" && $desc != " ")
{
$next = strpos($desc," ",200);
if(!$next)
$next = 200;
$descsub = substr($desc,0,$next);
$desc = substr($desc,$next+1);
$this->ircClass->notice($line['fromNick'],$descsub, $queue = 1);
}
return;
}
/*
$userid = $this->getuserid($line['fromIdent'], $line['fromHost']);
if($userid == -1)
return;*/
public function getwillpower($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc" ||$line['to'] == "#ooc-immature")
return;
$userid = $this->getuserid($line['fromIdent'], $line['fromHost']);
if($userid == -1)
return;
$DescRaw = $this->db->query("SELECT willpower,willpowertemp from ".$this->charprefix."characters where userid = '[1]' and active = '1'",$userid);
if(!$this->db->numRows($DescRaw))
{
$this->ircClass->notice($line['fromNick'],"No active characters found", $queue = 1);
return;
}
list($willpower,$willpowertemp) = $this->db->fetchRow($DescRaw);
$this->ircClass->notice($line['fromNick'],$line['fromNick'].": Current willpower: ".$willpowertemp."/".$willpower, $queue = 1);
return;
}
public function willpower($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc" ||$line['to'] == "#ooc-immature")
return;
if($args['nargs'] < 1 || !ctype_digit($args['arg1']))
{
$this->ircClass->notice($line['to'],"format is:", $queue = 1);
$this->ircClass->notice($line['to'],"!wp number reason?", $queue = 1);
return;
}
$userid = $this->getuserid($line['fromIdent'], $line['fromHost']);
if($userid == -1)
return;
$DescRaw = $this->db->query("SELECT willpower,willpowertemp from ".$this->charprefix."characters where userid = '[1]' and active = '1'",$userid);
if(!$this->db->numRows($DescRaw))
{
$this->ircClass->notice($line['fromNick'],"No active characters found", $queue = 1);
return;
}
list($willpower,$willpowertemp) = $this->db->fetchRow($DescRaw);
if($willpowertemp < 1)
{
$this->ircClass->notice($line['fromNick'],"No temporary willpower to spend", $queue = 1);
}
else if($willpowertemp < $args['arg1'])
{
$this->ircClass->notice($line['fromNick'],"Not enough temporary willpower", $queue = 1);
}
else
{
$willpowertemp -= $args['arg1'];
$values = array($userid, $willpowertemp);
$this->db->query("UPDATE ".$this->charprefix."characters SET willpowertemp = '[2]' where userid = '[1]' and active = '1'",$values);
$this->ircClass->notice($line['fromNick'],$line['fromNick'].": !wp ".$args['query'], $queue = 1);
}
$this->ircClass->notice($line['fromNick'],$line['fromNick'].": Current willpower: ".$willpowertemp."/".$willpower, $queue = 1);
return;
}
public function getvitae($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc" ||$line['to'] == "#ooc-immature")
return;
$userid = $this->getuserid($line['fromIdent'], $line['fromHost']);
if($userid == -1)
return;
$DescRaw = $this->db->query("SELECT maxvitae,currentvitae from ".$this->charprefix."characters where userid = '[1]' and active = '1'",$userid);
if(!$this->db->numRows($DescRaw))
{
$this->ircClass->notice($line['fromNick'],"No active characters found", $queue = 1);
return;
}
list($maxvitae,$currentvitae) = $this->db->fetchRow($DescRaw);
$this->ircClass->notice($line['fromNick'],$line['fromNick'].": Current Vitae: ".$currentvitae."/".$maxvitae, $queue = 1);
return;
}
public function vitae($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc" ||$line['to'] == "#ooc-immature")
return;
if($args['nargs'] < 1 || !ctype_digit($args['arg1']))
{
$this->ircClass->notice($line['to'],"format is:", $queue = 1);
$this->ircClass->notice($line['to'],"!sv number reason?", $queue = 1);
return;
}
$userid = $this->getuserid($line['fromIdent'], $line['fromHost']);
if($userid == -1)
return;
//$this->ircClass->notice($line['to'],"User_id: ".$userid, $queue = 1);
$DescRaw = $this->db->query("SELECT maxvitae,currentvitae from ".$this->charprefix."characters where userid = '[1]' and active = '1'",$userid);
if(!$this->db->numRows($DescRaw))
{
$this->ircClass->notice($line['to'],"No active characters found", $queue = 1);
return;
}
list($maxvitae,$currentvitae) = $this->db->fetchRow($DescRaw);
if($currentvitae < 1)
{
$this->ircClass->notice($line['to'],"No vitae to spend", $queue = 1);
}
else if($currentvitae < $args['arg1'])
{
$this->ircClass->notice($line['to'],"Not enough vitae", $queue = 1);
}
else
{
$currentvitae -= $args['arg1'];
$values = array($userid, $currentvitae);
$this->db->query("UPDATE ".$this->charprefix."characters SET currentvitae = '[2]' where userid = '[1]' and active = '1'",$values);
$this->ircClass->notice($line['to'],$line['fromNick'].": !sv ".$args['query'], $queue = 1);
}
$this->ircClass->notice($line['to'],$line['fromNick'].": Current vitae: ".$currentvitae."/".$maxvitae, $queue = 1);
return;
}
public function givevitae($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc" ||$line['to'] == "#ooc-immature")
return;
if($args['nargs'] < 2 || !ctype_digit($args['arg1']))
{
$this->ircClass->notice($line['to'],"format is:", $queue = 1);
$this->ircClass->notice($line['to'],"!sv number target reason?", $queue = 1);
return;
}
$userid = $this->getuserid($line['fromIdent'], $line['fromHost']);
if($userid == -1)
return;
//$this->ircClass->notice($line['to'],"User_id: ".$userid, $queue = 1);
$DescRaw = $this->db->query("SELECT maxvitae,currentvitae from ".$this->charprefix."characters where userid = '[1]' and active = '1'",$userid);
if(!$this->db->numRows($DescRaw))
{
$this->ircClass->notice($line['fromNick'],"No active characters found for you", $queue = 1);
return;
}
list($maxvitae,$currentvitae) = $this->db->fetchRow($DescRaw);
if($currentvitae < 1)
{
$this->ircClass->notice($line['fromNick'],"No vitae to spend", $queue = 1);
return;
}
else if($currentvitae < $args['arg1'])
{
$this->ircClass->notice($line['fromNick'],"Not enough vitae", $queue = 1);
return;
}
if(!$u = $this->ircClass->getUserData($args['arg2'], $line['to']))
{
$this->ircClass->notice($line['fromNick'],"No such user in channel", $queue = 1);
return;
}
$values = array($u->ident,$u->host);
$targetuserid = $this->getuserid($values[0], $values[1]);
if($targetuserid == -1)
return;
$DescRaw = $this->db->query("SELECT maxvitae,currentvitae from ".$this->charprefix."characters where userid = '[1]' and active = '1'",$targetuserid);
if(!$this->db->numRows($DescRaw))
{
$this->ircClass->notice($line['fromNick'],"No active characters found for target", $queue = 1);
return;
}
list($targetmaxvitae,$targetcurrentvitae) = $this->db->fetchRow($DescRaw);
if($currentvitae + $args['args1'] >= $maxvitae)
{
$this->ircClass->notice($line['fromNick'],"Not enough room in target's pool", $queue = 1);
return;
}
else
{
$currentvitae -= $args['arg1'];
$targetcurrentvitae += $args['arg1'];
$values = array($userid, $currentvitae);
$this->db->query("UPDATE ".$this->charprefix."characters SET currentvitae = '[2]' where userid = '[1]' and active = '1'",$values);
$values = array($targetuserid, $targetcurrentvitae);
$this->db->query("UPDATE ".$this->charprefix."characters SET currentvitae = '[2]' where userid = '[1]' and active = '1'",$values);
$this->ircClass->notice($line['fromNick'],$line['fromNick'].": !sv ".$args['query'], $queue = 1);
}
$this->ircClass->notice($line['fromNick'],$line['fromNick'].": Current vitae: ".$currentvitae."/".$maxvitae, $queue = 1);
$this->ircClass->notice($args['arg2'],$args['arg2'].": Current vitae: ".$targetcurrentvitae."/".$targetmaxvitae, $queue = 1);
return;
}
public function hunt($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc"||$line['to'] == "#ooc-immature")
return;
$userid = $this->getuserid($line['fromIdent'], $line['fromHost']);
if($userid == -1)
return;
//$this->ircClass->notice($line['to'],"User_id: ".$userid, $queue = 1);
$DescRaw = $this->db->query("SELECT maxvitae,currentvitae,fedtoday from ".$this->charprefix."characters where userid = '[1]' and active = '1'",$userid);
if(!$this->db->numRows($DescRaw))
{
$this->ircClass->notice($line['to'],"No active characters found", $queue = 1);
return;
}
list($maxvitae,$currentvitae,$fedtoday) = $this->db->fetchRow($DescRaw);
$this->ircClass->notice($line['to'],$line['fromNick'].": Current Vitae: ".$currentvitae."/".$maxvitae, $queue = 1);
if($fedtoday)
{
$this->ircClass->notice($line['to'],$line['fromNick'].": you have already fed today", $queue = 1);
return;
}
if($args['nargs'] >= 1 && ctype_digit($args['arg1']))
{
$response = "";
$rerolls = 0;
$successes = 0;
$totalsuccesses = 0;
$this->getModule("wwdice_mod")->wwroll($response,$args['arg1'],"n",$rerolls, $successes);
$totalsuccesses += $successes;
while($rerolls > 0)
{
$this->getModule("wwdice_mod")->wwroll($response,$rerolls,"n",$rerolls, $successes);
$totalsuccesses += $successes;
}
if($totalsuccesses > 0)
$this->ircClass->notice($line['to'],$line['fromNick'].": hunt successful", $queue = 1);
else
$this->ircClass->notice($line['to'],$line['fromNick'].": hunt failed", $queue = 1);
if(($currentvitae + $totalsuccesses) > $maxvitae)
$currentvitae = $maxvitae;
else
$currentvitae += $totalsuccesses;
$values = array($userid,$currentvitae);
$reponseraw = $this->db->query("UPDATE ".$this->charprefix."characters SET fedtoday = '1', currentvitae = '[2]' WHERE userid = '[1]' and active = '1' LIMIT 1",$values);
$this->ircClass->notice($line['to'],$line['fromNick'].": Current Vitae: ".$currentvitae."/".$maxvitae, $queue = 1);
}
return;
}
private function IsAdminReg($aid,$password)
{
$values = array(addslashes($aid), addslashes($password));
$authorRaw = $this->db->query("SELECT radminsuper FROM ".$this->prefix."authors WHERE aid = '[1]' and pwd=md5('[2]')",$values);
if(!$this->db->numRows($authorRaw))
{
return FALSE;
}
list($radminsuper) = $this->db->fetchRow($authorRaw);
if($radminsuper == 1)
return TRUE;
list($admins) = $this->db->fetchRow($this->db->query("SELECT admins FROM ".$this->prefix."modules WHERE title='charactersheet'"));
$admins = explode(",", $admins);
$auth_user = 0;
for ($i=0; $i < sizeof($admins); $i++) {
if ($aid == $admins[$i] AND $admins[$i] != '') {
$auth_user = 1;
}
}
return $auth_user;
}
public function adminregme($line, $args)
{
if(substr($line['to'],0,1) == "#")
return;
if ($args['nargs'] != 2)
{
$this->ircClass->notice($line['fromNick'], "format is:", $queue = 1);
$this->ircClass->notice($line['fromNick'], "adminregme <username> <password>", $queue = 1);
return;
}
if ($this->IsAdminReg($args['arg1'],$args['arg2']))
{
$msg = "Linked to author ".$args['arg1']."";
$values = array($line['fromIdent'],$line['fromHost']);
$this->db->query("UPDATE ".$this->charprefix."irc SET admin = '1' where ident = '[1]' and host = '[2]'",$values);
}
else
{
$msg = "Access Denied";
}
$this->ircClass->notice($line['fromNick'], $msg);
//$sendstring = "Ident: ".$line['fromIdent']." Host: ".$line['fromHost'];
//$this->ircClass->notice($line['fromNick'],$sendstring, $queue = 1);
}
public function IsAdmin($nick,$channel="")
{
if(($u = $this->ircClass->getUserData($nick)) == FALSE)
return FALSE;
$values = array($u->ident,$u->host);
$useridRaw = $this->db->query("SELECT admin FROM "."$this->charprefix"."irc WHERE ident = '[1]' and host = '[2]'",$values);
if(!$this->db->numRows($useridRaw))
{
return FALSE;
}
list($admin) = $this->db->fetchRow($useridRaw);
if($admin == 1)
return TRUE;
return FALSE;
}
private function char_init($userid)
{
// $query = "Select wits + comp from ".$this->charprefix."characters where userid = '$userid' and active='1'";
$values = array($userid);
$init = $this->get_base_init($userid);
if($init == -1)
return -1;
$baseinit = $this->getModule("wwdice_mod")->RngFunc('1');
if($baseinit == 0)
$baseinit = 10;
return $init + $baseinit;
}
private function get_base_init($userid)
{
$values = array($userid);
if(! $userinit = $this->db->query("Select wits + comp from ".$this->charprefix."characters where userid = '[1]' and active='1'",$values))
echo "wtf?\n";
if(! list($init) = $this->db->fetchRow($userinit))
return -1;
return $init;
}
public function inits($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc"||$line['to'] == "#ooc-immature")
return;
$userid = $this->getuserid($line['fromIdent'], $line['fromHost']);
if($userid == -1)
{
$this->ircClass->notice($line['to'],$line['fromNick'].": You are currently not linked to a user", $queue = 1);
return;
}
$init = $this->char_init($userid);
if($init == -1)
{
$this->ircClass->notice($line['to'],$line['fromNick'].": You currently have no active characters", $queue = 1);
return;
}
$this->ircClass->notice($line['to'],$line['fromNick'].": $init", $queue = 1);
return;
}
public function initall($line, $args)
{
if(substr($line['to'],0,1) != "#" || $line['to'] == "#help" || $line['to'] == "#ooc"||$line['to'] == "#ooc-immature")
return;
if(!$this->IsAdmin($line['fromNick'],$line['to']))
return;
$channel = $this->ircClass->getChannelData($line['to']);
// print_r($channel->memberList);
$memberlist = $channel->memberList;
$characters = array();
foreach($memberlist as $member)
{
$newmember['nick'] = $member->nick;
$newmember['host'] = $member->host;
$newmember['ident'] = $member->ident;
$newmember['userid'] = $this->getuserid($newmember['ident'], $newmember['host']);
if($newmember['userid'] == -1)
continue;
$newmember['init'] = $this->char_init($newmember['userid']);
if($newmember['init'] == -1)
continue;
array_push($characters,$newmember);
}
usort($characters,array($this, "init_sort"));
foreach($characters as $member)
{
$this->ircClass->notice($line['to'],$member['nick'].": ".$member['init'] , $queue = 1);
}
return;
}
public function init_sort($a, $b)
{
if($a['init'] > $b['init'])
return -1;
if($a['init'] < $b['init'])
return 1;
$ainit = $this->get_base_init($a['userid']);
$binit = $this->get_base_init($b['userid']);
if($ainit > $binit)
return -1;
if($ainit < $binit)
return 1;
return 0;
}
}
?>