Skip to content

Commit 4ba63eb

Browse files
authored
Merge branch 'multitheftauto:master' into fix/client-side-entity
2 parents 5929998 + 04b8ee6 commit 4ba63eb

File tree

13 files changed

+132
-421
lines changed

13 files changed

+132
-421
lines changed

Client/mods/deathmatch/logic/CMapEventManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool CMapEventManager::Call(const char* szName, const CLuaArguments& Arguments,
222222
lua_pushresource(pState, pSourceResource);
223223
lua_setglobal(pState, "sourceResource");
224224

225-
lua_pushelement(pState, pSourceResource->GetResourceDynamicEntity());
225+
lua_pushelement(pState, pSourceResource->GetResourceEntity());
226226
lua_setglobal(pState, "sourceResourceRoot");
227227
}
228228
else
@@ -400,4 +400,4 @@ void CMapEventManager::GetHandles(CLuaMain* pLuaMain, const char* szName, lua_St
400400
}
401401
}
402402
}
403-
}
403+
}

Client/mods/deathmatch/logic/CPacketHandler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,8 @@ void CPacketHandler::Packet_ChatEcho(NetBitStreamInterface& bitStream)
14121412
bitStream.Read(szMessage, iNumberOfBytesUsed);
14131413
szMessage[iNumberOfBytesUsed] = 0;
14141414
// actual limits enforced on the remote client, this is the maximum a string can be to be printed.
1415-
if (MbUTF8ToUTF16(szMessage).size() <=
1415+
SString textToProcess = bColorCoded ? RemoveColorCodes(szMessage) : szMessage;
1416+
if (MbUTF8ToUTF16(textToProcess).size() <=
14161417
MAX_CHATECHO_LENGTH + 6) // Extra 6 characters to fix #7125 (Teamsay + long name + long message = too long message)
14171418
{
14181419
// Strip it for bad characters

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,27 @@ bool CStaticFunctionDefinitions::ClearChatBox()
260260

261261
bool CStaticFunctionDefinitions::OutputChatBox(const char* szText, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, bool bColorCoded)
262262
{
263-
if (strlen(szText) <= MAX_OUTPUTCHATBOX_LENGTH)
264-
{
265-
CLuaArguments Arguments;
266-
Arguments.PushString(szText);
267-
Arguments.PushNumber(ucRed);
268-
Arguments.PushNumber(ucGreen);
269-
Arguments.PushNumber(ucBlue);
263+
if (!szText || szText[0] == '\0')
264+
return false;
265+
266+
SString textToProcess = bColorCoded ? RemoveColorCodes(szText) : szText;
267+
268+
if (textToProcess.length() > MAX_OUTPUTCHATBOX_LENGTH) {
269+
return false;
270+
}
270271

271-
bool bCancelled = !g_pClientGame->GetRootEntity()->CallEvent("onClientChatMessage", Arguments, false);
272-
if (!bCancelled)
273-
{
274-
m_pCore->ChatPrintfColor("%s", bColorCoded, ucRed, ucGreen, ucBlue, szText);
275-
return true;
276-
}
272+
CLuaArguments Arguments;
273+
Arguments.PushString(szText);
274+
Arguments.PushNumber(ucRed);
275+
Arguments.PushNumber(ucGreen);
276+
Arguments.PushNumber(ucBlue);
277+
278+
bool bCancelled = !g_pClientGame->GetRootEntity()->CallEvent("onClientChatMessage", Arguments, false);
279+
if (!bCancelled) {
280+
m_pCore->ChatPrintfColor("%s", bColorCoded, ucRed, ucGreen, ucBlue, szText);
281+
return true;
277282
}
283+
278284
return false;
279285
}
280286

Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "CHTTPD.h"
2323
#include "CStaticFunctionDefinitions.h"
2424

25-
#define MTA_SERVER_CONF_TEMPLATE "mtaserver.conf.template"
25+
#define SETTINGS_TEMPLATE_PATH "mtaserver.conf.template"
2626

2727
extern CGame* g_pGame;
2828

@@ -864,91 +864,90 @@ bool CMainConfig::AddMissingSettings()
864864
if (!g_pGame->IsUsingMtaServerConf())
865865
return false;
866866

867-
const SString templateFileName = PathJoin(g_pServerInterface->GetServerModPath(), "mtaserver.conf.template");
868-
867+
const std::string templateFileName = PathJoin(g_pServerInterface->GetServerModPath(), SETTINGS_TEMPLATE_PATH);
869868
if (!FileExists(templateFileName))
870869
return false;
871870

872-
CXMLFile* templateFile = g_pServerInterface->GetXML()->CreateXML(templateFileName);
873-
CXMLNode* templateRootNode = templateFile && templateFile->Parse() ? templateFile->GetRootNode() : nullptr;
871+
std::unique_ptr<CXMLFile> templateFile(g_pServerInterface->GetXML()->CreateXML(templateFileName.c_str()));
872+
if (!templateFile || !templateFile->Parse())
873+
{
874+
CLogger::ErrorPrintf("Failed to parse template file: '%s'\n", templateFileName.c_str());
875+
return false;
876+
}
877+
878+
CXMLNode* templateRootNode = templateFile->GetRootNode();
874879
if (!templateRootNode)
875880
{
876-
CLogger::ErrorPrintf("Can't parse '%s'\n", *templateFileName);
881+
CLogger::ErrorPrintf("Template file '%s' has no root node\n", templateFileName.c_str());
877882
return false;
878883
}
879884

880885
// Check that each item in the template also exists in the server config
881-
bool hasConfigChanged = false;
886+
bool configChanged = false;
882887
CXMLNode* previousNode = nullptr;
888+
883889
for (auto it = templateRootNode->ChildrenBegin(); it != templateRootNode->ChildrenEnd(); ++it)
884890
{
885891
CXMLNode* templateNode = *it;
886-
SString templateNodeTagName = templateNode->GetTagName();
892+
const std::string& templateNodeName = templateNode->GetTagName();
887893

894+
// Skip certain optional nodes
895+
if (templateNodeName == "resource" || templateNodeName == "module")
896+
continue;
897+
888898
// Find node with exact same attributes
889899
CXMLAttributes& templateAttributes = templateNode->GetAttributes();
890900
CXMLNode* foundNode = nullptr;
891901
for (auto it2 = m_pRootNode->ChildrenBegin(); it2 != m_pRootNode->ChildrenEnd(); ++it2)
892902
{
893903
CXMLNode* tempNode = *it2;
894-
if (tempNode->GetTagName() != templateNodeTagName)
895-
{
904+
if (tempNode->GetTagName() != templateNodeName)
896905
continue;
897-
}
906+
898907
CXMLAttributes& attributes = tempNode->GetAttributes();
899-
bool attributesMatch = true;
900-
908+
bool attributesMatch = true;
909+
901910
for (auto it3 = templateAttributes.ListBegin(); it3 != templateAttributes.ListEnd(); ++it3)
902911
{
903912
CXMLAttribute* templateAttribute = *it3;
904-
const SString& strKey = templateAttribute->GetName();
905-
const SString& strValue = templateAttribute->GetValue();
906-
907-
CXMLAttribute* foundAttribute = attributes.Find(strKey);
908-
if (!foundAttribute || foundAttribute->GetValue() != strValue)
913+
const SString& attrName = templateAttribute->GetName();
914+
915+
// Don't check value attribute which is intended to be different
916+
if (attrName == "value")
917+
continue;
918+
919+
const SString& attrValue = templateAttribute->GetValue();
920+
921+
CXMLAttribute* foundAttribute = attributes.Find(attrName);
922+
if (!foundAttribute || foundAttribute->GetValue() != attrValue)
909923
{
910924
attributesMatch = false;
911925
break;
912926
}
913927
}
914-
928+
915929
if (attributesMatch)
916930
{
917931
foundNode = tempNode;
918932
break;
919933
}
920934
}
921-
// Create missing node if not found
935+
922936
if (!foundNode)
923937
{
924-
CLogger::LogPrintf("Adding missing '%s' to mtaserver.conf\n", *templateNodeTagName);
925-
SString value = templateNode->GetTagContent();
926-
SString commentText = templateNode->GetCommentText();
927-
foundNode = m_pRootNode->CreateSubNode(templateNodeTagName, previousNode);
928-
foundNode->SetTagContent(value);
929-
foundNode->SetCommentText(commentText, true);
930-
931-
// Copy attributes from template node
932-
CXMLAttributes& templateAttributes = templateNode->GetAttributes();
933-
for (auto it = templateAttributes.ListBegin(); it != templateAttributes.ListEnd(); ++it)
934-
{
935-
CXMLAttribute* templateAttribute = *it;
936-
const SString& attributeName = templateAttribute->GetName();
937-
const SString& attributeValue = templateAttribute->GetValue();
938+
const std::string templateNodeValue = templateNode->GetTagContent();
939+
const SString templateNodeComment = templateNode->GetCommentText();
938940

939-
CXMLAttribute* newAttribute = foundNode->GetAttributes().Create(attributeName);
940-
if (newAttribute)
941-
newAttribute->SetValue(attributeValue);
942-
}
943-
hasConfigChanged = true;
941+
foundNode = m_pRootNode->CreateSubNode(templateNodeName.c_str(), previousNode);
942+
foundNode->SetTagContent(templateNodeValue.c_str());
943+
foundNode->SetCommentText(templateNodeComment.c_str(), true);
944+
945+
CLogger::LogPrintf("Added missing '%s' setting to mtaserver.conf\n", templateNodeName.c_str());
946+
configChanged = true;
944947
}
945948
previousNode = foundNode;
946949
}
947-
948-
// Clean up
949-
g_pServerInterface->GetXML()->DeleteXML(templateFile);
950-
FileDelete(templateFileName);
951-
return hasConfigChanged;
950+
return configChanged;
952951
}
953952

954953
bool CMainConfig::IsValidPassword(const char* szPassword)

0 commit comments

Comments
 (0)