static void
dissect_channel_create(tvbuff_t *tvb, proto_tree *tree, int offset)
{
   offset += 4;
   proto_tree_add_item(tree, hf_sametime_channel_id, tvb, offset, 4, ENC_BIG_ENDIAN);
   offset += 4;
   offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
   proto_tree_add_item(tree, hf_sametime_channel_service, tvb, offset, 4, ENC_BIG_ENDIAN);
   offset += 4;
   offset += 8;
   add_text_item(tvb, tree, offset, hf_sametime_field_text);
}
static void
dissect_channel_accept(tvbuff_t *tvb, proto_tree *tree, int offset)
{
   offset += 34;
   if (tvb_reported_length_remaining(tvb, offset + 2))        {
      offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
      if (tvb_get_guint8(tvb, offset))        {
         offset += 1;
         offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
         dissect_set_user_status(tvb, tree, offset);
      }
   }
}
void help_text_area::handle_header_cfg(const config &cfg)
{
	const std::string text = cfg["text"];
	if (text == "") {
		throw parse_error("Header markup must have text attribute.");
	}
	add_text_item(text, "", false, title2_size, true);
}
void help_text_area::handle_italic_cfg(const config &cfg)
{
	const std::string text = cfg["text"];
	if (text == "") {
		throw parse_error("Italic markup must have text attribute.");
	}
	add_text_item(text, "", false, -1, false, true);
}
void help_text_area::handle_bold_cfg(const config &cfg)
{
	const std::string text = cfg["text"];
	if (text.empty()) {
		throw parse_error("Bold markup must have text attribute.");
	}
	add_text_item(text, "", false, -1, true);
}
void help_text_area::handle_ref_cfg(const config &cfg)
{
	const std::string dst = cfg["dst"];
	const std::string text = cfg["text"];
	bool force = cfg["force"].to_bool();

	if (dst == "") {
		std::stringstream msg;
		msg << "Ref markup must have dst attribute. Please submit a bug"
		       " report if you have not modified the game files yourself. Erroneous config: ";
		write(msg, cfg);
		throw parse_error(msg.str());
	}

	if (find_topic(toplevel_, dst) == NULL && !force) {
		// detect the broken link but quietly silence the hyperlink for normal user
		add_text_item(text, game_config::debug ? dst : "", true);

		// FIXME: workaround: if different campaigns define different
		// terrains, some terrains available in one campaign will
		// appear in the list of seen terrains, and be displayed in the
		// help, even if the current campaign does not handle such
		// terrains. This will lead to the unit page generator creating
		// invalid references.
		//
		// Disabling this is a kludgey workaround until the
		// encountered_terrains system is fixed
		//
		// -- Ayin apr 8 2005
#if 0
		if (game_config::debug) {
			std::stringstream msg;
			msg << "Reference to non-existent topic '" << dst
			    << "'. Please submit a bug report if you have not"
			       "modified the game files yourself. Erroneous config: ";
			write(msg, cfg);
			throw parse_error(msg.str());
		}
#endif
	} else {
		add_text_item(text, dst);
	}
}
static int
dissect_handshake(tvbuff_t *tvb, proto_tree *tree, int offset)
{
   proto_tree_add_item(tree, hf_sametime_handshake_major, tvb, offset, 2, ENC_BIG_ENDIAN);
   offset += 2;
   proto_tree_add_item(tree, hf_sametime_handshake_minor, tvb, offset, 2, ENC_BIG_ENDIAN);
   offset += 2;
   offset += 4;
   proto_tree_add_item(tree, hf_sametime_handshake_srvrcalc_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
   offset += 4;
   proto_tree_add_item(tree, hf_sametime_login_type, tvb, offset, 2, ENC_BIG_ENDIAN);
   offset += 2;
   proto_tree_add_item(tree, hf_sametime_handshake_loclcalc_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
   offset += 4;
   offset += 6;
   offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
   offset += 8;
   offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);

   return offset;
}
void help_text_area::handle_format_cfg(const config &cfg)
{
	const std::string text = cfg["text"];
	if (text == "") {
		throw parse_error("Format markup must have text attribute.");
	}
	bool bold = cfg["bold"].to_bool();
	bool italic = cfg["italic"].to_bool();
	int font_size = cfg["font_size"].to_int(normal_font_size);
	SDL_Color color = string_to_color(cfg["color"]);
	add_text_item(text, "", false, font_size, bold, italic, color);
}
static void
dissect_handshake_ack(tvbuff_t *tvb, proto_tree *tree, int offset)
{
   proto_tree_add_item(tree, hf_sametime_handshake_major, tvb, offset, 2, ENC_BIG_ENDIAN);
   offset += 2;
   proto_tree_add_item(tree, hf_sametime_handshake_minor, tvb, offset, 2, ENC_BIG_ENDIAN);
   offset += 2;
   proto_tree_add_item(tree, hf_sametime_handshake_loclcalc_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
   offset += 4;
   offset += 4;
   offset += 4;
   add_text_item(tvb, tree, offset, hf_sametime_field_text);
}
static guint16
dissect_set_user_status(tvbuff_t *tvb, proto_tree *tree, int offset)
{
   guint16 user_status;

   user_status = tvb_get_ntohs(tvb, offset);
   proto_item_append_text(tree, ", %s", val_to_str(user_status, userstatusnames, "0x%04x"));
   proto_tree_add_item(tree, hf_sametime_user_status, tvb, offset, 2, ENC_BIG_ENDIAN);
   offset += 2;
   proto_tree_add_item(tree, hf_sametime_time, tvb, offset, 4, ENC_BIG_ENDIAN);
   offset += 4;
   add_text_item(tvb, tree, offset, hf_sametime_field_text);

   return user_status;
}
static void
dissect_login_ack(tvbuff_t *tvb, proto_tree *tree, int offset)
{
   offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
   proto_tree_add_item(tree, hf_sametime_login_type, tvb, offset, 2, ENC_BIG_ENDIAN);
   offset += 2;
   offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
   offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
   offset += 3;
   offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
   proto_tree_add_item(tree, hf_sametime_handshake_loclcalc_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
   offset += 4;
   offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
   offset += 21;
   offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
   add_text_item(tvb, tree, offset, hf_sametime_field_text);
}
static guint16
dissect_channel_send(tvbuff_t *tvb, proto_tree *tree, int offset)
{
   guint16 send_type, awareness;
   guint na;

   send_type = tvb_get_ntohs(tvb, offset);
   proto_item_append_text(tree, ", %s", val_to_str(send_type, sendtypenames, "0x%04x"));
   proto_tree_add_item(tree, hf_sametime_channel_send_type, tvb, offset, 2, ENC_BIG_ENDIAN);
   offset += 2;

   switch (send_type)        {
      case SAMETIME_SENDTYPE_AWARE_ADD:
         offset += 8;
         awareness = tvb_get_ntohs(tvb, offset);
         proto_item_append_text(tree, ", %s", val_to_str(awareness, awarenessnames, "0x%04x"));
         proto_tree_add_item(tree, hf_sametime_channel_awareness, tvb, offset, 2, ENC_BIG_ENDIAN);
         offset += 2;
         add_text_item(tvb, tree, offset, hf_sametime_field_text);

         break;

      case SAMETIME_SENDTYPE_OPT_DO_SET:
         offset += 20;
         na = tvb_get_ntohl(tvb, offset);
         offset += 4;
         if (na == 0x33)        {
            offset += add_text_item(tvb, tree, offset, hf_sametime_location_country);
            offset += add_text_item(tvb, tree, offset, hf_sametime_location_postalcode);
            offset += add_text_item(tvb, tree, offset, hf_sametime_location_province);
            offset += add_text_item(tvb, tree, offset, hf_sametime_location_city);
            offset += add_text_item(tvb, tree, offset, hf_sametime_location_phone);
            offset += 1;
            offset += add_text_item(tvb, tree, offset, hf_sametime_location_name);
            add_text_item(tvb, tree, offset, hf_sametime_location_timezone);
         } else        {
            add_text_item(tvb, tree, offset, hf_sametime_field_text);
         }

         break;

      case SAMETIME_SENDTYPE_OPT_GOT_SET:
         offset += 8;
         awareness = tvb_get_ntohs(tvb, offset);
         proto_item_append_text(tree, ", %s", val_to_str(awareness, awarenessnames, "0x%04x"));
         proto_tree_add_item(tree, hf_sametime_channel_awareness, tvb, offset, 2, ENC_BIG_ENDIAN);
         offset += 2;
         while (tvb_reported_length_remaining(tvb, offset) > 2)        {
            int n = add_text_item(tvb, tree, offset, hf_sametime_field_text);
            offset += (n) ? n : 1;
         }

         break;

      case SAMETIME_SENDTYPE_AWARE_SNAPSHOT:
         offset += 12;
         awareness = tvb_get_ntohs(tvb, offset);
         proto_item_append_text(tree, ", %s", val_to_str(awareness, awarenessnames, "0x%04x"));
         proto_tree_add_item(tree, hf_sametime_channel_awareness, tvb, offset, 2, ENC_BIG_ENDIAN);
         offset += 2;
         add_text_item(tvb, tree, offset, hf_sametime_field_text);

         break;

      case SAMETIME_SENDTYPE_AWARE_UPDATE:
         offset += 4;
         offset += 4;
         awareness = tvb_get_ntohs(tvb, offset);
         proto_item_append_text(tree, ", %s", val_to_str(awareness, awarenessnames, "0x%04x"));
         proto_tree_add_item(tree, hf_sametime_channel_awareness, tvb, offset, 2, ENC_BIG_ENDIAN);
         offset += 2;
         offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
         offset += 4;
         if (tvb_get_guint8(tvb, offset))        {
            offset += 1;
            offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
            dissect_set_user_status(tvb, tree, offset);
         }

         break;

      case 0x0000:
         offset += 14;
         add_text_item(tvb, tree, offset, hf_sametime_field_text);

         break;

      case 0x0002:
         offset += 8;
         offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
         offset += 3;
         add_text_item(tvb, tree, offset, hf_sametime_field_text);

         break;

      case 0x0005:        /* XML */
         if (26 <= tvb_reported_length_remaining(tvb, offset + 2))        {
            offset += 26;
            add_text_item(tvb, tree, offset, hf_sametime_field_text);
         }

         break;

      case 0x0007:
         offset += 8;
         if (4 <= tvb_reported_length_remaining(tvb, offset + 2))        {
            offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
            offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
            offset += 3;
            offset += add_text_item(tvb, tree, offset, hf_sametime_field_text);
            add_text_item(tvb, tree, offset, hf_sametime_field_text);
         }

         break;

      case 0x025a:
         offset += 10;
         add_text_item(tvb, tree, offset, hf_sametime_field_text);

         break;

      default:
         break;
   }

   return send_type;
}
static void
dissect_login_redirect(tvbuff_t *tvb, proto_tree *tree, int offset)
{
   offset += 2;
   add_text_item(tvb, tree, offset, hf_sametime_field_text);
}
Exemple #14
0
void help_text_area::set_items()
{
	last_row_.clear();
	items_.clear();
	curr_loc_.first = 0;
	curr_loc_.second = 0;
	curr_row_height_ = min_row_height_;
	// Add the title item.
	const std::string show_title =
		font::make_text_ellipsis(shown_topic_->title, title_size, inner_location().w);
	surface surf(font::get_rendered_text(show_title, title_size,
					     font::NORMAL_COLOR, TTF_STYLE_BOLD));
	if (surf != NULL) {
		add_item(item(surf, 0, 0, show_title));
		curr_loc_.second = title_spacing_;
		contents_height_ = title_spacing_;
		down_one_line();
	}
	// Parse and add the text.
	std::vector<std::string> const &parsed_items = shown_topic_->text.parsed_text();
	std::vector<std::string>::const_iterator it;
	for (it = parsed_items.begin(); it != parsed_items.end(); ++it) {
		if (*it != "" && (*it)[0] == '[') {
			// Should be parsed as WML.
			try {
				config cfg;
				std::istringstream stream(*it);
				read(cfg, stream);

#define TRY(name) do { \
				if (config &child = cfg.child(#name)) \
					handle_##name##_cfg(child); \
				} while (0)

				TRY(ref);
				TRY(img);
				TRY(bold);
				TRY(italic);
				TRY(header);
				TRY(jump);
				TRY(format);

#undef TRY

			}
			catch (config::error& e) {
				std::stringstream msg;
				msg << "Error when parsing help markup as WML: '" << e.message << "'";
				throw parse_error(msg.str());
			}
		}
		else {
			add_text_item(*it);
		}
	}
	down_one_line(); // End the last line.
	int h = height();
	set_position(0);
	set_full_size(contents_height_);
	set_shown_size(h);
}
Exemple #15
0
void help_text_area::add_text_item(const std::string& text, const std::string& ref_dst,
								   bool broken_link, int _font_size, bool bold, bool italic,
								   SDL_Color text_color
)
{
	const int font_size = _font_size < 0 ? normal_font_size : _font_size;
	if (text.empty())
		return;
	const int remaining_width = get_remaining_width();
	size_t first_word_start = text.find_first_not_of(" ");
	if (first_word_start == std::string::npos) {
		first_word_start = 0;
	}
	if (text[first_word_start] == '\n') {
		down_one_line();
		std::string rest_text = text;
		rest_text.erase(0, first_word_start + 1);
		add_text_item(rest_text, ref_dst, broken_link, _font_size, bold, italic, text_color);
		return;
	}
	const std::string first_word = get_first_word(text);
	int state = ref_dst == "" ? 0 : TTF_STYLE_UNDERLINE;
	state |= bold ? TTF_STYLE_BOLD : 0;
	state |= italic ? TTF_STYLE_ITALIC : 0;
	if (curr_loc_.first != get_min_x(curr_loc_.second, curr_row_height_)
		&& remaining_width < font::line_width(first_word, font_size, state)) {
		// The first word does not fit, and we are not at the start of
		// the line. Move down.
		down_one_line();
		std::string s = remove_first_space(text);
		add_text_item(s, ref_dst, broken_link, _font_size, bold, italic, text_color);
	}
	else {
		std::vector<std::string> parts = split_in_width(text, font_size, remaining_width);
		std::string first_part = parts.front();
		// Always override the color if we have a cross reference.
		SDL_Color color;
		if(ref_dst.empty())
			color = text_color;
		else if(broken_link)
			color = font::BAD_COLOR;
		else
			color = font::YELLOW_COLOR;

		surface surf(font::get_rendered_text(first_part, font_size, color, state));
		if (!surf.null())
			add_item(item(surf, curr_loc_.first, curr_loc_.second, first_part, ref_dst));
		if (parts.size() > 1) {

			std::string& s = parts.back();

			const std::string first_word_before = get_first_word(s);
			const std::string first_word_after = get_first_word(remove_first_space(s));
			if (get_remaining_width() >= font::line_width(first_word_after, font_size, state)
				&& get_remaining_width()
				< font::line_width(first_word_before, font_size, state)) {
				// If the removal of the space made this word fit, we
				// must move down a line, otherwise it will be drawn
				// without a space at the end of the line.
				s = remove_first_space(s);
				down_one_line();
			}
			else if (!(font::line_width(first_word_before, font_size, state)
					   < get_remaining_width())) {
				s = remove_first_space(s);
			}
			add_text_item(s, ref_dst, broken_link, _font_size, bold, italic, text_color);

		}
	}
}