Commit bc39dd19 authored by Adam Leyshon's avatar Adam Leyshon

Added simpler way to un-ban users

Moved the dev spawn check from MapComponent to GameComponent
Added dialog box to enter reactivation token.
Spawn check is no longer saved to gameasave file.
Added more translation strings
parent 807e7670
......@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Linq;
using Glitterworld_Prime.Tools;
using RimWorld;
using UnityEngine;
using Verse;
using Verse.AI;
......@@ -89,7 +90,15 @@ namespace Glitterworld_Prime
null, 0f,
null, null), myPawn, this, "ReservedBy"));
#endif
// Are they holding down shift?
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
Action reactivateAction = delegate { Find.WindowStack.Add(new DialogPrimeReactivate()); };
floatMenuOptions.Add(FloatMenuUtility.DecoratePrioritizedTask(
new FloatMenuOption("Reactivate", reactivateAction, MenuOptionPriority.InitiateSocial, null, null, 0f,
null, null), myPawn, this, "ReservedBy"));
}
floatMenuOptions.Add(FloatMenuUtility.DecoratePrioritizedTask(
new FloatMenuOption(tradeship.TraderName, action, MenuOptionPriority.InitiateSocial, null, null, 0f,
......@@ -106,4 +115,4 @@ namespace Glitterworld_Prime
#endregion
}
}
\ No newline at end of file
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using UnityEngine;
using Verse;
namespace Glitterworld_Prime
{
public class DialogPrimeReactivate : Window
{
protected string code;
private bool focusedRenameField;
public DialogPrimeReactivate()
{
this.forcePause = true;
this.doCloseX = true;
this.absorbInputAroundWindow = true;
this.closeOnAccept = false;
this.closeOnClickedOutside = true;
}
protected virtual int MaxCodeLength
{
get { return 8; }
}
public override Vector2 InitialSize
{
get { return new Vector2(280f, 175f); }
}
public override void DoWindowContents(Rect inRect)
{
Text.Font = GameFont.Small;
bool flag = false;
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
{
flag = true;
Event.current.Use();
}
GUI.SetNextControlName("CodeField");
string str = Widgets.TextField(new Rect(0.0f, 15f, inRect.width, 35f), this.code);
if (str.Length < (this.MaxCodeLength+1))
this.code = str;
if (!this.focusedRenameField)
{
UI.FocusControl("CodeField", (Window) this);
this.focusedRenameField = true;
}
if (!Widgets.ButtonText(
new Rect(15f, (float) ((double) inRect.height - 35.0 - 15.0), (float) ((double) inRect.width - 15.0 - 15.0),
35f), "OK", true, false, true) && !flag)
return;
AcceptanceReport acceptanceReport = this.CodeIsValid(this.code);
if (!acceptanceReport.Accepted)
{
Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.RejectInput, false);
}
else
{
TryActivate(this.code);
Find.WindowStack.TryRemove((Window) this, true);
}
}
private AcceptanceReport CodeIsValid(string code)
{
if (code.Length != MaxCodeLength)
return new AcceptanceReport("GWPActivateIncorrect".Translate());
return (AcceptanceReport) true;
}
private static void TryActivate(string code)
{
// API Call to reactivate
GlitterWorldApi.ReactivateUserAccount(code);
}
}
}
......@@ -55,9 +55,7 @@ namespace Glitterworld_Prime
if (response.StatusCode == HttpStatusCode.OK)
if (ClientVersion < response.Data.Version)
{
var d = new Dialog_MessageBox(
"This mod version is out of date. Please update before trading.", title: "GlitterWorldPrime");
Find.WindowStack.Add(d);
Find.WindowStack.Add(new Dialog_MessageBox("GWPOutOfDate".Translate(), title: "GlitterWorldPrime"));
return false;
}
else
......@@ -66,14 +64,40 @@ namespace Glitterworld_Prime
}
{
var d = new Dialog_MessageBox(
"We received an invalid response, It might be down or you maybe out of date.\nPlease check the forum/workshop.",
title: "GlitterWorldPrime");
Find.WindowStack.Add(d);
Find.WindowStack.Add(new Dialog_MessageBox("GWPBadResponse".Translate(), title: "GlitterWorldPrime"));
return false;
}
}
internal static void ReactivateUserAccount(string token)
{
LogWriter.WriteMessage("Trying to reactivate");
var client = CreateRestClient();
var request = new RestRequest($"/v4/{MarketUrl}/user/reactivate", Method.POST);
var requestData = new GlitterWorldActivationRequest
{
Token = token, UserId = Utilities.GetUserId(), UserType = Utilities.GetUserType()
};
request.AddJsonBody(requestData);
var response = ExecuteRequestExpectData<GlitterWorldActivationRequestResponse>(client, request);
CheckResponseForErrors(response);
if (response.StatusCode == HttpStatusCode.OK)
{
var accepted = response.Data.Accepted ? "GWPActivateOK".Translate() : "GWPActivateFail".Translate();
var gameComponent = Current.Game.GetComponent<GlitterWorldGameComponent>();
gameComponent.HasSpawned = false;
Find.WindowStack.Add(new Dialog_MessageBox(accepted, title: "GlitterWorldPrime Reactivation"));
return;
}
Find.WindowStack.Add(new Dialog_MessageBox("GWPBadResponse".Translate(), title: "GlitterWorldPrime"));
}
internal static bool CheckIsOnline()
{
LogWriter.WriteMessage("Getting Server Status");
......@@ -92,13 +116,12 @@ namespace Glitterworld_Prime
case HttpStatusCode.Gone:
Find.WindowStack.Add(new Dialog_MessageBox(
"The server is in maintenance mode, Please try again later.", title: "GlitterWorldPrime"));
"GWPServerMaintenanceMode".Translate(), title: "GlitterWorldPrime"));
return false;
default:
Find.WindowStack.Add(new Dialog_MessageBox(
"We received an invalid response, It might be down or you maybe out of date.\nPlease check the forum/workshop.",
title: "GlitterWorldPrime"));
Find.WindowStack.Add(
new Dialog_MessageBox("GWPBadResponse".Translate(), title: "GlitterWorldPrime"));
return false;
}
}
......@@ -135,10 +158,7 @@ namespace Glitterworld_Prime
}
{
var d = new Dialog_MessageBox(
"We received an invalid response, It might be down or you maybe out of date.\nPlease check the forum/workshop.",
title: "GlitterWorldPrime");
Find.WindowStack.Add(d);
Find.WindowStack.Add(new Dialog_MessageBox("GWPBadResponse".Translate(), title: "GlitterWorldPrime"));
return false;
}
}
......@@ -348,7 +368,7 @@ namespace Glitterworld_Prime
LogWriter.WriteMessage("Sending Colony Metadata");
reason = 0;
var client = CreateRestClient();
var mapComponent = map.GetComponent<GlitterWorld_MapComponent>();
var gameComponent = Current.Game.GetComponent<GlitterWorldGameComponent>();
// Send colony metadata.
var cmd = new GlitterWorldColonyMetadata(
......@@ -357,7 +377,7 @@ namespace Glitterworld_Prime
Utilities.GetUserType(),
Utilities.GetUserId(),
Find.TickManager.TicksAbs,
mapComponent.HasSpawned
gameComponent.HasSpawned
);
......@@ -502,4 +522,4 @@ namespace Glitterworld_Prime
#endregion
}
}
\ No newline at end of file
}
......@@ -81,6 +81,29 @@ namespace Glitterworld_Prime.ApiStructs
#endregion
}
[Serializable]
internal class GlitterWorldActivationRequest
{
#region Properties
public string Token { get; set; }
public string UserId { get; set; }
public string UserType { get; set; }
#endregion
}
[Serializable]
internal class GlitterWorldActivationRequestResponse
{
#region Properties
public bool Accepted { get; set; }
#endregion
}
[Serializable]
internal class GlitterWorldIdResponse
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
namespace Glitterworld_Prime
{
class GlitterWorldGameComponent : GameComponent
{
public GlitterWorldGameComponent(Verse.Game game)
{
}
private string _hasSpawned = "false";
internal bool HasSpawned
{
get { return _hasSpawned == "true"; }
set { _hasSpawned = value ? "true" : "false"; }
}
}
}
......@@ -22,7 +22,7 @@ namespace Glitterworld_Prime
private string _colonyId = "";
private TraderPrime _currentTradeShip;
private string _hasSpawned = "false";
private bool _initComplete;
#endregion
......@@ -54,12 +54,6 @@ namespace Glitterworld_Prime
internal bool HasSentThingListYet { get; set; }
internal bool HasSpawned
{
get { return _hasSpawned == "true"; }
set { _hasSpawned = value ? "true" : "false"; }
}
#endregion
#region Methods
......@@ -69,7 +63,6 @@ namespace Glitterworld_Prime
LogWriter.WriteMessage("GlitterWorld Prime saving/loading Colony Metadata");
base.ExposeData();
Scribe_Values.Look(ref _colonyId, "GlitterWorldPrimeColonyID", "", false);
Scribe_Values.Look(ref _hasSpawned, "GlitterWorldPrimeCompatibleApi", "", false);
LogWriter.WriteMessage("GlitterWorld Prime (Save/Load) now using Colony ID: " + _colonyId);
}
......
......@@ -73,6 +73,7 @@
<ItemGroup>
<Compile Include="Building_TradeWithPrime.cs" />
<Compile Include="DialogPrimeCheckSubscription.cs" />
<Compile Include="DialogPrimeReactivate.cs" />
<Compile Include="DialogPrimeTrade.cs" />
<Compile Include="DialogPrimeUpdateSubscription.cs" />
<Compile Include="GlitterWorldApi.cs" />
......@@ -80,6 +81,7 @@
<Compile Include="GlitterWorldAssets.cs" />
<Compile Include="GlitterWorldOrderItem.cs" />
<Compile Include="GlitterWorldItem.cs" />
<Compile Include="GlitterWorldGameComponent.cs" />
<Compile Include="GlitterWorld_MapComponent.cs" />
<Compile Include="GlitterWorldDelivery.cs" />
<Compile Include="GlitterWorldOrderTracker.cs" />
......
......@@ -24,8 +24,8 @@ namespace Glitterworld_Prime.Patches
public static void Prefix(ThingDef def, IntVec3 c, int stackCount = -1, bool direct = false)
{
var mapComponent = Find.CurrentMap.GetComponent<GlitterWorld_MapComponent>();
mapComponent.HasSpawned = true;
var gameComponent = Current.Game.GetComponent<GlitterWorldGameComponent>();
gameComponent.HasSpawned = true;
}
#endregion
......@@ -33,4 +33,4 @@ namespace Glitterworld_Prime.Patches
#endregion
}
}
\ No newline at end of file
}
......@@ -276,10 +276,14 @@ namespace Glitterworld_Prime
internal static GlitterWorld_MapComponent GetMapComponent(Map map)
{
foreach (var component in map.components)
if (component.GetType() == typeof(GlitterWorld_MapComponent))
return (GlitterWorld_MapComponent) component;
return null;
try
{
return map.GetComponent<GlitterWorld_MapComponent>();
}
catch (Exception)
{
return null;
}
}
internal static bool HasBaseNameBeenSet(Map m)
......
......@@ -20,9 +20,14 @@
<GWPDialogCantAffordSubscription2>But you cannot afford to renew, The cost is:</GWPDialogCantAffordSubscription2>
<GWPCurrency>Silver</GWPCurrency>
<GWPGiveItAway>We can't pay you for goods worth less than 1 Silver, Continue anyway?</GWPGiveItAway>
<GWPBanned>You are banned from using GlitterWorld Prime</GWPBanned>
<GWPBanned>You are banned from using GlitterWorld Prime OR Steam is in offline mode!</GWPBanned>
<GWPSendingThingList>Sending Supported Thing List</GWPSendingThingList>
<GWPSendingModList>Sending Supported Mods</GWPSendingModList>
<GWPGetMarketData>Getting Market Data</GWPGetMarketData>
<GWPBadResponse>The server did not respond or gave an invalid response, It might be down or you might be out of date.\n\nPlease check the Discord, the Ludeon forum or the Steam Workshop for updates and news.</GWPBadResponse>
<GWPActivateOK>The server accepted the token.\n\nPlease don't use Developer mode or you could end up banned again!</GWPActivateOK>
<GWPActivateFail>The server did not accepted the token, Please check your token was correct.</GWPActivateFail>
<GWPServerMaintenanceMode>The server is in maintenance mode, Please try again later.</GWPServerMaintenanceMode>
<GWPOutOfDate>This mod version is out of date. You'll need to update before trading.</GWPOutOfDate>
<GWPActivateIncorrect>The token should be 8 characters long.</GWPActivateIncorrect>
</LanguageData>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment