Advertisement
johnburn

Untitled

Dec 14th, 2011
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 395.55 KB | None | 0 0
  1. <?php
  2. class blowfish {
  3.     public function bytetob64($ec) {
  4.         $dc = "";
  5.         $k = 0 - 1;
  6.         do {
  7.             if (!($k < strlen($ec) - 1)) {
  8.                 break;
  9.             } else {
  10.                 ++$k;
  11.                 $left = ord($ec[$k]) << 24;
  12.                 ++$k;
  13.                 $left+= ord($ec[$k]) << 16;
  14.                 ++$k;
  15.                 $left+= ord($ec[$k]) << 8;
  16.                 ++$k;
  17.                 $left+= ord($ec[$k]);
  18.                 ++$k;
  19.                 $right = ord($ec[$k]) << 24;
  20.                 ++$k;
  21.                 $right+= ord($ec[$k]) << 16;
  22.                 ++$k;
  23.                 $right+= ord($ec[$k]) << 8;
  24.                 ++$k;
  25.                 $right+= ord($ec[$k]);
  26.                 $i = 0;
  27.             }
  28.             while ($i < 6) {
  29.                 $dc.= $this->B64[$right & 63];
  30.                 $right = $right >> 6;
  31.                 ++$i;
  32.             }
  33.             $i = 0;
  34.             do {
  35.             }
  36.             while (!($i < 6));
  37.             $dc.= $this->B64[$left & 63];
  38.             $left = $left >> 6;
  39.             ++$i;
  40.         }
  41.         while (1);
  42.         return $dc;
  43.     }
  44.     public function b64tobyte($ec) {
  45.         $dc = "";
  46.         $k = 0 - 1;
  47.         do {
  48.             if (!($k < strlen($ec) - 1)) {
  49.                 break;
  50.             } else {
  51.                 $right = 0;
  52.                 $left = 0;
  53.                 $i = 0;
  54.             }
  55.             while ($i < 6) {
  56.                 ++$k;
  57.                 $right|= @strpos(@$this->B64, @$ec[$k]) << $i * 6;
  58.                 ++$i;
  59.             }
  60.             $i = 0;
  61.             while ($i < 6) {
  62.                 ++$k;
  63.                 $left|= @strpos(@$this->B64, @$ec[$k]) << $i * 6;
  64.                 ++$i;
  65.             }
  66.             $i = 0;
  67.             while ($i < 4) {
  68.                 $dc.= chr(($left & 255 << (3 - $i) * 8) >> (3 - $i) * 8);
  69.                 ++$i;
  70.             }
  71.             $i = 0;
  72.             do {
  73.             }
  74.             while (!($i < 4));
  75.             $dc.= chr(($right & 255 << (3 - $i) * 8) >> (3 - $i) * 8);
  76.             ++$i;
  77.         }
  78.         while (1);
  79.         return $dc;
  80.     }
  81.     public function encrypt($text, $key) {
  82.         $td = mcrypt_module_open(MCRYPT_BLOWFISH, "", MCRYPT_MODE_ECB, "");
  83.         $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
  84.         $text.= str_repeat(chr(0), 8 - strlen($text) % 8);
  85.         mcrypt_generic_init($td, $key, $iv);
  86.         $ec = mcrypt_generic($td, $text);
  87.         mcrypt_module_close($td);
  88.         return bytetoB64($ec);
  89.     }
  90.     public function decrypt($text, $key) {
  91.         $td = mcrypt_module_open(MCRYPT_BLOWFISH, "", MCRYPT_MODE_ECB, "");
  92.         $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
  93.         mcrypt_generic_init($td, $key, $iv);
  94.         $tmp = mdecrypt_generic($td, B64tobyte($text));
  95.         $tmp = str_replace(chr(0), "", $tmp);
  96.         mcrypt_module_close($td);
  97.         return $tmp;
  98.     }
  99. }
  100. function mquery($query) {
  101.     if (debugoutput == 1) {
  102.         if (!($sql = mysql_query($query))) {
  103.             exit(mysql_error());
  104.         }
  105.         echo "MySQL -> " . $query . "\r\n";
  106.     } else {
  107.         $sql = mysql_query($query);
  108.     }
  109.     return $sql;
  110. }
  111. function cw($data, $word) {
  112.     if (strtolower(substr($data, 0, strlen($word))) == $word) {
  113.         return true;
  114.     }
  115.     return false;
  116. }
  117. function checkadmin($uid, $reqlvl) {
  118.     $userlvl = mysql_result(mquery("select admin from users where id='" . $uid . "'"), 0);
  119.     if ($reqlvl <= $userlvl) {
  120.         return true;
  121.     }
  122.     return false;
  123. }
  124. function escape($text) {
  125.     $text = str_replace("\\", "\\\\", $text);
  126.     $text = str_replace("-", "\\-", $text);
  127.     $text = str_replace("^", "\\^", $text);
  128.     $text = str_replace("`", "\\`", $text);
  129.     $text = str_replace("[", "\\[", $text);
  130.     $text = str_replace("]", "\\]", $text);
  131.     $text = str_replace("}", "\\}", $text);
  132.     $text = str_replace("{", "\\}", $text);
  133.     $text = str_replace("|", "\\|", $text);
  134.     $text = str_replace("_", "\\_", $text);
  135.     return $text;
  136. }
  137. define("starttime", time());
  138. define("version", "0.18-beta");
  139. $lastpingrequest = time();
  140. include ("./config.php");
  141. if (license != "ACCEPT") {
  142.     echo "You have to accept the license before you can use this software, see the config.\r\n";
  143.     exit();
  144. }
  145. $versioncheck = @file_get_contents("http://78.108.54.18/phpbnc.php?version=status");
  146. if ($versioncheck == false) {
  147.     echo "Cant contact beta server, please make sure you can reach 78.108.54.18 on port 80 tcp.\r\n";
  148.     exit();
  149. } else if (substr($versioncheck, 0, 4) == "LIVE") {
  150.     echo "The live version of phpBNC has been released, you wont be able to use this beta version anymore.\r\n";
  151.     exit();
  152. } else if (substr(version, 0, 4) < substr($versioncheck, strlen($versionchecker) - 4, 4)) {
  153.     echo "There has been a new version released for phpBNC, I suggest you upgrade to that.\r\n";
  154.     sleep(5);
  155. }
  156. unset($versioncheck);
  157. echo "Connecting to MySQL...\r\n";
  158. if (!($connecta = mysql_connect(myhost, myuser, mypwd))) {
  159.     exit(mysql_error());
  160. }
  161. if (!mysql_select_db(mydb)) {
  162.     exit(mysql_error());
  163. }
  164. echo "Connected to MySQL.\r\n";
  165. mquery("TRUNCATE TABLE `tempchannels`");
  166. mquery("update users set net_name=''");
  167. mquery("update users set currentnick=nick");
  168. $sockets = array();
  169. echo "Starting listening sockets...\r\n";
  170. foreach($listen as $ipet) {
  171.     if (substr($ipet, 0, 3) == "ssl") {
  172.         $context = stream_context_create();
  173.         stream_context_set_option($context, "ssl", "local_cert", sslcert);
  174.         stream_context_set_option($context, "ssl", "passphrase", sslkey);
  175.         stream_context_set_option($context, "ssl", "allow_self_signed", true);
  176.         stream_context_set_option($context, "ssl", "verify_peer", false);
  177.         $sock = stream_socket_server($ipet, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);
  178.         stream_set_blocking($sock, false);
  179.         echo $errno . " " . $errstr . "\r\n";
  180.         $sockets[] = $sock;
  181.         unset($sock);
  182.     } else {
  183.         $sock = stream_socket_server($ipet, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN);
  184.         echo $errno . " " . $errstr . "\r\n";
  185.         $sockets[] = $sock;
  186.         unset($sock);
  187.     }
  188.     unset($errno);
  189.     unset($errstr);
  190. }
  191. unset($listen);
  192. unset($ipt);
  193. if (enableident) {
  194.     $sock3 = stream_socket_server("tcp://" . identdip . ":" . identdport, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN);
  195.     echo $errno . " " . $errstr . "\r\n";
  196. }
  197. echo "Sockets up and runnning.\r\n";
  198. $clients = array();
  199. if (enableident) {
  200.     $identd = array($sock3);
  201. }
  202. $authed = array();
  203. $net_clients = array();
  204. $ident_ports = array();
  205. $admins = array();
  206. $tempnicks = array();
  207. $queue = array();
  208. $userconmem = array();
  209. echo "Loading usersettings into memory...\r\n";
  210. $usersettings = array();
  211. $sql = mquery("select * from users order by id asc");
  212. while ($RS = mysql_fetch_array($sql)) {
  213.     $usersettings[$RS['id']]['nick'] = $RS['nick'];
  214.     $usersettings[$RS['id']]['nickreq'] = "";
  215.     $usersettings[$RS['id']]['currentnick'] = $RS['currentnick'];
  216.     $usersettings[$RS['id']]['tempnick'] = $RS['nick'];
  217.     $usersettings[$RS['id']]['username'] = $RS['username'];
  218.     $usersettings[$RS['id']]['host'] = $RS['host'];
  219.     $usersettings[$RS['id']]['away_nick'] = $RS['away_nick'];
  220.     $usersettings[$RS['id']]['away_msg'] = $RS['away_msg'];
  221.     $usersettings[$RS['id']]['admin'] = $RS['admin'];
  222.     $usersettings[$RS['id']]['net_name'] = $RS['net_name'];
  223.     $usersettings[$RS['id']]['trailed'] = $RS['trailed'];
  224.     $usersettings[$RS['id']]['channellog'] = $RS['channellog'];
  225.     $usersettings[$RS['id']]['flood'] = $RS['flood'];
  226.     $usersettings[$RS['id']]['lastlogin'] = "";
  227.     $usersettings[$RS['id']]['lastcommand'] = time();
  228.     $usersettings[$RS['id']]['delay'] = 0;
  229.     $usersettings[$RS['id']]['lastcontry'] = time();
  230. }
  231. echo "Loaded usersettings into memory.\r\n";
  232. echo "Loading blowfish keys into memory...\r\n";
  233. $bfkeys = array();
  234. $sql = mquery("select * from blowfish_keys order by id asc");
  235. while ($RS = mysql_fetch_array($sql)) {
  236.     $bfkeys[$RS['uid']][$RS['target']]['name'] = $RS['target'];
  237.     $bfkeys[$RS['uid']][$RS['target']]['target_nick'] = $RS['target_nick'];
  238.     $bfkeys[$RS['uid']][$RS['target']]['key'] = $RS['key'];
  239. }
  240. echo "Loaded blowfish keys into memory.\r\n";
  241. $Var_8328->blowfish();
  242. $crypt = $Var_8328;
  243. echo "Im good to go, phpBNC v." . version . ", http://www.phpBNC.se/\r\n";
  244. echo "Starting in..";
  245. sleep(1);
  246. echo "5..";
  247. sleep(1);
  248. echo "4..";
  249. sleep(1);
  250. echo "3..";
  251. sleep(1);
  252. echo "2..";
  253. sleep(1);
  254. echo "1..\r\n";
  255. $lastmysqlcheck = time();
  256. $mysql_connection = "up";
  257. while (true) {
  258.     unset($uid);
  259.     usleep(10000);
  260.     if (0 < count($queue)) {
  261.         foreach($queue as $key => $qval1) {
  262.             foreach($qval1 as $uid => $qval2) {
  263.                 foreach($qval2 as $sendtime => $qval3) {
  264.                     if (!($sendtime < time())) {
  265.                         continue;
  266.                     } else if (array_key_exists($uid, $net_clients)) {
  267.                         fwrite($net_clients[$uid], $qval3['command']);
  268.                         unset($queue[$key]);
  269.                         unset($key);
  270.                         unset($qval1);
  271.                         unset($qval2);
  272.                         unset($qval3);
  273.                         unset($sendtime);
  274.                     } else {
  275.                         unset($queue[$key]);
  276.                         unset($key);
  277.                         unset($qval1);
  278.                         unset($qval2);
  279.                         unset($qval3);
  280.                         unset($sendtime);
  281.                     }
  282.                 }
  283.             }
  284.         }
  285.     }
  286.     if ($lastmysqlcheck < time() - 60 || $mysql_connection == "down" && $lastmysqlcheck < time() - 15) {
  287.         if (!mysql_ping($connecta)) {
  288.             $mysql_connection = "down";
  289.             foreach($admins as $useridet2) {
  290.                 foreach($authed as $cliID2) {
  291.                     if (@array_key_exists(@$useridet2, @$cliID2)) {
  292.                         fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "4MySQL:" . chr(3) . chr(2) . " Lost connection to mysql server.\r\n");
  293.                         fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "4MySQL:" . chr(3) . chr(2) . " Trying to reconnect..\r\n");
  294.                     }
  295.                 }
  296.             }
  297.             mysql_close($connecta);
  298.             unset($connecta);
  299.             $connecta = mysql_connect(myhost, myuser, mypwd);
  300.             mysql_select_db(mydb);
  301.             if (!mysql_ping($connecta)) {
  302.                 foreach($admins as $useridet2) {
  303.                     foreach($authed as $cliID2) {
  304.                         if (@array_key_exists(@$useridet2, @$cliID2)) {
  305.                             fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "4MySQL:" . chr(3) . chr(2) . " Can´t connect to mysql again, seems to be down.. testing again in 30 seconds\r\n");
  306.                         }
  307.                     }
  308.                 }
  309.                 $mysql_connection = "down";
  310.             } else {
  311.                 foreach($admins as $useridet2) {
  312.                     foreach($authed as $cliID2) {
  313.                         if (@array_key_exists(@$useridet2, @$cliID2)) {
  314.                             fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "3MySQL:" . chr(3) . chr(2) . " Connected to mysql server again, updating usermemory and bfkeys incase its out of sync.\r\n");
  315.                             unset($usersettings);
  316.                             $usersettings = array();
  317.                             $sql = mquery("select * from users order by id asc");
  318.                             while ($RS = mysql_fetch_array($sql)) {
  319.                                 $usersettings[$RS['id']]['nick'] = $RS['nick'];
  320.                                 $usersettings[$RS['id']]['nick'] = $RS['currentnick'];
  321.                                 $usersettings[$RS['id']]['username'] = $RS['username'];
  322.                                 $usersettings[$RS['id']]['host'] = $RS['host'];
  323.                                 $usersettings[$RS['id']]['away_nick'] = $RS['away_nick'];
  324.                                 $usersettings[$RS['id']]['away_msg'] = $RS['away_msg'];
  325.                                 $usersettings[$RS['id']]['admin'] = $RS['admin'];
  326.                                 $usersettings[$RS['id']]['net_name'] = $RS['net_name'];
  327.                                 $usersettings[$RS['id']]['trailed'] = $RS['trailed'];
  328.                                 $usersettings[$RS['id']]['channellog'] = $RS['channellog'];
  329.                                 $usersettings[$RS['id']]['flood'] = $RS['flood'];
  330.                                 $usersettings[$RS['id']]['lastlogin'] = "";
  331.                                 $usersettings[$RS['id']]['lastcommand'] = time();
  332.                                 $usersettings[$RS['id']]['delay'] = 0;
  333.                             }
  334.                             unset($bfkeys);
  335.                             $bfkeys = array();
  336.                             $sql = mquery("select * from blowfish_keys order by id asc");
  337.                             do {
  338.                                 if ($RS = mysql_fetch_array($sql)) {
  339.                                     $bfkeys[$RS['uid']][$RS['target']]['name'] = $RS['target'];
  340.                                     $bfkeys[$RS['uid']][$RS['target']]['target_nick'] = $RS['target_nick'];
  341.                                     $bfkeys[$RS['uid']][$RS['target']]['key'] = $RS['key'];
  342.                                 }
  343.                             }
  344.                             while (1);
  345.                         }
  346.                     }
  347.                 }
  348.                 $mysql_connection = "up";
  349.             }
  350.         } else {
  351.             $mysql_connection = "up";
  352.         }
  353.         $lastmysqlcheck = time();
  354.     }
  355.     if (enableident) {
  356.         $read = array_merge(array_values($clients), array_values($sockets), array_values($net_clients), array_values($identd));
  357.     } else {
  358.         $read = array_merge(array_values($clients), array_values($sockets), array_values($net_clients));
  359.     }
  360.     if (0 < stream_select($read, $write = NULL, $except = NULL, 0)) {
  361.         foreach($sockets as $sock) {
  362.             if (@(in_array($sock, $read) && !in_array($sock, $net_clients) && !in_array(@$sock, @$identd))) {
  363.                 $clients[] = $newsock = @stream_socket_accept(@$sock);
  364.                 stream_set_timeout($newsock, 5);
  365.                 stream_set_blocking($newsock, false);
  366.                 $currentonline = count($clients);
  367.                 @fwrite(@$newsock, @":phpBNC 375 you : \r\n" . (":phpBNC 372 you : \r\n") . ":phpBNC 372 you :           _               ___      __   ___  \r\n" . ":phpBNC 372 you :    _ __  | |__   _ __    / __\\  /\\ \\ \\ / __\\ \r\n" . ":phpBNC 372 you :   | '_ \\ | '_ \\ | '_ \\  /__\\// /  \\/ // /    \r\n" . ":phpBNC 372 you :   | |_) || | | || |_) |/ \\/  \\/ /\\  // /___  \r\n" . ":phpBNC 372 you :   | .__/ |_| |_|| .__/ \\_____/\\_\\ \\/ \\____/  \r\n" . ":phpBNC 372 you :   |_|           |_|                          \r\n" . ":phpBNC 372 you :                      By Daniel \"blodan\" Ylitalo \r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 372 you :    www.phpBNC.se / .com / .org / .eu / .net / .nu\r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 372 you :   There are " . @$currentonline . " client(s) connected to the BNC server.\r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 372 you :    Please login using /login <username> <password>\r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 376 you : \r\n" . ":phpBNC NOTICE you :If you have skip MOTD activated i suggest you deactivate it now.\r\n");
  368.                 unset($currentonline);
  369.                 $ip = explode(":", @stream_socket_get_name(@$newsock, @true));
  370.                 echo "New client connected: " . $ip[0] . "\r\n";
  371.                 unset($ip);
  372.                 $key = array_search($sock, $read);
  373.                 unset($read[$key]);
  374.                 unset($key);
  375.                 unset($newsock);
  376.             }
  377.         }
  378.         if (in_array($sock3, $read) && !in_array($sock3, $net_clients) && !in_array($sock3, $clients) && enableident == true) {
  379.             $identd[] = $newsock = @stream_socket_accept(@$sock3);
  380.             stream_set_blocking($newsock, 0);
  381.             $ip = explode(":", @stream_socket_get_name(@$newsock, @true));
  382.             echo "New identd connection: " . $ip[0] . "\r\n";
  383.             unset($ip);
  384.             $key = array_search($sock3, $read);
  385.             unset($read[$key]);
  386.             unset($key);
  387.             unset($newsock);
  388.         }
  389.         foreach($read as $read_sock) {
  390.             unset($data);
  391.             unset($uid);
  392.             $nfo = stream_get_meta_data($read_sock);
  393.             $data = fgets($read_sock);
  394.             if (preg_match("/^ERROR :Closing Link: (.*)$/", $data, $m)) {
  395.                 $online = 0;
  396.                 $uid = array_search($read_sock, $net_clients);
  397.                 foreach($authed as $cliID) {
  398.                     if (@array_key_exists(@$uid, @$cliID)) {
  399.                         $online = 1;
  400.                         fwrite($cliID[$uid], ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :You got disconnected from the IRC server you were connected to due to: " . $m[1] . "\r\n");
  401.                         fwrite($cliID[$uid], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$uid]['currentnick'] . " :You got disconnected from the IRC server you were connected to due to: " . $m[1] . "\r\n");
  402.                     }
  403.                 }
  404.                 if ($online == 0) {
  405.                     mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("You got disconnected from the IRC server you were connected to due to: " . $m[1]) . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($uid) . "')");
  406.                 }
  407.                 unset($online);
  408.             }
  409.             if (preg_match("/^NICK (.*)$/", $data, $m) && !in_array($read_sock, $authed)) {
  410.                 $tempnicks = array_merge(array($m[1] => $read_sock), $tempnicks);
  411.             }
  412.             if (preg_match("/^:(.*) 001 (.*) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
  413.                 $uid = array_search($read_sock, $net_clients);
  414.                 if ($usersettings[$uid]['currentnick'] != trim($m[2])) {
  415.                     foreach($authed as $cliID) {
  416.                         if (@array_key_exists(@$uid, @$cliID)) {
  417.                             fwrite($cliID[$uid], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :" . trim(substr($m[2], 0, 15)) . "][" . $usersettings[$uid]['username'] . "\r\n");
  418.                         }
  419.                     }
  420.                     mquery("update users set currentnick='" . mysql_real_escape_string(trim(substr($m[2], 0, 15))) . "' where id='" . mysql_real_escape_string($uid) . "'");
  421.                     $usersettings[$uid]['currentnick'] = trim(substr($m[2], 0, 15));
  422.                 }
  423.                 unset($m);
  424.                 unset($uid);
  425.             }
  426.             if (preg_match("/^:(.*) 005 (.*) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
  427.                 $string = explode(" ", $m[2]);
  428.                 unset($string[0]);
  429.                 foreach($string as $jadu) {
  430.                     $exist = false;
  431.                     if (preg_match("/^NETWORK=(.*)$/", $jadu, $z)) {
  432.                         mquery("update users set net_name='" . $z[1] . "' where id='" . array_search($read_sock, $net_clients) . "'");
  433.                         $usersettings[array_search(@$read_sock, @$net_clients) ]['net_name'] = $z[1];
  434.                     }
  435.                     if (preg_match("/^CHANTYPES=(.*?)$/", $jadu, $z)) {
  436.                         $i = 0;
  437.                         while ($i < strlen($z[1])) {
  438.                             if ($z[1][$i] == "&") {
  439.                                 $exist = true;
  440.                             }
  441.                             ++$i;
  442.                         }
  443.                         if ($exist == false) {
  444.                             $data = str_replace("CHANTYPES=" . $z[1], "CHANTYPES=" . $z[1] . "&", $data);
  445.                         }
  446.                     }
  447.                 }
  448.                 unset($exist);
  449.                 unset($temp);
  450.                 unset($jadu);
  451.                 unset($string);
  452.                 unset($z);
  453.             }
  454.             if (!$nfo['timed_out'] && !$nfo['eof']) {
  455.                 $data = trim($data);
  456.                 if (!empty("data")) {
  457.                     if (strtolower(substr($data, 0, 4)) == "ping") {
  458.                         strtok($data, ":");
  459.                         $pingrequest = strtok(":");
  460.                         fwrite($read_sock, "PONG :{$pingrequest}\r\n");
  461.                         unset($pingrequest);
  462.                         continue;
  463.                     }
  464.                     if (strtolower(substr($data, 0, 4)) == "quit") {
  465.                         continue;
  466.                     }
  467.                     $command = 0;
  468.                     $commands = array("pb", "bconnect", "login", "pass", "bhelp", "breconnect", "brestore", "bclear", "bquit", "readlog", "dellog");
  469.                     foreach($commands as $checkthis) {
  470.                         if (cw($data, $checkthis) == true) {
  471.                             $command = 1;
  472.                         }
  473.                     }
  474.                     if (@in_array(@$read_sock, @$net_clients)) {
  475.                         $uid = array_search($read_sock, $net_clients);
  476.                         $versionreq = false;
  477.                         if (debugoutput == 1) {
  478.                             echo "SERVER <-" . $data . "\r\n";
  479.                         }
  480.                         if (preg_match("/^:(.*?) PONG (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
  481.                             continue;
  482.                         }
  483.                         if (preg_match("/^:(.*?) 001 (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
  484.                             $userconmem[$uid][] = ":" . $m[1] . " 001 %nick% :" . $m[3];
  485.                             unset($m);
  486.                         }
  487.                         if (preg_match("/^:(.*?) 002 (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
  488.                             $userconmem[$uid][] = ":" . $m[1] . " 002 %nick% :" . $m[3];
  489.                             unset($m);
  490.                         }
  491.                         if (preg_match("/^:(.*?) 003 (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
  492.                             $userconmem[$uid][] = ":" . $m[1] . " 003 %nick% :" . $m[3];
  493.                             unset($m);
  494.                         }
  495.                         if (preg_match("/^:(.*?) 004 (.*?) (.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
  496.                             $userconmem[$uid][] = ":" . $m[1] . " 004 %nick% " . $m[3];
  497.                             unset($m);
  498.                         }
  499.                         if (preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG (.*?) :" . chr(1) . "VERSION" . chr(1) . "$/", $data, $m)) {
  500.                             if ($m[4][0] != "#") {
  501.                                 fwrite($read_sock, "NOTICE " . $m[1] . " :" . chr(1) . "VERSION This user is using phpBNC v." . version . ", www.phpBNC.se" . chr(1) . "\r\n");
  502.                                 $versionreq = true;
  503.                             }
  504.                             unset($m);
  505.                         }
  506.                         if (preg_match("/^:(.*?) 433 (.*?) (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients) && $m[2] != $usersettings[$uid]['currentnick']) {
  507.                             if (time() - $usersettings[$uid]['lastcontry'] < 15) {
  508.                                 foreach($authed as $cliID) {
  509.                                     if (@array_key_exists(@$uid, @$cliID)) {
  510.                                         fwrite($cliID[$uid], ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :_" . $usersettings[$uid]['tempnick'] . "\r\n");
  511.                                         $online = 1;
  512.                                     }
  513.                                 }
  514.                             }
  515.                             fwrite($read_sock, "NICK _" . $usersettings[$uid]['tempnick'] . "\r\n");
  516.                             $usersettings[$uid]['tempnick'] = "_" . $usersettings[$uid]['tempnick'];
  517.                         }
  518.                         if (preg_match("/^:(.*?) (.*?) " . escape($usersettings[$uid]['currentnick']) . " #(.*?) :Cannot join channel(.*)$/", $data, $m)) {
  519.                             mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='#" . mysql_real_escape_string($m[3]) . "'");
  520.                             unset($m);
  521.                         }
  522.                         if (preg_match("/^:" . escape($usersettings[$uid]['currentnick']) . "!" . escape($usersettings[$uid]['username']) . "@" . escape($usersettings[$uid]['host']) . " JOIN #(.*)$/", $data, $m)) {
  523.                             mquery("update tempchannels set channel='#" . mysql_real_escape_string($m[1]) . "' where uid='" . mysql_real_escape_string($uid) . "' and channel='#" . mysql_real_escape_string($m[1]) . "'");
  524.                         }
  525.                         if (preg_match("/^:" . escape($usersettings[$uid]['currentnick']) . "!" . escape($usersettings[$uid]['username']) . "@" . escape($usersettings[$uid]['host']) . " NICK :(.*)$/", $data, $m)) {
  526.                             foreach($admins as $useridet2) {
  527.                                 foreach($authed as $cliID2) {
  528.                                     if (@array_key_exists(@$useridet2, @$cliID2)) {
  529.                                         fwrite($cliID2[$useridet2], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :" . $m[1] . "][" . $usersettings[$uid]['username'] . "\r\n");
  530.                                     }
  531.                                 }
  532.                             }
  533.                             if ($usersettings[$uid]['nickreq'] == $m[1]) {
  534.                                 mquery("update users set currentnick='" . mysql_real_escape_string($m[1]) . "', nick='" . mysql_real_escape_string($m[1]) . "' where id='" . mysql_real_escape_string($uid) . "'");
  535.                                 $usersettings[$uid]['nickreq'] = "";
  536.                                 $usersettings[$uid]['nick'] = $m[1];
  537.                                 $usersettings[$uid]['tempnick'] = $m[1];
  538.                             } else {
  539.                                 mquery("update users set currentnick='" . mysql_real_escape_string($m[1]) . "' where id='" . mysql_real_escape_string($uid) . "'");
  540.                             }
  541.                             $usersettings[$uid]['currentnick'] = $m[1];
  542.                             if (0 < $usersettings[$uid]['admin']) {
  543.                                 $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
  544.                                 $ucounter = 0;
  545.                                 foreach($authed as $cliID) {
  546.                                     if (40 <= $ucounter) {
  547.                                         foreach($authed as $cliID) {
  548.                                             if (@array_key_exists(@$uid, @$cliID)) {
  549.                                                 fwrite($cliID[$uid], $alltheusers . "\r\n");
  550.                                             }
  551.                                         }
  552.                                         $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :";
  553.                                         $ucounter = 0;
  554.                                     }
  555.                                     $user = array_keys($cliID);
  556.                                     $user = $user[0];
  557.                                     $fore = "";
  558.                                     if ($usersettings[$user]['admin'] == 1) {
  559.                                         $fore = "+";
  560.                                     } else if ($usersettings[$user]['admin'] == 2) {
  561.                                         $fore = "@";
  562.                                     }
  563.                                     if ($ucounter == 0) {
  564.                                         $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  565.                                     } else {
  566.                                         $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  567.                                     }
  568.                                     ++$ucounter;
  569.                                 }
  570.                                 foreach($authed as $cliID) {
  571.                                     if (@array_key_exists(@$uid, @$cliID)) {
  572.                                         fwrite($cliID[$uid], $alltheusers . "\r\n");
  573.                                         fwrite($cliID[$uid], ":phpBNC 366 " . $usersettings[$uid]['currentnick'] . " &system :End of /NAMES list.\r\n");
  574.                                     }
  575.                                 }
  576.                                 unset($ucounter);
  577.                             }
  578.                             unset($useridet2);
  579.                             unset($cliID2);
  580.                             unset($m);
  581.                         }
  582.                         if (preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG " . escape($usersettings[$uid]['currentnick']) . " :\\+OK (.*)$/", $data, $m)) {
  583.                             if (@array_key_exists(@$m[2] . "@" . @$m[3], @$bfkeys[$uid])) {
  584.                                 $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " PRIVMSG " . $usersettings[$uid]['currentnick'] . " :" . decrypt($m[4], $bfkeys[$uid][$m[2] . "@" . $m[3]]['key']) . "\r\n";
  585.                                 mquery("update blowfish_keys set target_nick='" . mysql_real_escape_string($m[1]) . "' where uid='" . mysql_real_escape_string($uid) . "' and target='" . mysql_real_escape_string($m[2] . "@" . $m[3]) . "'");
  586.                                 $bfkeys[$uid][$m[2] . "@" . $m[3]]['target_nick'] = $m[1];
  587.                             }
  588.                             unset($m);
  589.                         } else if (preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG #(.*?) :\\+OK (.*)$/", $data, $m)) {
  590.                             if (@array_key_exists(@"#" . @$m[4], @$bfkeys[$uid])) {
  591.                                 $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " PRIVMSG #" . $m[4] . " :" . decrypt($m[5], $bfkeys[$uid]["#" . $m[4]]['key']) . "\r\n";
  592.                             }
  593.                             unset($m);
  594.                         } else if (preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG (.*?) :(.*)$/", $data, $m)) {
  595.                             $counter = false;
  596.                             if (@($m[4][0] == "#" && array_key_exists(@$m[4], @$bfkeys[$uid]))) {
  597.                                 $counter = true;
  598.                             }
  599.                             if (@array_key_exists(@$m[2] . "@" . @$m[3], @$bfkeys[$uid])) {
  600.                                 $counter = true;
  601.                             }
  602.                             if (substr($m[5], 0, 3) != "+OK" && $counter == true && strtolower(substr($m[5], 0, 7)) != chr(1) . "action") {
  603.                                 $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " PRIVMSG " . $m[4] . " :" . chr(3) . "4!" . chr(3) . " " . $m[5] . "\r\n";
  604.                                 if ($m[4][0] != "#") {
  605.                                     mquery("update blowfish_keys set target_nick='" . mysql_real_escape_string($m[1]) . "' where uid='" . mysql_real_escape_string($uid) . "' and target='" . mysql_real_escape_string($m[2] . "@" . $m[3]) . "'");
  606.                                     $bfkeys[$uid][$m[2] . "@" . $m[3]]['target_nick'] = $m[1];
  607.                                 }
  608.                             }
  609.                             unset($m);
  610.                             unset($counter);
  611.                         }
  612.                         if (preg_match("/^:(.*?) 332 (.*?) (.*?) :\\+OK (.*)$/", $data, $m)) {
  613.                             if (@array_key_exists(@$m[3], @$bfkeys[$uid])) {
  614.                                 $data = ":" . $m[1] . " 332 " . $m[2] . " " . $m[3] . " :" . decrypt($m[4], $bfkeys[$uid][$m[3]]['key']) . "\r\n";
  615.                             }
  616.                             unset($m);
  617.                         } else if (preg_match("/^:(.*?)!(.*?)@(.*?) TOPIC (.*?) :\\+OK (.*)$/", $data, $m)) {
  618.                             if (@array_key_exists(@$m[4], @$bfkeys[$uid])) {
  619.                                 $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " TOPIC " . $m[4] . " :" . decrypt($m[5], $bfkeys[$uid][$m[4]]['key']) . "\r\n";
  620.                             }
  621.                             unset($m);
  622.                         } else if (preg_match("/^:(.*?) 332 (.*?) (.*?) :(.*)$/", $data, $m)) {
  623.                             if (array_key_exists(@$m[3], @$bfkeys[$uid]) && substr($m[4], 0, 3) != "+OK") {
  624.                                 $data = ":" . $m[1] . " 332 " . $m[2] . " " . $m[3] . " :" . chr(3) . "4!" . chr(3) . " " . $m[4] . "\r\n";
  625.                             }
  626.                             unset($m);
  627.                         } else if (preg_match("/^:(.*?)!(.*?)@(.*?) TOPIC (.*?) :(.*)$/", $data, $m)) {
  628.                             if (array_key_exists(@$m[4], @$bfkeys[$uid]) && substr($m[5], 0, 3) != "+OK") {
  629.                                 $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " TOPIC " . $m[4] . " :" . chr(3) . "4!" . chr(3) . " " . $m[5] . "\r\n";
  630.                             }
  631.                             unset($m);
  632.                         }
  633.                         $online = 0;
  634.                         foreach($authed as $cliID) {
  635.                             if (@array_key_exists(@$uid, @$cliID)) {
  636.                                 fwrite($cliID[$uid], $data . "\r\n");
  637.                                 $online = 1;
  638.                             }
  639.                         }
  640.                         if ($online == 0 && $versionreq == false && preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG (.*?) :(.*)$/", $data, $m)) {
  641.                             if ($m[4] == $usersettings[$uid]['away_nick']) {
  642.                                 mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string($m[1] . ": " . mysql_real_escape_string($m[5])) . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($uid) . "')");
  643.                                 if (strlen($usersettings[$uid]['away_msg']) != 0) {
  644.                                     fwrite($read_sock, "PRIVMSG " . $m[1] . " :" . $usersettings[$uid]['away_msg'] . "\r\n");
  645.                                 }
  646.                             } else if ($m[4][0] == "#" && $usersettings[$uid]['channellog'] == 1) {
  647.                                 mquery("insert into channellogs (uid, date, text) Values('" . mysql_real_escape_string($uid) . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string(":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " PRIVMSG " . $m[4] . " :PHPBNC_SAVE_" . time() . "_" . $m[5]) . "')");
  648.                             }
  649.                         }
  650.                         if ($usersettings[$uid]['trailed'] == 1) {
  651.                             $nujeflar = fopen("trail/" . $usersettings[$uid]['username'] . ".txt", "a");
  652.                             fwrite($nujeflar, "SERVER <- " . $data . "\r\n");
  653.                             fclose($nujeflar);
  654.                             unset($nujeflar);
  655.                         }
  656.                         unset($online);
  657.                         unset($uid);
  658.                         unset($versionreq);
  659.                     } else {
  660.                         if (array_key_exists(@array_search(@$read_sock, @$clients), @$authed) && $command != 1) {
  661.                             $uid = array_search($read_sock, $authed[array_search($read_sock, $clients) ]);
  662.                             if (debugoutput == 1) {
  663.                                 echo "USER ->" . $data . "\r\n";
  664.                             }
  665.                             if (preg_match("/^PONG :(.*)$/", $data, $m) && in_array($read_sock, $clients)) {
  666.                                 continue;
  667.                             }
  668.                             if (preg_match("/^[Ll][Ii][Ss][Tt](.*)$/", $data, $m) && in_array($read_sock, $clients)) {
  669.                                 continue;
  670.                             }
  671.                             if (cw($data, "mode &system")) {
  672.                                 fwrite($read_sock, ":phpBNC 324 " . $usersettings[$uid]['currentnick'] . " &system +stnCN\r\n");
  673.                                 fwrite($read_sock, ":phpBNC 329 " . $usersettings[$uid]['currentnick'] . " &system " . starttime . "\r\n");
  674.                             } else {
  675.                                 if (cw($data, "privmsg &system :") && in_array($uid, $admins)) {
  676.                                     preg_match("/^PRIVMSG &system :(.*)$/", $data, $m);
  677.                                     foreach($admins as $adminid) {
  678.                                         if ($adminid != $uid) {
  679.                                             foreach($authed as $cliID) {
  680.                                                 if (@array_key_exists(@$adminid, @$cliID)) {
  681.                                                     fwrite($cliID[$adminid], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " PRIVMSG &system :" . $m[1] . "\r\n");
  682.                                                 }
  683.                                             }
  684.                                         }
  685.                                     }
  686.                                     unset($adminid);
  687.                                     unset($cliID);
  688.                                     unset($m);
  689.                                 } else {
  690.                                     if (cw($data, "who &system") && 0 < $usersettings[$uid]['admin']) {
  691.                                         $sql = mquery("select * from users order by id desc");
  692.                                         while ($RS = mysql_fetch_array($sql)) {
  693.                                             foreach($authed as $cliID) {
  694.                                                 if (@array_key_exists(@$RS['id'], @$cliID)) {
  695.                                                     if ($RS['admin'] == 2) {
  696.                                                         $add = "@";
  697.                                                     } else if ($RS['admin'] == 1) {
  698.                                                         $add = "+";
  699.                                                     } else {
  700.                                                         $add = "";
  701.                                                     }
  702.                                                     if ($uid == $RS['id']) {
  703.                                                         fwrite($read_sock, ":phpBNC 352 " . $usersettings[$uid]['currentnick'] . " &system " . $RS['username'] . " " . $RS['host'] . " phpBNC.se " . $RS['currentnick'] . "][" . $RS['username'] . " H" . $add . " :0 " . $RS['realname'] . "\r\n");
  704.                                                     } else {
  705.                                                         fwrite($read_sock, ":phpBNC 352 " . $usersettings[$uid]['currentnick'] . " &system " . $RS['username'] . " " . $RS['host'] . " phpBNC.se " . $RS['currentnick'] . "][" . $RS['username'] . " H" . $add . " :3 " . $RS['realname'] . "\r\n");
  706.                                                     }
  707.                                                 }
  708.                                             }
  709.                                         }
  710.                                         fwrite($read_sock, ":phpBNC 352 " . $usersettings[$uid]['currentnick'] . " &system phpBNC phpBNC.se phpBNC.se phpBNC H*@d :0 " . $RS['realname'] . "\r\n");
  711.                                         fwrite($read_sock, ":phpBNC 315 " . $usersettings[$uid]['currentnick'] . " &system :End of /WHO list.\r\n");
  712.                                         continue;
  713.                                     }
  714.                                     if (cw($data, "names &system") && 0 < $usersettings[$uid]['admin']) {
  715.                                         $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
  716.                                         $ucounter = 0;
  717.                                         foreach($authed as $cliID) {
  718.                                             if (40 <= $ucounter) {
  719.                                                 fwrite($read_sock, $alltheusers . "\r\n");
  720.                                                 $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :";
  721.                                                 $ucounter = 0;
  722.                                             }
  723.                                             $user = array_keys($cliID);
  724.                                             $user = $user[0];
  725.                                             $fore = "";
  726.                                             if ($usersettings[$user]['admin'] == 1) {
  727.                                                 $fore = "+";
  728.                                             } else if ($usersettings[$user]['admin'] == 2) {
  729.                                                 $fore = "@";
  730.                                             }
  731.                                             if ($ucounter == 0) {
  732.                                                 $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  733.                                             } else {
  734.                                                 $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  735.                                             }
  736.                                             ++$ucounter;
  737.                                         }
  738.                                         fwrite($read_sock, $alltheusers . "\r\n");
  739.                                         fwrite($read_sock, ":phpBNC 366 " . $usersettings[$uid]['currentnick'] . " &system :End of /NAMES list.\r\n");
  740.                                         unset($ucounter);
  741.                                         continue;
  742.                                     }
  743.                                     if (preg_match("/^USER (.*)$/", $data, $m)) {
  744.                                         continue;
  745.                                     }
  746.                                     if (preg_match("/^NOTICE (.*?) :LAGCHK (.*)$/", $data, $m)) {
  747.                                         fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NOTICE " . $usersettings[$uid]['currentnick'] . " :LAGCHK " . $m[2] . "\r\n");
  748.                                         unset($m);
  749.                                         continue;
  750.                                     }
  751.                                     if (preg_match("/^NOTICE (.*?) :lag(.*)$/", $data, $m)) {
  752.                                         fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NOTICE " . $usersettings[$uid]['currentnick'] . " :lag" . $m[2] . "\r\n");
  753.                                         unset($m);
  754.                                         continue;
  755.                                     }
  756.                                     if (cw($data, "join &system") || cw($data, "part &system")) {
  757.                                         continue;
  758.                                     }
  759.                                     if (cw($data, "who #") && time() - $usersettings[$uid]['lastlogin'] < 240) {
  760.                                         continue;
  761.                                     }
  762.                                     if (preg_match("/^[Jj][Oo][Ii][Nn] (.*?) (.*)$/", $data, $m)) {
  763.                                         if (0 < strpos("." . $m[1], ",")) {
  764.                                             $channels = explode(",", $m[1]);
  765.                                             $pwd = explode(",", $m[2]);
  766.                                             foreach($channels as $arkey => $chan) {
  767.                                                 $sql = mquery("select reason, until, channel, network from banned_channels where channel='" . mysql_real_escape_string($chan) . "' and network='*' or channel='" . mysql_real_escape_string($chan) . "' and network='" . $usersettings[$uid]['net_name'] . "'");
  768.                                                 if (0 < mysql_num_rows($sql)) {
  769.                                                     do {
  770.                                                         if ($RS = mysql_fetch_array($sql)) {
  771.                                                             fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :Channel " . $RS['channel'] . " on " . $RS['network'] . " is banned until " . date("Y-m-d H:i:s", $RS['until']) . " due to: " . $RS['reason'] . "\r\n");
  772.                                                         }
  773.                                                     }
  774.                                                     while (1);
  775.                                                 } else {
  776.                                                     $proceed[$arkey] = $chan;
  777.                                                     $keyproceed[$arkey] = $pwd[$arkey];
  778.                                                 }
  779.                                             }
  780.                                             $data = "JOIN " . implode(",", $proceed) . " " . implode(",", $keyproceed);
  781.                                             unset($sql);
  782.                                             unset($RS);
  783.                                             unset($proceed);
  784.                                             unset($chan);
  785.                                             unset($channels);
  786.                                             unset($pwd);
  787.                                             unset($m);
  788.                                         } else {
  789.                                             $sql = mquery("select reason, until, channel, network from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='*' or channel='" . mysql_real_escape_string($m[1]) . "' and network='" . $usersettings[$uid]['net_name'] . "'");
  790.                                             if (0 < mysql_num_rows($sql)) {
  791.                                                 while ($RS = mysql_fetch_array($sql)) {
  792.                                                     fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :Channel " . $RS['channel'] . " on " . $RS['network'] . " is banned until " . date("Y-m-d H:i:s", $RS['until']) . " due to: " . $RS['reason'] . "\r\n");
  793.                                                 }
  794.                                                 continue;
  795.                                             }
  796.                                             unset($sql);
  797.                                             unset($RS);
  798.                                         }
  799.                                     } else if (preg_match("/^[Jj][Oo][Ii][Nn] (.*)$/", $data, $m)) {
  800.                                         if (0 < strpos("." . $m[1], ",")) {
  801.                                             $channels = explode(",", $m[1]);
  802.                                             foreach($channels as $chan) {
  803.                                                 $sql = mquery("select reason, until, channel, network from banned_channels where channel='" . mysql_real_escape_string($chan) . "' and network='*' or channel='" . mysql_real_escape_string($chan) . "' and network='" . $usersettings[$uid]['net_name'] . "'");
  804.                                                 if (0 < mysql_num_rows($sql)) {
  805.                                                     do {
  806.                                                         if ($RS = mysql_fetch_array($sql)) {
  807.                                                             fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :Channel " . $RS['channel'] . " on " . $RS['network'] . " is banned until " . date("Y-m-d H:i:s", $RS['until']) . " due to: " . $RS['reason'] . "\r\n");
  808.                                                         }
  809.                                                     }
  810.                                                     while (1);
  811.                                                 } else {
  812.                                                     $proceed[] = $chan;
  813.                                                 }
  814.                                             }
  815.                                             $data = "JOIN " . implode(",", $proceed);
  816.                                             unset($proceed);
  817.                                             unset($chan);
  818.                                             unset($channels);
  819.                                             unset($sql);
  820.                                             unset($RS);
  821.                                             unset($m);
  822.                                         } else {
  823.                                             $sql = mquery("select reason, until, channel, network from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='*' or channel='" . mysql_real_escape_string($m[1]) . "' and network='" . $usersettings[$uid]['net_name'] . "'");
  824.                                             if (0 < mysql_num_rows($sql)) {
  825.                                                 while ($RS = mysql_fetch_array($sql)) {
  826.                                                     fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :Channel " . $RS['channel'] . " on " . $RS['network'] . " is banned until " . date("Y-m-d H:i:s", $RS['until']) . " due to: " . $RS['reason'] . "\r\n");
  827.                                                 }
  828.                                                 continue;
  829.                                             }
  830.                                         }
  831.                                     }
  832.                                     if ($usersettings[$uid]['trailed'] == 1) {
  833.                                         $nujeflar = fopen("trail/" . $usersettings[$uid]['username'] . ".txt", "a");
  834.                                         fwrite($nujeflar, "USER -> " . $data . "\r\n");
  835.                                         fclose($nujeflar);
  836.                                         unset($nujeflar);
  837.                                     }
  838.                                     if (@array_key_exists(@$uid, @$net_clients)) {
  839.                                         if (preg_match("/^PRIVMSG (.*?) :(.*)$/", $data, $m)) {
  840.                                             $therecheck = false;
  841.                                             if ($m[1][0] == "#") {
  842.                                                 if (@array_key_exists(@$m[1], @$bfkeys[$uid])) {
  843.                                                     $therecheck = true;
  844.                                                     $wherecheck = $m[1];
  845.                                                 }
  846.                                             } else {
  847.                                                 foreach($bfkeys[$uid] as $key => $val) {
  848.                                                     if (array_search($m[1], $val)) {
  849.                                                         $wherecheck = $key;
  850.                                                         $therecheck = true;
  851.                                                     }
  852.                                                 }
  853.                                             }
  854.                                             if ($therecheck == true) {
  855.                                                 if (strtolower(substr($m[2], 0, 7)) != chr(1) . "action" && substr($m[2], 0, 2) != "+p") {
  856.                                                     $data = "PRIVMSG " . $m[1] . " :+OK " . encrypt($m[2], $bfkeys[$uid][$wherecheck]['key']) . "\r\n";
  857.                                                 }
  858.                                                 if (substr($m[2], 0, 2) == "+p") {
  859.                                                     $data = "PRIVMSG " . $m[1] . " :" . substr($m[2], 2, strlen($m[2]) - 2) . "\r\n";
  860.                                                 }
  861.                                             }
  862.                                             unset($therecheck);
  863.                                             unset($wherecheck);
  864.                                         }
  865.                                         if (preg_match("/^TOPIC (.*?) :(.*)$/", $data, $m)) {
  866.                                             $therecheck = false;
  867.                                             if ($m[1][0] == "#") {
  868.                                                 if (@array_key_exists(@$m[1], @$bfkeys[$uid])) {
  869.                                                     $therecheck = true;
  870.                                                     $wherecheck = $m[1];
  871.                                                 }
  872.                                             } else {
  873.                                                 foreach($bfkeys[$uid] as $key => $val) {
  874.                                                     if (array_search($m[1], $val)) {
  875.                                                         $wherecheck = $key;
  876.                                                         $therecheck = true;
  877.                                                     }
  878.                                                 }
  879.                                             }
  880.                                             if ($therecheck == true) {
  881.                                                 if (substr($m[2], 0, 2) != "+p") {
  882.                                                     $data = "TOPIC " . $m[1] . " :+OK " . encrypt($m[2], $bfkeys[$uid][$wherecheck]['key']) . "\r\n";
  883.                                                 }
  884.                                                 if (substr($m[2], 0, 2) == "+p") {
  885.                                                     $data = "TOPIC " . $m[1] . " :" . substr($m[2], 2, strlen($m[2]) - 2) . "\r\n";
  886.                                                 }
  887.                                             }
  888.                                             unset($therecheck);
  889.                                             unset($wherecheck);
  890.                                         }
  891.                                         if (cw($data, "part")) {
  892.                                             strtok($data, " ");
  893.                                             $channel = strtok(" ");
  894.                                             $network = mysql_fetch_array(mquery("select net_name from users where id='" . mysql_real_escape_string($uid) . "'"));
  895.                                             mquery("delete from userchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($channel) . "' and network='" . mysql_real_escape_string($network['net_name']) . "'");
  896.                                             mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($channel) . "'");
  897.                                             unset($channel);
  898.                                             unset($network);
  899.                                         } else if (cw($data, "join")) {
  900.                                             strtok($data, " ");
  901.                                             $channel = strtok(" ");
  902.                                             $pw = strtok(" ");
  903.                                             if (0 < strpos("." . $channel, ",")) {
  904.                                                 $channels = explode(",", $channel);
  905.                                                 $pwd = explode(",", $pw);
  906.                                                 $network = mysql_fetch_array(mquery("select net_name from users where id='" . mysql_real_escape_string($uid) . "'"));
  907.                                                 foreach($channels as $keyen => $kanalen) {
  908.                                                     mquery("delete from userchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($kanalen) . "' and network='" . mysql_real_escape_string($network['net_name']) . "'");
  909.                                                     mquery("insert into userchannels (uid, channel, pw, network) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($kanalen) . "', '" . mysql_real_escape_string($pwd[$keyen]) . "', '" . mysql_real_escape_string($network['net_name']) . "')");
  910.                                                     mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($kanalen) . "'");
  911.                                                     mquery("insert into tempchannels (uid, channel, pw) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($kanalen) . "', '" . mysql_real_escape_string($pwd[$keyen]) . "')");
  912.                                                     unset($kanalen);
  913.                                                     unset($keyen);
  914.                                                 }
  915.                                                 unset($network);
  916.                                                 unset($channels);
  917.                                                 unset($channel);
  918.                                                 unset($pw);
  919.                                             } else {
  920.                                                 $network = mysql_fetch_array(mquery("select net_name from users where id='" . mysql_real_escape_string($uid) . "'"));
  921.                                                 mquery("delete from userchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($channel) . "' and network='" . mysql_real_escape_string($network['net_name']) . "'");
  922.                                                 mquery("insert into userchannels (uid, channel, pw, network) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($channel) . "', '" . mysql_real_escape_string($pw) . "', '" . mysql_real_escape_string($network['net_name']) . "')");
  923.                                                 mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($channel) . "'");
  924.                                                 mquery("insert into tempchannels (uid, channel, pw) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($channel) . "', '" . mysql_real_escape_string($pw) . "')");
  925.                                                 unset($channel);
  926.                                                 unset($network);
  927.                                                 unset($pw);
  928.                                             }
  929.                                         }
  930.                                         if (2 < time() - $usersettings[$uid]['lastcommand'] || $usersettings[$uid]['flood'] == 0) {
  931.                                             fwrite($net_clients[$uid], $data . "\r\n");
  932.                                             $usersettings[$uid]['lastcommand'] = time();
  933.                                             $usersettings[$uid]['delay'] = 0;
  934.                                         } else {
  935.                                             if (7 < $usersettings[$uid]['delay']) {
  936.                                                 $adder = 2;
  937.                                             } else {
  938.                                                 $adder = 1;
  939.                                             }
  940.                                             $queue[][$uid][mktime(date("H"), date("i"), date("s") + $usersettings[$uid]['delay'], date("m"), date("d"), date("Y")) ]['command'] = $data . "\r\n";
  941.                                             $usersettings[$uid]['delay'] = $usersettings[$uid]['delay'] + $adder;
  942.                                         }
  943.                                         unset($adder);
  944.                                         unset($channel);
  945.                                         unset($pw);
  946.                                     } else {
  947.                                         fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :You are NOT connected to a IRC server yet, use /bconnect to connect.\r\n");
  948.                                     }
  949.                                 }
  950.                             }
  951.                         } else {
  952.                             if (in_array(@$read_sock, @$identd) && enableident == true) {
  953.                                 if (debugoutput == 1) {
  954.                                     echo "IDENTD -> " . $data . "\r\n";
  955.                                 }
  956.                                 if (preg_match("/^(.*) , (.*)$/", $data, $m)) {
  957.                                     $uid = array_search($m[1], $ident_ports);
  958.                                     fwrite($read_sock, $m[2] . ", " . $m[1] . " : USERID : UNIX : " . $usersettings[$uid]['username'] . "\r\n");
  959.                                     unset($ident_ports[$uid]);
  960.                                     if (debugoutput == 1) {
  961.                                         echo "IDENT RESPONSE -> " . $m[2] . ", " . $m[1] . " : USERID : UNIX : " . $usersettings[$uid]['username'] . "\r\n";
  962.                                     }
  963.                                 }
  964.                             } else {
  965.                                 if (cw($data, "login") || cw($data, "pass")) {
  966.                                     $clientKEY = array_search($read_sock, $clients);
  967.                                     if (@in_array(@$read_sock, @$authed[$clientKEY])) {
  968.                                         $uid = array_search($read_sock, $authed[array_search($read_sock, $clients) ]);
  969.                                         fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :You are already logged in as " . $usersettings[$uid]['username'] . " smartass!\r\n");
  970.                                     } else {
  971.                                         if (preg_match("/^PASS (.*?):(.*)$/", $data, $m)) {
  972.                                             $username = $m[1];
  973.                                             $unamecheck = md5(strtolower($m[1]));
  974.                                             $password = md5(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out"));
  975.                                         } else if (preg_match("/^pass (.*?):(.*)$/", $data, $m)) {
  976.                                             $username = $m[1];
  977.                                             $unamecheck = md5(strtolower($m[1]));
  978.                                             $password = md5(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out"));
  979.                                         } else if (preg_match("/^LOGIN (.*) (.*)$/", $data, $m)) {
  980.                                             $username = $m[1];
  981.                                             $unamecheck = md5(strtolower($m[1]));
  982.                                             $password = md5(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out"));
  983.                                         } else if (preg_match("/^login (.*) (.*)$/", $data, $m)) {
  984.                                             $username = $m[1];
  985.                                             $unamecheck = md5(strtolower($m[1]));
  986.                                             $password = md5(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out"));
  987.                                         }
  988.                                         $ip = explode(":", stream_socket_get_name($read_sock, true));
  989.                                         $ip = $ip[0];
  990.                                         $hosten = gethostbyaddr($ip);
  991.                                         $sql = mquery("select id,banned,banned_until,network from users where md5(lower(username))='{$unamecheck}' and md5(password)='{$password}'");
  992.                                         if (mysql_num_rows($sql) == 1) {
  993.                                             $RS = mysql_fetch_array($sql);
  994.                                             $uid = $RS['id'];
  995.                                             $alreadyloggedin = 0;
  996.                                             foreach($authed as $cliID) {
  997.                                                 $useridet = array_keys($cliID);
  998.                                                 if ($useridet[0] == $uid) {
  999.                                                     $alreadyloggedin = 1;
  1000.                                                     break;
  1001.                                                     break;
  1002.                                                 }
  1003.                                             }
  1004.                                             if ($alreadyloggedin == 1) {
  1005.                                                 fwrite($read_sock, ":phpBNC NOTICE you :Someone has already logged in as " . $usersettings[$uid]['username'] . ", please wait until that client disconnects.\r\n");
  1006.                                             } else {
  1007.                                                 if (0 < strlen($RS['banned']) && time() < $RS['banned_until']) {
  1008.                                                     fwrite($read_sock, ":phpBNC NOTICE you :You are banned until " . date("Y-m-d H:i:s", $RS['banned_until']) . " due to: " . $RS['banned'] . ".\r\n");
  1009.                                                 } else {
  1010.                                                     if (@array_key_exists(@$uid, @$net_clients)) {
  1011.                                                         $currentnick = $usersettings[$uid]['currentnick'];
  1012.                                                     } else {
  1013.                                                         $currentnick = $usersettings[$uid]['nick'];
  1014.                                                         $usersettings[$uid]['currentnick'] = $usersettings[$uid]['nick'];
  1015.                                                         mquery("update users set currentnick=nick where id='" . mysql_real_escape_string($uid) . "'");
  1016.                                                     }
  1017.                                                     fwrite($read_sock, ":phpBNC NOTICE " . $currentnick . " :You are now logged in as " . $usersettings[$uid]['username'] . ".\r\n" . ":phpBNC NOTICE :For list of commands use /bhelp\r\n");
  1018.                                                     if (array_search($read_sock, $tempnicks) != $currentnick) {
  1019.                                                         fwrite($read_sock, ":" . array_search($read_sock, $tempnicks) . " NICK " . $currentnick . "\r\n");
  1020.                                                     }
  1021.                                                     $authed[$clientKEY] = array($uid => $read_sock);
  1022.                                                     if (@!array_key_exists(@$uid, @$net_clients)) {
  1023.                                                         fwrite($read_sock, ":" . $RS['network'] . " 001 " . $currentnick . " :Welcome to the " . $RS['network'] . " IRC Network " . $currentnick . "\r\n");
  1024.                                                     } else {
  1025.                                                         fwrite($read_sock, "NOTICE AUTH :*** Looking up your hostname\r\n");
  1026.                                                         fwrite($read_sock, "NOTICE AUTH :*** Checking Ident\r\n");
  1027.                                                         fwrite($read_sock, "NOTICE AUTH :*** Found your hostname\r\n");
  1028.                                                         fwrite($read_sock, "NOTICE AUTH :*** Got ident response\r\n");
  1029.                                                         foreach($userconmem[$uid] as $sendline) {
  1030.                                                             fwrite($read_sock, str_replace("%nick%", $currentnick, $sendline) . "\r\n");
  1031.                                                         }
  1032.                                                         fwrite($net_clients[$uid], "VERSION\r\n");
  1033.                                                         fwrite($net_clients[$uid], "LUSERS\r\n");
  1034.                                                     }
  1035.                                                     unset($tempnicks[array_search($read_sock, $tempnicks) ]);
  1036.                                                     if (0 < strlen($usersettings[$uid]['net_name'])) {
  1037.                                                         $currentnetwork = $usersettings[$uid]['net_name'];
  1038.                                                     } else {
  1039.                                                         $currentnetwork = "phpBNC";
  1040.                                                     }
  1041.                                                     if ($usersettings[$uid]['trailed'] == 1) {
  1042.                                                         fwrite($read_sock, ":phpBNC NOTICE you :An admin has activated trail for your account, that means that everything you send and receive is logged in a textfile, REMEMBER THIS.\r\n");
  1043.                                                     }
  1044.                                                     if (0 < $usersettings[$uid]['admin']) {
  1045.                                                         $admins[] = $uid;
  1046.                                                         fwrite($read_sock, ":" . $currentnick . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " JOIN &system\r\n");
  1047.                                                         fwrite($read_sock, ":phpBNC 332 " . $currentnick . " &system :System channel for phpBNC v." . version . "\r\n");
  1048.                                                         fwrite($read_sock, ":phpBNC 333 " . $currentnick . " &system phpBNC " . starttime . "\r\n");
  1049.                                                         $alltheusers = ":phpBNC 353 " . $currentnick . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
  1050.                                                         $ucounter = 0;
  1051.                                                         foreach($authed as $cliID) {
  1052.                                                             if (40 <= $ucounter) {
  1053.                                                                 fwrite($read_sock, $alltheusers . "\r\n");
  1054.                                                                 $alltheusers = ":phpBNC 353 " . $currentnick . "][" . $usersettings[$uid]['username'] . " = &system :";
  1055.                                                                 $ucounter = 0;
  1056.                                                             }
  1057.                                                             $user = array_keys($cliID);
  1058.                                                             $user = $user[0];
  1059.                                                             $fore = "";
  1060.                                                             if ($user != $uid) {
  1061.                                                                 if ($usersettings[$user]['admin'] == 1) {
  1062.                                                                     $fore = "+";
  1063.                                                                 } else if ($usersettings[$user]['admin'] == 2) {
  1064.                                                                     $fore = "@";
  1065.                                                                 }
  1066.                                                             }
  1067.                                                             if ($ucounter == 0) {
  1068.                                                                 $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  1069.                                                             } else {
  1070.                                                                 $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  1071.                                                             }
  1072.                                                             ++$ucounter;
  1073.                                                         }
  1074.                                                         fwrite($read_sock, $alltheusers . "\r\n");
  1075.                                                         fwrite($read_sock, ":phpBNC 366 " . $currentnick . " &system :End of /NAMES list.\r\n");
  1076.                                                         unset($ucounter);
  1077.                                                     }
  1078.                                                     $foere = "";
  1079.                                                     if ($usersettings[$uid]['admin'] == 1) {
  1080.                                                         $foere = "+v";
  1081.                                                     } else if ($usersettings[$uid]['admin'] == 2) {
  1082.                                                         $foere = "+o";
  1083.                                                     }
  1084.                                                     fwrite($read_sock, ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $currentnick . "][" . $usersettings[$uid]['username'] . "\r\n");
  1085.                                                     foreach($admins as $useridet) {
  1086.                                                         if ($useridet != $uid) {
  1087.                                                             foreach($authed as $cliID) {
  1088.                                                                 if (@array_key_exists(@$useridet, @$cliID)) {
  1089.                                                                     fwrite($cliID[$useridet], ":[email protected] PRIVMSG &system :" . chr(2) . "USER:" . chr(2) . " " . $usersettings[$uid]['username'] . " logged in from {$hosten}({$ip})\r\n");
  1090.                                                                     fwrite($cliID[$useridet], ":" . $currentnick . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " JOIN &system\r\n");
  1091.                                                                     if ($foere != "") {
  1092.                                                                         fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $currentnick . "][" . $usersettings[$uid]['username'] . "\r\n");
  1093.                                                                     }
  1094.                                                                 }
  1095.                                                             }
  1096.                                                         }
  1097.                                                     }
  1098.                                                     $msgcount = mysql_result(mquery("select count(*) from userlogs where toid='" . mysql_real_escape_string($uid) . "'"), 0);
  1099.                                                     if (0 < $msgcount) {
  1100.                                                         fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG " . $currentnick . " :You got " . $msgcount . " message(s) in your log, type /readlog to read them or /dellog to delete them.\r\n");
  1101.                                                     }
  1102.                                                     $usersettings[$uid]['lastlogin'] = time();
  1103.                                                     if (@array_key_exists(@$uid, @$net_clients)) {
  1104.                                                         fwrite($net_clients[$uid], "MODE " . $currentnick . "\r\n");
  1105.                                                         if ($usersettings[$uid]['channellog'] == 0) {
  1106.                                                             fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['currentnick'] . " -d\r\n");
  1107.                                                             fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['away_nick'] . " -d\r\n");
  1108.                                                             fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['nick'] . " -d\r\n");
  1109.                                                         }
  1110.                                                         fwrite($net_clients[$uid], "NICK :" . $usersettings[$uid]['nick'] . "\r\n");
  1111.                                                         if ($usersettings[$uid]['away_msg'] != "") {
  1112.                                                             fwrite($net_clients[$uid], "AWAY\r\n");
  1113.                                                         }
  1114.                                                         $chancounter = 0;
  1115.                                                         $sql = mquery("select channel from tempchannels where uid='" . mysql_real_escape_string($uid) . "' order by channel asc");
  1116.                                                         while ($RS = mysql_fetch_array($sql)) {
  1117.                                                             fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " JOIN " . $RS['channel'] . "\r\n");
  1118.                                                             if (2 < time() - $usersettings[$uid]['lastcommand'] || $usersettings[$uid]['flood'] == 0) {
  1119.                                                                 fwrite($net_clients[$uid], "TOPIC " . $RS['channel'] . "\r\n");
  1120.                                                                 fwrite($net_clients[$uid], "NAMES " . $RS['channel'] . "\r\n");
  1121.                                                                 $usersettings[$uid]['lastcommand'] = time();
  1122.                                                                 $usersettings[$uid]['delay'] = 0;
  1123.                                                             } else {
  1124.                                                                 $adder = 1;
  1125.                                                                 $queue[][$uid][mktime(date("H"), date("i"), date("s") + $usersettings[$uid]['delay'], date("m"), date("d"), date("Y")) ]['command'] = "NAMES " . $RS['channel'] . "\r\n";
  1126.                                                                 $queue[][$uid][mktime(date("H"), date("i"), date("s") + $usersettings[$uid]['delay'], date("m"), date("d"), date("Y")) ]['command'] = "TOPIC " . $RS['channel'] . "\r\n";
  1127.                                                                 if ($chancounter++ % 2 == 0) {
  1128.                                                                     $usersettings[$uid]['delay'] = $usersettings[$uid]['delay'] + $adder;
  1129.                                                                 }
  1130.                                                             }
  1131.                                                         }
  1132.                                                         unset($adder);
  1133.                                                         unset($chancounter);
  1134.                                                         unset($sql);
  1135.                                                         unset($RS);
  1136.                                                         if ($usersettings[$uid]['channellog'] == 1) {
  1137.                                                             $sql = mquery("select * from channellogs where uid='" . mysql_real_escape_string($uid) . "' order by date asc");
  1138.                                                             while ($RS = mysql_fetch_array($sql)) {
  1139.                                                                 fwrite($read_sock, $RS['text'] . "\r\n");
  1140.                                                             }
  1141.                                                             mquery("delete from channellogs where uid='" . mysql_real_escape_string($uid) . "'");
  1142.                                                         }
  1143.                                                     }
  1144.                                                 }
  1145.                                             }
  1146.                                         } else {
  1147.                                             if (0 < mysql_result(mquery("select count(*) from users where md5(lower(username))='{$unamecheck}'"), 0)) {
  1148.                                                 foreach($admins as $useridet2) {
  1149.                                                     foreach($authed as $cliID2) {
  1150.                                                         if (@array_key_exists(@$useridet2, @$cliID2)) {
  1151.                                                             fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "4WARNING:" . chr(3) . chr(2) . " {$username} tried to login with wrong password from {$hosten}({$ip})\r\n");
  1152.                                                         }
  1153.                                                     }
  1154.                                                 }
  1155.                                             }
  1156.                                             fwrite($read_sock, ":phpBNC NOTICE you :Wrong username or password, remember the password is CaSeSeNsiTivE!\r\n");
  1157.                                             $key = array_search($read_sock, $clients);
  1158.                                             unset($clients[$key]);
  1159.                                             fclose($read_sock);
  1160.                                             echo "client disconnected.\r\n";
  1161.                                         }
  1162.                                         unset($sql);
  1163.                                         unset($RS);
  1164.                                         unset($currentnick);
  1165.                                         unset($alreadyloggedin);
  1166.                                     }
  1167.                                 } else {
  1168.                                     if (@in_array(@$read_sock, @$authed[array_search(@$read_sock, @$clients) ])) {
  1169.                                         $uid = array_search($read_sock, $authed[array_search($read_sock, $clients) ]);
  1170.                                         $nick = $usersettings[$uid]['currentnick'];
  1171.                                         if (cw($data, "bconnect")) {
  1172.                                             $userinfo = mysql_fetch_array(mquery("select username, nick, host, port, `ssl`, network, realname from users where id='{$uid}'"));
  1173.                                             if (@array_key_exists(@$uid, @$net_clients)) {
  1174.                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :You are already connected to a network..\r\n");
  1175.                                             } else if (strlen($userinfo['host']) == 0) {
  1176.                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :You have to select a v-host before you can connect..\r\n");
  1177.                                             } else if (strlen($userinfo['realname']) == 0) {
  1178.                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please enter a realname before you connect..\r\n");
  1179.                                             } else if (strlen($userinfo['network']) == 0) {
  1180.                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please specify a server before you connect..\r\n");
  1181.                                             } else {
  1182.                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Trying to connect you to " . $userinfo['network'] . "..\r\n");
  1183.                                                 $tempcontext = stream_context_create();
  1184.                                                 stream_context_set_option($tempcontext, "socket", "bindto", gethostbyname($userinfo['host']) . ":0");
  1185.                                                 if ($userinfo['ssl'] == 1) {
  1186.                                                     $ssladd = "ssl://";
  1187.                                                 } else {
  1188.                                                     $ssladd = "tcp://";
  1189.                                                 }
  1190.                                                 $netsocket = stream_socket_client($ssladd . $userinfo['network'] . ":" . $userinfo['port'], $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $tempcontext);
  1191.                                                 if (!$netsocket) {
  1192.                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :A error occured, could not connect to " . $userinfo['network'] . ", error: " . $errstr . ".\r\n");
  1193.                                                 } else {
  1194.                                                     stream_set_timeout($netsocket, 1200);
  1195.                                                     stream_set_blocking($netsocket, false);
  1196.                                                     $net_clients = array($uid => $netsocket) + $net_clients;
  1197.                                                     if (enableident) {
  1198.                                                         $tempp = explode(":", stream_socket_get_name($netsocket, false));
  1199.                                                         $ident_ports[$uid] = $tempp[1];
  1200.                                                         unset($tempp);
  1201.                                                     }
  1202.                                                     fwrite($netsocket, "NICK " . $userinfo['nick'] . "\r\n");
  1203.                                                     fwrite($netsocket, "USER " . $userinfo['username'] . " \"" . $userinfo['nick'] . "\" \"" . $userinfo['host'] . "\" :" . $userinfo['realname'] . "\r\n");
  1204.                                                 }
  1205.                                                 if (0 < $usersettings[$uid]['admin']) {
  1206.                                                     $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
  1207.                                                     $ucounter = 0;
  1208.                                                     foreach($authed as $cliID) {
  1209.                                                         if (40 <= $ucounter) {
  1210.                                                             fwrite($read_sock, $alltheusers . "\r\n");
  1211.                                                             $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :";
  1212.                                                             $ucounter = 0;
  1213.                                                         }
  1214.                                                         $user = array_keys($cliID);
  1215.                                                         $user = $user[0];
  1216.                                                         $fore = "";
  1217.                                                         if ($usersettings[$user]['admin'] == 1) {
  1218.                                                             $fore = "+";
  1219.                                                         } else if ($usersettings[$user]['admin'] == 2) {
  1220.                                                             $fore = "@";
  1221.                                                         }
  1222.                                                         if ($ucounter == 0) {
  1223.                                                             $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  1224.                                                         } else {
  1225.                                                             $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  1226.                                                         }
  1227.                                                         ++$ucounter;
  1228.                                                     }
  1229.                                                     fwrite($read_sock, $alltheusers . "\r\n");
  1230.                                                     fwrite($read_sock, ":phpBNC 366 " . $usersettings[$uid]['currentnick'] . " &system :End of /NAMES list.\r\n");
  1231.                                                     unset($ucounter);
  1232.                                                 }
  1233.                                             }
  1234.                                             $usersettings[$uid]['lastcontry'] = time();
  1235.                                         } else {
  1236.                                             if (cw($data, "brestore")) {
  1237.                                                 if (@array_key_exists(@$uid, @$net_clients)) {
  1238.                                                     $sql = mquery("select channel,pw from userchannels where uid='{$uid}' order by channel asc");
  1239.                                                     if (mysql_num_rows($sql) == 0) {
  1240.                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :There was no stored channels for you, for some reason.\r\n");
  1241.                                                     }
  1242.                                                     if ($RS = mysql_fetch_array($sql)) {
  1243.                                                         if (0 < strlen($RS['pw'])) {
  1244.                                                             fwrite($net_clients[$uid], "JOIN " . $RS['channel'] . " " . $RS['pw'] . "\r\n");
  1245.                                                             mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($RS['channel']) . "'");
  1246.                                                             mquery("insert into tempchannels (uid, channel, pw) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($RS['channel']) . "', '" . mysql_real_escape_string($RS['pw']) . "')");
  1247.                                                         } else {
  1248.                                                             fwrite($net_clients[$uid], "JOIN " . $RS['channel'] . "\r\n");
  1249.                                                             mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($RS['channel']) . "'");
  1250.                                                             mquery("insert into tempchannels (uid, channel, pw) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($RS['channel']) . "', '')");
  1251.                                                             continue;
  1252.                                                         }
  1253.                                                     }
  1254.                                                 } else {
  1255.                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :You aren´t even connected to a network, use /bconnect to connect.\r\n");
  1256.                                                 }
  1257.                                             } else {
  1258.                                                 if (cw($data, "bclear")) {
  1259.                                                     mquery("delete from userchannels where uid='" . mysql_real_escape_string($uid) . "'");
  1260.                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your channel memory has been deleted.\r\n");
  1261.                                                 } else {
  1262.                                                     if (cw($data, "breconnect")) {
  1263.                                                         if (@array_key_exists(@$uid, @$net_clients)) {
  1264.                                                             fwrite($net_clients[$uid], "QUIT\r\n");
  1265.                                                             fclose($net_clients[$uid]);
  1266.                                                             unset($net_clients[$uid]);
  1267.                                                             unset($userconmem[$uid]);
  1268.                                                             mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "'");
  1269.                                                             $userinfo = mysql_fetch_array(mquery("select username, nick, host, port, `ssl`, network, realname from users where id='{$uid}'"));
  1270.                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Disconnected you from current network..\r\n");
  1271.                                                             if (strlen($userinfo['realname']) == 0) {
  1272.                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please enter a realname before you connect..\r\n");
  1273.                                                             } else if (strlen($userinfo['host']) == 0) {
  1274.                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please choose a host before you connect..\r\n");
  1275.                                                             } else {
  1276.                                                                 if (strlen($userinfo['network']) == 0) {
  1277.                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please specify a server before you connect..\r\n");
  1278.                                                                 } else {
  1279.                                                                     if ($usersettings[$uid]['currentnick'] != $userinfo['nick']) {
  1280.                                                                         fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :" . $userinfo['nick'] . "\r\n");
  1281.                                                                         foreach($admins as $useridet2) {
  1282.                                                                             foreach($authed as $cliID2) {
  1283.                                                                                 if (@array_key_exists(@$useridet2, @$cliID2)) {
  1284.                                                                                     fwrite($cliID2[$useridet2], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :" . $userinfo['nick'] . "][" . $usersettings[$uid]['username'] . "\r\n");
  1285.                                                                                 }
  1286.                                                                             }
  1287.                                                                         }
  1288.                                                                         $usersettings[$uid]['currentnick'] = $userinfo['nick'];
  1289.                                                                         mquery("update users set currentnick=nick where id='" . mysql_real_escape_string($uid) . "'");
  1290.                                                                     }
  1291.                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Trying to connect you to " . $userinfo['network'] . "..\r\n");
  1292.                                                                     sleep(1);
  1293.                                                                     $tempcontext = stream_context_create();
  1294.                                                                     stream_context_set_option($tempcontext, "socket", "bindto", gethostbyname($userinfo['host']) . ":0");
  1295.                                                                     if ($userinfo['ssl'] == 1) {
  1296.                                                                         $ssladd = "ssl://";
  1297.                                                                     } else {
  1298.                                                                         $ssladd = "tcp://";
  1299.                                                                     }
  1300.                                                                     $netsocket = stream_socket_client($ssladd . $userinfo['network'] . ":" . $userinfo['port'], $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $tempcontext);
  1301.                                                                     if (!$netsocket) {
  1302.                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :A error occured, could not connect to " . $userinfo['network'] . ", error: " . $errstr . ".\r\n");
  1303.                                                                     } else {
  1304.                                                                         stream_set_timeout($netsocket, 1200);
  1305.                                                                         stream_set_blocking($netsocket, false);
  1306.                                                                         $net_clients = array($uid => $netsocket) + $net_clients;
  1307.                                                                         if (enableident) {
  1308.                                                                             $tempp = explode(":", stream_socket_get_name($netsocket, false));
  1309.                                                                             $ident_ports[$uid] = $tempp[1];
  1310.                                                                             unset($tempp);
  1311.                                                                         }
  1312.                                                                         fwrite($netsocket, "NICK " . $userinfo['nick'] . "\r\n");
  1313.                                                                         fwrite($netsocket, "USER " . $userinfo['username'] . " \"" . $userinfo['nick'] . "\" \"" . $userinfo['host'] . "\" :" . $userinfo['realname'] . "\r\n");
  1314.                                                                         if (0 < $usersettings[$uid]['admin']) {
  1315.                                                                             $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
  1316.                                                                             $ucounter = 0;
  1317.                                                                             foreach($authed as $cliID) {
  1318.                                                                                 if (40 <= $ucounter) {
  1319.                                                                                     fwrite($read_sock, $alltheusers . "\r\n");
  1320.                                                                                     $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :";
  1321.                                                                                     $ucounter = 0;
  1322.                                                                                 }
  1323.                                                                                 $user = array_keys($cliID);
  1324.                                                                                 $user = $user[0];
  1325.                                                                                 $fore = "";
  1326.                                                                                 if ($usersettings[$user]['admin'] == 1) {
  1327.                                                                                     $fore = "+";
  1328.                                                                                 } else if ($usersettings[$user]['admin'] == 2) {
  1329.                                                                                     $fore = "@";
  1330.                                                                                 }
  1331.                                                                                 if ($ucounter == 0) {
  1332.                                                                                     $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  1333.                                                                                 } else {
  1334.                                                                                     $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  1335.                                                                                 }
  1336.                                                                                 ++$ucounter;
  1337.                                                                             }
  1338.                                                                             fwrite($read_sock, $alltheusers . "\r\n");
  1339.                                                                             fwrite($read_sock, ":phpBNC 366 " . $usersettings[$uid]['currentnick'] . " &system :End of /NAMES list.\r\n");
  1340.                                                                             unset($ucounter);
  1341.                                                                         }
  1342.                                                                     }
  1343.                                                                 }
  1344.                                                             }
  1345.                                                             $usersettings[$uid]['lastcontry'] = time();
  1346.                                                         } else {
  1347.                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :You aren´t even connected to a network, use /bconnect to connect.\r\n");
  1348.                                                         }
  1349.                                                     } else {
  1350.                                                         if (cw($data, "bquit")) {
  1351.                                                             if (@array_key_exists(@$uid, @$net_clients)) {
  1352.                                                                 fwrite($net_clients[$uid], "QUIT\r\n");
  1353.                                                                 fclose($net_clients[$uid]);
  1354.                                                                 unset($net_clients[$uid]);
  1355.                                                                 unset($userconmem[$uid]);
  1356.                                                                 mquery("update users set net_name='' where id='" . mysql_real_escape_string($uid) . "'");
  1357.                                                                 $sql = mquery("select * from tempchannels where uid='" . mysql_real_escape_string($uid) . "'");
  1358.                                                                 while ($RS = mysql_fetch_array($sql)) {
  1359.                                                                     fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " PART " . $RS['channel'] . "\r\n");
  1360.                                                                 }
  1361.                                                                 mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "'");
  1362.                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Disconnected you from current network..\r\n");
  1363.                                                                 unset($sql);
  1364.                                                                 unset($RS);
  1365.                                                                 $usersettings[$uid]['lastcontry'] = time();
  1366.                                                             } else {
  1367.                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :You aren´t even connected to a network, use /bconnect to connect.\r\n");
  1368.                                                             }
  1369.                                                         } else {
  1370.                                                             if (cw($data, "readlog")) {
  1371.                                                                 $sql = mquery("select * from userlogs where toid='" . mysql_real_escape_string($uid) . "' order by date asc");
  1372.                                                                 if (mysql_num_rows($sql) == 0) {
  1373.                                                                     fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :You got no messages.\r\n");
  1374.                                                                 } else {
  1375.                                                                     while ($RS = mysql_fetch_array($sql)) {
  1376.                                                                         fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :" . chr(2) . date("Y-m-d H:i:s", $RS['date']) . chr(2) . "> " . $RS['msg'] . "\r\n");
  1377.                                                                     }
  1378.                                                                 }
  1379.                                                             } else {
  1380.                                                                 if (cw($data, "dellog")) {
  1381.                                                                     mquery("delete from userlogs where toid='" . mysql_real_escape_string($uid) . "'");
  1382.                                                                     fwrite($read_sock, ":phpBNC PRIVMSG {$nick} :Private message(s) deleted.\r\n");
  1383.                                                                 } else {
  1384.                                                                     if (cw($data, "bhelp") || cw($data, "pb help")) {
  1385.                                                                         if (in_array($uid, $admins)) {
  1386.                                                                             $adminadd = ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | _____________________________________________________________________________________ | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : /´                                                                                     `\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                      As a admin you get a bit more fancy commands ;)                  | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   " . chr(2) . "Explanations" . chr(2) . "                                                                       | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   <duration>  - can be specified in minutes or days with m and d, ex. 10d or 50m      | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   <network>   - the network name the server reports when you are connected,           | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                 for ex. QuakeNet.org the network name would be QuakeNet (use * for    | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                 all networks)                                                         | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   <number>    - number of connections thats allowed on that specific v-host           | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                                                                                       | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   " . chr(2) . "Commands" . chr(2) . "                                                                           | \r\n";
  1387.                                                                             $normaladmin = ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                                                                                       | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   Normal-admin commands                                                               | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb stats               - shows some stats                                          | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb kick <username>     - kick a user, username is the same as the ident            | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb aset <username> <option> <value>                 - set a users values           | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb banchan <channel> <network> <duration> <reason>  - ban a channel                | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb unbanchan <channel> <network>                    - unban a channel              | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb find <string>             - search for a user                                   | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb check <channel> <network> - lists what bncusers currently in the specified chan | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb info <username>           - same as myinfo but with little more candy ;)        | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb ban <username> <duration> <reason>   - ban a user                               | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb unban <username>                     - unban a user                             | \r\n";
  1388.                                                                             $superadmin = ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                                                                                       | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   Super-admin commands                                                                | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb addhost <number> <hostname> - adds a v-host                                     | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb delhost <hostname>          - deletes a v-host                                  | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb allmsg <msg>                - sends a message to every user online, incl you    | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb trail <username>    - dumps a copy of everything the user says/receives to      | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                             trails/<username>.txt, the user however will be notified  | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                             of this action                                            | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb untrail <username>                                                              | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb admin <username> <newlevel> - make someone admin. levels 0, 1, 2 are available  | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb adduser <username> <password> - add a user                                      | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb deluser <username>          - delete a user                                     | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |  */pb createlink <ip>             - create a link to another phpBNC server            | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |  */pb dellink <ip>                - delete a link                                     | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |  */pb listlinks                   - lists all links                                   | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |  */pb addtrust <ip>               - add a ip thats allowed to link to you             | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |  */pb removetrust <ip>            - remove a ip from the allowed link list            | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |  */pb listtrusts                  - lists all trusted ips                             | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |  */pb allowglobaladmin <ip>       - allows a linked server to control this phpBNC     | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |  */pb delglobaladmin <ip>         - deletes the linked server from globaladmin        | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |  * = not included in this version                                                     | \r\n";
  1389.                                                                             $adminlvl = mysql_fetch_array(mquery("select admin from users where id='" . mysql_real_escape_string($uid) . "'"));
  1390.                                                                             if (1 <= $adminlvl['admin']) {
  1391.                                                                                 $adminadd = $adminadd . $normaladmin;
  1392.                                                                             }
  1393.                                                                             if ($adminlvl['admin'] == 2) {
  1394.                                                                                 $adminadd = $adminadd . $superadmin;
  1395.                                                                             }
  1396.                                                                         } else {
  1397.                                                                             $adminadd = "";
  1398.                                                                         }
  1399.                                                                         fwrite($read_sock, ":phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :                            _               ___      __   ___  \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :                     _ __  | |__   _ __    / __\\  /\\ \\ \\ / __\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :                    | '_ \\ | '_ \\ | '_ \\  /__\\// /  \\/ // /    \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :                    | |_) || | | || |_) |/ \\/  \\/ /\\  // /___  \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :                    | .__/ |_| |_|| .__/ \\_____/\\_\\ \\/ \\____/  \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :                    |_|           |_| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :                                        By Daniel \"blodan\" Ylitalo\r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :       There are " . count($clients) . " client(s) connected to the BNC server.\r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :     www.phpBNC.se / www.phpBNC.com / www.phpBNC.eu / www.phpBNC.net / www.phpBNC.org     \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :   _____________________________________________________________________________________   \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : /´                                                                                     `\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /bhelp or /pb help - shows this menu                                                | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /bconnect          - connects you to the IRC server you have specified              | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /breconnect        - reconnects you to the IRC server you are connected to          | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /bquit             - disconnects you from the IRC network you are connected to      | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /brestore          - joins all the channels you were in before the BNC died or      | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                        you decided to do a /breconnect (ofc not invite channels)      | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /bclear            - clears your restore memory of channels                         | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /readlog           - shows your saved messages                                      | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /dellog            - deletes your saved messages                                    | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                                                                                       | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set awaynick <awaynick>  - sets the nick the bnc will change to after being     | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                                  disconnected                                         | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set awaymsg <awaymsg>    - sets your awaymsg, for nothing enter ''              | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set nick <nick>          - sets your nick                                       | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set host <host>          - sets your host, you will have to /breconnect before  | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                                  changes takes effect.                                | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb list hosts               - lists all available v-hosts                          | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set channellog <on/off>  - enables or disables channel logging                  | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set floodcontrol <on/off> - enables or disables flood control                   | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set password <new password>  - sets a new password for your account.            | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set realname <realname>  - sets your realname, same as above.                   | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set server <server>      - hmm i wonder what this does?                         | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set port <port>          - sets the port, use + if you want SSL (ex. +7000)     | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb set key <channel or ident@host> <key>     -set blowfish key                     | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb del key <channel or ident@host>           -delete blowfish key                  | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb list keys                - lists your keys                                      | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb list channels            - lists banned channels                                | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb myinfo         - shows your info/settings                                       | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |   /pb uptime         - shows the bncs uptime                 #phpBNC @ QuakeNet.org   | \r\n" . $adminadd . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : `\\_____________________________________________________________________________________/´ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :  \r\n");
  1400.                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Remember to always configure your bnc in the query window, that way no \"miss-pastes\" can happen!\r\n");
  1401.                                                                     } else {
  1402.                                                                         if (cw($data, "pb")) {
  1403.                                                                             strtok($data, " ");
  1404.                                                                             $whattodo = strtolower(strtok(" "));
  1405.                                                                             if ($whattodo == "set") {
  1406.                                                                                 if (preg_match("/^[Pp][Bb] [Ss][Ee][Tt] (.*?) (.*)$/", $data, $m)) {
  1407.                                                                                     $section = $m[1];
  1408.                                                                                     $info = $m[2];
  1409.                                                                                     if ($section == "realname") {
  1410.                                                                                         if (!preg_match("/^[ a-z0-9\\\\,\\'\\.\\~\\_\\!\\@\\#$\\%\\^\\*\\(\\)\\_\\+\\=\\-\\|\\?\\<\\>\\/åäöæø]+$/i", $info)) {
  1411.                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your realname contains an invalid character.\r\n");
  1412.                                                                                         } else {
  1413.                                                                                             mquery("update users set realname='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
  1414.                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your realname has been updated.\r\n");
  1415.                                                                                         }
  1416.                                                                                     } else {
  1417.                                                                                         if ($section == "awaynick") {
  1418.                                                                                             if (!preg_match("/^[a-z0-9\\\\`\\^\\_\\-\\|\\[\\]{\\}]+$/i", $info)) {
  1419.                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-nick contains an invalid character.\r\n");
  1420.                                                                                             } else {
  1421.                                                                                                 mquery("update users set away_nick='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
  1422.                                                                                                 $usersettings[$uid]['away_nick'] = $info;
  1423.                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-nick has been updated.\r\n");
  1424.                                                                                             }
  1425.                                                                                         } else {
  1426.                                                                                             if ($section == "password") {
  1427.                                                                                                 mquery("update users set password='" . mysql_real_escape_string(sha1("wonder_if" . md5("someone" . $info . "will") . "figure_this_one_out")) . "' where id='{$uid}'");
  1428.                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your password has been updated.\r\n");
  1429.                                                                                             } else {
  1430.                                                                                                 if ($section == "nick") {
  1431.                                                                                                     if (!preg_match("/^[a-z0-9\\\\`\\^\\_\\-\\|\\[\\]{\\}]+$/i", $info)) {
  1432.                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your nick contains an invalid character.\r\n");
  1433.                                                                                                     } else {
  1434.                                                                                                         if (@array_key_exists(@$uid, @$net_clients)) {
  1435.                                                                                                             fwrite($net_clients[$uid], "NICK " . $info . "\r\n");
  1436.                                                                                                             $usersettings[$uid]['nickreq'] = $info;
  1437.                                                                                                         } else {
  1438.                                                                                                             $myinfo = mysql_fetch_array(mquery("select currentnick,username,host from users where id='{$uid}'"));
  1439.                                                                                                             foreach($authed as $cliID) {
  1440.                                                                                                                 if (@array_key_exists(@$uid, @$cliID)) {
  1441.                                                                                                                     fwrite($cliID[$uid], ":" . $myinfo['currentnick'] . "!" . $myinfo['username'] . "@" . $myinfo['host'] . " NICK :" . substr($info, 0, 15) . "\r\n");
  1442.                                                                                                                     break;
  1443.                                                                                                                     break;
  1444.                                                                                                                 }
  1445.                                                                                                             }
  1446.                                                                                                             foreach($admins as $useridet2) {
  1447.                                                                                                                 foreach($authed as $cliID2) {
  1448.                                                                                                                     if (@array_key_exists(@$useridet2, @$cliID2)) {
  1449.                                                                                                                         fwrite($cliID2[$useridet2], ":" . $myinfo['currentnick'] . "][" . $myinfo['username'] . "!" . $myinfo['username'] . "@" . $myinfo['host'] . " NICK :" . substr($info, 0, 15) . "][" . $myinfo['username'] . "\r\n");
  1450.                                                                                                                     }
  1451.                                                                                                                 }
  1452.                                                                                                             }
  1453.                                                                                                             mquery("update users set currentnick='" . mysql_real_escape_string(substr($info, 0, 15)) . "', nick='" . mysql_real_escape_string(substr($info, 0, 15)) . "' where id='{$uid}'");
  1454.                                                                                                             $usersettings[$uid]['currentnick'] = substr();
  1455.                                                                                                             $usersettings[$uid]['nick'] = substr($info, 0, 15);
  1456.                                                                                                             $usersettings[$uid]['tempnick'] = substr($info, 0, 15);
  1457.                                                                                                             fwrite($read_sock, ":phpBNC NOTICE " . substr($info, 0, 15) . " :Your nick has been updated.\r\n");
  1458.                                                                                                             unset($myinfo);
  1459.                                                                                                         }
  1460.                                                                                                     }
  1461.                                                                                                 } else {
  1462.                                                                                                     if ($section == "awaymsg") {
  1463.                                                                                                         if (!preg_match("/^[ a-z0-9\\\\[\\]\\(\\)\\_\\-\\#\\`\\'\\,\\.\\+\\åäöæø]+$/i", $info)) {
  1464.                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg contains an invalid character.\r\n");
  1465.                                                                                                         } else {
  1466.                                                                                                             if ($info == "''") {
  1467.                                                                                                                 $info = "";
  1468.                                                                                                             }
  1469.                                                                                                             mquery("update users set away_msg='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
  1470.                                                                                                             $usersettings[$uid]['away_msg'] = $info;
  1471.                                                                                                             if ($info != "") {
  1472.                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg has been updated.\r\n");
  1473.                                                                                                             } else {
  1474.                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg has been unset.\r\n");
  1475.                                                                                                             }
  1476.                                                                                                         }
  1477.                                                                                                     } else {
  1478.                                                                                                         if ($section == "channellog") {
  1479.                                                                                                             if ($info == "on") {
  1480.                                                                                                                 mquery("update users set channellog='1' where id='" . mysql_real_escape_string($uid) . "'");
  1481.                                                                                                                 $usersettings[$uid]['channellog'] = 1;
  1482.                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel logging has been switched on.\r\n");
  1483.                                                                                                             } else {
  1484.                                                                                                                 if ($info == "off") {
  1485.                                                                                                                     mquery("update users set channellog='0' where id='" . mysql_real_escape_string($uid) . "'");
  1486.                                                                                                                     $usersettings[$uid]['channellog'] = 0;
  1487.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel logging has been switched off.\r\n");
  1488.                                                                                                                 } else {
  1489.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb set channellog <on/off>\r\n");
  1490.                                                                                                                 }
  1491.                                                                                                             }
  1492.                                                                                                         } else {
  1493.                                                                                                             if ($section == "floodcontrol") {
  1494.                                                                                                                 if ($info == "on") {
  1495.                                                                                                                     mquery("update users set flood='1' where id='" . mysql_real_escape_string($uid) . "'");
  1496.                                                                                                                     $usersettings[$uid]['flood'] = 1;
  1497.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Flood protection has been switched on.\r\n");
  1498.                                                                                                                 } else {
  1499.                                                                                                                     if ($info == "off") {
  1500.                                                                                                                         mquery("update users set flood='0' where id='" . mysql_real_escape_string($uid) . "'");
  1501.                                                                                                                         $usersettings[$uid]['flood'] = 0;
  1502.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Flood protection has been switched off.\r\n");
  1503.                                                                                                                     } else {
  1504.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb set floodcontrol <on/off>\r\n");
  1505.                                                                                                                     }
  1506.                                                                                                                 }
  1507.                                                                                                             } else {
  1508.                                                                                                                 if ($section == "server") {
  1509.                                                                                                                     if (!preg_match("/^[a-z0-9\\-\\.]+$/i", $info)) {
  1510.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your serveraddress contains an invalid character.\r\n");
  1511.                                                                                                                     } else {
  1512.                                                                                                                         mquery("update users set network='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
  1513.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your server has been updated.\r\n");
  1514.                                                                                                                     }
  1515.                                                                                                                 } else {
  1516.                                                                                                                     if ($section == "key") {
  1517.                                                                                                                         $stuff = explode(" ", $info);
  1518.                                                                                                                         mquery("delete from blowfish_keys where uid='{$uid}' and target='" . mysql_real_escape_string($stuff[0]) . "'");
  1519.                                                                                                                         mquery("insert into blowfish_keys (uid, `target`, `key`) Values('{$uid}', '" . mysql_real_escape_string($stuff[0]) . "', '" . mysql_real_escape_string($stuff[1]) . "')");
  1520.                                                                                                                         $bfkeys[$uid][$stuff[0]]['name'] = $stuff[0];
  1521.                                                                                                                         $bfkeys[$uid][$stuff[0]]['target_nick'] = "";
  1522.                                                                                                                         $bfkeys[$uid][$stuff[0]]['key'] = $stuff[1];
  1523.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Key for " . $stuff[0] . " has been set.\r\n");
  1524.                                                                                                                         unset($stuff);
  1525.                                                                                                                     } else {
  1526.                                                                                                                         if ($section == "port") {
  1527.                                                                                                                             if (!preg_match("/^[0-9\\+]+$/i", $info)) {
  1528.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your port can only contain numbers.\r\n");
  1529.                                                                                                                             } else {
  1530.                                                                                                                                 if ($info[0] == "+") {
  1531.                                                                                                                                     $ssl = 1;
  1532.                                                                                                                                     $info = substr($info, 1, strlen($info) - 1);
  1533.                                                                                                                                 } else {
  1534.                                                                                                                                     $ssl = 0;
  1535.                                                                                                                                 }
  1536.                                                                                                                                 mquery("update users set port='{$info}', `ssl`='{$ssl}' where id='{$uid}'");
  1537.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your port has been updated.\r\n");
  1538.                                                                                                                             }
  1539.                                                                                                                         } else {
  1540.                                                                                                                             if ($section == "host") {
  1541.                                                                                                                                 $finns = mysql_fetch_array(mquery("select `count` from `v-hosts` where `host`='" . mysql_real_escape_string($info) . "'"));
  1542.                                                                                                                                 $finns2 = mysql_fetch_array(mquery("select count(*) from `v-hosts` where `host`='" . mysql_real_escape_string($info) . "'"));
  1543.                                                                                                                                 if ($finns2['count(*)'] == 1) {
  1544.                                                                                                                                     if (mysql_result(mquery("select count(*) from users where host='" . mysql_real_escape_string($info) . "'"), 0) == $finns['count']) {
  1545.                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :The userlimit for that v-host has been reached, please choose another one.\r\n");
  1546.                                                                                                                                     } else {
  1547.                                                                                                                                         mquery("update users set host='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
  1548.                                                                                                                                         $usersettings[$uid]['host'] = $info;
  1549.                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :V-host changed to " . $info . ", please do a /breconnect for it to change.\r\n");
  1550.                                                                                                                                     }
  1551.                                                                                                                                 } else {
  1552.                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :That v-host doesnt exist.\r\n");
  1553.                                                                                                                                 }
  1554.                                                                                                                                 unset($finns);
  1555.                                                                                                                                 unset($finns2);
  1556.                                                                                                                             }
  1557.                                                                                                                         }
  1558.                                                                                                                     }
  1559.                                                                                                                 }
  1560.                                                                                                             }
  1561.                                                                                                         }
  1562.                                                                                                     }
  1563.                                                                                                 }
  1564.                                                                                             }
  1565.                                                                                         }
  1566.                                                                                     }
  1567.                                                                                 } else {
  1568.                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb set <option> <value>\r\n");
  1569.                                                                                 }
  1570.                                                                                 unset($m);
  1571.                                                                                 unset($section);
  1572.                                                                                 unset($info);
  1573.                                                                             } else {
  1574.                                                                                 if ($whattodo == "aset" && checkadmin($uid, 1)) {
  1575.                                                                                     if (preg_match("/^[Pp][Bb] [Aa][Ss][Ee][Tt] (.*?) (.*?) (.*)$/", $data, $m)) {
  1576.                                                                                         $usrname = $m[1];
  1577.                                                                                         $section = $m[2];
  1578.                                                                                         $info = $m[3];
  1579.                                                                                         $checker = mquery("select id from users where md5(lower(username))='" . mysql_real_escape_string(md5(strtolower($usrname))) . "'");
  1580.                                                                                         if (mysql_num_rows($checker) == 1) {
  1581.                                                                                             $usrid = mysql_fetch_array($checker);
  1582.                                                                                             $usrid = $usrid['id'];
  1583.                                                                                             if ($section == "realname") {
  1584.                                                                                                 if (!preg_match("/^[ a-z0-9\\\\,\\'\\.\\~\\_\\!\\@\\#$\\%\\^\\*\\(\\)\\_\\+\\=\\-\\|\\?\\<\\>\\/åäöæø]+$/i", $info)) {
  1585.                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :That realname contains an invalid character.\r\n");
  1586.                                                                                                 } else {
  1587.                                                                                                     mquery("update users set realname='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
  1588.                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :That realname has been updated.\r\n");
  1589.                                                                                                 }
  1590.                                                                                             } else {
  1591.                                                                                                 if ($section == "awaynick") {
  1592.                                                                                                     if (!preg_match("/^[a-z0-9\\\\`\\^\\_\\-\\|\\[\\]{\\}]+$/i", $info)) {
  1593.                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :That away-nick contains an invalid character.\r\n");
  1594.                                                                                                     } else {
  1595.                                                                                                         mquery("update users set away_nick='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
  1596.                                                                                                         $usersettings[$usrid]['away_nick'] = $info;
  1597.                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :That away-nick has been updated.\r\n");
  1598.                                                                                                     }
  1599.                                                                                                 } else {
  1600.                                                                                                     if ($section == "password") {
  1601.                                                                                                         mquery("update users set password='" . mysql_real_escape_string(sha1("wonder_if" . md5("someone" . $info . "will") . "figure_this_one_out")) . "' where id='" . $usrid . "'");
  1602.                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :That password has been updated.\r\n");
  1603.                                                                                                     } else {
  1604.                                                                                                         if ($section == "nick") {
  1605.                                                                                                             if (!preg_match("/^[a-z0-9\\\\`\\^\\_\\-\\|\\[\\]{\\}]+$/i", $info)) {
  1606.                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :That nick contains an invalid character.\r\n");
  1607.                                                                                                             } else {
  1608.                                                                                                                 if (@array_key_exists(@$usrid, @$net_clients)) {
  1609.                                                                                                                     fwrite($net_clients[$usrid], "NICK " . $info . "\r\n");
  1610.                                                                                                                     $usersettings[$usrid]['nickreq'] = $info;
  1611.                                                                                                                 } else {
  1612.                                                                                                                     $myinfo = mysql_fetch_array(mquery("select currentnick,username,host from users where id='" . $usrid . "'"));
  1613.                                                                                                                     foreach($authed as $cliID) {
  1614.                                                                                                                         if (@array_key_exists(@$usrid, @$cliID)) {
  1615.                                                                                                                             fwrite($cliID[$usrid], ":" . $myinfo['currentnick'] . "!" . $myinfo['username'] . "@" . $myinfo['host'] . " NICK :" . substr($info, 0, 15) . "\r\n");
  1616.                                                                                                                             break;
  1617.                                                                                                                             break;
  1618.                                                                                                                         }
  1619.                                                                                                                     }
  1620.                                                                                                                     foreach($admins as $useridet2) {
  1621.                                                                                                                         foreach($authed as $cliID2) {
  1622.                                                                                                                             if (@array_key_exists(@$useridet2, @$cliID2)) {
  1623.                                                                                                                                 fwrite($cliID2[$useridet2], ":" . $myinfo['currentnick'] . "][" . $myinfo['username'] . "!" . $myinfo['username'] . "@" . $myinfo['host'] . " NICK :" . substr($info, 0, 15) . "][" . $myinfo['username'] . "\r\n");
  1624.                                                                                                                             }
  1625.                                                                                                                         }
  1626.                                                                                                                     }
  1627.                                                                                                                     mquery("update users set currentnick='" . mysql_real_escape_string(substr($info, 0, 15)) . "', nick='" . mysql_real_escape_string(substr($info, 0, 15)) . "' where id='" . $usrid . "'");
  1628.                                                                                                                     $usersettings[$usrid]['currentnick'] = substr($info, 0, 15);
  1629.                                                                                                                     $usersettings[$usrid]['nick'] = substr($info, 0, 15);
  1630.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE " . substr($info, 0, 15) . " :That nick has been updated.\r\n");
  1631.                                                                                                                     unset($myinfo);
  1632.                                                                                                                 }
  1633.                                                                                                             }
  1634.                                                                                                         } else {
  1635.                                                                                                             if ($section == "awaymsg") {
  1636.                                                                                                                 if (!preg_match("/^[ a-z0-9\\\\[\\]\\(\\)\\_\\-\\#\\`\\'\\,\\.\\+\\åäöæø]+$/i", $info)) {
  1637.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :That away-msg contains an invalid character.\r\n");
  1638.                                                                                                                 } else {
  1639.                                                                                                                     if ($info == "''") {
  1640.                                                                                                                         $info = "";
  1641.                                                                                                                     }
  1642.                                                                                                                     mquery("update users set away_msg='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
  1643.                                                                                                                     $usersettings[$usrid]['away_msg'] = $info;
  1644.                                                                                                                     if ($info != "") {
  1645.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg has been updated.\r\n");
  1646.                                                                                                                     } else {
  1647.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg has been unset.\r\n");
  1648.                                                                                                                     }
  1649.                                                                                                                 }
  1650.                                                                                                             } else {
  1651.                                                                                                                 if ($section == "channellog") {
  1652.                                                                                                                     if ($info == "on") {
  1653.                                                                                                                         mquery("update users set channellog='1' where id='" . mysql_real_escape_string($usrid) . "'");
  1654.                                                                                                                         $usersettings[$usrid]['channellog'] = 1;
  1655.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel logging has been switched on.\r\n");
  1656.                                                                                                                     } else {
  1657.                                                                                                                         if ($info == "off") {
  1658.                                                                                                                             mquery("update users set channellog='0' where id='" . mysql_real_escape_string($usrid) . "'");
  1659.                                                                                                                             $usersettings[$usrid]['channellog'] = 0;
  1660.                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel logging has been switched off.\r\n");
  1661.                                                                                                                         } else {
  1662.                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb aset <username> channellog <on/off>\r\n");
  1663.                                                                                                                         }
  1664.                                                                                                                     }
  1665.                                                                                                                 } else {
  1666.                                                                                                                     if ($section == "floodcontrol") {
  1667.                                                                                                                         if ($info == "on") {
  1668.                                                                                                                             mquery("update users set flood='1' where id='" . mysql_real_escape_string($usrid) . "'");
  1669.                                                                                                                             $usersettings[$usrid]['flood'] = 1;
  1670.                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Flood protection has been switched on.\r\n");
  1671.                                                                                                                         } else {
  1672.                                                                                                                             if ($info == "off") {
  1673.                                                                                                                                 mquery("update users set flood='0' where id='" . mysql_real_escape_string($usrid) . "'");
  1674.                                                                                                                                 $usersettings[$usrid]['flood'] = 0;
  1675.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Flood protection has been switched off.\r\n");
  1676.                                                                                                                             } else {
  1677.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb aset <username> floodcontrol <on/off>\r\n");
  1678.                                                                                                                             }
  1679.                                                                                                                         }
  1680.                                                                                                                     } else {
  1681.                                                                                                                         if ($section == "server") {
  1682.                                                                                                                             if (!preg_match("/^[a-z0-9\\-\\.]+$/i", $info)) {
  1683.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :That serveraddress contains an invalid character.\r\n");
  1684.                                                                                                                             } else {
  1685.                                                                                                                                 mquery("update users set network='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
  1686.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :That server has been updated.\r\n");
  1687.                                                                                                                             }
  1688.                                                                                                                         } else {
  1689.                                                                                                                             if ($section == "key") {
  1690.                                                                                                                                 $stuff = explode(" ", $info);
  1691.                                                                                                                                 mquery("delete from blowfish_keys where uid='" . $usrid . "' and target='" . mysql_real_escape_string($stuff[0]) . "'");
  1692.                                                                                                                                 mquery("insert into blowfish_keys (uid, `target`, `key`) Values('" . $usrid . "', '" . mysql_real_escape_string($stuff[0]) . "', '" . mysql_real_escape_string($stuff[1]) . "')");
  1693.                                                                                                                                 $bfkeys[$usrid][$stuff[0]]['name'] = $stuff[0];
  1694.                                                                                                                                 $bfkeys[$usrid][$stuff[0]]['target_nick'] = "";
  1695.                                                                                                                                 $bfkeys[$usrid][$stuff[0]]['key'] = $stuff[1];
  1696.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Key for " . $stuff[0] . " has been set.\r\n");
  1697.                                                                                                                                 unset($stuff);
  1698.                                                                                                                             } else {
  1699.                                                                                                                                 if ($section == "port") {
  1700.                                                                                                                                     if (!preg_match("/^[0-9\\+]+$/i", $info)) {
  1701.                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :The port can only contain numbers.\r\n");
  1702.                                                                                                                                     } else {
  1703.                                                                                                                                         if ($info[0] == "+") {
  1704.                                                                                                                                             $ssl = 1;
  1705.                                                                                                                                             $info = substr($info, 1, strlen($info) - 1);
  1706.                                                                                                                                         } else {
  1707.                                                                                                                                             $ssl = 0;
  1708.                                                                                                                                         }
  1709.                                                                                                                                         mquery("update users set port='{$info}', `ssl`='{$ssl}' where id='" . $usrid . "'");
  1710.                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your port has been updated.\r\n");
  1711.                                                                                                                                     }
  1712.                                                                                                                                 } else {
  1713.                                                                                                                                     if ($section == "host") {
  1714.                                                                                                                                         $finns = mysql_fetch_array(mquery("select `count` from `v-hosts` where `host`='" . mysql_real_escape_string($info) . "'"));
  1715.                                                                                                                                         $finns2 = mysql_fetch_array(mquery("select count(*) from `v-hosts` where `host`='" . mysql_real_escape_string($info) . "'"));
  1716.                                                                                                                                         if ($finns2['count(*)'] == 1) {
  1717.                                                                                                                                             if (mysql_result(mquery("select count(*) from users where host='" . mysql_real_escape_string($info) . "'"), 0) == $finns['count']) {
  1718.                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :The userlimit for that v-host has been reached, please choose another one.\r\n");
  1719.                                                                                                                                             } else {
  1720.                                                                                                                                                 mquery("update users set host='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
  1721.                                                                                                                                                 $usersettings[$usrid]['host'] = $info;
  1722.                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :V-host changed to " . $info . ", please tell the user to do a /breconnect for it to change.\r\n");
  1723.                                                                                                                                             }
  1724.                                                                                                                                         } else {
  1725.                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :That v-host doesnt exist.\r\n");
  1726.                                                                                                                                         }
  1727.                                                                                                                                         unset($finns);
  1728.                                                                                                                                         unset($finns2);
  1729.                                                                                                                                     }
  1730.                                                                                                                                 }
  1731.                                                                                                                             }
  1732.                                                                                                                         }
  1733.                                                                                                                     }
  1734.                                                                                                                 }
  1735.                                                                                                             }
  1736.                                                                                                         }
  1737.                                                                                                     }
  1738.                                                                                                 }
  1739.                                                                                             }
  1740.                                                                                         } else {
  1741.                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user doesn´t exist.\r\n");
  1742.                                                                                         }
  1743.                                                                                     } else {
  1744.                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb aset <username> <option> <value>\r\n");
  1745.                                                                                     }
  1746.                                                                                     unset($m);
  1747.                                                                                     unset($section);
  1748.                                                                                     unset($info);
  1749.                                                                                 } else {
  1750.                                                                                     if ($whattodo == "del") {
  1751.                                                                                         if (preg_match("/^[Pp][Bb] [Dd][Ee][Ll] (.*?) (.*)$/", $data, $m)) {
  1752.                                                                                             if ($m[1] == "key") {
  1753.                                                                                                 mquery("delete from blowfish_keys where uid='{$uid}' and target='" . mysql_real_escape_string($m[2]) . "'");
  1754.                                                                                                 unset($bfkeys[$uid][$m[2]]);
  1755.                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :The key for " . $m[2] . " has been deleted.\r\n");
  1756.                                                                                             }
  1757.                                                                                         } else {
  1758.                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb del <option> <value>\r\n");
  1759.                                                                                         }
  1760.                                                                                         unset($m);
  1761.                                                                                     } else {
  1762.                                                                                         if ($whattodo == "list") {
  1763.                                                                                             if (preg_match("/^[Pp][Bb] [Ll][Ii][Ss][Tt] (.*)$/", $data, $m)) {
  1764.                                                                                                 if ($m[1] == "keys") {
  1765.                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Blowfish keys for " . $usersettings[$uid]['username'] . "\r\n");
  1766.                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
  1767.                                                                                                     $sql = mquery("select target, `key` from blowfish_keys where uid='{$uid}'");
  1768.                                                                                                     while ($RS = mysql_fetch_array($sql)) {
  1769.                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $RS['target'] . " has key " . $RS['key'] . "\r\n");
  1770.                                                                                                     }
  1771.                                                                                                     unset($sql);
  1772.                                                                                                     unset($RS);
  1773.                                                                                                 } else {
  1774.                                                                                                     if ($m[1] == "hosts") {
  1775.                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Available v-hosts\r\n");
  1776.                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
  1777.                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :[number] [in use/limit] [host]\r\n");
  1778.                                                                                                         $counter = 1;
  1779.                                                                                                         $sql = mquery("select `host`, `count` from `v-hosts` order by `host` desc");
  1780.                                                                                                         while ($RS = mysql_fetch_array($sql)) {
  1781.                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :#" . $counter . " " . mysql_result(mquery("select count(*) from users where host='" . mysql_real_escape_string($RS['host']) . "'"), 0) . "/" . $RS['count'] . " " . $RS['host'] . "\r\n");
  1782.                                                                                                             ++$counter;
  1783.                                                                                                         }
  1784.                                                                                                         unset($counter);
  1785.                                                                                                         unset($sql);
  1786.                                                                                                         unset($RS);
  1787.                                                                                                     } else {
  1788.                                                                                                         if ($m[1] == "channels") {
  1789.                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Banned channels\r\n");
  1790.                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
  1791.                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} : [Channel] [Network] [Expires] [Reason]\r\n");
  1792.                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
  1793.                                                                                                             $sql = mquery("select * from banned_channels order by until desc");
  1794.                                                                                                             while ($RS = mysql_fetch_array($sql)) {
  1795.                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :[" . $RS['channel'] . "] [" . $RS['network'] . "] [" . date("Y-m-d H:i:s", $RS['until']) . "] [" . $RS['reason'] . "]\r\n");
  1796.                                                                                                             }
  1797.                                                                                                         } else {
  1798.                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, that list option doesnt exist\r\n");
  1799.                                                                                                         }
  1800.                                                                                                     }
  1801.                                                                                                 }
  1802.                                                                                             } else {
  1803.                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb list <option>\r\n");
  1804.                                                                                             }
  1805.                                                                                             unset($m);
  1806.                                                                                         } else {
  1807.                                                                                             if ($whattodo == "myinfo") {
  1808.                                                                                                 $info = mysql_fetch_array(mquery("select * from users where id='" . mysql_real_escape_string($uid) . "'"));
  1809.                                                                                                 if ($info['ssl'] == 1) {
  1810.                                                                                                     $info['port'] = "+" . $info['port'];
  1811.                                                                                                 }
  1812.                                                                                                 $ulength = 20 - strlen($info['username']);
  1813.                                                                                                 $nlength = 24 - strlen($info['nick']);
  1814.                                                                                                 $rlength = 20 - strlen($info['realname']);
  1815.                                                                                                 $anlength = 20 - strlen($info['away_nick']);
  1816.                                                                                                 $amlength = 21 - strlen($info['away_msg']);
  1817.                                                                                                 $hlength = 37 - strlen($info['host']);
  1818.                                                                                                 $plength = 37 - strlen($info['port']);
  1819.                                                                                                 $netlength = 35 - strlen($info['network']);
  1820.                                                                                                 $netnamelength = 29 - strlen($info['net_name']);
  1821.                                                                                                 if ($info['channellog'] == 1) {
  1822.                                                                                                     $info['channellog'] = "On";
  1823.                                                                                                 } else {
  1824.                                                                                                     $info['channellog'] = "Off";
  1825.                                                                                                 }
  1826.                                                                                                 if ($info['flood'] == 1) {
  1827.                                                                                                     $info['flood'] = "On";
  1828.                                                                                                 } else {
  1829.                                                                                                     $info['flood'] = "Off";
  1830.                                                                                                 }
  1831.                                                                                                 $chanlength = 31 - strlen($info['channellog']);
  1832.                                                                                                 $floodlength = 29 - strlen($info['flood']);
  1833.                                                                                                 $uspaces = "";
  1834.                                                                                                 $nspaces = "";
  1835.                                                                                                 $rspaces = "";
  1836.                                                                                                 $anspaces = "";
  1837.                                                                                                 $amspaces = "";
  1838.                                                                                                 $hspaces = "";
  1839.                                                                                                 $pspaces = "";
  1840.                                                                                                 $netspaces = "";
  1841.                                                                                                 $netnamespaces = "";
  1842.                                                                                                 $chanspaces = "";
  1843.                                                                                                 $floodspaces = "";
  1844.                                                                                                 $i = 0;
  1845.                                                                                                 while ($i < $ulength) {
  1846.                                                                                                     $uspaces.= " ";
  1847.                                                                                                     ++$i;
  1848.                                                                                                 }
  1849.                                                                                                 $i = 0;
  1850.                                                                                                 while ($i < $netnamelength) {
  1851.                                                                                                     $netnamespaces.= " ";
  1852.                                                                                                     ++$i;
  1853.                                                                                                 }
  1854.                                                                                                 $i = 0;
  1855.                                                                                                 while ($i < $nlength) {
  1856.                                                                                                     $nspaces.= " ";
  1857.                                                                                                     ++$i;
  1858.                                                                                                 }
  1859.                                                                                                 $i = 0;
  1860.                                                                                                 while ($i < $rlength) {
  1861.                                                                                                     $rspaces.= " ";
  1862.                                                                                                     ++$i;
  1863.                                                                                                 }
  1864.                                                                                                 $i = 0;
  1865.                                                                                                 while ($i < $anlength) {
  1866.                                                                                                     $anspaces.= " ";
  1867.                                                                                                     ++$i;
  1868.                                                                                                 }
  1869.                                                                                                 $i = 0;
  1870.                                                                                                 while ($i < $amlength) {
  1871.                                                                                                     $amspaces.= " ";
  1872.                                                                                                     ++$i;
  1873.                                                                                                 }
  1874.                                                                                                 $i = 0;
  1875.                                                                                                 while ($i < $hlength) {
  1876.                                                                                                     $hspaces.= " ";
  1877.                                                                                                     ++$i;
  1878.                                                                                                 }
  1879.                                                                                                 $i = 0;
  1880.                                                                                                 while ($i < $plength) {
  1881.                                                                                                     $pspaces.= " ";
  1882.                                                                                                     ++$i;
  1883.                                                                                                 }
  1884.                                                                                                 $i = 0;
  1885.                                                                                                 while ($i < $netlength) {
  1886.                                                                                                     $netspaces.= " ";
  1887.                                                                                                     ++$i;
  1888.                                                                                                 }
  1889.                                                                                                 $i = 0;
  1890.                                                                                                 while ($i < $chanlength) {
  1891.                                                                                                     $chanspaces.= " ";
  1892.                                                                                                     ++$i;
  1893.                                                                                                 }
  1894.                                                                                                 $i = 0;
  1895.                                                                                                 while ($i < $floodlength) {
  1896.                                                                                                     $floodspaces.= " ";
  1897.                                                                                                     ++$i;
  1898.                                                                                                 }
  1899.                                                                                                 fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :   _______________________________________________________________________________   \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : /´                                 |                                             `\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Username: " . $info['username'] . "{$uspaces}|    Server: " . $info['network'] . "{$netspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Nick: " . $info['nick'] . "{$nspaces}|    Network name: " . $info['net_name'] . "{$netnamespaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Realname: " . $info['realname'] . "{$rspaces}|    Port: " . $info['port'] . "{$pspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Awaynick: " . $info['away_nick'] . "{$anspaces}|    Host: " . $info['host'] . "{$hspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Awaymsg: " . $info['away_msg'] . "{$amspaces}|    Floodcontrol: " . $info['flood'] . "{$floodspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                                  |    Channellog: " . $info['channellog'] . "{$chanspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : `\\_________________________________|______________________________________________/´ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :  \r\n");
  1900.                                                                                                 unset($ulength);
  1901.                                                                                                 unset($nlength);
  1902.                                                                                                 unset($rlength);
  1903.                                                                                                 unset($anlength);
  1904.                                                                                                 unset($amlength);
  1905.                                                                                                 unset($hlength);
  1906.                                                                                                 unset($plength);
  1907.                                                                                                 unset($netlength);
  1908.                                                                                                 unset($netnamelength);
  1909.                                                                                                 unset($uspaces);
  1910.                                                                                                 unset($nspaces);
  1911.                                                                                                 unset($rspaces);
  1912.                                                                                                 unset($anspaces);
  1913.                                                                                                 unset($amspaces);
  1914.                                                                                                 unset($hspaces);
  1915.                                                                                                 unset($pspaces);
  1916.                                                                                                 unset($netspaces);
  1917.                                                                                                 unset($netnamespaces);
  1918.                                                                                                 unset($chanlength);
  1919.                                                                                                 unset($chanspaces);
  1920.                                                                                                 unset($floodlength);
  1921.                                                                                                 unset($floodspaces);
  1922.                                                                                                 unset($info);
  1923.                                                                                             } else {
  1924.                                                                                                 if ($whattodo == "uptime") {
  1925.                                                                                                     $time = time() - starttime;
  1926.                                                                                                     $weeks = floor($time / 604800);
  1927.                                                                                                     $time = $time - $weeks * 604800;
  1928.                                                                                                     $days = floor($time / 86400);
  1929.                                                                                                     $time = $time - $days * 86400;
  1930.                                                                                                     $hours = floor($time / 3600);
  1931.                                                                                                     $time = $time - $hours * 3600;
  1932.                                                                                                     $min = floor($time / 60);
  1933.                                                                                                     $sec = $time - $min * 60;
  1934.                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :I have been up for " . $weeks . " week(s), " . $days . " day(s), " . $hours . " hour(s), " . $min . " minute(s) and " . $sec . " second(s)\r\n");
  1935.                                                                                                     unset($sec);
  1936.                                                                                                     unset($hours);
  1937.                                                                                                     unset($min);
  1938.                                                                                                     unset($time);
  1939.                                                                                                     unset($weeks);
  1940.                                                                                                     unset($days);
  1941.                                                                                                 } else {
  1942.                                                                                                     if ($whattodo == "stats" && checkadmin($uid, 1)) {
  1943.                                                                                                         $time = time() - starttime;
  1944.                                                                                                         $weeks = floor($time / 604800);
  1945.                                                                                                         $time = $time - $weeks * 604800;
  1946.                                                                                                         $days = floor($time / 86400);
  1947.                                                                                                         $time = $time - $days * 86400;
  1948.                                                                                                         $hours = floor($time / 3600);
  1949.                                                                                                         $time = $time - $hours * 3600;
  1950.                                                                                                         $min = floor($time / 60);
  1951.                                                                                                         $sec = $time - $min * 60;
  1952.                                                                                                         $totsupadmins = 0;
  1953.                                                                                                         $supadminsonline = 0;
  1954.                                                                                                         $sql = mquery("select id from users where admin='2'");
  1955.                                                                                                         $totsupadmins = mysql_num_rows($sql);
  1956.                                                                                                         while ($RS = mysql_fetch_array($sql)) {
  1957.                                                                                                             if (in_array($RS['id'], $admins)) {
  1958.                                                                                                                 ++$supadminsonline;
  1959.                                                                                                             }
  1960.                                                                                                         }
  1961.                                                                                                         $totnormadmins = 0;
  1962.                                                                                                         $normadminsonline = 0;
  1963.                                                                                                         $sql = mquery("select id from users where admin='1'");
  1964.                                                                                                         $totnormadmins = mysql_num_rows($sql);
  1965.                                                                                                         while ($RS = mysql_fetch_array($sql)) {
  1966.                                                                                                             if (in_array($RS['id'], $admins)) {
  1967.                                                                                                                 ++$normadminsonline;
  1968.                                                                                                             }
  1969.                                                                                                         }
  1970.                                                                                                         $banned = mysql_result(mquery("select count(*) from users where banned != ''"), 0);
  1971.                                                                                                         $totusers = mysql_result(mquery("select count(*) from users"), 0);
  1972.                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :[ Users online: " . count($clients) . "/" . $totusers . " ][ Super-admins: " . $supadminsonline . "/" . $totsupadmins . " ][ Admins: " . $normadminsonline . "/" . $totnormadmins . " ][ Banned: " . $banned . " ][ Uptime: " . $weeks . " week(s), " . $days . " day(s), " . $hours . " hour(s), " . $min . " minute(s) and " . $sec . " second(s) ]\r\n");
  1973.                                                                                                         unset($sec);
  1974.                                                                                                         unset($hours);
  1975.                                                                                                         unset($min);
  1976.                                                                                                         unset($time);
  1977.                                                                                                         unset($weeks);
  1978.                                                                                                         unset($days);
  1979.                                                                                                         unset($totnormadmins);
  1980.                                                                                                         unset($normadminsonline);
  1981.                                                                                                         unset($totsupadmins);
  1982.                                                                                                         unset($supadminsonline);
  1983.                                                                                                         unset($banned);
  1984.                                                                                                         unset($sql);
  1985.                                                                                                         unset($RS);
  1986.                                                                                                         unset($totusers);
  1987.                                                                                                     } else {
  1988.                                                                                                         if ($whattodo == "kick" && checkadmin($uid, 1)) {
  1989.                                                                                                             if (preg_match("/^[Pp][Bb] [Kk][Ii][Cc][Kk] (.*)$/", $data, $m)) {
  1990.                                                                                                                 $online = 0;
  1991.                                                                                                                 $usid = mysql_fetch_array(mquery("select id from users where username='" . mysql_real_escape_string($m[1]) . "'"));
  1992.                                                                                                                 foreach($authed as $cliID) {
  1993.                                                                                                                     $useridet = array_keys($cliID);
  1994.                                                                                                                     if ($useridet[0] == $usid['id']) {
  1995.                                                                                                                         $online = 1;
  1996.                                                                                                                         break;
  1997.                                                                                                                         break;
  1998.                                                                                                                     }
  1999.                                                                                                                 }
  2000.                                                                                                                 if ($online == 1) {
  2001.                                                                                                                     $res = $cliID[$useridet[0]];
  2002.                                                                                                                     $key = array_search($res, $clients);
  2003.                                                                                                                     unset($clients[$key]);
  2004.                                                                                                                     unset($authed[$key]);
  2005.                                                                                                                     if (@array_key_exists(@$useridet[0], @$net_clients)) {
  2006.                                                                                                                         fwrite($net_clients[$useridet[0]], "NICK :" . $usersettings[$useridet[0]]['away_nick'] . "\r\n");
  2007.                                                                                                                         if ($usersettings[$useridet[0]]['channellog'] == 0) {
  2008.                                                                                                                             fwrite($net_clients[$useridet[0]], "MODE " . $usersettings[$useridet[0]]['away_nick'] . " +d\r\n");
  2009.                                                                                                                         }
  2010.                                                                                                                         if ($usersettings[$useridet[0]]['away-msg'] != "") {
  2011.                                                                                                                             fwrite($net_clients[$useridet[0]], "AWAY :" . $usersettings[$useridet[0]]['away_msg'] . "\r\n");
  2012.                                                                                                                         }
  2013.                                                                                                                     }
  2014.                                                                                                                     if (in_array($useridet[0], $admins)) {
  2015.                                                                                                                         $key3 = array_search($useridet[0], $admins);
  2016.                                                                                                                         unset($admins[$key3]);
  2017.                                                                                                                         unset($key3);
  2018.                                                                                                                     }
  2019.                                                                                                                     foreach($admins as $useridet2) {
  2020.                                                                                                                         foreach($authed as $cliID2) {
  2021.                                                                                                                             if (@array_key_exists(@$useridet2, @$cliID2)) {
  2022.                                                                                                                                 fwrite($cliID2[$useridet2], ":" . $usersettings[$useridet[0]]['currentnick'] . "][" . $usersettings[$useridet[0]]['username'] . "!" . $usersettings[$useridet[0]]['username'] . "@" . $usersettings[$useridet[0]]['host'] . " PART &system\r\n");
  2023.                                                                                                                                 fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " kicked " . $usersettings[$useridet[0]]['username'] . "\r\n");
  2024.                                                                                                                             }
  2025.                                                                                                                         }
  2026.                                                                                                                     }
  2027.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :User has been kicked of the bouncer.\r\n");
  2028.                                                                                                                     fwrite($res, ":phpBNC NOTICE " . $usersettings[$useridet[0]]['currentnick'] . " :You got kicked from the bouncer by " . $usersettings[$uid]['username'] . ".\r\n");
  2029.                                                                                                                     fclose($res);
  2030.                                                                                                                     echo $usersettings[$useridet[0]]['username'] . "s client disconnected.\r\n";
  2031.                                                                                                                     unset($res);
  2032.                                                                                                                     unset($key);
  2033.                                                                                                                     unset($useridet);
  2034.                                                                                                                     unset($useridet2);
  2035.                                                                                                                     unset($cliID);
  2036.                                                                                                                     unset($cliID2);
  2037.                                                                                                                     unset($online);
  2038.                                                                                                                     unset($usid);
  2039.                                                                                                                 } else {
  2040.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :User isn´t online.\r\n");
  2041.                                                                                                                 }
  2042.                                                                                                             } else {
  2043.                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb kick <username>\r\n");
  2044.                                                                                                             }
  2045.                                                                                                             unset($m);
  2046.                                                                                                         } else {
  2047.                                                                                                             if ($whattodo == "find" && checkadmin($uid, 1)) {
  2048.                                                                                                                 if (preg_match("/^[Pp][Bb] [Ff][Ii][Nn][Dd] (.*)$/", $data, $m)) {
  2049.                                                                                                                     $counter = 1;
  2050.                                                                                                                     $sql = mquery("select id, username, nick, admin from users where username like '%" . mysql_real_escape_string(str_replace("*", "%", $m[1])) . "%'");
  2051.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Found " . mysql_num_rows($sql) . " result(s).\r\n");
  2052.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
  2053.                                                                                                                     while ($RS = mysql_fetch_array($sql)) {
  2054.                                                                                                                         $online = "";
  2055.                                                                                                                         foreach($authed as $cliID) {
  2056.                                                                                                                             $useridet = array_keys($cliID);
  2057.                                                                                                                             if ($useridet[0] == $RS['id']) {
  2058.                                                                                                                                 $online = chr(3) . "3ONLINE" . chr(3);
  2059.                                                                                                                                 break;
  2060.                                                                                                                                 break;
  2061.                                                                                                                             }
  2062.                                                                                                                         }
  2063.                                                                                                                         if (strlen($online) == 0) {
  2064.                                                                                                                             $online = chr(3) . "4OFFLINE" . chr(3);
  2065.                                                                                                                         }
  2066.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :#" . $counter . " " . chr(2) . "nick" . chr(2) . ": " . $RS['currentnick'] . " " . chr(2) . "username" . chr(2) . ": " . $RS['username'] . " - " . $online . " - " . chr(2) . "level" . chr(2) . ": " . $RS['admin'] . "\r\n");
  2067.                                                                                                                         ++$counter;
  2068.                                                                                                                     }
  2069.                                                                                                                     unset($sql);
  2070.                                                                                                                     unset($RS);
  2071.                                                                                                                     unset($counter);
  2072.                                                                                                                     unset($online);
  2073.                                                                                                                     unset($useridet);
  2074.                                                                                                                     unset($cliID);
  2075.                                                                                                                     unset($m);
  2076.                                                                                                                 } else {
  2077.                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb find <username>\r\n");
  2078.                                                                                                                 }
  2079.                                                                                                             } else {
  2080.                                                                                                                 if ($whattodo == "banchan" && checkadmin($uid, 1)) {
  2081.                                                                                                                     if (preg_match("/^[Pp][Bb] [Bb][Aa][Nn][Cc][Hh][Aa][Nn] (.*?) (.*?) (.*?) (.*)$/", $data, $m)) {
  2082.                                                                                                                         if (strtolower($m[3][strlen($m[3]) - 1]) == "d") {
  2083.                                                                                                                             $newtime = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + substr($m[3], 0, strlen($m[3]) - 1), date("Y"));
  2084.                                                                                                                         } else if (strtolower($m[3][strlen($m[3]) - 1]) == "m") {
  2085.                                                                                                                             $newtime = mktime(date("H"), date("i") + substr($m[3], 0, strlen($m[3]) - 1), date("s"), date("m"), date("d"), date("Y"));
  2086.                                                                                                                         }
  2087.                                                                                                                         $counter = mysql_result(mquery("select count(*) from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='" . mysql_real_escape_string($m[2]) . "'"), 0);
  2088.                                                                                                                         if ($counter == 1) {
  2089.                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :This channel is already banned.\r\n");
  2090.                                                                                                                         } else {
  2091.                                                                                                                             mquery("insert into banned_channels (channel, network, until, reason, byid) Values('" . mysql_real_escape_string($m[1]) . "', '" . mysql_real_escape_string($m[2]) . "', '" . $newtime . "', '" . mysql_real_escape_string($m[4]) . "', '" . $uid . "')");
  2092.                                                                                                                             $sql = mquery("select uid from tempchannels where channel='" . mysql_real_escape_string($m[1]) . "'");
  2093.                                                                                                                             while ($RS = mysql_fetch_array($sql)) {
  2094.                                                                                                                                 $samenetwork = false;
  2095.                                                                                                                                 if ($m[2] != "*") {
  2096.                                                                                                                                     $net_name = mysql_fetch_array(mquery("select net_name from users where id='" . $RS['uid'] . "'"));
  2097.                                                                                                                                     if ($m[2] == $net_name['net_name']) {
  2098.                                                                                                                                         $samenetwork = true;
  2099.                                                                                                                                     }
  2100.                                                                                                                                 } else {
  2101.                                                                                                                                     $samenetwork = true;
  2102.                                                                                                                                 }
  2103.                                                                                                                                 if ($samenetwork == true) {
  2104.                                                                                                                                     fwrite($net_clients[$RS['uid']], "PART " . $m[1] . "\r\n");
  2105.                                                                                                                                     foreach($authed as $cliID) {
  2106.                                                                                                                                         if (@array_key_exists(@$RS['uid'], @$cliID)) {
  2107.                                                                                                                                             fwrite($cliID[$RS['uid']], ":phpBNC NOTICE " . $usersettings[$RS['uid']]['currentnick'] . " :The channel " . $m[1] . " you were in has been banned by an admin due to: " . $m[4] . ".\r\n");
  2108.                                                                                                                                         }
  2109.                                                                                                                                     }
  2110.                                                                                                                                 }
  2111.                                                                                                                             }
  2112.                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel is now banned.\r\n");
  2113.                                                                                                                             foreach($admins as $useridet2) {
  2114.                                                                                                                                 foreach($authed as $cliID2) {
  2115.                                                                                                                                     if (@array_key_exists(@$useridet2, @$cliID2)) {
  2116.                                                                                                                                         fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " banned channel " . $m[1] . " on network " . $m[2] . " due to: " . $m[4] . ".\r\n");
  2117.                                                                                                                                     }
  2118.                                                                                                                                 }
  2119.                                                                                                                             }
  2120.                                                                                                                         }
  2121.                                                                                                                         unset($m);
  2122.                                                                                                                         unset($samenetwork);
  2123.                                                                                                                         unset($cliID);
  2124.                                                                                                                         unset($net_name);
  2125.                                                                                                                         unset($sql);
  2126.                                                                                                                         unset($RS);
  2127.                                                                                                                         unset($counter);
  2128.                                                                                                                     } else {
  2129.                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb banchan <channel> <network> <duration> <reason>\r\n");
  2130.                                                                                                                     }
  2131.                                                                                                                 } else {
  2132.                                                                                                                     if ($whattodo == "unbanchan" && checkadmin($uid, 1)) {
  2133.                                                                                                                         if (preg_match("/^[Pp][Bb] [Uu][Nn][Bb][Aa][Nn][Cc][Hh][Aa][Nn] (.*?) (.*)$/", $data, $m)) {
  2134.                                                                                                                             if ($m[2] == "*") {
  2135.                                                                                                                                 $counter = mysql_result(mquery("select count(*) from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "'"), 0);
  2136.                                                                                                                             } else {
  2137.                                                                                                                                 $counter = mysql_result(mquery("select count(*) from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='" . mysql_real_escape_string($m[2]) . "'"), 0);
  2138.                                                                                                                             }
  2139.                                                                                                                             if (0 < $counter) {
  2140.                                                                                                                                 if ($m[2] == "*") {
  2141.                                                                                                                                     mquery("delete from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "'");
  2142.                                                                                                                                 } else {
  2143.                                                                                                                                     mquery("delete from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='" . mysql_real_escape_string($m[2]) . "'");
  2144.                                                                                                                                 }
  2145.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel " . $m[1] . " is now unbanned.\r\n");
  2146.                                                                                                                             } else {
  2147.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel " . $m[1] . " isnt even banned.\r\n");
  2148.                                                                                                                             }
  2149.                                                                                                                             foreach($admins as $useridet2) {
  2150.                                                                                                                                 foreach($authed as $cliID2) {
  2151.                                                                                                                                     if (@array_key_exists(@$useridet2, @$cliID2)) {
  2152.                                                                                                                                         fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " unbanned channel " . $m[1] . ".\r\n");
  2153.                                                                                                                                     }
  2154.                                                                                                                                 }
  2155.                                                                                                                             }
  2156.                                                                                                                             unset($m);
  2157.                                                                                                                             unset($counter);
  2158.                                                                                                                         } else {
  2159.                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb unbanchan <channel> <network>\r\n");
  2160.                                                                                                                         }
  2161.                                                                                                                     } else {
  2162.                                                                                                                         if ($whattodo == "check" && checkadmin($uid, 1)) {
  2163.                                                                                                                             if (preg_match("/^[Pp][Bb] [Cc][Hh][Ee][Cc][Kk] (.*)$/", $data, $m)) {
  2164.                                                                                                                                 $sql = mquery("select uid, channel from tempchannels where channel='" . $m[1] . "'");
  2165.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Found " . mysql_num_rows($sql) . " user(s) in " . $m[1] . ".\r\n");
  2166.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
  2167.                                                                                                                                 $counter = 0;
  2168.                                                                                                                                 while ($RS = mysql_fetch_array($sql)) {
  2169.                                                                                                                                     $online = "";
  2170.                                                                                                                                     foreach($authed as $cliID) {
  2171.                                                                                                                                         $useridet = array_keys($cliID);
  2172.                                                                                                                                         if ($useridet[0] == $RS['uid']) {
  2173.                                                                                                                                             $online = chr(3) . "3ONLINE" . chr(3);
  2174.                                                                                                                                             break;
  2175.                                                                                                                                             break;
  2176.                                                                                                                                         }
  2177.                                                                                                                                     }
  2178.                                                                                                                                     if (strlen($online) == 0) {
  2179.                                                                                                                                         $online = chr(3) . "4OFFLINE" . chr(3);
  2180.                                                                                                                                     }
  2181.                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :#" . $counter . " " . chr(2) . "nick" . chr(2) . ": " . $usersettings[$RS['uid']]['currentnick'] . " " . chr(2) . "username" . chr(2) . ": " . $usersettings[$RS['uid']]['username'] . " - " . $online . " - " . chr(2) . "level" . chr(2) . ": " . $usersettings[$RS['uid']]['admin'] . "\r\n");
  2182.                                                                                                                                     ++$counter;
  2183.                                                                                                                                 }
  2184.                                                                                                                                 unset($sql);
  2185.                                                                                                                                 unset($RS);
  2186.                                                                                                                                 unset($counter);
  2187.                                                                                                                                 unset($online);
  2188.                                                                                                                                 unset($useridet);
  2189.                                                                                                                                 unset($cliID);
  2190.                                                                                                                                 unset($m);
  2191.                                                                                                                             } else {
  2192.                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb check <channel>\r\n");
  2193.                                                                                                                             }
  2194.                                                                                                                         } else {
  2195.                                                                                                                             if ($whattodo == "info" && checkadmin($uid, 1)) {
  2196.                                                                                                                                 if (preg_match("/^[Pp][Bb] [Ii][Nn][Ff][Oo] (.*)$/", $data, $m)) {
  2197.                                                                                                                                     $info = mysql_fetch_array(mquery("select * from users where username='" . mysql_real_escape_string($m[1]) . "'"));
  2198.                                                                                                                                     if ($info['ssl'] == 1) {
  2199.                                                                                                                                         $info['port'] = "+" . $info['port'];
  2200.                                                                                                                                     }
  2201.                                                                                                                                     $ulength = 20 - strlen($info['username']);
  2202.                                                                                                                                     $nlength = 24 - strlen($info['nick']);
  2203.                                                                                                                                     $rlength = 20 - strlen($info['realname']);
  2204.                                                                                                                                     $anlength = 20 - strlen($info['away_nick']);
  2205.                                                                                                                                     $amlength = 21 - strlen($info['away_msg']);
  2206.                                                                                                                                     $hlength = 37 - strlen($info['host']);
  2207.                                                                                                                                     $plength = 37 - strlen($info['port']);
  2208.                                                                                                                                     $netlength = 35 - strlen($info['network']);
  2209.                                                                                                                                     $netnamelength = 29 - strlen($info['net_name']);
  2210.                                                                                                                                     if ($info['channellog'] == 1) {
  2211.                                                                                                                                         $info['channellog'] = "On";
  2212.                                                                                                                                     } else {
  2213.                                                                                                                                         $info['channellog'] = "Off";
  2214.                                                                                                                                     }
  2215.                                                                                                                                     if ($info['flood'] == 1) {
  2216.                                                                                                                                         $info['flood'] = "On";
  2217.                                                                                                                                     } else {
  2218.                                                                                                                                         $info['flood'] = "Off";
  2219.                                                                                                                                     }
  2220.                                                                                                                                     $chanlength = 31 - strlen($info['channellog']);
  2221.                                                                                                                                     $floodlength = 29 - strlen($info['flood']);
  2222.                                                                                                                                     $uspaces = "";
  2223.                                                                                                                                     $nspaces = "";
  2224.                                                                                                                                     $rspaces = "";
  2225.                                                                                                                                     $anspaces = "";
  2226.                                                                                                                                     $amspaces = "";
  2227.                                                                                                                                     $hspaces = "";
  2228.                                                                                                                                     $pspaces = "";
  2229.                                                                                                                                     $netspaces = "";
  2230.                                                                                                                                     $netnamespaces = "";
  2231.                                                                                                                                     $i = 0;
  2232.                                                                                                                                     while ($i < $ulength) {
  2233.                                                                                                                                         $uspaces.= " ";
  2234.                                                                                                                                         ++$i;
  2235.                                                                                                                                     }
  2236.                                                                                                                                     $i = 0;
  2237.                                                                                                                                     while ($i < $netnamelength) {
  2238.                                                                                                                                         $netnamespaces.= " ";
  2239.                                                                                                                                         ++$i;
  2240.                                                                                                                                     }
  2241.                                                                                                                                     $i = 0;
  2242.                                                                                                                                     while ($i < $nlength) {
  2243.                                                                                                                                         $nspaces.= " ";
  2244.                                                                                                                                         ++$i;
  2245.                                                                                                                                     }
  2246.                                                                                                                                     $i = 0;
  2247.                                                                                                                                     while ($i < $rlength) {
  2248.                                                                                                                                         $rspaces.= " ";
  2249.                                                                                                                                         ++$i;
  2250.                                                                                                                                     }
  2251.                                                                                                                                     $i = 0;
  2252.                                                                                                                                     while ($i < $anlength) {
  2253.                                                                                                                                         $anspaces.= " ";
  2254.                                                                                                                                         ++$i;
  2255.                                                                                                                                     }
  2256.                                                                                                                                     $i = 0;
  2257.                                                                                                                                     while ($i < $amlength) {
  2258.                                                                                                                                         $amspaces.= " ";
  2259.                                                                                                                                         ++$i;
  2260.                                                                                                                                     }
  2261.                                                                                                                                     $i = 0;
  2262.                                                                                                                                     while ($i < $hlength) {
  2263.                                                                                                                                         $hspaces.= " ";
  2264.                                                                                                                                         ++$i;
  2265.                                                                                                                                     }
  2266.                                                                                                                                     $i = 0;
  2267.                                                                                                                                     while ($i < $plength) {
  2268.                                                                                                                                         $pspaces.= " ";
  2269.                                                                                                                                         ++$i;
  2270.                                                                                                                                     }
  2271.                                                                                                                                     $i = 0;
  2272.                                                                                                                                     while ($i < $netlength) {
  2273.                                                                                                                                         $netspaces.= " ";
  2274.                                                                                                                                         ++$i;
  2275.                                                                                                                                     }
  2276.                                                                                                                                     $i = 0;
  2277.                                                                                                                                     while ($i < $chanlength) {
  2278.                                                                                                                                         $chanspaces.= " ";
  2279.                                                                                                                                         ++$i;
  2280.                                                                                                                                     }
  2281.                                                                                                                                     $i = 0;
  2282.                                                                                                                                     while ($i < $floodlength) {
  2283.                                                                                                                                         $floodspaces.= " ";
  2284.                                                                                                                                         ++$i;
  2285.                                                                                                                                     }
  2286.                                                                                                                                     fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :   _______________________________________________________________________________   \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : /´                                 |                                             `\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Username: " . $info['username'] . "{$uspaces}|    Server: " . $info['network'] . "{$netspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Nick: " . $info['nick'] . "{$nspaces}|    Network name: " . $info['net_name'] . "{$netnamespaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Realname: " . $info['realname'] . "{$rspaces}|    Port: " . $info['port'] . "{$pspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Awaynick: " . $info['away_nick'] . "{$anspaces}|    Host: " . $info['host'] . "{$hspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |    Awaymsg: " . $info['away_msg'] . "{$amspaces}|    Floodcontrol: " . $info['flood'] . "{$floodspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |                                  |    Channellog: " . $info['channellog'] . "{$chanspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : `\\_________________________________|______________________________________________/´ \r\n");
  2287.                                                                                                                                     $sql = mquery("select channel from tempchannels where uid='" . $info['id'] . "'");
  2288.                                                                                                                                     while ($RS = mysql_fetch_array($sql)) {
  2289.                                                                                                                                         $channels = $channels . $RS['channel'] . ", ";
  2290.                                                                                                                                     }
  2291.                                                                                                                                     fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : Hes currently in these channels: " . $channels . "\r\n");
  2292.                                                                                                                                     $channels = "";
  2293.                                                                                                                                     $sql = mquery("select channel, network from userchannels where uid='" . $info['id'] . "'");
  2294.                                                                                                                                     while ($RS = mysql_fetch_array($sql)) {
  2295.                                                                                                                                         $channels = $channels . $RS['channel'] . " (" . $RS['network'] . "), ";
  2296.                                                                                                                                     }
  2297.                                                                                                                                     fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : He has these channels stored: " . $channels . "\r\n");
  2298.                                                                                                                                     unset($ulength);
  2299.                                                                                                                                     unset($nlength);
  2300.                                                                                                                                     unset($rlength);
  2301.                                                                                                                                     unset($anlength);
  2302.                                                                                                                                     unset($amlength);
  2303.                                                                                                                                     unset($hlength);
  2304.                                                                                                                                     unset($plength);
  2305.                                                                                                                                     unset($netlength);
  2306.                                                                                                                                     unset($netnamelength);
  2307.                                                                                                                                     unset($uspaces);
  2308.                                                                                                                                     unset($nspaces);
  2309.                                                                                                                                     unset($rspaces);
  2310.                                                                                                                                     unset($anspaces);
  2311.                                                                                                                                     unset($amspaces);
  2312.                                                                                                                                     unset($hspaces);
  2313.                                                                                                                                     unset($pspaces);
  2314.                                                                                                                                     unset($netspaces);
  2315.                                                                                                                                     unset($netnamespaces);
  2316.                                                                                                                                     unset($chanlength);
  2317.                                                                                                                                     unset($chanspaces);
  2318.                                                                                                                                     unset($floodlength);
  2319.                                                                                                                                     unset($floodspaces);
  2320.                                                                                                                                     unset($info);
  2321.                                                                                                                                     unset($sql);
  2322.                                                                                                                                     unset($channels);
  2323.                                                                                                                                     unset($RS);
  2324.                                                                                                                                 } else {
  2325.                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb info <username>\r\n");
  2326.                                                                                                                                 }
  2327.                                                                                                                             } else {
  2328.                                                                                                                                 if ($whattodo == "ban" && checkadmin($uid, 1)) {
  2329.                                                                                                                                     if (preg_match("/^[Pp][Bb] [Bb][Aa][Nn] (.*?) (.*?) (.*)$/", $data, $m)) {
  2330.                                                                                                                                         if (strtolower($m[2][strlen($m[2]) - 1]) == "d") {
  2331.                                                                                                                                             $newtime = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + substr($m[2], 0, strlen($m[2]) - 1), date("Y"));
  2332.                                                                                                                                         } else if (strtolower($m[2][strlen($m[2]) - 1]) == "m") {
  2333.                                                                                                                                             $newtime = mktime(date("H"), date("i") + substr($m[2], 0, strlen($m[2]) - 1), date("s"), date("m"), date("d"), date("Y"));
  2334.                                                                                                                                         }
  2335.                                                                                                                                         $sql = mquery("select id, banned, banned_until from users where username='" . mysql_real_escape_string($m[1]) . "'");
  2336.                                                                                                                                         if (mysql_num_rows($sql) == 1) {
  2337.                                                                                                                                             $RS = mysql_fetch_array($sql);
  2338.                                                                                                                                             if (0 < strlen($RS['banned']) && time() < $RS['banned_until']) {
  2339.                                                                                                                                                 fwrite($read_sock, "phpBNC NOTICE {$nick} :This user is already banned due to: " . $RS['banned'] . " until: " . date("Y-m-d H:i:s", $RS['banned_until']) . "\r\n");
  2340.                                                                                                                                             } else {
  2341.                                                                                                                                                 mquery("update users set banned='" . mysql_real_escape_string($m[3]) . "', banned_until='" . $newtime . "' where id='" . mysql_real_escape_string($RS['id']) . "'");
  2342.                                                                                                                                                 if (@array_key_exists(@$RS['id'], @$net_clients)) {
  2343.                                                                                                                                                     fwrite($net_clients[$RS['id']], "QUIT\r\n");
  2344.                                                                                                                                                     fclose($net_clients[$RS['id']]);
  2345.                                                                                                                                                     unset($net_clients[$RS['id']]);
  2346.                                                                                                                                                 }
  2347.                                                                                                                                                 $online = 0;
  2348.                                                                                                                                                 foreach($authed as $cliID) {
  2349.                                                                                                                                                     if (@array_key_exists(@$RS['id'], @$cliID)) {
  2350.                                                                                                                                                         fwrite($cliID[$RS['id']], ":phpBNC NOTICE " . $usersettings[$RS['id']]['currentnick'] . " :You got banned due to: " . $m[3] . " until: " . date("Y-m-d H:i:s", $newtime) . "\r\n");
  2351.                                                                                                                                                         $online = 1;
  2352.                                                                                                                                                         break;
  2353.                                                                                                                                                         break;
  2354.                                                                                                                                                     }
  2355.                                                                                                                                                 }
  2356.                                                                                                                                                 if ($online == 1) {
  2357.                                                                                                                                                     $res = $cliID[$RS['id']];
  2358.                                                                                                                                                     $key = array_search($res, $clients);
  2359.                                                                                                                                                     unset($clients[$key]);
  2360.                                                                                                                                                     unset($authed[$key]);
  2361.                                                                                                                                                     if (in_array($RS['id'], $admins)) {
  2362.                                                                                                                                                         $key3 = array_search($RS['id'], $admins);
  2363.                                                                                                                                                         unset($admins[$key3]);
  2364.                                                                                                                                                         unset($key3);
  2365.                                                                                                                                                     }
  2366.                                                                                                                                                     foreach($admins as $useridet2) {
  2367.                                                                                                                                                         foreach($authed as $cliID2) {
  2368.                                                                                                                                                             if (@array_key_exists(@$useridet2, @$cliID2)) {
  2369.                                                                                                                                                                 fwrite($cliID2[$useridet2], ":" . $usersettings[$RS['id']]['currentnick'] . "][" . $usersettings[$RS['id']]['username'] . "!" . $usersettings[$RS['id']]['username'] . "@" . $usersettings[$RS['id']]['host'] . " PART &system\r\n");
  2370.                                                                                                                                                                 fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " " . chr(2) . "BANNED" . chr(2) . " " . $usersettings[$RS['id']]['username'] . " until " . date("Y-m-d H:i:s", $newtime) . " due to: " . $m[3] . "\r\n");
  2371.                                                                                                                                                             }
  2372.                                                                                                                                                         }
  2373.                                                                                                                                                     }
  2374.                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :User has been banned until " . date("Y-m-d H:i:s", $newtime) . ".\r\n");
  2375.                                                                                                                                                     fwrite($res, ":phpBNC NOTICE " . $usersettings[$RS['id']]['currentnick'] . " :You got banned from the bouncer by " . $usersettings[$uid]['username'] . " until " . date("Y-m-d H:i:s", $newtime) . " due to: " . $m[3] . ".\r\n");
  2376.                                                                                                                                                     fclose($res);
  2377.                                                                                                                                                     echo $usersettings[$RS['id']]['username'] . "s client disconnected.\r\n";
  2378.                                                                                                                                                 }
  2379.                                                                                                                                             }
  2380.                                                                                                                                         } else {
  2381.                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user didn´t exist.\r\n");
  2382.                                                                                                                                         }
  2383.                                                                                                                                         unset($m);
  2384.                                                                                                                                         unset($sql);
  2385.                                                                                                                                         unset($RS);
  2386.                                                                                                                                         unset($cliID);
  2387.                                                                                                                                         unset($res);
  2388.                                                                                                                                         unset($online);
  2389.                                                                                                                                     } else {
  2390.                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb ban <username> <duration> <reason>\r\n");
  2391.                                                                                                                                     }
  2392.                                                                                                                                 } else {
  2393.                                                                                                                                     if ($whattodo == "unban" && checkadmin($uid, 1)) {
  2394.                                                                                                                                         if (preg_match("/^[Pp][Bb] [Uu][Nn][Bb][Aa][Nn] (.*)$/", $data, $m)) {
  2395.                                                                                                                                             $counter = mquery("select banned, banned_until from users where username='" . mysql_real_escape_string($m[1]) . "'");
  2396.                                                                                                                                             if (mysql_num_rows($counter) == 1) {
  2397.                                                                                                                                                 if (0 < strlen($counter['banned']) && time() < $counter['banned_until']) {
  2398.                                                                                                                                                     mquery("update users set banned='', banned_until='0' where username='" . mysql_real_escape_string($m[1]) . "'");
  2399.                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " has been unbanned now.\r\n");
  2400.                                                                                                                                                 } else {
  2401.                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :This user isn´t banned.\r\n");
  2402.                                                                                                                                                 }
  2403.                                                                                                                                             } else {
  2404.                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user didn´t exist.\r\n");
  2405.                                                                                                                                             }
  2406.                                                                                                                                             foreach($admins as $useridet2) {
  2407.                                                                                                                                                 foreach($authed as $cliID2) {
  2408.                                                                                                                                                     if (@array_key_exists(@$useridet2, @$cliID2)) {
  2409.                                                                                                                                                         fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " unbanned " . $usersettings[$RS['id']]['username'] . ".\r\n");
  2410.                                                                                                                                                     }
  2411.                                                                                                                                                 }
  2412.                                                                                                                                             }
  2413.                                                                                                                                             unset($m);
  2414.                                                                                                                                             unset($useridet2);
  2415.                                                                                                                                             unset($cliID2);
  2416.                                                                                                                                             unset($counter);
  2417.                                                                                                                                         } else {
  2418.                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb unban <username>\r\n");
  2419.                                                                                                                                         }
  2420.                                                                                                                                     } else {
  2421.                                                                                                                                         if ($whattodo == "addhost" && checkadmin($uid, 2)) {
  2422.                                                                                                                                             if (preg_match("/^[Pp][Bb] [Aa][Dd][Dd][Hh][Oo][Ss][Tt] (.*) (.*)$/", $data, $m)) {
  2423.                                                                                                                                                 $counter = mysql_result(mquery("select count(*) from `v-hosts` where host='" . mysql_real_escape_string($m[2]) . "'"), 0);
  2424.                                                                                                                                                 if (0 < $counter) {
  2425.                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :That host is already added?.\r\n");
  2426.                                                                                                                                                 } else if (!is_numeric($m[1])) {
  2427.                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :The count syntax needs to be a number.\r\n");
  2428.                                                                                                                                                 } else {
  2429.                                                                                                                                                     mquery("insert into `v-hosts` (count, host) Values('" . mysql_real_escape_string($m[1]) . "', '" . mysql_real_escape_string($m[2]) . "')");
  2430.                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :V-host added.\r\n");
  2431.                                                                                                                                                     foreach($admins as $useridet2) {
  2432.                                                                                                                                                         foreach($authed as $cliID2) {
  2433.                                                                                                                                                             if (@array_key_exists(@$useridet2, @$cliID2)) {
  2434.                                                                                                                                                                 fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " added the v-host " . $m[2] . " with a limit of " . $m[1] . " user(s).\r\n");
  2435.                                                                                                                                                             }
  2436.                                                                                                                                                         }
  2437.                                                                                                                                                     }
  2438.                                                                                                                                                 }
  2439.                                                                                                                                                 unset($counter);
  2440.                                                                                                                                                 unset($m);
  2441.                                                                                                                                                 unset($useridet2);
  2442.                                                                                                                                                 unset($cliID2);
  2443.                                                                                                                                             } else {
  2444.                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb addhost <number> <hostname>\r\n");
  2445.                                                                                                                                             }
  2446.                                                                                                                                         } else {
  2447.                                                                                                                                             if ($whattodo == "delhost" && checkadmin($uid, 2)) {
  2448.                                                                                                                                                 if (preg_match("/^[Pp][Bb] [Dd][Ee][Ll][Hh][Oo][Ss][Tt] (.*)$/", $data, $m)) {
  2449.                                                                                                                                                     $counter = mysql_result(mquery("select count(*) from `v-hosts` where host='" . mysql_real_escape_string($m[1]) . "'"), 0);
  2450.                                                                                                                                                     if ($counter == 1) {
  2451.                                                                                                                                                         mquery("delete from `v-hosts` where host='" . $m[1] . "'");
  2452.                                                                                                                                                         $sql = mquery("select * from users where host='" . mysql_real_escape_string($m[1]) . "'");
  2453.                                                                                                                                                         while ($RS = mysql_fetch_array($sql)) {
  2454.                                                                                                                                                             $online = 0;
  2455.                                                                                                                                                             foreach($authed as $cliID) {
  2456.                                                                                                                                                                 $useridet = array_keys($cliID);
  2457.                                                                                                                                                                 if ($useridet[0] == $RS['id']) {
  2458.                                                                                                                                                                     fwrite($cliID[$useridet[0]], ":phpBNC NOTICE " . $usersettings[$useridet[0]]['currentnick'] . " :The v-host you were using got deleted, please pick a new one.\r\n");
  2459.                                                                                                                                                                     $online = 1;
  2460.                                                                                                                                                                     break;
  2461.                                                                                                                                                                     break;
  2462.                                                                                                                                                                 }
  2463.                                                                                                                                                             }
  2464.                                                                                                                                                             if ($online == 0) {
  2465.                                                                                                                                                                 mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("The v-host you were using got deleted, please pick a new one.") . "', UNIX_TIMESTAMP(), '" . $RS['id'] . "')");
  2466.                                                                                                                                                             }
  2467.                                                                                                                                                             $usersettings[$RS['id']]['host'] = "";
  2468.                                                                                                                                                         }
  2469.                                                                                                                                                         mquery("update users set host='' where host='" . mysql_real_escape_string($m[1]) . "'");
  2470.                                                                                                                                                         foreach($admins as $useridet2) {
  2471.                                                                                                                                                             foreach($authed as $cliID2) {
  2472.                                                                                                                                                                 if (@array_key_exists(@$useridet2, @$cliID2)) {
  2473.                                                                                                                                                                     fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " deleted the v-host " . $m[1] . ".\r\n");
  2474.                                                                                                                                                                 }
  2475.                                                                                                                                                             }
  2476.                                                                                                                                                         }
  2477.                                                                                                                                                     } else {
  2478.                                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :That host doesn´t exist.\r\n");
  2479.                                                                                                                                                     }
  2480.                                                                                                                                                     unset($m);
  2481.                                                                                                                                                     unset($online);
  2482.                                                                                                                                                     unset($useridet2);
  2483.                                                                                                                                                     unset($cliID2);
  2484.                                                                                                                                                     unset($cliID);
  2485.                                                                                                                                                     unset($useridet);
  2486.                                                                                                                                                     unset($sql);
  2487.                                                                                                                                                     unset($RS);
  2488.                                                                                                                                                     unset($counter);
  2489.                                                                                                                                                 } else {
  2490.                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb delhost <hostname>\r\n");
  2491.                                                                                                                                                 }
  2492.                                                                                                                                             } else {
  2493.                                                                                                                                                 if ($whattodo == "adduser" && checkadmin($uid, 2)) {
  2494.                                                                                                                                                     if (preg_match("/^[Pp][Bb] [Aa][Dd][Dd][Uu][Ss][Ee][Rr] (.*?) (.*)$/", $data, $m)) {
  2495.                                                                                                                                                         $counter = mysql_result(mquery("select count(*) from users where id='" . mysql_real_escape_string($m[1]) . "'"), 0);
  2496.                                                                                                                                                         if ($counter == 1) {
  2497.                                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :That username is already taken.\r\n");
  2498.                                                                                                                                                         } else if (!preg_match("/^[a-z0-9\\_\\-]+$/i", $m[1])) {
  2499.                                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :A username can only contain a-z, 0-9 _ -\r\n");
  2500.                                                                                                                                                         } else if (10 < strlen($m[1])) {
  2501.                                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :A username can only be 10 characters long.\r\n");
  2502.                                                                                                                                                         } else {
  2503.                                                                                                                                                             mquery("insert into users (username, password, network, nick, currentnick, host, realname, away_nick, net_name, banned) Values('" . mysql_real_escape_string($m[1]) . "', '" . mysql_real_escape_string(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out")) . "', '', '" . mysql_real_escape_string($m[1]) . "', '" . mysql_real_escape_string($m[1]) . "', '', '', '" . mysql_real_escape_string($m[1]) . "', '', '')");
  2504.                                                                                                                                                             $useridd = mysql_insert_id();
  2505.                                                                                                                                                             $usersettings[$useridd]['nick'] = $m[1];
  2506.                                                                                                                                                             $usersettings[$useridd]['currentnick'] = $m[1];
  2507.                                                                                                                                                             $usersettings[$useridd]['username'] = $m[1];
  2508.                                                                                                                                                             $usersettings[$useridd]['host'] = "";
  2509.                                                                                                                                                             $usersettings[$useridd]['away_nick'] = $m[1];
  2510.                                                                                                                                                             $usersettings[$useridd]['away_msg'] = "disconnected";
  2511.                                                                                                                                                             $usersettings[$useridd]['admin'] = 0;
  2512.                                                                                                                                                             $usersettings[$useridd]['net_name'] = "";
  2513.                                                                                                                                                             $usersettings[$useridd]['trailed'] = 0;
  2514.                                                                                                                                                             $usersettings[$useridd]['channellog'] = 0;
  2515.                                                                                                                                                             $usersettings[$useridd]['lastlogin'] = "";
  2516.                                                                                                                                                             $usersettings[$useridd]['lastcommand'] = time();
  2517.                                                                                                                                                             $usersettings[$useridd]['delay'] = 0;
  2518.                                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :User added.\r\n");
  2519.                                                                                                                                                             foreach($admins as $useridet2) {
  2520.                                                                                                                                                                 foreach($authed as $cliID2) {
  2521.                                                                                                                                                                     if (@array_key_exists(@$useridet2, @$cliID2)) {
  2522.                                                                                                                                                                         fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " added user " . $m[1] . ".\r\n");
  2523.                                                                                                                                                                     }
  2524.                                                                                                                                                                 }
  2525.                                                                                                                                                             }
  2526.                                                                                                                                                         }
  2527.                                                                                                                                                         unset($useridd);
  2528.                                                                                                                                                         unset($counter);
  2529.                                                                                                                                                         unset($m);
  2530.                                                                                                                                                         unset($useridet2);
  2531.                                                                                                                                                         unset($cliID2);
  2532.                                                                                                                                                     } else {
  2533.                                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb adduser <username> <password>\r\n");
  2534.                                                                                                                                                     }
  2535.                                                                                                                                                 } else {
  2536.                                                                                                                                                     if ($whattodo == "deluser" && checkadmin($uid, 2)) {
  2537.                                                                                                                                                         if (preg_match("/^PB deluser (.*)$/", $data, $m)) {
  2538.                                                                                                                                                             $online = 0;
  2539.                                                                                                                                                             $sql = mquery("select id from users where username='" . mysql_real_escape_string($m[1]) . "'");
  2540.                                                                                                                                                             if (mysql_num_rows($sql) == 1) {
  2541.                                                                                                                                                                 $usid = mysql_fetch_array($sql);
  2542.                                                                                                                                                                 foreach($authed as $cliID) {
  2543.                                                                                                                                                                     $useridet = array_keys($cliID);
  2544.                                                                                                                                                                     if ($useridet[0] == $usid['id']) {
  2545.                                                                                                                                                                         $online = 1;
  2546.                                                                                                                                                                         break;
  2547.                                                                                                                                                                         break;
  2548.                                                                                                                                                                     }
  2549.                                                                                                                                                                 }
  2550.                                                                                                                                                                 if ($online == 1) {
  2551.                                                                                                                                                                     $res = $cliID[$useridet[0]];
  2552.                                                                                                                                                                     $key = array_search($res, $clients);
  2553.                                                                                                                                                                     unset($clients[$key]);
  2554.                                                                                                                                                                     unset($authed[$key]);
  2555.                                                                                                                                                                     if (@array_key_exists(@$useridet[0], @$net_clients)) {
  2556.                                                                                                                                                                         fwrite($net_clients[$useridet[0]], "QUIT\r\n");
  2557.                                                                                                                                                                         fclose($net_clients[$useridet[0]]);
  2558.                                                                                                                                                                         unset($net_clients[$useridet[0]]);
  2559.                                                                                                                                                                     }
  2560.                                                                                                                                                                     if (in_array($useridet[0], $admins)) {
  2561.                                                                                                                                                                         $key3 = array_search($useridet[0], $admins);
  2562.                                                                                                                                                                         unset($admins[$key3]);
  2563.                                                                                                                                                                         unset($key3);
  2564.                                                                                                                                                                     }
  2565.                                                                                                                                                                     foreach($admins as $useridet2) {
  2566.                                                                                                                                                                         foreach($authed as $cliID2) {
  2567.                                                                                                                                                                             if (@array_key_exists(@$useridet2, @$cliID2)) {
  2568.                                                                                                                                                                                 fwrite($cliID2[$useridet2], ":" . $usersettings[$useridet[0]]['currentnick'] . "][" . $usersettings[$useridet[0]]['username'] . "!" . $usersettings[$useridet[0]]['username'] . "@" . $usersettings[$useridet[0]]['host'] . " PART &system\r\n");
  2569.                                                                                                                                                                                 fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " deleted " . $usersettings[$useridet[0]]['username'] . "\r\n");
  2570.                                                                                                                                                                             }
  2571.                                                                                                                                                                         }
  2572.                                                                                                                                                                     }
  2573.                                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :User has been deleted of the bouncer.\r\n");
  2574.                                                                                                                                                                     fwrite($res, ":phpBNC NOTICE " . $usersettings[$useridet[0]]['currentnick'] . " :You got deleted from the bouncer by " . $usersettings[$uid]['username'] . ".\r\n");
  2575.                                                                                                                                                                     fclose($res);
  2576.                                                                                                                                                                     echo $usersettings[$useridet[0]]['username'] . "s client disconnected.\r\n";
  2577.                                                                                                                                                                     unset($usersettings[$useridet[0]]);
  2578.                                                                                                                                                                     unset($res);
  2579.                                                                                                                                                                     unset($key);
  2580.                                                                                                                                                                     unset($useridet);
  2581.                                                                                                                                                                     unset($useridet2);
  2582.                                                                                                                                                                     unset($cliID);
  2583.                                                                                                                                                                     unset($cliID2);
  2584.                                                                                                                                                                     unset($online);
  2585.                                                                                                                                                                 } else {
  2586.                                                                                                                                                                     if (@array_key_exists(@$usid['id'], @$net_clients)) {
  2587.                                                                                                                                                                         fwrite($net_clients[$usid['id']], "QUIT\r\n");
  2588.                                                                                                                                                                         fclose($net_clients[$usid['id']]);
  2589.                                                                                                                                                                         unset($net_clients[$usid['id']]);
  2590.                                                                                                                                                                     }
  2591.                                                                                                                                                                     if (in_array($usid['id'], $admins)) {
  2592.                                                                                                                                                                         $key3 = array_search($usid['id'], $admins);
  2593.                                                                                                                                                                         unset($admins[$key3]);
  2594.                                                                                                                                                                         unset($key3);
  2595.                                                                                                                                                                     }
  2596.                                                                                                                                                                     foreach($admins as $useridet2) {
  2597.                                                                                                                                                                         foreach($authed as $cliID2) {
  2598.                                                                                                                                                                             if (@array_key_exists(@$useridet2, @$cliID2)) {
  2599.                                                                                                                                                                                 fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " deleted " . $usersettings[$usid['id']]['username'] . "\r\n");
  2600.                                                                                                                                                                             }
  2601.                                                                                                                                                                         }
  2602.                                                                                                                                                                     }
  2603.                                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :User has been deleted of the bouncer.\r\n");
  2604.                                                                                                                                                                     echo $usersettings[$usid['id']]['username'] . "s client disconnected.\r\n";
  2605.                                                                                                                                                                     unset($usersettings[$usid['id']]);
  2606.                                                                                                                                                                     unset($key);
  2607.                                                                                                                                                                     unset($useridet);
  2608.                                                                                                                                                                     unset($useridet2);
  2609.                                                                                                                                                                     unset($cliID);
  2610.                                                                                                                                                                     unset($cliID2);
  2611.                                                                                                                                                                     unset($online);
  2612.                                                                                                                                                                 }
  2613.                                                                                                                                                                 mquery("delete from users where id='" . $usid['id'] . "'");
  2614.                                                                                                                                                                 unset($usid);
  2615.                                                                                                                                                             } else {
  2616.                                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user doesn´t exist\r\n");
  2617.                                                                                                                                                             }
  2618.                                                                                                                                                         } else {
  2619.                                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb deluser <username>\r\n");
  2620.                                                                                                                                                         }
  2621.                                                                                                                                                         unset($m);
  2622.                                                                                                                                                     } else {
  2623.                                                                                                                                                         if ($whattodo == "allmsg" && checkadmin($uid, 2)) {
  2624.                                                                                                                                                             if (preg_match("/^[Pp][Bb] [Aa][Ll][Ll][Mm][Ss][Gg] (.*)$/", $data, $m)) {
  2625.                                                                                                                                                                 $sql = mquery("select id from users order by id asc");
  2626.                                                                                                                                                                 while ($RS = mysql_fetch_array($sql)) {
  2627.                                                                                                                                                                     $online = 0;
  2628.                                                                                                                                                                     foreach($authed as $cliID) {
  2629.                                                                                                                                                                         if (@array_key_exists(@$RS['id'], @$cliID)) {
  2630.                                                                                                                                                                             fwrite($cliID[$RS['id']], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$RS['id']]['currentnick'] . " :" . chr(2) . "ALLMSG" . chr(2) . ": " . $m[1] . ".\r\n");
  2631.                                                                                                                                                                             $online = 1;
  2632.                                                                                                                                                                         }
  2633.                                                                                                                                                                     }
  2634.                                                                                                                                                                     if ($online == 0) {
  2635.                                                                                                                                                                         mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string(chr(2) . "ALLMSG" . chr(2) . ": " . $m[1]) . "', UNIX_TIMESTAMP(), '" . $RS['id'] . "')");
  2636.                                                                                                                                                                     }
  2637.                                                                                                                                                                 }
  2638.                                                                                                                                                                 foreach($admins as $useridet2) {
  2639.                                                                                                                                                                     foreach($authed as $cliID2) {
  2640.                                                                                                                                                                         if (@array_key_exists(@$useridet2, @$cliID2)) {
  2641.                                                                                                                                                                             fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " sent an AMSG.\r\n");
  2642.                                                                                                                                                                         }
  2643.                                                                                                                                                                     }
  2644.                                                                                                                                                                 }
  2645.                                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :Message has been sent.\r\n");
  2646.                                                                                                                                                                 unset($m);
  2647.                                                                                                                                                                 unset($sql);
  2648.                                                                                                                                                                 unset($RS);
  2649.                                                                                                                                                                 unset($online);
  2650.                                                                                                                                                                 unset($cliID);
  2651.                                                                                                                                                                 unset($cliID2);
  2652.                                                                                                                                                                 unset($useridet2);
  2653.                                                                                                                                                             }
  2654.                                                                                                                                                         } else {
  2655.                                                                                                                                                             if ($whattodo == "trail" && checkadmin($uid, 2)) {
  2656.                                                                                                                                                                 if (preg_match("/^[Pp][Bb] [Tt][Rr][Aa][Ii][Ll] (.*)$/", $data, $m)) {
  2657.                                                                                                                                                                     $sql = mquery("select id, trailed from users where username='" . mysql_real_escape_string($m[1]) . "'");
  2658.                                                                                                                                                                     if (mysql_num_rows($sql) == 1) {
  2659.                                                                                                                                                                         $result = mysql_fetch_array($sql);
  2660.                                                                                                                                                                         if ($result['trailed'] == 1) {
  2661.                                                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user is already being trailed.\r\n");
  2662.                                                                                                                                                                         } else {
  2663.                                                                                                                                                                             mquery("update users set trailed='1' where id='" . $result['id'] . "'");
  2664.                                                                                                                                                                             $usersettings[$result['id']]['trailed'] = 1;
  2665.                                                                                                                                                                             $online = 0;
  2666.                                                                                                                                                                             foreach($authed as $cliID) {
  2667.                                                                                                                                                                                 if (@array_key_exists(@$result['id'], @$cliID)) {
  2668.                                                                                                                                                                                     fwrite($cliID[$result['id']], ":phpBNC NOTICE " . $usersettings[$result['id']]['currentnick'] . " :You are now being trailed, this mean that everything you write and receive is being logged to a textfile, " . chr(2) . "REMEBER THIS" . chr(2) . ".\r\n");
  2669.                                                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " is now being trailed.\r\n");
  2670.                                                                                                                                                                                     $online = 1;
  2671.                                                                                                                                                                                 }
  2672.                                                                                                                                                                             }
  2673.                                                                                                                                                                             if ($online == 0) {
  2674.                                                                                                                                                                                 mquery("insert into userlogs (msg, date, toid) Values('An Admin has put a trail on you, that means that everything you write and receive are logged in a textfile, " . chr(2) . "REMEMBER THIS" . chr(2) . ".', UNIX_TIMESTAMP(), '" . $result['id'] . "')");
  2675.                                                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " is now being trailed.\r\n");
  2676.                                                                                                                                                                             }
  2677.                                                                                                                                                                             foreach($admins as $useridet2) {
  2678.                                                                                                                                                                                 foreach($authed as $cliID2) {
  2679.                                                                                                                                                                                     if (@array_key_exists(@$useridet2, @$cliID2)) {
  2680.                                                                                                                                                                                         fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " decided to trail " . $m[1] . ".\r\n");
  2681.                                                                                                                                                                                     }
  2682.                                                                                                                                                                                 }
  2683.                                                                                                                                                                             }
  2684.                                                                                                                                                                         }
  2685.                                                                                                                                                                     } else {
  2686.                                                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Can´t find user.\r\n");
  2687.                                                                                                                                                                     }
  2688.                                                                                                                                                                     unset($m);
  2689.                                                                                                                                                                     unset($sql);
  2690.                                                                                                                                                                     unset($result);
  2691.                                                                                                                                                                     unset($online);
  2692.                                                                                                                                                                     unset($cliID2);
  2693.                                                                                                                                                                     unset($useridet2);
  2694.                                                                                                                                                                 } else {
  2695.                                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb trail <username>\r\n");
  2696.                                                                                                                                                                 }
  2697.                                                                                                                                                             } else {
  2698.                                                                                                                                                                 if ($whattodo == "untrail" && checkadmin($uid, 2)) {
  2699.                                                                                                                                                                     if (preg_match("/^[Pp][Bb] [Uu][Nn][Tt][Rr][Aa][Ii][Ll] (.*)$/", $data, $m)) {
  2700.                                                                                                                                                                         $sql = mquery("select id, trailed from users where username='" . mysql_real_escape_string($m[1]) . "'");
  2701.                                                                                                                                                                         if (mysql_num_rows($sql) == 1) {
  2702.                                                                                                                                                                             $result = mysql_fetch_array($sql);
  2703.                                                                                                                                                                             if ($result['trailed'] == 0) {
  2704.                                                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :This user isn´t being trailed stupid!!!.\r\n");
  2705.                                                                                                                                                                             } else {
  2706.                                                                                                                                                                                 mquery("update users set trailed='0' where id='" . $result['id'] . "'");
  2707.                                                                                                                                                                                 $usersettings[$result['id']]['trailed'] = 0;
  2708.                                                                                                                                                                                 $online = 0;
  2709.                                                                                                                                                                                 foreach($authed as $cliID) {
  2710.                                                                                                                                                                                     if (@array_key_exists(@$result['id'], @$cliID)) {
  2711.                                                                                                                                                                                         fwrite($cliID[$result['id']], ":phpBNC NOTICE " . $usersettings[$result['id']]['currentnick'] . " :You are " . chr(2) . "NOT" . chr(2) . " being trailed anymore.\r\n");
  2712.                                                                                                                                                                                         $online = 1;
  2713.                                                                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " is not being trailed anymore.\r\n");
  2714.                                                                                                                                                                                     }
  2715.                                                                                                                                                                                 }
  2716.                                                                                                                                                                                 if ($online == 0) {
  2717.                                                                                                                                                                                     mquery("insert into userlogs (msg, date, toid) Values('You are " . chr(2) . "NOT" . chr(2) . " being trailed anymore.', UNIX_TIMESTAMP(), '" . $result['id'] . "')");
  2718.                                                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " is not being trailed anymore.\r\n");
  2719.                                                                                                                                                                                 }
  2720.                                                                                                                                                                                 foreach($admins as $useridet2) {
  2721.                                                                                                                                                                                     foreach($authed as $cliID2) {
  2722.                                                                                                                                                                                         if (@array_key_exists(@$useridet2, @$cliID2)) {
  2723.                                                                                                                                                                                             fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " untrailed " . $m[1] . ".\r\n");
  2724.                                                                                                                                                                                         }
  2725.                                                                                                                                                                                     }
  2726.                                                                                                                                                                                 }
  2727.                                                                                                                                                                             }
  2728.                                                                                                                                                                         } else {
  2729.                                                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Can´t find user.\r\n");
  2730.                                                                                                                                                                         }
  2731.                                                                                                                                                                         unset($m);
  2732.                                                                                                                                                                         unset($sql);
  2733.                                                                                                                                                                         unset($result);
  2734.                                                                                                                                                                         unset($online);
  2735.                                                                                                                                                                         unset($cliID2);
  2736.                                                                                                                                                                         unset($useridet2);
  2737.                                                                                                                                                                     } else {
  2738.                                                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb untrail <username>\r\n");
  2739.                                                                                                                                                                     }
  2740.                                                                                                                                                                 } else {
  2741.                                                                                                                                                                     if ($whattodo == "admin" && checkadmin($uid, 2)) {
  2742.                                                                                                                                                                         if (preg_match("/^[Pp][Bb] [Aa][Dd][Mm][Ii][Nn] (.*) (.*)$/", $data, $m)) {
  2743.                                                                                                                                                                             if (is_numeric($m[2])) {
  2744.                                                                                                                                                                                 $sql = mquery("select id, admin from users where username='" . mysql_real_escape_string($m[1]) . "'");
  2745.                                                                                                                                                                                 if (mysql_num_rows($sql) == 1) {
  2746.                                                                                                                                                                                     $result = mysql_fetch_array($sql);
  2747.                                                                                                                                                                                     if ($result['admin'] == 0 && $m[2] == 0) {
  2748.                                                                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $usersettings[$result['id']]['username'] . " already is a normal user.\r\n");
  2749.                                                                                                                                                                                     } else {
  2750.                                                                                                                                                                                         if ($result['admin'] == 1 && $m[2] == 1) {
  2751.                                                                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $usersettings[$result['id']]['username'] . " already is a normal-admin.\r\n");
  2752.                                                                                                                                                                                         } else {
  2753.                                                                                                                                                                                             if ($result['admin'] == 2 && $m[2] == 2) {
  2754.                                                                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $usersettings[$result['id']]['username'] . " already is a super-admin.\r\n");
  2755.                                                                                                                                                                                             } else {
  2756.                                                                                                                                                                                                 foreach($admins as $useridet2) {
  2757.                                                                                                                                                                                                     foreach($authed as $cliID2) {
  2758.                                                                                                                                                                                                         if (@array_key_exists(@$useridet2, @$cliID2)) {
  2759.                                                                                                                                                                                                             fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " changed adminlevel on " . $usersettings[$result['id']]['username'] . " from " . $usersettings[$result['id']]['admin'] . " to " . $m[2] . ".\r\n");
  2760.                                                                                                                                                                                                         }
  2761.                                                                                                                                                                                                     }
  2762.                                                                                                                                                                                                 }
  2763.                                                                                                                                                                                                 $online = 0;
  2764.                                                                                                                                                                                                 foreach($authed as $cliID) {
  2765.                                                                                                                                                                                                     if (@array_key_exists(@$result['id'], @$cliID)) {
  2766.                                                                                                                                                                                                         fwrite($cliID[$result['id']], ":phpBNC NOTICE " . $usersettings[$result['id']]['currentnick'] . " :Your adminlevel has been changed to " . mysql_real_escape_string($m[2]) . ".\r\n");
  2767.                                                                                                                                                                                                         $online = 1;
  2768.                                                                                                                                                                                                         $hissocket = $cliID[$result['id']];
  2769.                                                                                                                                                                                                         fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . "s adminlevel has now been changed.\r\n");
  2770.                                                                                                                                                                                                     }
  2771.                                                                                                                                                                                                 }
  2772.                                                                                                                                                                                                 if ($m[2] == 0 && 0 < $usersettings[$result['id']]['admin']) {
  2773.                                                                                                                                                                                                     unset($admins[array_search($result['id'], $admins) ]);
  2774.                                                                                                                                                                                                     if ($online == 1) {
  2775.                                                                                                                                                                                                         fwrite($hissocket, ":" . $usersettings[$result['id']]['currentnick'] . "!" . $usersettings[$result['id']]['username'] . "@" . $usersettings[$result['id']]['host'] . " PART &system\r\n");
  2776.                                                                                                                                                                                                     }
  2777.                                                                                                                                                                                                     $foere = "";
  2778.                                                                                                                                                                                                     if ($usersettings[$result['id']]['admin'] == 1) {
  2779.                                                                                                                                                                                                         $foere = "-v";
  2780.                                                                                                                                                                                                     } else if ($usersettings[$result['id']]['admin'] == 2) {
  2781.                                                                                                                                                                                                         $foere = "-o";
  2782.                                                                                                                                                                                                     }
  2783.                                                                                                                                                                                                     foreach($admins as $useridet) {
  2784.                                                                                                                                                                                                         if ($useridet != $result['id']) {
  2785.                                                                                                                                                                                                             foreach($authed as $cliID) {
  2786.                                                                                                                                                                                                                 if (@!array_key_exists(@$useridet, @$cliID) || !($foere != "")) {
  2787.                                                                                                                                                                                                                     fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
  2788.                                                                                                                                                                                                                 }
  2789.                                                                                                                                                                                                             }
  2790.                                                                                                                                                                                                         }
  2791.                                                                                                                                                                                                     }
  2792.                                                                                                                                                                                                 } else if (0 < $m[2] && $usersettings[$result['id']]['admin'] == 0) {
  2793.                                                                                                                                                                                                     if ($online == 1) {
  2794.                                                                                                                                                                                                         fwrite($hissocket, ":" . $usersettings[$result['id']]['currentnick'] . "!" . $usersettings[$result['id']]['username'] . "@" . $usersettings[$result['id']]['host'] . " JOIN &system\r\n");
  2795.                                                                                                                                                                                                         fwrite($hissocket, ":phpBNC 332 " . $usersettings[$result['id']]['currentnick'] . " &system :System channel for phpBNC v." . version . "\r\n");
  2796.                                                                                                                                                                                                         fwrite($hissocket, ":phpBNC 333 " . $usersettings[$result['id']]['currentnick'] . " &system phpBNC " . starttime . "\r\n");
  2797.                                                                                                                                                                                                         $alltheusers = ":phpBNC 353 " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . " = &system :@phpBNC ";
  2798.                                                                                                                                                                                                         foreach($authed as $cliID) {
  2799.                                                                                                                                                                                                             $user = array_keys($cliID);
  2800.                                                                                                                                                                                                             $user = $user[0];
  2801.                                                                                                                                                                                                             $fore = "";
  2802.                                                                                                                                                                                                             if ($user != $result['id']) {
  2803.                                                                                                                                                                                                                 if ($usersettings[$user]['admin'] == 1) {
  2804.                                                                                                                                                                                                                     $fore = "+";
  2805.                                                                                                                                                                                                                 } else if ($usersettings[$user]['admin'] == 2) {
  2806.                                                                                                                                                                                                                     $fore = "@";
  2807.                                                                                                                                                                                                                 }
  2808.                                                                                                                                                                                                             }
  2809.                                                                                                                                                                                                             $alltheusers.= "{$fore}" . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'] . " ";
  2810.                                                                                                                                                                                                         }
  2811.                                                                                                                                                                                                         fwrite($hissocket, $alltheusers . "\r\n");
  2812.                                                                                                                                                                                                         fwrite($hissocket, ":phpBNC 366 " . $usersettings[$result['id']]['currentnick'] . " &system :End of /NAMES list.\r\n");
  2813.                                                                                                                                                                                                         $foere = "";
  2814.                                                                                                                                                                                                         if ($m[2] == 1) {
  2815.                                                                                                                                                                                                             $foere = "+v";
  2816.                                                                                                                                                                                                         } else if ($m[2] == 2) {
  2817.                                                                                                                                                                                                             $foere = "+o";
  2818.                                                                                                                                                                                                         }
  2819.                                                                                                                                                                                                         fwrite($hissocket, ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
  2820.                                                                                                                                                                                                         foreach($admins as $useridet) {
  2821.                                                                                                                                                                                                             if ($useridet != $result['id']) {
  2822.                                                                                                                                                                                                                 foreach($authed as $cliID) {
  2823.                                                                                                                                                                                                                     if (@!array_key_exists(@$useridet, @$cliID) || !($foere != "")) {
  2824.                                                                                                                                                                                                                         fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
  2825.                                                                                                                                                                                                                     }
  2826.                                                                                                                                                                                                                 }
  2827.                                                                                                                                                                                                             }
  2828.                                                                                                                                                                                                         }
  2829.                                                                                                                                                                                                     }
  2830.                                                                                                                                                                                                     $admins[] = $result['id'];
  2831.                                                                                                                                                                                                 } else if (0 < $m[2] && 0 < $usersettings[$result['id']]['admin']) {
  2832.                                                                                                                                                                                                     $oldfoere = "";
  2833.                                                                                                                                                                                                     if ($usersettings[$result['id']]['admin'] == 1) {
  2834.                                                                                                                                                                                                         $oldfoere = "-v";
  2835.                                                                                                                                                                                                     } else if ($usersettings[$result['id']]['admin'] == 2) {
  2836.                                                                                                                                                                                                         $oldfoere = "-o";
  2837.                                                                                                                                                                                                     }
  2838.                                                                                                                                                                                                     $foere = "";
  2839.                                                                                                                                                                                                     if ($m[2] == 1) {
  2840.                                                                                                                                                                                                         $foere = "+v";
  2841.                                                                                                                                                                                                     } else if ($m[2] == 2) {
  2842.                                                                                                                                                                                                         $foere = "+o";
  2843.                                                                                                                                                                                                     }
  2844.                                                                                                                                                                                                     if ($online == 1) {
  2845.                                                                                                                                                                                                         fwrite($hissocket, ":phpBNC!phpBNC@phpBNC MODE &system " . $oldfoere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
  2846.                                                                                                                                                                                                         fwrite($hissocket, ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
  2847.                                                                                                                                                                                                     }
  2848.                                                                                                                                                                                                     foreach($admins as $useridet) {
  2849.                                                                                                                                                                                                         if ($useridet != $result['id']) {
  2850.                                                                                                                                                                                                             foreach($authed as $cliID) {
  2851.                                                                                                                                                                                                                 if (@!array_key_exists(@$useridet, @$cliID) || !($foere != "")) {
  2852.                                                                                                                                                                                                                     fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $oldfoere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
  2853.                                                                                                                                                                                                                     fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
  2854.                                                                                                                                                                                                                 }
  2855.                                                                                                                                                                                                             }
  2856.                                                                                                                                                                                                         }
  2857.                                                                                                                                                                                                     }
  2858.                                                                                                                                                                                                 }
  2859.                                                                                                                                                                                                 if ($online == 0) {
  2860.                                                                                                                                                                                                     mquery("insert into userlogs (msg, date, toid) Values('Your adminlevel has been changed to " . mysql_real_escape_string($m[2]) . ".', UNIX_TIMESTAMP(), '" . $result['id'] . "')");
  2861.                                                                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . "s adminlevel has now been changed.\r\n");
  2862.                                                                                                                                                                                                 }
  2863.                                                                                                                                                                                                 mquery("update users set admin='" . mysql_real_escape_string($m[2]) . "' where id='" . $result['id'] . "'");
  2864.                                                                                                                                                                                                 $usersettings[$result['id']]['admin'] = $m[2];
  2865.                                                                                                                                                                                             }
  2866.                                                                                                                                                                                         }
  2867.                                                                                                                                                                                     }
  2868.                                                                                                                                                                                 } else {
  2869.                                                                                                                                                                                     fwrite($read_sock, ":phpBNC NOTICE {$nick} :Can´t find user.\r\n");
  2870.                                                                                                                                                                                 }
  2871.                                                                                                                                                                             } else {
  2872.                                                                                                                                                                                 fwrite($read_sock, ":phpBNC NOTICE {$nick} :You can only choose between 0, 1 and 2.\r\n");
  2873.                                                                                                                                                                             }
  2874.                                                                                                                                                                             unset($m);
  2875.                                                                                                                                                                             unset($online);
  2876.                                                                                                                                                                             unset($sql);
  2877.                                                                                                                                                                             unset($foere);
  2878.                                                                                                                                                                             unset($oldfoere);
  2879.                                                                                                                                                                             unset($result);
  2880.                                                                                                                                                                             unset($cliID2);
  2881.                                                                                                                                                                             unset($useridet2);
  2882.                                                                                                                                                                             unset($hissocket);
  2883.                                                                                                                                                                         } else {
  2884.                                                                                                                                                                             fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb admin <username> <newlevel>\r\n");
  2885.                                                                                                                                                                         }
  2886.                                                                                                                                                                     }
  2887.                                                                                                                                                                 }
  2888.                                                                                                                                                             }
  2889.                                                                                                                                                         }
  2890.                                                                                                                                                     }
  2891.                                                                                                                                                 }
  2892.                                                                                                                                             }
  2893.                                                                                                                                         }
  2894.                                                                                                                                     }
  2895.                                                                                                                                 }
  2896.                                                                                                                             }
  2897.                                                                                                                         }
  2898.                                                                                                                     }
  2899.                                                                                                                 }
  2900.                                                                                                             }
  2901.                                                                                                         }
  2902.                                                                                                     }
  2903.                                                                                                 }
  2904.                                                                                             }
  2905.                                                                                         }
  2906.                                                                                     }
  2907.                                                                                 }
  2908.                                                                             }
  2909.                                                                         }
  2910.                                                                     }
  2911.                                                                 }
  2912.                                                             }
  2913.                                                         }
  2914.                                                     }
  2915.                                                 }
  2916.                                             }
  2917.                                         }
  2918.                                     }
  2919.                                 }
  2920.                             }
  2921.                         }
  2922.                     }
  2923.                 }
  2924.             } else if (@in_array(@$read_sock, @$net_clients)) {
  2925.                 $netID = array_search($read_sock, $net_clients);
  2926.                 fclose($net_clients[$netID]);
  2927.                 unset($net_clients[$netID]);
  2928.                 unset($userconmem[$netID]);
  2929.                 mquery("update users set net_name='' where id='" . mysql_real_escape_string($netID) . "'");
  2930.                 $online = 0;
  2931.                 foreach($authed as $cliID) {
  2932.                     if (@array_key_exists(@$netID, @$cliID)) {
  2933.                         fwrite($cliID[$netID], ":phpBNC NOTICE " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
  2934.                         fwrite($cliID[$netID], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
  2935.                         $sql = mquery("select * from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
  2936.                         while ($RS = mysql_fetch_array($sql)) {
  2937.                             fwrite($cliID[$netID], ":" . $usersettings[$netID]['currentnick'] . "!" . $usersettings[$netID]['username'] . "@" . $usersettings[$netID]['host'] . " PART " . $RS['channel'] . "\r\n");
  2938.                         }
  2939.                         $online = 1;
  2940.                         break;
  2941.                         break;
  2942.                     }
  2943.                 }
  2944.                 if ($online == 0) {
  2945.                     mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("You got disconnected from the network you were connected to.") . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($netID) . "')");
  2946.                 }
  2947.                 mquery("delete from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
  2948.                 echo $usersettings[$netID]['username'] . " got disconnected from irc-network\r\n";
  2949.                 unset($sql);
  2950.                 unset($RS);
  2951.                 unset($online);
  2952.                 unset($netID);
  2953.                 unset($cliID);
  2954.             } else if (in_array(@$read_sock, @$identd) && enableident == true) {
  2955.                 $netID = array_search($read_sock, $identd);
  2956.                 fclose($identd[$netID]);
  2957.                 unset($identd[$netID]);
  2958.                 echo "identd connection got disconnected\r\n";
  2959.                 unset($netID);
  2960.             } else if (@in_array(@$read_sock, @$clients)) {
  2961.                 $cliID = array_search($read_sock, $clients);
  2962.                 $key = $cliID;
  2963.                 $uid = @array_search(@$read_sock, @$authed[$cliID]);
  2964.                 if ($uid != false) {
  2965.                     fclose($clients[$key]);
  2966.                     unset($clients[$key]);
  2967.                     unset($authed[$key]);
  2968.                     if (@array_key_exists(@$uid, @$net_clients)) {
  2969.                         fwrite($net_clients[$uid], "NICK :" . $usersettings[$uid]['away_nick'] . "\r\n");
  2970.                         if ($usersettings[$uid]['channellog'] == 0) {
  2971.                             fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['away_nick'] . " +d\r\n");
  2972.                         }
  2973.                         if ($usersettings[$uid]['away_msg'] != "") {
  2974.                             fwrite($net_clients[$uid], "AWAY :" . $usersettings[$uid]['away_msg'] . "\r\n");
  2975.                         }
  2976.                     }
  2977.                     if (in_array($uid, $admins)) {
  2978.                         $key3 = array_search($uid, $admins);
  2979.                         unset($admins[$key3]);
  2980.                         unset($key3);
  2981.                     }
  2982.                     foreach($admins as $useridet) {
  2983.                         foreach($authed as $cliID) {
  2984.                             if (@array_key_exists(@$useridet, @$cliID)) {
  2985.                                 fwrite($cliID[$useridet], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " PART &system\r\n");
  2986.                             }
  2987.                         }
  2988.                     }
  2989.                     echo $usersettings[$uid]['username'] . "s client disconnected.\r\n";
  2990.                     unset($key);
  2991.                     unset($uid);
  2992.                     unset($cliID);
  2993.                 } else {
  2994.                     $ip = explode(":", stream_socket_get_name($read_sock, true));
  2995.                     $ip = $ip[0];
  2996.                     $hosten = gethostbyaddr($ip);
  2997.                     foreach($admins as $useridet) {
  2998.                         foreach($authed as $cliID) {
  2999.                             if (@array_key_exists(@$useridet, @$cliID)) {
  3000.                                 fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :Someone connected and disconnected from " . $hosten . "(" . $ip . ")\r\n");
  3001.                             }
  3002.                         }
  3003.                     }
  3004.                     echo "Client disconnected without logging in: " . $ip . "\r\n";
  3005.                     fclose($clients[$key]);
  3006.                     unset($clients[$key]);
  3007.                     unset($ip);
  3008.                     unset($hosten);
  3009.                 }
  3010.             }
  3011.             unset($nfo);
  3012.         }
  3013.     }
  3014.     $discCli = array_keys($clients, "");
  3015.     $discNet = array_keys($net_clients, "");
  3016.     if (enableident) {
  3017.         $discIdent = array_keys($identd, "");
  3018.         if (0 < count($discIdent)) {
  3019.             foreach($discIdent as $netID) {
  3020.                 fclose($identd[$netID]);
  3021.                 unset($identd[$netID]);
  3022.             }
  3023.             echo "identd request got disconnected\r\n";
  3024.         }
  3025.     }
  3026.     if (0 < count($discNet)) {
  3027.         foreach($discNet as $netID) {
  3028.             fclose($net_clients[$netID]);
  3029.             unset($net_clients[$netID]);
  3030.             unset($userconmem[$netID]);
  3031.             mquery("delete from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
  3032.             mquery("update users set net_name='' where id='" . mysql_real_escape_string($netID) . "'");
  3033.             unset($userconmem[$netID]);
  3034.             $online = 0;
  3035.             foreach($authed as $cliID) {
  3036.                 if (@array_key_exists(@$netID, @$cliID)) {
  3037.                     fwrite($cliID[$netID], ":phpBNC NOTICE " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
  3038.                     fwrite($cliID[$netID], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
  3039.                     $online = 1;
  3040.                 }
  3041.             }
  3042.             if ($online == 0) {
  3043.                 mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("You got disconnected from the network you were connected to.") . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($netID) . "')");
  3044.             }
  3045.         }
  3046.         echo "got disconnected from network\r\n";
  3047.     }
  3048.     if (0 < count($discCli)) {
  3049.         foreach($discCli as $cliID) {
  3050.             $key = $cliID;
  3051.             $uid = @array_search(@$read_sock, @$authed[$cliID]);
  3052.             fclose($clients[$key]);
  3053.             unset($clients[$key]);
  3054.             unset($authed[$key]);
  3055.             if (@array_key_exists(@$uid, @$net_clients)) {
  3056.                 fwrite($net_clients[$uid], "NICK :" . $usersettings[$uid]['away_nick'] . "\r\n");
  3057.                 if ($usersettings[$uid]['channellog'] == 0) {
  3058.                     fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['away_nick'] . " +d\r\n");
  3059.                 }
  3060.                 if ($usersettings[$uid]['away_msg'] != "") {
  3061.                     fwrite($net_clients[$uid], "AWAY :" . $usersettings[$uid]['away_msg'] . "\r\n");
  3062.                 }
  3063.             }
  3064.             if (in_array($uid, $admins)) {
  3065.                 $key3 = array_search($uid, $admins);
  3066.                 unset($admins[$key3]);
  3067.                 foreach($admins as $useridet) {
  3068.                     foreach($authed as $cliID) {
  3069.                         if (@array_key_exists(@$useridet, @$cliID)) {
  3070.                             fwrite($cliID[$useridet], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings['host'] . " PART &system\r\n");
  3071.                         }
  3072.                     }
  3073.                 }
  3074.             }
  3075.             echo "client disconnected.\r\n";
  3076.         }
  3077.         unset($key);
  3078.         unset($uid);
  3079.         unset($key3);
  3080.     }
  3081.     unset($online);
  3082.     unset($discNet);
  3083.     unset($discCli);
  3084.     unset($discIdent);
  3085.     foreach($net_clients as $ircnet) {
  3086.         $nfonet = stream_get_meta_data($ircnet);
  3087.         if ($nfonet['eof'] == true || $nfonet['timed_out'] == true) {
  3088.             $netID = array_search($ircnet, $net_clients);
  3089.             fclose($net_clients[$netID]);
  3090.             unset($net_clients[$netID]);
  3091.             unset($userconmem[$netID]);
  3092.             mquery("update users set net_name='' where id='" . mysql_real_escape_string($netID) . "'");
  3093.             $online = 0;
  3094.             foreach($authed as $cliID) {
  3095.                 if (@array_key_exists(@$netID, @$cliID)) {
  3096.                     fwrite($cliID[$netID], ":phpBNC NOTICE " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
  3097.                     fwrite($cliID[$netID], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
  3098.                     $sql = mquery("select * from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
  3099.                     while ($RS = mysql_fetch_array($sql)) {
  3100.                         fwrite($cliID[$netID], ":" . $usersettings[$netID]['currentnick'] . "!" . $usersettings[$netID]['username'] . "@" . $usersettings[$netID]['host'] . " PART " . $RS['channel'] . "\r\n");
  3101.                     }
  3102.                     $online = 1;
  3103.                     break;
  3104.                     break;
  3105.                 }
  3106.             }
  3107.             if ($online == 0) {
  3108.                 mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("You got disconnected from the network you were connected to.") . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($netID) . "')");
  3109.             }
  3110.             mquery("delete from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
  3111.             echo $usersettings[$netID]['username'] . " got disconnected from irc-network\r\n";
  3112.             unset($sql);
  3113.             unset($RS);
  3114.             unset($online);
  3115.             unset($netID);
  3116.             unset($cliID);
  3117.         }
  3118.         unset($nfonet);
  3119.     }
  3120.     unset($ircnet);
  3121.     foreach($clients as $usernet) {
  3122.         $nfonet = stream_get_meta_data($usernet);
  3123.         if ($nfonet['eof'] == true || $nfonet['timed_out'] == true) {
  3124.             $cliID = array_search($usernet, $clients);
  3125.             $key = $cliID;
  3126.             $uid = @array_search(@$usernet, @$authed[$cliID]);
  3127.             if ($uid != false) {
  3128.                 fclose($clients[$key]);
  3129.                 unset($clients[$key]);
  3130.                 unset($authed[$key]);
  3131.                 if (@array_key_exists(@$uid, @$net_clients)) {
  3132.                     fwrite($net_clients[$uid], "NICK :" . $usersettings[$uid]['away_nick'] . "\r\n");
  3133.                     if ($usersettings[$uid]['channellog'] == 0) {
  3134.                         fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['away_nick'] . " +d\r\n");
  3135.                     }
  3136.                     if ($usersettings[$uid]['away_msg'] != "") {
  3137.                         fwrite($net_clients[$uid], "AWAY :" . $usersettings[$uid]['away_msg'] . "\r\n");
  3138.                     }
  3139.                 }
  3140.                 if (in_array($uid, $admins)) {
  3141.                     $key3 = array_search($uid, $admins);
  3142.                     unset($admins[$key3]);
  3143.                     unset($key3);
  3144.                 }
  3145.                 foreach($admins as $useridet) {
  3146.                     foreach($authed as $cliID) {
  3147.                         if (@array_key_exists(@$useridet, @$cliID)) {
  3148.                             fwrite($cliID[$useridet], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " PART &system\r\n");
  3149.                         }
  3150.                     }
  3151.                 }
  3152.                 echo $usersettings[$uid]['username'] . "s client disconnected.\r\n";
  3153.                 unset($key);
  3154.                 unset($uid);
  3155.                 unset($cliID);
  3156.             } else {
  3157.                 $ip = explode(":", stream_socket_get_name($read_sock, true));
  3158.                 $ip = $ip[0];
  3159.                 $hosten = gethostbyaddr($ip);
  3160.                 foreach($admins as $useridet) {
  3161.                     foreach($authed as $cliID) {
  3162.                         if (@array_key_exists(@$useridet, @$cliID)) {
  3163.                             fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :Someone connected and disconnected from " . $hosten . "(" . $ip . ")\r\n");
  3164.                         }
  3165.                     }
  3166.                 }
  3167.                 echo "Client disconnected without logging in: " . $ip . "\r\n";
  3168.                 fclose($clients[$key]);
  3169.                 unset($clients[$key]);
  3170.                 unset($ip);
  3171.                 unset($hosten);
  3172.             }
  3173.         }
  3174.         unset($nfonet);
  3175.     }
  3176.     unset($usernet);
  3177.     if (120 < time() - $lastpingrequest) {
  3178.         foreach($clients as $usernet) {
  3179.             fwrite($usernet, "PING :" . time() . "\r\n");
  3180.         }
  3181.         unset($usernet);
  3182.         foreach($net_clients as $ircnets) {
  3183.             fwrite($ircnets, "PING :" . time() . "\r\n");
  3184.         }
  3185.         unset($ircnets);
  3186.         $lastpingrequest = time();
  3187.     }
  3188.     foreach($usersettings as $usid => $val) {
  3189.         if (@(120 <= time() - $usersettings[$usid]['lastcontry'] && !array_key_exists(@$usid, @$net_clients))) {
  3190.             $userinfo = mysql_fetch_array(mquery("select username, nick, host, port, `ssl`, network, realname from users where id='{$usid}'"));
  3191.             $nick = $userinfo['nick'];
  3192.             $online = 0;
  3193.             foreach($authed as $cliID) {
  3194.                 $useridet = array_keys($cliID);
  3195.                 if ($useridet[0] == $usid) {
  3196.                     $online = 1;
  3197.                     $onlinesocket = $cliID[$useridet[0]];
  3198.                     break;
  3199.                     break;
  3200.                 }
  3201.             }
  3202.             if (strlen($userinfo['host']) != 0 && strlen($userinfo['realname']) != 0 && strlen($userinfo['network']) != 0) {
  3203.                 if ($online == 1) {
  3204.                     fwrite($onlinesocket, ":phpBNC NOTICE {$nick} :Trying to connect you to " . $userinfo['network'] . "..\r\n");
  3205.                 }
  3206.                 $tempcontext = stream_context_create();
  3207.                 stream_context_set_option($tempcontext, "socket", "bindto", gethostbyname($userinfo['host']) . ":0");
  3208.                 if ($userinfo['ssl'] == 1) {
  3209.                     $ssladd = "ssl://";
  3210.                 } else {
  3211.                     $ssladd = "tcp://";
  3212.                 }
  3213.                 $netsocket = stream_socket_client($ssladd . $userinfo['network'] . ":" . $userinfo['port'], $errno, $errstr, 2, STREAM_CLIENT_CONNECT, $tempcontext);
  3214.                 if (!$netsocket) {
  3215.                     if ($online == 1) {
  3216.                         fwrite($onlinesocket, ":phpBNC NOTICE {$nick} :A error occured, could not connect to " . $userinfo['network'] . ", error: " . $errstr . ".\r\n");
  3217.                     } else {
  3218.                         mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("A error occured, could not connect to " . $userinfo['network'] . ", error: " . $errstr . ".") . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($usid) . "')");
  3219.                     }
  3220.                 } else {
  3221.                     stream_set_timeout($netsocket, 1200);
  3222.                     stream_set_blocking($netsocket, 0);
  3223.                     $net_clients = array($usid => $netsocket) + $net_clients;
  3224.                     if (enableident) {
  3225.                         $tempp = explode(":", stream_socket_get_name($netsocket, false));
  3226.                         $ident_ports[$usid] = $tempp[1];
  3227.                         unset($tempp);
  3228.                     }
  3229.                     fwrite($netsocket, "NICK " . $userinfo['nick'] . "\r\n");
  3230.                     fwrite($netsocket, "USER " . $userinfo['username'] . " \"" . $userinfo['nick'] . "\" \"" . $userinfo['host'] . "\" :" . $userinfo['realname'] . "\r\n");
  3231.                 }
  3232.                 if (0 < $usersettings[$usid]['admin'] && $online == 1) {
  3233.                     $alltheusers = ":phpBNC 353 " . $usersettings[$usid]['currentnick'] . "][" . $usersettings[$usid]['username'] . " = &system :@phpBNC ";
  3234.                     $ucounter = 0;
  3235.                     foreach($authed as $cliID) {
  3236.                         if (40 <= $ucounter) {
  3237.                             fwrite($onlinesocket, $alltheusers . "\r\n");
  3238.                             $alltheusers = ":phpBNC 353 " . $usersettings[$usid]['currentnick'] . "][" . $usersettings[$usid]['username'] . " = &system :";
  3239.                             $ucounter = 0;
  3240.                         }
  3241.                         $user = array_keys($cliID);
  3242.                         $user = $user[0];
  3243.                         $fore = "";
  3244.                         if ($usersettings[$user]['admin'] == 1) {
  3245.                             $fore = "+";
  3246.                         } else if ($usersettings[$user]['admin'] == 2) {
  3247.                             $fore = "@";
  3248.                         }
  3249.                         if ($ucounter == 0) {
  3250.                             $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  3251.                         } else {
  3252.                             $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
  3253.                         }
  3254.                         ++$ucounter;
  3255.                     }
  3256.                     fwrite($onlinesocket, $alltheusers . "\r\n");
  3257.                     fwrite($onlinesocket, ":phpBNC 366 " . $usersettings[$usid]['currentnick'] . " &system :End of /NAMES list.\r\n");
  3258.                     unset($ucounter);
  3259.                 }
  3260.             }
  3261.             $usersettings[$usid]['lastcontry'] = time();
  3262.             unset($onlinesocket);
  3263.             unset($online);
  3264.             unset($usid);
  3265.         }
  3266.     }
  3267. }
  3268. foreach($sockets as $socket) {
  3269.     fclose($socket);
  3270. }
  3271. fclose($identd);
  3272. mysql_close($connecta);
  3273. ?>
  3274.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement