-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCClient.cpp
More file actions
1770 lines (1575 loc) · 48.8 KB
/
Copy pathCClient.cpp
File metadata and controls
1770 lines (1575 loc) · 48.8 KB
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
#include "../../common/resource/sections/CResourceNamedDef.h"
#include "../../common/sphere_library/CSRand.h"
#include "../../common/CLog.h"
//#include "../../common/CException.h" // included in the precompiled header
//#include "../../common/CExpression.h" // included in the precompiled header
//#include "../../common/CScriptParserBufs.h" // included in the precompiled header via CExpression.h
#include "../../common/CUOClientVersion.h"
#include "../../network/CClientIterator.h"
#include "../../network/CNetworkManager.h"
#include "../../network/CIPHistoryManager.h"
#include "../../network/send.h"
#include "../chars/CChar.h"
#include "../components/CCSpawn.h"
#include "../items/CItemMultiCustom.h"
#include "../CServer.h"
#include "../CWorld.h"
#include "../CWorldGameTime.h"
#include "../CWorldMap.h"
#include "../spheresvr.h"
#include "../triggers.h"
#include "CParty.h"
#include "CClient.h"
/////////////////////////////////////////////////////////////////
// -CClient stuff.
CClient::CClient(CNetState* state)
{
// This may be a web connection or Telnet ?
m_net = state;
m_iConnectType = CONNECT_UNK; // don't know what sort of connect this is yet.
// update ip history
HistoryIP& history = g_NetworkManager.getIPHistoryManager().getHistoryForIP(GetPeer());
++ history.m_iPendingConnectionRequests;
++ history.m_iAliveSuccessfulConnections;
m_Crypt.SetClientVerFromOther( g_Serv.m_ClientVersion );
m_pAccount = nullptr;
m_pChar = nullptr;
m_pGMPage = nullptr;
m_timeLogin = 0;
m_timeLastEvent = CWorldGameTime::GetCurrentTime().GetTimeRaw();
m_timeLastEventWalk = CWorldGameTime::GetCurrentTime().GetTimeRaw();
m_timeNextEventWalk = 0;
m_iWalkStepCount = 0;
m_iWalkTimeAvg = 500;
m_timeWalkStep = CSTime::GetMonotonicSysTimeMilli();
m_lastDir = 0;
_fShowPublicHouseContent = true;
m_Targ_Timeout = 0;
m_Targ_Mode = CLIMODE_SETUP_CONNECTING;
m_Prompt_Mode = CLIMODE_NORMAL;
m_tmSetup.m_dwIP = 0;
m_tmSetup.m_iConnect = 0;
m_tmSetup.m_fNewSeed = false;
m_Env.SetInvalid();
g_Log.Event(LOGM_CLIENTS_LOG, "%x:Client connected [Total:%" PRIuSIZE_T "]. IP='%s'. (Connecting/Connected: %d/%d).\n",
GetSocketID(), g_Serv.StatGet(SERV_STAT_CLIENTS), GetPeerStr(), history.m_iPendingConnectionRequests, history.m_iAliveSuccessfulConnections);
m_zLastMessage[0] = 0;
m_zLastObjMessage[0] = 0;
m_tNextPickup = 0;
m_BfAntiCheat = {};
m_ScreenSize = {};
m_pPopupPacket = nullptr;
m_pHouseDesign = nullptr;
m_fUpdateStats = 0;
m_timeLastSkillThrowing = 0;
m_pSkillThrowingTarg = nullptr;
m_SkillThrowingAnimID = ITEMID_NOTHING;
m_SkillThrowingAnimHue = 0;
m_SkillThrowingAnimRender = 0;
m_fUseNewChatSystem = false;
}
CClient::~CClient() noexcept
{
ADDTOCALLSTACK("CClient::~CClient");
EXC_TRY("Cleanup in destructor");
// update ip history
HistoryIP& history = g_NetworkManager.getIPHistoryManager().getHistoryForIP(GetPeer());
if (IsPreGameTypePacket())
{
EXC_TRYSUB("m_iPendingConnectionRequests");
ASSERT(history.m_iPendingConnectionRequests > 0);
-- history.m_iPendingConnectionRequests;
EXC_CATCHSUB("m_iPendingConnectionRequests");
}
-- history.m_iAliveSuccessfulConnections;
const bool fWasChar = ( m_pChar != nullptr );
if (fWasChar)
CharDisconnect(); // am i a char in game ?
if (m_pGMPage)
m_pGMPage->ClearHandler();
// Clear session-bound containers (CTAG and TOOLTIP)
//m_TagDefs.Clear();
CAccount * pAccount = GetAccount();
if ( pAccount )
{
pAccount->OnLogout(this, fWasChar);
m_pAccount = nullptr;
}
if (fWasChar)
g_Serv.m_Chats.QuitChat(this);
if (m_pPopupPacket != nullptr)
{
delete m_pPopupPacket;
m_pPopupPacket = nullptr;
}
if (m_net->isClosed() == false)
g_Log.EventError("Client being deleted without being safely removed from the network system.\n");
EXC_CATCH;
}
bool CClient::CanInstantLogOut() const
{
ADDTOCALLSTACK("CClient::CanInstantLogOut");
if ( g_Serv.IsLoadingGeneric()) // or exiting.
return true;
if ( ! g_Cfg.m_iClientLingerTime )
return true;
if ( GetPrivLevel() > PLEVEL_Player )
return true;
if ( m_pChar == nullptr )
return true;
if ( m_pChar->IsStatFlag(STATF_DEAD))
return true;
const CRegionWorld * pArea = m_pChar->GetRegion();
if ( pArea == nullptr )
return true;
if ( pArea->IsFlag( REGION_FLAG_INSTA_LOGOUT ))
return true;
const CRegion * pRoom = m_pChar->GetRoom(); //Allows Room flag to work!
if ( pRoom && pRoom->IsFlag( REGION_FLAG_INSTA_LOGOUT )) //sanity check for null rooms // Can C++ guarantee short-circuit evaluation for CRegion ?
return true;
return false;
}
void CClient::CharDisconnect()
{
ADDTOCALLSTACK("CClient::CharDisconnect");
// Disconnect the CChar from the client.
// Even tho the CClient might stay active.
if ( !m_pChar )
return;
int64 iLingerTime = g_Cfg.m_iClientLingerTime / MSECS_PER_SEC;
Announce(false);
bool fCanInstaLogOut = CanInstantLogOut();
/* stoned chars cannot logout if they are not privileged of course
if (m_pChar->IsStatFlag(STATF_STONE))
{
iLingerTime = 60*60; // 1 hour of linger time
fCanInstaLogOut = false;
}
*/
// we are not a client anymore
if ( IsChatActive() )
g_Serv.m_Chats.QuitChat(this);
if ( m_pHouseDesign )
m_pHouseDesign->EndCustomize(true);
if ( IsTrigUsed(TRIGGER_LOGOUT) )
{
CScriptTriggerArgsPtr pScriptArgs = CScriptParserBufs::GetCScriptTriggerArgsPtr();
pScriptArgs->Init(iLingerTime, fCanInstaLogOut, 0, nullptr);
m_pChar->OnTrigger(CTRIG_LogOut, pScriptArgs, m_pChar);
iLingerTime = (int)(pScriptArgs->m_iN1);
fCanInstaLogOut = (pScriptArgs->m_iN2 != 0);
}
if ( iLingerTime <= 0 )
fCanInstaLogOut = true;
// log out immediately ? (test before ClientDetach())
if ( ! fCanInstaLogOut )
{
// become an NPC for a little while
CItem * pItemChange = CItem::CreateBase( ITEMID_RHAND_POINT_W );
ASSERT(pItemChange);
pItemChange->SetName("Client Linger");
pItemChange->SetType(IT_EQ_CLIENT_LINGER);
pItemChange->SetTimeoutS(iLingerTime);
m_pChar->LayerAdd(pItemChange, LAYER_FLAG_ClientLinger);
}
else
{
// remove me from other clients screens now.
m_pChar->SetDisconnected();
}
m_pChar->ClientDetach(); // we are not a client any more.
// Gump memory cleanup, we don't want them on logged out players
m_mapOpenedGumps.clear();
// Layer dragging, moving it to backpack
CItem * pItemDragging = m_pChar->LayerFind(LAYER_DRAGGING);
if ( pItemDragging )
m_pChar->ItemBounce(pItemDragging);
m_pChar = nullptr;
}
CClient* CClient::GetNext() const
{
return static_cast <CClient*>(CSObjListRec::GetNext());
}
bool CClient::IsPriv(word flag) const
{ // PRIV_GM
if (GetAccount() == nullptr)
return false;
return(GetAccount()->IsPriv(flag));
}
void CClient::SetPrivFlags(word wPrivFlags)
{
if (GetAccount() == nullptr)
return;
GetAccount()->SetPrivFlags(wPrivFlags);
}
void CClient::ClearPrivFlags(word wPrivFlags)
{
if (GetAccount() == nullptr)
return;
GetAccount()->ClearPrivFlags(wPrivFlags);
}
// ------------------------------------------------
bool CClient::IsResDisp(RESDISPLAY_VERSION res) const
{
if (GetAccount() == nullptr)
return false;
return(GetAccount()->IsResDisp(res));
}
byte CClient::GetResDisp() const
{
if (GetAccount() == nullptr)
return UINT8_MAX;
return(GetAccount()->GetResDisp());
}
bool CClient::SetResDisp(RESDISPLAY_VERSION res)
{
if (GetAccount() == nullptr)
return false;
return (GetAccount()->SetResDisp(res));
}
bool CClient::SetGreaterResDisp(RESDISPLAY_VERSION res)
{
if (GetAccount() == nullptr)
return false;
return(GetAccount()->SetGreaterResDisp(res));
}
// ------------------------------------------------
void CClient::SetScreenSize(ushort x, ushort y)
{
m_ScreenSize.x = x;
m_ScreenSize.y = y;
}
PLEVEL_TYPE CClient::GetPrivLevel() const
{
// PLEVEL_Counsel
if (GetAccount() == nullptr)
return(PLEVEL_Guest);
return(GetAccount()->GetPrivLevel());
}
lpctstr CClient::GetName() const
{
if (GetAccount() == nullptr)
return("NA");
return(GetAccount()->GetName());
}
void CClient::SysMessage( lpctstr pszMsg ) const // System message (In lower left corner)
{
ADDTOCALLSTACK("CClient::SysMessage");
// Diff sorts of clients.
if ( !pszMsg || !*pszMsg ) return;
switch ( GetConnectType() )
{
case CONNECT_TELNET:
case CONNECT_AXIS:
{
if ( *pszMsg == '\0' )
return;
new PacketTelnet(this, pszMsg);
}
return;
case CONNECT_UOG:
{
if ( *pszMsg == '\0' )
return;
new PacketTelnet(this, pszMsg, true);
}
return;
case CONNECT_CRYPT:
case CONNECT_LOGIN:
case CONNECT_GAME:
const_cast <CClient*>(this)->addSysMessage(pszMsg);
return;
case CONNECT_HTTP:
const_cast <CClient*>(this)->m_Targ_Text = pszMsg;
return;
default:
return;
}
}
void CClient::Announce( bool fArrive ) const
{
ADDTOCALLSTACK("CClient::Announce");
if ( !GetAccount() || !GetChar() || !GetChar()->m_pPlayer )
return;
// We have logged in or disconnected.
// Annouce my arrival or departure.
tchar *pszMsg = Str_GetTemp();
if ( (g_Cfg.m_iArriveDepartMsg == 2) && (GetPrivLevel() > PLEVEL_Player) ) // notify of GMs
{
lpctstr zTitle = m_pChar->Noto_GetFameTitle();
snprintf(pszMsg, Str_TempLength(), "@231 STAFF: %s%s logged %s.", zTitle, m_pChar->GetName(), (fArrive ? "in" : "out"));
}
else if ( g_Cfg.m_iArriveDepartMsg == 1 ) // notify of players
{
const CRegion *pRegion = m_pChar->GetTopPoint().GetRegion(REGION_TYPE_AREA);
snprintf(pszMsg, Str_TempLength(), g_Cfg.GetDefaultMsg(DEFMSG_MSG_ARRDEP_1),
m_pChar->GetName(),
fArrive ? g_Cfg.GetDefaultMsg(DEFMSG_MSG_ARRDEP_2) : g_Cfg.GetDefaultMsg(DEFMSG_MSG_ARRDEP_3),
pRegion != nullptr ? pRegion->GetName() : g_Serv.GetName());
}
if ( pszMsg )
{
ClientIterator it;
for (CClient *pClient = it.next(); pClient != nullptr; pClient = it.next())
{
if ( (pClient == this) || (GetPrivLevel() > pClient->GetPrivLevel()) )
continue;
pClient->SysMessage(pszMsg);
}
}
// Check murder decay timer
CItem *pMurders = m_pChar->LayerFind(LAYER_FLAG_Murders);
if ( pMurders )
{
if ( fArrive ) // on client login, set active timer on murder memory
pMurders->SetTimeoutS(pMurders->m_itEqMurderCount.m_dwDecayBalance);
else // or make it inactive on logout
{
pMurders->m_itEqMurderCount.m_dwDecayBalance = (dword)(pMurders->GetTimerSAdjusted());
pMurders->SetTimeout(-1);
}
}
else if ( fArrive )
m_pChar->Noto_Murder(); // if there's no murder memory found, check if we need a new memory
}
////////////////////////////////////////////////////
bool CClient::CanSee( const CObjBaseTemplate * pObj ) const
{
ADDTOCALLSTACK("CClient::CanSee");
// Can player see item b
if ( !m_pChar || !pObj )
return false;
if ( pObj->IsChar() )
{
const CChar *pChar = static_cast<const CChar*>(pObj);
if ( pChar->IsDisconnected() )
{
if( !IsPriv(PRIV_ALLSHOW) )
return false;
//dont show pet when is ridden (cause double). Exception in debug mode you see it
else if ( pChar->IsStatFlag(STATF_PET) && pChar->IsStatFlag(STATF_RIDDEN) && !IsPriv(PRIV_DEBUG))
return false;
}
}
return m_pChar->CanSee( pObj );
}
bool CClient::CanHear( const CObjBaseTemplate * pSrc, TALKMODE_TYPE mode ) const
{
ADDTOCALLSTACK("CClient::CanHear");
// can we hear this text or sound.
if ( !IsConnectTypePacket() )
return false;
if ( (mode == TALKMODE_BROADCAST) || !pSrc )
return true;
if ( !m_pChar )
return false;
if ( IsPriv(PRIV_HEARALL) &&
pSrc->IsChar() &&
( mode == TALKMODE_SAY || mode == TALKMODE_WHISPER || mode == TALKMODE_YELL ) ) // HEARALL works only for this talkmodes
{
const CChar * pCharSrc = dynamic_cast <const CChar*> ( pSrc );
ASSERT(pCharSrc);
if ( pCharSrc->IsClientActive() && (pCharSrc->GetPrivLevel() <= GetPrivLevel()) )
return true;
}
return m_pChar->CanHear( pSrc, mode );
}
////////////////////////////////////////////////////
void CClient::addTargetVerb( lpctstr pszCmd, lpctstr ptcArg )
{
ADDTOCALLSTACK("CClient::addTargetVerb");
// Target a verb at some object .
ASSERT(pszCmd);
GETNONWHITESPACE(pszCmd);
SKIP_SEPARATORS(pszCmd);
if ( !strlen(pszCmd) )
pszCmd = ptcArg;
if ( pszCmd == ptcArg )
{
GETNONWHITESPACE(pszCmd);
SKIP_SEPARATORS(pszCmd);
ptcArg = "";
}
// priv here
PLEVEL_TYPE ilevel = g_Cfg.GetPrivCommandLevel( pszCmd );
if ( ilevel > GetPrivLevel() )
return;
m_Targ_Text.Format( "%s%s%s", pszCmd, ( ptcArg[0] && pszCmd[0] ) ? " " : "", ptcArg );
tchar * pszMsg = Str_GetTemp();
snprintf(pszMsg, Str_TempLength(), g_Cfg.GetDefaultMsg(DEFMSG_TARGET_COMMAND), m_Targ_Text.GetBuffer());
addTarget(CLIMODE_TARG_OBJ_SET, pszMsg);
}
void CClient::addTargetFunctionMulti( lpctstr pszFunction, ITEMID_TYPE itemid, HUE_TYPE color, bool fAllowGround )
{
ADDTOCALLSTACK("CClient::addTargetFunctionMulti");
// Target a verb at some object .
ASSERT(pszFunction);
GETNONWHITESPACE(pszFunction);
SKIP_SEPARATORS(pszFunction);
m_Targ_Text = pszFunction;
if ( CItemBase::IsID_Multi( itemid )) // a multi we get from Multi.mul
{
SetTargMode(CLIMODE_TARG_OBJ_FUNC);
new PacketAddTarget(this, fAllowGround ? PacketAddTarget::Ground : PacketAddTarget::Object,
CLIMODE_TARG_OBJ_FUNC, PacketAddTarget::None, itemid, color);
}
addTargetFunction( pszFunction, fAllowGround, false );
}
void CClient::addTargetFunction( lpctstr pszFunction, bool fAllowGround, bool fCheckCrime )
{
ADDTOCALLSTACK("CClient::addTargetFunction");
// Target a verb at some object .
ASSERT(pszFunction);
GETNONWHITESPACE(pszFunction);
SKIP_SEPARATORS(pszFunction);
m_Targ_Text = pszFunction;
addTarget( CLIMODE_TARG_OBJ_FUNC, nullptr, fAllowGround, fCheckCrime );
}
void CClient::addPromptConsoleFunction( lpctstr pszFunction, lpctstr pszSysmessage, bool bUnicode )
{
ADDTOCALLSTACK("CClient::addPromptConsoleFunction");
// Target a verb at some object .
ASSERT(pszFunction);
m_Prompt_Text = pszFunction;
addPromptConsole( CLIMODE_PROMPT_SCRIPT_VERB, pszSysmessage, CUID(), CUID(), bUnicode );
}
enum CLIR_TYPE
{
CLIR_ACCOUNT,
CLIR_GMPAGEP,
CLIR_HOUSEDESIGN,
CLIR_PARTY,
CLIR_TARG,
CLIR_TARGPROP,
CLIR_TARGPRV,
CLIR_QTY
};
lpctstr const CClient::sm_szRefKeys[CLIR_QTY+1] =
{
"ACCOUNT",
"GMPAGEP",
"HOUSEDESIGN",
"PARTY",
"TARG",
"TARGPROP",
"TARGPRV",
nullptr
};
bool CClient::r_GetRef( lpctstr & ptcKey, CScriptObj * & pRef )
{
ADDTOCALLSTACK("CClient::r_GetRef");
int i = FindTableHeadSorted( ptcKey, sm_szRefKeys, ARRAY_COUNT(sm_szRefKeys)-1 );
if ( i >= 0 )
{
ptcKey += strlen( sm_szRefKeys[i] );
SKIP_SEPARATORS(ptcKey);
switch (i)
{
case CLIR_ACCOUNT:
if ( ptcKey[-1] != '.' ) // only used as a ref !
break;
pRef = GetAccount();
return true;
case CLIR_GMPAGEP:
pRef = m_pGMPage;
return true;
case CLIR_HOUSEDESIGN:
pRef = m_pHouseDesign;
return true;
case CLIR_PARTY:
if (CChar* pCharThis = GetChar())
{
if (!strnicmp(ptcKey, "CREATE", 7))
{
if (pCharThis->m_pParty)
return false;
lpctstr oldKey = ptcKey;
ptcKey += 7;
// Do i want to send the "joined" message to the party members?
bool fSendMsgs = (Exp_GetSingle(ptcKey) != 0) ? true : false;
// Add all the UIDs to the party
for (int ip = 0; ip < 10; ++ip)
{
SKIP_ARGSEP(ptcKey);
CChar* pChar = CUID::CharFindFromUID(Exp_GetDWSingle(ptcKey));
if (!pChar)
continue;
if (!pChar->IsClientActive())
continue;
CPartyDef::AcceptEvent(pChar, pCharThis->GetUID(), true, fSendMsgs);
if (*ptcKey == '\0')
break;
}
ptcKey = oldKey; // Restoring back to real ptcKey, so we don't get errors for giving an uid instead of PDV_CREATE.
}
if (!pCharThis->m_pParty)
return false;
pRef = pCharThis->m_pParty;
return true;
}
return false;
case CLIR_TARG:
pRef = m_Targ_UID.ObjFind();
return true;
case CLIR_TARGPRV:
pRef = m_Targ_Prv_UID.ObjFind();
return true;
case CLIR_TARGPROP:
pRef = m_Prop_UID.ObjFind();
return true;
}
}
return CScriptObj::r_GetRef( ptcKey, pRef );
}
lpctstr const CClient::sm_szLoadKeys[CC_QTY+1] = // static
{
#define ADD(a,b) b,
#include "../../tables/CClient_props.tbl"
#undef ADD
nullptr
};
lpctstr const CClient::sm_szVerbKeys[CV_QTY+1] = // static
{
#define ADD(a,b) b,
#include "../../tables/CClient_functions.tbl"
#undef ADD
nullptr
};
bool CClient::r_WriteVal( lpctstr ptcKey, CSString & sVal, CTextConsole * pSrc, bool fNoCallParent, bool fNoCallChildren )
{
UnreferencedParameter(fNoCallChildren);
ADDTOCALLSTACK("CClient::r_WriteVal");
EXC_TRY("WriteVal");
if ( !strnicmp("CTAG", ptcKey, 4) )
{
bool fCtag = false;
bool fZero = false;
if (ptcKey[4] == '.') // CTAG.xxx - client tag
{
fCtag = true;
ptcKey += 5;
}
else if ((ptcKey[4] == '0') && (ptcKey[5] == '.')) // CTAG0.xxx - client tag
{
fCtag = true;
fZero = true;
ptcKey += 6;
}
if (fCtag)
{
sVal = m_TagDefs.GetKeyStr(ptcKey, fZero);
return true;
}
}
int index;
if ( !strnicmp( "TARGP", ptcKey, 5 ) && ( ptcKey[5] == '\0' || ptcKey[5] == '.' ) )
index = CC_TARGP;
else if ( !strnicmp( "SCREENSIZE", ptcKey, 10 ) && ( ptcKey[10] == '\0' || ptcKey[10] == '.' ) )
index = CC_SCREENSIZE;
else if ( !strnicmp( "REPORTEDCLIVER", ptcKey, 14 ) && ( ptcKey[14] == '\0' || ptcKey[14] == '.' ) )
index = CC_REPORTEDCLIVER;
else
index = FindTableSorted( ptcKey, sm_szLoadKeys, ARRAY_COUNT(sm_szLoadKeys)-1 );
switch (index)
{
case CC_ALLMOVE:
sVal.FormatVal( IsPriv( PRIV_ALLMOVE ));
break;
case CC_ALLSHOW:
sVal.FormatVal( IsPriv( PRIV_ALLSHOW ));
break;
case CC_CLIENTIS3D:
sVal.FormatVal( GetNetState()->isClient3D() );
break;
case CC_CLIENTISKR:
sVal.FormatVal( GetNetState()->isClientKR() );
break;
case CC_CLIENTISENHANCED:
sVal.FormatVal( GetNetState()->isClientEnhanced() );
break;
case CC_CLIENTVERSION:
{
sVal = m_Crypt.GetClientVer().c_str();
}
break;
case CC_DEBUG:
sVal.FormatVal( IsPriv( PRIV_DEBUG ));
break;
case CC_DETAIL:
sVal.FormatVal( IsPriv( PRIV_DETAIL ));
break;
case CC_GM: // toggle your GM status on/off
sVal.FormatVal( IsPriv( PRIV_GM ));
break;
case CC_HEARALL:
sVal.FormatVal( IsPriv( PRIV_HEARALL ));
break;
case CC_LASTEVENT:
sVal.FormatLLVal( m_timeLastEvent );
break;
case CC_LASTEVENTWALK:
sVal.FormatLLVal( m_timeLastEventWalk );
break;
case CC_PRIVSHOW:
// Show my priv title.
sVal.FormatVal( ! IsPriv( PRIV_PRIV_NOSHOW ));
break;
case CC_REPORTEDCLIVER:
{
ptcKey += strlen(sm_szLoadKeys[index]);
GETNONWHITESPACE(ptcKey);
dword uiCliVer = GetNetState()->getReportedVersion();
if ( ptcKey[0] == '\0' )
{
// Return full version string (eg: 5.0.2d)
sVal = CUOClientVersion(uiCliVer).GetVersionString().c_str();
}
else
{
// Return raw version number (eg: 5.0.2d = 5000204)
sVal.FormatUVal(uiCliVer);
}
}
break;
case CC_SCREENSIZE:
{
if ( ptcKey[10] == '.' )
{
ptcKey += strlen(sm_szLoadKeys[index]);
SKIP_SEPARATORS(ptcKey);
if ( !strnicmp("X", ptcKey, 1) )
sVal.Format( "%u", m_ScreenSize.x );
else if ( !strnicmp("Y", ptcKey, 1) )
sVal.Format( "%u", m_ScreenSize.y );
else
return false;
}
else
sVal.Format( "%u,%u", m_ScreenSize.x, m_ScreenSize.y );
} break;
case CC_TARG:
sVal.FormatHex(m_Targ_UID);
break;
case CC_TARGP:
if ( ptcKey[5] == '.' )
{
return m_Targ_p.r_WriteVal( ptcKey+6, sVal );
}
sVal = m_Targ_p.WriteUsed();
break;
case CC_TARGPROP:
sVal.FormatHex(m_Prop_UID);
break;
case CC_TARGPRV:
sVal.FormatHex(m_Targ_Prv_UID);
break;
case CC_TARGTXT:
sVal = m_Targ_Text;
break;
default:
//Special case: if fNoCallParent = true, call CScriptObj::r_WriteVal with fNoCallChildren = true, to check only for the ref
return CScriptObj::r_WriteVal( ptcKey, sVal, pSrc, false, fNoCallParent );
}
return true;
EXC_CATCH;
EXC_DEBUG_START;
EXC_ADD_KEYRET(pSrc);
EXC_DEBUG_END;
return false;
}
bool CClient::r_LoadVal( CScript & s )
{
ADDTOCALLSTACK("CClient::r_LoadVal");
EXC_TRY("LoadVal");
if ( GetAccount() == nullptr )
return false;
lpctstr ptcKey = s.GetKey();
if (!strnicmp("CTAG", ptcKey, 4))
{
if ((ptcKey[4] == '.') || (ptcKey[4] == '0'))
{
const bool fZero = ptcKey[4] == '0';
ptcKey = ptcKey + (fZero ? 6 : 5);
bool fQuoted = false;
lpctstr ptcArg = s.GetArgStr(&fQuoted);
m_TagDefs.SetStr(ptcKey, fQuoted, ptcArg, fZero);
return true;
}
}
switch ( FindTableSorted(ptcKey, sm_szLoadKeys, ARRAY_COUNT(sm_szLoadKeys)-1 ))
{
case CC_ALLMOVE:
addRemoveAll(true, false);
GetAccount()->TogPrivFlags( PRIV_ALLMOVE, s.GetArgStr() );
if ( IsSetOF( OF_Command_Sysmsgs ) )
GetChar()->SysMessage( IsPriv(PRIV_ALLMOVE)? "Allmove ON" : "Allmove OFF" );
addPlayerView(CPointMap());
break;
case CC_ALLSHOW:
addRemoveAll(false, true);
GetAccount()->TogPrivFlags( PRIV_ALLSHOW, s.GetArgStr() );
if ( IsSetOF( OF_Command_Sysmsgs ) )
GetChar()->SysMessage( IsPriv(PRIV_ALLSHOW)? "Allshow ON" : "Allshow OFF" );
addPlayerView(CPointMap());
break;
case CC_DEBUG:
addRemoveAll(true, false);
GetAccount()->TogPrivFlags( PRIV_DEBUG, s.GetArgStr() );
if ( IsSetOF( OF_Command_Sysmsgs ) )
GetChar()->SysMessage( IsPriv(PRIV_DEBUG)? "Debug ON" : "Debug OFF" );
addPlayerView(CPointMap());
break;
case CC_DETAIL:
GetAccount()->TogPrivFlags( PRIV_DETAIL, s.GetArgStr() );
if ( IsSetOF( OF_Command_Sysmsgs ) )
GetChar()->SysMessage( IsPriv(PRIV_DETAIL)? "Detail ON" : "Detail OFF" );
break;
case CC_GM: // toggle your GM status on/off
if ( GetPrivLevel() >= PLEVEL_GM )
{
GetAccount()->TogPrivFlags( PRIV_GM, s.GetArgStr() );
GetChar()->UpdatePropertyFlag();
if ( IsSetOF( OF_Command_Sysmsgs ) )
GetChar()->SysMessage( IsPriv(PRIV_GM)? "GM ON" : "GM OFF" );
}
break;
case CC_HEARALL:
GetAccount()->TogPrivFlags( PRIV_HEARALL, s.GetArgStr() );
if ( IsSetOF( OF_Command_Sysmsgs ) )
GetChar()->SysMessage( IsPriv(PRIV_HEARALL)? "Hearall ON" : "Hearall OFF" );
break;
case CC_PRIVSHOW:
// Hide my priv title.
if ( GetPrivLevel() >= PLEVEL_Counsel )
{
if ( ! s.HasArgs())
GetAccount()->TogPrivFlags( PRIV_PRIV_NOSHOW, nullptr );
else if ( s.GetArgVal() )
GetAccount()->ClearPrivFlags( PRIV_PRIV_NOSHOW );
else
GetAccount()->SetPrivFlags( PRIV_PRIV_NOSHOW );
GetChar()->UpdatePropertyFlag();
if ( IsSetOF( OF_Command_Sysmsgs ) )
GetChar()->SysMessage( IsPriv(PRIV_PRIV_NOSHOW)? "Privshow OFF" : "Privshow ON" );
}
break;
case CC_TARG:
m_Targ_UID.SetObjUID(s.GetArgVal());
break;
case CC_TARGP:
m_Targ_p.Read( s.GetArgRaw());
if ( !m_Targ_p.IsValidPoint() )
{
m_Targ_p.ValidatePoint();
SysMessagef( "Invalid point: %s", s.GetArgStr() );
}
break;
case CC_TARGPROP:
m_Prop_UID.SetObjUID(s.GetArgVal());
break;
case CC_TARGPRV:
m_Targ_Prv_UID.SetObjUID(s.GetArgVal());
break;
default:
return false;
}
return true;
EXC_CATCH;
EXC_DEBUG_START;
EXC_ADD_SCRIPT;
EXC_DEBUG_END;
return false;
}
bool CClient::r_Verb( CScript & s, CTextConsole * pSrc ) // Execute command from script
{
ADDTOCALLSTACK("CClient::r_Verb");
ASSERT(pSrc);
// NOTE: This can be called directly from a RES_WEBPAGE script.
// So do not assume we are a game client !
// NOTE: Mostly called from CChar::r_Verb
// NOTE: Little security here so watch out for dangerous scripts !
EXC_TRY("Verb-Special");
lpctstr ptcKey = s.GetKey();
// Old ver
if ( s.IsKeyHead( "SET", 3 ) && ( g_Cfg.m_Functions.ContainsKey( ptcKey ) == false ) )
{
PLEVEL_TYPE ilevel = g_Cfg.GetPrivCommandLevel( "SET" );
if ( ilevel > GetPrivLevel() )
return false;
ASSERT( m_pChar );
addTargetVerb( ptcKey+3, s.GetArgRaw());
return true;
}
if ( toupper( ptcKey[0] ) == 'X' && ( g_Cfg.m_Functions.ContainsKey( ptcKey ) == false ) )
{
PLEVEL_TYPE ilevel = g_Cfg.GetPrivCommandLevel( "SET" );
if ( ilevel > GetPrivLevel() )
return false;
// Target this command verb on some other object.
ASSERT( m_pChar );
addTargetVerb( ptcKey+1, s.GetArgRaw());
return true;
}
EXC_SET_BLOCK("Verb-Statement");
int index = FindTableSorted( s.GetKey(), sm_szVerbKeys, ARRAY_COUNT(sm_szVerbKeys)-1 );
switch (index)
{
case CV_ADD:
if ( s.HasArgs())
{
tchar *ppszArgs[2];
size_t iQty = Str_ParseCmds(s.GetArgStr(), ppszArgs, ARRAY_COUNT(ppszArgs));
if ( !IsValidGameObjDef(ppszArgs[0]) )
{
//g_Log.EventWarn("Invalid ADD argument '%s'\n", pszArgs);
SysMessageDefault( DEFMSG_CMD_INVALID );
return true;
}
CResourceID rid = g_Cfg.ResourceGetID(RES_QTY, ppszArgs[0], 0, true);
/*
if (rid.IsEmpty())
{
m_tmAdd.m_id = 0;
return true;
}
*/
// A great number of scripts, other than 3rd party GM assistants, still use .add for items instead of .additem, so in case a bare ID
// is passed, it's wise to consider it as an item ID.
if (rid.IsEmpty())
{
#if _DEBUG
g_Log.EventDebug("Use .ADDITEM or .ADDCHAR instead of .ADD; it is being kept for backwards compatibility, but it's more prone to errors, as it always considers given IDs to be items.\n");
#endif
rid = g_Cfg.ResourceGetID(RES_ITEMDEF, ppszArgs[0], 0, false);
ASSERT(!rid.IsEmpty());
}
m_tmAdd.m_id = rid.GetResIndex();
m_tmAdd.m_vcAmount = (iQty > 1) ? std::max((word)1, (word)atoi(ppszArgs[1])) : 1;
if ( (rid.GetResType() == RES_CHARDEF) || (rid.GetResType() == RES_SPAWN) )
{
m_Targ_Prv_UID.InitUID();
return addTargetChars(CLIMODE_TARG_ADDCHAR, (CREID_TYPE)m_tmAdd.m_id, false);
}
else
{
return addTargetItems(CLIMODE_TARG_ADDITEM, (ITEMID_TYPE)m_tmAdd.m_id);
}
}
else
{
if ( IsValidResourceDef( "D_ADD" ) )
Dialog_Setup( CLIMODE_DIALOG, g_Cfg.ResourceGetIDType(RES_DIALOG, "D_ADD"), 0, this->GetChar() );
else
Menu_Setup( g_Cfg.ResourceGetIDType( RES_MENU, "MENU_ADDITEM"));
}
break;
case CV_ADDITEM:
if (!s.HasArgs())
{
SysMessageDefault(DEFMSG_CMD_INVALID);
return true;
}
{
tchar *ppszArgs[2];
size_t iQty = Str_ParseCmds(s.GetArgStr(), ppszArgs, ARRAY_COUNT(ppszArgs));
if (!IsValidGameObjDef(ppszArgs[0]))