示例#1
0
static void schan_members_update(struct stats_member *m, char *chan)
{
	char *host;
#ifndef NO_EGG
	struct userrec *u;
#endif

	m->user = NULL;
	host = nmalloc(strlen(m->nick) + 1 + strlen(m->uhost) + 1);
	sprintf(host, "%s!%s", m->nick, m->uhost);
#ifndef NO_EGG
	u = get_user_by_host(host);
	if (u) {
		m->user = findsuser_by_name(u->handle);
		if (!m->user) {
	  		m->user = addsuser(u->handle, now, now);
	  		debug1("Stats.Mod: Created suserrec for %s.", u->handle);
		}
	} else
#endif
		m->user = findsuser(host);
	nfree(host);
	if (m->user) {
		m->stats = findlocstats(chan, m->user->user);
		if (!m->stats)
			m->stats = initstats(chan, m->user->user);
	}
}
示例#2
0
static void printstats(time_t start, time_t end)
{
	int i;
	fprintf(trace,"Time interval  %lu - %lu \n ",start, end);
	fprintf(trace,"Call\tNumberBytes\tNumber of Calls \n");
	fprintf(trace,"------------------------------------------------------\n");
	for(i=0;i<MPI_EVENTS;i++){if(mpistat[i].num!=0){fprintf(trace," %s\t%llu\t%d\n",mpistat[i].call,mpistat[i].bytes,mpistat[i].num);}}
	fprintf(trace,"------------------------------------------------------\n");
	initstats();
}
示例#3
0
void libinit(void)
{
    
    void * handle = RTLD_NEXT;
    char * error;
      
    #ifdef DEBUG
    printf("loading library \n");
    #endif
    libsend = (typeof (libsend)) (uintptr_t) dlsym (handle,"MPI_Send");
    librecv = (typeof (librecv)) (uintptr_t) dlsym (handle,"MPI_Recv");
    libirecv = (typeof (libirecv)) (uintptr_t) dlsym (handle,"MPI_Irecv");
    libisend= (typeof (libisend)) (uintptr_t) dlsym (handle,"MPI_Isend");
    //libMPI_Init_thread = (typeof (libMPI_Init_thread)) (uintptr_t) dlsym (handle,"MPI_Init_thread");
    libMPI_Waitall = (typeof  (libMPI_Waitall)) (uintptr_t) dlsym (handle,"MPI_Waitall");
    libMPI_Bcast = (typeof (libMPI_Bcast)) (uintptr_t) dlsym (handle, "MPI_Bcast");
    libMPI_Allreduce = (typeof (libMPI_Allreduce)) (uintptr_t) dlsym (handle,"MPI_Allreduce");
    libMPI_Reduce = (typeof (libMPI_Reduce)) (uintptr_t) dlsym (handle,"MPI_Reduce");
    libMPI_Gather = (typeof (libMPI_Gather)) (uintptr_t) dlsym (handle,"MPI_Gather");
    libMPI_Init = (typeof (libMPI_Init)) (uintptr_t) dlsym (handle,"MPI_Init");

    libMPI_Barrier = (typeof (libMPI_Barrier)) (uintptr_t) dlsym (handle,"MPI_Barrier");

    libMPI_Comm_size = (typeof (libMPI_Comm_size)) (uintptr_t) dlsym (handle,"MPI_Comm_size");

    libMPI_Comm_rank = (typeof (libMPI_Comm_rank)) (uintptr_t) dlsym (handle,"MPI_Comm_rank");
    libMPI_Wait = (typeof (libMPI_Wait)) (uintptr_t) dlsym (handle,"MPI_Wait");
     
     initstats();
     //starting timer
     struct timeval time;
     gettimeofday(&time,NULL);
     time_start_block=time.tv_sec;
     //printf("Time star : %llu \n");
     ///end timer block
     //read_conf_file();


     

    /* TODO: do not start eztrace right now.
     * We should wait for MPI_Init to be completed and get the local rank
     */
#ifdef EZTRACE_AUTOSTART
  //eztrace_start ();
#endif
}
示例#4
0
int
main (int argc, char *argv[])
{
  int rt;

  rt = _i18n_init (I18N_CAT_MIN);

  setdefaults ();
  getoptions (argc, argv);
  getpids (argc, argv);
  printheader ();
  initstats ();
  processlogfile ();
  printsummary ();

  _i18n_end (ls_catd);
  return (0);

}
示例#5
0
static void schan_members_join(struct llist_header *head, char *nick, char *uhost, char *user, char *chan)
{
	struct stats_member *m;
	char *host;
#ifndef NO_EGG
	struct chanset_t *eggchan;
#endif

	m = schan_members_create();
	m->nick = nmalloc(strlen(nick) + 1);
	strcpy(m->nick, nick);
	m->uhost = nmalloc(strlen(uhost) + 1);
	strcpy(m->uhost, uhost);
	m->joined = now;
	if (user) {
		m->user = findsuser_by_name(user);
		if (!m->user) {
			m->user = addsuser(user, now, now);
			debug1("Stats.Mod: Created suserrec for %s.", user);
		}
	} else {
		host = nmalloc(strlen(nick) + 1 + strlen(uhost) + 1);
		sprintf(host, "%s!%s", nick, uhost);
		m->user = findsuser(host);
		nfree(host);
	}
	if (m->user) {
		m->user->laston = now;
		m->stats = findlocstats(chan, m->user->user);
		if (!m->stats)
			m->stats = initstats(chan, m->user->user);
	}
#ifndef NO_EGG
	eggchan = findchan_by_dname(chan);
	if (chan)
		m->eggmember = ismember(eggchan, nick);
	if (!m->eggmember)
		debug2("Warning[stats.mod]: Couldn't find eggmember for %s in %s.", nick, chan);
#endif
	llist_append(head, (void *) m);
}
示例#6
0
文件: char.cpp 项目: cwc/OmegaRPG
/* set player to begin with */
bool initplayer(void)
{
    int i;
    int oldchar=false;
    FILE *fd;
    char *lname;
    int ret_value = false;

    lname = getlogin();

#if !defined(WIN32)
    // Get the login name if getlogin() failed
    if (!lname || strlen(lname) == 0)
    {
        struct passwd *dastuff;

        dastuff = getpwuid(getuid());
        lname = dastuff->pw_name;
    }
#endif

    strcpy(Player.name,lname);
    if (Player.name[0] >= 'a' && Player.name[0] <= 'z')
        Player.name[0] += 'A'-'a'; /* capitalise 1st letter */
    Player.itemweight = 0;
    Player.food = 36;
    Player.packptr = 0;
    Behavior = -1;
    Player.options = 0;
    for (i=0; i<MAXITEMS; i++)
        Player.possessions[i] = NULL;
    for (i=0; i<MAXPACK; i++)
        Player.pack[i] = NULL;
    for (i=0; i<NUMIMMUNITIES; i++) Player.immunity[i] = 0;
    for (i=0; i<NUMSTATI; i++) Player.status[i] = 0;
    for (i=0; i<NUMRANKS; i++) {
        Player.rank[i] = 0;
        Player.guildxp[i] = 0;
    }
    Player.patron = 0;
    Player.alignment = 0;
    Player.cash = 250;
    change_to_user_perms();
    if ((fd=omegarc_check())!=NULL) {
        fread((char *)&i,sizeof(int),1,fd);
        if (i != VERSION) {
            print1("Out of date .omegarc! Make another!");
            morewait();
        }
        else {
            oldchar = true;
            fread((char *)&Player,sizeof(Player),1,fd);
            fread((char *)&Searchnum,sizeof(int),1,fd);
            fread((char *)&Verbosity,sizeof(char),1,fd);
            strcpy(Player.name,lname);
            if (Player.name[0] >= 'a' && Player.name[0] <= 'z')
                Player.name[0] += 'A'-'a'; /* capitalise 1st letter */
        }
        fclose(fd);
    }
    change_to_game_perms();

    // Zop: initstats() can load a save file, so this block needs to precede the function
    /* DAG - put the code back in the same place, rather than duplicating */
    Searchnum = max(1,min(9,Searchnum));
    Player.hp = Player.maxhp = Player.maxcon;
    Player.mana = Player.maxmana = calcmana();
    Player.click = 1;
    strcpy(Player.combatManeuvers,"CCBC");
    calc_melee();
    ScreenOffset = -1000;	/* to force a redraw */

    if (! oldchar) {
        optionset(RUNSTOP);
        optionset(CONFIRM);
        optionset(SHOW_COLOUR);
        ret_value = initstats() ; /* RM 04-19-2000:loading patch */ /* DAG */
    }

    return ret_value > 0; /* RM 04-19-2000: loading patch */ /* DAG */
}
示例#7
0
int
main (int argc, char *argv[])
{
  int i = 0;
  while (++i < argc-1) {
    if (strcmp(argv[i], "-v") == 0) {
      vmode = 1;
    } else if (strcmp(argv[i], "-s") == 0) {
      smode = 1;
    } else if (strcmp(argv[i], "-a") == 0) {
      amode = 1;
    } else if (strcmp(argv[i], "-g") == 0) {
      gmode = 1;
    } else if (strcmp(argv[i], "-n") == 0) {
      nmode = 1;
      sscanf(argv[++i], "0x%x", &nextoffset);      
    } else if (strcmp(argv[i], "-r") == 0) {
      smode = 1;
      rmode = 1;
    } else {
      badusage();
    }
  }
  if (i > argc-1) badusage();
  strcpy(filename, argv[i]);
  if (!strends(".hat", filename)) strcat(filename, ".hat");
  stat(filename, &statbuf);
  filesize = statbuf.st_size;
  f = fopen(filename, (rmode ? "r+b" : "rb"));
  if (f==(FILE*)0) {
    fprintf(stderr, "cannot open trace file %s\n",filename);
    exit(1);
  }

  /* version checking added by MW */
  { int err;
    char *header = (char*)malloc(10*sizeof(char));
    err = fread(header,sizeof(char),8,f);
    if (err!=8) {
      fprintf(stderr,"hat-check (error): file %s is too short\n",filename);
      exit(1);
    }
    if (strncmp(header,"Hat",3)) {
      fprintf(stderr,"hat-check (error): file %s\n",filename);
      fprintf(stderr,"   does not appear to be a Hat archive.  Quitting.\n");
      exit(1);
    }
    if (strncmp(header+3,FILEVERSION,4)) {
      fprintf(stderr,"hat-check (warning): file %s\n",filename);
      fprintf(stderr,"   appears to be a Hat archive in format %s\n",header+3);
      fprintf(stderr,"   but this tool deals with format version %s\n",FILEVERSION);
      fprintf(stderr,"   I'm continuing, but there may be unexpected errors.\n");
    }
    fseek(f,(long int)(FileOffset)0,SEEK_SET);	/* reset to beginning of file */
    free(header);
  }

  if (nmode) {
    if (nextoffset >= filesize) {
      fprintf(stderr, "-n 0x%x is beyond end of trace file\n", nextoffset);
      exit(1);
    }
    amode = 1; rmode = 0; smode = 0;
  } else {
    nextoffset = (FileOffset)0;
  }
  if (rmode) {
    signal(SIGINT, restoretags);
#ifdef SIGQUIT
    signal(SIGQUIT, restoretags);
#endif
    markfromheader(buffer);
    strcat(filename, ".bridge");
    markfromoutput(filename,buffer);
    fseek(f,(long int)(FileOffset)0,SEEK_SET);
  }
  fseek(f,(long int)nextoffset,SEEK_SET);
  if (nmode) {
    nextnode();
  } else {
    if (smode) initstats();
    if (gmode) printf("digraph hat{\n");
    header();
    nodes();
    if (gmode) printf("}\n");
    if (amode && smode) putchar('\n');
    if (smode) reportstats();
  }
}
示例#8
0
文件: main.c 项目: alexleigh/sys161
int
main(int argc, char *argv[])
{
	int port = 2344;
	const char *config = "sys161.conf";
	const char *kernel = NULL;
	int usetcp=0;
	char *argstr = NULL;
	int j, opt;
	size_t argsize=0;
	int debugwait=0;
	int pass_signals=0;
#ifdef USE_TRACE
	int profiling=0;
#endif
	int use_second_console=0;
	const char *second_console = NULL;
	unsigned ncpus;

	/* This must come absolutely first so msg() can be used. */
	console_earlyinit();
	
	if (sizeof(u_int32_t)!=4) {
		/*
		 * Just in case.
		 */
		msg("sys161 requires sizeof(u_int32_t)==4");
		die();
	}

	while ((opt = mygetopt(argc, argv, "c:f:p:Pst:wk:"))!=-1) {
		switch (opt) {
		    case 'c': config = myoptarg; break;
		    case 'f':
#ifdef USE_TRACE
			set_tracefile(myoptarg);
#endif
			break;
		    case 'p': port = atoi(myoptarg); usetcp=1; break;
		    case 'P':
#ifdef USE_TRACE
			profiling = 1;
#endif
			break;
		    case 's': pass_signals = 1; break;
		    case 't': 
#ifdef USE_TRACE
			set_traceflags(myoptarg); 
#endif
			break;
		    case 'w': debugwait = 1; break;
		    case 'k':
		    use_second_console = 1;
		    second_console = myoptarg;
		    break;
		    default: usage(); break;
		}
	}
	if (myoptind==argc) {
		usage();
	}
	kernel = argv[myoptind++];
	
	for (j=myoptind; j<argc; j++) {
		argsize += strlen(argv[j])+1;
	}
	argstr = malloc(argsize+1);
	if (!argstr) {
		msg("malloc failed");
		die();
	}
	*argstr = 0;
	for (j=myoptind; j<argc; j++) {
		strcat(argstr, argv[j]);
		if (j<argc-1) strcat(argstr, " ");
	}

	/* This must come before bus_config in case a network card needs it */
	mkdir(".sockets", 0700);
	
	console_init(pass_signals, use_second_console, second_console);
	clock_init();
	ncpus = bus_config(config);

	initstats(ncpus);
	cpu_init(ncpus);

	if (usetcp) {
		gdb_inet_init(port);
	}
	else {
		unlink(".sockets/gdb");
		gdb_unix_init(".sockets/gdb");
	}

	unlink(".sockets/meter");
	meter_init(".sockets/meter");

	load_kernel(kernel, argstr);

	msg("System/161 %s, compiled %s %s", VERSION, __DATE__, __TIME__);
#ifdef USE_TRACE
	print_traceflags();
	if (profiling) {
		prof_setup();
	}
#endif

	if (debugwait) {
		stoploop();
	}
	
	run();

#ifdef USE_TRACE
	if (profiling) {
		prof_write();
	}
#endif

	bus_cleanup();
	console_cleanup();
	clock_cleanup();
	
	return 0;
}
示例#9
0
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;
}
示例#10
0
文件: char.c 项目: DavidKinder/Omega
/* set player to begin with */
void initplayer()
{
  int i;
  int oldchar=FALSE;
  FILE *fd;
  char *lname;
#if !defined(MSDOS) && !defined(_WIN32)
  struct passwd *dastuff;
#endif

  lname = getlogin();
#if !defined(MSDOS) && !defined(_WIN32)
  if (!lname || strlen(lname) == 0)
  {
       dastuff = getpwuid(getuid());
       lname = dastuff->pw_name;
  }
#endif
  strcpy(Player.name,lname);
  if (Player.name[0] >= 'a' && Player.name[0] <= 'z')
       Player.name[0] += 'A'-'a'; /* capitalise 1st letter */
  Player.itemweight = 0;
  Player.food = 36; 
  Player.packptr = 0;
  Behavior = -1;
  Player.options = 0;
  for (i=0;i<MAXITEMS;i++)
    Player.possessions[i] = NULL;
  for (i=0;i<MAXPACK;i++)
    Player.pack[i] = NULL;
  for (i=0;i<NUMIMMUNITIES;i++) Player.immunity[i] = 0;
  for (i=0;i<NUMSTATI;i++) Player.status[i] = 0;
  for (i=0;i<NUMRANKS;i++) {
    Player.rank[i] = 0;
    Player.guildxp[i] = 0;
  }
  Player.patron = 0;
  Player.alignment = 0;
  Player.cash = 250;
  change_to_user_perms();
  if ((fd=omegarc_check())!=NULL) {
    fread((char *)&i,sizeof(int),1,fd);
    if (i != VERSION) {
#if defined(MSDOS) || defined(AMIGA) || defined(_WIN32)
      print1("Out of date omega.rc! Make another!");
#else
      print1("Out of date .omegarc! Make another!");
#endif
      morewait();
    }
    else {
      oldchar = TRUE;
      fread((char *)&Player,sizeof(Player),1,fd);
      fread((char *)&Searchnum,sizeof(int),1,fd);
      fread((char *)&Verbosity,sizeof(char),1,fd);
      strcpy(Player.name,lname);
      if (Player.name[0] >= 'a' && Player.name[0] <= 'z')
	   Player.name[0] += 'A'-'a'; /* capitalise 1st letter */
    }
    fclose(fd);
  }
  change_to_game_perms();
  if (! oldchar) {
    optionset(RUNSTOP);
    optionset(CONFIRM);
#ifdef COMPRESS_SAVE_FILES
    optionset(COMPRESS_OPTION);
#endif
#if defined(MSDOS) || defined(AMIGA) || defined(_WIN32)
    optionset(SHOW_COLOUR);
#endif
    initstats();
  }
  Searchnum = max(1,min(9,Searchnum));
  Player.hp = Player.maxhp = Player.maxcon;
  Player.mana = Player.maxmana = calcmana();
  Player.click = 1;
  strcpy(Player.meleestr,"CCBC");
  calc_melee();
  ScreenOffset = -1000;	/* to force a redraw */
}
示例#11
0
/** Run the daemon.
 * @param[in] argc Number of arguments in \a argv.
 * @param[in] argv Arguments to program execution.
 */
int main(int argc, char **argv) {
  CurrentTime = time(NULL);

  thisServer.argc = argc;
  thisServer.argv = argv;
  thisServer.uid  = getuid();
  thisServer.euid = geteuid();

#ifdef MDEBUG
  mem_dbg_initialise();
#endif

#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_CORE)
  set_core_limit();
#endif

  umask(077);                   /* better safe than sorry --SRB */
  memset(&me, 0, sizeof(me));
  memset(&me_con, 0, sizeof(me_con));
  cli_connect(&me) = &me_con;
  cli_fd(&me) = -1;

  parse_command_line(argc, argv);

  if (chdir(dpath)) {
    fprintf(stderr, "Fail: Cannot chdir(%s): %s, check DPATH\n", dpath, strerror(errno));
    return 2;
  }

  if (!set_userid_if_needed())
    return 3;

  /* Check paths for accessibility */
  if (!check_file_access(SPATH, 'S', X_OK) ||
      !check_file_access(configfile, 'C', R_OK))
    return 4;

  if (!init_connection_limits())
    return 9;

  close_connections(!(thisServer.bootopt & (BOOT_DEBUG | BOOT_TTY | BOOT_CHKCONF)));

  /* daemon_init() must be before event_init() because kqueue() FDs
   * are, perversely, not inherited across fork().
   */
  daemon_init(thisServer.bootopt & BOOT_TTY);

#ifdef DEBUGMODE
  /* Must reserve fd 2... */
  if (debuglevel >= 0 && !(thisServer.bootopt & BOOT_TTY)) {
    int fd;
    if ((fd = open("/dev/null", O_WRONLY)) < 0) {
      fprintf(stderr, "Unable to open /dev/null (to reserve fd 2): %s\n",
	      strerror(errno));
      return 8;
    }
    if (fd != 2 && dup2(fd, 2) < 0) {
      fprintf(stderr, "Unable to reserve fd 2; dup2 said: %s\n",
	      strerror(errno));
      return 8;
    }
  }
#endif

  event_init(MAXCONNECTIONS);

  setup_signals();
  feature_init(); /* initialize features... */
  log_init(*argv);
  set_nomem_handler(outofmemory);

  initload();
  init_list();
  init_hash();
  init_class();
  initwhowas();
  initmsgtree();
  initstats();

  /* we need this for now, when we're modular this 
     should be removed -- hikari */
  ircd_crypt_init();

  motd_init();

  if (!init_conf()) {
    log_write(LS_SYSTEM, L_CRIT, 0, "Failed to read configuration file %s",
	      configfile);
    return 7;
  }

  if (thisServer.bootopt & BOOT_CHKCONF) {
    if (dbg_client)
      conf_debug_iline(dbg_client);
    fprintf(stderr, "Configuration file %s checked okay.\n", configfile);
    return 0;
  }

  debug_init(thisServer.bootopt & BOOT_TTY);
  if (check_pid()) {
    Debug((DEBUG_FATAL, "Failed to acquire PID file lock after fork"));
    exit(2);
  }

  init_server_identity();

  uping_init();

  stats_init();

  IPcheck_init();
  timer_add(timer_init(&connect_timer), try_connections, 0, TT_RELATIVE, 1);
  timer_add(timer_init(&ping_timer), check_pings, 0, TT_RELATIVE, 1);
  timer_add(timer_init(&destruct_event_timer), exec_expired_destruct_events, 0, TT_PERIODIC, 60);
  timer_add(timer_init(&mute_timer), check_expired_mutes, 0, TT_PERIODIC, 30);

  CurrentTime = time(NULL);

  SetMe(&me);
  cli_magic(&me) = CLIENT_MAGIC;
  cli_from(&me) = &me;
  make_server(&me);

  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);

  cli_lasttime(&me) = cli_since(&me) = cli_firsttime(&me) = CurrentTime;

  hAddClient(&me);

  write_pidfile();
  init_counters();

  Debug((DEBUG_NOTICE, "Server ready..."));
  log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready");

  event_loop();

  return 0;
}