mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 22:18:19 +00:00
Implement opening server on Windows (reading autoexec_server.log not working yet)
This commit is contained in:
parent
59ae288ead
commit
90f3199d98
|
@ -3214,11 +3214,17 @@ int pid(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
int shell_execute(const char *file)
|
||||
PROCESS shell_execute(const char *file)
|
||||
{
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
ShellExecute(NULL, NULL, file, NULL, NULL, SW_SHOWDEFAULT);
|
||||
// TODO: Get PID
|
||||
SHELLEXECUTEINFOA info;
|
||||
mem_zero(&info, sizeof(SHELLEXECUTEINFOA));
|
||||
info.lpVerb = "open";
|
||||
info.lpFile = file;
|
||||
info.nShow = SW_SHOWDEFAULT;
|
||||
info.fMask = SEE_MASK_NOCLOSEPROCESS;
|
||||
ShellExecuteEx(&info);
|
||||
return info.hProcess;
|
||||
#elif defined(CONF_FAMILY_UNIX)
|
||||
char *argv[2];
|
||||
pid_t pid;
|
||||
|
@ -3231,14 +3237,14 @@ int shell_execute(const char *file)
|
|||
#endif
|
||||
}
|
||||
|
||||
int kill_process(int pid)
|
||||
int kill_process(PROCESS process)
|
||||
{
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
// TODO: Implement
|
||||
return TerminateProcess(process, 0);
|
||||
#elif defined(CONF_FAMILY_UNIX)
|
||||
int status;
|
||||
kill(pid, SIGTERM);
|
||||
return waitpid(pid, &status, 0);
|
||||
kill(process, SIGTERM);
|
||||
return !waitpid(process, &status, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -1991,27 +1991,33 @@ int str_in_list(const char *list, const char *delim, const char *needle);
|
|||
*/
|
||||
int pid(void);
|
||||
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
typedef void *PROCESS;
|
||||
#else
|
||||
typedef pid_t PROCESS;
|
||||
#endif
|
||||
|
||||
/*
|
||||
Function: shell_execute
|
||||
Executes a given file.
|
||||
|
||||
Returns:
|
||||
pid of the new process
|
||||
handle/pid of the new process
|
||||
*/
|
||||
int shell_execute(const char *file);
|
||||
PROCESS shell_execute(const char *file);
|
||||
|
||||
/*
|
||||
Function: kill_process
|
||||
Sends kill signal to a process.
|
||||
|
||||
Parameters:
|
||||
pid - pid of the process
|
||||
process - handle/pid of the process
|
||||
|
||||
Returns:
|
||||
0 - Success
|
||||
1 - Error
|
||||
0 - Error
|
||||
1 - Success
|
||||
*/
|
||||
int kill_process(int pid);
|
||||
int kill_process(PROCESS process);
|
||||
|
||||
/*
|
||||
Function: os_is_winxp_or_lower
|
||||
|
|
|
@ -486,9 +486,9 @@ public:
|
|||
GetPath(Type, pDir, pBuffer, BufferSize);
|
||||
}
|
||||
|
||||
virtual const char* GetBinaryPath(const char *pDir, char *pBuffer, unsigned BufferSize)
|
||||
virtual const char* GetBinaryPath(const char *pFilename, char *pBuffer, unsigned BufferSize)
|
||||
{
|
||||
str_format(pBuffer, BufferSize, "%s%s%s", m_aBinarydir, !m_aBinarydir[0] ? "" : "/", pDir);
|
||||
str_format(pBuffer, BufferSize, "%s%s%s", m_aBinarydir, !m_aBinarydir[0] ? "" : "/", pFilename);
|
||||
return pBuffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
virtual bool RemoveBinaryFile(const char *pFilename) = 0;
|
||||
virtual bool RenameBinaryFile(const char* pOldFilename, const char* pNewFilename) = 0;
|
||||
virtual const char* GetBinaryPath(const char *pDir, char *pBuffer, unsigned BufferSize) = 0;
|
||||
virtual const char* GetBinaryPath(const char *pFilename, char *pBuffer, unsigned BufferSize) = 0;
|
||||
|
||||
static void StripPathAndExtension(const char *pFilename, char *pBuffer, int BufferSize);
|
||||
};
|
||||
|
|
|
@ -85,7 +85,7 @@ CMenus::CMenus()
|
|||
m_DemoPlayerState = DEMOPLAYER_NONE;
|
||||
m_Dummy = false;
|
||||
|
||||
m_ServerProcess.Pid = -1;
|
||||
m_ServerProcess.Process = 0;
|
||||
m_ServerProcess.Initialized = false;
|
||||
}
|
||||
|
||||
|
@ -2071,12 +2071,13 @@ extern "C" void font_debug_render();
|
|||
|
||||
void CMenus::OnRender()
|
||||
{
|
||||
if(m_ServerProcess.Pid != -1)
|
||||
if(m_ServerProcess.Process != 0)
|
||||
{
|
||||
// TODO: Maybe call this less often, or probably even cleaner, use econ
|
||||
if(!m_ServerProcess.Initialized)
|
||||
{
|
||||
IOHANDLE File = Storage()->OpenFile("autoexec_server.log", IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
char aBuf[MAX_PATH_LENGTH];
|
||||
IOHANDLE File = Storage()->OpenFile(Storage()->GetBinaryPath("autoexec_server.log", aBuf, sizeof(aBuf)), IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
if(File)
|
||||
{
|
||||
m_ServerProcess.LineReader.Init(File);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
struct CServerProcess
|
||||
{
|
||||
pid_t Pid;
|
||||
PROCESS Process;
|
||||
bool Initialized;
|
||||
CLineReader LineReader;
|
||||
};
|
||||
|
|
|
@ -49,17 +49,18 @@ void CMenus::RenderStartMenu(CUIRect MainView)
|
|||
Menu.HSplitBottom(5.0f, &Menu, 0); // little space
|
||||
Menu.HSplitBottom(40.0f, &Menu, &Button);
|
||||
static int s_LocalServerButton = 0;
|
||||
if(DoButton_Menu(&s_LocalServerButton, m_ServerProcess.Pid == -1 ? Localize("Run server") : Localize("Stop server"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "local_server" : 0, CUI::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), m_ServerProcess.Pid == -1 ? vec4(0.0f, 0.0f, 0.0f, 0.25f) : vec4(0.0f, 1.0f, 0.0f, 0.25f)) || (CheckHotKey(KEY_R) && Input()->KeyPress(KEY_R)))
|
||||
if(DoButton_Menu(&s_LocalServerButton, m_ServerProcess.Process ? Localize("Stop server") : Localize("Run server"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "local_server" : 0, CUI::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), m_ServerProcess.Process ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(0.0f, 0.0f, 0.0f, 0.25f)) || (CheckHotKey(KEY_R) && Input()->KeyPress(KEY_R)))
|
||||
{
|
||||
if(m_ServerProcess.Pid == -1)
|
||||
if(m_ServerProcess.Process)
|
||||
{
|
||||
Storage()->RemoveFile("autoexec_server.log", IStorage::TYPE_ALL);
|
||||
m_ServerProcess.Pid = shell_execute(PLAT_SERVER_EXEC);
|
||||
kill_process(m_ServerProcess.Process);
|
||||
m_ServerProcess.Process = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
kill_process(m_ServerProcess.Pid);
|
||||
m_ServerProcess.Pid = -1;
|
||||
Storage()->RemoveBinaryFile("autoexec_server.log");
|
||||
char aBuf[MAX_PATH_LENGTH];
|
||||
m_ServerProcess.Process = shell_execute(Storage()->GetBinaryPath(PLAT_SERVER_EXEC, aBuf, sizeof(aBuf)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue