diff --git a/backend/pages/admin/administrator.js b/backend/pages/admin/administrator.js index 3653a7ff..cb4ca8ff 100644 --- a/backend/pages/admin/administrator.js +++ b/backend/pages/admin/administrator.js @@ -87,7 +87,8 @@ module.exports.GET = async function(req, write, server, ctx, params) { client_version: getClientVersion(), csrftoken, global_chat_enabled: getServerSetting("chatGlobalEnabled") == "1", - global_chat_no_anon: getServerSetting("chatGlobalNoAnon") == "1" + global_chat_no_anon: getServerSetting("chatGlobalNoAnon") == "1", + chat_age_restriction: getServerSetting("chatAgeRestriction") }; write(render("administrator.html", data)); @@ -143,6 +144,11 @@ module.exports.POST = async function(req, write, server, ctx) { } else { updateServerSetting("chatGlobalNoAnon", "0"); } + if("set_chat_age_restriction" in post_data) { + var ageRestrictionHours = parseInt(post_data.set_chat_age_restriction); + if(isNaN(ageRestrictionHours) || ageRestrictionHours < 0) ageRestrictionHours = 0; + updateServerSetting("chatAgeRestriction", ageRestrictionHours.toString()); + } } if("announcement" in post_data) { var new_announcement = post_data.announcement; diff --git a/backend/websockets/chat.js b/backend/websockets/chat.js index a2cd460b..f4719163 100644 --- a/backend/websockets/chat.js +++ b/backend/websockets/chat.js @@ -170,6 +170,19 @@ module.exports = async function(ws, data, send, broadcast, server, ctx) { return; } + if(user.authenticated && user.date_joined) { + var ageRestrictionHours = parseInt(getServerSetting("chatAgeRestriction")); + if(ageRestrictionHours > 0) { + var accountAge = Date.now() - user.date_joined; + var minimumAge = ageRestrictionHours * 60 * 60 * 1000; + if(accountAge < minimumAge) { + var timeRemaining = calculateTimeDiff(minimumAge - accountAge); + serverChatResponse("Your account is too new. You must wait " + timeRemaining + " before chatting.", location); + return; + } + } + } + var isTestMessage = false; var isMuted = ( diff --git a/frontend/templates/administrator.html b/frontend/templates/administrator.html index 6ea97c19..ccf79521 100644 --- a/frontend/templates/administrator.html +++ b/frontend/templates/administrator.html @@ -306,6 +306,10 @@