Added Last 10 Caller functionallity

This commit is contained in:
Andrew Pamment 2016-03-23 15:21:53 +10:00
parent 56c092674f
commit e7161ab489
4 changed files with 68 additions and 0 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ magicka
msgs/* msgs/*
node* node*
doors/* doors/*
last10.dat

55
bbs.c
View File

@ -313,6 +313,59 @@ void disconnect(int socket) {
exit(0); exit(0);
} }
void display_last10_callers(int socket, struct user_record *user, int record) {
struct last10_callers callers[10];
struct last10_callers new_entry;
int i,z,j;
char buffer[256];
struct tm l10_time;
FILE *fptr = fopen("last10.dat", "rb");
s_putstring(socket, "\r\n\e[1;37mLast 10 callers:\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\r\n");
if (fptr != NULL) {
for (i=0;i<10;i++) {
if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) {
break;
}
}
fclose(fptr);
} else {
i = 0;
}
for (z=0;z<i;z++) {
localtime_r(&callers[z].time, &l10_time);
sprintf(buffer, "\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%02d:%02d %02d-%02d-%02d\e[0m\r\n", callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mday, l10_time.tm_mon + 1, l10_time.tm_year - 100);
s_putstring(socket, buffer);
}
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
if (strcasecmp(conf.sysop_name, user->loginname) != 0 && record) {
memset(&new_entry, 0, sizeof(struct last10_callers));
strcpy(new_entry.name, user->loginname);
strcpy(new_entry.location, user->location);
new_entry.time = time(NULL);
if (i == 10) {
j = 1;
} else {
j = 0;
}
fptr = fopen("last10.dat", "wb");
for (;j<i;j++) {
fwrite(&callers[j], sizeof(struct last10_callers), 1, fptr);
}
fwrite(&new_entry, sizeof(struct last10_callers), 1, fptr);
fclose(fptr);
}
sprintf(buffer, "Press any key to continue...\r\n");
s_putstring(socket, buffer);
s_getc(socket);
}
void display_info(int socket) { void display_info(int socket) {
char buffer[256]; char buffer[256];
struct utsname name; struct utsname name;
@ -518,6 +571,8 @@ void runbbs(int socket, char *config_path) {
// display info // display info
display_info(socket); display_info(socket);
display_last10_callers(socket, user, 1);
// main menu // main menu
main_menu(socket, user); main_menu(socket, user);

7
bbs.h
View File

@ -7,6 +7,12 @@
#define VERSION_MINOR 1 #define VERSION_MINOR 1
#define VERSION_STR "dev" #define VERSION_STR "dev"
struct last10_callers {
char name[17];
char location[33];
time_t time;
}__attribute__((packed));
struct door_config { struct door_config {
char *name; char *name;
char key; char key;
@ -80,6 +86,7 @@ extern void s_readstring(int socket, char *buffer, int max);
extern char s_getc(int socket); extern char s_getc(int socket);
extern void disconnect(int socket); extern void disconnect(int socket);
extern void display_info(int socket); extern void display_info(int socket);
extern void display_last10_callers(int socket, struct user_record *user, int record);
extern int save_user(struct user_record *user); extern int save_user(struct user_record *user);
extern int check_user(char *loginname); extern int check_user(char *loginname);

View File

@ -20,6 +20,11 @@ void main_menu(int socket, struct user_record *user) {
c = s_getc(socket); c = s_getc(socket);
switch(tolower(c)) { switch(tolower(c)) {
case '1':
{
display_last10_callers(socket, user, 0);
}
break;
case 'd': case 'd':
{ {
doquit = door_menu(socket, user); doquit = door_menu(socket, user);