-
Notifications
You must be signed in to change notification settings - Fork 404
/
worldserver.cpp
4406 lines (3992 loc) · 126 KB
/
worldserver.cpp
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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2016 EQEMu Development Team (http://eqemu.org)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../common/global_define.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#ifdef _WINDOWS
#include <process.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#endif
#include "../common/eq_packet_structs.h"
#include "../common/misc_functions.h"
#include "../common/rulesys.h"
#include "../common/say_link.h"
#include "../common/servertalk.h"
#include "../common/profanity_manager.h"
#include "client.h"
#include "command.h"
#include "corpse.h"
#include "entity.h"
#include "expedition.h"
#include "quest_parser_collection.h"
#include "guild_mgr.h"
#include "mob.h"
#include "petitions.h"
#include "raids.h"
#include "string_ids.h"
#include "titles.h"
#include "worldserver.h"
#include "zone.h"
#include "zone_config.h"
#include "../common/shared_tasks.h"
#include "shared_task_zone_messaging.h"
#include "dialogue_window.h"
#include "bot_command.h"
#include "../common/events/player_event_logs.h"
#include "../common/repositories/guild_tributes_repository.h"
#include "../common/patches/patches.h"
#include "../common/skill_caps.h"
extern EntityList entity_list;
extern Zone* zone;
extern volatile bool is_zone_loaded;
extern void Shutdown();
extern WorldServer worldserver;
extern PetitionList petition_list;
extern uint32 numclients;
extern volatile bool RunLoops;
extern QuestParserCollection *parse;
// QuestParserCollection *parse = 0;
WorldServer::WorldServer()
{
cur_groupid = 0;
last_groupid = 0;
oocmuted = false;
}
WorldServer::~WorldServer() {
}
void WorldServer::Connect()
{
m_connection = std::make_unique<EQ::Net::ServertalkClient>(Config->WorldIP, Config->WorldTCPPort, false, "Zone", Config->SharedKey);
m_connection->OnConnect([this](EQ::Net::ServertalkClient *client) {
OnConnected();
});
m_connection->OnMessage(std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_keepalive = std::make_unique<EQ::Timer>(1000, true, std::bind(&WorldServer::OnKeepAlive, this, std::placeholders::_1));
}
bool WorldServer::SendPacket(ServerPacket *pack)
{
m_connection->SendPacket(pack);
return true;
}
std::string WorldServer::GetIP() const
{
return m_connection->Handle()->RemoteIP();
}
uint16 WorldServer::GetPort() const
{
return m_connection->Handle()->RemotePort();
}
bool WorldServer::Connected() const
{
return m_connection->Connected();
}
void WorldServer::SetZoneData(uint32 iZoneID, uint32 iInstanceID) {
auto pack = new ServerPacket(ServerOP_SetZone, sizeof(SetZone_Struct));
SetZone_Struct* szs = (SetZone_Struct*)pack->pBuffer;
szs->zoneid = iZoneID;
szs->instanceid = iInstanceID;
if (zone) {
szs->staticzone = zone->IsStaticZone();
}
SendPacket(pack);
safe_delete(pack);
}
void WorldServer::OnConnected() {
ServerPacket* pack;
/* Tell the launcher what our information is */
pack = new ServerPacket(ServerOP_SetLaunchName, sizeof(LaunchName_Struct));
LaunchName_Struct* ln = (LaunchName_Struct*)pack->pBuffer;
strn0cpy(ln->launcher_name, m_launcherName.c_str(), 32);
strn0cpy(ln->zone_name, m_launchedName.c_str(), 16);
SendPacket(pack);
safe_delete(pack);
/* Tell the Worldserver basic information about this zone process */
pack = new ServerPacket(ServerOP_SetConnectInfo, sizeof(ServerConnectInfo));
ServerConnectInfo* sci = (ServerConnectInfo*)pack->pBuffer;
auto config = ZoneConfig::get();
sci->port = ZoneConfig::get()->ZonePort;
if (config->WorldAddress.length() > 0) {
strn0cpy(sci->address, config->WorldAddress.c_str(), 250);
}
if (config->LocalAddress.length() > 0) {
strn0cpy(sci->local_address, config->LocalAddress.c_str(), 250);
}
/* Fetch process ID */
if (getpid()) {
sci->process_id = getpid();
}
else {
sci->process_id = 0;
}
SendPacket(pack);
safe_delete(pack);
if (is_zone_loaded) {
SetZoneData(zone->GetZoneID(), zone->GetInstanceID());
entity_list.UpdateWho(true);
SendEmoteMessage(
0,
0,
Chat::Yellow,
fmt::format(
"Zone Connected | {}",
zone->GetZoneDescription()
).c_str()
);
zone->GetTimeSync();
}
else {
SetZoneData(0);
}
pack = new ServerPacket(ServerOP_LSZoneBoot, sizeof(ZoneBoot_Struct));
ZoneBoot_Struct* zbs = (ZoneBoot_Struct*)pack->pBuffer;
strcpy(zbs->compile_time, LAST_MODIFIED);
SendPacket(pack);
safe_delete(pack);
}
/* Zone Process Packets from World */
void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
{
ServerPacket tpack(opcode, p);
ServerPacket *pack = &tpack;
switch (opcode) {
case 0:
case ServerOP_KeepAlive: {
break;
}
case ServerOP_SetConnectInfo: {
if (pack->size != sizeof(ServerConnectInfo))
break;
ServerConnectInfo* sci = (ServerConnectInfo*)pack->pBuffer;
if (sci->port == 0) {
LogError("World did not have a port to assign from this server, the port range was not large enough.");
Shutdown();
}
else {
LogInfo("World assigned Port [{}] for this zone", sci->port);
ZoneConfig::SetZonePort(sci->port);
LogSys.SetDiscordHandler(&Zone::DiscordWebhookMessageHandler);
}
break;
}
case ServerOP_ChannelMessage: {
if (!is_zone_loaded)
break;
ServerChannelMessage_Struct* scm = (ServerChannelMessage_Struct*)pack->pBuffer;
if (scm->deliverto[0] == 0) {
entity_list.ChannelMessageFromWorld(scm->from, scm->to, scm->chan_num, scm->guilddbid, scm->language, scm->lang_skill, scm->message);
}
else {
Client* client = entity_list.GetClientByName(scm->deliverto);
if (client && client->Connected()) {
if (scm->chan_num == ChatChannel_TellEcho) {
if (scm->queued == 1) // tell was queued
client->Tell_StringID(QUEUED_TELL, scm->to, scm->message);
else if (scm->queued == 2) // tell queue was full
client->Tell_StringID(QUEUE_TELL_FULL, scm->to, scm->message);
else if (scm->queued == 3) // person was offline
client->MessageString(Chat::EchoTell, TOLD_NOT_ONLINE, scm->to);
else // normal tell echo "You told Soanso, 'something'"
// tell echo doesn't use language, so it looks normal to you even if nobody can understand your tells
client->ChannelMessageSend(scm->from, scm->to, scm->chan_num, Language::CommonTongue, Language::MaxValue, scm->message);
}
else if (scm->chan_num == ChatChannel_Tell) {
client->ChannelMessageSend(scm->from, scm->to, scm->chan_num, scm->language, scm->lang_skill, scm->message);
if (scm->queued == 0) { // this is not a queued tell
// if it's a tell, echo back to acknowledge it and make it show on the sender's client
scm->chan_num = ChatChannel_TellEcho;
memset(scm->deliverto, 0, sizeof(scm->deliverto));
strcpy(scm->deliverto, scm->from);
SendPacket(pack);
}
}
else {
client->ChannelMessageSend(scm->from, scm->to, scm->chan_num, scm->language, scm->lang_skill, scm->message);
}
}
}
break;
}
case ServerOP_VoiceMacro: {
if (!is_zone_loaded)
break;
ServerVoiceMacro_Struct* svm = (ServerVoiceMacro_Struct*)pack->pBuffer;
auto outapp = new EQApplicationPacket(OP_VoiceMacroOut, sizeof(VoiceMacroOut_Struct));
VoiceMacroOut_Struct* vmo = (VoiceMacroOut_Struct*)outapp->pBuffer;
strcpy(vmo->From, svm->From);
vmo->Type = svm->Type;
vmo->Voice = svm->Voice;
vmo->MacroNumber = svm->MacroNumber;
switch (svm->Type) {
case VoiceMacroTell: {
Client* c = entity_list.GetClientByName(svm->To);
if (!c)
break;
c->QueuePacket(outapp);
break;
}
case VoiceMacroGroup: {
Group* g = entity_list.GetGroupByID(svm->GroupID);
if (!g)
break;
for (unsigned int i = 0; i < MAX_GROUP_MEMBERS; i++) {
if (g->members[i] && g->members[i]->IsClient())
g->members[i]->CastToClient()->QueuePacket(outapp);
}
break;
}
case VoiceMacroRaid: {
Raid *r = entity_list.GetRaidByID(svm->RaidID);
if (!r) {
break;
}
for (const auto& m: r->members) {
if (m.is_bot) {
continue;
}
if (m.member) {
m.member->QueuePacket(outapp);
}
}
break;
}
}
safe_delete(outapp);
break;
}
case ServerOP_SpawnCondition: {
if (pack->size != sizeof(ServerSpawnCondition_Struct))
break;
if (!is_zone_loaded)
break;
ServerSpawnCondition_Struct* ssc = (ServerSpawnCondition_Struct*)pack->pBuffer;
zone->spawn_conditions.SetCondition(zone->GetShortName(), zone->GetInstanceID(), ssc->condition_id, ssc->value, true);
break;
}
case ServerOP_SpawnEvent: {
if (pack->size != sizeof(ServerSpawnEvent_Struct))
break;
if (!is_zone_loaded)
break;
ServerSpawnEvent_Struct* sse = (ServerSpawnEvent_Struct*)pack->pBuffer;
zone->spawn_conditions.ReloadEvent(sse->event_id);
break;
}
case ServerOP_AcceptWorldEntrance: {
if (pack->size != sizeof(WorldToZone_Struct))
break;
if (!is_zone_loaded)
break;
WorldToZone_Struct* wtz = (WorldToZone_Struct*)pack->pBuffer;
if (zone->GetMaxClients() != 0 && numclients >= zone->GetMaxClients())
wtz->response = -1;
else
wtz->response = 1;
SendPacket(pack);
break;
}
case ServerOP_ZoneToZoneRequest: {
if (pack->size != sizeof(ZoneToZone_Struct))
break;
if (!is_zone_loaded)
break;
ZoneToZone_Struct* ztz = (ZoneToZone_Struct*)pack->pBuffer;
LogZoning(
"ZoneToZone client [{}] guild_id [{}] requested_zone [{}] requested_zone_id [{}] requested_instance_id [{}] current_zone [{}] current_zone_id [{}] current_instance_id [{}] response [{}] admin [{}] ignorerestrictions [{}]",
ztz->name,
ztz->guild_id,
ZoneName(ztz->requested_zone_id),
ztz->requested_zone_id,
ztz->requested_instance_id,
ZoneName(ztz->current_zone_id),
ztz->current_zone_id,
ztz->current_instance_id,
ztz->response,
ztz->admin,
ztz->ignorerestrictions
);
// the client was rejected by the world server
// zone was not ready for some reason
if (ztz->current_zone_id == zone->GetZoneID() && ztz->current_instance_id == zone->GetInstanceID()) {
// it's a response
Entity* entity = entity_list.GetClientByName(ztz->name);
if (entity == 0)
break;
EQApplicationPacket *outapp;
outapp = new EQApplicationPacket(OP_ZoneChange, sizeof(ZoneChange_Struct));
ZoneChange_Struct* zc2 = (ZoneChange_Struct*)outapp->pBuffer;
if (ztz->response <= 0) {
zc2->success = ZoningMessage::ZoneNotReady;
entity->CastToMob()->SetZone(ztz->current_zone_id, ztz->current_instance_id);
entity->CastToClient()->SetZoning(false);
entity->CastToClient()->SetLockSavePosition(false);
LogZoning("ZoneToZone (ZoneNotReady) client [{}] guild_id [{}] requested_zone [{}] requested_zone_id [{}] requested_instance_id [{}] current_zone [{}] current_zone_id [{}] current_instance_id [{}] response [{}] admin [{}] ignorerestrictions [{}] ",
ztz->name,
ztz->guild_id,
ZoneName(ztz->requested_zone_id),
ztz->requested_zone_id,
ztz->requested_instance_id,
ZoneName(ztz->current_zone_id),
ztz->current_zone_id,
ztz->current_instance_id,
ztz->response,
ztz->admin,
ztz->ignorerestrictions
);
}
else {
entity->CastToClient()->UpdateWho(1);
strn0cpy(zc2->char_name, entity->CastToMob()->GetName(), 64);
zc2->zoneID = ztz->requested_zone_id;
zc2->instanceID = ztz->requested_instance_id;
zc2->success = 1;
// This block is necessary to clean up any merc objects owned by a Client. Maybe we should do this for bots, too?
if (entity->CastToClient()->GetMerc() != nullptr)
{
entity->CastToClient()->GetMerc()->ProcessClientZoneChange(entity->CastToClient());
}
entity->CastToMob()->SetZone(ztz->requested_zone_id, ztz->requested_instance_id);
if (ztz->ignorerestrictions == 3)
entity->CastToClient()->GoToSafeCoords(ztz->requested_zone_id, ztz->requested_instance_id);
}
outapp->priority = 6;
entity->CastToClient()->QueuePacket(outapp);
safe_delete(outapp);
switch (ztz->response)
{
case -2: {
entity->CastToClient()->Message(Chat::Red, "You do not own the required locations to enter this zone.");
break;
}
case -1: {
entity->CastToClient()->Message(Chat::Red, "The zone is currently full, please try again later.");
break;
}
case 0: {
entity->CastToClient()->Message(Chat::Red, "All zone servers are taken at this time, please try again later.");
break;
}
}
}
// the client was accepted by the world server
else {
// it's a request
ztz->response = 0;
if (zone->GetMaxClients() != 0 && numclients >= zone->GetMaxClients())
ztz->response = -1;
else {
ztz->response = 1;
}
SendPacket(pack);
break;
}
break;
}
case ServerOP_WhoAllReply: {
if (!is_zone_loaded)
break;
WhoAllReturnStruct* wars = (WhoAllReturnStruct*)pack->pBuffer;
if (wars && wars->id != 0 && wars->id<0xFFFFFFFF) {
Client* client = entity_list.GetClientByID(wars->id);
if (client) {
if (pack->size == 64)//no results
client->MessageString(Chat::White, WHOALL_NO_RESULTS);
else {
auto outapp = new EQApplicationPacket(OP_WhoAllResponse, pack->size);
memcpy(outapp->pBuffer, pack->pBuffer, pack->size);
client->QueuePacket(outapp);
safe_delete(outapp);
}
}
else {
LogDebug("[CLIENT] id=[{}], playerineqstring=[{}], playersinzonestring=[{}]. Dumping WhoAllReturnStruct:",
wars->id, wars->playerineqstring, wars->playersinzonestring);
}
}
else
LogError("WhoAllReturnStruct: Could not get return struct!");
break;
}
case ServerOP_EmoteMessage: {
if (!is_zone_loaded)
break;
ServerEmoteMessage_Struct* sem = (ServerEmoteMessage_Struct*)pack->pBuffer;
if (sem->to[0] != 0) {
if (strcasecmp(sem->to, zone->GetShortName()) == 0)
entity_list.MessageStatus(
sem->guilddbid,
sem->minstatus,
sem->type,
(char*)sem->message
);
else {
Client* client = entity_list.GetClientByName(sem->to);
if (client) {
char* newmessage = 0;
if (strstr(sem->message, "^") == 0)
client->Message(sem->type, (char*)sem->message);
else {
for (newmessage = strtok((char*)sem->message, "^"); newmessage != nullptr; newmessage = strtok(nullptr, "^"))
client->Message(sem->type, newmessage);
}
}
}
}
else {
char* newmessage = 0;
if (strstr(sem->message, "^") == 0) {
entity_list.MessageStatus(
sem->guilddbid,
sem->minstatus,
sem->type,
sem->message
);
} else {
for (newmessage = strtok((char*)sem->message, "^"); newmessage != nullptr; newmessage = strtok(nullptr, "^")) {
entity_list.MessageStatus(
sem->guilddbid,
sem->minstatus,
sem->type,
newmessage
);
}
}
}
break;
}
case ServerOP_Motd: {
if (pack->size != sizeof(ServerMotd_Struct))
break;
ServerMotd_Struct *smotd = (ServerMotd_Struct *)pack->pBuffer;
SerializeBuffer buf(100);
buf.WriteString(smotd->motd);
auto outapp = std::make_unique<EQApplicationPacket>(OP_MOTD, buf);
entity_list.QueueClients(0, outapp.get());
break;
}
case ServerOP_ShutdownAll: {
entity_list.Save();
Shutdown();
break;
}
case ServerOP_ZoneShutdown: {
if (pack->size != sizeof(ServerZoneStateChange_Struct)) {
LogError("Wrong size on ServerOP_ZoneShutdown. Got: [{}] Expected: [{}]", pack->size, sizeof(ServerZoneStateChange_Struct));
break;
}
if (!is_zone_loaded) {
SetZoneData(0);
} else {
SendEmoteMessage(
0,
0,
Chat::Yellow,
fmt::format(
"Zone Shutdown | {}",
zone->GetZoneDescription()
).c_str()
);
auto *s = (ServerZoneStateChange_Struct *) pack->pBuffer;
LogInfo("Zone shutdown by {}.", s->admin_name);
Zone::Shutdown();
}
break;
}
case ServerOP_ZoneBootup: {
if (pack->size != sizeof(ServerZoneStateChange_Struct)) {
LogError("Wrong size on ServerOP_ZoneShutdown. Got: [{}] Expected: [{}]", pack->size, sizeof(ServerZoneStateChange_Struct));
break;
}
auto *s = (ServerZoneStateChange_Struct *) pack->pBuffer;
if (is_zone_loaded) {
SetZoneData(zone->GetZoneID(), zone->GetInstanceID());
if (s->zone_id != zone->GetZoneID()) {
SendEmoteMessage(
s->admin_name,
0,
Chat::White,
fmt::format(
"Zone Bootup Failed | {} Already running",
zone->GetZoneDescription()
).c_str()
);
}
break;
}
if (s->admin_name[0] != 0) {
LogInfo("Zone bootup by {}.", s->admin_name);
}
Zone::Bootup(s->zone_id, s->instance_id, s->is_static);
break;
}
case ServerOP_ZoneIncClient: {
if (pack->size != sizeof(ServerZoneIncomingClient_Struct)) {
std::cout << "Wrong size on ServerOP_ZoneIncClient. Got: " << pack->size << ", Expected: " << sizeof(ServerZoneIncomingClient_Struct) << std::endl;
break;
}
ServerZoneIncomingClient_Struct* szic = (ServerZoneIncomingClient_Struct*)pack->pBuffer;
if (is_zone_loaded) {
SetZoneData(zone->GetZoneID(), zone->GetInstanceID());
if (szic->zoneid == zone->GetZoneID()) {
auto client = entity_list.GetClientByLSID(szic->lsid);
if (client) {
client->Kick("Dropped by world CLE subsystem");
client->Save();
}
zone->RemoveAuth(szic->lsid);
zone->AddAuth(szic);
}
}
else {
if ((Zone::Bootup(szic->zoneid, szic->instanceid))) {
zone->AddAuth(szic);
}
}
break;
}
case ServerOP_DropClient: {
if (pack->size != sizeof(ServerZoneDropClient_Struct)) {
break;
}
ServerZoneDropClient_Struct* drop = (ServerZoneDropClient_Struct*)pack->pBuffer;
if (zone) {
zone->RemoveAuth(drop->lsid);
auto client = entity_list.GetClientByLSID(drop->lsid);
if (client) {
client->Kick("Dropped by world CLE subsystem");
client->Save();
}
}
break;
}
case ServerOP_ZonePlayer: {
ServerZonePlayer_Struct* szp = (ServerZonePlayer_Struct*)pack->pBuffer;
auto client = entity_list.GetClientByName(szp->name);
if (client) {
if (!strcasecmp(szp->adminname, szp->name)) {
client->Message(
Chat::White,
fmt::format(
"Zoning to {} ({}).",
ZoneLongName(
ZoneID(szp->zone)
),
ZoneID(szp->zone)
).c_str()
);
} else if (client->GetAnon() == 1 && client->Admin() > szp->adminrank) {
break;
} else {
std::string name = Strings::ToLower(szp->name);
name[0] = toupper(name[0]);
SendEmoteMessage(
szp->adminname,
0,
Chat::White,
fmt::format(
"Summoning {} to {:.2f}, {:.2f}, {:.2f} in {} ({}).",
name,
szp->x_pos,
szp->y_pos,
szp->z_pos,
ZoneLongName(
ZoneID(szp->zone)
),
ZoneID(szp->zone)
).c_str()
);
}
if (!szp->instance_id) {
client->MovePC(ZoneID(szp->zone), szp->instance_id, szp->x_pos, szp->y_pos, szp->z_pos, client->GetHeading(), szp->ignorerestrictions, GMSummon);
} else {
if (database.GetInstanceID(client->CharacterID(), ZoneID(szp->zone))) {
client->RemoveFromInstance(database.GetInstanceID(client->CharacterID(), ZoneID(szp->zone)));
}
client->AssignToInstance(szp->instance_id);
client->MovePC(ZoneID(szp->zone), szp->instance_id, szp->x_pos, szp->y_pos, szp->z_pos, client->GetHeading(), szp->ignorerestrictions, GMSummon);
}
}
break;
}
case ServerOP_KickPlayer: {
ServerKickPlayer_Struct* skp = (ServerKickPlayer_Struct*)pack->pBuffer;
Client* client;
if (strlen(skp->name)) {
client = entity_list.GetClientByName(skp->name);
} else if (skp->account_id) {
client = entity_list.GetClientByAccID(skp->account_id);
}
if (client) {
if (skp->adminrank >= client->Admin()) {
client->WorldKick();
SendEmoteMessage(
skp->adminname,
0,
Chat::White,
fmt::format(
"Remote Kick | {} booted{}.",
skp->name,
is_zone_loaded ?
fmt::format(
" in {}",
zone->GetZoneDescription()
) :
""
).c_str()
);
} else if (client->GetAnon() != 1) {
SendEmoteMessage(
skp->adminname,
0,
Chat::White,
fmt::format(
"Remote Kick | Your Status Level is not high enough to kick {}.",
skp->name
).c_str()
);
}
}
break;
}
case ServerOP_KillPlayer: {
ServerKillPlayer_Struct* skp = (ServerKillPlayer_Struct*)pack->pBuffer;
Client* client = entity_list.GetClientByName(skp->target);
if (client) {
if (skp->admin >= client->Admin()) {
client->GMKill();
SendEmoteMessage(
skp->gmname,
0,
Chat::White,
fmt::format(
"Remote Kill | {} killed{}",
skp->target,
is_zone_loaded ?
fmt::format(
"in {}",
zone->GetZoneDescription()
) :
""
).c_str()
);
} else if (client->GetAnon() != 1) {
SendEmoteMessage(
skp->gmname,
0,
Chat::White,
fmt::format(
"Remote Kill | Your Status Level is not high enough to kill {}",
skp->target
).c_str()
);
}
}
break;
}
case ServerOP_OnlineGuildMembersResponse:
case ServerOP_RefreshGuild:
case ServerOP_DeleteGuild:
case ServerOP_GuildCharRefresh:
case ServerOP_GuildMemberUpdate:
case ServerOP_GuildPermissionUpdate:
case ServerOP_GuildRankUpdate:
case ServerOP_GuildRankNameChange:
case ServerOP_LFGuildUpdate:
case ServerOP_GuildMemberLevelUpdate:
case ServerOP_GuildMemberPublicNote:
case ServerOP_GuildChannel:
case ServerOP_GuildURL:
case ServerOP_GuildMemberRemove:
case ServerOP_GuildMemberAdd:
case ServerOP_GuildSendGuildList:
case ServerOP_GuildMembersList:
{
guild_mgr.ProcessWorldPacket(pack);
break;
}
case ServerOP_FlagUpdate: {
Client* client = entity_list.GetClientByAccID(*((uint32*)pack->pBuffer));
if (client) {
client->UpdateAdmin();
}
break;
}
case ServerOP_GMGoto: {
if (pack->size != sizeof(ServerGMGoto_Struct)) {
std::cout << "Wrong size on ServerOP_GMGoto. Got: " << pack->size << ", Expected: " << sizeof(ServerGMGoto_Struct) << std::endl;
break;
}
if (!is_zone_loaded)
break;
ServerGMGoto_Struct* gmg = (ServerGMGoto_Struct*)pack->pBuffer;
Client* client = entity_list.GetClientByName(gmg->gotoname);
if (client) {
SendEmoteMessage(
gmg->myname,
0,
Chat::Red,
fmt::format(
"Summoning you to {} in {} at {:.2f}, {:.2f}, {:.2f}",
client->GetCleanName(),
zone->GetZoneDescription(),
client->GetX(),
client->GetY(),
client->GetZ()
).c_str()
);
auto outpack = new ServerPacket(ServerOP_ZonePlayer, sizeof(ServerZonePlayer_Struct));
ServerZonePlayer_Struct* szp = (ServerZonePlayer_Struct*)outpack->pBuffer;
strcpy(szp->adminname, gmg->myname);
strcpy(szp->name, gmg->myname);
strcpy(szp->zone, zone->GetShortName());
szp->instance_id = zone->GetInstanceID();
szp->x_pos = client->GetX();
szp->y_pos = client->GetY();
szp->z_pos = client->GetZ();
SendPacket(outpack);
safe_delete(outpack);
}
else {
SendEmoteMessage(
gmg->myname,
0,
Chat::Red,
fmt::format(
"Error: {} not found.",
gmg->gotoname
).c_str()
);
}
break;
}
case ServerOP_MultiLineMsg: {
ServerMultiLineMsg_Struct* mlm = (ServerMultiLineMsg_Struct*)pack->pBuffer;
Client* client = entity_list.GetClientByName(mlm->to);
if (client) {
auto outapp = new EQApplicationPacket(OP_MultiLineMsg, strlen(mlm->message));
strcpy((char*)outapp->pBuffer, mlm->message);
client->QueuePacket(outapp);
safe_delete(outapp);
}
break;
}
case ServerOP_Uptime: {
if (pack->size != sizeof(ServerUptime_Struct)) {
std::cout << "Wrong size on ServerOP_Uptime. Got: " << pack->size << ", Expected: " << sizeof(ServerUptime_Struct) << std::endl;
break;
}
ServerUptime_Struct* sus = (ServerUptime_Struct*)pack->pBuffer;
uint32 ms = Timer::GetCurrentTime();
std::string time_string = Strings::MillisecondsToTime(ms);
SendEmoteMessage(
sus->adminname,
0,
Chat::White,
fmt::format(
"Zoneserver {} | Uptime: {}",
sus->zoneserverid,
time_string
).c_str()
);
}
case ServerOP_Petition: {
std::cout << "Got Server Requested Petition List Refresh" << std::endl;
ServerPetitionUpdate_Struct* sus = (ServerPetitionUpdate_Struct*)pack->pBuffer;
// this was typoed to = instead of ==, not that it acts any different now though..
if (sus->status == 0) petition_list.ReadDatabase();
else if (sus->status == 1) petition_list.ReadDatabase(); // Until I fix this to be better....
break;
}
case ServerOP_RezzPlayer: {
RezzPlayer_Struct* srs = (RezzPlayer_Struct*)pack->pBuffer;
if (srs->rezzopcode == OP_RezzRequest)
{
// The Rezz request has arrived in the zone the player to be rezzed is currently in,
// so we send the request to their client which will bring up the confirmation box.
Client* client = entity_list.GetClientByName(srs->rez.your_name);
if (client)
{
if (client->IsRezzPending())
{
auto Response = new ServerPacket(ServerOP_RezzPlayerReject,
strlen(srs->rez.rezzer_name) + 1);
char *Buffer = (char *)Response->pBuffer;
sprintf(Buffer, "%s", srs->rez.rezzer_name);
worldserver.SendPacket(Response);
safe_delete(Response);
break;
}
//pendingrezexp is the amount of XP on the corpse. Setting it to a value >= 0
//also serves to inform Client::OPRezzAnswer to expect a packet.
client->SetPendingRezzData(srs->exp, srs->dbid, srs->rez.spellid, srs->rez.corpse_name);
LogSpells("[WorldServer::HandleMessage] OP_RezzRequest in zone [{}] for [{}] spellid [{}]",
zone->GetShortName(), client->GetName(), srs->rez.spellid);
auto outapp = new EQApplicationPacket(OP_RezzRequest,
sizeof(Resurrect_Struct));
memcpy(outapp->pBuffer, &srs->rez, sizeof(Resurrect_Struct));
client->QueuePacket(outapp);
safe_delete(outapp);
break;
}
}
if (srs->rezzopcode == OP_RezzComplete) {
// We get here when the Rezz complete packet has come back via the world server
// to the zone that the corpse is in.
Corpse* corpse = entity_list.GetCorpseByName(srs->rez.corpse_name);
if (corpse && corpse->IsCorpse()) {
LogSpells("[WorldServer::HandleMessage] OP_RezzComplete received in zone [{}] for corpse [{}]",
zone->GetShortName(), srs->rez.corpse_name);
LogSpells("[WorldServer::HandleMessage] Found corpse. Marking corpse as rezzed if needed");
// I don't know why Rezzed is not set to true in CompleteRezz().
if (!IsEffectInSpell(srs->rez.spellid, SE_SummonToCorpse)) {
corpse->IsRezzed(true);
corpse->CompleteResurrection();
}
}
}
break;
}
case ServerOP_RezzPlayerReject:
{
char *Rezzer = (char *)pack->pBuffer;
Client* c = entity_list.GetClientByName(Rezzer);
if (c)
c->MessageString(Chat::SpellWornOff, REZZ_ALREADY_PENDING);
break;
}
case ServerOP_ZoneReboot: {
std::cout << "Got Server Requested Zone reboot" << std::endl;
ServerZoneReboot_Struct* zb = (ServerZoneReboot_Struct*)pack->pBuffer;
break;
}
case ServerOP_SyncWorldTime: {
if (zone != 0 && !zone->is_zone_time_localized) {
LogInfo("[{}] Received Message SyncWorldTime", __FUNCTION__);
eqTimeOfDay* newtime = (eqTimeOfDay*)pack->pBuffer;
zone->zone_time.SetCurrentEQTimeOfDay(newtime->start_eqtime, newtime->start_realtime);
auto outapp = new EQApplicationPacket(OP_TimeOfDay, sizeof(TimeOfDay_Struct));
TimeOfDay_Struct* time_of_day = (TimeOfDay_Struct*)outapp->pBuffer;
zone->zone_time.GetCurrentEQTimeOfDay(time(0), time_of_day);
entity_list.QueueClients(0, outapp, false);
safe_delete(outapp);
char time_message[255];
time_t current_time = time(nullptr);
TimeOfDay_Struct eq_time{};
zone->zone_time.GetCurrentEQTimeOfDay(current_time, &eq_time);
sprintf(time_message, "EQTime [%02d:%s%d %s]",
((eq_time.hour - 1) % 12) == 0 ? 12 : ((eq_time.hour - 1) % 12),
(eq_time.minute < 10) ? "0" : "",
eq_time.minute,
(eq_time.hour >= 13) ? "pm" : "am"
);
LogInfo("Time Broadcast Packet: {}", time_message);
zone->SetZoneHasCurrentTime(true);
}
if (zone && zone->is_zone_time_localized) {
LogInfo("Received request to sync time from world, but our time is localized currently");
}
break;
}
case ServerOP_RefreshCensorship: {
if (!EQ::ProfanityManager::LoadProfanityList(&database))
LogError("Received request to refresh the profanity list..but, the action failed");
break;