PHP Code:
<?php
//NOTE! If you want to edit the subject / body of the mail sent in-game, go to line #97.
//Note2: Remember that the $_GET['r'] should be the username of the character reqruiting / recieving the mail..
//Note3: The mail script hasn't been tested, I'm 33% sure that it'll work though. :/)
$Item_ID = '1337'; //Edit this to the ID of the reward for reqruiting a friend (sent in mail).
$MySQL_Host = 'localhost'; //The host IP / hostname
$MySQL_User = 'root'; //The username used to access the database
$MySQL_Pass = 'ascent'; //The password used to access the database
$Database_Name = 'logon'; //The database name, this is the database containing the characters, account and mailbox table. 'logon' is your best bet. :]
$Table_1 = 'used'; //This is the table where all IPs wil be stored
//No need to edit below this point.
//#################################
$ip=$_SERVER['REMOTE_ADDR'];
if(!empty($_GET['r']))
{
$connection = mysql_connect("$MySQL_Host", "$MySQL_User", "$MySQL_Pass");
if (!$connection) {
die('I call shenanigans.');
}
if (!mysql_select_db("$Database_Name")) {
die('I call shenanigans.');
}
//If the table 'used'($Table_1) doesn't exist, create :]
if(!mysql_num_rows(mysql_query("SHOW TABLES LIKE '$Table_1'")))
{
mysql_query("CREATE TABLE `used` (`IP` VARCHAR (50)) TYPE = MyISAM");
}
//If the Reqruit A Friend -account is not made already, create :]
$lastAccountID = mysql_query("SELECT MAX(acct) FROM accounts");
$lastAccountID = mysql_result($lastAccountID,0)+1;
$reqacciscreated = mysql_num_rows(mysql_query("select * from accounts where login='Reqruit A Friend Name' and password='bs pass'"));
if($reqacciscreated==0)
{
mysql_query("INSERT INTO `accounts` (`acct`, `login`, `password`, `gm`, `flags`, `forceLanguage`)
VALUES ('$lastAccountID', 'Reqruit A Friend Name', 'bs pass', '0', '24', 'enUS');");
}
//If the Reqruit A Friend -player is not made already, create :]
$reqnameiscreated = mysql_num_rows(mysql_query("SELECT * FROM characters WHERE name='Reqruit A Friend'"));
if($reqnameiscreated==0)
{
$lastUserID = mysql_query("SELECT MAX(guid) FROM characters");
$lastUserID = mysql_result($lastUserID,0)+1;
mysql_query("INSERT INTO `characters` (`guid`, `acct`, `name`) VALUES ('$lastUserID', '$lastAccountID', 'Reqruit A Friend');");
}
//Get R :]
$ref=$_GET['r'];
//Remove SQL injection vulnerbilliti.. Vul.. I don't know how it's spelled.. Doesn't matter either. :]
$ref=mysql_real_escape_string($ref);
//If the clicker has already clicked, return 1, else 0 / null?
$hasclicked=mysql_num_rows(mysql_query("select * from $Table_1 where IP='$ip'"));
//Get last message ID
$lastmes = mysql_query("SELECT MAX(message_id) FROM mailbox");
$lastmes = mysql_result($lastmes,0)+1;;
echo $lastmes;
//Get player guid
$playerid = mysql_fetch_array(mysql_query("SELECT * FROM characters WHERE name='$ref'"));
$playerid = $playerid[0];
//Get Reqruit A Friend-id
$rafguid = mysql_fetch_array(mysql_query("SELECT * FROM characters WHERE name='Reqruit A Friend'"));
$rafguid = $rafguid[0];
//Register the visit (add IP to used refs - Send mail to player)
if($hasclicked==0)
{
mysql_query("INSERT INTO $Table_1
VALUES('$ip')");
if($ref && $playerid!=0)
{
mysql_query("
INSERT INTO mailbox (`message_id`, `message_type`, `player_guid`, `sender_guid`, `subject`, `body`, `money`, `attached_item_guids`, `cod`, `stationary`, `expiry_time`, `delivery_time`, `copy_made`, `read_flag`, `deleted_flag`)
VALUES ('$lastmes', '0', '$playerid', '$rafguid', 'Reqruit-A-Friend reward', 'Thank you for using our a reqruit-a-friend system! As a small token of our appreciation, I\'ve sent you this item.', '0', '$Item_ID', '0', '0', '1266629480', '0', '0', '0', '0');"); //You may want to edit the subject / body.. Can be found on this line
}
}
mysql_close($connection);
//Connection is closed. :]
}
else
{
$connection = mysql_connect("$MySQL_Host", "$MySQL_User", "$MySQL_Pass");
if (!$connection) {
die('I call shenanigans.');
}
if (!mysql_select_db("$Database_Name")) {
die('I call shenanigans.');
}
$hasclicked=mysql_num_rows(mysql_query("select * from $Table_1 where IP='$ip'"));
if($hasclicked=='0')
{
mysql_query("INSERT INTO `used` (`IP`) VALUES ('$ip');");
}
mysql_close($connection);
}
?>
There.. Uhmm.. It automatically adds a character with the name of 'Reqruit a Friend' but.. Yeah, I added a few comments so that you should be able to understand it, even though my coding might be a bit uhmm.. Rubbish.. So.. Yeah