Skip to content

Commit

Permalink
- fixed /whois when console dump includes timestamps (also using the …
Browse files Browse the repository at this point in the history
…less spammy /players command now to get player info)
  • Loading branch information
PredatH0r committed Dec 4, 2015
1 parent 624bb5f commit 933ec58
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 27 deletions.
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ c:\program files (x86)\Steam\SteamApps\workshop\content\282440\539252269
Changelog
=========

Version 2.18
---
- fixed /whois when console dump includes timestamps (also using the less spammy /players command now to get player info)

Version 2.17
---
- show warning when the offical UI in web.pak is newer than the currently selected alternative UI
Expand Down
2 changes: 1 addition & 1 deletion source/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace ExtraQL
{
public partial class MainForm : Form
{
public const string Version = "2.17";
public const string Version = "2.18";

private readonly Config config;
private readonly HttpServer server;
Expand Down
6 changes: 6 additions & 0 deletions source/Servlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,15 @@ private static Dictionary<int, string> ExtractConfigstrings(int i, string[] line
int index = -1;
string value = "";
var info = new Dictionary<int, string>();
var regexTimestamp = new Regex(@"^\[\d+:\d\d.\d+\] (.*)");
for (; i < lines.Length; i++)
{
string line = lines[i];

var match = regexTimestamp.Match(line);
if (match.Success)
line = match.Groups[1].Value;

if (line.Length >= 4 && line[0] == ' ' && line[4] == ':')
{
if (index == 0 || index >= 529 && index < 529 + 32)
Expand Down
15 changes: 8 additions & 7 deletions source/scripts/_elo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name QLStats: Adds an /elo command to show rating information from qlstats.net
// @version 0.1
// @version 1.1
// @author PredatH0r
// @description Use "/elo help" in the console to get a list of available commands.
// @description /elo score: display rating for all players on the server
Expand All @@ -12,6 +12,9 @@

/*
Version 1.1
- fixed help text
Version 1.0
- rewrite to work with Steam exclusive version of Quake Live
Expand Down Expand Up @@ -99,7 +102,6 @@ Version 1.0
function showHelp() {
qz_instance.SendGameCommand("echo Usage: ^5/" + CVAR_elo + "^7 <^3command^7>");
qz_instance.SendGameCommand("echo \"^3say^7 shows the QLRanks score to all players\"");
/*
qz_instance.SendGameCommand("echo \"^3table^7|^3list^7|^3simple^7 ^^^7... formatted in your console\"");
qz_instance.SendGameCommand("echo \"^3method^7=x show/set output method\"");
qz_instance.SendGameCommand("echo \"^3format^7=x show/set output format used by method=echo\"");
Expand All @@ -109,13 +111,12 @@ Version 1.0
qz_instance.SendGameCommand("echo \"^3games^7 shows the number of completed games for each player\"");
qz_instance.SendGameCommand("echo \"^3shuffle^7! suggest/arrange teams based on QLRanks score\"");
qz_instance.SendGameCommand("echo \" append ^3,+all,+player1,-player2^7 to add/remove players\"");
qz_instance.SendGameCommand("echo \"^3profile=^7x opens QLranks.com player profile in your browser\"");
//qz_instance.SendGameCommand("echo \"^3profile=^7x opens QLranks.com player profile in your browser\"");
qz_instance.SendGameCommand("echo \" ^3x^7 is a comma separated list of game types and players\"");
*/
qz_instance.SendGameCommand("echo \"^3update^7 clears cached Elo scores\"");
qz_instance.SendGameCommand("echo \"\"");
qz_instance.SendGameCommand("echo \"Badge letters after Elo score indicate number of games completed\"");
qz_instance.SendGameCommand("echo ^3A-J^7: <100...<1000, ^3K-Y^7: <2000...<16000, ^3Z^7: >=16000");
//qz_instance.SendGameCommand("echo \"\"");
//qz_instance.SendGameCommand("echo \"Badge letters after Elo score indicate number of games completed\"");
//qz_instance.SendGameCommand("echo ^3A-J^7: <100...<1000, ^3K-Y^7: <2000...<16000, ^3Z^7: >=16000");
}

function clearEloCache() {
Expand Down
52 changes: 34 additions & 18 deletions source/scripts/whois.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// ==UserScript==
// @name Whois: Adds a /whois command to show alias nicknames stored on qlstats.net
// @version 1.0
// @version 1.1
// @author PredatH0r
// @description Use "/whois nickname -or- client-id (from /players)"
// @enabled 1
// ==/UserScript==

/*
Version 1.1
- using /players instead of /configstrings to get list of players
Version 1.0
- first release
Expand All @@ -21,7 +24,7 @@ Version 1.0
// constants
var CVAR_whois = "whois";
var HelpText = "a user script command. Use ^3" + CVAR_whois +" help^7 to get some help.";
var ConfigstringsMarker = "]\\configstrings";
var CondumpMarker = "]\\players";

// state variables
var pendingAjaxRequest = null;
Expand All @@ -36,6 +39,7 @@ Version 1.0
var postal = window.req("postal");
var channel = postal.channel();
channel.subscribe("cvar." + CVAR_whois, onCommand);
channel.subscribe("cvar.ui_mainmenu", function() { playerCache.timestamp = 0; }); // happens on connect and map change

echo("^2whois.js installed");
}
Expand All @@ -57,8 +61,10 @@ Version 1.0

if (val == "help")
showHelp();
else if (val == "update")
else if (val == "update") {
playerCache.timestamp = 0;
showAliases("*");
}
else
showAliases(val);
}
Expand Down Expand Up @@ -125,51 +131,61 @@ Version 1.0
return;
}

qz_instance.SendGameCommand("echo " + ConfigstringsMarker); // text marker required by extraQL servlet
qz_instance.SendGameCommand("configstrings");
qz_instance.SendGameCommand("echo " + CondumpMarker); // text marker required by extraQL servlet
qz_instance.SendGameCommand("players");
setTimeout(function () {
qz_instance.SendGameCommand("condump extraql_condump.txt");
setTimeout(function () {
var xhttp = new XMLHttpRequest();
xhttp.timeout = 1000;
xhttp.onload = function () { onExtraQLServerInfo(arg, xhttp, callback); }
xhttp.onload = function () { onExtraQLCondump(arg, xhttp, callback); }
xhttp.onerror = function () {
echo("^3extraQL.exe not running:^7");
pendingAjaxRequest = null;
}
xhttp.open("GET", "http://localhost:27963/serverinfo", true);
xhttp.open("GET", "http://localhost:27963/condump", true);
xhttp.send();
}, 100);
}, 1000);


function onExtraQLServerInfo(arg, xhttp, callback) {
function onExtraQLCondump(arg, xhttp, callback) {
if (xhttp.status != 200) {
pendingAjaxRequest = null;
return;
}

var json = null;
try {
json = JSON.parse(xhttp.responseText);
} catch (err) {
}
if (!json || !json.players) {
var players = getPlayersFromCondump(xhttp.responseText);
if (!players || players.length == 0) {
pendingAjaxRequest = null;
return;
}

playerCache.players = json.players;
playerCache.players = players;
playerCache.timestamp = Date.now();
requestAliasInformation(arg, json.players, callback);
requestAliasInformation(arg, players, callback);
}

function getPlayersFromCondump(condump) {
var idx = condump.lastIndexOf(CondumpMarker);
if (idx < 0) {
return null;
}
var players = [];
var lines = condump.substring(idx).split('\n');
lines.forEach(function (line) {
var match = /^(?:\[\d+:\d\d\.\d+\] )?([ \d]\d) (.) (.+) steam:(\d+)$/.exec(line);
if (match)
players.push({ clientid: parseInt(match[1].trim()), opflag: match[2], name: match[3], steamid: match[4] });
});
return players;
}

function requestAliasInformation(arg, players, callback) {
var steamIds = [];
pendingAjaxRequest = {};
for (var i = 0; i < players.length; i++) {
var obj = players[i];
var player = { "steamid": obj.st, "name": obj.n, "clientid": obj.clientid };
var player = players[i];
if (arg == "*" || player.name.indexOf(arg) >= 0 || player.clientid.toString() == arg) {
steamIds.push(player.steamid);
pendingAjaxRequest[player.steamid] = player;
Expand Down
2 changes: 1 addition & 1 deletion workshop/extraQL.vdf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"previewfile" "d:\sources\extraQL\workshop\extraQL1.png"
"visibility" "0"
"title" "extraQL userscripts"
"changenote" "https://github.com/PredatH0r/extraQL/releases/tag/v2.16"
"changenote" "https://github.com/PredatH0r/extraQL/releases/tag/v2.17"
}

0 comments on commit 933ec58

Please sign in to comment.