Door Games working!, stdio ones not done yet...
This commit is contained in:
parent
a6094e5512
commit
cb36e71300
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,3 +3,5 @@
|
|||||||
*.core
|
*.core
|
||||||
magicka
|
magicka
|
||||||
msgs/*
|
msgs/*
|
||||||
|
node*
|
||||||
|
doors/*
|
||||||
|
2
Makefile
2
Makefile
@ -3,7 +3,7 @@ CFLAGS=-I/usr/local/include
|
|||||||
DEPS = bbs.h
|
DEPS = bbs.h
|
||||||
JAMLIB = /usr/local/lib/libjam.a
|
JAMLIB = /usr/local/lib/libjam.a
|
||||||
|
|
||||||
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o
|
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o
|
||||||
%.o: %.c $(DEPS)
|
%.o: %.c $(DEPS)
|
||||||
$(CC) -c -o $@ $< $(CFLAGS)
|
$(CC) -c -o $@ $< $(CFLAGS)
|
||||||
|
|
||||||
|
54
bbs.c
54
bbs.c
@ -38,7 +38,55 @@ void timer_handler(int signum) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static int door_config_handler(void* user, const char* section, const char* name,
|
||||||
|
const char* value)
|
||||||
|
{
|
||||||
|
struct bbs_config *conf = (struct bbs_config *)user;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0;i<conf->door_count;i++) {
|
||||||
|
if (strcasecmp(conf->doors[i]->name, section) == 0) {
|
||||||
|
// found it
|
||||||
|
if (strcasecmp(name, "key") == 0) {
|
||||||
|
conf->doors[i]->key = value[0];
|
||||||
|
} else if (strcasecmp(name, "command") == 0) {
|
||||||
|
conf->doors[i]->command = strdup(value);
|
||||||
|
} else if (strcasecmp(name, "stdio") == 0) {
|
||||||
|
if (strcasecmp(value, "true") == 0) {
|
||||||
|
conf->doors[i]->stdio = 1;
|
||||||
|
} else {
|
||||||
|
conf->doors[i]->stdio = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conf->door_count == 0) {
|
||||||
|
conf->doors = (struct door_config **)malloc(sizeof(struct door_config *));
|
||||||
|
} else {
|
||||||
|
conf->doors = (struct door_config **)realloc(conf->doors, sizeof(struct door_config *) * (conf->door_count + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->doors[conf->door_count] = (struct door_config *)malloc(sizeof(struct door_config));
|
||||||
|
|
||||||
|
conf->doors[conf->door_count]->name = strdup(section);
|
||||||
|
|
||||||
|
if (strcasecmp(name, "key") == 0) {
|
||||||
|
conf->doors[conf->door_count]->key = value[0];
|
||||||
|
} else if (strcasecmp(name, "command") == 0) {
|
||||||
|
conf->doors[conf->door_count]->command = strdup(value);
|
||||||
|
} else if (strcasecmp(name, "stdio") == 0) {
|
||||||
|
if (strcasecmp(value, "true") == 0) {
|
||||||
|
conf->doors[conf->door_count]->stdio = 1;
|
||||||
|
} else {
|
||||||
|
conf->doors[conf->door_count]->stdio = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
conf->door_count++;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
static int mail_area_handler(void* user, const char* section, const char* name,
|
static int mail_area_handler(void* user, const char* section, const char* name,
|
||||||
const char* value)
|
const char* value)
|
||||||
{
|
{
|
||||||
@ -324,6 +372,8 @@ void runbbs(int socket, char *config_path) {
|
|||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
|
|
||||||
conf.mail_conference_count = 0;
|
conf.mail_conference_count = 0;
|
||||||
|
conf.door_count = 0;
|
||||||
|
|
||||||
// Load BBS data
|
// Load BBS data
|
||||||
if (ini_parse(config_path, handler, &conf) <0) {
|
if (ini_parse(config_path, handler, &conf) <0) {
|
||||||
printf("Unable to load configuration ini (%s)!\n", config_path);
|
printf("Unable to load configuration ini (%s)!\n", config_path);
|
||||||
@ -337,6 +387,10 @@ void runbbs(int socket, char *config_path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ini_parse("doors.ini", door_config_handler, &conf) <0) {
|
||||||
|
printf("Unable to load configuration ini (doors.ini)!\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
// find out which node we are
|
// find out which node we are
|
||||||
mynode = 0;
|
mynode = 0;
|
||||||
|
11
bbs.h
11
bbs.h
@ -7,6 +7,13 @@
|
|||||||
#define VERSION_MINOR 1
|
#define VERSION_MINOR 1
|
||||||
#define VERSION_STR "dev"
|
#define VERSION_STR "dev"
|
||||||
|
|
||||||
|
struct door_config {
|
||||||
|
char *name;
|
||||||
|
char key;
|
||||||
|
char *command;
|
||||||
|
int stdio;
|
||||||
|
};
|
||||||
|
|
||||||
struct mail_area {
|
struct mail_area {
|
||||||
char *name;
|
char *name;
|
||||||
char *path;
|
char *path;
|
||||||
@ -36,6 +43,8 @@ struct bbs_config {
|
|||||||
int newuserlvl;
|
int newuserlvl;
|
||||||
int mail_conference_count;
|
int mail_conference_count;
|
||||||
struct mail_conference **mail_conferences;
|
struct mail_conference **mail_conferences;
|
||||||
|
int door_count;
|
||||||
|
struct door_config **doors;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sec_level_t {
|
struct sec_level_t {
|
||||||
@ -82,4 +91,6 @@ extern void main_menu(int socket, struct user_record *user);
|
|||||||
|
|
||||||
extern int mail_getemailcount(struct user_record *user);
|
extern int mail_getemailcount(struct user_record *user);
|
||||||
extern int mail_menu(int socket, struct user_record *user);
|
extern int mail_menu(int socket, struct user_record *user);
|
||||||
|
|
||||||
|
extern int door_menu(int socket, struct user_record *user);
|
||||||
#endif
|
#endif
|
||||||
|
95
doors.c
Normal file
95
doors.c
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "bbs.h"
|
||||||
|
|
||||||
|
extern struct bbs_config conf;
|
||||||
|
extern int mynode;
|
||||||
|
|
||||||
|
int write_door32sys(int socket, struct user_record *user) {
|
||||||
|
struct stat s;
|
||||||
|
char buffer[256];
|
||||||
|
FILE *fptr;
|
||||||
|
|
||||||
|
sprintf(buffer, "%s/node%d", conf.bbs_path, mynode);
|
||||||
|
|
||||||
|
if (stat(buffer, &s) != 0) {
|
||||||
|
mkdir(buffer, 0755);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(buffer, "%s/node%d/door32.sys", conf.bbs_path, mynode);
|
||||||
|
|
||||||
|
fptr = fopen(buffer, "w");
|
||||||
|
|
||||||
|
if (!fptr) {
|
||||||
|
printf("Unable to open %s for writing!\n", buffer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fptr, "2\n"); // telnet type
|
||||||
|
fprintf(fptr, "%d\n", socket); // socket
|
||||||
|
fprintf(fptr, "38400\n"); // baudrate
|
||||||
|
fprintf(fptr, "Magicka %d.%d\n", VERSION_MAJOR, VERSION_MINOR);
|
||||||
|
fprintf(fptr, "%d\n", user->id);
|
||||||
|
fprintf(fptr, "%s %s\n", user->firstname, user->lastname);
|
||||||
|
fprintf(fptr, "%s\n", user->loginname);
|
||||||
|
fprintf(fptr, "%d\n", user->sec_level);
|
||||||
|
fprintf(fptr, "%d\n", user->timeleft);
|
||||||
|
fprintf(fptr, "1\n"); // ansi emulation = 1
|
||||||
|
fprintf(fptr, "%d\n", mynode);
|
||||||
|
|
||||||
|
fclose(fptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
|
||||||
|
char buffer[256];
|
||||||
|
if (write_door32sys(socket, user) != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stdio) {
|
||||||
|
} else {
|
||||||
|
sprintf(buffer, "%s %d %d", cmd, mynode, socket);
|
||||||
|
system(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int door_menu(int socket, struct user_record *user) {
|
||||||
|
int doquit = 0;
|
||||||
|
int dodoors = 0;
|
||||||
|
char prompt[128];
|
||||||
|
int i;
|
||||||
|
char c;
|
||||||
|
while (!dodoors) {
|
||||||
|
s_displayansi(socket, "doors");
|
||||||
|
|
||||||
|
sprintf(prompt, "TL: %dm :> ", user->timeleft);
|
||||||
|
s_putstring(socket, prompt);
|
||||||
|
|
||||||
|
c = s_getc(socket);
|
||||||
|
|
||||||
|
switch(tolower(c)) {
|
||||||
|
case 'q':
|
||||||
|
dodoors = 1;
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
doquit = 1;
|
||||||
|
dodoors = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
for (i=0;i<conf.door_count;i++) {
|
||||||
|
if (tolower(c) == tolower(conf.doors[i]->key)) {
|
||||||
|
rundoor(socket, user, conf.doors[i]->command, conf.doors[i]->stdio);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return doquit;
|
||||||
|
}
|
8
doors.ini
Normal file
8
doors.ini
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[Test Door]
|
||||||
|
; the key to press in the door menu must not be Q or G not case sensitive
|
||||||
|
key = 0
|
||||||
|
; the command is passed node number as first argument
|
||||||
|
; and socket number as second argument.
|
||||||
|
command = /home/andrew/MagickaBBS/doors/rundoor.sh
|
||||||
|
; whether or not to use stdio redirection
|
||||||
|
stdio = false
|
@ -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 'd':
|
||||||
|
{
|
||||||
|
doquit = door_menu(socket, user);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
{
|
{
|
||||||
doquit = mail_menu(socket, user);
|
doquit = mail_menu(socket, user);
|
||||||
|
7
users.c
7
users.c
@ -153,6 +153,9 @@ int inst_user(struct user_record *user) {
|
|||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user->id = sqlite3_last_insert_rowid(db);
|
||||||
|
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -385,6 +388,10 @@ struct user_record *new_user(int socket) {
|
|||||||
|
|
||||||
user->laston = time(NULL);
|
user->laston = time(NULL);
|
||||||
user->timeleft = user->sec_info->timeperday;
|
user->timeleft = user->sec_info->timeperday;
|
||||||
|
user->cur_file_dir = 0;
|
||||||
|
user->cur_file_sub = 0;
|
||||||
|
user->cur_mail_area = 0;
|
||||||
|
user->cur_mail_conf = 0;
|
||||||
inst_user(user);
|
inst_user(user);
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
Reference in New Issue
Block a user