Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from VTCManager/fix-for-rpc-issues
Browse files Browse the repository at this point in the history
Fix for Discord rpc issues
  • Loading branch information
joschiservice authored Jun 17, 2020
2 parents 80eed6d + 4dea4a4 commit ac160c6
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 39 deletions.
2 changes: 1 addition & 1 deletion VTC_WPF/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace VTCManager
public static class Config
{
//VERSIONS
public static string ClientVersion = "3.0.2.0 Beta";
public static string ClientVersion = "3.0.3.1 Beta";
public static string TelemetryVersion = "1.10";

//FILES
Expand Down
1 change: 0 additions & 1 deletion VTC_WPF/Joschis_Design.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public Joschis_Design()
Telemetry.RefuelEnd += TelemetryHandler.RefuelEnd;
Telemetry.RefuelPayed += TelemetryHandler.RefuelPayed;
jobHandler = new JobHandler();
Discord = new DiscordHandler();

InitializeComponent();
}
Expand Down
78 changes: 66 additions & 12 deletions VTC_WPF/Klassen/DiscordHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ public class DiscordHandler
private const string DiscordAppID = "659036297561767948";
private const string DefaultDiscordLargeImageKey = "truck-icon";
private static Timer onJobInfoTimer;
public static Timer FreeRoamSpeedUpdateTimer;
private static RichPresence jobRPC;
private static bool JobInfoActive;
private static Translation translation;

