Skip to content
Permalink
Browse files

Fix #1174: accept team & table of players in outputChatBox (#1213)

* Accept table of players as visibleTo argument

* Use broadcast instead of for loop in outputChatBox

* Add ability to pass team element
  • Loading branch information
StrixG authored and qaisjp committed Jan 21, 2020
1 parent e8c7c16 commit d2c53c73e327ade55862043af9bd53da64dd351a
@@ -9828,6 +9828,17 @@ bool CStaticFunctionDefinitions::OutputChatBox(const char* szText, CElement* pEl
pPlayer->Send(CChatEchoPacket(szText, ucRed, ucGreen, ucBlue, bColorCoded));
return true;
}
else if (IS_TEAM(pElement))
{
CTeam* pTeam = static_cast<CTeam*>(pElement);
list<CPlayer*>::const_iterator iter = pTeam->PlayersBegin();
for (; iter != pTeam->PlayersEnd(); iter++)
{
CPlayer* pPlayer = *iter;
pPlayer->Send(CChatEchoPacket(szText, ucRed, ucGreen, ucBlue, bColorCoded));
}
return true;
}

if (pElement == m_pMapManager->GetRootElement())
{
@@ -9842,6 +9853,14 @@ bool CStaticFunctionDefinitions::OutputChatBox(const char* szText, CElement* pEl
return false;
}

void CStaticFunctionDefinitions::OutputChatBox(const char* szText, const std::vector<CPlayer*>& sendList, unsigned char ucRed, unsigned char ucGreen,
unsigned char ucBlue, bool bColorCoded)
{
assert(szText);

CPlayerManager::Broadcast(CChatEchoPacket(szText, ucRed, ucGreen, ucBlue, bColorCoded), sendList);
}

bool CStaticFunctionDefinitions::ClearChatBox(CElement* pElement)
{
assert(pElement);
@@ -546,6 +546,8 @@ class CStaticFunctionDefinitions
static bool SetMaxPlayers(unsigned int uiMax);
static bool OutputChatBox(const char* szText, CElement* pElement, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, bool bColorCoded,
CLuaMain* pLuaMain);
static void OutputChatBox(const char* szText, const std::vector<CPlayer*>& sendList, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue,
bool bColorCoded);
static bool OutputConsole(const char* szText, CElement* pElement);
static bool SetServerPassword(const SString& strPassword, bool bSave);
static bool ClearChatBox(CElement* pElement);
@@ -43,18 +43,27 @@ int CLuaFunctionDefs::SetMaxPlayers(lua_State* luaVM)

int CLuaFunctionDefs::OutputChatBox(lua_State* luaVM)
{
// bool outputChatBox ( string text [, element visibleTo=getRootElement(), int r=231, int g=217, int b=176, bool colorCoded=false ] )
SString ssChat;
CElement* pElement;
bool bColorCoded;
// bool outputChatBox ( string text [, element/table visibleTo=getRootElement(), int r=231, int g=217, int b=176, bool colorCoded=false ] )
SString ssChat;
std::vector<CPlayer*> sendList;
CElement* pElement = nullptr;
bool bColorCoded;
// Default
unsigned char ucRed = 231;
unsigned char ucGreen = 217;
unsigned char ucBlue = 176;

CScriptArgReader argStream(luaVM);
argStream.ReadString(ssChat);
argStream.ReadUserData(pElement, m_pRootElement);

if (argStream.NextIsTable())
{
argStream.ReadUserDataTable(sendList);
}
else
{
argStream.ReadUserData(pElement, m_pRootElement);
}

if (argStream.NextIsNumber() && argStream.NextIsNumber(1) && argStream.NextIsNumber(2))
{
@@ -72,9 +81,18 @@ int CLuaFunctionDefs::OutputChatBox(lua_State* luaVM)
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM);
if (pLuaMain)
{
CStaticFunctionDefinitions::OutputChatBox((const char*)ssChat, pElement, ucRed, ucGreen, ucBlue, bColorCoded, pLuaMain);
lua_pushboolean(luaVM, true);
return 1;
if (pElement)
{
CStaticFunctionDefinitions::OutputChatBox((const char*)ssChat, pElement, ucRed, ucGreen, ucBlue, bColorCoded, pLuaMain);
lua_pushboolean(luaVM, true);
return 1;
}
else if (sendList.size() > 0)
{
CStaticFunctionDefinitions::OutputChatBox((const char*)ssChat, sendList, ucRed, ucGreen, ucBlue, bColorCoded);
lua_pushboolean(luaVM, true);
return 1;
}
}
}
else
@@ -733,7 +751,7 @@ int CLuaFunctionDefs::GetRemoteRequests(lua_State* luaVM)
if (pResource)
pLuaMain = pResource->GetVirtualMachine();

if(!argStream.HasErrors())
if (!argStream.HasErrors())
{
lua_newtable(luaVM);

0 comments on commit d2c53c7

Please sign in to comment.
You can’t perform that action at this time.