Skip to content

Commit 529460f

Browse files
committed
Journal monitor refactoring (to make event definitions more self contained).
1 parent 8496187 commit 529460f

42 files changed

Lines changed: 1177 additions & 1078 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

EddiCore/EDDI.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ internal async Task<bool> eventLocationAsync( LocationEvent theEvent )
17171717
CurrentStarSystem.powerAcquisitionProgress = theEvent.powerAcquisitionProgress;
17181718
CurrentStarSystem.powerControlProgress = theEvent.powerControlProgress;
17191719
CurrentStarSystem.powerReinforcementControlPoints = theEvent.powerReinforcementControlPoints;
1720-
currentStarSystem.powerUnderminingControlPoints = theEvent.powerUnderminingControlPoints;
1720+
CurrentStarSystem.powerUnderminingControlPoints = theEvent.powerUnderminingControlPoints;
17211721

17221722
if ( theEvent.docked )
17231723
{
@@ -1764,6 +1764,10 @@ internal async Task<bool> eventLocationAsync( LocationEvent theEvent )
17641764
Environment = Constants.ENVIRONMENT_NORMAL_SPACE;
17651765
}
17661766

1767+
if ( theEvent.bodyType == BodyType.Planet )
1768+
{
1769+
theEvent.bodyType = CurrentStarSystem.bodies.FirstOrDefault( b => b.bodyId != null && b.bodyId == theEvent.bodyId )?.bodyType ?? theEvent.bodyType;
1770+
}
17671771
if ( theEvent.bodyname != null && ( theEvent.bodyType == BodyType.Moon ||
17681772
theEvent.bodyType == BodyType.Planet ) )
17691773
{
@@ -2374,6 +2378,14 @@ private async Task<bool> eventEnteredNormalSpaceAsync( EnteredNormalSpaceEvent t
23742378
await updateCurrentSystemAsync( theEvent.systemname, theEvent.systemAddress ).ConfigureAwait( false );
23752379
}
23762380

2381+
if ( theEvent.bodyType == BodyType.Planet )
2382+
{
2383+
theEvent.bodyType = CurrentStarSystem?.bodies
2384+
.FirstOrDefault( b => b.bodyId != null && b.bodyId == theEvent.bodyId )
2385+
?.bodyType ??
2386+
theEvent.bodyType;
2387+
}
2388+
23772389
if (theEvent.taxi is true)
23782390
{
23792391
Vehicle = Constants.VEHICLE_TAXI;

Events/CargoEvent.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using EddiDataDefinitions;
22
using System;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using Utilities;
56

67
namespace EddiEvents
@@ -29,5 +30,36 @@ public CargoEvent(DateTime timestamp, bool update, string vessel, List<CargoInfo
2930
this.inventory = inventory;
3031
this.cargocarried = cargocarried;
3132
}
33+
34+
public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad )
35+
{
36+
var inventory = new List<CargoInfoItem>();
37+
38+
var vessel = JsonParsing.getString(data, "Vessel");
39+
var cargocarried = JsonParsing.getOptionalInt(data, "Count") ?? 0;
40+
data.TryGetValue( "Inventory", out var val );
41+
if ( val != null )
42+
{
43+
var inventoryJson = (List<object>)val;
44+
foreach ( var cargoJson in inventoryJson.Cast<IDictionary<string, object>>() )
45+
{
46+
var name = JsonParsing.getString(cargoJson, "Name");
47+
var missionid = JsonParsing.getOptionalULong(cargoJson, "MissionID");
48+
var count = JsonParsing.getInt(cargoJson, "Count");
49+
var stolen = JsonParsing.getInt(cargoJson, "Stolen");
50+
var info = new CargoInfoItem(name, missionid, count, stolen);
51+
inventory.Add( info );
52+
}
53+
events.Add( new CargoEvent( timestamp, false, vessel, inventory, cargocarried ) { raw = line, fromLoad = fromLogLoad } );
54+
return true;
55+
}
56+
else if ( CargoInfo.TryFromFile( timestamp, vessel, cargocarried, out var info, out line ) && info != null )
57+
{
58+
events.Add( new CargoEvent( timestamp, true, vessel, info.Inventory, cargocarried ) { raw = line, fromLoad = fromLogLoad } );
59+
return true;
60+
}
61+
62+
return false;
63+
}
3264
}
3365
}

