123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
- set_time_limit(0);
-
-
- include_once("config.php");
-
-
- $username = $argv[1];
-
-
- if(!isset($username) || $username == "") {
- echo "Username not given...";
- exit(1);
- }
-
-
- $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
-
-
- socket_connect($socket, $server, $port);
-
-
- $nickline = "NICK " . $username . "\n";
- $userline = "USER " . $username . " 0 * :" . $username . "'s Bot\n";
-
-
- socket_write($socket, $nickline, strlen($nickline));
- socket_write($socket, $userline, strlen($userline));
-
- sleep(1);
-
-
-
- while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') {
- if($bytes !== FALSE) {
-
- $data = $r_data;
- }
-
-
- if(file_exists(".$username.push")) {
-
- $pushFile = file_get_contents(".$username.push");
-
- socket_write($socket, $pushFile, strlen($pushFile));
-
- unlink(".$username.push");
- }
-
-
- if(!file_exists(".$username.pingfile")) {
-
- doLog("Exiting, $username logged out...");
- $quitline = "QUIT :$username left the web client\n";
- socket_write($socket, $quitline, strlen($quitline));
- socket_close($socket);
- exit(0);
- } else if (date("YmdHis.", filemtime(".$username.pingfile"))<(date("YmdHis.", filemtime(".$username.pingfile"))-10)) {
-
- doLog("Exiting, $username timed out...");
- $quitline = "QUIT :$username's web session timed out\n";
- socket_write($socket, $quitline, strlen($quitline));
- socket_close($socket);
- exit(1);
- }
-
-
-
- if(isset($data)) {
- $stringMsg = explode('PRIVMSG', $data);
-
- $socketFileContents = file_get_contents(".$username.socket");
-
- file_put_contents(".$username.socket", $socketFileContents . $data);
- $ex = explode(' ', $data);
-
-
- if ($ex[0] == "PING") {
-
- doLog("PONG, $username response...");
- $pongline = "PONG " . $ex[1] . "\n";
-
- socket_write($socket, $pongline, strlen($pongline));
- }
- }
-
-
- usleep(500);
- }
-
- ?>
|