diff --git a/backend/pages/accounts/configure.js b/backend/pages/accounts/configure.js index 17cc1220..60f44b29 100644 --- a/backend/pages/accounts/configure.js +++ b/backend/pages/accounts/configure.js @@ -276,6 +276,7 @@ module.exports.GET = async function(req, write, server, ctx, params) { square_chars, no_log_edits: world.opts.noLogEdits, no_chat_global: world.opts.noChatGlobal, + no_anon_chat: world.opts.noAnonChat, no_copy: world.opts.noCopy, half_chars, mixed_chars, @@ -535,6 +536,10 @@ module.exports.POST = async function(req, write, server, ctx) { if(modifyWorldProp(world, "feature/memberTilesAddRemove", Boolean(membertiles_addremove))) { featureUpdates.push({type: "memberTilesAddRemove", value: Boolean(membertiles_addremove)}); } + var no_anon_chat = post_data.no_anon_chat == "1"; + if(modifyWorldProp(world, "opts/noAnonChat", no_anon_chat)) { + featureUpdates.push({type: "noAnonChat", value: no_anon_chat}); + } if(featureUpdates.length) { ws_broadcast({ @@ -974,4 +979,4 @@ module.exports.POST = async function(req, write, server, ctx) { redirect: "/accounts/configure/" + new_world_name + "/" }); } -} \ No newline at end of file +} diff --git a/backend/pages/admin/administrator.js b/backend/pages/admin/administrator.js index 1e54a51c..3653a7ff 100644 --- a/backend/pages/admin/administrator.js +++ b/backend/pages/admin/administrator.js @@ -86,7 +86,8 @@ module.exports.GET = async function(req, write, server, ctx, params) { custom_ranks, client_version: getClientVersion(), csrftoken, - global_chat_enabled: getServerSetting("chatGlobalEnabled") == "1" + global_chat_enabled: getServerSetting("chatGlobalEnabled") == "1", + global_chat_no_anon: getServerSetting("chatGlobalNoAnon") == "1" }; write(render("administrator.html", data)); @@ -134,6 +135,14 @@ module.exports.POST = async function(req, write, server, ctx) { } else { updateServerSetting("chatGlobalEnabled", "0"); } + if("set_chat_global_no_anon" in post_data) { + var isNoAnon = post_data.set_chat_global_no_anon; + if(isNoAnon == "on") { + updateServerSetting("chatGlobalNoAnon", "1"); + } + } else { + updateServerSetting("chatGlobalNoAnon", "0"); + } } if("announcement" in post_data) { var new_announcement = post_data.announcement; diff --git a/backend/pages/world_props.js b/backend/pages/world_props.js index a3fcc152..d5be7303 100644 --- a/backend/pages/world_props.js +++ b/backend/pages/world_props.js @@ -63,6 +63,7 @@ module.exports.GET = async function(req, write, server, ctx) { writeInt: world.opts.writeInt, desc: world.opts.desc, noChatGlobal: world.opts.noChatGlobal, + noAnonChat: world.opts.noAnonChat, noCopy: world.opts.noCopy, defaultScriptPath: world.opts.defaultScriptPath, colorPalette: world.opts.colorPaletteEnabled ? world.opts.colorPalette : null, diff --git a/backend/pages/yourworld.js b/backend/pages/yourworld.js index cefacede..09961e3a 100644 --- a/backend/pages/yourworld.js +++ b/backend/pages/yourworld.js @@ -125,6 +125,7 @@ module.exports.GET = async function(req, write, server, ctx, params) { write_interval: write_int, no_copy: world.opts.noCopy, no_chat_global: world.opts.noChatGlobal || !isGlobalEnabled, + no_anon_chat: world.opts.noAnonChat, color_palette: world.opts.colorPaletteEnabled ? world.opts.colorPalette : null, bg_color_palette: world.opts.bgColorPaletteEnabled ? world.opts.bgColorPalette : null } diff --git a/backend/subsystems/world_mgr.js b/backend/subsystems/world_mgr.js index be36f1eb..47bfe011 100644 --- a/backend/subsystems/world_mgr.js +++ b/backend/subsystems/world_mgr.js @@ -73,6 +73,7 @@ var world_default_props = { square_chars: false, no_log_edits: false, no_chat_global: false, + no_anon_chat: false, no_copy: false, half_chars: false, char_rate: "", @@ -216,6 +217,7 @@ function makeWorldObject() { squareChars: false, noLogEdits: false, noChatGlobal: false, + noAnonChat: false, noCopy: false, halfChars: false, charRate: "", @@ -341,6 +343,7 @@ function loadWorldIntoObject(world, wobj) { wobj.opts.squareChars = getAndProcWorldProp(wprops, "square_chars"); wobj.opts.noLogEdits = getAndProcWorldProp(wprops, "no_log_edits"); wobj.opts.noChatGlobal = getAndProcWorldProp(wprops, "no_chat_global"); + wobj.opts.noAnonChat = getAndProcWorldProp(wprops, "no_anon_chat"); wobj.opts.noCopy = getAndProcWorldProp(wprops, "no_copy"); wobj.opts.halfChars = getAndProcWorldProp(wprops, "half_chars"); wobj.opts.charRate = getAndProcWorldProp(wprops, "char_rate"); @@ -502,6 +505,7 @@ async function commitWorld(world) { "opts/squareChars", "opts/noLogEdits", "opts/noChatGlobal", + "opts/noAnonChat", "opts/noCopy", "opts/halfChars", "opts/charRate", @@ -539,6 +543,7 @@ async function commitWorld(world) { square_chars: world.opts.squareChars, no_log_edits: world.opts.noLogEdits, no_chat_global: world.opts.noChatGlobal, + no_anon_chat: world.opts.noAnonChat, no_copy: world.opts.noCopy, half_chars: world.opts.halfChars, char_rate: world.opts.charRate, diff --git a/backend/websockets/chat.js b/backend/websockets/chat.js index 7b88b242..57bf442e 100644 --- a/backend/websockets/chat.js +++ b/backend/websockets/chat.js @@ -139,6 +139,32 @@ module.exports = async function(ws, data, send, broadcast, server, ctx) { return; } + var username_to_display = user.username; + if(accountSystem == "uvias") { + username_to_display = user.display_username; + } + var has_chat_username = typeof username_to_display == "string" && !!username_to_display.trim(); + + if(location == "global") { + var chatGlobalNoAnon = getServerSetting("chatGlobalNoAnon") == "1"; + if(chatGlobalNoAnon && !user.authenticated) { + serverChatResponse("Sign in to send messages in global chat.", location); + return; + } + if(user.authenticated && !has_chat_username) { + serverChatResponse("Your account needs a username to send messages in global chat.", location); + return; + // I'm not sure if this case can actually happen, but just in case - Alan + } + } //elseif? + + if(location == "page") { + if(world.opts.noAnonChat && !user.authenticated) { + serverChatResponse("Sign in to send messages in this world.", location); + return; + } + } + var isMuted = false; var isTestMessage = false; var muteInfo = null; @@ -198,11 +224,6 @@ module.exports = async function(ws, data, send, broadcast, server, ctx) { data.customMeta = sanitizeCustomMeta(data.customMeta); } - var username_to_display = user.username; - if(accountSystem == "uvias") { - username_to_display = user.display_username; - } - var chatBlockLimit = 1280; // [rank, name, args, description, example] diff --git a/frontend/static/yw/javascript/owot.js b/frontend/static/yw/javascript/owot.js index 36d36507..0a0c5265 100644 --- a/frontend/static/yw/javascript/owot.js +++ b/frontend/static/yw/javascript/owot.js @@ -8366,6 +8366,9 @@ var ws_functions = { case "noCopy": state.worldModel.no_copy = value; break; + case "noAnonChat": + state.worldModel.no_anon_chat = value; + break; case "chat": state.worldModel.chat_permission = value; elm.chatbar.disabled = !Permissions.can_chat(state.userModel, state.worldModel); diff --git a/frontend/templates/administrator.html b/frontend/templates/administrator.html index 40f1c855..6ea97c19 100644 --- a/frontend/templates/administrator.html +++ b/frontend/templates/administrator.html @@ -302,6 +302,10 @@