From 5f85c722798d2154f8d823941ed1854dcae6cc4b Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Fri, 20 Mar 2020 09:12:19 -0500 Subject: [PATCH] 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