Skip to content

Commit 1b241e5

Browse files
committed
Added Discord support
1 parent d6615a7 commit 1b241e5

File tree

3 files changed

+208
-94
lines changed

3 files changed

+208
-94
lines changed

src/Data/Ets2TelemetryData.cs

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Funbit.Ets.Telemetry.Server.Data
88
class Ets2TelemetryData : IEts2TelemetryData
99
{
1010
Box<Ets2TelemetryStructure> _rawData;
11-
11+
1212
public void Update(Ets2TelemetryStructure rawData)
1313
{
1414
_rawData = new Box<Ets2TelemetryStructure>(rawData);
@@ -34,7 +34,6 @@ internal static string BytesToString(byte[] bytes)
3434

3535
public IEts2Game Game => new Ets2Game(_rawData);
3636
public IEts2Truck Truck => new Ets2Truck(_rawData);
37-
public IEts2Trailer Trailer => new Ets2Trailer(_rawData);
3837
public IEts2Job Job => new Ets2Job(_rawData);
3938
public IEts2Navigation Navigation => new Ets2Navigation(_rawData);
4039
}
@@ -59,6 +58,11 @@ public Ets2Game(Box<Ets2TelemetryStructure> rawData)
5958
public DateTime NextRestStopTime => Ets2TelemetryData.MinutesToDate(_rawData.Struct.nextRestStop);
6059
public string Version => $"{_rawData.Struct.ets2_version_major}.{_rawData.Struct.ets2_version_minor}";
6160
public string TelemetryPluginVersion => _rawData.Struct.ets2_telemetry_plugin_revision.ToString();
61+
62+
public string Everything =>
63+
$"Stats for game:\nGame: {GameName}\nPaused: {Paused}\nTime: {Time.ToString()}\n" +
64+
$"Next Rest Stop Time: {NextRestStopTime}\nTime Scale: {TimeScale}\nGame Version: {Version}\nTelemetry Version: {TelemetryPluginVersion}" +
65+
$"{(TimeScale == 0 ? "\n\n(Game is " + (Connected ? "closed)" : "starting up)") : "")}";
6266
}
6367

6468
class Ets2Vector : IEts2Vector
@@ -112,12 +116,12 @@ public Ets2Truck(Box<Ets2TelemetryStructure> rawData)
112116
/// <summary>
113117
/// Truck speed in km/h.
114118
/// </summary>
115-
public float Speed => _rawData.Struct.speed * 3.6f;
119+
public int Speed => (int)(_rawData.Struct.speed * 3.6f);
116120

117121
/// <summary>
118122
/// Cruise control speed in km/h.
119123
/// </summary>
120-
public float CruiseControlSpeed => _rawData.Struct.cruiseControlSpeed * 3.6f;
124+
public int CruiseControlSpeed => (int)(_rawData.Struct.cruiseControlSpeed * 3.6f);
121125

