Skip to content

Commit

Permalink
Allow HK_GET_CLIENTID to continue processing if the player is not o…
Browse files Browse the repository at this point in the history
…nline. (TheStarport#28)

* Allow `HK_GET_CLIENTID` to continue processing if the player is not online.

`HK_GET_CLIENTID` would force the calling function to return early if the error was `HKE_PLAYER_NOT_LOGGED_IN`, which limits the usefulness of commands such as ban/unban. This change allows processing to continue with the first argument set to -1.

* Avoid changing `HK_GET_CLIENTID` to avoid bugs.
  • Loading branch information
dwmunster authored Jan 7, 2021
1 parent 86a74d6 commit f9dc491
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/HkFuncPlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ HK_ERROR HkGetCash(const std::wstring &wscCharname, int &iCash) {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

HK_ERROR HkAddCash(const std::wstring &wscCharname, int iAmount) {
HK_GET_CLIENTID(iClientID, wscCharname);
HK_GET_CLIENTID_OR_LOGGED_OUT(iClientID, wscCharname);

uint iClientIDAcc = 0;
if (iClientID == -1) {
Expand Down Expand Up @@ -160,7 +160,7 @@ HK_ERROR HkKickReason(const std::wstring &wscCharname,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

HK_ERROR HkBan(const std::wstring &wscCharname, bool bBan) {
HK_GET_CLIENTID(iClientID, wscCharname);
HK_GET_CLIENTID_OR_LOGGED_OUT(iClientID, wscCharname);

CAccount *acc;
if (iClientID != -1)
Expand Down Expand Up @@ -456,7 +456,7 @@ HK_ERROR HkAddCargo(const std::wstring &wscCharname,

HK_ERROR HkRename(const std::wstring &wscCharname,
const std::wstring &wscNewCharname, bool bOnlyDelete) {
HK_GET_CLIENTID(iClientID, wscCharname);
HK_GET_CLIENTID_OR_LOGGED_OUT(iClientID, wscCharname);

if ((iClientID == -1) && !HkGetAccountByCharname(wscCharname))
return HKE_CHAR_DOES_NOT_EXIST;
Expand Down
6 changes: 6 additions & 0 deletions source/Hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,4 +921,10 @@ extern EXPORT HK_ERROR HkGetClientID(bool &bIdString, uint &iClientID,
bool bIdString = false; \
uint a = uint(-1); \
if (auto err = HkGetClientID(bIdString, a, b); err != HKE_OK) \
return err;

#define HK_GET_CLIENTID_OR_LOGGED_OUT(a,b) \
bool bIdString = false; \
uint a = uint(-1); \
if (auto err = HkGetClientID(bIdString, a, b); err != HKE_OK && err != HKE_PLAYER_NOT_LOGGED_IN) \
return err;

0 comments on commit f9dc491

Please sign in to comment.