Skip to content

Instantly share code, notes, and snippets.

@andiskiy
Created April 1, 2020 14:35
Show Gist options
  • Save andiskiy/2861322eda75abbf06b120c1ba977a4e to your computer and use it in GitHub Desktop.
Save andiskiy/2861322eda75abbf06b120c1ba977a4e to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
module Rcon
class Base
attr_reader :host, :game_session
class << self
def call(game_session)
new(game_session).call
end
end
def initialize(game_session)
@host = game_session.host
@game_session = game_session
connect
end
private
def connect
return if source_server.rcon_authenticated?
begin
source_server.rcon_auth(host.password)
rescue StandardError => e
Log.create(model: 202,
item: host.id,
text: "Steam Condenser Error! Authenticate fail. Message: #{e}")
end
end
def exec(command)
source_server.rcon_exec(command)
rescue StandardError => e
Log.create(model: 202,
item: host.id,
text: "Steam Condenser Error! RCON_exec:#{command}. Ошибка: #{e}")
false
end
def map
@map ||= game_session.map
end
def match
@match ||= game_session.match
end
def source_server
@source_server ||= SourceServer.new(host.ip)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment