35 lines
769 B
JavaScript
35 lines
769 B
JavaScript
var PORT = 8080;
|
|
var gameMode = true;
|
|
|
|
var allSockets = [];
|
|
var userCnt = 0;
|
|
|
|
var express = require('express');
|
|
var app = express();
|
|
app.use(express.static(__dirname + '/'));
|
|
var server = require('http').Server(app);
|
|
var io = require('socket.io')(server);
|
|
var map = require("./s_map.js");
|
|
|
|
server.listen(PORT);
|
|
|
|
console.log("Pirate running on port:"+PORT);
|
|
console.log();
|
|
io.on('connection', function(socket){
|
|
userCnt++;
|
|
console.log("New user", socket.id);
|
|
allSockets[socket.id] = socket;
|
|
|
|
socket.on('disconnect', function () {
|
|
userCnt--;
|
|
console.log("User Disconnected:", socket.id);
|
|
});
|
|
|
|
socket.on('getmap', function (width, hight) {
|
|
var newmap = map.generateMap(width,hight);
|
|
//console.log("getmap",newmap);
|
|
socket.emit("getmap", newmap);
|
|
});
|
|
});
|
|
|