summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-02-22 23:33:56 +0000
committerrodri <rgl@antares-labs.eu>2020-02-22 23:33:56 +0000
commitf8d8ceaa929f2a507c1465a5c94299cb8ebceb70 (patch)
treea46bc0c155360bd8785f9fc0dfe2653e4412b0ac
downloadbbs-f8d8ceaa929f2a507c1465a5c94299cb8ebceb70.tar.gz
bbs-f8d8ceaa929f2a507c1465a5c94299cb8ebceb70.tar.bz2
bbs-f8d8ceaa929f2a507c1465a5c94299cb8ebceb70.zip
now version controlled.HEADmaster
-rw-r--r--bbs.c129
-rw-r--r--greeting8
-rw-r--r--mkfile14
-rwxr-xr-xtcp6662
4 files changed, 153 insertions, 0 deletions
diff --git a/bbs.c b/bbs.c
new file mode 100644
index 0000000..2a6cbd2
--- /dev/null
+++ b/bbs.c
@@ -0,0 +1,129 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+
+#define DEFGREET "Welcome to Antares Labs Computer Bulletin Board Sytem\r\n\r\n"
+#define BAUDRATE 300
+
+Biobuf bin, bout;
+char *wdir = "/sys/lib/bbs";
+char username[32];
+int debug;
+
+void
+usage(void)
+{
+ fprint(2, "usage: bbs [-d] [-m pwd]\n");
+ exits("usage");
+}
+
+void
+reply(char *msg, long len)
+{
+ char *s;
+
+ for(s = msg; (s-msg) < len; s++){
+ write(1, s, 1);
+ sleep(1000/(BAUDRATE/8));
+ }
+}
+
+void
+greet(void)
+{
+ char buf[1024];
+ int fd, n;
+
+ fd = open("greeting", OREAD);
+ if(fd < 0)
+ reply(DEFGREET, strlen(DEFGREET));
+ else
+ while((n = read(fd, buf, sizeof buf)) > 0)
+ reply(buf, n);
+ close(fd);
+
+ reply(ctime(time(0)), 30-1);
+}
+
+int
+signup(void)
+{
+ char *line, *passwd;
+ int len;
+
+ reply("username (32 chars max): ", 25);
+ line = Brdline(&bin, '\n');
+ len = Blinelen(&bin);
+ line[len-2] = 0;
+ strncpy(username, line, sizeof username);
+ reply("password: ", 10);
+ line = Brdline(&bin, '\n');
+ len = Blinelen(&bin);
+ line[len-2] = 0;
+ passwd = malloc(len);
+ strncpy(passwd, line, len);
+
+}
+
+int
+login(void)
+{
+ char *line;
+ int len;
+
+ reply("login: ", 7);
+ line = Brdline(&bin, '\n');
+ len = Blinelen(&bin);
+ line[len-2] = 0;
+ strncpy(username, line, sizeof username);
+ if(strcmp(username, "new") == 0)
+ signup();
+
+ return 0;
+}
+
+void
+main(int argc, char *argv[])
+{
+ char *line;
+ int len, i;
+
+ ARGBEGIN{
+ case 'm':
+ wdir = EARGF(usage());
+ break;
+ case 'd':
+ debug++;
+ break;
+ }ARGEND;
+
+ Binit(&bin, 0, OREAD);
+ Binit(&bout, 1, OWRITE);
+
+ if(debug)
+ for(i = 0; i < argc; i++)
+ fprint(2, "arg%d: %s\n", i, argv[i]);
+
+ if(chdir(wdir) < 0)
+ sysfatal("chdir: %r");
+
+ greet();
+
+ if(login() < 0){
+ fprint(2, "login failed for %s\n", username);
+ exits(0);
+ }
+ while(line = Brdline(&bin, '\n')){
+ if(strcmp(line, "q") == 0){
+ print("bye!\n");
+ exits(0);
+ }
+ len = Blinelen(&bin);
+ Bwrite(&bout, line, len);
+ Bflush(&bout);
+ }
+
+ Bterm(&bin);
+ Bterm(&bout);
+ exits(0);
+}
diff --git a/greeting b/greeting
new file mode 100644
index 0000000..e0554fc
--- /dev/null
+++ b/greeting
@@ -0,0 +1,8 @@
+ Welcome
+ to
+ Hosaka Industries
+ Computer Bulletin Board System
+
+
+if you don't have an account yet, login as `new'.
+ \ No newline at end of file
diff --git a/mkfile b/mkfile
new file mode 100644
index 0000000..df35d40
--- /dev/null
+++ b/mkfile
@@ -0,0 +1,14 @@
+</$objtype/mkfile
+BIN=/$objtype/bin
+
+OFILES=\
+ bbs.$O
+
+TARG=bbs
+
+</sys/src/cmd/mkone
+
+service:VQ:
+ >/sys/log/bbs
+ chmod +aw /sys/log/bbs
+ cp tcp666 /rc/bin/service
diff --git a/tcp666 b/tcp666
new file mode 100755
index 0000000..3c37bb0
--- /dev/null
+++ b/tcp666
@@ -0,0 +1,2 @@
+#!/bin/rc
+exec /bin/bbs -m /usr/rgl/tmp/bbs >>[2]/sys/log/bbs