Skip to content

Commit

Permalink
online milestones
Browse files Browse the repository at this point in the history
  • Loading branch information
volas committed Jan 7, 2025
1 parent fbd8877 commit ae79190
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/__DEFINES/bridge.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define BRIDGE_ROUNDSTAT "roundstat" //shuttle/server starting/round starting
#define BRIDGE_SERVICE "service" //private debug msgs
#define BRIDGE_ANNOUNCE "announce" //general announces for players
#define BRIDGE_SAMOSBOR "samosbor" //online milestones notifications

//admin
#define BRIDGE_ADMINCOM "admincom" //admin faxes and command console
Expand Down
2 changes: 2 additions & 0 deletions code/controllers/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ var/global/bridge_secret = null
var/hard_deletes_overrun_threshold = 0.5
var/hard_deletes_overrun_limit = 0

var/samosbor = TRUE

/datum/configuration/New()
for (var/type in subtypesof(/datum/game_mode))
var/datum/game_mode/M = type
Expand Down
61 changes: 61 additions & 0 deletions code/controllers/subsystem/samosbor.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#define SAMOSBOR_CACHE_FOLDER "cache/samosbor"
#define SAMOSBOR_CACHE_PATH(suffix) "[SAMOSBOR_CACHE_FOLDER]/milestones_[suffix].txt"

SUBSYSTEM_DEF(samosbor)
name = "Samosbor"
init_order = SS_INIT_DEFAULT
flags = SS_NO_FIRE

var/current_milestone = 10 // also as first milestone
var/milestone_step = 10

var/day
var/notfication_timer

/datum/controller/subsystem/samosbor/Initialize()
if(!config.samosbor)
return ..()

day = time2text(world.realtime, "YYYY_MM_DD")

var/cache_path = SAMOSBOR_CACHE_PATH(day)
if(fexists(cache_path))
var/cached_milestone = text2num(trim(file2text(cache_path)))

if(isnum(cached_milestone) && cached_milestone >= (current_milestone + milestone_step))
current_milestone = cached_milestone
else
fdel(cache_path)

RegisterSignal(SSdcs, COMSIG_GLOB_CLIENT_CONNECT, PROC_REF(client_connected))

return ..()

/datum/controller/subsystem/samosbor/proc/client_connected(datum/source, client/connected)
SIGNAL_HANDLER

var/players_online = length(global.clients)
if(players_online >= current_milestone)
INVOKE_ASYNC(src, PROC_REF(milestone_reached), players_online)

/datum/controller/subsystem/samosbor/proc/milestone_reached(players_online)
world.log << "players_online [players_online]"

current_milestone = max(current_milestone, players_online - (players_online % milestone_step))

var/cache_path = SAMOSBOR_CACHE_PATH(day)
fdel(cache_path)
text2file(num2text(current_milestone), cache_path) // note: delete previous days files, todo or do it with host tools

// 30 seconds timer so we don't spam it at the start of the round
notfication_timer = addtimer(CALLBACK(src, PROC_REF(milestone_notification), current_milestone), 30 SECONDS, TIMER_UNIQUE|TIMER_OVERRIDE)

/datum/controller/subsystem/samosbor/proc/milestone_notification(milestone)
world.send2bridge(
type = list(BRIDGE_ANNOUNCE, BRIDGE_SAMOSBOR),
attachment_title = "New today's milestone reached: more than **[milestone]** players!",
attachment_msg = "Join now: <[BYOND_JOIN_LINK]>"
)

#undef SAMOSBOR_CACHE_FOLDER
#undef SAMOSBOR_CACHE_PATH
1 change: 1 addition & 0 deletions taucetistation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
#include "code\controllers\subsystem\round_aspects.dm"
#include "code\controllers\subsystem\round_rating.dm"
#include "code\controllers\subsystem\runechat.dm"
#include "code\controllers\subsystem\samosbor.dm"
#include "code\controllers\subsystem\shuttles.dm"
#include "code\controllers\subsystem\smartlight.dm"
#include "code\controllers\subsystem\spacedrift.dm"
Expand Down

0 comments on commit ae79190

Please sign in to comment.