Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online milestones #13706

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
60 changes: 60 additions & 0 deletions code/controllers/subsystem/samosbor.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#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/next_milestone = 10 // players online when we send the next notification
var/milestone_step = 10

var/day
var/notfication_timer

/datum/controller/subsystem/samosbor/Initialize()
if(!config.chat_bridge)
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 >= (next_milestone + milestone_step))
next_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 >= next_milestone)
INVOKE_ASYNC(src, PROC_REF(milestone_reached), players_online)

/datum/controller/subsystem/samosbor/proc/milestone_reached(players_online)
var/current_milestone = max(next_milestone, players_online - (players_online % milestone_step))
next_milestone = current_milestone + milestone_step

var/cache_path = SAMOSBOR_CACHE_PATH(day)
fdel(cache_path)
text2file(num2text(next_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 = "Новый результат на сегодня: более [milestone] игроков онлайн!",
attachment_msg = BRIDGE_JOIN_LINKS
)

#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
Loading