Skip to content

Commit

Permalink
Update Lua and fix crash when resource stops with open sockets (by ccw)
Browse files Browse the repository at this point in the history
  • Loading branch information
Necktrox committed Feb 20, 2017
1 parent 152d2a3 commit 5317855
Show file tree
Hide file tree
Showing 28 changed files with 63 additions and 27 deletions.
Binary file modified libs/x32/lua5.1.a
Binary file not shown.
Binary file modified libs/x32/lua5.1.lib
Binary file not shown.
Binary file modified libs/x32/lua5.1.pdb
Binary file not shown.
Binary file modified libs/x32/lua5.1_d.a
Binary file not shown.
Binary file modified libs/x32/lua5.1_d.lib
Binary file not shown.
Binary file modified libs/x32/lua5.1_d.pdb
Binary file not shown.
Binary file modified libs/x64/lua5.1.a
Binary file not shown.
Binary file modified libs/x64/lua5.1.lib
Binary file not shown.
Binary file modified libs/x64/lua5.1.pdb
Binary file not shown.
Binary file modified libs/x64/lua5.1_d.a
Binary file not shown.
Binary file modified libs/x64/lua5.1_d.lib
Binary file not shown.
Binary file modified libs/x64/lua5.1_d.pdb
Binary file not shown.
4 changes: 2 additions & 2 deletions modules/sockets/include/CFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright 2003-2008 MTA. All Rights Reserved.
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is 2002-2003 Rockstar North
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand Down
4 changes: 2 additions & 2 deletions modules/sockets/include/CLuaArgument.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright 2003-2008 MTA. All Rights Reserved.
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is 2002-2003 Rockstar North
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand Down
4 changes: 2 additions & 2 deletions modules/sockets/include/CLuaArguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright 2003-2008 MTA. All Rights Reserved.
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is 2002-2003 Rockstar North
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand Down
3 changes: 2 additions & 1 deletion modules/sockets/include/CSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ class CSocket
CSocket (lua_State *luaVM, const string& strHost, const unsigned short& usPort);
~CSocket (); // Delete only - Does not trigger any events

void CloseSocketWithEvent (); // Close socket and trigger event
void CloseSocketWithEvent (bool bTriggerCloseEvent); // Close socket and optionally trigger event
bool Send (const string& data);
bool DoPulse ();
bool IsConnected ();

void* GetUserdata ();
lua_State* GetLuaVM() { return m_pLuaVM; }
static int GetTotalOpenSocketCount ();

private:
Expand Down
6 changes: 4 additions & 2 deletions modules/sockets/include/CSocketManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ class CSocketManager
{
public:
static void DoPulse();

static void ResourceStopped( lua_State * luaVM );

static void SocketAdd (CSocket*& pSocket);
static void SocketRemove(CSocket*& pSocket);
static void SocketRemove(CSocket*& pSocket, bool bTriggerCloseEvent=true);
static bool GetSocket (CSocket*& pSocket, void* pUserdata);
static bool GetSocketByLuaVM(CSocket*& pSocket, lua_State * luaVM);

static void HandleStop ();
};
4 changes: 2 additions & 2 deletions modules/sockets/include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright 2003-2008 MTA. All Rights Reserved.
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is 2002-2003 Rockstar North
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand Down
4 changes: 2 additions & 2 deletions modules/sockets/include/ml_sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright 2003-2008 MTA. All Rights Reserved.
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is 2002-2003 Rockstar North
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand Down
4 changes: 2 additions & 2 deletions modules/sockets/src/CFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright © 2003-2008 MTA. All Rights Reserved.
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is © 2002-2003 Rockstar North
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand Down
4 changes: 2 additions & 2 deletions modules/sockets/src/CLuaArgument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright © 2003-2008 MTA. All Rights Reserved.
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is © 2002-2003 Rockstar North
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand Down
4 changes: 2 additions & 2 deletions modules/sockets/src/CLuaArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright © 2003-2008 MTA. All Rights Reserved.
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is © 2002-2003 Rockstar North
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand Down
5 changes: 3 additions & 2 deletions modules/sockets/src/CSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ CSocket::~CSocket()
}
}

void CSocket::CloseSocketWithEvent()
void CSocket::CloseSocketWithEvent(bool bTriggerCloseEvent)
{
// Close the socket, if it exists, and trigger the closed event
if (m_pSocket != ERR_INVALID_SOCKET)
{
CloseSocket();
TriggerEvent("onSockClosed");
if ( bTriggerCloseEvent )
TriggerEvent("onSockClosed");
}
}

Expand Down
34 changes: 32 additions & 2 deletions modules/sockets/src/CSocketManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,29 @@ void CSocketManager::DoPulse()
}
}


void CSocketManager::ResourceStopped( lua_State * luaVM )
{
// Enusure all sockets using luaVM are closed
CSocket* pSocket;
while( GetSocketByLuaVM( pSocket, luaVM ) )
{
SocketRemove( pSocket, false );
}
}


void CSocketManager::SocketAdd(CSocket*& pSocket)
{
// Add the socket to the loop stuff
vecSockets.push_back(pSocket);
}

void CSocketManager::SocketRemove(CSocket*& pSocket)
void CSocketManager::SocketRemove(CSocket*& pSocket, bool bTriggerCloseEvent)
{
ListRemove(vecSockets, pSocket);
ListRemove(processQueue, pSocket);
pSocket->CloseSocketWithEvent();
pSocket->CloseSocketWithEvent(bTriggerCloseEvent);
ListRemove(deleteList, pSocket);
deleteList.push_back(pSocket);
}
Expand All @@ -75,6 +87,24 @@ bool CSocketManager::GetSocket(CSocket*& pSocket, void* pUserdata)
return false;
}


bool CSocketManager::GetSocketByLuaVM(CSocket*& pSocket, lua_State * luaVM)
{
// Loop through all sockets
for (unsigned int i = 0; i < vecSockets.size(); ++i)
{
// Compare the current socket's luaVM with the one we're looking for
if (vecSockets[i]->GetLuaVM() == luaVM)
{
// If it's the one we want, assign pSocket to it and return true
pSocket = vecSockets[i];
return true;
}
}

return false;
}

void CSocketManager::HandleStop()
{
// Triggered at module stop. Simply destroys all sockets
Expand Down
4 changes: 2 additions & 2 deletions modules/sockets/src/ml_sockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright © 2003-2008 MTA. All Rights Reserved.
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is © 2002-2003 Rockstar North
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand Down
6 changes: 4 additions & 2 deletions premake5.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

-- Create helper function for output
binpath = function (path) targetdir("%{wks.location}../bin/".. path) end
cwd = os.getcwd()
binpath = function (path) targetdir(os.realpath(("%s/bin/%s"):format(cwd, path))) end

workspace "MTA Modules"

Expand All @@ -27,7 +28,8 @@ workspace "MTA Modules"

filter "configurations:Debug"
defines { "DEBUG" }
flags { "C++14", "Symbols" }
flags { "C++14" }
symbols "On"
targetsuffix "_d"

filter "configurations:Release"
Expand Down
Binary file modified utils/premake5
Binary file not shown.
Binary file modified utils/premake5.exe
Binary file not shown.

0 comments on commit 5317855

Please sign in to comment.