-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fixed remaining errors with being loaded
- Loading branch information
1 parent
067b084
commit 121269a
Showing
8 changed files
with
11,592 additions
and
26 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Reference: NewtonsoftAlias.Json | ||
|
||
using System.Collections.Generic; | ||
using System; | ||
using NewtonsoftAlias.Json; | ||
using NewtonsoftAlias.Json.Linq; | ||
|
||
namespace Oxide.Ext.GamingApi | ||
{ | ||
public class AccountConverter : JsonConverter<Account> | ||
{ | ||
public override void WriteJson(JsonWriter writer, Account value, JsonSerializer serializer) | ||
{ | ||
writer.WriteValue(value.ToString()); | ||
|
||
JObject jo = new JObject(); | ||
if (value.PackageId != null) | ||
{ | ||
jo.Add("id", JToken.FromObject(value.PackageId, serializer)); | ||
} | ||
jo.WriteTo(writer); | ||
} | ||
|
||
public override Account ReadJson(JsonReader reader, Type objectType, Account existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
string s = (string)reader.Value; | ||
Account acc = new Account(); | ||
acc.PackageId = "test"; | ||
return acc; | ||
} | ||
} | ||
|
||
public class Account | ||
{ | ||
public string PackageId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
namespace Oxide.Ext.GamingApi | ||
// Reference: NewtonsoftAlias.Json | ||
// Reference: NATS.Client | ||
// Reference: RustGameAPI | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using NewtonsoftAlias.Json; | ||
using Oxide.Core; | ||
using Oxide.Core.Extensions; | ||
|
||
namespace Oxide.Ext.GamingApi | ||
{ | ||
using System; | ||
using System.Reflection; | ||
using Oxide.Core; | ||
using Oxide.Core.Extensions; | ||
|
||
public class GamingApiExtension : Extension | ||
{ | ||
|
@@ -12,6 +20,41 @@ public class GamingApiExtension : Extension | |
public GamingApiExtension(ExtensionManager manager) : base(manager) | ||
{ | ||
Interface.Oxide.LogInfo("[GamingApi Ext] Started"); | ||
Interface.Oxide.LogInfo("[GamingApi Ext] Libraries " + manager.GetLibraries().ToString()); | ||
Account account = new Account | ||
{ | ||
PackageId = "test" | ||
}; | ||
|
||
string json2 = JsonConvert.SerializeObject(account, Formatting.Indented, new AccountConverter()); | ||
// { | ||
// "Email": "[email protected]", | ||
// "Active": true, | ||
// "CreatedDate": "2013-01-20T00:00:00Z", | ||
// "Roles": [ | ||
// "User", | ||
// "Admin" | ||
// ] | ||
// } | ||
|
||
Interface.Oxide.LogInfo("[GamingApi Ext] Serialized message " + json2); | ||
Player p = new Player() { Name = "Test", Id = "TEST", Address = "123", AdditionalProperties = new Dictionary<string, object>()}; | ||
p.AdditionalProperties.Add("TEST", 123); | ||
|
||
JsonSerializerSettings settings = new JsonSerializerSettings | ||
{ | ||
TypeNameHandling = TypeNameHandling.Auto, | ||
ContractResolver = OmitTypeNamesOnDynamicsResolver.Instance, | ||
Formatting = Formatting.Indented, | ||
Converters= new List<JsonConverter> { new PlayerConverter() } | ||
}; | ||
var json = JsonConvert.SerializeObject(p, settings); | ||
Interface.Oxide.LogInfo("[GamingApi Ext] Serialized message " + json); | ||
|
||
Asyncapi.Nats.Client.Models.Player p2 = new Asyncapi.Nats.Client.Models.Player() { Name = "Test", Id = "TEST", Address = "123", AdditionalProperties = new Dictionary<string, object>() }; | ||
p2.AdditionalProperties.Add("TEST", 123); | ||
var json3 = JsonConvert.SerializeObject(p2, settings); | ||
Interface.Oxide.LogInfo("[GamingApi Ext] Serialized message " + json3); | ||
} | ||
|
||
////public override bool SupportsReloading => true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Reflection; | ||
using NewtonsoftAlias.Json; | ||
using NewtonsoftAlias.Json.Serialization; | ||
|
||
namespace Oxide.Ext.GamingApi | ||
{ | ||
public class OmitTypeNamesOnDynamicsResolver : DefaultContractResolver | ||
{ | ||
|
||
public static readonly OmitTypeNamesOnDynamicsResolver Instance = new OmitTypeNamesOnDynamicsResolver(); | ||
|
||
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) | ||
{ | ||
JsonProperty prop = base.CreateProperty(member, memberSerialization); | ||
if (member.GetCustomAttribute<System.Runtime.CompilerServices.DynamicAttribute>() != null) | ||
{ | ||
prop.TypeNameHandling = TypeNameHandling.None; | ||
} | ||
return prop; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Reference: NewtonsoftAlias.Json | ||
|
||
using System.Collections.Generic; | ||
using NewtonsoftAlias.Json; | ||
using NewtonsoftAlias.Json.Linq; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Oxide.Ext.GamingApi | ||
{ | ||
|
||
[JsonConverter(typeof(PlayerConverter))] | ||
public class Player | ||
{ | ||
private string id; | ||
private string name; | ||
private string address; | ||
private Dictionary<string, dynamic> additionalProperties; | ||
|
||
public string Id | ||
{ | ||
get { return id; } | ||
set { id = value; } | ||
} | ||
|
||
public string Name | ||
{ | ||
get { return name; } | ||
set { name = value; } | ||
} | ||
|
||
public string Address | ||
{ | ||
get { return address; } | ||
set { address = value; } | ||
} | ||
|
||
public Dictionary<string, object> AdditionalProperties | ||
{ | ||
get { return additionalProperties; } | ||
set { additionalProperties = value; } | ||
} | ||
} | ||
|
||
public class PlayerConverter : JsonConverter<Player> | ||
{ | ||
public override Player ReadJson(JsonReader reader, System.Type objectType, Player existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
JObject jo = JObject.Load(reader); | ||
Player value = new Player(); | ||
return value; | ||
} | ||
public override void WriteJson(JsonWriter writer, Player value, JsonSerializer serializer) | ||
{ | ||
JObject jo = new JObject(); | ||
if (value.Id != null) | ||
{ | ||
jo.Add("id", JToken.FromObject(value.Id, serializer)); | ||
} | ||
if (value.Name != null) | ||
{ | ||
jo.Add("name", JToken.FromObject(value.Name, serializer)); | ||
} | ||
if (value.Address != null) | ||
{ | ||
jo.Add("address", JToken.FromObject(value.Address, serializer)); | ||
} | ||
if (value.AdditionalProperties != null) | ||
{ | ||
for (int index = 0; index < value.AdditionalProperties.Count; index++) | ||
{ | ||
KeyValuePair<string, object> unwrapProperty = value.AdditionalProperties.ElementAt(index); | ||
if (unwrapProperty.Key != null && unwrapProperty.Value != null) | ||
{ | ||
if (!jo.ContainsKey(unwrapProperty.Key)) | ||
{ | ||
jo.Add(unwrapProperty.Key, JToken.FromObject(unwrapProperty.Value, serializer)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
jo.WriteTo(writer); | ||
} | ||
|
||
public override bool CanRead => true; | ||
public override bool CanWrite => true; | ||
} | ||
} |