Skip to content

Commit f0fea5f

Browse files
Mid May of 2025 update.
This general update improves and fixes several parts if the server stack. - Replaces every NET's own Base64 decoder with our custom one, which has a new managed fallback, due to some Base64-encoded data not being decrypted right. - WebAPIService: Adjusts Lua2Xml code to handle vectors from lua table (classic lua interpreter not has this data-type (nor it does have matrix type, but this is TODO for now this one), fixes the random AES key generator with a fallback if the http request failed (the website shuted-down?) and implements more Ubisoft API responses. - NetworkLibrary: Fixes empty base64 decoding, implements GeoIP new "GetCountryLangCodeFromIP" method and revise the CertificateHelper loading to help importing existing certs to our system, on top of adding more RootCa to the CERTIFICATES.TXT file. - Horizon: Re-implement Home Anti-Cheat IP Perma ban, implements more Crud endpoints, implements and fixes more security functions and fallback again on the classic NAT domain (seems to be alive again?). - ApacheNet: Implements more static Routes, as well as a remote reboot/shutdown function (whitelisted by IP). - Remote Control: Show my Commodore passion via a startup jingle :).
1 parent 5a55fb7 commit f0fea5f

File tree

89 files changed

+5971
-530
lines changed

Some content is hidden

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

89 files changed

+5971
-530
lines changed

AuxiliaryServices/HomeTools/BARFramework/BARArchive.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,12 @@ private void WriteHeader(EndianAwareBinaryWriter writer)
628628
if (m_endian == EndianType.BigEndian) // This data is always little endian.
629629
{
630630
writer.Write(EndianUtils.EndianSwap(IV));
631-
writer.Write(EndianUtils.EndianSwap(LIBSECURE.InitiateAESBuffer(CipheredHeaderData, Convert.FromBase64String(version2key), IV, "CTR") ?? Array.Empty<byte>()));
631+
writer.Write(EndianUtils.EndianSwap(LIBSECURE.InitiateAESBuffer(CipheredHeaderData, version2key.IsBase64().Item2, IV, "CTR") ?? Array.Empty<byte>()));
632632
}
633633
else
634634
{
635635
writer.Write(IV);
636-
writer.Write(LIBSECURE.InitiateAESBuffer(CipheredHeaderData, Convert.FromBase64String(version2key), IV, "CTR") ?? Array.Empty<byte>());
636+
writer.Write(LIBSECURE.InitiateAESBuffer(CipheredHeaderData, version2key.IsBase64().Item2, IV, "CTR") ?? Array.Empty<byte>());
637637
}
638638
}
639639
else

AuxiliaryServices/HomeTools/BARFramework/TOC.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using EndianTools;
2+
using NetworkLibrary.Extension;
23
using System;
34
using System.Collections;
45
using System.Collections.Generic;
@@ -189,7 +190,7 @@ public byte[] GetBytesVersion2(string key, byte[] IV, EndianType endian)
189190
binaryWriter.Write(tocentry.IV);
190191
}
191192
binaryWriter.Close();
192-
return Crypto.LIBSECURE.InitiateAESBuffer(memoryStream.ToArray(), Convert.FromBase64String(key), IV, "CTR") ?? Array.Empty<byte>();
193+
return Crypto.LIBSECURE.InitiateAESBuffer(memoryStream.ToArray(), key.IsBase64().Item2, IV, "CTR") ?? Array.Empty<byte>();
193194
}
194195

195196
public uint Version1Size
@@ -247,4 +248,4 @@ internal void ResortOffsets()
247248

248249
private BARArchive m_parent;
249250
}
250-
}
251+
}

AuxiliaryServices/HomeTools/PS3 Creator/pkg2sfo.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CustomLogger;
1+
using CustomLogger;
2+
using NetworkLibrary.Extension;
23
using System;
34
using System.Data;
45
using System.IO;
@@ -830,7 +831,7 @@ public static string Decrypt(string cipherText, string Password, CipherMode ciph
830831
// First we need to turn the input string into a byte array.
831832
// We presume that Base64 encoding was used
832833

833-
byte[] cipherBytes = Convert.FromBase64String(cipherText);
834+
byte[] cipherBytes = cipherText.IsBase64().Item2;
834835

835836
// Then, we need to turn the password into Key and IV
836837
// We are using salt to make it harder to guess our key

AuxiliaryServices/HomeTools/UnBAR/RunUnBAR.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static Task RunExtract(string filePath, string outDir, ushort cdnMode)
148148
Buffer.BlockCopy(RawBarData, 24, SharcHeader, 0, SharcHeader.Length);
149149

150150
SharcHeader = LIBSECURE.InitiateAESBuffer(SharcHeader,
151-
Convert.FromBase64String(options), HeaderIV, "CTR");
151+
options.IsBase64().Item2, HeaderIV, "CTR");
152152

