Class: TF2LineParser::Events::Event
- Inherits:
-
Object
- Object
- TF2LineParser::Events::Event
- Defined in:
- lib/tf2_line_parser/events/event.rb
Direct Known Subclasses
BuiltObject, CaptureBlock, ChargeDeployed, ChargeEnded, ChargeReady, Chat, Connect, ConsoleSay, Damage, Disconnect, EmptyUber, EnteredGame, FirstHealAfterSpawn, Heal, IntermissionWinLimit, KilledObject, LostUberAdvantage, MedicDeath, MedicDeathEx, PVPEvent, PlayerActionEvent, PlayerExtinguished, PointCapture, PositionReport, RconCommand, RoundEventWithVariables, RoundEventWithoutVariables, Score, Unknown
Instance Attribute Summary collapse
-
#airshot ⇒ Object
Returns the value of attribute airshot.
-
#cap_name ⇒ Object
Returns the value of attribute cap_name.
-
#cap_number ⇒ Object
Returns the value of attribute cap_number.
-
#customkill ⇒ Object
Returns the value of attribute customkill.
-
#healing ⇒ Object
Returns the value of attribute healing.
-
#item ⇒ Object
Returns the value of attribute item.
-
#length ⇒ Object
Returns the value of attribute length.
-
#message ⇒ Object
Returns the value of attribute message.
-
#method ⇒ Object
Returns the value of attribute method.
-
#player ⇒ Object
Returns the value of attribute player.
-
#role ⇒ Object
Returns the value of attribute role.
-
#score ⇒ Object
Returns the value of attribute score.
-
#target ⇒ Object
Returns the value of attribute target.
-
#team ⇒ Object
Returns the value of attribute team.
-
#time ⇒ Object
Returns the value of attribute time.
-
#type ⇒ Object
Returns the value of attribute type.
-
#ubercharge ⇒ Object
Returns the value of attribute ubercharge.
-
#unknown ⇒ Object
Returns the value of attribute unknown.
-
#value ⇒ Object
Returns the value of attribute value.
-
#weapon ⇒ Object
Returns the value of attribute weapon.
Class Method Summary collapse
- .parse_player_section(section) ⇒ Object
- .parse_target_section(section) ⇒ Object
- .regex_cap ⇒ Object
- .regex_console ⇒ Object
- .regex_message ⇒ Object
- .regex_player ⇒ Object
- .regex_results(matched_line) ⇒ Object
- .regex_target ⇒ Object
- .regex_time ⇒ Object
- .time_format ⇒ Object
- .types ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#airshot ⇒ Object
Returns the value of attribute airshot.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def airshot @airshot end |
#cap_name ⇒ Object
Returns the value of attribute cap_name.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def cap_name @cap_name end |
#cap_number ⇒ Object
Returns the value of attribute cap_number.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def cap_number @cap_number end |
#customkill ⇒ Object
Returns the value of attribute customkill.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def customkill @customkill end |
#healing ⇒ Object
Returns the value of attribute healing.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def healing @healing end |
#item ⇒ Object
Returns the value of attribute item.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def item @item end |
#length ⇒ Object
Returns the value of attribute length.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def length @length end |
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def @message end |
#method ⇒ Object
Returns the value of attribute method.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def method @method end |
#player ⇒ Object
Returns the value of attribute player.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def player @player end |
#role ⇒ Object
Returns the value of attribute role.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def role @role end |
#score ⇒ Object
Returns the value of attribute score.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def score @score end |
#target ⇒ Object
Returns the value of attribute target.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def target @target end |
#team ⇒ Object
Returns the value of attribute team.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def team @team end |
#time ⇒ Object
Returns the value of attribute time.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def time @time end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def type @type end |
#ubercharge ⇒ Object
Returns the value of attribute ubercharge.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def ubercharge @ubercharge end |
#unknown ⇒ Object
Returns the value of attribute unknown.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def unknown @unknown end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def value @value end |
#weapon ⇒ Object
Returns the value of attribute weapon.
6 7 8 |
# File 'lib/tf2_line_parser/events/event.rb', line 6 def weapon @weapon end |
Class Method Details
.parse_player_section(section) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/tf2_line_parser/events/event.rb', line 72 def self.parse_player_section(section) return [nil, nil, nil, nil] unless section # Find all <...> groups in the section parts = section.scan(/<([^>]*)>/) return [nil, nil, nil, nil] if parts.length < 2 # For the cheeky name tests, we need to find the last complete set of uid/steamid/team # Look for the pattern: <uid><steamid><team> at the end if parts.length >= 3 # Try to find the last complete set of 3 groups # Start from the end and work backwards last_valid_set = nil (parts.length - 2).downto(0) do |i| if i + 2 < parts.length uid = parts[i][0] steamid = parts[i + 1][0] team = parts[i + 2][0] # Check if this looks like a valid set (uid is numeric, steamid looks like steam id, team is valid) if uid.match?(/^\d+$/) && (steamid.start_with?('STEAM_') || steamid.start_with?('[U:')) && ['Red', 'Blue', 'Unassigned', 'Spectator', ''].include?(team) # This looks like a valid player info set last_valid_set = [i, uid, steamid, team] break # Take the last (rightmost) valid set end end end if last_valid_set i, uid, steamid, team = last_valid_set # The name is everything before the first <...> group of this set uid_start = section.index("<#{uid}>") if uid_start name = section[0...uid_start] return [name, uid, steamid, team] end end end # Handle cases with 2 or 3 groups (normal case) if parts.length == 2 # Only uid and steamid, no team uid = parts[0][0] steamid = parts[1][0] team = "" else # uid, steamid, and team uid = parts[-3][0] steamid = parts[-2][0] team = parts[-1][0] end # The name is everything before the first <...> group name_end = section.index("<#{uid}>") return [nil, nil, nil, nil] unless name_end name = section[0...name_end] [name, uid, steamid, team] end |
.parse_target_section(section) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/tf2_line_parser/events/event.rb', line 133 def self.parse_target_section(section) return [nil, nil, nil, nil] unless section # Same logic as player but for targets parts = section.scan(/<([^>]*)>/) return [nil, nil, nil, nil] if parts.length < 2 # Handle cases with 2 or 3 groups if parts.length == 2 # Only uid and steamid, no team uid = parts[0][0] steamid = parts[1][0] team = "" else # uid, steamid, and team uid = parts[-3][0] steamid = parts[-2][0] team = parts[-1][0] end # The name is everything before the first <...> group name_end = section.index("<#{uid}>") return [nil, nil, nil, nil] unless name_end name = section[0...name_end] [name, uid, steamid, team] end |
.regex_cap ⇒ Object
25 26 27 |
# File 'lib/tf2_line_parser/events/event.rb', line 25 def self.regex_cap @regex_cap ||= '\(cp "(?\'cp_number\'\d+)"\) \(cpname "(?\'cp_name\'[^"]*)"' end |
.regex_console ⇒ Object
29 30 31 |
# File 'lib/tf2_line_parser/events/event.rb', line 29 def self.regex_console @regex_console ||= '"Console<0><Console><Console>"' end |
.regex_message ⇒ Object
33 34 35 |
# File 'lib/tf2_line_parser/events/event.rb', line 33 def self. @regex_message ||= '"(?\'message\'.*)"' end |
.regex_player ⇒ Object
17 18 19 |
# File 'lib/tf2_line_parser/events/event.rb', line 17 def self.regex_player @regex_player ||= /"(?<player_section>.*?)"/ end |
.regex_results(matched_line) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/tf2_line_parser/events/event.rb', line 45 def self.regex_results(matched_line) out = [] attributes.each do |attribute| case attribute when :player_section if matched_line['player_section'] out.concat(parse_player_section(matched_line['player_section'])) else out.concat([nil, nil, nil, nil]) end when :target_section if matched_line['target_section'] out.concat(parse_target_section(matched_line['target_section'])) else out.concat([nil, nil, nil, nil]) end else out << matched_line[attribute] end end out end |
.regex_target ⇒ Object
21 22 23 |
# File 'lib/tf2_line_parser/events/event.rb', line 21 def self.regex_target @regex_target ||= /"(?<target_section>.*?)"/ end |
.regex_time ⇒ Object
13 14 15 |
# File 'lib/tf2_line_parser/events/event.rb', line 13 def self.regex_time @regex_time ||= 'L (?\'time\'\\d{2}/\\d{2}/\\d{4} - \\d{2}:\\d{2}:\\d{2}):' end |
.time_format ⇒ Object
9 10 11 |
# File 'lib/tf2_line_parser/events/event.rb', line 9 def self.time_format @time_format ||= '%m/%d/%Y - %T' end |
.types ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/tf2_line_parser/events/event.rb', line 37 def self.types # ordered by how common the messages are @types ||= [ShotFired, ShotHit, PositionReport, HeadshotDamage, Airshot, Damage, AirshotHeal, Heal, PickupItem, Assist, Kill, CaptureBlock, PointCapture, ChargeDeployed, MedicDeath, MedicDeathEx, EmptyUber, ChargeReady, ChargeEnded, FirstHealAfterSpawn, LostUberAdvantage, BuiltObject, PlayerExtinguished, JoinedTeam, EnteredGame, RoleChange, Spawn, Suicide, KilledObject, Say, TeamSay, Domination, Revenge, RoundWin, CurrentScore, RoundLength, RoundStart, RoundSetupBegin, RoundSetupEnd, MiniRoundStart, MiniRoundSelected, MiniRoundLength, MiniRoundWin, WorldIntermissionWinLimit, IntermissionWinLimit, Connect, Disconnect, RconCommand, ConsoleSay, MatchEnd, FinalScore, RoundStalemate, Unknown].freeze end |
Instance Method Details
#parse_time(time_string) ⇒ Object
68 69 70 |
# File 'lib/tf2_line_parser/events/event.rb', line 68 def parse_time(time_string) Time.strptime(time_string, Event.time_format) end |