This commit is contained in:
frtk 2016-02-10 14:12:52 +01:00
parent fd9fcdd4d6
commit cd0961e643
5 changed files with 174 additions and 22 deletions

View File

@ -17,7 +17,6 @@ The app has a few nodejs packages dependencies. If you want to install them manu
```
cd nodePong
npm install fs
npm install colors
npm install express
npm install http
npm install socket.io

View File

@ -9,34 +9,38 @@
*/
//---
var fs = require('fs');
var colors = require('colors');
var express = require('express');
var http = require('http');
var iosocket = require('socket.io');
//--- server app libs & params
var servU = require('./server/server_utils.js');
var servP = require('./server/server_params.js');
//var servP = require('./server/server_config.js');
var nPong = require('./server/server_core.js');
//--- nodePong config
var config = require('./server/server_config.js');
//
nPong.Server.setVersion(config.VERSION);
nPong.Server.log("$ ##### nodePong - v" + nPong.Server.version);
/*
* starting HTTP and socket.io services
*/
//---
serverMsg("$ ##### nodePong - v0.0.1 ");
//--- HTTP server
serverMsg("$ # starting http service on port " + servP.params.port);
nPong.Server.log("$ # starting http service on port " + config.HTTP.port);
var app = express();
var httpserv = http.createServer(app);
httpserv.listen(servP.params.port);
httpserv.listen(config.HTTP.port);
//--- allow access to static files from "/client" directory
app.use(express.static(__dirname + '/client/'));
//--- socket.io
serverMsg('$ # registering socket.io service on port ' + servP.params.port);
nPong.Server.log('$ # registering socket.io service on port ' + config.HTTP.port);
var io = require('socket.io').listen(httpserv, {log: false});
serverMsg('$ #####');
//
nPong.Server.log('$ #####');
@ -46,13 +50,3 @@ serverMsg('$ #####');
*/
//---
/*
* FUNCTIONS
*/
function serverMsg(msg) {
return console.log((servU.datelib.newDateToString() + msg).yellow);
}

25
server/server_config.js Normal file
View File

@ -0,0 +1,25 @@
/**
* @file server_config.js
* @author frtk
*/
var VERSION = '0.0.5';
/**
* HTTP Service
*/
var HTTP = {
port: 8042,
}
/**
*
* EXPORTS
*
*/
if (typeof exports !== "undefined") {
exports.HTTP = HTTP;
exports.VERSION = VERSION;
}

117
server/server_core.js Normal file
View File

@ -0,0 +1,117 @@
/**
* @file server_core.js
* @author frtk
*/
/**
*
* nodePong Server Object
*
*/
var Server = {
/*
* Data
*/
// version
version: '',
// Users and Games
users: [],
games: [],
/*
*
*/
//--- init()
init: function() {
var self = this;
},
//--- setVersion(s)
setVersion: function(s) {
this.version = s;
},
/*
* Server Messages
*/
//---
log: function(msg) {
var self = this;
return console.log(self.newDateToString() + msg);
},
//--- dateToString
dateToString: function(date) {
var self = this;
return '[' + self.addZero(date.getHours(), 'h') + ':'
+ self.addZero(date.getMinutes(), 'm') + ':'
+ self.addZero(date.getSeconds(), 's') + ':'
+ self.addZero(date.getMilliseconds(), 'ms') + ']';
},
//--- addZero
addZero: function(value, type) {
switch(type) {
case 'h':
case 'm':
case 's':
if (value < 10) value = '0' + value;
break;
case 'ms':
if (value < 10) value = '00' + value;
else if (value >= 10 && value < 100) value = '0' + value;
break;
default:
break;
};
return value;
},
//--- return new date string
newDateToString: function() {
var self = this;
return self.dateToString(new Date());
},
};
/**
*
* nodePong User Object
*
*/
var User = function(name) {
};
/**
*
* nodePong Game Object
*
*/
var Game = function() {
};
/**
*
* EXPORT
*
*/
if (typeof exports !== "undefined") {
exports.Server = Server;
exports.User = User;
exports.Game = Game;
}

View File

@ -1,5 +1,22 @@
### **v0.0.5:**
- objects naming convention change in server_core.js, and consequently in nodePong.js
- added "User" and "Game" Objects skeletton in server_core.js
- added "version" as a parameter of core.Server object (to later send it to clients @ connection)
### **v0.0.4:**
- added server_core.js, with "core" app server side object skeletton
- added "serverMsg" features to "core" (including date utilities)
- removed server_utils.js (moved serverMsg() function to the core object)
- updated README.md (removed "npm install colors)
- moved server.params.js to server_config.js, and changed naming convention
- updated nodePong.js with new config setup
### **v0.0.3:**
- Added infos in README.md