Server Initialization and Serverside Galaxy/Zone Delivery

Made the master server connect to the database and now it's listening for and responding correctly to GalaxyRequestMessages and ZoneRequestMessages, generating the zone contents if they do not yet exist.
This commit is contained in:
hyperion51 2020-03-27 01:53:03 +00:00
commit f8a6582154
34 changed files with 845 additions and 115 deletions

View file

@ -1108,6 +1108,7 @@
<e p="PowerBrush.shader" t="Include" />
<e p="SimplexBrush.shader" t="Include" />
</e>
<e p="StrategyGameManager.cs" t="Include" />
<e p="TextMesh Pro" t="Include">
<e p="Fonts" t="Include">
<e p="LiberationSans - OFL.txt" t="Include" />

View file

@ -397,6 +397,7 @@
<Compile Include="Assets\Scripts\UnityExtensions.cs" />
<Compile Include="Assets\Scripts\UnityFormatters.cs" />
<Compile Include="Assets\Scripts\ZoneRenderer.cs" />
<Compile Include="Assets\StrategyGameManager.cs" />
<None Include="Assets\Shaders\AdditiveUI.shader" />
<None Include="Assets\Shaders\Background.shader" />
<None Include="Assets\TextMesh Pro\Resources\Shaders\TMP_SDF-Surface-Mobile.shader" />

View file

@ -18,10 +18,10 @@ public class LoginScreen : MonoBehaviour
void Start()
{
Error.text = "";
Error.text = " ";
LoginButton.CurrentState = FlatButtonState.Selected;
CultClient.AddMessageListener<LoginSuccessMessage>(success => SceneManager.LoadScene("Main"));
CultClient.AddMessageListener<ErrorMessage>(error => Error.text = error.Error);
CultClient.OnError += s => Error.text = s;
RegisterButton.OnClick += _ =>
{
if (_registering)

View file

@ -0,0 +1,77 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Galaxy Background
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 57000f7bd59643b4f9a5731dea6468ef
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -196,49 +196,6 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 313576382}
m_CullTransparentMesh: 0
--- !u!1 &518090073
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 518090075}
- component: {fileID: 518090074}
m_Layer: 0
m_Name: NetworkManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &518090074
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 518090073}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a4689a973ca91db4c94ad7946b6cdf48, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &518090075
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 518090073}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 533.1099, y: 377.69528, z: 10.5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0

View file

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using LiteNetLib;
@ -33,9 +34,9 @@ public static class CultClient {
Logger($"Sending message {MessagePackSerializer.SerializeToJson(m as Message)}");
_peer.Send(m as Message);
}
else Logger("Cannot send message, client is not verified!");
else OnError?.Invoke("Cannot send, client is not verified!");
}
else Logger("Cannot send message, client is not connected!");
else OnError?.Invoke("Cannot send, client is not connected!");
}
public static void ClearMessageListeners()
@ -52,25 +53,37 @@ public static class CultClient {
public static void Login(string auth, string password)
{
if (8 < password.Length && password.Length < 32)
Send(new LoginMessage
{
Auth = auth,
Password = _hasher.ComputeHash(Encoding.UTF8.GetBytes(password))
});
else Logger("Invalid Password");
if (auth.Length>0)
{
if (8 <= password.Length && password.Length < 32)
Send(new LoginMessage
{
Auth = auth,
Password = _hasher.ComputeHash(Encoding.UTF8.GetBytes(password))
});
else OnError?.Invoke("Password Invalid: needs to be at least 8 characters");
}
else OnError?.Invoke("Email/Username Empty");
}
public static void Register(string email, string username, string password)
{
if (8 < password.Length && password.Length < 32)
Send(new RegisterMessage
if (email.Length > 0)
{
if (username.Length > 0)
{
Email = email,
Name = username,
Password = _hasher.ComputeHash(Encoding.UTF8.GetBytes(password))
});
else Logger("Invalid Password");
if (8 <= password.Length && password.Length < 32)
Send(new RegisterMessage
{
Email = email,
Name = username,
Password = _hasher.ComputeHash(Encoding.UTF8.GetBytes(password))
});
else OnError?.Invoke("Password Invalid: needs to be at least 8 characters");
}
else OnError?.Invoke("Username Empty");
}
else OnError?.Invoke("Email Empty");
}
public static void Connect(string host = "localhost", int port = 3075)

View file

@ -52,6 +52,8 @@ public class SerializerTestWindow : EditorWindow
}
};
Converter.Serializer.Converters.Add(new MathJsonConverter());
// Set extensions to default resolver.
var resolver = CompositeResolver.Create(
MathResolver.Instance,
@ -61,8 +63,6 @@ public class SerializerTestWindow : EditorWindow
var options = MessagePackSerializerOptions.Standard.WithResolver(resolver);
MessagePackSerializer.DefaultOptions = options;
Converter.Serializer.Converters.Add(new MathJsonConverter());
if (GUILayout.Button("Print MsgPack JSON"))
Debug.Log(MessagePackSerializer.SerializeToJson(obj, options));

View file

@ -76,7 +76,7 @@ public class DatabaseCache
return _types[typeof(T)].Values.Cast<T>();
}
public void Delete(DatabaseEntry entry)
public void Delete(DatabaseEntry entry, bool remote = false)
{
_entries.Remove(entry.ID);
foreach (var type in _types.Values)
@ -84,6 +84,7 @@ public class DatabaseCache
type.Remove(entry.ID);
}
OnDataDeleteLocal?.Invoke(entry);
if (!remote)
OnDataDeleteLocal?.Invoke(entry);
}
}

View file

