From c685c87621192376f3f3f3f68f13b4853f0d5012 Mon Sep 17 00:00:00 2001 From: Martin Ambrus Date: Tue, 7 Nov 2017 13:26:18 +0100 Subject: [PATCH] refactor: all users set up together during install Closes #278 --- install/include/accounts.php | 87 +++++++++++++++++++++++++ install/include/multihunter.php | 34 ---------- install/include/support.php | 23 ------- install/index.php | 7 +- install/process.php | 8 +-- install/templates/accounts.tpl | 105 ++++++++++++++++++++++++++++++ install/templates/config.tpl | 40 ------------ install/templates/menu.tpl | 15 ++--- install/templates/multihunter.tpl | 36 ---------- install/templates/support.tpl | 36 ---------- 10 files changed, 203 insertions(+), 188 deletions(-) create mode 100644 install/include/accounts.php delete mode 100644 install/include/multihunter.php delete mode 100644 install/include/support.php create mode 100644 install/templates/accounts.tpl delete mode 100644 install/templates/multihunter.tpl delete mode 100644 install/templates/support.tpl diff --git a/install/include/accounts.php b/install/include/accounts.php new file mode 100644 index 00000000..d9ffbb43 --- /dev/null +++ b/install/include/accounts.php @@ -0,0 +1,87 @@ + 'define("ADMIN_RECEIVE_SUPPORT_MESSAGES", '.($_POST['admin_support_msgs'] == 'true' ? 'true' : 'false').');', + '/define\("ADMIN_ALLOW_INCOMING_RAIDS",[^)]+\);/' => 'define("ADMIN_ALLOW_INCOMING_RAIDS", '.($_POST['admin_raidable'] == 'true' ? 'true' : 'false').');', + '/define\("INCLUDE_ADMIN",[^)]+\);/' => 'define("INCLUDE_ADMIN", '.($_POST['admin_rank'] == 'true' ? 'true' : 'false').');' + ]; + + $gameConfig = preg_replace(array_keys($regexFindReplace), array_values($regexFindReplace), $gameConfig); + file_put_contents($configFile, $gameConfig); + + // create Admin user, if details were provided and was not created yet + if ( + !empty($_POST['aname']) && + !empty($_POST['aemail']) && + !empty($_POST['apass']) && + !empty($_POST['atribe']) && + strtolower($_POST['aname']) != 'multihunter' && + strtolower($_POST['aname']) != 'support' + ) { + mysqli_query($database->dblink, "INSERT INTO " . TB_PREFIX . "users SET username = '".$database->escape($_POST['aname'])."', password = '" . password_hash($_POST['apass'], PASSWORD_BCRYPT, ['cost' => 12]) . "', email = '".$database->escape($_POST['aemail'])."', tribe = ".(int) $_POST['atribe'].", access = 9, is_bcrypt = 1") OR DIE (mysqli_error($database->dblink)); + $uid = mysqli_insert_id($database->dblink); + $admin_village_created = false; + $xcoor = 50; + while (!$admin_village_created) { + $wid = $admin->getWref($xcoor++, 50); + $status = $database->getVillageState($wid); + if($status == 0) { + $database->setFieldTaken($wid); + $database->addVillage($wid, $uid, $_POST['aname'], 1); + $database->addResourceFields($wid, $database->getVillageType($wid)); + $database->addUnits($wid); + $database->addTech($wid); + $database->addABTech($wid); + $admin_village_created = true; + } + } + } + + // set up MultiHunter + $password = $_POST['mhpw']; + mysqli_query($database->dblink, "UPDATE " . TB_PREFIX . "users SET password = '" . password_hash($password, PASSWORD_BCRYPT,['cost' => 12]) . "' WHERE username = 'Multihunter'"); + $wid = $admin->getWref(0, 0); + $uid = 5; + $status = $database->getVillageState($wid); + if($status == 0) { + $database->setFieldTaken($wid); + $database->addVillage($wid, $uid, 'Multihunter', '0'); + $database->addResourceFields($wid, $database->getVillageType($wid)); + $database->addUnits($wid); + $database->addTech($wid); + $database->addABTech($wid); + } + + // set up Support + $password = $_POST['spw']; + mysqli_query($database->dblink, "UPDATE " . TB_PREFIX . "users SET password = '" . password_hash($password, PASSWORD_BCRYPT,['cost' => 12]) . "' WHERE username = 'Support'"); + + $gameinstall = 0; + header("Location: ../index.php?s=5"); + +?> \ No newline at end of file diff --git a/install/include/multihunter.php b/install/include/multihunter.php deleted file mode 100644 index 6a551611..00000000 --- a/install/include/multihunter.php +++ /dev/null @@ -1,34 +0,0 @@ - 12]) . "' WHERE username = 'Multihunter'"); - $wid = $admin->getWref(0, 0); - $uid = 5; - $status = $database->getVillageState($wid); - if($status == 0) { - $database->setFieldTaken($wid); - $database->addVillage($wid, $uid, 'Multihunter', '0'); - $database->addResourceFields($wid, $database->getVillageType($wid)); - $database->addUnits($wid); - $database->addTech($wid); - $database->addABTech($wid); - } - } - -$gameinstall = 0; - header("Location: ../index.php?s=5"); - -?> \ No newline at end of file diff --git a/install/include/support.php b/install/include/support.php deleted file mode 100644 index 6cd1bab4..00000000 --- a/install/include/support.php +++ /dev/null @@ -1,23 +0,0 @@ - 12]) . "' WHERE username = 'Support'"); - } - - $gameinstall = 0; - header("Location: ../index.php?s=6"); - -?> \ No newline at end of file diff --git a/install/index.php b/install/index.php index 5546de4a..6c6def4a 100644 --- a/install/index.php +++ b/install/index.php @@ -82,7 +82,7 @@ function proceed() {
draw(); for($i = 0; $i < ($_GET['s']+1); $i++) { $bar->tick(); @@ -114,12 +114,9 @@ function proceed() { include("templates/wdata.tpl"); break; case 4: - include("templates/multihunter.tpl"); + include("templates/accounts.tpl"); break; case 5: - include("templates/support.tpl"); - break; - case 6: include("templates/end.tpl"); break; } diff --git a/install/process.php b/install/process.php index e203f9c8..bde5b796 100755 --- a/install/process.php +++ b/install/process.php @@ -77,10 +77,8 @@ class Process { $findReplace["%SDB%"] = $_POST['sdb']; $findReplace["%PREFIX%"] = $_POST['prefix']; $findReplace["%CONNECTT%"] = $_POST['connectt']; - $findReplace["%AEMAIL%"] = $_POST['aemail']; - $findReplace["%ANAME%"] = $_POST['aname']; - $findReplace["%ASUPPMSGS%"] = ($_POST['admin_support_msgs'] == 'true' ? 'true' : 'false'); - $findReplace["%ARAIDS%"] = ($_POST['admin_raidable'] == 'true' ? 'true' : 'false'); + $findReplace["%ASUPPMSGS%"] = 'true'; + $findReplace["%ARAIDS%"] = 'false'; //$findReplace["%SUBDOM%"] = $_POST['subdom']; $findReplace["%LOGBUILD%"] = $_POST['log_build']; $findReplace["%LOGTECH%"] = $_POST['log_tech']; @@ -94,7 +92,7 @@ class Process { //$findReplace["%MINPASSLENGTH%"] = $_POST['passlength']; //$findReplace["%SPECIALCHARS%"] = $_POST['specialchars']; $findReplace["%ACTIVATE%"] = $_POST['activate']; - $findReplace["%ARANK%"] = $_POST['admin_rank']; + $findReplace["%ARANK%"] = 'false'; $findReplace["%QUEST%"] = $_POST['quest']; $findReplace["%QTYPE%"] = $_POST['qtype']; $findReplace["%BEGINNER%"] = $_POST['beginner']; diff --git a/install/templates/accounts.tpl b/install/templates/accounts.tpl new file mode 100644 index 00000000..1494c322 --- /dev/null +++ b/install/templates/accounts.tpl @@ -0,0 +1,105 @@ +

At least MultiHunter & Support password are required in this form.


"; +} + +?> + +
+ +

+ Multihunter account + + + + +
Name:
Password:
Note: Rember this password! You need it for the Admin
+

+ +

+ Support account + + + + +
Name:
Password:
Note: Rember this password! You need it for the Admin
+

+ +

+ Admin account + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Admin name:
Admin email:
Admin password:
Admin tribe: + +
Show admin in stats: + +
Include Support Messages in Admin Mailbox: + +
Allow Administrative Accounts to be Raided and Attacked: + +
Note: this will add a first user and will set them up as an Admin
Note: you can leave this section empty, if you want
+

+ +
+
+
+ +
diff --git a/install/templates/config.tpl b/install/templates/config.tpl index efb6a541..932f97ef 100644 --- a/install/templates/config.tpl +++ b/install/templates/config.tpl @@ -240,46 +240,6 @@ echo "
Error creating constant.php

-

- ADMIN ACCOUNT - - - - - - - - - - - - - - - - - - - - - -
Admin name:
Admin email:
Show admin in stats: - -
Include Support Messages in Admin Mailbox: - -
Allow Administrative Accounts to be Raided and Attacked: - -
-

SQL RELATED diff --git a/install/templates/menu.tpl b/install/templates/menu.tpl index f21ac635..24977125 100644 --- a/install/templates/menu.tpl +++ b/install/templates/menu.tpl @@ -19,25 +19,22 @@ switch($_GET['s']) { case 0: - echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Multihunter
  • Support
  • End
  • "; + echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Accounts
  • End
  • "; break; case 1: - echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Multihunter
  • Support
  • End
  • "; + echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Accounts
  • End
  • "; break; case 2: - echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Multihunter
  • Support
  • End
  • "; + echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Accounts
  • End
  • "; break; case 3: - echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Multihunter
  • Support
  • End
  • "; + echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Accounts
  • End
  • "; break; case 4: - echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Multihunter
  • Support
  • End
  • "; + echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Accounts
  • End
  • "; break; case 5: - echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Multihunter
  • Support
  • End
  • "; - break; - case 6: - echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Multihunter
  • Support
  • End
  • "; + echo "
  • Intro
  • Configuration
  • Database
  • World Data
  • Accounts
  • End
  • "; break; } diff --git a/install/templates/multihunter.tpl b/install/templates/multihunter.tpl deleted file mode 100644 index 942536ae..00000000 --- a/install/templates/multihunter.tpl +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - -

    - Create Multihunter account -

    - - - -
    Name:
    Password:
    Note: Rember this password! You need it for the ACP
    -

    - -
    -
    - - -
    diff --git a/install/templates/support.tpl b/install/templates/support.tpl deleted file mode 100644 index 6ffc5c7c..00000000 --- a/install/templates/support.tpl +++ /dev/null @@ -1,36 +0,0 @@ - - - - -
    - -

    - Create Support account - - - - -
    Name:
    Password:
    Note: Rember this password! You need it for the ACP
    -

    - -
    -
    -
    - -