race at registration

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • race at registration

      hey im trying to have race selection at registration.
      i have the race module, also put race in uni1_user just after auth.
      then in login folder//////reg.php i add code so far but stuck on what to do next ...thank in advance for the help

      $this->assign(array(
      'raceSelect'=> $raceSelect,


      line :122-$race = HTTP::_GP('race', '');


      $sql = "INSERT INTO %%USERS_VALID%% SET
      `race` = :race,

      $db->insert($sql, array(
      ':race' => $race,
    • Here are the other steps to do in addition to the one you have already done

      search

      PHP Source Code: ShowVertifyPage.class.php

      1. list($userID, $planetID) = PlayerUtil::createPlayer($userData['universe'], $userData['userName'], $userData['password'], $userData['email'], $userData['language']);
      Replace by

      PHP Source Code: ShowVertifyPage.class.php

      1. list($userID, $planetID) = PlayerUtil::createPlayer($userData['universe'], $userData['userName'], $userData['password'], $userData['email'], $userData['race'], $userData['language']);
      search

      PHP Source Code: PlayerUtil.class.php

      1. static public function createPlayer($universe, $userName, $userPassword, $userMail, $userLanguage = NULL, $galaxy = NULL, $system = NULL, $position = NULL, $name = NULL, $authlevel = 0, $userIpAddress = NULL)
      replace by

      PHP Source Code

      1. static public function createPlayer($universe, $userName, $userPassword, $userMail, $race, $userLanguage = NULL, $galaxy = NULL, $system = NULL, $position = NULL, $name = NULL, $authlevel = 0, $userIpAddress = NULL)
      serach

      PHP Source Code: PlayerUtil.class.php

      1. $params = array(
      2. ':username' => $userName,
      3. ':email' => $userMail,
      4. ':email2' => $userMail,
      5. ':authlevel' => $authlevel,
      6. ':universe' => $universe,
      7. ':language' => $userLanguage,
      8. ':registerAddress' => !empty($userIpAddress) ? $userIpAddress : Session::getClientIp(),
      9. ':onlinetime' => TIMESTAMP,
      10. ':registerTimestamp' => TIMESTAMP,
      11. ':password' => $userPassword,
      12. ':dpath' => DEFAULT_THEME,
      13. ':timezone' => $config->timezone,
      14. ':nameLastChanged' => 0,
      15. ':darkmatter_start' => $config->darkmatter_start,
      16. );
      17. $sql = 'INSERT INTO %%USERS%% SET
      18. username = :username,
      19. email = :email,
      20. email_2 = :email2,
      21. authlevel = :authlevel,
      22. universe = :universe,
      23. lang = :language,
      24. ip_at_reg = :registerAddress,
      25. onlinetime = :onlinetime,
      26. register_time = :registerTimestamp,
      27. password = :password,
      28. dpath = :dpath,
      29. timezone = :timezone,
      30. uctime = :nameLastChanged,
      31. darkmatter = :darkmatter_start;';
      Display All
      replace by

      PHP Source Code: PlayerUtil.class.php

      1. $params = array(
      2. ':username' => $userName,
      3. ':email' => $userMail,
      4. ':email2' => $userMail,
      5. ':authlevel' => $authlevel,
      6. ':universe' => $universe,
      7. ':language' => $userLanguage,
      8. ':registerAddress' => !empty($userIpAddress) ? $userIpAddress : Session::getClientIp(),
      9. ':onlinetime' => TIMESTAMP,
      10. ':registerTimestamp' => TIMESTAMP,
      11. ':password' => $userPassword,
      12. ':dpath' => DEFAULT_THEME,
      13. ':timezone' => $config->timezone,
      14. ':nameLastChanged' => 0,
      15. ':darkmatter_start' => $config->darkmatter_start,
      16. ':race' => $race,
      17. );
      18. $sql = 'INSERT INTO %%USERS%% SET
      19. username = :username,
      20. email = :email,
      21. email_2 = :email2,
      22. authlevel = :authlevel,
      23. universe = :universe,
      24. lang = :language,
      25. ip_at_reg = :registerAddress,
      26. onlinetime = :onlinetime,
      27. register_time = :registerTimestamp,
      28. password = :password,
      29. dpath = :dpath,
      30. timezone = :timezone,
      31. uctime = :nameLastChanged,
      32. darkmatter = :darkmatter_start,
      33. race = :race;';
      Display All
      enjoy
    • thank you for the help, the above went without issue, but i get an error in the showreg. when i pull it up
      Undefined variable: raceSelect

      if i delete the line no errors but i also have no selection

      in the tpl i put line

      {if count($raceSelect) > 1}<div class="blocks">
      <span class="lable">{$LNG.registerRace}</span>
      <select name="race" id="race" class="sel_uni">{html_options options=$raceSelect}</select>
      {if !empty($error.race)}
      <span class="error errorRace"></span>
      {/if}


      thanks in advance
    • if you want to use <select name="race" id="race" class="sel_uni">{html_options options=$raceSelect}</select>
      your $raceSelect variable must return an array.
    • $this->assign(array(
      'referralData'=> $referralData,
      'accountName'=> $accountName,
      'externalAuth'=> $externalAuth,
      'universeSelect' => $universeSelect,
      'rascSelect' => $raceSelect,
    • thats as far as i got on reg php page

      on function show() i havent put anything yet

      PHP Source Code

      1. <?php
      2. /**
      3. * 2Moons
      4. * by Jan-Otto Kröpke 2009-2016
      5. *
      6. * For the full copyright and license information, please view the LICENSE
      7. *
      8. * @package 2Moons
      9. * @author Jan-Otto Kröpke <slaver7@gmail.com>
      10. * @copyright 2009 Lucky
      11. * @copyright 2016 Jan-Otto Kröpke <slaver7@gmail.com>
      12. * @licence MIT
      13. * @version 1.8.0
      14. * @link https://github.com/jkroepke/2Moons
      15. */
      16. class ShowRegisterPage extends AbstractLoginPage
      17. {
      18. function __construct()
      19. {
      20. parent::__construct();
      21. $this->setWindow('light');
      22. }
      23. function show()
      24. {
      25. global $LNG;
      26. $universeSelect = array();
      27. $referralData = array('id' => 0, 'name' => '');
      28. $accountName = "";
      29. $externalAuth = HTTP::_GP('externalAuth', array());
      30. $referralID = HTTP::_GP('referralID', 0);
      31. foreach(Universe::availableUniverses() as $uniId)
      32. {
      33. $config = Config::get($uniId);
      34. $universeSelect[$uniId] = $config->uni_name.($config->game_disable == 0 || $config->reg_closed == 1 ? $LNG['uni_closed'] : '');
      35. }
      36. if(!isset($externalAuth['account'], $externalAuth['method']))
      37. {
      38. $externalAuth['account'] = 0;
      39. $externalAuth['method'] = '';
      40. }
      41. else
      42. {
      43. $externalAuth['method'] = strtolower(str_replace(array('_', '\\', '/', '.', "\0"), '', $externalAuth['method']));
      44. }
      45. if(!empty($externalAuth['account']) && file_exists('includes/extauth/'.$externalAuth['method'].'.class.php'))
      46. {
      47. $path = 'includes/extauth/'.$externalAuth['method'].'.class.php';
      48. require($path);
      49. $methodClass = ucwords($externalAuth['method']).'Auth';
      50. /** @var $authObj externalAuth */
      51. $authObj = new $methodClass;
      52. if(!$authObj->isActiveMode())
      53. {
      54. $this->redirectTo('index.php?code=5');
      55. }
      56. if(!$authObj->isValid())
      57. {
      58. $this->redirectTo('index.php?code=4');
      59. }
      60. $accountData = $authObj->getAccountData();
      61. $accountName = $accountData['name'];
      62. }
      63. $config = Config::get();
      64. if($config->ref_active == 1 && !empty($referralID))
      65. {
      66. $db = Database::get();
      67. $sql = "SELECT username FROM %%USERS%% WHERE id = :referralID AND universe = :universe;";
      68. $referralAccountName = $db->selectSingle($sql, array(
      69. ':referralID' => $referralID,
      70. ':universe' => Universe::current()
      71. ), 'username');
      72. if(!empty($referralAccountName))
      73. {
      74. $referralData = array('id' => $referralID, 'name' => $referralAccountName);
      75. }
      76. }
      77. $this->assign(array(
      78. 'referralData' => $referralData,
      79. 'accountName' => $accountName,
      80. 'externalAuth' => $externalAuth,
      81. 'universeSelect' => $universeSelect,
      82. 'raceSelect' => $raceSelect,
      83. 'registerRulesDesc' => sprintf($LNG['registerRulesDesc'], '<a href="index.php?page=rules">'.$LNG['menu_rules'].'</a>')
      84. ));
      85. $this->display('page.register.default.tpl');
      86. }
      87. function send()
      88. {
      89. global $LNG;
      90. $config = Config::get();
      91. if($config->game_disable == 0 || $config->reg_closed == 1)
      92. {
      93. $this->printMessage($LNG['registerErrorUniClosed'], array(array(
      94. 'label' => $LNG['registerBack'],
      95. 'url' => 'javascript:window.history.back()',
      96. )));
      97. }
      98. $userName = HTTP::_GP('username', '', UTF8_SUPPORT);
      99. $password = HTTP::_GP('password', '', true);
      100. $password2 = HTTP::_GP('passwordReplay', '', true);
      101. $mailAddress = HTTP::_GP('email', '');
      102. $mailAddress2 = HTTP::_GP('emailReplay', '');
      103. $rulesChecked = HTTP::_GP('rules', 0);
      104. $language = HTTP::_GP('lang', '');
      105. $race = HTTP::_GP('race', '');
      106. $referralID = HTTP::_GP('referralID', 0);
      107. $externalAuth = HTTP::_GP('externalAuth', array());
      108. if(!isset($externalAuth['account'], $externalAuth['method']))
      109. {
      110. $externalAuthUID = 0;
      111. $externalAuthMethod = '';
      112. }
      113. else
      114. {
      115. $externalAuthUID = $externalAuth['account'];
      116. $externalAuthMethod = strtolower(str_replace(array('_', '\\', '/', '.', "\0"), '', $externalAuth['method']));
      117. }
      118. $errors = array();
      119. if(empty($userName)) {
      120. $errors[] = $LNG['registerErrorUsernameEmpty'];
      121. }
      122. if(!PlayerUtil::isNameValid($userName)) {
      123. $errors[] = $LNG['registerErrorUsernameChar'];
      124. }
      125. if(strlen($password) < 6) {
      126. $errors[] = $LNG['registerErrorPasswordLength'];
      127. }
      128. if($password != $password2) {
      129. $errors[] = $LNG['registerErrorPasswordSame'];
      130. }
      131. if(!PlayerUtil::isMailValid($mailAddress)) {
      132. $errors[] = $LNG['registerErrorMailInvalid'];
      133. }
      134. if(empty($mailAddress)) {
      135. $errors[] = $LNG['registerErrorMailEmpty'];
      136. }
      137. if($mailAddress != $mailAddress2) {
      138. $errors[] = $LNG['registerErrorMailSame'];
      139. }
      140. if($rulesChecked != 1) {
      141. $errors[] = $LNG['registerErrorRules'];
      142. }
      143. $db = Database::get();
      144. $sql = "SELECT (
      145. SELECT COUNT(*)
      146. FROM %%USERS%%
      147. WHERE universe = :universe
      148. AND username = :userName
      149. ) + (
      150. SELECT COUNT(*)
      151. FROM %%USERS_VALID%%
      152. WHERE universe = :universe
      153. AND username = :userName
      154. ) as count;";
      155. $countUsername = $db->selectSingle($sql, array(
      156. ':universe' => Universe::current(),
      157. ':userName' => $userName,
      158. ), 'count');
      159. $sql = "SELECT (
      160. SELECT COUNT(*)
      161. FROM %%USERS%%
      162. WHERE universe = :universe
      163. AND (
      164. email = :mailAddress
      165. OR email_2 = :mailAddress
      166. )
      167. ) + (
      168. SELECT COUNT(*)
      169. FROM %%USERS_VALID%%
      170. WHERE universe = :universe
      171. AND email = :mailAddress
      172. ) as count;";
      173. $countMail = $db->selectSingle($sql, array(
      174. ':universe' => Universe::current(),
      175. ':mailAddress' => $mailAddress,
      176. ), 'count');
      177. if($countUsername!= 0) {
      178. $errors[] = $LNG['registerErrorUsernameExist'];
      179. }
      180. if($countMail != 0) {
      181. $errors[] = $LNG['registerErrorMailExist'];
      182. }
      183. if ($config->capaktiv === '1')
      184. {
      185. require('includes/libs/reCAPTCHA/autoload.php');
      186. $recaptcha = new \ReCaptcha\ReCaptcha($config->capprivate);
      187. $resp = $recaptcha->verify(HTTP::_GP('g-recaptcha-response', ''), Session::getClientIp());
      188. if (!$resp->isSuccess())
      189. {
      190. $errors[] = $LNG['registerErrorCaptcha'];
      191. }
      192. }
      193. if (!empty($errors)) {
      194. $this->printMessage(implode("<br>\r\n", $errors), array(array(
      195. 'label' => $LNG['registerBack'],
      196. 'url' => 'javascript:window.history.back()',
      197. )));
      198. }
      199. $path = 'includes/extauth/'.$externalAuthMethod.'.class.php';
      200. if(!empty($externalAuth['account']) && file_exists($path))
      201. {
      202. require($path);
      203. $methodClass = ucwords($externalAuthMethod).'Auth';
      204. /** @var $authObj externalAuth */
      205. $authObj = new $methodClass;
      206. $externalAuthUID = 0;
      207. if($authObj->isActiveMode() && $authObj->isValid()) {
      208. $externalAuthUID = $authObj->getAccount();
      209. }
      210. }
      211. if($config->ref_active == 1 && !empty($referralID))
      212. {
      213. $sql = "SELECT COUNT(*) as state FROM %%USERS%% WHERE id = :referralID AND universe = :universe;";
      214. $Count = $db->selectSingle($sql, array(
      215. ':referralID' => $referralID,
      216. ':universe' => Universe::current()
      217. ), 'state');
      218. if($Count == 0)
      219. {
      220. $referralID = 0;
      221. }
      222. }
      223. else
      224. {
      225. $referralID = 0;
      226. }
      227. $validationKey = md5(uniqid('2m'));
      228. $sql = "INSERT INTO %%USERS_VALID%% SET
      229. `userName` = :userName,
      230. `validationKey` = :validationKey,
      231. `password` = :password,
      232. `email` = :mailAddress,
      233. `date` = :timestamp,
      234. `ip` = :remoteAddr,
      235. `language` = :language,
      236. `race` = :race,
      237. `universe` = :universe,
      238. `referralID` = :referralID,
      239. `externalAuthUID` = :externalAuthUID,
      240. `externalAuthMethod` = :externalAuthMethod;";
      241. $db->insert($sql, array(
      242. ':userName' => $userName,
      243. ':validationKey' => $validationKey,
      244. ':password' => PlayerUtil::cryptPassword($password),
      245. ':mailAddress' => $mailAddress,
      246. ':timestamp' => TIMESTAMP,
      247. ':remoteAddr' => Session::getClientIp(),
      248. ':language' => $language,
      249. ':race' => $race,
      250. ':universe' => Universe::current(),
      251. ':referralID' => $referralID,
      252. ':externalAuthUID' => $externalAuthUID,
      253. ':externalAuthMethod' => $externalAuthMethod
      254. ));
      255. $validationID = $db->lastInsertId();
      256. $verifyURL = 'index.php?page=vertify&i='.$validationID.'&k='.$validationKey;
      257. if($config->user_valid == 0 || !empty($externalAuthUID))
      258. {
      259. $this->redirectTo($verifyURL);
      260. }
      261. else
      262. {
      263. require 'includes/classes/Mail.class.php';
      264. $MailRAW = $LNG->getTemplate('email_vaild_reg');
      265. $MailContent = str_replace(array(
      266. '{USERNAME}',
      267. '{PASSWORD}',
      268. '{GAMENAME}',
      269. '{VERTIFYURL}',
      270. '{GAMEMAIL}',
      271. ), array(
      272. $userName,
      273. $password,
      274. $config->game_name.' - '.$config->uni_name,
      275. HTTP_PATH.$verifyURL,
      276. $config->smtp_sendmail,
      277. ), $MailRAW);
      278. $subject = sprintf($LNG['registerMailVertifyTitle'], $config->game_name);
      279. Mail::send($mailAddress, $userName, $subject, $MailContent);
      280. $this->printMessage($LNG['registerSendComplete']);
      281. }
      282. }
      283. }
      Display All
    • already it can't work simply because your variable $raceSelect is not defined.
      In addition it must return the list of your different races in the form of an array
    • i looked in the old version that has this and it has this

      while ($raceWhile = $GLOBALS['DATABASE']->FetchArray($raceAllConfig))
      {
      $raceSelect[$raceWhile['race_id']] = $raceWhile['race_name'];
    • you want to put a theme by race?

      here is the correct code of course I don't know your SQL

      PHP Source Code

      1. $raceSelect = [];
      2. $resultRace = $db->select("Your sql queries");
      3. foreach($resultRace as $raceWhile) {
      4. $raceSelect[$raceWhile['race_id']] = $raceWhile['race_name'];
      5. }
    • ty for your help, i really appreciated it, but i get error after error. i guess it was a good idea only i 'll give it up for now as im not able to properly code it, i appaologize for wasting your time... but thank you