From 746c93f3677e0bc8526d69c0552f280edde93095 Mon Sep 17 00:00:00 2001 From: joonicks Date: Sun, 21 Sep 2025 16:26:51 +0200 Subject: [PATCH] minor related updates: warnings, hostinfo, calc, debug, ... --- src/core.c | 27 ++++++++++++++++++++++++++- src/global.h | 6 +++--- src/h.h | 4 ++-- src/io.c | 5 +++-- src/main.c | 4 ++++ src/spy.c | 11 ++++++++--- src/text.h | 3 ++- 7 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/core.c b/src/core.c index a38a1b0..024d87c 100644 --- a/src/core.c +++ b/src/core.c @@ -1,7 +1,7 @@ /* EnergyMech, IRC bot software - Parts Copyright (c) 1997-2018 proton + Parts Copyright (c) 1997-2024 proton 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 @@ -29,6 +29,10 @@ #include "mcmd.h" #include "settings.h" +#ifdef HOSTINFO +#include +#endif /* HOSTINFO */ + #ifdef IDWRAP void unlink_identfile(void) @@ -444,6 +448,13 @@ void signoff(char *from, char *reason) Free(¤t->lastcmds[i]); } + /* + * little of this n that + */ + Free((char**)¤t->nick); + Free((char**)¤t->wantnick); + Free((char**)¤t->userhost); + /* * These 2 are used by do_die() to pass reason and doer. */ @@ -1251,6 +1262,10 @@ void do_version(COMMAND_ARGS) void do_core(COMMAND_ARGS) { +#ifdef HOSTINFO + char *h,hostname[256]; + struct utsname un; +#endif /* HOSTINFO */ char tmp[MSGLEN]; /* big buffers at the top */ Server *sp; Chan *chan; @@ -1330,6 +1345,16 @@ void do_core(COMMAND_ARGS) table_buffer(TEXT_CURRSERVERNOT); table_buffer(TEXT_SERVERONTIME,idle2str(now - current->ontime,FALSE)); table_buffer(TEXT_BOTMODES,(*current->modes) ? current->modes : TEXT_NONE); +#ifdef HOSTINFO + hostname[255] = 0; + if (gethostname(hostname,250) < 0) + h = "(hostname error)"; + else + h = hostname; + + if (uname(&un) == 0) + table_buffer(TEXT_HOSTINFO,h,un.sysname,un.release,un.machine); +#endif /* HOSTINFO */ table_buffer(TEXT_CURRENTTIME,time2str(now)); table_buffer(TEXT_BOTSTARTED,time2str(uptime)); table_buffer(TEXT_BOTUPTIME,idle2str(now - uptime,FALSE)); diff --git a/src/global.h b/src/global.h index 2009c04..b8fca97 100644 --- a/src/global.h +++ b/src/global.h @@ -1,7 +1,7 @@ /* EnergyMech, IRC bot software - Copyright (c) 1997-2018 proton + Copyright (c) 1997-2024 proton 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 @@ -42,8 +42,8 @@ #define DEFAULTCMDCHAR '-' #define MECHUSERLOGIN "v3.energymech.net" -BEG const char VERSION[] MDEF("3.1p" GITHASH); -BEG const char SRCDATE[] MDEF("April 14th, 2018"); +BEG const char VERSION[] MDEF("3.2p" GITHASH); +BEG const char SRCDATE[] MDEF("May 13th, 2024"); #ifdef __CYGWIN__ BEG const char BOTCLASS[] MDEF("WinMech"); #else /* ! CYGWIN */ diff --git a/src/h.h b/src/h.h index ce8f159..dc1dc63 100644 --- a/src/h.h +++ b/src/h.h @@ -336,7 +336,7 @@ void select_monitor() __page(CORE_SEG); void process_monitor() __page(CORE_SEG); int parse_proc_status(char *line) __page(CMD1_SEG); int parse_proc_cpuinfo(char *line) __page(CMD1_SEG); -void do_hostinfo(COMMAND_ARGS) __page(CMD1_SEG); +void do_sysinfo(COMMAND_ARGS) __page(CMD1_SEG); void do_meminfo(COMMAND_ARGS) __page(CMD1_SEG); void do_cpuinfo(COMMAND_ARGS) __page(CMD1_SEG); void do_filemon(COMMAND_ARGS) __page(CMD1_SEG); @@ -419,7 +419,7 @@ LS void sig_segv(int) __attr(RARE_SEG, __noreturn__); #endif LS void sig_term(int) __attr(RARE_SEG, __noreturn__); /* rare */ LS void doit(void) __page(CORE_SEG); -LS int main(int argc, char **argv, char **envp) __page(CFG1_SEG); +LS int main(int argc, char **argv, char **envp) __page(INIT_SEG); /* net.c */ diff --git a/src/io.c b/src/io.c index 9a818ce..c4b686a 100644 --- a/src/io.c +++ b/src/io.c @@ -269,7 +269,7 @@ int SockAccept(int sock) /* * Format text and send to a socket or file descriptor */ -int to_file(int sock, const char *format, ...) +int to_file(const int sock, const char *format, ...) { va_list msg; #if defined(DEBUG) && !defined(GENCMD_C) @@ -357,7 +357,8 @@ void to_user_q(const char *target, const char *format, ...) if (STARTUP_ECHOTOCONSOLE) { - write(1,message,strlen(message)); + int n; + n = write(1,message,strlen(message)); return; } diff --git a/src/main.c b/src/main.c index c482471..e242532 100755 --- a/src/main.c +++ b/src/main.c @@ -1287,6 +1287,10 @@ int main(int argc, char **argv, char **envp) if (startup == STARTUP_TESTRUN) { +#ifdef DEBUG + if (debug_on_exit == TRUE) + run_debug(); +#endif /* DEBUG */ to_file(1,"init: test run completed, exiting...\n"); _exit(0); } diff --git a/src/spy.c b/src/spy.c index 0cf4631..633a82c 100644 --- a/src/spy.c +++ b/src/spy.c @@ -69,6 +69,9 @@ static int basepos(char c) return(63); return(0); } +#if defined(SHACRYPT) || defined(MD5CRYPT) +char *CRYPT_FUNC(const char *, const char *); +#endif void send_spy(const char *src, const char *format, ...) { @@ -130,12 +133,12 @@ void send_spy(const char *src, const char *format, ...) SHA-512 | 86 characters */ #ifdef SHACRYPT - sprintf(tempdata,"$6$%04x",(now & 0xFFFF)); + sprintf(tempdata,"$6$%04x",(uint32_t)(now & 0xFFFF)); rnd = CRYPT_FUNC(tempsrc,tempdata); #endif /* SHACRYPT */ #if !defined(SHACRYPT) && defined(MD5CRYPT) - sprintf(tempdata,"$1$%04x",(now & 0xFFFF)); + sprintf(tempdata,"$1$%04x",(uint32_t)(now & 0xFFFF)); rnd = CRYPT_FUNC(tempsrc,tempdata); #endif /* !SHACRYPT && MD5CRYPT */ @@ -164,7 +167,9 @@ void send_spy(const char *src, const char *format, ...) #endif /* DEBUG */ if ((fd = open(spy->dest,O_WRONLY|O_CREAT|O_APPEND,NEWFILEMODE)) >= 0) { - write(fd,tempdata,dst - tempdata); + int n; + + n = write(fd,tempdata,dst - tempdata); close(fd); } } diff --git a/src/text.h b/src/text.h index 54d343e..5680a30 100755 --- a/src/text.h +++ b/src/text.h @@ -1,7 +1,7 @@ /* EnergyMech, IRC bot software - Copyright (c) 2000-2018 proton + Copyright (c) 2000-2024 proton 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 @@ -102,6 +102,7 @@ #define TEXT_BOTUPTIME "Uptime\t%s" #define TEXT_BOTVERSION "Version\t%s (%s)" #define TEXT_BOTFEATURES "Features\t%s" +#define TEXT_HOSTINFO "Host\t%s %s %s %s" #define TEXT_CSERV "Current Server: %s:%i" #define TEXT_CSERVNOT "Current Server: " TEXT_NOTINSERVLIST