SHARE
TWEET

Untitled

a guest Apr 27th, 2016 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var _ = require('lodash');
  2. var server = require('http').Server();
  3. var io = require('socket.io')(server);
  4. var mysql = require('mysql');
  5. var request = require("request");
  6.  
  7.  
  8. var connection = mysql.createConnection({
  9.     host: 'localhost',
  10.     user: 'XXX',
  11.     password: 'XXX',
  12.     database: 'XXX'
  13. });
  14.  
  15. server.listen(4555);
  16.  
  17. var timeleft;
  18. var winnerNumber = 99;
  19. var gameTime = 45;
  20. var end_at = 0;
  21.  
  22.  
  23. io.on('connection', function (socket) {
  24.  
  25.     getLatestColors(socket);
  26.  
  27.     //emitujemy timer do nowo polaczonych graczy
  28.     socket.emit('startTimer', (new Date).getTime(), end_at);
  29.  
  30.  
  31.     setInterval(function () {
  32.         if (winnerNumber != 99) {
  33.             socket.emit('clearGame', winnerNumber);
  34.             setTimeout(function () {
  35.                 winnerNumber = 99;
  36.                 socket.emit('clearWinner', true);
  37.             }, 5000);
  38.             return;
  39.         }
  40.         if (timeleft < 1) {
  41.             socket.emit('counter', 45);
  42.         } else {
  43.             socket.emit('counter', timeleft);
  44.         }
  45.     }, 1000);
  46. });
  47.  
  48.  
  49. connection.connect(function (err) {
  50.     if (err) {
  51.         console.error('error connecting: ' + err.stack);
  52.         return;
  53.     }
  54. });
  55. ////////////////// CSBOX.pl Bot v0.0.1
  56.  
  57.  
  58. setInterval(function () {
  59.     CheckTimer();
  60. }, 1000);
  61.  
  62. function CheckTimer() {
  63.     // aktualnie brak timera
  64.     if (end_at <= (new Date).getTime()) {
  65.  
  66.         // pobieramy uzytkownikow z aktualnej gry
  67.         connection.query('SELECT count(*) as cnt,(SELECT id FROM roulette_history ORDER BY id DESC LIMIT 1) as gameid, (SELECT endTime FROM roulette_history ORDER BY id DESC LIMIT 1) as endTime FROM placed_bets WHERE gameID = (SELECT id FROM roulette_history ORDER BY id DESC LIMIT 1)', function (err, rows) {
  68.             var users = rows[0]['cnt'];
  69.             var endTime = rows[0]['cnt'];
  70.             var roundId = rows[0]['gameid'];
  71.             if (users > 0 && endTime == 0) {
  72.                 var unixTime = parseInt(new Date().getTime() / 1000, 10);
  73.                 connection.query('UPDATE roulette_history SET endTime="' + unixTime + '" WHERE id= (SELECT id FROM roulette_history ORDER BY id DESC LIMIT 1)', function (err, rows) {
  74.                     if (err) {
  75.                         console.log('Wystąpił błąd');
  76.                     } else {
  77.                         //zwyciezcy starej gry
  78.                         //proceedWinners(roundId);
  79.                         console.log('zwyciezcy starej gry');
  80.                         //puszczamy nowy timer/gre
  81.                         end_at = endTime;
  82.                         io.on('connection', function (socket) {
  83.                             socket.emit('startTimer', (new Date).getTime(), end_at);
  84.                         });
  85.                     }
  86.                 });
  87.                 return;
  88.             }
  89.         });
  90.  
  91.     } else {
  92.         //aktualnie mamy timerek
  93.  
  94.     }
  95.  
  96.  
  97. }
  98.  
  99. function getLatestColors(socket) {
  100.     connection.query("SELECT * FROM roulette_history WHERE numberWon != '99' ORDER BY id DESC LIMIT 10", function (err, rows) {
  101.         socket.emit('lastColors', rows);
  102.     });
  103. };
  104.  
  105.  
  106. function proceedWinners(roundID) {
  107.     request({
  108.         url: 'http://csgourban.com/getWinningColor98475983457xkjhas82',
  109.         json: true
  110.     }, function (error, response, body) {
  111.         console.log(body['number']);
  112.         winnerNumber = body['number'];
  113.     });
  114.     proceeded = false;
  115. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top