diff --git a/plugins/jobs/events/char_connected_event_handler.rb b/plugins/jobs/events/char_connected_event_handler.rb deleted file mode 100644 index 3ae1632314..0000000000 --- a/plugins/jobs/events/char_connected_event_handler.rb +++ /dev/null @@ -1,19 +0,0 @@ -module AresMUSH - module Jobs - class CharConnectedEventHandler - def on_event(event) - char = Character[event.char_id] - client = event.client - - return if !Jobs.can_access_jobs?(char) - - Global.dispatcher.queue_timer(2, "Jobs", client) do - jobs = Jobs.filtered_jobs(char) - paginator = Paginator.paginate(jobs, 1, 20) - template = JobsListTemplate.new(char, paginator) - client.emit template.render - end - end - end - end -end \ No newline at end of file diff --git a/plugins/login/commands/onconnect_cmd.rb b/plugins/login/commands/onconnect_cmd.rb new file mode 100644 index 0000000000..9a84e0d85d --- /dev/null +++ b/plugins/login/commands/onconnect_cmd.rb @@ -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 diff --git a/plugins/login/events/char_connected_event_handler.rb b/plugins/login/events/char_connected_event_handler.rb index 1fc7001721..e2df634c1a 100644 --- a/plugins/login/events/char_connected_event_handler.rb +++ b/plugins/login/events/char_connected_event_handler.rb @@ -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 diff --git a/plugins/login/help/en/onconnect.md b/plugins/login/help/en/onconnect.md new file mode 100644 index 0000000000..aa685d09e0 --- /dev/null +++ b/plugins/login/help/en/onconnect.md @@ -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 ` \ No newline at end of file diff --git a/plugins/login/locales/locale_en.yml b/plugins/login/locales/locale_en.yml index 896230ba03..a63ba1e51e 100644 --- a/plugins/login/locales/locale_en.yml +++ b/plugins/login/locales/locale_en.yml @@ -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}" \ No newline at end of file + 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." \ No newline at end of file diff --git a/plugins/login/login.rb b/plugins/login/login.rb index 178491c839..882ebb7333 100644 --- a/plugins/login/login.rb +++ b/plugins/login/login.rb @@ -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" @@ -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" @@ -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 diff --git a/plugins/login/public/login_char.rb b/plugins/login/public/login_char.rb index cb1158f52f..093c300112 100644 --- a/plugins/login/public/login_char.rb +++ b/plugins/login/public/login_char.rb @@ -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