Skip to content

Commit

Permalink
Set basics for message dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
a727891 committed Feb 4, 2013
1 parent 93f8d37 commit a2b9708
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
24 changes: 23 additions & 1 deletion Client/js/app.js
Expand Up @@ -4,14 +4,36 @@
define([], function () {
var app = Class.extend({
init:function () {
var self = this;
this.socket = io.connect('http://localhost:8080');


this.socket.on('1', function (data) {
console.log("recieved a 1");
self.dispatchMessage(data);
});
this.handlers = [];
this.handlers["WELCOME"] = this.receiveWelcome;


},

dispatchMessage:function (data) {

},


receiveWelcome:function (data) {
var id = data[1],
name = data[2],
x = data[3],
y = data[4],
hp = data[5];

if (this.welcome_callback) {
this.welcome_callback(id, name, x, y, hp);
}
},

});

return app
Expand Down
2 changes: 1 addition & 1 deletion Server/Server.js
Expand Up @@ -2,7 +2,7 @@
var cls = require("./lib/class");

module.exports = Server = cls.Class.extend({
init:function () {
init:function (log) {

this.onPlayerConnect(function (player) {
log.warn('player connect');
Expand Down
7 changes: 6 additions & 1 deletion app.js
Expand Up @@ -25,10 +25,15 @@ function main() {
log.DebugEnable(process.env.LogDebug);
log.info('Starting Server...');

var server = new Server();
var server = new Server(log);

IO.sockets.on('connection', function (socket) {
server.connectCallback(new Player(0, 0, 0));
socket.emit('1', '');

socket.on('disconnect', function () {
console.log('Socket died');
});
});
}

Expand Down

0 comments on commit a2b9708

Please sign in to comment.