Skip to content
Merged
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
7 changes: 6 additions & 1 deletion backend/pages/accounts/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -974,4 +979,4 @@ module.exports.POST = async function(req, write, server, ctx) {
redirect: "/accounts/configure/" + new_world_name + "/"
});
}
}
}
11 changes: 10 additions & 1 deletion backend/pages/admin/administrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions backend/pages/world_props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions backend/pages/yourworld.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions backend/subsystems/world_mgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down Expand Up @@ -216,6 +217,7 @@ function makeWorldObject() {
squareChars: false,
noLogEdits: false,
noChatGlobal: false,
noAnonChat: false,
noCopy: false,
halfChars: false,
charRate: "",
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -502,6 +505,7 @@ async function commitWorld(world) {
"opts/squareChars",
"opts/noLogEdits",
"opts/noChatGlobal",
"opts/noAnonChat",
"opts/noCopy",
"opts/halfChars",
"opts/charRate",
Expand Down Expand Up @@ -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,
Expand Down
31 changes: 26 additions & 5 deletions backend/websockets/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions frontend/static/yw/javascript/owot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions frontend/templates/administrator.html
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ <h1>Administrator Panel</h1>
Global chat enabled:
<input type="checkbox" name="set_chat_global_enabled" id="set_chat_global_enabled"{%if global_chat_enabled%} checked{%endif%}>
</div>
<div>
Global chat: prevent anonymous users:
<input type="checkbox" name="set_chat_global_no_anon" id="set_chat_global_no_anon"{%if global_chat_no_anon%} checked{%endif%}>
</div>
<input type="submit" value="Set">
</form>
</div>
Expand Down
9 changes: 9 additions & 0 deletions frontend/templates/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,15 @@ <h1>Options for "<a href="/{{ world }}">{{ world }}</a>"</h1>
Allows users to chat using the chatbox.
</td>
</tr>
<tr>
<td class="feature_name">No anonymous chat</td>
<td>
<input type="checkbox" name="no_anon_chat" value="1"{%if no_anon_chat%} checked{%endif%}>
</td>
<td class="feature_description">
Prevent anonymous (unregistered) users from chatting. Registered users can always chat.
</td>
</tr>
<tr>
<td class="feature_name">Change text color</td>
<td>
Expand Down
3 changes: 2 additions & 1 deletion runserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ var sql_edits_init = "./backend/edits.sql";

var serverSettings = {
announcement: "",
chatGlobalEnabled: "1"
chatGlobalEnabled: "1",
chatGlobalNoAnon: "0"
};
var serverSettingsStatus = {};

Expand Down