<?php
include("config.php");
include(
"functions.php");

$fso = @fsockopen($host$port$errno$errstr2) or die("can't connect\n");
if(
$fsoregister();

while(
1) {

    
$buffer fgets($fso);
    
    if(
strlen($buffer) > 2){
        echo 
"[RECV] {$buffer}";
        
$bad 0;
        include(
"commands.php");
    }
    else{
        ++
$bad;
        if(
$bad >= 2) echo "connection issue?\n";
        if(
$bad >= 10$restarting TRUE;
        
#if we haven't heard from the server in a while, reconnect?
    
}
    
    if(
feof($fso) && $restarting !== TRUE) die("connection broke!\n");
    if(
$restarting === TRUE){
        
sleep(1);
        
$fso = @fsockopen($host$port$errno$errstr2) or die("can't connect\n");
        if(
$fso){
            
register();
            
$restarting FALSE;
        }
    }    

    
flush();

}

?>