153153
if (SharcHeader == null)
154154
return Task.CompletedTask; // Sharc Header failed to decrypt.
@@ -159,7 +159,7 @@ private static Task RunExtract(string filePath, string outDir, ushort cdnMode)
159159
Buffer.BlockCopy(RawBarData, 24, SharcHeader, 0, SharcHeader.Length);
160160

161161
SharcHeader = LIBSECURE.InitiateAESBuffer(SharcHeader,
162-
Convert.FromBase64String(options), HeaderIV, "CTR");
162+
options.IsBase64().Item2, HeaderIV, "CTR");
163163

164164
if (SharcHeader == null)
165165
return Task.CompletedTask; // Sharc Header failed to decrypt.
@@ -170,7 +170,7 @@ private static Task RunExtract(string filePath, string outDir, ushort cdnMode)
170170
Buffer.BlockCopy(RawBarData, 24, SharcHeader, 0, SharcHeader.Length);
171171

172172
SharcHeader = LIBSECURE.InitiateAESBuffer(SharcHeader,
173-
Convert.FromBase64String(options), HeaderIV, "CTR");
173+
options.IsBase64().Item2, HeaderIV, "CTR");
174174

175175
if (SharcHeader == null)
176176
return Task.CompletedTask; // Sharc Header failed to decrypt.
@@ -201,7 +201,7 @@ private static Task RunExtract(string filePath, string outDir, ushort cdnMode)
201201

202202
ToolsImplementation.IncrementIVBytes(HeaderIV, 1); // IV so we increment.
203203

204-
SharcTOC = LIBSECURE.InitiateAESBuffer(SharcTOC, Convert.FromBase64String(options), HeaderIV, "CTR");
204+
SharcTOC = LIBSECURE.InitiateAESBuffer(SharcTOC, options.IsBase64().Item2, HeaderIV, "CTR");
205205

