/* Dump status info out to dcc */ void tell_verbose_status(int idx) { char *vers_t = NULL, *uni_t = NULL; int i; struct utsname un; if (!uname(&un) < 0) { vers_t = " "; uni_t = "*unknown*"; } else { vers_t = un.release; uni_t = un.sysname; } i = count_users(userlist); dprintf(idx, "I am %s, running %s: %d user%s\n", conf.bot->nick, ver, i, i == 1 ? "" : "s"); dprintf(idx, "my user: %s\n", conf.bot->u->handle); if (conf.bot->localhub) dprintf(idx, "I am a localhub.\n"); if (conf.bot->hub && isupdatehub()) dprintf(idx, "I am an update hub.\n"); tell_verbose_uptime(idx); if (admin[0]) dprintf(idx, "Admin: %s\n", admin); dprintf(idx, "OS: %s %s\n", uni_t, vers_t); dprintf(idx, "Running from: %s\n", binname); dprintf(idx, "uid: %s (%d) pid: %lu homedir: %s\n", conf.username, conf.uid, (unsigned long) mypid, conf.homedir); if (tempdir[0]) dprintf(idx, "Tempdir : %s\n", tempdir); if (conf.datadir) dprintf(idx, "Datadir : %s\n", conf.datadir); }
adduser() { count_users(); load_limits(); if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); vclose(); exit(0); } if ( MaxPopAccounts != -1 && CurPopAccounts >= MaxPopAccounts ) { sprintf(StatusMessage, "%s %d\n", get_html_text("199"), MaxPopAccounts); show_menu(); vclose(); exit(0); } send_template( "add_user.html" ); }
int main(int argc, char *argv[]) { static struct timespec res; static int loadavg[3]; time_t t; uint32_t days, hours, mins; struct tm *tm; int u; /* Get the clocks we want */ clock_gettime(CLOCK_MONOTONIC, &res); time(&t); tm = localtime(&t); printf(" %02d:%02d:%02d up ", tm->tm_hour, tm->tm_min, tm->tm_sec); mins = res.tv_sec / 60; hours = mins / 60; days = hours / 24; mins %= 60; hours %= 24; if (days == 1) printf("1 day, "); else if (days > 1) printf("%d days, ", (unsigned int)days); printf("%02d:%02d, ", (unsigned int)hours, (unsigned int)mins); u = count_users(); printf("%d user%s", u, u != 1 ? "s" : ""); if (getloadavg(loadavg, 3) == 3) { printf(", load average:"); printload(loadavg[0]); printload(loadavg[1]); printload(loadavg[2]); } printf("\n"); }
/* Dump status info out to dcc */ void tell_verbose_status(int idx) { char s[256], s1[121], s2[81]; char *vers_t, *uni_t; int i; time_t now2 = now - online_since, hr, min; float cputime; #ifdef HAVE_UNAME struct utsname un; if (uname(&un) < 0) { #endif vers_t = " "; uni_t = "*unknown*"; #ifdef HAVE_UNAME } else { vers_t = un.release; uni_t = un.sysname; } #endif i = count_users(userlist); dprintf(idx, "I am %s, running %s: %d user%s (mem: %uk).\n", botnetnick, ver, i, i == 1 ? "" : "s", (int) (expected_memory() / 1024)); s[0] = 0; if (now2 > 86400) { /* days */ sprintf(s, "%d day", (int) (now2 / 86400)); if ((int) (now2 / 86400) >= 2) strcat(s, "s"); strcat(s, ", "); now2 -= (((int) (now2 / 86400)) * 86400); } hr = (time_t) ((int) now2 / 3600); now2 -= (hr * 3600); min = (time_t) ((int) now2 / 60); sprintf(&s[strlen(s)], "%02d:%02d", (int) hr, (int) min); s1[0] = 0; if (backgrd) strcpy(s1, MISC_BACKGROUND); else { if (term_z) strcpy(s1, MISC_TERMMODE); else if (con_chan) strcpy(s1, MISC_STATMODE); else strcpy(s1, MISC_LOGMODE); } cputime = getcputime(); if (cputime < 0) sprintf(s2, "CPU: unknown"); else { hr = cputime / 60; cputime -= hr * 60; sprintf(s2, "CPU: %02d:%05.2f", (int) hr, cputime); /* Actally min/sec */ } dprintf(idx, "%s %s (%s) - %s - %s: %4.1f%%\n", MISC_ONLINEFOR, s, s1, s2, MISC_CACHEHIT, 100.0 * ((float) cache_hit) / ((float) (cache_hit + cache_miss))); dprintf(idx, "Configured with: " EGG_AC_ARGS "\n"); if (admin[0]) dprintf(idx, "Admin: %s\n", admin); dprintf(idx, "Config file: %s\n", configfile); dprintf(idx, "OS: %s %s\n", uni_t, vers_t); dprintf(idx, "Process ID: %d (parent %d)\n", getpid(), getppid()); /* info library */ dprintf(idx, "%s %s\n", MISC_TCLLIBRARY, ((interp) && (Tcl_Eval(interp, "info library") == TCL_OK)) ? tcl_resultstring() : "*unknown*"); /* info tclversion/patchlevel */ dprintf(idx, "%s %s (%s %s)\n", MISC_TCLVERSION, ((interp) && (Tcl_Eval(interp, "info patchlevel") == TCL_OK)) ? tcl_resultstring() : (Tcl_Eval(interp, "info tclversion") == TCL_OK) ? tcl_resultstring() : "*unknown*", MISC_TCLHVERSION, TCL_PATCH_LEVEL ? TCL_PATCH_LEVEL : "*unknown*"); if (tcl_threaded()) dprintf(idx, "Tcl is threaded.\n"); #ifdef TLS dprintf(idx, "TLS support is enabled.\n"); dprintf(idx, "TLS library: %s\n", SSLeay_version(SSLEAY_VERSION)); #else dprintf(idx, "TLS support is not available.\n"); #endif #ifdef IPV6 dprintf(idx, "IPv6 support is enabled.\n"); #else dprintf(idx, "IPv6 support is not available.\n"); #endif dprintf(idx, "Socket table: %d/%d\n", threaddata()->MAXSOCKS, max_socks); }
int main(int arg_c, char **arg_v) { int i, xx; char s[25]; FILE *f; struct sigaction sv; struct chanset_t *chan; #ifdef DEBUG struct rlimit cdlim; #endif #ifdef STOP_UAC int nvpair[2]; #endif /* Make sure it can write core, if you make debug. Else it's pretty * useless (dw) * * Only allow unlimited size core files when compiled with DEBUG defined. * This is not a good idea for normal builds -- in these cases, use the * default system resource limits instead. */ #ifdef DEBUG cdlim.rlim_cur = RLIM_INFINITY; cdlim.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &cdlim); #endif #ifdef DEBUG_CONTEXT /* Initialise context list */ for (i = 0; i < 16; i++) Context; #endif /* Include patch.h header for patch("...") */ #include "patch.h" argc = arg_c; argv = arg_v; /* Version info! */ egg_snprintf(ver, sizeof ver, "eggdrop v%s", egg_version); egg_snprintf(version, sizeof version, "Eggdrop v%s (C) 1997 Robey Pointer (C) 2010 Eggheads", egg_version); /* Now add on the patchlevel (for Tcl) */ sprintf(&egg_version[strlen(egg_version)], " %u", egg_numver); strcat(egg_version, egg_xtra); /* For OSF/1 */ #ifdef STOP_UAC /* Don't print "unaligned access fixup" warning to the user */ nvpair[0] = SSIN_UACPROC; nvpair[1] = UAC_NOPRINT; setsysinfo(SSI_NVPAIRS, (char *) nvpair, 1, NULL, 0); #endif /* Set up error traps: */ sv.sa_handler = got_bus; sigemptyset(&sv.sa_mask); #ifdef SA_RESETHAND sv.sa_flags = SA_RESETHAND; #else sv.sa_flags = 0; #endif sigaction(SIGBUS, &sv, NULL); sv.sa_handler = got_segv; sigaction(SIGSEGV, &sv, NULL); #ifdef SA_RESETHAND sv.sa_flags = 0; #endif sv.sa_handler = got_fpe; sigaction(SIGFPE, &sv, NULL); sv.sa_handler = got_term; sigaction(SIGTERM, &sv, NULL); sv.sa_handler = got_hup; sigaction(SIGHUP, &sv, NULL); sv.sa_handler = got_quit; sigaction(SIGQUIT, &sv, NULL); sv.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sv, NULL); sv.sa_handler = got_ill; sigaction(SIGILL, &sv, NULL); sv.sa_handler = got_alarm; sigaction(SIGALRM, &sv, NULL); /* Initialize variables and stuff */ now = time(NULL); chanset = NULL; egg_memcpy(&nowtm, localtime(&now), sizeof(struct tm)); lastmin = nowtm.tm_min; srandom((unsigned int) (now % (getpid() + getppid()))); init_mem(); init_language(1); if (argc > 1) for (i = 1; i < argc; i++) do_arg(argv[i]); printf("\n%s\n", version); #ifndef CYGWIN_HACKS /* Don't allow eggdrop to run as root * This check isn't useful under cygwin and has been * reported to cause trouble in some situations. */ if (((int) getuid() == 0) || ((int) geteuid() == 0)) fatal("ERROR: Eggdrop will not run as root!", 0); #endif #ifndef REPLACE_NOTIFIER init_threaddata(1); #endif init_userent(); init_misc(); init_bots(); init_modules(); if (backgrd) bg_prepare_split(); init_tcl(argc, argv); init_language(0); #ifdef STATIC link_statics(); #endif strncpyz(s, ctime(&now), sizeof s); strcpy(&s[11], &s[20]); putlog(LOG_ALL, "*", "--- Loading %s (%s)", ver, s); chanprog(); if (!encrypt_pass) { printf(MOD_NOCRYPT); bg_send_quit(BG_ABORT); exit(1); } i = 0; for (chan = chanset; chan; chan = chan->next) i++; putlog(LOG_MISC, "*", "=== %s: %d channels, %d users.", botnetnick, i, count_users(userlist)); #ifdef TLS ssl_init(); #endif cache_miss = 0; cache_hit = 0; if (!pid_file[0]) egg_snprintf(pid_file, sizeof pid_file, "pid.%s", botnetnick); /* Check for pre-existing eggdrop! */ f = fopen(pid_file, "r"); if (f != NULL) { fgets(s, 10, f); xx = atoi(s); i = kill(xx, SIGCHLD); /* Meaningless kill to determine if pid * is used */ if (i == 0 || errno != ESRCH) { printf(EGG_RUNNING1, botnetnick); printf(EGG_RUNNING2, pid_file); bg_send_quit(BG_ABORT); exit(1); } } /* Move into background? */ if (backgrd) { bg_do_split(); } else { /* !backgrd */ xx = getpid(); if (xx != 0) { FILE *fp; /* Write pid to file */ unlink(pid_file); fp = fopen(pid_file, "w"); if (fp != NULL) { fprintf(fp, "%u\n", xx); if (fflush(fp)) { /* Let the bot live since this doesn't appear to be a botchk */ printf(EGG_NOWRITE, pid_file); fclose(fp); unlink(pid_file); } else fclose(fp); } else printf(EGG_NOWRITE, pid_file); } } use_stderr = 0; /* Stop writing to stderr now */ if (backgrd) { /* Ok, try to disassociate from controlling terminal (finger cross) */ #ifdef HAVE_SETPGID setpgid(0, 0); #endif /* Tcl wants the stdin, stdout and stderr file handles kept open. */ freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr); #ifdef CYGWIN_HACKS FreeConsole(); #endif } /* Terminal emulating dcc chat */ if (!backgrd && term_z) { int n = new_dcc(&DCC_CHAT, sizeof(struct chat_info)); getvhost(&dcc[n].sockname, AF_INET); dcc[n].sock = STDOUT; dcc[n].timeval = now; dcc[n].u.chat->con_flags = conmask; dcc[n].u.chat->strip_flags = STRIP_ALL; dcc[n].status = STAT_ECHO; strcpy(dcc[n].nick, "HQ"); strcpy(dcc[n].host, "llama@console"); /* HACK: Workaround not to pass literal "HQ" as a non-const arg */ dcc[n].user = get_user_by_handle(userlist, dcc[n].nick); /* Make sure there's an innocuous HQ user if needed */ if (!dcc[n].user) { userlist = adduser(userlist, dcc[n].nick, "none", "-", USER_PARTY); dcc[n].user = get_user_by_handle(userlist, dcc[n].nick); } setsock(STDOUT, 0); /* Entry in net table */ dprintf(n, "\n### ENTERING DCC CHAT SIMULATION ###\n\n"); dcc_chatter(n); } then = now; online_since = now; autolink_cycle(NULL); /* Hurry and connect to tandem bots */ add_help_reference("cmds1.help"); add_help_reference("cmds2.help"); add_help_reference("core.help"); add_hook(HOOK_SECONDLY, (Function) core_secondly); add_hook(HOOK_MINUTELY, (Function) core_minutely); add_hook(HOOK_HOURLY, (Function) core_hourly); add_hook(HOOK_REHASH, (Function) event_rehash); add_hook(HOOK_PRE_REHASH, (Function) event_prerehash); add_hook(HOOK_USERFILE, (Function) event_save); add_hook(HOOK_BACKUP, (Function) backup_userfile); add_hook(HOOK_DAILY, (Function) event_logfile); add_hook(HOOK_DAILY, (Function) event_resettraffic); add_hook(HOOK_LOADED, (Function) event_loaded); call_hook(HOOK_LOADED); debug0("main: entering loop"); while (1) { mainloop(1); } }
void stand(struct char_data *ch, struct gameobject *on) { // TODO - need to extract can_get_obj from get_obj // Impassible positions. switch (ch->position) { case POS_STANDING: if (on == NULL || on == ch->on) { send_to_char("You are already standing.\n\r", ch); return; } break; case POS_FIGHTING: send_to_char("Maybe you should finish this fight first?\n\r", ch); return; case POS_SLEEPING: if (IS_AFFECTED(ch, AFF_SLEEP)) { send_to_char("You can't wake up!\n\r", ch); return; } break; } // Validate target object, if any. if (on != NULL) { if (!is_standupon(on)) { send_to_char("You can't seem to find a place to stand.\n\r", ch); return; } if (ch->on != on && (long)count_users(on) >= on->value[0]) { act_new("There's no room to stand on $p.", ch, on, NULL, TO_ROOM, POS_DEAD, false); return; } // TODO check if object is gettable } // stand up, possibly on something. ch->position = POS_STANDING; if (on != ch->on) { struct gameobject *old_on = ch->on; ch->on = on; if (old_on != NULL && can_see_obj(ch, old_on)) { // TODO - only if object is gettable. get_obj(ch, old_on, NULL); } } // Notify. switch (ch->position) { default: if (on == NULL) { send_to_char("You stand up.\n\r", ch); act("$n stands up.", ch, NULL, NULL, TO_ROOM); } else if (IS_SET(on->value[2], STAND_AT)) { act("You stand at $p.", ch, on, NULL, TO_CHAR); act("$n stands at $p.", ch, on, NULL, TO_ROOM); } else if (IS_SET(on->value[2], STAND_ON)) { act("You stand on $p.", ch, on, NULL, TO_CHAR); act("$n stands on $p.", ch, on, NULL, TO_ROOM); } else { act("You stand in $p.", ch, on, NULL, TO_CHAR); act("$n stands on $p.", ch, on, NULL, TO_ROOM); } break; case POS_SLEEPING: if (on == NULL) { send_to_char("You wake and stand up.\n\r", ch); act("$n wakes and stands up.", ch, NULL, NULL, TO_ROOM); } else if (IS_SET(on->value[2], STAND_AT)) { act_new("You wake and stand at $p.", ch, on, NULL, TO_CHAR, POS_DEAD, false); act("$n wakes and stands at $p.", ch, on, NULL, TO_ROOM); } else if (IS_SET(on->value[2], STAND_ON)) { act_new("You wake and stand on $p.", ch, on, NULL, TO_CHAR, POS_DEAD, false); act("$n wakes and stands on $p.", ch, on, NULL, TO_ROOM); } else { act_new("You wake and stand in $p.", ch, on, NULL, TO_CHAR, POS_DEAD, false); act("$n wakes and stands in $p.", ch, on, NULL, TO_ROOM); } look_room(ch, ch->in_room); break; } }
void sit(struct char_data *ch, struct gameobject *on) { // TODO - it is currently possible to defeat object pickup restrictions by // sitting on them. Need to extract can_get_obj from get_obj and use it! // Impassible positions. switch (ch->position) { case POS_SITTING: if (on == NULL || on == ch->on) { send_to_char("You are already sitting down.\n\r", ch); return; } break; case POS_FIGHTING: send_to_char("Maybe you should finish this fight first?\n\r", ch); return; case POS_SLEEPING: if (IS_AFFECTED(ch, AFF_SLEEP)) { send_to_char("You can't wake up!\n\r", ch); return; } break; } // Validate target object, if any. if (on != NULL) { if (!is_situpon(on)) { send_to_char("You can't sit on that.\n\r", ch); return; } if (ch->position == POS_SLEEPING && on != ch->on) { send_to_char("You'll need to wake up to find it.\n\r", ch); return; } if (on->carried_by != NULL && on->carried_by != ch) { act_new("The $p is being held by someone!", ch, on, NULL, TO_CHAR, POS_DEAD, false); return; } if (on->in_obj != NULL) { if (on->in_obj->in_room != ch->in_room) { send_to_char("What? Where?\n\r", ch); return; } } if (ch->on != on && (long)count_users(on) >= on->value[0]) { act_new("There's no more room on $p.", ch, on, NULL, TO_CHAR, POS_DEAD, false); return; } } // Sit down, possibly on and object. ch->position = POS_SITTING; if (on != NULL) { ch->on = on; if (on->carried_by == ch) { obj_from_char(on); obj_to_room(on, ch->in_room); } else if (on->in_obj != NULL) { obj_from_obj(on); obj_to_room(on, ch->in_room); } } // Notify switch (ch->position) { default: if (on == NULL) { send_to_char("You sit down.\n\r", ch); act("$n sits down on the ground.", ch, NULL, NULL, TO_ROOM); } else if (IS_SET(on->value[2], SIT_AT)) { act("You sit down at $p.", ch, on, NULL, TO_CHAR); act("$n sits down at $p.", ch, on, NULL, TO_ROOM); } else if (IS_SET(on->value[2], SIT_ON)) { act("You sit on $p.", ch, on, NULL, TO_CHAR); act("$n sits on $p.", ch, on, NULL, TO_ROOM); } else { act("You sit down in $p.", ch, on, NULL, TO_CHAR); act("$n sits down in $p.", ch, on, NULL, TO_ROOM); } break; case POS_SLEEPING: if (on == NULL) { send_to_char("You wake and sit up.\n\r", ch); act("$n wakes and sits up.", ch, NULL, NULL, TO_ROOM); } else if (IS_SET(on->value[2], SIT_AT)) { act_new("You wake and sit at $p.", ch, on, NULL, TO_CHAR, POS_DEAD, false); act("$n wakes and sits at $p.", ch, on, NULL, TO_ROOM); } else if (IS_SET(on->value[2], SIT_ON)) { act_new("You wake and sit on $p.", ch, on, NULL, TO_CHAR, POS_DEAD, false); act("$n wakes and sits at $p.", ch, on, NULL, TO_ROOM); } else { act_new("You wake and sit in $p.", ch, on, NULL, TO_CHAR, POS_DEAD, false); act("$n wakes and sits in $p.", ch, on, NULL, TO_ROOM); } break; case POS_RESTING: if (on == NULL) { send_to_char("You stop resting.\n\r", ch); } else if (IS_SET(on->value[2], SIT_AT)) { act("You sit at $p.", ch, on, NULL, TO_CHAR); act("$n sits at $p.", ch, on, NULL, TO_ROOM); } else if (IS_SET(on->value[2], SIT_ON)) { act("You sit on $p.", ch, on, NULL, TO_CHAR); act("$n sits on $p.", ch, on, NULL, TO_ROOM); } break; } }
/** Create a new Z-line and add it to global lists. * \a ipmask must be an IP mask to create an IP-based ban. * * @param[in] cptr Client that sent us the Z-line. * @param[in] sptr Client that originated the Z-line. * @param[in] ipmask Text mask for the Z-line. * @param[in] reason Reason for Z-line. * @param[in] expire Expiration time of Z-line. * @param[in] lastmod Last modification time of Z-line. * @param[in] lifetime Lifetime of Z-line. * @param[in] flags Bitwise combination of ZLINE_* flags. * @return Zero or CPTR_KILLED, depending on whether \a sptr is suicidal. */ int zline_add(struct Client *cptr, struct Client *sptr, char *ipmask, char *reason, time_t expire, time_t lastmod, time_t lifetime, unsigned int flags) { struct Zline *azline; char imask[HOSTLEN + 2]; char *mask; int tmp; assert(0 != ipmask); assert(0 != reason); assert(((flags & (ZLINE_GLOBAL | ZLINE_LOCAL)) == ZLINE_GLOBAL) || ((flags & (ZLINE_GLOBAL | ZLINE_LOCAL)) == ZLINE_LOCAL)); Debug((DEBUG_DEBUG, "zline_add(\"%s\", \"%s\", \"%s\", \"%s\", %Tu, %Tu " "%Tu, 0x%04x)", cli_name(cptr), cli_name(sptr), ipmask, reason, expire, lastmod, lifetime, flags)); mask = ipmask; if (sizeof(imask) < ircd_snprintf(0, imask, sizeof(imask), "%s", mask)) return send_reply(sptr, ERR_LONGMASK); else if (MyUser(sptr) || (IsUser(sptr) && flags & ZLINE_LOCAL)) { switch (zline_checkmask(mask)) { case CHECK_OVERRIDABLE: /* oper overrided restriction */ if (flags & ZLINE_OPERFORCE) break; /*FALLTHROUGH*/ case CHECK_REJECTED: return send_reply(sptr, ERR_MASKTOOWIDE, imask); break; } if ((tmp = count_users(imask, flags)) >= feature_int(FEAT_ZLINEMAXUSERCOUNT) && !(flags & ZLINE_OPERFORCE)) return send_reply(sptr, ERR_TOOMANYUSERS, tmp); } if (!check_if_ipmask(ipmask)) return send_reply(sptr, ERR_INVALIDMASK); /* * You cannot set a negative (or zero) expire time, nor can you set an * expiration time for greater than ZLINE_MAX_EXPIRE. */ if (!(flags & ZLINE_FORCE) && (expire <= TStime() || expire > TStime() + ZLINE_MAX_EXPIRE)) { if (!IsServer(sptr) && MyConnect(sptr)) send_reply(sptr, ERR_BADEXPIRE, expire); return 0; } else if (expire <= TStime()) { /* This expired Z-line was forced to be added, so mark it inactive. */ flags &= ~ZLINE_ACTIVE; } if (!lifetime) /* no lifetime set, use expiration time */ lifetime = expire; /* lifetime is already an absolute timestamp */ /* Inform ops... */ sendto_opmask_butone(0, ircd_strncmp(reason, "AUTO", 4) ? SNO_GLINE : SNO_AUTO, "%s adding %s%s ZLINE for %s, expiring at " "%Tu: %s", (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ? cli_name(sptr) : cli_name((cli_user(sptr))->server), (flags & ZLINE_ACTIVE) ? "" : "deactivated ", (flags & ZLINE_LOCAL) ? "local" : "global", mask, expire, reason); /* and log it */ log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE, "%#C adding %s ZLINE for %s, expiring at %Tu: %s", sptr, flags & ZLINE_LOCAL ? "local" : "global", mask, expire, reason); /* make the zline */ azline = make_zline(mask, reason, expire, lastmod, lifetime, flags); /* since we've disabled overlapped Z-line checking, azline should * never be NULL... */ assert(azline); zline_propagate(cptr, sptr, azline); return do_zline(cptr, sptr, azline); /* knock off users if necessary */ }
u_char * var_hrsys(struct variable * vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { static char string[1024]; #if defined(solaris2) /* max size of nvram property */ char bootparam[8192]; #endif time_t now; #ifndef NR_TASKS int nproc = 0; #endif #ifdef linux FILE *fp; #endif #if CAN_USE_SYSCTL && defined(CTL_KERN) && defined(KERN_MAXPROC) static int maxproc_mib[] = { CTL_KERN, KERN_MAXPROC }; int buf_size; #endif #if defined(hpux10) || defined(hpux11) struct pst_static pst_buf; #endif if (header_hrsys(vp, name, length, exact, var_len, write_method) == MATCH_FAILED) return NULL; switch (vp->magic) { case HRSYS_UPTIME: long_return = get_uptime(); return (u_char *) & long_return; case HRSYS_DATE: #if defined(HAVE_MKTIME) && defined(HAVE_STIME) *write_method=ns_set_time; #endif (void *) time(&now); return (u_char *) date_n_time(&now, var_len); case HRSYS_LOAD_DEV: long_return = get_load_dev(); return (u_char *) & long_return; case HRSYS_LOAD_PARAM: #ifdef linux if((fp = fopen("/proc/cmdline", "r")) != NULL) { fgets(string, sizeof(string), fp); fclose(fp); } else { return NULL; } #elif defined(solaris2) *write_method=set_solaris_bootcommand_parameter; if ( get_solaris_eeprom_parameter("boot-command",bootparam) ) { snmp_log(LOG_ERR,"unable to lookup boot-command from eeprom\n"); return NULL; } strlcpy(string,bootparam,sizeof(string)); #else #if NO_DUMMY_VALUES return NULL; #endif sprintf(string, "ask Dave"); /* XXX */ #endif *var_len = strlen(string); return (u_char *) string; case HRSYS_USERS: long_return = count_users(); return (u_char *) & long_return; case HRSYS_PROCS: #if USING_HOST_HR_SWRUN_MODULE long_return = count_processes(); #else #if NO_DUMMY_VALUES return NULL; #endif long_return = 0; #endif return (u_char *) & long_return; case HRSYS_MAXPROCS: #if defined(NR_TASKS) long_return = NR_TASKS; /* <linux/tasks.h> */ #elif CAN_USE_SYSCTL && defined(CTL_KERN) && defined(KERN_MAXPROC) buf_size = sizeof(nproc); if (sysctl(maxproc_mib, 2, &nproc, &buf_size, NULL, 0) < 0) return NULL; long_return = nproc; #elif defined(hpux10) || defined(hpux11) pstat_getstatic(&pst_buf, sizeof(struct pst_static), 1, 0); long_return = pst_buf.max_proc; #elif defined(solaris2) long_return=get_max_solaris_processes(); if(long_return == -1) return NULL; #elif defined(NPROC_SYMBOL) auto_nlist(NPROC_SYMBOL, (char *) &nproc, sizeof(int)); long_return = nproc; #else #if NO_DUMMY_VALUES return NULL; #endif long_return = 0; #endif return (u_char *) & long_return; default: DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_hrsys\n", vp->magic)); } return NULL; } /* end var_hrsys */
int main(int argc, char **argv) { int xx, i; #ifdef STOP_UAC int nvpair[2]; #endif char buf[520], s[25]; FILE *f; #ifndef ENABLE_STRIP struct rlimit cdlim; #endif /* Don't allow Eggdrop to run as root. */ if (((int) getuid() == 0) || ((int) geteuid() == 0)) fatal("ERROR: Eggdrop will not run as root!", 0); #ifndef ENABLE_STRIP cdlim.rlim_cur = RLIM_INFINITY; cdlim.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &cdlim); #endif #include "patch.h" /* Version info! */ egg_snprintf(ver, sizeof ver, "eggdrop v%s", egg_version); egg_snprintf(version, sizeof version, "Eggdrop v%s (C) 1997 Robey Pointer (C) 2005 Eggheads", egg_version); /* Now add on the patchlevel (for Tcl) */ sprintf(&egg_version[strlen(egg_version)], " %u", egg_numver); strcat(egg_version, egg_xtra); #ifdef STOP_UAC nvpair[0] = SSIN_UACPROC; nvpair[1] = UAC_NOPRINT; setsysinfo(SSI_NVPAIRS, (char *) nvpair, 1, NULL, 0); #endif /* Set up error / signal traps. */ setup_signal_traps(); /* Initialize a few variables before main loop. */ cache_miss = 0; cache_hit = 0; chanset = NULL; now = time(NULL); egg_memcpy(&nowtm, localtime(&now), sizeof(struct tm)); lastmin = nowtm.tm_min; /* Initialize random number generator. */ srandom((unsigned int) (now % (getpid() + getppid()))); init_mem(); init_language(1); /* Process command line arguments. */ process_args(argc, argv); printf("\n%s\n", version); init_dcc_max(); init_userent(); logfile_init(0); init_bots(); init_net(); init_modules(); if (backgrd) bg_prepare_split(); init_tcl(argc, argv); init_language(0); help_init(); traffic_init(); logfile_init(1); #ifdef STATIC link_statics(); #endif strncpyz(s, ctime(&now), sizeof s); strcpy(&s[11], &s[20]); putlog(LOG_ALL, "*", "--- Loading %s (%s)", ver, s); /* Read configuration data. */ readconfig(); /* Check for encryption module. */ if (!encrypt_pass) { printf(MOD_NOCRYPT); bg_send_quit(BG_ABORT); exit(1); } putlog(LOG_MISC, "*", "=== %s: %d channels, %d users.", botnetnick, count_channels(), count_users(userlist)); if (!pid_file[0]) egg_snprintf(pid_file, sizeof pid_file, "pid.%s", botnetnick); /* Check for pre-existing eggdrop! */ f = fopen(pid_file, "r"); if (f != NULL) { fgets(s, 10, f); xx = atoi(s); kill(xx, SIGCHLD); /* Meaningless kill to determine if PID is used. */ if (errno != ESRCH) { printf(EGG_RUNNING1, botnetnick); printf(EGG_RUNNING2, pid_file); bg_send_quit(BG_ABORT); exit(1); } } /* Move into background? */ if (backgrd) { #ifndef CYGWIN_HACKS bg_do_split(); } else { #endif xx = getpid(); if (xx != 0) { FILE *fp; /* Write PID to file. */ unlink(pid_file); fp = fopen(pid_file, "w"); if (fp != NULL) { fprintf(fp, "%u\n", xx); if (fflush(fp)) { /* Let the bot live since this doesn't appear to be a botchk. */ printf("Cannot not write to '%s' (PID file).\n", pid_file); fclose(fp); unlink(pid_file); } else fclose(fp); } else printf("Cannot not write to '%s' (PID file).\n", pid_file); #ifdef CYGWIN_HACKS printf("Launched into the background (PID: %d)\n\n", xx); #endif } } use_stderr = 0; /* Stop writing to stderr now */ if (backgrd) { /* Ok, try to disassociate from controlling terminal (finger cross) */ #if defined(HAVE_SETPGID) && !defined(CYGWIN_HACKS) setpgid(0, 0); #endif /* Tcl wants the stdin, stdout and stderr file handles kept open. */ freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr); #ifdef CYGWIN_HACKS FreeConsole(); #endif } /* Terminal emulating dcc chat */ if (!backgrd && term_z) { int n = new_dcc(&DCC_CHAT, sizeof(struct chat_info)); dcc[n].addr = iptolong(getmyip()); dcc[n].sock = STDOUT; dcc[n].timeval = now; dcc[n].u.chat->con_flags = conmask; dcc[n].u.chat->strip_flags = STRIP_ALL; dcc[n].status = STAT_ECHO; strcpy(dcc[n].nick, "HQ"); strcpy(dcc[n].host, "llama@console"); /* HACK: Workaround not to pass literal "HQ" as a non-const arg */ dcc[n].user = get_user_by_handle(userlist, dcc[n].nick); /* Make sure there's an innocuous HQ user if needed */ if (!dcc[n].user) { userlist = adduser(userlist, dcc[n].nick, "none", "-", USER_PARTY); dcc[n].user = get_user_by_handle(userlist, dcc[n].nick); } setsock(STDOUT, 0); /* Entry in net table */ dprintf(n, "\n### ENTERING DCC CHAT SIMULATION ###\n\n"); dcc_chatter(n); } then = now; online_since = now; autolink_cycle(NULL); /* Hurry and connect to tandem bots. */ add_help_reference("cmds1.help"); add_help_reference("cmds2.help"); add_help_reference("core.help"); /* Create hooks. */ add_hook(HOOK_SECONDLY, (Function) core_secondly); add_hook(HOOK_MINUTELY, (Function) core_minutely); add_hook(HOOK_HOURLY, (Function) core_hourly); add_hook(HOOK_REHASH, (Function) event_rehash); add_hook(HOOK_PRE_REHASH, (Function) event_prerehash); add_hook(HOOK_USERFILE, (Function) event_save); add_hook(HOOK_BACKUP, (Function) backupuserfile); add_hook(HOOK_DAILY, (Function) event_logfile); add_hook(HOOK_DAILY, (Function) traffic_reset); add_hook(HOOK_LOADED, (Function) event_loaded); call_hook(HOOK_LOADED); debug0("main: entering loop"); while (1) { int socket_cleanup = 0; #ifdef USE_TCL_EVENTS /* Process a single Tcl event. */ Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT); #endif now = time(NULL); random(); /* Every second... */ if (now != then) { call_hook(HOOK_SECONDLY); then = now; } /* Only do this every so often. */ if (!socket_cleanup) { socket_cleanup = 5; /* Remove dead dcc entries. */ dcc_remove_lost(); /* Check for server or dcc activity. */ dequeue_sockets(); } else { socket_cleanup--; } /* Free unused structures. */ garbage_collect(); xx = sockgets(buf, &i); if (xx >= 0) { /* Non-error */ int idx; for (idx = 0; idx < dcc_total; idx++) { if (dcc[idx].sock != xx) continue; if (dcc[idx].type && dcc[idx].type->activity) { traffic_update_in(dcc[idx].type, (strlen(buf) + 1)); /* Traffic stats. */ dcc[idx].type->activity(idx, buf, i); } else { putlog(LOG_MISC, "*", "!!! untrapped dcc activity: type %s, sock %d", dcc[idx].type->name, dcc[idx].sock); } break; } } else if (xx == -1) { /* EOF */ int idx; if (i == STDOUT && !backgrd) fatal("END OF FILE ON TERMINAL", 0); for (idx = 0; idx < dcc_total; idx++) { if (dcc[idx].sock != i) continue; if (dcc[idx].type && dcc[idx].type->eof) { dcc[idx].type->eof(idx); } else { putlog(LOG_MISC, "*", "*** ATTENTION: DEAD SOCKET (%d) OF TYPE %s UNTRAPPED", i, dcc[idx].type ? dcc[idx].type->name : "*UNKNOWN*"); killsock(i); lostdcc(idx); } idx = dcc_total + 1; } if (idx == dcc_total) { putlog(LOG_MISC, "*", "(@) EOF socket %d, not a dcc socket, not anything.", i); close(i); killsock(i); } } else if (xx == -2 && errno != EINTR) { /* select() error */ putlog(LOG_MISC, "*", "* Socket error #%d; recovering.", errno); for (i = 0; i < dcc_total; i++) { if ((fcntl(dcc[i].sock, F_GETFD, 0) == -1) && (errno == EBADF)) { putlog(LOG_MISC, "*", "DCC socket %d (type %d, name '%s') expired -- pfft", dcc[i].sock, dcc[i].type, dcc[i].nick); killsock(dcc[i].sock); lostdcc(i); i--; } } } else if (xx == -3) { call_hook(HOOK_IDLE); socket_cleanup = 0; /* If we've been idle, cleanup & flush */ } if (do_restart) { if (do_restart == -2) { rehash(); } else { int f = 1; module_entry *p; Function startfunc; char name[256]; check_tcl_event("prerestart"); /* Unload as many modules as possible */ while (f) { f = 0; for (p = module_list; p != NULL; p = p->next) { dependancy *d = dependancy_list; int ok = 1; while (ok && d) { if (d->needed == p) ok = 0; d = d->next; } if (ok) { strcpy(name, p->name); if (module_unload(name, botnetnick) == NULL) { f = 1; break; } } } } /* Make sure we don't have any modules left hanging around other than * "eggdrop" and the two that are supposed to be. */ for (f = 0, p = module_list; p; p = p->next) { if (strcmp(p->name, "eggdrop") && strcmp(p->name, "encryption") && strcmp(p->name, "uptime")) { f++; } } if (f != 0) { putlog(LOG_MISC, "*", MOD_STAGNANT); } /* Flush log files to disk. */ flushlogs(); /* Clean up Tcl stuff. */ kill_tcl(); /* Initialize stuff again. */ init_tcl(argc, argv); init_language(0); help_init(); traffic_init(); logfile_init(1); /* This resets our modules which we didn't unload (encryption and uptime). */ for (p = module_list; p; p = p->next) { if (p->funcs) { startfunc = p->funcs[MODCALL_START]; startfunc(NULL); } } rehash(); restart_chons(); call_hook(HOOK_LOADED); } do_restart = 0; } } }
addusernow() { char pw[50]; int cnt=0, num; char *c_num; char **mailingListNames; char *tmp; char *email; char **arguments; int pid; int i; int error; struct vqpasswd *mypw; c_num = malloc(MAX_BUFF); email = malloc(128); tmp = malloc(MAX_BUFF); arguments = (char **)malloc(MAX_BUFF); count_users(); load_limits(); if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); vclose(); exit(0); } if ( MaxPopAccounts != -1 && CurPopAccounts >= MaxPopAccounts ) { sprintf(StatusMessage, "%s %d\n", get_html_text("199"), MaxPopAccounts); show_menu(); vclose(); exit(0); } GetValue(TmpCGI,Newu, "newu=", MAX_BUFF); if ( fixup_local_name(Newu) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("148"), Newu); adduser(); vclose(); exit(0); } if ( check_local_user(Newu) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("175"), Newu); adduser(); vclose(); exit(0); } GetValue(TmpCGI,Password1, "password1=", MAX_BUFF); GetValue(TmpCGI,Password2, "password2=", MAX_BUFF); if ( strncmp( Password1, Password2, MAX_BUFF ) != 0 ) { sprintf(StatusMessage, "%s\n", get_html_text("200")); adduser(); vclose(); exit(0); } if ( strlen(Password1) <= 0 ) { sprintf(StatusMessage, "%s\n", get_html_text("234")); adduser(); vclose(); exit(0); } strcpy(email, ""); strcat(email,Newu); strcat(email,"@"); strcat(email,Domain); GetValue(TmpCGI,Gecos, "gecos=", MAX_BUFF); if ( strlen( Gecos ) == 0 ) { strcpy(Gecos, Newu); } GetValue(TmpCGI, c_num, "number_of_mailinglist=", MAX_BUFF); num = atoi(c_num); if(!(mailingListNames = malloc(sizeof(char *) * num))) { sprintf(StatusMessage, "%s\n", get_html_text("201")); vclose(); exit(0); } else { for(cnt = 0; cnt < num; cnt++) { if(!(mailingListNames[cnt] = malloc(MAX_BUFF))) { sprintf(StatusMessage, "%s\n", get_html_text("201")); vclose(); exit(0); } } for(cnt = 0; cnt < num; cnt++) { sprintf(tmp, "subscribe%d=", cnt); error = GetValue(TmpCGI, mailingListNames[cnt], tmp, MAX_BUFF); if( error != -1 ) { pid=fork(); if (pid==0) { sprintf(TmpBuf1, "%s/ezmlm-sub", EZMLMDIR); sprintf(TmpBuf2, "%s/%s", RealDir, mailingListNames[cnt]); execl(TmpBuf1, "ezmlm-sub", TmpBuf2, email, NULL); exit(127); } else { wait(&pid); } } } } /* add the user then get the vpopmail password structure */ if ( vadduser( Newu, Domain, Password1, Gecos, USE_POP ) == 0 && #ifdef MYSQL_REPLICATION !sleep(2) && #endif (mypw = vauth_getpw( Newu, Domain )) != NULL ) { /* from the load_limits() function, set user flags */ if( DisablePOP > 0 ) mypw->pw_gid |= NO_POP; if( DisableIMAP > 0 ) mypw->pw_gid |= NO_IMAP; if( DisableDialup > 0 ) mypw->pw_gid |= NO_DIALUP; if( DisablePasswordChanging > 0 ) mypw->pw_gid |= NO_PASSWD_CHNG; if( DisableWebmail > 0 ) mypw->pw_gid |= NO_WEBMAIL; if( DisableRelay > 0 ) mypw->pw_gid |= NO_RELAY; if( DefaultQuota[0]!= 0 ) mypw->pw_shell = DefaultQuota; /* update the user information */ if ( vauth_setpw( mypw, Domain ) != VA_SUCCESS ) { /* report error */ sprintf(StatusMessage, "%s %s@%s (%s) %s", get_html_text("002"), Newu, Domain, Gecos, get_html_text("120")); } else { /* report success */ sprintf(StatusMessage, "%s %s@%s (%s) %s", get_html_text("002"), Newu, Domain, Gecos, get_html_text("119")); } /* otherwise, report error */ } else { sprintf(StatusMessage, "<font color=\"red\">%s %s@%s (%s) %s</font>", get_html_text("002"), Newu, Domain, Gecos, get_html_text("120")); } call_hooks( HOOK_ADDUSER ); /* After we add the user, show the user page * people like to visually verify the results */ show_users(Username, Domain, Mytime); }
/* Dump status info out to dcc */ void tell_verbose_status(int idx) { char s[256], s1[121], s2[81]; char *vers_t, *uni_t; int i; time_t now2 = now - online_since, hr, min; #ifdef HAVE_GETRUSAGE struct rusage ru; #else # ifdef HAVE_CLOCK clock_t cl; # endif #endif #ifdef HAVE_UNAME struct utsname un; if (!uname(&un) < 0) { #endif vers_t = " "; uni_t = "*unknown*"; #ifdef HAVE_UNAME } else { vers_t = un.release; uni_t = un.sysname; } #endif i = count_users(userlist); dprintf(idx, "I am %s, running %s: %d user%s (mem: %uk).\n", botnetnick, ver, i, i == 1 ? "" : "s", (int) (expected_memory() / 1024)); #ifdef IPV6 dprintf(idx, "Unofficial IPv6 patch for v1.6.21 based on the v1.6.18 IPv6 patch \n"); #endif s[0] = 0; if (now2 > 86400) { /* days */ sprintf(s, "%d day", (int) (now2 / 86400)); if ((int) (now2 / 86400) >= 2) strcat(s, "s"); strcat(s, ", "); now2 -= (((int) (now2 / 86400)) * 86400); } hr = (time_t) ((int) now2 / 3600); now2 -= (hr * 3600); min = (time_t) ((int) now2 / 60); sprintf(&s[strlen(s)], "%02d:%02d", (int) hr, (int) min); s1[0] = 0; if (backgrd) strcpy(s1, MISC_BACKGROUND); else { if (term_z) strcpy(s1, MISC_TERMMODE); else if (con_chan) strcpy(s1, MISC_STATMODE); else strcpy(s1, MISC_LOGMODE); } #ifdef HAVE_GETRUSAGE getrusage(RUSAGE_SELF, &ru); hr = (int) ((ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) / 60); min = (int) ((ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) - (hr * 60)); sprintf(s2, "CPU: %02d:%02d", (int) hr, (int) min); /* Actally min/sec */ #else # ifdef HAVE_CLOCK cl = (clock() / CLOCKS_PER_SEC); hr = (int) (cl / 60); min = (int) (cl - (hr * 60)); sprintf(s2, "CPU: %02d:%02d", (int) hr, (int) min); /* Actually min/sec */ # else sprintf(s2, "CPU: unknown"); # endif #endif dprintf(idx, "%s %s (%s) - %s - %s: %4.1f%%\n", MISC_ONLINEFOR, s, s1, s2, MISC_CACHEHIT, 100.0 * ((float) cache_hit) / ((float) (cache_hit + cache_miss))); dprintf(idx, "Configured with: " EGG_AC_ARGS "\n"); if (admin[0]) dprintf(idx, "Admin: %s\n", admin); dprintf(idx, "Config file: %s\n", configfile); dprintf(idx, "OS: %s %s\n", uni_t, vers_t); /* info library */ dprintf(idx, "%s %s\n", MISC_TCLLIBRARY, ((interp) && (Tcl_Eval(interp, "info library") == TCL_OK)) ? tcl_resultstring() : "*unknown*"); /* info tclversion/patchlevel */ dprintf(idx, "%s %s (%s %s)\n", MISC_TCLVERSION, ((interp) && (Tcl_Eval(interp, "info patchlevel") == TCL_OK)) ? tcl_resultstring() : (Tcl_Eval(interp, "info tclversion") == TCL_OK) ? tcl_resultstring() : "*unknown*", MISC_TCLHVERSION, TCL_PATCH_LEVEL ? TCL_PATCH_LEVEL : "*unknown*"); if (tcl_threaded()) dprintf(idx, "Tcl is threaded.\n"); dprintf(idx, "Socket table: %d/%d\n", threaddata()->MAXSOCKS, max_socks); }
void do_stand (CHAR_DATA * ch, char *argument) { OBJ_DATA *obj = NULL; if (argument[0] != '\0') { if(ch->infight) { send_to_char ("Maybe you should finish fighting first?\n\r", ch); return; } obj = get_obj_list (ch, argument, ch->in_room->contents); if (obj == NULL) { send_to_char ("You don't see that here.\n\r", ch); return; } if (obj->item_type != ITEM_FURNITURE || (!IS_SET (obj->value[2], STAND_AT) && !IS_SET (obj->value[2], STAND_ON) && !IS_SET (obj->value[2], STAND_IN))) { send_to_char ("You can't seem to find a place to stand.\n\r", ch); return; } if (ch->on != obj && count_users (obj) >= obj->value[0]) { act_new ("There's no room to stand on $p.", ch, obj, NULL, TO_CHAR, POS_DEAD); return; } ch->on = obj; } switch (ch->position) { case POS_SLEEPING: if (obj == NULL) { send_to_char ("You wake and stand up.\n\r", ch); act ("$n wakes and stands up.", ch, NULL, NULL, TO_ROOM); ch->on = NULL; } else if (IS_SET (obj->value[2], STAND_AT)) { act_new ("You wake and stand at $p.", ch, obj, NULL, TO_CHAR, POS_DEAD); act ("$n wakes and stands at $p.", ch, obj, NULL, TO_ROOM); } else if (IS_SET (obj->value[2], STAND_ON)) { act_new ("You wake and stand on $p.", ch, obj, NULL, TO_CHAR, POS_DEAD); act ("$n wakes and stands on $p.", ch, obj, NULL, TO_ROOM); } else { act_new ("You wake and stand in $p.", ch, obj, NULL, TO_CHAR, POS_DEAD); act ("$n wakes and stands in $p.", ch, obj, NULL, TO_ROOM); } ch->position = POS_STANDING; do_function (ch, &do_look, "auto"); break; case POS_RESTING: case POS_SITTING: if (obj == NULL) { send_to_char ("You stand up.\n\r", ch); act ("$n stands up.", ch, NULL, NULL, TO_ROOM); ch->on = NULL; } else if (IS_SET (obj->value[2], STAND_AT)) { act ("You stand at $p.", ch, obj, NULL, TO_CHAR); act ("$n stands at $p.", ch, obj, NULL, TO_ROOM); } else if (IS_SET (obj->value[2], STAND_ON)) { act ("You stand on $p.", ch, obj, NULL, TO_CHAR); act ("$n stands on $p.", ch, obj, NULL, TO_ROOM); } else { act ("You stand in $p.", ch, obj, NULL, TO_CHAR); act ("$n stands on $p.", ch, obj, NULL, TO_ROOM); } ch->position = POS_STANDING; break; case POS_STANDING: send_to_char ("You are already standing.\n\r", ch); break; case POS_FIGHTING: send_to_char ("You are already fighting!\n\r", ch); break; } return; }
void do_sleep (CHAR_DATA * ch, char *argument) { OBJ_DATA *obj = NULL; switch (ch->position) { case POS_SLEEPING: send_to_char ("You are already sleeping.\n\r", ch); break; case POS_RESTING: case POS_SITTING: case POS_STANDING: if (argument[0] == '\0' && ch->on == NULL) { send_to_char ("You go to sleep.\n\r", ch); act ("$n goes to sleep.", ch, NULL, NULL, TO_ROOM); ch->position = POS_SLEEPING; } else { /* find an object and sleep on it */ if (argument[0] == '\0') obj = ch->on; else obj = get_obj_list (ch, argument, ch->in_room->contents); if (obj == NULL) { send_to_char ("You don't see that here.\n\r", ch); return; } if (obj->item_type != ITEM_FURNITURE || (!IS_SET (obj->value[2], SLEEP_ON) && !IS_SET (obj->value[2], SLEEP_IN) && !IS_SET (obj->value[2], SLEEP_AT))) { send_to_char ("You can't sleep on that!\n\r", ch); return; } if (ch->on != obj && count_users (obj) >= obj->value[0]) { act_new ("There is no room on $p for you.", ch, obj, NULL, TO_CHAR, POS_DEAD); return; } ch->on = obj; if (IS_SET (obj->value[2], SLEEP_AT)) { act ("You go to sleep at $p.", ch, obj, NULL, TO_CHAR); act ("$n goes to sleep at $p.", ch, obj, NULL, TO_ROOM); } else if (IS_SET (obj->value[2], SLEEP_ON)) { act ("You go to sleep on $p.", ch, obj, NULL, TO_CHAR); act ("$n goes to sleep on $p.", ch, obj, NULL, TO_ROOM); } else { act ("You go to sleep in $p.", ch, obj, NULL, TO_CHAR); act ("$n goes to sleep in $p.", ch, obj, NULL, TO_ROOM); } ch->position = POS_SLEEPING; } break; case POS_FIGHTING: send_to_char ("You are already fighting!\n\r", ch); break; } return; }
void do_sit (CHAR_DATA * ch, char *argument) { OBJ_DATA *obj = NULL; if(ch->infight) { send_to_char ("Maybe you should finish this fight first?\n\r", ch); return; } /* okay, now that we know we can sit, find an object to sit on */ if (argument[0] != '\0') { obj = get_obj_list (ch, argument, ch->in_room->contents); if (obj == NULL) { send_to_char ("You don't see that here.\n\r", ch); return; } } else obj = ch->on; if (obj != NULL) { if (obj->item_type != ITEM_FURNITURE || (!IS_SET (obj->value[2], SIT_ON) && !IS_SET (obj->value[2], SIT_IN) && !IS_SET (obj->value[2], SIT_AT))) { send_to_char ("You can't sit on that.\n\r", ch); return; } if (obj != NULL && ch->on != obj && count_users (obj) >= obj->value[0]) { act_new ("There's no more room on $p.", ch, obj, NULL, TO_CHAR, POS_DEAD); return; } ch->on = obj; } switch (ch->position) { case POS_SLEEPING: if (obj == NULL) { send_to_char ("You wake and sit up.\n\r", ch); act ("$n wakes and sits up.", ch, NULL, NULL, TO_ROOM); } else if (IS_SET (obj->value[2], SIT_AT)) { act_new ("You wake and sit at $p.", ch, obj, NULL, TO_CHAR, POS_DEAD); act ("$n wakes and sits at $p.", ch, obj, NULL, TO_ROOM); } else if (IS_SET (obj->value[2], SIT_ON)) { act_new ("You wake and sit on $p.", ch, obj, NULL, TO_CHAR, POS_DEAD); act ("$n wakes and sits at $p.", ch, obj, NULL, TO_ROOM); } else { act_new ("You wake and sit in $p.", ch, obj, NULL, TO_CHAR, POS_DEAD); act ("$n wakes and sits in $p.", ch, obj, NULL, TO_ROOM); } ch->position = POS_SITTING; break; case POS_RESTING: if (obj == NULL) send_to_char ("You stop resting.\n\r", ch); else if (IS_SET (obj->value[2], SIT_AT)) { act ("You sit at $p.", ch, obj, NULL, TO_CHAR); act ("$n sits at $p.", ch, obj, NULL, TO_ROOM); } else if (IS_SET (obj->value[2], SIT_ON)) { act ("You sit on $p.", ch, obj, NULL, TO_CHAR); act ("$n sits on $p.", ch, obj, NULL, TO_ROOM); } ch->position = POS_SITTING; break; case POS_SITTING: send_to_char ("You are already sitting down.\n\r", ch); break; case POS_STANDING: if (obj == NULL) { send_to_char ("You sit down.\n\r", ch); act ("$n sits down on the ground.", ch, NULL, NULL, TO_ROOM); } else if (IS_SET (obj->value[2], SIT_AT)) { act ("You sit down at $p.", ch, obj, NULL, TO_CHAR); act ("$n sits down at $p.", ch, obj, NULL, TO_ROOM); } else if (IS_SET (obj->value[2], SIT_ON)) { act ("You sit on $p.", ch, obj, NULL, TO_CHAR); act ("$n sits on $p.", ch, obj, NULL, TO_ROOM); } else { act ("You sit down in $p.", ch, obj, NULL, TO_CHAR); act ("$n sits down in $p.", ch, obj, NULL, TO_ROOM); } ch->position = POS_SITTING; break; } return; }