Events/ClearSaveEvent.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Utilities;
34

45
namespace EddiEvents
@@ -22,5 +23,13 @@ public ClearedSaveEvent(DateTime timestamp, string name, string frontierID) : ba
2223
this.name = name;
2324
this.frontierID = frontierID;
2425
}
26+
27+
public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad )
28+
{
29+
var name = JsonParsing.getString(data, "Name");
30+
var frontierID = JsonParsing.getString(data, "FID");
31+
events.Add( new ClearedSaveEvent( timestamp, name, frontierID ) { raw = line, fromLoad = fromLogLoad } );
32+
return true;
33+
}
2534
}
2635
}

Events/CommanderContinuedEvent.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using EddiDataDefinitions;
22
using System;
3+
using System.Collections.Generic;
34
using Utilities;
45

56
namespace EddiEvents
@@ -89,5 +90,57 @@ public CommanderContinuedEvent(DateTime timestamp, string commander, string fron
8990
this.gameversion = version;
9091
this.gamebuild = build;
9192
}
93+
94+
public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad )
95+
{
96+
var commander = JsonParsing.getString(data, "Commander");
97+
var frontierID = JsonParsing.getString(data, "FID");
98+
99+
// Active expansions
100+
var horizons = JsonParsing.getOptionalBool(data, "Horizons") ?? false; // Whether the account has the Horizons DLC
101+
var odyssey = JsonParsing.getOptionalBool(data, "Odyssey") ?? false; // Whether the account has the Odyssey DLC
102+
Logging.Info( $"Active expansions... Horizons: {horizons}, Odyssey: {odyssey}." );
103+
104+
var shipEDModel = JsonParsing.getString(data, "Ship"); // This describes a vehicle, whether ship or otherwise.
105+
// If on foot this may be a suit & if in an SRV then this may be an SRV.
106+
var shipName = JsonParsing.getString(data, "ShipName");
107+
var shipIdent = JsonParsing.getString(data, "ShipIdent");
108+
var shipId = JsonParsing.getOptionalLong(data, "ShipID"); // If on foot we'll get a suit ID here, which we need to treat as a long
109+
110+
// shipId may be null either if we're logging into CQC or if we're logging in while in an Apex taxi service
111+
if ( shipId == null )
112+
{
113+
if ( !string.IsNullOrEmpty( shipEDModel ) && shipEDModel.ToLowerInvariant().Contains( "taxi" ) )
114+
{
115+
// This is a taxi
116+
}
117+
else
118+
{
119+
// The LoadGame event for entering CQC contains no ship details.
120+
// We are entering CQC. Flag it back to EDDI so we can ignore everything that happens until
121+
// we're out of CQC again
122+
events.Add( new EnteredCQCEvent( timestamp, commander ) { raw = line, fromLoad = fromLogLoad } );
123+
return true;
124+
}
125+
}
126+
127+
var startedLanded = JsonParsing.getOptionalBool(data, "StartedLanded");
128+
var startDead = JsonParsing.getOptionalBool(data, "StartDead");
129+
130+
var credits = JsonParsing.getOptionalLong(data, "Credits") ?? 0;
131+
var loan = JsonParsing.getOptionalLong(data, "Loan") ?? 0;
132+
133+
var fuel = JsonParsing.getOptionalDecimal(data, "FuelLevel");
134+
var fuelCapacity = JsonParsing.getOptionalDecimal(data, "FuelCapacity");
135+
136+
var version = JsonParsing.getString(data, "gameversion")?.Trim();
137+
var build = JsonParsing.getString(data, "build")?.Trim();
138+
139+
var mode = GameMode.FromEDName(JsonParsing.getString(data, "GameMode"));
140+
var group = JsonParsing.getString(data, "Group"); // The name of the group, only if the mode is "Group"
141+
142+
events.Add( new CommanderContinuedEvent( timestamp, commander, frontierID, horizons, odyssey, shipId, shipEDModel, shipName, shipIdent, startedLanded, startDead, mode, group, credits, loan, fuel, fuelCapacity, version, build ) { raw = line, fromLoad = fromLogLoad } );
143+
return true;
144+
}
92145
}
93146
}

