Skip to content

Commit b8868f7

Browse files
committed
Improved server dll version check
1 parent 56b4506 commit b8868f7

File tree

4 files changed

+40
-46
lines changed

4 files changed

+40
-46
lines changed

MTA10_Server/core/CDynamicLibrary.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ bool CDynamicLibrary::Load ( const char* szFilename )
9999
}
100100
#endif
101101

102+
// Check for version mismatch
103+
if ( !CheckMtaVersion( ExtractFilename( szFilename ) ) )
104+
{
105+
return false;
106+
}
107+
102108
// Return whether we succeeded or not
103109
return m_hModule != 0;
104110
}
@@ -150,3 +156,34 @@ FuncPtr_t CDynamicLibrary::GetProcedureAddress ( const char* szProcName )
150156

151157
return NULL;
152158
}
159+
160+
161+
bool CDynamicLibrary::CheckMtaVersion( const char* szLibName )
162+
{
163+
#if MTASA_VERSION_TYPE == VERSION_TYPE_RELEASE
164+
// define MTASA_SKIP_VERSION_CHECKS in "build_overrides_s.h" to skip version checks
165+
#ifndef MTASA_SKIP_VERSION_CHECKS
166+
167+
if ( m_hModule == 0 )
168+
return false;
169+
170+
char buffer[256];
171+
buffer[0] = 0;
172+
GetLibMtaVersion( buffer, sizeof( buffer ) );
173+
SString strVersionCore = buffer;
174+
175+
buffer[0] = 0;
176+
FUNC_GetMtaVersion* pfnGetMtaVersion = (FUNC_GetMtaVersion*) ( GetProcedureAddress ( "GetLibMtaVersion" ) );
177+
if ( pfnGetMtaVersion )
178+
pfnGetMtaVersion( buffer, sizeof( buffer ) );
179+
if ( strVersionCore != buffer )
180+
{
181+
Print( "ERROR: '%s' library version is '%s' (Expected '%s')\n", szLibName, buffer, *strVersionCore );
182+
Print( "Reinstall MTA\n" );
183+
return false;
184+
}
185+
186+
#endif
187+
#endif
188+
return true;
189+
}

MTA10_Server/core/CDynamicLibrary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CDynamicLibrary
3131
bool IsLoaded ( void );
3232

3333
FuncPtr_t GetProcedureAddress ( const char* szProcName );
34+
bool CheckMtaVersion ( const char* szLibName );
3435

3536
private:
3637
#ifdef WIN32

MTA10_Server/core/CServerImpl.cpp

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -165,38 +165,6 @@ void CServerImpl::Daemonize () const
165165
}
166166
#endif
167167

168-
bool CServerImpl::CheckLibVersions( void )
169-
{
170-
#if MTASA_VERSION_TYPE == VERSION_TYPE_RELEASE
171-
// define MTASA_SKIP_VERSION_CHECKS in "build_overrides_s.h" to skip version checks
172-
#ifndef MTASA_SKIP_VERSION_CHECKS
173-
174-
char buffer[256];
175-
buffer[0] = 0;
176-
GetLibMtaVersion( buffer, sizeof( buffer ) );
177-
SString strVersionCore = buffer;
178-
179-
CDynamicLibrary* dynLibList[] = { &m_NetworkLibrary, &m_XMLLibrary, &m_pModManager->GetDynamicLibrary() };
180-
const char* dynLibNameList[] = { "net", "xml", "deathmatch" };
181-
182-
for( uint i = 0 ; i < NUMELMS( dynLibList ) ; i++ )
183-
{
184-
buffer[0] = 0;
185-
FUNC_GetMtaVersion* pfnGetMtaVersion = (FUNC_GetMtaVersion*) ( dynLibList[i]->GetProcedureAddress ( "GetLibMtaVersion" ) );
186-
if ( pfnGetMtaVersion )
187-
pfnGetMtaVersion( buffer, sizeof( buffer ) );
188-
if ( strVersionCore != buffer )
189-
{
190-
Print( "ERROR: '%s' library version is '%s' (Expected '%s')\n", dynLibNameList[i], buffer, *strVersionCore );
191-
Print( "Try reinstalling\n" );
192-
return false;
193-
}
194-
}
195-
196-
#endif
197-
#endif
198-
return true;
199-
}
200168

201169
int CServerImpl::Run ( int iArgumentCount, char* szArguments [] )
202170
{
@@ -378,19 +346,8 @@ int CServerImpl::Run ( int iArgumentCount, char* szArguments [] )
378346
// Make the modmanager load our mod
379347
if ( m_pModManager->Load ( "deathmatch", iArgumentCount, szArguments ) ) // Hardcoded for now
380348
{
381-
if ( CheckLibVersions() )
382-
{
383-
// Enter our mainloop
384-
MainLoop ();
385-
}
386-
else
387-
{
388-
// Version mismatch
389-
Print ( "Press Q to shut down the server!\n" );
390-
WaitForKey ( 'q' );
391-
DestroyWindow ( );
392-
return ERROR_LOADING_MOD;
393-
}
349+
// Enter our mainloop
350+
MainLoop ();
394351
}
395352
else
396353
{

MTA10_Server/core/CServerImpl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class CServerImpl : public CServerInterface
7373

7474
private:
7575
void MainLoop ( void );
76-
bool CheckLibVersions ( void );
7776

7877
bool ParseArguments ( int iArgumentCount, char* szArguments [] );
7978

0 commit comments

Comments
 (0)