From e7822eb5069617c735c75b8216fd8a6ea106471c Mon Sep 17 00:00:00 2001 From: AnonymousHybi Date: Sun, 20 May 2018 01:32:12 +0100 Subject: [PATCH] Adds in the Discord Verification system and fixes the bot~ --- SQL/feedback_schema.sql | 9 ++++++- SQL/tgstation_schema.sql | 24 +++++++++---------- code/controllers/configuration_ch.dm | 35 ++++++++++++++++++++++++++++ code/hub.dm | 2 +- code/modules/client/client procs.dm | 27 +++++++++++++++++++++ code/modules/ext_scripts/irc.dm | 13 ++++++----- config/example/config.txt | 9 ++++++- scripts/ircbot_message.py | 29 +++++++++++------------ vorestation.dme | 1 + 9 files changed, 113 insertions(+), 36 deletions(-) create mode 100644 code/controllers/configuration_ch.dm diff --git a/SQL/feedback_schema.sql b/SQL/feedback_schema.sql index ee8975263b..fa19f9db3f 100644 --- a/SQL/feedback_schema.sql +++ b/SQL/feedback_schema.sql @@ -124,4 +124,11 @@ CREATE TABLE `vr_player_hours` ( `department` varchar(64) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, `hours` double NOT NULL, PRIMARY KEY (`ckey`,`department`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +CREATE TABLE `discord2byond` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `ckey` varchar(32) NOT NULL, + `userid` int(32) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql index 65f1b537ab..4978c514b8 100644 --- a/SQL/tgstation_schema.sql +++ b/SQL/tgstation_schema.sql @@ -2,13 +2,13 @@ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; -CREATE SCHEMA IF NOT EXISTS `shawn_chompstation_master` DEFAULT CHARACTER SET latin1 ; -USE `shawn_chompstation_master` ; +CREATE SCHEMA IF NOT EXISTS `tgstation` DEFAULT CHARACTER SET latin1 ; +USE `tgstation` ; -- ----------------------------------------------------- --- Table `shawn_chompstation_master`.`death` +-- Table `tgstation`.`death` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `shawn_chompstation_master`.`death` ( +CREATE TABLE IF NOT EXISTS `tgstation`.`death` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `pod` TEXT NOT NULL COMMENT 'Place of death' , `coord` TEXT NOT NULL COMMENT 'X, Y, Z POD' , @@ -31,9 +31,9 @@ DEFAULT CHARACTER SET = latin1; -- ----------------------------------------------------- --- Table `shawn_chompstation_master`.`karma` +-- Table `tgstation`.`karma` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `shawn_chompstation_master`.`karma` ( +CREATE TABLE IF NOT EXISTS `tgstation`.`karma` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `spendername` TEXT NOT NULL , `spenderkey` TEXT NOT NULL , @@ -51,9 +51,9 @@ DEFAULT CHARACTER SET = latin1; -- ----------------------------------------------------- --- Table `shawn_chompstation_master`.`karmatotals` +-- Table `tgstation`.`karmatotals` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `shawn_chompstation_master`.`karmatotals` ( +CREATE TABLE IF NOT EXISTS `tgstation`.`karmatotals` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `byondkey` TEXT NOT NULL , `karma` INT(11) NOT NULL , @@ -64,9 +64,9 @@ DEFAULT CHARACTER SET = latin1; -- ----------------------------------------------------- --- Table `shawn_chompstation_master`.`library` +-- Table `tgstation`.`library` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `shawn_chompstation_master`.`library` ( +CREATE TABLE IF NOT EXISTS `tgstation`.`library` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `author` TEXT NOT NULL , `title` TEXT NOT NULL , @@ -79,9 +79,9 @@ DEFAULT CHARACTER SET = latin1; -- ----------------------------------------------------- --- Table `shawn_chompstation_master`.`population` +-- Table `tgstation`.`population` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `shawn_chompstation_master`.`population` ( +CREATE TABLE IF NOT EXISTS `tgstation`.`population` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `playercount` INT(11) NULL DEFAULT NULL , `admincount` INT(11) NULL DEFAULT NULL , diff --git a/code/controllers/configuration_ch.dm b/code/controllers/configuration_ch.dm new file mode 100644 index 0000000000..70f481e198 --- /dev/null +++ b/code/controllers/configuration_ch.dm @@ -0,0 +1,35 @@ +// Making this file to allow us to easily understand the location of any modifications to the config file made by Chompers and to try and prevent any conflicts happening in the future. +// Basically a copy pasta from virgo's configuration.dm file but it'll make life easer for us to just toggle on/off. + + +/datum/configuration + var/discord_restriction = 0 + +/hook/startup/proc/read_ch_config() + var/list/Lines = file2list("config/config.txt") + for(var/t in Lines) + if(!t) continue + + t = trim(t) + if (length(t) == 0) + continue + else if (copytext(t, 1, 2) == "#") + continue + + var/pos = findtext(t, " ") + var/name = null +// var/value = null //Commenting out because config doesn't contain any values at the moment. - Jonathan + + if (pos) + name = lowertext(copytext(t, 1, pos)) +// value = copytext(t, pos + 1) //Commenting out because config doesn't contain any values at the moment. - Jonathan + else + name = lowertext(t) + + if (!name) + continue + + switch (name) + if ("discord_restriction") + config.discord_restriction = 1 + return 1 diff --git a/code/hub.dm b/code/hub.dm index 9bd4fae1d8..26f890b58c 100644 --- a/code/hub.dm +++ b/code/hub.dm @@ -3,7 +3,7 @@ hub = "Exadv1.spacestation13" //hub_password = "SORRYNOPASSWORD" hub_password = "kMZy3U5jJHSiBQjr" - name = "Space Station 13" + name = "CHOMPstation | Vore RPing Server | Must be in Discord | 24/7 Extended (Test server)" /* This is for any host that would like their server to appear on the main SS13 hub. To use it, simply replace the password above, with the password found below, and it should work. diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index fe37d19f4b..bf926e5b91 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -251,6 +251,8 @@ //Panic bunker code if (isnum(player_age) && player_age == 0) //first connection + log_adminwarn("[key] has joined for the first time.") //Chompstation edit, notifying admins of a first join <3 + message_admins("[key] has joined for the first time.") if (config.panic_bunker && !holder && !deadmin_holder) log_adminwarn("Failed Login: [key] - New account attempting to connect during panic bunker") message_admins("Failed Login: [key] - New account attempting to connect during panic bunker") @@ -258,6 +260,13 @@ qdel(src) return 0 + // Chompstation edit, adds restriction that you can only join with discord account linked to your ckey - Jonathan + if(config.discord_restriction && !IsDiscordLinked(ckey)) + to_chat(src,"This server requires you to be linked to the Chompers Discord server in order to connect. Please head to https://chompstation.tk to find out more about our server.") + qdel(src) + return 0 + // Chompstation edit end + // VOREStation Edit Start - Department Hours if(config.time_off) var/DBQuery/query_hours = dbcon.NewQuery("SELECT department, hours FROM vr_player_hours WHERE ckey = '[sql_ckey]'") @@ -372,3 +381,21 @@ client/verb/character_setup() set category = "Preferences" if(prefs) prefs.ShowChoices(usr) + +// Chompstation Edit, adding a proc to check if their account is linked to discord. - Jonathan +/proc/IsDiscordLinked(ckey) + establish_db_connection() + if(!dbcon.IsConnected()) + return null + + var/sql_ckey = sql_sanitize_text(ckey) + + var/DBQuery/query = dbcon.NewQuery("SELECT * FROM discord2byond WHERE ckey = '[sql_ckey]'") + query.Execute() + + if(query.NextRow()) + if(ckey in query.item) + return 1 + else + return 0 +// Chompstation Edit end. \ No newline at end of file diff --git a/code/modules/ext_scripts/irc.dm b/code/modules/ext_scripts/irc.dm index 103fdf55d0..9a37208adf 100644 --- a/code/modules/ext_scripts/irc.dm +++ b/code/modules/ext_scripts/irc.dm @@ -1,17 +1,18 @@ -/proc/send2irc(var/channel, var/msg) +/proc/send2irc(var/msg, var/admin = 0) if(config.use_irc_bot) paranoid_sanitize(msg) - ext_python("ircbot_message.py", "[config.comms_password] [config.irc_bot_host] [channel] [msg]") + if(admin) + msg = "ADMIN - [msg]" + // 3rd param is unused in the bot, would spend time to fix this but I'm lazy. - Jon + ext_python("ircbot_message.py", "[config.comms_password] [config.irc_bot_host] null [msg]") return /proc/send2mainirc(var/msg) - if(config.main_irc) - send2irc(config.main_irc, msg) + send2irc(msg) return /proc/send2adminirc(var/msg) - var/queuedmsg = "ADMIN - [msg]" - send2irc(config.admin_irc, queuedmsg) + send2irc(msg, 1) return /hook/startup/proc/ircNotify() diff --git a/config/example/config.txt b/config/example/config.txt index f9ff877e89..0f59d3c767 100644 --- a/config/example/config.txt +++ b/config/example/config.txt @@ -408,4 +408,11 @@ ENGINE_MAP Supermatter Engine,Edison's Bane # Applies a limit to the number of assistants and visitors respectively # LIMIT_INTERNS 6 -# LIMIT_VISITORS 6 \ No newline at end of file +# LIMIT_VISITORS 6 + +## Setting to prevent players from joining without having their accounts linked to their discord account. +## WIP system to allow a bot to be a interface to allow basic moderation to both discord and SS13 at the same time. +## A specific bot is required to use this, ask Jonathan123ii on discord about this information. +## Uncomment to enable discord restriction, default off if you leave commented. +# DISCORD_RESTRICTION + diff --git a/scripts/ircbot_message.py b/scripts/ircbot_message.py index 4339019e03..fc029772f9 100644 --- a/scripts/ircbot_message.py +++ b/scripts/ircbot_message.py @@ -1,31 +1,30 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # Four arguments, password host channel and message. # EG: "ircbot_message.py hunter2 example.com #adminchannel ADMINHELP, people are killing me!" -import sys,cPickle,socket,HTMLParser +import sys +import socket def pack(): - ht = HTMLParser.HTMLParser() - - passwd = sys.argv[1] - ip = sys.argv[3] + try: - data = [] - for in_data in sys.argv[4:]: #The rest of the arguments is data - data += {ht.unescape(in_data)} + data = sys.argv[4:] + print(data) except: data = "NO DATA SPECIFIED" - dictionary = {"ip":ip,"data":[passwd] + data} - pickled = cPickle.dumps(dictionary) - nudge(pickled) + data = str(data) + data = bytes(data, "ascii") + print(data) + nudge(data) + def nudge(data): HOST = sys.argv[2] PORT = 45678 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((HOST,PORT)) + s.connect((HOST, PORT)) s.send(data) s.close() -if __name__ == "__main__" and len(sys.argv) > 1: # If not imported and more than one argument - pack() +if __name__ == "__main__" and len(sys.argv) > 1: # If not imported and more than one argument + pack() \ No newline at end of file diff --git a/vorestation.dme b/vorestation.dme index 3862a582ca..b340e6b6f2 100644 --- a/vorestation.dme +++ b/vorestation.dme @@ -174,6 +174,7 @@ #include "code\controllers\autotransfer.dm" #include "code\controllers\communications.dm" #include "code\controllers\configuration.dm" +#include "code\controllers\configuration_ch.dm" #include "code\controllers\configuration_vr.dm" #include "code\controllers\controller.dm" #include "code\controllers\emergency_shuttle_controller.dm"