Permalink
Browse files

Set basics for message dispatcher

  • Loading branch information...
1 parent 93f8d37 commit a2b9708338ba77ce820fb25677ef26215355e03c @a727891 committed Feb 4, 2013
Showing with 30 additions and 3 deletions.
  1. +23 −1 Client/js/app.js
  2. +1 −1 Server/Server.js
  3. +6 −1 app.js
View
@@ -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
View
@@ -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');
View
7 app.js
@@ -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');
+ });
});
}

0 comments on commit a2b9708

Please sign in to comment.