SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
#include "log.h"
#include "list.h"
#include "client.h"
ch_dst = ch_itr;
list_add_tail(&ch_dst->link_node, &ch_src->channel_links);
- Log_info("Adding channel link %s -> %s", ch_src->name, ch_dst->name);
+ ch_src->linkcount++;
+ Log_info("Adding channel link '%s' -> '%s'", ch_src->name, ch_dst->name);
}
}
list_iterate_safe(itr, save, &channels) {
ch = list_get_entry(itr, channel_t, flatlist_node);
- Log_debug("Free channel %s", ch->name);
+ Log_debug("Free channel '%s'", ch->name);
free(ch->name);
if (ch->desc)
free(ch->desc);
}
-int Chan_playerJoin(channel_t *ch, client_t *client)
+int Chan_userLeave(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;
Chan_freeChannel(leaving);
}
}
+ return leaving_id;
+}
+
+int Chan_userJoin(channel_t *ch, client_t *client)
+{
+ int leaving_id;
+
+ Log_debug("Add user %s to channel %s", client->username, ch->name);
+
+ /* Only allowed in one channel at a time */
+ leaving_id = Chan_userLeave(client);
list_add_tail(&client->chan_node, &ch->clients);
client->channel = (void *)ch;
return leaving_id;
}
-int Chan_playerJoin_id(int channelid, client_t *client)
+int Chan_userJoin_id(int channelid, client_t *client)
{
channel_t *ch_itr = NULL;
do {
return -1;
}
else
- return Chan_playerJoin(ch_itr, client);
+ return Chan_userJoin(ch_itr, client);
}
-bool_t Chan_playerJoin_id_test(int channelid)
+bool_t Chan_userJoin_id_test(int channelid)
{
channel_t *ch_itr = NULL;
do {
{
list_del(&ch->node);
}
+
+void Chan_buildTreeList(channel_t *ch, struct dlist *head)
+{
+ channellist_t *chl;
+ struct dlist *itr;
+ channel_t *sub;
+
+ chl = malloc(sizeof(channellist_t));
+ chl->chan = ch;
+ init_list_entry(&chl->node);
+ list_add_tail(&chl->node, head);
+
+ list_iterate(itr, &ch->subs) {
+ sub = list_get_entry(itr, channel_t, node);
+ Chan_buildTreeList(sub, head);
+ }
+}
+
+void Chan_freeTreeList(struct dlist *head)
+{
+ struct dlist *itr, *save;
+ list_iterate_safe(itr, save, head) {
+ free(list_get_entry(itr, channellist_t, node));
+ }
+}