Skip to content

Commit

Permalink
Adding command for connect commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnfaraday committed May 23, 2018
1 parent 2411537 commit 2f88ac1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 22 deletions.
19 changes: 0 additions & 19 deletions plugins/jobs/events/char_connected_event_handler.rb

This file was deleted.

28 changes: 28 additions & 0 deletions plugins/login/commands/onconnect_cmd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module AresMUSH
module Login
class OnConnectCmd
include CommandHandler

attr_accessor :commands

def parse_args
self.commands = list_arg(cmd.args, ",") || []
end

def check_num_commands
return t('login.too_many_onconnect_commands') if self.commands.count > 5
return nil
end

def handle
if (self.commands.empty?)
enactor.update(onconnect_commands: [])
client.emit_success t('login.onconnect_commands_cleared')
else
enactor.update(onconnect_commands: self.commands)
client.emit_success t('login.onconnect_commands_set')
end
end
end
end
end
8 changes: 8 additions & 0 deletions plugins/login/events/char_connected_event_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def on_event(event)
template = NoticesTemplate.new(char)
client.emit template.render
end

if (char.onconnect_commands)
char.onconnect_commands.each_with_index do |cmd, i|
Global.dispatcher.queue_timer(2 + i, "Login commands", client) do
Global.dispatcher.queue_command(client, Command.new(cmd))
end
end
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions plugins/login/help/en/onconnect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
toc: Miscellaneous
summary: Commands to run when you connect.
---

You always see the notices screen when you connect, which shows you a summary of what's new on the game. You can optionally run additional commands (commonly 'where' or 'jobs' when you first connect).

`onconnect <comma-separated list of commands to run>`
6 changes: 5 additions & 1 deletion plugins/login/locales/locale_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ en:
cant_boot_admin: "Nice try. You can't boot an admin character!"

boot_title: "Character Booted"
boot_message: "%{booter} has booted %{bootee}. Reason:%R%R%{reason}"
boot_message: "%{booter} has booted %{bootee}. Reason:%R%R%{reason}"

onconnect_commands_set: "Commands to run on connect set."
onconnect_commands_cleared: "Commands to run on connect cleared."
too_many_onconnect_commands: "You can only set five startup commands."
6 changes: 4 additions & 2 deletions plugins/login/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def self.get_cmd_handler(client, cmd, enactor)
return AliasCmd
when "boot"
return BootCmd
when "connect"
return ConnectCmd
when "create"
return CreateCmd
when "email"
Expand All @@ -35,6 +37,8 @@ def self.get_cmd_handler(client, cmd, enactor)
end
when "last"
return LastCmd
when "onconnect"
return OnConnectCmd
when "password"
case cmd.switch
when "reset"
Expand All @@ -53,8 +57,6 @@ def self.get_cmd_handler(client, cmd, enactor)
end
when "tour"
return TourCmd
when "connect"
return ConnectCmd
when "watch"
return WatchCmd
end
Expand Down
2 changes: 2 additions & 0 deletions plugins/login/public/login_char.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Character
attribute :last_hostname
attribute :last_on, :type => DataType::Time

attribute :onconnect_commands, :type => DataType::Array, :default => []

def is_guest?
self.has_any_role?(Login.guest_role)
end
Expand Down

0 comments on commit 2f88ac1

Please sign in to comment.