library_php_2.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /***************************************************************************
00004 
00005 VooDoo cIRCle - an IRC (ro)bot
00006 Copyright (C) 2004-2005 by Marian VooDooMan Meravy (vdmfun@hotmail.com)
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00022 ****************************************************************************/
00023 
00030 class c_server {
00031     var $host;                  
00032     var $port;                  
00033     var $nick;                  
00034     
00035     var $isupport;              
00036     var $user_mode_prefix;      
00037     var $chan_modes_class_a;    
00038     var $chan_modes_class_b;    
00039     var $chan_modes_class_c;    
00040     var $chan_modes_class_d;    
00041     
00051     function init($host,$port,$nick) {
00052         $this->host=$host;
00053         $this->port=$port;
00054         $this->nick=$nick;
00055     }
00056 }
00057 
00064 class c_input {
00065     var $channel;       
00066     var $params;        
00067     
00075     function init($channel) {
00076         $this->channel=$channel;
00077         $this->params=array();
00078     }
00079   
00088     function set_next_parameter($value) {
00089         array_push($this->params,$value);
00090     }
00091     
00099     function get_channel() {
00100         return $this->channel;
00101     }
00102     
00112     function get_param($index)
00113     {
00114         if($index>=count($this->params))
00115             return NULL;
00116         return $this->params[$index];
00117     }
00118 }
00119 
00126 class c_user {
00127     var $nick;              
00128     var $ident;             
00129     var $host;              
00130     var $full_name;         
00131     var $name;              
00132     var $online;            
00133     var $host_unknown;      
00134     var $host_bot;          
00135     var $irc_op;            
00136     var $mode;              
00137     var $host_masks;        
00138     var $fullname_masks;    
00139     var $meta;              
00140     var $groups;            
00141     
00162     function init($nick, $ident, $host, $full_name, $name, $online,
00163         $host_unknown, $host_bot, $irc_op, $mode, $host_masks,
00164         $fullname_masks, $meta, $groups)
00165     {
00166         $this->nick=$nick;
00167         $this->ident=$ident;
00168         $this->host=$host;
00169         $this->full_name=$full_name;
00170         $this->name=$name;
00171         $this->online=$online;
00172         $this->host_unknown=$host_unknown;
00173         $this->host_bot=$host_bot;
00174         $this->irc_op=$irc_op;
00175         $this->mode=$mode;
00176         $this->host_masks=$host_masks;
00177         $this->fullname_mask=$fullname_masks;
00178         $this->meta=$meta;
00179         $this->groups=$groups;
00180     }
00181 }
00182 
00189 class c_channel {
00190     var $name;              
00191     var $users;             
00192     var $bans;              
00193     var $exceptions;        
00194     var $invites;           
00195     var $reops;             
00196     
00197     var $key;               
00198     var $limit;             
00199     var $mode;              
00200     var $topic;             
00201     
00213     function init($name,$bans,$exceptions,$invites,$reops)
00214     {
00215         $this->name=$name;
00216         $this->users=array();
00217         $this->bans=$bans;
00218         $this->exceptions=$exceptions;
00219         $this->invites=$invites;
00220         $this->reops=$reops;
00221     }
00222     
00231     function add_user($user)
00232     {
00233         foreach($this->users as $e)
00234             if($e->nick==$user->nick)
00235                 return;
00236         array_push($this->users,$user);
00237     }
00238     
00250     function find_users_name($name,$want_online,$want_offline,$ignore_case)
00251     {
00252         if(!$want_online && !$want_offline) {
00253             echo "Warning: ".__CLASS__."::".__FUNCTION__."() three-state logic issue: Do we want online, offline, or both? You want none!\n";
00254             return array(); // optimization: it is not needed to continue
00255         }
00256         $res=array();
00257         foreach($this->users as $e) {
00258             if((($want_online && $e->online) || ($want_offline && !$e->online)) && ((!$ignore_case && $e->name==$name) || ($ignore_case && strtolower($e->name)==strtolower($name))))
00259                 array_push($res,$e);
00260         }
00261         return $res;
00262     }
00263 
00274     function find_user_nick($nick,$ignore_case)
00275     {
00276         foreach($this->users as $e) {
00277             if((!$ignore_case && $e->nick==$nick) || ($ignore_case && strtolower($e->nick)==strtolower($nick)))
00278                 return $e;
00279         }
00280         return NULL;
00281     }
00282     
00290     function find_irc_op()
00291     {
00292         $res=array();
00293         foreach($this->users as $e) {
00294             if($e->irc_op)
00295                 array_push($res,$e);
00296         }
00297         return $res;
00298     }
00299     
00307     function find_unknown()
00308     {
00309         $res=array();
00310         foreach($this->users as $e) {
00311             if($e->host_unknown)
00312                 array_push($res,$e);
00313         }
00314         return $res;
00315     }
00316     
00325     function find_host_bot()
00326     {
00327         $res=array();
00328         foreach($this->users as $e) {
00329             if($e->host_bot)
00330                 array_push($res,$e);
00331         }
00332         return $res;
00333     }
00334     
00344     function find_mode($mode,$plus)
00345     {
00346         if(strlen($mode)!=1) {
00347             echo "Error: c_channel::find_mode() argument \$mode should be string one-character long. It is: \"".$mode."\"\n";
00348             return array();
00349         }
00350         $res=array();
00351         foreach($this->users as $e) {
00352             if(($plus && strpos($e->mode,$mode)!==FALSE) || (!$plus && strpos($e->mode,$mode)===FALSE))
00353                 array_push($res,$e);
00354         }
00355         return $res;
00356     }
00357 }
00358 
00365 class c_filesys_access {
00366     var $all_users;             
00367     var $user_name;             
00368     var $owner;                 
00369     var $read;                  
00370     var $delete;                
00371     var $notify_owner;          
00372     var $notify_user;           
00373     var $secure;                
00374     var $all_on_channel;        
00375     var $also_unknown;          
00376     var $notify_owner_message;  
00377     var $notify_user_message;   
00378     
00397     function init($all_users, $user_name, $owner, $read, $delete,
00398         $notify_owner, $notify_user, $secure, $all_on_channel,
00399         $also_unknown, $notify_owner_message, $notify_user_message)
00400     {
00401         $this->all_users=$all_users;
00402         $this->user_name=$user_name;
00403         $this->owner=$owner;
00404         $this->read=$read;
00405         $this->delete=$delete;
00406         $this->notify_owner=$notify_owner;
00407         $this->notify_user=$notify_user;
00408         $this->secure=$secure;
00409         $this->all_on_channel=$all_on_channel;
00410         $this->also_unknown=$also_unknown;
00411         $this->notify_owner_message=$notify_owner_message;
00412         $this->notify_user_message=$notify_user_message;
00413     }
00414 }
00415 
00422 class c_filesys_event {
00423     var $event_has_read;            
00424     var $event_owner_notified;      
00425     var $event_user_name;           
00426     var $user_notified;             
00427     var $event_timestamp;           
00428     
00440     function init($event_has_read, $event_owner_notified, $event_user_name,
00441         $user_notified, $event_timestamp)
00442     {
00443         $this->event_has_read=$event_has_read;
00444         $this->event_owner_notified=$event_owner_notified;
00445         $this->event_user_name=$event_user_name;
00446         $this->user_notified=$user_notified;
00447         $this->event_timestamp=$event_timestamp;
00448     }
00449 }
00450 
00458 class c_filesys_object {
00459     var $type;              
00460     var $internal_name;     
00461     var $public_name;       
00462     var $time;              
00463     var $published;         
00464     var $complete;          
00465     var $expiration;        
00466     
00467     var $access;            
00468     var $events;            
00469     
00483     function init($type, $internal_name, $public_name, $time, $published,
00484         $complete, $expiration)
00485     {
00486         $this->type=$type;
00487         $this->internal_name=$internal_name;
00488         $this->public_name=$public_name;
00489         $this->time=$time;
00490         $this->published=$published;
00491         $this->complete=$complete;
00492         $this->expiration=$expiration;
00493         $this->access=array();
00494         $this->events=array();
00495     }
00496     
00504     function add_access($access) {
00505         array_push($this->access,$access);
00506     }
00507     
00515     function add_event($event) {
00516         array_push($this->events,$event);
00517     }
00518 }
00519 
00526 class c_output {
00527     var $lines;     
00528     
00529     var $commited;
00530     
00537     function init() {
00538         $this->lines="";
00539         $this->commited=FALSE;
00540     }
00541     
00551     function put($priority_class,$raw)
00552     {
00553         $x="PUT ".$priority_class." ".$raw;
00554         $this->lines.=$x."\n";
00555     }
00556     
00567     function put_lines($priority_class,$prefix,$lines,$allow_empty)
00568     {
00569         $lns=explode("\n",$lines);
00570         foreach($lns as $element) {
00571             $str=str_replace("\r","",$element);
00572             if(!$allow_empty && $str=="")
00573                 continue;
00574             $x="PUT ".$priority_class." ".$prefix.$str;
00575             $this->lines.=$x."\n";
00576         }
00577     }
00578     
00586     function log($string)
00587     {
00588         $x="LOG ".addcslashes($string,"\000..\037\177..\377");
00589         $this->lines.=$x."\n";
00590     }
00591     
00601     function execute($procedure,$arguments)
00602     {
00603         $x="EXECUTE ".$procedure."(";
00604         $first=TRUE;
00605         foreach($arguments as $e) {
00606             if(!$first)
00607                 $x.=",";
00608             $first=FALSE;
00609             $x.="\"";
00610             $x.=addslashes($e);
00611             $x.="\"";
00612         }
00613         $x.=")";
00614         
00615         $this->lines.=$x."\n";
00616     }
00617     
00627     function filesys($object)
00628     {
00629         $r="FILESYS InternalName ".$object->internal_name;
00630         $this->lines.=$r."\n";
00631 
00632         $r="FILESYS SET type ".$object->type;
00633         $this->lines.=$r."\n";
00634 
00635         $r="FILESYS SET PublicName ".$object->public_name;
00636         $this->lines.=$r."\n";
00637 
00638         $r="FILESYS SET Time ".$object->time;
00639         $this->lines.=$r."\n";
00640 
00641         $r="FILESYS SET Published ".($object->published?"1":"0");
00642         $this->lines.=$r."\n";
00643 
00644         $r="FILESYS SET Complete ".($object->complete?"1":"0");
00645         $this->lines.=$r."\n";
00646 
00647         $r="FILESYS SET Expiration ".$object->expiration;
00648         $this->lines.=$r."\n";
00649 
00650         foreach($object->access as $e) {
00651             // begin of access rights
00652             $r="FILESYS ACCESS_BEGIN";
00653             $this->lines.=$r."\n";
00654 
00655             $r="FILESYS SET AllUsers ".($e->all_users?"1":"0");
00656             $this->lines.=$r."\n";
00657 
00658             $r="FILESYS SET UserName ".$e->user_name;
00659             $this->lines.=$r."\n";
00660 
00661             $r="FILESYS SET Owner ".($e->owner?"1":"0");
00662             $this->lines.=$r."\n";
00663 
00664             $r="FILESYS SET Read ".($e->read?"1":"0");
00665             $this->lines.=$r."\n";
00666 
00667             $r="FILESYS SET Delete ".($e->delete?"1":"0");
00668             $this->lines.=$r."\n";
00669 
00670             $r="FILESYS SET NotifyOwner ".($e->notify_owner?"1":"0");
00671             $this->lines.=$r."\n";
00672             
00673             $r="FILESYS SET NotifyUser ".($e->notify_user?"1":"0");
00674             $this->lines.=$r."\n";
00675 
00676             $r="FILESYS SET Secure ".($e->secure?"1":"0");
00677             $this->lines.=$r."\n";
00678 
00679             $r="FILESYS SET AllOnChannel ".$e->all_on_channel;
00680             $this->lines.=$r."\n";
00681 
00682             $r="FILESYS SET AlsoUnknown ".($e->also_unknown?"1":"0");
00683             $this->lines.=$r."\n";
00684 
00685             // warning: string "hello\nworld\x07!" should be represented as "hello\\nworld\\x07!"
00686             $r="FILESYS SET NotifyOwnerMessage ".$e->notify_owner_message;
00687             $this->lines.=$r."\n";
00688 
00689             // warning: string "hello\nworld\x07!" should be represented as "hello\\nworld\\x07!"
00690             $r="FILESYS SET NotifyUserMessage ".$e->notify_user_message;
00691             $this->lines.=$r."\n";
00692 
00693             // end of access rights
00694             $r="FILESYS ACCESS_END";
00695             $this->lines.=$r."\n";
00696         }
00697         
00698         // event modifying not supported yet
00699 
00700         // commit
00701         $r="FILESYS COMMIT";
00702         $this->lines.=$r."\n";
00703     }
00704     
00711     function cancel($string)
00712     {
00713         $this->lines="";
00714     }
00715     
00722     function commit()
00723     {
00724         if($this->commited) {
00725             echo "Warning: ".__CLASS__."::".__FUNCTION__."() You have already done commit - this can confuse bot!\n";
00726         }
00727         $this->commited=TRUE;
00728         echo "\n#####\n".$this->lines."#####\n"; // NB: we got \n at the end of $this->lines
00729         $this->lines="";
00730     }
00731 }
00732 
00733 ?>

Generated on Sun Jul 24 16:21:26 2005 for Library for "php_2" scripting by  doxygen 1.4.3