Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion dll/game/LobbyInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,16 @@ class LobbyInfo {
}

void registerSlot(struct PlayerSlot* slot) {
if (!slot) {
debug("registerSlot: slot is NULL\r\n");
return;
}
std::lock_guard<std::mutex> l(player_slot_mutex);
int slot_number = slot->slotNumber;
if (slot_number < 0 || slot_number >= MAX_SLOT_NUMBERS) {
debug((char*)("registerSlot: invalid slot_number " + std::to_string(slot_number) + "\r\n").c_str());
return;
}
if (playerSlots[slot_number] == slot) {
return;
}
Expand All @@ -131,17 +139,28 @@ class LobbyInfo {

struct PlayerSlot* getPlayerSlot(int slot_number) {
std::lock_guard<std::mutex> l(player_slot_mutex);
if (slot_number < 0 || slot_number >= MAX_SLOT_NUMBERS) {
debug((char*)("getPlayerSlot: invalid slot_number " + std::to_string(slot_number) + "\r\n").c_str());
return NULL;
}
return this->playerSlots[slot_number];
}

std::string getSlotNickname(int slot_number) {
// @todo invalid argument exception
std::lock_guard<std::mutex> l(player_slot_mutex);
if (slot_number < 0 || slot_number >= MAX_SLOT_NUMBERS) {
debug((char*)("getSlotNickname: invalid slot_number " + std::to_string(slot_number) + "\r\n").c_str());
return "";
}
return this->slotNicknames[slot_number];
}

void setSlotNickname(int slot_number, std::string nickname) {
std::lock_guard<std::mutex> l(player_slot_mutex);
if (slot_number < 0 || slot_number >= MAX_SLOT_NUMBERS) {
debug((char*)("setSlotNickname: invalid slot_number " + std::to_string(slot_number) + "\r\n").c_str());
return;
}
this->slotNicknames[slot_number] = nickname;
}

Expand Down
19 changes: 14 additions & 5 deletions dll/game/PlayerInfo/LagabuseDotaPlayerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ class LagabuseDotaPlayerInfo : public PlayerInfo {
LagabuseDotaPlayerInfo& operator=(LagabuseDotaPlayerInfo const&) = delete; // disable copy-assignment constructor

virtual void applyJsonData(nlohmann::basic_json<std::map> json) override {
this->rating = json["rating"];
this->wins = json["wins"];
this->loses = json["loses"];
this->gamesCount = this->wins + this->loses;
this->rank = json["rank"];
try {
this->rating = json.value("rating", 0UL);
this->wins = json.value("wins", 0UL);
this->loses = json.value("loses", 0UL);
this->gamesCount = this->wins + this->loses;
this->rank = json.value("rank", 0UL);
} catch (const nlohmann::json::exception& e) {
debug((char*)("JSON parse error in applyJsonData: " + std::string(e.what()) + "\r\n").c_str());
this->rating = 0;
this->wins = 0;
this->loses = 0;
this->gamesCount = 0;
this->rank = 0;
}
}

virtual std::string compileNameString() override {
Expand Down
15 changes: 11 additions & 4 deletions dll/game/PlayerInfoUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,17 @@ class PlayerInfoUpdater {
debug((char*)querystring.c_str());
debug("\r\n");
if (res) {
auto player_info_list = json::parse(res->body);
for (json::iterator it = player_info_list.begin(); it != player_info_list.end(); ++it) {
std::string nickname = (*it)["name"];
player_info_mapped[nickname] = *it;
try {
auto player_info_list = json::parse(res->body);
for (json::iterator it = player_info_list.begin(); it != player_info_list.end(); ++it) {
std::string nickname = (*it).value("name", "");
if (!nickname.empty()) {
player_info_mapped[nickname] = *it;
}
}
} catch (const nlohmann::json::exception& e) {
debug((char*)("JSON parse error in fetchPlayersInfo: " + std::string(e.what()) + "\r\n").c_str());
should_reschedule = true;
}
}
else {
Expand Down
10 changes: 9 additions & 1 deletion dll/game/hook-handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ __declspec(dllexport) void __stdcall onAfterSlotInit(struct PlayerSlot* slot) {
}

__declspec(dllexport) void __stdcall onSlotChange(struct PlayerSlot* slot, char* nickname) {
if (!slot) {
return;
}
std::string str_nickname;
if (nickname) {
str_nickname = nickname;
Expand Down Expand Up @@ -136,9 +139,14 @@ __declspec(dllexport) int __stdcall isDefaultUpdatingTeamTextDisabled() {
}

__declspec(dllexport) void __stdcall afterSlotTextsUpdate(struct PlayerSlot* slot) {
if (!slot) {
return;
}
int slotNumber = slot->slotNumber;
std::string nickname = lobby_info->getSlotNickname(slotNumber);
lobby_info->getPlayerInfo(nickname)->applyToPlayerSlot(slot);
if (!nickname.empty()) {
lobby_info->getPlayerInfo(nickname)->applyToPlayerSlot(slot);
}
}

__declspec(dllexport) void init_hook_handlers() {
Expand Down
32 changes: 28 additions & 4 deletions dll/game/player-slot-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ extern "C" {

// PlayerName
LPVOID getPlayerNameTextFrame(struct PlayerSlot* slot) {
if (!slot || !slot->playerName || !slot->playerName->comboBox) {
return NULL;
}
return slot->playerName->comboBox->firstTextFrame;
}

Expand All @@ -15,11 +18,17 @@ void initPlayerNameFont(struct PlayerSlot* slot, const char* fontPath, float fon
}

void setPlayerNameText(struct PlayerSlot* slot, const char* text) {
textFrameSetText(getPlayerNameTextFrame(slot), text);
LPVOID textFrame = getPlayerNameTextFrame(slot);
if (textFrame) {
textFrameSetText(textFrame, text);
}
}

// PlayerRace
LPVOID getPlayerRaceTextFrame(struct PlayerSlot* slot) {
if (!slot || !slot->playerRace || !slot->playerRace->comboBox) {
return NULL;
}
return slot->playerRace->comboBox->firstTextFrame;
}

Expand All @@ -28,11 +37,17 @@ void initPlayerRaceFont(struct PlayerSlot* slot, const char* fontPath, float fon
}

void setPlayerRaceText(struct PlayerSlot* slot, const char* text) {
textFrameSetText(getPlayerRaceTextFrame(slot), text);
LPVOID textFrame = getPlayerRaceTextFrame(slot);
if (textFrame) {
textFrameSetText(textFrame, text);
}
}

// PlayerTeam
LPVOID getPlayerTeamTextFrame(struct PlayerSlot* slot) {
if (!slot || !slot->teamButtonTitle) {
return NULL;
}
return slot->teamButtonTitle;
}

Expand All @@ -41,11 +56,17 @@ void initPlayerTeamFont(struct PlayerSlot* slot, const char* fontPath, float fon
}

void setPlayerTeamText(struct PlayerSlot* slot, const char* text) {
textFrameSetText(getPlayerTeamTextFrame(slot), text);
LPVOID textFrame = getPlayerTeamTextFrame(slot);
if (textFrame) {
textFrameSetText(textFrame, text);
}
}

// PlayerHandicap
LPVOID getPlayerHandicapTextFrame(struct PlayerSlot* slot) {
if (!slot || !slot->playerHandicap || !slot->playerHandicap->comboBox) {
return NULL;
}
return slot->playerHandicap->comboBox->firstTextFrame;
}

Expand All @@ -54,7 +75,10 @@ void initPlayerHandicapFont(struct PlayerSlot* slot, const char* fontPath, float
}

void setHandicapText(struct PlayerSlot* slot, const char* text) {
textFrameSetText(getPlayerHandicapTextFrame(slot), text);
LPVOID textFrame = getPlayerHandicapTextFrame(slot);
if (textFrame) {
textFrameSetText(textFrame, text);
}
}

#ifdef __cplusplus
Expand Down