Skip to content

Commit

Permalink
Restrict traits from being changed after approval.
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnfaraday committed Jul 2, 2021
1 parent 010e478 commit 9a04455
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Note: If you are using _just_ traits (without any other skills system), you prob

## Uninstalling

Removing the plugin requires some code fiddling. See [Uninstalling Plugins](https://www.aresmush.com/tutorials/code/extras.html#uninstalling-plugins).
Removing the plugin requires some code fiddling. See [Uninstalling Traits](Uninstalling.md).

## License

Expand Down
40 changes: 40 additions & 0 deletions Uninstalling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Uninstalling Traits

Ares plugins plug IN easily, but taking them out requires a bit of code fiddling.

1. Open the [tinker](https://aresmush.com/tutorials/code/tinker.html#how-to-tinker) page (Admin -> Tinker) in the web portal with a coder character.

2. Copy/paste the following to the tinker file, **right below `module AresMUSH`**. This will let us clear out the database fields.

```
class Character
attribute :traits
end
```

3. Add the following code to the `handle` method of the tinker file.

```
begin
Traits.uninstall_plugin
Manage.uninstall_plugin("traits")
client.emit_success "Plugin uninstalled."
rescue Exception => e
Global.logger.debug "Error loading plugin: #{e} backtrace=#{e.backtrace[0,10]}"
client.emit_failure "Error uninstalling plugin: #{e}"
end
```

4. Click "Save" on the tinker page.

5. Switch to a game client window and run the `tinker` command.

6. Switch back to the web portal tinker page and click "Reset".

7. Manually remove all plugin's files from your server (and GitHub fork, if applicable), including:
* aresmush/plugins/traits
* aresmush/game/config/traits.yml
* Web portal files - See the /webportal folder in this repo for a specific list of files.

8. Deploy the website.
20 changes: 13 additions & 7 deletions plugin/commands/remove_trait_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ def required_args

def handle
ClassTargetFinder.with_a_character(self.name, client, enactor) do |model|
if (enactor.name == model.name || Chargen.can_approve?(enactor))
traits = model.traits || {}
traits.delete self.trait_name
model.update(traits: traits)
client.emit_success t('traits.trait_removed')
else
if (!Traits.can_edit_traits?(enactor, model))
client.emit_failure t('dispatcher.not_allowed')
return
end


error = Traits.check_traits_locked(enactor, model)
if (error)
client.emit_failure error
return
end

traits = model.traits || {}
traits.delete self.trait_name
model.update(traits: traits)
client.emit_success t('traits.trait_removed')
end
end
end
Expand Down
20 changes: 13 additions & 7 deletions plugin/commands/set_trait_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ def required_args

def handle
ClassTargetFinder.with_a_character(self.name, client, enactor) do |model|
if (enactor.name == model.name || Chargen.can_approve?(enactor))
traits = model.traits || {}
traits[self.trait_name] = self.description
model.update(traits: traits)
client.emit_success t('traits.trait_set')
else
if (!Traits.can_edit_traits?(enactor, model))
client.emit_failure t('dispatcher.not_allowed')
return
end


error = Traits.check_traits_locked(enactor, model)
if (error)
client.emit_failure error
return
end

traits = model.traits || {}
traits[self.trait_name] = self.description
model.update(traits: traits)
client.emit_success t('traits.trait_set')
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions plugin/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module AresMUSH
module Traits
def self.can_edit_traits?(enactor, model)
enactor.name == model.name || Traits.can_manage_traits?(enactor)
end

def self.can_manage_traits?(enactor)
Chargen.can_approve?(enactor)
end

def self.check_traits_locked(enactor, model)
return nil if Traits.can_manage_traits?(enactor)
return Chargen.check_chargen_locked(model)
end

def self.uninstall_plugin
Character.all.each do |c|
c.update(traits: nil)
end
end

end
end

0 comments on commit 9a04455

Please sign in to comment.