1
0
mirror of https://github.com/exane/not-gwent-online synced 2024-10-31 10:36:53 +00:00
not-gwent-online/server/server.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-06-15 19:03:12 +00:00
var argv = require('minimist')(process.argv.slice(2));
2016-06-04 07:30:47 +00:00
var http = require("http");
var express = require('express');
var app = express();
var Config = require("../public/Config")
2015-06-24 16:22:56 +00:00
global.connections = require("./Connections")();
global.matchmaking = require("./Matchmaker")();
global.Room = require("./Room");
global.User = require("./User");
2016-06-04 07:30:47 +00:00
var server = http.createServer(app);
global.io = require("socket.io").listen(server);
server.listen(Config.Server.port);
2015-06-24 16:22:56 +00:00
2016-06-04 07:30:47 +00:00
app.use(express.static('public'));
app.use('/public', express.static('public'));
app.use('/assets', express.static('assets'));
2015-06-24 16:22:56 +00:00
2016-06-04 07:30:47 +00:00
app.listen(Config.WebServer.port);
2015-06-24 16:22:56 +00:00
2015-07-05 10:27:19 +00:00
var admin = io.of("/admin");
2015-06-27 13:37:36 +00:00
io.on("connection", function(socket) { //global connection
2015-06-24 16:22:56 +00:00
var user;
connections.add(user = User(socket));
console.log("new user ", user.getName());
socket.on("disconnect", function() {
connections.remove(user);
user.disconnect();
console.log("user ", user.getName(), " disconnected");
user = null;
2015-07-01 17:51:09 +00:00
//io.emit("update:playerOnline", connections.length());
2015-06-24 16:22:56 +00:00
})
2015-07-01 17:51:09 +00:00
io.emit("update:playerOnline", connections.length());
2015-07-05 10:27:19 +00:00
})
admin.on("connection", function(socket) {
socket.on("sendMessage", function(msg) {
console.log("admin send msg: " + msg);
io.emit("notification", {
message: msg
})
})
2015-06-24 16:22:56 +00:00
})