Beispiel #1
0
int filter_or_ignore_text(unsigned char *text_to_add, int len)
{
	int	l, type;
	unsigned char *ptr;

	//check for auto receiving #help
	for(ptr=text_to_add, l=len; l >0; ptr++, l--){
		if(!(*ptr&0x80))	break;
	}
	if(len > 0 && *ptr == '#' && !strncasecmp(ptr, "#help request", 9)){
		auto_open_encyclopedia= 0;
	}

	//check if ignored
	type=strncasecmp(&text_to_add[1],"[PM from",8)?0:1;
	if(pre_check_if_ignored(text_to_add,type))return 0;
	//All right, we do not ignore the person
	if(afk)
		{
			if(type)add_message_to_pm_log(text_to_add,len);
			else if(is_talking_about_me(&text_to_add[1],len-1))send_afk_message(&text_to_add[1], type);
		}
	//parse for URLs
	find_last_url(text_to_add,len);
	//filter any naughty words out
	return(filter_text(text_to_add, len));
}
int main() {
	char* words = console_read_line(100, 1000);
	char** words_split = NULL;
	int split_len = str_split(&words_split, words, ", ");
	char* text = console_read_line(100, 1000);
	text = filter_text(text, words_split, split_len, '*');

	printf("\n%s\n", text);

	if (words_split) free_str_arr(words_split, split_len);
	if (words) free(words);
	if (text) free(text);
	return 0;
}
Beispiel #3
0
int main() 
{
	vector<string,allocator>   *text_file      = retrieve_text();
        text_loc 		   *text_locations = separate_words( text_file );

        string filt_elems( "\",.;:!?)(" );
        filter_text( text_locations->first, filt_elems );
        suffix_text( text_locations->first );	
	strip_caps(  text_locations->first );

	map<string,loc*,less<string>,allocator> *text_map = build_word_map( text_locations );
        query_text( text_file, text_map );

	return 0;
}
Beispiel #4
0
void ftp_printf(int sock,char *fmt,...){
 char *buf;
 va_list ap;
 if(!(buf=(char *)malloc(1024+1)))
  printe("ftp_printf(): allocating memory failed.",1);
 memset(buf,0x0,1024+1);
 va_start(ap,fmt);
 vsnprintf(buf,1024,fmt,ap);
 va_end(ap);
 write(sock,buf,strlen(buf)); /* write it, then mod it for display. */
 filter_text(buf);
 if(!no_io)
  printf("-> %s\n",buf);
 free(buf);
 return;
}
Beispiel #5
0
int main() 
{
	vector<string,allocator>   *text_file      = retrieve_text();
        text_loc 		   *text_locations = separate_words( text_file );

        string filt_elems( "\",.;:!?)(" );
        filter_text( text_locations->first, filt_elems );

	ostream_iterator< string > output( cout, "\n" );

	cout << "----------- about to generate text read --------------\n";
        copy( text_file->begin(), text_file->end(), output );

	cout << "-------- about to generate word and location data ----\n";
	display_text_locations( text_locations );

	return 0;
}
Beispiel #6
0
void ftp_read(int sock){
 char *buf;
 if(!(buf=(char *)malloc(1024+1)))
  printe("ftp_read(): allocating memory failed.",1);
 memset(buf,0x0,1024);
 read(sock,buf,1024);
 filter_text(buf);
 if(!no_io)
  printf("<- %s\n",buf);
 /* some initial reply checking, not too much. */
 if(!ftp_i)
  if(!strstr(buf,"GtkFTPd"))
   printe("this exploit is only for GtkFTPd, failed.",1);
 if(ftp_i==2)
  if(strncmp(buf,"230",3))
   printe("invalid username/password, failed.",1);
 if(ftp_i==3)
  if(strncmp(buf,"250",3))
   printe("invalid writable directory, failed. (try \"/\")",1);
 free(buf);
 ftp_i++; /* increase the response identifier. */
 return;
}
Beispiel #7
0
int filter_or_ignore_text (char *text_to_add, int len, int size, Uint8 channel)
{
	int l, idx;

	if (len <= 0) return 0;	// no point

	//check for auto receiving #help
	for (idx = 0; idx < len; idx++)
	{
		if (!is_color (text_to_add[idx])) break;
	}
	l = len - idx;
	if (l >= strlen(help_request_str) && text_to_add[idx] == '#' && (strncasecmp (&text_to_add[idx], help_request_str, strlen(help_request_str)) == 0 || strncasecmp (&text_to_add[idx], "#mod chat", 9) == 0))
	{
		auto_open_encyclopedia = 0;
	}

	/*
	DANGER, WILL ROBINSON!

	The below code should not exist in it's present form.  I'd change it,
	but I'd need access to the server.  Simply checking text output (which
	is used for all sorts of things) for the phrase "Game Date" is very
	dangerous.  Example: what if, in the future, we allow spaces in
	character names?  Someone chooses the name "Game Date" and walks around
	saying "hi".  Everyone's clients in the area interpret this as being a
	Game Date command.

	I've made the below code not *as* dangerous. Had a user been able to
	fake out the below code, previously, it would have caused a buffer overflow
	in their client if they didn't write in only numbers after it.  Now, they
	won't crash; it'll just be misparsed.

	General practice recommendation: don't mix server commands with user
	input.

	 - Karen
	*/
	/*
	ed (ttlanhil): made it check if it's a server colour. still not perfect
	(this should have been done server-side instead of parsing the date), but safer
	*/
	if (from_color_char (text_to_add[0]) == c_green1 && my_strncompare(text_to_add+1,"Game Date", 9))
	{
		//we assume that the server will still send little-endian dd/mm/yyyy... we could make it safer by parsing the format too, but it's simpler to assume
		const char * const month_names[] = { "Aluwia", "Seedar", "Akbar", "Zartia", "Elandra", "Viasia", "Fruitfall", "Mortia", "Carnelar", "Nimlos", "Chimar", "Vespia" };
		const char * const day_names[] = { "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th" };
		char new_str[100];
		const char *ptr=text_to_add;
		short unsigned int day=1, month=1, year=0;
		int offset = 0;

		while(!isdigit(ptr[offset]))
		{
			offset++;
			if (offset >= sizeof(new_str))
			{
				LOG_ERROR("error (1) parsing date string: %s",text_to_add);
				//something evil this way comes...
				return 0;
			}
		}
		ptr += offset;

		if (sscanf (ptr,"%hu%*[-/]%hu%*[-/]%hu",&day,&month,&year) < 3
		    || day <= 0 || month <= 0
		    || day > 30 || month > 12 || year > 9999)
		{
			LOG_ERROR("error (2) parsing date string: %s",text_to_add);
			//something evil this way comes...
		}
		else
		{
			// only display initial or "#date" user requested date
			if (!set_date(ptr))
			{
				safe_snprintf(new_str, sizeof(new_str), date_format, day_names[day-1], month_names[month-1], year);
				LOG_TO_CONSOLE(c_green1, new_str);
			}

			//Calculate fraction Big Lunar month (2 conjunction months) less game clock time
			//Represented in Degrees.
			skybox_time_d = (SDL_GetTicks()%( 1296000 * 1000 ));
			skybox_time_d *= 360.0/( 1296000.0 * 1000.0);
			skybox_time_d = -skybox_time_d;
			skybox_time_d += 360.0 * (((month%2)*30 + day-1)*360 + game_minute)/21600.0;
			skybox_update_positions();
			return 0;
		}
	}

	if (from_color_char (text_to_add[0]) == c_green1 && my_strncompare(text_to_add+1,"Game Time", 9))
	{
		real_game_second = atoi(&text_to_add[18]);
		next_second_time = cur_time + 1000;
        new_second();
	}

	// Check for local messages to be translated into actor movements (contains [somthing])
	if (channel == CHAT_LOCAL)
	{
		if(parse_text_for_emote_commands(text_to_add, len)) return 0;
	}

	if (channel == CHAT_SERVER) {
		if (my_strncompare(text_to_add+1, "You started to harvest ", 23)) {
			strncpy(harvest_name, text_to_add+1+23, len-1-23-1);
			harvest_name[len-1-23-1] = '\0';
			harvesting = 1;
		}
		else if ((my_strncompare(text_to_add+1, "You stopped harvesting.", 23)) ||
			(my_strncompare(text_to_add+1, "You can't harvest while fighting (duh)!", 39)) ||
			(my_strncompare(text_to_add+1, "You can't do that while trading!", 32)) ||
			(my_strncompare(text_to_add+1, "You are too far away! Get closer!", 33)) ||
			(my_strncompare(text_to_add+1, "You can't harvest here", 22)) ||
			(my_strncompare(text_to_add+1, "You lack the knowledge of ", 26)) ||
			((my_strncompare(text_to_add+1, "You need to wear ", 17) && strstr(text_to_add, "order to harvest") != NULL)) ||
			((my_strncompare(text_to_add+1, "You need to have a ", 19) && strstr(text_to_add, "order to harvest") != NULL)))
		{
			harvesting = 0;
		}
		else if (is_death_message(text_to_add+1)) {
			// nothing to be done here cause all is done in the test function
		}
		else if (my_strncompare(text_to_add+1, "You found ", 10) && strstr(text_to_add+1, " coins.")) {
			decrement_harvest_counter(atoi(text_to_add+11));
		} 
		else if (my_strncompare(text_to_add+1, "Send Item UIDs ", 15)) {
			if (text_to_add[1+15] == '0')
				item_uid_enabled = 0;
			else if (text_to_add[1+15] == '1')
				item_uid_enabled = 1;
			printf("item_uid_enabled=%d\n", item_uid_enabled);
		}
		else if ((copy_next_LOCATE_ME > 0) && my_strncompare(text_to_add+1, "You are in ", 11)) {
			char buffer[4096];
			switch (copy_next_LOCATE_ME)
			{
				case 1:
					copy_to_clipboard(text_to_add+1);
					break;
				case 2:
					snprintf(buffer, sizeof(buffer), "@My Position: %s", text_to_add + 12);
					send_input_text_line(buffer, strlen(buffer));
					break;
			}
			copy_next_LOCATE_ME = 0;
			return 0;
		}
		else if (my_strncompare(text_to_add+1, "You see: ", 9)) {
			achievements_player_name(text_to_add+10, len-10);
		}
		else if (my_strncompare(text_to_add+1, "You just got food poisoned!", 27)) {
			increment_poison_incidence();
		}
		else if (strstr(text_to_add+1, "aborted the trade.")) {
			trade_aborted(text_to_add+1);
		}
		else if (strstr(text_to_add+1, "Trade session failed")) {
			trade_aborted(text_to_add+1);
		}
		else if (strstr(text_to_add+1, "You have been saved!")) {
			last_save_time = time(NULL);
		}
		
	} else if (channel == CHAT_LOCAL) {
		if (harvesting && my_strncompare(text_to_add+1, username_str, strlen(username_str))) {
			char *ptr = text_to_add+1+strlen(username_str);
			if (my_strncompare(ptr, " found a ", 9)) {
				ptr += 9;
				if (my_strncompare(ptr, "bag of gold, getting ", 21)) {
					decrement_harvest_counter(atoi(ptr+21));
				} else if (!strstr(ptr, " could not carry ")) {
					decrement_harvest_counter(1);
				}
			}
		} else if (my_strncompare(text_to_add+1, "(*) ", 4)) {
			increment_summon_counter(text_to_add+1+4);
			if (summoning_filter) return 0;
		}
	}
	/* check for misc counter strings */
	catch_counters_text(text_to_add+1);

	/* put #mpm in a popup box, on top of all else */
	if ((channel == CHAT_MODPM) && (my_strncompare(text_to_add+1, "[Mod PM from", 12))) {
		display_server_popup_win(text_to_add);
	}

	//Make sure we don't check our own messages.
	if( !(channel == CHAT_PERSONAL && len >= strlen(pm_from_str) && strncasecmp (text_to_add+1, pm_from_str, strlen(pm_from_str)) != 0) &&
		!(channel == CHAT_MODPM && len >= strlen(mod_pm_from_str) && strncasecmp (text_to_add+1, mod_pm_from_str, strlen(mod_pm_from_str)) != 0)
	) {

		//check if ignored - pre_check_if_ignored() checks for Mod PM's etc to not ignore (or it  would be asking for trouble)
		if (pre_check_if_ignored (text_to_add, len, channel))
		{
			return 0;
		}
		//All right, we do not ignore the person
		if (afk)
		{
			if (channel == CHAT_PERSONAL || channel == CHAT_MODPM)
			{
				// player sent us a PM
				add_message_to_pm_log (text_to_add, len, channel);
				if (afk_snd_warning) {
					do_afk_sound();
				}
			}
			else if (channel == CHAT_LOCAL && from_color_char (text_to_add[0]) == c_grey1 && is_talking_about_me (&text_to_add[1], len-1, 0))
			{
				// player mentions our name in local chat
				if (afk_local) {
					add_message_to_pm_log (&text_to_add[1], len - 1, channel);
					if (afk_snd_warning) {
						do_afk_sound();
					}
				} else {
					send_afk_message (&text_to_add[1], len - 1, channel);
				}
			}
			else if (channel == CHAT_SERVER)
			{
				// check if this was a trade attempt
				int i;
				for (i = 1; i < len; i++) {
					if (text_to_add[i] == ' ' || text_to_add[i] == ':' || is_color (text_to_add[i])) {
						break;
					}
				}
				if (i < len-15 && strncasecmp (&text_to_add[i], " wants to trade", 15) == 0) {
					send_afk_message (&text_to_add[1], len - 1, channel);
					if (afk_snd_warning) {
						do_afk_sound();
					}
				}
			}
		}
	} else {	//We sent this PM or MODPM. Can we expect a reply?
		int len = 0;
		char name[MAX_USERNAME_LENGTH];
		for(;text_to_add[len+8] != ':' && len < MAX_USERNAME_LENGTH - 1; ++len);
		safe_strncpy(name, text_to_add+8, len+1);
		if(check_if_ignored(name)){
			char msg[65];
			safe_snprintf(msg, sizeof(msg), warn_currently_ignoring, name);
			LOG_TO_CONSOLE(c_red2, msg);
		}
	}

	// parse for URLs
	find_all_url (text_to_add, len);

	// look for buddy-wants-to-add-you messages
	if(channel == CHAT_SERVER && from_color_char (text_to_add[0]) == c_green1)
	{
		for (l = 1; l < len; l++)
		{
			if (text_to_add[l] == ' ') break;
		}
		if (len - l >= strlen(msg_accept_buddy_str) && strncmp (&text_to_add[l], msg_accept_buddy_str, strlen(msg_accept_buddy_str)) == 0 && l <=32)
		{
			char name[32];
			int i;
			int cur_char;
			/*entropy says: I really fail to understand the logic of that safe_snprintf. And gcc can't understand it either
			  because the name is corrupted. so we implement it the old fashioned way.
			  Grum responds: actually it's the MingW compiler on windows that doesn't understand it, because it doesn't
			  terminate the string when the buffer threatens to overflow. It works fine with gcc on Unix, and using
			  sane_safe_snprintf should also fix it on windows.
			safe_snprintf (name, l, "%s", &text_to_add[1]);
			*/
			for (i = 0; i < sizeof (name); i++)
			{
				cur_char = text_to_add[i+1];
				name[i] = cur_char;
				if (cur_char == ' ')
				{
					name[i] = '\0';
					break;
				}
			}
			add_buddy_confirmation (name);
		}
	}

	// look for astrology messages
	if((channel == CHAT_SERVER) && is_astrology_message (text_to_add))
	{
		return 0;
	}

	// filter any naughty words out
	return filter_text (text_to_add, len, size);
}
Beispiel #8
0
void
fallback_dialog_show (Defaults*    d,
		      const gchar* sender,
		      const gchar* app_name,
		      int          id,
		      const gchar* title_text,
		      const gchar* _body_message,
		      gchar**      actions)
{
	GtkWidget* dialog;
	GtkWidget* hbox;
	GtkWidget* vbox;
	GtkWidget* title;
	GtkWidget* body;
	GtkWidget* image;
	gchar*     body_message = NULL;
	gchar*     new_body_message = NULL;
	guint      gap = EM2PIXELS (defaults_get_margin_size (d), d);
	gboolean   success = FALSE;
	GError*    error = NULL;

	if (!IS_DEFAULTS (d) ||
	    !sender          ||
	    !app_name        ||
	    !title_text      ||
	    !_body_message   ||
	    !actions)
		return;

	DialogInfo* dialog_info = g_new0 (DialogInfo, 1);
	if (!dialog_info)
		return;

	dialog_info->id = id;
	dialog_info->sender = g_strdup(sender);

	dialog = gtk_dialog_new ();

	hbox = g_object_new (GTK_TYPE_HBOX,
			     "spacing", gap,
			     "border-width", 12,
			     NULL);

	// We deliberately use the gtk-dialog-warning icon rather than
	// the specified one to discourage people from trying to use
	// the notification system as a way of showing custom alert
	// dialogs.
	image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
					  GTK_ICON_SIZE_DIALOG);
	gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
	gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);

	vbox = g_object_new (GTK_TYPE_VBOX,
			     NULL);

	title = gtk_label_new (NULL);
	gtk_label_set_text (GTK_LABEL (title), title_text);

	gtk_label_set_line_wrap (GTK_LABEL (title), TRUE);

	body = gtk_label_new (NULL);
	body_message = filter_text (_body_message);
	if (body_message)
	{
		success = pango_parse_markup (body_message,
					      -1,
					      0,
					      NULL,
					      &new_body_message,
					      NULL,
					      &error);

		if (error && !success)
		{
			g_warning ("fallback_dialog_show(): Got error \"%s\"\n",
		        	   error->message);
			g_error_free (error);
			error = NULL;
		}
	}

	if (new_body_message)
	{
		gtk_label_set_text (GTK_LABEL (body), new_body_message);
		g_free (new_body_message);
	}
	else
		gtk_label_set_text (GTK_LABEL (body), body_message);

	g_free (body_message);

	gtk_label_set_line_wrap (GTK_LABEL (body), TRUE);

	gtk_misc_set_alignment (GTK_MISC (title), 0.0, 0.0);
	gtk_box_pack_start (GTK_BOX (vbox), title, TRUE, TRUE, 0);

	gtk_misc_set_alignment (GTK_MISC (body), 0.0, 0.0);
	gtk_box_pack_start (GTK_BOX (vbox), body, TRUE, TRUE, 0);

	gtk_container_add (GTK_CONTAINER (hbox), vbox);

	gtk_container_add (GTK_CONTAINER (
				   gtk_dialog_get_content_area (
					   GTK_DIALOG (dialog))),
			   hbox);

	gtk_container_set_border_width (GTK_CONTAINER (dialog), 2);

	gtk_window_set_position (GTK_WINDOW (dialog),
				 GTK_WIN_POS_CENTER);
	gtk_window_set_default_size (GTK_WINDOW (dialog),
				     EM2PIXELS (defaults_get_bubble_width (d) * 1.2f, d),
				     -1);
	gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
	gtk_window_set_title (GTK_WINDOW (dialog), app_name);
	gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE);

	// is it a bad notification with actions?
	if (actions[0] != NULL)
		add_pathological_action_buttons (dialog, actions);

	GtkButton *cancel = GTK_BUTTON (
		gtk_dialog_add_button (GTK_DIALOG (dialog),
				       GTK_STOCK_CANCEL,
				       GTK_RESPONSE_CANCEL));
	g_signal_connect_swapped (G_OBJECT (cancel),
				  "button-release-event",
				  G_CALLBACK (handle_close),
				  dialog);
	gtk_widget_set_can_default(GTK_WIDGET(cancel), FALSE);

	g_signal_connect (G_OBJECT (dialog),
			  "response",
			  G_CALLBACK (handle_close),
			  dialog);
		
		
	GtkButton *ok = GTK_BUTTON (
		gtk_dialog_add_button (GTK_DIALOG (dialog),
				       GTK_STOCK_OK,
				       GTK_RESPONSE_OK));
	g_object_set_data_full (G_OBJECT (ok),
				"_libnotify_action",
				g_strdup ("default"),
				g_free);
	g_signal_connect (G_OBJECT (ok),
			  "button-release-event",
			  G_CALLBACK (handle_response),
			  dialog);
	gtk_widget_set_can_default(GTK_WIDGET(ok), FALSE);

	g_object_set_data (G_OBJECT (dialog),
			   "_dialog_info",
			   dialog_info);

	g_signal_connect (G_OBJECT (dialog),
			  "button-release-event",
			  G_CALLBACK (handle_response),
			  dialog);

	gtk_window_set_focus (GTK_WINDOW (dialog),
			      NULL);
	gtk_window_set_default (GTK_WINDOW (dialog),
				NULL);

	gtk_widget_show_all (dialog);
}