Commit c7831182 authored by Adam Leyshon's avatar Adam Leyshon
Browse files

Added Ban checks

Corrected typos in translation file
Added check for very small silver amounts
parent 36f1d67e
...@@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.25420.1 ...@@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Glitterworld Prime", "Glitterworld Prime\Glitterworld Prime.csproj", "{1976D016-8918-48C9-A54E-4D9EF7F200B7}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Glitterworld Prime", "Glitterworld Prime\Glitterworld Prime.csproj", "{1976D016-8918-48C9-A54E-4D9EF7F200B7}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6D3468B4-EA3F-4886-BF33-142B8436A96F}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
......
...@@ -30,6 +30,7 @@ namespace Glitterworld_Prime ...@@ -30,6 +30,7 @@ namespace Glitterworld_Prime
private DownloadStatus _isDownloadComplete = DownloadStatus.Incomplete; private DownloadStatus _isDownloadComplete = DownloadStatus.Incomplete;
private bool _resubscribePromptShown; private bool _resubscribePromptShown;
private GlitterWorldSubscriptionMetadata _subscriptionMeta; private GlitterWorldSubscriptionMetadata _subscriptionMeta;
private int? _reason;
#endregion #endregion
...@@ -124,7 +125,17 @@ namespace Glitterworld_Prime ...@@ -124,7 +125,17 @@ namespace Glitterworld_Prime
break; break;
case DownloadStatus.Failed: case DownloadStatus.Failed:
Messages.Message("GWPUnavailable".Translate(), MessageTypeDefOf.NegativeEvent); string message;
if (_reason != null)
{
message = _reason == 403 ? "GWPBanned".Translate() : "GWPUnavailable".Translate();
}
else
{
message = "GWPUnavailable".Translate();
}
Messages.Message(message, MessageTypeDefOf.NegativeEvent);
Close(); Close();
break; break;
} }
...@@ -180,9 +191,11 @@ namespace Glitterworld_Prime ...@@ -180,9 +191,11 @@ namespace Glitterworld_Prime
} }
// Update Colony MetaData // Update Colony MetaData
if (!GlitterWorldApi.SendColonyMeta(_player.Map)) int reason;
if (!GlitterWorldApi.SendColonyMeta(_player.Map, out reason))
{ {
_isDownloadComplete = DownloadStatus.Failed; _isDownloadComplete = DownloadStatus.Failed;
if (reason != 0) _reason = reason;
return; return;
} }
...@@ -196,7 +209,7 @@ namespace Glitterworld_Prime ...@@ -196,7 +209,7 @@ namespace Glitterworld_Prime
} }
LogWriter.WriteMessage( LogWriter.WriteMessage(
$"GlitterWorld API: Subscripton server has expiry tick @ {_subscriptionMeta.TickSubscriptionExpires}"); $"GlitterWorld API: Subscription server has expiry tick @ {_subscriptionMeta.TickSubscriptionExpires}");
_mapComponent.SubscriptionExpiry = _subscriptionMeta.TickSubscriptionExpires; _mapComponent.SubscriptionExpiry = _subscriptionMeta.TickSubscriptionExpires;
_isDownloadComplete = DownloadStatus.Complete; _isDownloadComplete = DownloadStatus.Complete;
...@@ -215,10 +228,10 @@ namespace Glitterworld_Prime ...@@ -215,10 +228,10 @@ namespace Glitterworld_Prime
private Dialog_MessageBox CannotAffordSub() private Dialog_MessageBox CannotAffordSub()
{ {
var s = new StringBuilder(); var s = new StringBuilder();
s.AppendLine("GWPDialgoCantAffordSubscription1".Translate()); s.AppendLine("GWPDialogCantAffordSubscription1".Translate());
s.AppendLine("GWPDialgoCantAffordSubscription2".Translate()); s.AppendLine("GWPDialogCantAffordSubscription2".Translate());
s.AppendLine($"{_subscriptionMeta.SubscriptionCost} {"GWPCurrency".Translate()}"); s.AppendLine($"{_subscriptionMeta.SubscriptionCost} {"GWPCurrency".Translate()}");
return new Dialog_MessageBox(s.ToString(), title: "GWPDialgoCantAffordSubscriptionTitle".Translate()); return new Dialog_MessageBox(s.ToString(), title: "GWPDialogCantAffordSubscriptionTitle".Translate());
} }
#endregion #endregion
......
...@@ -164,7 +164,7 @@ namespace Glitterworld_Prime ...@@ -164,7 +164,7 @@ namespace Glitterworld_Prime
{ {
Action action = () => Action action = () =>
{ {
Log.Message("Button clicked", true); Log.Message("GWP Starting order build", true);
bool flag; bool flag;
...@@ -172,7 +172,7 @@ namespace Glitterworld_Prime ...@@ -172,7 +172,7 @@ namespace Glitterworld_Prime
if (!TradeSession.deal.TryExecute(out flag)) if (!TradeSession.deal.TryExecute(out flag))
{ {
Log.Message("Error @ TradeSession.deal.TryExecute()", true); Log.Message("Error at TradeSession.deal.TryExecute() or Colony couldn't afford it", true);
return; return;
} }
...@@ -205,6 +205,14 @@ namespace Glitterworld_Prime ...@@ -205,6 +205,14 @@ namespace Glitterworld_Prime
}; };
if (TradeSession.deal.DoesTraderHaveEnoughSilver()) if (TradeSession.deal.DoesTraderHaveEnoughSilver())
{ {
var amt = TradeSession.deal.SilverTradeable.CountToTransferToSource;
if (amt > 0 && amt < 1)
{
SoundDefOf.ClickReject.PlayOneShotOnCamera(null);
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("GWPGiveItAway".Translate(),
action, false, null));
}
action(); action();
} }
else else
......
...@@ -363,10 +363,10 @@ namespace Glitterworld_Prime ...@@ -363,10 +363,10 @@ namespace Glitterworld_Prime
} }
public static bool SendColonyMeta(Map map) public static bool SendColonyMeta(Map map, out int reason)
{ {
LogWriter.WriteMessage("Sending Colony Metadata"); LogWriter.WriteMessage("Sending Colony Metadata");
reason = 0;
var client = CreateRestClient(); var client = CreateRestClient();
// Send colony metadata. // Send colony metadata.
...@@ -407,6 +407,10 @@ namespace Glitterworld_Prime ...@@ -407,6 +407,10 @@ namespace Glitterworld_Prime
LogWriter.WriteMessage($"Colony ID from server: {Utilities.GetMapComponent(map).ColonyId}"); LogWriter.WriteMessage($"Colony ID from server: {Utilities.GetMapComponent(map).ColonyId}");
return true; return true;
case HttpStatusCode.Forbidden:
// Banned!
reason = 403;
return false;
} }
LogWriter.WriteErrorMessage("Failed to get trade identifier, Trades will fail."); LogWriter.WriteErrorMessage("Failed to get trade identifier, Trades will fail.");
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#endregion #endregion
using System; using System;
using System.Web.Script.Serialization;
namespace Glitterworld_Prime namespace Glitterworld_Prime
{ {
...@@ -34,18 +35,8 @@ namespace Glitterworld_Prime ...@@ -34,18 +35,8 @@ namespace Glitterworld_Prime
public string Quality public string Quality
{ {
get get { return _quality ?? (_quality = ""); }
{ set { _quality = value ?? ""; }
if (_quality == null) _quality = "";
return _quality;
}
set
{
if (value == null)
_quality = "";
else
_quality = value;
}
} }
public int Quantity { get; set; } public int Quantity { get; set; }
...@@ -70,6 +61,7 @@ namespace Glitterworld_Prime ...@@ -70,6 +61,7 @@ namespace Glitterworld_Prime
public float SellPriceOverride { get; set; } public float SellPriceOverride { get; set; }
#endregion #endregion
//public GlitterWorldItem(string name, float currentBuyPrice, float baseMarketValue, int quantity, //public GlitterWorldItem(string name, float currentBuyPrice, float baseMarketValue, int quantity,
...@@ -83,4 +75,10 @@ namespace Glitterworld_Prime ...@@ -83,4 +75,10 @@ namespace Glitterworld_Prime
// Quality = quality; // Quality = quality;
//} //}
} }
}
\ No newline at end of file public class GlitterWorldItemDumpData : GlitterWorldItem
{
public string LocalizedName { get; set; }
public string LanguageCode { get; set; }
}
}
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
......
...@@ -20,7 +20,7 @@ namespace Glitterworld_Prime.Tools ...@@ -20,7 +20,7 @@ namespace Glitterworld_Prime.Tools
thing.TryGetComp<CompQuality>().SetQuality(quality, ArtGenerationContext.Outsider); thing.TryGetComp<CompQuality>().SetQuality(quality, ArtGenerationContext.Outsider);
} }
private static IEnumerable<GlitterWorldItem> ComputeItemsMadeFromStuff(ThingDef thing, private static IEnumerable<GlitterWorldItemDumpData> ComputeItemsMadeFromStuff(ThingDef thing,
Dictionary<StuffCategoryDef, List<ThingDef>> stuffData) Dictionary<StuffCategoryDef, List<ThingDef>> stuffData)
{ {
foreach (var category in thing.stuffCategories) foreach (var category in thing.stuffCategories)
...@@ -31,18 +31,19 @@ namespace Glitterworld_Prime.Tools ...@@ -31,18 +31,19 @@ namespace Glitterworld_Prime.Tools
// Create the Thing // Create the Thing
Thing t = Utilities.CreateThing(thing.defName, 1, stuff.defName); Thing t = Utilities.CreateThing(thing.defName, 1, stuff.defName);
yield return new GlitterWorldItem() yield return new GlitterWorldItemDumpData()
{ {
Name = thing.defName, Name = thing.defName,
StuffType = stuff.defName, StuffType = stuff.defName,
BaseMarketValue = t.MarketValue, BaseMarketValue = t.MarketValue,
MinifiedContainer = thing.Minifiable MinifiedContainer = thing.Minifiable,
LocalizedName = $"{stuff.LabelCap} {thing.LabelCap}"
}; };
} }
} }
} }
private static IEnumerable<GlitterWorldItem> ComputeItemsMadeFromStuffWithQuality(ThingDef thing, private static IEnumerable<GlitterWorldItemDumpData> ComputeItemsMadeFromStuffWithQuality(ThingDef thing,
Dictionary<StuffCategoryDef, List<ThingDef>> stuffData) Dictionary<StuffCategoryDef, List<ThingDef>> stuffData)
{ {
for (var quality = 2; quality < 7; quality++) for (var quality = 2; quality < 7; quality++)
...@@ -53,41 +54,45 @@ namespace Glitterworld_Prime.Tools ...@@ -53,41 +54,45 @@ namespace Glitterworld_Prime.Tools
{ {
Thing t = Utilities.CreateThing(thing.defName, 1, stuff.defName); Thing t = Utilities.CreateThing(thing.defName, 1, stuff.defName);
setQuality(t, (QualityCategory)quality); var qualityObject = (QualityCategory) quality;
setQuality(t, qualityObject);
yield return new GlitterWorldItem() yield return new GlitterWorldItemDumpData()
{ {
Name = thing.defName, Name = thing.defName,
Quality = Enum.GetName(typeof(QualityCategory), quality), Quality = Enum.GetName(typeof(QualityCategory), quality),
StuffType = stuff.defName, StuffType = stuff.defName,
BaseMarketValue = t.MarketValue, BaseMarketValue = t.MarketValue,
MinifiedContainer = thing.Minifiable MinifiedContainer = thing.Minifiable,
LocalizedName = $"{qualityObject.GetLabel()} {stuff.LabelCap} {thing.LabelCap}"
}; };
} }
} }
} }
private static IEnumerable<GlitterWorldItem> ComputeItemsWithQuality(ThingDef thing) private static IEnumerable<GlitterWorldItemDumpData> ComputeItemsWithQuality(ThingDef thing)
{ {
for (var quality = 2; quality < 7; quality++) for (var quality = 2; quality < 7; quality++)
{ {
Thing t = Utilities.CreateThing(thing.defName, 1); Thing t = Utilities.CreateThing(thing.defName, 1);
setQuality(t, (QualityCategory)quality); var qualityObject = (QualityCategory) quality;
yield return new GlitterWorldItem() setQuality(t, qualityObject);
yield return new GlitterWorldItemDumpData()
{ {
Name = thing.defName, Name = thing.defName,
Quality = Enum.GetName(typeof(QualityCategory), quality), Quality = Enum.GetName(typeof(QualityCategory), quality),
BaseMarketValue = t.MarketValue, BaseMarketValue = t.MarketValue,
MinifiedContainer = thing.Minifiable MinifiedContainer = thing.Minifiable,
LocalizedName = $"{qualityObject.GetLabel()} {thing.LabelCap}"
}; };
} }
} }
private static IEnumerable<GlitterWorldItem> ComputeThingDef(ThingDef thing, private static IEnumerable<GlitterWorldItemDumpData> ComputeThingDef(ThingDef thing,
Dictionary<StuffCategoryDef, List<ThingDef>> stuffData) Dictionary<StuffCategoryDef, List<ThingDef>> stuffData)
{ {
var result = new List<GlitterWorldItem>(); var result = new List<GlitterWorldItemDumpData>();
// Add support for things made of stuff. // Add support for things made of stuff.
if (thing.MadeFromStuff) if (thing.MadeFromStuff)
...@@ -103,21 +108,22 @@ namespace Glitterworld_Prime.Tools ...@@ -103,21 +108,22 @@ namespace Glitterworld_Prime.Tools
if (thing.HasComp(typeof(CompQuality))) if (thing.HasComp(typeof(CompQuality)))
result.AddRange(ComputeItemsWithQuality(thing)); result.AddRange(ComputeItemsWithQuality(thing));
else else
result.Add(new GlitterWorldItem() result.Add(new GlitterWorldItemDumpData()
{ {
Name = thing.defName, Name = thing.defName,
BaseMarketValue = thing.BaseMarketValue, BaseMarketValue = thing.BaseMarketValue,
MinifiedContainer = thing.Minifiable MinifiedContainer = thing.Minifiable,
LocalizedName = thing.LabelCap
}); });
} }
return result; return result;
} }
private static IEnumerable<GlitterWorldItem> GetThingData() private static IEnumerable<GlitterWorldItemDumpData> GetThingData()
{ {
var stuffCategories = new Dictionary<StuffCategoryDef, List<ThingDef>>(); var stuffCategories = new Dictionary<StuffCategoryDef, List<ThingDef>>();
var thingData = new List<GlitterWorldItem>(); var thingData = new List<GlitterWorldItemDumpData>();
var stuffCategoryDefs = DefDatabase<StuffCategoryDef>.AllDefsListForReading; var stuffCategoryDefs = DefDatabase<StuffCategoryDef>.AllDefsListForReading;
var things = DefDatabase<ThingDef>.AllDefsListForReading; var things = DefDatabase<ThingDef>.AllDefsListForReading;
...@@ -154,7 +160,14 @@ namespace Glitterworld_Prime.Tools ...@@ -154,7 +160,14 @@ namespace Glitterworld_Prime.Tools
internal static void DumpData() internal static void DumpData()
{ {
var data = new List<GlitterWorldItem>(GetThingData()); var languageName = Verse.LanguageDatabase.activeLanguage.FriendlyNameEnglish;
var data = new List<GlitterWorldItemDumpData>(GetThingData());
data.ForEach(t =>
{
t.LanguageCode = languageName.ToLowerInvariant();
t.LocalizedName = t.LocalizedName.ToLowerInvariant();
});
var path = Path.Combine(GenFilePaths.SaveDataFolderPath, "GWP-MarketDataDump.json"); var path = Path.Combine(GenFilePaths.SaveDataFolderPath, "GWP-MarketDataDump.json");
var jsonString = RestSharp.SimpleJson.SerializeObject(data); var jsonString = RestSharp.SimpleJson.SerializeObject(data);
File.WriteAllText(path, jsonString); File.WriteAllText(path, jsonString);
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
<GWPDialogSubscribe1>Resubscribe? This will cost</GWPDialogSubscribe1> <GWPDialogSubscribe1>Resubscribe? This will cost</GWPDialogSubscribe1>
<GWPDialogSubscribe2>for</GWPDialogSubscribe2> <GWPDialogSubscribe2>for</GWPDialogSubscribe2>
<GWPSubscriptionDuration>1 Quadrum</GWPSubscriptionDuration> <GWPSubscriptionDuration>1 Quadrum</GWPSubscriptionDuration>
<GWPDialgoCantAffordSubscriptionTitle>Not enough resources</GWPDialgoCantAffordSubscriptionTitle> <GWPDialogCantAffordSubscriptionTitle>Not enough resources</GWPDialogCantAffordSubscriptionTitle>
<GWPDialgoCantAffordSubscription1>Your GlitterWorld Prime Subscription has ended</GWPDialgoCantAffordSubscription1> <GWPDialogCantAffordSubscription1>Your GlitterWorld Prime Subscription has ended</GWPDialogCantAffordSubscription1>
<GWPDialgoCantAffordSubscription2>But you cannot afford to renew, The cost is:</GWPDialgoCantAffordSubscription2> <GWPDialogCantAffordSubscription2>But you cannot afford to renew, The cost is:</GWPDialogCantAffordSubscription2>
<GWPCurrency>Silver</GWPCurrency> <GWPCurrency>Silver</GWPCurrency>
<GWPGiveItAway>We can't pay you for goods worth less than 1 Silver, Continue anyway?</GWPGiveItAway>
<GWPBanned>You have been banned from using GlitterWorld Prime</GWPBanned>
</LanguageData> </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