Beispiel #1
0
/**
 * A player is attempting to create a channel
 * @param sd: Player data
 * @param chname: Channel name
 * @param chpass: Channel password
 * @return 0 on success or -1 on failure
 */
int channel_pccreate(struct map_session_data *sd, char *chname, char *chpass){
	char output[CHAT_SIZE_MAX];
	int8 res;

	if(!sd || !chname)
		return 0;

	res = channel_chk(chname,chpass,7);
	if(res==0){ //success
		struct Channel *channel = channel_create_simple(chname,chpass,CHAN_TYPE_PRIVATE,sd->status.char_id);
		channel_join(channel,sd);
		if( ( channel->opt & CHAN_OPT_ANNOUNCE_SELF ) ) {
			sprintf(output, msg_txt(sd,1403),chname); // You're now in the '%s' channel.
			clif_displaymessage(sd->fd, output);
		}
	} else { //failure display cause
		switch(res){
		case -1: sprintf(output, msg_txt(sd,1405), CHAN_NAME_LENGTH); break;// Channel name must start with '#'.
		case -2: sprintf(output, msg_txt(sd,1406), CHAN_NAME_LENGTH); break;// Channel length must be between 3 and %d.
		case -3: sprintf(output, msg_txt(sd,1436), CHAN_NAME_LENGTH); break;// Channel password can't be over %d characters.
		case -4: sprintf(output, msg_txt(sd,1407), chname);// Channel '%s' is not available.
		}
		clif_displaymessage(sd->fd, output);
		return -1;
	}
	return 0;
}
Beispiel #2
0
/**
 * Make a player join the guild channel
 * - Create a guild channel if it does not exist
 * @param sd: Player data
 * @param flag: Join type (1 - Guild chat, 2 - Ally chat)
 * @return
 *   0: Success
 *  -1: Invalid player
 *  -2: Player has no guild attached
 */
int channel_gjoin(struct map_session_data *sd, int flag){
	struct Channel *channel;
	struct guild *g;

	if(!sd || sd->state.autotrade) return -1;
	g = sd->guild;
	if(!g) return -2;

	channel = g->channel;
	if(!channel){
		channel = channel_create_simple(NULL,NULL,CHAN_TYPE_ALLY,g->guild_id);
		g->channel = channel;
		channel_ajoin(g);
	}
	if(flag&1) {
		channel_join(channel,sd);	//join our guild chat
	}
	if(flag&2){
		int i;
		for (i = 0; i < MAX_GUILDALLIANCE; i++){
			struct guild *ag; //allied guld
			struct guild_alliance *ga = &g->alliance[i]; //guild alliance
			if(ga->guild_id && (ga->opposition==0) && (ag=guild_search(ga->guild_id)) ) //only join allies
				channel_join(ag->channel,sd);
		}
	}
	return 0;
}
Beispiel #3
0
/**
 * Lookup a channel name
 * @param chname: Channel name
 * @param sd: Player data, can be NULL, used to solve #map and #ally cases
 * @param flag: Lookup types (1 - Create channel if it does not exist (map or ally only), 2 - Join the channel if not joined yet (map or ally only))
 * @return NULL on channel not found or channel data on success
 */
struct Channel* channel_name2channel(char *chname, struct map_session_data *sd, int flag){
	if(channel_chk(chname, NULL, 1))
		return NULL;
	if(sd && strcmpi(chname + 1,channel_config.map_tmpl.name) == 0){
		if(flag&1 && !map[sd->bl.m].channel)
			map[sd->bl.m].channel = channel_create_simple(NULL,NULL,CHAN_TYPE_MAP,sd->bl.m);
		if(flag&2 && channel_pc_haschan(sd,map[sd->bl.m].channel) < 1)
			channel_mjoin(sd);
		return map[sd->bl.m].channel;
	}
	else if(sd && (strcmpi(chname + 1,channel_config.ally_tmpl.name) == 0) && sd->guild){
		if(flag&1 && !sd->guild->channel)
			sd->guild->channel = channel_create_simple(NULL,NULL,CHAN_TYPE_ALLY,sd->guild->guild_id);
		if(flag&2 && channel_pc_haschan(sd,map[sd->bl.m].channel) < 1)
			channel_gjoin(sd,3);
		return sd->guild->channel;
	}
	else
		return (struct Channel*) strdb_get(channel_db, chname + 1);
}
Beispiel #4
0
/**
 * Make a player join the map channel
 * - Create the map_channel if it does not exist
 * @param sd: Player data
 * @return
 *  -1: Invalid player
 *  -2: Player already in channel (channel_join)
 *  -3: Player banned (channel_join)
 */
int channel_mjoin(struct map_session_data *sd) {
	char mout[60];
	if(!sd) return -1;

	if( !map[sd->bl.m].channel ) {
		map[sd->bl.m].channel = channel_create_simple(NULL,NULL,CHAN_TYPE_MAP,sd->bl.m);
	}

	if( map[sd->bl.m].channel->opt & CHAN_OPT_ANNOUNCE_SELF ) {
		sprintf(mout, msg_txt(sd,1435),map[sd->bl.m].channel->name,map[sd->bl.m].name); // You're now in the '#%s' channel for '%s'.
		clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], mout, false, SELF);
	}

	return channel_join(map[sd->bl.m].channel,sd);
}