From beac56d15d55af2dc9aa939a8ae279a6d32bc09b Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Mon, 13 Aug 2007 04:25:41 +0000
Subject: [PATCH] Add QOTD service (sends the current automessage)

---
 exec/qotdservice.js | 59 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 exec/qotdservice.js

diff --git a/exec/qotdservice.js b/exec/qotdservice.js
new file mode 100644
index 0000000000..861e9f9b6d
--- /dev/null
+++ b/exec/qotdservice.js
@@ -0,0 +1,59 @@
+// qotdservice.js
+
+// Synchronet Service for the Quote of The Day protocol (RFC 865)
+
+// $Id$
+
+
+const REVISION = "$Revision$".split(' ')[1];
+
+var output_buf = "";
+
+// Write a string to the client socket
+function write(str)
+{
+	output_buf += str;
+}
+
+// Write all the output at once
+function flush()
+{
+	client.socket.send(output_buf);
+}
+
+function done()
+{
+	flush();
+	exit();
+}
+
+automsg=new File(system.data_dir+"msgs/auto.msg");
+if(!automsg.open("r",true)) {
+	log("Error opening "+system.data_dir+"msgs/auto.msg for read");
+	write("No AutoMessage set\r\n");
+	done();
+}
+
+while(1) {
+	if(!client.socket.is_connected)
+		done();
+	b=automsg.readBin(1);
+	if(automsg.eof)
+		done();
+	if(b==1) {	// CTRL-A... eat it
+		b=automsg.readBin(1);
+		if(b!=1)
+			continue;
+	}
+	if(b < 32) {
+		switch(b) {
+			case 9:
+			case 10:
+			case 13:
+				break;
+			default:
+				continue;
+		}
+	}
+	write(ascii(b));
+}
-- 
GitLab