diff options
author | rodri <rgl@antares-labs.eu> | 2024-11-16 14:02:27 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-11-16 14:02:27 +0000 |
commit | 8f1306dfeadd090819c1257d2d4c244e52f98614 (patch) | |
tree | 15c3d60b3a4fa0ea41ae52bffe4812577ae4861a /btsd.c | |
parent | ccd149a329f9a33195c2c6216158e283f8993076 (diff) | |
download | battleship-8f1306dfeadd090819c1257d2d4c244e52f98614.tar.gz battleship-8f1306dfeadd090819c1257d2d4c244e52f98614.tar.bz2 battleship-8f1306dfeadd090819c1257d2d4c244e52f98614.zip |
add a stats command. change the main buttons appearance.
Diffstat (limited to 'btsd.c')
-rw-r--r-- | btsd.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -15,6 +15,7 @@ enum { CMshoot, CMgetmatches, CMwatch, + CMgetstats, CMleave, }; Cmdtab clcmd[] = { @@ -24,6 +25,7 @@ Cmdtab clcmd[] = { CMshoot, "shoot", 2, CMgetmatches, "watch", 1, CMwatch, "watch", 2, + CMgetstats, "stats", 1, CMleave, "leave", 1, }; @@ -33,6 +35,7 @@ Channel *playerq; Channel *mmctl; /* matchmaker's */ Match theater; RWLock theaterlk; +Ref nplayers; Player * @@ -187,6 +190,12 @@ sendmatches(Channel *c) } void +sendstats(Channel *c) +{ + chanprint(c, "stats %ld\n", nplayers.ref); +} + +void broadcast(Stands *s, char *fmt, ...) { va_list arg; @@ -260,6 +269,8 @@ playerproc(void *arg) threadsetname("player %s", p->nci->raddr); + incref(&nplayers); + threadsetgrp(p->io.fd); threadcreate(netrecvthread, &p->io, mainstacksize); threadcreate(netsendthread, &p->io, mainstacksize); @@ -287,6 +298,7 @@ playerproc(void *arg) if(ct->index == CMid && strlen(cb->f[1]) > 0){ snprint(p->name, sizeof p->name, "%s", cb->f[1]); sendmatches(p->io.out); + sendstats(p->io.out); }else chanprint(p->io.out, "id\n"); }else @@ -304,7 +316,8 @@ playerproc(void *arg) chanprint(p->io.out, "no such match\n"); else sendp(m->ctl, newmsg(p, estrdup("take seat"))); - } + }else if(ct->index == CMgetstats) + sendstats(p->io.out); break; case Watching: if(ct->index == CMleave) @@ -338,6 +351,9 @@ Nocmd: End: if(debug) fprint(2, "[%d] lost connection\n", getpid()); + + decref(&nplayers); + threadkillgrp(threadgetgrp()); threadexits(nil); } |