@ -6,11 +6,22 @@ using static Unity.Mathematics.math;
public class GameContext
{
private DatabaseCache _databaseCache;
private DatabaseCache _cache;
public GlobalData GlobalData => _databaseCache.GetAll<GlobalData>().FirstOrDefault();
public GlobalData GlobalData => _cache.GetAll<GlobalData>().FirstOrDefault();
private readonly Dictionary<CraftedItemData, int> Tier = new Dictionary<CraftedItemData, int>();
public GameContext(DatabaseCache cache)
{
_cache = cache;
var globalData = _cache.GetAll<GlobalData>().FirstOrDefault();
if (globalData == null)
{
globalData = new GlobalData();
_cache.Add(globalData);
}
}
public float PlanetRadius(float mass)
{
@ -21,29 +32,29 @@ public class GameContext
{
if (Tier.ContainsKey(itemData)) return Tier[itemData];
Tier[itemData] = itemData.Ingredients.Keys.Max(ci => _databaseCache.Get<ItemData>(ci) is CraftedItemData craftableIngredient ? ItemTier(craftableIngredient) : 0);
Tier[itemData] = itemData.Ingredients.Keys.Max(ci => _cache.Get<ItemData>(ci) is CraftedItemData craftableIngredient ? ItemTier(craftableIngredient) : 0);
return Tier[itemData];
}
public ItemData GetData(ItemInstance item)
{
return _databaseCache.Get<ItemData>(item.Data);
return _cache.Get<ItemData>(item.Data);
}
public SimpleCommodityData GetData(SimpleCommodity item)
{
return _databaseCache.Get<SimpleCommodityData>(item.Data);
return _cache.Get<SimpleCommodityData>(item.Data);
}
public CraftedItemData GetData(CraftedItemInstance item)
{
return _databaseCache.Get<CraftedItemData>(item.Data);
return _cache.Get<CraftedItemData>(item.Data);
}
public EquippableItemData GetData(Gear gear)
{
return _databaseCache.Get<EquippableItemData>(gear.Data);
return _cache.Get<EquippableItemData>(gear.Data);
}
public float GetMass(ItemInstance item)
@ -128,7 +139,7 @@ public class GameContext
public SimpleCommodity CreateInstance(Guid data, int count)
{
var item = _databaseCache.Get<SimpleCommodityData>(data);
var item = _cache.Get<SimpleCommodityData>(data);
if (item != null)
return new SimpleCommodity
{
@ -142,7 +153,7 @@ public class GameContext
public CraftedItemInstance CreateInstance(Guid data, float quality)
{
var item = _databaseCache.Get<CraftedItemData>(data);
var item = _cache.Get<CraftedItemData>(data);
if (item == null)
{
throw new InvalidOperationException("Attempted to create crafted item instance using missing or incorrect item id");
@ -150,7 +161,7 @@ public class GameContext
var ingredients = item.Ingredients.SelectMany(ci =>
{
var ingredient = _databaseCache.Get(ci.Key);
var ingredient = _cache.Get(ci.Key);
return ingredient is SimpleCommodityData
? (IEnumerable<ItemInstance>) new[] {CreateInstance(ci.Key, ci.Value)}
: Enumerable.Range(0, ci.Value).Select(i => CreateInstance(ci.Key, quality));

View file

@ -3,18 +3,19 @@ using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Galaxy")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
public class GlobalData : DatabaseEntry
{
[InspectableField] [JsonProperty("targetPersistenceDuration")] [Key(1)]
public float TargetPersistenceDuration;
public float TargetPersistenceDuration = 3;
[InspectableField] [JsonProperty("heatRadiationPower")] [Key(2)]
public float HeatRadiationPower;
public float HeatRadiationPower = 1;
[InspectableField] [JsonProperty("heatRadiationMultiplier")] [Key(3)]
public float HeatRadiationMultiplier;
public float HeatRadiationMultiplier = 1;
[InspectableField] [JsonProperty("radiusPower")] [Key(4)]
public float RadiusPower = 1.75f;

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]

View file

@ -1,6 +1,7 @@
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]

View file

@ -4,6 +4,7 @@ using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]

View file

@ -1,6 +1,7 @@
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Items")]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
public class ReactorBehaviorData : IItemBehaviorData

View file

@ -2,6 +2,7 @@
using MessagePack;
using Newtonsoft.Json;
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]

View file

@ -36,6 +36,7 @@ public abstract class ItemData : DatabaseEntry, INamedEntry
}
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
public class SimpleCommodityData : ItemData {}
@ -54,6 +55,7 @@ public abstract class CraftedItemData : ItemData
public Dictionary<Guid, int> Ingredients = new Dictionary<Guid, int>();
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
public class CompoundCommodityData : CraftedItemData {}
@ -123,6 +125,7 @@ public abstract class EquippableItemData : CraftedItemData
}
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
@ -133,6 +136,7 @@ public class GearData : EquippableItemData
[IgnoreMember] public override HardpointType HardpointType => Hardpoint;
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
@ -165,6 +169,7 @@ public class HullData : EquippableItemData
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Hull;
}
[RethinkTable("Items")]
[InspectableField]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
@ -174,6 +179,7 @@ public class HardpointData
public HardpointType Type;
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]
@ -188,6 +194,7 @@ public class ShieldData : EquippableItemData
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Shield;
}
[RethinkTable("Items")]
[Inspectable]
[MessagePackObject]
[JsonObject(MemberSerialization.OptIn)]

View file

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using LiteNetLib;
using MessagePack;
using Unity.Mathematics;
[Union(0,typeof(PingMessage))]
[Union(1,typeof(LoginMessage))]
@ -75,4 +76,35 @@ public class ChatBroadcastMessage : Message
public class ChangeNameMessage : Message
{
[Key(0)] public string Name;
}
[MessagePackObject]
public class GalaxyRequestMessage : Message { }
[MessagePackObject]
public class GalaxyResponseMessage : Message
{
[Key(0)] public GalaxyResponseZone[] Zones;
}
[MessagePackObject]
public class GalaxyResponseZone
{
[Key(0)] public Guid ZoneID;
[Key(1)] public Guid[] Links;
[Key(2)] public string Name;
[Key(3)] public float2 Position;
}
[MessagePackObject]
public class ZoneRequestMessage : Message
{
[Key(0)] public Guid ZoneID;
}
[MessagePackObject]
public class ZoneResponseMessage : Message
{
[Key(0)] public ZoneData Zone;
[Key(1)] public DatabaseEntry[] Contents;
}

View file

