From aea92ef126cc0fe4433fa04805c06947f92e96d6 Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 11 Dec 2011 05:48:55 +0100 Subject: [PATCH] added cmd_restart cmd_reload and cmd_die; added Socket.NoDelay setting to configuration (maybe this speeds up the sockets a little bit more?) --- src/ClientSocket.c | 9 +++++++++ src/cmd_global.h | 3 +++ src/cmd_global_die.c | 27 +++++++++++++++++++++++++++ src/cmd_global_reload.c | 27 +++++++++++++++++++++++++++ src/cmd_global_restart.c | 28 ++++++++++++++++++++++++++++ src/commands.c | 3 +++ src/main.c | 15 ++++++++++++--- src/main.h | 3 ++- 8 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 src/cmd_global_die.c create mode 100644 src/cmd_global_reload.c create mode 100644 src/cmd_global_restart.c diff --git a/src/ClientSocket.c b/src/ClientSocket.c index abf11a1..5fa795e 100644 --- a/src/ClientSocket.c +++ b/src/ClientSocket.c @@ -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); diff --git a/src/cmd_global.h b/src/cmd_global.h index b4aaa05..ffd2be8 100644 --- a/src/cmd_global.h +++ b/src/cmd_global.h @@ -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 index 0000000..5d2d02b --- /dev/null +++ b/src/cmd_global_die.c @@ -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 . + */ + +#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 index 0000000..7d363cb --- /dev/null +++ b/src/cmd_global_reload.c @@ -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 . + */ + +#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 index 0000000..81cb7dd --- /dev/null +++ b/src/cmd_global_restart.c @@ -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 . + */ + +#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); +} diff --git a/src/commands.c b/src/commands.c index c41a673..ec5902c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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 diff --git a/src/main.c b/src/main.c index 1728d00..189cfd3 100644 --- a/src/main.c +++ b/src/main.c @@ -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; } diff --git a/src/main.h b/src/main.h index b4cf00f..5198615 100644 --- a/src/main.h +++ b/src/main.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -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(); -- 2.20.1