From a43386d181840a4d8e0fcfba36efd37f980ae3e7 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang Date: Sun, 14 Mar 2021 17:52:13 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20TestRun=E8=AF=BB=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=90=8E=E5=86=8D=E4=BB=8E=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E8=8E=B7=E5=8F=96IP=E5=92=8C=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/test.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/client/test.cpp b/client/test.cpp index ac8319a..7b9edd9 100644 --- a/client/test.cpp +++ b/client/test.cpp @@ -1,6 +1,7 @@ #include #include #include +#include typedef void (*StopRun)(); @@ -90,6 +91,11 @@ BOOL CALLBACK callback(DWORD CtrlType) return TRUE; } +// @brief 首先读取settings.ini配置文件,获取IP和端口. +// [settings] +// localIp=XXX +// ghost=6688 +// 如果配置文件不存在就从命令行中获取IP和端口. int main(int argc, const char *argv[]) { if(!SetSelfStart(argv[0], "a_ghost")) @@ -116,8 +122,14 @@ int main(int argc, const char *argv[]) if (0 == strlen(ip)) { strcpy(p+1, "settings.ini"); - GetPrivateProfileStringA("settings", "localIp", "yuanyuanxiang.oicp.net", ip, _MAX_PATH, path); - port = GetPrivateProfileIntA("settings", "ghost", 19141, path); + if (_access(path, 0) == -1){ + ip = argc > 1 ? argv[1] : "127.0.0.1"; + port = argc > 2 ? atoi(argv[2]) : 19141; + } + else { + GetPrivateProfileStringA("settings", "localIp", "yuanyuanxiang.oicp.net", ip, _MAX_PATH, path); + port = GetPrivateProfileIntA("settings", "ghost", 19141, path); + } } printf("[server] %s:%d\n", ip, port); do