@ -99,7 +99,7 @@ public class PlanetData : DatabaseEntry, INamedEntry
public class OrbitData : DatabaseEntry
{
[JsonProperty("parent")] [Key(1)]
public Guid Parent;
public Guid? Parent;
[JsonProperty("distance")] [Key(2)]
public float Distance;

View file

@ -24,30 +24,14 @@
GlowAmount("GlowAmount", Float) = 0
GlowPower("GlowPower", Float) = 0
StarBoost("StarBoost", Float) = 0
// required for UI.Mask
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
GalaxyAmplitude("GalaxyAmplitude", Float) = 1
}
SubShader
{
Tags { "RenderType"="Opaque" }
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
LOD 100
// required for UI.Mask
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
ColorMask [_ColorMask]
Blend One One
Cull Off Lighting Off ZWrite Off
Pass
{
@ -96,6 +80,7 @@
float GlowAmount;
float GlowPower;
float StarBoost;
float GalaxyAmplitude;
v2f vert (appdata v)
{
@ -130,11 +115,11 @@
float spokes = (sin(atan*Arms) + SpokeOffset) * SpokeScale;
float noise = fBm(i.uv + NoisePosition.xx, 7);
float shape = lerp(spokes - EdgeReduction * length(offset), 1, pow(circle + CoreBoostOffset, CoreBoostPower) * CoreBoost);
float gal = max(shape - noise * clamp(circle,0,1), 0);
float gal = max(shape - noise * clamp(circle,0,1), 0) * GalaxyAmplitude;
float glow = (pow(circle,GlowPower) + GlowOffset) * GlowAmount;
float stars = tex2D(_MainTex, i.uv2) * clamp(shape*StarBoost, 0, 1);
fixed4 col = fixed4(gal*_CloudColor.rgb + glow*_GlowColor.rgb + stars.xxx, 1);
return col;
return col;
}
ENDCG
}

View file

@ -0,0 +1,63 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
public class StrategyGameManager : MonoBehaviour
{
public TabGroup PrimaryTabGroup;
public TabButton GalaxyTabButton;
public TabButton ZoneTabButton;
public Prototype GalaxyZonePrototype;
public Prototype GalaxyZoneLinkPrototype;
public float GalaxyScale;
public Prototype ZoneObjectPrototype;
private DatabaseCache _cache;
private GameContext _context;
private Dictionary<Guid, GalaxyResponseZone> _galaxy;
private TabButton _currentTab;
private bool _galaxyPopulated;
void Start()
{
PrimaryTabGroup.OnTabChange += button =>
{
_currentTab = button;
if (button == GalaxyTabButton)
{
}
};
CultClient.AddMessageListener<GalaxyResponseMessage>(galaxy =>
{
_galaxy = galaxy.Zones.ToDictionary(z=>z.ZoneID);
if (_currentTab == GalaxyTabButton && !_galaxyPopulated)
{
_galaxyPopulated = true;
var linkedZones = new List<Guid>();
foreach (var zone in galaxy.Zones)
{
var instance = GalaxyZonePrototype.Instantiate<Transform>();
instance.position = float3(zone.Position,0) * GalaxyScale;
foreach (var linkedZone in zone.Links.Where(l=>linkedZones.Contains(l)))
{
var link = GalaxyZoneLinkPrototype.Instantiate<Transform>();
var diff = _galaxy[linkedZone].Position - zone.Position;
link.rotation = Quaternion.Euler(0,0,atan2(diff.y, diff.x) * Mathf.Rad2Deg);
link.localScale = new Vector3(length(diff) * GalaxyScale, 1, 1);
}
}
}
});
CultClient.Send(new GalaxyRequestMessage());
}
void Update()
{
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1c1faf0a46b9cf24498cd5ec93c34c71
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -8,6 +8,9 @@
<ItemGroup>
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="1.1.3" />
<PackageReference Include="MessagePack" Version="2.1.90" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0-preview.1.20120.4" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.2-dev-10272" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0-dev-00864" />
<PackageReference Include="System.Reactive.Linq" Version="4.3.2" />
</ItemGroup>

View file

@ -1,18 +1,241 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using MessagePack;
using MessagePack.Resolvers;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using RethinkDb.Driver;
using RethinkDb.Driver.Net;
using Serilog;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace ChatApp.Server
{
class Program
{
private static readonly RethinkDB R = RethinkDB.R;
private static ILogger _logger;
static async Task Main(string[] args)
{
var connection = RethinkDb.Driver.RethinkDB.R.Connection().Hostname("asgard.gamecult.games")
var serilogger = new LoggerConfiguration()
.WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
var loggerFactory = LoggerFactory.Create(builder =>
{
builder
// .AddFilter("Microsoft", LogLevel.Warning)
// .AddFilter("System", LogLevel.Warning)
// .AddFilter("LoggingConsoleApp.Program", LogLevel.Debug)
.AddSerilog(serilogger)
.AddConsole();
});
_logger = loggerFactory.CreateLogger<Program>();
// Register extensions to Json.NET Serialization
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Converters = new List<JsonConverter>
{
new MathJsonConverter(),
Converter.DateTimeConverter,
Converter.BinaryConverter,
Converter.GroupingConverter,
Converter.PocoExprConverter
}
};
Converter.Serializer.Converters.Add(new MathJsonConverter());
// Register extensions to MessagePack Serialization
var resolver = CompositeResolver.Create(
MathResolver.Instance,
NativeGuidResolver.Instance,
StandardResolver.Instance
);
var options = MessagePackSerializerOptions.Standard.WithResolver(resolver);
MessagePackSerializer.DefaultOptions = options;
var connection = R.Connection().Hostname("asgard.gamecult.games")
.Port(RethinkDBConstants.DefaultPort).Timeout(60).Connect();
var cache = new DatabaseCache();
// When entries are changed locally, push the changes to RethinkDB
cache.OnDataUpdateLocal += async entry =>
{
var table = entry.GetType().GetCustomAttribute<RethinkTableAttribute>()?.TableName ?? "Other";
var result = await R.Db("Aetheria").Table(table).Update(entry).RunAsync(connection);
_logger.Log(LogLevel.Information, $"Uploaded entry to RethinkDB: {entry.ID} result: {result}");
};
cache.OnDataInsertLocal += async entry =>
{
var table = entry.GetType().GetCustomAttribute<RethinkTableAttribute>()?.TableName ?? "Other";
var result = await R.Db("Aetheria").Table(table).Insert(entry).RunAsync(connection);
_logger.Log(LogLevel.Information, $"Inserted entry to RethinkDB: {entry.ID} result: {result}");
};
cache.OnDataDeleteLocal += async entry =>
{
var table = entry.GetType().GetCustomAttribute<RethinkTableAttribute>()?.TableName ?? "Other";
var result = await R.Db("Aetheria").Table(table).Get(entry.ID).Delete().RunAsync(connection);
_logger.Log(LogLevel.Information, $"Deleted entry from RethinkDB: {entry.ID} result: {result}");
};
// Get data from RethinkDB
GetTable("Items", connection, cache);
GetTable("Galaxy", connection, cache);
GetTable("Users", connection, cache);
// Subscribe to changes from RethinkDB
SubscribeTable("Items", connection, cache);
SubscribeTable("Galaxy", connection, cache);
SubscribeTable("Users", connection, cache);
var server = new MasterServer(cache)
{
Logger = _logger
};
server.Start();
var context = new GameContext(cache);
server.AddMessageListener<GalaxyRequestMessage>(galaxyRequest => galaxyRequest.Peer.Send(
new GalaxyResponseMessage
{
Zones = cache.GetAll<ZoneData>().Select(zd=>
new GalaxyResponseZone
{
Name = zd.Name,
Position = zd.Position,
ZoneID = zd.ID,
Links = zd.Wormholes.ToArray()
}).ToArray()
}));
server.AddMessageListener<ZoneRequestMessage>(zoneRequest =>
{
var zone = cache.Get<ZoneData>(zoneRequest.ZoneID);
// Zone has not been populated, generate the contents now!
if (!zone.Planets.Any())
{
var planets = ZoneGenerator.GenerateEntities(context, zone, 10000, 2000);
// Create collections to map between zone generator output and database entries
var orbitMap = new Dictionary<Planet, OrbitData>();
var orbitInverseMap = new Dictionary<OrbitData, Planet>();
// Create orbit database entries
var orbitData = planets.Select(planet =>
{
var data = new OrbitData()
{
ID = Guid.NewGuid(),
Distance = planet.Distance,
Period = planet.Period,
Phase = planet.Phase,
Zone = zone.ID
};
orbitMap[planet] = data;
orbitInverseMap[data] = planet;
return data;
}).ToArray();
// Link OrbitData parents to database GUIDs
foreach (var data in orbitData)
data.Parent = orbitInverseMap[data].Parent != null
? orbitMap[orbitInverseMap[data].Parent].ID
: (Guid?) null;
foreach (var data in orbitData) cache.Add(data);
var planetData = planets.Select(planet =>
{
var planetDatum = new PlanetData
{
Mass = planet.Mass,
ID = Guid.NewGuid(),
Orbit = orbitMap[planet].ID,
Zone = zone.ID
};
planetDatum.Name = planetDatum.ID.ToString().Substring(0, 8);
return planetDatum;
}).ToArray();
foreach (var data in planetData) cache.Add(data);
zone.Planets = planetData.Select(pd => pd.ID).ToList();
zone.Orbits = orbitData.Select(od => od.ID).ToList();
cache.Add(zone);
}
zoneRequest.Peer.Send(
new ZoneResponseMessage
{
Zone = zone,
Contents = zone.Orbits.Select(id=>cache.Get(id))
.Concat(zone.Planets.Select(id=>cache.Get(id)))
.Concat(zone.Stations.Select(id=>cache.Get(id))).ToArray()
});
});
while (true)
{
Thread.Sleep(100);
}
}
private static void SubscribeTable(string table, Connection connection, DatabaseCache cache)
{
Task.Run(async () =>
{
var result = await R.Db("Aetheria").Table(table).Changes()
.RunChangesAsync<DatabaseEntry>(connection);
while (await result.MoveNextAsync())
{
var change = result.Current;
if (change.OldValue == null)
{
_logger.Log(LogLevel.Information,
$"Received change from RethinkDB {table} table (Entry Created): {change.NewValue.GetType()} {(change.NewValue as INamedEntry)?.EntryName ?? ""}:{change.NewValue.ID}");
cache.Add(change.NewValue, true);
}
else if (change.NewValue == null)
{
_logger.Log(LogLevel.Information,
$"Received change from RethinkDB {table} table (Entry Deleted): {change.OldValue.GetType()} {(change.OldValue as INamedEntry)?.EntryName ?? ""}:{change.OldValue.ID}");
cache.Delete(change.NewValue, true);
}
else
{
_logger.Log(LogLevel.Information,
$"Received change from RethinkDB {table} table: {change.NewValue.GetType()} {(change.NewValue as INamedEntry)?.EntryName ?? ""}:{change.NewValue.ID}");
cache.Add(change.NewValue, true);
}
}
});
}
private static void GetTable(string table, Connection connection, DatabaseCache cache)
{
Task.Run(async () =>
{
var result = await R.Db("Aetheria").Table(table).RunCursorAsync<DatabaseEntry>(connection);
while (await result.MoveNextAsync())
{
var entry = result.Current;
_logger.Log(LogLevel.Information,
$"Received {table} entry from RethinkDB: {entry.GetType()} {(entry as INamedEntry)?.EntryName ?? ""}:{entry.ID}");
cache.Add(entry, true);
}
});
}
}
}

View file

@ -13,7 +13,7 @@ using Microsoft.Extensions.Logging;
public class MasterServer
{
public ILogger Logger = null;
public ILogger Logger = null;
private const string EmailPattern =
@"^([0-9a-zA-Z]" + //Start with a digit or alphabetical
@ -160,7 +160,7 @@ using Microsoft.Extensions.Logging;
if (!Argon2.Verify(userData.Password, login.Password))
{
peer.Send(new ErrorMessage {Error = "Password Wrong"});
peer.Send(new ErrorMessage {Error = "Password Incorrect"});
return;
}

View file

@ -1,5 +1,5 @@
{
"version": 1,
"dgSpecHash": "LaLbB/EzWT7PS2nCJ7Zvz9VBwKXuCganVRJQP9+eDGNNnOpJrCFiPR+ViZlJmQ3P6Rw1oFe3X9IFOPvUk+CQ7w==",
"dgSpecHash": "sFWvYW5XyOIohzDOMwavhUdA8OsoBuu6z9esKhsDsCU6RrNN9Cg8w5POijL+g5TZIEge2fkS+Jud2B4k4rcHSg==",
"success": true
}

View file

@ -51,6 +51,18 @@
"target": "Package",
"version": "[2.1.90, )"
},
"Microsoft.Extensions.Logging.Console": {
"target": "Package",
"version": "[5.0.0-preview.1.20120.4, )"
},
"Serilog.Extensions.Logging": {
"target": "Package",
"version": "[3.0.2-dev-10272, )"
},
"Serilog.Sinks.File": {
"target": "Package",
"version": "[5.0.0-dev-00864, )"
},
"System.Reactive.Linq": {
"target": "Package",
"version": "[4.3.2, )"

View file

@ -184,6 +184,33 @@
"lib/netstandard2.0/Microsoft.Extensions.Logging.Abstractions.dll": {}
}
},
"Microsoft.Extensions.Logging.Configuration/5.0.0-preview.1.20120.4": {
"type": "package",
"dependencies": {
"Microsoft.Extensions.Logging": "5.0.0-preview.1.20120.4",
"Microsoft.Extensions.Options.ConfigurationExtensions": "5.0.0-preview.1.20120.4"
},
"compile": {
"lib/netstandard2.0/Microsoft.Extensions.Logging.Configuration.dll": {}
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Logging.Configuration.dll": {}
}
},
"Microsoft.Extensions.Logging.Console/5.0.0-preview.1.20120.4": {
"type": "package",
"dependencies": {
"Microsoft.Extensions.Configuration.Abstractions": "5.0.0-preview.1.20120.4",
"Microsoft.Extensions.Logging": "5.0.0-preview.1.20120.4",
"Microsoft.Extensions.Logging.Configuration": "5.0.0-preview.1.20120.4"
},
"compile": {
"lib/netstandard2.0/Microsoft.Extensions.Logging.Console.dll": {}
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Logging.Console.dll": {}
}
},
"Microsoft.Extensions.Options/5.0.0-preview.1.20120.4": {
"type": "package",
"dependencies": {
@ -198,6 +225,21 @@
"lib/netstandard2.0/Microsoft.Extensions.Options.dll": {}
}
},
"Microsoft.Extensions.Options.ConfigurationExtensions/5.0.0-preview.1.20120.4": {
"type": "package",
"dependencies": {
"Microsoft.Extensions.Configuration.Abstractions": "5.0.0-preview.1.20120.4",
"Microsoft.Extensions.Configuration.Binder": "5.0.0-preview.1.20120.4",
"Microsoft.Extensions.DependencyInjection.Abstractions": "5.0.0-preview.1.20120.4",
"Microsoft.Extensions.Options": "5.0.0-preview.1.20120.4"
},
"compile": {
"lib/netstandard2.0/Microsoft.Extensions.Options.ConfigurationExtensions.dll": {}
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Options.ConfigurationExtensions.dll": {}
}
},
"Microsoft.Extensions.Primitives/5.0.0-preview.1.20120.4": {
"type": "package",
"dependencies": {
@ -268,6 +310,46 @@
"lib/netstandard1.0/Remotion.Linq.dll": {}
}
},
"Serilog/2.8.0": {
"type": "package",
"dependencies": {
"System.Collections.NonGeneric": "4.3.0"
},
"compile": {
"lib/netstandard2.0/Serilog.dll": {}
},
"runtime": {
"lib/netstandard2.0/Serilog.dll": {}
}
},
"Serilog.Extensions.Logging/3.0.2-dev-10272": {
"type": "package",
"dependencies": {
"Microsoft.Extensions.Logging": "2.0.0",
"Serilog": "2.8.0"
},
"compile": {
"lib/netstandard2.0/Serilog.Extensions.Logging.dll": {}
},
"runtime": {
"lib/netstandard2.0/Serilog.Extensions.Logging.dll": {}
}
},
"Serilog.Sinks.File/5.0.0-dev-00864": {
"type": "package",
"dependencies": {
"Serilog": "2.5.0",
"System.IO.FileSystem": "4.0.1",
"System.Text.Encoding.Extensions": "4.0.11",
"System.Threading.Timer": "4.0.1"
},
"compile": {
"lib/netstandard2.0/Serilog.Sinks.File.dll": {}
},
"runtime": {
"lib/netstandard2.0/Serilog.Sinks.File.dll": {}
}
},
"System.Collections/4.3.0": {
"type": "package",
"dependencies": {
@ -472,7 +554,7 @@
"System.Threading.Tasks": "4.3.0"
},
"compile": {
"ref/netstandard1.3/_._": {}
"ref/netstandard1.3/System.IO.FileSystem.dll": {}
}
},
"System.IO.FileSystem.Primitives/4.3.0": {
@ -481,7 +563,7 @@
"System.Runtime": "4.3.0"
},
"compile": {
"ref/netstandard1.3/_._": {}
"ref/netstandard1.3/System.IO.FileSystem.Primitives.dll": {}
},
"runtime": {
"lib/netstandard1.3/System.IO.FileSystem.Primitives.dll": {}
@ -732,7 +814,7 @@
"System.Runtime": "4.3.0"
},
"compile": {
"ref/netstandard1.3/_._": {}
"ref/netstandard1.3/System.Runtime.Handles.dll": {}
}
},
"System.Runtime.InteropServices/4.3.0": {
@ -798,7 +880,7 @@
"System.Text.Encoding": "4.3.0"
},
"compile": {
"ref/netstandard1.3/_._": {}
"ref/netstandard1.3/System.Text.Encoding.Extensions.dll": {}
}
},
"System.Text.RegularExpressions/4.3.0": {
@ -858,6 +940,17 @@
"lib/netstandard1.3/System.Threading.Thread.dll": {}
}
},
"System.Threading.Timer/4.0.1": {
"type": "package",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.0.1",
"Microsoft.NETCore.Targets": "1.0.1",
"System.Runtime": "4.1.0"
},
"compile": {
"ref/netstandard1.2/System.Threading.Timer.dll": {}
}
},
"System.Xml.ReaderWriter/4.3.0": {
"type": "package",
"dependencies": {
@ -1247,6 +1340,38 @@
"microsoft.extensions.logging.abstractions.nuspec"
]
},
"Microsoft.Extensions.Logging.Configuration/5.0.0-preview.1.20120.4": {
"sha512": "pt0FHtvJYZ/dFCXqENaYWHXQ4U7lxSZ+/xGFBNlwtOe8mRpHYt/yCReUVCRxNkuQq2SfKZfk9D3psax/Nhan1g==",
"type": "package",
"path": "microsoft.extensions.logging.configuration/5.0.0-preview.1.20120.4",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"lib/netcoreapp5.0/Microsoft.Extensions.Logging.Configuration.dll",
"lib/netcoreapp5.0/Microsoft.Extensions.Logging.Configuration.xml",
"lib/netstandard2.0/Microsoft.Extensions.Logging.Configuration.dll",
"lib/netstandard2.0/Microsoft.Extensions.Logging.Configuration.xml",
"microsoft.extensions.logging.configuration.5.0.0-preview.1.20120.4.nupkg.sha512",
"microsoft.extensions.logging.configuration.nuspec"
]
},
"Microsoft.Extensions.Logging.Console/5.0.0-preview.1.20120.4": {
"sha512": "8ZoMuTRlWQ3FLBg7TqM+f5mkBFYvJCFIc+Ayy3NtDpIRBvlhk6HAgehcFRZyRru7k7qBz74AH+hBKz7yklTJBg==",
"type": "package",
"path": "microsoft.extensions.logging.console/5.0.0-preview.1.20120.4",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"lib/netcoreapp5.0/Microsoft.Extensions.Logging.Console.dll",
"lib/netcoreapp5.0/Microsoft.Extensions.Logging.Console.xml",
"lib/netstandard2.0/Microsoft.Extensions.Logging.Console.dll",
"lib/netstandard2.0/Microsoft.Extensions.Logging.Console.xml",
"microsoft.extensions.logging.console.5.0.0-preview.1.20120.4.nupkg.sha512",
"microsoft.extensions.logging.console.nuspec"
]
},
"Microsoft.Extensions.Options/5.0.0-preview.1.20120.4": {
"sha512": "xL0TKJZ9DTWSZWyhtux5gjxrXkBOlLr0Ga0MaprkBJFe4HBGNBz1qR5uiCqOQvmTCTeuajDCh51YHyLgby44lQ==",
"type": "package",
@ -1263,6 +1388,22 @@
"microsoft.extensions.options.nuspec"
]
},
"Microsoft.Extensions.Options.ConfigurationExtensions/5.0.0-preview.1.20120.4": {
"sha512": "YCpcamBR86CLcGrGbMTAdUek8ScCbAtgdhWpbJUbZhhfzZ04LLXwxepQDr70v+oKWOve13C8cJN3lyofiirO9w==",
"type": "package",
"path": "microsoft.extensions.options.configurationextensions/5.0.0-preview.1.20120.4",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"lib/netcoreapp5.0/Microsoft.Extensions.Options.ConfigurationExtensions.dll",
"lib/netcoreapp5.0/Microsoft.Extensions.Options.ConfigurationExtensions.xml",
"lib/netstandard2.0/Microsoft.Extensions.Options.ConfigurationExtensions.dll",
"lib/netstandard2.0/Microsoft.Extensions.Options.ConfigurationExtensions.xml",
"microsoft.extensions.options.configurationextensions.5.0.0-preview.1.20120.4.nupkg.sha512",
"microsoft.extensions.options.configurationextensions.nuspec"
]
},
"Microsoft.Extensions.Primitives/5.0.0-preview.1.20120.4": {
"sha512": "TXN/iw+ZLtReje7mljcf7wUr3iiOx5ffCEYLu2T7st8N5hclsswbhFovw4pIUjrpj+NIdUhr6SCvTSGFhZvewA==",
"type": "package",
@ -1360,6 +1501,66 @@
"remotion.linq.nuspec"
]
},
"Serilog/2.8.0": {
"sha512": "zjuKXW5IQws43IHX7VY9nURsaCiBYh2kyJCWLJRSWrTsx/syBKHV8MibWe2A+QH3Er0AiwA+OJmO3DhFJDY1+A==",
"type": "package",
"path": "serilog/2.8.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"lib/net45/Serilog.dll",
"lib/net45/Serilog.pdb",
"lib/net45/Serilog.xml",
"lib/net46/Serilog.dll",
"lib/net46/Serilog.pdb",
"lib/net46/Serilog.xml",
"lib/netstandard1.0/Serilog.dll",
"lib/netstandard1.0/Serilog.pdb",
"lib/netstandard1.0/Serilog.xml",
"lib/netstandard1.3/Serilog.dll",
"lib/netstandard1.3/Serilog.pdb",
"lib/netstandard1.3/Serilog.xml",
"lib/netstandard2.0/Serilog.dll",
"lib/netstandard2.0/Serilog.pdb",
"lib/netstandard2.0/Serilog.xml",
"serilog.2.8.0.nupkg.sha512",
"serilog.nuspec"
]
},
"Serilog.Extensions.Logging/3.0.2-dev-10272": {
"sha512": "1lFlCjlZX6ErLsuPik4JKiYoPTTmu5Jvz9zQA3dpmL63W7jRRNqbNMFuJXZl5We1v0kWAVnil5rOsqejTgVOCg==",
"type": "package",
"path": "serilog.extensions.logging/3.0.2-dev-10272",
"files": [
".nupkg.metadata",
".signature.p7s",
"lib/netstandard2.0/Serilog.Extensions.Logging.dll",
"lib/netstandard2.0/Serilog.Extensions.Logging.xml",
"serilog-extension-nuget.png",
"serilog.extensions.logging.3.0.2-dev-10272.nupkg.sha512",
"serilog.extensions.logging.nuspec"
]
},
"Serilog.Sinks.File/5.0.0-dev-00864": {
"sha512": "HIJcKs0ySpd/SqRxHN7RtIwAkT+9T/8HdQEY97fFFoAEOYFGfb/M/yolRftpJ8DT1jIYsn48fWxS3vyVrlApxA==",
"type": "package",
"path": "serilog.sinks.file/5.0.0-dev-00864",
"files": [
".nupkg.metadata",
".signature.p7s",
"lib/net45/Serilog.Sinks.File.dll",
"lib/net45/Serilog.Sinks.File.pdb",
"lib/net45/Serilog.Sinks.File.xml",
"lib/netstandard1.3/Serilog.Sinks.File.dll",
"lib/netstandard1.3/Serilog.Sinks.File.pdb",
"lib/netstandard1.3/Serilog.Sinks.File.xml",
"lib/netstandard2.0/Serilog.Sinks.File.dll",
"lib/netstandard2.0/Serilog.Sinks.File.pdb",
"lib/netstandard2.0/Serilog.Sinks.File.xml",
"serilog.sinks.file.5.0.0-dev-00864.nupkg.sha512",
"serilog.sinks.file.nuspec"
]
},
"System.Collections/4.3.0": {
"sha512": "3Dcj85/TBdVpL5Zr+gEEBUuFe2icOnLalmEh9hfck1PTYbbyWuZgh4fmm2ysCLTrqLQw6t3TgTyJ+VLp+Qb+Lw==",
"type": "package",
@ -3800,6 +4001,60 @@
"system.threading.thread.nuspec"
]
},
"System.Threading.Timer/4.0.1": {
"sha512": "saGfUV8uqVW6LeURiqxcGhZ24PzuRNaUBtbhVeuUAvky1naH395A/1nY0P2bWvrw/BreRtIB/EzTDkGBpqCwEw==",
"type": "package",
"path": "system.threading.timer/4.0.1",
"files": [
".nupkg.metadata",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net451/_._",
"lib/portable-net451+win81+wpa81/_._",
"lib/win81/_._",
"lib/wpa81/_._",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net451/_._",
"ref/netcore50/System.Threading.Timer.dll",
"ref/netcore50/System.Threading.Timer.xml",
"ref/netcore50/de/System.Threading.Timer.xml",
"ref/netcore50/es/System.Threading.Timer.xml",
"ref/netcore50/fr/System.Threading.Timer.xml",
"ref/netcore50/it/System.Threading.Timer.xml",
"ref/netcore50/ja/System.Threading.Timer.xml",
"ref/netcore50/ko/System.Threading.Timer.xml",
"ref/netcore50/ru/System.Threading.Timer.xml",
"ref/netcore50/zh-hans/System.Threading.Timer.xml",
"ref/netcore50/zh-hant/System.Threading.Timer.xml",
"ref/netstandard1.2/System.Threading.Timer.dll",
"ref/netstandard1.2/System.Threading.Timer.xml",
"ref/netstandard1.2/de/System.Threading.Timer.xml",
"ref/netstandard1.2/es/System.Threading.Timer.xml",
"ref/netstandard1.2/fr/System.Threading.Timer.xml",
"ref/netstandard1.2/it/System.Threading.Timer.xml",
"ref/netstandard1.2/ja/System.Threading.Timer.xml",
"ref/netstandard1.2/ko/System.Threading.Timer.xml",
"ref/netstandard1.2/ru/System.Threading.Timer.xml",
"ref/netstandard1.2/zh-hans/System.Threading.Timer.xml",
"ref/netstandard1.2/zh-hant/System.Threading.Timer.xml",
"ref/portable-net451+win81+wpa81/_._",
"ref/win81/_._",
"ref/wpa81/_._",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"system.threading.timer.4.0.1.nupkg.sha512",
"system.threading.timer.nuspec"
]
},
"System.Xml.ReaderWriter/4.3.0": {
"sha512": "GrprA+Z0RUXaR4N7/eW71j1rgMnEnEVlgii49GZyAjTH7uliMnrOU3HNFBr6fEDBCJCIdlVNq9hHbaDR621XBA==",
"type": "package",
@ -3920,6 +4175,9 @@
"Economy.Shared >= 1.0.0",
"Isopoh.Cryptography.Argon2 >= 1.1.3",
"MessagePack >= 2.1.90",
"Microsoft.Extensions.Logging.Console >= 5.0.0-preview.1.20120.4",
"Serilog.Extensions.Logging >= 3.0.2-dev-10272",
"Serilog.Sinks.File >= 5.0.0-dev-00864",
"System.Reactive.Linq >= 4.3.2"
]
},
@ -3974,6 +4232,18 @@
"target": "Package",
"version": "[2.1.90, )"
},
"Microsoft.Extensions.Logging.Console": {
"target": "Package",
"version": "[5.0.0-preview.1.20120.4, )"
},
"Serilog.Extensions.Logging": {
"target": "Package",
"version": "[3.0.2-dev-10272, )"
},
"Serilog.Sinks.File": {
"target": "Package",
"version": "[5.0.0-dev-00864, )"
},
"System.Reactive.Linq": {
"target": "Package",
"version": "[4.3.2, )"

View file

@ -41,6 +41,18 @@
"target": "Package",
"version": "[2.1.90, )"
},
"Microsoft.Extensions.Logging.Console": {
"target": "Package",
"version": "[5.0.0-preview.1.20120.4, )"
},
"Serilog.Extensions.Logging": {
"target": "Package",
"version": "[3.0.2-dev-10272, )"
},
"Serilog.Sinks.File": {
"target": "Package",
"version": "[5.0.0-dev-00864, )"
},
"System.Reactive.Linq": {
"target": "Package",
"version": "[4.3.2, )"

View file

@ -1,21 +1,44 @@
# Aetheria
This repository is the home of Aetheria, which could be described as a sci-fi hybrid ARPG/RTS MMO about a group of corporations colonizing a hostile alien galaxy, with a satirical narrative critiquing late-stage capitalism.
This repository is the home of Aetheria, a sci-fi hybrid ARPG/RTS MMO about a group of corporations colonizing a hostile alien galaxy, with a satirical narrative critiquing late-stage capitalism.
## Table of Contents
[toc]
## Aetheria
### Game Design
The ARPG game design document is available [here](https://docs.google.com/document/d/1iULu1WsbuQoUM3c87XkGseb1P-8R5xlruoiyg03TsSE/edit?usp=sharing), while the RTS gameplay is documented [here](https://docs.google.com/document/d/1U3uGFqQboAiFJ_Y-nUOGpyixbXUHRbc5DiCuB59GM4w/edit?usp=sharing). The goal is to essentially create two games which both take place in the same persistent universe, allowing players with vastly different preferences to struggle together for the survival of mankind. Each instance of the game lasts until the inevitable destruction of the entire population at the hands of aliens, after which the universe resets. Each loop is designed to last up to a couple of months, during which the hostility of the aliens steadily increases until the players are unable to hold back the tide.
Previously I have built prototypes of the ARPG gameplay, [here's a video of the most recent one](https://www.youtube.com/watch?v=PNwVGtvefCg). While it included stations, AI opponents, multiple ships and a complex loadout system which simulates heat transfer between all of the ship's hardpoints with temperature affecting the performance of each item differently, the world was rather static and empty.
### Previous Work
As a result, the current focus is on the economy system, and building a client-server architecture for the networked simulation of a persistent universe. The goal is to create an RTS client, allowing players to take the role of a corporation, where they can define roles for their population, gather resources, build infrastructure, research new technology and produce items in order to make as much money as possible.
The concept for Aetheria goes back many years, during which I have steadily acquired my current skill with the primary objective of becoming competent enough to realize my vision. Previously I have built prototypes of the ARPG gameplay, [here's a video of the most recent one](https://www.youtube.com/watch?v=PNwVGtvefCg). While it included stations, AI opponents, multiple ships and a complex loadout system which simulates heat transfer between all of the ship's hardpoints with temperature affecting the performance of each item differently, the world was rather static and empty.
### Current Work
As a result of lessons learned, the current focus is on the economy system, and building a client-server architecture for the networked simulation of a persistent universe. The goal is to create an RTS client, allowing players to take the role of a corporation, where they can define roles for their population, gather resources, build infrastructure, research new technology and produce items in order to make as much money as possible.
Once we have built a persistent universe with a dynamic economy, we will begin rebuilding the ARPG client allowing the player to take control of a single ship and engage in fast-paced combat, questing and trading.
## Architecture
There are two solutions in this repository. One is a Unity project containing the desktop client for Aetheria, and the other is a .NET Core server application intended to run on Linux cloud servers. There is some code shared between them, located at [Assets/Scripts/ServerShared](Assets/Scripts/ServerShared), defining a common protocol and data serialization format. Client-Server communication is implemented using [LiteNetLib](https://github.com/RevenantX/LiteNetLib), a reliable UDP transport library which we use to transmit [MessagePack](https://github.com/neuecc/MessagePack-CSharp) over the wire.
There are two solutions in this repository. One is a Unity project containing the desktop client for Aetheria, and the other is a .NET Core application intended to run on Linux cloud servers. There is some code shared between them, located at [Assets/Scripts/ServerShared](Assets/Scripts/ServerShared), defining a common protocol and data serialization format. Client-Server communication is implemented using [LiteNetLib](https://github.com/RevenantX/LiteNetLib), a reliable UDP transport library which we use to transmit [MessagePack](https://github.com/neuecc/MessagePack-CSharp) over the wire.
Aetheria uses [RethinkDB](https://rethinkdb.com/) for data persistence. To make this possible, all persistent data is marked with attributes for both MessagePack and [JSON.Net](https://www.newtonsoft.com/json) serialization. During operation, the client does not communicate with the database server directly, only the game server does that; the game server caches data relevant to the game and sends it to the clients.
## Database Editor Tools
## Contributing
### Getting the Files
In order to checkout the project, you need a git client (Github's zip download will not work!). You also need to have installed [Git LFS (Large File Storage)](https://git-lfs.github.com/). This is necessary because assets in gamedev projects can get rather large, and Git is essentially a text versioning system that does not by itself support that use case well.
### Choosing a Task
We are organizing according to an [Agile development](https://en.wikipedia.org/wiki/Agile_software_development) schedule, with the progress of each sprint being tracked on its own board in the [Github Projects tab](https://github.com/rwvens/Aetheria-Economy/projects). If you wish to take on a task from the board, please contact us to become an official contributor so that the task can be assigned to you directly. Some issues are not on the sprint schedule, those are ideal for developers who want to jump in but are shy about joining.
### Database Editor Tools
In order to facilitate the creation and maintenance of game data, there is a Unity editor utility which communicates directly with RethinkDB. You can access the tools by selecting Window/Aetheria Database Tools in Unity's menu. This will cause two windows to appear, the Database List View and the Database Inspector.
@ -27,6 +50,20 @@ At the top of the list view there is a text field where you can enter the URL of
You can unfold the categories of items in the list view to see what items exist. If you select an item, the Database Inspector will populate with all of the available fields of that item. Any changes you make in the Inspector will automatically be pushed to RethinkDB. If you've connected to the production database, this will update the stats of in-game items in real-time!
### Galaxy Editor
When you select a galaxy asset in the Unity scene hierarchy, a custom editor opens in the inspector which enables the procedural generation of a new galaxy. There you can find some variables pertaining to the galaxy as a whole, such as the number and twist of the spiral arms.
#### Map Layer Data
Below that is an editor for map layer data which allows the creation of a density map defining the value of some variable as it varies over the space containing the galaxy, which can be previewed at the top of the inspector. By default the star density map layer is displayed, which controls the distribution of stars. Any number of map layers can be created, defining variables such as the radius of zones and the presence of life and resources to be mined.
#### Star Tools
After the map layer data section is a foldout containing tools which allow you to generate stars according to the star density map. Stars are placed by accumulating density while walking over a space-filling Hilbert curve, maintaining some minimum distance between stars. This isn't as good as a proper sampling algorithm like Poisson disk sampling or Mitchell’s best-candidate algorithm, but it gets the job done ([please feel free to contribute a better sampling algorithm!](https://github.com/rwvens/Aetheria-Economy/issues/15)).
After generating stars, you can generate the links between them, which performs a Delaunay Tessellation, and then remove some proportion of links until the desired sparsity is reached. The algorithm for filtering star links is also not ideal, [there's an issue for fixing that, too!](https://github.com/rwvens/Aetheria-Economy/issues/25)
## Contact Us
If you want to chat, please join [our Discord server](https://discord.gg/trbteNj).