Skip to content

Commit

Permalink
server log autoupdate + version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Sep 1, 2019
1 parent 436f78c commit 6db2b31
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 48 deletions.
1 change: 1 addition & 0 deletions dev_roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Medium stuff:
- [x] Let admins change their password
- [ ] Create a init.cfg for the fxserver to execute containing all txAdmin commands
- [ ] Revert txadminclient cl_logger.js back into lua and fix the mismatch of killer ID
- [x] Improve server log page

Minor stuff:
- [x] Remove del in favour of fs-extra.emptyDir https://github.com/jprichardson/node-fs-extra/blob/master/docs/emptyDir.md
Expand Down
36 changes: 28 additions & 8 deletions src/webroutes/serverLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,31 @@ const isUndefined = (x) => { return (typeof x === 'undefined') };
* @param {object} req
*/
module.exports = async function action(res, req) {
let log = processLog(globals.intercomTempLog);
let out = await webUtils.renderMasterView('serverLog', req.session, {headerTitle: 'Server Log', log});
return res.send(out);
//If page
if(isUndefined(req.query.offset)){
let log = processLog(globals.intercomTempLog.slice(-100));
let renderData = {
headerTitle: 'Server Log',
offset: globals.intercomTempLog.length,
log
}
let out = await webUtils.renderMasterView('serverLog', req.session, renderData);
return res.send(out);

//If offset
}else if(parseInt(req.query.offset) !== NaN){
if(req.query.offset === globals.intercomTempLog.length){
return res.send({offset: globals.intercomTempLog.length, log : false});
}else{
let log = processLog(globals.intercomTempLog.slice(req.query.offset));
return res.send({offset: globals.intercomTempLog.length, log});
}

//If null
}else{
let log = processLog(globals.intercomTempLog.slice(-100));
return res.send({offset: globals.intercomTempLog.length, log});
}
};


Expand All @@ -26,9 +48,7 @@ module.exports = async function action(res, req) {
* @param {array} resList
*/
function processLog(logArray){
if(!logArray.length) return false;

let out = [];
let out = '';
logArray.forEach(event => {
if(
isUndefined(event.timestamp) ||
Expand All @@ -41,10 +61,10 @@ function processLog(logArray){
let time = new Date(parseInt(event.timestamp)*1000).toLocaleTimeString()
let source = processPlayerData(event.source);
let eventMessage = processEventTypes(event)
out.push(`[${time}] ${source} ${eventMessage}`)
out += `[${time}] ${source} ${eventMessage}\n`;
});

return out.join('\n');
return out;
}


Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.11.6-mplus",
"version": "1.11.6-mplus2",
"changelog": "Deprecated Message. Please Update.",
"allVersions": [
{
Expand Down
5 changes: 3 additions & 2 deletions web/actionLog.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@


<style>
.admin-log-content{
.pre-log-content{
height: calc(100vh - 251px);
margin-bottom: 0;
}
</style>

Expand All @@ -13,7 +14,7 @@ <h3>Action Log</h3>
</div>
<div class="card border-primary">
<div class="card-body">
<pre id="console" class="pre-scroll admin-log-content">{{log}}</pre>
<pre id="console" class="pre-scroll pre-log-content">{{log}}</pre>
</div>
</div>

Expand Down
82 changes: 45 additions & 37 deletions web/serverLog.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@


<style>
.admin-log-content{
.pre-log-content{
height: calc(100vh - 326px); /* -251px */
margin-bottom: 0;
}

.event-source{
Expand All @@ -27,16 +28,7 @@ <h3>Server Log <span class="badge badge-light">BETA</span></h3>
</div>
<div class="card border-primary">
<div class="card-body">
{{if(options.log === false)}}
<div style="display:flex;justify-content:center;align-items:center;" class="admin-log-content">
<h1 class="text-muted">
&lt; empty log &gt;
</h1>
</div>
</div>
{{#else}}
<pre id="console" class="pre-scroll admin-log-content">{{log|safe}}</pre>
{{/if}}
<pre id="console" class="pre-scroll pre-log-content">{{log|safe}}</pre>
</div>
</div>

Expand All @@ -45,35 +37,51 @@ <h1 class="text-muted">


<script>
$(document).ready(function () {
$("#console").scrollTop($("#console")[0].scrollHeight);

//Player name click function
$('.event-source').click(function(e){
let ids = $(this).data('player-identifiers');
if(!ids) return;
let name = $(this).data('player-name') || 'unknown';

$("#modPlayerInfoTitle").html(name);
$("#modPlayerInfoIdentifiers").html(ids.split(';').join(', <br>\n'));
$("#modPlayerInfoButtons").html('<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>');
$('#modPlayerInfo').modal('show');
$(document).ready(function () {
scrollToBottom();
setupHovers();
});

//Player name hover highlight (NOTE: Experiment)
$('.event-source').mouseenter(function(e){
let ids = $(this).data('player-identifiers');
if(!ids) return;
setInterval(getNewData, 5000);

$('.event-source').each(function(e){
if($(this).data('player-identifiers') !== ids) return;
$(this).addClass("highlight-player");
var currOffset = '{{offset}}';
function getNewData(){
$.ajax({
type: "GET",
url: `/serverLog?offset=${currOffset}`,
timeout: 2000,
success: function (data) {
//FIXME: temporary before database
if(typeof data.offset !== 'undefined') currOffset = data.offset;
if(typeof data.log !== 'undefined' && data.log !== false && data.log.length){
$("#console").append(data.log);
scrollToBottom();
setupHovers();
}
},
error: function (xmlhttprequest, textstatus, message) {
console.log(`Error refreshing server log: ${message}`)
}
});
});
$('.event-source').mouseleave(function(e){
$('.event-source').each(function(e){
$(this).removeClass("highlight-player");
}

function scrollToBottom(){
try {
$("#console").scrollTop($("#console")[0].scrollHeight);
} catch (error) {}
}

//Player name click function
function setupHovers(){
$('.event-source').click(function(e){
let ids = $(this).data('player-identifiers');
if(!ids) return;
let name = $(this).data('player-name') || 'unknown';

$("#modPlayerInfoTitle").html(name);
$("#modPlayerInfoIdentifiers").html(ids.split(';').join(', <br>\n'));
$("#modPlayerInfoButtons").html('<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>');
$('#modPlayerInfo').modal('show');
});
});
});
}
</script>

0 comments on commit 6db2b31

Please sign in to comment.