<?php
/*My XAT BOT*/
$xatuser = "Chat(bot)"; //Damnit
$uid = "241861280";
$picurl = "http://i185.photobucket.com/albums/x49/dotred/b.png";
$homeurl = "http://www.xatstuff.com";
$roomid = "17460274";
$smilies = array(":)", ":D", ":P", ";)", "(d)", "(x)");
$commands_enabled = true;
$owners = array("177412559", "16393", "121040483", "6804916");
$port = 10025;
$addr = "174.36.242.34";
$i = 0; //DONT CHANGE PLZ
// Output basic HTML header
// Create a socket object
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0)
{
trace("Socket errror: " . socket_strerror($socket));
die();
}
else
trace("Socket object created");
// Establish connection
$result = socket_connect($socket, $addr, $port);
// Check connection
if ($result < 0)
{
trace ("Received: " . socket_strerror($result));
}
else
{
trace("Connection successfull");
$handShake = "<y m=\"1\" />" . chr(0);
//$handShake = "<y r=\"" . $roomid . "\" />" . chr(0);
//$handShake = "<policy-file-request/>" . chr(0);
trace("Sending: " . $handShake);
socket_write($socket, $handShake, strlen($handShake));
// Wait for server response
while(true)
{
$err = false;
$out = socket_read($socket, 1024) or $err = true;
if($err == true){
trace("Socket closed");
exec("C:\\www\\xatbot.bat");
exit();
}
if($out){
trace("Received: " . $out);
if(stripos($out, "<cross-domain") > -1){
trace("Connected to Xat. Sending chat connection");
$send = "<y m=\"1\">" . chr(0);
} else if (stripos($out, "<y") > -1 ) {
$yi = stribet($out, '<y i="', '" c=');
//$yc = stribet($out, 'c="', '"');
//$send = "<j2 l4=\"1623\" l3=\"1479\" l2=\"0\" q=\"1\" y=\"" . $yi . '" k="1743250365" k3="0" z="11" p="0" c="' . $roomid . '" f="2" u="2" d0="0" n="' . $xatuser . '" a="' . $picurl . '" h="' . $homeurl . '" v="0" />' . chr(0);
$send = "<j2 l4=\"1637\" l3=\"1482\" l2=\"0\" y=\"" . $yi . "\" k=\"3787785620\" k3=\"0\" z=\"11\" p=\"0\" c=\"" . $roomid . "\" f=\"0\" u=\"" . $uid . "\" d0=\"0\" n=\"" . $xatuser . "\" a=\"" . $picurl . "\" h=\"" . $homeurl . "\" v=\"1\" />" . chr(0);
trace("Sending: " . $send);
socket_write($socket, $send, strlen($send));
} else if(stripos($out, "<done />") > -1){
trace("Connected to chat successfully!");
$done = true;
} else if(stripos($out, "<u") > -1 && $done == true){
$nB = true;
$isBanned = 0;
$isGagged = 0;
$isForever = 0;
$ui = stribet($out, "u=\"", "\"");
$uj = strbet($out, "n=\"", "\"");
$ur = strbet($out, "f=\"", "\"");
$uq = strbet($out, "q=\"", "\"");
$online = (xInt($uq) & 1) != 0;
if($us & 1 || $ur & 8){
$notBanned = 1;
}
if($ur & 16){
$isBanned = 1;
}
if($ur & 256){
$isGagged = 1;
}
if($ur & 64){
$isForever = 1;
}
trace("Banned: " . $isBanned . "; Gagged: " . $isGagged . "; Forever: " . $isForever . "; Not-Banned: " . $notBanned . "; Online: " . $online);
if($isBanned || $isGagged || $isForever){
$nB = false;
}
if($notBanned){
$nB = true;
}
if(!$online){
$nB = false;
}
trace("NB stat: " . $nB);
if($nB){
$send = "<p u=\"" . $ui . "\" t=\"Welcome, " . $uj . "!\" s=\"2\" u=\"" . $uid . "\" />" . chr(0);
trace("Sending: " . $send);
socket_write($socket, $send, strlen($send));
}
} else if(stripos($out, "<m") > -1){
$message = stribet($out, "t=\"", "\"");
$uid_part = stribet($out, "u=\"", "\"");
$senduid = explode("_", $uid_part);
trace("User " . $senduid[0] . " said: " . $message);
if(in_array($senduid[0], $owners)){
if(strtolower($message) == "bot enable commands"){
$commands_enabled = true;
}
if(strtolower($message) == "bot disable commands"){
$commands_enabled = false;
}
}
if(filter($message)){
$send = "<c p=\"Autobanning user for swearing\" u=\"" . $senduid[0] . "\" t=\"/g3600\" />" . chr(0);
trace("Auto banning user");
socket_write($socket, $send, strlen($send));
}
if($commands_enabled){
if(stristr($message, "banme")){
$send = "<c p=\"Autobanning user for no reason\" u=\"" . $senduid[0] . "\" t=\"/g3600\" />" . chr(0);
trace("Auto banning user");
socket_write($socket, $send, strlen($send));
}
if(stristr($message, "kickme")){
$send = "<c p=\"Automatically kicking user for no reason\" u=\"" . $senduid[0] . "\" t=\"/k\" />" . chr(0);
trace("Kicking user");
socket_write($socket, $send, strlen($send));
}
if(stristr($message, "guestme")){
$send = "<c u=\"" . $senduid[0] . "\" t=\"/r\" />" . chr(0);
trace("Guesting user");
socket_write($socket, $send, strlen($send));
}
if(stristr($message, "memberme")){
$send = "<c u=\"" . $senduid[0] . "\" t=\"/e\" />" . chr(0);
trace("Membering user");
socket_write($socket, $send, strlen($send));
}
}
} else if(stripos($out, "<p") > -1){
if($commands_enabled){
$message = stribet($out, "t=\"", "\"");
$uid_part = stribet($out, "u=\"", "\"");
$senduid = explode("_", $uid_part);
if(filter($message)){
$send = "<c p=\"Autobanning user for swearing\" u=\"" . $senduid[0] . "\" t=\"/g3600\" />" . chr(0);
trace("Auto banning user");
socket_write($socket, $send, strlen($send));
}
if(stristr($message, "banme")){
$send = "<c p=\"Autobanning user for no reason\" u=\"" . $senduid[0] . "\" t=\"/g3600\" />" . chr(0);
trace("Auto banning user");
socket_write($socket, $send, strlen($send));
}
if(stristr($message, "kickme")){
$send = "<c p=\"Automatically kicking user for no reason\" u=\"" . $senduid[0] . "\" t=\"/k\" />" . chr(0);
trace("Kicking user");
socket_write($socket, $send, strlen($send));
}
if(stristr($message, "guestme")){
$send = "<c u=\"" . $senduid[0] . "\" t=\"/r\" />" . chr(0);
trace("Guesting user");
socket_write($socket, $send, strlen($send));
}
if(stristr($message, "memberme")){
$send = "<c u=\"" . $senduid[0] . "\" t=\"/e\" />" . chr(0);
trace("Membering user");
socket_write($socket, $send, strlen($send));
}
}
trace($senduid[0]);
if(in_array($senduid[0], $owners)){
if(strtolower($message) == "bot enable commands"){
$commands_enabled = true;
}
if(strtolower($message) == "bot disable commands"){
$commands_enabled = false;
}
$spl = explode(" ", $message);
if($spl[0] == "ban"){
$banuid = $spl[1];
$length = $spl[2] * 60 * 60;
$send = "<c p=\"Banning for no reason\" u=\"" . $banuid . "\" t=\"/g" . $length . "\" />" . chr(0);
trace("Force banning user");
socket_write($socket, $send, strlen($send));
}
$spl = explode(" ", $message);
if($spl[0] == "say"){
trace("Forced to speak");
$msg = str_ireplace("say ", "", $message);
$send = "<m t=\"" . $msg . "\" u=\"" . $uid . "\" />" . chr(0);
socket_write($socket, $send, strlen($send));
}
}
} else if(stripos($out, "<idle />")){
exec("C:\\www\\xatbot.bat");
trace("Socket closed");
exit();
} else if(stripos($out, "<c")){
exec("C:\\www\\xatbot.bat");
trace("Socket closed");
exit();
}
}
if($i == 100){
$i = 0;
$send = "<m t=\"" . $smilies[array_rand($smilies)] ."\" u=\"" . $uid . "\" />" . chr(0);
socket_write($socket, $send, strlen($send));
}
$i = $i + 1;
}
// Close html tags
socket_close($socket);
}
function trace($msg)
{
echo "--> " . $msg . "\n";
}
function stribet($inputstr, $delimiterLeft, $delimiterRight) {
$posLeft = stripos($inputstr, $delimiterLeft) + strlen($delimiterLeft);
$posRight = stripos($inputstr, $delimiterRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
}
function strbet($inputstr, $delimiterLeft, $delimiterRight) {
$posLeft = strpos($inputstr, $delimiterLeft) + strlen($delimiterLeft);
$posRight = strpos($inputstr, $delimiterRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
} //Does the same as stribet but case sensitive
function parseInt($string) {
// return intval($string);
if(preg_match('/(\d+)/', $string, $array)) {
return $array[1];
} else {
return false;
}
}
function xInt($arg){
$loc1 = parseInt($arg);
if ($loc1 === false){
return(0);
} // end if
return($loc1);
} // End of the function
function filter($text){
$badWordsArray = explode("\r\n", file_get_contents("swears.txt"));
foreach($badWordsArray as $badWord) {
if(stristr($text, $badWord) !== false){
trace("BAD WORD FOUND: " . $badWord);
return true;
}
}
return false;
}
?>