From 8f1306dfeadd090819c1257d2d4c244e52f98614 Mon Sep 17 00:00:00 2001 From: rodri Date: Sat, 16 Nov 2024 14:02:27 +0000 Subject: add a stats command. change the main buttons appearance. --- btsd.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'btsd.c') diff --git a/btsd.c b/btsd.c index 1d640f8..9a6807a 100644 --- a/btsd.c +++ b/btsd.c @@ -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 * @@ -186,6 +189,12 @@ sendmatches(Channel *c) runlock(&theaterlk); } +void +sendstats(Channel *c) +{ + chanprint(c, "stats %ld\n", nplayers.ref); +} + void broadcast(Stands *s, char *fmt, ...) { @@ -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); } -- cgit v1.2.3