iw4x-client/src/Components/Modules/Singleton.cpp

38 lines
925 B
C++
Raw Normal View History

2015-12-28 20:52:31 -05:00
#include "..\..\STDInclude.hpp"
2015-12-27 14:05:43 -05:00
namespace Components
{
bool Singleton::FirstInstance = true;
bool Singleton::IsFirstInstance()
{
return Singleton::FirstInstance;
}
Singleton::Singleton()
{
if (Dedicated::IsDedicated()) return;
2015-12-27 14:16:01 -05:00
Singleton::FirstInstance = (CreateMutex(NULL, FALSE, "iw4x_mutex") && GetLastError() != ERROR_ALREADY_EXISTS);
2015-12-29 17:13:23 -05:00
//Checking if the instance is for the connect protocol
if (!Singleton::FirstInstance)
2015-12-27 14:05:43 -05:00
{
2015-12-29 17:13:23 -05:00
if (ConnectProtocol::InvokeConnect() == TRUE)
{
//Connect command was successfuly sent to the first instance, exiting the second game instance now.
ExitProcess(0);
}
else
{
//No connect command was provided, continuing with normal processing.
2016-01-03 18:00:07 -05:00
if (!Singleton::FirstInstance && MessageBoxA(0, "Do you want to start another instance?", "Game already running", MB_ICONEXCLAMATION | MB_YESNO) == IDNO)
2015-12-29 17:13:23 -05:00
{
ExitProcess(0);
}
}
2015-12-27 14:05:43 -05:00
}
2015-12-29 17:13:23 -05:00
2015-12-27 14:05:43 -05:00
}
}