added cmd_restart cmd_reload and cmd_die; added Socket.NoDelay setting to configurati...
authorpk910 <philipp@zoelle1.de>
Sun, 11 Dec 2011 04:48:55 +0000 (05:48 +0100)
committerpk910 <philipp@zoelle1.de>
Sun, 11 Dec 2011 04:54:59 +0000 (05:54 +0100)
src/ClientSocket.c
src/cmd_global.h
src/cmd_global_die.c [new file with mode: 0644]
src/cmd_global_reload.c [new file with mode: 0644]
src/cmd_global_restart.c [new file with mode: 0644]
src/commands.c
src/main.c
src/main.h

index abf11a1945e0611006a54125947f0f5b223e9214..5fa795e30c028887bfdc7fdb3a4389c3b90f8e52 100644 (file)
@@ -22,6 +22,7 @@
 #include "WHOHandler.h"
 #include "HandleInfoHandler.h"
 #include "ssl.h"
+#include "ConfigParser.h"
 
 struct socket_list {
     struct ClientSocket *data;
@@ -169,6 +170,14 @@ int connect_socket(struct ClientSocket *client) {
     } else
         return 0;
     
+    if(get_int_field("Sockets.NoDelay")) {
+        int flag = 1;
+        if(setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) == -1) {
+            perror("setsockopt() failed");
+            return 0;
+        }
+    }
+    
     client->sock = sock;
     client->flags |= SOCKET_FLAG_CONNECTED | SOCKET_FLAG_RECONNECT;
     client->connection_time = time(0);
index b4aaa05f9d1dd594a334eb1cd79b6a4ae4e44641..ffd2be846f25b4b9bcfbda78ad3c06ddc99f072d 100644 (file)
@@ -41,6 +41,7 @@ CMD_BIND(global_cmd_bind);
 CMD_BIND(global_cmd_bots);
 CMD_BIND(global_cmd_command);
 CMD_BIND(global_cmd_commands);
+CMD_BIND(global_cmd_die);
 CMD_BIND(global_cmd_emote);
 CMD_BIND(global_cmd_god);
 CMD_BIND(global_cmd_motd);
@@ -48,6 +49,8 @@ CMD_BIND(global_cmd_netinfo);
 CMD_BIND(global_cmd_notice);
 CMD_BIND(global_cmd_raw);
 CMD_BIND(global_cmd_register);
+CMD_BIND(global_cmd_reload);
+CMD_BIND(global_cmd_restart);
 CMD_BIND(global_cmd_reloadlang);
 CMD_BIND(global_cmd_say);
 CMD_BIND(global_cmd_setaccess);
diff --git a/src/cmd_global_die.c b/src/cmd_global_die.c
new file mode 100644 (file)
index 0000000..5d2d02b
--- /dev/null
@@ -0,0 +1,27 @@
+/* cmd_global_die.c - NeonServ v5.2
+ * Copyright (C) 2011  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "cmd_global.h"
+
+/*
+* no args
+*/
+
+CMD_BIND(global_cmd_die) {
+    //hard work! :D
+    stop_bot(); 
+}
diff --git a/src/cmd_global_reload.c b/src/cmd_global_reload.c
new file mode 100644 (file)
index 0000000..7d363cb
--- /dev/null
@@ -0,0 +1,27 @@
+/* cmd_global_reload.c - NeonServ v5.2
+ * Copyright (C) 2011  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "cmd_global.h"
+
+/*
+* argv[0]  soft  (optional)
+*/
+
+CMD_BIND(global_cmd_reload) {
+    reload_config();
+    reply(client, user, "reloaded.");
+}
diff --git a/src/cmd_global_restart.c b/src/cmd_global_restart.c
new file mode 100644 (file)
index 0000000..81cb7dd
--- /dev/null
@@ -0,0 +1,28 @@
+/* cmd_global_restart.c - NeonServ v5.2
+ * Copyright (C) 2011  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "cmd_global.h"
+
+/*
+* argv[0]  soft  (optional)
+*/
+
+CMD_BIND(global_cmd_restart) {
+    int hard_restart = 1;
+    if(argc > 0 && !stricmp(argv[0], "soft")) hard_restart = 0;
+    restart_bot(hard_restart);
+}
index c41a673c233d8667ecd6ff61bdfecf3127b76e7d..ec5902c967719cddf6f020faebfb385f0ba45f46 100644 (file)
@@ -48,6 +48,9 @@ void register_commands() {
     OPER_COMMAND("unbind",       global_cmd_unbind,    1,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED | CMDFLAG_ESCAPE_ARGS);
     OPER_COMMAND("setaccess",    global_cmd_setaccess, 2,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
     OPER_COMMAND("bots",         global_cmd_bots,      0,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
+    OPER_COMMAND("reload",       global_cmd_reload,    0,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    OPER_COMMAND("restart",      global_cmd_restart,   0,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    OPER_COMMAND("die",          global_cmd_die,       0,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
     #undef OPER_COMMAND
     
     //NeonServ Commands
index 1728d00aeac1b47b0a947b7fcd6790a40fec6b8d..189cfd3f597a94fb9ebace10885559b624836e80 100644 (file)
@@ -38,7 +38,7 @@
 #include "ssl.h"
 
 time_t start_time;
-static int running;
+static int running, hard_restart;
 static int statistics_requested_lusers = 0;
 int statistics_enabled;
 TIMEQ_CALLBACK(main_statistics);
@@ -92,7 +92,7 @@ static int load_mysql_config() {
     return 1;
 }
 
-int main(void) {
+int main(int argc, char *argv[]) {
 main:
     
     start_time = time(0);
@@ -147,6 +147,14 @@ main:
         queue_loop();
     }
     cleanup();
+    if(hard_restart) {
+        /* Append a NULL to the end of argv[]. */
+        char **restart_argv = (char **)alloca((argc + 1) * sizeof(char *));
+        memcpy(restart_argv, argv, argc * sizeof(char *));
+        restart_argv[argc] = NULL;
+        
+        execv(argv[0], restart_argv);
+    }
     goto main;
 }
 
@@ -179,7 +187,8 @@ int stricmplen (const char *s1, const char *s2, int len)
    return c1 - c2;
 }
 
-void restart_bot(int hard_restart) {
+void restart_bot(int do_hard_restart) {
+    hard_restart = do_hard_restart;
     running = 0;
 }
 
index b4cf00f26cd7893c2082d9c9f8056cb509ecfe16..51986150719b5914edb794ed0d7c5850c234f026 100644 (file)
@@ -36,6 +36,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <netinet/tcp.h>
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <sys/wait.h>
@@ -111,7 +112,7 @@ extern int statistics_enabled;
 int stricmp (const char *s1, const char *s2);
 int stricmplen (const char *s1, const char *s2, int len);
 
-void restart_bot(int hard_restart);
+void restart_bot(int do_hard_restart);
 void stop_bot();
 void reload_config();