Merge branch 'master' into Playerbot

This commit is contained in:
Yunfan Li
2024-08-12 01:07:20 +08:00
44 changed files with 433 additions and 305 deletions

View File

@@ -69,36 +69,62 @@ public:
static char* LineFromMessage(char*& pos) { char* start = strtok(pos, "\n"); pos = nullptr; return start; }
void SendNotification(std::string_view str);
template<typename... Args>
void SendNotification(uint32 strId, Args&&... args)
{
if (HasSession())
SendNotification(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
}
template<typename... Args>
void SendNotification(char const* fmt, Args&&... args)
{
if (HasSession())
SendNotification(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
}
void SendGMText(std::string_view str);
template<typename... Args>
void SendGMText(uint32 strId, Args&&... args)
{
// GMText should be sent to all sessions
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendGMText(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
});
}
template<typename... Args>
void SendGMText(char const* fmt, Args&&... args)
{
// GMText should be sent to all sessions
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendGMText(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
});
}
void SendWorldText(std::string_view str);
template<typename... Args>
void SendWorldText(uint32 strId, Args&&... args)
{
// WorldText should be sent to all sessions
SessionMap::const_iterator itr;
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
Player* player = itr->second->GetPlayer();
if (player && player->IsInWorld())
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendWorldText(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
}
}
});
}
template<typename... Args>
void SendWorldText(char const* fmt, Args&&... args)
{
// WorldTextOptional should be sent to all sessions
SessionMap::const_iterator itr;
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
Player* player = itr->second->GetPlayer();
if (player && player->IsInWorld())
// WorldText should be sent to all sessions
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendWorldText(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
}
}
});
}
void SendWorldTextOptional(std::string_view str, uint32 flag);
@@ -106,31 +132,21 @@ public:
void SendWorldTextOptional(uint32 strId, uint32 flag, Args&&... args)
{
// WorldTextOptional should be sent to all sessions
SessionMap::const_iterator itr;
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
Player* player = itr->second->GetPlayer();
if (player && player->IsInWorld())
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendWorldTextOptional(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...), flag);
}
}
});
}
template<typename... Args>
void SendWorldTextOptional(char const* fmt, uint32 flag, Args&&... args)
{
// WorldTextOptional should be sent to all sessions
SessionMap::const_iterator itr;
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
Player* player = itr->second->GetPlayer();
if (player && player->IsInWorld())
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendWorldTextOptional(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...), flag);
}
}
});
}
// function with different implementation for chat/console
@@ -143,13 +159,15 @@ public:
template<typename... Args>
void PSendSysMessage(char const* fmt, Args&&... args)
{
SendSysMessage(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
if (HasSession())
SendSysMessage(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
}
template<typename... Args>
void PSendSysMessage(uint32 entry, Args&&... args)
{
SendSysMessage(PGetParseString(entry, std::forward<Args>(args)...));
if (HasSession())
SendSysMessage(PGetParseString(entry, std::forward<Args>(args)...));
}
template<typename... Args>
@@ -198,6 +216,12 @@ public:
// Returns either the selected player or self if there is no selected player
Player* getSelectedPlayerOrSelf() const;
// Has different implementation for console
virtual bool HasSession() const;
// Do whatever you want to all the players with a valid session [including GameMasters], i.e.: param exec = [&](Player* p) { p->Whatever(); }
// A "valid" session requires player->IsInWorld() to be true
void DoForAllValidSessions(std::function<void(Player*)> exec);
char* extractKeyFromLink(char* text, char const* linkType, char** something1 = nullptr);
char* extractKeyFromLink(char* text, char const* const* linkTypes, int* found_idx, char** something1 = nullptr);
char* extractQuotedArg(char* args);
@@ -247,6 +271,9 @@ public:
LocaleConstant GetSessionDbcLocale() const override;
int GetSessionDbLocaleIndex() const override;
// CLI does not have a session, so we override it to always be true to output SendNotification and PSendSysMessage to console
bool HasSession() const override;
private:
void* m_callbackArg;
Print* m_print;