From c9ccf230490e721c7cf892ba16920d0bb895ec3c Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Tue, 29 Jan 2019 18:44:55 -0500 Subject: [PATCH 01/16] Cleaning up unused gems. --- Gemfile | 2 -- Gemfile.lock | 7 ------- engine/aresmush.rb | 1 - 3 files changed, 10 deletions(-) diff --git a/Gemfile b/Gemfile index 5666a271d5..0c488802a0 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,6 @@ gem 'timezone', '~> 1.2.10' gem 'dentaku', '~>3.1' gem 'json', '~> 2.1.0' gem 'redcarpet', '~> 3.4.0' -gem 'html2markdown', '0.0.3' gem 'sinatra', '~> 2.0.4' gem 'thin', '~> 1.7.2' gem 'sinatra-cross_origin', '~>0.4.0' @@ -26,7 +25,6 @@ gem 'aws-sdk-s3', '~> 1.8.2' gem 'rubyzip', '~> 1.2.2' gem 'diff-lcs', '~> 1.3' gem 'diffy', '~> 3.2.0' -gem "nokogiri", "~> 1.8.5" gem 'sassc', '~> 2.0.0' gem 'htmlentities', '~>4.3.4' gem 'handlebars', '~>0.8.0' diff --git a/Gemfile.lock b/Gemfile.lock index ed6e3596c3..af83ea2ed3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,8 +37,6 @@ GEM therubyracer (~> 0.12.1) handlebars-source (4.0.12) hiredis (0.6.1) - html2markdown (0.0.3) - nokogiri htmlentities (4.3.4) http_parser.rb (0.6.0) i18n (0.9.5) @@ -47,13 +45,10 @@ GEM json (2.1.0) libv8 (3.16.14.19) log4r (1.1.10) - mini_portile2 (2.3.0) minitest (5.11.3) mustermann (1.0.3) nest (3.1.1) redic - nokogiri (1.8.5) - mini_portile2 (~> 2.3.0) ohm (3.1.1) nest (~> 3) redic (~> 1.5.0) @@ -119,12 +114,10 @@ DEPENDENCIES erubis (~> 2.7.0) eventmachine (~> 1.2.5) handlebars (~> 0.8.0) - html2markdown (= 0.0.3) htmlentities (~> 4.3.4) i18n (~> 0.7) json (~> 2.1.0) log4r (~> 1.1.10) - nokogiri (~> 1.8.5) ohm (~> 3.1.1) rake (~> 12.3) redcarpet (~> 3.4.0) diff --git a/engine/aresmush.rb b/engine/aresmush.rb index accc85fe02..757eaae8a4 100644 --- a/engine/aresmush.rb +++ b/engine/aresmush.rb @@ -18,7 +18,6 @@ require 'rspec/core/rake_task' require 'pp' require 'net/http' -require 'html2markdown' require 'handlebars' require 'htmlentities' From 0e4a49e9e6feece7829ab9e09326095c8e7c8dfb Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Tue, 29 Jan 2019 18:45:10 -0500 Subject: [PATCH 02/16] Linked chars method. --- plugins/arescentral/public/arescentral_api.rb | 11 +++++++++++ plugins/arescentral/web/get_players_handler.rb | 6 ++---- plugins/profile/public/profile_api.rb | 7 +++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/arescentral/public/arescentral_api.rb b/plugins/arescentral/public/arescentral_api.rb index 78e1831f0e..bac381a8c9 100644 --- a/plugins/arescentral/public/arescentral_api.rb +++ b/plugins/arescentral/public/arescentral_api.rb @@ -28,5 +28,16 @@ def self.is_alt?(char1, char2) def self.is_registered? !!Game.master.api_game_id end + + # Includes both handle linking and player tag linking. + def self.are_chars_linked?(char1, char2) + return true if AresCentral.is_alt?(char1, char2) + tag1 = Profile.get_player_tag(char1) + tag2 = Profile.get_player_tag(char2) + return false if !tag1 + return false if !tag2 + return tag1 == tag2 + end + end end \ No newline at end of file diff --git a/plugins/arescentral/web/get_players_handler.rb b/plugins/arescentral/web/get_players_handler.rb index 04c81a8884..7c43edebec 100644 --- a/plugins/arescentral/web/get_players_handler.rb +++ b/plugins/arescentral/web/get_players_handler.rb @@ -15,12 +15,10 @@ def handle(request) add_alt(players, c.name, c) end - player_tag = c.profile_tags.select { |t| t.start_with?("player") }.first + player_tag = Profile.get_player_tag(c) next if !player_tag - - player_tag = player_tag.after(":").titleize - add_alt(players, player_tag, c) + add_alt(players, player_tag.titleize, c) end players.sort.map { |name, alts| { name: name, alts: alts }} diff --git a/plugins/profile/public/profile_api.rb b/plugins/profile/public/profile_api.rb index 6f7daefd73..530bae7641 100644 --- a/plugins/profile/public/profile_api.rb +++ b/plugins/profile/public/profile_api.rb @@ -37,5 +37,12 @@ def self.general_field(char, field_type, value) char.handle ? "@#{char.handle.name}" : "" end end + + def self.get_player_tag(char) + player_tag = char.profile_tags.select { |t| t.start_with?("player") }.first + return nil if !player_tag + player_tag = player_tag.after(":") + player_tag.blank? ? nil : player_tag + end end end \ No newline at end of file From 54b9f33137955e622e00e7211709b072162c2c11 Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Tue, 29 Jan 2019 18:45:26 -0500 Subject: [PATCH 03/16] Show scene log num in room desc. --- plugins/describe/locales/locale_en.yml | 2 +- plugins/describe/templates/room.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/describe/locales/locale_en.yml b/plugins/describe/locales/locale_en.yml index bb36aeefa0..4517624f81 100644 --- a/plugins/describe/locales/locale_en.yml +++ b/plugins/describe/locales/locale_en.yml @@ -33,7 +33,7 @@ en: exits_title: "Exits:" no_way_out: "No way out!" - scene_log_active: "+++ The scene log is active in this room. +++" + scene_log_active: "+++ The scene log (%{num}) is active in this room. +++" watching_from_web: "(Via Web)" no_such_detail: "No such detail available." detail_deleted: "Detail deleted." diff --git a/plugins/describe/templates/room.erb b/plugins/describe/templates/room.erb index 1128fac3f2..b98250a718 100644 --- a/plugins/describe/templates/room.erb +++ b/plugins/describe/templates/room.erb @@ -14,7 +14,7 @@ <% end %> <% if logging_enabled %> -%xy<%= center( t('describe.scene_log_active'), 78 )%>%xn +%xy<%= center( t('describe.scene_log_active', :num => room.scene.id), 78 )%>%xn <% end %> <%= divider %> %xg<%= t('describe.players_title') %>%xn From b9af7a7f414f70b1718032386a47e9889ebaeddc Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Tue, 29 Jan 2019 18:45:49 -0500 Subject: [PATCH 04/16] Trending scene template. Scene permission fix. --- plugins/scenes/events/cron_event_handler.rb | 7 +++---- plugins/scenes/templates/trending_scenes.erb | 6 ++++++ .../scenes/templates/trending_scenes_template.rb | 13 +++++++++++++ plugins/scenes/web/get_scene_handler.rb | 3 ++- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 plugins/scenes/templates/trending_scenes.erb create mode 100644 plugins/scenes/templates/trending_scenes_template.rb diff --git a/plugins/scenes/events/cron_event_handler.rb b/plugins/scenes/events/cron_event_handler.rb index 0fd0cb5063..ca634b5cd8 100644 --- a/plugins/scenes/events/cron_event_handler.rb +++ b/plugins/scenes/events/cron_event_handler.rb @@ -89,10 +89,9 @@ def post_trending_scenes recent_scenes = Scene.all.select { |s| s.shared && s.likes > 0 && (Time.now - (s.date_shared || s.created_at) < 864000) } trending = recent_scenes.sort_by { |s| -s.likes }[0, 10] - post = trending.each_with_index - .map { |s, i| "#{i+1}. #{(s.title || "").ljust(30)} #{s.url}"} - .join("%R") - + template = TrendingScenesTemplate.new(trending) + post = template.render + Forum.system_post( Global.read_config("scenes", "trending_scenes_category"), t('scenes.trending_scenes_subject'), diff --git a/plugins/scenes/templates/trending_scenes.erb b/plugins/scenes/templates/trending_scenes.erb new file mode 100644 index 0000000000..5c0c68f19b --- /dev/null +++ b/plugins/scenes/templates/trending_scenes.erb @@ -0,0 +1,6 @@ + +<% scenes.each_with_index do |scene, i| %> +<%= left("#{i+1}.", 3) -%> +<%= left("#{scene.title}", 30) -%> +<%= scene.url %> +<% end %> \ No newline at end of file diff --git a/plugins/scenes/templates/trending_scenes_template.rb b/plugins/scenes/templates/trending_scenes_template.rb new file mode 100644 index 0000000000..83123713f7 --- /dev/null +++ b/plugins/scenes/templates/trending_scenes_template.rb @@ -0,0 +1,13 @@ +module AresMUSH + module Scenes + class TrendingScenesTemplate < ErbTemplateRenderer + + attr_accessor :scenes + + def initialize(scenes) + @scenes = scenes + super File.dirname(__FILE__) + "/trending_scenes.erb" + end + end + end +end \ No newline at end of file diff --git a/plugins/scenes/web/get_scene_handler.rb b/plugins/scenes/web/get_scene_handler.rb index 619e00c75b..eee0901c98 100644 --- a/plugins/scenes/web/get_scene_handler.rb +++ b/plugins/scenes/web/get_scene_handler.rb @@ -14,7 +14,8 @@ def handle(request) end if (edit_mode) - if (!Scenes.can_read_scene?(enactor, scene)) + can_edit = scene.shared ? Scenes.can_edit_scene?(enactor, scene) : Scenes.can_read_scene?(enactor, scene) + if (!can_edit) return { error: t('dispatcher.not_allowed') } end else From 4d51210264507f70b076c3918fde379b589883ea Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Tue, 29 Jan 2019 18:46:33 -0500 Subject: [PATCH 05/16] Game friends not all showing. Luck emitting to scene. --- plugins/friends/templates/friends_template.rb | 2 +- plugins/fs3skills/commands/luck_spend_cmd.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/friends/templates/friends_template.rb b/plugins/friends/templates/friends_template.rb index 5a509328c6..beaebc7c18 100644 --- a/plugins/friends/templates/friends_template.rb +++ b/plugins/friends/templates/friends_template.rb @@ -12,7 +12,7 @@ def friendships end def unlinked_friendships - @enactor.friendships.select { |f| !f.friend.handle }.sort_by { |f| f.friend.name } + @enactor.friendships.select { |f| !handle_friends.include?(f.friend.handle) }.sort_by { |f| f.friend.name } end def friend_note(friend) diff --git a/plugins/fs3skills/commands/luck_spend_cmd.rb b/plugins/fs3skills/commands/luck_spend_cmd.rb index bd441cbca7..f0efd8cc7b 100644 --- a/plugins/fs3skills/commands/luck_spend_cmd.rb +++ b/plugins/fs3skills/commands/luck_spend_cmd.rb @@ -23,6 +23,10 @@ def handle enactor.spend_luck(1) message = t('fs3skills.luck_point_spent', :name => enactor_name, :reason => reason) enactor_room.emit_ooc message + if (enactor_room.scene) + Scenes.add_to_scene(enactor_room.scene, message) + end + Achievements.award_achievement(enactor, "fs3_luck_spent", 'fs3', "Spent a luck point.") category = Jobs.system_category From bb660af97be07cf782d2014b572360cf769e1c2f Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Tue, 29 Jan 2019 18:47:47 -0500 Subject: [PATCH 06/16] Wiki file permissions. --- plugins/website/helpers/general.rb | 7 +++++ .../web/file_delete_request_handler.rb | 2 +- .../web/file_update_request_handler.rb | 2 +- .../website/web/get_file_request_handler.rb | 27 +++++++++++++++++++ plugins/website/website.rb | 2 ++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 plugins/website/web/get_file_request_handler.rb diff --git a/plugins/website/helpers/general.rb b/plugins/website/helpers/general.rb index 28bfe3668f..3da8b0f21f 100644 --- a/plugins/website/helpers/general.rb +++ b/plugins/website/helpers/general.rb @@ -62,5 +62,12 @@ def self.engine_api_keys Global.read_config("secrets", "engine_api_keys") || [] end + def self.can_edit_wiki_file?(actor, folder) + return false if !actor + wiki_admin = Website.can_manage_wiki?(actor) + own_folder = folder.upcase == actor.name_upcase + wiki_admin || own_folder + end + end end diff --git a/plugins/website/web/file_delete_request_handler.rb b/plugins/website/web/file_delete_request_handler.rb index e9a9f5d62f..4e5c2cc192 100644 --- a/plugins/website/web/file_delete_request_handler.rb +++ b/plugins/website/web/file_delete_request_handler.rb @@ -12,7 +12,7 @@ def handle(request) error = Website.check_login(request) return error if error - if (!enactor.is_admin?) + if (!Website.can_edit_wiki_file?(enactor, folder)) return { error: t('dispatcher.not_allowed') } end diff --git a/plugins/website/web/file_update_request_handler.rb b/plugins/website/web/file_update_request_handler.rb index 25a56b99f1..34cecb3f85 100644 --- a/plugins/website/web/file_update_request_handler.rb +++ b/plugins/website/web/file_update_request_handler.rb @@ -14,7 +14,7 @@ def handle(request) error = Website.check_login(request) return error if error - if (!enactor.is_approved?) + if (!Website.can_edit_wiki_file?(enactor, folder)) return { error: t('dispatcher.not_allowed') } end diff --git a/plugins/website/web/get_file_request_handler.rb b/plugins/website/web/get_file_request_handler.rb new file mode 100644 index 0000000000..ace0603919 --- /dev/null +++ b/plugins/website/web/get_file_request_handler.rb @@ -0,0 +1,27 @@ +module AresMUSH + module Website + class GetFileRequestHandler + def handle(request) + enactor = request.enactor + name = request.args[:name] + folder = request.args[:folder] + + error = Website.check_login(request, true) + return error if error + + if (name.blank? || folder.blank?) + return { error: t('webportal.missing_required_fields') } + end + + path = File.join(folder, name) + + { + name: name, + folder: folder, + path: path, + can_edit: Website.can_edit_wiki_file?(enactor, folder) + } + end + end + end +end \ No newline at end of file diff --git a/plugins/website/website.rb b/plugins/website/website.rb index fa6585d306..0ae573c836 100644 --- a/plugins/website/website.rb +++ b/plugins/website/website.rb @@ -68,6 +68,8 @@ def self.get_web_request_handler(request) return GetWikiTagRequestHandler ## FILES + when "file" + return GetFileRequestHandler when "deleteFile" return FileDeleteRequestHandler when "files" From 738bdf1151e31a755cf9ed804340189e33834fe3 Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Wed, 30 Jan 2019 09:12:09 -0500 Subject: [PATCH 07/16] Online char finder singular. --- engine/aresmush/helpers/online_char_finder.rb | 30 +++-- engine/styles/ares.scss | 3 + .../online_char_finder_specs.rb | 105 ++++++------------ 3 files changed, 59 insertions(+), 79 deletions(-) diff --git a/engine/aresmush/helpers/online_char_finder.rb b/engine/aresmush/helpers/online_char_finder.rb index 7931c490a3..e67e290963 100644 --- a/engine/aresmush/helpers/online_char_finder.rb +++ b/engine/aresmush/helpers/online_char_finder.rb @@ -8,14 +8,13 @@ def initialize(client, char) end class OnlineCharFinder - def self.find(name, client, allow_handles = false) - return FindResult.new(OnlineCharResult.new(client, client.char), nil) if (name.downcase == "me") + def self.find(name) online = Global.client_monitor.logged_in - .select { |other_client, other_char| exact_match?(other_char, name, allow_handles, client)} + .select { |other_client, other_char| exact_match?(other_char, name)} .map { |other_client, other_char| OnlineCharResult.new(other_client, other_char )} if (online.count == 0) online = Global.client_monitor.logged_in - .select { |other_client, other_char| partial_match?(other_char, name, allow_handles, client)} + .select { |other_client, other_char| partial_match?(other_char, name)} .map { |other_client, other_char| OnlineCharResult.new(other_client, other_char )} end @@ -26,11 +25,22 @@ def self.find(name, client, allow_handles = false) end FindResult.new(nil, t('db.ambiguous_char_online', :name => name)) end - - def self.with_online_chars(names, client, allow_handles = false, &block) + + def self.with_an_online_char(name, client, &block) + result = self.find(name) + + if (!result.found?) + client.emit_failure(result.error) + return + end + + yield result.target + end + + def self.with_online_chars(names, client, &block) to_clients = [] names.each do |name| - result = self.find(name, client, allow_handles) + result = self.find(name) if (!result.found?) client.emit_failure(result.error) @@ -43,22 +53,20 @@ def self.with_online_chars(names, client, allow_handles = false, &block) private - def self.exact_match?(char, name, allow_handles, viewer) + def self.exact_match?(char, name) name = name.upcase return false if name.blank? return false if !char return true if char.name_upcase == name return true if char.alias_upcase == name - return true if allow_handles && char.handle && char.handle.upcase == name && char.handle_visible_to?(viewer) return false end - def self.partial_match?(char, name, allow_handles, viewer) + def self.partial_match?(char, name) name = name.upcase return false if name.blank? return false if !char return true if char.name_upcase.start_with?(name) - return true if allow_handles && char.handle && char.handle.upcase.start_with?(name) && char.handle_visible_to?(viewer) return false end end diff --git a/engine/styles/ares.scss b/engine/styles/ares.scss index 5286c1cdd5..f2817fe258 100644 --- a/engine/styles/ares.scss +++ b/engine/styles/ares.scss @@ -673,6 +673,9 @@ CHARGEN SCREEN SCENES SCREEN ------------------------- */ +.pose-box { +} + .scene-pose { padding: 10px; margin: 15px; diff --git a/spec/plugin_helpers/online_char_finder_specs.rb b/spec/plugin_helpers/online_char_finder_specs.rb index c0491c64fc..46b234d77a 100644 --- a/spec/plugin_helpers/online_char_finder_specs.rb +++ b/spec/plugin_helpers/online_char_finder_specs.rb @@ -16,22 +16,13 @@ module AresMUSH stub_translate_for_testing end - it "should return the client for the me keword" do - char = double - allow(@client).to receive(:char) { char } - result = OnlineCharFinder.find("me", @client) - expect(result.target.client).to eq @client - expect(result.target.char).to eq char - expect(result.error).to be_nil - end - it "should return a matching online char" do allow(@char1).to receive(:name_upcase) { "HARVEY" } allow(@char1).to receive(:alias_upcase) { nil } allow(@char2).to receive(:name_upcase) { "BOB" } allow(@char2).to receive(:alias_upcase) { nil } allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1, @client2 => @char2 }} - result = OnlineCharFinder.find("bo", @client) + result = OnlineCharFinder.find("bo") expect(result.target.client).to eq @client2 expect(result.target.char).to eq @char2 expect(result.error).to be_nil @@ -41,7 +32,7 @@ module AresMUSH allow(@char1).to receive(:name_upcase) { "HARVEY" } allow(@char1).to receive(:alias_upcase) { "HVY" } allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1 }} - result = OnlineCharFinder.find("hvy", @client) + result = OnlineCharFinder.find("hvy") expect(result.target.client).to eq @client1 expect(result.target.char).to eq @char1 expect(result.error).to be_nil @@ -54,7 +45,7 @@ module AresMUSH allow(@char1).to receive(:alias_upcase) { nil } allow(@char2).to receive(:alias_upcase) { nil } allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1, @client2 => @char2 }} - result = OnlineCharFinder.find("Ann", @client) + result = OnlineCharFinder.find("Ann") expect(result.target).to be_nil expect(result.error).to eq "db.ambiguous_char_online" end @@ -65,62 +56,17 @@ module AresMUSH allow(@char1).to receive(:alias_upcase) { nil } allow(@char2).to receive(:alias_upcase) { nil } allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1, @client2 => @char2 }} - result = OnlineCharFinder.find("Ann", @client) - expect(result.target.client).to eq @client1 - expect(result.target.char).to eq @char1 - expect(result.error).to be_nil - end - - it "should match a handle if allowed to" do - allow(@char1).to receive(:name_upcase) { "HARVEY" } - allow(@char1).to receive(:alias_upcase) { "HVY" } - allow(@char1).to receive(:handle) { "@Nemo" } - allow(@char1).to receive(:handle_visible_to?).with(@client) { true } - allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1 }} - result = OnlineCharFinder.find("@Nemo", @client, true) + result = OnlineCharFinder.find("Ann") expect(result.target.client).to eq @client1 expect(result.target.char).to eq @char1 expect(result.error).to be_nil end - it "should match part of a handle if allowed to" do - allow(@char1).to receive(:name_upcase) { "HARVEY" } - allow(@char1).to receive(:alias_upcase) { "HVY" } - allow(@char1).to receive(:handle) { "@Nemo" } - allow(@char1).to receive(:handle_visible_to?).with(@client) { true } - allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1 }} - result = OnlineCharFinder.find("@Nem", @client, true) - expect(result.target.client).to eq @client1 - expect(result.target.char).to eq @char1 - expect(result.error).to be_nil - end - - it "should not match a handle if not allowed" do - allow(@char1).to receive(:name_upcase) { "HARVEY" } - allow(@char1).to receive(:alias_upcase) { "HVY" } - allow(@char1).to receive(:handle) { "@Nemo" } - allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1 }} - result = OnlineCharFinder.find("@Nemo", @client, false) - expect(result.target).to be_nil - expect(result.error).to eq "db.no_char_online_found" - end - - it "should not match a handle if handle can't be seen" do - allow(@char1).to receive(:name_upcase) { "HARVEY" } - allow(@char1).to receive(:alias_upcase) { "HVY" } - allow(@char1).to receive(:handle) { "@Nemo" } - allow(@char1).to receive(:handle_visible_to?).with(@client) { false } - allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1 }} - result = OnlineCharFinder.find("@Nemo", @client, false) - expect(result.target).to be_nil - expect(result.error).to eq "db.no_char_online_found" - end - it "should return failure result if nothing found" do allow(@char1).to receive(:name_upcase) { "ANNE" } allow(@char1).to receive(:alias_upcase) { nil } allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1 }} - result = OnlineCharFinder.find("Bob", @client) + result = OnlineCharFinder.find("Bob") expect(result.target).to be_nil expect(result.error).to eq "db.no_char_online_found" end @@ -132,21 +78,44 @@ module AresMUSH end it "should emit failure if a char doesn't exist" do - result = FindResult.new(nil, "error msg") - expect(OnlineCharFinder).to receive(:find).with("n1", @client, false) { result } + result1 = FindResult.new(nil, "error msg") + expect(OnlineCharFinder).to receive(:find).with("n1") { result1 } expect(@client).to receive(:emit_failure).with("error msg") - OnlineCharFinder.with_online_chars(["n1", "n2"], @client) do |clients| + OnlineCharFinder.with_online_chars(["n1", "n2"], @client) do |results| raise "Should not get here." end end it "should call the block with the clients if they exist" do - client1 = double - client2 = double - expect(OnlineCharFinder).to receive(:find).with("n1", @client, false) { FindResult.new(client1, nil) } - expect(OnlineCharFinder).to receive(:find).with("n2", @client, false) { FindResult.new(client2, nil) } - OnlineCharFinder.with_online_chars(["n1", "n2"], @client) do |clients| - expect(clients).to eq [client1, client2] + result1 = double + result2 = double + expect(OnlineCharFinder).to receive(:find).with("n1") { FindResult.new(result1, nil) } + expect(OnlineCharFinder).to receive(:find).with("n2") { FindResult.new(result2, nil) } + OnlineCharFinder.with_online_chars(["n1", "n2"], @client) do |results| + expect(results).to eq [result1, result2] + end + end + end + + describe :with_an_online_char do + before do + @client = double + end + + it "should emit failure if a char doesn't exist" do + result1 = FindResult.new(nil, "error msg") + expect(OnlineCharFinder).to receive(:find).with("n1") { result1 } + expect(@client).to receive(:emit_failure).with("error msg") + OnlineCharFinder.with_an_online_char("n1", @client) do |result| + raise "Should not get here." + end + end + + it "should call the block with the result if they exist" do + result1 = double + expect(OnlineCharFinder).to receive(:find).with("n1") { FindResult.new(result1, nil) } + OnlineCharFinder.with_an_online_char("n1", @client) do |result| + expect(result).to eq result1 end end end From c9f19827347d588f8dc0b0b341afd8fc1c1074c3 Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Wed, 30 Jan 2019 09:12:48 -0500 Subject: [PATCH 08/16] Unshared scenes on web and go home after scene end. --- plugins/rooms/public/rooms_api.rb | 8 ++++++ plugins/scenes/commands/scene_home_cmd.rb | 34 +++++++++++++++++++++++ plugins/scenes/help/en/scenes.md | 4 +++ plugins/scenes/helpers.rb | 9 +++++- plugins/scenes/locales/locale_en.yml | 7 ++++- plugins/scenes/public/scenes_char.rb | 5 ++++ plugins/scenes/scenes.rb | 2 ++ plugins/scenes/web/live_scenes_handler.rb | 17 +++++++++++- 8 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 plugins/scenes/commands/scene_home_cmd.rb diff --git a/plugins/rooms/public/rooms_api.rb b/plugins/rooms/public/rooms_api.rb index abe95cacee..ce225a26d1 100644 --- a/plugins/rooms/public/rooms_api.rb +++ b/plugins/rooms/public/rooms_api.rb @@ -33,6 +33,14 @@ def self.send_to_welcome_room(client, char) def self.send_to_ooc_room(client, char) Rooms.move_to(client, char, Game.master.ooc_room) end + + def self.send_to_home(client, char) + Rooms.move_to(client, char, char.room_home || Game.master.ooc_room) + end + + def self.send_to_work(client, char) + Rooms.move_to(client, char, char.room_work || Game.master.ooc_room) + end def self.ic_start_room Game.master.ic_start_room diff --git a/plugins/scenes/commands/scene_home_cmd.rb b/plugins/scenes/commands/scene_home_cmd.rb new file mode 100644 index 0000000000..656f304645 --- /dev/null +++ b/plugins/scenes/commands/scene_home_cmd.rb @@ -0,0 +1,34 @@ +module AresMUSH + module Scenes + class SceneHomeCmd + include CommandHandler + + attr_accessor :option + + def parse_args + self.option = !cmd.args ? nil : cmd.args.downcase + end + + def required_args + [ self.option ] + end + + def check_option + options = [ 'ooc', 'home', 'work' ] + return nil if options.include?(self.option) + t('scenes.invalid_home_option', :options => options.join(", ")) + end + + def check_option_set + return t('scenes.no_home_set') if self.option == 'home' && !enactor.room_home + return t('scenes.no_work_set') if self.option == 'work' && !enactor.room_work + return nil + end + + def handle + enactor.update(scene_home: self.option) + client.emit_success t('scenes.scene_home_set', :option => self.option) + end + end + end +end diff --git a/plugins/scenes/help/en/scenes.md b/plugins/scenes/help/en/scenes.md index 59c9fb1a3e..6578911b6a 100644 --- a/plugins/scenes/help/en/scenes.md +++ b/plugins/scenes/help/en/scenes.md @@ -84,6 +84,10 @@ You should stop a scene when it's over. Scenes with empty rooms will be stopped > **Tip:** Admins and characters with the `manage_scenes` permission can stop and delete other people's scenes. +When a scene in a temp room stops, characters are normally sent back to the Offstage lounge. You can instead choose to be sent to your character's home or workplace, if you've set one with the home or work command. + +`scene/home ` - Sets your scene home preference. + ## Logging and Poses The scene system starts a scene log automatically. To disable this, or for more help with scene logs, including the pose editing commands, see [Scene Logging](/help/logging). \ No newline at end of file diff --git a/plugins/scenes/helpers.rb b/plugins/scenes/helpers.rb index 6fdc17d5eb..e38d0f8b62 100644 --- a/plugins/scenes/helpers.rb +++ b/plugins/scenes/helpers.rb @@ -71,7 +71,14 @@ def self.stop_scene(scene, enactor) connected_client = Login.find_client(c) if (scene.temp_room) - Rooms.send_to_ooc_room(connected_client, c) + case c.scene_home + when 'home' + Rooms.send_to_home(connected_client, c) + when 'work' + Rooms.send_to_work(connected_client, c) + else + Rooms.send_to_ooc_room(connected_client, c) + end message = t('scenes.scene_ending', :name => enactor.name) else message = t('scenes.scene_ending_public', :name => enactor.name) diff --git a/plugins/scenes/locales/locale_en.yml b/plugins/scenes/locales/locale_en.yml index a2a513d9cb..4e0dcf7bf6 100644 --- a/plugins/scenes/locales/locale_en.yml +++ b/plugins/scenes/locales/locale_en.yml @@ -126,4 +126,9 @@ en: scene_notify_uninvited: "%{name} has withdrawn the invitation to join scene %{num}." no_talking_quiet_room: "Sssh. This is the quiet room." - no_talking_ooc_lounge: "Chatting in the OOC lounge is sent to the %{channel} channel so everyone can participate. Make sure you've joined and un-muted that channel if you want to chat here." \ No newline at end of file + no_talking_ooc_lounge: "Chatting in the OOC lounge is sent to the %{channel} channel so everyone can participate. Make sure you've joined and un-muted that channel if you want to chat here." + + invalid_home_option: "That is not a valid home option. Try one of these: %{options}" + scene_home_set: "You will now go to %{option} when a temp room scene ends." + no_home_set: "You haven't set a home." + no_work_set: "You haven't set a workplace." \ No newline at end of file diff --git a/plugins/scenes/public/scenes_char.rb b/plugins/scenes/public/scenes_char.rb index 196b168518..50d06fa1e0 100644 --- a/plugins/scenes/public/scenes_char.rb +++ b/plugins/scenes/public/scenes_char.rb @@ -6,6 +6,7 @@ class Character attribute :pose_nudge, :type => DataType::Boolean, :default => true attribute :pose_nudge_muted, :type => DataType::Boolean attribute :pose_word_count, :type => DataType::Integer + attribute :scene_home def autospace self.pose_autospace @@ -24,5 +25,9 @@ def last_posed def scenes_starring Scene.scenes_starring(self) end + + def unshared_scenes + Scene.all.select { |s| !s.shared && s.participants.include?(self) } + end end end \ No newline at end of file diff --git a/plugins/scenes/scenes.rb b/plugins/scenes/scenes.rb index 1d54a65be7..8435d793c3 100644 --- a/plugins/scenes/scenes.rb +++ b/plugins/scenes/scenes.rb @@ -72,6 +72,8 @@ def self.get_cmd_handler(client, cmd, enactor) return SceneCharCmd when "addpose" return SceneAddPoseCmd + when "home" + return SceneHomeCmd when "join" return SceneJoinCmd when "location", "privacy", "summary", "title", "type", "icdate", "plot" diff --git a/plugins/scenes/web/live_scenes_handler.rb b/plugins/scenes/web/live_scenes_handler.rb index 6c4a4c25f9..5ffa26bc69 100644 --- a/plugins/scenes/web/live_scenes_handler.rb +++ b/plugins/scenes/web/live_scenes_handler.rb @@ -8,7 +8,7 @@ def handle(request) return error if error - Scene.all.select { |s| !s.completed }.sort { |s1, s2| sort_scene(s1, s2) }.reverse.map { |s| { + active = Scene.all.select { |s| !s.completed }.sort { |s1, s2| sort_scene(s1, s2) }.reverse.map { |s| { id: s.id, title: s.title, summary: s.summary, @@ -33,6 +33,21 @@ def handle(request) participating: Scenes.is_participant?(s, enactor), last_posed: s.last_posed ? s.last_posed.name : nil }} + if (enactor) + unshared = enactor.unshared_scenes.sort_by { |s| s.id.to_i }.reverse.map { |s| { + title: s.date_title, + people: s.participant_names.join(' '), + id: s.id }} + else + unshared = nil + end + + { + active: active, + unshared: unshared, + unshared_warning_days: Global.read_config('scenes', 'unshared_scene_deletion_days') + } + end def sort_scene(s1, s2) From 4c516aa60be19b609598e508a25d789987f4afb1 Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Thu, 31 Jan 2019 00:21:17 -0500 Subject: [PATCH 09/16] Mute and hide forums. --- plugins/forum/commands/forum_hide_cmd.rb | 29 ++++++++++++++++ plugins/forum/commands/forum_mute_cmd.rb | 19 +++++++++++ .../events/char_connected_event_handler.rb | 12 +++++++ plugins/forum/forum.rb | 12 ++++++- plugins/forum/help/en/forum.md | 22 ++++++++----- plugins/forum/helpers.rb | 29 +++++++++++++++- plugins/forum/locales/locale_en.yml | 7 ++++ plugins/forum/public/bbs_board.rb | 3 +- plugins/forum/public/bbs_prefs.rb | 31 +++++++++++++++++ plugins/forum/templates/category_template.rb | 2 +- plugins/forum/templates/index.erb | 6 +++- plugins/forum/templates/index_template.rb | 11 ++++++- .../web/forum_category_request_handler.rb | 2 +- .../forum/web/forum_hide_request_handler.rb | 33 +++++++++++++++++++ .../forum/web/forum_list_request_handler.rb | 13 +++++++- .../forum/web/forum_mute_request_handler.rb | 18 ++++++++++ 16 files changed, 232 insertions(+), 17 deletions(-) create mode 100644 plugins/forum/commands/forum_hide_cmd.rb create mode 100644 plugins/forum/commands/forum_mute_cmd.rb create mode 100644 plugins/forum/events/char_connected_event_handler.rb create mode 100644 plugins/forum/public/bbs_prefs.rb create mode 100644 plugins/forum/web/forum_hide_request_handler.rb create mode 100644 plugins/forum/web/forum_mute_request_handler.rb diff --git a/plugins/forum/commands/forum_hide_cmd.rb b/plugins/forum/commands/forum_hide_cmd.rb new file mode 100644 index 0000000000..8e3bb5bf2e --- /dev/null +++ b/plugins/forum/commands/forum_hide_cmd.rb @@ -0,0 +1,29 @@ +module AresMUSH + module Forum + class ForumHideCmd + include CommandHandler + + attr_accessor :hide, :category_name + + def parse_args + self.hide = cmd.switch_is?("hide") ? true : false + self.category_name = titlecase_arg(cmd.args) + end + + def handle + Forum.with_a_category(self.category_name, client, enactor) do |category| + prefs = Forum.get_forum_prefs(enactor, category) + if (!prefs) + prefs = BbsPrefs.create(bbs_board: category, character: enactor) + end + prefs.update(hidden: self.hide) + if (self.hide) + client.emit_success t('forum.category_hidden', :name => self.category_name) + else + client.emit_success t('forum.category_shown', :name => self.category_name) + end + end + end + end + end +end diff --git a/plugins/forum/commands/forum_mute_cmd.rb b/plugins/forum/commands/forum_mute_cmd.rb new file mode 100644 index 0000000000..76f5ff42e4 --- /dev/null +++ b/plugins/forum/commands/forum_mute_cmd.rb @@ -0,0 +1,19 @@ +module AresMUSH + module Forum + class ForumMuteCmd + include CommandHandler + + attr_accessor :option + + def parse_args + self.option = cmd.switch_is?("mute") ? true : false + end + + def handle + enactor.update(forum_muted: self.option) + message = self.option ? t('forum.forum_muted') : t('forum.forum_unmuted') + client.emit_success message + end + end + end +end diff --git a/plugins/forum/events/char_connected_event_handler.rb b/plugins/forum/events/char_connected_event_handler.rb new file mode 100644 index 0000000000..2ee3ce1a43 --- /dev/null +++ b/plugins/forum/events/char_connected_event_handler.rb @@ -0,0 +1,12 @@ +module AresMUSH + module Forum + class CharDisconnectedEventHandler + def on_event(event) + client = event.client + char = Character[event.char_id] + + char.update(forum_muted: false) + end + end + end +end diff --git a/plugins/forum/forum.rb b/plugins/forum/forum.rb index c06b13891e..734ceee301 100644 --- a/plugins/forum/forum.rb +++ b/plugins/forum/forum.rb @@ -32,9 +32,13 @@ def self.get_cmd_handler(client, cmd, enactor) when "describe" return ForumDescCmd when "edit" - return ForumEditCmd + return ForumEditCmd + when "hide", "show" + return ForumHideCmd when "move" return ForumMoveCmd + when "mute", "unmute" + return ForumMuteCmd when "new" return ForumNewCmd when "order" @@ -66,6 +70,8 @@ def self.get_event_handler(event_name) case event_name when "RoleDeletedEvent" return RoleDeletedEventHandler + when "CharDisconnectedEvent" + return CharDisconnectedEventHandler end nil @@ -79,8 +85,12 @@ def self.get_web_request_handler(request) return AddReplyRequestHandler when "forumCategory" return ForumCategoryRequestHandler + when "forumHide" + return ForumHideRequestHandler when "forumList" return ForumListRequestHandler + when "forumMute" + return ForumMuteRequestHandler when "forumTopic" return ForumTopicRequestHandler when "forumUnread" diff --git a/plugins/forum/help/en/forum.md b/plugins/forum/help/en/forum.md index 6650f2edd5..edc25e4900 100644 --- a/plugins/forum/help/en/forum.md +++ b/plugins/forum/help/en/forum.md @@ -17,14 +17,6 @@ Inspired by the widely-loved [Myrrdin’s Bulletin Board System](http://www.firs > **Tip:** For all of the forum commands, you can specify either the category name or number. Those familiar with Myrddin's BBS should find that the commands you're used to (bbread, bbpost, etc.) also work here. - +==~~~~~====~~~~====~~~~====~~~~=====~~~~=====~~~~====~~~~====~~~~====~~~~~==+ - # Name Description R/W - ------------------------------------------------------------------------------ - 1 Announcements Important announcements. rw - 2 Requests Questions, bugs or suggestions. rw - 3 Cookie Awards rw - +==~~~~~====~~~~====~~~~====~~~~=====~~~~=====~~~~====~~~~====~~~~====~~~~~==+ - The 'rw' on the end tells you whether you can read and/or write to that category. ## Reading Forums @@ -37,6 +29,12 @@ To view topics in a category, you need to use the `forum` command with the categ `forum` - Lists available categories. `forum ` - Lists posts on the selected category. + +## Hiding Categories + +If there are forum categories you don't use, you can hide them from the list and suppress notifications of new posts there. + +`forum/hide ` and `forum/unhide ` - Hide or show a category. ## Reading Topics @@ -93,4 +91,10 @@ You cannot edit a reply once it's been posted, but you can delete it and try aga Forum administrators with the **can\_manage\_forum** permission are able to delete other people's replies. -`forum/deletereply /=` - Deletes a forum reply. \ No newline at end of file +`forum/deletereply /=` - Deletes a forum reply. + +### Notifications + +When RPing, you may want to mute forum notifications. This will last until your next login. + +`forum/mute` and `forum/unmute` - Mutes notifications until your next login. \ No newline at end of file diff --git a/plugins/forum/helpers.rb b/plugins/forum/helpers.rb index 87f66513d3..014fecdc85 100644 --- a/plugins/forum/helpers.rb +++ b/plugins/forum/helpers.rb @@ -6,6 +6,12 @@ def self.can_manage_forum?(actor) actor.has_permission?("manage_forum") end + # NOTE: May return nil + def self.get_forum_prefs(char, category) + prefs = char.bbs_prefs + return prefs ? prefs.find(bbs_board_id: category.id).first : nil + end + def self.can_write_to_category?(char, category) return false if !category roles = category.write_roles.to_a @@ -68,7 +74,9 @@ def self.post(category_name, subject, message, author, client = nil) :author => author_name) Global.notifier.notify_ooc(:new_forum_post, message) do |char| - Forum.can_read_category?(char, category) + !Forum.is_forum_muted?(char) && + Forum.can_read_category?(char, category) && + !Forum.is_category_hidden?(char, category) end Forum.handle_forum_achievement(author, :post) @@ -173,6 +181,25 @@ def self.handle_forum_achievement(char, type) Achievements.award_achievement(char, type, 'community', message) end + + def self.is_category_hidden?(char, category) + return false if !char + prefs = Forum.get_forum_prefs(char, category) + return prefs ? prefs.hidden : false + end + + def self.visible_categories(char) + BbsBoard.all_sorted.select { |b| !Forum.is_category_hidden?(char, b) } + end + + def self.hidden_categories(char) + BbsBoard.all_sorted.select { |b| Forum.is_category_hidden?(char, b) } + end + + def self.is_forum_muted?(char) + return false if !char + return char.is_forum_muted? + end end end diff --git a/plugins/forum/locales/locale_en.yml b/plugins/forum/locales/locale_en.yml index 0b4166a8c5..d4083a5d5a 100644 --- a/plugins/forum/locales/locale_en.yml +++ b/plugins/forum/locales/locale_en.yml @@ -51,3 +51,10 @@ en: starting_archive: "Starting Forum archive. Your posts will print out one by one with a short delay in-between to avoid spamming your client." too_much_for_archive: "That forum has too many posts for the automatic archive feature. 30 is the limit. You'll have to read them manually or move some to another category temporarily and do the archive in stages. Sorry." + + + category_hidden: "Category %{name} is now hidden." + category_shown: "Category %{name} is now shown." + hidden_categories_title: "Hidden:" + forum_muted: "Forum notifications have been muted until your next login." + forum_unmuted: "Forum notifications have been unmuted." \ No newline at end of file diff --git a/plugins/forum/public/bbs_board.rb b/plugins/forum/public/bbs_board.rb index f46ebf4d3f..2add35724e 100644 --- a/plugins/forum/public/bbs_board.rb +++ b/plugins/forum/public/bbs_board.rb @@ -36,6 +36,7 @@ def last_post end def unread_posts(char) + return [] if Forum.is_category_hidden?(char, self) return [] if !Forum.can_read_category?(char, self) bbs_posts.select { |p| p.is_unread?(char) } end @@ -43,7 +44,7 @@ def unread_posts(char) def has_unread?(char) !unread_posts(char).empty? end - + def self.all_sorted BbsBoard.all.sort_by(:order) end diff --git a/plugins/forum/public/bbs_prefs.rb b/plugins/forum/public/bbs_prefs.rb new file mode 100644 index 0000000000..0b9117a7a8 --- /dev/null +++ b/plugins/forum/public/bbs_prefs.rb @@ -0,0 +1,31 @@ +module AresMUSH + class Character + attribute :forum_muted, :type => DataType::Boolean + collection :bbs_prefs, "AresMUSH::BbsPrefs" + + before_delete :delete_bbs_prefs + + def is_forum_muted? + self.forum_muted + end + + def delete_bbs_prefs + if self.bbs_prefs + self.bbs_prefs.destroy + end + end + + end + + class BbsPrefs < Ohm::Model + include ObjectModel + + reference :character, "AresMUSH::Character" + reference :bbs_board, "AresMUSH::BbsBoard" + + index :bbs_board + + attribute :hidden, :type => DataType::Boolean + + end +end diff --git a/plugins/forum/templates/category_template.rb b/plugins/forum/templates/category_template.rb index 637dd37c08..ca36a45dee 100644 --- a/plugins/forum/templates/category_template.rb +++ b/plugins/forum/templates/category_template.rb @@ -35,7 +35,7 @@ def can_post def num(i) "#{i+1}" end - + def unread(post) post.is_unread?(@enactor) ? t('forum.unread_marker') : " " end diff --git a/plugins/forum/templates/index.erb b/plugins/forum/templates/index.erb index 1d6d201f22..d02800f9fa 100644 --- a/plugins/forum/templates/index.erb +++ b/plugins/forum/templates/index.erb @@ -2,10 +2,14 @@ %xh<%= t('forum.categories_list_title') %>%xn <%= divider %> <% categories.each_with_index do |b, i| -%> -<%= right(num(i), 3) -%> +<%= right(b.category_index, 3) -%> <%= center(unread(b),5) -%> <%= left(b.name,27) -%> <%= left(b.description,33) -%> <%= center(permission(b), 5) %> <% end %> +<% if any_hidden? %> +%ld +<%= t('forum.hidden_categories_title') %> <%= hidden_categories %> +<% end %> <%= footer %> \ No newline at end of file diff --git a/plugins/forum/templates/index_template.rb b/plugins/forum/templates/index_template.rb index 45de92ff70..eb9814672c 100644 --- a/plugins/forum/templates/index_template.rb +++ b/plugins/forum/templates/index_template.rb @@ -6,7 +6,8 @@ class ForumIndexTemplate < ErbTemplateRenderer def initialize(char) @char = char - @categories = BbsBoard.all_sorted + @categories = Forum.visible_categories(char) + @hidden = Forum.hidden_categories(char) super File.dirname(__FILE__) + "/index.erb" end @@ -14,6 +15,14 @@ def num(index) "#{index+1}" end + def hidden_categories + @hidden.map { |h| "#{h.category_index}-#{h.name}" }.join(' ') + end + + def any_hidden? + @hidden.count > 0 + end + # Shows whether the character has read or write permissions # to the category. (e.g. rw or r-) def permission(category) diff --git a/plugins/forum/web/forum_category_request_handler.rb b/plugins/forum/web/forum_category_request_handler.rb index 65f4b50ed9..1b59899b75 100644 --- a/plugins/forum/web/forum_category_request_handler.rb +++ b/plugins/forum/web/forum_category_request_handler.rb @@ -25,7 +25,7 @@ def handle(request) title: p.subject, unread: enactor && p.is_unread?(enactor), date: p.created_date_str(enactor), - author: p.author_name, + author: p.author_name }} { diff --git a/plugins/forum/web/forum_hide_request_handler.rb b/plugins/forum/web/forum_hide_request_handler.rb new file mode 100644 index 0000000000..10a49ddfcf --- /dev/null +++ b/plugins/forum/web/forum_hide_request_handler.rb @@ -0,0 +1,33 @@ +module AresMUSH + module Forum + class ForumHideRequestHandler + def handle(request) + + category_id = request.args[:category_id] + hide = request.args[:hide] + enactor = request.enactor + + category = BbsBoard[category_id.to_i] + if (!category) + return { error: t('webportal.not_found') } + end + + error = Website.check_login(request) + return error if error + + if (!Forum.can_read_category?(enactor, category)) + return { error: t('forum.cannot_access_category') } + end + + prefs = Forum.get_forum_prefs(enactor, category) + if (!prefs) + prefs = BbsPrefs.create(bbs_board: category, character: enactor) + end + prefs.update(hidden: hide) + + { + } + end + end + end +end \ No newline at end of file diff --git a/plugins/forum/web/forum_list_request_handler.rb b/plugins/forum/web/forum_list_request_handler.rb index abf4af8f9e..2944150ea7 100644 --- a/plugins/forum/web/forum_list_request_handler.rb +++ b/plugins/forum/web/forum_list_request_handler.rb @@ -8,7 +8,7 @@ def handle(request) error = Website.check_login(request, true) return error if error - BbsBoard.all_sorted + categories = Forum.visible_categories(enactor) .select { |b| Forum.can_read_category?(enactor, b) } .map { |b| { id: b.id, @@ -17,7 +17,18 @@ def handle(request) unread: enactor && b.has_unread?(enactor), last_post: get_last_post(b, enactor) }} + + hidden =Forum.hidden_categories(enactor) + .map { |b| { + id: b.id, + name: b.name + }} + { + categories: categories, + hidden: hidden, + is_muted: Forum.is_forum_muted?(enactor) + } end def get_last_post(board, enactor) diff --git a/plugins/forum/web/forum_mute_request_handler.rb b/plugins/forum/web/forum_mute_request_handler.rb new file mode 100644 index 0000000000..a8e84e63fc --- /dev/null +++ b/plugins/forum/web/forum_mute_request_handler.rb @@ -0,0 +1,18 @@ +module AresMUSH + module Forum + class ForumMuteRequestHandler + def handle(request) + + option = (request.args[:muted] || "").to_bool + enactor = request.enactor + + error = Website.check_login(request) + return error if error + + enactor.update(forum_muted: option) + { + } + end + end + end +end \ No newline at end of file From 0fe6bf1baea6c03c62c3c6b432df806a3ba74c27 Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Thu, 31 Jan 2019 00:21:51 -0500 Subject: [PATCH 10/16] Online char singular. --- engine/aresmush/helpers/online_char_finder.rb | 6 +++++- engine/aresmush/models/find_by_name.rb | 4 ++++ .../plugin_helpers/online_char_finder_specs.rb | 18 +++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/engine/aresmush/helpers/online_char_finder.rb b/engine/aresmush/helpers/online_char_finder.rb index e67e290963..e62c423050 100644 --- a/engine/aresmush/helpers/online_char_finder.rb +++ b/engine/aresmush/helpers/online_char_finder.rb @@ -19,7 +19,11 @@ def self.find(name) end if (online.count == 0) - return FindResult.new(nil, t('db.no_char_online_found', :name => name)) + if (Character.all.select { |c| c.name_upcase.start_with?(name.upcase) }.first) + return FindResult.new(nil, t('db.no_char_online_found', :name => name)) + else + return FindResult.new(nil, t('db.object_not_found', :name => name)) + end elsif (online.count == 1) return FindResult.new(online.first, nil) end diff --git a/engine/aresmush/models/find_by_name.rb b/engine/aresmush/models/find_by_name.rb index e3ed737336..03bfb25e3b 100644 --- a/engine/aresmush/models/find_by_name.rb +++ b/engine/aresmush/models/find_by_name.rb @@ -28,6 +28,10 @@ def find_any_by_name(name_or_id) find(name_upcase: name_or_id.upcase).to_a.select { |x| x } end + def named(name) + find_one_by_name(name) + end + def find_one_by_name(name) find_any_by_name(name).first end diff --git a/spec/plugin_helpers/online_char_finder_specs.rb b/spec/plugin_helpers/online_char_finder_specs.rb index 46b234d77a..cf49726f73 100644 --- a/spec/plugin_helpers/online_char_finder_specs.rb +++ b/spec/plugin_helpers/online_char_finder_specs.rb @@ -62,14 +62,26 @@ module AresMUSH expect(result.error).to be_nil end - it "should return failure result if nothing found" do - allow(@char1).to receive(:name_upcase) { "ANNE" } + it "should return failure result if nothing found and char exists" do + allow(@char1).to receive(:name_upcase) { "BOB" } allow(@char1).to receive(:alias_upcase) { nil } + allow(@char2).to receive(:name_upcase) { "ANNA" } + allow(Character).to receive(:all) { [ @char1, @char2 ] } allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1 }} - result = OnlineCharFinder.find("Bob") + result = OnlineCharFinder.find("Ann") expect(result.target).to be_nil expect(result.error).to eq "db.no_char_online_found" end + + it "should return not found result if nothing found and char doesn't exist" do + allow(@char1).to receive(:name_upcase) { "BOB" } + allow(@char1).to receive(:alias_upcase) { nil } + allow(Character).to receive(:all) { [ ] } + allow(@client_monitor).to receive(:logged_in) { {@client1 => @char1 }} + result = OnlineCharFinder.find("X") + expect(result.target).to be_nil + expect(result.error).to eq "db.object_not_found" + end end describe :with_online_chars do From 6acdc51f1625e0d2dc14eba573e9434642e19112 Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Thu, 31 Jan 2019 00:25:36 -0500 Subject: [PATCH 11/16] Scene stsart scene num --- plugins/scenes/commands/scene_start_cmd.rb | 2 +- plugins/scenes/locales/locale_en.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/scenes/commands/scene_start_cmd.rb b/plugins/scenes/commands/scene_start_cmd.rb index 16a7324b84..0dec6b9ceb 100644 --- a/plugins/scenes/commands/scene_start_cmd.rb +++ b/plugins/scenes/commands/scene_start_cmd.rb @@ -68,7 +68,7 @@ def handle room = enactor_room room.update(scene: scene) scene.update(room: room) - room.emit_ooc t('scenes.announce_scene_start', :privacy => self.privacy, :name => enactor_name) + room.emit_ooc t('scenes.announce_scene_start', :privacy => self.privacy, :name => enactor_name, :num => scene.id) end end end diff --git a/plugins/scenes/locales/locale_en.yml b/plugins/scenes/locales/locale_en.yml index 4e0dcf7bf6..502c38b59d 100644 --- a/plugins/scenes/locales/locale_en.yml +++ b/plugins/scenes/locales/locale_en.yml @@ -32,7 +32,7 @@ en: scene_about_to_join: "You will join the scene in a moment." access_not_allowed: "You do not have access to that scene." scene_already_completed: "That scene is already over." - announce_scene_start: "%{name} has started a new %xh%{privacy}%xH scene here." + announce_scene_start: "%{name} has started a new %xh%{privacy}%xH scene (%{num}) here." location_set: "Scene location changed:%R%R%{description}" scene_nag: "There's no scene running here. Starting a scene will activate repose and make it easy to share the scene with the web portal. Just do `scene/start` if you want to start one." open: "Open" From 5f77a46939b85eaf87bc6afba2d1e21dea40d00a Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Thu, 31 Jan 2019 03:35:59 -0500 Subject: [PATCH 12/16] Hide scene locations for private scenes. --- plugins/scenes/templates/scenes_list_template.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/scenes/templates/scenes_list_template.rb b/plugins/scenes/templates/scenes_list_template.rb index fc1076a1f9..14d56b3284 100644 --- a/plugins/scenes/templates/scenes_list_template.rb +++ b/plugins/scenes/templates/scenes_list_template.rb @@ -19,6 +19,7 @@ def characters(scene) end def title(scene) + return "##{scene.id} <#{privacy(scene)}>" if scene.private_scene "##{scene.id} <#{privacy(scene)}> - #{scene.title || scene.location}" end @@ -27,7 +28,7 @@ def organizer(scene) end def location(scene) - "#{scene.location} (#{location_type(scene)})" + scene.private_scene ? t('scenes.private') : "#{scene.location} (#{location_type(scene)})" end def last_activity(scene) From cc4c62cf1e52fb394da3ce1d9de30e0beac3779d Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Thu, 31 Jan 2019 04:02:09 -0500 Subject: [PATCH 13/16] Mute scenes. --- plugins/scenes/helpers.rb | 7 ++++- plugins/scenes/locales/locale_en.yml | 4 ++- plugins/scenes/public/scene.rb | 1 + plugins/scenes/scenes.rb | 4 ++- plugins/scenes/web/live_scene_handler.rb | 1 + plugins/scenes/web/mute_scene_handler.rb | 38 ++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 plugins/scenes/web/mute_scene_handler.rb diff --git a/plugins/scenes/helpers.rb b/plugins/scenes/helpers.rb index e38d0f8b62..747902ffcf 100644 --- a/plugins/scenes/helpers.rb +++ b/plugins/scenes/helpers.rb @@ -5,7 +5,7 @@ def self.new_scene_activity(scene, data = nil) last_posed = scene.last_posed ? scene.last_posed.name : nil web_msg = "#{scene.id}|#{last_posed}|#{data}" Global.client_monitor.notify_web_clients(:new_scene_activity, web_msg) do |char| - Scenes.can_read_scene?(char, scene) + Scenes.can_read_scene?(char, scene) && !Scenes.is_scene_muted?(char, scene) end end @@ -385,5 +385,10 @@ def self.send_to_ooc_chat_if_needed(enactor, client, message) end return false end + + def self.is_scene_muted?(char, scene) + return false if !char + return scene.muters.include?(char) + end end end diff --git a/plugins/scenes/locales/locale_en.yml b/plugins/scenes/locales/locale_en.yml index 502c38b59d..389a915688 100644 --- a/plugins/scenes/locales/locale_en.yml +++ b/plugins/scenes/locales/locale_en.yml @@ -131,4 +131,6 @@ en: invalid_home_option: "That is not a valid home option. Try one of these: %{options}" scene_home_set: "You will now go to %{option} when a temp room scene ends." no_home_set: "You haven't set a home." - no_work_set: "You haven't set a workplace." \ No newline at end of file + no_work_set: "You haven't set a workplace." + + not_a_part_of_scene: "You are not participating in that scene." \ No newline at end of file diff --git a/plugins/scenes/public/scene.rb b/plugins/scenes/public/scene.rb index 64806596de..c0fe658ef6 100644 --- a/plugins/scenes/public/scene.rb +++ b/plugins/scenes/public/scene.rb @@ -31,6 +31,7 @@ class Scene < Ohm::Model set :participants, "AresMUSH::Character" set :likers, "AresMUSH::Character" set :readers, "AresMUSH::Character" + set :muters, "AresMUSH::Character" before_delete :delete_poses_and_log diff --git a/plugins/scenes/scenes.rb b/plugins/scenes/scenes.rb index 8435d793c3..114585d48d 100644 --- a/plugins/scenes/scenes.rb +++ b/plugins/scenes/scenes.rb @@ -164,7 +164,9 @@ def self.get_web_request_handler(request) when "liveScenes" return LiveScenesRequestHandler when "liveScene" - return LiveSceneRequestHandler + return LiveSceneRequestHandler + when "muteScene" + return MuteSceneRequestHandler when "myScenes" return MyScenesRequestHandler when "plots" diff --git a/plugins/scenes/web/live_scene_handler.rb b/plugins/scenes/web/live_scene_handler.rb index e68ebf41f2..9c5a8c02dd 100644 --- a/plugins/scenes/web/live_scene_handler.rb +++ b/plugins/scenes/web/live_scene_handler.rb @@ -57,6 +57,7 @@ def handle(request) participants: participants, scene_type: scene.scene_type ? scene.scene_type.titlecase : 'unknown', can_edit: enactor && Scenes.can_read_scene?(enactor, scene), + is_muted: enactor && scene.muters.include?(enactor), poses: scene.poses_in_order.map { |p| { char: { name: p.character.name, icon: Website.icon_for_char(p.character) }, order: p.order, diff --git a/plugins/scenes/web/mute_scene_handler.rb b/plugins/scenes/web/mute_scene_handler.rb new file mode 100644 index 0000000000..c9fa822b15 --- /dev/null +++ b/plugins/scenes/web/mute_scene_handler.rb @@ -0,0 +1,38 @@ +module AresMUSH + module Scenes + class MuteSceneRequestHandler + def handle(request) + scene = Scene[request.args[:id]] + muted = (request.args[:muted] || "").to_bool + enactor = request.enactor + + if (!scene) + return { error: t('webportal.not_found') } + end + + error = Website.check_login(request) + return error if error + + if (!scene.participants.include?(enactor)) + return { error: t('scenes.not_a_part_of_scene') } + end + + if (muted) + Global.logger.debug "Scene #{scene.id} muted by #{enactor.name}." + + if (!scene.muters.include?(enactor)) + scene.muters.add enactor + end + else + Global.logger.debug "Scene #{scene.id} unmuted by #{enactor.name}." + + if (scene.muters.include?(enactor)) + scene.muters.delete enactor + end + end + + {} + end + end + end +end \ No newline at end of file From 8a11d70b93a85c57a57df4833f8dc8e6dcd56f8a Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Thu, 31 Jan 2019 22:54:50 -0500 Subject: [PATCH 14/16] Wiki export add char scenes. --- bin/setup_test_game | 12 ------------ engine/aresmush/connection.rb | 8 ++++++-- plugins/website/wiki_exporter.rb | 20 +++++++++++++++++--- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/bin/setup_test_game b/bin/setup_test_game index 076c4d8a7d..22e59dc81d 100644 --- a/bin/setup_test_game +++ b/bin/setup_test_game @@ -68,18 +68,6 @@ chmod +x bin/* # ######################################################################################### -echo -e "${ARES_INSTALL_TEXT} Run the configure script to set up basic game options." - -bin/configure - -# ######################################################################################### - -echo -e "${ARES_INSTALL_TEXT} Initialize the database." - -bin/wipedb - -# ######################################################################################### - echo -e "${ARES_INSTALL_TEXT} Installing Node for Ember." curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash diff --git a/engine/aresmush/connection.rb b/engine/aresmush/connection.rb index 9692b4a41c..750bc8a94d 100644 --- a/engine/aresmush/connection.rb +++ b/engine/aresmush/connection.rb @@ -18,6 +18,7 @@ def post_init @negotiator.send_naws_request @negotiator.send_charset_request + rescue Exception => e Global.logger.warn "Could not decode IP address. error=#{e} backtrace=#{e.backtrace[0,10]}" @ip_addr = "0.0.0.0" @@ -40,6 +41,7 @@ def connect_client(client) def send_data(msg) begin + ##telnet_debug(msg, "SEND") super msg rescue Exception => e Global.logger.warn "Could not send to connection: error=#{e} backtrace=#{e.backtrace[0,10]}." @@ -91,6 +93,8 @@ def receive_data(data) end parts.each do |part| + ##telnet_debug(part, "RECV") + next if !part part = "#{part.chomp}\n" input = @negotiator.handle_input(part) @@ -130,7 +134,7 @@ def strip_control_chars(data) stripped.gsub(/\^@/,"") end - def telnet_debug(part) + def telnet_debug(part, prefix) chars = part.split("").map { |c| c.ord } special = { @@ -170,7 +174,7 @@ def telnet_debug(part) end - puts "---------------" + puts "#{prefix} ---------------" puts part.inspect puts output.join(" ") diff --git a/plugins/website/wiki_exporter.rb b/plugins/website/wiki_exporter.rb index a9f1ca8513..fd882bf721 100644 --- a/plugins/website/wiki_exporter.rb +++ b/plugins/website/wiki_exporter.rb @@ -56,9 +56,8 @@ def self.export_index end end - def self.export_scenes + def self.build_scene_index(scenes) index = {} - scenes = Scene.shared_scenes.sort_by { |s| s.icdate }.reverse scenes.each do |s| puts "Parsing scene #{s.id} #{s.title}" @@ -79,6 +78,11 @@ def self.export_scenes f.puts render_template(File.join(template_path, 'scene.hbs'), { model: response }, s.date_title) end end + index + end + + def self.export_scenes + index = build_scene_index(Scene.shared_scenes.sort_by { |s| s.icdate }.reverse) File.open(File.join(export_path, "scenes.html"), 'w') do |f| @@ -135,7 +139,13 @@ def self.export_chars page_name = "#{c.name}.html" File.open(File.join(export_path, page_name), 'w') do |f| - template = ExportHandlebarsTemplate.new(File.join(template_path, 'char.hbs')) + + index = build_scene_index(c.scenes_starring.sort_by { |s| s.icdate }.reverse) + groups = index.group_by { |k, v| v[:type] } + scenes_by_type = groups.map { |k, v| { name: k, scenes: v.map { |page, data| data } }} + template = HandlebarsTemplate.new(File.join(AresMUSH.plugin_path, 'website', 'templates', 'wiki_scene_list.hbs')) + scenes = template.render(types: groups.keys, scenes_by_type: scenes_by_type ) + request = WebRequest.new( { args: { id: c.id } } ) response = Profile::CharacterRequestHandler.new.handle(request) @@ -168,6 +178,10 @@ def self.export_chars gallery = gallery.gsub("", "") profile << gallery profile << "" + + profile << '
' + profile << scenes + profile << "
" f.puts format_wiki_template(profile, c.name) From 455638de08bbe467c1306ae510b776f52ec6b3d1 Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Thu, 31 Jan 2019 23:30:43 -0500 Subject: [PATCH 15/16] Rename self. --- plugins/login/public/login_char.rb | 2 +- plugins/manage/commands/db/alias_cmd.rb | 2 +- plugins/manage/commands/db/rename_cmd.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/login/public/login_char.rb b/plugins/login/public/login_char.rb index 13fea9c503..685fa44534 100644 --- a/plugins/login/public/login_char.rb +++ b/plugins/login/public/login_char.rb @@ -39,7 +39,7 @@ def self.check_name(name, enactor = nil) found = Character.find_one_by_name(name) if (enactor) - return t('validation.char_name_taken') if (enactor != found) + return t('validation.char_name_taken') if (found && enactor != found) else return t('validation.char_name_taken') if found end diff --git a/plugins/manage/commands/db/alias_cmd.rb b/plugins/manage/commands/db/alias_cmd.rb index 077d78b183..be72c572a2 100644 --- a/plugins/manage/commands/db/alias_cmd.rb +++ b/plugins/manage/commands/db/alias_cmd.rb @@ -30,7 +30,7 @@ def handle end if (target.class == Character) - name_validation_msg = Character.check_name(self.alias) + name_validation_msg = Character.check_name(self.alias, target) else existing_exit = enactor_room.has_exit?(self.alias) if (existing_exit) diff --git a/plugins/manage/commands/db/rename_cmd.rb b/plugins/manage/commands/db/rename_cmd.rb index 3a9766a3bd..d8e8ca7bf9 100644 --- a/plugins/manage/commands/db/rename_cmd.rb +++ b/plugins/manage/commands/db/rename_cmd.rb @@ -23,7 +23,7 @@ def handle return end - name_validation_msg = model.class.check_name(self.name) + name_validation_msg = model.class.check_name(self.name, model) if (name_validation_msg) client.emit_failure(name_validation_msg) return From 566ddda55316db08ba0586d210293018138b546b Mon Sep 17 00:00:00 2001 From: Linda Naughton Date: Thu, 31 Jan 2019 23:42:21 -0500 Subject: [PATCH 16/16] Version bump. --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 1cbc812594..751b1ea05f 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.38 +0.39