Por underewarr, 01 de mar. de 2019 em C e C++
info
Grupo: Banidos
Registrado: 25/01/13
Posts: 114
Reputação: +14
Gênero: Masculino
Char no Tibia: Tiuzao Doidao
Um código simples para fazer o global server save, e logo após reiniciar o servidor.
Windows
Adicione no Config.Lua
shutdownAtGlobalSave = true globalSaveEnabled = true
No Game.cpp adicione uma nova função
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; }
Adicione em game.h
bool isRunning(const char* name);
Em Game.cpp procure por
void Game::setGameState(GameState_t newState)
E adicione logo a baixo.
Scheduler::getInstance().stop(); Dispatcher::getInstance().stop();
E abaixo disso adicione
const char* name = "AutoRun.exe"; if(!isRunning(name)) WinExec(name, SW_SHOWNORMAL);
Em otsystem.h adicione um novo include
#include <windows.h>
Agora vamos anexar isso
#include <tlhelp32.h>
Esta feito agora basta compilar um programa chamado autorun.exe com o código a baixo. Após a compilação coloque o exe na pasta do servidor e inicie.
#include <windows.h> #include <tlhelp32.h> #include <iostream> const int _time = 10; char* name = "servidor.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; }
Linux:
Para desativar.
Em otserv.cpp , procure por :
{ #if defined(WINDOWS) && !defined(__CONSOLE__) if(MessageBox(GUI::getInstance()->m_mainWindow, "Unable to fetch blacklist! Continue?", "Blacklist", MB_YESNO) == IDNO) #else std::cout << "Unable to fetch blacklist! Continue? (y/N)" << std::endl; char buffer = getchar(); if(buffer == 10 || (buffer != 121 && buffer != 89)) #endif startupErrorMessage("Unable to fetch blacklist!"); }
substitua por :
/*{ #if defined(WINDOWS) && !defined(__CONSOLE__) if(MessageBox(GUI::getInstance()->m_mainWindow, "Unable to fetch blacklist! Continue?", "Blacklist", MB_YESNO) == IDNO) #else std::cout << "Unable to fetch blacklist! Continue? (y/N)" << std::endl; char buffer = getchar(); if(buffer == 10 || (buffer != 121 && buffer != 89)) #endif startupErrorMessage("Unable to fetch blacklist!"); }*/
Agora no Terminal:
while true; do ./theforgottenserver -y; done
Creditos: Underewar
Editado Março 1 por underewarr
info
Grupo: Banidos
Registrado: 25/01/13
Posts: 114
Reputação: +14
Gênero: Masculino
Char no Tibia: Tiuzao Doidao
Um código simples para fazer o global server save, e logo após reiniciar o servidor.
Windows
Adicione no Config.Lua
No Game.cpp adicione uma nova função
Adicione em game.h
Em Game.cpp procure por
void Game::setGameState(GameState_t newState)E adicione logo a baixo.
Scheduler::getInstance().stop(); Dispatcher::getInstance().stop();E abaixo disso adicione
Em otsystem.h adicione um novo include
Agora vamos anexar isso
Esta feito agora basta compilar um programa chamado autorun.exe com o código a baixo. Após a compilação coloque o exe na pasta do servidor e inicie.
Linux:
Para desativar.
Em otserv.cpp , procure por :
substitua por :
/*{ #if defined(WINDOWS) && !defined(__CONSOLE__) if(MessageBox(GUI::getInstance()->m_mainWindow, "Unable to fetch blacklist! Continue?", "Blacklist", MB_YESNO) == IDNO) #else std::cout << "Unable to fetch blacklist! Continue? (y/N)" << std::endl; char buffer = getchar(); if(buffer == 10 || (buffer != 121 && buffer != 89)) #endif startupErrorMessage("Unable to fetch blacklist!"); }*/Agora no Terminal:
while true; do ./theforgottenserver -y; done
Creditos: Underewar
Editado Março 1 por underewarr