disallowing multiple IrrlichtDevice's being opened
disallowing multiple IrrlichtDevice's being opened
Hello, just wondering. How do I stop more then 1 IrrlichtDevice from being opened?
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
Re: disallowing multiple IrrlichtDevice's being opened
Easy. Just don't create multiple devices.ericaus wrote:Hello, just wondering. How do I stop more then 1 IrrlichtDevice from being opened?
"Whoops..."
Re: disallowing multiple IrrlichtDevice's being opened
that way would be easy but not so great.randomMesh wrote:Easy. Just don't create multiple devices.ericaus wrote:Hello, just wondering. How do I stop more then 1 IrrlichtDevice from being opened?
I now done some testing with the source code and added:
Code: Select all
HWnd = FindWindow(ClassName, NULL); // I'll change NULL to a window name that I'll have inside a project to avoid problems if I have a new project using IrrlichtDevice.
if (HWnd != NULL)
{
hInstance = NULL;
MessageBox(HWnd, "Oops, a device is already opened", "duplicate", MB_OK);
//closeDevice(); // this doesn't work.
//return 0; // this doesn't work.
//HWnd = NULL; // this doesn't work.
//PostQuitMessage(0); // this kind of works but would make problems when getting an IrrlichtDevice into fullscreen
}
Code: Select all
// get handle to exe file
HINSTANCE hInstance = GetModuleHandle(0);
// create the window if we need to and we do not use the null device
if (!CreationParams.WindowId && CreationParams.DriverType != video::EDT_NULL)
{
const c8* ClassName = "CIrrDeviceWin32";
Last edited by ericaus on Sat Oct 03, 2009 4:31 am, edited 1 time in total.
Just wondering - is there any reason why you want to prevent that? I do occasionally work with 2 devices open at the same time and think it's not such a good idea to change something like that in the engine. Always try to minimize changes in your engine version, it will make updating so much easier even if you have a good patch management.
randomMesh gave a good hint there - just don't open more than one if you don't need that. You usually do that anyway just once in initializing, so it's not exactly something happens accidentally (usually).
Or (just guessing) do you maybe want to prevent your application getting started more than once? Then you better use a mutex (in your app - not in the engine).
randomMesh gave a good hint there - just don't open more than one if you don't need that. You usually do that anyway just once in initializing, so it's not exactly something happens accidentally (usually).
Or (just guessing) do you maybe want to prevent your application getting started more than once? Then you better use a mutex (in your app - not in the engine).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Oh, its just so that once I become professionalized in using Irrlicht, I could attempt creating MORPG's and disallow users from opening more than 1 application and playing on multiple accounts.CuteAlien wrote:Just wondering - is there any reason why you want to prevent that?
hmm, mutex. I've never heard of it, though I'll do some research on that.CuteAlien wrote:Then you better use a mutex (in your app - not in the engine).
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
You could create a shared memory segment and check if it is already present.
You can use boost::interprocess for this.
You can use boost::interprocess for this.
"Whoops..."
The mutex solution works perfectly. After a bit of research, I added:
in the first couple of lines inside int main() before calling anything else inside a test project.
Code: Select all
HANDLE handle = CreateMutex(NULL, false, "demo");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
MessageBox(0, "Application is already running", "duplicate", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
And the user will open a vm, start a second app from the vm and laugh about the programmer who tried to avoid this.....ericaus wrote:Oh, its just so that once I become professionalized in using Irrlicht, I could attempt creating MORPG's and disallow users from opening more than 1 application and playing on multiple accounts.
You could create a temp file when your game starts and erase it when you close the game. On startup you check if the file exists. If it does, you won't be able to start. Of course, someone would try erase the file after starting one copy of game but the game would shut down abruptly after some time (you could check for file existence after every 30 seconds or so)Nox wrote: And the user will open a vm, start a second app from the vm and laugh about the programmer who tried to avoid this.....
It may not be the most elegant solution, but I think it works.
Even worse - the games crashes once, the file would not get deleted and the user couldn't start it any-more. Actually speaking out of experience here, as some applications occasionally try that thing (for other reasons - it's sometimes nice to protect users from accidentally opening same application twice).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Not the one the server sees, but you can use proxies.Eigen wrote:Or can you change your IP as well when running in VM?
There is no way that works 100%. You have to prevent the user from creating multiple accounts. Once the user has more than one account he can use them both.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Preventing a user from creating more than one account is pretty much impossible, I think. You can easily limit one account per IP but then you'd simply use another computer.
I think you have deal with it once the game is running. Monitoring interactions between users. (It could be made automatic on the server) If two users are constantly trading things, etc. then have the administrator have a look and warn both accounts, if needed. If that doesn't help, delete them. If you make it a rule, there should not be any misunderstanding.
I think you have deal with it once the game is running. Monitoring interactions between users. (It could be made automatic on the server) If two users are constantly trading things, etc. then have the administrator have a look and warn both accounts, if needed. If that doesn't help, delete them. If you make it a rule, there should not be any misunderstanding.