aboutsummaryrefslogtreecommitdiff
path: root/musw.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-05-05 22:35:14 +0000
committerrodri <rgl@antares-labs.eu>2023-05-05 22:35:14 +0000
commitd2c0ab7a62b7a2c99c4c491ce55466859429571b (patch)
tree5010f2e6b2e3a87486a7f65dd73f40eee7fec04c /musw.c
parentf959555dc653ecf54d75b180fcd018075e652e93 (diff)
downloadmusw-d2c0ab7a62b7a2c99c4c491ce55466859429571b.tar.gz
musw-d2c0ab7a62b7a2c99c4c491ce55466859429571b.tar.bz2
musw-d2c0ab7a62b7a2c99c4c491ce55466859429571b.zip
handle player quits gracefully.
also fixed a bug whereby a player would never be freed if no party was happening, and another one where deleting a player from the player queue would cause a nil pointer deref.
Diffstat (limited to 'musw.c')
-rw-r--r--musw.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/musw.c b/musw.c
index 0703393..edd3826 100644
--- a/musw.c
+++ b/musw.c
@@ -232,6 +232,26 @@ initconn(void)
}
void
+buhbye(void)
+{
+ Frame *frame;
+ int i, naptime;
+
+ if(netconn.state != NCSConnected)
+ return;
+
+ i = 10;
+ naptime = 2000/i;
+ while(i--){
+ frame = newframe(nil, NCbuhbye, netconn.lastseq+1, 0, 0, nil);
+ signframe(frame, netconn.dh.priv);
+ sendp(egress, frame);
+
+ sleep(naptime);
+ }
+}
+
+void
sendkeys(ulong kdown)
{
Frame *frame;
@@ -273,8 +293,12 @@ kbdproc(void *)
}
if(buf[0] == 'c'){
if(utfrune(buf, Kdel)){
+defenestrate:
close(fd);
threadexitsall(nil);
+ }else if(utfrune(buf, 'q')){
+ buhbye();
+ goto defenestrate;
}
}
if(buf[0] != 'k' && buf[0] != 'K')
@@ -415,6 +439,15 @@ threadnetppu(void *)
sendp(egress, newf);
break;
+ case NSawol:
+ weplaying = 0;
+
+ newf = newframe(nil, NCawol, frame->seq+1, frame->seq, 0, nil);
+ signframe(newf, netconn.dh.priv);
+
+ sendp(egress, newf);
+
+ break;
case NSbuhbye:
weplaying = 0;
netconn.state = NCSDisconnected;
@@ -607,6 +640,8 @@ State *matching_δ(State *s, void*)
State *playing_δ(State *s, void*)
{
+ if(!weplaying)
+ return &gamestates[GSMatching];
return s;
}