From 901dd00ce3d3360ddc56eb86b2c697491e6ee67a Mon Sep 17 00:00:00 2001 From: Aaron Dean <8dino2@gmail.com> Date: Mon, 4 Dec 2023 15:36:27 -0500 Subject: [PATCH 1/4] Added news --- action/news.txt | 4 ++++ plugins/news.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 action/news.txt create mode 100644 plugins/news.lua diff --git a/action/news.txt b/action/news.txt new file mode 100644 index 0000000..3768ab3 --- /dev/null +++ b/action/news.txt @@ -0,0 +1,4 @@ +"This is the first announcement" +"This is the second announcement" +"This is the third announcement" +"This is the fourth announcement" diff --git a/plugins/news.lua b/plugins/news.lua new file mode 100644 index 0000000..e759fda --- /dev/null +++ b/plugins/news.lua @@ -0,0 +1,53 @@ +local version = "1.0" +gi.AddCommandString("set q2a_news "..version.."\n") + +local broadcasts = {} + +function news_os_exec(script) + os.execute(script) + wait(1000) -- wait 1s to make sure download is complete and went smooth + for line in io.lines('action/broadcasts.txt') do + table.insert(broadcasts, line) + end + local last_update = os.date() + gi.AddCommandString('sets news_update '..last_update..'\n') -- write update time to cvar +end + +function q2a_load(config) + gi.dprintf("news.lua q2a_load(): "..version.." for Action Quake 2 loaded.\n") + + root_dir = config.root_dir + url = config.url + if root_dir == nil then + gi.dprintf("news.lua q2a_load(): 'root_dir' not defined in the config.lua file... aborting\n") + return 0 + end + if url == nil then + gi.dprintf("news.lua q2a_load(): 'url' not defined in the config.lua file... aborting\n") + return 0 + end + + gi.dprintf("news.lua q2a_load(): Checking/Downloading news... ") + news_update = root_dir..'plugins/news_update.sh "'..url..'" ' + news_os_exec(cvarbans_update) -- check for updated cvarbanlist on load +end + + +local current_index = 1 +local last_check = os.time() + +function RunFrame() + local now = os.time() + + if now - last_check >= 600 then -- 600 seconds = 10 minutes + local bcast = broadcasts[current_index] + gi.bprintf(PRINT_CHAT, '*** '..bcast..'\n') + + current_index = current_index + 1 + if current_index > #broadcasts then + current_index = 1 + end + + last_check = now + end +end From 1f2efb5aa3fa49a0e0f399694c5690c9fa5a693a Mon Sep 17 00:00:00 2001 From: Aaron Dean <8dino2@gmail.com> Date: Mon, 4 Dec 2023 15:41:25 -0500 Subject: [PATCH 2/4] Added news_update.sh --- plugins/news.lua | 3 +++ plugins/news_update.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100755 plugins/news_update.sh diff --git a/plugins/news.lua b/plugins/news.lua index e759fda..21242b0 100644 --- a/plugins/news.lua +++ b/plugins/news.lua @@ -3,6 +3,9 @@ gi.AddCommandString("set q2a_news "..version.."\n") local broadcasts = {} +function wait (millisecond) +end + function news_os_exec(script) os.execute(script) wait(1000) -- wait 1s to make sure download is complete and went smooth diff --git a/plugins/news_update.sh b/plugins/news_update.sh new file mode 100755 index 0000000..b7af7d4 --- /dev/null +++ b/plugins/news_update.sh @@ -0,0 +1,27 @@ +#!/usr/bin/bash +# a script that checks and downloads of the news master file + +# download URL +url="$1" +gamedir="$2" +# bypass modsecurity +usaragent="-d --user-agent=news-update-script" +# parse the filename from the download path +filename=$(echo $url | sed -n 's/^\(.*\/\)*\(.*\)/\2/p') + +# script to download latest h_news.cfg from github +cd "${0%/*}" # cd to current dir +cd ../$gamedir/ # cd back and to game dir + +#### script +# download the file if updated since last time, and output wheter it updated or not to console + +if [[ "$url" == *"githubusercontent"* ]]; then + # not using -N switch for wget since github does not support "last update" parameter, the file will be downloaded on every check, wich is not optimal + wget -O $filename $url 2>&1 | tee | grep -E 'Omitting download|"h_news.txt" saved|ERROR 404: Not Found' +else + # using -N switch for wget since the file os not hosted on github, best solution, since file will only be downloaded if changed + wget $usaragent -N $url 2>&1 | tee | grep -E 'Omitting download|"h_news.txt" saved|ERROR 404: Not Found' +fi + +exit \ No newline at end of file From 35fa852a8c35a38b0ebd4ac76a7d189ffc221b05 Mon Sep 17 00:00:00 2001 From: Aaron Dean <8dino2@gmail.com> Date: Mon, 4 Dec 2023 16:03:46 -0500 Subject: [PATCH 3/4] Fixed a few things --- action/news.txt | 8 ++++---- plugins/cvarbans.lua | 2 +- plugins/news.lua | 18 +++++++++++------- plugins/news_update.sh | 6 +++--- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/action/news.txt b/action/news.txt index 3768ab3..cf0947b 100644 --- a/action/news.txt +++ b/action/news.txt @@ -1,4 +1,4 @@ -"This is the first announcement" -"This is the second announcement" -"This is the third announcement" -"This is the fourth announcement" +"If you aren't already in Discord, join us @ https://discord.aq2world.com/ !" +"Don't forget to visit our forums @ https://forums.aq2world.com/ !" +"Congrats to matic for his Map Jam-winning map, torg!" +"Watch for new events in Discord, such as our regular CTF matches!" diff --git a/plugins/cvarbans.lua b/plugins/cvarbans.lua index a4f29f9..371f065 100644 --- a/plugins/cvarbans.lua +++ b/plugins/cvarbans.lua @@ -91,7 +91,7 @@ function q2a_load(config) return 0 end - gi.dprintf("cvarbans.lua q2a_load(): Checking/Downloading new cvarbans... ") + gi.dprintf("cvarbans.lua q2a_load(): Checking/Downloading new cvarbans...\n") cvarbans_update = root_dir..'plugins/cvarbans_update.sh "'..url..'" "'..game..'"' cvarbans_os_exec(cvarbans_update) -- check for updated cvarbanlist on load end \ No newline at end of file diff --git a/plugins/news.lua b/plugins/news.lua index 21242b0..b6910b6 100644 --- a/plugins/news.lua +++ b/plugins/news.lua @@ -1,19 +1,23 @@ local version = "1.0" gi.AddCommandString("set q2a_news "..version.."\n") - +local game = gi.cvar("game", "").string local broadcasts = {} function wait (millisecond) end +function load_news() + for line in io.lines('action/news.txt') do + table.insert(broadcasts, line) + end +end + function news_os_exec(script) os.execute(script) wait(1000) -- wait 1s to make sure download is complete and went smooth - for line in io.lines('action/broadcasts.txt') do - table.insert(broadcasts, line) - end local last_update = os.date() gi.AddCommandString('sets news_update '..last_update..'\n') -- write update time to cvar + load_news() end function q2a_load(config) @@ -30,9 +34,9 @@ function q2a_load(config) return 0 end - gi.dprintf("news.lua q2a_load(): Checking/Downloading news... ") - news_update = root_dir..'plugins/news_update.sh "'..url..'" ' - news_os_exec(cvarbans_update) -- check for updated cvarbanlist on load + gi.dprintf("news.lua q2a_load(): Checking/Downloading news...\n") + news_update = root_dir..'plugins/news_update.sh "'..url..'" "'..game..'"' + news_os_exec(news_update) -- check for updated news on load end diff --git a/plugins/news_update.sh b/plugins/news_update.sh index b7af7d4..82f52d2 100755 --- a/plugins/news_update.sh +++ b/plugins/news_update.sh @@ -9,7 +9,7 @@ usaragent="-d --user-agent=news-update-script" # parse the filename from the download path filename=$(echo $url | sed -n 's/^\(.*\/\)*\(.*\)/\2/p') -# script to download latest h_news.cfg from github +# script to download latest news.txt from github cd "${0%/*}" # cd to current dir cd ../$gamedir/ # cd back and to game dir @@ -18,10 +18,10 @@ cd ../$gamedir/ # cd back and to game dir if [[ "$url" == *"githubusercontent"* ]]; then # not using -N switch for wget since github does not support "last update" parameter, the file will be downloaded on every check, wich is not optimal - wget -O $filename $url 2>&1 | tee | grep -E 'Omitting download|"h_news.txt" saved|ERROR 404: Not Found' + wget -O $filename $url 2>&1 | tee | grep -E 'Omitting download|"news.txt" saved|ERROR 404: Not Found' else # using -N switch for wget since the file os not hosted on github, best solution, since file will only be downloaded if changed - wget $usaragent -N $url 2>&1 | tee | grep -E 'Omitting download|"h_news.txt" saved|ERROR 404: Not Found' + wget $usaragent -N $url 2>&1 | tee | grep -E 'Omitting download|"news.txt" saved|ERROR 404: Not Found' fi exit \ No newline at end of file From f89f1eefc35767d6df5e900135aac4ae12a5f7b0 Mon Sep 17 00:00:00 2001 From: Aaron Dean <8dino2@gmail.com> Date: Mon, 4 Dec 2023 16:16:58 -0500 Subject: [PATCH 4/4] Some formatting on news.txt --- action/news.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/action/news.txt b/action/news.txt index cf0947b..aa36c4e 100644 --- a/action/news.txt +++ b/action/news.txt @@ -1,4 +1,4 @@ -"If you aren't already in Discord, join us @ https://discord.aq2world.com/ !" -"Don't forget to visit our forums @ https://forums.aq2world.com/ !" -"Congrats to matic for his Map Jam-winning map, torg!" -"Watch for new events in Discord, such as our regular CTF matches!" +If you aren't already in Discord, join us @ https://discord.aq2world.com/ ! <<< +Don't forget to visit our forums @ https://forums.aq2world.com/ ! <<< +Congrats to matic for his Map Jam-winning map, torg! <<< +Watch for new events in Discord, such as our regular CTF matches! <<<