From 5f85c722798d2154f8d823941ed1854dcae6cc4b Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Fri, 20 Mar 2020 09:12:19 -0500 Subject: [PATCH 1/3] Fix the Master Server so it works Instructions: 1. In SQL, create an account called "srb2_ms" @ "localhost" (or your hostname). 2. Grant the account full priviledges to "srb2_ms" (the database). 3. Compile, and run using the sh script provided. That's all I'm telling you, I don't want this to become rampant. --- tools/masterserver/.gitignore | 4 +-- tools/masterserver/ipcs.h | 2 +- tools/masterserver/masterserver.sh | 21 ++++++++-------- tools/masterserver/server.cpp | 8 ++++-- tools/masterserver/structure.sql | 40 ++++++++++++++++-------------- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/tools/masterserver/.gitignore b/tools/masterserver/.gitignore index 9f45745a3..8ae879eec 100644 --- a/tools/masterserver/.gitignore +++ b/tools/masterserver/.gitignore @@ -1,4 +1,4 @@ /client /server -/server.log -/*.o +/*.log +/*.o \ No newline at end of file diff --git a/tools/masterserver/ipcs.h b/tools/masterserver/ipcs.h index b9dc52fdf..4e144f4a5 100644 --- a/tools/masterserver/ipcs.h +++ b/tools/masterserver/ipcs.h @@ -140,8 +140,8 @@ typedef struct char port[8]; char name[32]; INT32 room; - char key[32]; // Secret key for linking dedicated servers to accounts char version[8]; // format is: x.yy.z (like 1.30.2 or 1.31) + char key[32]; // Secret key for linking dedicated servers to accounts } ATTRPACK msg_server_t; typedef struct diff --git a/tools/masterserver/masterserver.sh b/tools/masterserver/masterserver.sh index 9b1adb128..fe4ba0071 100755 --- a/tools/masterserver/masterserver.sh +++ b/tools/masterserver/masterserver.sh @@ -5,9 +5,10 @@ # Get LSB functions . /lib/lsb/init-functions -. /etc/default/rcS +#. /etc/default/rcS -SRB2MS=/usr/local/bin/masterserver +#SRB2MS=/usr/local/bin/masterserver +SRB2MS=./server SRB2MS_PORT=28900 # Check that the package is still installed @@ -15,11 +16,9 @@ SRB2MS_PORT=28900 case "$1" in start) - log_begin_msg "Starting SRB2MS..." + log_begin_msg "Starting SRB2MS...\n" umask 002 - if start-stop-daemon --start \ - --exec $SRB2MS \ - -- $SRB2MS_PORT; then + if exec $SRB2MS $SRB2MS_PORT & then log_end_msg 0 else log_end_msg $? @@ -27,11 +26,11 @@ case "$1" in ;; stop) - log_begin_msg "Stopping SRB2MS..." - if start-stop-daemon --stop --exec $SRB2MS; then - log_end_msg 0 + log_begin_msg "Stopping SRB2MS...\n" + if killall $SRB2MS -q & then + log_end_msg 0 else - log_end_msg $? + log_end_msg $? fi ;; @@ -40,7 +39,7 @@ case "$1" in ;; *) - e cho "Usage: /etc/init.d/masterserver {start|stop|restart|force-reload}" + echo "Usage: $0 {start|stop|restart|force-reload}" exit 1 ;; esac diff --git a/tools/masterserver/server.cpp b/tools/masterserver/server.cpp index b7ed0d6b4..883ba5985 100644 --- a/tools/masterserver/server.cpp +++ b/tools/masterserver/server.cpp @@ -86,7 +86,7 @@ typedef struct //============================================================================= -#define HOSTNAME "loopback" +#define HOSTNAME "localhost" #define USER "srb2_ms" #define PASSWORD "gLRDRb7WgLRDRb7W" #define DATABASE "srb2_ms" @@ -841,6 +841,10 @@ static void addServer(int id, char *buffer, bool firstadd) info->port[sizeof (info->port)-1] = '\0'; info->name[sizeof (info->name)-1] = '\0'; info->version[sizeof (info->version)-1] = '\0'; + + logPrintf(logfile, "addServer(): Version = \"%s\"\n", info->version); + logPrintf(logfile, "addServer(): Key = \"%s\"\n", info->key); + // retrieve the true ip of the server strcpy(info->ip, server_socket.getClientIP(id)); //strcpy(info->port, server_socket.getClientPort(id)); @@ -995,7 +999,7 @@ int main(int argc, char *argv[]) if (server_socket.listen(argv[1]) < 0) { - fprintf(stderr, "Error while initializing the server\n"); + fprintf(stderr, "Error while initializing the server; port being used! Try killing the other Master Server.\n"); exit(2); } diff --git a/tools/masterserver/structure.sql b/tools/masterserver/structure.sql index 3cc2cb15b..013c22383 100644 --- a/tools/masterserver/structure.sql +++ b/tools/masterserver/structure.sql @@ -13,8 +13,8 @@ SET time_zone = "+00:00"; -- Database: `srb2ms` -- -CREATE DATABASE IF NOT EXISTS `srb2ms` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; -USE `srb2ms`; +CREATE DATABASE IF NOT EXISTS `srb2_ms` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; +USE `srb2_ms`; -- -------------------------------------------------------- @@ -25,8 +25,8 @@ USE `srb2ms`; CREATE TABLE `ms_bans` ( `bid` int(11) DEFAULT NULL, - `ipstart` int(11) DEFAULT NULL, - `ipend` int(11) DEFAULT NULL, + `ipstart` int(10) unsigned DEFAULT NULL, + `ipend` int(10) unsigned DEFAULT NULL, `full_endtime` int(11) DEFAULT NULL, `permanent` tinyint(1) DEFAULT NULL, `hostonly` tinyint(1) DEFAULT NULL, @@ -63,19 +63,19 @@ INSERT INTO `ms_rooms` (`room_id`, `title`, `motd`, `visible`, `order`, `private -- CREATE TABLE `ms_servers` ( - `sid` int(11) NOT NULL, + `sid` int(11) primary key AUTO_INCREMENT, `name` text COLLATE utf8mb4_unicode_ci NOT NULL, `ip` text COLLATE utf8mb4_unicode_ci NOT NULL, - `port` int(11) NOT NULL, + `port` int(11) NOT NULL DEFAULT 5029, `version` text COLLATE utf8mb4_unicode_ci NOT NULL, - `timestamp` int(11) NOT NULL, - `room` int(11) NOT NULL, + `timestamp` int(11) NOT NULL DEFAULT 0, + `room` int(11) NOT NULL DEFAULT 0, `key` text COLLATE utf8mb4_unicode_ci NOT NULL, - `room_override` int(11) NOT NULL, - `upnow` tinyint(1) NOT NULL, - `permanent` tinyint(1) NOT NULL, - `delisted` tinyint(1) NOT NULL, - `sticky` int(11) NOT NULL + `room_override` int(11) NOT NULL DEFAULT 0, + `upnow` tinyint(1) NOT NULL DEFAULT 1, + `permanent` tinyint(1) NOT NULL DEFAULT 0, + `delisted` tinyint(1) NOT NULL DEFAULT 0, + `sticky` int(11) NOT NULL DEFAULT 0 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- @@ -85,16 +85,20 @@ CREATE TABLE `ms_servers` ( -- CREATE TABLE `ms_versions` ( - `mod_id` int(11) NOT NULL, - `mod_version` int(11) NOT NULL + `mod_id` int(10) unsigned primary key AUTO_INCREMENT, + `mod_version` int(10) unsigned NOT NULL DEFAULT 1, + `mod_vstring` varchar(45) NOT NULL DEFAULT 'v1.0', + `mod_codebase` int(10) unsigned NOT NULL DEFAULT 205, + `mod_name` varchar(255) NOT NULL DEFAULT 'Default MOD Name', + `mod_url` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Dumping data for table `ms_versions` -- -INSERT INTO `ms_versions` (`mod_id`, `mod_version`) VALUES -(12, 25); +INSERT INTO `ms_versions` (`mod_id`, `mod_version`, `mod_vstring`, `mod_codebase`, `mod_name`, `mod_url`) VALUES +(18, 42, 'v2.2.2', 205, 'SRB2 2.2', 'SRB2.org'); -- -------------------------------------------------------- @@ -114,4 +118,4 @@ COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; \ No newline at end of file From 66929c3c620e1e1ce386065e51992a9349a9c147 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Mon, 4 May 2020 01:38:38 -0500 Subject: [PATCH 2/3] Allow multiple ports to host under one IP address. --- tools/masterserver/server.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/masterserver/server.cpp b/tools/masterserver/server.cpp index 883ba5985..1f3f15a80 100644 --- a/tools/masterserver/server.cpp +++ b/tools/masterserver/server.cpp @@ -291,17 +291,17 @@ void MySQL_AddServer(const char *ip, const char *port, const char *name, const c char checkquery[500]; char updatequery[5000]; char queryp1[5000] = "INSERT INTO `ms_servers` (`name`,`ip`,`port`,`version`,`timestamp`,`room`,`key`) VALUES ('%s','%s','%s','%s','%ld','%d','%s')"; - char checkqueryp1[500] = "SELECT room_override FROM `ms_servers` WHERE `ip` = '%s'"; + char checkqueryp1[500] = "SELECT room_override FROM `ms_servers` WHERE `ip` = '%s' AND `port` = '%s'"; char updatequeryp1[5000]; if(firstadd) { logPrintf(logfile, "First add.\n"); - strcpy(updatequeryp1, "UPDATE `ms_servers` SET `name` = '%s', `port` = '%s', `version` = '%s', timestamp = '%ld', upnow = '1', `room` = '%d', `delisted` = '0', `key` = '%s' WHERE `ip` = '%s'"); + strcpy(updatequeryp1, "UPDATE `ms_servers` SET `name` = '%s', `port` = '%s', `version` = '%s', timestamp = '%ld', upnow = '1', `room` = '%d', `delisted` = '0', `key` = '%s' WHERE `ip` = '%s' AND `port` = '%s'"); } else { logPrintf(logfile, "Update ping.\n"); - strcpy(updatequeryp1, "UPDATE `ms_servers` SET `name` = '%s', `port` = '%s', `version` = '%s', timestamp = '%ld', upnow = '1', `room` = '%d', `key` = '%s' WHERE `ip` = '%s' AND `delisted` = '0'"); + strcpy(updatequeryp1, "UPDATE `ms_servers` SET `name` = '%s', `port` = '%s', `version` = '%s', timestamp = '%ld', upnow = '1', `room` = '%d', `key` = '%s' WHERE `ip` = '%s' AND `port` = '%s' AND `delisted` = '0'"); } MySQL_Conn(false); mysql_real_escape_string(conn, escapedName, name, (unsigned long)strlen(name)); @@ -314,10 +314,10 @@ void MySQL_AddServer(const char *ip, const char *port, const char *name, const c logPrintf(errorfile, "IP %s tried to use the private room %d! THIS SHOULD NOT HAPPEN\n", ip, room); return; } - sprintf(checkquery, checkqueryp1, ip); + sprintf(checkquery, checkqueryp1, ip, port); time_t timestamp; timestamp = time (NULL); - logPrintf(logfile, "Checking for existing servers in table with the same IP...\n"); + logPrintf(logfile, "Checking for existing servers in table with the same IP and port...\n"); logPrintf(mysqlfile, "Executing MySQL Query: %s\n", checkquery); if(mysql_query(conn, checkquery)) { logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); @@ -343,7 +343,7 @@ void MySQL_AddServer(const char *ip, const char *port, const char *name, const c mysql_free_result(res); logPrintf(logfile, "Server's IP already exists, so let's just update it instead...\n"); logPrintf(logfile, "Updating Server Data for %s\n", ip); - sprintf(updatequery, updatequeryp1, escapedName, escapedPort, escapedVersion, timestamp, room, escapedKey, ip); + sprintf(updatequery, updatequeryp1, escapedName, escapedPort, escapedVersion, timestamp, room, escapedKey, ip, port); logPrintf(mysqlfile, "Executing MySQL Query: %s\n", updatequery); if(mysql_query(conn, updatequery)) { logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); @@ -619,10 +619,10 @@ void MySQL_ListServServers(UINT32 id, UINT32 type, const char *ip) { void MySQL_RemoveServer(char *ip, char *port, char *name, char *version) { char escapedName[255]; char updatequery[5000]; - char updatequeryp1[5000] = "UPDATE `ms_servers` SET upnow = '0' WHERE `ip` = '%s' AND `permanent` = '0'"; + char updatequeryp1[5000] = "UPDATE `ms_servers` SET upnow = '0' WHERE `ip` = '%s' AND `port` = '%s' AND `permanent` = '0'"; MySQL_Conn(false); mysql_real_escape_string(conn, escapedName, name, (unsigned long)strlen(name)); - sprintf(updatequery, updatequeryp1, ip); + sprintf(updatequery, updatequeryp1, ip, port); logPrintf(mysqlfile, "Executing MySQL Query: %s\n", updatequery); if(mysql_query(conn, updatequery)) { logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); From a02306b674af77bf154ff6e55c970074723b21d5 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Mon, 4 May 2020 01:44:49 -0500 Subject: [PATCH 3/3] Fix small inconsistency --- tools/masterserver/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/masterserver/server.cpp b/tools/masterserver/server.cpp index 1f3f15a80..d00205301 100644 --- a/tools/masterserver/server.cpp +++ b/tools/masterserver/server.cpp @@ -341,7 +341,7 @@ void MySQL_AddServer(const char *ip, const char *port, const char *name, const c if(atoi(row[0]) != 0) room = atoi(row[0]); mysql_free_result(res); - logPrintf(logfile, "Server's IP already exists, so let's just update it instead...\n"); + logPrintf(logfile, "Server's IP and port already exists, so let's just update it instead...\n"); logPrintf(logfile, "Updating Server Data for %s\n", ip); sprintf(updatequery, updatequeryp1, escapedName, escapedPort, escapedVersion, timestamp, room, escapedKey, ip, port); logPrintf(mysqlfile, "Executing MySQL Query: %s\n", updatequery);