Skip to content

Commit 75011d4

Browse files
committed
* Protect gold, bank gold, loyalty, and manner changes with CurrencyChange
* Remove StripEvtComment to handle using string_views instead
1 parent c8a8be8 commit 75011d4

File tree

8 files changed

+77
-92
lines changed

8 files changed

+77
-92
lines changed

src/Server/Ebenezer/AISocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ void CAISocket::RecvUserExp(char* pBuf)
11291129
return;
11301130
}
11311131

1132-
pUser->m_pUserData->m_iLoyalty += sLoyalty;
1132+
CurrencyChange(pUser->m_pUserData->m_iLoyalty, sLoyalty);
11331133
pUser->ExpChange(sExp);
11341134

11351135
if (sLoyalty > 0)

src/Server/Ebenezer/EXEC.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ bool EXEC::Parse(const char* line, const std::string& filename, int lineNumber)
2222
bool handled = true;
2323
char temp[1024] {};
2424

25-
std::string commentStripped = StripEvtComment(line);
26-
ParseSpace(temp, commentStripped.c_str(), index);
27-
28-
size_t opcode = hashing::djb2::hash(std::string_view(temp));
25+
ParseSpace(temp, line, index);
26+
std::string_view tempView(temp);
27+
size_t commentPosition = tempView.find(';');
28+
size_t opcode;
29+
if (commentPosition != std::string::npos)
30+
opcode = hashing::djb2::hash(tempView.substr(0, commentPosition));
31+
else
32+
opcode = hashing::djb2::hash(tempView);
2933
switch (opcode)
3034
{
3135
// E SAY {'up' event ID} {'ok' event ID} {talk ID 1} {talk ID 2} {talk ID 3} {talk ID 4} {talk ID 5} {talk ID 6} {talk ID 7} {talk ID 8}

src/Server/Ebenezer/EbenezerApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ void EbenezerApp::BattleZoneVictoryCheck()
25142514
if (pTUser->m_pUserData->m_bNation == m_bVictory
25152515
// Zone Check!
25162516
&& pTUser->m_pUserData->m_bZone == pTUser->m_pUserData->m_bNation)
2517-
pTUser->m_pUserData->m_iGold += AWARD_GOLD; // Target is in the area.
2517+
CurrencyChange(pTUser->m_pUserData->m_iGold, AWARD_GOLD); // Target is in the area.
25182518
}
25192519
}
25202520

src/Server/Ebenezer/KnightsManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,9 @@ void CKnightsManager::ReceiveKnightsProcess(CUser* pUser, const char* pBuf, uint
896896

897897
void CKnightsManager::RecvCreateKnights(CUser* pUser, const char* pBuf)
898898
{
899+
static constexpr uint32_t CLAN_CREATE_COST = 500'000;
899900
int index = 0, sendIndex = 0, namelen = 0, idlen = 0, knightsindex = 0, nation = 0,
900-
community = 0, money = 0;
901+
community = 0;
901902
CKnights* pKnights = nullptr;
902903
char sendBuffer[128] {}, knightsname[MAX_ID_SIZE + 1] {}, chiefname[MAX_ID_SIZE + 1] {};
903904

@@ -931,8 +932,7 @@ void CKnightsManager::RecvCreateKnights(CUser* pUser, const char* pBuf)
931932

932933
pUser->m_pUserData->m_bKnights = knightsindex;
933934
pUser->m_pUserData->m_bFame = KNIGHTS_DUTY_CHIEF;
934-
money = pUser->m_pUserData->m_iGold - 500000;
935-
pUser->m_pUserData->m_iGold = money;
935+
CurrencyChange(pUser->m_pUserData->m_iGold, -CLAN_CREATE_COST);
936936

937937
for (int i = 0; i < MAX_CLAN; i++)
938938
{
@@ -968,7 +968,7 @@ void CKnightsManager::RecvCreateKnights(CUser* pUser, const char* pBuf)
968968
SetString(sendBuffer, knightsname, namelen, sendIndex);
969969
SetByte(sendBuffer, 5, sendIndex); // knights grade
970970
SetByte(sendBuffer, 0, sendIndex);
971-
SetDWORD(sendBuffer, money, sendIndex);
971+
SetDWORD(sendBuffer, pUser->m_pUserData->m_iGold, sendIndex);
972972
m_pMain->Send_Region(sendBuffer, sendIndex, pUser->m_pUserData->m_bZone, pUser->m_RegionX,
973973
pUser->m_RegionZ, nullptr, false);
974974
//pUser->Send( sendBuffer, sendIndex );

src/Server/Ebenezer/LOGIC_ELSE.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ bool LOGIC_ELSE::Parse_and(const char* line, const std::string& filename, int li
3434
bool handled = true;
3535
char temp[1024] {};
3636

37-
std::string commentStripped = StripEvtComment(line);
38-
ParseSpace(temp, commentStripped.c_str(), index);
39-
40-
size_t opcode = hashing::djb2::hash(std::string_view(temp));
37+
ParseSpace(temp, line, index);
38+
std::string_view tempView(temp);
39+
size_t commentPosition = tempView.find(';');
40+
size_t opcode;
41+
if (commentPosition != std::string::npos)
42+
opcode = hashing::djb2::hash(tempView.substr(0, commentPosition));
43+
else
44+
opcode = hashing::djb2::hash(tempView);
4145
switch (opcode)
4246
{
4347
// A CHECK_UNDER_WEIGHT

0 commit comments

Comments
 (0)