FakeClientTester

This commit is contained in:
AlessandroCH
2025-07-09 22:38:12 +02:00
parent 623f7a111c
commit f47ec48073
4 changed files with 6775 additions and 0 deletions

View File

@@ -19,6 +19,10 @@
<ItemGroup>
<Protobuf Include="*.proto" ProtoRoot="." GrpcServices="None" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Campofinale.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="AbilityActionCreateGadget.proto" />
<None Remove="AbilityActionSummon.proto" />
@@ -897,5 +901,8 @@
<None Remove="WorktopOptionNotify.proto" />
<None Remove="WorldPlayerReviveReq.proto" />
</ItemGroup>
<ItemGroup>
<None Include="Campofinale.cs" />
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

@@ -165,6 +165,7 @@ namespace Campofinale.Network
PutUInt16(data, (ushort)body.Length, 1);
PutByteArray(data, head.ToByteArray(), 3);
PutByteArray(data, body, 3 + head.ToByteArray().Length);
if(Server.config!=null)
if (Server.config.logOptions.packets && !Server.scMessageToHide.Contains((ScMsgId)msgId))
Logger.Print($"Sending Packet: {((ScMsgId)msgId).ToString().Pastel(Color.LightBlue)} Id: {msgId} with {data.Length} Bytes");
@@ -181,6 +182,28 @@ namespace Campofinale.Network
byte headLength = GetByte(byteArray, 0);
ushort bodyLength = GetUInt16(byteArray, 1);
byte[] csHeadBytes = new byte[headLength];
byte[] BodyBytes = new byte[bodyLength];
Array.Copy(byteArray, 3, csHeadBytes, 0, headLength);
Array.Copy(byteArray, 3+ headLength, BodyBytes, 0, bodyLength);
CSHead csHead_ = CSHead.Parser.ParseFrom(csHeadBytes);
/*if (Server.config.logOptions.packets && !Server.csMessageToHide.Contains((CsMsgId)csHead_.Msgid))
{
Logger.Print(csHead_.ToString());
}*/
seqNext = csHead_.UpSeqid;
return new Packet() { csHead = csHead_, finishedBody = BodyBytes,cmdId=csHead_.Msgid };
}
/// <summary>
/// Read the byteArray as a valid packet
/// </summary>
/// <param name="byteArray"></param>
/// <returns>The decoded packet</returns>
public static Packet Read(byte[] byteArray)
{
byte headLength = GetByte(byteArray, 0);
ushort bodyLength = GetUInt16(byteArray, 1);
byte[] csHeadBytes = new byte[headLength];
byte[] BodyBytes = new byte[bodyLength];
Array.Copy(byteArray, 3, csHeadBytes, 0, headLength);

View File

@@ -1,13 +1,80 @@
using Campofinale;
using Newtonsoft.Json;
using System.Net.Sockets;
using System.Net;
using Campofinale.Network;
using Campofinale.Protocol;
using Google.Protobuf;
using Pastel;
using System.Drawing;
class Program
{
static void Main(string[] args)
{
StartServer(args);
//FakeClientTester();
}
public static byte[] ConcatenateByteArrays(byte[] array1, byte[] array2)
{
return array1.Concat(array2).ToArray();
}
private static void FakeClientTester()
{
string serverIp = "beyond-ric.gryphline.com";
int serverPort = 30000;
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress[] addresses = Dns.GetHostAddresses(serverIp);
IPAddress ipAddress = addresses[0];
socket.Connect(new IPEndPoint(ipAddress, serverPort));
socket.Send(Packet.EncodePacket((int)CsMsgId.CsLogin,new CsLogin() { ClientVersion="0.5.5",Uid= "", Token= "", Env=EnvType.Prod,PlatformId=ClientPlatformType.Windows,Area=AreaType.Oversea,ClientResVersion="", LoginToken= "" }.ToByteArray()));
while (true)
{
byte[] buffer = new byte[3];
int length = socket.Receive(buffer);
if (length == 3)
{
Packet packet = null;
byte headLength = Packet.GetByte(buffer, 0);
ushort bodyLength = Packet.GetUInt16(buffer, 1);
byte[] moreData = new byte[bodyLength + headLength];
while (socket.Available < moreData.Length)
{
}
int mLength = socket.Receive(moreData);
if (mLength == moreData.Length)
{
buffer = ConcatenateByteArrays(buffer, moreData);
packet = Packet.Read(buffer);
switch ((ScMsgId)packet.cmdId)
{
case ScMsgId.ScLogin:
ScLogin p1 = ScLogin.Parser.ParseFrom(packet.finishedBody);
Console.WriteLine(JsonConvert.SerializeObject(p1));
break;
case ScMsgId.ScNtfErrorCode:
ScNtfErrorCode p2 = ScNtfErrorCode.Parser.ParseFrom(packet.finishedBody);
Console.WriteLine(JsonConvert.SerializeObject(p2));
break;
default:
string base64 = Convert.ToBase64String(packet.finishedBody);
Console.WriteLine($"{(ScMsgId)packet.cmdId}: {base64}");
break;
}
}
}
}
}
private static void StartServer(string[] args)
{
Console.Title = "Initializing...";