Skip to content

Commit c41fd56

Browse files
committed
Some cleanup and added summaries
1 parent d3f77ca commit c41fd56

File tree

7 files changed

+90
-54
lines changed

7 files changed

+90
-54
lines changed

TLobbyEditor/Commands/CommandVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CommandVersion : IRocketCommand
1212
public string Help => "Gets the version of the plugin";
1313
public string Syntax => "";
1414
public List<string> Aliases => new List<string>();
15-
public List<string> Permissions => new List<string> { "tshop.version" };
15+
public List<string> Permissions => new List<string> { "tlobbyeditor.version" };
1616

1717

1818
public void Execute(IRocketPlayer caller, string[] command)

TLobbyEditor/Helpers/LobbyHelpers.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@
44

55
namespace Tavstal.TLobbyEditor.Helpers
66
{
7+
/// <summary>
8+
/// A static class containing helper methods for working with lobby-related data.
9+
/// </summary>
10+
/// <remarks>
11+
/// This class provides utility methods to retrieve counts related to server workshop files and mode configuration fields.
12+
/// </remarks>
713
public static class LobbyHelpers
814
{
15+
/// <summary>
16+
/// Gets the count of workshop items for the server.
17+
/// </summary>
18+
/// <returns>
19+
/// The number of workshop items, calculated based on the server's workshop file IDs.
20+
/// </returns>
921
public static int GetWorkshopCount() =>
10-
(String.Join(",", Provider.getServerWorkshopFileIDs().Select(x => x.ToString()).ToArray()).Length - 1) / 120 + 1;
22+
(string.Join(",", Provider.getServerWorkshopFileIDs().Select(x => x.ToString()).ToArray()).Length - 1) / 120 + 1;
1123

24+
/// <summary>
25+
/// Gets the count of configuration fields for the mode configuration data.
26+
/// </summary>
27+
/// <returns>
28+
/// The number of configuration fields, calculated based on the mode configuration data.
29+
/// </returns>
1230
public static int GetConfigurationCount() =>
13-
(String.Join(",", typeof(ModeConfigData).GetFields()
31+
(string.Join(",", typeof(ModeConfigData).GetFields()
1432
.SelectMany(x => x.FieldType.GetFields().Select(y => y.GetValue(x.GetValue(Provider.modeConfigData))))
15-
.Select(x => x is bool v ? v ? "T" : "F" : (String.Empty + x)).ToArray()).Length - 1) / 120 + 1;
16-
33+
.Select(x => x is bool v ? v ? "T" : "F" : (string.Empty + x)).ToArray()).Length - 1) / 120 + 1;
1734
}
1835
}

TLobbyEditor/Models/ReservedSlots.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,14 @@ public class ReservedSlots
1212
public int MaxReservedSlots { get; set; }
1313

1414
public ReservedSlots() { }
15+
16+
public ReservedSlots(bool enable, bool requirePermission, string permission, int defaultSlots, int maxReservedSlots)
17+
{
18+
Enable = enable;
19+
RequirePermission = requirePermission;
20+
Permission = permission;
21+
DefaultSlots = defaultSlots;
22+
MaxReservedSlots = maxReservedSlots;
23+
}
1524
}
1625
}

TLobbyEditor/Models/StringExtensions.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

TLobbyEditor/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("Tavstal")]
1111
[assembly: AssemblyProduct("TLobbyEditor")]
12-
[assembly: AssemblyCopyright("Copyright © 2024 Tavstal")]
12+
[assembly: AssemblyCopyright("Copyright © 2025 Tavstal")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("en")]
1515

TLobbyEditor/TLobbyEditor.cs

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,23 @@
1414

