Skip to content

Commit

Permalink
Changelog Overhaul (#13051)
Browse files Browse the repository at this point in the history
* Changelog Overhaul

* SQL Update

* This is why I hate merge conflicts

* Comment Correction

* Farie Fixes + Tested with blank DB

* Colours + Titles

* Colour tweaks

* I fell victim to my own CI Chains!

* Cleans up the remains of the old changelogs

* Fixes formatting

* Kyet Changes

* Date
  • Loading branch information
AffectedArc07 authored May 18, 2020
1 parent b2b12c3 commit 7ea6f19
Show file tree
Hide file tree
Showing 62 changed files with 15,167 additions and 14,542 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
- find . -name "*.json" -not -path "./nano/node_modules/*" -print0 | xargs -0 python3 ./tools/travis/json_verifier.py
- tools/travis/build_nanoui.sh
- tools/travis/check_grep.sh
- tools/travis/check_changelogs.sh
- python3 tools/travis/check_line_endings.py
- ~/dreamchecker

Expand Down
16 changes: 15 additions & 1 deletion SQL/paradise_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -594,4 +594,18 @@ CREATE TABLE `connection_log` (
`ip` varchar(32) NOT NULL,
`computerid` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `changelog`
--
DROP TABLE IF EXISTS `changelog`;
CREATE TABLE `changelog` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`pr_number` INT(11) NOT NULL,
`date_merged` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`author` VARCHAR(32) NOT NULL,
`cl_type` ENUM('FIX','WIP','TWEAK','SOUNDADD','SOUNDDEL','CODEADD','CODEDEL','IMAGEADD','IMAGEDEL','SPELLCHECK','EXPERIMENT') NOT NULL,
`cl_entry` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
16 changes: 15 additions & 1 deletion SQL/paradise_schema_prefixed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,18 @@ CREATE TABLE `SS13_connection_log` (
`ip` varchar(32) NOT NULL,
`computerid` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `SS13_changelog`
--
DROP TABLE IF EXISTS `SS13_changelog`;
CREATE TABLE `SS13_changelog` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`pr_number` INT(11) NOT NULL,
`date_merged` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`author` VARCHAR(32) NOT NULL,
`cl_type` ENUM('FIX','WIP','TWEAK','SOUNDADD','SOUNDDEL','CODEADD','CODEDEL','IMAGEADD','IMAGEDEL','SPELLCHECK','EXPERIMENT') NOT NULL,
`cl_entry` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
2 changes: 1 addition & 1 deletion SQL/updates/10-11.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ ALTER TABLE feedback.population CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4
ALTER TABLE feedback.privacy CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE feedback.vpn_whitelist CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE feedback.watch CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE feedback.whitelist CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE feedback.whitelist CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
13 changes: 13 additions & 0 deletions SQL/updates/11-12.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Updating the SQL from version 11 to version 12. -AffectedArc07
#Creating a table for the new changelog system

DROP TABLE IF EXISTS `changelog`;
CREATE TABLE IF NOT EXISTS `changelog` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`pr_number` INT(11) NOT NULL,
`date_merged` TIMESTAMP NOT NULL DEFAULT current_timestamp(),
`author` VARCHAR(32) NOT NULL,
`cl_type` ENUM('FIX','WIP','TWEAK','SOUNDADD','SOUNDDEL','CODEADD','CODEDEL','IMAGEADD','IMAGEDEL','SPELLCHECK','EXPERIMENT') NOT NULL,
`cl_entry` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
2 changes: 1 addition & 1 deletion code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
#define INVESTIGATE_BOMB "bombs"

// The SQL version required by this version of the code
#define SQL_VERSION 11
#define SQL_VERSION 12

// Vending machine stuff
#define CAT_NORMAL 1
Expand Down
1 change: 0 additions & 1 deletion code/_globalvars/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ GLOBAL_VAR(host)
GLOBAL_VAR(join_motd)
GLOBAL_VAR(join_tos)
GLOBAL_VAR_INIT(game_version, "ParaCode")
GLOBAL_VAR_INIT(changelog_hash, md5('html/changelog.html')) //used to check if the CL changed
GLOBAL_VAR_INIT(game_year, (text2num(time2text(world.realtime, "YYYY")) + 544))

GLOBAL_VAR_INIT(aliens_allowed, 1)
Expand Down
230 changes: 230 additions & 0 deletions code/controllers/subsystem/changelog.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
/*
Subsystem core for ParadiseSS13 changelogs
Author: AffectedArc07
Basically this SS extracts changelogs from the past 30 days from the database, and cleanly formats them into HTML that the players can see
It only runs the extraction on initialize to ensure that the changelog doesnt change mid round, and to reduce the amount of DB calls that need to be done
The changelog entries are generated from the PHP scripts in tools/githubChangelogProcessor.php
This SS also handles the checking of player CL dates and informing them if it has changed
*/

SUBSYSTEM_DEF(changelog)
name = "Changelog"
flags = SS_NO_FIRE
var/current_cl_timestamp = "0" // Timestamp is seconds since UNIX epoch (1st January 1970). ITs also a string because BYOND doesnt like big numbers.
var/ss_ready = FALSE // Is the SS ready? We dont want to run procs if we have not generated yet
var/list/startup_clients_button = list() // Clients who connected before initialization who need their button color updating
var/list/startup_clients_open = list() // Clients who connected before initialization who need the CL opening
var/changelogHTML = "" // HTML that the changelog will use to display

/datum/controller/subsystem/changelog/Initialize()
// This entire subsystem relies on SQL being here.
if(!GLOB.dbcon.IsConnected())
return ..()

var/DBQuery/latest_cl_date = GLOB.dbcon.NewQuery("SELECT UNIX_TIMESTAMP(date_merged) AS ut FROM [format_table_name("changelog")] ORDER BY date_merged DESC LIMIT 1")
if(!latest_cl_date.Execute())
var/err = latest_cl_date.ErrorMsg()
log_game("SQL ERROR during SSchangelog initialization L24. Error: \[[err]\]\n")
message_admins("SQL ERROR during SSchangelog initialization L24. Error: \[[err]\]\n")
// Abort if we cant do this
return ..()

while(latest_cl_date.NextRow())
current_cl_timestamp = latest_cl_date.item[1]

if(!GenerateChangelogHTML()) // if this failed to generate
to_chat(world, "<span class='alert'>WARNING: Changelog failed to generate. Please inform a coder/server dev</span>")
return ..()

ss_ready = TRUE
// Now we can alert anyone who wanted to check the changelog
for(var/x in startup_clients_button)
var/client/C = x
UpdatePlayerChangelogButton(C)

// Now we can alert anyone who wanted to check the changelog
for(var/client/C in startup_clients_open)
OpenChangelog(C)

return ..()


/datum/controller/subsystem/changelog/proc/UpdatePlayerChangelogDate(client/C)
if(!ss_ready)
return // Only return here, we dont have to worry about a queue list because this will be called from ShowChangelog()
// Technically this is only for the date but we can also do the UI button at the same time
var/datum/preferences/P = GLOB.preferences_datums[C.ckey]
if(P.toggles & UI_DARKMODE)
winset(C, "rpane.changelog", "background-color=#40628a;font-color=#ffffff;font-style=none")
else
winset(C, "rpane.changelog", "background-color=none;font-style=none")
C.prefs.lastchangelog = current_cl_timestamp
var/DBQuery/updatePlayerCLTime = GLOB.dbcon.NewQuery("UPDATE [format_table_name("player")] SET lastchangelog='[sanitizeSQL(current_cl_timestamp)]' WHERE ckey='[C.ckey]'")
if(!updatePlayerCLTime.Execute())
var/err = updatePlayerCLTime.ErrorMsg()
log_game("SQL ERROR during lastchangelog updating. Error: \[[err]\]\n")
message_admins("SQL ERROR during lastchangelog updating. Error: \[[err]\]\n")
to_chat(C, "Couldn't update your last seen changelog, please try again later.")
return FALSE
return TRUE

/datum/controller/subsystem/changelog/proc/UpdatePlayerChangelogButton(client/C)
// If SQL aint even enabled, just set the button to default style
if(!GLOB.dbcon.IsConnected())
if(C.prefs.toggles & UI_DARKMODE)
winset(C, "rpane.changelog", "background-color=#40628a;text-color=#FFFFFF")
else
winset(C, "rpane.changelog", "background-color=none;text-color=#000000")
return

// If SQL is enabled but we aint ready, queue them up, and use the default style
if(!ss_ready)
startup_clients_button |= C
if(C.prefs.toggles & UI_DARKMODE)
winset(C, "rpane.changelog", "background-color=#40628a;text-color=#FFFFFF")
else
winset(C, "rpane.changelog", "background-color=none;text-color=#000000")
return

// If we are ready, process the button style
if(C.prefs.lastchangelog != current_cl_timestamp)
winset(C, "rpane.changelog", "background-color=#bb7700;text-color=#FFFFFF;font-style=bold")
to_chat(C, "<span class='info'>Changelog has changed since your last visit.</span>")
else
if(C.prefs.toggles & UI_DARKMODE)
winset(C, "rpane.changelog", "background-color=#40628a;text-color=#FFFFFF")
else
winset(C, "rpane.changelog", "background-color=none;text-color=#000000")


/datum/controller/subsystem/changelog/proc/OpenChangelog(client/C)
// If SQL isnt enabled, dont even queue them, just tell them it wont work
if(!GLOB.dbcon.IsConnected())
to_chat(C, "<span class='notice'>This server is not running with an SQL backend. Changelog is unavailable.</span>")
return

// If SQL is enabled but we aint ready, queue them up
if(!ss_ready)
startup_clients_open |= C
to_chat(C, "<span class='notice'>The changelog system is still initializing. The changelog will open for you once it has initialized.</span>")
return

UpdatePlayerChangelogDate(C)
UpdatePlayerChangelogButton(C)

var/datum/browser/cl_popup = new(C.mob, "changelog", "Changelog", 700, 800)
cl_popup.set_content(changelogHTML)
cl_popup.open()

/client/verb/changes()
set name = "Changelog"
set desc = "View the changelog."
set category = "OOC"
// Just invoke the actual CL thing
SSchangelog.OpenChangelog(src)

// Helper to turn CL types into a fontawesome icon instead of an image
// The colors are #28a745 for green, #fd7e14 for orange, and #dc3545 for red.
// These colours are from bootstrap and look good with black and white
/datum/controller/subsystem/changelog/proc/Text2Icon(text)
switch(text)
if("FIX")
return "<i title='Fix' class='fas fa-tools'></i></span>" // Fixes are white because while they are good, they have no negative coutnerpart
if("WIP")
return "<span style='color: #fd7e14;'><i title='Work In Progress' class='fas fa-hard-hat'></i></span>" // WIP stuff is orange because new code is good but its not done yet
if("TWEAK")
return "<i title='Tweak' class='fas fa-sliders-h'></i>" // Tweaks are white because they could be good or bad, and theres no specific add or remove
if("SOUNDADD")
return "<span style='color: #28a745;'><i title='Sound Added' class='fas fa-volume-up'></i></span>" // Sound additions are green because its something new
if("SOUNDDEL")
return "<span style='color: #dc3545;'><i title='Sound Removed' class='fas fa-volume-mute'></i></span>" // Sound removals are red because something has been removed
if("CODEADD")
return "<span style='color: #28a745;'><i title='Code Addition' class='fas fa-plus'></i></span>" // Code additions are green because its something new
if("CODEDEL")
return "<span style='color: #dc3545;'><i title='Code Removal' class='fas fa-minus'></i></span>" // Code removals are red becuase someting has been removed
if("IMAGEADD")
return "<span style='color: #28a745;'><i title='Image/Sprite Addition' class='fas fa-folder-plus'></i></span>" // Image additions are green because something has been added
if("IMAGEDEL")
return "<span style='color: #dc3545;'><i title='Image/Sprite Removal' class='fas fa-folder-minus'></i></span>" // Image removals are red because something has been removed
if("SPELLCHECK")
return "<i title='Spelling/Grammar Fix' class='fas fa-font'></i>" // Spellcheck is white because theres no dedicated negative to it, so theres no red for it to collate with
if("EXPERIMENT")
return "<span style='color: #fd7e14;'><i title='Experimental' class='fas fa-exclamation-triangle'></i></span>" // Experimental stuff is orange because while its a new feature, its unstable
else // Just incase the DB somehow breaks
return "<span style='color: #28a745;'><i title='Code Addition' class='fas fa-plus'></i></span>" // Same here

// This proc is the star of the show
/datum/controller/subsystem/changelog/proc/GenerateChangelogHTML()
// Modify the code below to modify the header of the changelog
var/changelog_header = {"
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" rel="stylesheet">
<title>ParadiseSS13 Changelog</title>
<base target='_blank' />
<link rel='styelsheet' href='fontawesome.min.css'>
<center>
<p style='font-size: 20px'><b>Paradise Station Changelog</b></p>
<p><a href='[config.forum_link_url]'>Forum</a> - <a href='[config.wikiurl]'>Wiki</a> - <a href='[config.githuburl]'>GitHub</a></p>
</center>
"}

var/list/prs_to_process = list()
// Grab all from last 30 days
var/DBQuery/pr_list_query = GLOB.dbcon.NewQuery("SELECT DISTINCT pr_number FROM changelog WHERE date_merged BETWEEN NOW() - INTERVAL 30 DAY AND NOW() ORDER BY date_merged DESC")
if(!pr_list_query.Execute())
var/err = pr_list_query.ErrorMsg()
log_game("SQL ERROR during CL generation L143. Error: \[[err]\]\n")
message_admins("SQL ERROR during CL generation L143. Error: \[[err]\]\n")
return FALSE

while(pr_list_query.NextRow())
prs_to_process += text2num(pr_list_query.item[1])

// Load in the header
changelogHTML += changelog_header

// Make blocks for all the PRs
for(var/pr_number in prs_to_process)
// Initial declarations
var/pr_block = "" // HTML for the changelog section
var/author = "" // Author of the PR
var/merge_date = "" // Timestamp of when the PR was merged

// Now we gather the data from the DB
// Also we probably dont need to sanitize the PR number but you never know
var/DBQuery/pr_meta = GLOB.dbcon.NewQuery("SELECT author,DATE(date_merged) AS date FROM changelog WHERE pr_number = [sanitizeSQL(pr_number)] LIMIT 1")
if(!pr_meta.Execute())
var/err = pr_meta.ErrorMsg()
log_game("SQL ERROR during CL generation L190. Error: \[[err]\]\n")
message_admins("SQL ERROR during CL generation L190. Error: \[[err]\]\n")
return FALSE

while(pr_meta.NextRow())
author = pr_meta.item[1]
merge_date = pr_meta.item[2]

// Now for each actual entry
var/DBQuery/db_entries = GLOB.dbcon.NewQuery("SELECT cl_type, cl_entry FROM changelog WHERE pr_number = [sanitizeSQL(pr_number)]")
if(!db_entries.Execute())
var/err = db_entries.ErrorMsg()
log_game("SQL ERROR during CL generation L204. Error: \[[err]\]\n")
message_admins("SQL ERROR during CL generation L204. Error: \[[err]\]\n")
return FALSE


// Now we make a changelog block
pr_block += "<div class='statusDisplay'>"
// If the github URL in the config has a trailing slash, it doesnt matter here, thankfully github accepts having a double slash: https://github.com/org/repo//pull/1
pr_block += "<p class='white'><a href='[config.githuburl]/pull/[pr_number]'>#[pr_number]</a> by <b>[author]</b> (Merged on [merge_date])</span>"

while(db_entries.NextRow())
pr_block += "<p>[Text2Icon(db_entries.item[1])] [db_entries.item[2]]</p>"

pr_block += "</div><br>"

changelogHTML += pr_block

// Make sure we return TRUE so we know it worked
return TRUE
30 changes: 6 additions & 24 deletions code/modules/client/client procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,11 @@
send_resources()

if(prefs.toggles & UI_DARKMODE) // activates dark mode if its flagged. -AA07
if(establish_db_connection())
activate_darkmode()
activate_darkmode()
else
// activate_darkmode() calls the CL update button proc, so we dont want it double called
SSchangelog.UpdatePlayerChangelogButton(src)

if(prefs.lastchangelog != GLOB.changelog_hash) //bolds the changelog button on the interface so we know there are updates. -CP
if(establish_db_connection())
to_chat(src, "<span class='info'>Changelog has changed since your last visit.</span>")
update_changelog_button()

if(prefs.toggles & DISABLE_KARMA) // activates if karma is disabled
if(establish_db_connection())
Expand Down Expand Up @@ -825,7 +823,7 @@
// IF YOU CHANGE ANYTHING IN ACTIVATE, MAKE SURE IT HAS A DEACTIVATE METHOD, -AA07
/client/proc/activate_darkmode()
///// BUTTONS /////
update_changelog_button()
SSchangelog.UpdatePlayerChangelogButton(src)
/* Rpane */
winset(src, "rpane.textb", "background-color=#40628a;text-color=#FFFFFF")
winset(src, "rpane.infob", "background-color=#40628a;text-color=#FFFFFF")
Expand Down Expand Up @@ -857,7 +855,7 @@

/client/proc/deactivate_darkmode()
///// BUTTONS /////
update_changelog_button()
SSchangelog.UpdatePlayerChangelogButton(src)
/* Rpane */
winset(src, "rpane.textb", "background-color=none;text-color=#000000")
winset(src, "rpane.infob", "background-color=none;text-color=#000000")
Expand Down Expand Up @@ -887,22 +885,6 @@
///// NOTIFY USER /////
to_chat(src, "<span class='notice'>Darkmode Disabled</span>") // what a sick fuck

// Better changelog button handling
/client/proc/update_changelog_button()
if(establish_db_connection())
if(prefs.lastchangelog != GLOB.changelog_hash)
winset(src, "rpane.changelog", "background-color=#bb7700;text-color=#FFFFFF;font-style=bold")
else
if(prefs.toggles & UI_DARKMODE)
winset(src, "rpane.changelog", "background-color=#40628a;text-color=#FFFFFF")
else
winset(src, "rpane.changelog", "background-color=none;text-color=#000000")
else
if(prefs.toggles & UI_DARKMODE)
winset(src, "rpane.changelog", "background-color=#40628a;text-color=#FFFFFF")
else
winset(src, "rpane.changelog", "background-color=none;text-color=#000000")

/client/proc/generate_clickcatcher()
if(!void)
void = new()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/client/preference/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
var/last_id

//game-preferences
var/lastchangelog = "" //Saved changlog filesize to detect if there was a change
var/lastchangelog = "1" //Saved changlog timestamp (unix epoch) to detect if there was a change. Dont set this to 0 unless you want the last changelog date to be 4x longer than the expected lifespan of the universe.
var/exp
var/ooccolor = "#b82e00"
var/list/be_special = list() //Special role selection
Expand Down
Loading

0 comments on commit 7ea6f19

Please sign in to comment.