- sleep(2);
-
- // Ok, now try again.
- // echo "Connecting to ", $sockname, "...<BR>\n";
- // flush();
- $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
+ sleep(1);
+
+ // Keep attempting connections 10 times per second up to 100 times
+ $attempts = 0;
+ while (!$clientsocket) {
+ usleep(100);
+ if (is_array(stat($sockname)))
+ $clientsocket = fsockopen(SOCKET_PREFIX.$sockname, 0, $errno, $errstr, 5);
+ else
+ $clientsocket = false;
+ $attempts += 1;
+ if ($attempts > 100) {
+ echo "ERROR: unable to start connection proxy. ";
+ echo "Please contact your system administrator.<BR>\n";
+ flush();
+ exit(1);
+ }
+ }
+
+ // At this point we have a good connection to Citadel.
+ $identity=array(
+ "DevelNr" => '0',
+ "ClientID" => '8',
+ "VersionNumber" => '001',
+ "ClientInfoString" => 'PHP web client|',
+ "Remote Address" => $_SERVER['REMOTE_ADDR'] );
+
+ ctdl_iden($identity); // Identify client
+ ctdl_MessageFormatsPrefered(array("text/html","text/plain"));
+ if (isset($_SESSION["username"])) {
+ login_existing_user(
+ $_SESSION["username"],
+ $_SESSION["password"]
+ );
+ }
+
+ if (isset($_SESSION["room"])) {
+ ctdl_goto($_SESSION["room"]);
+ }
+ else {
+ ctdl_goto("_BASEROOM_");
+ }