public DiscordHandler()
public DiscordHandler(Translation translation)
{

FreeRoamSpeedUpdateTimer = new Timer();
onJobInfoTimer = new Timer();
DiscordHandler.translation = translation;
client = new DiscordRpcClient(DiscordAppID);
client.Initialize();
client.SetPresence(new RichPresence()
{
Details = "Starte...",
Details = translation.DISCORD_IDLE,
Assets = new Assets()
{
LargeImageKey = DefaultDiscordLargeImageKey,
Expand All @@ -35,16 +39,17 @@ public DiscordHandler()

public void OnJobStart(string cargo, int weight, string origin, string destination, string truck_brand_id, string truck)
{
FreeRoamSpeedUpdateTimer.Enabled = false;
string DiscordLargeImageKey = getTruckImageKey(truck_brand_id);
jobRPC = new RichPresence()
{
Details = "Fracht: " + cargo + "(" + weight/1000 + "t)",
State = "von " + origin + " nach " + destination,
Details = translation.DISCORD_JOB_CARGO+": " + cargo + "(" + weight/1000 + "t)",
State = origin + "->" + destination,

Assets = new Assets()
{
LargeImageKey = DiscordLargeImageKey,
LargeImageText = "Fährt "+ truck,
LargeImageText = translation.DISCORD_DRIVING + " " + truck,
SmallImageKey = DiscordSmallImageKey,
SmallImageText = "v" + Config.ClientVersion
}
Expand All @@ -53,7 +58,6 @@ public void OnJobStart(string cargo, int weight, string origin, string destinati
client.SetPresence(jobRPC);
client.Invoke();
JobInfoActive = true;
onJobInfoTimer = new Timer();
onJobInfoTimer.Elapsed += new ElapsedEventHandler(updateOnJob);
onJobInfoTimer.Interval = 5000;
onJobInfoTimer.Enabled = true;
Expand All @@ -66,7 +70,7 @@ private void updateOnJob(object sender, ElapsedEventArgs e)
RichPresence RPC = new RichPresence()
{
Details = (int)TelemetryHandler.Telemetry_Data.TruckValues.CurrentValues.DashboardValues.Speed.Kph+" km/h",
State = (int)TelemetryHandler.Telemetry_Data.NavigationValues.NavigationDistance/1000+" km("+ (int)((((TelemetryHandler.Telemetry_Data.NavigationValues.NavigationDistance/1000)/TelemetryHandler.Telemetry_Data.JobValues.PlannedDistanceKm)*100)) + "%) verbleibend",
State = (int)TelemetryHandler.Telemetry_Data.NavigationValues.NavigationDistance/1000+" km("+ (int)((((TelemetryHandler.Telemetry_Data.NavigationValues.NavigationDistance/1000)/TelemetryHandler.Telemetry_Data.JobValues.PlannedDistanceKm)*100)) + "%) "+translation.DISCORD_JOB_REMAINING,

Assets = new Assets()
{
Expand All @@ -87,24 +91,49 @@ private void updateOnJob(object sender, ElapsedEventArgs e)
JobInfoActive = true;
}
}
private void updateFreeRoamSpeed(object sender, ElapsedEventArgs e)
{
string DiscordLargeImageKey = getTruckImageKey(TelemetryHandler.Telemetry_Data.TruckValues.ConstantsValues.BrandId);
RichPresence RPC = new RichPresence()
{
Details = translation.DISCORD_FREEROAM,
State = (int)TelemetryHandler.Telemetry_Data.TruckValues.CurrentValues.DashboardValues.Speed.Kph + " km/h",

Assets = new Assets()
{
LargeImageKey = DiscordLargeImageKey,
LargeImageText = translation.DISCORD_DRIVING + " " + TelemetryHandler.Telemetry_Data.TruckValues.ConstantsValues.Brand+" "+ TelemetryHandler.Telemetry_Data.TruckValues.ConstantsValues.Name,
SmallImageKey = DiscordSmallImageKey,
SmallImageText = "v" + Config.ClientVersion
}
};
client.SetPresence(RPC);
client.Invoke();
JobInfoActive = false;
}

public void FreeRoam(string truck_brand_id, string truck)
public void FreeRoam()
{
string DiscordLargeImageKey = getTruckImageKey(truck_brand_id);
onJobInfoTimer.Enabled = false;
string DiscordLargeImageKey = getTruckImageKey(TelemetryHandler.Telemetry_Data.TruckValues.ConstantsValues.BrandId);
RichPresence RPC = new RichPresence()
{
Details = "Frei wie der Wind",
Details = translation.DISCORD_FREEROAM,
State = (int)TelemetryHandler.Telemetry_Data.TruckValues.CurrentValues.DashboardValues.Speed.Kph + " km/h",

Assets = new Assets()
{
LargeImageKey = DiscordLargeImageKey,
LargeImageText = "Driving " + truck,
LargeImageText = translation.DISCORD_DRIVING + " " + TelemetryHandler.Telemetry_Data.TruckValues.ConstantsValues.Brand + " " + TelemetryHandler.Telemetry_Data.TruckValues.ConstantsValues.Name,
SmallImageKey = DiscordSmallImageKey,
SmallImageText = "v" + Config.ClientVersion
}
};
client.SetPresence(RPC);
client.Invoke();
FreeRoamSpeedUpdateTimer.Elapsed += new ElapsedEventHandler(updateFreeRoamSpeed);
FreeRoamSpeedUpdateTimer.Interval = 3000;
FreeRoamSpeedUpdateTimer.Enabled = true;
}

private string getTruckImageKey(string truck_brand_id)
Expand All @@ -114,7 +143,32 @@ private string getTruckImageKey(string truck_brand_id)
{
DiscordLargeImageKey = "brand-renault";
}
else if (truck_brand_id == "scania")
{
DiscordLargeImageKey = "brand-scania";
}
else if (truck_brand_id == "mercedes")
{
DiscordLargeImageKey = "brand-mercedes";
}
return DiscordLargeImageKey;
}
public void idle()
{
client = new DiscordRpcClient(DiscordAppID);
client.Initialize();
client.SetPresence(new RichPresence()
{
Details = translation.DISCORD_IDLE,
Assets = new Assets()
{
LargeImageKey = DefaultDiscordLargeImageKey,
LargeImageText = "Beyond the limits",
SmallImageKey = DiscordSmallImageKey,
SmallImageText = "v" + Config.ClientVersion
}

});
}
}
}
33 changes: 29 additions & 4 deletions VTC_WPF/Klassen/TelemetryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public class TelemetryHandler
private MainWindow mainWindow;
public static DiscordHandler Discord;
public static bool onJob = false;
public static bool freeroamactive = false;
public static bool idleactive = false;

public TelemetryHandler(MainWindow mainWindow)
public TelemetryHandler(MainWindow mainWindow, Translation translation)
{
this.mainWindow = mainWindow;
Discord = new DiscordHandler();
Discord = new DiscordHandler(translation);
Telemetry = new SCSSdkTelemetry();
Telemetry.Data += Telemetry_Data_Handler;
Telemetry.JobStarted += TelemetryHandler.JobStarted;
Expand All @@ -41,9 +43,30 @@ private void Telemetry_Data_Handler(SCSTelemetry data, bool newTimestamp)
Telemetry_Data = data;
if(data != null)
{
if (!String.IsNullOrWhiteSpace(data.TruckValues.ConstantsValues.BrandId) && !onJob)
if (!String.IsNullOrWhiteSpace(data.TruckValues.ConstantsValues.BrandId))
{
Discord.FreeRoam(Telemetry_Data.TruckValues.ConstantsValues.BrandId, Telemetry_Data.TruckValues.ConstantsValues.Brand + " " + Telemetry_Data.TruckValues.ConstantsValues.Name);
if (!String.IsNullOrWhiteSpace(data.TruckValues.ConstantsValues.BrandId) && !onJob && !freeroamactive)
{
Discord.FreeRoam();
freeroamactive = true;
idleactive = false;
}
}
else
{
if (!idleactive)
{
Discord.idle();
idleactive = true;
}
}
}
else
{
if (!idleactive)
{
Discord.idle();
idleactive = true;
}
}
}
Expand Down Expand Up @@ -109,13 +132,15 @@ public static void JobDelivered(object sender, EventArgs e)
post_param.Add("truck_damage_at_end", Telemetry_Data.TruckValues.CurrentValues.DamageValues.Engine.ToString());
JObject response = API.HTTPSRequestPost(API.job_delivered, post_param);
onJob = false;
Discord.FreeRoam();
}

public static void JobCancelled(object sender, EventArgs e)
{
checkTelemetry();
JObject response = API.HTTPSRequestGet(API.job_canceled);
onJob = false;
Discord.FreeRoam();
}

public static void JobStarted(object sender, EventArgs e)
Expand Down
23 changes: 22 additions & 1 deletion VTC_WPF/Klassen/Translation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public class Translation
BUTTON_ATS_STARTEN,
BUTTON_TMP_STARTEN,
ATS_PATH_NOT_FOUND,
ETS2_PATH_NOT_FOUND;
ETS2_PATH_NOT_FOUND,
DISCORD_IDLE,
DISCORD_JOB_CARGO,
DISCORD_DRIVING,
DISCORD_JOB_REMAINING,
DISCORD_FREEROAM;
public Translation(String lang)
{
version = "Version: 3.0";
Expand Down Expand Up @@ -57,6 +62,22 @@ public Translation(String lang)
BUTTON_TMP_STARTEN = lang == "DE" ? "Truckers-MP" : "Truckers-MP";
ATS_PATH_NOT_FOUND = lang == "DE" ? "Du hast in den Einstellungen noch keinen Link für ATS angegeben ! Du kannst den Pfad jederzeit nachtragen!" : "You have not yet specified a link for ATS in the settings! You can add the path at any time!";
ETS2_PATH_NOT_FOUND = lang == "DE" ? "Du hast in den Einstellungen noch keinen Link für ETS2 angegeben ! Du kannst den Pfad jederzeit nachtragen!" : "You have not yet specified a link for ETS2 in the settings! You can add the path at any time!";
if(lang == "DE")
{
DISCORD_IDLE = "Kein Spiel aktiv.";
DISCORD_JOB_CARGO = "Fracht";
DISCORD_DRIVING = "Fährt";
DISCORD_JOB_REMAINING = "verbleibend";
DISCORD_FREEROAM = "Frei wie der Wind";
}
else
{
DISCORD_IDLE = "No game running.";
DISCORD_JOB_CARGO = "Cargo";
DISCORD_DRIVING = "Driving";
DISCORD_JOB_REMAINING = "remaining";
DISCORD_FREEROAM = "Free as the wind";
}


}
Expand Down
38 changes: 20 additions & 18 deletions VTC_WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public partial class MainWindow : MetroWindow
int Tankinhalt;
private object polyline1;
private TelemetryHandler telemetryhandler;
private Translation translation;


public MainWindow()
Expand All @@ -47,12 +48,13 @@ public MainWindow()
TelemetryInstaller.check();
jobHandler = new JobHandler();
Truck_Daten = new Truck_Daten();
telemetryhandler = new TelemetryHandler(this);

InitializeComponent();

Lade_Themes();
lade_Translations();
//must be after lade_Translations
telemetryhandler = new TelemetryHandler(this, translation);
utils.Build_Registry();

Sprachauswahl.SelectedValue = utils.Reg_Lesen("Config", "Sprache", false);
Expand Down Expand Up @@ -179,23 +181,23 @@ private void Telemetry_Data_Handler(SCSTelemetry data, bool updated)

public void lade_Translations()
{
Translation trans = new Translation(utils.Reg_Lesen("Config", "Sprache", false));
TAB_FAHRT.Header = trans.TAB_Fahrt_Text;
TAB_FREUNDE.Header = trans.TAB_FREUNDE_TEXT;
TAB_VERKEHR.Header = trans.TAB_VERKEHR_TEXT;
TAB_EINSTELLUNGEN.Header = trans.TAB_EINSTELLUNGEN_TEXT;
LBL_FAHRT_SCHADEN_TITEL.Content = trans.SCHADENSANZEIGE_TITEL;
LBL_Truck_Name.Content = trans.TRUCK_NAME;
LBL_Truck_Model.Content = trans.TRUCK_MODELL;
TAB_FAHRT_LBL_MOTOR.Content = trans.TAB_FAHRT_LBL_MOTOR;
TAB_FAHRT_LBL_GETRIEBE.Content = trans.TAB_FAHRT_LBL_GETRIEBE;
TAB_FAHRT_LBL_RAEDER.Content = trans.TAB_FAHRT_LBL_RAEDER;
TAB_FAHRT_LBL_FAHRWERK.Content = trans.TAB_FAHRT_LBL_FAHRWERK;
TAB_FAHRT_LBL_FAHRERHAUS.Content = trans.TAB_FAHRT_LBL_FAHRERHAUS;
TAB_FAHRT_LBL_FRACHTSCHADEN.Content = trans.TAB_FAHRT_LBL_FRACHTSCHADEN;
BUTTON_ATS_STARTEN.Text = trans.BUTTON_ATS_STARTEN;
BUTTON_ETS_STARTEN.Text = trans.BUTTON_ETS_STARTEN;
BUTTON_TMP_STARTEN.Text = trans.BUTTON_TMP_STARTEN;
translation = new Translation(utils.Reg_Lesen("Config", "Sprache", false));
TAB_FAHRT.Header = translation.TAB_Fahrt_Text;
TAB_FREUNDE.Header = translation.TAB_FREUNDE_TEXT;
TAB_VERKEHR.Header = translation.TAB_VERKEHR_TEXT;
TAB_EINSTELLUNGEN.Header = translation.TAB_EINSTELLUNGEN_TEXT;
LBL_FAHRT_SCHADEN_TITEL.Content = translation.SCHADENSANZEIGE_TITEL;
LBL_Truck_Name.Content = translation.TRUCK_NAME;
LBL_Truck_Model.Content = translation.TRUCK_MODELL;
TAB_FAHRT_LBL_MOTOR.Content = translation.TAB_FAHRT_LBL_MOTOR;
TAB_FAHRT_LBL_GETRIEBE.Content = translation.TAB_FAHRT_LBL_GETRIEBE;
TAB_FAHRT_LBL_RAEDER.Content = translation.TAB_FAHRT_LBL_RAEDER;
TAB_FAHRT_LBL_FAHRWERK.Content = translation.TAB_FAHRT_LBL_FAHRWERK;
TAB_FAHRT_LBL_FAHRERHAUS.Content = translation.TAB_FAHRT_LBL_FAHRERHAUS;
TAB_FAHRT_LBL_FRACHTSCHADEN.Content = translation.TAB_FAHRT_LBL_FRACHTSCHADEN;
BUTTON_ATS_STARTEN.Text = translation.BUTTON_ATS_STARTEN;
BUTTON_ETS_STARTEN.Text = translation.BUTTON_ETS_STARTEN;
BUTTON_TMP_STARTEN.Text = translation.BUTTON_TMP_STARTEN;



Expand Down
4 changes: 2 additions & 2 deletions VTC_WPF/VTCManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EF016EC9-B8DC-4FC6-94F1-03D46F93388D}</ProjectGuid>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<RootNamespace>VTCManager</RootNamespace>
<AssemblyName>VTCManager</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
Expand All @@ -30,7 +30,7 @@
<InstallUrl>https://cdn.vtcmanager.eu/client/</InstallUrl>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage>
<ApplicationRevision>6</ApplicationRevision>
<ApplicationRevision>8</ApplicationRevision>
<ApplicationVersion>3.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down

0 comments on commit ac160c6

Please sign in to comment.