122126
public bool CruiseControlOn => _rawData.Struct.cruiseControl != 0;
123127
public float Odometer => _rawData.Struct.truckOdometer;
@@ -126,7 +130,7 @@ public Ets2Truck(Box<Ets2TelemetryStructure> rawData)
126130
public int ForwardGears => _rawData.Struct.gearsForward;
127131
public int ReverseGears => _rawData.Struct.gearsReverse;
128132
public string ShifterType => Ets2TelemetryData.BytesToString(_rawData.Struct.shifterType);
129-
public float EngineRpm => _rawData.Struct.engineRpm;
133+
public int EngineRpm => (int)_rawData.Struct.engineRpm;
130134
public float EngineRpmMax => _rawData.Struct.engineRpmMax;
131135
public float Fuel => _rawData.Struct.fuel;
132136
public float FuelCapacity => _rawData.Struct.fuelCapacity;
@@ -246,46 +250,31 @@ public IEts2Wheel[] Wheels
246250
}
247251
}
248252
*/
249-
}
250-
251-
class Ets2Trailer : IEts2Trailer
252-
{
253-
readonly Box<Ets2TelemetryStructure> _rawData;
254253

255-
public Ets2Trailer(Box<Ets2TelemetryStructure> rawData)
256-
{
257-
_rawData = rawData;
258-
}
254+
public string Everything =>
255+
$"Stats for truck:\nName: {Make} {Model}\nOdometer: {Odometer}\n\n" +
256+
$"Speed: {Speed} KMH\n" +
257+
(Speed == 0 ? $"Parking Brake Engaged: {ParkBrakeOn}\n" : $"RPM: {EngineRpm}/{EngineRpmMax}\n") +
258+
(CruiseControlOn ? $"Cruise Control Speed: {int.Parse(CruiseControlSpeed.ToString())}\n" : "") +
259+
$"Gear: {(DisplayedGear == 0 ? "N" : DisplayedGear.ToString())}/{ForwardGears + ReverseGears} ({ForwardGears}/{ReverseGears})\nShift Type: {ShifterType}\n" +
260+
$"Fuel: {Fuel}/{FuelCapacity}\n\n" +
259261

260-
public bool Attached => _rawData.Struct.trailer_attached != 0;
261-
public string Id => Ets2TelemetryData.BytesToString(_rawData.Struct.trailerId);
262-
public string Name => Ets2TelemetryData.BytesToString(_rawData.Struct.trailerName);
262+
$"Damages:\nCabin: {WearCabin}\nChassis: {WearChassis}\nEngine: {WearEngine}\nTransmission: {WearTransmission}\nWheels: {WearWheels}\n\n" +
263263

264-
/// <summary>
265-
/// Trailer mass in kilograms.
266-
/// </summary>
267-
public float Mass => _rawData.Struct.trailerMass;
268-
269-
public float Wear => _rawData.Struct.wearTrailer;
270-
271-
public IEts2Placement Placement => new Ets2Placement(
272-
_rawData.Struct.trailerCoordinateX,
273-
_rawData.Struct.trailerCoordinateY,
274-
_rawData.Struct.trailerCoordinateZ,
275-
_rawData.Struct.trailerRotationX,
276-
_rawData.Struct.trailerRotationY,
277-
_rawData.Struct.trailerRotationZ);
264+
$"Lights: " + (LightsBeamHighOn ? "On (High Beams)" : LightsBeamLowOn ? "On" : "Off") + "\n\n" +
265+
(BlinkerLeftOn ? "**Turning Left**" : "") +
266+
(BlinkerRightOn ? "**Turning Right**" : "");
278267
}
279268

280269
class Ets2Navigation : IEts2Navigation
281270
{
282271
readonly Box<Ets2TelemetryStructure> _rawData;
283-
272+
284273
public Ets2Navigation(Box<Ets2TelemetryStructure> rawData)
285274
{
286275
_rawData = rawData;
287276
}
288-
277+
289278
public DateTime EstimatedTime => Ets2TelemetryData.SecondsToDate((int)_rawData.Struct.navigationTime);
290279
public int EstimatedDistance => (int)_rawData.Struct.navigationDistance;
291280
public int SpeedLimit => _rawData.Struct.navigationSpeedLimit > 0 ? (int)Math.Round(_rawData.Struct.navigationSpeedLimit * 3.6f) : 0;
@@ -300,9 +289,24 @@ public Ets2Job(Box<Ets2TelemetryStructure> rawData)
300289
_rawData = rawData;
301290
}
302291

292+
public bool Attached => _rawData.Struct.trailer_attached != 0;
293+
public string Id => Ets2TelemetryData.BytesToString(_rawData.Struct.trailerId);
294+
public string Name => Ets2TelemetryData.BytesToString(_rawData.Struct.trailerName);
295+
public float Mass => _rawData.Struct.trailerMass;
296+
297+
public float Wear => _rawData.Struct.wearTrailer;
298+
299+
public IEts2Placement Placement => new Ets2Placement(
300+
_rawData.Struct.trailerCoordinateX,
301+
_rawData.Struct.trailerCoordinateY,
302+
_rawData.Struct.trailerCoordinateZ,
303+
_rawData.Struct.trailerRotationX,
304+
_rawData.Struct.trailerRotationY,
305+
_rawData.Struct.trailerRotationZ);
306+
303307
public int Income => _rawData.Struct.jobIncome;
304308
public DateTime DeadlineTime => Ets2TelemetryData.MinutesToDate(_rawData.Struct.jobDeadline);
305-
public DateTime RemainingTime
309+
public DateTime RemainingTime
306310
{
307311
get
308312
{
@@ -311,11 +315,18 @@ public DateTime RemainingTime
311315
return Ets2TelemetryData.MinutesToDate(0);
312316
}
313317
}
318+
public DateTime EstimatedTime => Ets2TelemetryData.SecondsToDate((int)_rawData.Struct.navigationTime);
319+
public int EstimatedDistance => (int)_rawData.Struct.navigationDistance;
314320

