1
0

添加控制台交互

This commit is contained in:
Your Name 2023-04-15 19:13:34 +08:00
parent 9b3fb69702
commit f4e6593c7a
5 changed files with 32 additions and 3373 deletions

View File

@ -110,7 +110,7 @@ elseif(TARGET_OS STREQUAL "mac")
endif()
option(WEBSOCKETS "Enable websockets support" OFF)
option(MYSQL "Enable mysql support" OFF)
option(MYSQL "Enable mysql support" ON)
option(TEST_MYSQL "Test mysql support in unit tests (also sets -DMYSQL=ON)" OFF)
option(AUTOUPDATE "Enable the autoupdater" OFF)
option(INFORM_UPDATE "Inform about available updates" ON)

File diff suppressed because it is too large Load Diff

View File

@ -195,6 +195,5 @@ int main(int argc, const char **argv)
// free
delete pKernel;
return Ret;
}

View File

@ -7,6 +7,7 @@
#include <base/math.h>
#include <base/system.h>
#include <cstdio>
#include <engine/config.h>
#include <engine/console.h>
#include <engine/engine.h>
@ -37,9 +38,11 @@
// DDRace
#include <engine/shared/linereader.h>
#include <pthread.h>
#include <vector>
#include <zlib.h>
#include "antibot.h"
#include "databases/connection.h"
#include "databases/connection_pool.h"
#include "register.h"
@ -2521,6 +2524,22 @@ int CServer::LoadMap(const char *pMapName)
return 1;
}
bool initConsole=false;
//控制台线程
void* CreateConsoleThread(void* p){
IConsole* console=(IConsole*)p;
while(true){
if(!initConsole) continue;
printf(" ->");
char cmd[256];
int result=scanf("%s",cmd);
if(result==1){
console->ExecuteLine(cmd);
}else{
printf("命令格式错误!\n");
}
}
}
int CServer::Run()
{
@ -2542,7 +2561,6 @@ int CServer::Run()
Client.m_pPersistentData = malloc(Size);
}
}
// load map
if(!LoadMap(Config()->m_SvMap))
{
@ -2629,14 +2647,23 @@ int CServer::Run()
dbg_msg("server", "+-------------------------+");
}
//控制台
{
pthread_t thread;
//创建一个控制台线程
pthread_create(&thread, nullptr,CreateConsoleThread,Console());
}
// start game
{
bool NonActive = false;
bool PacketWaiting = false;
m_GameStartTime = time_get();
//更新服务器信息
UpdateServerInfo();
initConsole=true;
//服务器非停止时
while(m_RunServer < STOPPING)
{
if(NonActive)
@ -2696,7 +2723,6 @@ int CServer::Run()
str_copy(Config()->m_SvMap, m_aCurrentMap);
}
}
// handle dnsbl
if(Config()->m_SvDnsbl)
{
@ -2853,7 +2879,8 @@ int CServer::Run()
}
if(IsInterrupted())
{
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "interrupted");
initConsole=false;
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "服务器被终止");
break;
}
}

View File

@ -295,7 +295,6 @@ public:
//int TickSpeed()
int Init();
void SendLogLine(const CLogMessage *pMessage);
void SetRconCID(int ClientID) override;
int GetAuthedState(int ClientID) const override;