some summary texts
This commit is contained in:
parent
9c1f691fa3
commit
dc3eace03b
@ -20,6 +20,10 @@ public static class Logger
|
|||||||
var method = frame?.GetMethod();
|
var method = frame?.GetMethod();
|
||||||
return method?.DeclaringType?.Name ?? "Server";
|
return method?.DeclaringType?.Name ?? "Server";
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Print a text in the console
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text"></param>
|
||||||
public static void Print(string text)
|
public static void Print(string text)
|
||||||
{
|
{
|
||||||
string className = GetCallingClassName();
|
string className = GetCallingClassName();
|
||||||
@ -27,6 +31,10 @@ public static class Logger
|
|||||||
string prefix = "<" + "INFO".Pastel("03fcce") + $":{className.Pastel("999")}>";
|
string prefix = "<" + "INFO".Pastel("03fcce") + $":{className.Pastel("999")}>";
|
||||||
Console.WriteLine($"{prefix} " + text);
|
Console.WriteLine($"{prefix} " + text);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Print a text in the console as Error
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text"></param>
|
||||||
public static void PrintError(string text)
|
public static void PrintError(string text)
|
||||||
{
|
{
|
||||||
string className = GetCallingClassName();
|
string className = GetCallingClassName();
|
||||||
@ -34,6 +42,10 @@ public static class Logger
|
|||||||
string prefix = "<" + "ERROR".Pastel("eb4034") + $":{className.Pastel("999")}>";
|
string prefix = "<" + "ERROR".Pastel("eb4034") + $":{className.Pastel("999")}>";
|
||||||
Console.WriteLine($"{prefix} " + text.Pastel("917e7e"));
|
Console.WriteLine($"{prefix} " + text.Pastel("917e7e"));
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Print a text in the console as a Warn
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text"></param>
|
||||||
public static void PrintWarn(string text)
|
public static void PrintWarn(string text)
|
||||||
{
|
{
|
||||||
string className = GetCallingClassName();
|
string className = GetCallingClassName();
|
||||||
@ -54,7 +66,10 @@ public static class Logger
|
|||||||
Logger.hideLogs = hideLogs;
|
Logger.hideLogs = hideLogs;
|
||||||
logWriter = new StreamWriter("latest.log", false);
|
logWriter = new StreamWriter("latest.log", false);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Log a message
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message"></param>
|
||||||
public static void Log(string message)
|
public static void Log(string message)
|
||||||
{
|
{
|
||||||
if (!hideLogs)
|
if (!hideLogs)
|
||||||
|
@ -61,6 +61,11 @@ namespace Campofinale.Network
|
|||||||
byte networkValue = buf[index];
|
byte networkValue = buf[index];
|
||||||
return networkValue;
|
return networkValue;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Parse the body using a specific IMessage proto class
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TBody"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
public TBody DecodeBody<TBody>() where TBody : IMessage<TBody>, new()
|
public TBody DecodeBody<TBody>() where TBody : IMessage<TBody>, new()
|
||||||
{
|
{
|
||||||
return new MessageParser<TBody>(() => new()).ParseFrom(finishedBody);
|
return new MessageParser<TBody>(() => new()).ParseFrom(finishedBody);
|
||||||
@ -76,35 +81,10 @@ namespace Campofinale.Network
|
|||||||
|
|
||||||
Buffer.BlockCopy(source, 0, destination, offset, source.Length);
|
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)
|
public static byte[] EncryptWithPublicKey(byte[] data, string publicKey)
|
||||||
{
|
{
|
||||||
// Crea un oggetto RSA
|
|
||||||
using (RSA rsa = RSA.Create())
|
using (RSA rsa = RSA.Create())
|
||||||
{
|
{
|
||||||
|
|
||||||
publicKey = publicKey.Replace("-----BEGIN PUBLIC KEY-----", "");
|
publicKey = publicKey.Replace("-----BEGIN PUBLIC KEY-----", "");
|
||||||
publicKey = publicKey.Replace("\r", "");
|
publicKey = publicKey.Replace("\r", "");
|
||||||
publicKey = publicKey.Replace("\n", "");
|
publicKey = publicKey.Replace("\n", "");
|
||||||
@ -112,24 +92,44 @@ namespace Campofinale.Network
|
|||||||
publicKey = publicKey.Trim();
|
publicKey = publicKey.Trim();
|
||||||
Logger.Print(publicKey);
|
Logger.Print(publicKey);
|
||||||
byte[] publicKey_ = Convert.FromBase64String(publicKey);
|
byte[] publicKey_ = Convert.FromBase64String(publicKey);
|
||||||
// Importa la chiave pubblica
|
|
||||||
rsa.ImportSubjectPublicKeyInfo(publicKey_, out _);
|
rsa.ImportSubjectPublicKeyInfo(publicKey_, out _);
|
||||||
|
|
||||||
// Crittografa i dati
|
|
||||||
return rsa.Encrypt(data, RSAEncryptionPadding.OaepSHA256);
|
return rsa.Encrypt(data, RSAEncryptionPadding.OaepSHA256);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Set the data of the packet with the Message Id and the body
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgId"></param>
|
||||||
|
/// <param name="body">The proto message</param>
|
||||||
|
/// <returns>The current Packet</returns>
|
||||||
public Packet SetData(ScMsgId msgId, IMessage body)
|
public Packet SetData(ScMsgId msgId, IMessage body)
|
||||||
{
|
{
|
||||||
set_body = body;
|
set_body = body;
|
||||||
cmdId = (int)msgId;
|
cmdId = (int)msgId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Encode the packet using the Packet class
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="packet">The packet</param>
|
||||||
|
/// <param name="seq">the sequence id</param>
|
||||||
|
/// <param name="totalPackCount">the pack count</param>
|
||||||
|
/// <param name="currentPackIndex"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static byte[] EncodePacket(Packet packet,ulong seq = 0, uint totalPackCount = 1, uint currentPackIndex = 0)
|
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);
|
return EncodePacket(packet.cmdId,packet.set_body,seq, totalPackCount, currentPackIndex);
|
||||||
}
|
}
|
||||||
public static ulong seqNext = 1;
|
public static ulong seqNext = 1;
|
||||||
|
/// <summary>
|
||||||
|
/// Encode the packet using the msgId and the body
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgId"></param>
|
||||||
|
/// <param name="body"></param>
|
||||||
|
/// <param name="seqNext_"></param>
|
||||||
|
/// <param name="totalPackCount"></param>
|
||||||
|
/// <param name="currentPackIndex"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static byte[] EncodePacket(int msgId, IMessage body, ulong seqNext_ = 0, uint totalPackCount=1,uint currentPackIndex=0)
|
public static byte[] EncodePacket(int msgId, IMessage body, ulong seqNext_ = 0, uint totalPackCount=1,uint currentPackIndex=0)
|
||||||
{
|
{
|
||||||
if (seqNext_ == 0)
|
if (seqNext_ == 0)
|
||||||
@ -149,6 +149,15 @@ namespace Campofinale.Network
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Encode the packet with msgId and body as byte array
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgId"></param>
|
||||||
|
/// <param name="body"></param>
|
||||||
|
/// <param name="seqNext_"></param>
|
||||||
|
/// <param name="totalPackCount"></param>
|
||||||
|
/// <param name="currentPackIndex"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static byte[] EncodePacket(int msgId, byte[] body, ulong seqNext_ = 0, uint totalPackCount = 1, uint currentPackIndex = 0)
|
public static byte[] EncodePacket(int msgId, byte[] body, ulong seqNext_ = 0, uint totalPackCount = 1, uint currentPackIndex = 0)
|
||||||
{
|
{
|
||||||
if (seqNext_ == 0)
|
if (seqNext_ == 0)
|
||||||
@ -172,6 +181,12 @@ namespace Campofinale.Network
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Read the byteArray as a valid packet
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="byteArray"></param>
|
||||||
|
/// <returns>The decoded packet</returns>
|
||||||
public static Packet Read(Player client,byte[] byteArray)
|
public static Packet Read(Player client,byte[] byteArray)
|
||||||
{
|
{
|
||||||
byte headLength = GetByte(byteArray, 0);
|
byte headLength = GetByte(byteArray, 0);
|
||||||
|
@ -74,7 +74,7 @@ namespace Campofinale.Packets.Sc
|
|||||||
ScriptId = l.scriptId,
|
ScriptId = l.scriptId,
|
||||||
IsDone = false,
|
IsDone = false,
|
||||||
State = 1,
|
State = 1,
|
||||||
|
|
||||||
};
|
};
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (var item in l.properties)
|
foreach (var item in l.properties)
|
||||||
|
@ -186,12 +186,20 @@ namespace Campofinale
|
|||||||
{
|
{
|
||||||
chars = DatabaseManager.db.LoadCharacters(roleId);
|
chars = DatabaseManager.db.LoadCharacters(roleId);
|
||||||
}
|
}
|
||||||
//Added in 1.0.7
|
/// <summary>
|
||||||
|
/// Get the character using the guid *Added in 1.0.7*
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="guid"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public Character GetCharacter(ulong guid)
|
public Character GetCharacter(ulong guid)
|
||||||
{
|
{
|
||||||
return chars.Find(c => c.guid == guid);
|
return chars.Find(c => c.guid == guid);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Get the character using the template id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="templateId"></param>
|
||||||
|
/// <returns>Character</returns>
|
||||||
public Character GetCharacter(string templateId)
|
public Character GetCharacter(string templateId)
|
||||||
{
|
{
|
||||||
return chars.Find(c => c.id==templateId);
|
return chars.Find(c => c.id==templateId);
|
||||||
|
Loading…
Reference in New Issue
Block a user