Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Servidor: app.js
- // Iniciando servidor HTTP
- var app = require('http').createServer()
- , io = require('socket.io').listen(app)
- , fs = require('fs')
- ;
- var mysql = require('mysql');
- var pool = mysql.createPool({
- connectionLimit : 10,
- database: 'hungercase',
- host: 'localhost',
- user: 'root',
- password: 'h3S7CbpM'
- });
- app.listen(5000, function() {
- console.log("Servidor rodando!");
- });
- // Iniciando Socket.IO
- var visitas = 0;
- // Evento connection ocorre quando entra um novo usuário.
- var INTERVAL;
- count = 60;
- io.on('connection', function(socket){
- if (!INTERVAL) {
- INTERVAL = setInterval(function() {
- function verificarJogo(jogo) {
- // aqui podes fazer as verificações que precisas
- console.log(jogo);
- }
- function buscaJogo(id) {
- var select = 'SELECT * FROM `info` WHERE `id` = ' + id;
- pool.query(select, function(err, row) {
- if (err) console.log(err);
- verificarJogo(row[0].jogo);
- });
- }
- buscaJogo(1);
- });
- // Inicio do Contador
- socket.broadcast.emit('count', count);
- count --;
- if(count === -1){
- count=60;
- }
- console.log(count);
- // Fim do Contador
- }, 1000);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement