Skip to content

Commit 4f5b866

Browse files
(NEEDS TESTING) - Initial Release of Sodium 2.
(NEEDS TESTING) - Initial Release of Sodium 2.
1 parent 7d505ea commit 4f5b866

File tree

157 files changed

+7724
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+7724
-82
lines changed

BackendServices/AuxiliaryServices/WebAPIService/OHS/Batch.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public class Batch
129129
case "usercounter/incrementmany/":
130130
resultfromcommand = UserCounter.Increment_Many(PostData, ContentType, directorypath, data, game);
131131
break;
132+
case "usercounter/increment_setentry/":
133+
resultfromcommand = UserCounter.IncrementSetEntry(PostData, ContentType, directorypath, data, game);
134+
break;
132135
case "userinventory/addglobalitems/":
133136
resultfromcommand = UserInventory.AddGlobalItems(PostData, ContentType, directorypath + $"/{project}/", data, game);
134137
break;

BackendServices/AuxiliaryServices/WebAPIService/OHS/JaminProcessor.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class JaminProcessor
1111
{
1212
public static bool VerifyHash(string str, string referencehash)
1313
{
14-
if (EncryptDecrypt.Hash32Str(str) == referencehash.ToUpper())
14+
if (EncryptDecrypt.Hash32Str(str).Equals(referencehash, StringComparison.InvariantCultureIgnoreCase))
1515
return true;
1616

1717
return false;
@@ -309,8 +309,8 @@ public static object[] ExecuteLuaScript(string luaScript)
309309
private static string ToLiteral(string input)
310310
{
311311
StringBuilder literal = new StringBuilder(input.Length + 2);
312-
literal.Append("\"");
313-
foreach (var c in input)
312+
literal.Append('"');
313+
foreach (char c in input)
314314
{
315315
switch (c)
316316
{
@@ -327,10 +327,8 @@ private static string ToLiteral(string input)
327327
default:
328328
// ASCII printable character
329329
if (c >= 0x20 && c <= 0x7e)
330-
{
331330
literal.Append(c);
332331
// As UTF16 escaped character
333-
}
334332
else
335333
{
336334
literal.Append(@"\u");
@@ -339,7 +337,7 @@ private static string ToLiteral(string input)
339337
break;
340338
}
341339
}
342-
literal.Append("\"");
340+
literal.Append('"');
343341
return literal.ToString();
344342
}
345343
}

BackendServices/AuxiliaryServices/WebAPIService/OHS/Leaderboard.cs

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text;
99
using System.Text.RegularExpressions;
1010
using System;
11+
using System.Linq;
1112

1213
namespace WebAPIService.OHS
1314
{
@@ -374,13 +375,16 @@ public static string UpdateScoreboard(string json, string nameToUpdate, int newS
374375
{
375376
foreach (var entry in entries)
376377
{
377-
var rankData = new Dictionary<string, object>
378-
{
379-
{ "[\"user\"]", $"\"{entry.Name}\"" }, // Enclose string in double quotes and put it inside the brackets
380-
{ "[\"score\"]", $"\"{entry.Score}\"" } // For numbers, no need to enclose in quotes and put it inside the brackets
381-
};
378+
if (!string.IsNullOrEmpty(entry.Name))
379+
{
380+
var rankData = new Dictionary<string, object>
381+
{
382+
{ "[\"user\"]", $"\"{entry.Name}\"" }, // Enclose string in double quotes and put it inside the brackets
383+
{ "[\"score\"]", $"\"{entry.Score}\"" } // For numbers, no need to enclose in quotes and put it inside the brackets
384+
};
382385

383-
luaTable.Add(entry.Rank, rankData);
386+
luaTable.Add(entry.Rank, rankData);
387+
}
384388
}
385389

386390
// Step 3: Format the Lua table as a string using regex
@@ -421,7 +425,7 @@ public static string RequestByUsers(string? jsontable, string scoreboardpath)
421425
{
422426
StringBuilder? resultBuilder = new StringBuilder();
423427

424-
foreach (string user in data.Users)
428+
foreach (string user in data.Users.Where(user => !string.IsNullOrEmpty(user)))
425429
{
426430
string? scoreboarddata = File.ReadAllText(scoreboardfile);
427431

@@ -441,7 +445,7 @@ public static string RequestByUsers(string? jsontable, string scoreboardpath)
441445
{
442446
foreach (var entry in entries)
443447
{
444-
if (entry.Name == user)
448+
if (!string.IsNullOrEmpty(entry.Name) && entry.Name.Equals(user))
445449
{
446450
if (entry.Score != 0)
447451
{
@@ -492,7 +496,7 @@ public static string RequestByUsers(string? jsontable, string scoreboardpath)
492496

493497
foreach (var entry in scoreentries)
494498
{
495-
if (i >= 1)
499+
if (i >= 1 && !string.IsNullOrEmpty(entry.Name))
496500
{
497501
var rankData = new Dictionary<string, object>
498502
{
@@ -564,11 +568,7 @@ public static string RequestByUsers(string? jsontable, string scoreboardpath)
564568
string scoreboardfile = scoreboardpath + $"/scoreboard_{key}.json";
565569

566570
if (!File.Exists(scoreboardfile))
567-
{
568-
Scoreboard? scoreboard = GenerateSampleScoreboard(numEntries);
569-
File.WriteAllText(scoreboardfile, JsonConvert.SerializeObject(scoreboard, Formatting.Indented));
570-
scoreboard = null;
571-
}
571+
File.WriteAllText(scoreboardfile, JsonConvert.SerializeObject(GenerateSampleScoreboard(numEntries), Formatting.Indented));
572572

573573
scoreboardfile = File.ReadAllText(scoreboardfile);
574574

@@ -596,7 +596,7 @@ public static string RequestByUsers(string? jsontable, string scoreboardpath)
596596

597597
foreach (var entry in entries)
598598
{
599-
if (i >= start)
599+
if (i >= start && !string.IsNullOrEmpty(entry.Name))
600600
{
601601
var rankData = new Dictionary<string, object>
602602
{
@@ -632,15 +632,12 @@ public static string RequestByUsers(string? jsontable, string scoreboardpath)
632632
public static Scoreboard GenerateSampleScoreboard(int numEntries)
633633
{
634634
Scoreboard scoreboard = new Scoreboard();
635-
Random? random = new Random();
636635

637-
scoreboard.Entries = new List<ScoreboardEntry>();
636+
scoreboard.Entries = new List<ScoreboardEntry>(numEntries);
638637

639638
for (int i = 1; i <= numEntries; i++)
640639
{
641-
string playerName = ScoreboardNameGenerator.GenerateRandomName();
642-
int score = random.Next(100, 1000); // Generate a random score between 100 and 999
643-
scoreboard.Entries.Add(new ScoreboardEntry { Name = playerName, Score = score });
640+
scoreboard.Entries.Add(new ScoreboardEntry { Name = string.Empty, Score = 0 });
644641
}
645642

646643
// Sort the entries by score in descending order
@@ -652,8 +649,6 @@ public static Scoreboard GenerateSampleScoreboard(int numEntries)
652649
scoreboard.Entries[i].Rank = i + 1;
653650
}
654651

655-
random = null;
656-
657652
return scoreboard;
658653
}
659654

@@ -763,19 +758,6 @@ public override void WriteJson(JsonWriter writer, ScoreBoardUpdate? value, JsonS
763758
}
764759
}
765760

766-
public class ScoreboardNameGenerator
767-
{
768-
private static Random random = new Random();
769-
770-
// List of silly French-sounding words to be used in the names
771-
private static string[] sillyFrenchWords = { "Croissant", "Baguette", "Fougasse", "TarteAuFromage", "Tabernack", "UnePetiteContine", "ChuckNorris", "Pamplemousse", "JimCarrey", "Fromage" };
772-
773-
public static string GenerateRandomName()
774-
{
775-
return sillyFrenchWords[random.Next(0, sillyFrenchWords.Length)];
776-
}
777-
}
778-
779761
public class ScoreboardEntry
780762
{
781763
public string? Name { get; set; }

BackendServices/AuxiliaryServices/WebAPIService/OHS/User.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public class User
227227
// Check if the "key" property exists and if it is an object
228228
if (jsonObject.TryGetValue("key", out JToken? keyValueToken) && keyValueToken.Type == JTokenType.Object)
229229
// Convert the JToken to a Lua table-like string
230-
output = JaminProcessor.ConvertJTokenToLuaTable(keyValueToken, false);
230+
output = JaminProcessor.ConvertJTokenToLuaTable(keyValueToken, true); // Nested, because we expect the array instead.
231231
}
232232
}
233233
}
@@ -245,7 +245,7 @@ public class User
245245
// Check if the "key" property exists and if it is an object
246246
if (jsonObject.TryGetValue("key", out JToken? keyValueToken) && keyValueToken.Type == JTokenType.Object)
247247
// Convert the JToken to a Lua table-like string
248-
output = JaminProcessor.ConvertJTokenToLuaTable(keyValueToken, false);
248+
output = JaminProcessor.ConvertJTokenToLuaTable(keyValueToken, true); // Nested, because we expect the array instead.
249249
}
250250
}
251251
}

0 commit comments

Comments
 (0)