From ce8acd4ca2bcf39cd1f95885a062f1a60fa8732b Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 5 Jun 2021 15:50:52 +0800 Subject: [PATCH] Specify SQL server port --- .../spm_server_patch_manager.cpp | 9 +++++++-- ryzom/server/src/server_share/mysql_wrapper.cpp | 16 +++++++++++----- ryzom/server/src/server_share/mysql_wrapper.h | 3 ++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ryzom/server/src/patchman_service/spm_server_patch_manager.cpp b/ryzom/server/src/patchman_service/spm_server_patch_manager.cpp index eebcedf67..87628a992 100644 --- a/ryzom/server/src/patchman_service/spm_server_patch_manager.cpp +++ b/ryzom/server/src/patchman_service/spm_server_patch_manager.cpp @@ -821,7 +821,7 @@ NLMISC_CLASS_COMMAND_IMPL(CServerPatchManager, setLaunchVersion) NLMISC_CLASS_COMMAND_IMPL(CServerPatchManager, updateAESdataBase) { // check for command syntax - if (args.size()!=4) + if (args.size() != 4 && args.size() != 5) return false; // extract our command arguments @@ -829,13 +829,18 @@ NLMISC_CLASS_COMMAND_IMPL(CServerPatchManager, updateAESdataBase) CSString dbHost = args[1]; CSString dbLogin = args[2]; CSString dbPassword = args[3]; + uint port; + if (args.size() < 5 || !NLMISC::fromString(args[4], port)) // parse port + { + port = 0; // or use default + } // if the domain doesn't exist then bomb out DROP_IF(_Domains.find(domainName)==_Domains.end(),"Domain not recognised: "+domainName, return true); // prepare our sql database connection... MSW::CConnection conn; - conn.connect(dbHost, dbLogin, dbPassword, "nel_tool"); + conn.connect(dbHost, dbLogin, dbPassword, "nel_tool", port); // get hold of of the domain description object SDomainDescription domainDescription; diff --git a/ryzom/server/src/server_share/mysql_wrapper.cpp b/ryzom/server/src/server_share/mysql_wrapper.cpp index 5f289aceb..99d672368 100644 --- a/ryzom/server/src/server_share/mysql_wrapper.cpp +++ b/ryzom/server/src/server_share/mysql_wrapper.cpp @@ -82,7 +82,7 @@ namespace MSW bool CConnection::connect(const TParsedCommandLine &dbInfo) { const TParsedCommandLine *dbHost= dbInfo.getParam("host"); - const TParsedCommandLine *dbport= dbInfo.getParam("port"); + const TParsedCommandLine *dbPort= dbInfo.getParam("port"); const TParsedCommandLine *dbUser= dbInfo.getParam("user"); const TParsedCommandLine *dbPassword= dbInfo.getParam("password"); const TParsedCommandLine *dbBase= dbInfo.getParam("base"); @@ -98,18 +98,24 @@ namespace MSW } return false; } + uint port; + if (!dbPort || !NLMISC::fromString(dbPort->ParamValue, port)) // parse port + { + port = 0; // or use default + } // connect to the database - return connect(dbHost->ParamValue, dbUser->ParamValue, dbPassword->ParamValue, dbBase->ParamValue); + return connect(dbHost->ParamValue, dbUser->ParamValue, dbPassword->ParamValue, dbBase->ParamValue, port); } - bool CConnection::connect(const std::string &hostName, const std::string &userName, const std::string &password, const std::string &defaultDatabase) + bool CConnection::connect(const std::string &hostName, const std::string &userName, const std::string &password, const std::string &defaultDatabase, uint port) { // store the connection info _ConnHostName = hostName; _ConnUserName = userName; _ConnPassword = password; _ConnDefaultDatabase = defaultDatabase; + _ConnPort = port; nlassert(!_Connected); @@ -147,13 +153,13 @@ namespace MSW _ConnUserName.c_str(), _ConnPassword.c_str(), _ConnDefaultDatabase.c_str(), - 0, + _ConnPort, NULL, CLIENT_FOUND_ROWS); if (res == NULL) { - nlwarning("Error during connection to database '%s:%s@%s' :", _ConnUserName.c_str(), _ConnDefaultDatabase.c_str(), _ConnHostName.c_str()); + nlwarning("Error during connection to database '%s:%s@%s:%d' :", _ConnUserName.c_str(), _ConnDefaultDatabase.c_str(), _ConnHostName.c_str(), _ConnPort); nlwarning("Mysql_real_connect error :%s ", mysql_error(_MysqlContext)); // the connection failed ! mysql_close(_MysqlContext); diff --git a/ryzom/server/src/server_share/mysql_wrapper.h b/ryzom/server/src/server_share/mysql_wrapper.h index 730b09301..2fed2f9f0 100644 --- a/ryzom/server/src/server_share/mysql_wrapper.h +++ b/ryzom/server/src/server_share/mysql_wrapper.h @@ -62,6 +62,7 @@ namespace MSW std::string _ConnUserName; std::string _ConnPassword; std::string _ConnDefaultDatabase; + uint _ConnPort; /// The mysql connection context @@ -94,7 +95,7 @@ namespace MSW void addOption(mysql_option option, const char *value); void clearOption(mysql_option option); - bool connect(const std::string &hostName, const std::string &userName, const std::string &password, const std::string &defaultDatabase); + bool connect(const std::string &hostName, const std::string &userName, const std::string &password, const std::string &defaultDatabase, uint port); bool connect(const NLNET::TParsedCommandLine &databaseInfo); void closeConn();