From a6ef7126bea0fd4da90c67fa85571c8419aaaa3e Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 15 Apr 2023 23:30:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0readline=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + src/engine/server/main.cpp | 7 ++++--- src/engine/server/server.cpp | 17 ++++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f820fac..0a7859c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2569,6 +2569,7 @@ if(SERVER) PROPERTY OUTPUT_NAME ${SERVER_EXECUTABLE} ) target_link_libraries(game-server ${LIBS_SERVER}) + target_link_libraries(game-server readline) target_include_directories(game-server PRIVATE ${PNG_INCLUDE_DIRS}) list(APPEND TARGETS_OWN game-server) list(APPEND TARGETS_LINK game-server) diff --git a/src/engine/server/main.cpp b/src/engine/server/main.cpp index 28d25cb..5389da5 100644 --- a/src/engine/server/main.cpp +++ b/src/engine/server/main.cpp @@ -1,4 +1,5 @@ +#include #define _WIN32_WINNT 0x0501 #include @@ -47,6 +48,9 @@ void HandleSigIntTerm(int Param) int main(int argc, const char **argv) { + signal(SIGINT, HandleSigIntTerm); + signal(SIGTERM, HandleSigIntTerm); + CCmdlineFix CmdlineFix(&argc, &argv); bool Silent = false; @@ -94,9 +98,6 @@ int main(int argc, const char **argv) return -1; } - signal(SIGINT, HandleSigIntTerm); - signal(SIGTERM, HandleSigIntTerm); - #if defined(CONF_EXCEPTION_HANDLING) init_exception_handler(); #endif diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 8341589..a7e46d0 100755 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include #include @@ -39,8 +41,12 @@ // DDRace #include #include +#include #include #include +#include +#include +#include #include "antibot.h" #include "databases/connection.h" @@ -2528,14 +2534,11 @@ int CServer::LoadMap(const char *pMapName) void* CreateConsoleThread(void* p){ IConsole* console=(IConsole*)p; while(true){ - printf(" ->"); - char cmd[256]; - int result=scanf("%s",cmd); - if(result==1){ + char* cmd=readline("\001\033[34m\002DDNet->\001\033[0m\002"); + if(!*cmd) continue; + add_history(cmd); console->ExecuteLine(cmd); - }else{ - printf("命令格式错误!\n"); - } + free(cmd); } }