]> Pileus Git - ~andy/rhawk/commitdiff
Allow players to grant access to other IRC users
authorAndy Spencer <andy753421@gmail.com>
Sat, 10 Aug 2013 05:13:48 +0000 (05:13 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 10 Aug 2013 07:17:37 +0000 (07:17 +0000)
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
spades.awk
test.awk
test.txt

diff --git a/mkfile b/mkfile
index e9a6d991f1c80388eea97a54436626bebbfe4423..201a4ecdbc3d31246f9192c0d517d212aefd8f62 100644 (file)
--- 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
index e5516e0710079d6575d33603f95be6254fc557a6..15091170df583c481050a45835318ff1e2279b9d 100644 (file)
@@ -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)\>/ {
index 3758f284d00d05981fcf541595400bb2dd70564d..808a8e74514fa2ad2078b98bec50d3541417b10a 100644 (file)
--- 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<length(players); pi++)
+               if (auths[pi])
+                       auth(auths[pi], players[pi])
        for (ti=0; ti<nturns; ti++)
                for (pi=0; pi<length(players); pi++)
                        command(players[pi], turns[pi][ti])
index 45ea615c5c331f0aa4d912cf211d4b0c16c19ef6..9ba0ddffd10d9f3426eeb55facc3281b21c36238 100644 (file)
--- a/test.txt
+++ b/test.txt
 #   nn   - newgame to n
 #   e    - endgame
 #   j    - join
+#   Y    - allow
+#   N    - deny
+#   S    - show
+#   d    - deal
 #   l    - look
 #   bn   - bid n
 #   s    - score
 #   B    - bids
 #   t    - tricks
-#   t    - tricks
 #   T    - turn
 #   pn   - pass card n
 #   card - play card
 #  -card - play but don't add to deck
 #  +card - add to deck but don't play
 
+# Test allow / deny
+#          .- The game has not yet started
+#          |          .- You are not playing
+#          |          |- Is a primary player
+#          |          |- Is not logged in
+#          |          |- Can now playing for
+#          |          |- Is already playing for
+#          |          |      .- You are not playing
+#          |          |      |- Is a primary player
+#          |          |      |- Is not playing for
+#          |          |      |- Can no longer play
+#          |          |      |- Is not playing for
+auth/auth: .        . .      .     . .  .     -As
+nope:      .        . Yauth  Nauth . .  .      .
+a/aa:      n        . Ya     Na    d b1 Yauth +As
+b/bb:      Ynewgame j Ynope  Nnope d b1 .      Ah
+c/cc:      Nnewgame j Yauth  Nauth d b1 .      Ad
+d/dd:      .        j Yauth  Nauth d b1 .      Ac
+
 # Test scoring
-x: s s s s s s s  s  s  s  s  s
-x: B B B B B B B  B  B  B  B  B
-x: t t t t t t t  t  t  t  t  t
-x: T T T T T T T  T  T  T  T  T
-A: n j . . . d b3 .  .  .  As .
-b: . . j . . d .  b3 .  .  Ah .
-c: . . . j . d .  .  b3 .  Ad .
-d: . . . . j d .  .  .  b3 Ac .
+#x: s s s s s s s  s  s  s  s  s
+#x: B B B B B B B  B  B  B  B  B
+#x: t t t t t t t  t  t  t  t  t
+#x: T T T T T T T  T  T  T  T  T
+#A: n j . . . d b3 .  .  .  As .
+#b: . . j . . d .  b3 .  .  Ah .
+#c: . . . j . d .  .  b3 .  Ad .
+#d: . . . . j d .  .  .  b3 Ac .
 
 # Nil/blind
 #a: n j d l b0  .  .    As Ks Qs Js 10s 9s 8s 7s 6s 5s 4s 3s 2s t e