Skip to content

Commit

Permalink
MSSP Config to use Properties for easier serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryCordewener committed Jan 2, 2024
1 parent 337845c commit 8aac7ed
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
18 changes: 9 additions & 9 deletions TelnetNegotiationCore/Interpreters/TelnetMSSPInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public partial class TelnetInterpreter
.Where(x => x.Attribute != null)
.ToImmutableDictionary(x => x.Attribute.Name.ToUpper());

private JsonSerializerOptions _serializerOptions = new JsonSerializerOptions() { IncludeFields = true };

/// <summary>
/// Mud Server Status Protocol will provide information to the requestee about the server's contents.
/// </summary>
Expand Down Expand Up @@ -146,7 +144,7 @@ private async Task ReadMSSPValues()
StoreClientMSSPDetails(group.Key, group.Select(x => CurrentEncoding.GetString(x.Second.ToArray())));
}

_Logger.Debug("Registering MSSP: {@msspConfig}", JsonSerializer.Serialize<MSSPConfig>(_msspConfig(), _serializerOptions));
_Logger.Debug("Registering MSSP: {@msspConfig}", _msspConfig());

await Task.CompletedTask;
}
Expand All @@ -161,26 +159,28 @@ private void StoreClientMSSPDetails(string variable, IEnumerable<string> value)
if (MSSPAttributeMembers.ContainsKey(variable.ToUpper()))
{
var foundAttribute = MSSPAttributeMembers[variable.ToUpper()];
var fieldInfo = (FieldInfo)foundAttribute.Member;
var fieldInfo = (PropertyInfo)foundAttribute.Member;

if (fieldInfo.FieldType == typeof(Func<string>))
var msspConfig = _msspConfig();
if (fieldInfo.PropertyType == typeof(string))
{
fieldInfo.SetValue(_msspConfig(), value.First());
fieldInfo.SetValue(msspConfig, value.First());
}
else if (fieldInfo.FieldType == typeof(Func<int>))
else if (fieldInfo.PropertyType == typeof(int))
{
var val = int.Parse(value.First());
fieldInfo.SetValue(_msspConfig(), val);
}
else if (fieldInfo.FieldType == typeof(Func<bool>))
else if (fieldInfo.PropertyType == typeof(bool))
{
var val = value.First() == "1";
fieldInfo.SetValue(_msspConfig(), val);
}
else if (fieldInfo.FieldType == typeof(Func<IEnumerable<string>>))
else if (fieldInfo.PropertyType == typeof(IEnumerable<string>))
{
fieldInfo.SetValue(_msspConfig(), value);
}
_msspConfig = () => msspConfig;
}
else
{
Expand Down
96 changes: 48 additions & 48 deletions TelnetNegotiationCore/Models/MSSPConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace TelnetNegotiationCore.Models
/// <summary>
/// Indicates the MSSP-safe name to send.
/// </summary>
[AttributeUsage(AttributeTargets.Field, Inherited = false)]
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
public class NameAttribute : Attribute
{
public string Name { get; private set; }
Expand All @@ -21,7 +21,7 @@ public NameAttribute(string name)
/// <summary>
/// Indicates whether or not it's in the official MSSP definition.
/// </summary>
[AttributeUsage(AttributeTargets.Field, Inherited = false)]
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
public class OfficialAttribute : Attribute
{
public bool Official { get; private set; }
Expand All @@ -39,75 +39,75 @@ public class MSSPConfig
{
/// <summary>NAME: Name of the MUD.</summary>
[Name("NAME"), Official(true)]
public string Name;
public string Name { get; set; }

/// <summary>PLAYERS: Current number of logged in players.</summary>
[Name("PLAYERS"), Official(true)]
public int Players;
public int Players { get; set; }

/// <summary>UPTIME: Unix time value of the startup time of the MUD.</summary>
[Name("UPTIME"), Official(true)]
public int Uptime;
public int Uptime { get; set; }

/// <summary>CODEBASE: Name of the codebase, eg Merc 2.1. You can report multiple codebases using the array format, make sure to report the current codebase last.</summary>
[Name("CODEBASE"), Official(true)]
public IEnumerable<string> Codebase;
public IEnumerable<string> Codebase { get; set; }

/// <summary>CONTACT: Email address for contacting the MUD.</summary>
[Name("CONTACT"), Official(true)]
public string Contact;
public string Contact { get; set; }

/// <summary>CRAWL DELAY: Preferred minimum number of hours between crawls. Send -1 to use the crawler's default.</summary>
[Name("CRAWL DELAY"), Official(true)]
public int Crawl_Delay;
public int Crawl_Delay { get; set; }

/// <summary>CREATED: Year the MUD was created.</summary>
[Name("CREATED"), Official(true)]
public string Created;
public string Created { get; set; }

/// <summary>HOSTNAME: Current or new hostname.</summary>
[Name("HOSTNAME"), Official(true)]
public string Hostname;
public string Hostname { get; set; }

/// <summary>ICON: URL to a square image in bmp, png, jpg, or gif format. The icon should be equal or larger than 64x64 pixels, with a filesize no larger than 256KB.</summary>
[Name("ICON"), Official(true)]
public string Icon;
public string Icon { get; set; }

/// <summary>IP: Current or new IP address.</summary>
[Name("IP"), Official(true)]
public string IP;
public string IP { get; set; }

/// <summary>IPV6: Current or new IPv6 address.</summary>
[Name("IPV6"), Official(true)]
public string IPV6;
public string IPV6 { get; set; }

/// <summary>LANGUAGE: English name of the language used, eg German or English</summary>
[Name("LANGUAGE"), Official(true)]
public string Language;
public string Language { get; set; }

/// <summary>LOCATION: English short name of the country where the server is located, using ISO 3166.</summary>
[Name("LOCATION"), Official(true)]
public string Location;
public string Location { get; set; }

/// <summary>MINIMUM AGE: Current minimum age requirement, omit if not applicable.</summary>
[Name("MINIMUM AGE"), Official(true)]
public string Minimum_Age;
public string Minimum_Age { get; set; }

/// <summary>PORT: Current or new port number. Can be used multiple times, most important port last.</summary>
[Name("PORT"), Official(true)]
public int Port;
public int Port { get; set; }

/// <summary>REFERRAL: A list of other MSSP enabled MUDs for the crawler to check using the host port format and array notation. Adding referrals is important to make MSSP decentralized. Make sure to separate the host and port with a space rather than : because IPv6 addresses contain colons.</summary>
[Name("REFERRAL"), Official(true)]
public IEnumerable<string> Referral;
public IEnumerable<string> Referral { get; set; }

/// <summary>The port number for a SSL (Secure Socket Layer) encrypted connection.</summary>
[Name("SSL"), Official(true)]
public string Ssl;
public string Ssl { get; set; }

/// <summary>WEBSITE: URL to MUD website, this should include the http:// or https:// prefix.</summary>
[Name("WEBSITE"), Official(true)]
public string Website;
public string Website { get; set; }

/// <summary>FAMILY: AberMUD, CoffeeMUD, DikuMUD, Evennia, LPMud, MajorMUD, MOO, Mordor, SocketMud, TinyMUD, TinyMUCK, TinyMUSH, Custom.
/// Report Custom unless it's a well established family.
Expand All @@ -116,28 +116,28 @@ public class MSSPConfig
///
/// Check the MUD family tree for naming and capitalization.</summary>
[Name("FAMILY"), Official(true)]
public IEnumerable<string> Family;
public IEnumerable<string> Family { get; set; }

/// <summary>GENRE: Adult, Fantasy, Historical, Horror, Modern, Mystery, None, Romance, Science Fiction, Spiritual</summary>
[Name("GENRE"), Official(true)]
public string Genre;
public string Genre { get; set; }

/// <summary>GAMEPLAY: Adventure, Educational, Hack and Slash, None, Player versus Player, Player versus Environment, Questing, Roleplaying, Simulation, Social, Strategy</summary>
[Name("GAMEPLAY"), Official(true)]
public IEnumerable<string> Gameplay;
public IEnumerable<string> Gameplay { get; set; }


/// <summary>STATUS: Alpha, Closed Beta, Open Beta, Live</summary>
[Name("STATUS"), Official(true)]
public string Status;
public string Status { get; set; }

/// <summary>GAMESYSTEM: D&D, d20 System, World of Darkness, Etc. Use Custom if using a custom game system. Use None if not available.</summary>
[Name("GAMESYSTEM"), Official(true)]
public string Gamesystem;
public string Gamesystem { get; set; }

/// <summary>INTERMUD: AberChat, I3, IMC2, MudNet, Etc. Can be used multiple times if you support several protocols, most important protocol last. Leave empty or omit if no Intermud protocol is supported.</summary>
[Name("INTERMUD"), Official(true)]
public IEnumerable<string> Intermud;
public IEnumerable<string> Intermud { get; set; }

/// <summary>SUBGENRE: Alternate History, Anime, Cyberpunk, Detective, Discworld, Dragonlance, Christian Fiction, Classical Fantasy,
/// Crime, Dark Fantasy, Epic Fantasy, Erotic, Exploration, Forgotten Realms, Frankenstein, Gothic, High Fantasy,
Expand All @@ -146,94 +146,94 @@ public class MSSPConfig
///
/// Use None if not applicable.</summary>
[Name("SUBGENRE"), Official(true)]
public string Subgenre;
public string Subgenre { get; set; }

/// <summary>AREAS: Current number of areas.</summary>
[Name("AREAS"), Official(true)]
public int Areas;
public int Areas { get; set; }

/// <summary>HELPFILES: Current number of help files.</summary>
[Name("HELPFILES"), Official(true)]
public int Helpfiles;
public int Helpfiles { get; set; }

/// <summary>MOBILES: Current number of unique mobiles.</summary>
[Name("MOBILES"), Official(true)]
public int Mobiles;
public int Mobiles { get; set; }

/// <summary>OBJECTS: Current number of unique objects.</summary>
[Name("OBJECTS"), Official(true)]
public int Objects;
public int Objects { get; set; }

/// <summary>ROOMS: Current number of unique rooms, use 0 if roomless.</summary>
[Name("ROOMS"), Official(true)]
public int Rooms;
public int Rooms { get; set; }

/// <summary>CLASSES: Number of player classes, use 0 if classless.</summary>
[Name("CLASSES"), Official(true)]
public int Classes;
public int Classes { get; set; }

/// <summary>LEVELS: Number of player levels, use 0 if level-less.</summary>
[Name("LEVELS"), Official(true)]
public int Levels;
public int Levels { get; set; }

/// <summary>RACES: Number of player races, use 0 if raceless.</summary>
[Name("RACES"), Official(true)]
public int Races;
public int Races { get; set; }

/// <summary>SKILLS: Number of player skills, use 0 if skill-less.</summary>
[Name("SKILLS"), Official(true)]
public int Skills;
public int Skills { get; set; }

/// <summary>ANSI: Supports ANSI colors ? 1 or 0</summary>
[Name("ANSI"), Official(true)]
public bool Ansi;
public bool Ansi { get; set; }

/// <summary>PUEBLO: Supports Pueblo ? 1 or 0</summary>
[Name("PUEBLO"), Official(false)]
public bool Pueblo;
public bool Pueblo { get; set; }

/// <summary>MSP: Supports MSP ? 1 or 0</summary>
[Name("MSP"), Official(true)]
public bool MSP;
public bool MSP { get; set; }

/// <summary>UTF-8: Supports UTF-8 ? 1 or 0</summary>
[Name("UTF-8"), Official(true)]
public bool UTF_8;
public bool UTF_8 { get; set; }

/// <summary>VT100: Supports VT100 interface ? 1 or 0</summary>
[Name("VT100"), Official(true)]
public bool VT100;
public bool VT100 { get; set; }

/// <summary>XTERM: 256 COLORS Supports xterm 256 colors ? 1 or 0</summary>
[Name("XTERM 256 COLORS"), Official(true)]
public bool XTerm_256_Colors;
public bool XTerm_256_Colors { get; set; }

/// <summary>XTERM: TRUE COLORS Supports xterm 24 bit colors ? 1 or 0</summary>
[Name("XTERM TRUE COLORS"), Official(true)]
public bool XTerm_True_Colors;
public bool XTerm_True_Colors { get; set; }

/// <summary>PAY: TO PLAY Pay to play ? 1 or 0</summary>
[Name("PAY TO PLAY"), Official(true)]
public bool Pay_To_Play;
public bool Pay_To_Play { get; set; }

/// <summary>PAY: FOR PERKS Pay for perks ? 1 or 0</summary>
[Name("PAY FOR PERKS"), Official(true)]
public bool Pay_For_Perks;
public bool Pay_For_Perks { get; set; }

/// <summary>HIRING: BUILDERS Game is hiring builders ? 1 or 0</summary>
[Name("HIRING BUILDERS"), Official(true)]
public bool Hiring_Builders;
public bool Hiring_Builders { get; set; }

/// <summary>HIRING: CODERS Game is hiring coders ? 1 or 0</summary>
[Name("HIRING CODERS"), Official(true)]
public bool Hiring_Coders;
public bool Hiring_Coders { get; set; }

/// <summary>Additional information.
/// Dictionary Key serves as the MSSP Key
/// Dictionary Value.obj serves as the MSSP Value
/// Dictionary Value.type serves as the MSSP Value Type for unboxing
/// We only support IEnumerable<string>, bool, int and string at this time</summary>
[Official(false)]
public Dictionary<string, dynamic> Extended = new();
public Dictionary<string, dynamic> Extended { get; set; } = new ();
}
}

0 comments on commit 8aac7ed

Please sign in to comment.