/* * Display main menu. */ void hedit_disp_menu(struct descriptor_data *d) { struct house_data *house; char *name; house = OLC_HOUSE(d); get_char_colors(d->character); if ((name = get_name_by_id(H_OWNER(house))) == NULL) name = str_dup("nobody"); else name = str_dup(get_name_by_id(H_OWNER(house))); clear_screen(d); write_to_output(d, TRUE, "-- House Number : [%s%d%s]\r\n" "%s0%s) Owner : %s%s\r\n" "%s1%s) Atrium : [%s%d%s] %s%s\r\n" "%s2%s) Exit : [%s%d%s] %s%s\r\n" "%s3%s) House type : %s%s\r\n" "%s4%s) Prune-safe : %s%s\r\n" "%s5%s) Cost : [%s%d%s]\r\n" "%s6%s) Max Secure containers : [%s%d%s]\r\n" "%s7%s) Max Locked-down objs : [%s%d%s]\r\n" "%sR%s) Rooms Menu\r\n" "%sC%s) Co-Owners Menu\r\n" "%sG%s) Guests Menu\r\n" "%sD%s) Delete this house\r\n" "%sQ%s) Quit\r\n" "Enter Choice : ", cyn, OLC_NUM(d), nrm, grn, nrm, yel, CAP(name), grn, nrm, cyn, real_room(H_ATRIUM(house)) == NOWHERE ? -1 : world[real_room(H_ATRIUM(house))].number, nrm, yel, real_room(H_ATRIUM(house)) == NOWHERE ? "Nowhere" : world[real_room(H_ATRIUM(house))].name, grn, nrm, cyn, H_EXIT(house) < 0 || H_EXIT(house) >= NUM_OF_DIRS ? -1 : H_EXIT(house), nrm, yel, H_EXIT(house) < 0 || H_EXIT(house) >= NUM_OF_DIRS ? "Nowhere" : dirs[H_EXIT(house)], grn, nrm, cyn, house_types[H_MODE(house)], grn, nrm, cyn, YESNO(H_PRUNE_SAFE(house)), grn, nrm, cyn, H_COST(house), nrm, grn, nrm, cyn, H_MAX_SECURE(house), nrm, grn, nrm, cyn, H_MAX_LOCKED(house), nrm, grn, nrm, grn, nrm, grn, nrm, grn, nrm, grn, nrm ); release_buffer(name); OLC_MODE(d) = HEDIT_MAIN_MENU; }
int main(int argc, char **argv) { const size_t MEASES_SIZE = 99; unsigned short server_port = 2001; unsigned short server_http_port = 2002; std::string server_host = "127.0.0.1"; dariadb::net::client::Client::Param p(server_host, server_port, server_http_port); dariadb::net::client::Client_Ptr connection{new dariadb::net::client::Client(p)}; connection->connect(); if (!connection->addToScheme("cpu.core1")) { throw std::logic_error("create param error"); } if (!connection->addToScheme("cpu.core2")) { throw std::logic_error("create param error"); } if (!connection->addToScheme("memory")) { throw std::logic_error("create param error"); } std::map<std::string, dariadb::Id> name2id = connection->loadScheme(); dariadb::MeasArray ma; auto current_time = dariadb::timeutil::current_time(); for (size_t i = 0; i < MEASES_SIZE; ++i) { dariadb::Meas cpu1, cpu2, memory; cpu1.id = name2id["cpu.core1"]; cpu1.value = dariadb::Value(i); cpu1.time = current_time++; cpu2.id = name2id["cpu.core2"]; cpu2.value = dariadb::Value(i); cpu2.time = current_time++; memory.id = name2id["memory"]; memory.value = dariadb::Value(i); memory.time = current_time++; ma.push_back(cpu1); ma.push_back(cpu2); ma.push_back(memory); } connection->append(ma); dariadb::IdArray ids{name2id["cpu.core1"], name2id["cpu.core2"], name2id["memory"]}; dariadb::QueryInterval interval_query(ids, dariadb::Flag(), dariadb::MIN_TIME, current_time); auto values = connection->readInterval(interval_query); for (auto measurement : values) { std::cout << " id: " << measurement.id << " name:" << get_name_by_id(name2id, measurement.id) << " timepoint: " << dariadb::timeutil::to_string(measurement.time) << " value:" << measurement.value << std::endl; } connection->disconnect(); }
void hedit_guests_menu(struct descriptor_data *d) { struct house_data *house; int i; house = OLC_HOUSE(d); get_char_colors(d->character); clear_screen(d); write_to_output(d, TRUE, "## ID Player\r\n\r\n"); for (i = 0; H_GUEST(house, i) != NOBODY; i++) write_to_output(d, TRUE, "%2d - [%s%5d%s] - %s%s%s\r\n", i, cyn, H_GUEST(house, i), nrm, yel, *get_name_by_id(H_GUEST(house, i)) == NOBODY ? "<Deleted>" : get_name_by_id(H_GUEST(house, i)), nrm); write_to_output(d, TRUE, "\r\n" "%sA%s) Add a new guest.\r\n" "%sD%s) Delete a guest.\r\n" "%sQ%s) Quit\r\n" "Enter choice : ", grn, nrm, grn, nrm, grn, nrm, grn, nrm); OLC_MODE(d) = HEDIT_GUESTS_MENU; }
/* should do sanity checks on vnums & remove invalid records */ void House_boot(void) { struct house_control_rec temp_house; int real_house, real_atrium; FILE *fl; memset((char *)house_control,0,sizeof(struct house_control_rec)*MAX_HOUSES); if (!(fl = fopen(HCONTROL_FILE, "rb"))) { log("House control file does not exist."); return; } while (!feof(fl) && num_of_houses < MAX_HOUSES) { fread(&temp_house, sizeof(struct house_control_rec), 1, fl); if (feof(fl)) break; if (get_name_by_id(temp_house.owner) == NULL) continue; /* owner no longer exists -- skip */ if ((real_house = real_room(temp_house.vnum)) < 0) continue; /* this vnum doesn't exist -- skip */ if ((find_house(temp_house.vnum)) >= 0) continue; /* this vnum is already a hosue -- skip */ if ((real_atrium = real_room(temp_house.atrium)) < 0) continue; /* house doesn't have an atrium -- skip */ if (temp_house.exit_num < 0 || temp_house.exit_num >= NUM_OF_DIRS) continue; /* invalid exit num -- skip */ if (TOROOM(real_house, temp_house.exit_num) != real_atrium) continue; /* exit num mismatch -- skip */ house_control[num_of_houses++] = temp_house; SET_BIT_AR(ROOM_FLAGS(real_house), ROOM_HOUSE); SET_BIT_AR(ROOM_FLAGS(real_house), ROOM_PRIVATE); SET_BIT_AR(ROOM_FLAGS(real_atrium), ROOM_ATRIUM); House_load(temp_house.vnum); } fclose(fl); House_save_control(); }
char *read_delete(long recipient) /* recipient is the name as it appears in the index. recipient_formatted is the name as it should appear on the mail header (i.e. the text handed to the player) */ { header_block_type header; data_block_type data; mail_index_type *mail_pointer, *prev_mail; position_list_type *position_pointer; long mail_address, following_block; char *message, *tmstr, buf[200]; size_t string_size; if (recipient < 0) { log("SYSERR: Mail system -- non-fatal error #6."); return 0; } if (!(mail_pointer = find_char_in_index(recipient))) { log("SYSERR: Mail system -- post office spec_proc error? Error #7."); return 0; } if (!(position_pointer = mail_pointer->list_start)) { log("SYSERR: Mail system -- non-fatal error #8."); return 0; } if (!(position_pointer->next)) { /* just 1 entry in list. */ mail_address = position_pointer->position; free(position_pointer); /* now free up the actual name entry */ if (mail_index == mail_pointer) { /* name is 1st in list */ mail_index = mail_pointer->next; free(mail_pointer); } else { /* find entry before the one we're going to del */ for (prev_mail = mail_index; prev_mail->next != mail_pointer; prev_mail = prev_mail->next); prev_mail->next = mail_pointer->next; free(mail_pointer); } } else { /* move to next-to-last record */ while (position_pointer->next->next) position_pointer = position_pointer->next; mail_address = position_pointer->next->position; free(position_pointer->next); position_pointer->next = 0; } /* ok, now lets do some readin'! */ read_from_file(&header, BLOCK_SIZE, mail_address); if (header.block_type != HEADER_BLOCK) { log("SYSERR: Oh dear."); no_mail = 1; log("SYSERR: Mail system disabled! -- Error #9."); return 0; } tmstr = asctime(localtime(&header.header_data.mail_time)); *(tmstr + strlen(tmstr) - 1) = '\0'; sprintf(buf, " * * * * Midgaard Mail System * * * *\r\n" "Date: %s\r\n" " To: %s\r\n" "From: %s\r\n\r\n", tmstr, get_name_by_id(recipient), get_name_by_id(header.header_data.from)); string_size = (sizeof(char) * (strlen(buf) + strlen(header.txt) + 1)); CREATE(message, char, string_size); strcpy(message, buf); strcat(message, header.txt); message[string_size - 1] = '\0'; following_block = header.header_data.next_block; /* mark the block as deleted */ header.block_type = DELETED_BLOCK; write_to_file(&header, BLOCK_SIZE, mail_address); push_free_list(mail_address); while (following_block != LAST_BLOCK) { read_from_file(&data, BLOCK_SIZE, following_block); string_size = (sizeof(char) * (strlen(message) + strlen(data.txt) + 1)); RECREATE(message, char, string_size); strcat(message, data.txt); message[string_size - 1] = '\0'; mail_address = following_block; following_block = data.block_type; data.block_type = DELETED_BLOCK; write_to_file(&data, BLOCK_SIZE, mail_address); push_free_list(mail_address); } return message; }
/* char *read_delete(long #1) * #1 - The id number of the person we're checking mail for. * Returns the message text of the mail received. * * Retrieves one messsage for a player. The mail is then discarded from * the file. Expects mail to exist. */ char *read_delete(long recipient) { FILE *mail_file, *new_file; struct mail_t *record, *record_to_keep = NULL; char buf[MAX_STRING_LENGTH]; if (!(mail_file = fopen(MAIL_FILE, "r"))) { perror("read_delete: Mail file not accessible."); return strdup("Mail system malfunction - please report this"); } if (!(new_file = fopen(MAIL_FILE_TMP, "w"))) { perror("read_delete: new Mail file not accessible."); fclose(mail_file); return strdup("Mail system malfunction - please report this"); } record = read_mail_record(mail_file); while (record) { if (!record_to_keep && record->recipient == recipient) { record_to_keep = record; record = read_mail_record(mail_file); continue; /* don't write and free this one just yet */ } write_mail_record(new_file, record); free_mail_record(record); record = read_mail_record(mail_file); } if (!record_to_keep) sprintf(buf, "Mail system error - please report"); else { char *tmstr, *from, *to; tmstr = asctime(localtime(&record_to_keep->sent_time)); *(tmstr + strlen(tmstr) - 1) = '\0'; from = get_name_by_id(record_to_keep->sender); to = get_name_by_id(record_to_keep->recipient); snprintf(buf, sizeof(buf), " * * * * tbaMUD Mail System * * * *\r\n" "Date: %s\r\n" "To : %s\r\n" "From: %s\r\n" "\r\n" "%s", tmstr, to ? to : "Unknown", from ? from : "Unknown", record_to_keep->body ? record_to_keep->body : "No message" ); free_mail_record(record_to_keep); } fclose(mail_file); fclose(new_file); remove(MAIL_FILE); rename(MAIL_FILE_TMP, MAIL_FILE); return strdup(buf); }
/* * char *read_delete(long #1) * #1 - The id number of the person we're checking mail for. * Returns the message text of the mail received. * * Retrieves one messsage for a player. The mail is then discarded from * the file and the mail index. */ char * read_delete (long recipient) { header_block_type header; data_block_type data; mail_index_type *mail_pointer, *prev_mail; position_list_type *position_pointer; long mail_address, following_block; char *message, *tmstr, buf[200]; char *from, *to; size_t string_size; if (recipient < 0) { log ("SYSERR: Mail system -- non-fatal error #6. (recipient: %ld)", recipient); return (NULL); } if (!(mail_pointer = find_char_in_index (recipient))) { log ("SYSERR: Mail system -- post office spec_proc error? Error #7. (invalid character in index)"); return (NULL); } if (!(position_pointer = mail_pointer->list_start)) { log ("SYSERR: Mail system -- non-fatal error #8. (invalid position pointer %p)", position_pointer); return (NULL); } if (!(position_pointer->next)) { /* just 1 entry in list. */ mail_address = position_pointer->position; free (position_pointer); /* now free up the actual name entry */ if (mail_index == mail_pointer) { /* name is 1st in list */ mail_index = mail_pointer->next; free (mail_pointer); } else { /* find entry before the one we're going to del */ for (prev_mail = mail_index; prev_mail->next != mail_pointer; prev_mail = prev_mail->next); prev_mail->next = mail_pointer->next; free (mail_pointer); } } else { /* move to next-to-last record */ while (position_pointer->next->next) position_pointer = position_pointer->next; mail_address = position_pointer->next->position; free (position_pointer->next); position_pointer->next = NULL; } /* ok, now lets do some readin'! */ read_from_file (&header, BLOCK_SIZE, mail_address); if (header.block_type != HEADER_BLOCK) { log ("SYSERR: Oh dear. (Header block %ld != %d)", header.block_type, HEADER_BLOCK); no_mail = TRUE; log ("SYSERR: Mail system disabled! -- Error #9. (Invalid header block.)"); return (NULL); } tmstr = asctime (localtime (&header.header_data.mail_time)); *(tmstr + strlen (tmstr) - 1) = '\0'; from = get_name_by_id (header.header_data.from); to = get_name_by_id (recipient); sprintf (buf, " ---==* McLandia Email Service *==--- \r\n" "Date: %s\r\n" " To: %s\r\n" "From: %s\r\n\r\n", tmstr, to ? to : "Unknown", from ? from : "Unknown"); string_size = (sizeof (char) * (strlen (buf) + strlen (header.txt) + 1)); CREATE (message, char, string_size); strcpy (message, buf); strcat (message, header.txt); message[string_size - 1] = '\0'; following_block = header.header_data.next_block; /* mark the block as deleted */ header.block_type = DELETED_BLOCK; write_to_file (&header, BLOCK_SIZE, mail_address); push_free_list (mail_address); while (following_block != LAST_BLOCK) { read_from_file (&data, BLOCK_SIZE, following_block); string_size = (sizeof (char) * (strlen (message) + strlen (data.txt) + 1)); RECREATE (message, char, string_size); strcat (message, data.txt); message[string_size - 1] = '\0'; mail_address = following_block; following_block = data.block_type; data.block_type = DELETED_BLOCK; write_to_file (&data, BLOCK_SIZE, mail_address); push_free_list (mail_address); } return (message); }