Skip to content

Commit 5317855

Browse files
author
Necktrox
committed
Update Lua and fix crash when resource stops with open sockets (by ccw)
1 parent 152d2a3 commit 5317855

28 files changed

+63
-27
lines changed

libs/x32/lua5.1.a

487 KB
Binary file not shown.

libs/x32/lua5.1.lib

214 Bytes
Binary file not shown.

libs/x32/lua5.1.pdb

3.82 MB
Binary file not shown.

libs/x32/lua5.1_d.a

-29.9 KB
Binary file not shown.

libs/x32/lua5.1_d.lib

216 Bytes
Binary file not shown.

libs/x32/lua5.1_d.pdb

6.13 MB
Binary file not shown.

libs/x64/lua5.1.a

1.12 MB
Binary file not shown.

libs/x64/lua5.1.lib

210 Bytes
Binary file not shown.

libs/x64/lua5.1.pdb

3.42 MB
Binary file not shown.

libs/x64/lua5.1_d.a

-16.2 KB
Binary file not shown.

libs/x64/lua5.1_d.lib

212 Bytes
Binary file not shown.

libs/x64/lua5.1_d.pdb

6.05 MB
Binary file not shown.

modules/sockets/include/CFunctions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright 2003-2008 MTA. All Rights Reserved.
7+
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is 2002-2003 Rockstar North
9+
* Grand Theft Auto is (c) 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS

modules/sockets/include/CLuaArgument.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright 2003-2008 MTA. All Rights Reserved.
7+
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is 2002-2003 Rockstar North
9+
* Grand Theft Auto is (c) 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS

modules/sockets/include/CLuaArguments.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright 2003-2008 MTA. All Rights Reserved.
7+
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is 2002-2003 Rockstar North
9+
* Grand Theft Auto is (c) 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS

modules/sockets/include/CSocket.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ class CSocket
3737
CSocket (lua_State *luaVM, const string& strHost, const unsigned short& usPort);
3838
~CSocket (); // Delete only - Does not trigger any events
3939

40-
void CloseSocketWithEvent (); // Close socket and trigger event
40+
void CloseSocketWithEvent (bool bTriggerCloseEvent); // Close socket and optionally trigger event
4141
bool Send (const string& data);
4242
bool DoPulse ();
4343
bool IsConnected ();
4444

4545
void* GetUserdata ();
46+
lua_State* GetLuaVM() { return m_pLuaVM; }
4647
static int GetTotalOpenSocketCount ();
4748

4849
private:

modules/sockets/include/CSocketManager.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ class CSocketManager
1919
{
2020
public:
2121
static void DoPulse();
22-
22+
static void ResourceStopped( lua_State * luaVM );
23+
2324
static void SocketAdd (CSocket*& pSocket);
24-
static void SocketRemove(CSocket*& pSocket);
25+
static void SocketRemove(CSocket*& pSocket, bool bTriggerCloseEvent=true);
2526
static bool GetSocket (CSocket*& pSocket, void* pUserdata);
27+
static bool GetSocketByLuaVM(CSocket*& pSocket, lua_State * luaVM);
2628

2729
static void HandleStop ();
2830
};

modules/sockets/include/Common.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright 2003-2008 MTA. All Rights Reserved.
7+
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is 2002-2003 Rockstar North
9+
* Grand Theft Auto is (c) 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS

modules/sockets/include/ml_sockets.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright 2003-2008 MTA. All Rights Reserved.
7+
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is 2002-2003 Rockstar North
9+
* Grand Theft Auto is (c) 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS

modules/sockets/src/CFunctions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright © 2003-2008 MTA. All Rights Reserved.
7+
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is © 2002-2003 Rockstar North
9+
* Grand Theft Auto is (c) 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS

modules/sockets/src/CLuaArgument.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright © 2003-2008 MTA. All Rights Reserved.
7+
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is © 2002-2003 Rockstar North
9+
* Grand Theft Auto is (c) 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS

modules/sockets/src/CLuaArguments.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright © 2003-2008 MTA. All Rights Reserved.
7+
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is © 2002-2003 Rockstar North
9+
* Grand Theft Auto is (c) 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS

modules/sockets/src/CSocket.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ CSocket::~CSocket()
6464
}
6565
}
6666

67-
void CSocket::CloseSocketWithEvent()
67+
void CSocket::CloseSocketWithEvent(bool bTriggerCloseEvent)
6868
{
6969
// Close the socket, if it exists, and trigger the closed event
7070
if (m_pSocket != ERR_INVALID_SOCKET)
7171
{
7272
CloseSocket();
73-
TriggerEvent("onSockClosed");
73+
if ( bTriggerCloseEvent )
74+
TriggerEvent("onSockClosed");
7475
}
7576
}
7677

modules/sockets/src/CSocketManager.cpp

+32-2
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,29 @@ void CSocketManager::DoPulse()
3939
}
4040
}
4141

42+
43+
void CSocketManager::ResourceStopped( lua_State * luaVM )
44+
{
45+
// Enusure all sockets using luaVM are closed
46+
CSocket* pSocket;
47+
while( GetSocketByLuaVM( pSocket, luaVM ) )
48+
{
49+
SocketRemove( pSocket, false );
50+
}
51+
}
52+
53+
4254
void CSocketManager::SocketAdd(CSocket*& pSocket)
4355
{
4456
// Add the socket to the loop stuff
4557
vecSockets.push_back(pSocket);
4658
}
4759

48-
void CSocketManager::SocketRemove(CSocket*& pSocket)
60+
void CSocketManager::SocketRemove(CSocket*& pSocket, bool bTriggerCloseEvent)
4961
{
5062
ListRemove(vecSockets, pSocket);
5163
ListRemove(processQueue, pSocket);
52-
pSocket->CloseSocketWithEvent();
64+
pSocket->CloseSocketWithEvent(bTriggerCloseEvent);
5365
ListRemove(deleteList, pSocket);
5466
deleteList.push_back(pSocket);
5567
}
@@ -75,6 +87,24 @@ bool CSocketManager::GetSocket(CSocket*& pSocket, void* pUserdata)
7587
return false;
7688
}
7789

90+
91+
bool CSocketManager::GetSocketByLuaVM(CSocket*& pSocket, lua_State * luaVM)
92+
{
93+
// Loop through all sockets
94+
for (unsigned int i = 0; i < vecSockets.size(); ++i)
95+
{
96+
// Compare the current socket's luaVM with the one we're looking for
97+
if (vecSockets[i]->GetLuaVM() == luaVM)
98+
{
99+
// If it's the one we want, assign pSocket to it and return true
100+
pSocket = vecSockets[i];
101+
return true;
102+
}
103+
}
104+
105+
return false;
106+
}
107+
78108
void CSocketManager::HandleStop()
79109
{
80110
// Triggered at module stop. Simply destroys all sockets

modules/sockets/src/ml_sockets.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright © 2003-2008 MTA. All Rights Reserved.
7+
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is © 2002-2003 Rockstar North
9+
* Grand Theft Auto is (c) 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS

premake5.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

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

56
workspace "MTA Modules"
67

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

2829
filter "configurations:Debug"
2930
defines { "DEBUG" }
30-
flags { "C++14", "Symbols" }
31+
flags { "C++14" }
32+
symbols "On"
3133
targetsuffix "_d"
3234

3335
filter "configurations:Release"

utils/premake5

995 KB
Binary file not shown.

utils/premake5.exe

301 KB
Binary file not shown.

0 commit comments

Comments
 (0)