Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. // Servidor: app.js
  2. // Iniciando servidor HTTP
  3. var app = require('http').createServer()
  4. , io = require('socket.io').listen(app)
  5. , fs = require('fs')
  6. ;
  7. var mysql = require('mysql');
  8.  
  9. var pool = mysql.createPool({
  10. connectionLimit : 10,
  11. database: 'hungercase',
  12. host: 'localhost',
  13. user: 'root',
  14. password: 'h3S7CbpM'
  15. });
  16.  
  17. app.listen(5000, function() {
  18. console.log("Servidor rodando!");
  19. });
  20. // Iniciando Socket.IO
  21. var visitas = 0;
  22. // Evento connection ocorre quando entra um novo usuário.
  23.  
  24. var INTERVAL;
  25.  
  26.  
  27. count = 60;
  28. io.on('connection', function(socket){
  29.  
  30.  
  31.  
  32. if (!INTERVAL) {
  33.  
  34. INTERVAL = setInterval(function() {
  35.  
  36.  
  37.  
  38.  
  39. function verificarJogo(jogo) {
  40. // aqui podes fazer as verificações que precisas
  41. console.log(jogo);
  42. }
  43.  
  44. function buscaJogo(id) {
  45. var select = 'SELECT * FROM `info` WHERE `id` = ' + id;
  46. pool.query(select, function(err, row) {
  47. if (err) console.log(err);
  48. verificarJogo(row[0].jogo);
  49. });
  50. }
  51.  
  52. buscaJogo(1);
  53.  
  54.  
  55.  
  56. });
  57.  
  58.  
  59. // Inicio do Contador
  60.  
  61. socket.broadcast.emit('count', count);
  62. count --;
  63. if(count === -1){
  64.  
  65. count=60;
  66. }
  67.  
  68. console.log(count);
  69.  
  70. // Fim do Contador
  71.  
  72. }, 1000);
  73.  
  74. }
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement