mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-06 04:44:21 +00:00
Create Users
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
############################################################################
|
||||
## Created by: KFCSpike ##
|
||||
## Contributors: KFCSpike ##
|
||||
## License: TravianZ Project ##
|
||||
## Copyright: TravianZ (c) 2014. All rights reserved. ##
|
||||
############################################################################
|
||||
|
||||
?>
|
||||
|
||||
<form action="../GameEngine/Admin/Mods/addUsers.php" method="POST">
|
||||
<input type="hidden" name="id" id="id" value="<?php echo $id; ?>">
|
||||
<center><b>Create Users and Villages</b>
|
||||
<br><br>
|
||||
<font color="Red">
|
||||
<b>
|
||||
Submitting this form will create new Users (and their home Villages) on your server!<br>
|
||||
</b>
|
||||
</font>
|
||||
<br>
|
||||
<b>Base Name</b> should be between 4 and 20 characters long
|
||||
<br><br>
|
||||
<b>How Many</b> should be between 1 and 200<br>
|
||||
(Higher values might take a while or cause a crash!)
|
||||
<br><br>
|
||||
If you want to run this more than once you should use different a different Base Name each time - if a UserName already exists it will be skipped
|
||||
<br><br>
|
||||
Example:<br>
|
||||
Base Name = Farm<br>
|
||||
How Many = 5<br>
|
||||
Users created will be Farm1, Farm2, Farm3, Farm4, Farm5<br>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<?php
|
||||
$baseNameFontColor = "Black";
|
||||
$amountFontColor = "Black";
|
||||
$baseName = "Farm";
|
||||
$amount = 20;
|
||||
|
||||
if(isset($_GET['e']))
|
||||
{
|
||||
// If &e is set then &bn + &am should be as well
|
||||
$baseName = ($_GET['bn']);
|
||||
$amount = ($_GET['am']);
|
||||
switch ($_GET['e'])
|
||||
{
|
||||
case 'BN2S':
|
||||
$baseNameFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Base Name is too short (min 4 chars)</font></b>';
|
||||
break;
|
||||
case 'BN2L':
|
||||
$baseNameFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Base Name is too long (max 20 chars)</font></b>';
|
||||
break;
|
||||
case 'AMLO':
|
||||
$amountFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Minimum of 1 for How Many</font></b>';
|
||||
break;
|
||||
case 'AMHI':
|
||||
$amountFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Maximum of 200 for How Many</font></b>';
|
||||
break;
|
||||
default:
|
||||
// Should never reach here
|
||||
$baseNameFontColor = "Black";
|
||||
$amountFontColor = "Black";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Unknown</font></b>';
|
||||
}
|
||||
}
|
||||
elseif ( isset($_GET['g']) && $_GET['g'] == 'OK')
|
||||
{
|
||||
$baseName = ($_GET['bn']);
|
||||
$amount = ($_GET['am']);
|
||||
$skipped = ($_GET['sk']);
|
||||
echo '<br /><br />
|
||||
<font color="Blue"><b>'
|
||||
. $amount .
|
||||
'</b></font>
|
||||
Users and Villages added using Base Name
|
||||
<font color="Blue"><b>'
|
||||
. $baseName .
|
||||
'</b></font><br>';
|
||||
if ($skipped > 0)
|
||||
{
|
||||
echo '<font color="Red"><b>'
|
||||
. $skipped .
|
||||
'</b></font>
|
||||
Users not created as the user name already exists
|
||||
</b></font><br>';
|
||||
}
|
||||
echo 'Now would be a good time to '
|
||||
. '<a href="' . SERVER . 'dorf1.php">Return to the server</a>'
|
||||
. ' this will update rankings etc but <b>will</b> take a while!<br>'
|
||||
. ' Make sure <b>max_execution_time</b> is set to a high enough value in php.ini<br><br>'
|
||||
. 'Choose a different <b>Base Name</b> if you want to create more<br>';
|
||||
// Clear the basename from form values so not used again
|
||||
$baseName = "";
|
||||
$amount = "";
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
<font color ="<?php echo $baseNameFontColor ?>">Base Name </font><input name="users_base_name" id="users_name" value="<?php echo $baseName ?>" maxlength="20">
|
||||
<br><br>
|
||||
<font color ="<?php echo $amountFontColor ?>">How Many <font><input name="users_amount" id="users_amount" value="<?php echo $amount ?>" maxlength="4">
|
||||
<br><br>
|
||||
<input type="submit" value="Create Users">
|
||||
</center>
|
||||
</form>
|
||||
+4
-1
@@ -6,7 +6,7 @@
|
||||
## Developed by: Dzoki ##
|
||||
## Reworked: aggenkeech ##
|
||||
## License: TravianX Project ##
|
||||
## Copyright: TravianX (c) 2010-2012. All rights reserved. ##
|
||||
## Copyright: TravianX (c) 2010-2014. All rights reserved. ##
|
||||
## ##
|
||||
#################################################################################
|
||||
|
||||
@@ -135,6 +135,9 @@ $up_avl = $latest - $ver ;
|
||||
<a href="?p=givePlusRes">Give All Res Bonus</a>
|
||||
<a href="?p=maintenenceResetPlusBonus">Reset Res Bonus</a>
|
||||
<br />
|
||||
<a href="#"><b>Users</b></a>
|
||||
<a href="?p=addUsers">Create Users</a>
|
||||
<br />
|
||||
<a href="#"><b>Natars</b></a>
|
||||
<a href="?p=natarend">Add WW Villages</a>
|
||||
<a href="?p=natarbuildingplan">Add WW Building Plan Villages</a>
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
############################################################################
|
||||
## Filename addUsers.php ##
|
||||
## Created by: KFCSpike ##
|
||||
## Contributors: KFCSpike ##
|
||||
## License: TravianZ Project ##
|
||||
## Copyright: TravianZ (c) 2014. All rights reserved. ##
|
||||
############################################################################
|
||||
|
||||
|
||||
include_once("../../config.php");
|
||||
include_once("../../Session.php");
|
||||
include_once("../../Automation.php");
|
||||
mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS);
|
||||
mysql_select_db(SQL_DB);
|
||||
|
||||
$id = $_POST['id'];
|
||||
$baseName = $_POST['users_base_name'];
|
||||
$amount = (int) $_POST['users_amount'];
|
||||
|
||||
// Some basic error checking
|
||||
if (strlen($baseName) < 4)
|
||||
{
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=BN2S&bn=$baseName&am=$amount");
|
||||
}
|
||||
elseif (strlen($baseName) > 20)
|
||||
{
|
||||
// Might be needed if older browers don't respect form maxlength
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=BN2L&bn=$baseName&am=$amount");
|
||||
}
|
||||
elseif ($amount < 1)
|
||||
{
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=AMLO&bn=$baseName&am=$amount");
|
||||
}
|
||||
elseif ($amount > 200) // TODO: Make this a config variable?
|
||||
{
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=AMHI&bn=$baseName&am=$amount");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Looks OK, let's go for it
|
||||
$created = 0;
|
||||
$skipped = 0;
|
||||
for ($i= 1; $i <= $amount; $i++)
|
||||
{
|
||||
$userName = $baseName . $i;
|
||||
// Random passwords disallow admin logging in to use the accounts
|
||||
$password = $generator->generateRandStr(20);
|
||||
|
||||
// Leaving the line below but commented out - could be used to
|
||||
// allow admin to log in to the generated accounts and play them
|
||||
// Easily guessed by players so should only be used for testing
|
||||
//$password = $baseName . $i . 'PASS';
|
||||
|
||||
$email = $baseName . $i . '@example.com';
|
||||
$tribe = rand(1, 3);
|
||||
// Create in a random quad
|
||||
$kid = rand(1,4);
|
||||
// Dont need to activate, not 100% sure we need to initialise $act
|
||||
$act = "";
|
||||
|
||||
// Check username not already registered
|
||||
if($database->checkExist($userName,0))
|
||||
{
|
||||
// Name already used, do nothing except update $skipped
|
||||
$skipped ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Register them and build the village
|
||||
$uid = $database->register($userName, md5($password), $email, $tribe ,$act);
|
||||
if($uid)
|
||||
{
|
||||
/*
|
||||
* @TODO
|
||||
*
|
||||
* Make beginners protection optional for Users created
|
||||
*
|
||||
* Allow option to create (random) bigger villages,
|
||||
* upgrade fields, granary, warehouse, wall etc
|
||||
*
|
||||
* Allow option to create (random) troops in some villages
|
||||
*
|
||||
* Don't directly access the DB, create a $database function
|
||||
* where required
|
||||
*/
|
||||
|
||||
// Show beginners protection in User Profile - see TODOs
|
||||
// Need a $database function for this
|
||||
// (assuming we don't already have one as creating Natars also updates this way)
|
||||
$q = "UPDATE " . TB_PREFIX . "users SET desc2 = '[#0]' WHERE id = $uid";
|
||||
mysql_query($q) or die(mysql_error());
|
||||
|
||||
$database->updateUserField($uid,"act","",1);
|
||||
$wid = $database->generateBase($kid,0);
|
||||
$database->setFieldTaken($wid);
|
||||
$database->addVillage($wid,$uid,$userName,1);
|
||||
$database->addResourceFields($wid,$database->getVillageType($wid));
|
||||
$database->addUnits($wid);
|
||||
$database->addTech($wid);
|
||||
$database->addABTech($wid);
|
||||
$database->updateUserField($uid,"access",USER,1);
|
||||
$created ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do nothing as the user wasn't created or some unknown error
|
||||
}
|
||||
}
|
||||
}
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&g=OK&bn=$baseName&am=$created&sk=$skipped");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user