添加readline优化控制台输入
This commit is contained in:
parent
18dfa2d933
commit
a6ef7126be
@ -2569,6 +2569,7 @@ if(SERVER)
|
|||||||
PROPERTY OUTPUT_NAME ${SERVER_EXECUTABLE}
|
PROPERTY OUTPUT_NAME ${SERVER_EXECUTABLE}
|
||||||
)
|
)
|
||||||
target_link_libraries(game-server ${LIBS_SERVER})
|
target_link_libraries(game-server ${LIBS_SERVER})
|
||||||
|
target_link_libraries(game-server readline)
|
||||||
target_include_directories(game-server PRIVATE ${PNG_INCLUDE_DIRS})
|
target_include_directories(game-server PRIVATE ${PNG_INCLUDE_DIRS})
|
||||||
list(APPEND TARGETS_OWN game-server)
|
list(APPEND TARGETS_OWN game-server)
|
||||||
list(APPEND TARGETS_LINK game-server)
|
list(APPEND TARGETS_LINK game-server)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
#include <readline/readline.h>
|
||||||
#define _WIN32_WINNT 0x0501
|
#define _WIN32_WINNT 0x0501
|
||||||
|
|
||||||
#include <base/logger.h>
|
#include <base/logger.h>
|
||||||
@ -47,6 +48,9 @@ void HandleSigIntTerm(int Param)
|
|||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
|
signal(SIGINT, HandleSigIntTerm);
|
||||||
|
signal(SIGTERM, HandleSigIntTerm);
|
||||||
|
|
||||||
CCmdlineFix CmdlineFix(&argc, &argv);
|
CCmdlineFix CmdlineFix(&argc, &argv);
|
||||||
bool Silent = false;
|
bool Silent = false;
|
||||||
|
|
||||||
@ -94,9 +98,6 @@ int main(int argc, const char **argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGINT, HandleSigIntTerm);
|
|
||||||
signal(SIGTERM, HandleSigIntTerm);
|
|
||||||
|
|
||||||
#if defined(CONF_EXCEPTION_HANDLING)
|
#if defined(CONF_EXCEPTION_HANDLING)
|
||||||
init_exception_handler();
|
init_exception_handler();
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include <base/system.h>
|
#include <base/system.h>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include <engine/config.h>
|
#include <engine/config.h>
|
||||||
#include <engine/console.h>
|
#include <engine/console.h>
|
||||||
#include <engine/engine.h>
|
#include <engine/engine.h>
|
||||||
@ -39,8 +41,12 @@
|
|||||||
// DDRace
|
// DDRace
|
||||||
#include <engine/shared/linereader.h>
|
#include <engine/shared/linereader.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
#include <readline/readline.h>
|
||||||
|
#include <readline/history.h>
|
||||||
|
#include <csignal>
|
||||||
|
|
||||||
#include "antibot.h"
|
#include "antibot.h"
|
||||||
#include "databases/connection.h"
|
#include "databases/connection.h"
|
||||||
@ -2528,14 +2534,11 @@ int CServer::LoadMap(const char *pMapName)
|
|||||||
void* CreateConsoleThread(void* p){
|
void* CreateConsoleThread(void* p){
|
||||||
IConsole* console=(IConsole*)p;
|
IConsole* console=(IConsole*)p;
|
||||||
while(true){
|
while(true){
|
||||||
printf(" ->");
|
char* cmd=readline("\001\033[34m\002DDNet->\001\033[0m\002");
|
||||||
char cmd[256];
|
if(!*cmd) continue;
|
||||||
int result=scanf("%s",cmd);
|
add_history(cmd);
|
||||||
if(result==1){
|
|
||||||
console->ExecuteLine(cmd);
|
console->ExecuteLine(cmd);
|
||||||
}else{
|
free(cmd);
|
||||||
printf("命令格式错误!\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user