Skip to content

Commit 78740d4

Browse files
committed
Finalized beta
1 parent 531590c commit 78740d4

File tree

11 files changed

+323
-104
lines changed

11 files changed

+323
-104
lines changed

Controller/RTAuthentificationSettings.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ namespace LiveSplit.Racetime.Controller
99
{
1010
internal class RTAuthentificationSettings : IAuthentificationSettings
1111
{
12-
public virtual string ClientID => "Rt8ey6rjcQblDxxuERCxZOfJ9p59ANnFWF92HueU";
13-
public virtual string ClientSecret => "JYVuPmXmylFc3J8vNN3W8egUmeJ9bRPQGCTvZqEjc24KMaCpihhRA0cK7GNZCOxADkJyYo3mjxvuVcaj4OKUv8dZDUmMqa91kuQWf8eV9YwEmalsedMbZZcfAgAW6rAT";
14-
public virtual string AuthServer => "http://192.168.178.70:8000/";
15-
public virtual string SuccessEndpoint => "o/done";
16-
public virtual string FailureEndpoint => "o/done?error=access_denied";
17-
public virtual string AuthorizationEndpoint => "o/authorize";
18-
public virtual string TokenEndpoint => "o/token";
19-
public virtual string UserInfoEndpoint => "o/userinfo";
20-
public virtual string RevokeEndpoint => "o/revoke_token/";
21-
public virtual string Scopes => "read chat_message race_action";
22-
public virtual IPAddress RedirectAddress => IPAddress.Loopback;
23-
public virtual int RedirectPort => 6969;
24-
public virtual string ChallengeMethod => "S256";
12+
public virtual string ClientID => Properties.Resources.OAUTH_CLIENTID;
13+
public virtual string ClientSecret => Properties.Resources.OAUTH_CLIENTSECRET;
14+
public virtual string AuthServer => Properties.Resources.OAUTH_SERVER;
15+
public virtual string SuccessEndpoint => Properties.Resources.OAUTH_ENDPOINT_SUCCESS;
16+
public virtual string FailureEndpoint => Properties.Resources.OAUTH_ENDPOINT_FAILURE;
17+
public virtual string AuthorizationEndpoint => Properties.Resources.OAUTH_ENDPOINT_AUTHORIZATION;
18+
public virtual string TokenEndpoint => Properties.Resources.OAUTH_ENDPOINT_TOKEN;
19+
public virtual string UserInfoEndpoint => Properties.Resources.OAUTH_ENDPOINT_USERINFO;
20+
public virtual string RevokeEndpoint => Properties.Resources.OAUTH_ENDPOINT_REVOKE;
21+
public virtual string Scopes => Properties.Resources.OAUTH_SCOPES;
22+
public virtual IPAddress RedirectAddress => IPAddress.Parse(Properties.Resources.OAUTH_REDIRECT_ADDRESS);
23+
public virtual int RedirectPort => int.Parse(Properties.Resources.OAUTH_REDIRECT_PORT);
24+
public virtual string ChallengeMethod => Properties.Resources.OAUTH_CHALLENGE_METHOD;
2525
}
2626
}

Controller/RacetimeAuthenticator.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ private static string GenerateRandomBase64Data(uint length)
8181
}
8282

8383

