Senseika wrote:
I assume this teaches how to take a server out? (At least if you have more than one person doing this at once on different IPs/Computers)
Sure, a person could easily max out all the sockets on a single script. It wouldn't crash the server, but nobody would be able to connect.
Tony wrote:
Wow, so registration through browser is possible?
Code:
<?php
/* Variables used in this script:
- $_dir Directory to where the users' accounts are stored.
- $_filename Filename of the user that is going to be created.
- $_handle Opened file handle.
- $_data The .ini file data.
- $username
- $password
*/
$username = 'cruzn';
$password = 'notcruzn';
$_dir = 'C:\\Documents and Settings\\path\\to\\Accounts\\'; // Notice: TRAILING SLASH.
$_filename = $username . '.ini'; // Filename of the user (simply the requested username with .ini at the end.
if( file_exists($_dir) ){ // Make sure the directory we want exists.
if( !file_exists($_dir . $_filename) ){ // Check to see if the file exists (failure = username already taken).
if( $_handle = fopen($_dir . $_filename, "w") ){ // Username is free, open (and create) the user's .ini file.
// This is all the data that will be put into the user's .ini file.
$_data = '[GENERAL]
Login=' . $username . '
Password=' . $password . '
[CHAR1]
Class=1
Map=1
X=10
Y=6
[CHAR2]
Class=1
Map=1
X=10
Y=6
[CHAR3]
Class=1
Map=1
X=10
Y=6';
fwrite($_handle, $_data) or die('Error writing to file.'); // Create the account by writing in all the data.
fclose($_handle) or die; // Close the file.
};
}else{ // The account already exists.
echo 'Account already exists.';
};
}else{
echo 'Could not find the specified directory.';
};
?>
Old code, and it's for Elysium, but yes -- you can register through a browser.
Also, and online script (again, old code and for Elysium):
Code:
<?
set_time_limit(2);
$socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); // Create the Socket
$connection = @socket_connect($socket, "127.0.0.1", 4000); // Connect to server
$message = "whosonline" . chr(0) . chr(237);
@socket_write($socket, $message) or die("Could not write output.");
$data = @socket_read($socket, 2046);
list($packet, $data, $a) = explode(chr(0), $data);
echo "1: " . $packet . " = \"" . $data . "\"";
if( $packet == "PLAYERMSG" ){
if( @preg_match('#There are (.*?) other players online:#', $data, $a) ){
if( @preg_match('#There are ' . $a[1] . ' other players online: (.*).#', $data, $b) ){
$players = explode(", ", $b[1]);
while( list(, $id) = each($players) ){
echo "Player: " . $id . "\n<br>";
$message = "playerinforequest" . chr(0) . $id . chr(237);
@socket_write($socket, $message) or die("Could not write output.");
$data = @socket_read($socket, 2046);
list($packet, $data) = explode(chr(0), $data);
if( $packet == "PLAYERMSG" ){
echo $data . '<br>';
};
};
};
}elseif( $data == "There are no other players online." ){
@socket_close($socket);
die('No players online.');
}else{
@socket_close($socket);
die('Received incorrect data. "' . $data . '"');
};
};
?>