db.exists('go2:'+ip, function(err, data){
    if(err) throw err;

    if(data == 0){

      //First time voting??
      db.multi()
        .set('go2:'+ip, JSON.stringify(coord))
        .expireat('go2:'+ip, expire_time)
        .zincrby('go2:votes', 1, JSON.stringify(coord))
        .exec(function(err, results){
          if(err) throw err;
          go.voteStone(false, coord, function(){
            callback();
          });
        });
    } else {

      //Subsequent votes...
      db.get('go2:'+ip, function(err, old_coord){
        db.multi()
          .zincrby('go2:votes', -1, old_coord)
          .zincrby('go2:votes', 1, JSON.stringify(coord))
          .set('go2:'+ip, JSON.stringify(coord))
          .expireat('go2:'+ip, expire_time)
          .exec(function(err){
            if(err) throw err;
            go.voteStone(JSON.parse(old_coord), coord, function(){
              callback();
            });
          });
      });
    }
  });
function logChat(name, text){
  db.multi()
    .lpush('go2:chat_log', name + ': ' + text)
    .ltrim('go2:chat_log', 0, 9)
    .exec(function(err){
      if(err) throw err;
    });
}
function getChatLog(callback){
  var log = '';
  db.lrange('go2:chat_log', 0, -1, function(err, messages){
    if(err) throw err;
    for(var i = 0; i < messages.length; i++){
      log += messages[messages.length-1 - i] + '<br/>';
      if(i == messages.length -1)
        callback(log);
    }
  });
}
Beispiel #4
0
      collection.find({"numero":lesLogos.numeroImage}).toArray(function(err, data){

        // Si la Réponse est Bonne
        if (reponse == data[0].nom){
          // le Résultat est Positif
          
          tableauJoueurs[socket.id].bonneReponse++;
          tableauJoueurs[socket.id].mauvaiseReponse;
          
          console.log('joueur');
          console.log(tableauJoueurs[socket.id].score);
          console.log(tableauJoueurs[socket.id].bonneReponse);
          
          lesLogos.numeroImage++;
          
          if (tableauJoueurs[socket.id].bonneReponse == 10){
            console.log('entrer');
            var collectionJoueurs = db.get().collection('joueurs');
            collectionJoueurs.findOneAndUpdate({"pseudo":tableauJoueurs[socket.id].pseudo},{$inc:{"score":1}});

          };
          
          // Recherche de la donnée ayant le NEW Numéro Image Correspondant
           collection.find({"numero":lesLogos.numeroImage}).toArray(function(err, data){

              lesLogos.nomImage = data[0].img;

              var laCouleur = '#CFFFAB'; //green

              //lesLogos.backgroundColor = laCouleur;
              tableauJoueurs[socket.id].backgroundColor = laCouleur;

              /// ENVOIS Quatre //////////////////////////
              io.emit('envoisQuatre', { message:'message de l\'envois Quatre', lesLogos:lesLogos, backgroundColor:tableauJoueurs[socket.id].backgroundColor, nomImage:lesLogos.nomImage, numeroImage:lesLogos.numeroImage, id: tableauJoueurs[socket.id].publicId, bonneReponse:tableauJoueurs[socket.id].bonneReponse, mauvaiseReponse:tableauJoueurs[socket.id].mauvaiseReponse })

            }) // FIN 1er collection.fin()
         
        // Si la Réponse est Fausse
        } else {
          
          tableauJoueurs[socket.id].mauvaiseReponse++;
          tableauJoueurs[socket.id].bonneReponse;
          
          
          var laCouleur = '#FFBBB3'; //red
          
          tableauJoueurs[socket.id].backgroundColor = laCouleur;

          /// ENVOIS Quatre //////////////////////////
          io.emit('envoisQuatre', { message:'message de l\'envois Quatre', lesLogos:lesLogos, backgroundColor:tableauJoueurs[socket.id].backgroundColor, nomImage:lesLogos.nomImage, numeroImage:lesLogos.numeroImage, id: tableauJoueurs[socket.id].publicId, mauvaiseReponse:tableauJoueurs[socket.id].mauvaiseReponse, bonneReponse:tableauJoueurs[socket.id].bonneReponse})
          
        } //FIN else

      }); // FIN 2eme collection.find()
 db.get('go2:'+ip, function(err, old_coord){
   db.multi()
     .zincrby('go2:votes', -1, old_coord)
     .zincrby('go2:votes', 1, JSON.stringify(coord))
     .set('go2:'+ip, JSON.stringify(coord))
     .expireat('go2:'+ip, expire_time)
     .exec(function(err){
       if(err) throw err;
       go.voteStone(JSON.parse(old_coord), coord, function(){
         callback();
       });
     });
 });