84-
85-
8684
public override async Task<bool> Authorize(bool forceRefresh = false)
8785
{
86+
//token refresh currently not implemented
87+
8888
Error = null;
8989
string reqState, state, verifier, challenge, request, response;
9090
TcpListener localEndpoint;
91-
bool refresh = false;// IsRefreshRequired || forceRefresh; //if we were authorized, but know that the token already expired, go right to the refresh
9291

9392
reauthenticate:
9493

@@ -124,9 +123,8 @@ public override async Task<bool> Authorize(bool forceRefresh = false)
124123
{
125124
if (Error == "invalid_token" && RefreshToken != null)
126125
{
127-
//try again, but this time to refresh
128-
//refresh = true;
129-
goto reauthenticate;
126+
Error = "Access Token expired";
127+
goto failure;
130128
}
131129
else
132130
{
@@ -151,7 +149,7 @@ public override async Task<bool> Authorize(bool forceRefresh = false)
151149

152150
//Step 2: Getting authorized
153151
request = $"code={Code}&redirect_uri={RedirectUri}&client_id={s.ClientID}&code_verifier={verifier}&client_secret={s.ClientSecret}" + (!IsRefreshRequired ? $"&scope={s.Scopes}&grant_type=authorization_code" : $"&refresh_token={RefreshToken}&grant_type=refresh_token");
154-
152+
Console.WriteLine(request);
155153
var result = await RestRequest(s.TokenEndpoint, request);
156154
if (result.Item1 != 200)
157155
{

Controller/RacetimeChannel.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
using LiveSplit.Model;
1111
using LiveSplit.Model.Comparisons;
1212
using LiveSplit.Model.Input;
13-
using LiveSplit.Options;
1413
using LiveSplit.Racetime.Model;
1514
using LiveSplit.Web;
16-
using LiveSplit.Web.SRL;
1715

1816
namespace LiveSplit.Racetime.Controller
1917
{
@@ -30,15 +28,11 @@ public static async Task RunPeriodically(Action action, TimeSpan period, Cancell
3028
}
3129
}
3230

33-
public const string restProto = "http";
34-
public const string wsProto = "ws";
35-
public const string serverDomain = "192.168.178.70";
3631
public const int bufferSize = 20480;
3732
public const int maxBufferSize = 2097152;
38-
public const int serverPort = 8000;
3933

40-
public string FullWebRoot => string.Format("{0}://{1}:{2}/", restProto, serverDomain, serverPort);
41-
public string FullSocketRoot => string.Format("{0}://{1}:{2}/", wsProto, serverDomain, serverPort);
34+
public string FullWebRoot => string.Format("{0}://{1}/", Properties.Resources.PROTOCOL_REST, Properties.Resources.DOMAIN);
35+
public string FullSocketRoot => string.Format("{0}://{1}/", Properties.Resources.PROTOCOL_WEBSOCKET, Properties.Resources.DOMAIN);
4236

4337
public Race Race { get; set; }
4438
public UserStatus PersonalStatus
@@ -70,7 +64,7 @@ public RacetimeChannel(LiveSplitState state, ITimerModel model)
7064
RunPeriodically(() => Reconnect(), new TimeSpan(0, 0, 10), reconnect_cts.Token);
7165

7266

73-
this.Model = model;
67+
Model = model;
7468

7569
state.OnSplit += State_OnSplit;
7670
state.OnUndoSplit += State_OnUndoSplit;
@@ -173,8 +167,8 @@ public async Task RunAsync(string id)
173167
{
174168
if (await Authenticator.Authorize())
175169
{
176-
Console.WriteLine(Authenticator.Identity);
177170
SendSystemMessage($"Authorization successful. Hello, {Authenticator.Identity?.Name}");
171+
Authorized?.Invoke(this, null);
178172
}
179173
else
180174
{
@@ -247,7 +241,6 @@ public async Task RunAsync(string id)
247241
}
248242
catch (Exception ex)
249243
{
250-
//Console.WriteLine(ex.InnerException.Message);
251244
}
252245
}
253246

@@ -345,7 +338,6 @@ private void UpdateRaceData(RaceMessage msg)
345338

346339
public IEnumerable<ChatMessage> Parse(dynamic m)
347340
{
348-
// Console.WriteLine(m.GetType().ToString() + m.ToString());
349341
switch (m.type)
350342
{
351343
case "error":
@@ -364,7 +356,6 @@ public IEnumerable<ChatMessage> Parse(dynamic m)
364356
RequestOutputReset?.Invoke(this, new EventArgs());
365357
foreach (var msg in m.messages)
366358
{
367-
//Console.WriteLine(msg);
368359
if (msg.user == null)
369360
yield return RTModelBase.Create<RaceBotMessage>(msg);
370361
else
@@ -424,6 +415,7 @@ private void State_OnSplit(object sender, EventArgs e)
424415
public event EventHandler UserListRefreshed;
425416
public event EventHandlerT<IEnumerable<ChatMessage>> MessageReceived;
426417
public event EventHandler RequestOutputReset;
418+
public event EventHandler Authorized;
427419

428420

429421

@@ -439,12 +431,16 @@ public void Disconnect()
439431
websocket_cts.Cancel();
440432
reconnect_cts.Cancel();
441433

434+
Authenticator.RevokeAccess();
435+
442436
Model.Reset();
443-
//Model.CurrentState.Run.Clear();
437+
Model.CurrentState.Run.Offset = TimeSpan.Zero;
444438
Model.OnPause -= Model_OnPause;
445439
Model.OnSplit -= State_OnSplit;
446440
Model.OnReset -= State_OnReset;
447441
Model.OnUndoSplit -= State_OnUndoSplit;
442+
443+
448444
}
449445

450446
public void Forfeit()
@@ -455,7 +451,7 @@ public void Forfeit()
455451

456452
public void RemoveRaceComparisons()
457453
{
458-
Console.WriteLine("Remove Race Comparisons");
454+
459455
}
460456

461457
public bool TryCreateCommand(ref string message)
@@ -466,7 +462,6 @@ public bool TryCreateCommand(ref string message)
466462
end = message.IndexOf(' ') <= 0 ? message.Length - 1 : message.IndexOf(' ') - 1;
467463

468464
var command = message.Substring(1, end).TrimEnd().ToLower();
469-
//var parameter = message.Substring(message.IndexOf(' ')).TrimStart();
470465
message = "{ \"action\": \""+command+"\" }";
471466
return true;
472467
}

Model/ChatMessage.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ public virtual string Message
1616
{
1717
get
1818
{
19-
return Data.message;
19+
try
20+
{
21+
return Data.message_plain;
22+
}
23+
catch
24+
{
25+
return Data.message;
26+
}
2027
}
2128
}
2229
public virtual RacetimeUser User

0 commit comments

Comments
 (0)