mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-28 00:24:23 +00:00
@lietuvis10 fix for addUser
@lietuvis10 fix for addUser
This commit is contained in:
+185
-138
@@ -1,15 +1,4 @@
|
||||
<?php
|
||||
#################################################################################
|
||||
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
||||
## --------------------------------------------------------------------------- ##
|
||||
## Filename addUsers.php ##
|
||||
## Created by KFCSpike ##
|
||||
## Improve by ronix ##
|
||||
## Developed by: Shadow ##
|
||||
## License: TravianZ Project ##
|
||||
## Copyright: TravianZ (c) 2010-2025. All rights reserved. ##
|
||||
## ##
|
||||
#################################################################################
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
@@ -17,10 +6,7 @@ use App\Entity\User;
|
||||
$autoprefix = '';
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$autoprefix = str_repeat('../', $i);
|
||||
if (file_exists($autoprefix.'autoloader.php')) {
|
||||
// we have our path, let's leave
|
||||
break;
|
||||
}
|
||||
if (file_exists($autoprefix.'autoloader.php')) break;
|
||||
}
|
||||
|
||||
include_once($autoprefix."GameEngine/config.php");
|
||||
@@ -28,156 +14,217 @@ include_once($autoprefix."GameEngine/Session.php");
|
||||
include_once($autoprefix."GameEngine/Automation.php");
|
||||
include_once($autoprefix."GameEngine/Database.php");
|
||||
|
||||
$wgarray=array(1=>1200,1700,2300,3100,4000,5000,6300,7800,9600,11800,14400,17600,21400,25900,31300,37900,45700,55100,66400,80000);
|
||||
$wgarray = array(1=>1200,1700,2300,3100,4000,5000,6300,7800,9600,11800,14400,17600,21400,25900,31300,37900,45700,55100,66400,80000);
|
||||
|
||||
foreach ($_POST as $key => $value) {
|
||||
$_POST[$key] = $database->escape($value);
|
||||
}
|
||||
|
||||
$id = (int) $_POST['id'];
|
||||
$baseName = $_POST['users_base_name'];
|
||||
$amount = (int) $_POST['users_amount'];
|
||||
$beginnersProtection = $_POST['users_protection'];
|
||||
$postTribe = (int) $_POST['tribe'];
|
||||
$id = (int) $_POST['id'];
|
||||
$baseName = $_POST['users_base_name'];
|
||||
$amount = isset($_POST['users_amount']) ? (int) $_POST['users_amount'] : 0; // accounts (legacy)
|
||||
$villagesRequested = isset($_POST['villages_amount']) ? (int) $_POST['villages_amount'] : 0; // for single account
|
||||
$beginnersProtection = isset($_POST['users_protection']) ? $_POST['users_protection'] : 0;
|
||||
$postTribe = (int) $_POST['tribe'];
|
||||
$mode = isset($_POST['mode']) ? $_POST['mode'] : 'many_accounts';
|
||||
|
||||
// Some basic error checking
|
||||
if (strlen($baseName) < 4)
|
||||
{
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=BN2S&bn=$baseName&am=$amount");
|
||||
// Basic validation
|
||||
if (strlen($baseName) < 4) {
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=BN2S&bn=$baseName&am=$amount&vi=$villagesRequested&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
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");
|
||||
if (strlen($baseName) > 20) {
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=BN2L&bn=$baseName&am=$amount&vi=$villagesRequested&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
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
|
||||
|
||||
// convenience closure: pick tribe once (for a user)
|
||||
$chooseTribe = function(int $postTribe) {
|
||||
if ($postTribe === 0) return rand(1,3);
|
||||
return max(1, min(3, $postTribe));
|
||||
};
|
||||
|
||||
// convenience closure: builds/units/resources for one village
|
||||
$createVillage = function(int $uid, string $villageName, int $tribe, bool $isCapital) use ($database, $automation, $wgarray) : int {
|
||||
// Random quad
|
||||
$kid = rand(1,4);
|
||||
|
||||
// Second arg (1) historically used as "capital" in your code; non-capital = 0
|
||||
$wid = $database->generateBase($kid, $isCapital ? 1 : 0);
|
||||
$database->setFieldTaken($wid);
|
||||
|
||||
// random resources + storage sizing (same as your current logic)
|
||||
$rand_resource = rand(30000, 80000);
|
||||
$level_storage = rand(10, 20);
|
||||
$cap_storage = $wgarray[$level_storage]*(STORAGE_BASE/800);
|
||||
if ($rand_resource > $cap_storage) $rand_resource = $cap_storage;
|
||||
|
||||
$time = time();
|
||||
$capitalFlag = $isCapital ? 1 : 0;
|
||||
|
||||
// vdata
|
||||
$q = "INSERT INTO ".TB_PREFIX."vdata (`wref`,`owner`,`name`,`capital`,`pop`,`cp`,`celebration`,`type`,`wood`,`clay`,`iron`,`maxstore`,`crop`,`maxcrop`,`lastupdate`,`loyalty`,`exp1`,`exp2`,`exp3`,`created`)
|
||||
VALUES (".(int)$wid.",".(int)$uid.",'".$database->escape($villageName)."',$capitalFlag,200,1,0,0,$rand_resource,$rand_resource,$rand_resource,$cap_storage,$rand_resource,$cap_storage,$time,100,0,0,0,$time)";
|
||||
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
|
||||
|
||||
// fdata (unchanged randomization from your current code)
|
||||
$q = "INSERT INTO ".TB_PREFIX."fdata (`vref`,`f1`,`f1t`,`f2`,`f2t`,`f3`,`f3t`,`f4`,`f4t`,`f5`,`f5t`,`f6`,`f6t`,`f7`,`f7t`,`f8`,`f8t`,`f9`,`f9t`,`f10`,`f10t`,`f11`,`f11t`,`f12`,`f12t`,`f13`,`f13t`,`f14`,`f14t`,`f15`,`f15t`,`f16`,`f16t`,`f17`,`f17t`,`f18`,`f18t`,`f19`,`f19t`,`f20`,`f20t`,`f21`,`f21t`,`f22`,`f22t`,`f23`,`f23t`,`f24`,`f24t`,`f25`,`f25t`,`f26`,`f26t`,`f27`,`f27t`,`f28`,`f28t`,`f29`,`f29t`,`f30`,`f30t`,`f31`,`f31t`,`f32`,`f32t`,`f33`,`f33t`,`f34`,`f34t`,`f35`,`f35t`,`f36`,`f36t`,`f37`,`f37t`,`f38`,`f38t`,`f39`,`f39t`,`f40`,`f40t`,`f99`,`f99t`,`wwname`)
|
||||
VALUES ($wid ,".rand(5,10).",1,".rand(5,10).",4,".rand(5,10).",1,".rand(5,10).",3,".rand(5,10).",2,".rand(5,10).",2,".rand(5,10).",3,".rand(5,10).",4,".rand(5,10).",4,".rand(5,10).",3,".rand(5,10).",3,".rand(5,10).",4,".rand(5,10).",4,".rand(5,10).",1,".rand(5,10).",4,".rand(5,10).",2,".rand(5,10).",1,".rand(5,10).",2,".rand(2,5).",8,".rand(5,20).",37,".rand(10,20).",26,".rand(10,20).",22,".rand(10,20).",19,".rand(2,5).",9,$level_storage,11,".rand(10,20).",15,".rand(10,20).",20,0,0,".rand(10,15).",17,$level_storage,10,".rand(5,10).",12,0,0,10,23,0,0,0,0,0,0,0,0,".rand(5,10).",18,".rand(5,10).",16,0,0,0,0,'World Wonder')";
|
||||
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
|
||||
|
||||
// pop/cp recount
|
||||
$automation->recountPop($wid);
|
||||
$automation->recountPop($wid);
|
||||
|
||||
// units: random per tribe (same as your code)
|
||||
$q = "UPDATE " . TB_PREFIX . "units SET
|
||||
u".(($tribe-1)*10+1)." = ".rand(100, 2000).",
|
||||
u".(($tribe-1)*10+2)." = ".rand(100, 2400).",
|
||||
u".(($tribe-1)*10+3)." = ".rand(100, 1600).",
|
||||
u".(($tribe-1)*10+4)." = ".rand(100, 1500).",
|
||||
u".(($tribe-1)*10+5)." = ".rand(48, 1700).",
|
||||
u".(($tribe-1)*10+6)." = ".rand(60, 1800)."
|
||||
WHERE vref = '".$wid."'";
|
||||
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
|
||||
|
||||
return $wid;
|
||||
};
|
||||
|
||||
// ===== Branch by mode =====
|
||||
if ($mode === 'many_accounts') {
|
||||
if ($amount < 1) {
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=AMLO&bn=$baseName&am=$amount&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
if ($amount > 200) {
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=AMHI&bn=$baseName&am=$amount&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
|
||||
$created = 0;
|
||||
$skipped = 0;
|
||||
$addUnitsWrefs = [];
|
||||
$addTechWrefs = [];
|
||||
$addABTechWrefs = [];
|
||||
$addTechWrefs = [];
|
||||
$addABTechWrefs= [];
|
||||
|
||||
for ($i= 1; $i <= $amount; $i++)
|
||||
{
|
||||
for ($i=1; $i <= $amount; $i++) {
|
||||
$userName = $baseName . $i;
|
||||
// Random passwords disallow admin logging in to use the accounts
|
||||
$password = $generator->generateRandStr(20);
|
||||
$email = $userName . '@example.com';
|
||||
$tribe = $chooseTribe($postTribe);
|
||||
$act = "";
|
||||
|
||||
// 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';
|
||||
if ($postTribe == 0)
|
||||
{
|
||||
// Random Tribe
|
||||
$tribe = rand(1, 3);
|
||||
if (User::exists($database, $userName)) {
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No error checking here but should be set to 1-3 from form
|
||||
$tribe = $postTribe;
|
||||
|
||||
$uid = $database->register($userName, password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]), $email, $tribe, $act);
|
||||
if (!$uid) continue;
|
||||
|
||||
// profile protection dove
|
||||
$q = "UPDATE " . TB_PREFIX . "users SET desc2 = '[#0]' WHERE id = ".(int)$uid;
|
||||
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
|
||||
|
||||
if (!$beginnersProtection) {
|
||||
$protection = time();
|
||||
mysqli_query($GLOBALS["link"], "UPDATE ".TB_PREFIX."users SET protect = '".$protection."' WHERE id = ".(int)$uid) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
// 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(User::exists($database, $userName))
|
||||
{
|
||||
// Name already used, do nothing except update $skipped
|
||||
$skipped ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Register them and build the village
|
||||
$uid = $database->register($userName, password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]), $email, $tribe, $act);
|
||||
if($uid)
|
||||
{
|
||||
/*
|
||||
* [MENTION=6887]Todo[/MENTION]
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
$database->updateUserField($uid,"act","",1);
|
||||
|
||||
// Show the dove in User Profile - will show this even if
|
||||
// beginners protection is not checked
|
||||
// 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 = ".(int) $uid;
|
||||
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
|
||||
// One capital village (legacy)
|
||||
$villageName = $userName . "'s village";
|
||||
$wid = $createVillage($uid, $villageName, $tribe, true);
|
||||
|
||||
if (!$beginnersProtection)
|
||||
{
|
||||
// No beginners protection so set it to current time
|
||||
// TODO create a $database function for this
|
||||
// also used in editProtection.php so assuming no function
|
||||
// already exists
|
||||
$protection = time();
|
||||
mysqli_query($GLOBALS["link"], "UPDATE ".TB_PREFIX."users SET
|
||||
protect = '".$protection."'
|
||||
WHERE id = ".(int) $uid) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
$addUnitsWrefs[] = $wid;
|
||||
$addTechWrefs[] = $wid;
|
||||
$addABTechWrefs[] = $wid;
|
||||
|
||||
$database->updateUserField($uid,"act","",1);
|
||||
$wid = $database->generateBase($kid, 1);
|
||||
$database->setFieldTaken($wid);
|
||||
$database->updateUserField($uid,"access",USER,1);
|
||||
|
||||
//calculate random generate value and level building
|
||||
$rand_resource=rand(30000, 80000);
|
||||
$level_storage=rand(10, 20);
|
||||
$cap_storage=$wgarray[$level_storage]*(STORAGE_BASE/800);
|
||||
$rand_resource=($rand_resource>$cap_storage)? $cap_storage:$rand_resource;
|
||||
|
||||
//insert village with all resource and building with random level
|
||||
$time = time();
|
||||
$q = "INSERT INTO ".TB_PREFIX."vdata (`wref`,`owner`,`name`,`capital`,`pop`,`cp`,`celebration`,`type`,`wood`,`clay`,`iron`,`maxstore`,`crop`,`maxcrop`,`lastupdate`,`loyalty`,`exp1`,`exp2`,`exp3`,`created`) values (".(int) $wid.",".(int) $uid.",'".$userName."\'s village',1,200,1,0,0,$rand_resource,$rand_resource,$rand_resource,$cap_storage,$rand_resource,$cap_storage,$time,100,0,0,0,$time)";
|
||||
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
|
||||
$q = "insert into ".TB_PREFIX."fdata (`vref`,`f1`,`f1t`,`f2`,`f2t`,`f3`,`f3t`,`f4`,`f4t`,`f5`,`f5t`,`f6`,`f6t`,`f7`,`f7t`,`f8`,`f8t`,`f9`,`f9t`,`f10`,`f10t`,`f11`,`f11t`,`f12`,`f12t`,`f13`,`f13t`,`f14`,`f14t`,`f15`,`f15t`,`f16`,`f16t`,`f17`,`f17t`,`f18`,`f18t`,`f19`,`f19t`,`f20`,`f20t`,`f21`,`f21t`,`f22`,`f22t`,`f23`,`f23t`,`f24`,`f24t`,`f25`,`f25t`,`f26`,`f26t`,`f27`,`f27t`,`f28`,`f28t`,`f29`,`f29t`,`f30`,`f30t`,`f31`,`f31t`,`f32`,`f32t`,`f33`,`f33t`,`f34`,`f34t`,`f35`,`f35t`,`f36`,`f36t`,`f37`,`f37t`,`f38`,`f38t`,`f39`,`f39t`,`f40`,`f40t`,`f99`,`f99t`,`wwname`) values ($wid ,".rand(5,10).",1,".rand(5,10).",4,".rand(5,10).",1,".rand(5,10).",3,".rand(5,10).",2,".rand(5,10).",2,".rand(5,10).",3,".rand(5,10).",4,".rand(5,10).",4,".rand(5,10).",3,".rand(5,10).",3,".rand(5,10).",4,".rand(5,10).",4,".rand(5,10).",1,".rand(5,10).",4,".rand(5,10).",2,".rand(5,10).",1,".rand(5,10).",2,".rand(2,5).",8,".rand(5,20).",37,".rand(10,20).",26,".rand(10,20).",22,".rand(10,20).",19,".rand(2,5).",9,$level_storage,11,".rand(10,20).",15,".rand(10,20).",20,0,0,".rand(10,15).",17,$level_storage,10,".rand(5,10).",12,0,0,10,23,0,0,0,0,0,0,0,0,".rand(5,10).",18,".rand(5,10).",16,0,0,0,0,'World Wonder')";
|
||||
mysqli_query($GLOBALS["link"], $q);
|
||||
$pop = $automation->recountPop($wid);
|
||||
$cp = $automation->recountPop($wid);
|
||||
$addUnitsWrefs[] = $wid;
|
||||
$addTechWrefs[] = $wid;
|
||||
$addABTechWrefs[] = $wid;
|
||||
$database->updateUserField($uid,"access",USER,1);
|
||||
|
||||
//insert units randomly generate the number of troops
|
||||
$q = "UPDATE " . TB_PREFIX . "units SET u".(($tribe-1)*10+1)." = ".rand(100, 2000).", u".(($tribe-1)*10+2)." = ".rand(100, 2400).", u".(($tribe-1)*10+3)." = ".rand(100, 1600).", u".(($tribe-1)*10+4)." = ".rand(100, 1500).", u".(($tribe-1)*10+5)." = " .rand(48, 1700).", u".(($tribe-1)*10+6)." = ".rand(60, 1800)." WHERE vref = '".$wid."'";
|
||||
mysqli_query($GLOBALS["link"], $q);
|
||||
|
||||
$created ++;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do nothing as the user wasn't created or some unknown error
|
||||
}
|
||||
}
|
||||
$created++;
|
||||
}
|
||||
|
||||
$database->addUnits($addUnitsWrefs);
|
||||
$database->addTech($addTechWrefs);
|
||||
$database->addABTech($addABTechWrefs);
|
||||
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&g=OK&bn=$baseName&am=$created&sk=$skipped&bp=$beginnersProtection&tr=$postTribe");
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&g=OK&bn=$baseName&am=$created&sk=$skipped&bp=$beginnersProtection&tr=$postTribe&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
|
||||
// ===== Single account with X villages =====
|
||||
if ($mode === 'single_with_villages') {
|
||||
if ($villagesRequested < 1) {
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=VILO&bn=$baseName&vi=$villagesRequested&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
if ($villagesRequested > 200) {
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=VIHI&bn=$baseName&vi=$villagesRequested&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userName = $baseName; // exact name, no numeric suffix
|
||||
$password = $generator->generateRandStr(20);
|
||||
$email = $userName . '@example.com';
|
||||
$tribe = $chooseTribe($postTribe);
|
||||
$act = "";
|
||||
|
||||
if (User::exists($database, $userName)) {
|
||||
// Don’t silently add villages to an existing (maybe real) user via this tool.
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=AMLO&bn=$baseName&vi=$villagesRequested&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
|
||||
$uid = $database->register($userName, password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]), $email, $tribe, $act);
|
||||
if (!$uid) {
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=Unknown&bn=$baseName&vi=$villagesRequested&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
|
||||
// protection dove
|
||||
$q = "UPDATE " . TB_PREFIX . "users SET desc2 = '[#0]' WHERE id = ".(int)$uid;
|
||||
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
|
||||
|
||||
if (!$beginnersProtection) {
|
||||
$protection = time();
|
||||
mysqli_query($GLOBALS["link"], "UPDATE ".TB_PREFIX."users SET protect = '".$protection."' WHERE id = ".(int)$uid) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
|
||||
$database->updateUserField($uid,"act","",1);
|
||||
|
||||
$addUnitsWrefs = [];
|
||||
$addTechWrefs = [];
|
||||
$addABTechWrefs= [];
|
||||
|
||||
for ($v=1; $v <= $villagesRequested; $v++) {
|
||||
$isCapital = ($v === 1);
|
||||
$villageName = $userName . ($isCapital ? " (Capital)" : " #" . $v);
|
||||
$wid = $createVillage($uid, $villageName, $tribe, $isCapital);
|
||||
|
||||
$addUnitsWrefs[] = $wid;
|
||||
$addTechWrefs[] = $wid;
|
||||
$addABTechWrefs[] = $wid;
|
||||
|
||||
// Set the first village as active/capital in the usual tables if your code expects it:
|
||||
if ($isCapital) {
|
||||
// ensure vdata.capital already 1; if you have any “default village” linkage, set that here.
|
||||
}
|
||||
}
|
||||
|
||||
// Tech & ABTech for all villages
|
||||
$database->addUnits($addUnitsWrefs);
|
||||
$database->addTech($addTechWrefs);
|
||||
$database->addABTech($addABTechWrefs);
|
||||
|
||||
// Enable user after villages created
|
||||
$database->updateUserField($uid,"access",USER,1);
|
||||
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&g=OK&bn=$baseName&vi=$villagesRequested&sk=0&bp=$beginnersProtection&tr=$postTribe&mo=$mode");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Fallback (shouldn’t happen)
|
||||
header("Location: ../../../Admin/admin.php?p=addUsers&e=Unknown&bn=$baseName&mo=$mode");
|
||||
?>
|
||||
@@ -0,0 +1,167 @@
|
||||
<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">
|
||||
Submitting this form will create new Users and/or Villages on your server!
|
||||
</font>
|
||||
<br>
|
||||
<font color="blue">
|
||||
Includes resources, main building, rally point, warehouse, granary, wall, market, residence, troops (for hero level-up), and one cranny.
|
||||
</font>
|
||||
<p><b>Base Name</b> should be between 4 and 20 characters long</p>
|
||||
|
||||
<!-- NEW: Mode switch -->
|
||||
<b>Mode</b><br>
|
||||
<label><input type="radio" name="mode" value="many_accounts" checked> Many accounts (legacy): create X accounts with 1 village each</label><br>
|
||||
<label><input type="radio" name="mode" value="single_with_villages"> Single account: create 1 account with X villages</label>
|
||||
<br><br>
|
||||
|
||||
<!-- Legacy fields -->
|
||||
<b>How Many (accounts)</b> should be between 1 and 200<br>
|
||||
(Higher values might take a while or cause a crash!)
|
||||
<br><br>
|
||||
|
||||
<!-- Example -->
|
||||
If you want to run this more than once you should use a different Base Name each time.<br>
|
||||
<br>
|
||||
Example (legacy):<br>
|
||||
Base Name = Farm | How Many (accounts) = 5 → Users: Farm1..Farm5<br>
|
||||
Example (single):<br>
|
||||
Base Name = FarmLord | Villages = 5 → User: FarmLord with 5 villages
|
||||
<br><br>
|
||||
|
||||
<?php
|
||||
$baseNameFontColor = "Black";
|
||||
$amountFontColor = "Black";
|
||||
$villagesFontColor = "Black";
|
||||
|
||||
$baseName = "Farm";
|
||||
$amount = 20; // accounts (legacy)
|
||||
$villages = 5; // villages (single account)
|
||||
$mode = "many_accounts";
|
||||
|
||||
if(isset($_GET['e'])) {
|
||||
$baseName = ($_GET['bn']);
|
||||
$amount = isset($_GET['am']) ? ($_GET['am']) : $amount;
|
||||
$villages = isset($_GET['vi']) ? ($_GET['vi']) : $villages;
|
||||
$mode = isset($_GET['mo']) ? ($_GET['mo']) : $mode;
|
||||
|
||||
switch ($_GET['e']) {
|
||||
case 'BN2S':
|
||||
$baseNameFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Base Name is too short (min 4 chars)</b></font>';
|
||||
break;
|
||||
case 'BN2L':
|
||||
$baseNameFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Base Name is too long (max 20 chars)</b></font>';
|
||||
break;
|
||||
case 'AMLO':
|
||||
$amountFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Minimum of 1 for How Many (accounts)</b></font>';
|
||||
break;
|
||||
case 'AMHI':
|
||||
$amountFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Maximum of 200 for How Many (accounts)</b></font>';
|
||||
break;
|
||||
case 'VILO':
|
||||
$villagesFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Minimum of 1 for Villages</b></font>';
|
||||
break;
|
||||
case 'VIHI':
|
||||
$villagesFontColor = "Red";
|
||||
echo '<br /><br /><font color="Red"><b>Error: Maximum of 200 for Villages</b></font>';
|
||||
break;
|
||||
default:
|
||||
echo '<br /><br /><font color="Red"><b>Error: Unknown</b></font>';
|
||||
}
|
||||
}
|
||||
elseif ( isset($_GET['g']) && $_GET['g'] == 'OK') {
|
||||
$baseName = ($_GET['bn']);
|
||||
$mode = ($_GET['mo']);
|
||||
$skipped = ($_GET['sk']);
|
||||
$beginnersProtection = ($_GET['bp']);
|
||||
|
||||
// interpret the tribe label
|
||||
switch ($_GET['tr']) {
|
||||
case '0': $tribe = RANDOM; break;
|
||||
case '1': $tribe = TRIBE1; break;
|
||||
case '2': $tribe = TRIBE2; break;
|
||||
case '3': $tribe = TRIBE3; break;
|
||||
default: $tribe = 'Unknown';
|
||||
}
|
||||
|
||||
if ($mode === 'many_accounts') {
|
||||
$amount = ($_GET['am']);
|
||||
echo '<br /><br /><font color="Blue"><b>'.$amount.'</b></font> Users (1 village each) added with Base Name <font color="Blue"><b>'.$baseName.'</b></font><br>';
|
||||
} else {
|
||||
$villages = ($_GET['vi']);
|
||||
echo '<br /><br />Created User <font color="Blue"><b>'.$baseName.'</b></font> with <font color="Blue"><b>'.$villages.'</b></font> villages.<br>';
|
||||
}
|
||||
|
||||
if (($mode === 'many_accounts' && $amount > 0) || ($mode === 'single_with_villages' && $villages > 0)) {
|
||||
$usersMessage = ($mode === 'many_accounts' ? (($amount > 1) ? 'these Users' : 'this User') : 'this User');
|
||||
$begMessage = 'Beginners Protection was ';
|
||||
if (!$beginnersProtection) { $begMessage .= '<font color="red"><b>NOT</b></font> '; }
|
||||
$begMessage .= 'set for '.$usersMessage.'<br>';
|
||||
echo $begMessage;
|
||||
|
||||
$tribeMessage = 'Tribe for '.$usersMessage.' was '.$tribe.'<br>';
|
||||
echo $tribeMessage;
|
||||
}
|
||||
|
||||
if ($skipped > 0) {
|
||||
echo '<font color="Red"><b>'.$skipped.'</b></font> Users not created as the user name already exists<br>';
|
||||
}
|
||||
|
||||
echo '<br>Now would be a good time to <a href="'.SERVER.'/dorf1.php">Return to the server</a> (updates rankings; may take a while)<br>'
|
||||
. 'Make sure <b>max_execution_time</b> is set high enough in php.ini<br><br>';
|
||||
$baseName = ""; $amount = ""; $villages = "";
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
</center>
|
||||
|
||||
<!-- Base name -->
|
||||
<font color ="<?php echo $baseNameFontColor ?>">Base Name </font>
|
||||
<input type ="text" name="users_base_name" id="users_name" value="<?php echo $baseName ?>" maxlength="20">
|
||||
<br><br>
|
||||
|
||||
<!-- Accounts amount (legacy) -->
|
||||
<div id="accountsBlock">
|
||||
<font color ="<?php echo $amountFontColor ?>">How Many (accounts) </font>
|
||||
<input type ="text" name="users_amount" id="users_amount" value="<?php echo $amount ?>" maxlength="4">
|
||||
</div>
|
||||
|
||||
<!-- Villages amount (single account) -->
|
||||
<div id="villagesBlock" style="margin-top:10px;">
|
||||
<font color ="<?php echo $villagesFontColor ?>">Villages (for single account) </font>
|
||||
<input type ="text" name="villages_amount" id="villages_amount" value="<?php echo $villages ?>" maxlength="4">
|
||||
</div>
|
||||
|
||||
<br>
|
||||
Beginners Protection <input type ="checkbox" name="users_protection" id="users_protection" checked>
|
||||
<br><br>
|
||||
Tribe:<br>
|
||||
<label><input type="radio" name="tribe" value="0" checked> <?php echo RANDOM; ?></label><br>
|
||||
<label><input type="radio" name="tribe" value="1"> <?php echo TRIBE1; ?></label><br>
|
||||
<label><input type="radio" name="tribe" value="2"> <?php echo TRIBE2; ?></label><br>
|
||||
<label><input type="radio" name="tribe" value="3"> <?php echo TRIBE3; ?></label><br>
|
||||
<br><br>
|
||||
<input type="submit" value="Create">
|
||||
|
||||
<script>
|
||||
// Tiny progressive disclosure (no external JS)
|
||||
(function(){
|
||||
function sync() {
|
||||
var mode = document.querySelector('input[name="mode"]:checked').value;
|
||||
document.getElementById('accountsBlock').style.opacity = (mode==='many_accounts') ? '1' : '0.3';
|
||||
document.getElementById('villagesBlock').style.opacity = (mode==='single_with_villages') ? '1' : '0.3';
|
||||
}
|
||||
var radios = document.querySelectorAll('input[name="mode"]');
|
||||
for (var i=0;i<radios.length;i++){ radios[i].addEventListener('change', sync); }
|
||||
sync();
|
||||
})();
|
||||
</script>
|
||||
</form>
|
||||
Reference in New Issue
Block a user