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() endif()
option(WEBSOCKETS "Enable websockets support" OFF) 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(TEST_MYSQL "Test mysql support in unit tests (also sets -DMYSQL=ON)" OFF)
option(AUTOUPDATE "Enable the autoupdater" OFF) option(AUTOUPDATE "Enable the autoupdater" OFF)
option(INFORM_UPDATE "Inform about available updates" ON) 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 // free
delete pKernel; delete pKernel;
return Ret; return Ret;
} }

View File

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

View File

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