From 4fd6405764415fb18bc61ba801ca121936a11a10 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sat, 10 Aug 2013 05:13:48 +0000 Subject: [PATCH] Allow players to grant access to other IRC users This lets multiple IRC users play as the same primary player. This should help with players in different time zones and with different schedules. --- mkfile | 8 +++++--- spades.awk | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++- test.awk | 36 +++++++++++++++++++++++++--------- test.txt | 40 +++++++++++++++++++++++++++++--------- 4 files changed, 119 insertions(+), 22 deletions(-) diff --git a/mkfile b/mkfile index e9a6d99..201a4ec 100644 --- a/mkfile +++ b/mkfile @@ -6,9 +6,11 @@ test:Q: #awk -f rhawk < testirc.txt #awk -f rhawk < testirc.txt awk -f test.awk test.txt \ - | awk '-vDEBUG=1' -frhawk 2>&1 \ - | grep -v '^ >\|USER\|NICK\|CAP\|JOIN\|TOPIC\|WHO\|unicode' - #| grep 'points\|bid\|took' + | awk '-vDEBUG=1' -frhawk 2>&1 1>/dev/null \ + | grep -v '^ > \(USER\|NICK\|CAP\|JOIN\|TOPIC\|WHO\)' \ + | grep -v '^ . .*\(ACCOUNT\|IDENTIFY\|unicode\|colors\)' \ + | sed -e 's/^ > PRIVMSG #\w* :/rhawk:\t/' \ + -e 's/^ < :\([^!]*\)![^ ]* PRIVMSG #\w* :/\1:\t/ ' test-select:Q: select.so #awk -f select.awk diff --git a/spades.awk b/spades.awk index e5516e0..1509117 100644 --- a/spades.awk +++ b/spades.awk @@ -53,6 +53,7 @@ function sp_reset(type) delete sp_hands # [p] Each players cards delete sp_players # [p] Player names players["name"] -> i delete sp_auths # [c] Player auth names auths["auth"] -> "name" + delete sp_share # [c] Player teammates share["friend"] -> "name" delete sp_order # [i] Player order order[i] -> "name" delete sp_scores # [i] Teams score } @@ -92,6 +93,7 @@ function sp_save(file, game) 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); @@ -130,6 +132,7 @@ function sp_load(file, game) 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"]); } @@ -343,7 +346,8 @@ BEGIN { } // { - sp_from = AUTH in sp_auths ? sp_auths[AUTH] : FROM + sp_from = AUTH in sp_auths ? sp_auths[AUTH] : \ + AUTH in sp_share ? sp_share[AUTH] : FROM sp_valid = sp_from && sp_from == sp_player } @@ -450,6 +454,57 @@ sp_state == "play" && sp_deal() } +/^\.allow \S+$/ { + _who = $2 in USERS ? USERS[$2]["auth"] : "" + _str = _who && _who != $2 ? $2 " (" _who ")" : $2 + if (sp_state ~ "new|join") { + reply("The game has not yet started") + } + else if (!(sp_from in sp_players)) { + reply("You are not playing") + } + else if (!_who) { + reply(_str " is not logged in") + } + else if (_who in sp_players || _who in sp_auths) { + reply(_str " is a primary player") + } + else if (_who in sp_share) { + reply(_str " is already playing for " sp_share[_who]) + } + else { + reply(_str " can now play for " sp_from) + sp_share[_who] = sp_from + } +} + +/^\.deny \S+$/ { + _who = $2 in USERS ? USERS[$2]["auth"] : $2 + _str = _who && _who != $2 ? $2 " (" _who ")" : $2 + if (sp_state ~ "new|join") { + reply("The game has not yet started") + } + else if (!(sp_from in sp_players)) { + reply("You are not playing") + } + else if (_who in sp_players || _who in sp_auths) { + reply(_str " is a primary player") + } + else if (!(_who in sp_share) || sp_share[_who] != sp_from) { + reply(_str " is not playing for " sp_from) + } + else { + reply(_str " can no longer play for " sp_from) + delete sp_share[_who] + } +} + +sp_state ~ "(bid|pass|play)" && +/^\.show/ { + for (_i in sp_share) + say(_i " can play for " sp_share[_i]); +} + !sp_valid && (sp_state == "bid" || sp_state == "play") && /^\.(bid|play)\>/ { diff --git a/test.awk b/test.awk index 3758f28..808a8e7 100644 --- a/test.awk +++ b/test.awk @@ -4,6 +4,11 @@ function say(who, msg) print ":" who"!u@h PRIVMSG #rhtest :" msg } +function auth(user, nick) +{ + print ":" nick "!u@c ACCOUNT " user +} + function error(msg) { print "error: " msg > "/dev/stderr" @@ -17,11 +22,14 @@ function debug(msg) function command(who, cmd) { arg=cmd - gsub(/\<[nbp]|[+-]/, "", arg) + gsub(/\<[nbpYNS]|[+-]/, "", arg) if (cmd ~ /^\./) 0 # nop else if (cmd ~ /^n/) say(who, ".newgame " arg) else if (cmd ~ /^e/) say(who, ".endgame ") else if (cmd ~ /^j/) say(who, ".join") + else if (cmd ~ /^Y/) say(who, ".allow " arg) + else if (cmd ~ /^N/) say(who, ".deny " arg) + else if (cmd ~ /^S/) say(who, ".show ") else if (cmd ~ /^d/) say("andy753421", ".deal " who " " hand[who]) else if (cmd ~ /^l/) say(who, ".look") else if (cmd ~ /^b/) say(who, ".bid " arg) @@ -42,26 +50,36 @@ function reset() } # Rules -BEGIN { reset() } +BEGIN { + auth("andy753421", "andy753421") + reset() +} // { gsub(/#.*/, "") } /^[^ ]+:/ { - gsub(/:/, "") + gsub(/:/, " ") + split($1, parts, "/"); pi = length(players) if (NF-2 > nturns) nturns = NF-1 for (i=2; i<=NF; i++) turns[pi][i-2] = $i - players[pi] = $1 - hand[$1] = $0 - gsub(/^\w*|[nbp-]\w+|\<[nejlbsBtpd]\>|[.+]/, "", hand[$1]) - gsub(/^ */, "", hand[$1]) - print $1 ": " hand[$1] > "/dev/stderr" - say($1, "unicode :(") + who = parts[1] + players[pi] = parts[1] + auths[pi] = parts[2] + hand[who] = $0 + gsub(/^\w*(\/\w*)?|[nbpYN-]\w+|\<[nejadwlbsBtpdS]\>|[.+]/, "", hand[who]) + gsub(/^ */, "", hand[who]) + print who ": " hand[who] > "/dev/stderr" + say(who, "unicode :(") + say(who, "colors :(") } /^\s*$/ { + for (pi=0; pi