1515
namespace Tavstal.TLobbyEditor
1616
{
17+
/// <summary>
18+
/// Represents a plugin for the lobby editor, inheriting from <see cref="PluginBase{TLobbyEditorConfiguration}"/>.
19+
/// </summary>
20+
/// <remarks>
21+
/// This class serves as the entry point for the lobby editor plugin and provides the functionality to configure and manage the lobby editor settings.
22+
/// </remarks>
23+
// ReSharper disable once InconsistentNaming
1724
public class TLobbyEditor : PluginBase<TLobbyEditorConfiguration>
1825
{
19-
public new static TLobbyEditor Instance { get; private set; }
26+
public static TLobbyEditor Instance { get; private set; }
2027

28+
/// <summary>
29+
/// Called when the plugin is loaded. Initializes the necessary resources and configurations for the plugin.
30+
/// </summary>
31+
/// <remarks>
32+
/// Override this method to implement the logic required during the loading of the plugin, such as setting up event handlers or loading configuration files.
33+
/// </remarks>
2134
public override void OnLoad()
2235
{
2336
Instance = this;
@@ -43,18 +56,43 @@ public override void OnLoad()
4356
Logger.Log("#########################################");
4457
}
4558

59+
/// <summary>
60+
/// Called when the plugin is unloaded. Cleans up resources and event handlers used by the plugin.
61+
/// </summary>
62+
/// <remarks>
63+
/// Override this method to implement the logic required for cleanup, such as unsubscribing from events or releasing resources.
64+
/// </remarks>
4665
public override void OnUnLoad()
4766
{
48-
UnturnedPermissions.OnJoinRequested -= Event_OnPlayerConnectPending;
67+
UnturnedPermissions.OnJoinRequested -= OnPlayerConnectPending;
4968
Level.onPostLevelLoaded -= LateInit;
5069

5170
Logger.Log("TLobbyEdtior has been successfully unloaded");
5271
}
5372

73+
/// <summary>
74+
/// Initializes the lobby modification process after the level is loaded.
75+
/// </summary>
76+
/// <param name="level">The level index or identifier that indicates when to start the modification process.</param>
77+
/// <remarks>
78+
/// This method is typically called after the level is initialized to begin the process of modifying lobby information.
79+
/// </remarks>
5480
private void LateInit(int level) => StartModifyingLobbyInfo();
5581

82+
/// <summary>
83+
/// Starts a new thread to modify the lobby information.
84+
/// </summary>
85+
/// <remarks>
86+
/// This method initiates a separate thread to run the <see cref="Modify"/> method, allowing the modification process to occur asynchronously.
87+
/// </remarks>
5688
private void StartModifyingLobbyInfo() => new Thread(Modify).Start();
5789

90+
/// <summary>
91+
/// Modifies the lobby information.
92+
/// </summary>
93+
/// <remarks>
94+
/// This method is executed on a separate thread and is responsible for making changes to the lobby's data or settings. The exact implementation will depend on the specific requirements of the lobby modification.
95+
/// </remarks>
5896
private void Modify()
5997
{
6098
try
@@ -103,9 +141,7 @@ private void Modify()
103141
if (Config.HidePlugins)
104142
SteamGameServer.SetKeyValue("rocketplugins", "0");
105143
else if (Config.MessPlugins)
106-
{
107-
SteamGameServer.SetKeyValue("rocketplugins", Config.Plugins.GetString(","));
108-
}
144+
SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", Config.Plugins));
109145
else
110146
SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", R.Plugins.GetPlugins().Select(p => p.Name).ToArray()));
111147
#endregion
@@ -165,26 +201,9 @@ private void Modify()
165201
#endregion
166202

167203
string tags = "";
168-
tags += String.Concat(new string[]
169-
{
170-
Config.IsPVP ? "PVP" : "PVE",
171-
",<gm>",
172-
Config.MessGamemode ? Config.Gamemode : Provider.gameMode.GetType().Name,
173-
"</gm>,",
174-
Config.HasCheats ? "CHy" : "CHn",
175-
",",
176-
difficulty,
177-
",",
178-
cameraMode,
179-
",",
180-
!Config.HideWorkshop ? "WSy" : "WSn",
181-
",",
182-
Config.GoldOnly ? "GLD" : "F2P",
183-
",",
184-
Config.HasBattleye ? "BEy" : "BEn"
185-
});
186-
187-
if (!String.IsNullOrEmpty(Provider.configData.Browser.Thumbnail))
204+
tags += string.Concat(Config.IsPVP ? "PVP" : "PVE", ",<gm>", Config.MessGamemode ? Config.Gamemode : Provider.gameMode.GetType().Name, "</gm>,", Config.HasCheats ? "CHy" : "CHn", ",", difficulty, ",", cameraMode, ",", !Config.HideWorkshop ? "WSy" : "WSn", ",", Config.GoldOnly ? "GLD" : "F2P", ",", Config.HasBattleye ? "BEy" : "BEn");
205+
206+
if (!string.IsNullOrEmpty(Provider.configData.Browser.Thumbnail))
188207
tags += ",<tn>" + Provider.configData.Browser.Thumbnail + "</tn>";
189208

190209
SteamGameServer.SetGameTags(tags);
@@ -196,19 +215,15 @@ private void Modify()
196215
if (Config.DescriptionFull.Length == 0)
197216
{
198217
SteamGameServer.SetKeyValue("Browser_Desc_Full_Count", "0");
199-
SteamGameServer.SetKeyValue("Browser_Desc_Full_Line_0", String.Empty);
218+
SteamGameServer.SetKeyValue("Browser_Desc_Full_Line_0", string.Empty);
200219
}
201220
else
202221
{
203222
SteamGameServer.SetKeyValue("Browser_Desc_Full_Count", Config.DescriptionFull.Length.ToString());
204223

205224
for (int i = 0; i < Config.DescriptionFull.Length; i++)
206-
{
207225
SteamGameServer.SetKeyValue("Browser_Desc_Full_Line_" + i, Config.DescriptionFull[i] + System.Environment.NewLine);
208-
}
209226
}
210-
211-
212227
#endregion
213228
});
214229

@@ -219,10 +234,18 @@ private void Modify()
219234
}
220235
}
221236

