/** Rehash motd and rule files (motd_file/rules_file and all tld entries). */ void rehash_motdrules() { ConfigItem_tld *tlds; reread_motdsandrules(); for (tlds = conf_tld; tlds; tlds = (ConfigItem_tld *) tlds->next) { /* read_motd() accepts NULL in first arg and acts sanely */ read_motd(tlds->motd_file, &tlds->motd); read_motd(tlds->rules_file, &tlds->rules); read_motd(tlds->smotd_file, &tlds->smotd); read_motd(tlds->opermotd_file, &tlds->opermotd); read_motd(tlds->botmotd_file, &tlds->botmotd); } }
static void download_staff_file_complete(char *url, char *file, char *errorbuf, int cached, void *dummy) { Download.in_progress = 0; Download.once_completed = 1; if (!cached) { if (!file) { config_error("Error downloading %s: %s", url, errorbuf); return; } remove_staff_file(); Download.path = strdup(file); read_motd(Download.path, &staff); } else { char *urlfile = url_getfilename(url); char *file = unreal_getfilename(urlfile); char *tmp = unreal_mktemp("tmp", file); /* TODO: handle null returns ? */ unreal_copyfile(Download.path, tmp); remove_staff_file(); Download.path = strdup(tmp); MyFree(urlfile); } }
static int download_staff_file(ConfigEntry *ce) { int ret = 0; struct stat sb; char *file, *filename; if (Download.in_progress) return 0; Download.is_url = 1; ircstrdup(Download.url, ce->ce_vardata); file = url_getfilename(ce->ce_vardata); filename = unreal_getfilename(file); /* TODO: handle NULL returns */ ircstrdup(Download.file, filename); MyFree(file); if (!loop.ircd_rehashing && !Download.once_completed) { char *error; if (config_verbose > 0) config_status("Downloading %s", Download.url); if (!(file = download_file(ce->ce_vardata, &error))) { config_error("%s:%i: test: error downloading '%s': %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_vardata, error); return -1; } Download.once_completed = 1; ircstrdup(Download.path, file); read_motd(Download.path, &staff); MyFree(file); return 0; } file = Download.path ? Download.path : Download.file; if ((ret = stat(file, &sb)) && errno != ENOENT) { /* I know, stat shouldn't fail... */ config_error("%s:%i: could not get the creation time of %s: stat() returned %d: %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, Download.file, ret, strerror(errno)); return -1; } if (config_verbose > 0) config_status("Downloading %s", Download.url); Download.in_progress = 1; download_file_async(Download.url, sb.st_ctime, download_staff_file_complete, NULL); return 0; }
void reread_motdsandrules() { read_motd(conf_files->motd_file, &motd); read_motd(conf_files->rules_file, &rules); read_motd(conf_files->smotd_file, &smotd); read_motd(conf_files->botmotd_file, &botmotd); read_motd(conf_files->opermotd_file, &opermotd); read_motd(conf_files->svsmotd_file, &svsmotd); }
int main(int argc, char *argv[]) { uid_t uid, euid; int portarg = 0, fd; #ifdef SAVE_MAXCLIENT_STATS FILE *mcsfp; #endif memset(&me, 0, sizeof(aClient)); if ((timeofday = time(NULL)) == -1) { (void) fprintf(stderr, "ERROR: Clock Failure (%d)\n", errno); exit(errno); } build_version(); Count.server = 1; /* us */ Count.oper = 0; Count.chan = 0; Count.local = 0; Count.total = 0; Count.invisi = 0; Count.unknown = 0; Count.max_loc = 0; Count.max_tot = 0; Count.today = 0; Count.weekly = 0; Count.monthly = 0; Count.yearly = 0; Count.start = NOW; Count.day = NOW; Count.week = NOW; Count.month = NOW; Count.year = NOW; #ifdef SAVE_MAXCLIENT_STATS mcsfp=fopen(DPATH "/.maxclients", "r"); if(mcsfp!=NULL) { fscanf(mcsfp, "%d %d %li %li %li %ld %ld %ld %ld", &Count.max_loc, &Count.max_tot, &Count.weekly, &Count.monthly, &Count.yearly, &Count.start, &Count.week, &Count.month, &Count.year); fclose(mcsfp); } #endif /* * this code by [email protected] * it is intended to keep the ircd from being swapped out. BSD * swapping criteria do not match the requirements of ircd */ #ifdef INITIAL_DBUFS dbuf_init(); /* set up some dbuf stuff to control paging */ #endif sbrk0 = (char *) sbrk((size_t) 0); uid = getuid(); euid = geteuid(); #ifdef PROFIL (void) monstartup(0, etext); (void) moncontrol(1); (void) signal(SIGUSR1, s_monitor); #endif myargv = argv; (void) umask(077); /* better safe than sorry --SRB */ memset((char *) &me, '\0', sizeof(me)); setup_signals(); /* * * All command line parameters have the syntax "-fstring" or "-f * string" (e.g. the space is optional). String may be empty. Flag * characters cannot be concatenated (like "-fxyz"), it would * conflict with the form "-fstring". */ while (--argc > 0 && (*++argv)[0] == '-') { char *p = argv[0] + 1; int flag = *p++; if (flag == '\0' || *p == '\0') { if (argc > 1 && argv[1][0] != '-') { p = *++argv; argc -= 1; } else p = ""; } switch (flag) { case 'a': bootopt |= BOOT_AUTODIE; break; case 'c': bootopt |= BOOT_CONSOLE; break; case 'q': bootopt |= BOOT_QUICK; break; case 'd': (void) setuid((uid_t) uid); dpath = p; break; case 'o': /* Per user local daemon... */ (void) setuid((uid_t) uid); bootopt |= BOOT_OPER; break; #ifdef CMDLINE_CONFIG case 'f': (void) setuid((uid_t) uid); configfile = p; break; # ifdef KPATH case 'k': (void) setuid((uid_t) uid); klinefile = p; break; # endif #endif case 'h': strncpyzt(me.name, p, sizeof(me.name)); break; case 'i': bootopt |= BOOT_INETD | BOOT_AUTODIE; break; case 'p': if ((portarg = atoi(p)) > 0) portnum = portarg; break; case 's': bootopt |= BOOT_STDERR; break; case 't': (void) setuid((uid_t) uid); bootopt |= BOOT_TTY; break; case 'v': (void) printf("ircd %s\n", version); exit(0); case 'x': #ifdef DEBUGMODE (void) setuid((uid_t) uid); debuglevel = atoi(p); debugmode = *p ? p : "0"; bootopt |= BOOT_DEBUG; break; #else (void) fprintf(stderr, "%s: DEBUGMODE must be defined for -x y\n", myargv[0]); exit(0); #endif default: bad_command(); break; } } if (chdir(dpath)) { perror("chdir"); exit(-1); } if ((uid != euid) && !euid) { (void) fprintf(stderr, "ERROR: do not run ircd setuid root. Make it setuid a normal user.\n"); exit(-1); } if (argc > 0) return bad_command(); /* This should exit out */ initialize_ssl(); motd = (aMotd *) NULL; helpfile = (aMotd *) NULL; motd_tm = NULL; #ifdef SHORT_MOTD shortmotd = NULL; #endif read_motd(MOTD); read_help(HELPFILE); #ifdef SHORT_MOTD read_shortmotd(SHORTMOTD); #endif clear_client_hash_table(); clear_channel_hash_table(); clear_scache_hash_table(); /* server cache name table */ clear_ip_hash_table(); /* client host ip hash table */ initlists(); initclass(); initwhowas(); initstats(); init_tree_parse(msgtab); init_send(); NOW = time(NULL); open_debugfile(); NOW = time(NULL); init_fdlist(&serv_fdlist); init_fdlist(&oper_fdlist); init_fdlist(&listen_fdlist); #ifndef NO_PRIORITY init_fdlist(&busycli_fdlist); #endif init_fdlist(&default_fdlist); { int i; for (i = MAXCONNECTIONS + 1; i > 0; i--) { default_fdlist.entry[i] = i - 1; } } if ((timeofday = time(NULL)) == -1) { #ifdef USE_SYSLOG syslog(LOG_WARNING, "Clock Failure (%d), TS can be corrupted", errno); #endif sendto_ops("Clock Failure (%d), TS can be corrupted", errno); } #ifdef WINGATE_NOTICE strcpy(ProxyMonURL, "http://"); strncpyzt((ProxyMonURL + 7), DEFAULT_PROXY_INFO_URL, (TOPICLEN + 1) - 7); strncpyzt(ProxyMonHost, MONITOR_HOST, (HOSTLEN + 1)); #endif if (portnum < 0) portnum = PORTNUM; me.port = portnum; (void) init_sys(); me.flags = FLAGS_LISTEN; #ifndef _WIN32 if (bootopt & BOOT_INETD) { me.fd = 0; local[0] = &me; me.flags = FLAGS_LISTEN; } else #endif me.fd = -1; #ifdef USE_SYSLOG # define SYSLOG_ME "ircd" openlog(SYSLOG_ME, LOG_PID | LOG_NDELAY, LOG_FACILITY); #endif if ((fd = openconf(configfile)) == -1) { Debug((DEBUG_FATAL, "Failed in reading configuration file %s", configfile)); (void) printf("Couldn't open configuration file %s\n", configfile); exit(-1); } (void) initconf(bootopt, fd); /* comstuds SEPARATE_QUOTE_KLINES_BY_DATE code */ #ifdef SEPARATE_QUOTE_KLINES_BY_DATE { struct tm *tmptr; char timebuffer[20], filename[200]; tmptr = localtime(&NOW); (void) strftime(timebuffer, 20, "%y%m%d", tmptr); ircsprintf(filename, "%s.%s", klinefile, timebuffer); if ((fd = openconf(filename)) == -1) { Debug((DEBUG_ERROR, "Failed reading kline file %s", filename)); (void) printf("Couldn't open kline file %s\n", filename); } else (void) initconf(0, fd); } #else # ifdef KPATH if ((fd = openconf(klinefile)) == -1) { Debug((DEBUG_ERROR, "Failed reading kline file %s", klinefile)); (void) printf("Couldn't open kline file %s\n", klinefile); } else (void) initconf(0, fd); # endif #endif if (!(bootopt & BOOT_INETD)) { static char star[] = "*"; aConfItem *aconf; u_long vaddr; if ((aconf = find_me()) && portarg <= 0 && aconf->port > 0) portnum = aconf->port; Debug((DEBUG_ERROR, "Port = %d", portnum)); if ((aconf->passwd[0] != '\0') && (aconf->passwd[0] != '*')) vaddr = inet_addr(aconf->passwd); else vaddr = (u_long) NULL; if (inetport(&me, star, portnum, vaddr)) { if (bootopt & BOOT_STDERR) fprintf(stderr, "Couldn't bind to primary port %d\n", portnum); #ifdef USE_SYSLOG (void) syslog(LOG_CRIT, "Couldn't bind to primary port %d\n", portnum); #endif exit(1); } } else if (inetport(&me, "*", 0, 0)) { if (bootopt & BOOT_STDERR) fprintf(stderr, "Couldn't bind to port passed from inetd\n"); #ifdef USE_SYSLOG (void) syslog(LOG_CRIT, "Couldn't bind to port passed from inetd\n"); #endif exit(1); } (void) get_my_name(&me, me.sockhost, sizeof(me.sockhost) - 1); if (me.name[0] == '\0') strncpyzt(me.name, me.sockhost, sizeof(me.name)); me.hopcount = 0; me.authfd = -1; me.confs = NULL; me.next = NULL; me.user = NULL; me.from = &me; SetMe(&me); make_server(&me); me.serv->up = me.name; me.lasttime = me.since = me.firsttime = NOW; (void) add_to_client_hash_table(me.name, &me); /* We don't want to calculate these every time they are used :) */ sprintf(REPORT_DO_DNS, REPORT_DO_DNS_, me.name); sprintf(REPORT_FIN_DNS, REPORT_FIN_DNS_, me.name); sprintf(REPORT_FIN_DNSC, REPORT_FIN_DNSC_, me.name); sprintf(REPORT_FAIL_DNS, REPORT_FAIL_DNS_, me.name); sprintf(REPORT_DO_ID, REPORT_DO_ID_, me.name); sprintf(REPORT_FIN_ID, REPORT_FIN_ID_, me.name); sprintf(REPORT_FAIL_ID, REPORT_FAIL_ID_, me.name); R_do_dns = strlen(REPORT_DO_DNS); R_fin_dns = strlen(REPORT_FIN_DNS); R_fin_dnsc = strlen(REPORT_FIN_DNSC); R_fail_dns = strlen(REPORT_FAIL_DNS); R_do_id = strlen(REPORT_DO_ID); R_fin_id = strlen(REPORT_FIN_ID); R_fail_id = strlen(REPORT_FAIL_ID); check_class(); if (bootopt & BOOT_OPER) { aClient *tmp = add_connection(&me, 0); if (!tmp) exit(1); SetMaster(tmp); } else write_pidfile(); Debug((DEBUG_NOTICE, "Server ready...")); #ifdef USE_SYSLOG syslog(LOG_NOTICE, "Server Ready"); #endif NOW = time(NULL); #ifndef NO_PRIORITY check_fdlists(); #endif if ((timeofday = time(NULL)) == -1) { #ifdef USE_SYSLOG syslog(LOG_WARNING, "Clock Failure (%d), TS can be corrupted", errno); #endif sendto_ops("Clock Failure (%d), TS can be corrupted", errno); } #ifdef DUMP_DEBUG dumpfp=fopen("dump.log", "w"); #endif io_loop(); return 0; }
int main(int argc,char *args[]) { int n,c; unsigned long long prof,start,end; end_of_data_ptr=sbrk(0); time_now=time(NULL); printf("\n"); printf(" ********************************************\n"); printf(" * Astonia 3 - The Conflict Server *\n"); printf(" * Version %d.%02d.%02d *\n",VERSION>>16,(VERSION>>8)&255,VERSION&255); printf(" ********************************************\n"); printf(" * Copyright (C) 2001-2008 Intent Software *\n"); printf(" * Copyright (C) 1997-2001 Daniel Brockhaus *\n"); printf(" ********************************************\n"); printf("\n"); if (argc>1) { while (1) { c=getopt(argc,args,"a:m:i:dhc"); if (c==-1) break; switch (c) { case 'a': if (optarg) areaID=atoi(optarg); break; case 'm': if (optarg) areaM=atoi(optarg); break; case 'd': demon=1; break; case 'h': fprintf(stderr,"Usage: %s [-a <areaID>] [-m <mirror>] [-n <use this class A net>] [-d] [-c]\n\n-d Demonize\n-c Disable concurrent database access\n\n",args[0]); exit(0); case 'c': multi=0; break; //case 'n': if (optarg) server_net=atoi(optarg); break; case 'i': if (optarg) serverID=atoi(optarg); break; } } } if (!areaID) { printf("No areaID given, assuming areaID=1\n"); areaID=1; } if (!areaM) { printf("No mirror given, assuming areaM=1\n"); areaM=1; } if (!serverID) { printf("No serverID given, assuming serverID=1\n"); serverID=1; } #ifdef STAFF while (!check_staff_start()) sleep(1); #endif // set character number limit depending on area switch(areaID) { case 1: maxchars=512; break; case 2: maxchars=896; break; case 3: maxchars=384; break; case 4: maxchars=2048; break; case 5: maxchars=768; break; case 6: maxchars=384; break; case 7: maxchars=1280; break; case 8: maxchars=384; break; case 9: maxchars=1280; break; case 10: maxchars=512; break; case 11: maxchars=384; break; case 12: maxitem=1024*48; maxchars=384; break; case 13: maxchars=9*50+200; break; case 14: maxchars=16*50+200; break; case 15: maxchars=384; break; case 16: maxchars=384; break; case 17: maxchars=512; break; case 18: maxchars=768; break; case 19: maxchars=384; break; case 20: maxchars=768; break; case 21: maxchars=768; break; case 22: maxchars=512; break; case 23: maxchars=512; break; case 24: maxchars=384; break; case 25: maxchars=384+8*25*2; break; case 26: maxchars=256; break; case 27: maxchars=2048; break; case 28: maxchars=384; break; case 29: maxchars=512; break; case 30: maxchars=384; break; case 31: maxitem=1024*40; maxchars=512; break; case 32: maxchars=1280; break; case 33: maxchars=1600; break; case 34: maxchars=1280; break; case 35: maxchars=768; break; case 36: maxchars=768; break; case 37: maxchars=1024; break; default: maxchars=768; break; } // set item and effect limit if (!maxitem) maxitem=max(maxchars*12+10240,20480); if (!maxeffect) maxeffect=max(maxchars*2,1024); printf("serverID=%d, areaID=%d, areaM=%d, maxchars=%d, maxitem=%d, maxeffect=%d\n\n", serverID,areaID,areaM,maxchars,maxitem,maxeffect); if (demon) { printf("Demonizing...\n\n"); if (fork()) exit(0); for (n=0; n<256; n++) close(n); setsid(); #ifndef STAFF nologin=1; #endif } // ignore the silly pipe errors: signal(SIGPIPE,SIG_IGN); // ignore sighup - just to be safe signal(SIGHUP,SIG_IGN); /*signal(SIGSEGV,sig_crash); signal(SIGFPE,sig_crash); signal(SIGBUS,sig_crash); signal(SIGSTKFLT,sig_crash);*/ // shutdown gracefully if possible: signal(SIGQUIT,sig_leave); signal(SIGINT,sig_leave); signal(SIGTERM,sig_leave); // show profile info on CTRL-Z signal(SIGTSTP,sig_showprof); // init random number generator srand(time_now); if (!init_smalloc()) exit(1); if (!init_mem()) exit(1); if (!init_prof()) exit(1); if (!init_log()) exit(1); if (!init_database()) exit(1); if (!init_lookup()) exit(1); if (!init_sector()) exit(1); if (!init_los()) exit(1); if (!init_timer()) exit(1); if (!init_notify()) exit(1); if (!init_create()) exit(1); if (!init_lib()) exit(1); if (!init_io()) exit(1); if (!init_path()) exit(1); if (!init_effect()) exit(1); if (!init_container()) exit(1); if (!init_store()) exit(1); if (!init_chat()) exit(1); init_sound_sector(); xlog("AreaID=%d, AreaM=%d, entering game loop...",areaID,areaM); dlog(0,0,"Server started"); prof_reset(); while (!quit) { sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (busy)",areaID,areaM,serverID,online,(10000-server_idle)/100); start=rdtsc(); lock_server(); time_now=time(NULL); prof=prof_start(26); tick_date(); prof_stop(26,prof); prof=prof_start(22); tick_timer(); prof_stop(22,prof); prof=prof_start(4); tick_char(); prof_stop(4,prof); prof=prof_start(24); tick_effect(); prof_stop(24,prof); prof=prof_start(36); tick_clan(); prof_stop(36,prof); prof=prof_start(39); tick_club(); prof_stop(39,prof); prof=prof_start(5); tick_player(); prof_stop(5,prof); prof=prof_start(34); tick_login(); prof_stop(34,prof); prof=prof_start(6); pflush(); prof_stop(6,prof); prof=prof_start(7); io_loop(); prof_stop(7,prof); prof=prof_start(3); tick_chat(); prof_stop(3,prof); if (showprof) { show_prof(); showprof=0; } prof=prof_start(8); prof_update(); prof_stop(8,prof); end=rdtsc(); cycles=end-start; if ((ticker&2047)==0) { prof=prof_start(27); area_alive(0); prof_stop(27,prof); prof=prof_start(28); backup_players(); prof_stop(28,prof); call_stat_update(); read_motd(); reinit_log(); } if ((ticker&255)==0) { call_check_task(); call_area_load(); shutdown_warn(); #ifdef STAFF check_staff_stop(); #endif } if ((ticker&255)==168) { prof=prof_start(38); consistency_check_items(); consistency_check_map(); consistency_check_chars(); consistency_check_containers(); prof_stop(38,prof); } unlock_server(); sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (idle)",areaID,areaM,serverID,online,(10000-server_idle)/100); prof=prof_start(1); tick_sleep(0); prof_stop(1,prof); ticker++; } xlog("Left game loop"); respawn_check(); for (n=1; n<MAXCHARS; n++) { if (ch[n].flags&CF_PLAYER) { exit_char(n); } } area_alive(1); show_prof(); dlog(0,0,"Server stopped"); xlog("map check"); check_map(); exit_lib(); exit_database(); xlog("Clean shutdown"); showmem(); exit_log(); exit_io(); return 0; }