MCPcopy Create free account
hub / github.com/crossuo/crossuo / CPacketBookPageData

Method CPacketBookPageData

src/Network/Packets.cpp:1280–1343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1278}
1279
1280CPacketBookPageData::CPacketBookPageData(CGumpBook *gump, int page)
1281 : CPacket(1)
1282{
1283 int lineCount = 0;
1284
1285 CGUITextEntry *entry = gump->GetEntry(page);
1286
1287 if (entry != nullptr)
1288 {
1289 CEntryText &textEntry = entry->m_Entry;
1290 // FIXME: PACKET: check if this should be ASCII or UTF8
1291 auto data = wstr_to_utf8(textEntry.GetTextW());
1292 size_t len = data.length();
1293 size_t size = 9 + 4 + 1;
1294
1295 if (len != 0u)
1296 {
1297 size += len;
1298 const char *str = data.c_str();
1299
1300 for (int i = 0; i < (int)len; i++)
1301 {
1302 if (*(str + i) == '\n')
1303 {
1304 lineCount++;
1305 }
1306 }
1307
1308 if (str[len - 1] != '\n')
1309 {
1310 lineCount++;
1311 }
1312 }
1313
1314 Resize(size, true);
1315
1316 WriteUInt8(0x66);
1317 WriteUInt16BE((uint16_t)size);
1318 WriteUInt32BE(gump->Serial);
1319 WriteUInt16BE(0x0001);
1320
1321 WriteUInt16BE(page);
1322 WriteUInt16BE(lineCount);
1323
1324 if (len != 0u)
1325 {
1326 const char *str = data.c_str();
1327
1328 for (int i = 0; i < (int)len; i++)
1329 {
1330 char ch = *(str + i);
1331
1332 if (ch == '\n')
1333 {
1334 ch = 0;
1335 }
1336
1337 *Ptr++ = ch;

Callers

nothing calls this directly

Calls 5

wstr_to_utf8Function · 0.85
GetEntryMethod · 0.80
GetTextWMethod · 0.80
lengthMethod · 0.80
c_strMethod · 0.80

Tested by

no test coverage detected