forked from EQMacEmu/Server
-
Notifications
You must be signed in to change notification settings - Fork 57
/
zoneserver.cpp
1658 lines (1520 loc) · 49.5 KB
/
zoneserver.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-2005 EQEMu Development Team (http://eqemulator.net)
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 "zoneserver.h"
#include "clientlist.h"
#include "login_server.h"
#include "login_server_list.h"
#include "zonelist.h"
#include "worlddb.h"
#include "client.h"
#include "../common/md5.h"
#include "world_config.h"
#include "../common/guilds.h"
#include "../common/packet_dump.h"
#include "../common/misc.h"
#include "../common/strings.h"
#include "cliententry.h"
#include "wguild_mgr.h"
#include "ucs.h"
#include "queryserv.h"
#include "../common/content/world_content_service.h"
#include "../common/zone_store.h"
#include "../common/patches/patches.h"
#include "../common/skill_caps.h"
extern ClientList client_list;
extern ZSList zoneserver_list;
extern LoginServerList loginserverlist;
extern volatile bool RunLoops;
extern volatile bool UCSServerAvailable_;
extern UCSConnection UCSLink;
extern QueryServConnection QSLink;
void CatchSignal(int sig_num);
ZoneServer::ZoneServer(std::shared_ptr<EQ::Net::ServertalkServerConnection> in_connection, EQ::Net::ConsoleServer* in_console)
: tcpc(in_connection), zone_boot_timer(5000) {
/* Set Process tracking variable defaults */
memset(zone_name, 0, sizeof(zone_name));
memset(compiled, 0, sizeof(compiled));
memset(client_address, 0, sizeof(client_address));
memset(client_local_address, 0, sizeof(client_local_address));
zone_server_id = zoneserver_list.GetNextID();
zone_server_previous_zone_id = 0;
zone_server_previous_guild_id = 0xFFFFFFFF;
zone_server_zone_id = 0;
zone_server_guild_id = 0xFFFFFFFF;
zone_os_process_id = 0;
client_port = 0;
is_booting_up = false;
ucs_connected = false;
is_authenticated = false;
is_static_zone = false;
zone_player_count = 0;
tcpc->OnMessage(std::bind(&ZoneServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
boot_timer_obj = std::make_unique<EQ::Timer>(100, true, [this](EQ::Timer* obj) {
if (zone_boot_timer.Check()) {
LSBootUpdate(GetZoneID(), true);
zone_boot_timer.Disable();
}
});
console = in_console;
}
ZoneServer::~ZoneServer() {
if (RunLoops)
client_list.CLERemoveZSRef(this);
}
bool ZoneServer::SetZone(uint32 iZoneID, bool iStaticZone, uint32 iGuildID) {
is_booting_up = false;
const char* zonename = MakeLowerString(ZoneName(iZoneID));
char* longname;
if (iZoneID)
Log(Logs::Detail, Logs::WorldServer, "Setting to '%s' (%d:%d)%s", (zonename) ? zonename : "", iZoneID, iGuildID,
iStaticZone ? " (Static)" : "");
zone_server_zone_id = iZoneID;
zone_server_guild_id = iGuildID;
if (iZoneID != 0)
{
zone_server_previous_zone_id = iZoneID;
zone_server_previous_guild_id = iGuildID;
}
if (zone_server_zone_id == 0) {
client_list.CLERemoveZSRef(this);
zone_player_count = 0;
if (zone_server_previous_guild_id != 0xFFFFFFFF)
LSSleepUpdate(GetPrevZoneID());
}
is_static_zone = iStaticZone;
if (zonename)
{
strn0cpy(zone_name, zonename, sizeof(zone_name));
if (database.GetZoneLongName((char*)zone_name, &longname, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr))
{
strn0cpy(long_name, longname, sizeof(long_name));
safe_delete_array(longname);
}
else
strcpy(long_name, "");
}
else
{
strcpy(zone_name, "");
strcpy(long_name, "");
}
client_list.ZoneBootup(this);
zone_boot_timer.Start();
return true;
}
void ZoneServer::LSShutDownUpdate(uint32 zoneid) {
if (WorldConfig::get()->UpdateStats) {
auto pack = new ServerPacket;
pack->opcode = ServerOP_LSZoneShutdown;
pack->size = sizeof(ZoneShutdown_Struct);
pack->pBuffer = new uchar[pack->size];
memset(pack->pBuffer, 0, pack->size);
auto zsd = (ZoneShutdown_Struct*)pack->pBuffer;
if (zoneid == 0) {
zsd->zone = GetPrevZoneID();
}
else {
zsd->zone = zoneid;
}
zsd->zone_wid = GetID();
loginserverlist.SendPacket(pack);
safe_delete(pack);
}
}
void ZoneServer::LSBootUpdate(uint32 zoneid, bool startup) {
if (WorldConfig::get()->UpdateStats) {
auto pack = new ServerPacket;
pack->opcode = startup ? ServerOP_LSZoneStart : ServerOP_LSZoneBoot;
pack->size = sizeof(ZoneBoot_Struct);
pack->pBuffer = new uchar[pack->size];
memset(pack->pBuffer, 0, pack->size);
auto bootup = (ZoneBoot_Struct*)pack->pBuffer;
if (startup) {
strcpy(bootup->compile_time, GetCompileTime());
}
bootup->zone = zoneid;
bootup->zone_wid = GetID();
loginserverlist.SendPacket(pack);
safe_delete(pack);
}
}
void ZoneServer::LSSleepUpdate(uint32 zone_id) {
if (WorldConfig::get()->UpdateStats) {
auto pack = new ServerPacket;
pack->opcode = ServerOP_LSZoneSleep;
pack->size = sizeof(ServerLSZoneSleep_Struct);
pack->pBuffer = new uchar[pack->size];
memset(pack->pBuffer, 0, pack->size);
auto sleep = (ServerLSZoneSleep_Struct*)pack->pBuffer;
sleep->zone = zone_id;
sleep->zone_wid = GetID();
loginserverlist.SendPacket(pack);
safe_delete(pack);
}
}
extern void TriggerManualQuake(QuakeType in_quake_type);
void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet& p) {
ServerPacket tpack(opcode, p);
auto pack = &tpack;
switch (opcode) {
case 0:
case ServerOP_KeepAlive:
case ServerOP_ZAAuth: {
break;
}
case ServerOP_LSZoneBoot: {
if (pack->size == sizeof(ZoneBoot_Struct)) {
auto zbs = (ZoneBoot_Struct*)pack->pBuffer;
SetCompile(zbs->compile_time);
}
break;
}
case ServerOP_GroupInvite: {
if (pack->size != sizeof(GroupInvite_Struct)) {
break;
}
auto gis = (GroupInvite_Struct*)pack->pBuffer;
client_list.SendPacket(gis->invitee_name, pack);
break;
}
case ServerOP_GroupFollow: {
if (pack->size != sizeof(ServerGroupFollow_Struct)) {
break;
}
auto sgfs = (ServerGroupFollow_Struct*)pack->pBuffer;
client_list.SendPacket(sgfs->gf.name1, pack);
break;
}
case ServerOP_GroupFollowAck: {
if (pack->size != sizeof(ServerGroupFollowAck_Struct)) {
break;
}
auto sgfas = (ServerGroupFollowAck_Struct*)pack->pBuffer;
client_list.SendPacket(sgfas->Name, pack);
break;
}
case ServerOP_GroupCancelInvite: {
if (pack->size != sizeof(GroupCancel_Struct)) {
break;
}
auto gcs = (GroupCancel_Struct*)pack->pBuffer;
client_list.SendPacket(gcs->name1, pack);
break;
}
case ServerOP_GroupSetID: {
if (pack->size != sizeof(GroupSetID_Struct)) {
break;
}
auto gsi = (GroupSetID_Struct*)pack->pBuffer;
// set groupid in CLE
uint32 char_id = gsi->char_id;
ClientListEntry* client_cle = client_list.FindCLEByCharacterID(gsi->char_id);
if (client_cle) {
client_cle->SetGroupID(gsi->group_id);
}
break;
}
case ServerOP_GroupIDReq: {
SendGroupIDs();
break;
}
case ServerOP_GroupLeave: {
if (pack->size != sizeof(ServerGroupLeave_Struct)) {
break;
}
zoneserver_list.SendPacket(pack); //bounce it to all zones
break;
}
case ServerOP_GroupJoin: {
if (pack->size != sizeof(ServerGroupJoin_Struct)) {
break;
}
zoneserver_list.SendPacket(pack); //bounce it to all zones
break;
}
case ServerOP_RaidGroupJoin: {
if (pack->size != sizeof(ServerRaidGroupJoin_Struct)) {
break;
}
zoneserver_list.SendPacket(pack); //bounce it to all zones
break;
}
case ServerOP_ForceGroupUpdate: {
if (pack->size != sizeof(ServerForceGroupUpdate_Struct)) {
break;
}
zoneserver_list.SendPacket(pack); //bounce it to all zones
break;
}
case ServerOP_OOZGroupMessage: {
zoneserver_list.SendPacket(pack); //bounce it to all zones
// check for characters zoning and queue messages
auto gcm = (ServerGroupChannelMessage_Struct*)pack->pBuffer;
if (gcm->groupid != 0) {
char membername[MAX_GROUP_MEMBERS][64]; // group member names
bool groupLoaded = false; // only query the database if there are clients zoning
// iterate client_list looking for clients that are zoning
std::vector<ClientListEntry*> vec;
client_list.GetClients("", vec);
for (auto it = vec.begin(); it != vec.end(); ++it) {
ClientListEntry* cle = *it;
if (cle)
{
uint32 groupid = cle->GroupID();
if (cle->Online() == CLE_Status::Zoning && groupid == gcm->groupid && !cle->TellQueueFull())
{
// queue group chat message
size_t struct_size = sizeof(ServerChannelMessage_Struct) + strlen(gcm->message) + 1;
ServerChannelMessage_Struct* scm = (ServerChannelMessage_Struct*) new uchar[struct_size];
memset(scm, 0, struct_size);
strcpy(scm->deliverto, cle->name());
strcpy(scm->from, gcm->from);
scm->chan_num = ChatChannel_Group;
scm->language = gcm->language;
scm->lang_skill = gcm->lang_skill;
strcpy(scm->message, gcm->message);
scm->queued = 1;
cle->PushToTellQueue(scm); // deallocation is handled in processing or deconstructor
}
}
}
}
break;
}
case ServerOP_DisbandGroup: {
if (pack->size != sizeof(ServerDisbandGroup_Struct)) {
break;
}
auto sdbg = (ServerDisbandGroup_Struct*)pack->pBuffer;
if (sdbg->groupid > 0) {
client_list.ClearGroup(sdbg->groupid); // clear groupid from all matching CLE's
}
zoneserver_list.SendPacket(pack); //bounce it to all zones
break;
}
case ServerOP_ChangeGroupLeader: {
if (pack->size != sizeof(ServerGroupLeader_Struct)) {
break;
}
zoneserver_list.SendPacket(pack); //bounce it to all zones
break;
}
case ServerOP_CheckGroupLeader: {
if (pack->size != sizeof(ServerGroupLeader_Struct)) {
break;
}
auto sgls = (ServerGroupLeader_Struct*)pack->pBuffer;
ClientListEntry* cle = client_list.FindCharacter(sgls->leader_name);
if (cle) {
zoneserver_list.SendPacket(pack); //bounce it to all zones
}
else {
LogInfo("Character {} is not found, group ownership will not be transferred.", sgls->leader_name);
}
break;
}
case ServerOP_RaidAdd: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidRemove: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidRemoveLD: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidDisband: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidChangeGroup: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_UpdateGroup: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidGroupDisband: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidGroupAdd: {
if (pack->size != sizeof(ServerRaidGroupAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidGroupRemove: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidGroupSay:
case ServerOP_RaidSay: {
zoneserver_list.SendPacket(pack); // broadcast to zones
break;
}
case ServerOP_RaidGroupLeader: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidLeader: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidTypeChange: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RaidAddLooter: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RemoveRaidLooter: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_DetailsChange: {
if (pack->size != sizeof(ServerRaidGeneralAction_Struct)) {
break;
}
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_SpawnCondition: {
if (pack->size != sizeof(ServerSpawnCondition_Struct))
break;
//bounce the packet to the correct zone server, if its up
ServerSpawnCondition_Struct* ssc = (ServerSpawnCondition_Struct*)pack->pBuffer;
zoneserver_list.SendPacket(ssc->zoneID, 0, pack);
break;
}
case ServerOP_SpawnEvent: {
if (pack->size != sizeof(ServerSpawnEvent_Struct))
break;
//bounce the packet to the correct zone server, if its up
ServerSpawnEvent_Struct* sse = (ServerSpawnEvent_Struct*)pack->pBuffer;
zoneserver_list.SendPacket(sse->zoneID, 0, pack);
break;
}
case ServerOP_ChannelMessage: {
if (pack->size < sizeof(ServerChannelMessage_Struct)) {
break;
}
auto scm = (ServerChannelMessage_Struct*)pack->pBuffer;
if (scm->chan_num == 20) {
UCSLink.SendMessage(scm->from, scm->message);
break;
}
// tells get a reply echo
if (scm->chan_num == ChatChannel_Tell || scm->chan_num == ChatChannel_TellEcho) {
if (scm->deliverto[0] == '*') {
if (console) {
auto con = console->FindByAccountName(&scm->deliverto[1]);
if (
!con ||
(
!con->SendChannelMessage(
scm,
[&scm]() {
auto pack = new ServerPacket(ServerOP_ChannelMessage, sizeof(ServerChannelMessage_Struct) + strlen(scm->message) + 1);
memcpy(pack->pBuffer, scm, pack->size);
auto scm2 = (ServerChannelMessage_Struct*)pack->pBuffer;
strcpy(scm2->deliverto, scm2->from);
scm2->noreply = true;
client_list.SendPacket(scm->from, pack);
safe_delete(pack);
}
)
) &&
!scm->noreply
) {
zoneserver_list.SendEmoteMessage(
scm->from,
0,
AccountStatus::Player,
Chat::White,
fmt::format(
"{} is not online at this time.",
scm->to
).c_str()
);
}
}
break;
}
auto cle = client_list.FindCharacter(scm->deliverto);
if (cle == 0 || cle->Online() < CLE_Status::Zoning ||
(cle->TellsOff() && (scm->fromadmin < cle->Admin() || scm->fromadmin < 80))) {
// client not found or has tells off
if (scm->chan_num == ChatChannel_Tell) {
ClientListEntry* sender = client_list.FindCharacter(scm->from);
if (!sender || !sender->Server())
break;
scm->chan_num = ChatChannel_TellEcho;
scm->queued = 3; // offline
strcpy(scm->deliverto, scm->from);
// ideally this would be trimming off the message too, oh well
sender->Server()->SendPacket(pack);
}
}
else if (cle->Online() == CLE_Status::Zoning) {
if (scm->chan_num == ChatChannel_Tell) {
ClientListEntry* sender = client_list.FindCharacter(scm->from);
if (cle->TellQueueFull()) {
if (!sender || !sender->Server())
break;
scm->chan_num = ChatChannel_TellEcho;
scm->queued = 2; // queue full
strcpy(scm->deliverto, scm->from);
sender->Server()->SendPacket(pack);
}
else {
if (cle && sender->Revoked() && cle->Admin() <= 0)
break;
size_t struct_size = sizeof(ServerChannelMessage_Struct) + strlen(scm->message) + 1;
ServerChannelMessage_Struct* temp = (ServerChannelMessage_Struct*) new uchar[struct_size];
memset(temp, 0, struct_size); // just in case, was seeing some corrupt messages, but it shouldn't happen
memcpy(temp, scm, struct_size);
temp->queued = 1;
cle->PushToTellQueue(temp); // deallocation is handled in processing or deconstructor
if (!sender || !sender->Server())
break;
scm->chan_num = ChatChannel_TellEcho;
scm->queued = 1; // queued
strcpy(scm->deliverto, scm->from);
sender->Server()->SendPacket(pack);
}
}
}
else if (cle->Server() == 0) {
if (scm->chan_num == ChatChannel_Tell)
zoneserver_list.SendEmoteMessage(scm->from, 0, AccountStatus::Player, Chat::Default, fmt::format(" {} is not contactable at this time'", scm->to).c_str());
}
else
{
if (scm->chan_num == ChatChannel_Tell) {
ClientListEntry* sender = client_list.FindCharacter(scm->from);
if (cle && sender && sender->Revoked() && cle->Admin() <= 0)
{
if (scm->chan_num == ChatChannel_Tell)
zoneserver_list.SendEmoteMessage(scm->from, 0, AccountStatus::Player, Chat::Default, "You are server muted, and aren't able to send a message to anyone but a CSR.");
break;
}
}
cle->Server()->SendPacket(pack);
}
}
else {
//if (scm->chan_num == ChatChannel_OOC || scm->chan_num == ChatChannel_Broadcast || scm->chan_num == ChatChannel_GMSAY) {
// console_list.SendChannelMessage(scm);
//}
zoneserver_list.SendPacket(pack); // broadcast to zones
if (scm->chan_num == ChatChannel_Guild || scm->chan_num == ChatChannel_GMSAY || scm->chan_num == ChatChannel_Broadcast) {
// check for characters zoning and see if they would be eligible for this message, and if so, queue message
std::vector<ClientListEntry*> vec;
client_list.GetClients("", vec);
for (auto it = vec.begin(); it != vec.end(); ++it) {
ClientListEntry* cle = *it;
if (cle->Online() == CLE_Status::Zoning && !cle->TellQueueFull()) {
// is this client one of the targets of this message?
if
(
(scm->chan_num == ChatChannel_Guild && scm->guilddbid == cle->GuildID()) ||
(scm->chan_num == ChatChannel_GMSAY && cle->Admin() >= 80) ||
scm->chan_num == ChatChannel_Broadcast
)
{
// queue chat message
size_t struct_size = sizeof(ServerChannelMessage_Struct) + strlen(scm->message) + 1;
ServerChannelMessage_Struct* scm2 = (ServerChannelMessage_Struct*) new uchar[struct_size];
memset(scm2, 0, struct_size);
strcpy(scm2->deliverto, cle->name());
strcpy(scm2->from, scm->from);
scm2->chan_num = scm->chan_num;
scm2->language = scm->language;
scm2->lang_skill = scm->lang_skill;
strcpy(scm2->message, scm->message);
scm2->queued = 1;
cle->PushToTellQueue(scm2); // deallocation is handled in processing or deconstructor
}
}
}
}
}
break;
}
case ServerOP_EmoteMessage: {
auto sem = (ServerEmoteMessage_Struct*)pack->pBuffer;
zoneserver_list.SendEmoteMessageRaw(sem->to, sem->guilddbid, sem->minstatus, sem->type, sem->message);
break;
}
case ServerOP_RezzPlayerAccept: {
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_RezzPlayer: {
auto sRezz = (RezzPlayer_Struct*)pack->pBuffer;
if (zoneserver_list.SendPacket(pack)) {
LogInfo("Sent Rez packet for {}", sRezz->rez.your_name);
}
else {
LogInfo("Could not send Rez packet for {}", sRezz->rez.your_name);
}
break;
}
case ServerOP_RezzPlayerReject: {
char* Recipient = (char*)pack->pBuffer;
client_list.SendPacket(Recipient, pack);
break;
}
case ServerOP_MultiLineMsg: {
auto mlm = (ServerMultiLineMsg_Struct*)pack->pBuffer;
client_list.SendPacket(mlm->to, pack);
break;
}
case ServerOP_SetZone: {
if (pack->size != sizeof(SetZone_Struct)) {
break;
}
SetZone_Struct* szs = (SetZone_Struct*)pack->pBuffer;
if (szs->zoneid != 0) {
if (ZoneName(szs->zoneid))
SetZone(szs->zoneid, szs->staticzone, szs->zoneguildid);
else
SetZone(0);
}
break;
}
case ServerOP_SetConnectInfo: {
if (pack->size != sizeof(ServerConnectInfo)) {
break;
}
auto sci = (ServerConnectInfo*)pack->pBuffer;
if (!sci->port) {
client_port = zoneserver_list.GetAvailableZonePort();
ServerPacket p(ServerOP_SetConnectInfo, sizeof(ServerConnectInfo));
memset(p.pBuffer, 0, sizeof(ServerConnectInfo));
ServerConnectInfo* sci = (ServerConnectInfo*)p.pBuffer;
sci->port = client_port;
SendPacket(&p);
LogInfo("Auto zone port configuration. Telling zone to use port [{}]", client_port);
}
else {
client_port = sci->port;
LogInfo("Zone specified port [{}]", client_port);
}
if (sci->address[0]) {
strn0cpy(client_address, sci->address, 250);
LogInfo("Zone specified address [{}]", sci->address);
}
if (sci->local_address[0]) {
strn0cpy(client_local_address, sci->local_address, 250);
LogInfo("Zone specified local address [{}]", sci->local_address);
}
if (sci->process_id) {
zone_os_process_id = sci->process_id;
}
break;
}
case ServerOP_SetLaunchName: {
if (pack->size != sizeof(LaunchName_Struct)) {
break;
}
const LaunchName_Struct* ln = (const LaunchName_Struct*)pack->pBuffer;
launcher_name = ln->launcher_name;
launched_name = ln->zone_name;
database.ZoneConnected(ZoneID(ln->zone_name), ln->zone_name);
LogInfo("Zone started with name [{}] by launcher [{}]", launched_name.c_str(), launcher_name.c_str());
break;
}
case ServerOP_ShutdownAll: {
if (pack->size == 0) {
zoneserver_list.SendPacket(pack);
zoneserver_list.Process();
CatchSignal(2);
}
else {
auto wsd = (WorldShutDown_Struct*)pack->pBuffer;
if (!wsd->time && !wsd->interval && zoneserver_list.shutdowntimer->Enabled()) {
zoneserver_list.shutdowntimer->Disable();
zoneserver_list.reminder->Disable();
}
else {
zoneserver_list.shutdowntimer->Start(wsd->time);
zoneserver_list.reminder->Start(wsd->interval - 1000);
zoneserver_list.reminder->SetDuration(wsd->interval);
zoneserver_list.shutdowntimer->Start();
zoneserver_list.reminder->Start();
}
}
break;
}
case ServerOP_ZoneShutdown: {
auto s = (ServerZoneStateChange_struct*)pack->pBuffer;
ZoneServer* zs = 0;
if (s->ZoneServerID) {
zs = zoneserver_list.FindByZoneID(s->ZoneServerID, s->ZoneServerGuildID);
}
else if (s->zoneid) {
zs = zoneserver_list.FindByName(ZoneName(s->zoneid));
}
else {
zoneserver_list.SendEmoteMessage(s->adminname, 0, AccountStatus::Player, Chat::White, "Error: SOP_ZoneShutdown: neither ID nor name specified");
}
if (zs == 0) {
zoneserver_list.SendEmoteMessage(s->adminname, 0, AccountStatus::Player, Chat::White, "Error: SOP_ZoneShutdown: zoneserver not found");
}
else {
zs->SendPacket(pack);
}
break;
}
case ServerOP_ZoneBootup: {
auto s = (ServerZoneStateChange_struct*)pack->pBuffer;
uint32 ZoneServerID = s->ZoneServerID;
if (ZoneServerID == 0) {
ZoneServerID = zoneserver_list.GetAvailableZoneID();
if (ZoneServerID == 0) {
break;
}
}
zoneserver_list.SOPZoneBootup(s->adminname, ZoneServerID, s->ZoneServerGuildID, ZoneName(s->zoneid), s->makestatic);
break;
}
case ServerOP_ZoneStatus: {
if (pack->size >= 1) {
auto z = (ServerZoneStatus_Struct*)pack->pBuffer;
zoneserver_list.SendZoneStatus(z->name, z->admin, this);
}
break;
}
case ServerOP_AcceptWorldEntrance: {
if (pack->size != sizeof(WorldToZone_Struct)) {
break;
}
auto wtz = (WorldToZone_Struct*)pack->pBuffer;
Client* client = 0;
client = client_list.FindByAccountID(wtz->account_id);
if (client != 0) {
client->Clearance(wtz->response);
}
break;
}
case ServerOP_ZoneToZoneRequest: {
//
// solar: ZoneChange is received by the zone the player is in, then the
// zone sends a ZTZ which ends up here. This code then find the target
// (ingress point) and boots it if needed, then sends the ZTZ to it.
// The ingress server will decide wether the player can enter, then will
// send back the ZTZ to here. This packet is passed back to the egress
// server, which will send a ZoneChange response back to the client
// which can be an error, or a success, in which case the client will
// disconnect, and their zone location will be saved when ~Client is
// called, so it will be available when they ask to zone.
//
if (pack->size != sizeof(ZoneToZone_Struct)) {
break;
}
auto ztz = (ZoneToZone_Struct*)pack->pBuffer;
ClientListEntry* client = nullptr;
if (WorldConfig::get()->UpdateStats) {
client = client_list.FindCharacter(ztz->name);
}
Log(Logs::Detail, Logs::WorldServer, "ZoneToZone request for %s current zone %d req zone %d",
ztz->name, ztz->current_zone_id, ztz->requested_zone_id);
/* This is a request from the egress zone */
if (GetZoneID() == ztz->current_zone_id && GetZoneGuildID() == ztz->current_zone_guild_id) {
Log(Logs::Detail, Logs::WorldServer, "Processing ZTZ for egress from zone for client %s", ztz->name);
if (ztz->admin < 80 && ztz->ignorerestrictions < 2 && zoneserver_list.IsZoneLocked(ztz->requested_zone_id)) {
ztz->response = 0;
SendPacket(pack);
break;
}
ZoneServer* ingress_server = nullptr;
ingress_server = zoneserver_list.FindByZoneID(ztz->requested_zone_id, ztz->requested_zone_guild_id);
/* Zone was already running*/
if (ingress_server) {
Log(Logs::Detail, Logs::WorldServer, "Found a zone already booted for %s", ztz->name);
ztz->response = 1;
}
/* Boot the Zone*/
else {
int server_id;
if (!RuleB(World, DontBootDynamics) || ztz->requested_zone_guild_id != 0xFFFFFFFF)
{
if ((server_id = zoneserver_list.TriggerBootup(ztz->requested_zone_id, ztz->requested_zone_guild_id))) {
Log(Logs::Detail, Logs::WorldServer, "Successfully booted a zone for %s", ztz->name);
// bootup successful, ready to rock
ztz->response = 1;
ingress_server = zoneserver_list.FindByID(server_id);
}
else
{
Log(Logs::Detail, Logs::WorldServer, "FAILED to boot a zone for %s", ztz->name);
// bootup failed, send back error code 0
ztz->response = 0;
}
}
else
{
LogInfo("FAILED to boot a zone for [{}]", ztz->name);
// bootup failed, send back error code 0
ztz->response = 0;
}
}
if (ztz->response != 0 && client)
client->LSZoneChange(ztz);
SendPacket(pack); // send back to egress server
if (ingress_server) {
ingress_server->SendPacket(pack); // inform target server
}
}
/* Response from Ingress server, route back to egress */
else {
Log(Logs::Detail, Logs::WorldServer, "Processing ZTZ for ingress to zone for client %s", ztz->name);
ZoneServer* egress_server = nullptr;
egress_server = zoneserver_list.FindByZoneID(ztz->current_zone_id, ztz->current_zone_guild_id);
if (egress_server) {
egress_server->SendPacket(pack);
}
}
break;
}
case ServerOP_ClientList: {
if (pack->size != sizeof(ServerClientList_Struct)) {
Log(Logs::Detail, Logs::WorldServer, "Wrong size on ServerOP_ClientList. Got: %d, Expected: %d", pack->size, sizeof(ServerClientList_Struct));
break;
}
client_list.ClientUpdate(this, (ServerClientList_Struct*)pack->pBuffer);
break;
}
case ServerOP_ClientListKA: {
auto sclka = (ServerClientListKeepAlive_Struct*)pack->pBuffer;
if (pack->size < 4 || pack->size != 4 + (4 * sclka->numupdates)) {
Log(Logs::Detail, Logs::WorldServer, "Wrong size on ServerOP_ClientListKA. Got: %d, Expected: %d", pack->size, (4 + (4 * sclka->numupdates)));
break;
}
client_list.CLEKeepAlive(sclka->numupdates, sclka->wid);
break;
}
case ServerOP_Who: {
auto whoall = (ServerWhoAll_Struct*)pack->pBuffer;
auto whom = new Who_All_Struct;
memset(whom, 0, sizeof(Who_All_Struct));
whom->gmlookup = whoall->gmlookup;
whom->lvllow = whoall->lvllow;
whom->lvlhigh = whoall->lvlhigh;
whom->wclass = whoall->wclass;
whom->wrace = whoall->wrace;
whom->guildid = whoall->guildid;
strcpy(whom->whom, whoall->whom);
client_list.SendWhoAll(whoall->fromid, whoall->from, whoall->admin, whom);
safe_delete(whom);
break;
}
case ServerOP_RequestOnlineGuildMembers: {
auto srogms = (ServerRequestOnlineGuildMembers_Struct*)pack->pBuffer;
Log(Logs::Detail, Logs::Guilds, "ServerOP_RequestOnlineGuildMembers Recieved. FromID=%i GuildID=%i", srogms->FromID, srogms->GuildID);
client_list.SendOnlineGuildMembers(srogms->FromID, srogms->GuildID);
break;
}
case ServerOP_ClientVersionSummary: {
auto srcvss = (ServerRequestClientVersionSummary_Struct*)pack->pBuffer;
client_list.SendClientVersionSummary(srcvss->Name);
break;
}
case ServerOP_ReloadRules: {
zoneserver_list.SendPacket(pack);
RuleManager::Instance()->LoadRules(&database, "default");
break;
}
case ServerOP_ReloadSpellModifiers: {
zoneserver_list.SendPacket(pack);
break;
}
case ServerOP_ReloadRulesWorld:
{
RuleManager::Instance()->LoadRules(&database, "default");
break;
}
case ServerOP_FriendsWho: {
auto FriendsWho = (ServerFriendsWho_Struct*)pack->pBuffer;
client_list.SendFriendsWho(FriendsWho, this);
break;
}
case ServerOP_KickPlayer: {
auto skp = (ServerKickPlayer_Struct*)pack->pBuffer;
ClientListEntry* cle = client_list.FindCLEByAccountID(skp->AccountID);
if (cle) {
cle->SetOnline(CLE_Status::Offline);
}
zoneserver_list.SendPacket(pack);
break;