Commit 43a9267e authored by Adam Leyshon's avatar Adam Leyshon
Browse files

Merge branch 'aleyshon_compat_fixes' into 'develop'

Completely re-worked order system.

See merge request GWP/Release!3
parents 8e85ed84 42e4eced
<?xml version="1.0"?>
<!-- Generated by NAntBuilder v2.0 -->
<project default="A17">
<property name="ModName" value="GlitterWorldPrime [A17]" />
<property name="ModPath" value="F:\Games\RimWorld1557Win\Mods\Glitterworld Prime A17\" />
<!-- Name: 'ModOutput' Value: 'C:\Users\aleyshon\Desktop\Mod\GlitterWorldPrime [A17] Debug\' -->
<property name="ModOutput" value="C:\Users\aleyshon\Desktop\Mod\GlitterWorldPrime [A17] Debug\" />
<property name="ModBinary" value="${ModPath}\Assemblies\GlitterWorld Prime.dll" />
<property name="MSBuildPath" value="C:\Program Files (x86)\MSBuild\14.0\Bin\Msbuild.exe" />
<property name="SteamModFolder" value="E:\Games\Steam\steamapps\common\RimWorld\Mods" />
<target name="A17">
<echo message="Building default target " />
<!-- Build Debug -->
<exec program="${MSBuildPath}">
<arg value="${ModPath}\Glitterworld Prime.sln" />
<arg value="/t:Clean,Build" />
<arg value="/p:Configuration=Debug" />
</exec>
<!-- Set Git Output File -->
<property name="git.output.file" value="${path::get-temp-path()}\sha1.txt" />
<!-- Get Git SHA -->
<exec program="git.exe" commandline="rev-parse --short HEAD" workingdir="${ModPath}" output="${git.output.file}" />
<!-- Get SHA from File -->
<loadfile file="${git.output.file}" property="git.output" />
<!-- Cleanup Git Output -->
<property name="ModSHA" value="${string::trim(git.output)}" />
<!-- Copy About Folder -->
<copy todir="${ModOutput}\About" overwrite="True">
<fileset basedir="${ModPath}\About" />
</copy>
<!-- Load About.xml -->
<loadfile file="${ModOutput}\About\About.xml" property="ModAbout">
<filterchain>
<replacetokens>
<token key="SHAHASH" value="${ModSHA}" />
</replacetokens>
</filterchain>
</loadfile>
<!-- Save About.xml -->
<echo message="${ModAbout}" file="${ModOutput}\About\About.xml" />
<!-- Get Version Info -->
<property name="ModBinaryVersion" value="${assemblyname::get-version(assemblyname::get-assembly-name(ModBinary))}" />
<!-- Load Version.xml -->
<loadfile file="${ModOutput}\About\Version.xml" property="ModVersion">
<filterchain>
<replacetokens>
<token key="Version" value="${ModBinaryVersion}" />
</replacetokens>
</filterchain>
</loadfile>
<!-- Save Version.xml -->
<echo message="${ModVersion}" file="${ModOutput}\About\Version.xml" />
<!-- Copy Assemblies -->
<copy todir="${ModOutput}\Assemblies" overwrite="True">
<fileset basedir="${ModPath}\Assemblies">
<include name="*.dll" />
</fileset>
</copy>
<!-- Copy Defs -->
<copy todir="${ModOutput}\Defs" overwrite="True">
<fileset basedir="${ModPath}\Defs" />
</copy>
<!-- Copy Textures -->
<copy todir="${ModOutput}\Textures" overwrite="True">
<fileset basedir="${ModPath}\Textures" />
</copy>
<zip zipfile="${ModOutput}\..\..\${ModName} Build ${ModSHA}.zip" if="False">
<fileset prefix="${ModName}" basedir="${ModOutput}">
<include name="**/*" />
</fileset>
</zip>
<delete dir="${SteamModFolder}\${ModName}" />
<!-- Copy Mod to Steam -->
<copy todir="${SteamModFolder}\${ModName}\" overwrite="True">
<fileset basedir="${ModOutput}" />
</copy>
</target>
</project>
<?xml version="1.0"?>
<!-- Generated by NAntBuilder v2.0 -->
<project default="A17">
<property name="ModName" value="GlitterWorldPrime [A17]" />
<property name="ModPath" value="F:\Games\RimWorld1557Win\Mods\Glitterworld Prime A17\" />
<property name="ModOutput" value="C:\Users\aleyshon\Desktop\Mod\GlitterWorldPrime [A17]\" />
<property name="ModBinary" value="${ModPath}\Assemblies\GlitterWorld Prime.dll" />
<property name="MSBuildPath" value="C:\Program Files (x86)\MSBuild\14.0\Bin\Msbuild.exe" />
<property name="SteamModFolder" value="E:\Games\Steam\steamapps\common\RimWorld\Mods" />
<target name="A17">
<echo message="Building default target " />
<!-- Build Release -->
<exec program="${MSBuildPath}">
<arg value="${ModPath}\Glitterworld Prime.sln" />
<arg value="/t:Clean,Build" />
<arg value="/p:Configuration=Release" />
</exec>
<!-- Set Git Output File -->
<property name="git.output.file" value="${path::get-temp-path()}\sha1.txt" />
<!-- Get Git SHA -->
<exec program="git.exe" commandline="rev-parse --short HEAD" workingdir="${ModPath}" output="${git.output.file}" />
<!-- Get SHA from File -->
<loadfile file="${git.output.file}" property="git.output" />
<!-- Cleanup Git Output -->
<property name="ModSHA" value="${string::trim(git.output)}" />
<!-- Copy About Folder -->
<copy todir="${ModOutput}\About" overwrite="True">
<fileset basedir="${ModPath}\About" />
</copy>
<!-- Load About.xml -->
<loadfile file="${ModOutput}\About\About.xml" property="ModAbout">
<filterchain>
<replacetokens>
<token key="SHAHASH" value="${ModSHA}" />
</replacetokens>
</filterchain>
</loadfile>
<!-- Save About.xml -->
<echo message="${ModAbout}" file="${ModOutput}\About\About.xml" />
<!-- Get Version Info -->
<property name="ModBinaryVersion" value="${assemblyname::get-version(assemblyname::get-assembly-name(ModBinary))}" />
<!-- Load Version.xml -->
<loadfile file="${ModOutput}\About\Version.xml" property="ModVersion">
<filterchain>
<replacetokens>
<token key="Version" value="${ModBinaryVersion}" />
</replacetokens>
</filterchain>
</loadfile>
<!-- Save Version.xml -->
<echo message="${ModVersion}" file="${ModOutput}\About\Version.xml" />
<!-- Copy Assemblies -->
<copy todir="${ModOutput}\Assemblies" overwrite="True">
<fileset basedir="${ModPath}\Assemblies">
<include name="*.dll" />
</fileset>
</copy>
<!-- Copy Defs -->
<copy todir="${ModOutput}\Defs" overwrite="True">
<fileset basedir="${ModPath}\Defs" />
</copy>
<!-- Copy Textures -->
<copy todir="${ModOutput}\Textures" overwrite="True">
<fileset basedir="${ModPath}\Textures" />
</copy>
<zip zipfile="${ModOutput}\..\..\${ModName} Build ${ModSHA}.zip">
<fileset prefix="${ModName}" basedir="${ModOutput}">
<include name="**/*" />
</fileset>
</zip>
<delete dir="${SteamModFolder}\${ModName}" />
<!-- Copy Mod to Steam -->
<copy todir="${SteamModFolder}\${ModName}\" overwrite="True">
<fileset basedir="${ModOutput}" />
</copy>
</target>
</project>
<?xml version="1.0" encoding="utf-8"?>
<ModMetaData>
<name>GlitterWorld Prime [B18]</name>
<name>GlitterWorld Prime [Unstable]</name>
<author>TwistedSoul / TheCodeCache.NET</author>
<targetVersion>0.18.0</targetVersion>
<targetVersion>0.19.0</targetVersion>
<url>https://www.thecodecache.net</url>
<description>
Build: @SHAHASH@ \n
&lt;color=orange&gt;&lt;b&gt;Warning: &lt;/b&gt; \n
While care has been taken to make sure stuff works, \n
Your items can be lost if the trade with the server fails.&lt;/color&gt;\n
By using this mod you acknowledge this and accept the risk.
Anything you want, delivered anywhere in the universe in under 24 earth hours!
</description>
</ModMetaData>
1206654786
\ No newline at end of file
......@@ -7,14 +7,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Glitterworld Prime", "Glitt
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug B18|Any CPU = Debug B18|Any CPU
Release B18|Any CPU = Release B18|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug B18|Any CPU.ActiveCfg = Debug B18|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug B18|Any CPU.Build.0 = Debug B18|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release B18|Any CPU.ActiveCfg = Release B18|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release B18|Any CPU.Build.0 = Release B18|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -3,7 +3,7 @@
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, Building_TradeWithPrime.cs, Created 2017-11-18
// Glitterworld Prime, Building_TradeWithPrime.cs, Created 2018-07-22
#endregion
......
......@@ -3,7 +3,7 @@
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, DialogPrimeCheckSubscription.cs, Created 2018-01-16
// Glitterworld Prime, DialogPrimeCheckSubscription.cs, Created 2018-07-22
#endregion
......@@ -157,17 +157,34 @@ namespace Glitterworld_Prime
_isDownloadComplete = DownloadStatus.Failed;
return;
}
// Get Unique Colony ID if one isn't set.
if (_mapComponent.ColonyId.NullOrEmpty())
if (!GlitterWorldApi.CreateNewColonyId(_player.Map))
#if DEBUG
LogWriter.WriteMessage($"User type is {Utilities.GetUserType()}");
LogWriter.WriteMessage($"User ID is {Utilities.GetUserId()}");
#endif
if (Utilities.GetUserType() == "Normal" && Utilities.GetUserId().NullOrEmpty())
{
var result = GlitterWorldApi.CreateUserId();
if (result == null)
{
_isDownloadComplete = DownloadStatus.Failed;
return;
}
Utilities.StoreUserId(result);
}
else
{
#if DEBUG
LogWriter.WriteMessage($"Not creating new ID");
#endif
}
// Update Colony MetaData
GlitterWorldApi.UploadColonyMetadata(_player.Map);
if (!GlitterWorldApi.SendColonyMeta(_player.Map))
{
_isDownloadComplete = DownloadStatus.Failed;
return;
}
// Check if the user has a subscription and how long is left.
_subscriptionMeta = GlitterWorldApi.GetSubscriptionData(_player.Map);
......
......@@ -3,7 +3,7 @@
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, DialogPrimeGetData.cs, Created 2017-11-18
// Glitterworld Prime, DialogPrimeGetData.cs, Created 2018-07-22
#endregion
......
......@@ -251,15 +251,25 @@ namespace Glitterworld_Prime
_cachedCurrencyTradeable = (from x in TradeSession.deal.AllTradeables
where x.IsCurrency
select x).FirstOrDefault();
#if DEBUG
foreach (var tr in TradeSession.deal.AllTradeables)
LogWriter.WriteMessage(
$"Item {tr.AnyThing.GetInnerIfMinified().def} is minified: {tr.AnyThing.def.Minifiable}, " +
$"Belongs in Categories {string.Join(", ", tr.AnyThing.GetInnerIfMinified().def.thingCategories.Select(t => t.ToString()).ToArray())} ");
#endif
_cachedTradeables = (from tr in TradeSession.deal.AllTradeables
where !tr.IsCurrency
where !tr.Label.NullOrEmpty() &&
tr.Label.ToLowerInvariant().Contains(_textFilter.ToLowerInvariant())
where _filter.DescendantThingDefs.Contains(tr.FirstThingColony?.GetInnerIfMinified().def) || !_filterOnlyColonyItems &&
where _filter.DescendantThingDefs.Contains(tr.FirstThingColony?.GetInnerIfMinified().def) ||
!_filterOnlyColonyItems &&
_filter.DescendantThingDefs.Contains(tr.FirstThingTrader?.GetInnerIfMinified().def)
orderby tr.ThingDef.defName descending
select tr).ThenBy(tr => tr, _sorter1.Comparer).ThenBy(tr => tr, _sorter2.Comparer)
.ThenBy(tr => TransferableUIUtility.DefaultListOrderPriority(tr)).ThenBy(tr => tr.ThingDef.label)
.ThenBy(TransferableUIUtility.DefaultListOrderPriority).ThenBy(tr => tr.ThingDef.label)
.ThenBy(
delegate(Tradeable tr)
{
......
......@@ -3,7 +3,7 @@
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, DialogPrimeUpdateSubscription.cs, Created 2018-01-17
// Glitterworld Prime, DialogPrimeUpdateSubscription.cs, Created 2018-07-22
#endregion
......
......@@ -3,13 +3,14 @@
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, GlitterWorldApi.cs, Created 2017-11-18
// Glitterworld Prime, GlitterWorldApi.cs, Created 2018-07-22
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Net;
......@@ -17,7 +18,6 @@ using System.Text;
using Glitterworld_Prime.ApiStructs;
using RestSharp;
using Verse;
using Steamworks;
namespace Glitterworld_Prime
{
......@@ -25,9 +25,13 @@ namespace Glitterworld_Prime
{
#region Fields
private static readonly float ClientVersion = 2.5f;
private static readonly float ClientVersion = 3.0f;
private static readonly string BaseUrl = "https://prime.thecodecache.net";
#if LOCALSERVER
private static readonly string BaseUrl = "http://127.0.0.1:5000/v3";
#else
private static readonly string BaseUrl = "https://prime.thecodecache.net/v3";
#endif
#endregion
......@@ -38,7 +42,7 @@ namespace Glitterworld_Prime
LogWriter.WriteMessage("Getting API Version");
var client = CreateRestClient();
var request = new RestRequest("/server/version/api", Method.GET);
var request = new RestRequest("/application/version", Method.GET);
var response =
ExecuteRequestExpectData<GlitterWorldApiVersionResponse>(client, request);
......@@ -72,7 +76,7 @@ namespace Glitterworld_Prime
LogWriter.WriteMessage("Getting Server Status");
var client = CreateRestClient();
var request = new RestRequest("/server/maintenance/mode", Method.GET);
var request = new RestRequest("/application/maintenance/mode", Method.GET);
var response = ExecuteRequestNoDataExpected(client, request);
......@@ -100,7 +104,7 @@ namespace Glitterworld_Prime
{
LogWriter.WriteMessage("Getting Server Status Async");
var client = CreateRestClient();
var request = new RestRequest("/server/maintenance/mode", Method.GET);
var request = new RestRequest("/application/maintenance/mode", Method.GET);
client.ExecuteAsyncGet(request, callback, "GET");
}
......@@ -109,7 +113,7 @@ namespace Glitterworld_Prime
LogWriter.WriteMessage("Getting Maintenance Window");
var client = CreateRestClient();
var request = new RestRequest("/server/maintenance/window", Method.GET);
var request = new RestRequest("/application/maintenance/window", Method.GET);
var response =
ExecuteRequestExpectData<GlitterWorldApiServerMaintenanceWindow>(client, request);
......@@ -119,7 +123,7 @@ namespace Glitterworld_Prime
if (response.Data.IsSet() && response.Data.IsSoon())
{
var d = new Dialog_MessageBox(
$"The server will be starting maintenance at {response.Data.StartTime().ToString()} and will last {response.Data.DurationInHours()} hour(s).",
$"The server will be starting maintenance at {response.Data.StartTime().ToString(CultureInfo.CurrentCulture)} and will last {response.Data.DurationInHours()} hour(s).",
title: "GlitterWorldPrime");
Find.WindowStack.Add(d);
}
......@@ -145,39 +149,14 @@ namespace Glitterworld_Prime
LogWriter.DumpObjectToLog(response);
}
public static bool CreateNewColonyId(Map map)
{
LogWriter.WriteMessage("Getting Colony ID");
var client = CreateRestClient();
var request = new RestRequest("/colony/generate_id", Method.GET);
var response =
ExecuteRequestExpectData<GlitterWorldColonyIdResponse>(client, request);
if (response.StatusCode == HttpStatusCode.OK)
{
Utilities.GetMapComponent(map).ColonyId = response.Data.UUID;
LogWriter.WriteMessage("This colony is now known as " +
Utilities.GetMapComponent(map).ColonyId);
return true;
}
LogWriter.WriteErrorMessage("Failed to get Colony identifier, Trades will fail.");
return false;
}
public static void GetServerGoodsAsync(GlitterWorld_MapComponent mapComponent,
Action<IRestResponse<List<GlitterWorldItem>>, RestRequestAsyncHandle> callback)
{
LogWriter.WriteMessage("Getting Market Data");
var client = CreateRestClient();
var request = new RestRequest("/market/get_items", Method.POST);
var request = new RestRequest("/market/process_item_list_request", Method.POST);
#if B18
// Compress the list of things to request and send it as a file.
var jsonString = request.JsonSerializer.Serialize(mapComponent.ThingsToRequestFromMarket);
byte[] compressed;
......@@ -197,9 +176,7 @@ namespace Glitterworld_Prime
}
request.AddFileBytes("things", compressed, "things");
#else
request.AddJsonBody(mapComponent.ThingsToRequestFromMarket);
#endif
client.ExecuteAsyncPost(request,
callback, "POST");
......@@ -227,8 +204,8 @@ namespace Glitterworld_Prime
return response.Data;
}
public static bool PlaceOrder(string colonyId, int currentTick, List<GlitterWorldItem> thingsSold,
List<GlitterWorldItem> thingsOnOrder)
public static bool PlaceOrder(string colonyId, int currentTick, List<GlitterWorldOrderItem> thingsSold,
List<GlitterWorldOrderItem> thingsOnOrder)
{
LogWriter.WriteMessage("Placing Order");
......@@ -288,6 +265,26 @@ namespace Glitterworld_Prime
return false;
}
public static RestRequestAsyncHandle UpdateOrderStatusAsync(string colonyId, string orderId, string status,
Action<IRestResponse, RestRequestAsyncHandle> callback)
{
LogWriter.WriteMessage($"Marking order {orderId} as {status}.");
var client = CreateRestClient();
var request = new RestRequest($"/orders/{colonyId}/{orderId}", Method.POST);
var statusBody = new GlitterWorldOrderStatus
{
Status = status
};
request.AddJsonBody(statusBody);
// Make request.
return client.ExecuteAsyncPost(request, callback, "POST");
}
public static GlitterWorldDeliveryMetaData GetDeliveryMetaData(string colonyId, string orderId)
{
......@@ -338,50 +335,91 @@ namespace Glitterworld_Prime
return true;
}
public static bool UploadColonyMetadata(Map map)
public static GlitterWorldIdResponse CreateUserId()
{
#if DEBUG
LogWriter.WriteMessage("Getting a User ID from Server");
#endif
var client = CreateRestClient();
var request = new RestRequest("/user/create", Method.GET);
// Make request.
try
{
var response = ExecuteRequestExpectData<GlitterWorldIdResponse>(client, request);
// Return data if 200 OK else null.
if (response.StatusCode == HttpStatusCode.OK) return response.Data;
LogWriter.WriteErrorMessage("Failed to get user data");
}
catch (Exception e)
{
LogWriter.WriteErrorMessage("Failed to get user data");
LogWriter.DumpObjectToLog(e);
}
return null;
}
public static bool SendColonyMeta(Map map)
{
LogWriter.WriteMessage("Sending Colony Metadata");
var client = CreateRestClient();
RestRequest request;
// Send colony metadata.
var cmd = new GlitterWorldColonyMetadata(
Utilities.GetColonyFaction().Name,
Find.World.info.name, Utilities.GetCurrentMapName(map),
Utilities.GetUserSteamId()
Utilities.GetUserType(),
Utilities.GetUserId()
);
request = new RestRequest("/colonies/" + Utilities.GetMapComponent(map).ColonyId, Method.PUT);
request.AddJsonBody(cmd);
var response = ExecuteRequestNoDataExpected(client, request);
var colonyId = Utilities.GetMapComponent(map).ColonyId;
if (response.StatusCode != HttpStatusCode.OK)
IRestResponse<GlitterWorldIdResponse> response;
if (colonyId.NullOrEmpty() || !colonyId.NullOrEmpty() && colonyId.Contains("-"))
{
LogWriter.WriteErrorMessage("Failed to send Colony Metadata, Trades will fail.");
return false;
var request = new RestRequest("/colonies/create", Method.PUT);
request.AddJsonBody(cmd);
response = ExecuteRequestExpectData<GlitterWorldIdResponse>(client, request);
}
else
{
var request = new RestRequest("/colonies/" + Utilities.GetMapComponent(map).ColonyId, Method.PUT);
return true;
request.AddJsonBody(cmd);
response = ExecuteRequestExpectData<GlitterWorldIdResponse>(client, request);
}
private static RestClient CreateRestClient()
switch (response.StatusCode)
{
var client = new RestClient(BaseUrl);
#if B18
client.AllowDecompression = true;
#else
client.AllowDecompression = false;
#endif
client.UserAgent = "GlitterWorldPrime " + Utilities.Version;
case HttpStatusCode.OK:
return true;
case HttpStatusCode.Created:
Utilities.GetMapComponent(map).ColonyId = response.Data.Hash;
var steamId = Utilities.GetUserSteamId();
LogWriter.WriteMessage($"Colony ID from server: {Utilities.GetMapComponent(map).ColonyId}");
if (steamId != "")
client.UserAgent += " Steam";
else
client.UserAgent += " Standard";
return true;
}
LogWriter.WriteErrorMessage("Failed to get trade identifier, Trades will fail.");
return false;
}
private static RestClient CreateRestClient()
{
var client = new RestClient(BaseUrl)
{
AllowDecompression = true,
UserAgent = $"GlitterWorldPrime {Utilities.Version} {Utilities.GetUserType()}"
};
return client;
}
......
......@@ -3,7 +3,7 @@
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, GlitterWorldApiStructs.cs, Created 2017-11-18
// Glitterworld Prime, GlitterWorldApiStructs.cs, Created 2018-07-22
#endregion
......@@ -82,13 +82,11 @@ namespace Glitterworld_Prime.ApiStructs
}
[Serializable]
public