All pastes #166481 Raw Edit

freeone3000

public c v1 · immutable
·published 2006-09-10 23:00 UTC
rendered paste body
void add_to_buffer(Uint8 * msg, int len, int type, int colour){	Uint8 buf[1024];	int this_len;	if (type == 0 && len < 5)		return;		//The message is just garbage from the server, ignore it	lock_text_buffer();	while (len > 0 && *msg) {		this_len = 0;		if (!max_lines % 1000)			cur_buf = (text **) realloc(cur_buf, (max_lines + 1000) * sizeof(text *));	//allocate the next 1000 lines		cur_buf[max_lines] = (text *) calloc(1, sizeof(text));		cur_buf[max_lines]->lines = -1;	//Start, will grow to 0 on next char added.		while (*msg) {			if (*msg == 10) {				msg++;				len--;				break;			}	//Put new lines in a seperate text buffer to make scrolling simpler...			if (!(this_len % text_line_lenght))				cur_buf[max_lines]->lines++;	//Add a line...			if (*msg > 126 && *msg < 155) {				colour = get_colour(*msg);				msg++;				len--;			}			buf[this_len++] = *msg++;		}		len -= this_len;		buf[this_len++] = 0;		cur_buf[max_lines]->text = (char *) calloc(this_len, sizeof(char));		if (buffer_index == max_lines)			buffer_index++;		strcpy(cur_buf[max_lines]->text, buf);		cur_buf[max_lines++]->colour = colour;		if (type != CONSOLE_TEXT) {			fprintf(log_file, "%s\n", buf);			fflush(log_file);		}	}	unlock_text_buffer();}void check_message_type(char *msg, int len){	int type;	if (getting_location_str && !strncmp(msg + 1, "You are in ", 11)) {		get_location_str(msg + 1, len - 1);		return;	}	if ((type = check_if_ignored(msg, len)) < 0)		return;	//AFK...	if (afk) {		if (type == SEND_PM) {			send_afk_message(msg + 1, type); //freeedit			add_message_to_pm_log(msg + 1, len - 1);		} else if (is_talking_about_me(msg + 1, len - 1))			send_afk_message(msg + 1, type);	}	int in_channel = 0;	char channum = *msg; //TODO do lookups.	char *chanstr = malloc(sizeof(char)*13);	if(channum>=5 && channum <= 7) {		sprintf(chanstr, " @ %d", cur_chans[channum-5]);		in_channel = 1;	}	if(in_channel) {		channum -= 5;		char *part1 = malloc(sizeof(char)*50); //TODO restrict the size of these and the next two.		char *part2 = malloc(sizeof(char)*120);		part2 = strchr(msg, ']');		if(part2!=NULL) {			strncpy(part1, msg, strlen(msg)-strlen(part2));			strcat(part1, chanstr);			strcat(part1, part2);#ifdef ELC_CHAT_DEBUG			char *c = malloc(sizeof(char)*50);			sprintf(c, "Color on %d is %d, which %s the current channel", channum, part1[0], (channum==cur_chan)?"is":"isn't");			add_to_text_log(c);			//free c#endif			add_to_buffer(part1+1, strlen(part1), type, part1[0]);			//Should clean up chanstr, part1, and part2 here.		} else {			add_to_buffer(msg+1, len, type, msg[0]);		}	} else {		add_to_buffer(msg+1, len, type, msg[0]); //To remove the whole junk thinger.	}}