From e96b79d82ac9a370da6f4410ccc2e2bc454a5878 Mon Sep 17 00:00:00 2001
From: cyan <>
Date: Mon, 8 Dec 2003 23:33:53 +0000
Subject: [PATCH] Fix for 'invalid origin' bug on the QWK master, involving not
 checking for existing servers before allowing dynamic QWK connects.

---
 exec/ircd.js             | 43 ++++++++++++++++++++++++++++++++--------
 exec/load/ircd_server.js |  1 -
 exec/load/ircd_unreg.js  |  8 ++++----
 3 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/exec/ircd.js b/exec/ircd.js
index b0d70abfde..8a541c38cd 100644
--- a/exec/ircd.js
+++ b/exec/ircd.js
@@ -1144,17 +1144,44 @@ function IRCClient_numeric482(tmp_chan_nam) {
 //////////////////// Multi-numeric Display Functions ////////////////////
 
 function IRCClient_lusers() {
-	// FIXME: calc invis clients
-	this.numeric("251", ":There are " + true_array_len(Users) + " users and 0 invisible on " + true_array_len(Servers) + " servers.");
-	// FIXME: calc total opers
-	this.numeric("252", "0 :IRC operators online.");
-	this.numeric("253", "0 :unknown connection(s).");
-	this.numeric("254", true_array_len(Channels) + " :channels formed.");
-	this.numeric("255", ":I have " + true_array_len(Local_Users) + " clients and " + true_array_len(Local_Servers) + " servers.");
-	this.numeric("250", ":Highest connection count: " + hcc_total + " (" + hcc_users + " clients.)");
+	this.numeric(251, ":There are " + num_noninvis_users() + " users and " + num_invis_users() + " invisible on " + true_array_len(Servers) + " servers.");
+	this.numeric(252, num_opers() + " :IRC operators online.");
+	var unknown_connections = true_array_len(Unregistered);
+	if (unknown_connections)
+		this.numeric(253, unknown_connections + " :unknown connection(s).");
+	this.numeric(254, true_array_len(Channels) + " :channels formed.");
+	this.numeric(255, ":I have " + true_array_len(Local_Users) + " clients and " + true_array_len(Local_Servers) + " servers.");
+	this.numeric(250, ":Highest connection count: " + hcc_total + " (" + hcc_users + " clients.)");
 	this.server_notice(hcc_counter + " clients have connected since " + strftime("%a %b %e %H:%M:%S %Y %Z",server_uptime));
 }
 
+function num_noninvis_users() {
+	var counter = 0;
+	for(myuser in Users) {
+		if (!Users[myuser].mode&USERMODE_INVISIBLE)
+			counter++;
+	}
+	return counter;
+}
+
+function num_invis_users() {
+	var counter = 0;
+	for(myuser in Users) {
+		if (Users[myuser].mode&USERMODE_INVISIBLE)
+			counter++;
+	}
+	return counter;
+}
+
+function num_opers() {
+	var counter = 0;
+	for(myuser in Users) {
+		if (Users[myuser].mode&USERMODE_OPER)
+			counter++;
+	}
+	return counter;
+}
+
 function IRCClient_motd() {
 	var motd_file = new File(system.text_dir + "ircmotd.txt");
 	if (motd_file.exists==false)
diff --git a/exec/load/ircd_server.js b/exec/load/ircd_server.js
index aa0120e0de..5131f311cb 100644
--- a/exec/load/ircd_server.js
+++ b/exec/load/ircd_server.js
@@ -72,7 +72,6 @@ function IRC_Server() {
 	this.synchronize=IRCClient_synchronize;
 	this.reintroduce_nick=IRCClient_reintroduce_nick;
 	this.finalize_server_connect=IRCClient_finalize_server_connect;
-	this.do_msg=IRCClient_do_msg;
 	// Global Functions
 	this.check_timeout=IRCClient_check_timeout;
 	this.set_chanmode=IRCClient_set_chanmode;
diff --git a/exec/load/ircd_unreg.js b/exec/load/ircd_unreg.js
index dbbbe01a03..3387655e03 100644
--- a/exec/load/ircd_unreg.js
+++ b/exec/load/ircd_unreg.js
@@ -170,6 +170,10 @@ function Unregistered_Commands() {
 				this.numeric461("SERVER");
 				break;
 			}
+			if (Servers[cmd[1].toUpperCase()]) {
+				this.quit("Server already exists.");
+				return 0;
+			}
 			var this_nline = 0;
 			var qwk_slave = false;
 			var qwkid = cmd[1].slice(0,cmd[1].indexOf(".")).toUpperCase();
@@ -208,10 +212,6 @@ function Unregistered_Commands() {
 				this.quit("Server not configured.");
 				return 0;
 			}
-			if (Servers[cmd[1].toUpperCase()]) {
-				this.quit("Server already exists.");
-				return 0;
-			}
 			// Take care of registration right now.
 			Servers[cmd[1].toLowerCase()] = new IRC_Server;
 			var new_server = Servers[cmd[1].toLowerCase()];
-- 
GitLab