void switchChannels(char* from, char* to, struct USER *user) { struct CNODE *channelIterator; pthread_mutex_lock(&channels.channels_mutex); channelIterator = channels_find(&channels, to); if (channelIterator == NULL) { pthread_mutex_unlock(&channels.channels_mutex); sendError("Channel does not exist. You can create using /create <alias>", user); return; } struct CHANNEL *channelToJoin = &channelIterator->channel; channelIterator = channels_find(&channels, from); struct CHANNEL *channelToLeave = &channelIterator->channel; pthread_mutex_unlock(&channels.channels_mutex); pthread_mutex_lock(&channelToJoin->channel_mutex); channel_insert(channelToJoin, user); pthread_mutex_unlock(&channelToJoin->channel_mutex); bzero(user->channelAlias, ALIAS_LEN); strcpy(user->channelAlias, channelToJoin->alias); pthread_mutex_lock(&channelToLeave->channel_mutex); channel_delete(channelToLeave, user); pthread_mutex_unlock(&channelToLeave->channel_mutex); }
void removeUser(struct USER *user) { struct CNODE *channelIterator; channelIterator = channels_find(&channels, user->channelAlias); struct CHANNEL *channel = &channelIterator->channel; pthread_mutex_lock(&channel->channel_mutex); channel_delete(channel, user); pthread_mutex_unlock(&channel->channel_mutex); }
t_channel *channel_new(const char *name) { t_channel *this; if ((this = malloc(sizeof(t_channel))) == NULL) return (NULL); if (channel_ctor(this, name) == RET_FAILURE) { channel_delete(this); return (NULL); } return (this); }
PUBLIC BOOL HTMuxChannel_delete (HTMuxChannel * me) { if (me) { HTList * list = NULL; HTTRACE(MUX_TRACE, "Mux Channel. Deleting %p\n" _ me); if (muxchs && (list = muxchs[me->hash])) { HTList_removeObject(list, (void *) me); channel_delete(me); return YES; } } return NO; }
void chanmod_command_delchan (NICK * nick, CHANNEL * channel, const char *cmd, const char **args, int argc) { char *c; if ((channel->permanent != 0) || ((nick->user->admin == 0) && !(user_get_channel_modes (nick->user, channel) & USER_OWNER))) { puttext ("NOTICE %s :You cannot remove channel %s\r\n", nick->nick, channel->channel); return; } c = strdup (channel->channel); channel_delete (c); puttext ("NOTICE %s :Deleted channel %s\r\n", nick->nick, c); free (c); }
PUBLIC BOOL HTMuxChannel_deleteAll (void) { if (muxchs) { HTList * cur; int cnt; for (cnt=0; cnt<HOST_HASH_SIZE; cnt++) { if ((cur = muxchs[cnt])) { HTMuxChannel * pres; while ((pres = (HTMuxChannel *) HTList_nextObject(cur))) channel_delete(pres); } HTList_delete(muxchs[cnt]); } HT_FREE(muxchs); } return YES; }
/** * Make player leave the channel and cleanup association * - If no one remains in the chat, delete it * @param channel: Channel data * @param sd: Player data * @param flag: Called from deletion process, do not recall delete * @return * 0: Success * -1: Invalid player or channel */ int channel_clean(struct Channel *channel, struct map_session_data *sd, int flag) { unsigned char i; if(!channel || !sd) return -1; if( channel == sd->gcbind ) sd->gcbind = NULL; ARR_FIND(0, sd->channel_count, i, sd->channels[i] == channel); if( i < sd->channel_count ) { unsigned char cursor = i; sd->channels[i] = NULL; sd->channel_tick[i] = 0; for(; i < sd->channel_count; i++ ) { //slice move list down if( sd->channels[i] == NULL ) continue; if(i != cursor) { sd->channels[cursor] = sd->channels[i]; sd->channel_tick[cursor] = sd->channel_tick[i]; } cursor++; } if ( !(sd->channel_count = cursor) ) { //if in no more chan delete db aFree(sd->channels); aFree(sd->channel_tick); sd->channels = NULL; sd->channel_tick = NULL; } } idb_remove(channel->users,sd->status.char_id); //remove user for channel user list //auto delete when no more user in if( !db_size(channel->users) && !(flag&1) ) channel_delete(channel,false); return 0; }
/** * A player is attempting to delete a channel * @param sd: Player data * @param chname: Channel name * @return 0 on success or -1 on failure */ int channel_pcdelete(struct map_session_data *sd, char *chname){ struct Channel *channel; char output[CHAT_SIZE_MAX]; if(!sd || !chname) return 0; if( channel_chk(chname,NULL,1) ) { clif_displaymessage(sd->fd, msg_txt(sd,1405));// Channel name must start with '#'. return -1; } channel = channel_name2channel(chname,sd,0); if(channel_pc_haschan(sd,channel)<0){ sprintf(output, msg_txt(sd,1425),chname);// You're not part of the '%s' channel. clif_displaymessage(sd->fd, output); return -2; //channel doesn't exist or player don't have it } channel_delete(channel,false); sprintf(output, msg_txt(sd,1448),chname); // Channel '%s' deleted. clif_displaymessage(sd->fd, output); return 0; }