Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional API / Showing Radio Data #93

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Binary file modified server/.vs/ETS2 Local Radio desktop/v16/.suo
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
294c31e6fff85af254053313cf06002d2cdbdb0f
13 changes: 13 additions & 0 deletions server/Capture/obj/Release/Capture.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ F:\Mods\ETS2\ETS2 Map Capture Tool\ets2-local-radio\server\bin\EasyHook64Svc.exe
F:\Mods\ETS2\ETS2 Map Capture Tool\ets2-local-radio\server\bin\EasyLoad32.dll
F:\Mods\ETS2\ETS2 Map Capture Tool\ets2-local-radio\server\bin\EasyLoad64.dll
F:\Mods\ETS2\ETS2 Map Capture Tool\ets2-local-radio\server\Capture\obj\Release\Capture.csprojAssemblyReference.cache
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\bin\EasyHook32.dll
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\bin\EasyHook64.dll
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\bin\EasyLoad32.dll
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\bin\EasyLoad64.dll
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\bin\EasyHook32Svc.exe
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\bin\EasyHook64Svc.exe
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\Capture\obj\Release\Capture.csprojAssemblyReference.cache
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\Capture\obj\Release\Capture.Properties.Resources.resources
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\Capture\obj\Release\Capture.csproj.GenerateResource.cache
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\Capture\obj\Release\Capture.csproj.CoreCompileInputs.cache
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\Capture\obj\Release\Capture.csproj.CopyComplete
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\Capture\obj\Release\Capture.dll
C:\Users\joshu\Documents\GitHub\ets2-local-radio\server\Capture\obj\Release\Capture.pdb
Binary file modified server/Capture/obj/Release/Capture.csproj.GenerateResource.cache
Binary file not shown.
Binary file modified server/Capture/obj/Release/Capture.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified server/Capture/obj/Release/Capture.dll
Binary file not shown.
Binary file modified server/Capture/obj/Release/Capture.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Ets2SdkClient">
<HintPath>F:\Downloads\ets2-sdk-plugin-master\ets2-client\C#\Ets2SdkClient\bin\Release\Ets2SdkClient.dll</HintPath>
<HintPath>..\plugins\Ets2SdkClient.dll</HintPath>
</Reference>
<Reference Include="Gma.System.MouseKeyHook, Version=5.6.130.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MouseKeyHook.5.6.0\lib\net40\Gma.System.MouseKeyHook.dll</HintPath>
Expand Down
48 changes: 48 additions & 0 deletions server/ETS2 Local Radio desktop/SimpleServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,24 @@ public class SimpleHTTPServer
private string _rootDirectory;
private HttpListener _listener;
private int _port;
private string _radioSignal;

public int Port
{
get { return _port; }
private set { }
}
public string RadioSignal
{
get { return _radioSignal; }
set { _radioSignal = value; }
}
private string _radioStation;
public string RadioStation
{
get { return _radioStation; }
set { _radioStation = value; }
}

