PHP game server for TerranQuest. https://terranquest.net

login.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. require 'required.php';
  3. if (is_empty($VARS['user'])) {
  4. sendError(USERNAME_MISSING, true);
  5. }
  6. if (is_empty($VARS['pass'])) {
  7. sendError(PASSWORD_MISSING, true);
  8. }
  9. $VARS['user'] = strtolower(str_replace(" ", "", $VARS['user']));
  10. /* Insert code to check login here */
  11. /* ------------------------------- */
  12. $loginok = file_get_contents("https://sso.netsyms.com/api/simpleauth.php?get=1&user=" . urlencode($VARS['user']) . "&pass=" . $VARS['pass']);
  13. if ($loginok != "OK") {
  14. sendError(str_replace("Error: ", "", $loginok), true);
  15. }
  16. /* Put code here to get the unique UUID (internal ID) for the player */
  17. $guid = file_get_contents("https://sso.netsyms.com/api/getguid.php?user=" . urlencode($VARS['user']));
  18. /* ------------------------------- */
  19. if (is_empty($guid)) {
  20. sendError(ACCOUNT_MISSING, true);
  21. }
  22. if (!$database->has('players', ['uuid' => $guid])) {
  23. $database->insert('players', ['uuid' => $guid, 'level' => 1.0, 'energy' => 100, 'maxenergy' => 100, '#lastping' => 'NOW()', 'nickname' => $VARS['user']]);
  24. }
  25. // Setup the session
  26. $_SESSION['username'] = $VARS['user'];
  27. $_SESSION['guid'] = $_SESSION['uuid'] = $guid;
  28. $_SESSION['loggedin'] = true;
  29. // Give out the beta tester badge and stuff to people
  30. if (BETA_MODE) {
  31. if (!$database->has('player_badges', ["AND" => ['playeruuid' => $guid, 'badgeid' => 1]])) {
  32. $database->insert('player_badges', ['playeruuid' => $guid, 'badgeid' => 1, '#gotdate' => "NOW()"]);
  33. // Give some free credits as thanks
  34. $database->update('players', ['credits' => 500], ['uuid' => $guid]);
  35. }
  36. }
  37. sendOK();