Skip to content

Commit 4d9b9e7

Browse files
committed
Actually fix the damn config bug
1 parent d9b25ce commit 4d9b9e7

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

Alibi/ClientSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected override void OnDisconnected()
8787

8888
protected override void OnReceived(byte[] buffer, long offset, long size)
8989
{
90-
if (offset + size >= buffer.Length)
90+
if (offset + size >= buffer.Length || Client == null)
9191
return;
9292
var msg = Encoding.UTF8.GetString(buffer, (int) offset, (int) size);
9393
var disallowedRequests = "GET;HEAD;POST;PUT;DELETE;TRACE;OPTIONS;CONNECT;PATCH".Split(';');

Alibi/Configuration.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Net;
4+
using System.Runtime.Serialization;
45
using Alibi.Helpers;
56
using Alibi.Plugins.API;
67
using Newtonsoft.Json;
@@ -13,8 +14,8 @@ public class Configuration : IConfiguration
1314
#pragma warning disable CA2235 // Mark all non-serializable fields
1415
public string ServerName { get; internal set; } = "Test ServerRef";
1516
public string ServerDescription { get; internal set; } = "Example server description.";
16-
public string Motd { get; internal set; } = "Welcome to my test server! Type /help for a list of commands you can run.";
17-
17+
public string Motd { get; internal set; } =
18+
"Welcome to my test server! Type /help for a list of commands you can run.";
1819
public IPAddress BoundIpAddress { get; internal set; } = IPAddress.Parse("0.0.0.0");
1920
public int Port { get; internal set; } = 27016;
2021
public int WebsocketPort { get; internal set; } = 27017;
@@ -54,7 +55,7 @@ public void SaveToFile(string path)
5455

5556
public static Configuration LoadFromFile(string path)
5657
{
57-
var jsonSettings = new JsonSerializerSettings();
58+
var jsonSettings = new JsonSerializerSettings() {ContractResolver = new JsonResolver()};
5859
jsonSettings.Converters.Add(new IpConverter());
5960
var conf = JsonConvert.DeserializeObject<Configuration>(File.ReadAllText(path), jsonSettings);
6061
File.WriteAllText(path, JsonConvert.SerializeObject(conf, Formatting.Indented, jsonSettings));

Alibi/Helpers/JsonResolver.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Reflection;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Serialization;
4+
5+
namespace Alibi.Helpers
6+
{
7+
public class JsonResolver : DefaultContractResolver
8+
{
9+
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
10+
{
11+
var prop = base.CreateProperty(member, memberSerialization);
12+
13+
if (member.DeclaringType == typeof(Configuration))
14+
{
15+
prop.Writable = true;
16+
}
17+
18+
return prop;
19+
}
20+
}
21+
}

Alibi/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ static Program()
2020
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
2121
ResetEvent = new ManualResetEvent(false);
2222
Environment.CurrentDirectory = GetRealProcessDirectory();
23-
if (!File.Exists(Server.ConfigPath)
24-
|| new FileInfo(Server.ConfigPath).Length <= 0)
23+
if (!File.Exists(Server.ConfigPath) || new FileInfo(Server.ConfigPath).Length <= 0)
2524
new Configuration().SaveToFile(Server.ConfigPath);
2625
_server = new Server(Configuration.LoadFromFile(Server.ConfigPath));
2726
Console.Title = "Alibi - Running";

0 commit comments

Comments
 (0)