/// <summary>
/// Construct server with given port.
Expand Down Expand Up @@ -249,6 +261,8 @@ private void Process(HttpListenerContext context)
try
{
Station.SetStation(station.Split("/".ToCharArray())[0], station.Split("/".ToCharArray())[1], station.Split("?".ToCharArray())[1]);
RadioStation = station.Split("/".ToCharArray())[0];
RadioSignal = station.Split("/".ToCharArray())[1];
}
catch (Exception)
{
Expand All @@ -273,6 +287,40 @@ private void Process(HttpListenerContext context)
context.Response.OutputStream.Write(Encoding.UTF8.GetBytes(text), 0, Encoding.UTF8.GetBytes(text).Length);
context.Response.OutputStream.Flush();
}
else if (context.Request.Url.AbsolutePath == "/api/radio/")
{
string json = "{\"Radio\":\"" + RadioStation + "\",\"Signal\":\"" + RadioSignal + "\"}";
context.Response.ContentType = "application/json";
context.Response.ContentLength64 = Encoding.UTF8.GetBytes(json).Length;
context.Response.StatusCode = (int)HttpStatusCode.OK;
context.Response.OutputStream.Write(Encoding.UTF8.GetBytes(json), 0, Encoding.UTF8.GetBytes(json).Length);
context.Response.OutputStream.Flush();
}
else if (context.Request.Url.AbsolutePath.StartsWith("/api/radio/set/"))
{
string station = context.Request.Url.AbsoluteUri;
station = WebUtility.UrlDecode(station);
//station = station.Split(new string[] { "/station/" }, StringSplitOptions.None)[1];
station = station.Split(new string[] { "/api/radio/set/" }, StringSplitOptions.None)[1];
try
{
RadioSignal = station.Split("/".ToCharArray())[0];
Console.WriteLine("Radio Signal: " + RadioSignal);
}
catch(Exception ex)
{
Console.WriteLine("Radio Signal: " + ex);
}
//RadioSignal = station;

string text = "{\"Success\": true}";

context.Response.ContentType = "application/json";
context.Response.ContentLength64 = Encoding.UTF8.GetBytes(text).Length;
context.Response.StatusCode = (int)HttpStatusCode.OK;
context.Response.OutputStream.Write(Encoding.UTF8.GetBytes(text), 0, Encoding.UTF8.GetBytes(text).Length);
context.Response.OutputStream.Flush();
}
else if (context.Request.Url.AbsolutePath == "/commands/")
{
string text = Newtonsoft.Json.JsonConvert.SerializeObject(Main.commandsData);
Expand Down
14 changes: 12 additions & 2 deletions server/ETS2 Local Radio desktop/Station.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@

namespace ETS2_Local_Radio_server
{
static class Station
public class Station
{
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);

public struct Rect
{
//public string RadioStation;
public int Left { get; set; }
public int Top { get; set; }
public int Right { get; set; }
public int Bottom { get; set; }
}

public static string NowPlaying = "Now playing:";

public static bool RTL = false;

public static string RadioStation = "-";
public static string RadioSignal = "1";

public static int Width = 0;
public static int Height = 0;

Expand All @@ -48,6 +53,7 @@ public struct Rect
public static System.Timers.Timer Timer = new System.Timers.Timer();

public static void SetStation(string name, string signal, string logoPath = null)

{
try
{
Expand All @@ -62,7 +68,7 @@ public static void SetStation(string name, string signal, string logoPath = null
return;
}
}

Rect rectangle = new Rect();
GetWindowRect(CaptureProcess.Process.MainWindowHandle, ref rectangle);
Width = rectangle.Right - rectangle.Left;
Expand Down Expand Up @@ -94,6 +100,10 @@ public static void SetStation(string name, string signal, string logoPath = null

var stringSize = g.MeasureString(NowPlaying + " " + name, font);
var nowPlayingSize = g.MeasureString(NowPlaying + " ", font);

RadioStation = name;
RadioSignal = signal;

var nameSize = g.MeasureString(name, font);
var topLeft = new PointF((512 / 2) - (stringSize.Width / 2) + 123,
(bmp.Height / 2) - (stringSize.Height / 2));
Expand Down
Binary file added server/plugins/Ets2SdkClient.dll
Binary file not shown.
39 changes: 39 additions & 0 deletions server/plugins/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
The MIT License (MIT)

Copyright (c) 2014 Hans

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Copyright (c) 2015 Michael "MiKo" Koch, [email protected]

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgement in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
4 changes: 4 additions & 0 deletions server/plugins/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This folder contains the ETS2 SDK plugin by nlhans (https://github.com/nlhans/ets2-sdk-plugin)
Once you run ETS2 Local Radio for the first time,
it should automatically ask you for the ETS2 folder and copy the files.
If it does not work, please copy the plugins manually to the ETS2 installation folder.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion web/lib/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function initialise() {
$.getJSON(g_api + "/api/", function (data) {
refresh(data);
});
//$.post(g_api + "/api/radio/set/" + calculateReception(g_countries[country].whitenoise) + "/");
}, 1000);

setInterval(function () {
Expand Down Expand Up @@ -147,6 +148,7 @@ function initialise() {
}
}
});
$.post(g_api + "/api/radio/set/" + calculateReception(g_countries[g_current_country].whitenoise) + "/");
}, 250);

$('#volumeControl').on("change mousemove", function () {
Expand Down Expand Up @@ -295,8 +297,8 @@ function refresh(data) {
if (Object.keys(available_countries).toString() != Object.keys(g_countries).toString()) {
//If they don't contain the same keys (ie. a country update)
g_countries = available_countries;

refreshStations();
$.get(g_api + "/api/radio/set/" + calculateReception(g_countries[country].whitenoise) + "/");
/*
for(var key in g_countries){
$.getJSON("/favourite/" + key, function (data) {
Expand All @@ -306,6 +308,7 @@ function refresh(data) {
*/
} else {
setWhitenoise(available_countries[g_current_country]["whitenoise"]);
$.get(g_api + "/api/radio/set/" + calculateReception(g_countries[country].whitenoise)+ "/");
g_countries = available_countries;

}
Expand Down