2016-03-22 01:48:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2016-03-27 00:33:43 +00:00
|
|
|
#include <stdlib.h>
|
2016-03-22 01:48:59 +00:00
|
|
|
#include <ctype.h>
|
2016-03-23 06:31:00 +00:00
|
|
|
#include <sys/stat.h>
|
2016-03-22 01:48:59 +00:00
|
|
|
#include "bbs.h"
|
2016-04-12 05:19:56 +00:00
|
|
|
#include "lua/lua.h"
|
|
|
|
#include "lua/lualib.h"
|
|
|
|
#include "lua/lauxlib.h"
|
2016-03-22 01:48:59 +00:00
|
|
|
|
2016-08-04 09:25:49 +00:00
|
|
|
extern struct bbs_config conf;
|
2017-04-22 01:53:44 +00:00
|
|
|
extern struct user_record *gUser;
|
|
|
|
extern int mynode;
|
2016-03-22 01:48:59 +00:00
|
|
|
|
2017-04-12 06:38:33 +00:00
|
|
|
void display_bulletins() {
|
|
|
|
int i;
|
|
|
|
char buffer[PATH_MAX];
|
2017-04-12 12:34:08 +00:00
|
|
|
struct stat s;
|
2017-04-12 06:38:33 +00:00
|
|
|
i = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-16 15:05:16 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
|
2017-04-12 06:38:33 +00:00
|
|
|
while (stat(buffer, &s) == 0) {
|
2018-02-05 09:27:48 +00:00
|
|
|
s_printf("\e[2J\e[1;1H");
|
2017-09-09 03:28:49 +00:00
|
|
|
s_displayansi_pause(buffer, 1);
|
2018-02-05 09:27:48 +00:00
|
|
|
s_printf(get_string(185));
|
2017-04-12 06:38:33 +00:00
|
|
|
s_getc();
|
2018-02-05 09:27:48 +00:00
|
|
|
s_printf("\r\n");
|
2017-04-12 06:38:33 +00:00
|
|
|
i++;
|
2018-10-16 15:05:16 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
|
2017-04-12 06:38:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 01:53:44 +00:00
|
|
|
void active_nodes() {
|
|
|
|
int i;
|
|
|
|
struct stat s;
|
|
|
|
char buffer[PATH_MAX];
|
|
|
|
FILE *fptr;
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
for (i = 0; i < conf.nodes; i++) {
|
|
|
|
snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i + 1);
|
2017-04-22 01:53:44 +00:00
|
|
|
if (stat(buffer, &s) == 0) {
|
|
|
|
fptr = fopen(buffer, "r");
|
2018-10-08 14:13:11 +00:00
|
|
|
if (fptr) {
|
2017-04-22 01:53:44 +00:00
|
|
|
fgets(buffer, PATH_MAX, fptr);
|
|
|
|
fclose(fptr);
|
|
|
|
chomp(buffer);
|
2018-10-08 14:13:11 +00:00
|
|
|
s_printf(get_string(216), i + 1, buffer);
|
2017-04-22 01:53:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void send_node_msg() {
|
|
|
|
char buffer[PATH_MAX];
|
|
|
|
char msg[257];
|
|
|
|
int nodetomsg = 0;
|
|
|
|
struct stat s;
|
|
|
|
FILE *fptr;
|
|
|
|
|
2017-04-22 02:08:31 +00:00
|
|
|
s_printf(get_string(217));
|
2017-04-22 01:53:44 +00:00
|
|
|
active_nodes();
|
|
|
|
|
|
|
|
s_readstring(buffer, 4);
|
|
|
|
nodetomsg = atoi(buffer);
|
|
|
|
|
|
|
|
if (nodetomsg < 1 || nodetomsg > conf.nodes) {
|
|
|
|
s_printf(get_string(218));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s_printf(get_string(219));
|
|
|
|
|
|
|
|
s_readstring(msg, 256);
|
|
|
|
|
|
|
|
snprintf(buffer, PATH_MAX, "%s/node%d", conf.bbs_path, nodetomsg);
|
|
|
|
|
|
|
|
if (stat(buffer, &s) != 0) {
|
|
|
|
mkdir(buffer, 0755);
|
|
|
|
}
|
|
|
|
snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, nodetomsg);
|
|
|
|
|
|
|
|
fptr = fopen(buffer, "a");
|
|
|
|
if (fptr) {
|
|
|
|
fprintf(fptr, get_string(220), gUser->loginname, mynode, msg);
|
|
|
|
fclose(fptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 06:38:33 +00:00
|
|
|
void display_textfiles() {
|
|
|
|
int i;
|
2018-02-05 09:26:06 +00:00
|
|
|
int redraw = 1;
|
|
|
|
int start = 0;
|
|
|
|
int selected = 0;
|
|
|
|
char c;
|
2017-04-12 06:38:33 +00:00
|
|
|
|
2018-10-16 15:05:15 +00:00
|
|
|
if (ptr_vector_len(&conf.text_files) == 0) {
|
2018-02-05 09:26:06 +00:00
|
|
|
s_printf("\e[2J\e[1;1H");
|
|
|
|
s_printf(get_string(148));
|
|
|
|
s_printf(get_string(185));
|
|
|
|
s_getc();
|
2018-10-08 14:13:11 +00:00
|
|
|
s_printf("\r\n");
|
2018-02-05 09:26:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-04-12 06:38:33 +00:00
|
|
|
|
2018-02-05 09:26:06 +00:00
|
|
|
while (1) {
|
|
|
|
if (redraw) {
|
|
|
|
s_printf("\e[2J\e[1;1H");
|
2017-04-12 06:38:33 +00:00
|
|
|
s_printf(get_string(143));
|
|
|
|
s_printf(get_string(144));
|
2018-10-16 15:05:15 +00:00
|
|
|
for (size_t i = start; i < start + 22 && i < ptr_vector_len(&conf.text_files); i++) {
|
|
|
|
struct text_file *file = ptr_vector_get(&conf.text_files, i);
|
2018-10-16 15:21:42 +00:00
|
|
|
s_printf(get_string(i == selected ? 249 : 250), i - start + 2, i, file->name);
|
2017-04-12 06:38:33 +00:00
|
|
|
}
|
2018-02-05 09:26:06 +00:00
|
|
|
s_printf("\e[%d;5H", selected - start + 2);
|
|
|
|
redraw = 0;
|
|
|
|
}
|
|
|
|
c = s_getchar();
|
|
|
|
if (tolower(c) == 'q') {
|
|
|
|
break;
|
|
|
|
} else if (c == 27) {
|
|
|
|
c = s_getchar();
|
|
|
|
if (c == 91) {
|
|
|
|
c = s_getchar();
|
|
|
|
if (c == 66) {
|
|
|
|
// down
|
|
|
|
if (selected + 1 >= start + 22) {
|
|
|
|
start += 22;
|
2018-10-16 15:05:15 +00:00
|
|
|
if (start >= ptr_vector_len(&conf.text_files)) {
|
|
|
|
start = ptr_vector_len(&conf.text_files) - 22;
|
2018-02-05 09:26:06 +00:00
|
|
|
}
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
selected++;
|
2018-10-16 15:05:15 +00:00
|
|
|
if (selected >= ptr_vector_len(&conf.text_files)) {
|
|
|
|
selected = ptr_vector_len(&conf.text_files) - 1;
|
2018-02-05 09:26:06 +00:00
|
|
|
} else {
|
2018-10-08 14:13:11 +00:00
|
|
|
if (!redraw) {
|
2018-10-16 15:05:15 +00:00
|
|
|
struct text_file *prev_file = ptr_vector_get(&conf.text_files, selected - 1);
|
|
|
|
struct text_file *file = ptr_vector_get(&conf.text_files, selected);
|
|
|
|
assert(prev_file != NULL);
|
|
|
|
assert(file != NULL);
|
|
|
|
s_printf(get_string(250), selected - start + 1, selected - 1, prev_file->name);
|
|
|
|
s_printf(get_string(249), selected - start + 2, selected, file->name);
|
2018-02-05 09:26:06 +00:00
|
|
|
s_printf("\e[%d;5H", selected - start + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (c == 65) {
|
|
|
|
// up
|
|
|
|
if (selected - 1 < start) {
|
|
|
|
start -= 22;
|
|
|
|
if (start < 0) {
|
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
selected--;
|
|
|
|
if (selected < 0) {
|
|
|
|
selected = 0;
|
|
|
|
} else {
|
2018-10-08 14:13:11 +00:00
|
|
|
if (!redraw) {
|
2018-10-16 15:05:15 +00:00
|
|
|
struct text_file *file = ptr_vector_get(&conf.text_files, selected);
|
|
|
|
struct text_file *next_file = ptr_vector_get(&conf.text_files, selected + 1);
|
|
|
|
s_printf(get_string(249), selected - start + 2, selected, file->name);
|
|
|
|
s_printf(get_string(250), selected - start + 3, selected + 1, next_file->name);
|
2018-02-05 09:26:06 +00:00
|
|
|
s_printf("\e[%d;5H", selected - start + 2);
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-02-05 09:26:06 +00:00
|
|
|
}
|
|
|
|
} else if (c == 75) {
|
|
|
|
// END KEY
|
2018-10-16 15:05:15 +00:00
|
|
|
selected = ptr_vector_len(&conf.text_files) - 1;
|
|
|
|
start = selected - 21;
|
2018-02-05 09:26:06 +00:00
|
|
|
if (start < 0) {
|
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
redraw = 1;
|
|
|
|
} else if (c == 72) {
|
|
|
|
// HOME KEY
|
|
|
|
selected = 0;
|
|
|
|
start = 0;
|
|
|
|
redraw = 1;
|
|
|
|
} else if (c == 86 || c == '5') {
|
|
|
|
if (c == '5') {
|
|
|
|
s_getchar();
|
|
|
|
}
|
|
|
|
// PAGE UP
|
|
|
|
selected = selected - 22;
|
|
|
|
if (selected < 0) {
|
|
|
|
selected = 0;
|
|
|
|
}
|
|
|
|
start = selected;
|
|
|
|
redraw = 1;
|
|
|
|
} else if (c == 85 || c == '6') {
|
|
|
|
if (c == '6') {
|
|
|
|
s_getchar();
|
|
|
|
}
|
|
|
|
// PAGE DOWN
|
|
|
|
selected = selected + 22;
|
2018-10-16 15:05:15 +00:00
|
|
|
if (selected >= ptr_vector_len(&conf.text_files)) {
|
|
|
|
selected = ptr_vector_len(&conf.text_files) - 1;
|
2018-02-05 09:26:06 +00:00
|
|
|
}
|
|
|
|
start = selected;
|
|
|
|
redraw = 1;
|
2017-04-12 06:38:33 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-05 09:26:06 +00:00
|
|
|
} else if (c == 13) {
|
2018-10-16 15:05:15 +00:00
|
|
|
struct text_file *file = ptr_vector_get(&conf.text_files, selected);
|
|
|
|
assert(file != NULL);
|
2018-02-05 09:26:06 +00:00
|
|
|
s_printf("\e[2J\e[1;1H");
|
2018-10-16 15:05:15 +00:00
|
|
|
s_displayansi_p(file->path);
|
2018-02-05 09:26:06 +00:00
|
|
|
s_printf(get_string(185));
|
|
|
|
s_getc();
|
2018-10-08 14:13:11 +00:00
|
|
|
s_printf("\r\n");
|
2018-02-05 09:26:06 +00:00
|
|
|
redraw = 1;
|
2017-04-12 06:38:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-09 03:28:49 +00:00
|
|
|
}
|