Guest User

Untitled

a guest
Jun 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. <?
  2. /* */
  3. /* timestamp thingy */
  4. /*
  5. */
  6.  
  7. mysql_query("SET AUTOCOMMIT = 0;");
  8. mysql_query("START TRANSACTION;");
  9. $sqlquery = mysql_query("SELECT timer FROM cu_users WHERE userid=$user FOR UPDATE");
  10. $lastarmourupdate = mysql_result($sqlquery , 0, 'timer');
  11. //echo " laupvar $lastarmourupdate "; //DEBUG!
  12. //if it's 0, do initial timestampupdate...
  13. if ($lastarmourupdate==0){
  14. //setting the timestamp from 0 to NOW, UNIX_TIMESTAMP transforms the date into seconds.
  15. $query=sprintf("UPDATE cu_users SET `timer` = UNIX_TIMESTAMP(NOW()) WHERE userid = '%s'",
  16. mysql_real_escape_string($user));
  17. mysql_query($query);
  18. mysql_query("COMMIT");
  19. } else {
  20. //querying database to see the difference between the current databasetime and the savedtimestamp
  21. //$timedifference returns the elapsed time in Seconds..
  22. $query=sprintf("SELECT UNIX_TIMESTAMP(NOW()) - '%s'", mysql_real_escape_string($lastarmourupdate));
  23. $timedifference = mysql_result(mysql_query($query),0);
  24. //echo "timedifference $timedifference"; //DEBUG!
  25. //check if timedifference is bigger than 1 hours (3600 seconds)
  26. if ($timedifference >= 300){
  27. //if so, calculate the amount of armour the player would recieve..
  28. $baseamount = 1+ floor($timedifference / 300); //1 + rounded down armour...
  29. $query=sprintf("UPDATE cu_users SET `uhealth`=`uhealth`+'%s',
  30. `uenergy`=`uenergy`+'%s'
  31. WHERE `userid`='%s'",
  32. mysql_real_escape_string($baseamount * 10),
  33. mysql_real_escape_string($baseamount),
  34. mysql_real_escape_string($user));
  35. // echo "Query $query" ; //DEBUG!
  36. mysql_query($query);
  37. //also calculate the time for the new timestamp using MODULA
  38. $left_over_time = ($timedifference % 300);
  39. //update players set a new timestamp
  40. $query = sprintf("UPDATE cu_users SET `timer`= '%s' WHERE `userid`='%s'",
  41. mysql_real_escape_string('UNIX_TIMESTAMP(NOW()' - '.$left_over_time'),
  42. mysql_real_escape_string($user));
  43. mysql_query($query);
  44. mysql_query("COMMIT");
  45. }
  46. else
  47. {
  48. mysql_query("ROLLBACK");
  49. }
  50. mysql_query("SET AUTOCOMMIT = 1;");
  51. }
  52. /* */
  53. /* end of timestamp thingy */
  54. /* */
  55. $result = mysql_query("SELECT uhealth, uenergy, umaxhealth, umaxenergy FROM `cu_users` WHERE `userid` = $user");
  56. $row = mysql_fetch_assoc($result);
  57. $thp = $row['uhealth'];
  58. $tmhp = $row['umaxhealth'];
  59. $ten = $row['uenergy'];
  60. $tmen = $row['umaxenergy'];
  61. if ($thp > $tmhp)
  62. {
  63. mysql_query("UPDATE cu_users SET uhealth = (umaxhealth) WHERE userid = $user");
  64. }
  65. if ($ten > $tmen)
  66. {
  67. mysql_query("UPDATE cu_users SET uenergy = (umaxenergy) WHERE userid = $user");
  68. }
Add Comment
Please, Sign In to add comment