?? channel.c
字號:
old_channel->shortname = xstrdup(channel->shortname); old_channel->memberlist = NULL; member = channel->memberlist; /* First pass */ while (member) { old_member = xmalloc(sizeof(t_channelmember)); old_member->connection = member->connection; if (old_channel->memberlist) old_member->next = old_channel->memberlist; else old_member->next = NULL; old_channel->memberlist = old_member; member = member->next; } /* Second pass - remove connections from channel */ member = old_channel->memberlist; while (member) { channel_del_connection(channel,member->connection); conn_set_channel_var(member->connection,NULL); member = member->next; } list_prepend_data(channellist_old,old_channel); } /* Channel is empty - Destroying it */ channel->flags &= ~channel_flags_permanent; if (channel_destroy(channel,&curr)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not destroy channel"); } /* Cleanup and reload */ if (list_destroy(channellist_head)<0) return -1; channellist_head = NULL; channellist_create(); /* Now put all users on their previous channel */ LIST_TRAVERSE(channellist_old,curr) { if (!(channel = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"old channel list contains NULL item"); continue; } memberlist = channel->memberlist; while (memberlist) { member = memberlist; memberlist = memberlist->next; conn_set_channel(member->connection, channel->shortname); } } /* Ross don't blame me for this but this way the code is cleaner */ LIST_TRAVERSE(channellist_old,curr) { if (!(channel = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"old channel list contains NULL item"); continue; } memberlist = channel->memberlist; while (memberlist) { member = memberlist; memberlist = memberlist->next; xfree((void*)member); } if (channel->shortname) xfree((void*)channel->shortname); if (list_remove_data(channellist_old,channel,&curr)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not remove item from list"); xfree((void*)channel); } if (list_destroy(channellist_old)<0) return -1; } return 0;} extern int channellist_create(void){ channellist_head = list_create(); return channellist_load_permanent(prefs_get_channelfile());}extern int channellist_destroy(void){ t_channel * channel; t_elem * curr; if (channellist_head) { LIST_TRAVERSE(channellist_head,curr) { if (!(channel = elem_get_data(curr))) /* should not happen */ { eventlog(eventlog_level_error,__FUNCTION__,"channel list contains NULL item"); continue; } channel_destroy(channel,&curr); } if (list_destroy(channellist_head)<0) return -1; channellist_head = NULL; } return 0;}extern t_list * channellist(void){ return channellist_head;}extern int channellist_get_length(void){ return list_get_length(channellist_head);}extern int channel_get_max(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return 0; } return channel->maxmembers;}extern int channel_get_curr(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return 0; } return channel->currmembers;}extern int channel_conn_is_tmpOP(t_channel const * channel, t_connection * c){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return 0; } if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account"); return 0; } if (!conn_get_tmpOP_channel(c)) return 0; if (strcmp(conn_get_tmpOP_channel(c),channel_get_name(channel))==0) return 1; return 0;}extern int channel_conn_has_tmpVOICE(t_channel const * channel, t_connection * c){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return 0; } if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account"); return 0; } if (!conn_get_tmpVOICE_channel(c)) return 0; if (strcmp(conn_get_tmpVOICE_channel(c),channel_get_name(channel))==0) return 1; return 0;}static t_channel * channellist_find_channel_by_fullname(char const * name){ t_channel * channel; t_elem const * curr; if (channellist_head) { LIST_TRAVERSE(channellist_head,curr) { channel = elem_get_data(curr); if (!channel->name) { eventlog(eventlog_level_error,__FUNCTION__,"found channel with NULL name"); continue; } if (strcasecmp(channel->name,name)==0) return channel; } } return NULL;}/* Find a channel based on the name. * Create a new channel if it is a permanent-type channel and all others * are full. */extern t_channel * channellist_find_channel_by_name(char const * name, char const * country, char const * realmname){ t_channel * channel; t_elem const * curr; int foundperm; int foundlang; int maxchannel; /* the number of "rollover" channels that exist */ char const * saveshortname; char const * savespecialname; char const * savetag; int savebotflag; int saveoperflag; int savelogflag; unsigned int savemoderated; char const * savecountry; char const * saverealmname; int savemaxmembers; t_channel * special_channel; // try to make gcc happy and initialize all variables saveshortname = savespecialname = savetag = savecountry = saverealmname = NULL; savebotflag = saveoperflag = savelogflag = savemaxmembers = savemoderated = 0; maxchannel = 0; foundperm = 0; foundlang = 0; if (channellist_head) { LIST_TRAVERSE(channellist_head,curr) { channel = elem_get_data(curr); if (!channel->name) { eventlog(eventlog_level_error,__FUNCTION__,"found channel with NULL name"); continue; } if (strcasecmp(channel->name,name)==0) { // eventlog(eventlog_level_debug,__FUNCTION__,"found exact match for \"%s\"",name); return channel; } if (channel->shortname && strcasecmp(channel->shortname,name)==0) { special_channel = channellist_find_channel_by_name(channel->name,country,realmname); if (special_channel) channel= special_channel; /* FIXME: what should we do if the client doesn't have a country? For now, just take the first * channel that would otherwise match. */ if ( ((!channel->country && !foundlang) || !country || (channel->country && country && (strcmp(channel->country, country)==0))) && ((!channel->realmname && !realmname) || (channel->realmname && realmname && (strcmp(channel->realmname, realmname)==0))) ) { if (channel->maxmembers==-1 || channel->currmembers<channel->maxmembers) { eventlog(eventlog_level_debug,__FUNCTION__,"found permanent channel \"%s\" for \"%s\"",channel->name,name); return channel; } if (!foundlang && (channel->country)) //remember we had found a language specific channel but it was full { foundlang = 1; if (!(channel->flags & channel_flags_autoname)) savespecialname = channel->name; maxchannel = 0; } maxchannel++; } // eventlog(eventlog_level_debug,__FUNCTION__,"countries didn't match"); foundperm = 1; /* save off some info in case we need to create a new copy */ saveshortname = channel->shortname; savetag = channel->clienttag; savebotflag = channel->flags & channel_flags_allowbots; saveoperflag = channel->flags & channel_flags_allowopers; if (channel->logname) savelogflag = 1; else savelogflag = 0; if (country) savecountry = country; else savecountry = channel->country; if (realmname) saverealmname = realmname; else saverealmname = channel->realmname; savemaxmembers = channel->maxmembers; savemoderated = channel->flags & channel_flags_moderated; } } } /* we've gone thru the whole list and either there was no match or the * channels are all full. */ if (foundperm) /* All the channels were full, create a new one */ { char * channelname; if (!foundlang || !savespecialname) { if (!(channelname=channel_format_name(saveshortname,savecountry,saverealmname,maxchannel+1))) return NULL; } else { if (!(channelname=channel_format_name(savespecialname,NULL,saverealmname,maxchannel+1))) return NULL; } channel = channel_create(channelname,saveshortname,savetag,1,savebotflag,saveoperflag,savelogflag,savecountry,saverealmname,savemaxmembers,savemoderated,0,1); xfree(channelname); eventlog(eventlog_level_debug,__FUNCTION__,"created copy \"%s\" of channel \"%s\"",(channel)?(channel->name):("<failed>"),name); return channel; } /* no match */ eventlog(eventlog_level_debug,__FUNCTION__,"could not find channel \"%s\"",name); return NULL;}extern t_channel * channellist_find_channel_bychannelid(unsigned int channelid){ t_channel * channel; t_elem const * curr; if (channellist_head) { LIST_TRAVERSE(channellist_head,curr) { channel = elem_get_data(curr); if (!channel->name) { eventlog(eventlog_level_error,__FUNCTION__,"found channel with NULL name"); continue; } if (channel->id==channelid) return channel; } } return NULL;}extern int channel_set_userflags(t_connection * c){ unsigned int newflags; char const * channel; t_account * acc; if (!c) return -1; // user not connected, no need to update his flags acc = conn_get_account(c); /* well... unfortunatly channel_get_name never returns NULL but "" instead so we first have to check if user is in a channel at all */ if ((!conn_get_channel(c)) || (!(channel = channel_get_name(conn_get_channel(c))))) return -1; if (account_get_auth_admin(acc,channel) == 1 || account_get_auth_admin(acc,NULL) == 1) newflags = MF_BLIZZARD; else if (account_get_auth_operator(acc,channel) == 1 || account_get_auth_operator(acc,NULL) == 1) newflags = MF_BNET; else if (channel_conn_is_tmpOP(conn_get_channel(c),c)) newflags = MF_GAVEL; else if ((account_get_auth_voice(acc,channel) == 1) || (channel_conn_has_tmpVOICE(conn_get_channel(c),c))) newflags = MF_VOICE; else if ((conn_get_clienttag(c) == CLIENTTAG_WARCRAFT3_UINT) || (conn_get_clienttag(c) == CLIENTTAG_WAR3XP_UINT)) newflags = W3_ICON_SET; else newflags = 0; if (conn_get_flags(c) != newflags) { conn_set_flags(c, newflags); channel_update_userflags(c); } return 0;}/*** Westwood Online Extensions*/extern char const * channel_wol_get_game_owner(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return NULL; } return channel->gameOwner;}extern int channel_wol_set_game_owner(t_channel * channel, char const * gameOwner){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return 0; } if (channel->gameOwner) xfree((void *)channel->gameOwner); /* avoid warning */ channel->gameOwner = xstrdup(gameOwner); return 1;}extern int channel_wol_get_game_ownerip(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return -1; } return channel->gameOwnerIP;}extern int channel_wol_set_game_ownerip(t_channel * channel, int gameOwnerIP){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return 0; } if (gameOwnerIP) channel->gameOwnerIP = gameOwnerIP; return 1;}extern int channel_wol_get_game_type(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return -1; } return channel->gameType;}extern int channel_wol_set_game_type(t_channel * channel, int gameType){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return 0; } if (gameType) channel->gameType = gameType; return 1;}extern int channel_wol_get_game_tournament(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return -1; } return channel->gameTournament;}extern int channel_wol_set_game_tournament(t_channel * channel, int gameTournament){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return 0; } if (gameTournament) channel->gameTournament = gameTournament; return 1;}extern char const * channel_wol_get_game_options(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return NULL; } return channel->gameOptions;}extern int channel_wol_set_game_options(t_channel * channel, char const * gameOptions){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return 0; } if (channel->gameOptions) xfree((void *)channel->gameOptions); /* avoid warning */ channel->gameOptions = xstrdup(gameOptions); return 1;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -