home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
239.lha
/
amiga
/
src
/
bbs
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-02
|
3KB
|
129 lines
/*
* MAIN.C
*
* This is a combination client-server. Client in that it is run
* either manually or via DNET startup. Server in that it accepts
* remote connects. However, since the server is not started up as
* a dnet server, it will not be killed automatically.
*
* (1) Listen on PORT_BBS for connections
* (2) Monitor DNET and disconnect idle or connect timeout limit
* (3) IPC interface commands
*
* (4) Accept connections on PORT_BBS and handle BBS functions.
*/
#include "defs.h"
#include <local/xmisc.h>
long Chan;
extern int Enable_Abort;
main(ac, av)
char *av[];
{
PORT *DListen();
PORT *port;
long mask;
long lmask; /* listen port mask */
long cmask; /* channel port mask */
long imask; /* ipc port mask */
Enable_Abort = 0;
openlibs(DRES_LIB);
port = DListen(PORT_BBS);
if (port == NULL) {
puts("DBBS: DBBS already running, exiting");
closelibs(-1);
exit(1);
}
lmask = 1 << port->mp_SigBit;
cmask = 0;
imask = 0;
mask = SIGBREAKF_CTRL_C | lmask | cmask | imask;
for (;;) {
register long sigs = Wait(mask);
if (Chan && (sigs & cmask)) { /* read into buffer and pass on */
char buf[64];
short n;
char aux;
n = DNRead(Chan, buf, sizeof(buf));
if (n > 0) {
printf("Recv: ");
fflush(stdout);
write(1, buf, n);
}
if (n == -2) {
short val;
short cmd = DGetIoctl(Chan, &val, &aux);
if (cmd >= 0)
HandleIoctl(cmd, val, aux);
printf("RECV IOCTL %d %d %d\n", cmd, val, aux);
}
if (n < 0)
printf("GET N %d\n", n);
}
if (Chan && DCheckEof(Chan)) {
DWrite(Chan, "DBBS close\n", 11);
DClose(Chan);
puts("Disconnect");
Chan = 0;
mask &= ~cmask;
cmask = 0;
}
if (sigs & SIGBREAKF_CTRL_C)
break;
if (sigs & lmask) {
if (!Chan) {
printf("Connect ");
if (Chan = DAccept(port)) {
puts("OK");
cmask = 1 << ((PORT *)Chan)->mp_SigBit;
DQueue(Chan, 4);
mask |= cmask;
HelloMsg();
DIoctl(Chan, CIO_MODE, 3, 0); /* set echo+cooked mode */
} else {
puts("Failed");
}
} else {
DNAAccept(port);
}
}
if (sigs & imask) {
;
}
}
if (Chan)
DClose(Chan);
if (port)
DUnListen(port);
closelibs(-1);
}
/*
* Hello Msg.
*
* DBBS:hello.msg
*/
HelloMsg()
{
FILE *fi = fopen("dbbs:hello.msg", "r");
char buf[128];
if (fi) {
while (fgets(buf, sizeof(buf), fi))
DWrite(Chan, buf, strlen(buf));
fclose(fi);
}
}
HandleIoctl(cmd, n, aux)
{
}