315321
public string SourceCity => Ets2TelemetryData.BytesToString(_rawData.Struct.jobCitySource);
316322
public string SourceCompany => Ets2TelemetryData.BytesToString(_rawData.Struct.jobCompanySource);
317323
public string DestinationCity => Ets2TelemetryData.BytesToString(_rawData.Struct.jobCityDestination);
318324
public string DestinationCompany => Ets2TelemetryData.BytesToString(_rawData.Struct.jobCompanyDestination);
325+
326+
public string Everything =>
327+
$"Stats for job:\nDelivering {Name} (Internal Name: {Id}) from {SourceCity} ({SourceCompany}) to {DestinationCity} ({DestinationCompany})\nPay: {Income}\n\n" +
328+
$"Estimated Arrival: {EstimatedTime.Hour}:{EstimatedTime.Minute}:{EstimatedTime.Second}\nTime Left: {EstimatedTime.Hour}:{EstimatedTime.Minute}:{EstimatedTime.Second}\n\n" +
329+
$"Trailer:\nAttached: {Attached}\nWeight: {Mass}KG\nDamage: {Wear}";
319330
}
320331

321332
/*
@@ -357,7 +368,7 @@ public Ets2GearSlot(Box<Ets2TelemetryStructure> rawData, int slotIndex)
357368
}
358369
*/
359370

360-
class Box<T> where T : struct
371+
class Box<T> where T : struct
361372
{
362373
public T Struct { get; set; }
363374

src/Data/IEts2TelemetryData.cs

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@ public interface IEts2TelemetryData
88
/// Game information.
99
/// </summary>
1010
IEts2Game Game { get; }
11-
11+
1212
/// <summary>
1313
/// Truck information.
1414
/// </summary>
1515
IEts2Truck Truck { get; }
1616

17-
/// <summary>
18-
/// Trailer information.
19-
/// </summary>
20-
IEts2Trailer Trailer { get; }
21-
2217
/// <summary>
2318
/// Job information.
2419
/// </summary>
@@ -79,6 +74,10 @@ public interface IEts2Game
7974
/// Example: 3
8075
/// </summary>
8176
float TimeScale { get; }
77+
/// <summary>
78+
/// Returns all other variables within this interface as one long string, with newlines in between
79+
/// </summary>
80+
string Everything { get; }
8281
}
8382

8483
public interface IEts2Vector
@@ -135,7 +134,7 @@ public interface IEts2Truck
135134
/// Current truck speed in km/h.
136135
/// Example: 50.411231
137136
/// </summary>
138-
float Speed { get; }
137+
int Speed { get; }
139138

140139
/// <summary>
141140
/// Represents vehicle space linear acceleration of
@@ -147,7 +146,7 @@ public interface IEts2Truck
147146
/// Current truck placement in the game world.
148147
/// </summary>
149148
IEts2Placement Placement { get; }
150-
149+
151150
/// <summary>
152151
/// The value of the odometer in km.
153152
/// Example: 105809.25
@@ -157,7 +156,7 @@ public interface IEts2Truck
157156
/// Speed selected for the cruise control in km/h.
158157
/// Example: 75
159158
/// </summary>
160-
float CruiseControlSpeed { get; }
159+
int CruiseControlSpeed { get; }
161160

