void do_memory(USER_DATA *usr, char *argument) { HELP_DATA *fHelp; char buf[STRING]; int count1, count2; memory_other(usr); do_statforum(usr, ""); memory_validates(usr); memory_banishes(usr); count1 = count2 = 0; for (fHelp = first_help; fHelp; fHelp = fHelp->next) count1++; sprintf(buf, "Help : %4d -- %d bytes\n\r", count1, count1 * (sizeof(*fHelp))); send_to_user(buf, usr); sprintf(buf, "Strings %5d strings of %7d bytes (max %d).\n\r", nAllocString, sAllocString, MAX_STRING); send_to_user(buf, usr); sprintf(buf, "Perms %5d blocks of %7d bytes.\n\r", nAllocPerm, sAllocPerm); send_to_user(buf, usr); sprintf(buf, "Total %d users found.\n\r", count_files(USER_DIR)); send_to_user(buf, usr); return; }
void func_delete_mail(USER_DATA *usr, char *argument) { MAIL_DATA *pMail; int vnum = 1; int anum = 0; if (argument[0] == '\0' || !is_number(argument)) { syntax("[#Wd#x]elete <mail number>", usr); return; } anum = atoi(argument); for (pMail = usr->pMailFirst; pMail; pMail = pMail->next) { if (pMail && (vnum++ == anum)) { if (pMail->marked) { send_to_user( "This message is already marked for deletion.\n\r", usr); return; } print_to_user(usr, "Message %d marked for deletion.\n\r", vnum - 1); pMail->marked = TRUE; return; } } send_to_user("There aren't that many mail.\n\r", usr); return; }
void edit_mail_mode(USER_DATA *usr, char *argument) { char arg[INPUT]; while (isspace(*argument)) argument++; smash_tilde(argument); usr->timer = 0; argument = one_argument(argument, arg); if (arg[0] == '\0') { func_rnew_mail(usr); return; } else if (!str_cmp(arg, "?") || !str_cmp(arg, "h")) { do_help(usr, "MAIL_DATA-INDEX"); return; } else if (!str_cmp(arg, "l")) { func_list_mail(usr); return; } else if (!str_cmp(arg, "r")) { func_reply_mail(usr, argument); return; } else if (!str_cmp(arg, "d")) { func_delete_mail(usr, argument); return; } else if (!str_cmp(arg, "q")) { func_quit_mail(usr); return; } else if (!str_cmp(arg, "c")) { if (argument[0] == '\0') { syntax("[#Wc#x]ompose <user name>", usr); return; } if (!is_user(argument)) { send_to_user("No such user.\n\r", usr); return; } if (is_enemy(usr, argument)) { send_to_user("You can't sent mail to your enemies.\n\r", usr); return; } mail_attach(usr); if (usr->pCurrentMail->to) free_string(usr->pCurrentMail->to); usr->pCurrentMail->to = str_dup(argument); EDIT_MODE(usr) = EDITOR_MAIL_SUBJECT; return; } else if (is_number(arg)) { func_read_mail(usr, arg); return; } else { send_to_user( "Unknown mail command, try '?' in order to show help.\n\r", usr); return; } }
void do_mail(USER_DATA *usr, char *argument) { char arg[INPUT]; one_argument(argument, arg); if (arg[0] == '\0') { print_to_user(usr, "\n\rTotal messages: %-3d\n\r\n\r", count_mail(usr)); do_help(usr, "MAIL_DATA-INDEX"); EDIT_MODE(usr) = EDITOR_MAIL; return; } if (!is_user(arg)) { send_to_user("No such user.\n\r", usr); return; } if (is_enemy(usr, arg)) { send_to_user("You can't sent mail to your enemies.\n\r", usr); return; } mail_attach(usr); if (usr->pCurrentMail->to) free_string(usr->pCurrentMail->to); usr->pCurrentMail->to = str_dup(arg); EDIT_MODE(usr) = EDITOR_MAIL_SUBJECT; }
/* Sends a string to scripts. */ void non_format_to_scripts(char *buf) { struct user_t *user; user = non_human_user_list; /* If we are the parent, send directly to script processes */ if(pid > 0) { while(user != NULL) { if(user->type == SCRIPT) send_to_user(buf, user); user = user->next; } } /* If we are child, send to parent first */ else { while(user != NULL) { if(user->type == FORKED) send_to_user(buf, user); user = user->next; } } }
void finger_mail(USER_DATA *usr, char *name) { MAIL_DATA *pMail; MAIL_DATA *fMailFirst; MAIL_DATA *fMailLast; USER_DATA *to; char buf[INPUT]; FILE *fpMail; int count = 0; int new_count = 0; if (!(to = get_user(name))) { if (!is_user(name)) { bbs_bug("Finger_mail: No such user %s", name); send_to_user("ERROR: No such user.\n\r", usr); return; } fMailFirst = NULL; fMailLast = NULL; sprintf(buf, "%s%s", MAIL_DIR, capitalize(name)); if (!(fpMail = fopen(buf, "r"))) { bbs_bug("Finger_mail: Could not open to read %s", buf); /* send_to_user("ERROR: Could not open mail file.\n\r", usr); BAXTER */ send_to_user("Mail: No new messages.\n\r\n\r", usr); return; } while ((pMail = read_mail(fpMail)) != NULL) LINK(pMail, fMailFirst, fMailLast); for (pMail = fMailFirst; pMail; pMail = pMail->next) { if (pMail) { if (pMail->stamp_time > pMail->read_time) new_count++; count++; } } if (new_count > 0) sprintf(buf, "Mail: %d new message%s.\n\r\n\r", new_count, new_count > 1 ? "s" : ""); else sprintf(buf, "Mail: No new messages.\n\r\n\r"); send_to_user(buf, usr); return; } if (unread_mail(to) > 0) sprintf(buf, "Mail: %d new message%s.\n\r\n\r", unread_mail(to), unread_mail(to) > 1 ? "s" : ""); else sprintf(buf, "Mail: No new messages.\n\r\n\r"); send_to_user(buf, usr); return; }
void do_unread_mail(USER_DATA *usr) { if (unread_mail(usr) > 0) print_to_user(usr, "#YMail: %d new mail%s.#x\n\r\n\r", unread_mail(usr), unread_mail(usr) > 1 ? "s" : ""); else send_to_user("Mail: No new mails.\n\r\n\r", usr); if (!IS_TOGGLE(usr, TOGGLE_XING)) send_to_user("You toggle message eXpress Off!\n\r", usr); if (IS_TOGGLE(usr, TOGGLE_IDLE)) send_to_user("You toggle idle mode On!\n\r", usr); }
void func_list_mail(USER_DATA *usr) { MAIL_DATA *pMail; char buf[STRING]; BUFFER *buffer; int vnum = 0; buffer = new_buf(); add_buf(buffer, " Num Date From Subject\n\r"); for (pMail = usr->pMailFirst; pMail; pMail = pMail->next) { if (pMail) { sprintf(buf, "%s %3d %s %-15s %s\n\r", pMail->marked ? "M" : (pMail->stamp_time > pMail->read_time) ? "N" : " ", vnum + 1, time_str(pMail->stamp_time), pMail->from, pMail->subject); add_buf(buffer, buf); vnum++; } } if (vnum > 0) { page_to_user(buf_string(buffer), usr); free_buf(buffer); return; } send_to_user("You don't have any mail.\n\r", usr); free_buf(buffer); return; }
static unsigned int get_icmp(unsigned int hook, struct sk_buff **pskb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)) { struct iphdr *iph = (*pskb)->nh.iph; struct packet_info info; if(iph->protocol == IPPROTO_ICMP) { read_lock_bh(&user_proc.lock); if(user_proc.pid != 0) { read_unlock_bh(&user_proc.lock); info.src = iph->saddr; info.dest = iph->daddr; send_to_user(&info); } else read_unlock_bh(&user_proc.lock); } return NF_ACCEPT; }
void func_rnew_mail(USER_DATA *usr) { MAIL_DATA *pMail; char buf[STRING]; BUFFER *buffer; int vnum = 1; buffer = new_buf(); for (pMail = usr->pMailFirst; pMail; pMail = pMail->next) { if (pMail->stamp_time <= pMail->read_time) break; } if (pMail) { time_t *last_read = &pMail->read_time; *last_read = UMAX(*last_read, pMail->stamp_time); sprintf(buf, "Reading new message %d.\n\rDate: %s\n\rFrom: %s\n\r" "Subject: %s\n\r\n\r", vnum, time_str(pMail->stamp_time), pMail->from, pMail->subject); add_buf(buffer, buf); add_buf(buffer, pMail->message); add_buf(buffer, "#x\n\r"); page_to_user(buf_string(buffer), usr); free_buf(buffer); save_mail(usr); return; } send_to_user("No new messages.\n\r", usr); return; }
/*---------------- * MAPPING OFF ---------------------------- */ void CEngine::mappingOff() { if (mapping) { send_to_user("--[ Mapping is now OFF!\r\n"); mapping = 0; } }
void do_reboot(USER_DATA *usr, char *argument) { DESC_DATA *d, *d_next; FILE *fp; char p_buf[100]; char c_buf[100]; extern int port; extern int control; if (!(fp = fopen(COPYOVER_FILE, "w"))) { send_to_user("ERROR: Could not open to save copyover.data\n\r", usr); bbs_bug("Do_copyover: Could not open to save %s", COPYOVER_FILE); return; } system_info("Rebooting, please reamin seated"); for (d = desc_list; d; d = d_next) { USER_DATA *usr = d->user; d_next = d->next; if (!USR(d) || d->login > CON_LOGIN) { write_to_desc(d->descr, "\n\r\007Sorry, we are rebooting. " "Come back in a few minutes.\n\r", 0); close_socket(d); } else if (EDIT_MODE(USR(d)) != EDITOR_NONE) { write_to_desc(d->descr, "\n\r\007Sorry, we are rebooting. " "Come back in a few minutes.\n\r", 0); close_socket(d); } else { fprintf(fp, "%d %s %s %s %s\n", d->descr, usr->pBoard->short_name, usr->name, d->ident, d->host); save_user(usr); } } fprintf(fp, "-1\n"); fclose(fp); fclose(fpReserve); sprintf(p_buf, "%d", port); sprintf(c_buf, "%d", control); execl(EXE_FILE, "bbs", p_buf, "copyover", c_buf, (char *) NULL); perror("Do_copyover: execl"); send_to_user("ERROR: Copyover failed!\n\r", usr); fpReserve = fopen(NULL_FILE, "r"); }
void edit_mail_send(USER_DATA *usr) { USER_DATA *to; FILE *fpMail; char buf[INPUT]; if (!usr->pCurrentMail) { send_to_user("ERROR: Null usr->pCurrentMail.\n\r", usr); bbs_bug("Edit_mail_send: Null usr->pCurrentMail"); return; } if ((to = get_user(usr->pCurrentMail->to)) != NULL) /* if user is online */ { LINK(usr->pCurrentMail, to->pMailFirst, to->pMailLast); save_mail(to); /* edit_mail_free(usr); BAXTER */ usr->pCurrentMail = NULL; if (isBusySelf(to)) add_buffer(to, "#WYou have new mail.#x\n\r"); else send_to_user("#WYou have new mail.#x\n\r", to); return; } sprintf(buf, "%s%s", MAIL_DIR, capitalize(usr->pCurrentMail->to)); fclose(fpReserve); if (!(fpMail = fopen(buf, "a"))) { print_to_user(usr, "ERROR: Could not open to write %s's mail file.\n\r", capitalize(usr->pCurrentMail->to)); bbs_bug("Save_mail: Could not open to write %s", buf); fpReserve = fopen(NULL_FILE, "r"); /* edit_mail_free(usr); BAXTER */ usr->pCurrentMail = NULL; return; } append_mail(usr->pCurrentMail, fpMail); fclose(fpMail); fpReserve = fopen(NULL_FILE, "r"); /* edit_mail_free(usr); */ usr->pCurrentMail = NULL; return; }
void CEngine::printStacks() { char line[2048]; QByteArray s; send_to_user(" -----------------------------\n"); sprintf(line, "Conf: Mapping %s, AutoChecks [Desc %s, Exits %s, Terrain %s],\r\n" " AutoRefresh settings %s (RName/Desc quotes %i/%i), \r\n" " AngryLinker %s DualLinker %s\r\n", ON_OFF(mapping), ON_OFF(conf->getAutomerge()), ON_OFF(conf->getExitsCheck() ), ON_OFF(conf->getTerrainCheck() ), ON_OFF(conf->getAutorefresh() ), conf->getNameQuote(), conf->getDescQuote(), ON_OFF(conf->getAngrylinker() ),ON_OFF(conf->getDuallinker() ) ); send_to_user(line); stacker.printStacks(); }
void CEngine::updateRegions() { CRoom *r; print_debug(DEBUG_ANALYZER, "in updateRegions"); // update Regions info only if we are in full sync if (stacker.amount() == 1) { r = stacker.first(); last_region = r->getRegion(); // If this room was JUST added, it has no region set. if (last_region == NULL) { return; // probably it needs some heavier work ...region settings might not work correctly } if (last_region != users_region && conf->getRegionsAutoReplace() == false) { if (last_warning_region != last_region && conf->getRegionsAutoSet() == false) { send_to_user("--[ Moved to another region: new region %s\r\n", (const char *) last_region->getName() ); last_warning_region = last_region; } if (conf->getRegionsAutoSet()) set_users_region( last_region ); } if (conf->getRegionsAutoReplace() && last_region != users_region) { // update is required ... send_to_user( "--[ Regions update: Room region changed from %s to %s\r\n", (const char *) last_region->getName(), (const char *) users_region->getName()); r->setRegion(users_region); last_region = users_region; toggle_renderer_reaction(); } } print_debug(DEBUG_ANALYZER, "leaving updateRegions"); }
/* Sends data from a script to a user. */ void script_to_user(char *buf, struct user_t *user) { char command[21]; char nick[MAX_NICK_LEN+1]; struct user_t *to_user; sscanf(buf, "%20s %50s", command, nick); if((to_user = get_human_user(nick)) != NULL) send_to_user(buf + 14 + strlen(nick) + 1, to_user); else send_to_non_humans(buf, FORKED, user); }
void mail_remove(USER_DATA *usr, MAIL_DATA *pMail, bool fSave) { if (!pMail) { send_to_user("ERROR: Null pMail.\n\r", usr); bbs_bug("Mail_remove: Null pMail"); return; } UNLINK(pMail, usr->pMailFirst, usr->pMailLast); free_mail(pMail); if (fSave) save_mail(usr); return; }
/* This function takes a string and sends it to all script parsing pocesses. */ void command_to_scripts(const char *format, ...) { static char buf[0xFFFF]; struct user_t *user; if(format) { va_list args; va_start(args, format); vsnprintf(buf, 0xFFFE, format, args); va_end(args); } user = non_human_user_list; /* If we are the parent, send directly to script processes */ if(pid > 0) { while(user != NULL) { if(user->type == SCRIPT) send_to_user(buf, user); user = user->next; } } /* If we are child, send to parent first */ else { while(user != NULL) { if(user->type == FORKED) send_to_user(buf, user); user = user->next; } } }
void do_test(USER_DATA *usr, char *argument) { FILE *pFile; pFile = fopen("../lib/alo", "w"); if (pFile) { fput_string(pFile, "%s", argument); fputc(' ', pFile); fput_string(pFile, "%s", usr->name); fputc('\n', pFile); fclose(pFile); return; } send_to_user("Acilamiyor.\n\r", usr); return; }
void do_rtest(USER_DATA *usr, char *argument) { FILE *pFile; char *alo, *isim; pFile = fopen("../lib/alo", "r"); if (pFile) { alo = str_dup(fget_string(pFile)); isim = str_dup(fget_string(pFile)); fclose(pFile); print_to_user(usr, "%s, %s\n\r", alo, isim); return; } send_to_user("Acilamiyor.\n\r", usr); return; }
void CEngine::do_exits(const char *exits_line) { int exits[6]; unsigned int i; CRoom *r; parse_exits(exits_line, exits); r = engine->addedroom; if (r == NULL) return; print_debug(DEBUG_ANALYZER /*& DEBUG_TOUSER*/, "Exits: Adding exits information to the new room."); for (i = 0; i <= 5; i++) { ExitDirection iDir = static_cast<ExitDirection>(i); if (r->isExitPresent(iDir) == true) { if (exits[i] == 0) { /* oneway case */ map->oneway_room_id = r->getExitLeadsTo(iDir); r->removeExit(iDir); } if (exits[i] == E_CLOSEDDOOR) r->setDoor(iDir, "exit"); continue; } if (exits[i] == E_CLOSEDDOOR) { r->setDoor(iDir, "exit"); } if (exits[i] == E_PORTAL) { send_to_user("--[ Attention PORTAL was in room as you entered it. Fix existing exits if needed\r\n"); } if ((exits[i] > 0) && (exits[i] != E_PORTAL)) r->setExitUndefined(iDir); } stacker.put(engine->addedroom); return; }
void save_mail(USER_DATA *usr) { MAIL_DATA *pMail; FILE *fpMail; char buf[INPUT]; sprintf(buf, "%s%s", MAIL_DIR, capitalize(usr->name)); fclose(fpReserve); if (!(fpMail = fopen(buf, "w"))) { send_to_user("ERROR: Could not open to write your mail file.\n\r", usr); bbs_bug("Save_mail: Could not open to write %s", buf); fpReserve = fopen(NULL_FILE, "r"); return; } for (pMail = usr->pMailFirst; pMail; pMail = pMail->next) if (pMail) append_mail(pMail, fpMail); fclose(fpMail); fpReserve = fopen(NULL_FILE, "r"); return; }
int write_debug(unsigned int flag, const char *format, va_list args) { char txt[MAX_STR_LEN*2]; int size; int i; if (conf != NULL && !conf->getLogFileEnabled()) return -1; // log file is disabled if (logfile == NULL) { debug_timer.start(); QString fileName = QString("logs/" + QDateTime::currentDateTime().toString("dd.MM.yyyy-hh.mm.ss") + ".txt"); printf("Using the LOGFILE : %s\r\n", (const char *) fileName.toLocal8Bit() ); logFileName = new QString(); *logFileName = fileName; logfile = fopen( (const char *) fileName.toLocal8Bit(), "w+"); if (!logfile) { perror ("Error opening logfile for writing"); return -1; } } size = vsnprintf(txt, sizeof(txt), format, args); for (i = 0; debug_data[i].name; i++) if (IS_SET(flag, debug_data[i].flag) && debug_data[i].state) { fprintf(logfile, "[%i] %s: %s\r\n", debug_timer.elapsed(), debug_data[i].title, txt); fflush(logfile); if (IS_SET(flag, DEBUG_TOUSER) ) send_to_user("--[ %s: %s\r\n", debug_data[i].title, txt); } return size; }
void func_read_mail(USER_DATA *usr, char *argument) { MAIL_DATA *pMail; char buf[STRING]; BUFFER *buffer; int vnum = 1; int anum = 0; if (argument[0] == '\0' || !is_number(argument)) { syntax("[#Wre#x]ad <mail number>", usr); return; } anum = atoi(argument); buffer = new_buf(); for (pMail = usr->pMailFirst; pMail; pMail = pMail->next) { if (pMail && (vnum++ == anum)) { time_t *last_read = &pMail->read_time; *last_read = UMAX(*last_read, pMail->stamp_time); sprintf(buf, "Reading message %d.\n\rDate: %s\n\rFrom: %s\n\r" "Subject: %s\n\r\n\r", vnum - 1, time_str(pMail->stamp_time), pMail->from, pMail->subject); add_buf(buffer, buf); add_buf(buffer, pMail->message); add_buf(buffer, "#x\n\r"); page_to_user(buf_string(buffer), usr); free_buf(buffer); save_mail(usr); return; } } send_to_user("There aren't that many mail.\n\r", usr); return; }
void edit_mail_subject(USER_DATA *usr, char *argument) { while (isspace(*argument)) argument++; usr->timer = 0; mail_attach(usr); smash_tilde(argument); if (argument[0] == '\0') { /* edit_mail_free(usr); BAXTER */ EDIT_MODE(usr) = EDITOR_NONE; return; } else if (strlen(argument) > 20) { send_to_user("Subject too long.\n\r", usr); return; } if (usr->pCurrentMail->subject) free_string(usr->pCurrentMail->subject); usr->pCurrentMail->subject = str_dup(argument); EDIT_MODE(usr) = EDITOR_MAIL_WRITE; string_edit(usr, &usr->pCurrentMail->message); }
void CEngine::angryLinker(CRoom *r) { CRoom *p; unsigned int i; CRoom *candidates[6]; int distances[6]; int z; if (!conf->getAngrylinker()) return; print_debug(DEBUG_ROOMS && DEBUG_ANALYZER, "in AngryLinker"); if (r == NULL) { print_debug(DEBUG_ROOMS, "given room is NULL"); return; } if (r->anyUndefinedExits() != true) { print_debug(DEBUG_ROOMS, "returning, no undefined exits in room found"); return; /* no need to try and link this room - there are no undefined exits */ } /* reset the data */ for (i=0; i <= 5; i++) { distances[i] = 15000; candidates[i] = 0; } z = 0; // if you are performing the full run over all rooms, it's better // to lock the Map completely. // else the other thread might delete the room you are examining at the moment! //map->lockForWrite(); QVector<CRoom *> rooms = map->getRooms(); /* find the closest neighbours by coordinate */ for (i = 0; i < map->size(); i++) { p = rooms[i]; /* z-axis: up and down exits */ if (p->getZ() != r->getZ()) { if ((p->getX() != r->getX()) || (p->getY() != r->getY())) continue; /* up exit */ if (p->getZ() > r->getZ()) { z = p->getZ() - r->getZ(); if (z < distances[ED_UP]) { /* update */ distances[ED_UP] = z; candidates[ED_UP] = p; } } /* DOWN exit */ if (r->getZ() > p->getZ()) { z = r->getZ() - p->getZ(); if (z < distances[ED_DOWN]) { /* update */ distances[ED_DOWN] = z; candidates[ED_DOWN] = p; } } } /* done with z-axis */ /* x-axis. */ if ((p->getY() == r->getY()) && (p->getZ() == r->getZ())) { if (p->getX() == r->getX()) continue; /* all coordinates are the same - skip */ /* EAST exit */ if (p->getX() > r->getX()) { z = p->getX() - r->getX(); if (z < distances[ED_EAST]) { /* update */ distances[ED_EAST] = z; candidates[ED_EAST] = p; } } /* WEST exit */ if (r->getX() > p->getX()) { z = r->getX() - p->getX(); if (z < distances[ED_WEST]) { /* update */ distances[ED_WEST] = z; candidates[ED_WEST] = p; } } } /* y-axis. */ if ((p->getX() == r->getX()) && (p->getZ() == r->getZ())) { if (p->getY() == r->getY()) continue; /* all coordinates are the same - skip */ /* NORTH exit */ if (p->getY() > r->getY()) { z = p->getY() - r->getY(); if (z < distances[ED_NORTH]) { /* update */ distances[ED_NORTH] = z; candidates[ED_NORTH] = p; } } /* SOUTH exit */ if (r->getY() > p->getY()) { z = r->getY() - p->getY(); if (z < distances[ED_SOUTH]) { /* update */ distances[ED_SOUTH] = z; candidates[ED_SOUTH] = p; } } } } print_debug(DEBUG_ROOMS, "candidates gathered"); /* ok, now we have candidates for linking - lets check directions and connections*/ for (i=0; i <= 5; i++) { ExitDirection iDir = static_cast<ExitDirection> (i); if (r->isExitUndefined(iDir) && candidates[i] != NULL) if (candidates[i]->isExitUndefined( reversenum(iDir) ) == true) { if (distances[ i ] <= 2) { print_debug(DEBUG_ROOMS, "we have a match for AngryLinker!"); print_debug(DEBUG_ROOMS, "ID: %i to %i exit %s.", r->getId(), candidates[i]->getId(), exits[i] ); /* ok, do the linking */ candidates[ i ]->setExitLeadsTo( reversenum(iDir), r); r->setExitLeadsTo(iDir, candidates[ i ]); print_debug(DEBUG_ROOMS, "Linked.", r->getId(), candidates[i]->getId(), exits[i] ); send_to_user("--[ (AngryLinker) Linked exit %s with %s [%i].\r\n", exits[ i ], (const char*) candidates[i]->getName(), candidates[i]->getId()); } } } //map->unlock(); }
/* ------------------------------ prints the given room --------------------*/ void CRoom::sendRoom() const { unsigned int i, pos; char line[MAX_STR_LEN]; send_to_user(" Id: %i, Flags: %s, Region: %s, Coord: %i,%i,%i\r\n", getId(), (const char *) conf->sectors[ (int) getTerrain() ].desc, (const char *) region->getName(), getX(), getY(), getZ()); send_to_user(" [32m%s[0m\r\n", (const char *) getName() ); line[0] = 0; pos = 0; if (!(proxy->isMudEmulation() && conf->getBriefMode() ) ) { QByteArray desc = getDesc(); for (i = 0; i <= strlen(desc); i++) if (desc[i] == '|') { line[pos] = 0; send_to_user("%s\r\n", line); line[0] = 0; pos = 0; } else { line[pos++] = desc[i]; } } send_to_user(" note: %s\r\n", (const char *) getNote()); sprintf(line, "Doors:"); for (i = 0; i <= 5; i++) { ExitDirection iDir = static_cast<ExitDirection>(i); if (isDoorSecret(iDir)) { sprintf(line + strlen(line), " %c: %s", dirbynum(iDir), (const char *) getDoor(iDir)); } } send_to_user("%s\r\n", line); if (conf->getBriefMode() && proxy->isMudEmulation()) { sprintf(line, "Exits: "); for (i = 0; i <= 5; i++) { ExitDirection iDir = static_cast<ExitDirection>(i); if (isExitPresent(iDir) == true) { if ( isExitUndefined(iDir) ) { sprintf(line + strlen(line), " #%s#", exitnames[i]); continue; } if ( isExitDeath(iDir) ) { sprintf(line + strlen(line), " !%s!", exitnames[i]); continue; } if (isDoorSet(iDir)) { if (isDoorSecret(iDir) == false) { sprintf(line + strlen(line), " (%s)", exitnames[i]); } else { sprintf(line + strlen(line), " +%s+", exitnames[i]); } } else { sprintf(line + strlen(line), " %s", exitnames[i]); } } } } else { line[0] = 0; sprintf(line, " exits:"); for (i = 0; i <= 5; i++) { ExitDirection iDir = static_cast<ExitDirection>(i); if (isExitPresent(iDir) == true) { if (isExitUndefined(iDir) ) { sprintf(line + strlen(line), " #%s#", exitnames[i]); continue; } if (isExitDeath(iDir)) { sprintf(line + strlen(line), " !%s!", exitnames[i]); continue; } if (isDoorSet(iDir)) { if (isDoorSecret(iDir) == false) { sprintf(line + strlen(line), " (%s)", exitnames[i]); } else { sprintf(line + strlen(line), " +%s+", exitnames[i]); } } else { sprintf(line + strlen(line), " %s", exitnames[i]); } sprintf(line + strlen(line), " -[to %i]-", getExitLeadsTo(iDir) ); } } } send_to_user("%s\r\n", line); }
void do_reboo(USER_DATA *usr, char *argument) { send_to_user("If you want to REBOOT, spell it out.\n\r", usr); return; }
/* * Change and show config settings (admin command). */ void do_config(USER_DATA *usr, char *argument) { char arg[INPUT]; argument = one_argument(argument, arg); if (arg[0] == '\0') { print_to_user(usr, "---[BBS Config]-----------------------------------------------\n\r" "Name : %-25s E-Mail : %s\n\r" "Host : %-25s Port : %d\n\r" "State: %-25s Version: %s\n\r" "---[Toggles]--------------------------------------------------\n\r" "Newbie lock: %s Admin lock: %s Noresolve: %s\n\r\n\r", config.bbs_name, config.bbs_email, config.bbs_host, config.bbs_port, config.bbs_state, config.bbs_version, IS_SET(config.bbs_flags, BBS_NEWLOCK) ? "Yes" : "No", IS_SET(config.bbs_flags, BBS_ADMLOCK) ? "Yes" : "No", IS_SET(config.bbs_flags, BBS_NORESOLVE) ? "Yes" : "No"); return; } if (!str_cmp(arg, "name")) { if (argument[0] == '\0') { syntax("config name <argument>", usr); return; } free_string(config.bbs_name); config.bbs_name = str_dup(capitalize(argument)); print_to_user(usr, "Ok, BBS name now: %s\n\r", config.bbs_name); save_config(); return; } else if (!str_cmp(arg, "email")) { if (argument[0] == '\0') { syntax("config email <argument>", usr); return; } free_string(config.bbs_email); config.bbs_email = str_dup(argument); print_to_user(usr, "Ok, BBS email now: %s\n\r", config.bbs_email); save_config(); return; } else if (!str_cmp(arg, "version")) { if (argument[0] == '\0') { syntax("config version <argument>", usr); return; } free_string(config.bbs_version); config.bbs_version = str_dup(argument); print_to_user(usr, "Ok, BBS version now: %s\n\r", config.bbs_version); save_config(); return; } else if (!str_cmp(arg, "host")) { if (argument[0] == '\0') { syntax("config host <argument>", usr); return; } free_string(config.bbs_host); config.bbs_host = str_dup(argument); print_to_user(usr, "Ok, BBS host now: %s\n\r", config.bbs_host); save_config(); return; } else if (!str_cmp(arg, "state")) { if (argument[0] == '\0') { syntax("config state <argument>", usr); return; } free_string(config.bbs_state); config.bbs_state = str_dup(capitalize(argument)); print_to_user(usr, "Ok, BBS state now: %s\n\r", config.bbs_state); save_config(); return; } else if (!str_cmp(arg, "port")) { if (argument[0] == '\0' || !is_number(argument)) { syntax("config port <argument>", usr); return; } if (atoi(argument) > 9999 || atoi(argument) <= 1234) { send_to_user("That's not a valid BBS port.\n\r", usr); return; } config.bbs_port = atoi(argument); print_to_user(usr, "Ok, BBS email now: %d\n\r", config.bbs_email); save_config(); return; } else if (!str_cmp(arg, "newbie")) { if (!str_cmp(argument, "on")) { if (IS_SET(config.bbs_flags, BBS_NEWLOCK)) { send_to_user("BBS newbie lock is already On.\n\r", usr); return; } SET_BIT(config.bbs_flags, BBS_NEWLOCK); send_to_user("Ok, BBS newbie lock is On.\n\r", usr); save_config(); return; } else if (!str_cmp(argument, "off")) { if (!IS_SET(config.bbs_flags, BBS_NEWLOCK)) { send_to_user("BBS newbie lock is already Off.\n\r", usr); return; } REM_BIT(config.bbs_flags, BBS_NEWLOCK); send_to_user("Ok, BBS newbie lock is Off.\n\r", usr); save_config(); return; } else { syntax("config newbie on|off", usr); return; } } else if (!str_cmp(arg, "admin")) { if (!str_cmp(argument, "on")) { if (IS_SET(config.bbs_flags, BBS_ADMLOCK)) { send_to_user("BBS admin lock is already On.\n\r", usr); return; } SET_BIT(config.bbs_flags, BBS_ADMLOCK); send_to_user("Ok, BBS admin lock is On.\n\r", usr); save_config(); return; } else if (!str_cmp(argument, "off")) { if (!IS_SET(config.bbs_flags, BBS_ADMLOCK)) { send_to_user("BBS admin lock is already Off.\n\r", usr); return; } REM_BIT(config.bbs_flags, BBS_ADMLOCK); send_to_user("Ok, BBS admin lock is Off.\n\r", usr); save_config(); return; } else { syntax("config admin on|off", usr); return; } } else if (!str_cmp(arg, "noresolve")) { if (!str_cmp(argument, "on")) { if (IS_SET(config.bbs_flags, BBS_NORESOLVE)) { send_to_user("BBS noresolve is already On.\n\r", usr); return; } SET_BIT(config.bbs_flags, BBS_NORESOLVE); send_to_user("Ok, BBS noresolve is On.\n\r", usr); save_config(); return; } else if (!str_cmp(argument, "off")) { if (!IS_SET(config.bbs_flags, BBS_NORESOLVE)) { send_to_user("BBS noresolve is already Off.\n\r", usr); return; } REM_BIT(config.bbs_flags, BBS_NORESOLVE); send_to_user("Ok, BBS noresolve is Off.\n\r", usr); save_config(); return; } else { syntax("config noresolve on|off", usr); return; } } else { syntax("config <type> <argument>", usr); return; } }
/* Returns 1 on success and 0 on failure */ int perl_init(void) { char path[MAX_FDP_LEN+1]; char *script_list[256]; char *myargv[] = {"", NULL}; int i, k, len; int sock; struct sockaddr_un remote_addr; char temp_nick[MAX_NICK_LEN+1]; char temp_host[MAX_HOST_LEN+1]; char *buf, *bufp; int spaces=0, entries=0; int l; int erret; int flags; memset(&remote_addr, 0, sizeof(struct sockaddr_un)); /* First kill off scripts that is already running. */ remove_all(SCRIPT, 1, 1); /* Reads the script names in the script directory */ snprintf(path, MAX_FDP_LEN, "%s/%s", config_dir, SCRIPT_DIR); i = my_scandir(path, script_list); if(i == 0) return 1; k = i-1; for(i = 0; i <= k; i++) { myargv[1] = script_list[i]; if((pid = fork()) == -1) { logprintf(1, "Fork failed, exiting process\n"); logerror(1, errno); quit = 1; return 0;; } /* If we are the parent */ if(pid > 0) { logprintf(3, "Forked new script parsing process for script %s, childs pid is %d and parents pid is %d\n", script_list[i], pid, getpid()); pid = getpid(); } /* And if we are the child */ else { pid = -1; /* Close the listening sockets */ while(((erret = close(listening_unx_socket)) != 0) && (errno == EINTR)) logprintf(1, "Error - In perl_init()/close(): Interrupted system call. Trying again.\n"); if(erret != 0) { logprintf(1, "Error - In perl_init()/close(): "); logerror(1, errno); } while(((erret = close(listening_udp_socket)) != 0) && (errno == EINTR)) logprintf(1, "Error - In perl_init()/close(): Interrupted system call. Trying again.\n"); if(erret != 0) { logprintf(1, "Error - In perl_init()/close(): "); logerror(1, errno); } /* Set the alarm */ alarm(ALARM_TIME); /* And connect to parent process */ if((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { logprintf(1, "Error - In perl_init()/socket(): "); logerror(1, errno); free(script_list[i]); exit(EXIT_FAILURE); } remote_addr.sun_family = AF_UNIX; strcpy(remote_addr.sun_path, un_sock_path); len = strlen(remote_addr.sun_path) + sizeof(remote_addr.sun_family) + 1; if(connect(sock, (struct sockaddr *)&remote_addr, len) == -1) { logprintf(1, "Error - In perl_init()/connect(): "); logerror(1, errno); free(script_list[i]); exit(EXIT_FAILURE); } if((flags = fcntl(sock, F_GETFL, 0)) < 0) { logprintf(1, "Error - In new_human_user()/in fcntl(): "); logerror(1, errno); close(sock); return -1; } /* Non blocking mode */ if(fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) { logprintf(1, "Error - In new_human_user()/in fcntl(): "); logerror(1, errno); close(sock); return -1; } /* The parent process will be a special kind of user */ /* Allocate space for the new user. Since the process * should be empty on users and no one is to be added, * we use non_human_user_list. */ /* Allocate space for the new user */ if((non_human_user_list = malloc(sizeof(struct user_t))) == NULL) { logprintf(1, "Error - In parl_init()/malloc(): "); logerror(1, errno); quit = 1; free(script_list[i]); exit(EXIT_FAILURE); } non_human_user_list->sock = sock; non_human_user_list->rem = 0; non_human_user_list->type = SCRIPT; non_human_user_list->buf = NULL; non_human_user_list->outbuf = NULL; non_human_user_list->next = NULL; non_human_user_list->email = NULL; non_human_user_list->desc = NULL; memset(non_human_user_list->nick, 0, MAX_NICK_LEN+1); sprintf(non_human_user_list->nick, "parent process"); sprintf(non_human_user_list->hostname, "parent_process"); send_to_user("$NewScript|", non_human_user_list); /* Remove all users. */ remove_all(~SCRIPT, 0, 0); /* Initialize the perl interpreter for this process */ if((my_perl = perl_alloc()) == NULL) { logprintf(1, "perl_alloc() failed\n"); free(script_list[i]); exit(EXIT_FAILURE); } perl_construct(my_perl); if(perl_parse(my_perl, xs_init, 2, myargv, NULL)) { logprintf(1, "Parse of %s failed.\n", script_list[i]); free(script_list[i]); exit(EXIT_FAILURE); } if(perl_run(my_perl)) { logprintf(1, "Couldn't run perl script %s.\n", script_list[i]); free(script_list[i]); exit(EXIT_FAILURE); } /* Run the scripts main sub if it exists. */ { dSP; ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; call_pv("main", G_DISCARD|G_EVAL); SPAGAIN; PUTBACK; FREETMPS; LEAVE; } free(script_list[i]); /* Get info of all users. */ if(i == 0) { sem_take(user_list_sem); /* Attach to the shared segment */ if((buf = (char *)shmat(get_user_list_shm_id(), NULL, 0)) == (char *)-1) { logprintf(1, "Error - In perl_init()/shmat(): "); logerror(1, errno); sem_give(user_list_sem); quit = 1; return -1; } if(sscanf(buf, "%d %d", &spaces, &entries) != 2) { logprintf(1, "Error - In perl_init(): Couldn't get number of entries\n"); shmdt(buf); sem_give(user_list_sem); quit = 1; return -1; } bufp = buf + 30; for(l = 1; l <= spaces; l++) { if(*bufp != '\0') { sscanf(bufp, "%50s %120s", temp_nick, temp_host); uprintf(non_human_user_list, "$GetINFO %s $Script|", temp_nick); } bufp += USER_LIST_ENT_SIZE; } shmdt(buf); sem_give(user_list_sem); } return 1; } free(script_list[i]); } return 1; }