Oskar
Forum friend
- Joined
- Jan 24, 2009
- Messages
- 2,256
- Reaction score
- 331
Prosty kodzik, dzi?ki kt?remu mo?emy w??czy? w config.lua globalny save, wraz z opcj? restartu silnika:
W game.cpp dodajcie now? funkcj?:
W game.h deklaracja:
W game.cpp znajd? funkcj?:
A w niej:
I tu? pod tym dodaj:
W otsystem.h pod:
Doklej:
Oraz kod do programu:
Teraz wystarczy skompilowa? kodzik, plik nazwa? AutoRun.exe i wklei? do folderu z silnikiem.
PHP:
shutdownAtGlobalSave = true
globalSaveEnabled = true
W game.cpp dodajcie now? funkcj?:
PHP:
bool Game::isRunning(const char* name)
{
PROCESSENTRY32 proc32;
HANDLE hSnapshot;
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
proc32.dwSize = sizeof(PROCESSENTRY32);
bool isRunning = false;
if(Process32First(hSnapshot, &proc32))
{
while(Process32Next(hSnapshot, &proc32))
{
std::string filename_str = std::string(proc32.szExeFile);
if(filename_str == name)
{
isRunning = true;
break;
}
}
}
CloseHandle(hSnapshot);
return isRunning;
}
W game.h deklaracja:
PHP:
bool isRunning(const char* name);
W game.cpp znajd? funkcj?:
PHP:
void Game::setGameState(GameState_t newState)
A w niej:
PHP:
Scheduler::getInstance().stop();
Dispatcher::getInstance().stop();
I tu? pod tym dodaj:
PHP:
const char* name = "AutoRun.exe";
if(!isRunning(name))
WinExec(name, SW_SHOWNORMAL);
W otsystem.h pod:
PHP:
#include <windows.h>
Doklej:
PHP:
#include <tlhelp32.h>
Oraz kod do programu:
PHP:
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
const int _time = 10;
char* name = "Nazwa serwera.exe";
bool isRunning()
{
PROCESSENTRY32 proc32;
HANDLE hSnapshot;
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
proc32.dwSize = sizeof(PROCESSENTRY32);
std::cout << "Check the server is running." << std::endl;
bool isRunning = false;
if(Process32First(hSnapshot, &proc32))
{
while(Process32Next(hSnapshot, &proc32))
{
std::string filename_str = std::string(proc32.szExeFile);
if(filename_str == name)
{
isRunning = true;
break;
}
}
}
CloseHandle(hSnapshot);
return isRunning;
}
bool checkServer()
{
while(true)
{
Sleep(_time * 1000);
if(!isRunning())
{
std::cout << "Run the server." << std::endl;
WinExec(name, SW_SHOWNORMAL);
return true;
}
}
return false;
}
int main()
{
if(checkServer())
return 0;
return 1;
}
Teraz wystarczy skompilowa? kodzik, plik nazwa? AutoRun.exe i wklei? do folderu z silnikiem.