162161
/// <summary>
163162
/// Brand Id of the current truck.
@@ -202,7 +201,7 @@ public interface IEts2Truck
202201
/// Current RPM value of the truck's engine (rotates per minute).
203202
/// Example: 1372.3175
204203
/// </summary>
205-
float EngineRpm { get; }
204+
int EngineRpm { get; }
206205
/// <summary>
207206
/// Maximal RPM value of the truck's engine.
208207
/// Example: 2500
@@ -284,7 +283,7 @@ public interface IEts2Truck
284283
/// Example: 0
285284
/// </summary>
286285
float GameClutch { get; }
287-
286+
288287
/// <summary>
289288
/// Current level of the retarder brake.
290289
/// Ranges from 0 to RetarderStepCount.
@@ -307,7 +306,7 @@ public interface IEts2Truck
307306
/// TODO: need to fix.
308307
/// </summary>
309308
//int ShifterToggle { get; }
310-
309+
311310
/// <summary>
312311
/// Pressure in the brake air tank in psi.
313312
/// Example: 133.043961
@@ -353,7 +352,7 @@ public interface IEts2Truck
353352
/// Example: 0
354353
/// </summary>
355354
float AdblueCapacity { get; }
356-
355+
357356
/// <summary>
358357
/// Current level of truck's engine wear/damage between 0 (min) and 1 (max).
359358
/// Example: 0.00675457
@@ -551,6 +550,10 @@ public interface IEts2Truck
551550
/// Example: 22
552551
/// </summary>
553552
float BatteryVoltageWarningValue { get; }
553+
/// <summary>
554+
/// Returns all other variables within this interface as one long string, with newlines in between
555+
/// </summary>
556+
string Everything { get; }
554557
}
555558

556559
public interface IEts2Navigation
@@ -576,6 +579,33 @@ public interface IEts2Navigation
576579

577580
public interface IEts2Job
578581
{
582+
/// <summary>
583+
/// Id of the cargo for internal use by code.
584+
/// Example: "derrick"
585+
/// </summary>
586+
string Id { get; }
587+
/// <summary>
588+
/// Localized name of the current trailer for display purposes.
589+
/// Example: "Derrick"
590+
/// </summary>
591+
string Name { get; }
592+
/// <summary>
593+
/// Is the trailer attached to the truck or not.
594+
/// </summary>
595+
bool Attached { get; }
596+
/// <summary>
597+
/// Trailer mass in kilograms.
598+
/// </summary>
599+
float Mass { get; }
600+
/// <summary>
601+
/// Current trailer placement in the game world.
602+
/// </summary>
603+
IEts2Placement Placement { get; }
604+
/// <summary>
605+
/// Current level of trailer wear/damage between 0 (min) and 1 (max).
606+
/// Example: 0.0314717
607+
/// </summary>
608+
float Wear { get; }
579609
/// <summary>
580610
/// Reward in internal game-specific currency.
581611
/// Example: 2316
@@ -593,7 +623,17 @@ public interface IEts2Job
593623
/// Example: "0001-01-01T07:06:00Z"
594624
/// </summary>
595625
DateTime RemainingTime { get; }
596-
626+
/// <summary>
627+
/// Relative estimated time of arrival.
628+
/// Example: "0001-01-01T02:05:00Z"
629+
/// </summary>
630+
DateTime EstimatedTime { get; }
631+
632+
/// <summary>
633+
/// Estimated distance to the destination in meters.
634+
/// Example: 1224
635+
/// </summary>
636+
int EstimatedDistance { get; }
597637
/// <summary>
598638
/// Localized name of the source city for display purposes.
599639
/// Example: "Linz"
@@ -614,38 +654,10 @@ public interface IEts2Job
614654
/// Example: "JCB"
615655
/// </summary>
616656
string DestinationCompany { get; }
617-
}
618-
619-
public interface IEts2Trailer
620-
{
621-
/// <summary>
622-
/// Id of the cargo for internal use by code.
623-
/// Example: "derrick"
624-
/// </summary>
625-
string Id { get; }
626657
/// <summary>
627-
/// Localized name of the current trailer for display purposes.
628-
/// Example: "Derrick"
629-
/// </summary>
630-
string Name { get; }
631-
/// <summary>
632-
/// Is the trailer attached to the truck or not.
658+
/// Returns all other variables within this interface as one long string, with newlines in between
633659
/// </summary>
634-
bool Attached { get; }
635-
/// <summary>
636-
/// Mass of the cargo in kilograms.
637-
/// Example: 22000
638-
/// </summary>
639-
float Mass { get; }
640-
/// <summary>
641-
/// Current trailer placement in the game world.
642-
/// </summary>
643-
IEts2Placement Placement { get; }
644-
/// <summary>
645-
/// Current level of trailer wear/damage between 0 (min) and 1 (max).
646-
/// Example: 0.0314717
647-
/// </summary>
648-
float Wear { get; }
660+
string Everything { get; }
649661
}
650662

651663
/*

0 commit comments

Comments
 (0)