Loading...   

  • Created By Uleat On: 07:15 PM February 20, 2018
  • Link

	static inline void ServerToSoFSayLink(std::string& sofSayLink, const std::string& serverSayLink)
	{
		if (constants::SayLinkBodySize == EQEmu::legacy::SAY_LINK_BODY_LENGTH) {
			sofSayLink = serverSayLink;
			return;
		}
		
		// Nothing blocks both the saylink and wndnotify styles from being
		// in the same message..but, it should never be handled that way

		if (serverSayLink.find('\x12') != std::string::npos) {
			auto segments = SplitString(serverSayLink, '\x12');

			for (size_t segment_iter = 0; segment_iter < segments.size(); ++segment_iter) {
				if (segment_iter & 1) {
					if (segments[segment_iter].length() <= EQEmu::legacy::SAY_LINK_BODY_LENGTH) {
						sofSayLink.append(segments[segment_iter]);
						Log(Logs::General, Logs::Error, "SayLink[SoF] segment length: %u, emu body length: %u",
							segments[segment_iter].length(), EQEmu::legacy::SAY_LINK_BODY_LENGTH);

						continue;
					}

					// Idx:  0 1     6     11    16    21    26    31    36 37   41 43    48       (Source)
					// RoF2: X XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX X  XXXX XX XXXXX XXXXXXXX (56)
					// SoF:  X XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX       X  XXXX  X XXXXX XXXXXXXX (50)
					// Diff:                                       ^^^^^         ^

					sofSayLink.push_back('\x12');
					sofSayLink.append(segments[segment_iter].substr(0, 31));
					sofSayLink.append(segments[segment_iter].substr(36, 5));

					if (segments[segment_iter][41] == '0')
						sofSayLink.push_back(segments[segment_iter][42]);
					else
						sofSayLink.push_back('F');

					sofSayLink.append(segments[segment_iter].substr(43));
					sofSayLink.push_back('\x12');
				}
				else {
					sofSayLink.append(segments[segment_iter]);
				}
			}

			return;
		}

		const size_t open_offset = strlen("<a WndNotify=\"");

		size_t wnd_notify_open = serverSayLink.find("<a WndNotify=\"");
		if (wnd_notify_open == std::string::npos) {
			sofSayLink = serverSayLink;
			return;
		}

		wnd_notify_open += open_offset;
		sofSayLink.append(serverSayLink.substr(0, wnd_notify_open));

		size_t wnd_notify_close = serverSayLink.find("\"", wnd_notify_open);
		if (wnd_notify_close == std::string::npos) {
			sofSayLink.append(serverSayLink.substr(wnd_notify_open));
			return;
		}
		
		while (wnd_notify_open != std::string::npos) {
			wnd_notify_open += open_offset;
			if (wnd_notify_open > wnd_notify_close) {
				sofSayLink.append(serverSayLink.substr(wnd_notify_close, wnd_notify_open));
			}

			wnd_notify_close = serverSayLink.find("\"", wnd_notify_open);
			if (wnd_notify_close == std::string::npos) {
				sofSayLink.append(serverSayLink.substr(wnd_notify_open));
				break;
			}
			
			if ((wnd_notify_close - wnd_notify_open) == EQEmu::legacy::WND_NOTIFY_LINK_BODY_LENGTH) {
				// Idx:  0 1     6     11    16    21    26    31    36 37   41 43    48       (Source)
				// RoF2: X XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX X  XXXX XX XXXXX XXXXXXXX (56)
				// SoF:  X XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX       X  XXXX  X XXXXX XXXXXXXX (50)
				// Diff:                                       ^^^^^         ^

				sofSayLink.append(EQEmu::legacy::WND_NOTIFY_FRAME_ID);
				sofSayLink.push_back(',');
				sofSayLink.append(serverSayLink.substr(wnd_notify_open, wnd_notify_close).substr(1, 30));
				sofSayLink.append(serverSayLink.substr(wnd_notify_open, wnd_notify_close).substr(36, 5));

				if (serverSayLink.substr(wnd_notify_open, wnd_notify_close)[41] == '0')
					sofSayLink.push_back(serverSayLink.substr(wnd_notify_open, wnd_notify_close)[42]);
				else
					sofSayLink.push_back('F');

				sofSayLink.append(serverSayLink.substr(wnd_notify_open, wnd_notify_close).substr(43));
			}
			else {
				sofSayLink.append(serverSayLink.substr(wnd_notify_open, wnd_notify_close));
			}

			wnd_notify_open = serverSayLink.find("<a WndNotify=\"", wnd_notify_close);
		}
	}

Raw Paste Data