Beispiel #6
0
app.post('/enregistrement-joueur', function(req,res){
  var collection = db.get().collection('joueurs');
  if (req.body.pseudo != '' && req.body.mdp != ''){
    collection.find({pseudo:req.body.pseudo}).toArray(function(err, data){
      if (data.length !=0){
        res.render('inscription', {nomPage: "Inscription", message:"Un autre utilisateur a déjà ce pseudo, choisissez en un autre.."});
      } else {
        collection.insert({pseudo:req.body.pseudo, mdp:req.body.mdp, score:0});
        joueursEnLigne.pseudoJoueur = req.body.pseudo;
        joueursEnLigne.scoreTotalJoueur = 0;
        res.render('valide', {nomPage: "valide", pseudo:req.body.pseudo});
      }
    });
  } else {
    res.render('inscription', { nomPage: 'Inscription', message: "Veuillez saisir les informations suivantes : votre Pseudo et votre Mot de Passe"});
  }
});
function updateBoard(){

  //Reset timer/tweet variables
  global.tweeted = false;
  global.start_time = new Date().getTime();
  global.next_round = new Date().addHours(round_time);

  //Get top ranked coordinate
  db.zrevrange('go2:votes', 0, 0, function(err, data){
    if(err) throw err;

    if(data.length > 0){
      coord = JSON.parse(data);

      //Update eidogo board
      go.playMove(coord, function(coord){

      var info_obj = { color: global.current_color
                    , stones: go.rules.board.stones
                    ,   heat: go.rules.board.markers
                    , passes: go.rules.board.passes
                    ,resigns: go.rules.board.resigns
                    ,   caps: go.rules.board.captures };

        //clear votes and update redis board
        db.multi()
          .set('go2:info', JSON.stringify(info_obj))
          .del('go2:votes')
          .exec(function(err){
            if(err) throw err;
            sendBoardInfo();

            //update SGF file
            sgf.move(coord);
        });
      });
    } else {

    //In case of no votes reset clock
      next_round = new Date().addHours(round_time);
      return;
    }
  });
}
function vote(coord, ip, callback){

  //Get UNIX time stamp for when all votes should expire
  var expire_time = Math.round(next_round.getTime()/1000);


  db.exists('go2:'+ip, function(err, data){
    if(err) throw err;

    if(data == 0){

      //First time voting??
      db.multi()
        .set('go2:'+ip, JSON.stringify(coord))
        .expireat('go2:'+ip, expire_time)
        .zincrby('go2:votes', 1, JSON.stringify(coord))
        .exec(function(err, results){
          if(err) throw err;
          go.voteStone(false, coord, function(){
            callback();
          });
        });
    } else {

      //Subsequent votes...
      db.get('go2:'+ip, function(err, old_coord){
        db.multi()
          .zincrby('go2:votes', -1, old_coord)
          .zincrby('go2:votes', 1, JSON.stringify(coord))
          .set('go2:'+ip, JSON.stringify(coord))
          .expireat('go2:'+ip, expire_time)
          .exec(function(err){
            if(err) throw err;
            go.voteStone(JSON.parse(old_coord), coord, function(){
              callback();
            });
          });
      });
    }
  });
};
      go.playMove(coord, function(coord){

      var info_obj = { color: global.current_color
                    , stones: go.rules.board.stones
                    ,   heat: go.rules.board.markers
                    , passes: go.rules.board.passes
                    ,resigns: go.rules.board.resigns
                    ,   caps: go.rules.board.captures };

        //clear votes and update redis board
        db.multi()
          .set('go2:info', JSON.stringify(info_obj))
          .del('go2:votes')
          .exec(function(err){
            if(err) throw err;
            sendBoardInfo();

            //update SGF file
            sgf.move(coord);
        });
      });
Beispiel #10
0
app.post('/connexion-verification', function(req, res){
  var collection = db.get().collection('joueurs'); 
  if (req.body.pseudo != '' && req.body.mdp != ''){
    collection.find({pseudo:req.body.pseudo, mdp:req.body.mdp}).toArray(function(err, data){
      //console.log(req.params.pseudo);
      if (data.length !=0){
        //console.log(data);
        joueursEnLigne.pseudoJoueur = data[0].pseudo;
        joueursEnLigne.scoreTotalJoueur = data[0].score;
        
          res.render('jeuBack', {nomPage: "Jouer", pseudo:req.body.pseudo, infosMulti:data, titre:'A vous de jouer..'});
        
      } else {
        //var dataRecup = {pseudo:req.body.pseudo, mdp:req.body.mdp};
        res.render('connexion',{nomPage : "Connexion", message: "Votre pseudo ou mot de passe est incorrect"});
      }
    });
  } else {
    res.render('connexion',{nomPage : "Connexion", message: "Veuillez saisir les informations suivantes : votre Pseudo et votre Mot de Passe"});
  }
});
Beispiel #11
0
function init() {
    return db.open( {
            server: databaseName,
            version: 1,
            schema: {
                // the surveys
                surveys: {
                    key: {
                        keyPath: 'enketoId',
                        autoIncrement: false
                    },
                    indexes: {
                        enketoId: {
                            unique: true
                        }
                    }
                },
                // the resources that belong to a survey
                resources: {
                    key: {
                        autoIncrement: false
                    },
                    indexes: {
                        key: {
                            unique: true
                        }
                    }
                },
                // Records in separate table because it makes more sense for getting, updating and removing records
                // if they are not stored in one (giant) array or object value.
                // Need to watch out for bad iOS bug: http://www.raymondcamden.com/2014/9/25/IndexedDB-on-iOS-8--Broken-Bad
                // but with the current keys there is no risk of using the same key in multiple tables.
                // InstanceId is the key because instanceName may change when editing a draft.
                records: {
                    key: {
                        keyPath: 'instanceId',
                    },
                    indexes: {
                        // useful to check if name exists
                        name: {
                            unique: true
                        },
                        // the actual key
                        instanceId: {
                            unique: true
                        },
                        // to get all records belonging to a form
                        enketoId: {
                            unique: false
                        }
                    }
                },
                // the files that belong to a record
                files: {
                    key: {
                        autoIncrement: false
                    },
                    indexes: {
                        key: {
                            unique: true
                        }
                    }
                },
                // settings or other global app properties
                properties: {
                    key: {
                        keyPath: 'name',
                        autoIncrement: false
                    },
                    indexes: {
                        key: {
                            unique: true
                        }
                    }
                }
            }
        } )
        .then( function( s ) {
            server = s;
            console.debug( 'WHoohoeeee, we\'ve got ourselves a database! Now let\'s check if it works properly.' );
        } )
        .then( _isWriteable )
        .then( _setBlobStorageEncoding )
        .then( function() {
            available = true;
        } )
        .catch( function( e ) {
            // make error more useful and throw it further down the line
            var error = new Error( t( 'store.error.notavailable', {
                error: e.message
            } ) );
            error.status = 500;
            throw error;
        } );
}
Beispiel #12
0
app.get('/score', function(req, res){
  var collection = db.get().collection('joueurs');
  collection.find().limit(5).sort({score:-1}).toArray(function(err, data){
    res.render('score',{joueurs : data, nomPage : "Les scores"})
  })
});
Beispiel #13
0
  if (req.session.connexion == undefined){
    req.session.connexion = 0;
  }
  next();
});

// Fichiers Statiques
app.use('/js', express.static(__dirname + '/js'));
app.use('/img', express.static(__dirname + '/img'));
app.use('/css', express.static(__dirname + '/css'));

db.connect(URL, function(err){
  if (err){
    console.log('Impossible de se connecter à la base de données.');
  } else {
    httpServer.listen(8888, function(){
      console.log('Le serveur est disponible sur le port 8888')
    });
  }
});

//fonction qui produit la réponse HTTP.
var writeResponse = function writeHTTPResponse(HTTPResponse, responseCode, responseBody) {
    HTTPResponse.writeHead(responseCode, {
        'Content-type': 'text/html; charset=UTF-8',
        'Content-length': responseBody.length
    });
    HTTPResponse.write(responseBody, function() {
        HTTPResponse.end();
    });
};
DB.setTypes(MySQL, {
	'blob'                      : {'type' : 'string', 'binary' : true, 'character_maximum_length' : '65535'},
	'bool'                      : {'type' : 'bool'},
	'bigint unsigned'           : {'type' : 'int', 'min' : '0', 'max' : '18446744073709551615'},
	'datetime'                  : {'type' : 'string'},
	'decimal unsigned'          : {'type' : 'float', 'exact' : true, 'min' : '0'},
	'double'                    : {'type' : 'float'},
	'double precision unsigned' : {'type' : 'float', 'min' : '0'},
	'double unsigned'           : {'type' : 'float', 'min' : '0'},
	'enum'                      : {'type' : 'string'},
	'fixed'                     : {'type' : 'float', 'exact' : true},
	'fixed unsigned'            : {'type' : 'float', 'exact' : true, 'min' : '0'},
	'float unsigned'            : {'type' : 'float', 'min' : '0'},
	'int unsigned'              : {'type' : 'int', 'min' : '0', 'max' : '4294967295'},
	'integer unsigned'          : {'type' : 'int', 'min' : '0', 'max' : '4294967295'},
	'longblob'                  : {'type' : 'string', 'binary' : true, 'character_maximum_length' : '4294967295'},
	'longtext'                  : {'type' : 'string', 'character_maximum_length' : '4294967295'},
	'mediumblob'                : {'type' : 'string', 'binary' : true, 'character_maximum_length' : '16777215'},
	'mediumint'                 : {'type' : 'int', 'min' : '-8388608', 'max' : '8388607'},
	'mediumint unsigned'        : {'type' : 'int', 'min' : '0', 'max' : '16777215'},
	'mediumtext'                : {'type' : 'string', 'character_maximum_length' : '16777215'},
	'national varchar'          : {'type' : 'string'},
	'numeric unsigned'          : {'type' : 'float', 'exact' : true, 'min' : '0'},
	'nvarchar'                  : {'type' : 'string'},
	'point'                     : {'type' : 'string', 'binary' : true},
	'real unsigned'             : {'type' : 'float', 'min' : '0'},
	'set'                       : {'type' : 'string'},
	'smallint unsigned'         : {'type' : 'int', 'min' : '0', 'max' : '65535'},
	'text'                      : {'type' : 'string', 'character_maximum_length' : '65535'},
	'tinyblob'                  : {'type' : 'string', 'binary' : true, 'character_maximum_length' : '255'},
	'tinyint'                   : {'type' : 'int', 'min' : '-128', 'max' : '127'},
	'tinyint unsigned'          : {'type' : 'int', 'min' : '0', 'max' : '255'},
	'tinytext'                  : {'type' : 'string', 'character_maximum_length' : '255'},
	'year'                      : {'type' : 'string'}
});
Beispiel #15
0
 .then( function() {
     return db.open( {
         server: databaseName,
         version: 2,
         schema: {
             // the surveys
             surveys: {
                 key: {
                     keyPath: 'enketoId',
                     autoIncrement: false
                 },
                 indexes: {
                     enketoId: {
                         unique: true
                     }
                 }
             },
             // the resources that belong to a survey
             resources: {
                 key: {
                     autoIncrement: false
                 },
                 indexes: {
                     key: {
                         unique: true
                     }
                 }
             },
             // Records in separate table because it makes more sense for getting, updating and removing records
             // if they are not stored in one (giant) array or object value.
             // Need to watch out for bad iOS bug: http://www.raymondcamden.com/2014/9/25/IndexedDB-on-iOS-8--Broken-Bad
             // but with the current keys there is no risk of using the same key in multiple tables.
             // InstanceId is the key because instanceName may change when editing a draft.
             records: {
                 key: {
                     keyPath: 'instanceId',
                 },
                 indexes: {
                     // useful to check if name exists
                     name: {
                         unique: true
                     },
                     // the actual key
                     instanceId: {
                         unique: true
                     },
                     // to get all records belonging to a form
                     enketoId: {
                         unique: false
                     }
                 }
             },
             // the files that belong to a record
             files: {
                 key: {
                     autoIncrement: false
                 },
                 indexes: {
                     key: {
                         unique: true
                     }
                 }
             },
             // settings or other global app properties
             properties: {
                 key: {
                     keyPath: 'name',
                     autoIncrement: false
                 },
                 indexes: {
                     key: {
                         unique: true
                     }
                 }
             },
             // Dynamic data, passed by via querystring is stored in a separate table, 
             // because its update mechanism is separate from the survey + resources. 
             // Otherwise the all-or-nothing form+resources update would remove this data.
             data: {
                 key: {
                     keyPath: 'enketoId',
                     autoIncrement: false
                 },
                 indexes: {
                     enketoId: {
                         unique: true
                     }
                 }
             }
         }
     } );
 } )