From ce40be343eca6c4be1616bc902ed052a8013008b Mon Sep 17 00:00:00 2001 From: KFCSpike Date: Sat, 21 Dec 2013 20:01:55 +0000 Subject: [PATCH] Create Users --- Admin/Templates/addUsers.tpl | 110 ++++++++++++++++++++++++++++ Admin/admin.php | 5 +- GameEngine/Admin/Mods/addUsers.php | 113 +++++++++++++++++++++++++++++ 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 Admin/Templates/addUsers.tpl create mode 100644 GameEngine/Admin/Mods/addUsers.php diff --git a/Admin/Templates/addUsers.tpl b/Admin/Templates/addUsers.tpl new file mode 100644 index 00000000..9ec415bf --- /dev/null +++ b/Admin/Templates/addUsers.tpl @@ -0,0 +1,110 @@ + + +
+ +
Create Users and Villages +

+ + + Submitting this form will create new Users (and their home Villages) on your server!
+
+
+
+ Base Name should be between 4 and 20 characters long +

+ How Many should be between 1 and 200
+ (Higher values might take a while or cause a crash!) +

+ 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 +

+ Example:
+ Base Name = Farm
+ How Many = 5
+ Users created will be Farm1, Farm2, Farm3, Farm4, Farm5
+
+
+ +
Error: Base Name is too short (min 4 chars)'; + break; + case 'BN2L': + $baseNameFontColor = "Red"; + echo '

Error: Base Name is too long (max 20 chars)'; + break; + case 'AMLO': + $amountFontColor = "Red"; + echo '

Error: Minimum of 1 for How Many'; + break; + case 'AMHI': + $amountFontColor = "Red"; + echo '

Error: Maximum of 200 for How Many'; + break; + default: + // Should never reach here + $baseNameFontColor = "Black"; + $amountFontColor = "Black"; + echo '

Error: Unknown'; + } + } + elseif ( isset($_GET['g']) && $_GET['g'] == 'OK') + { + $baseName = ($_GET['bn']); + $amount = ($_GET['am']); + $skipped = ($_GET['sk']); + echo '

+ ' + . $amount . + ' + Users and Villages added using Base Name + ' + . $baseName . + '
'; + if ($skipped > 0) + { + echo '' + . $skipped . + ' + Users not created as the user name already exists +
'; + } + echo 'Now would be a good time to ' + . 'Return to the server' + . ' this will update rankings etc but will take a while!
' + . ' Make sure max_execution_time is set to a high enough value in php.ini

' + . 'Choose a different Base Name if you want to create more
'; + // Clear the basename from form values so not used again + $baseName = ""; + $amount = ""; + } + ?> +
+ Base Name   +

+ How Many    +

+ +
+ diff --git a/Admin/admin.php b/Admin/admin.php index 7c125f6f..9e91129e 100644 --- a/Admin/admin.php +++ b/Admin/admin.php @@ -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 ; Give All Res Bonus Reset Res Bonus
+ Users + Create Users +
Natars Add WW Villages Add WW Building Plan Villages diff --git a/GameEngine/Admin/Mods/addUsers.php b/GameEngine/Admin/Mods/addUsers.php new file mode 100644 index 00000000..bb94697b --- /dev/null +++ b/GameEngine/Admin/Mods/addUsers.php @@ -0,0 +1,113 @@ + 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"); +} +?>