Class: ESM::Server
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ESM::Server
- Defined in:
- lib/esm/model/server.rb
Class Method Summary collapse
-
.correct_id(server_id) ⇒ Object
Checks to see if there are any corrections and provides them for the server id.
- .server_ids ⇒ Object
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #connection ⇒ Object
-
#execute_sqf!(code, execute_on: "server", player: nil, target: nil) ⇒ Any
Sends the provided SQF code to the linked connection.
-
#log_error(log_message) ⇒ Object
Sends a message to the client with a unique ID then logs the ID to the community's logging channel.
- #status_embed(status, reason: "") ⇒ Object
Class Method Details
.correct_id(server_id) ⇒ Object
Checks to see if there are any corrections and provides them for the server id
12 13 14 15 |
# File 'lib/esm/model/server.rb', line 12 def self.correct_id(server_id) checker = DidYouMean::SpellChecker.new(dictionary: server_ids) checker.correct(server_id) end |
Instance Method Details
#connected? ⇒ Boolean
21 22 23 24 25 |
# File 'lib/esm/model/server.rb', line 21 def connected? return ESM::Websocket.connected?(server_id) unless v2? # V1 !connection.nil? end |
#connection ⇒ Object
17 18 19 |
# File 'lib/esm/model/server.rb', line 17 def connection ESM::Connection::Server.client(public_id) end |
#execute_sqf!(code, execute_on: "server", player: nil, target: nil) ⇒ Any
Sends the provided SQF code to the linked connection.
@note: The result is ran through a JSON parser. The type may not be what you expect, but it will be consistent. For example, an empty hash map will always be represented by an empty array []
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/esm/model/server.rb', line 58 def execute_sqf!(code, execute_on: "server", player: nil, target: nil) = ESM::Message.new.set_type(:call) .set_data( function_name: "ESMs_command_sqf", execute_on: "server", code: code ) .(player:, target:) response = ().data.result # Check if it's JSON like result = ESM::JSON.parse(response.to_s) return response if result.nil? # Check to see if its a hashmap possible_hashmap = ESM::Arma::HashMap.from(result) return result if possible_hashmap.nil? result end |
#log_error(log_message) ⇒ Object
Sends a message to the client with a unique ID then logs the ID to the community's logging channel
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/esm/model/server.rb', line 30 def log_error() uuid = SecureRandom.uuid send_error("[#{uuid}] #{}") return if community.logging_channel_id.blank? ESM.bot.deliver( I18n.t("exceptions.extension_error", server_id: server_id, id: uuid), to: community.logging_channel_id ) end |
#status_embed(status, reason: "") ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/esm/model/server.rb', line 80 def (status, reason: "") ESM::Embed.build do |e| e.color = (status == :connected) ? :green : :red e.title = "#{server_name} (`#{server_id}`)" if status == :connected e.description = I18n.t("server_connected") else description = I18n.t("server_disconnect.base") description += "\n#{reason}" if reason.present? e.description = description e. = I18n.t("server_disconnect.footer") end e.add_field(name: I18n.t("uptime"), value: uptime, inline: true) end end |