mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-27 05:57:24 +01:00
Introduced forum account authentication system.
Added a new configuration .txt to enable forum database communication. Every connected client receives a new verb to use this system, 'Activate Forum Account' as defined in forum_activation.dm. git-svn-id: http://tgstation13.googlecode.com/svn/trunk@1173 316c924e-a436-60f5-8080-3fe189b3f50e
This commit is contained in:
@@ -241,6 +241,59 @@
|
||||
else
|
||||
diary << "Unknown setting in configuration: '[name]'"
|
||||
|
||||
/datum/configuration/proc/loadforumsql(filename) // -- TLE
|
||||
var/text = file2text(filename)
|
||||
|
||||
if (!text)
|
||||
diary << "No forumdbconfig.txt file found, retaining defaults"
|
||||
world << "No forumdbconfig.txt file found, retaining defaults"
|
||||
return
|
||||
|
||||
diary << "Reading forum database configuration file [filename]"
|
||||
|
||||
var/list/CL = dd_text2list(text, "\n")
|
||||
|
||||
for (var/t in CL)
|
||||
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
|
||||
|
||||
if (pos)
|
||||
name = lowertext(copytext(t, 1, pos))
|
||||
value = copytext(t, pos + 1)
|
||||
else
|
||||
name = lowertext(t)
|
||||
|
||||
if (!name)
|
||||
continue
|
||||
|
||||
switch (name)
|
||||
if ("address")
|
||||
forumsqladdress = value
|
||||
if ("port")
|
||||
forumsqlport = value
|
||||
if ("database")
|
||||
forumsqldb = value
|
||||
if ("login")
|
||||
forumsqllogin = value
|
||||
if ("password")
|
||||
forumsqlpass = value
|
||||
if ("activatedgroup")
|
||||
forum_activated_group = value
|
||||
if ("authenticatedgroup")
|
||||
forum_authenticated_group = value
|
||||
else
|
||||
diary << "Unknown setting in configuration: '[name]'"
|
||||
|
||||
/datum/configuration/proc/pick_mode(mode_name)
|
||||
// I wish I didn't have to instance the game modes in order to look up
|
||||
// their information, but it is the only way (at least that I know of).
|
||||
|
||||
+15
-1
@@ -202,4 +202,18 @@ var
|
||||
sqllogin = "root"
|
||||
sqlpass = ""
|
||||
|
||||
sqllogging = 0 // Should we log deaths, population stats, etc?
|
||||
sqllogging = 0 // Should we log deaths, population stats, etc?
|
||||
|
||||
|
||||
|
||||
// Forum MySQL configuration (for use with forum account/key authentication)
|
||||
// These are all default values that will load should the forumdbconfig.txt
|
||||
// file fail to read for whatever reason.
|
||||
|
||||
forumsqladdress = "localhost"
|
||||
forumsqlport = "3306"
|
||||
forumsqldb = "tgstation"
|
||||
forumsqllogin = "root"
|
||||
forumsqlpass = ""
|
||||
forum_activated_group = "2"
|
||||
forum_authenticated_group = "10"
|
||||
@@ -0,0 +1,97 @@
|
||||
//*******************************
|
||||
//
|
||||
// Forum SQL Account Activation
|
||||
//
|
||||
//*******************************
|
||||
//
|
||||
// This module allows players to associate their BYOND keys with a specific forum username on the /tg/station forums.
|
||||
// Its original intent is to disable posting for any non-associated forum accounts, and only allow players who've activated
|
||||
// their account in-game to be able to post, hopefully reducing the spam the forum receives dramatically.
|
||||
//
|
||||
// This effect, of course, is not achieved entirely within BYOND. Some configuration on the forum-side is required as well.
|
||||
// Targetted for phpBB3, not tested with earlier versions.
|
||||
//
|
||||
//
|
||||
// Requires Dantom.DB library ( http://www.byond.com/developer/Dantom/DB )
|
||||
//
|
||||
// Written by TLE for /tg/station13
|
||||
|
||||
|
||||
/proc/associate_key_with_forum(var/accname as text, var/playerkey as text)
|
||||
var/DBConnection/dbcon = new()
|
||||
var/uid
|
||||
|
||||
// TODO: Replace local vars with global var references
|
||||
var/TG13user = forumsqllogin
|
||||
var/TG13pass = forumsqlpass
|
||||
var/TG13db = forumsqldb
|
||||
var/TG13address = forumsqladdress
|
||||
var/TG13port = forumsqlport
|
||||
|
||||
dbcon.Connect("dbi:mysql:[TG13db]:[TG13address]:[TG13port]","[TG13user]","[TG13pass]")
|
||||
if(!dbcon.IsConnected())
|
||||
usr << "<font color=red><b>Server Connection Error</b> : Unable to open a connection with the forum database.</font>"
|
||||
usr << "<i>Potential causes for this problem: Incorrect login information, incorrect server connection information, the forum server is down or not responding to requests, your firewall is blocking outgoing SQL requests.</i>"
|
||||
return
|
||||
|
||||
// Sanitize inputs to avoid SQL injection attacks
|
||||
accname = dd_replacetext(accname, "'", "''")
|
||||
accname = dd_replacetext(accname, ";", "")
|
||||
accname = dd_replacetext(accname, "&", "")
|
||||
playerkey = dd_replacetext(playerkey, "'", "''")
|
||||
playerkey = dd_replacetext(playerkey, ";", "")
|
||||
playerkey = dd_replacetext(playerkey, "&", "")
|
||||
|
||||
|
||||
var/DBQuery/query = dbcon.NewQuery("SELECT user_id FROM [forumsqldb].phpbb_users WHERE username = '[accname]'")
|
||||
query.Execute()
|
||||
while(query.NextRow())
|
||||
uid = query.item[1] // Find and save the account's user_id
|
||||
if(!uid)
|
||||
usr << "Forum account not found!"
|
||||
dbcon.Disconnect()
|
||||
return
|
||||
|
||||
query = dbcon.NewQuery("SELECT pf_byondkey FROM [forumsqldb].phpbb_profile_fields_data WHERE user_id = [uid]")
|
||||
if(!query.Execute())
|
||||
usr << "Unable to verify whether account is already associated with a BYOND key or not. This error shouldn't occur, please contact an administrator."
|
||||
dbcon.Disconnect()
|
||||
return
|
||||
if(query.RowCount() > 0)
|
||||
query.NextRow()
|
||||
var/currentholder = query.item[1]
|
||||
usr << "Forum account already has a BYOND key associated with it. The current BYOND key associated with the account is \"[currentholder]\"."
|
||||
usr << "If this is not a key you own and you feel that someone has wrongfully authenticated your forum account please contact an administrator to have your account returned to you."
|
||||
dbcon.Disconnect()
|
||||
return
|
||||
|
||||
query = dbcon.NewQuery("SELECT * FROM [forumsqldb].phpbb_user_group WHERE user_id = [uid] AND group_id = [forum_authenticated_group]")
|
||||
if(!query.Execute())
|
||||
usr << "Unable to verify whether account is already part of the authenticated group or not. This error should not occur, please contact an administrator."
|
||||
dbcon.Disconnect()
|
||||
return
|
||||
if(query.RowCount() > 0)
|
||||
usr << "Forum account already belongs to the authenticated group. If this is your account and you did not authenticate it please contact an administrator to have your account returned to you."
|
||||
dbcon.Disconnect()
|
||||
return
|
||||
|
||||
query = dbcon.NewQuery("INSERT INTO [forumsqldb].phpbb_profile_fields_data (user_id, pf_byondkey) VALUES ([uid], '[playerkey]')") // Remember which key is associated with the account
|
||||
if(!query.Execute())
|
||||
usr << "Unable to associate key with account. Authentication failed."
|
||||
dbcon.Disconnect()
|
||||
return
|
||||
|
||||
query = dbcon.NewQuery("UPDATE [forumsqldb].phpbb_user_group SET group_id = [forum_authenticated_group] WHERE user_id = [uid] AND group_id = [forum_activated_group]") // Replace 'Registered Users' group with 'Activated Users'
|
||||
if(!query.Execute())
|
||||
usr << "Unable to move account into authenticated group. This error shouldn't occur, contact an administrator for help. Authentication failed."
|
||||
dbcon.Disconnect()
|
||||
return
|
||||
else
|
||||
usr << "Authentication succeeded. You may now start posting on the <a href=http://tgstation13.servehttp.com/phpBB3/>tgstation forums</a>."
|
||||
dbcon.Disconnect()
|
||||
|
||||
|
||||
/client/verb/activate_forum_account(var/a as text)
|
||||
set name = "Activate Forum Account"
|
||||
set desc = "Associate a tgstation forum account with your BYOND key to enable posting."
|
||||
associate_key_with_forum(a, src.key)
|
||||
@@ -65,6 +65,7 @@
|
||||
config = new /datum/configuration()
|
||||
config.load("config/config.txt")
|
||||
config.loadsql("config/dbconfig.txt")
|
||||
config.loadforumsql("config/forumdbconfig.txt")
|
||||
// apply some settings from config..
|
||||
abandon_allowed = config.respawn
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# This configuration file is for the forum database, if you need to set up
|
||||
# population, death, etc. tracking see 'dbconfig.txt'
|
||||
# The login credentials for this will likely differ from those in dbconfig.txt!
|
||||
|
||||
# Server the MySQL database can be found at
|
||||
# Examples: localhost, 200.135.5.43, www.mysqldb.com, etc.
|
||||
ADDRESS localhost
|
||||
|
||||
# MySQL server port (default is 3306)
|
||||
PORT 3306
|
||||
|
||||
# Database the population, death, karma, etc. tables may be found in
|
||||
DATABASE tgstation13
|
||||
|
||||
# Username/Login used to access the database
|
||||
LOGIN mylogin
|
||||
|
||||
# Password used to access the database
|
||||
PASSWORD mypassword
|
||||
@@ -263,6 +263,7 @@
|
||||
#include "code\defines\procs\command_alert.dm"
|
||||
#include "code\defines\procs\command_name.dm"
|
||||
#include "code\defines\procs\dbcore.dm"
|
||||
#include "code\defines\procs\forum_activation.dm"
|
||||
#include "code\defines\procs\gamehelpers.dm"
|
||||
#include "code\defines\procs\helpers.dm"
|
||||
#include "code\defines\procs\logging.dm"
|
||||
|
||||
Reference in New Issue
Block a user