Leave channel when disconnecting and remove channel if temporary and last user.
authorfatbob313 <martin@fatbob.nu>
Thu, 28 Jan 2010 21:49:27 +0000 (21:49 +0000)
committerfatbob313 <martin@fatbob.nu>
Thu, 28 Jan 2010 21:49:27 +0000 (21:49 +0000)
src/channel.c
src/channel.h
src/client.c

index 1e71be3db880492061e52e3495aa91665565a581..db5cfaa4c0e1e5aff595bd029be368dd0b784e20 100644 (file)
@@ -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;
index d0b0a8a4314627b867fff54ff86037a43d134eb4..cd916c29ebe59925594ed3f948c31919020c3db8 100644 (file)
@@ -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);
index 58ffb2514294f3656f5567687a9e4b63fdad70f1..68252dc13da5a03360ed9be17f515a2daedc831d 100644 (file)
@@ -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);