Author Topic: Coding a simple php Internet Relay Server (IRC) [Need help]  (Read 409 times)

I didn't put this in coding help since I think that's torque-script only. But some of you may know I'm trying to make a workshop-type system, We almost got there before until Pacnet "retired" from coding our server* so that means I'll have to do Torquescript AND the PHP aswell,  And I of course don't know how many people on these forums know how to code PHP.

If you can help anyone that would be great and you'll go on the credits once it's done (If it's done, I'm not good at php, I'm only good at the torque script side.). If you are wondering about the toruqe side of the IRC it's basiclly done. I just need to do this and a listening loop on the client.



This "should" send a message to all clients who are connected. If you could help with multi-clients that would be even better. I've added some comments to the code.

Code: [Select]
#c:/PHP/php -q //This is where the php.exe is on my computer, it does run but
just goes into a loop not doing much.

error_reporting(E_ALL); //Just reports errors

set_time_limit(0); //Stops it automaticlly stopping

ob_implicit_flush();

$address = "192.0.0.1"; //I don't even know which adress you put here...
$port = 10000;

if($sock = socket_create(AF_NET, SOCK_STREAM, SOL_TCP)) === false) {
echo "Crap, an error!"\n;
}

if(socket_bind($sock, $address, $port) == false) {
echo "an error to do with binding";
}

if(socket_listen($sock, 5) === false) {
echo "socket didn't listen";
}

do {
if(($msgsock = socket_accept($sock)) == false) {
echo "failure";
break;
}
$msg = "\nWelcome to Blockland Workbench Chat, This message will probably
be spammed through the chat...";
socket_write($msgsock, $msg, strlen($msg));
socket_close($msgsock); //This closes the socket so it can be reused
} while (true);

socket_close($sock);
?>


*Seriously Pacnet, we were getting close to finishing until you left us stranded.