Advertisement
Guest User

Untitled

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