From: pk910 Date: Wed, 19 Dec 2012 13:34:00 +0000 (+0100) Subject: Merge remote-tracking branch 'origin/development' X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=1361faa990413b8f09967597ebe0a70dabeab0b3;hp=5cd595edf6322d8968be3709dab8ae84012fa79e Merge remote-tracking branch 'origin/development' --- diff --git a/Makefile.am b/Makefile.am index b03b830..679e1f6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -67,6 +67,7 @@ libNeonHelp_la_LIBADD = $(MYSQL_LIBS) libNeonBackup_la_SOURCES = src/modules/NeonBackup.mod/bot_NeonBackup.c \ src/modules/NeonBackup.mod/cmd_neonbackup.c \ + src/modules/NeonBackup.mod/cmd_neonbackup_recover.c \ src/modules/NeonBackup.mod/module.c libNeonBackup_la_LDFLAGS = -module -rpath /nowhere -avoid-version -no-undefined libNeonBackup_la_LIBADD = $(MYSQL_LIBS) diff --git a/neonserv.example.conf b/neonserv.example.conf index 9bab950..b10eca7 100644 --- a/neonserv.example.conf +++ b/neonserv.example.conf @@ -125,6 +125,7 @@ "protected" = 0; "hide_networkname" = 0; //hide network name "hide_botnick" = 0; //hide bot nick, ident, host + // "use_bot" = "BotNick"; //use this bot for the statistics "hide_chancount" = 0; //hide joined channel count "hide_usercount" = 0; //hide number of users the bot can see }; diff --git a/src/IOEngine_epoll.c b/src/IOEngine_epoll.c index e363949..d1c139f 100644 --- a/src/IOEngine_epoll.c +++ b/src/IOEngine_epoll.c @@ -83,8 +83,14 @@ static void engine_epoll_loop(struct timeval *timeout) { tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec; if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) { - iohandler_events(timer_priority, 0, 0); - iohandler_close(timer_priority); //also sets timer_priority to the next timed element + if(timer_priority->constant_timeout) { + tdiff.tv_sec = 0; + iohandler_set_timeout(timer_priority, &tdiff); + iohandler_events(timer_priority, 0, 0); + } else { + iohandler_events(timer_priority, 0, 0); + iohandler_close(timer_priority); //also sets timer_priority to the next timed element + } continue; } else if(tdiff.tv_usec < 0) { tdiff.tv_sec--; @@ -120,8 +126,14 @@ static void engine_epoll_loop(struct timeval *timeout) { tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec; if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) { - iohandler_events(timer_priority, 0, 0); - iohandler_close(timer_priority); //also sets timer_priority to the next timed element + if(timer_priority->constant_timeout) { + tdiff.tv_sec = 0; + iohandler_set_timeout(timer_priority, &tdiff); + iohandler_events(timer_priority, 0, 0); + } else { + iohandler_events(timer_priority, 0, 0); + iohandler_close(timer_priority); //also sets timer_priority to the next timed element + } continue; } break; diff --git a/src/IOEngine_kevent.c b/src/IOEngine_kevent.c index f729dbb..ee93f86 100644 --- a/src/IOEngine_kevent.c +++ b/src/IOEngine_kevent.c @@ -89,8 +89,14 @@ static void engine_kevent_loop(struct timeval *timeout) { tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec; if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) { - iohandler_events(timer_priority, 0, 0); - iohandler_close(timer_priority); //also sets timer_priority to the next timed element + if(timer_priority->constant_timeout) { + tdiff.tv_sec = 0; + iohandler_set_timeout(timer_priority, &tdiff); + iohandler_events(timer_priority, 0, 0); + } else { + iohandler_events(timer_priority, 0, 0); + iohandler_close(timer_priority); //also sets timer_priority to the next timed element + } continue; } else if(tdiff.tv_usec < 0) { tdiff.tv_sec--; @@ -130,8 +136,14 @@ static void engine_kevent_loop(struct timeval *timeout) { tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec; if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) { - iohandler_events(timer_priority, 0, 0); - iohandler_close(timer_priority); //also sets timer_priority to the next timed element + if(timer_priority->constant_timeout) { + tdiff.tv_sec = 0; + iohandler_set_timeout(timer_priority, &tdiff); + iohandler_events(timer_priority, 0, 0); + } else { + iohandler_events(timer_priority, 0, 0); + iohandler_close(timer_priority); //also sets timer_priority to the next timed element + } continue; } break; diff --git a/src/IOEngine_select.c b/src/IOEngine_select.c index 2d85d7c..aff5fb9 100644 --- a/src/IOEngine_select.c +++ b/src/IOEngine_select.c @@ -16,6 +16,7 @@ */ #include "IOEngine.h" #include +#include #ifdef WIN32 #define _WIN32_WINNT 0x501 #include @@ -25,8 +26,10 @@ #include #endif +static int engine_select_timer_delay_fix; + static int engine_select_init() { - /* empty */ + engine_select_timer_delay_fix = 0; return 1; } @@ -53,6 +56,7 @@ static void engine_select_loop(struct timeval *timeout) { struct IODescriptor *iofd, *tmp_iofd; struct timeval now, tdiff; int select_result; + int timer_fix; gettimeofday(&now, NULL); @@ -60,6 +64,7 @@ static void engine_select_loop(struct timeval *timeout) { FD_ZERO(&read_fds); FD_ZERO(&write_fds); + select_result = 0; for(iofd = first_descriptor; iofd; iofd = tmp_iofd) { tmp_iofd = iofd->next; if(iofd->type == IOTYPE_STDIN) { @@ -96,6 +101,7 @@ static void engine_select_loop(struct timeval *timeout) { if(iofd->fd > fds_size) fds_size = iofd->fd; FD_SET(iofd->fd, &read_fds); + select_result++; #endif } else if(iofd->type == IOTYPE_SERVER || iofd->type == IOTYPE_CLIENT) { @@ -104,6 +110,7 @@ static void engine_select_loop(struct timeval *timeout) { if(iofd->fd > fds_size) fds_size = iofd->fd; FD_SET(iofd->fd, &read_fds); + select_result++; if(iohandler_wants_writes(iofd)) FD_SET(iofd->fd, &write_fds); } @@ -113,8 +120,14 @@ static void engine_select_loop(struct timeval *timeout) { tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec; if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) { - iohandler_events(timer_priority, 0, 0); - iohandler_close(timer_priority); //also sets timer_priority to the next timed element + if(timer_priority->constant_timeout) { + tdiff.tv_sec = 0; + iohandler_set_timeout(timer_priority, &tdiff); + iohandler_events(timer_priority, 0, 0); + } else { + iohandler_events(timer_priority, 0, 0); + iohandler_close(timer_priority); //also sets timer_priority to the next timed element + } continue; } else if(tdiff.tv_usec < 0) { tdiff.tv_sec--; @@ -122,13 +135,28 @@ static void engine_select_loop(struct timeval *timeout) { } if(timeval_is_smaler((&tdiff), timeout)) { timeout->tv_sec = tdiff.tv_sec; - timeout->tv_usec = tdiff.tv_usec; + timeout->tv_usec = tdiff.tv_usec + engine_select_timer_delay_fix; + if(timeout->tv_usec < 0) { + timeout->tv_sec--; + timeout->tv_usec += 1000000; + } } break; } - //select system call - select_result = select(fds_size + 1, &read_fds, &write_fds, NULL, timeout); + if(select_result) { + //select system call + select_result = select(fds_size + 1, &read_fds, &write_fds, NULL, timeout); + } else { + #ifdef WIN32 + Sleep((timeout->tv_sec * 1000) + (timeout->tv_usec / 1000) + 1); + #else + struct timespec usleep_time; + usleep_time.tv_sec = timeout->tv_sec; + usleep_time.tv_nsec = timeout->tv_usec * 1000; + nanosleep(&usleep_time, NULL); + #endif + } if (select_result < 0) { if (errno != EINTR) { @@ -154,9 +182,20 @@ static void engine_select_loop(struct timeval *timeout) { while(timer_priority) { tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec; - if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) { - iohandler_events(timer_priority, 0, 0); - iohandler_close(timer_priority); //also sets timer_priority to the next timed element + timer_fix = (tdiff.tv_sec * 1000000) + tdiff.tv_usec; + if(timer_fix <= 100) { + if(timer_fix + 100 < engine_select_timer_delay_fix || timer_fix - 100 > engine_select_timer_delay_fix) { + engine_select_timer_delay_fix = ((engine_select_timer_delay_fix * 19) + timer_fix) / 20; + iohandler_log(IOLOG_DEBUG, "timer delay fix set to: %d us", engine_select_timer_delay_fix); + } + if(timer_priority->constant_timeout) { + tdiff.tv_sec = 0; + iohandler_set_timeout(timer_priority, &tdiff); + iohandler_events(timer_priority, 0, 0); + } else { + iohandler_events(timer_priority, 0, 0); + iohandler_close(timer_priority); //also sets timer_priority to the next timed element + } continue; } break; diff --git a/src/IOEngine_win32.c b/src/IOEngine_win32.c index bce6fc1..e29f8e5 100644 --- a/src/IOEngine_win32.c +++ b/src/IOEngine_win32.c @@ -63,8 +63,14 @@ static LRESULT CALLBACK engine_win32_wndproc(HWND hWnd, UINT uMsg, WPARAM wParam tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec; if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) { - iohandler_events(timer_priority, 0, 0); - iohandler_close(timer_priority); //also sets timer_priority to the next timed element + if(timer_priority->constant_timeout) { + tdiff.tv_sec = 0; + iohandler_set_timeout(timer_priority, &tdiff); + iohandler_events(timer_priority, 0, 0); + } else { + iohandler_events(timer_priority, 0, 0); + iohandler_close(timer_priority); //also sets timer_priority to the next timed element + } continue; } break; @@ -213,9 +219,15 @@ static void engine_win32_loop(struct timeval *timeout) { while(timer_priority) { tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec; tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec; - if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec < 1000)) { - iohandler_events(timer_priority, 0, 0); - iohandler_close(timer_priority); //also sets timer_priority to the next timed element + if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec < 100)) { + if(timer_priority->constant_timeout) { + tdiff.tv_sec = 0; + iohandler_set_timeout(timer_priority, &tdiff); + iohandler_events(timer_priority, 0, 0); + } else { + iohandler_events(timer_priority, 0, 0); + iohandler_close(timer_priority); //also sets timer_priority to the next timed element + } continue; } else if(tdiff.tv_usec < 0) { tdiff.tv_sec--; diff --git a/src/IOHandler.c b/src/IOHandler.c index 52b27b3..b2a391b 100644 --- a/src/IOHandler.c +++ b/src/IOHandler.c @@ -73,20 +73,30 @@ extern struct IOEngine engine_kevent; extern struct IOEngine engine_epoll; extern struct IOEngine engine_win32; +int iohandler_settings = 0; struct IOEngine *engine = NULL; +void iohandler_set(int setting, int value) { + if(value) + iohandler_settings |= setting; + else + iohandler_settings &= ~setting; +} + static void iohandler_init_engine() { if(engine) return; IOTHREAD_MUTEX_INIT(io_thread_sync); IOTHREAD_MUTEX_INIT(io_poll_sync); //try other engines - if(!engine && engine_kevent.init && engine_kevent.init()) - engine = &engine_kevent; - if(!engine && engine_epoll.init && engine_epoll.init()) - engine = &engine_epoll; - if(!engine && engine_win32.init && engine_win32.init()) - engine = &engine_win32; + if(!(iohandler_settings & IOHANDLER_SETTING_HIGH_PRECISION_TIMER)) { + if(!engine && engine_kevent.init && engine_kevent.init()) + engine = &engine_kevent; + if(!engine && engine_epoll.init && engine_epoll.init()) + engine = &engine_epoll; + if(!engine && engine_win32.init && engine_win32.init()) + engine = &engine_win32; + } if (!engine) { if(engine_select.init()) @@ -185,8 +195,13 @@ struct IODescriptor *iohandler_add(int sockfd, enum IOType type, struct timeval descriptor->type = type; descriptor->state = (type == IOTYPE_STDIN ? IO_CONNECTED : IO_CLOSED); descriptor->callback = callback; - if(timeout) + if(timeout) { descriptor->timeout = *timeout; + if(descriptor->timeout.tv_usec > 1000000) { + descriptor->timeout.tv_usec -= 1000000; + descriptor->timeout.tv_sec++; + } + } if(type != IOTYPE_TIMER) { descriptor->readbuf.buffer = malloc(IO_READ_BUFLEN + 2); descriptor->readbuf.bufpos = 0; @@ -220,9 +235,20 @@ void iohandler_set_timeout(struct IODescriptor *descriptor, struct timeval *time descriptor->next->prev = descriptor->prev; if(descriptor == timer_priority) timer_priority = descriptor->next; - if(timeout) + if(timeout && timeout->tv_sec == 0 && descriptor->constant_timeout) { + descriptor->timeout.tv_usec += (descriptor->constant_timeout % 1000) * 1000; + descriptor->timeout.tv_sec += (descriptor->constant_timeout / 1000); + if(descriptor->timeout.tv_usec > 1000000) { + descriptor->timeout.tv_sec += (descriptor->timeout.tv_usec / 1000000); + descriptor->timeout.tv_usec %= 1000000; + } + } else if(timeout) { descriptor->timeout = *timeout; - else { + if(descriptor->timeout.tv_usec > 1000000) { + descriptor->timeout.tv_usec -= 1000000; + descriptor->timeout.tv_sec++; + } + } else { descriptor->timeout.tv_sec = 0; descriptor->timeout.tv_usec = 0; } @@ -249,6 +275,26 @@ struct IODescriptor *iohandler_timer(struct timeval timeout, iohandler_callback return descriptor; } +struct IODescriptor *iohandler_constant_timer(int msec, iohandler_callback *callback) { + struct IODescriptor *descriptor; + struct timeval timeout; + gettimeofday(&timeout, NULL); + timeout.tv_usec += (msec % 1000) * 1000; + timeout.tv_sec += (msec / 1000); + if(timeout.tv_usec > 1000000) { + timeout.tv_sec += (timeout.tv_usec / 1000000); + timeout.tv_usec %= 1000000; + } + descriptor = iohandler_add(-1, IOTYPE_TIMER, &timeout, callback); + if(!descriptor) { + iohandler_log(IOLOG_ERROR, "could not allocate memory for IODescriptor in %s:%d", __FILE__, __LINE__); + return NULL; + } + descriptor->constant_timeout = msec; + iohandler_log(IOLOG_DEBUG, "added timer descriptor (sec: %d; usec: %d)", timeout.tv_sec, timeout.tv_usec); + return descriptor; +} + struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, int ssl, const char *bindhost, iohandler_callback *callback) { return iohandler_connect_flags(hostname, port, ssl, bindhost, callback, IOHANDLER_CONNECT_IPV4 | IOHANDLER_CONNECT_IPV6); } diff --git a/src/IOHandler.h b/src/IOHandler.h index 9542985..82781d6 100644 --- a/src/IOHandler.h +++ b/src/IOHandler.h @@ -83,6 +83,7 @@ struct IODescriptor { enum IOType type; enum IOStatus state; struct timeval timeout; + int constant_timeout; iohandler_callback *callback; struct IOBuffer readbuf; struct IOBuffer writebuf; @@ -115,8 +116,13 @@ struct IOEvent { #define IOHANDLER_CONNECT_IPV4 0x01 #define IOHANDLER_CONNECT_IPV6 0x02 /* overrides IOHANDLER_CONNECT_IPV4 */ +#define IOHANDLER_SETTING_HIGH_PRECISION_TIMER 0x01 + +void iohandler_set(int setting, int value); + struct IODescriptor *iohandler_add(int sockfd, enum IOType type, struct timeval *timeout, iohandler_callback *callback); struct IODescriptor *iohandler_timer(struct timeval timeout, iohandler_callback *callback); +struct IODescriptor *iohandler_constant_timer(int msec, iohandler_callback *callback); struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, int ssl, const char *bind, iohandler_callback *callback); struct IODescriptor *iohandler_connect_flags(const char *hostname, unsigned int port, int ssl, const char *bindhost, iohandler_callback *callback, int flags); struct IODescriptor *iohandler_listen(const char *hostname, unsigned int port, iohandler_callback *callback); diff --git a/src/IOHandler_SSL.c b/src/IOHandler_SSL.c index 5d87cec..5408e97 100644 --- a/src/IOHandler_SSL.c +++ b/src/IOHandler_SSL.c @@ -16,13 +16,12 @@ */ #include "IOEngine.h" #include "IOHandler_SSL.h" +#ifdef HAVE_SSL void iohandler_ssl_init() { -#ifdef HAVE_SSL SSL_library_init(); OpenSSL_add_all_algorithms(); /* load & register all cryptos, etc. */ SSL_load_error_strings(); -#endif } static void iohandler_ssl_error() { @@ -33,7 +32,6 @@ static void iohandler_ssl_error() { } void iohandler_ssl_connect(struct IODescriptor *iofd) { -#ifdef HAVE_SSL iofd->state = IO_SSLWAIT; iofd->ssl_server_hs = 0; struct IOSSLNode *sslnode = malloc(sizeof(*sslnode)); @@ -61,11 +59,9 @@ void iohandler_ssl_connect(struct IODescriptor *iofd) { ssl_connect_err: free(sslnode); iohandler_events(iofd, 0, 0); -#endif } void iohandler_ssl_listen(struct IODescriptor *iofd, const char *certfile, const char *keyfile) { -#ifdef HAVE_SSL struct IOSSLNode *sslnode = malloc(sizeof(*sslnode)); sslnode->sslContext = SSL_CTX_new(SSLv23_server_method()); if(!sslnode->sslContext) { @@ -97,11 +93,9 @@ ssl_listen_err: free(sslnode); iofd->sslnode = NULL; iohandler_events(iofd, 0, 0); -#endif } void iohandler_ssl_client_handshake(struct IODescriptor *iofd) { -#ifdef HAVE_SSL // Perform an SSL handshake. int ret = SSL_do_handshake(iofd->sslnode->sslHandle); iofd->ssl_hs_read = 0; @@ -126,11 +120,9 @@ void iohandler_ssl_client_handshake(struct IODescriptor *iofd) { iohandler_events(iofd, 0, 0); break; } -#endif } void iohandler_ssl_client_accepted(struct IODescriptor *iofd, struct IODescriptor *client_iofd) { -#ifdef HAVE_SSL struct IOSSLNode *sslnode = malloc(sizeof(*sslnode)); sslnode->sslHandle = SSL_new(sslnode->sslContext); if(!sslnode->sslHandle) { @@ -153,11 +145,9 @@ void iohandler_ssl_client_accepted(struct IODescriptor *iofd, struct IODescripto ssl_accept_err: iohandler_close(client_iofd); free(sslnode); -#endif } void iohandler_ssl_server_handshake(struct IODescriptor *iofd) { -#ifdef HAVE_SSL // Perform an SSL handshake. int ret = SSL_accept(iofd->sslnode->sslHandle); iofd->ssl_hs_read = 0; @@ -182,11 +172,9 @@ void iohandler_ssl_server_handshake(struct IODescriptor *iofd) { iohandler_events(iofd, 0, 0); break; } -#endif } void iohandler_ssl_disconnect(struct IODescriptor *iofd) { -#ifdef HAVE_SSL if(!iofd->sslnode) return; SSL_shutdown(iofd->sslnode->sslHandle); SSL_free(iofd->sslnode->sslHandle); @@ -194,11 +182,9 @@ void iohandler_ssl_disconnect(struct IODescriptor *iofd) { free(iofd->sslnode); iofd->sslnode = NULL; iofd->ssl_active = 0; -#endif } int iohandler_ssl_read(struct IODescriptor *iofd, char *buffer, int len) { -#ifdef HAVE_SSL if(!iofd->sslnode) return 0; int ret = SSL_read(iofd->sslnode->sslHandle, buffer, len); int update = (iofd->ssl_hs_read || iofd->ssl_hs_write); @@ -230,12 +216,9 @@ int iohandler_ssl_read(struct IODescriptor *iofd, char *buffer, int len) { return -1; break; } -#endif - return 0; } int iohandler_ssl_write(struct IODescriptor *iofd, char *buffer, int len) { -#ifdef HAVE_SSL if(!iofd->sslnode) return 0; int ret = SSL_write(iofd->sslnode->sslHandle, buffer, len); int update = (iofd->ssl_hs_read || iofd->ssl_hs_write); @@ -267,6 +250,18 @@ int iohandler_ssl_write(struct IODescriptor *iofd, char *buffer, int len) { return -1; break; } -#endif - return 0; } + +#else +// NULL-backend + +void iohandler_ssl_init() {}; +void iohandler_ssl_connect(struct IODescriptor *iofd) {}; +void iohandler_ssl_listen(struct IODescriptor *iofd, const char *certfile, const char *keyfile) {}; +void iohandler_ssl_client_handshake(struct IODescriptor *iofd) {}; +void iohandler_ssl_client_accepted(struct IODescriptor *iofd, struct IODescriptor *client_iofd) {}; +void iohandler_ssl_server_handshake(struct IODescriptor *iofd) {}; +void iohandler_ssl_disconnect(struct IODescriptor *iofd) {}; +int iohandler_ssl_read(struct IODescriptor *iofd, char *buffer, int len) { return 0; }; +int iohandler_ssl_write(struct IODescriptor *iofd, char *buffer, int len) { return 0; }; +#endif diff --git a/src/modules/NeonBackup.mod/cmd_neonbackup.c b/src/modules/NeonBackup.mod/cmd_neonbackup.c index 9234854..f78bf37 100644 --- a/src/modules/NeonBackup.mod/cmd_neonbackup.c +++ b/src/modules/NeonBackup.mod/cmd_neonbackup.c @@ -23,6 +23,9 @@ void register_commands() { //NeonBackup Commands register_command_alias(6, "NeonBackup"); - + #define OPER_COMMAND(NAME,FUNCTION,PARAMCOUNT,GACCESS,FLAGS) register_command(6, NAME, module_id, FUNCTION, PARAMCOUNT, NULL, GACCESS, FLAGS) + // NAME FUNCTION PARAMS ACCS FLAGS + OPER_COMMAND("recover", neonbackup_cmd_recover, 0, 900, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH); + #undef OPER_COMMAND } \ No newline at end of file diff --git a/src/modules/NeonBackup.mod/cmd_neonbackup.h b/src/modules/NeonBackup.mod/cmd_neonbackup.h index fed816d..d6f1763 100644 --- a/src/modules/NeonBackup.mod/cmd_neonbackup.h +++ b/src/modules/NeonBackup.mod/cmd_neonbackup.h @@ -32,5 +32,6 @@ void register_commands(); +CMD_BIND(neonbackup_cmd_recover); #endif diff --git a/src/modules/NeonBackup.mod/cmd_neonbackup_recover.c b/src/modules/NeonBackup.mod/cmd_neonbackup_recover.c new file mode 100644 index 0000000..dc71276 --- /dev/null +++ b/src/modules/NeonBackup.mod/cmd_neonbackup_recover.c @@ -0,0 +1,56 @@ +/* cmd_neonbackup_recover.c - NeonServ v5.6 + * Copyright (C) 2011-2012 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_neonbackup.h" + +/* +* no argv +*/ +static struct ClientSocket *neonbackup_cmd_recover_get_bot(int clientid) { + struct ClientSocket *bot; + for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) { + if(bot->clientid == clientid) + return bot; + } + return NULL; +} + +CMD_BIND(neonbackup_cmd_recover) { + MYSQL_RES *res; + MYSQL_ROW row; + printf_mysql_query("SELECT `channels`.`channel_name`, `bots`.`id` FROM `bot_channels`, `bots`, `channels` WHERE `bots`.`id` = `botid` AND `channel_id` = `chanid` AND `active` = 1"); + res = mysql_use(); + + struct ClientSocket *bot; + struct ChanUser *chanuser; + while ((row = mysql_fetch_row(res)) != NULL) { + chan = getChanByName(row[0]); + if(!chan) + continue; + bot = neonbackup_cmd_recover_get_bot(atoi(row[1])); + if(!bot) + continue; + if(!(chanuser = getChanUser(bot->user, chan))) { + requestInvite(bot->user, chan); + reply(textclient, user, "NS_INVITE_DONE", bot->user->nick, chan->name); + } else if(!chanuser->flags & CHANUSERFLAG_OPPED) { + requestOp(bot->user, chan); + reply(textclient, user, "NS_OP_DONE", chan->name); + } + } + logEvent(event); +} diff --git a/src/modules/NeonServ.mod/bot_NeonServ.c b/src/modules/NeonServ.mod/bot_NeonServ.c index c3cb123..ca2a308 100644 --- a/src/modules/NeonServ.mod/bot_NeonServ.c +++ b/src/modules/NeonServ.mod/bot_NeonServ.c @@ -243,7 +243,7 @@ static const struct default_language_entry msgtab[] = { {"NS_RESYNC_DONE", "Synchronized users in $b%s$b with the userlist."}, /* {ARGS: "#TestChan"} */ {"NS_TIMEBAN_DURATION_TOO_SHORT", "You must specify a ban duration of at least %d seconds."}, /* {ARGS: 30} */ {"NS_TIMEBAN_DONE", "Banned $b%s$b from %s for %s. (matching %d users)"}, /* {ARGS: "*!*@bla*", "#TestChan", "2 hours", 5} */ - {"NS_MODE_INVALID", "$b%c$b is an invalid set of channel modes."}, /* {ARGS: "+xyz"} */ + {"NS_MODE_INVALID", "$b%s$b is an invalid set of channel modes."}, /* {ARGS: "+xyz"} */ {"NS_MODE_LOCKED", "Modes conflicting with $b%s$b are not allowed in %s."}, /* {ARGS: "+xyz", "#TestChan"} */ {"NS_MODE_DONE", "Channel modes are now $b%s$b."}, /* {ARGS: "+xyz"} */ {"NS_MODE_ENFOPS", "You may not op or deop users on $b%s$b."}, /* {ARGS: "#TestChan"} */ @@ -358,7 +358,7 @@ static const struct default_language_entry msgtab[] = { {"NS_NICKLIST_NICK", "Nick"}, {"NS_NICKLIST_STATE", "State"}, {"NS_NICKLIST_ACCESS", "Access"}, - {"NS_NICKLIST_SYNC", "use `nicklist sync` to fix all red and orange entrys in the list above (add opped users with %d and voiced with %d access)"}, + {"NS_NICKLIST_SYNC", "use `nicklist sync` to fix all red and orange entrys in the list above (add opped users with %d and voiced with %d access)"}, /* {ARGS: 200, 100} */ {"NS_NICKLIST_ACCESS_BOT", "Bot"}, {"NS_NICKLIST_ACCESS_OPER", "Operator"}, {"NS_SETBOT_UNKNOWN", "`%d` is an unknown botid."}, /* {ARGS: 50} */ diff --git a/src/modules/global.mod/cmd_global_version.c b/src/modules/global.mod/cmd_global_version.c index da7968b..9cc3392 100644 --- a/src/modules/global.mod/cmd_global_version.c +++ b/src/modules/global.mod/cmd_global_version.c @@ -27,10 +27,13 @@ CMD_BIND(global_cmd_version) { reply(textclient, user, "NeonServ can be found on: http://dev.pk910.de/NeonServ"); //helpers :D reply(textclient, user, "special thanks to:"); - reply(textclient, user, " Zer0n, TeaTow, Phil (testing and ideas current version)"); - reply(textclient, user, " Buschman, Zer0n, Neon (translating current version)"); - reply(textclient, user, " Patschi95, DerGrinch, Darkfly, Zer0n, Buschman (testing and ideas older versions)"); - reply(textclient, user, " Buschman, Georg, richard (translating older versions)"); + reply(textclient, user, " Testing and Ideas:"); + reply(textclient, user, " Zer0n, TeaTow, Phil, Stricted"); + reply(textclient, user, " Translations:"); + reply(textclient, user, " Buschman (de), Zer0n (de), Neon (de), TheFlie (nl), GodsWarriors (pt)"); + reply(textclient, user, " Others:"); + reply(textclient, user, " Patschi95, DerGrinch, Darkfly, Zer0n, Buschman (testing and ideas older versions)"); + reply(textclient, user, " Buschman, Georg, richard (translating older versions)"); reply(textclient, user, "and all the other users that reported all these nasty bugs :D"); reply(textclient, user, "\002If you found a bug or if you have a good idea report it on http://dev.pk910.de/BugTrack\002"); diff --git a/src/modules/stats.mod/module.c b/src/modules/stats.mod/module.c index c81e3a6..4780077 100644 --- a/src/modules/stats.mod/module.c +++ b/src/modules/stats.mod/module.c @@ -94,21 +94,27 @@ static TIMEQ_CALLBACK(stats_timer_callback) { if(get_int_field(tmp)) pkgpos += sprintf(pkgbuf + pkgpos, "*\n"); else { - struct ClientSocket *bot, *bot1 = NULL, *bot2 = NULL, *bot3 = NULL; + sprintf(tmp, "modules/%s/use_bot", modname); + char *botname = get_string_field(tmp); + struct ClientSocket *bot, *bot1 = NULL, *bot2 = NULL, *bot3 = NULL, *bot4 = NULL; for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) { - if(bot->botid == 1 && (bot->flags & SOCKET_FLAG_PREFERRED)) + if(botname && !stricmp(bot->nick, botname)) bot1 = bot; - else if((bot->flags & SOCKET_FLAG_PREFERRED)) + else if(bot->botid == 1 && (bot->flags & SOCKET_FLAG_PREFERRED)) bot2 = bot; - else + else if((bot->flags & SOCKET_FLAG_PREFERRED)) bot3 = bot; + else + bot4 = bot; } if(bot1) bot = bot1; else if(bot2) bot = bot2; - else + else if(bot3) bot = bot3; + else + bot = bot4; if(bot) { pkgpos += sprintf(pkgbuf + pkgpos, "%s!%s@%s %d\n", (bot->user ? bot->user->nick : "*"), (bot->user ? bot->user->ident : "*"), (bot->host ? bot->host : "*"), bot->port); } else diff --git a/src/overall.h b/src/overall.h index ff6f408..55b48ea 100644 --- a/src/overall.h +++ b/src/overall.h @@ -142,7 +142,7 @@ #define MAXLOGLEN 1024 #define TRIGGERLEN 50 #define MAXNUMPARAMS 200 /* maximum number of parameters in one line */ -#define MAXLANGUAGES 5 +#define MAXLANGUAGES 15 #define MAXMODES 6 #define INVITE_TIMEOUT 30 #define BOTWAR_DETECTION_TIME 7 diff --git a/src/test/Makefile b/src/test/Makefile deleted file mode 100644 index 37fa3d8..0000000 --- a/src/test/Makefile +++ /dev/null @@ -1,12 +0,0 @@ - -CC = gcc -CFLAGS = -g -O0 -Wall -Wshadow -Werror -DHAVE_PTHREAD_H -LDFLAGS = -lws2_32 -lpthread - -OBJ = ../IOEngine_epoll.o ../IOEngine_kevent.o ../IOEngine_select.o ../IOEngine_win32.o ../IOHandler.o ../IOHandler_SSL.o iotest.o - -all: $(OBJ) - $(CC) $(CFLAGS) -oiotest $(OBJ) $(LDFLAGS) - -%.o: %.c - $(CC) $(CFLAGS) -o$@ -c $< diff --git a/src/test/iotest.c b/src/test/iotest.c deleted file mode 100644 index 15f32f4..0000000 --- a/src/test/iotest.c +++ /dev/null @@ -1,63 +0,0 @@ -/* main.c - IOMultiplexer - * Copyright (C) 2012 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 -#include "../IOHandler.h" - -static IOHANDLER_CALLBACK(io_callback); -static IOHANDLER_LOG_BACKEND(io_log); - -static struct IODescriptor *irc_iofd = NULL; - -int main(int argc, char *argv[]) { - iolog_backend = io_log; - - irc_iofd = iohandler_connect("pk910.de", 6667, 0, NULL, io_callback); - - struct IODescriptor *iofd; - iofd = iohandler_add(0, IOTYPE_STDIN, NULL, io_callback); - iofd->read_lines = 1; - - while(1) { - iohandler_poll(); - } -} - -static IOHANDLER_CALLBACK(io_callback) { - switch(event->type) { - case IOEVENT_CONNECTED: - printf("[connect]\n"); - break; - case IOEVENT_CLOSED: - printf("[disconnect]\n"); - break; - case IOEVENT_RECV: - if(event->iofd->type == IOTYPE_STDIN) { - iohandler_printf(irc_iofd, "%s\n", event->data.recv_str); - printf("[out] %s\n", event->data.recv_str); - } else - printf("[in] %s\n", event->data.recv_str); - break; - - default: - break; - } -} - -static IOHANDLER_LOG_BACKEND(io_log) { - //printf("%s", line); -} diff --git a/src/test/socket/Makefile b/src/test/socket/Makefile new file mode 100644 index 0000000..724e34b --- /dev/null +++ b/src/test/socket/Makefile @@ -0,0 +1,12 @@ + +CC = gcc +CFLAGS = -g -O0 -Wall -Wshadow -Werror -DHAVE_PTHREAD_H +LDFLAGS = -lws2_32 -lpthread + +OBJ = ../../IOEngine_epoll.o ../../IOEngine_kevent.o ../../IOEngine_select.o ../../IOEngine_win32.o ../../IOHandler.o ../../IOHandler_SSL.o iotest.o + +all: $(OBJ) + $(CC) $(CFLAGS) -oiotest $(OBJ) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -o$@ -c $< diff --git a/src/test/socket/iotest.c b/src/test/socket/iotest.c new file mode 100644 index 0000000..15f32f4 --- /dev/null +++ b/src/test/socket/iotest.c @@ -0,0 +1,63 @@ +/* main.c - IOMultiplexer + * Copyright (C) 2012 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 +#include "../IOHandler.h" + +static IOHANDLER_CALLBACK(io_callback); +static IOHANDLER_LOG_BACKEND(io_log); + +static struct IODescriptor *irc_iofd = NULL; + +int main(int argc, char *argv[]) { + iolog_backend = io_log; + + irc_iofd = iohandler_connect("pk910.de", 6667, 0, NULL, io_callback); + + struct IODescriptor *iofd; + iofd = iohandler_add(0, IOTYPE_STDIN, NULL, io_callback); + iofd->read_lines = 1; + + while(1) { + iohandler_poll(); + } +} + +static IOHANDLER_CALLBACK(io_callback) { + switch(event->type) { + case IOEVENT_CONNECTED: + printf("[connect]\n"); + break; + case IOEVENT_CLOSED: + printf("[disconnect]\n"); + break; + case IOEVENT_RECV: + if(event->iofd->type == IOTYPE_STDIN) { + iohandler_printf(irc_iofd, "%s\n", event->data.recv_str); + printf("[out] %s\n", event->data.recv_str); + } else + printf("[in] %s\n", event->data.recv_str); + break; + + default: + break; + } +} + +static IOHANDLER_LOG_BACKEND(io_log) { + //printf("%s", line); +} diff --git a/src/test/timer/Makefile b/src/test/timer/Makefile new file mode 100644 index 0000000..724e34b --- /dev/null +++ b/src/test/timer/Makefile @@ -0,0 +1,12 @@ + +CC = gcc +CFLAGS = -g -O0 -Wall -Wshadow -Werror -DHAVE_PTHREAD_H +LDFLAGS = -lws2_32 -lpthread + +OBJ = ../../IOEngine_epoll.o ../../IOEngine_kevent.o ../../IOEngine_select.o ../../IOEngine_win32.o ../../IOHandler.o ../../IOHandler_SSL.o iotest.o + +all: $(OBJ) + $(CC) $(CFLAGS) -oiotest $(OBJ) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -o$@ -c $< diff --git a/src/test/timer/iotest.c b/src/test/timer/iotest.c new file mode 100644 index 0000000..17a91ec --- /dev/null +++ b/src/test/timer/iotest.c @@ -0,0 +1,81 @@ +/* main.c - IOMultiplexer + * Copyright (C) 2012 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 +#include "../../IOHandler.h" + +#define TEST_DURATION 100 + +static IOHANDLER_CALLBACK(io_callback); +static IOHANDLER_LOG_BACKEND(io_log); + +static struct timeval test_clock1, test_clock2; +static int timercount; + +void add_timer(int ms) { + struct timeval timeout; + gettimeofday(&timeout, NULL); + timeout.tv_usec += (ms % 1000) * 1000; + timeout.tv_sec += (ms / 1000); + if(timeout.tv_usec > 1000000) { + timeout.tv_usec -= 1000000; + timeout.tv_sec++; + } + iohandler_timer(timeout, io_callback); +} + +int main(int argc, char *argv[]) { + iolog_backend = io_log; + + iohandler_set(IOHANDLER_SETTING_HIGH_PRECISION_TIMER, 1); + + gettimeofday(&test_clock1, NULL); + gettimeofday(&test_clock2, NULL); + //add_timer(TEST_DURATION); + iohandler_constant_timer(TEST_DURATION, io_callback); + timercount = 0; + + printf("[timer 0] %ld.%ld\n", test_clock1.tv_sec, test_clock1.tv_usec); + + while(1) { + iohandler_poll(); + } +} + +static IOHANDLER_CALLBACK(io_callback) { + struct timeval curr_time; + int diff1; + double diff2; + switch(event->type) { + case IOEVENT_TIMEOUT: + //add_timer(TEST_DURATION); + timercount++; + gettimeofday(&curr_time, NULL); + diff1 = (curr_time.tv_sec - test_clock1.tv_sec) * 1000 + ((curr_time.tv_usec - test_clock1.tv_usec) / 1000); + diff2 = (curr_time.tv_sec - test_clock2.tv_sec) * 1000 + ((curr_time.tv_usec - test_clock2.tv_usec) / 1000.0); + diff2 -= (timercount * TEST_DURATION); + gettimeofday(&test_clock1, NULL); + printf("[timer %03d] %ld.%06ld [%d ms] accuracy: %f ms\n", timercount, curr_time.tv_sec, curr_time.tv_usec, diff1, diff2); + break; + default: + break; + } +} + +static IOHANDLER_LOG_BACKEND(io_log) { + //printf("%s", line); +}