New broadcast ability, to send notifications of log in to clients on network
This commit is contained in:
parent
b18e9ee10e
commit
e769e5448f
51
bbs.c
51
bbs.c
@ -12,6 +12,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <fts.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include "bbs.h"
|
||||
#include "lua/lua.h"
|
||||
#include "lua/lualib.h"
|
||||
@ -41,6 +42,44 @@ void sigint_handler(int s)
|
||||
{
|
||||
// do nothing...
|
||||
}
|
||||
void broadcast(char *mess, ...) {
|
||||
char buffer[512];
|
||||
struct sockaddr_in s;
|
||||
int bcast_sock;
|
||||
int broadcastEnable=1;
|
||||
int ret;
|
||||
|
||||
|
||||
|
||||
if (conf.broadcast_enable) {
|
||||
bcast_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
ret=setsockopt(bcast_sock, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));
|
||||
|
||||
if (ret) {
|
||||
dolog("broadcast: Couldn't set socket to broadcast mode");
|
||||
close(bcast_sock);
|
||||
return;
|
||||
}
|
||||
memset(&s, 0, sizeof(struct sockaddr_in));
|
||||
|
||||
s.sin_family=AF_INET;
|
||||
s.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
s.sin_port = htons((unsigned short)conf.broadcast_port);
|
||||
bind(bcast_sock, (struct sockaddr *)&s, sizeof(struct sockaddr_in));
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, mess);
|
||||
vsnprintf(buffer, 512, mess, ap);
|
||||
va_end(ap);
|
||||
|
||||
ret = sendto(bcast_sock, buffer, strlen(buffer) + 1, 0, (struct sockaddr *)&s, sizeof(struct sockaddr_in));
|
||||
|
||||
if (ret < 0) {
|
||||
dolog("broadcast: Couldn't send broadcast");
|
||||
}
|
||||
close(bcast_sock);
|
||||
}
|
||||
}
|
||||
|
||||
void dolog(char *fmt, ...) {
|
||||
char buffer[512];
|
||||
@ -61,12 +100,12 @@ void dolog(char *fmt, ...) {
|
||||
dolog("Error opening log file!");
|
||||
return;
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buffer, 512, fmt, ap);
|
||||
va_end(ap);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buffer, 512, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(logfptr, "%02d:%02d:%02d [%d][%s] %s\n", time_now.tm_hour, time_now.tm_min, time_now.tm_sec, mypid, ipaddress, buffer);
|
||||
fprintf(logfptr, "%02d:%02d:%02d [%d][%s] %s\n", time_now.tm_hour, time_now.tm_min, time_now.tm_sec, mypid, ipaddress, buffer);
|
||||
|
||||
fclose(logfptr);
|
||||
}
|
||||
@ -680,6 +719,7 @@ tryagain:
|
||||
|
||||
// do post-login
|
||||
dolog("%s logged in, on node %d", user->loginname, mynode);
|
||||
broadcast("%s: %s logged in, on node %d", conf.bbs_name, user->loginname, mynode);
|
||||
// check time left
|
||||
now = time(NULL);
|
||||
localtime_r(&now, &thetime);
|
||||
@ -749,6 +789,7 @@ tryagain:
|
||||
|
||||
|
||||
dolog("%s is logging out, on node %d", user->loginname, mynode);
|
||||
broadcast("%s: %s is logging out, on node %d", conf.bbs_name, user->loginname, mynode);
|
||||
disconnect("Log out");
|
||||
}
|
||||
|
||||
|
2
bbs.h
2
bbs.h
@ -127,6 +127,8 @@ struct bbs_config {
|
||||
int nodes;
|
||||
int newuserlvl;
|
||||
int automsgwritelvl;
|
||||
int broadcast_enable;
|
||||
int broadcast_port;
|
||||
int mail_conference_count;
|
||||
struct mail_conference **mail_conferences;
|
||||
int door_count;
|
||||
|
@ -24,6 +24,8 @@ QWK Max Messages = 5000
|
||||
ZIP Command = zip -j *a *f
|
||||
UNZIP Command = unzip -j -o *a -d *d
|
||||
Archivers = config/archivers.ini
|
||||
Broadcast Enable = false
|
||||
Broadcast Port = 2027
|
||||
|
||||
[paths]
|
||||
WWW Path = /home/andrew/MagickaBBS/www
|
||||
|
9
main.c
9
main.c
@ -379,6 +379,14 @@ static int handler(void* user, const char* section, const char* name,
|
||||
conf->bwave_max_msgs = atoi(value);
|
||||
} else if (strcasecmp(name, "archivers") == 0) {
|
||||
conf->archiver_path = strdup(value);
|
||||
} else if (strcasecmp(name, "broadcast enable") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->broadcast_enable = 1;
|
||||
} else {
|
||||
conf->broadcast_enable = 0;
|
||||
}
|
||||
} else if (strcasecmp(name, "broadcast port") == 0) {
|
||||
conf->broadcast_port = atoi(value);
|
||||
}
|
||||
} else if (strcasecmp(section, "paths") == 0){
|
||||
if (strcasecmp(name, "ansi path") == 0) {
|
||||
@ -842,6 +850,7 @@ int main(int argc, char **argv) {
|
||||
conf.www_path = NULL;
|
||||
conf.archiver_path = NULL;
|
||||
conf.archiver_count = 0;
|
||||
conf.broadcast_enable = 0;
|
||||
|
||||
// Load BBS data
|
||||
if (ini_parse(argv[1], handler, &conf) <0) {
|
||||
|
Reference in New Issue
Block a user