From 3cdeee27cb0c83268f73bfb8a745b0da9dd3f175 Mon Sep 17 00:00:00 2001 From: fatbob313 Date: Thu, 28 Jan 2010 21:49:27 +0000 Subject: [PATCH] Leave channel when disconnecting and remove channel if temporary and last user. --- src/channel.c | 16 ++++++++++++---- src/channel.h | 1 + src/client.c | 8 +++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/channel.c b/src/channel.c index 1e71be3..db5cfaa 100644 --- a/src/channel.c +++ b/src/channel.c @@ -254,14 +254,11 @@ void Chan_addChannel(channel_t *parent, channel_t *ch) } -int Chan_playerJoin(channel_t *ch, client_t *client) +int Chan_playerLeave(client_t *client) { channel_t *leaving = NULL; int leaving_id = -1; - /* Only allowed in one channel at a time */ - Log_debug("Add player %s to channel %s", client->playerName, ch->name); - if (client->channel) { list_del(&client->chan_node); leaving = (channel_t *)client->channel; @@ -270,6 +267,17 @@ int Chan_playerJoin(channel_t *ch, client_t *client) Chan_freeChannel(leaving); } } + return leaving_id; +} + +int Chan_playerJoin(channel_t *ch, client_t *client) +{ + int leaving_id; + + Log_debug("Add player %s to channel %s", client->playerName, ch->name); + + /* Only allowed in one channel at a time */ + leaving_id = Chan_playerLeave(client); list_add_tail(&client->chan_node, &ch->clients); client->channel = (void *)ch; return leaving_id; diff --git a/src/channel.h b/src/channel.h index d0b0a8a..cd916c2 100644 --- a/src/channel.h +++ b/src/channel.h @@ -57,6 +57,7 @@ void Chan_addClient(channel_t *c, client_t *client); void Chan_removeClient(channel_t *c, client_t *client); int Chan_playerJoin(channel_t *ch, client_t *client); int Chan_playerJoin_id(int channelid, client_t *client); +int Chan_playerLeave(client_t *client); bool_t Chan_playerJoin_id_test(int channelid); channel_t *Chan_iterate(channel_t **channelpptr); channel_t *Chan_iterate_siblings(channel_t *parent, channel_t **channelpptr); diff --git a/src/client.c b/src/client.c index 58ffb25..68252dc 100644 --- a/src/client.c +++ b/src/client.c @@ -220,6 +220,13 @@ void Client_free(client_t *client) ntohs(client->remote_tcp.sin_port)); if (client->authenticated) { + int leave_id; + leave_id = Chan_playerLeave(client); + if (leave_id > 0) { /* Remove temp channel */ + sendmsg = Msg_create(ChannelRemove); + sendmsg->payload.channelRemove->channel_id = leave_id; + Client_send_message_except(client, sendmsg); + } sendmsg = Msg_create(UserRemove); sendmsg->payload.userRemove->session = client->sessionId; Client_send_message_except(client, sendmsg); @@ -231,7 +238,6 @@ void Client_free(client_t *client) Voicetarget_free_all(client); list_del(&client->node); - list_del(&client->chan_node); if (client->ssl) SSL_free(client->ssl); close(client->tcpfd); -- 2.30.2