Skip to content
Permalink
Browse files

Chatting, Game GUI Started, Misc stuff

- Removed old files
+ Added in-game gui such as chat/chatbox
   + Type then press enter to send
+ Some server sided checks done
  • Loading branch information...
LexTheGreat committed Feb 26, 2015
1 parent 3da7913 commit 3a61d30f3097f2e9ae547039ea2c8f713b2062df
Showing with 103 additions and 1,660 deletions.
  1. +22 −17 app.js
  2. +2 −0 nodemmo/objects/player.js
  3. +13 −11 public/game/game.js
  4. +20 −1 public/game/network.js
  5. +0 −1,340 public/game/old/Interface.js
  6. +0 −25 public/game/old/NetworkHandler.js
  7. +0 −8 public/game/old/Player.js
  8. +0 −244 public/game/old/core.js
  9. +28 −0 public/index.html
  10. +18 −14 server.js
39 app.js
@@ -39,13 +39,6 @@ if (typeof String.prototype.startsWith != 'function') {
};
}

/*var playerToSocket = function(id) {
Global.Server.sockets.clients().forEach(function(Socket) {
if(Socket.id == id) {
return Socket
}
});
}*/
var ClientSocket = {};
Global.Server.sockets.on('connection', function(socket) {
NConsole.writeLine("[" + socket.id + ":connection] Socket Connected!");
@@ -72,7 +65,6 @@ Global.Server.sockets.on('connection', function(socket) {
GameServer.Network.onLogin(socket, data.Username, data.Password);
}
});

socket.on('onMovement', function(data) {
if(typeof data != 'number') {
socket.emit('popup', "Incorect Data. Kicked! (Stop Trying to Cheat!)");
@@ -86,7 +78,18 @@ Global.Server.sockets.on('connection', function(socket) {
}
GameServer.Network.onMovement(socket, data);
});

socket.on('onMessage', function(data) {
if(typeof data != 'string') {
socket.emit('popup', "Incorect Data. Kicked! (Stop Trying to Cheat!)");
GameServer.Network.kickPlayer(socket);
return;
}
if(data.length > 100 && data.length == 0) {
socket.emit('popup', "Message to length incorect!");
return;
}
GameServer.Network.onMessage(socket, data);
});
socket.on('disconnect', function() {
NConsole.writeLine("[" + socket.id + ":disconnect]: Disconnected!");
if(typeof GameServer.GameObjects.Players[socket.id] != "undefined") {
@@ -97,16 +100,18 @@ Global.Server.sockets.on('connection', function(socket) {
});

ServerLoop = function() {
var self = this;
for(var SocketID in ClientSocket) {
if(SocketID != 'undefined') {
var Socket = ClientSocket[SocketID];
if(Socket != 'undefined') {
GameServer.pFunc.sendPlayers(Socket);
setTimeout(function() {
var self = this;
for(var SocketID in ClientSocket) {
if(SocketID != 'undefined') {
var Socket = ClientSocket[SocketID];
if(Socket != 'undefined') {
GameServer.pFunc.sendPlayers(Socket);
}
}
}
}
setImmediate(ServerLoop)
setImmediate(ServerLoop)
}, 1000/30);
}
setImmediate(ServerLoop)

@@ -10,6 +10,8 @@ var Player = function() {
// Animation Variables
this.nextAniT = 5;
this.AniT = 0;

this.Socket = "";
};

Player.prototype = {
@@ -54,6 +54,8 @@ window.GameEngine = function() {
ctx: this.Canvas.getContext('2d'),
fps: 0,
draw: function() {
this.parent.Canvas.width = window.innerWidth;
this.parent.Canvas.height = window.innerHeight;
this.ctx.clearRect(0, 0, this.parent.Canvas.width, this.parent.Canvas.height);
this.ctx.save();
// Start Draw objects here
@@ -130,18 +132,18 @@ window.GameEngine = function() {
var self = this;

setTimeout(function() {
requestAnimationFrame(function() {self.update()})

requestAnimationFrame(function() {self.update()})

if(isMoving) {
Network.sendMovement(Dir);
this.didsendReset = false;
} else if(!this.didsendReset) {
Network.sendReset();
this.didsendReset = true
}
self.parent.Render.draw();
if(isMoving) {
Network.sendMovement(Dir);
this.didsendReset = false;
} else if(!this.didsendReset) {
Network.sendReset();
this.didsendReset = true
}
self.parent.Render.draw();
}, 1000/30);
//setInterval(function() {

@@ -2,6 +2,17 @@ $(function() {
window.Socket = false;
window.Network = new Network();
window.Game = new GameEngine();

$('#chatBox').bind("enterKey",function(e){
Socket.emit('onMessage', $('#chatBox').val());
$('#chatBox').val("");
});
$('#chatBox').keyup(function(e){
if(e.keyCode == 13)
{
$(this).trigger("enterKey");
}
});
});

var Network = function() {
@@ -29,6 +40,14 @@ var Network = function() {
window.Game.NetVar.Players = data.Players;
}
});

Socket.on('onMessage', function(data) {
$( "#chatLog" ).append( "<p><xmp>" + data.Sender + ": " + data.Message + "</xmp></p>" );
});

Socket.on('popup', function(data) {
alert("Server: " + data);
});
}

Network.prototype = {
@@ -45,6 +64,6 @@ Network.prototype = {
},
sendReset: function() {
Socket.emit("onMovement", -1);
}
},
}

0 comments on commit 3a61d30

Please sign in to comment.
You can’t perform that action at this time.