Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. var express = require('express');
  2. var router = express.Router();
  3. var md5 = require('md5');
  4. var mysql = require('mysql');
  5. var connection = mysql.createConnection({
  6. host: '134.255.224.163',
  7. user: '',
  8. password: '',
  9. database: 'account'
  10. });
  11.  
  12. let serverid = 4990;
  13. let apikey = "lNLJEn7ZfIu8bY4wCBhySG35zaq6pXsU";
  14. let coins = 30;
  15.  
  16. function mysqlEscape(stringToEscape){
  17. return stringToEscape
  18. .replace("\\", "\\\\")
  19. .replace("\'", "\\\'")
  20. .replace("\"", "\\\"")
  21. .replace("\n", "\\\n")
  22. .replace("\r", "\\\r")
  23. .replace("\x00", "\\\x00")
  24. .replace("\x1a", "\\\x1a");
  25. }
  26.  
  27. /* GET home page. */
  28. router.post('/', function (req, res, next) {
  29. let apidata = req.body;
  30. if (req.body.hash === md5(serverid + apikey + apidata.userid + apidata.timestamp)) { // Vote stimmt dem Hash überein = Vote true
  31. let today = new Date();
  32. if (today.getDay() == 1) {
  33. coins = 50;
  34. } else {
  35. coins = 30;
  36. }
  37. console.log("userid: " + apidata.userid + " voted at: " + apidata.timestamp); // Mysql Statement
  38. connection.query('UPDATE account SET coins = coins +' +mysqlEscape(coins)+ ', votelink1=1 WHERE login = "'+mysqlEscape(apidata.userid)+'" and votelink1 = 0;', function (error) {
  39. if (error) throw error;
  40. console.log('Updated userids coins: '+apidata.userid);
  41. });
  42. } else {
  43. //Vote Fail
  44. }
  45. res.status(200).send("OK");
  46. });
  47.  
  48. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement