terminal-velocity / eCrackers

0 stars 0 forks source link

INDEX #2

Open ir-g opened 7 years ago

ir-g commented 7 years ago
var express = require("express")
var app = express();
var server = require("http").Server(app);
var io = require("socket.io")(server);
var config = require('./config/config.js');
var mongoose = require('mongoose');
//var auth = require('./auth.js');
var UUID = require('uuid-js');

server.listen(config.listen.port, config.listen.hostname);

mongoose.connect(config.dbURL);
require('./models');

/*
io.on("connection", function (socket){
  socket.emit("message", "testing");
});
*/
var sockets = {};

io.on("connection", function (socket){
  var uuid4 = UUID.create();
  socket.uuid = uuid4;
  sockets[uuid4] = socket;
  socket.on("signup", function(data){
    //DATABASE: ADD USER -
    console.log(data);
    auth(data.user,socket.uuid);
    socket.emit("id", data.name);
  });
  socket.on("getcode", function(){
    //START MATCH WITH THIS CODE, adding the socket.uuid as host
    socket.emit("code", Math.floor(Math.random() * 300));
  });
  socket.on("submitcode", function(){
    //Add the socket.uuid as the opponent in the match, and send a start message to both socket, and sockets[{{HOST UUID}}]
    socket.emit("start");
  });
});

app.use("/", express.static("../frontend"))