Events/CommanderLoadingEvent.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Utilities;
34

45
namespace EddiEvents
@@ -22,5 +23,13 @@ public CommanderLoadingEvent(DateTime timestamp, string name, string frontierID)
2223
this.name = name;
2324
this.frontierID = frontierID;
2425
}
26+
27+
public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad )
28+
{
29+
var name = JsonParsing.getString(data, "Name");
30+
var frontierID = JsonParsing.getString(data, "FID");
31+
events.Add( new CommanderLoadingEvent( timestamp, name, frontierID ) { raw = line, fromLoad = fromLogLoad } );
32+
return true;
33+
}
2534
}
2635
}

Events/CommanderProgressEvent.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Utilities;
34

45
namespace EddiEvents
@@ -45,5 +46,28 @@ public CommanderProgressEvent(DateTime timestamp, decimal combat, decimal trade,
4546
this.mercenary = mercenary;
4647
this.exobiologist = exobiologist;
4748
}
49+
50+
public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad )
51+
{
52+
data.TryGetValue( "Combat", out var val );
53+
decimal combat = (long?)val ?? 0;
54+
data.TryGetValue( "Trade", out val );
55+
decimal trade = (long?)val ?? 0;
56+
data.TryGetValue( "Explore", out val );
57+
decimal exploration = (long?)val ?? 0;
58+
data.TryGetValue( "CQC", out val );
59+
decimal cqc = (long?)val ?? 0;
60+
data.TryGetValue( "Empire", out val );
61+
decimal empire = (long?)val ?? 0;
62+
data.TryGetValue( "Federation", out val );
63+
decimal federation = (long?)val ?? 0;
64+
data.TryGetValue( "Soldier", out val );
65+
decimal soldier = (long?)val ?? 0;
66+
data.TryGetValue( "Exobiologist", out val );
67+
decimal exobiologist = (long?)val ?? 0;
68+
69+
events.Add( new CommanderProgressEvent( timestamp, combat, trade, exploration, cqc, empire, federation, soldier, exobiologist ) { raw = line, fromLoad = fromLogLoad } );
70+
return true;
71+
}
4872
}
4973
}

Events/CommanderRanksEvent.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using EddiDataDefinitions;
22
using System;
3+
using System.Collections.Generic;
34
using Utilities;
45

56
namespace EddiEvents
@@ -46,5 +47,28 @@ public CommanderRatingsEvent(DateTime timestamp, CombatRating combat, TradeRatin
4647
this.mercenary = mercenary;
4748
this.exobiologist = exobiologist;
4849
}
50+
51+
public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad )
52+
{
53+
data.TryGetValue( "Combat", out var val );
54+
var combat = CombatRating.FromRank((int)((long?)val ?? 0));
55+
data.TryGetValue( "Trade", out val );
56+
var trade = TradeRating.FromRank((int)((long?)val ?? 0));
57+
data.TryGetValue( "Explore", out val );
58+
var exploration = ExplorationRating.FromRank((int)((long?)val ?? 0));
59+
data.TryGetValue( "CQC", out val );
60+
var cqc = CQCRating.FromRank((int)((long?)val ?? 0));
61+
data.TryGetValue( "Empire", out val );
62+
var empire = EmpireRating.FromRank((int)((long?)val ?? 0));
63+
data.TryGetValue( "Federation", out val );
64+
var federation = FederationRating.FromRank((int)((long?)val ?? 0));
65+
data.TryGetValue( "Soldier", out val );
66+
var mercenary = MercenaryRating.FromRank((int)((long?)val ?? 0));
67+
data.TryGetValue( "Exobiologist", out val );
68+
var exobiologist = ExobiologistRating.FromRank((int)((long?)val ?? 0));
69+
70+
events.Add( new CommanderRatingsEvent( timestamp, combat, trade, exploration, cqc, empire, federation, mercenary, exobiologist ) { raw = line, fromLoad = fromLogLoad } );
71+
return true;
72+
}
4973
}
5074
}

Events/CommanderReputationEvent.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Utilities;
34

