#include "crule.h"
#include "hash.h"
#include "ircd_alloc.h"
+#include "ircd_features.h"
#include "ircd_log.h"
#include "ircd_reply.h"
#include "ircd_signal.h"
* Global data (YUCK!)
*--------------------------------------------------------------------------*/
struct Client me; // That's me
+struct Connection me_con; // That's me too
struct Client *GlobalClientList = &me; // Pointer to beginning of Client list
time_t TSoffset = 0; // Offset of timestamps to system clock
int GlobalRehashFlag = 0; // do a rehash if set
* API: server_die
*--------------------------------------------------------------------------*/
void server_die(const char* message) {
- ircd_log(L_CRIT, "Server terminating: %s", message);
- sendto_opmask_butone(0, SNO_OLDSNO, "Server terminating: %s", message);
+ /* log_write will send out message to both log file and as server notice */
+ log_write(LS_SYSTEM, L_CRIT, 0, "Server terminating: %s", message);
flush_connections(0);
close_connections(1);
thisServer.running = 0;
void server_restart(const char* message) {
static int restarting = 0;
- ircd_log(L_WARNING, "Restarting Server: %s", message);
- if (restarting)
+ /* inhibit sending any server notices; we may be in a loop */
+ log_write(LS_SYSTEM, L_WARNING, LOG_NOSNOTICE, "Restarting Server: %s",
+ message);
+ if (restarting++) /* increment restarting to prevent looping */
return;
sendto_opmask_butone(0, SNO_OLDSNO, "Restarting server: %s", message);
/* Have to reopen since it has been closed above */
log_reopen();
- ircd_log(L_CRIT, "execv(%s,%s) failed: %m\n", SPATH, *thisServer.argv);
+ log_write(LS_SYSTEM, L_CRIT, 0, "execv(%s,%s) failed: %m", SPATH,
+ *thisServer.argv);
Debug((DEBUG_FATAL, "Couldn't restart server \"%s\": %s",
SPATH, (strerror(errno)) ? strerror(errno) : ""));
static void write_pidfile(void) {
FILE *pidf;
- if (!(pidf = fopen(PPATH, "w+"))) {
+ if (!(pidf = fopen(feature_str(FEAT_PPATH), "w+"))) {
Debug((DEBUG_NOTICE,
- "Error opening pid file \"%s\": %s", PPATH, strerror(errno)));
+ "Error opening pid file \"%s\": %s", feature_str(FEAT_PPATH),
+ strerror(errno)));
return;
}
if (fprintf(pidf, "%5d\n", getpid()) < 5)
- Debug((DEBUG_NOTICE, "Error writing to pid file %s", PPATH));
+ Debug((DEBUG_NOTICE, "Error writing to pid file %s",
+ feature_str(FEAT_PPATH)));
fclose(pidf);
}
/* Remove dead clients. */
if (IsDead(cptr)) {
- exit_client(cptr, cptr, &me, cptr->info);
+ exit_client(cptr, cptr, &me, cli_info(cptr));
continue;
}
max_ping = IsRegistered(cptr) ? client_get_ping(cptr) : CONNECTTIMEOUT;
Debug((DEBUG_DEBUG, "check_pings(%s)=status:%s limit: %d current: %d",
- cptr->name, (cptr->flags & FLAGS_PINGSENT) ? "[Ping Sent]" : "[]",
- max_ping, (int)(CurrentTime - cptr->lasttime)));
+ cli_name(cptr), (cli_flags(cptr) & FLAGS_PINGSENT) ? "[Ping Sent]" : "[]",
+ max_ping, (int)(CurrentTime - cli_lasttime(cptr))));
/* Ok, the thing that will happen most frequently, is that someone will
* have sent something recently. Cover this first for speed.
*/
- if (CurrentTime-cptr->lasttime < max_ping) {
- expire = cptr->lasttime + max_ping;
+ if (CurrentTime-cli_lasttime(cptr) < max_ping) {
+ expire = cli_lasttime(cptr) + max_ping;
if (expire < next_check)
next_check = expire;
continue;
}
/* Quit the client after max_ping*2 - they should have answered by now */
- if (CurrentTime-cptr->lasttime >= (max_ping*2) ) {
+ if (CurrentTime-cli_lasttime(cptr) >= (max_ping*2) ) {
/* If it was a server, then tell ops about it. */
if (IsServer(cptr) || IsConnecting(cptr) || IsHandshake(cptr))
sendto_opmask_butone(0, SNO_OLDSNO,
- "No response from %s, closing link", cptr->name);
+ "No response from %s, closing link", cli_name(cptr));
exit_client_msg(cptr, cptr, &me, "Ping timeout");
continue;
}
/* Display message if they have sent a NICK and a USER but no
* nospoof PONG.
*/
- if (*cptr->name && cptr->user && *cptr->user->username) {
+ if (*(cli_name(cptr)) && cli_user(cptr) && *(cli_user(cptr))->username) {
send_reply(cptr, SND_EXPLICIT | ERR_BADPING,
":Your client may not be compatible with this server.");
send_reply(cptr, SND_EXPLICIT | ERR_BADPING,
continue;
}
- if (!(cptr->flags & FLAGS_PINGSENT)) {
+ if (!(cli_flags(cptr) & FLAGS_PINGSENT)) {
/* If we havent PINGed the connection and we havent heard from it in a
* while, PING it to make sure it is still alive.
*/
- cptr->flags |= FLAGS_PINGSENT;
+ cli_flags(cptr) |= FLAGS_PINGSENT;
/* If we're late in noticing don't hold it against them :) */
- cptr->lasttime = CurrentTime - max_ping;
+ cli_lasttime(cptr) = CurrentTime - max_ping;
if (IsUser(cptr))
- sendrawto_one(cptr, MSG_PING " :%s", me.name);
+ sendrawto_one(cptr, MSG_PING " :%s", cli_name(&me));
else
- sendcmdto_one(&me, CMD_PING, cptr, ":%s", me.name);
+ sendcmdto_one(&me, CMD_PING, cptr, ":%s", cli_name(&me));
}
- expire = cptr->lasttime + max_ping * 2;
+ expire = cli_lasttime(cptr) + max_ping * 2;
if (expire < next_check)
next_check=expire;
}
case 't': thisServer.bootopt |= BOOT_TTY; break;
case 'd': dpath = optarg; break;
case 'f': configfile = optarg; break;
- case 'h': ircd_strncpy(me.name, optarg, HOSTLEN); break;
+ case 'h': ircd_strncpy(cli_name(&me), optarg, HOSTLEN); break;
case 'v': printf("ircd %s\n", version); exit(0);
case 'x':
umask(077); /* better safe than sorry --SRB */
memset(&me, 0, sizeof(me));
- me.fd = -1;
+ memset(&me_con, 0, sizeof(me_con));
+ cli_connect(&me) = &me_con;
+ cli_fd(&me) = -1;
parse_command_line(argc, argv);
/* Check paths for accessibility */
if (!check_file_access(SPATH, 'S', X_OK) ||
- !check_file_access(configfile, 'C', R_OK) ||
- !check_file_access(MPATH, 'M', R_OK) ||
- !check_file_access(RPATH, 'R', R_OK))
+ !check_file_access(configfile, 'C', R_OK))
return 4;
#ifdef DEBUG
daemon_init(thisServer.bootopt & BOOT_TTY);
setup_signals();
+ feature_mark(); /* initialize features... */
log_init(*argv);
set_nomem_handler(outofmemory);
if (!init_string()) {
- ircd_log(L_CRIT, "Failed to initialize string module");
+ log_write(LS_SYSTEM, L_CRIT, 0, "Failed to initialize string module");
return 6;
}
motd_init();
if (!init_conf()) {
- ircd_log(L_CRIT, "Failed to read configuration file %s", configfile);
+ log_write(LS_SYSTEM, L_CRIT, 0, "Failed to read configuration file %s",
+ configfile);
return 7;
}
CurrentTime = time(NULL);
SetMe(&me);
- me.from = &me;
+ cli_from(&me) = &me;
make_server(&me);
- me.serv->timestamp = TStime(); /* Abuse own link timestamp as start TS */
- me.serv->prot = atoi(MAJOR_PROTOCOL);
- me.serv->up = &me;
- me.serv->down = NULL;
- me.handler = SERVER_HANDLER;
+ cli_serv(&me)->timestamp = TStime(); /* Abuse own link timestamp as start TS */
+ cli_serv(&me)->prot = atoi(MAJOR_PROTOCOL);
+ cli_serv(&me)->up = &me;
+ cli_serv(&me)->down = NULL;
+ cli_handler(&me) = SERVER_HANDLER;
SetYXXCapacity(&me, MAXCLIENTS);
- me.lasttime = me.since = me.firsttime = CurrentTime;
+ cli_lasttime(&me) = cli_since(&me) = cli_firsttime(&me) = CurrentTime;
hAddClient(&me);
init_counters();
Debug((DEBUG_NOTICE, "Server ready..."));
- ircd_log(L_NOTICE, "Server Ready");
+ log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready");
event_loop();