diff --git a/Campofinale/Logger.cs b/Campofinale/Logger.cs index e634add..8669522 100644 --- a/Campofinale/Logger.cs +++ b/Campofinale/Logger.cs @@ -20,6 +20,10 @@ public static class Logger var method = frame?.GetMethod(); return method?.DeclaringType?.Name ?? "Server"; } + /// + /// Print a text in the console + /// + /// public static void Print(string text) { string className = GetCallingClassName(); @@ -27,6 +31,10 @@ public static class Logger string prefix = "<" + "INFO".Pastel("03fcce") + $":{className.Pastel("999")}>"; Console.WriteLine($"{prefix} " + text); } + /// + /// Print a text in the console as Error + /// + /// public static void PrintError(string text) { string className = GetCallingClassName(); @@ -34,6 +42,10 @@ public static class Logger string prefix = "<" + "ERROR".Pastel("eb4034") + $":{className.Pastel("999")}>"; Console.WriteLine($"{prefix} " + text.Pastel("917e7e")); } + /// + /// Print a text in the console as a Warn + /// + /// public static void PrintWarn(string text) { string className = GetCallingClassName(); @@ -54,7 +66,10 @@ public static class Logger Logger.hideLogs = hideLogs; logWriter = new StreamWriter("latest.log", false); } - + /// + /// Log a message + /// + /// public static void Log(string message) { if (!hideLogs) diff --git a/Campofinale/Network/Packet.cs b/Campofinale/Network/Packet.cs index d3a990e..b2c3208 100644 --- a/Campofinale/Network/Packet.cs +++ b/Campofinale/Network/Packet.cs @@ -61,6 +61,11 @@ namespace Campofinale.Network byte networkValue = buf[index]; return networkValue; } + /// + /// Parse the body using a specific IMessage proto class + /// + /// + /// public TBody DecodeBody() where TBody : IMessage, new() { return new MessageParser(() => new()).ParseFrom(finishedBody); @@ -76,35 +81,10 @@ namespace Campofinale.Network Buffer.BlockCopy(source, 0, destination, offset, source.Length); } - public static byte[] ToByteArray(IntPtr ptr, int length) - { - if (ptr == IntPtr.Zero) - { - throw new ArgumentException("Pointer cannot be null", nameof(ptr)); - } - - byte[] byteArray = new byte[length]; - Marshal.Copy(ptr, byteArray, 0, length); - return byteArray; - } - public static IntPtr ByteArrayToIntPtr(byte[] data) - { - if (data == null) throw new ArgumentNullException(nameof(data)); - - // Allocate unmanaged memory - IntPtr ptr = Marshal.AllocHGlobal(data.Length); - - // Copy the byte array to the unmanaged memory - Marshal.Copy(data, 0, ptr, data.Length); - - return ptr; - } public static byte[] EncryptWithPublicKey(byte[] data, string publicKey) { - // Crea un oggetto RSA using (RSA rsa = RSA.Create()) { - publicKey = publicKey.Replace("-----BEGIN PUBLIC KEY-----", ""); publicKey = publicKey.Replace("\r", ""); publicKey = publicKey.Replace("\n", ""); @@ -112,24 +92,44 @@ namespace Campofinale.Network publicKey = publicKey.Trim(); Logger.Print(publicKey); byte[] publicKey_ = Convert.FromBase64String(publicKey); - // Importa la chiave pubblica rsa.ImportSubjectPublicKeyInfo(publicKey_, out _); - - // Crittografa i dati return rsa.Encrypt(data, RSAEncryptionPadding.OaepSHA256); } } + /// + /// Set the data of the packet with the Message Id and the body + /// + /// + /// The proto message + /// The current Packet public Packet SetData(ScMsgId msgId, IMessage body) { set_body = body; cmdId = (int)msgId; return this; } + /// + /// Encode the packet using the Packet class + /// + /// The packet + /// the sequence id + /// the pack count + /// + /// public static byte[] EncodePacket(Packet packet,ulong seq = 0, uint totalPackCount = 1, uint currentPackIndex = 0) { return EncodePacket(packet.cmdId,packet.set_body,seq, totalPackCount, currentPackIndex); } public static ulong seqNext = 1; + /// + /// Encode the packet using the msgId and the body + /// + /// + /// + /// + /// + /// + /// public static byte[] EncodePacket(int msgId, IMessage body, ulong seqNext_ = 0, uint totalPackCount=1,uint currentPackIndex=0) { if (seqNext_ == 0) @@ -149,6 +149,15 @@ namespace Campofinale.Network return data; } + /// + /// Encode the packet with msgId and body as byte array + /// + /// + /// + /// + /// + /// + /// public static byte[] EncodePacket(int msgId, byte[] body, ulong seqNext_ = 0, uint totalPackCount = 1, uint currentPackIndex = 0) { if (seqNext_ == 0) @@ -172,6 +181,12 @@ namespace Campofinale.Network return data; } + /// + /// Read the byteArray as a valid packet + /// + /// + /// + /// The decoded packet public static Packet Read(Player client,byte[] byteArray) { byte headLength = GetByte(byteArray, 0); diff --git a/Campofinale/Packets/Sc/PacketScSelfSceneInfo.cs b/Campofinale/Packets/Sc/PacketScSelfSceneInfo.cs index c00f6ff..9e4fff3 100644 --- a/Campofinale/Packets/Sc/PacketScSelfSceneInfo.cs +++ b/Campofinale/Packets/Sc/PacketScSelfSceneInfo.cs @@ -74,7 +74,7 @@ namespace Campofinale.Packets.Sc ScriptId = l.scriptId, IsDone = false, State = 1, - + }; int i = 0; foreach (var item in l.properties) diff --git a/Campofinale/Player.cs b/Campofinale/Player.cs index 382272d..afc1eef 100644 --- a/Campofinale/Player.cs +++ b/Campofinale/Player.cs @@ -186,12 +186,20 @@ namespace Campofinale { chars = DatabaseManager.db.LoadCharacters(roleId); } - //Added in 1.0.7 + /// + /// Get the character using the guid *Added in 1.0.7* + /// + /// + /// public Character GetCharacter(ulong guid) { return chars.Find(c => c.guid == guid); } - + /// + /// Get the character using the template id + /// + /// + /// Character public Character GetCharacter(string templateId) { return chars.Find(c => c.id==templateId);