Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.50 KB | None | 0 0
  1. /*
  2. Initalizing packages
  3. */
  4. var fs = require('fs');
  5. var request = require('request');
  6. var config = require('./config.json');
  7. var CryptoJS = require("crypto-js");
  8. var log4js = require('log4js');
  9. var express = require('express');
  10. var sha256 = require('sha256');
  11. var math = require('mathjs');
  12. var app = express();
  13.  
  14. var server = require('http').createServer();
  15. var io = require('socket.io')(server);
  16. server.listen(8880);
  17.  
  18.  
  19. updateLog(time());
  20. function updateLog(time) {
  21. log4js.configure({
  22. appenders: [
  23. { type: 'console' },
  24. { type: 'file', filename: 'logs/site_'+time+'.log' }
  25. ]
  26. });
  27. }
  28.  
  29. var admin_steamid = '76561198130247489';
  30.  
  31. var logger = log4js.getLogger();
  32.  
  33. var mysql = require('mysql');
  34. var db_config = {
  35. //debug: true,
  36. host: config.options.sql['host'],
  37. user: config.options.sql['username'],
  38. password: config.options.sql['password'],
  39. database: config.options.sql['database'],
  40. supportBigNumbers: true
  41. };
  42. var pool;
  43. handleDisconnect();
  44.  
  45. process.on('uncaughtException', function (err) {
  46. logger.error('Strange error');
  47. logger.error(err);
  48. });
  49.  
  50. //GAME INFO
  51. var AppID = 730;
  52. var ContextID = 2;
  53. var minDep = config.options.minDeposit;
  54.  
  55.  
  56. //ROULETTE
  57. var currentMode = 'NONE';
  58. var currentColors = {};
  59. var betTimes = {};
  60. var usersBalance = {};
  61. var currentSums = {
  62. 'red': 0,
  63. 'blue': 0,
  64. 'green': 0,
  65. 'black': 0
  66. };
  67. var currentBets = [];
  68. var currentTimer = 30;
  69. var currentLastNumber = -1;
  70. var currentLastWooble = -1;
  71. var currentHash = "";
  72. var currentSecret = "";
  73. var currentLottery = "";
  74. var lastRolls = [];
  75. var withdrawItems = [];
  76.  
  77. var proxies = config.proxies;
  78.  
  79. var inventoryTimer = {};
  80. var socketBySteam = {};
  81.  
  82. var antiFlood = {};
  83. var timesFlooding = {};
  84.  
  85. var inventoryUser = {};
  86.  
  87. //CHAT FUNCTIONS
  88. var chatMessages = [];
  89. var usersOnline = {};
  90. var antiSpamChat = {};
  91. //CHAT FUNCTIONS
  92.  
  93. startRoulette();
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. io.on('connection', function(socket) {
  101. socket.on('hash', function(m) {
  102. var address = socket.handshake.address;
  103. addHistory(socket);
  104.  
  105. if(!usersOnline[address])
  106. {
  107. usersOnline[address] = 1;
  108. }
  109. if(m.hash)
  110. {
  111. pool.query('SELECT steamid, refmoney, tlink FROM users WHERE hash = ' + pool.escape(m.hash), function(err, row) {
  112. if(err) throw err;
  113. if(row.length == 0) return;
  114.  
  115.  
  116. usersBalance[row[0].steamid] = {
  117. 'balance': row[0].refmoney
  118. }
  119.  
  120. if(socketBySteam.hasOwnProperty(row[0].steamid))
  121. {
  122. delete socketBySteam[row[0].steamid];
  123. socketBySteam[row[0].steamid] = {
  124. 'info': socket.id
  125. };
  126. }
  127. else
  128. {
  129. socketBySteam[row[0].steamid] = {
  130. 'info': socket.id
  131. };
  132. }
  133.  
  134. currentBets.forEach(function(item) {
  135. socket.emit('roulette_newbet', item.bet, item.color, item.user, item.avatar, item.name);
  136. });
  137.  
  138. var emitRolls = lastRolls.join('/');
  139. socket.emit('roulette_addroll', emitRolls);
  140. io.sockets.emit('connections', Object.keys(usersOnline).length);
  141. socket.emit('roulette_hash', currentHash);
  142. socket.emit('roulette_bets', currentSums);
  143. socket.emit('connected', row[0].refmoney, row[0].steamid, row[0].tlink, currentLastNumber, currentLastWooble);
  144. socket.emit('roulette_start', currentTimer);
  145. });
  146. }
  147. else
  148. {
  149. currentBets.forEach(function(item) {
  150. socket.emit('roulette_newbet', item.bet, item.color, item.user, item.avatar, item.name);
  151. });
  152.  
  153. var emitRolls = lastRolls.join('/');
  154. socket.emit('roulette_addroll', emitRolls);
  155. io.sockets.emit('connections', Object.keys(usersOnline).length);
  156. socket.emit('roulette_hash', currentHash);
  157. socket.emit('roulette_bets', currentSums);
  158. socket.emit('connected', 0, 'not logged in', 'not logged in', currentLastNumber, currentLastWooble);
  159. socket.emit('roulette_start', currentTimer);
  160. }
  161. });
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. socket.on('roulette_addbet', function(value, bet, hash) {
  170. logger.trace(value + ' ' + bet);
  171. if(currentMode == 'WAITING')
  172. {
  173. pool.query('SELECT name, avatar, steamid, refmoney FROM users WHERE hash = ' + pool.escape(hash), function(err, row) {
  174. if(err) throw err;
  175. if(row.length == 0) return;
  176.  
  177. if(value > row[0].refmoney)
  178. {
  179. socket.emit('msg', {
  180. tip: 'error',
  181. msg: 'You do not have enough money!'
  182. });
  183. return;
  184. }
  185.  
  186. if(value <= 0 || value >= 500000)
  187. {
  188. socket.emit('msg', {
  189. tip: 'error',
  190. msg: 'You can bet more than $0.01 and less than $500 coins!'
  191. });
  192. return;
  193. }
  194.  
  195. if(!currentColors.hasOwnProperty(row[0].steamid))
  196. {
  197. currentColors[row[0].steamid] = {
  198. 'red': 0,
  199. 'blue': 0,
  200. 'green': 0,
  201. 'black': 0
  202. };
  203. }
  204.  
  205. if(currentColors[row[0].steamid]['red'] == 1 && bet == 'red')
  206. {
  207. socket.emit('msg', {
  208. tip: 'error',
  209. msg: 'You can\'t bet on same color twice!'
  210. });
  211. return;
  212. }
  213. else if(currentColors[row[0].steamid]['blue'] == 1 && bet == 'blue')
  214. {
  215. socket.emit('msg', {
  216. tip: 'error',
  217. msg: 'You can\'t bet on same color twice!'
  218. });
  219. return;
  220. }
  221. else if(currentColors[row[0].steamid]['green'] == 1 && bet == 'green')
  222. {
  223. socket.emit('msg', {
  224. tip: 'error',
  225. msg: 'You can\'t bet on same color twice!'
  226. });
  227. return;
  228. }
  229. else if(currentColors[row[0].steamid]['black'] == 1 && bet == 'black')
  230. {
  231. socket.emit('msg', {
  232. tip: 'error',
  233. msg: 'You can\'t bet on same color twice!'
  234. });
  235. return;
  236. }
  237. else
  238. {
  239.  
  240. pool.query('UPDATE users SET refmoney = refmoney - ' + pool.escape(value) + ' WHERE steamid = ' + pool.escape(row[0].steamid), function(er, ro) {
  241. if(er) throw er;
  242. if(ro.length == 0) return;
  243. pool.query('INSERT INTO bets SET user = ' + pool.escape(row[0].steamid) + ', bettime=UNIX_TIMESTAMP(), color = ' + pool.escape(bet) + ', amount = ' + pool.escape(value) + ', won = 0', function(e, r) {
  244. if(e) throw e;
  245. if(r.length == 0) return;
  246.  
  247. pool.query('UPDATE info SET `value` = `value` + ' + pool.escape(value) + ' WHERE name = "roulette"');
  248.  
  249. getBalance(socket, row[0].steamid);
  250.  
  251. currentBets.push({
  252. "id": r.insertId,
  253. "bet": value,
  254. "color": bet,
  255. "user": row[0].steamid,
  256. "avatar": row[0].avatar,
  257. "name": row[0].name
  258. });
  259.  
  260. if(!betTimes.hasOwnProperty(row[0].steamid))
  261. {
  262. betTimes[row[0].steamid] = 0;
  263. betTimes[row[0].steamid] += 1;
  264. }
  265. else
  266. {
  267. betTimes[row[0].steamid] += 1;
  268. }
  269.  
  270. currentSums[bet] += value;
  271. currentColors[row[0].steamid][bet] = 1;
  272.  
  273. io.sockets.emit('roulette_newbet', value, bet, row[0].steamid, row[0].avatar, row[0].name);
  274. socket.emit('msg', {
  275. tip: 'alert',
  276. msg: 'You successfully placed bet #' + r.insertId + ' (' + betTimes[row[0].steamid] +'/3)'
  277. });
  278. io.sockets.emit('roulette_bets', currentSums);
  279. });
  280. });
  281. }
  282. });
  283. }
  284. });
  285.  
  286. //CHAT FUNCTIONS
  287. socket.on('nMsg', function(m)  {
  288. var mesaj = m.message;
  289. var utilizator = m.user;
  290. var hide = 0;
  291. var address = socket.client.request.headers['x-forwarded-for'] || socket.request.connection.remoteAddress;
  292.  
  293. pool.query('SELECT `name`,`avatar`,`steamid`,`admin`,`mute` FROM `users` WHERE `hash` = ' + pool.escape(utilizator), function(err, res) {
  294. if (err) throw err;
  295. var row = res;
  296.  
  297. if (!res[0]) return err;
  298.  
  299. if (mesaj.length > 128 || mesaj.length < 6 && res[0].admin != 1) {
  300. socket.emit('msg', {
  301. tip: 'alert',
  302. msg: 'Error: Minimum length 6 and maximum length 128 to send a message.'
  303. });
  304. return;
  305. } else {
  306. if (antiSpamChat[res[0].steamid] + 2 >= time() && res[0].admin != 1) {
  307. socket.emit('msg', {
  308. tip: 'alert',
  309. msg: 'Error: You need to wait before sending another message.'
  310. });
  311. return;
  312. } else {
  313. antiSpamChat[res[0].steamid] = time();
  314. }
  315.  
  316. var caca = null;
  317. if (caca = /^\/clear/.exec(mesaj)) {
  318. if (row[0].admin == 1 || row[0].admin == 92) {
  319. io.sockets.emit('addMessage', {
  320. tip: 'clear',
  321. name: 'Alert',
  322. rank: '0',
  323. avatar: 'http://services.imobbr.com/galeria/78/avatar.png',
  324. msg: 'Chat was cleared by Admin ' + row[0].name + '.'
  325. });
  326.  
  327. chatMessages = [];
  328. logger.trace('Chat: Cleared by Admin ' + row[0].name + '.');
  329. }
  330. } else if (caca = /^\/mute ([0-9]*) ([0-9]*)/.exec(mesaj)) {
  331. if (row[0].admin == 1 || row[0].admin == 92) {
  332. var t = time();
  333. pool.query('UPDATE `users` SET `mute` = ' + pool.escape(parseInt(t) + parseInt(caca[2])) + ' WHERE `steamid` = ' + pool.escape(caca[1]), function(err2, row2) {
  334. if (err2) throw err2;
  335. if (row2.affectedRows == 0) {
  336. socket.emit('msg', {
  337. tip: 'alert',
  338. msg: 'Steamid not found in database.'
  339. });
  340. logger.trace('Mute: Steamid not found in database (' + caca[1] + ').');
  341. return;
  342. }
  343.  
  344. socket.emit('msg', {
  345. tip: 'alert',
  346. msg: 'You have muted user for ' + caca[2] + ' seconds.'
  347. });
  348. logger.trace('Mute: Steamid ' + caca[1] + ' has been muted for ' + caca[2] + ' seconds by ' + row[0].name + ' (' + row[0].steamid + ').');
  349. });
  350. }
  351. } else if (caca = /^\/wload/.exec(mesaj)) {
  352. if (row[0].admin == 1) {
  353.  
  354. }
  355. } else {
  356.  
  357. if (row[0].mute > time() && row[0].mute != 0) {
  358. socket.emit('msg', {
  359. tip: 'alert',
  360. msg: 'You are muted (seconds remaining: ' + parseInt(row[0].mute - time()) + ').'
  361. });
  362. logger.trace('Mute: ' + row[0].name + ' (' + row[0].steamid + ') tried to speak (' + mesaj + ') while muted (seconds remaining: ' + parseInt(row[0].mute - time()) + ').');
  363. return;
  364. }
  365.  
  366. if (chatMessages.length > 20) {
  367. chatMessages.shift();
  368. }
  369.  
  370.  
  371. chatMessages.push({
  372. name: res[0].name,
  373. avatar: res[0].avatar,
  374. steamid: res[0].steamid,
  375. rank: res[0].admin,
  376. message: mesaj
  377. });
  378.  
  379. io.sockets.emit('addMessage', {
  380. msg: mesaj,
  381. avatar: res[0].avatar,
  382. steamid: res[0].steamid,
  383. rank: res[0].admin,
  384. name: res[0].name
  385. });
  386. logger.trace('Chat: Message from ' + row[0].name + ' (SID: ' + row[0].steamid + ', IP: ' + address + ', hide: ' + hide + ') --> ' + mesaj);
  387. }
  388. }
  389. });
  390. });
  391.  
  392. socket.on('disconnect', function(m) {
  393. var address = socket.handshake.address;
  394.  
  395. delete usersOnline[address];
  396. io.sockets.emit('connections', Object.keys(usersOnline).length);
  397. });
  398. });
  399.  
  400.  
  401. function startRoulette()
  402. {
  403. if(currentMode == 'NONE')
  404. {
  405. currentHash = sha256('CSGO7-' + time() + '-' + Math.floor(Math.random() * (690 - 1 + 1)) + 1);
  406. currentLottery = time();
  407. currentSecret = makeCode();
  408. logger.trace('[Roulette] nextRoll --> Round hash: ' + currentHash + ', Lottery: ' + currentLottery + ', Secret: ' + currentSecret + ', Cifra: ' + getCifra(currentHash, currentSecret, currentLottery));
  409. pool.query('INSERT INTO rolls SET cifra = ' + pool.escape(getCifra(currentHash, currentSecret, currentLottery)) + ', hash = ' + pool.escape(currentHash) + ', lottery = ' + pool.escape(currentLottery) + ', secret = ' + pool.escape(currentSecret));
  410. io.sockets.emit('roulette_hash', currentHash);
  411. currentMode = 'WAITING';
  412. var rolls = setInterval(function() {
  413. currentTimer = currentTimer - 1;
  414. if(currentTimer == 0)
  415. {
  416. clearInterval(rolls);
  417. currentMode = 'ROLLING';
  418. setTimeout(function() {
  419. startRolling();
  420. }, 600);
  421. }
  422. }, 1000);
  423. }
  424. else if(currentMode == 'ENDED')
  425. {
  426. currentHash = sha256('CSGO7-' + time() + '-' + Math.floor(Math.random() * (690 - 1 + 1)) + 1);
  427. currentLottery = time();
  428. currentSecret = makeCode();
  429.  
  430. logger.trace('[Roulette] nextRoll --> Round hash: ' + currentHash + ', Lottery: ' + currentLottery + ', Secret: ' + currentSecret + ', Cifra: ' + getCifra(currentHash, currentSecret, currentLottery));
  431. pool.query('INSERT INTO rolls SET cifra = ' + pool.escape(getCifra(currentHash, currentSecret, currentLottery)) + ', hash = ' + pool.escape(currentHash) + ', lottery = ' + pool.escape(currentLottery) + ', secret = ' + pool.escape(currentSecret));
  432. io.sockets.emit('roulette_hash', currentHash);
  433. currentTimer = 30;
  434. currentMode = 'WAITING';
  435. var rolls = setInterval(function() {
  436. currentTimer = currentTimer - 1;
  437. if(currentTimer == 0)
  438. {
  439. clearInterval(rolls);
  440. currentMode = 'ROLLING';
  441. setTimeout(function() {
  442. startRolling();
  443. }, 600);
  444. }
  445. }, 1000);
  446. io.sockets.emit('roulette_start', currentTimer);
  447. }
  448. }
  449.  
  450. function startRolling()
  451. {
  452. pool.query('SELECT * FROM rolls WHERE lottery = ' + pool.escape(currentLottery), function(err, row) {
  453.  
  454.  
  455. var cifra = row[0].cifra;
  456.  
  457. var wooble = Math.random() * (1 - 0.1) + 0.1;
  458.  
  459. io.sockets.emit('roulette_roll', cifra, wooble);
  460.  
  461. setTimeout(function() {
  462. io.sockets.emit('roulette_secret', currentSecret);
  463. setTimeout(function() {
  464. currentLastNumber = cifra;
  465. currentLastWooble = wooble;
  466. // pool.query('INSERT INTO rolls SET cifra = ' + pool.escape(cifra) + ', hash = ' + pool.escape(currentHash) + ', lottery = ' + pool.escape(currentLottery) + ', secret = ' + pool.escape(currentSecret));
  467.  
  468. if(lastRolls.length >= 10)
  469. {
  470. lastRolls.shift();
  471. }
  472. lastRolls.push(cifra);
  473. winnerRoulette(cifra);
  474. }, 2500);
  475. }, 7000);
  476. });
  477. }
  478.  
  479. function winnerRoulette(cifra)
  480. {
  481. pool.query('SELECT * FROM rolls WHERE lottery = ' + pool.escape(currentLottery), function(err, row) {
  482.  
  483. var number = row[0].cifra;
  484. currentMode = 'ENDED';
  485. currentBets.forEach(function(i) {
  486. if(i.color == 'red' && (number == 1))
  487. {
  488. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
  489. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  490. if(i.user !== admin_steamid) {
  491. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*3) + ' WHERE name = "roulette"');
  492. }
  493. usersBalance[i.user]['refmoney'] += i.bet*3;
  494. if(io.sockets.connected[socketBySteam[i.user]['info']])
  495. {
  496. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  497. }
  498. }else if(i.color == 'red' && (number >= 3 && number <= 4))
  499. {
  500. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
  501. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  502. if(i.user !== admin_steamid) {
  503. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*3) + ' WHERE name = "roulette"');
  504. }
  505. usersBalance[i.user]['refmoney'] += i.bet*3;
  506. if(io.sockets.connected[socketBySteam[i.user]['info']])
  507. {
  508. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  509. }
  510. }else if(i.color == 'red' && (number >= 6 && number <= 7))
  511. {
  512. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
  513. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  514. if(i.user !== admin_steamid) {
  515. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*3) + ' WHERE name = "roulette"');
  516. }
  517. usersBalance[i.user]['refmoney'] += i.bet*3;
  518. if(io.sockets.connected[socketBySteam[i.user]['info']])
  519. {
  520. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  521. }
  522. }else if(i.color == 'red' && (number >= 9 && number <= 10))
  523. {
  524. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
  525. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  526. if(i.user !== admin_steamid) {
  527. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*3) + ' WHERE name = "roulette"');
  528. }
  529. usersBalance[i.user]['refmoney'] += i.bet*3;
  530. if(io.sockets.connected[socketBySteam[i.user]['info']])
  531. {
  532. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  533. }
  534. }else if(i.color == 'red' && (number >= 12 && number <= 13))
  535. {
  536. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
  537. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  538. if(i.user !== admin_steamid) {
  539. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*3) + ' WHERE name = "roulette"');
  540. }
  541. usersBalance[i.user]['refmoney'] += i.bet*3;
  542. if(io.sockets.connected[socketBySteam[i.user]['info']])
  543. {
  544. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  545. }
  546. }else if(i.color == 'red' && (number >= 15 && number <= 16))
  547. {
  548. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
  549. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  550. if(i.user !== admin_steamid) {
  551. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*3) + ' WHERE name = "roulette"');
  552. }
  553. usersBalance[i.user]['refmoney'] += i.bet*3;
  554. if(io.sockets.connected[socketBySteam[i.user]['info']])
  555. {
  556. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  557. }
  558. }else if(i.color == 'red' && (number == 18))
  559. {
  560. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
  561. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  562. if(i.user !== admin_steamid) {
  563. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*3) + ' WHERE name = "roulette"');
  564. }
  565. usersBalance[i.user]['refmoney'] += i.bet*3;
  566. if(io.sockets.connected[socketBySteam[i.user]['info']])
  567. {
  568. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  569. }
  570. }else if(i.color == 'green' && (number == 2))
  571. {
  572. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
  573. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  574. if(i.user !== admin_steamid) {
  575. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*5) + ' WHERE name = "roulette"');
  576. }
  577. usersBalance[i.user]['refmoney'] += i.bet*5;
  578. if(io.sockets.connected[socketBySteam[i.user]['info']])
  579. {
  580. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  581. }
  582. }else if(i.color == 'green' && (number == 5))
  583. {
  584. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
  585. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  586. if(i.user !== admin_steamid) {
  587. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*5) + ' WHERE name = "roulette"');
  588. }
  589. usersBalance[i.user]['refmoney'] += i.bet*5;
  590. if(io.sockets.connected[socketBySteam[i.user]['info']])
  591. {
  592. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  593. }
  594. }else if(i.color == 'green' && (number == 8))
  595. {
  596. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
  597. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  598. if(i.user !== admin_steamid) {
  599. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*5) + ' WHERE name = "roulette"');
  600. }
  601. usersBalance[i.user]['refmoney'] += i.bet*5;
  602. if(io.sockets.connected[socketBySteam[i.user]['info']])
  603. {
  604. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  605. }
  606. }else if(i.color == 'green' && (number == 11))
  607. {
  608. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
  609. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  610. if(i.user !== admin_steamid) {
  611. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*5) + ' WHERE name = "roulette"');
  612. }
  613. usersBalance[i.user]['refmoney'] += i.bet*5;
  614. if(io.sockets.connected[socketBySteam[i.user]['info']])
  615. {
  616. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  617. }
  618. }else if(i.color == 'green' && (number == 14))
  619. {
  620. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
  621. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  622. if(i.user !== admin_steamid) {
  623. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*5) + ' WHERE name = "roulette"');
  624. }
  625. usersBalance[i.user]['refmoney'] += i.bet*5;
  626. if(io.sockets.connected[socketBySteam[i.user]['info']])
  627. {
  628. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  629. }
  630. }else if(i.color == 'green' && (number == 17))
  631. {
  632. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
  633. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  634. if(i.user !== admin_steamid) {
  635. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*5) + ' WHERE name = "roulette"');
  636. }
  637. usersBalance[i.user]['refmoney'] += i.bet*5;
  638. if(io.sockets.connected[socketBySteam[i.user]['info']])
  639. {
  640. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  641. }
  642. }
  643. else if(i.color == 'black' && (number >= 19 && number <= 36))
  644. {
  645. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*2) + ' WHERE steamid = ' + pool.escape(i.user));
  646. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  647. if(i.user !== admin_steamid) {
  648. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*2) + ' WHERE name = "roulette"');
  649. }
  650. usersBalance[i.user]['refmoney'] += i.bet*2;
  651. if(io.sockets.connected[socketBySteam[i.user]['info']])
  652. {
  653. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  654. }
  655. }
  656. else if(i.color == 'blue' && (number == 0))
  657. {
  658. pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*30) + ' WHERE steamid = ' + pool.escape(i.user));
  659. pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
  660. if(i.user !== admin_steamid) {
  661. pool.query('UPDATE info SET `value` = `value` - ' + pool.escape(i.bet*30) + ' WHERE name = "roulette"');
  662. }
  663. usersBalance[i.user]['refmoney'] += i.bet*30;
  664. if(io.sockets.connected[socketBySteam[i.user]['info']])
  665. {
  666. io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
  667. }
  668. }
  669. });
  670. startRoulette();
  671. currentColors = {};
  672. currentBets = [];
  673. betTimes = {};
  674. currentSums = {
  675. 'red': 0,
  676. 'blue': 0,
  677. 'green': 0,
  678. 'black': 0
  679. };
  680. });
  681. }
  682.  
  683. function getCifra(hash, secret, lottery)
  684. {
  685. var cifra = sha256(hash+'-'+secret+'-'+lottery);
  686. cifra = hexdec(cifra.substr(0, 16)) % 37;
  687. return cifra;
  688. }
  689.  
  690. function hexdec(hexString) {
  691. hexString = (hexString + '').replace(/[^a-f0-9]/gi, '')
  692. return parseInt(hexString, 16)
  693. }
  694.  
  695. function getBalance(socket, steamid)
  696. {
  697. pool.query('SELECT refmoney FROM users WHERE steamid = ' + pool.escape(steamid), function(err, row) {
  698. if(err) throw err;
  699. if(row.length == 0) return;
  700.  
  701. var balanta = row[0].refmoney;
  702. usersBalance[steamid]['refmoney'] = row[0].refmoney;
  703. socket.emit('roulette_balance', balanta);
  704. });
  705. }
  706.  
  707.  
  708.  
  709.  
  710. function isInArray(value, array) {
  711. return array.indexOf(value) > -1;
  712. }
  713.  
  714. function time()
  715. {
  716. return parseInt(new Date().getTime()/1000);
  717. }
  718.  
  719. function addHistory(socket)
  720. {
  721. chatMessages.forEach(function(itm) {
  722. socket.emit('addMessage', {
  723. msg: itm.message,
  724. avatar: itm.avatar,
  725. steamid: itm.steamid,
  726. rank: itm.rank,
  727. name: itm.name
  728. });
  729. })
  730. }
  731.  
  732. function makeCode() {
  733. var text = "";
  734. var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  735.  
  736. for(var i=0; i < 12; i++)
  737. text += possible.charAt(Math.floor(Math.random() * possible.length));
  738.  
  739. return text;
  740. }
  741.  
  742. function getProxy()
  743. {
  744. return "http://" + proxies[random(0,proxies.length-1)];
  745. }
  746.  
  747. function random(min, max) {
  748. return Math.floor(Math.random() * (max - min + 1)) + min;
  749. }
  750.  
  751.  
  752.  
  753. function getRandomFloat(min, max) {
  754. return (Math.random() * (max - min) + min).toFixed(10);
  755. }
  756.  
  757. function handleDisconnect() {
  758. pool = mysql.createConnection(db_config);
  759.  
  760. pool.connect(function(err) {
  761. if(err) {
  762. logger.trace('Error: Connecting to database: ', err);
  763. setTimeout(handleDisconnect, 2000);
  764. }
  765. });
  766.  
  767. pool.on('error', function(err) {
  768. logger.trace('Error: Database error: ', err);
  769. if(err.code === 'PROTOCOL_CONNECTION_LOST') {
  770. handleDisconnect();
  771. } else {
  772. throw err;
  773. }
  774. });
  775. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement