Skip to content

Commit

Permalink
added history log player in sever list page
Browse files Browse the repository at this point in the history
  • Loading branch information
hgouveia committed Nov 20, 2015
1 parent 6670cee commit 98e5a11
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 10 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,3 @@ Legal: http://opensource.org/licenses/MIT

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/hgouveia/html5multiplayer/trend.png)](https://bitdeli.com/free "Bitdeli Badge")



[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/hgouveia/html5multiplayer/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

27 changes: 26 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<link type="text/css" rel="stylesheet" href="styles/layout.css">
<script type="text/javascript" src='scripts/game/utils.js'></script>
<script type="text/javascript" src='scripts/game/main.js'></script>

<script type="text/javascript" src='scripts/libs/socket.io-client/socket.io.js'></script>
<script type="text/javascript" src='scripts/game/entities/player.js'></script>
<script type="text/javascript" src='scripts/game/entities/playerbot.js'></script>
<script type="text/javascript" src='scripts/game/entities/bullet.js'></script>
<script type="text/javascript" src='scripts/game/entities/statsbox.js'></script>
<script type="text/javascript" src='scripts/game/multiplayer.js'></script>
<script type="text/javascript" src='scripts/game/gamelogic.js'></script>

<script type="text/javascript" src='scripts/game/main.js'></script>
</head>
<body>
<div id="main" class="main">
Expand All @@ -24,5 +34,20 @@ <h1>Block Multiplayer</h1>
ga('send', 'pageview');

</script>
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//analytics.joyalstudios.com/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//analytics.joyalstudios.com/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
</body>
</html>
2 changes: 1 addition & 1 deletion scripts/game/entities/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var Player = function(_name,_x,_y,_angle,_life,_color,_isLocalPlayer){
lastX = 0, lastY = 0, elapseTime;

//Update var helpers
var lastState = false; var time=0; flickeringToggle=false;
var lastState = false, time=0, flickeringToggle=false;

//Public
this.x = 0, this.y = 0, this.id = 0,this.angle = 0;
Expand Down
38 changes: 35 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ var util = require("util"), // Utility resources (logging, object inspection

var port = 3478;
var expressServer;
var clients;
var clients= [],
players= [],
logPlayers= [],
enableLogPlayer = true;

//Initializ the server
function initialize(){
players = clients = [];
players = [];
logPlayers = [];
clients = [];


expressServer = app.listen(port);
Expand Down Expand Up @@ -51,6 +56,10 @@ function socketEvents(client) {
//[MSG] General message: emitted from onPlayerDead [DEP] event only for now
//[KLL] Player Kill: emitted from onPlayerDead [DEP] event

//update log player
if(enableLogPlayer){
updatelogPlayer(client.id);
}
};


Expand Down Expand Up @@ -94,6 +103,9 @@ function onNewPlayer(data) {

// Add new player to the players array
players.push(newPlayer);
if(enableLogPlayer){
logPlayers.push(newPlayer);
}
};

// Player has moved
Expand Down Expand Up @@ -174,7 +186,22 @@ function playerById(id) {

return false;
};
//Update the player info in the logPlayer array
function updatelogPlayer(id){

var player = playerById(id);

if (player){

for (var i = 0; i < logPlayers.length; i++) {
if (logPlayers[i].id == id){
logPlayers[i] = player;
break;
}
};

}
}
/*_____________EXPRESS_________*/
var app = express();
app.set('views', __dirname + '/views');
Expand All @@ -188,7 +215,12 @@ app.get('/', function (req, res) {
});

app.get('/list', function (req, res) {
res.render('playerlist', { players: players });
var params = {
"players" : players,
"logPlayers" : logPlayers,
"enableLogPlayer" : enableLogPlayer
};
res.render('playerlist', params);
});

/// catch 404 and forwarding to error handler
Expand Down
33 changes: 32 additions & 1 deletion server/views/playerlist.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<% layout('layout') -%>
<h2>Active Players</h2>
<table class="table table-bordered table-striped">
<tr>
<td></td>
Expand All @@ -25,4 +26,34 @@
</tr>
<% } %>

</table>
</table>
<% if (enableLogPlayer){ %>
<h2>History Players</h2>
<table class="table table-bordered table-striped">
<tr>
<td></td>
<td>Name</td>
<td>Life</td>
<td>Dead</td>
<td>Kill</td>
<td>X</td>
<td>Y</td>
<td>ID</td>
</tr>
<% for (var i = 0; i < logPlayers.length; i++) {
var player = logPlayers[i];
%>
<tr>
<td><%= (i+1) %></td>
<td><%= player.name %></td>
<td><%= player.getLife() %></td>
<td><%= player.getDead() %></td>
<td><%= player.getKill() %></td>
<td><%= player.x %></td>
<td><%= player.y %></td>
<td><%= player.id %></td>
</tr>
<% } %>

</table>
<% } %>

0 comments on commit 98e5a11

Please sign in to comment.