void gen_board_list(struct board_data *board, struct creature *ch) { PGresult *res; char time_buf[30]; int idx, count; time_t post_time; res = sql_query ("select extract(epoch from post_time), name, subject from board_messages where board='%s' order by idnum desc", tmp_sqlescape(board->name)); count = PQntuples(res); if (count == 0) { send_to_char(ch, "This board is empty.\r\n"); return; } acc_string_clear(); acc_sprintf ("This is a bulletin board. Usage: READ/REMOVE <messg #>, WRITE <header>\r\n%sThere %s %d message%s on the board.%s\r\n", CCGRN(ch, C_NRM), (count == 1) ? "is" : "are", count, (count == 1) ? "" : "s", CCNRM(ch, C_NRM)); for (idx = 0; idx < count; idx++) { post_time = atol(PQgetvalue(res, idx, 0)); strftime(time_buf, 30, "%b %e, %Y", localtime(&post_time)); acc_sprintf("%s%-2d %s:%s %s %-12s :: %s\r\n", CCGRN(ch, C_NRM), count - idx, CCRED(ch, C_NRM), CCNRM(ch, C_NRM), time_buf, tmp_sprintf("(%s)", PQgetvalue(res, idx, 1)), PQgetvalue(res, idx, 2)); } page_string(ch->desc, acc_get_string()); }
void gen_board_read(struct board_data *board, struct creature *ch, char *argument) { struct creature *player; PGresult *res; time_t post_time; char time_buf[30]; int idx; if (IS_PC(ch)) player = ch; else if (ch->desc && ch->desc->original) player = ch->desc->original; else { send_to_char(ch, "You're a mob. Go awei.\r\n"); return; } if (ALLOW != react(board->read_perms, player)) { send_to_char(ch, "%s\r\n", board->deny_read); return; } idx = atoi(argument) - 1; if (idx < 0) { send_to_char(ch, "That is not a valid message.\r\n"); return; } res = sql_query ("select extract(epoch from post_time), name, subject, body from board_messages where board='%s' order by idnum limit 1 offset %d", tmp_sqlescape(board->name), idx); if (PQntuples(res) == 0) { send_to_char(ch, "That message does not exist on this board.\r\n"); return; } acc_string_clear(); post_time = atol(PQgetvalue(res, 0, 0)); strftime(time_buf, 30, "%a %b %e %Y", localtime(&post_time)); acc_sprintf("%sMessage %s : %s %-12s :: %s%s\r\n\r\n%s\r\n", CCBLD(ch, C_CMP), argument, time_buf, tmp_sprintf("(%s)", PQgetvalue(res, 0, 1)), CCNRM(ch, C_CMP), PQgetvalue(res, 0, 2), PQgetvalue(res, 0, 3)); page_string(ch->desc, acc_get_string()); }
static int load_dyntext_buffer(dynamic_text_file * dyntext) { char *path = tmp_sprintf("text/%s", dyntext->filename); FILE *fl = fopen(path, "r"); if (fl == NULL) { errlog("unable to open dynamic text file '%s'.", path); perror("dyntext fopen:"); return -1; } char line[1024]; acc_string_clear(); while (fgets(line, 1024, fl)) { acc_strcat(line, NULL); } acc_strcat("\n", NULL); free(dyntext->buffer); dyntext->buffer = strdup(tmp_gsub(acc_get_string(), "\n", "\r\n")); fclose(fl); return 0; }
void gen_board_show(struct creature *ch) { PGresult *res; int idx, count; res = sql_query ("select board, COUNT(*) from board_messages group by board order by count desc"); count = PQntuples(res); if (count == 0) { send_to_char(ch, "There are no messages on any board.\r\n"); return; } acc_string_clear(); acc_sprintf ("Board Count\r\n--------------------------\r\n"); for (idx = 0; idx < count; idx++) acc_sprintf("%-20s %5s\r\n", PQgetvalue(res, idx, 0), PQgetvalue(res, idx, 1)); page_string(ch->desc, acc_get_string()); }