# Per game
if (type >= 2) {
- sp_channel = "" # channel to play in
sp_state = "new" # {new,join,bid,pass,play}
sp_owner = "" # Who started the game
sp_playto = 0 # Score the game will go to
# Persistent
if (type >= 3) {
+ sp_channel = "" # channel to play in
sp_log = "" # Log file name
delete sp_notify # [p] E-mail notification address
}
json_copy(game, "tricks", sp_tricks);
# Per game
- game["channel"] = sp_channel;
game["owner"] = sp_owner;
game["playto"] = sp_playto;
game["dealer"] = sp_dealer;
game["turn"] = sp_turn;
game["player"] = sp_player;
game["limit"] = sp_limit;
- game["log"] = sp_log;
json_copy(game, "hands", sp_hands);
json_copy(game, "players", sp_players);
json_copy(game, "auths", sp_auths);
json_copy(game, "share", sp_share);
json_copy(game, "order", sp_order);
json_copy(game, "scores", sp_scores);
+
+ # Persistent
+ game["channel"] = sp_channel;
+ game["log"] = sp_log;
json_copy(game, "notify", sp_notify);
# Save
sp_acopy(sp_tricks, game["tricks"]);
# Per game
- sp_channel = game["channel"];
sp_owner = game["owner"];
sp_playto = game["playto"];
sp_dealer = game["dealer"];
sp_turn = game["turn"];
sp_player = game["player"];
sp_limit = game["limit"];
- sp_log = game["log"];
sp_acopy(sp_hands, game["hands"]);
sp_acopy(sp_players, game["players"]);
sp_acopy(sp_auths, game["auths"]);
sp_acopy(sp_share, game["share"]);
sp_acopy(sp_order, game["order"]);
sp_acopy(sp_scores, game["scores"]);
+
+ # Persistent
+ sp_channel = game["channel"];
+ sp_log = game["log"];
sp_acopy(sp_notify, game["notify"]);
}
}
}
+# Statistics
+function sp_delay(sec)
+{
+ return (sec > 60*60*24 ? int(sec/60/60/24) "d " : "") \
+ (sec > 60*60 ? int(sec/60/60)%24 "h " : "") \
+ int(sec/60)%60 "m"
+}
+
+function sp_max(list, i, max)
+{
+ for (i=0; i<length(list); i++)
+ if (max == "" || list[i] > max)
+ max = list[i]
+ return max
+}
+
+function sp_avg(list, i, sum)
+{
+ for (i=0; i<length(list); i++)
+ sum += list[i]
+ return sum / length(list)
+}
+
+function sp_stats(file, line, arr, time, user, turn, start, delay)
+{
+ # Process log file
+ while ((stat = getline line < file) > 0) {
+ # Parse date
+ if (!match(line, /^([0-9\- \:]*) \| (.*)$/, arr))
+ continue
+ gsub(/[:-]/, " ", arr[1])
+ time = mktime(arr[1])
+
+ # Parse user
+ if (!match(arr[2], /^([^:]*): (.*)$/, arr))
+ continue
+ user = arr[1]
+
+ # Record user latency
+ if (turn) {
+ delay[turn][length(delay[turn])] = time - start
+ turn = 0
+ }
+ if (match(arr[2], /^it is your.*$/, arr)) {
+ turn = user
+ start = time
+ }
+ }
+ close(file)
+
+ # Check for error
+ if (stat < 0)
+ reply("File does not exist: " file);
+
+ # Output statistics
+ for (user in delay) {
+ say("latency for " user \
+ ": " sp_delay(sp_avg(delay[user])) " (avg)" \
+ ", " sp_delay(sp_max(delay[user])) " (max)")
+ }
+}
+
# Misc
BEGIN {
cmd = "od -An -N4 -td4 /dev/random"
}
}
-(DST == sp_channel) &&
+(TO == NICK || DST == sp_channel) &&
/^\.log/ {
say("http://pileus.org/andy/spades/" sp_log)
}
+(TO == NICK || DST == sp_channel) &&
+/^\.stats$/ {
+ sp_stats("logs/" sp_log);
+}
+
+(TO == NICK || DST == sp_channel) &&
+/^\.stats ([0-9]+_[0-9]+)(\.log)$/ {
+ gsub(/\.log$/, "", $2);
+ sp_stats("logs/" $2 ".log");
+}
+
/^\.((new|end|load)game|join|look|bid|pass|play|notify)/ {
sp_save("var/sp_cur.json");
}