206206
if (SharcTOC != null)
207207
{

AuxiliaryServices/HorizonService/LIBRARY.Database/DbController.cs

+58-53
Original file line numberDiff line numberDiff line change
@@ -265,66 +265,73 @@ public async Task<string> GetPlayerList()
265265
/// </summary>
266266
/// <param name="name">Case insensitive name of player.</param>
267267
/// <returns>Returns account.</returns>
268-
public async Task<AccountDTO> GetAccountByName(string name, int appId)
268+
public async Task<AccountDTO> GetAccountByName(string name, int appId, bool forceRpcnCheck = false)
269269
{
270270
AccountDTO result = null;
271271

272272
try
273273
{
274274
if (_settings.SimulatedMode)
275275
{
276-
if (name == "gameRecorder_r2_pubeta_master" && appId == 21731)
276+
if (name != null)
277277
{
278-
AccountDTO R2PuBeta;
279-
_simulatedAccounts.Add(R2PuBeta = new AccountDTO()
278+
if (name == "gameRecorder_r2_pubeta_master" && appId == 21731)
280279
{
281-
AccountId = 2,
282-
AccountName = "gameRecorder_r2_pubeta_master",
283-
AccountPassword = string.Empty,
284-
AccountWideStats = new int[Constants.LADDERSTATSWIDE_MAXLEN],
285-
AccountCustomWideStats = new int[1000],
286-
AppId = 21731,
287-
MachineId = string.Empty,
288-
MediusStats = string.Empty,
289-
Friends = Array.Empty<AccountRelationDTO>(),
290-
Ignored = Array.Empty<AccountRelationDTO>(),
291-
IsBanned = false
292-
});
293-
294-
return R2PuBeta;
295-
}
296-
else if (name == "ftb3 Moderator_0" && appId == 21694)
297-
{
298-
AccountDTO ftb3Mod;
299-
_simulatedAccounts.Add(ftb3Mod = new AccountDTO()
280+
AccountDTO R2PuBeta;
281+
_simulatedAccounts.Add(R2PuBeta = new AccountDTO()
282+
{
283+
AccountId = 2,
284+
AccountName = "gameRecorder_r2_pubeta_master",
285+
AccountPassword = string.Empty,
286+
AccountWideStats = new int[Constants.LADDERSTATSWIDE_MAXLEN],
287+
AccountCustomWideStats = new int[1000],
288+
AppId = 21731,
289+
MachineId = string.Empty,
290+
MediusStats = string.Empty,
291+
Friends = Array.Empty<AccountRelationDTO>(),
292+
Ignored = Array.Empty<AccountRelationDTO>(),
293+
IsBanned = false
294+
});
295+
296+
return R2PuBeta;
297+
}
298+
else if (name == "ftb3 Moderator_0" && appId == 21694)
300299
{
301-
AccountId = 2,
302-
AccountName = "ftb3 Moderator_0",
303-
AccountPassword = string.Empty,
304-
AccountWideStats = new int[Constants.LADDERSTATSWIDE_MAXLEN],
305-
AccountCustomWideStats = new int[1000],
306-
AppId = 21694,
307-
MachineId = string.Empty,
308-
MediusStats = string.Empty,
309-
Friends = Array.Empty<AccountRelationDTO>(),
310-
Ignored = Array.Empty<AccountRelationDTO>(),
311-
IsBanned = false
312-
});
313-
314-
return ftb3Mod;
300+
AccountDTO ftb3Mod;
301+
_simulatedAccounts.Add(ftb3Mod = new AccountDTO()
302+
{
303+
AccountId = 2,
304+
AccountName = "ftb3 Moderator_0",
305+
AccountPassword = string.Empty,
306+
AccountWideStats = new int[Constants.LADDERSTATSWIDE_MAXLEN],
307+
AccountCustomWideStats = new int[1000],
308+
AppId = 21694,
309+
MachineId = string.Empty,
310+
MediusStats = string.Empty,
311+
Friends = Array.Empty<AccountRelationDTO>(),
312+
Ignored = Array.Empty<AccountRelationDTO>(),
313+
IsBanned = false
314+
});
315+
316+
return ftb3Mod;
317+
}
318+
else
319+
result = _simulatedAccounts.FirstOrDefault(x =>
320+
x.AppId == appId &&
321+
x.AccountName != null &&
322+
(forceRpcnCheck
323+
? x.AccountName.ToLower() == name.ToLower()
324+
: (x.AccountName.EndsWith("@RPCN", StringComparison.OrdinalIgnoreCase)
325+
? x.AccountName.Substring(0, x.AccountName.Length - "@RPCN".Length)
326+
: x.AccountName).ToLower() == name.ToLower()
327+
)
328+
);
315329
}
316-
else
317-
result = _simulatedAccounts.FirstOrDefault(x => x.AppId == appId &&
318-
x.AccountName != null &&
319-
name != null &&
320-
(x.AccountName.EndsWith("@RPCN")
321-
? x.AccountName.Substring(0, x.AccountName.Length - "@RPCN".Length)
322-
: x.AccountName).ToLower() == name.ToLower());
323330
}
324331
else
325332
{
326333
name = HttpUtility.UrlEncode(name);
327-
string route = $"Account/searchAccountByName?AccountName={name}&AppId={appId}";
334+
string route = $"Account/searchAccountByName?AccountName={name}&AppId={appId}&ForceRpcnCheck={forceRpcnCheck}";
328335
result = await GetDbAsync<AccountDTO>(route);
329336
}
330337
}
@@ -397,7 +404,7 @@ public async Task<AccountDTO> CreateAccount(CreateAccountDTO createAccount, ICha
397404
{
398405
if (_settings.SimulatedMode)
399406
{
400-
var checkExisting = await GetAccountByName(createAccount.AccountName, createAccount.AppId);
407+
var checkExisting = await GetAccountByName(createAccount.AccountName, createAccount.AppId, true);
401408
if (checkExisting == null)
402409
{
403410
_simulatedAccounts.Add(result = new AccountDTO()
@@ -712,24 +719,22 @@ public async Task<bool> PostAccountIp(int accountId, string ip)
712719
/// <summary>
713720
/// Gets whether or not the ip is banned.
714721
/// </summary>
715-
public async Task<bool> GetIsIpBanned(string ip)
722+
public async Task<bool> GetIsIpBanned(IPAddress ip)
716723
{
717724
bool result = false;
718725

719726
try
720727
{
721728
if (_settings.SimulatedMode)
722729
{
723-
if (IPAddress.TryParse(ip, out IPAddress Parsedip) && Parsedip != null && Parsedip != IPAddress.None)
730+
if (ip != null && ip != IPAddress.None && ip != IPAddress.Any && ip != IPAddress.IPv6Any)
724731
{
725-
(string, bool) ResultItem = JsonDatabaseController.ReadFromJsonFile(directoryPath, "IPAddress", InternetProtocolUtils.GetIPAddressAsUInt(Parsedip).ToString());
732+
(string, bool) ResultItem = JsonDatabaseController.ReadFromJsonFile(directoryPath, "IPAddress", InternetProtocolUtils.GetIPAddressAsUInt(ip).ToString());
726733

727734
switch (ResultItem.Item1)
728735
{
729736
case "OK":
730737
return ResultItem.Item2;
731-
default:
732-
return false;
733738
}
734739
}
735740

@@ -879,11 +884,11 @@ public async Task<bool> PostMachineId(int accountId, string machineId)
879884
/// Posts the given ip to ban to the database.
880885
/// </summary>
881886
/// <param name="ipToBan">client ip.</param>
882-
public async Task<bool> BanIp(string ipToBan)
887+
public async Task<bool> BanIp(IPAddress ipToBan)
883888
{
884889
bool result = false;
885890

886-
if (string.IsNullOrEmpty(ipToBan))
891+
if (ipToBan == null || ipToBan == IPAddress.None || ipToBan == IPAddress.Any || ipToBan == IPAddress.IPv6Any)
887892
return result;
888893

889894
try

AuxiliaryServices/WebAPIService/OHS/LUA2XmlCode.cs

+24-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,18 @@ local function tableCount(tbl)
6464
6565
local convert =
6666
{
67-
string = function( val ) return tostring(val) end,
67+
string = function( val )
68+
-- Workaround for lack of Vector4 in classic lua interpreters.
69+
local pattern = ""^([+-]?[0-9]*%.?[0-9]+),([+-]?[0-9]*%.?[0-9]+),([+-]?[0-9]*%.?[0-9]+),([+-]?[0-9]*%.?[0-9]+)$""
70+
local x, y, z, w = val:match(pattern)
71+
-- If we found the vector pattern, process it
72+
if x and y and z and w then
73+
local components = {x, y, z, w}
74+
return table.concat(components, ','), 'vec'
75+
else
76+
return tostring(val) -- Default string conversion
77+
end
78+
end,
6879
boolean = function( val ) return tostring(val), 'bool' end,
6980
number = function( val ) return math.floor(val) == val and string.format('%d', val) or tostring(val), 'num' end,
7081
vector4 = function( val ) return table.concat({val:X(), val:Y(), val:Z(), val:W()}, ','), 'vec' end,
@@ -166,7 +177,18 @@ local function toXml( tbl, indent )
166177
167178
local ENCODE =
168179
{
169-
string = function( x ) return tostring(x) end,
180+
string = function( val )
181+
-- Workaround for lack of Vector4 in classic lua interpreters.
182+
local pattern = ""^([+-]?[0-9]*%.?[0-9]+),([+-]?[0-9]*%.?[0-9]+),([+-]?[0-9]*%.?[0-9]+),([+-]?[0-9]*%.?[0-9]+)$""
183+
local x, y, z, w = val:match(pattern)
184+
-- If we found the vector pattern, process it
185+
if x and y and z and w then
186+
local components = {x, y, z, w}
187+
return table.concat(components, ','), 'vec'
188+
else
189+
return tostring(val) -- Default string conversion
190+
end
191+
end,
170192
boolean = function( x ) return tostring(x), 'bool' end,
171193
['nil'] = function( x ) return nil, 'nil' end,
172194
number = function( x ) return math.floor(x) == x and string.format('%d', x) or tostring(x), 'num' end,

0 commit comments

Comments
 (0)