222-
private void Event_OnPlayerConnectPending(CSteamID steamid, ref ESteamRejection? rejectionReason)
237+
/// <summary>
238+
/// Called when a player is attempting to connect to the server, but their connection is still pending.
239+
/// </summary>
240+
/// <param name="steamId">The Steam ID of the player attempting to connect.</param>
241+
/// <param name="rejectionReason">The reason for rejecting the player's connection, if applicable. This is passed by reference and can be modified.</param>
242+
/// <remarks>
243+
/// This method allows you to handle player connection attempts before they are fully processed. You can modify the <paramref name="rejectionReason"/> to reject the connection if needed.
244+
/// </remarks>
245+
private void OnPlayerConnectPending(CSteamID steamId, ref ESteamRejection? rejectionReason)
223246
{
224-
SteamPending pending = Provider.pending.Find(x => x.playerID.steamID == steamid);
225-
UnturnedPlayer player = UnturnedPlayer.FromCSteamID(steamid);
247+
//SteamPending pending = Provider.pending.Find(x => x.playerID.steamID == steamId);
248+
UnturnedPlayer player = UnturnedPlayer.FromCSteamID(steamId);
226249

227250
if (Config.ReservedSlots.Enable)
228251
{

TLobbyEditor/TLobbyEditorConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Tavstal.TLobbyEditor
66
{
7+
// ReSharper disable once InconsistentNaming
78
public class TLobbyEditorConfiguration : ConfigurationBase
89
{
910
[JsonProperty(Order = 3)]
@@ -33,6 +34,7 @@ public class TLobbyEditorConfiguration : ConfigurationBase
3334
[JsonProperty(Order = 15)]
3435
public string Gamemode { get; set; }
3536
[JsonProperty(Order = 16)]
37+
// ReSharper disable once InconsistentNaming
3638
public bool IsPVP { get; set; }
3739
[JsonProperty(Order = 17)]
3840
public bool HasCheats { get; set; }

0 commit comments

Comments
 (0)