source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
Arie/serveme
https://github.com/Arie/serveme
app/models/group.rb
Ruby
apache-2.0
97
master
1,774
# typed: strict # frozen_string_literal: true class Group < ActiveRecord::Base extend T::Sig DONATOR_GROUP = T.let(find_or_create_by(name: "Donators"), Group) ADMIN_GROUP = T.let(find_or_create_by(name: "Admins"), Group) LEAGUE_ADMIN_GROUP = T.let(find_or_create_by(name: "League Admins"), Group) CONFIG_ADMI...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/map_upload.rb
Ruby
apache-2.0
97
master
12,028
# typed: true # frozen_string_literal: true require "zip" class MapUpload < ActiveRecord::Base extend T::Sig belongs_to :user has_one_attached :file attr_accessor :maps validates_presence_of :user_id validate :validate_not_already_present validate :validate_file_is_a_bsp validate :validate_not_black...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/rgl_profile.rb
Ruby
apache-2.0
97
master
1,004
# typed: true # frozen_string_literal: true require "nokogiri" class RglProfile extend T::Sig attr_accessor :json sig { params(profile_body: String).void } def initialize(profile_body) @json = JSON.parse(profile_body) end sig { returns(String) } def league_name "RGL" end sig { returns(Str...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/server_info.rb
Ruby
apache-2.0
97
master
5,832
# typed: true # frozen_string_literal: true class ServerInfo extend T::Sig attr_accessor :server, :server_connection delegate :condenser, to: :server, prefix: false sig { params(server: T.any(Server, OpenStruct)).void } def initialize(server) @server = server @server_connection = conden...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/whitelist.rb
Ruby
apache-2.0
97
master
496
# typed: true # frozen_string_literal: true class Whitelist < ActiveRecord::Base extend T::Sig has_many :reservations, dependent: :nullify validates_presence_of :file sig { returns(T.any(ActiveRecord::Relation, ActiveRecord::Associations::CollectionProxy)) } def self.active where(hidden: false) end ...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/log_upload.rb
Ruby
apache-2.0
97
master
2,367
# typed: true # frozen_string_literal: true class LogUpload < ActiveRecord::Base extend T::Sig belongs_to :reservation validates_presence_of :reservation_id validates_presence_of :file_name, unless: :tftrue_upload? validate :validate_log_file_exists, unless: :tftrue_upload? sig { params(reservation_id:...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/player_statistic.rb
Ruby
apache-2.0
97
master
337
# typed: strict # frozen_string_literal: true class PlayerStatistic < ActiveRecord::Base belongs_to :reservation_player has_one :server, through: :reservation_player, autosave: false has_one :reservation, through: :reservation_player, autosave: false has_one :user, through: :reservation_player, aut...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/ozfortress_profile.rb
Ruby
apache-2.0
97
master
963
# typed: false # frozen_string_literal: true class OzfortressProfile DIVISION_TIERS = { "Premier" => 0, "High" => 1, "Intermediate" => 2, "Main" => 3, "Open" => 4, "Division 1" => 1, "Division 2" => 2, "Division 3" => 3, "Division 4" => 4, "Division 5" => 5 }.freeze attr_...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/statistic.rb
Ruby
apache-2.0
97
master
3,552
# typed: true # frozen_string_literal: true class Statistic extend T::Sig sig { returns(Hash) } def self.top_10_users Rails.cache.fetch "top_10_users_#{Date.current}", expires_in: 6.hours do if User.column_names.include?("reservations_count") top_users = User.includes(:groups) ...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/paypal_order.rb
Ruby
apache-2.0
97
master
2,243
# typed: true # frozen_string_literal: true class PaypalOrder < Order extend T::Sig include PayPal::SDK::REST sig { returns(T::Boolean) } def prepare set_redirect_urls add_transaction if payment.create update(status: "Redirected", payment_id: payment.id) else Sentry.capture_excepti...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/file_upload.rb
Ruby
apache-2.0
97
master
4,454
# typed: true # frozen_string_literal: true class FileUpload < ActiveRecord::Base extend T::Sig belongs_to :user has_many :server_uploads has_many :servers, through: :server_uploads validates_presence_of :user_id validate :validate_file_permissions mount_uploader :file, FileUploader sig { returns(T:...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/reservation_player.rb
Ruby
apache-2.0
97
master
7,605
# typed: true # frozen_string_literal: true class ReservationPlayer < ActiveRecord::Base extend T::Sig require "csv" require "ipaddr" belongs_to :reservation, optional: true has_one :server, through: :reservation, autosave: false belongs_to :user, primary_key: :uid, foreign_key: :steam_uid, optional: true...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/etf2l_profile.rb
Ruby
apache-2.0
97
master
2,279
# typed: true # frozen_string_literal: true class Etf2lProfile extend T::Sig attr_accessor :json sig { params(profile_body: String).void } def initialize(profile_body) @json = JSON.parse(profile_body) end sig { returns(String) } def league_name "ETF2L" end sig { returns(T.nilable(String)) ...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/remote_server.rb
Ruby
apache-2.0
97
master
1,044
# typed: true # frozen_string_literal: true class RemoteServer < Server extend T::Sig sig { params(output_filename: String, output_content: String).returns(T.nilable(T::Boolean)) } def write_configuration(output_filename, output_content) file = Tempfile.new("config_file") file.sync = true file.write(...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/league_ban.rb
Ruby
apache-2.0
97
master
557
# typed: strict # frozen_string_literal: true class LeagueBan extend T::Sig sig { params(steam_uid: T.any(String, Integer)).returns(T.nilable(T.any(Etf2lProfile, RglProfile))) } def self.fetch(steam_uid) profile = klass&.fetch(steam_uid) profile if profile&.banned? rescue Faraday::TimeoutError nil...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/file_upload_permission.rb
Ruby
apache-2.0
97
master
1,044
# typed: true # frozen_string_literal: true class FileUploadPermission < ActiveRecord::Base extend T::Sig belongs_to :user validates :allowed_paths, presence: true validate :validate_paths_format sig { params(path: String).returns(T.nilable(T::Boolean)) } def path_allowed?(path) return false if allo...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/server.rb
Ruby
apache-2.0
97
master
29,273
# typed: true # frozen_string_literal: true class Server < ActiveRecord::Base extend T::Sig include ApplicationHelper has_many :group_servers has_many :groups, through: :group_servers has_many :reservations has_many :current_reservations, -> { where(starts_at: ..Time.current).where(ends_at: Time.current.....
github
Arie/serveme
https://github.com/Arie/serveme
app/models/ip_lookup.rb
Ruby
apache-2.0
97
master
1,458
# typed: true # frozen_string_literal: true class IpLookup < ActiveRecord::Base attr_accessor :synced_from_region validates :ip, presence: true, uniqueness: true after_create_commit :schedule_cross_region_sync after_update_commit :schedule_cross_region_sync_on_false_positive_change after_update_commit :sch...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/user.rb
Ruby
apache-2.0
97
master
7,164
# typed: true # frozen_string_literal: true require "securerandom" class User < ActiveRecord::Base extend T::Sig devise :omniauthable, :rememberable, :trackable has_many :reservations has_many :log_uploads, through: :reservations has_many :group_users, -> { where(expires_at: nil).or(where(expires_at: Time....
github
Arie/serveme
https://github.com/Arie/serveme
app/models/whitelist_tf.rb
Ruby
apache-2.0
97
master
1,419
# typed: strict # frozen_string_literal: true class WhitelistTf < ActiveRecord::Base extend T::Sig validates_presence_of :tf_whitelist_id, :content validates_format_of :tf_whitelist_id, with: /\A[a-zA-Z0-9_-]*\z/ sig { params(tf_whitelist_id: String).returns(T::Boolean) } def self.download_and_save_whiteli...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/order.rb
Ruby
apache-2.0
97
master
2,219
# typed: true # frozen_string_literal: true class Order < ActiveRecord::Base extend T::Sig self.table_name = :paypal_orders belongs_to :product belongs_to :user has_one :voucher attr_accessor :source_type delegate :name, to: :product, allow_nil: true, prefix: true validates_presence_of :user_id, :p...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/rcon_ftp_server.rb
Ruby
apache-2.0
97
master
491
# typed: true # frozen_string_literal: true class RconFtpServer < RemoteServer extend T::Sig include FtpAccess sig { returns(T.nilable(T.any(String, T::Boolean))) } def restart Rails.logger.info("Attempting RCON restart of server #{name}") result = rcon_exec("_restart") result.is_a?(String) ? resu...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/reservation.rb
Ruby
apache-2.0
97
master
15,733
# typed: true # frozen_string_literal: true class Reservation < ActiveRecord::Base extend T::Sig enum :democheck_mode, { kick: "kick", warn: "warn", disable: "disable" }, default: :kick, prefix: :democheck belongs_to :user, counter_cache: true belongs_to :server, counter_cache: true belongs_to :server_conf...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/stac_detection.rb
Ruby
apache-2.0
97
master
254
# typed: true # frozen_string_literal: true class StacDetection < ActiveRecord::Base belongs_to :reservation belongs_to :stac_log, optional: true FILTERED_TYPES = /\ASilent ?Aim|Trigger ?Bot|CmdNum SPIKE|Aimsnap\z/i MIN_COUNT_THRESHOLD = 3 end
github
Arie/serveme
https://github.com/Arie/serveme
app/models/league_maps.rb
Ruby
apache-2.0
97
master
913
# typed: true # frozen_string_literal: true class LeagueMaps extend T::Sig attr_accessor :name, :maps def initialize(name:, maps:) @name = name @maps = maps end sig { returns(T::Array[LeagueMaps]) } def self.all grouped_league_maps + [ new(name: "All maps", maps: MapUpload.available_maps) ] ...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/cloud_server.rb
Ruby
apache-2.0
97
master
10,289
# typed: true # frozen_string_literal: true require "open3" class CloudServer < RemoteServer extend T::Sig include SshExecution CLOUD_STATUSES = %w[provisioning ssh_ready ready destroyed].freeze validates :cloud_status, inclusion: { in: CLOUD_STATUSES }, allow_nil: true belongs_to :cloud_reservation, clas...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/server_statistic.rb
Ruby
apache-2.0
97
master
378
# typed: strict # frozen_string_literal: true class ServerStatistic < ActiveRecord::Base extend T::Sig belongs_to :reservation belongs_to :server after_create :notify_discord private sig { void } def notify_discord return unless T.unsafe(reservation).discord_channel_id.present? DiscordReserv...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/ssh_server.rb
Ruby
apache-2.0
97
master
923
# typed: true # frozen_string_literal: true class SshServer < RemoteServer extend T::Sig include SshExecution sig { returns(T.nilable(Net::SSH::Connection::Session)) } def ssh @ssh ||= Net::SSH.start(ip, nil, timeout: 5, keepalive: true, keepalive_interval: 5, keepalive_maxcount: 2, bind_address: "0.0.0.0...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/product.rb
Ruby
apache-2.0
97
master
615
# typed: strict # frozen_string_literal: true class Product < ActiveRecord::Base extend T::Sig has_many :orders validates_presence_of :name, :price sig { returns(String) } def list_name "#{name} - #{price.round.to_i} #{currency}" end sig { returns(Integer) } def price_in_cents price.round * ...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/reservation_status.rb
Ruby
apache-2.0
97
master
1,233
# typed: true # frozen_string_literal: true class ReservationStatus < ActiveRecord::Base extend T::Sig belongs_to :reservation validates_presence_of :reservation_id after_create_commit -> { T.unsafe(self).broadcast_prepend_to T.unsafe(self).reservation } after_create_commit -> { T.unsafe(self).broadcast_re...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/concerns/steam_id_anonymizer.rb
Ruby
apache-2.0
97
master
1,008
# typed: true # frozen_string_literal: true module SteamIdAnonymizer extend ActiveSupport::Concern extend T::Sig class_methods do extend T::Sig sig { params(steam_uid: T.nilable(String)).returns(T.nilable(String)) } def anonymize_steam_id(steam_uid) return nil if steam_uid.blank? # Use...
github
Arie/serveme
https://github.com/Arie/serveme
app/models/concerns/globe_data.rb
Ruby
apache-2.0
97
master
1,670
# typed: false # frozen_string_literal: true module GlobeData extend ActiveSupport::Concern def globe_server_data(servers_with_players) permanent_servers = Server.active.not_cloud.where.not(latitude: nil, longitude: nil) servers_with_players_hash = servers_with_players.to_h { |data| [ data[:server].id, d...
github
Arie/serveme
https://github.com/Arie/serveme
app/helpers/application_helper.rb
Ruby
apache-2.0
97
master
2,695
# typed: false # frozen_string_literal: true module ApplicationHelper def donator? @donator ||= current_user&.donator? end def admin? @admin ||= current_user&.admin? end def used_free_server_count Reservation.current.where(server_id: Server.without_group).count + docker_hosts_used_count end ...
github
Arie/serveme
https://github.com/Arie/serveme
app/helpers/donators_helper.rb
Ruby
apache-2.0
97
master
1,076
# typed: false # frozen_string_literal: true module DonatorsHelper def format_exact_duration(start_time, end_time) return nil unless start_time && end_time duration_seconds = end_time - start_time # For short durations (less than a day), show hours and minutes if duration_seconds < 1.day hour...
github
Arie/serveme
https://github.com/Arie/serveme
app/helpers/rcon_helper.rb
Ruby
apache-2.0
97
master
924
# typed: true # frozen_string_literal: true module RconHelper def rcon_commands [ { command: "say", description: "Sends a message to all players", example: 'say "Hello World!"' }, { command: "kick", description: "Kicks a player", example: 'kick "Player Name"' }, { command: "kickid", description...
github
Arie/serveme
https://github.com/Arie/serveme
app/helpers/log_line_view_helper.rb
Ruby
apache-2.0
97
master
31,082
# typed: false # frozen_string_literal: true module LogLineViewHelper extend T::Sig include ERB::Util # Type alias for the formatted hash from LogLineFormatter FormattedLogLine = T.type_alias { T::Hash[Symbol, T.untyped] } # Team colors matching TF2 style TEAM_COLORS = { "red" => "#BD3B3B", "blue...
github
Arie/serveme
https://github.com/Arie/serveme
app/helpers/log_line_helper.rb
Ruby
apache-2.0
97
master
5,155
# typed: true # frozen_string_literal: true module LogLineHelper def clean_log_line(line) line .gsub(ip_regex, "0.0.0.0") .gsub(rcon_password_regex, 'rcon_password "*****"') .gsub(sv_password_regex, 'sv_password "*****"') .gsub(tv_password_regex, 'tv_password "*****"') .gsub(tftrue_...
github
Arie/serveme
https://github.com/Arie/serveme
app/helpers/reservations_helper.rb
Ruby
apache-2.0
97
master
5,967
# typed: false # frozen_string_literal: true module ReservationsHelper def find_servers_for_user @reservation = new_reservation @servers = free_servers @docker_hosts = free_docker_hosts render :find_servers end def find_servers_for_reservation @reservation = reservation @servers = free_s...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/custom_whitelist_validator.rb
Ruby
apache-2.0
97
master
829
# typed: true # frozen_string_literal: true module Reservations class CustomWhitelistValidator < ActiveModel::Validator def validate(record) return unless record.custom_whitelist_id.present? && record.custom_whitelist_id_changed? if record.custom_whitelist_id.match(/\A[a-zA-Z0-9_-]*\z/) try_...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/starts_not_too_far_in_future_validator.rb
Ruby
apache-2.0
97
master
339
# typed: true # frozen_string_literal: true module Reservations class StartsNotTooFarInFutureValidator < ActiveModel::Validator def validate(record) return unless record.starts_at && record.starts_at > 3.hours.from_now record.errors.add(:starts_at, "can't be this far in the future for non-donators")...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/starts_not_too_far_in_past_validator.rb
Ruby
apache-2.0
97
master
328
# typed: true # frozen_string_literal: true module Reservations class StartsNotTooFarInPastValidator < ActiveModel::Validator def validate(record) return unless record.starts_at && record.starts_at < 15.minutes.ago record.errors.add(:starts_at, "can't be more than 15 minutes in the past") end ...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/password_validator.rb
Ruby
apache-2.0
97
master
428
# typed: true # frozen_string_literal: true module Reservations class PasswordValidator < ActiveModel::Validator def validate(record) regex = /^[a-zA-Z!@\d\- #$^&*()_+}'|:<>?,.\[\]]*$/ options[:fields].each do |field| value = record.send(field) next if value.blank? || value.match?(reg...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/map_is_valid_validator.rb
Ruby
apache-2.0
97
master
458
# typed: true # frozen_string_literal: true module Reservations class MapIsValidValidator < ActiveModel::Validator def validate(record) return if record.first_map.blank? record.errors.add(:first_map, "you can't play this mode on our servers") if record.first_map.starts_with?(MapUpload.invalid_types_...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/user_is_available_validator.rb
Ruby
apache-2.0
97
master
370
# typed: true # frozen_string_literal: true module Reservations class UserIsAvailableValidator < ActiveModel::Validator def validate(record) return unless record.collides_with_own_reservation? msg = "you already have a reservation in this timeframe" record.errors.add(:starts_at, msg) rec...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/docker_host_capacity_validator.rb
Ruby
apache-2.0
97
master
537
# typed: true # frozen_string_literal: true module Reservations class DockerHostCapacityValidator < ActiveModel::Validator def validate(record) return unless record.server&.cloud_provider == "remote_docker" docker_host = DockerHost.find_by(id: record.server.cloud_location) return unless docker...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/only_one_future_reservation_per_user_validator.rb
Ruby
apache-2.0
97
master
431
# typed: true # frozen_string_literal: true module Reservations class OnlyOneFutureReservationPerUserValidator < ActiveModel::Validator def validate(record) return unless record.user future_reservations = record.user.reservations.future record.errors.add(:starts_at, "you can only have 1 planne...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/cloud_server_concurrency_validator.rb
Ruby
apache-2.0
97
master
529
# typed: true # frozen_string_literal: true module Reservations class CloudServerConcurrencyValidator < ActiveModel::Validator def validate(record) return unless record.user return unless record.server.is_a?(CloudServer) return if record.server.cloud_provider.in?(%w[docker remote_docker]) ...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/server_is_available_validator.rb
Ruby
apache-2.0
97
master
390
# typed: true # frozen_string_literal: true module Reservations class ServerIsAvailableValidator < ActiveModel::Validator def validate(record) return unless record.server && (record.collides_with_other_users_reservation? || record.collides_with_own_reservation_on_same_server?) record.errors.add(:ser...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/chronologicality_of_times_validator.rb
Ruby
apache-2.0
97
master
415
# typed: true # frozen_string_literal: true module Reservations class ChronologicalityOfTimesValidator < ActiveModel::Validator def validate(record) record.errors.add(:ends_at, "needs to be at least 30 minutes after start time") if validatable?(record) && (record.starts_at + 30.minutes) > record.ends_at ...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/length_of_reservation_validator.rb
Ruby
apache-2.0
97
master
576
# typed: true # frozen_string_literal: true module Reservations class LengthOfReservationValidator < ActiveModel::Validator def validate(record) return unless !record.extending && record.duration.round > maximum_reservation_length(record) duration_in_hours = (maximum_reservation_length(record) / 360...
github
Arie/serveme
https://github.com/Arie/serveme
app/validators/reservations/reservable_by_user_validator.rb
Ruby
apache-2.0
97
master
365
# typed: true # frozen_string_literal: true module Reservations class ReservableByUserValidator < ActiveModel::Validator def validate(record) return unless record.server_id.present? && !Server.active.reservable_by_user(record.user).map(&:id).include?(record.server_id) record.errors.add(:server_id, "...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/ai_command_handler.rb
Ruby
apache-2.0
97
master
25,452
# typed: false require "openai" class AiCommandHandler attr_reader :reservation REDIS_CONTEXT_TTL = 1.hour MAX_CONTEXT_HISTORY = 10 MAP_SEARCH_TOOL = { type: "function", function: { name: "find_maps", description: "Search for TF2 maps based on a query string. Returns a ranked list of mat...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/league_admin_ai_service.rb
Ruby
apache-2.0
97
master
21,629
# typed: false # frozen_string_literal: true class LeagueAdminAiService SYSTEM_PROMPT = <<~PROMPT.freeze You are an investigation assistant for TF2 league admins on serveme.tf. Your ONLY purpose is to help investigate players. If a message is not related to player investigation, politely decline. INVEST...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/proxy_detection_service.rb
Ruby
apache-2.0
97
master
1,242
# typed: false # frozen_string_literal: true class ProxyDetectionService class AllProvidersExhaustedError < StandardError; end PROVIDERS = [ { service: IpQualityScoreService, name: "IPQS" }, { service: FraudlogixService, name: "Fraudlogix" } ].freeze def self.check(ip) new.check(ip) end def ...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/server_metric.rb
Ruby
apache-2.0
97
master
4,593
# typed: true # frozen_string_literal: true class ServerMetric delegate :server, :map_name, :cpu, :traffic_in, :traffic_out, :uptime, :fps, to: :server_info attr_reader :server_info def initialize(server_info) @server_info = server_info return unless current_reservation save_server_statistics ...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/local_log_copier.rb
Ruby
apache-2.0
97
master
527
# typed: true # frozen_string_literal: true require "open3" class LocalLogCopier < LogCopier def copy_logs _, stderr, status = T.unsafe(Open3).capture3("LANG=ALL", "LC_ALL=C", "sed", "-i", "-r", 's/(\b[0-9]{1,3}\.){3}[0-9]{1,3}\b/0.0.0.0/g', *logs) Rails.logger.error("Failed to strip IPs from logs: #{stderr...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/live_match_stats.rb
Ruby
apache-2.0
97
master
16,549
# typed: false # frozen_string_literal: true class LiveMatchStats REDIS_PREFIX = "live_match" EXPIRY = 12.hours.to_i ANSI_REGEX = /\e\[\d*;?\d*m\[?K?/ MAP_START_REGEX = /Started map "/ class << self # Process a single raw log line (used by rebuild and standalone callers) def process_line(reservatio...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/string_sanitizer.rb
Ruby
apache-2.0
97
master
1,166
# typed: strict # frozen_string_literal: true # Service to sanitize strings by handling invalid UTF-8 bytes. # Replaces the deprecated ActiveSupport::Multibyte::Chars#tidy_bytes. # Implementation based on Rails' ActiveSupport::Multibyte::Unicode#tidy_bytes module StringSanitizer extend T::Sig # Sanitizes a string...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/rgl_api.rb
Ruby
apache-2.0
97
master
1,085
# typed: strict # frozen_string_literal: true class RglApi extend T::Sig sig { params(steam_uid: T.any(String, Integer)).returns(T.nilable(String)) } def self.profile(steam_uid) cached_profile_response(steam_uid) || fetch_profile(steam_uid) end sig { params(steam_uid: T.any(String, Integer)).returns(T....
github
Arie/serveme
https://github.com/Arie/serveme
app/services/discord_reservation_notifier.rb
Ruby
apache-2.0
97
master
6,206
# typed: false # frozen_string_literal: true class DiscordReservationNotifier # Flag mappings for Discord emoji FLAG_MAPPINGS = { "uk" => "gb", "en" => "england", "scotland" => "scotland", "europeanunion" => "eu" }.freeze def initialize(reservation) @reservation = reservation @server =...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/log_line_formatter.rb
Ruby
apache-2.0
97
master
6,579
# typed: true # frozen_string_literal: true class LogLineFormatter extend T::Sig TIMESTAMP_REGEX = /^L (\d{2}\/\d{2}\/\d{4} - \d{2}:\d{2}:\d{2}):/ # Patterns for sanitizing sensitive data IP_REGEX = /(\b[0-9]{1,3}\.){3}[0-9]{1,3}\b/ RCON_PASSWORD_REGEX = /rcon_password "\S+"/ SV_PASSWORD_REGEX = /sv_pass...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/map_search_service.rb
Ruby
apache-2.0
97
master
5,312
# typed: true # frozen_string_literal: true class MapSearchService extend T::Sig sig { params(query: String).void } def initialize(query) @query = query.downcase @terms = @query.split end sig { returns(T::Array[String]) } def search return [] if @query.empty? maps = MapUpload.available_m...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/current_players_service.rb
Ruby
apache-2.0
97
master
4,485
# typed: false # frozen_string_literal: true class CurrentPlayersService def self.all_servers_with_current_players recent_stats = PlayerStatistic.joins(reservation_player: { reservation: :server }) .where("player_statistics.created_at >= ?", 90.seconds.ago) ...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/ban_appeal_enrichment_service.rb
Ruby
apache-2.0
97
master
7,416
# typed: false # frozen_string_literal: true class BanAppealEnrichmentService REGIONS = { na: "https://direct.na.serveme.tf", sea: "https://direct.sea.serveme.tf", au: "https://direct.au.serveme.tf" }.freeze def initialize(discord_uid) @discord_uid = discord_uid end def collect # Step 1...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/i_am_feeling_lucky.rb
Ruby
apache-2.0
97
master
1,999
# typed: true # frozen_string_literal: true class IAmFeelingLucky attr_accessor :user def initialize(user) @user = user end def build_reservation new_reservation_attributes = { starts_at: starts_at, ends_at: ends_at } user.reservations.build(base_attributes.merge(new_reservation_a...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/collision_finder.rb
Ruby
apache-2.0
97
master
1,166
# typed: true # frozen_string_literal: true class CollisionFinder attr_reader :colliding_with, :collider def initialize(colliding_with, collider) @colliding_with = colliding_with @collider = collider end def colliding_reservations colliding = (front_rear_and_internal_collisions + overlap_co...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/cloudflare_dns_service.rb
Ruby
apache-2.0
97
master
2,801
# typed: false # frozen_string_literal: true class CloudflareDnsService class Error < StandardError; end BASE_URL = "https://api.cloudflare.com/client/v4" def create_a_record(hostname, ip) response = post("zones/#{zone_id}/dns_records", { type: "A", name: hostname, content: ip, prox...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/grant_perks.rb
Ruby
apache-2.0
97
master
373
# typed: true # frozen_string_literal: true class GrantPerks attr_accessor :product, :user def initialize(product, user) @product = product @user = user end def perform AddGroupMembership.new(product.days, user).perform AddGroupMembership.new(product.days, user, Group.private_user(user))...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/add_group_membership.rb
Ruby
apache-2.0
97
master
979
# typed: true # frozen_string_literal: true class AddGroupMembership attr_accessor :duration, :user, :group def initialize(days, user, group = Group.donator_group) @duration = days.days @user = user @group = group end def perform group_membership.expires_at = new_expiration_time gr...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/populate_resolved_ips_service.rb
Ruby
apache-2.0
97
master
949
# typed: true class PopulateResolvedIpsService def self.call new.call end def update_server(server) return if Rails.env.test? begin if server.ip.match?(/^\d+\.\d+\.\d+\.\d+$/) resolved_ip = server.ip else resolved_ip = lookup_hostname(server.ip) end server.up...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/ozfortress_api.rb
Ruby
apache-2.0
97
master
1,484
# typed: false # frozen_string_literal: true class OzfortressApi BASE_URL = "https://ozfortress.com/api/v1" class << self def steam_id_for_discord(discord_uid) return nil unless api_key.present? response = connection.get("users/discord_id/#{discord_uid}") return nil unless response.success...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/generate_order_voucher.rb
Ruby
apache-2.0
97
master
309
# typed: true # frozen_string_literal: true class GenerateOrderVoucher attr_accessor :order def initialize(order) @order = order end def perform voucher = Voucher.generate!(order.product) voucher.order = order voucher.created_by = order.user voucher.save! voucher end end
github
Arie/serveme
https://github.com/Arie/serveme
app/services/etf2l_api.rb
Ruby
apache-2.0
97
master
963
# typed: strict # frozen_string_literal: true class Etf2lApi extend T::Sig sig { params(steam_uid: T.any(String, Integer)).returns(T.nilable(String)) } def self.profile(steam_uid) cached_profile_response(steam_uid) || fetch_profile(steam_uid) end sig { params(steam_uid: T.any(String, Integer)).returns(...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/log_copier.rb
Ruby
apache-2.0
97
master
694
# typed: false # frozen_string_literal: true class LogCopier attr_accessor :reservation, :server, :logs def initialize(reservation, server) @server = server @reservation = reservation @logs = server.logs end def self.copy(reservation, server) server.log_copier_class...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/download_then_zip_file_creator.rb
Ruby
apache-2.0
97
master
1,821
# typed: true # frozen_string_literal: true require "open3" class DownloadThenZipFileCreator < ZipFileCreator def create_zip tmp_dir = Dir.mktmpdir begin reservation.status_update("Downloading logs and demos from server") server.copy_from_server(files_to_zip, tmp_dir) reservation.status_up...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/league_maps_sync_service.rb
Ruby
apache-2.0
97
master
7,126
# typed: true # frozen_string_literal: true require "net/http" require "uri" require "timeout" class LeagueMapsSyncService extend T::Sig GITHUB_RAW_URL = "https://raw.githubusercontent.com/Arie/serveme/refs/heads/master/config/league_maps.yml" CACHE_KEY = "league_maps_config" CACHE_EXPIRY = 24.hours sig {...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/user_search_service.rb
Ruby
apache-2.0
97
master
2,939
# typed: true # frozen_string_literal: true class UserSearchService extend T::Sig sig { params(input: T.nilable(String)).void } def initialize(input) @input = input.to_s.strip end sig { returns(T::Array[User]) } def search return [] if @input.blank? # For exact ID matches, return just that u...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/stac_logs_downloader.rb
Ruby
apache-2.0
97
master
2,120
# typed: false # frozen_string_literal: true class StacLogsDownloader attr_reader :reservation def initialize(reservation) @reservation = reservation end def download_and_process server_stac_logs = reservation.server.stac_logs return unless server_stac_logs.any? begin tmp_dir = Dir.mkt...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/log_streaming_service.rb
Ruby
apache-2.0
97
master
10,737
# typed: false # frozen_string_literal: true class LogStreamingService DEFAULT_CHUNK_SIZE = 1_000 MAX_CHUNK_SIZE = 5_000 # Cache for LogLineIndex instances, keyed by filename # Uses a simple LRU-style approach with max 20 cached indexes @@index_cache = {} @@index_cache_mutex = Mutex.new MAX_CACHED_INDEX...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/server_for_reservation_finder.rb
Ruby
apache-2.0
97
master
615
# typed: false # frozen_string_literal: true class ServerForReservationFinder attr_reader :reservation def initialize(reservation) @reservation = reservation end def servers colliding_reservations = CollisionFinder.new(Reservation.where(server_id: available_for_user), reservation).colliding_reservati...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/log_line_index.rb
Ruby
apache-2.0
97
master
3,408
# typed: false # frozen_string_literal: true # Provides efficient random access to log files by maintaining a byte-offset index. # The index is built incrementally and extends automatically as the file grows. # # Performance characteristics: # - Index building: O(n) for n lines, but only indexes what's needed # - Rand...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/find_players_in_log.rb
Ruby
apache-2.0
97
master
1,022
# typed: true # frozen_string_literal: true class FindPlayersInLog attr_accessor :log PLAYER_JOINED_REGEX = /L (?'time'.*): "(?'player_nick'.+)<(?'player_uid'\d+)><(?'player_steamid'(\[\S+\]|STEAM_\S+))><>" STEAM USERID validated/ def self.perform(log) finder = new(log) finder.parse_log finder.play...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/docker_host_reservation_creator.rb
Ruby
apache-2.0
97
master
2,311
# typed: false # frozen_string_literal: true class DockerHostReservationCreator attr_reader :user, :docker_host_id, :reservation_params def initialize(user:, docker_host_id:, reservation_params:) @user = user @docker_host_id = docker_host_id @reservation_params = reservation_params end def create...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/docker_host_setup_service.rb
Ruby
apache-2.0
97
master
10,600
# typed: false # frozen_string_literal: true class DockerHostSetupService DOCKER_IMAGE = "serveme/tf2-cloud-server:latest" attr_reader :docker_host def initialize(docker_host) @docker_host = docker_host end def create_vm raise "No cloud provider configured" unless docker_host.provider? raise "...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/scoreboard_stats.rb
Ruby
apache-2.0
97
master
907
# typed: false # frozen_string_literal: true class ScoreboardStats def self.from_match(reservation_match) players = reservation_match.match_players.map do |mp| { steam_uid: mp.steam_uid, name: mp.user&.nickname || mp.steam_uid.to_s, team: mp.team, tf2_class: mp.tf2_class, ...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/rcon_autocomplete.rb
Ruby
apache-2.0
97
master
17,162
# typed: false # frozen_string_literal: true class RconAutocomplete attr_accessor :query, :reservation def initialize(reservation = nil) @reservation = reservation end def autocomplete(query) @query = query.downcase # Return empty array for empty query return [] if @query.blank? # Check...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/scoreboard_connection_info.rb
Ruby
apache-2.0
97
master
1,397
# typed: false # frozen_string_literal: true class ScoreboardConnectionInfo def self.for_reservation(reservation) result = from_reservation_players(reservation) merge_player_statistics!(result, reservation) result end def self.from_reservation_players(reservation) result = {} reservation.re...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/user_finder_service.rb
Ruby
apache-2.0
97
master
1,622
# typed: true # frozen_string_literal: true class UserFinderService extend T::Sig sig { params(input: T.nilable(String)).void } def initialize(input) @input = input.to_s.strip end sig { returns(T.nilable(User)) } def find return nil if @input.blank? find_by_user_id || find_by_steam_id6...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/remote_log_copier.rb
Ruby
apache-2.0
97
master
526
# typed: true # frozen_string_literal: true class RemoteLogCopier < LogCopier def copy_logs zipfile_name_and_path = Rails.root.join("public", "uploads", reservation.zipfile_name) return unless File.exist?(zipfile_name_and_path) Zip::File.open(zipfile_name_and_path) do |zip| zip.each do |entry| ...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/friendly_password_generator.rb
Ruby
apache-2.0
97
master
1,994
# typed: true # frozen_string_literal: true class FriendlyPasswordGenerator extend T::Sig sig { returns(String) } def self.generate "#{left.sample}-#{right.sample}-#{rand(999)}" end def self.left %w[ australium blood collectors community decorated diamond f...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/command_validator.rb
Ruby
apache-2.0
97
master
708
# typed: true require "set" class CommandValidator def self.validate(command_string) return true unless command_string.present? unless defined?(ALLOWED_SERVER_COMMANDS) raise "CommandValidator Error: ALLOWED_SERVER_COMMANDS constant not defined. Initializer might have failed." end commands =...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/stac_log_processor.rb
Ruby
apache-2.0
97
master
4,654
# typed: true # frozen_string_literal: true class StacLogProcessor # Common regex patterns STEAM_ID_PATTERN = /StAC cached SteamID: (STEAM_\d+:\d+:\d+)/ TIMESTAMP_PATTERN = /<.*?>/ # Detection-specific patterns AIM_DETECTION_PATTERN = /\s*\[StAC\] ((?:Possible )?[Tt]riggerbot|SilentAim|Aimsnap) detection(?:...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/ip_quality_score_service.rb
Ruby
apache-2.0
97
master
1,575
# typed: false # frozen_string_literal: true class IpQualityScoreService BASE_URL = "https://www.ipqualityscore.com/api/json/ip" FRAUD_SCORE_THRESHOLD = 90 class QuotaExceededError < StandardError; end class ApiError < StandardError; end def self.check(ip) new.check(ip) end def check(ip) respo...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/player_announcement_service.rb
Ruby
apache-2.0
97
master
4,096
# typed: false # frozen_string_literal: true class PlayerAnnouncementService def self.build_info(steam_uid, ip, reserver: true) location_parts = build_location_parts(steam_uid, ip, reserver: reserver) history_parts = build_history_parts(steam_uid) league_parts = build_league_parts(steam_uid) alt_part...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/zip_file_creator.rb
Ruby
apache-2.0
97
master
753
# typed: true # frozen_string_literal: true class ZipFileCreator attr_accessor :reservation, :files_to_zip def initialize(reservation, files_to_zip) @reservation = reservation @files_to_zip = files_to_zip end def self.create(reservation, files_to_zip) server = reservation.ser...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/log_parser.rb
Ruby
apache-2.0
97
master
8,553
# typed: false # frozen_string_literal: true class LogParser MIN_MATCH_DURATION_SECONDS = 300 PlayerStats = Struct.new(:steam_uid, :name, :team_counts, :class_counts, :kills, :assists, :deaths, :damage, :damage_taken, :healing, :heals_received, :ubers, :drops, :airshots, :caps, keyword_init: true) do def team...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/discord_api_client.rb
Ruby
apache-2.0
97
master
5,861
# typed: false # frozen_string_literal: true class DiscordApiClient BASE_URL = "https://discord.com/api/v10" RATE_LIMIT_KEY_PREFIX = "discord_rate_limit" class << self def update_message(channel_id:, message_id:, embed:, components: nil) payload = { embeds: [ embed ] } payload[:components] = com...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/reservation_manager.rb
Ruby
apache-2.0
97
master
1,319
# typed: true # frozen_string_literal: true class ReservationManager extend T::Sig attr_reader :reservation delegate :server, to: :reservation, prefix: false def initialize(reservation) @reservation = reservation end def start_reservation return if server.is_a?(CloudServer) if previous_res...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/ban_appeal_user_info_service.rb
Ruby
apache-2.0
97
master
3,448
# typed: false # frozen_string_literal: true class BanAppealUserInfoService def initialize(steam_uid: nil, discord_uid: nil, admin_user:) @steam_uid = steam_uid @discord_uid = discord_uid @admin_user = admin_user end def collect user = find_user steam_uid = user&.uid || @steam_uid reser...
github
Arie/serveme
https://github.com/Arie/serveme
app/services/server_for_user_finder.rb
Ruby
apache-2.0
97
master
955
# typed: false # frozen_string_literal: true class ServerForUserFinder attr_reader :user, :starts_at, :ends_at def initialize(user, starts_at, ends_at) @user = user @starts_at = starts_at @ends_at = ends_at end def servers if (ends_at....