diff --git a/README.md b/README.md index 25afade..70d9d02 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/nodePong.js b/nodePong.js index c5141f9..cdfe781 100644 --- a/nodePong.js +++ b/nodePong.js @@ -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); -} diff --git a/server/server_config.js b/server/server_config.js new file mode 100644 index 0000000..7fbb05c --- /dev/null +++ b/server/server_config.js @@ -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; +} diff --git a/server/server_core.js b/server/server_core.js new file mode 100644 index 0000000..552255e --- /dev/null +++ b/server/server_core.js @@ -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; +} diff --git a/version.md b/version.md index 6c38e83..1a0ed5b 100644 --- a/version.md +++ b/version.md @@ -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