1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Chat.h"
#include "AccountMgr.h"
#include "CellImpl.h"
#include "CharacterCache.h"
#include "ChatCommand.h"
#include "ChatPackets.h"
#include "Common.h"
#include "GridNotifiersImpl.h"
#include "Group.h"
#include "Language.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Optional.h"
#include "Player.h"
#include "Realm.h"
#include "StringConvert.h"
#include "World.h"
#include "WorldSession.h"
#include <boost/algorithm/string/replace.hpp>
#include <sstream>
Player* ChatHandler::GetPlayer() const { return m_session ? m_session->GetPlayer() : nullptr; }
char* ChatHandler::LineFromMessage(char*& pos)
{
char* start = strtok(pos, "\n");
pos = nullptr;
return start;
}
char const* ChatHandler::GetTrinityString(uint32 entry) const
{
return m_session->GetTrinityString(entry);
}
bool ChatHandler::HasPermission(uint32 permission) const
{
return m_session->HasPermission(permission);
}
std::string ChatHandler::GetNameLink() const
{
return GetNameLink(m_session->GetPlayer());
}
bool ChatHandler::HasLowerSecurity(Player* target, ObjectGuid guid, bool strong)
{
WorldSession* target_session = nullptr;
uint32 target_account = 0;
if (target)
target_session = target->GetSession();
else if (!guid.IsEmpty())
target_account = sCharacterCache->GetCharacterAccountIdByGuid(guid);
if (!target_session && !target_account)
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return true;
}
return HasLowerSecurityAccount(target_session, target_account, strong);
}
bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_account, bool strong)
{
uint32 target_sec;
// allow everything from console and RA console
if (!m_session)
return false;
// ignore only for non-players for non strong checks (when allow apply command at least to same sec level)
if (m_session->HasPermission(rbac::RBAC_PERM_CHECK_FOR_LOWER_SECURITY) && !strong && !sWorld->getBoolConfig(CONFIG_GM_LOWER_SECURITY))
return false;
if (target)
target_sec = target->GetSecurity();
else if (target_account)
target_sec = AccountMgr::GetSecurity(target_account, realm.Id.Realm);
else
return true; // caller must report error for (target == nullptr && target_account == 0)
AccountTypes target_ac_sec = AccountTypes(target_sec);
if (m_session->GetSecurity() < target_ac_sec || (strong && m_session->GetSecurity() <= target_ac_sec))
{
SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
SetSentErrorMessage(true);
return true;
}
return false;
}
void ChatHandler::SendSysMessage(std::string_view str, bool escapeCharacters)
{
std::string msg{ str };
// Replace every "|" with "||" in msg
if (escapeCharacters && msg.find('|') != std::string::npos)
{
std::vector<std::string_view> tokens = Trinity::Tokenize(msg, '|', true);
std::ostringstream stream;
for (size_t i = 0; i < tokens.size() - 1; ++i)
stream << tokens[i] << "||";
stream << tokens[tokens.size() - 1];
msg = stream.str();
}
WorldPackets::Chat::Chat packet;
for (std::string_view line : Trinity::Tokenize(str, '\n', true))
{
packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
m_session->SendPacket(packet.Write());
}
}
void ChatHandler::SendGlobalSysMessage(const char *str)
{
WorldPackets::Chat::Chat packet;
for (std::string_view line : Trinity::Tokenize(str, '\n', true))
{
packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
sWorld->SendGlobalMessage(packet.Write());
}
}
void ChatHandler::SendGlobalGMSysMessage(const char *str)
{
WorldPackets::Chat::Chat packet;
for (std::string_view line : Trinity::Tokenize(str, '\n', true))
{
packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
sWorld->SendGlobalGMMessage(packet.Write());
}
}
void ChatHandler::SendSysMessage(uint32 entry)
{
SendSysMessage(GetTrinityString(entry));
}
bool ChatHandler::_ParseCommands(std::string_view text)
{
if (Trinity::ChatCommands::TryExecuteCommand(*this, text))
return true;
// Pretend commands don't exist for regular players
if (m_session && !m_session->HasPermission(rbac::RBAC_PERM_COMMANDS_NOTIFY_COMMAND_NOT_FOUND_ERROR))
return false;
// Send error message for GMs
PSendSysMessage(LANG_CMD_INVALID, STRING_VIEW_FMT_ARG(text));
SetSentErrorMessage(true);
return true;
}
bool ChatHandler::ParseCommands(std::string_view text)
{
ASSERT(!text.empty());
// chat case (.command or !command format)
if ((text[0] != '!') && (text[0] != '.'))
return false;
// ignore single . and ! in line
if (text.length() < 2)
return false;
// ignore messages staring from many dots.
if (text[1] == text[0])
return false;
// ignore messages with separator after .
if (text[1] == Trinity::Impl::ChatCommands::COMMAND_DELIMITER)
return false;
return _ParseCommands(text.substr(1));
}
Player* ChatHandler::getSelectedPlayer()
{
if (!m_session)
return nullptr;
ObjectGuid selected = m_session->GetPlayer()->GetTarget();
if (!selected)
return m_session->GetPlayer();
return ObjectAccessor::FindConnectedPlayer(selected);
}
Unit* ChatHandler::getSelectedUnit()
{
if (!m_session)
return nullptr;
if (Unit* selected = m_session->GetPlayer()->GetSelectedUnit())
return selected;
return m_session->GetPlayer();
}
WorldObject* ChatHandler::getSelectedObject()
{
if (!m_session)
return nullptr;
ObjectGuid guid = m_session->GetPlayer()->GetTarget();
if (!guid)
return GetNearbyGameObject();
return ObjectAccessor::GetUnit(*m_session->GetPlayer(), guid);
}
Creature* ChatHandler::getSelectedCreature()
{
if (!m_session)
return nullptr;
return ObjectAccessor::GetCreatureOrPetOrVehicle(*m_session->GetPlayer(), m_session->GetPlayer()->GetTarget());
}
Player* ChatHandler::getSelectedPlayerOrSelf()
{
if (!m_session)
return nullptr;
ObjectGuid selected = m_session->GetPlayer()->GetTarget();
if (!selected)
return m_session->GetPlayer();
// first try with selected target
Player* targetPlayer = ObjectAccessor::FindConnectedPlayer(selected);
// if the target is not a player, then return self
if (!targetPlayer)
targetPlayer = m_session->GetPlayer();
return targetPlayer;
}
char* ChatHandler::extractKeyFromLink(char* text, char const* linkType, char** something1)
{
// skip empty
if (!text)
return nullptr;
// skip spaces
while (*text == ' '||*text == '\t'||*text == '\b')
++text;
if (!*text)
return nullptr;
// return non link case
if (text[0] != '|')
return strtok(text, " ");
// [name] Shift-click form |color|linkType:key|h[name]|h|r
// or
// [name] Shift-click form |color|linkType:key:something1:...:somethingN|h[name]|h|r
char* check = strtok(text, "|"); // skip color
if (!check)
return nullptr; // end of data
char* cLinkType = strtok(nullptr, ":"); // linktype
if (!cLinkType)
return nullptr; // end of data
if (strcmp(cLinkType, linkType) != 0)
{
strtok(nullptr, " "); // skip link tail (to allow continue strtok(nullptr, s) use after retturn from function
SendSysMessage(LANG_WRONG_LINK_TYPE);
return nullptr;
}
char* cKeys = strtok(nullptr, "|"); // extract keys and values
char* cKeysTail = strtok(nullptr, "");
char* cKey = strtok(cKeys, ":|"); // extract key
if (something1)
*something1 = strtok(nullptr, ":|"); // extract something
strtok(cKeysTail, "]"); // restart scan tail and skip name with possible spaces
strtok(nullptr, " "); // skip link tail (to allow continue strtok(nullptr, s) use after return from function
return cKey;
}
char* ChatHandler::extractKeyFromLink(char* text, char const* const* linkTypes, int* found_idx, char** something1)
{
// skip empty
if (!text)
return nullptr;
// skip spaces
while (*text == ' '||*text == '\t'||*text == '\b')
++text;
if (!*text)
return nullptr;
// return non link case
if (text[0] != '|')
return strtok(text, " ");
// [name] Shift-click form |color|linkType:key|h[name]|h|r
// or
// [name] Shift-click form |color|linkType:key:something1:...:somethingN|h[name]|h|r
// or
// [name] Shift-click form |linkType:key|h[name]|h|r
char* tail;
if (text[1] == 'c')
{
char* check = strtok(text, "|"); // skip color
if (!check)
return nullptr; // end of data
tail = strtok(nullptr, ""); // tail
}
else
tail = text+1; // skip first |
char* cLinkType = strtok(tail, ":"); // linktype
if (!cLinkType)
return nullptr; // end of data
for (int i = 0; linkTypes[i]; ++i)
{
if (strcmp(cLinkType, linkTypes[i]) == 0)
{
char* cKeys = strtok(nullptr, "|"); // extract keys and values
char* cKeysTail = strtok(nullptr, "");
char* cKey = strtok(cKeys, ":|"); // extract key
if (something1)
*something1 = strtok(nullptr, ":|"); // extract something
strtok(cKeysTail, "]"); // restart scan tail and skip name with possible spaces
strtok(nullptr, " "); // skip link tail (to allow continue strtok(nullptr, s) use after return from function
if (found_idx)
*found_idx = i;
return cKey;
}
}
strtok(nullptr, " "); // skip link tail (to allow continue strtok(nullptr, s) use after return from function
SendSysMessage(LANG_WRONG_LINK_TYPE);
return nullptr;
}
GameObject* ChatHandler::GetNearbyGameObject()
{
if (!m_session)
return nullptr;
Player* pl = m_session->GetPlayer();
GameObject* obj = nullptr;
Trinity::NearestGameObjectCheck check(*pl);
Trinity::GameObjectLastSearcher<Trinity::NearestGameObjectCheck> searcher(pl, obj, check);
Cell::VisitGridObjects(pl, searcher, SIZE_OF_GRIDS);
return obj;
}
GameObject* ChatHandler::GetObjectFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid)
{
if (!m_session)
return nullptr;
auto bounds = m_session->GetPlayer()->GetMap()->GetGameObjectBySpawnIdStore().equal_range(lowguid);
if (bounds.first != bounds.second)
return bounds.first->second;
return nullptr;
}
Creature* ChatHandler::GetCreatureFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid)
{
if (!m_session)
return nullptr;
// Select the first alive creature or a dead one if not found
Creature* creature = nullptr;
auto bounds = m_session->GetPlayer()->GetMap()->GetCreatureBySpawnIdStore().equal_range(lowguid);
for (auto it = bounds.first; it != bounds.second; ++it)
{
creature = it->second;
if (it->second->IsAlive())
break;
}
return creature;
}
enum GuidLinkType
{
GUID_LINK_PLAYER = 0, // must be first for selection in not link case
GUID_LINK_CREATURE = 1,
GUID_LINK_GAMEOBJECT = 2
};
static char const* const guidKeys[] =
{
"Hplayer",
"Hcreature",
"Hgameobject",
nullptr
};
ObjectGuid::LowType ChatHandler::extractLowGuidFromLink(char* text, HighGuid& guidHigh)
{
int type = 0;
// |color|Hcreature:creature_guid|h[name]|h|r
// |color|Hgameobject:go_guid|h[name]|h|r
// |color|Hplayer:name|h[name]|h|r
char* idS = extractKeyFromLink(text, guidKeys, &type);
if (!idS)
return 0;
switch (type)
{
case GUID_LINK_PLAYER:
{
guidHigh = HighGuid::Player;
std::string name = idS;
if (!normalizePlayerName(name))
return 0;
if (Player* player = ObjectAccessor::FindPlayerByName(name))
return player->GetGUID().GetCounter();
ObjectGuid guid = sCharacterCache->GetCharacterGuidByName(name);
if (guid.IsEmpty())
return 0;
return guid.GetCounter();
}
case GUID_LINK_CREATURE:
{
guidHigh = HighGuid::Creature;
ObjectGuid::LowType lowguid = Trinity::StringTo<ObjectGuid::LowType>(idS).value_or(UI64LIT(0));
return lowguid;
}
case GUID_LINK_GAMEOBJECT:
{
guidHigh = HighGuid::GameObject;
ObjectGuid::LowType lowguid = Trinity::StringTo<ObjectGuid::LowType>(idS).value_or(UI64LIT(0));
return lowguid;
}
}
// unknown type?
return 0;
}
std::string ChatHandler::extractPlayerNameFromLink(char* text)
{
// |color|Hplayer:name|h[name]|h|r
char* name_str = extractKeyFromLink(text, "Hplayer");
if (!name_str)
return "";
std::string name = name_str;
if (!normalizePlayerName(name))
return "";
return name;
}
bool ChatHandler::extractPlayerTarget(char* args, Player** player, ObjectGuid* player_guid /*= nullptr*/, std::string* player_name /*= nullptr*/)
{
if (args && *args)
{
std::string name = extractPlayerNameFromLink(args);
if (name.empty())
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
Player* pl = ObjectAccessor::FindPlayerByName(name);
// if allowed player pointer
if (player)
*player = pl;
// if need guid value from DB (in name case for check player existence)
ObjectGuid guid = !pl && (player_guid || player_name) ? sCharacterCache->GetCharacterGuidByName(name) : ObjectGuid::Empty;
// if allowed player guid (if no then only online players allowed)
if (player_guid)
*player_guid = pl ? pl->GetGUID() : guid;
if (player_name)
*player_name = pl || !guid.IsEmpty() ? name : "";
}
else
{
// populate strtok buffer to prevent crashes
static char dummy[1] = "";
strtok(dummy, "");
Player* pl = getSelectedPlayerOrSelf();
// if allowed player pointer
if (player)
*player = pl;
// if allowed player guid (if no then only online players allowed)
if (player_guid)
*player_guid = pl ? pl->GetGUID() : ObjectGuid::Empty;
if (player_name)
*player_name = pl ? pl->GetName() : "";
}
// some from req. data must be provided (note: name is empty if player does not exist)
if ((!player || !*player) && (!player_guid || !*player_guid) && (!player_name || player_name->empty()))
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
return true;
}
char* ChatHandler::extractQuotedArg(char* args)
{
if (!args || !*args)
return nullptr;
if (*args == '"')
return strtok(args+1, "\"");
else
{
// skip spaces
while (*args == ' ')
{
args += 1;
continue;
}
// return nullptr if we reached the end of the string
if (!*args)
return nullptr;
// since we skipped all spaces, we expect another token now
if (*args == '"')
{
// return an empty string if there are 2 "" in a row.
// strtok doesn't handle this case
if (*(args + 1) == '"')
{
strtok(args, " ");
static char arg[1];
arg[0] = '\0';
return arg;
}
else
return strtok(args + 1, "\"");
}
else
return nullptr;
}
}
bool ChatHandler::needReportToTarget(Player* chr) const
{
Player* pl = m_session->GetPlayer();
return pl != chr && pl->IsVisibleGloballyFor(chr);
}
LocaleConstant ChatHandler::GetSessionDbcLocale() const
{
return m_session->GetSessionDbcLocale();
}
LocaleConstant ChatHandler::GetSessionDbLocaleIndex() const
{
return m_session->GetSessionDbLocaleIndex();
}
std::string ChatHandler::playerLink(std::string const& name) const
{
return m_session ? "|cffffffff|Hplayer:" + name + "|h[" + name + "]|h|r" : name;
}
std::string ChatHandler::GetNameLink(Player* chr) const
{
return playerLink(chr->GetName());
}
char const* CliHandler::GetTrinityString(uint32 entry) const
{
return sObjectMgr->GetTrinityStringForDBCLocale(entry);
}
void CliHandler::SendSysMessage(std::string_view str, bool /*escapeCharacters*/)
{
m_print(m_callbackArg, str);
m_print(m_callbackArg, "\r\n");
}
bool CliHandler::ParseCommands(std::string_view str)
{
if (str.empty())
return false;
// Console allows using commands both with and without leading indicator
if (str[0] == '.' || str[0] == '!')
str = str.substr(1);
return _ParseCommands(str);
}
std::string CliHandler::GetNameLink() const
{
return GetTrinityString(LANG_CONSOLE_COMMAND);
}
bool CliHandler::needReportToTarget(Player* /*chr*/) const
{
return true;
}
bool ChatHandler::GetPlayerGroupAndGUIDByName(const char* cname, Player*& player, Group*& group, ObjectGuid& guid, bool offline)
{
player = nullptr;
guid.Clear();
if (cname)
{
std::string name = cname;
if (!name.empty())
{
if (!normalizePlayerName(name))
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
player = ObjectAccessor::FindPlayerByName(name);
if (offline)
guid = sCharacterCache->GetCharacterGuidByName(name);
}
}
if (player)
{
group = player->GetGroup();
if (!guid || !offline)
guid = player->GetGUID();
}
else
{
if (getSelectedPlayer())
player = getSelectedPlayer();
else
player = m_session->GetPlayer();
if (!guid || !offline)
guid = player->GetGUID();
group = player->GetGroup();
}
return true;
}
LocaleConstant CliHandler::GetSessionDbcLocale() const
{
return sWorld->GetDefaultDbcLocale();
}
LocaleConstant CliHandler::GetSessionDbLocaleIndex() const
{
return sObjectMgr->GetDBCLocaleIndex();
}
std::string const AddonChannelCommandHandler::PREFIX = "TrinityCore";
bool AddonChannelCommandHandler::ParseCommands(std::string_view str)
{
if (str.length() < 5)
return false;
char opcode = str[0];
echo = &str[1];
switch (opcode)
{
case 'p': // p Ping
SendAck();
return true;
case 'h': // h Issue human-readable command
case 'i': // i Issue command
{
if (!str[5])
return false;
humanReadable = (opcode == 'h');
std::string_view cmd = str.substr(5);
if (_ParseCommands(cmd)) // actual command starts at str[5]
{
if (!hadAck)
SendAck();
if (HasSentErrorMessage())
SendFailed();
else
SendOK();
}
else
{
PSendSysMessage(LANG_CMD_INVALID, STRING_VIEW_FMT_ARG(cmd));
SendFailed();
}
return true;
}
default:
return false;
}
}
void AddonChannelCommandHandler::Send(std::string const& msg)
{
WorldPackets::Chat::Chat chat;
chat.Initialize(CHAT_MSG_WHISPER, LANG_ADDON, GetSession()->GetPlayer(), GetSession()->GetPlayer(), msg, 0, "", LOCALE_enUS, PREFIX);
GetSession()->SendPacket(chat.Write());
}
void AddonChannelCommandHandler::SendAck() // a Command acknowledged, no body
{
ASSERT(echo);
char ack[6] = "a";
memcpy(ack + 1, echo, 4);
ack[5] = '\0';
Send(ack);
hadAck = true;
}
void AddonChannelCommandHandler::SendOK() // o Command OK, no body
{
ASSERT(echo);
char ok[6] = "o";
memcpy(ok + 1, echo, 4);
ok[5] = '\0';
Send(ok);
}
void AddonChannelCommandHandler::SendFailed() // f Command failed, no body
{
ASSERT(echo);
char fail[6] = "f";
memcpy(fail + 1, echo, 4);
fail[5] = '\0';
Send(fail);
}
// m Command message, message in body
void AddonChannelCommandHandler::SendSysMessage(std::string_view str, bool escapeCharacters)
{
ASSERT(echo);
if (!hadAck)
SendAck();
std::string msg = "m";
msg.append(echo, 4);
std::string body(str);
if (escapeCharacters)
boost::replace_all(body, "|", "||");
size_t pos, lastpos;
for (lastpos = 0, pos = body.find('\n', lastpos); pos != std::string::npos; lastpos = pos + 1, pos = body.find('\n', lastpos))
{
std::string line(msg);
line.append(body, lastpos, pos - lastpos);
Send(line);
}
msg.append(body, lastpos, pos - lastpos);
Send(msg);
}
|