45
namespace EddiEvents
@@ -29,5 +30,15 @@ public CommanderReputationEvent(DateTime timestamp, decimal empire, decimal fede
2930
this.independent = independent;
3031
this.alliance = alliance;
3132
}
33+
34+
public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad )
35+
{
36+
var empire = JsonParsing.getOptionalDecimal(data, "Empire") ?? 0;
37+
var federation = JsonParsing.getOptionalDecimal(data, "Federation") ?? 0;
38+
var independent = JsonParsing.getOptionalDecimal(data, "Independent") ?? 0;
39+
var alliance = JsonParsing.getOptionalDecimal(data, "Alliance") ?? 0;
40+
events.Add( new CommanderReputationEvent( timestamp, empire, federation, independent, alliance ) { raw = line, fromLoad = fromLogLoad } );
41+
return true;
42+
}
3243
}
3344
}

Events/CommanderStartedEvent.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Utilities;
34

45
namespace EddiEvents
@@ -26,5 +27,14 @@ public CommanderStartedEvent(DateTime timestamp, string name, string frontierID,
2627
this.frontierID = frontierID;
2728
this.package = package;
2829
}
30+
31+
public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad )
32+
{
33+
var name = JsonParsing.getString(data, "Name");
34+
var frontierID = JsonParsing.getString(data, "FID");
35+
var package = JsonParsing.getString(data, "Package");
36+
events.Add( new CommanderStartedEvent( timestamp, name, frontierID, package ) { raw = line, fromLoad = fromLogLoad } );
37+
return true;
38+
}
2939
}
3040
}

Events/DestinationArrivedEvent.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using EddiDataDefinitions;
22
using System;
3+
using System.Collections.Generic;
4+
using System.Text.RegularExpressions;
35
using Utilities;
46

57
namespace EddiEvents
@@ -40,5 +42,48 @@ public DestinationArrivedEvent ( DateTime timestamp, string invariantName, strin
4042
this.threat = threat ?? 0;
4143
this.marketID = marketID;
4244
}
45+
46+
public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad )
47+
{
48+
if ( fromLogLoad ) { return true; } // Skip handling this during log loading
49+
50+
// "Type" may be either a signal source or proper name.
51+
// If proper name, it might be a fleet carrier with both name and ID.
52+
var type = JsonParsing.getString( data, "Type" );
53+
var typeLocalized = JsonParsing.getString( data, "Type_Localised" );
54+
var threat = JsonParsing.getOptionalInt( data, "Threat" ) ?? 0; // Typically 0 except for USS drops.
55+
var marketID = JsonParsing.getOptionalLong( data, "MarketID" );
56+
57+
if ( type.StartsWith( "$" ) )
58+
{
59+
// Symbolic signal source name. Prefer our own localization and fallback using the provided localization string if needed.
60+
var signalSource = SignalSource.FromEDName( type );
61+
if ( signalSource != null )
62+
{
63+
signalSource.fallbackLocalizedName = typeLocalized;
64+
type = signalSource.invariantName;
65+
typeLocalized = signalSource.localizedName;
66+
}
67+
}
68+
else
69+
{
70+
// Destination might be a fleet carrier with name and carrier ID in a single string.
71+
// Check and break apart if needed.
72+
var fleetCarrierRegex = new Regex( "^(.+)(?> )([A-Za-z0-9]{3}-[A-Za-z0-9]{3})$" );
73+
if ( string.IsNullOrEmpty( typeLocalized ) && fleetCarrierRegex.IsMatch( type ) )
74+
{
75+
// Fleet carrier names include both the carrier name and carrier ID, we need to separate them
76+
var fleetCarrierParts = fleetCarrierRegex.Matches( type )[ 0 ].Groups;
77+
if ( fleetCarrierParts.Count == 3 )
78+
{
79+
type = fleetCarrierParts[ 2 ].Value;
80+
typeLocalized = fleetCarrierParts[ 1 ].Value;
81+
}
82+
}
83+
}
84+
85+
events.Add( new DestinationArrivedEvent( timestamp, type, typeLocalized, threat, marketID ) { raw = line, fromLoad = false } );
86+
return true;
87+
}
4388
}
4489
}

0 commit comments

Comments
 (0)