[C#] Packet receive problem

06/09/2019 17:38 Roxeez#1
Hi, today i wanted to try making some stuff using the C# nostale crypto adaptation i've shared, crypto seems to work but i'm stuck with sockets.

I've this code
Code:
if (packet.Header == "OK")
{
    SendPacket("game_start");
    _pulseTimer.Start();

    Task.Run(() =>
    {
        while (_client.Connected)
        {
            packets = ReceivePackets();

            foreach (string value in packets)
            {
                PacketReceived?.Invoke(this, new Packet(value));
            }
        }
    });
    return true;
}
It's for receiving all packets and fire an event
Code:
private void OnPacketReceived(object sender, Packet packet)
{
    Console.WriteLine(packet.Header);
}
But the problem is sometime (most of the time) i'm only receiving these packets and the socket don't read anymore after
Code:
tit
info
fd
fd
c_info
c_info_reset
equip
lev
stat
ski
at
c_map
sc
cond
pairy
rsfi
rage
rank_cool
clinit
flinit
kdlinit
That's my receive packets method
Code:
private List<string> ReceivePackets()
{
    var bytes = new byte[_client.ReceiveBufferSize];
    int size = _stream.Read(bytes, 0, bytes.Length);
    return Decrypt(bytes, size);
}
#Decrypt is just a method who use the correct Decrypt method according if we are on login server or world server.

I believe it's because the #Read method is blocked waiting for something from the server but idk what's the problem

Thanks in advance for your help, i'm beginner to this kind of stuff (socket etc..)

Edit : I'm posting this here because i'm not sure if it's a C# general question or just something i'm missing about nostale server (like sending a packet or something like this)
06/09/2019 19:23 Nortank#2
You are supposed to

sendPacket("lbs 0");

at the same time than "game_start"

and "npinfo 0" when you receive "sc_p_stc 0 0"

But I don't know if this will fix your problem


Edit : try to print out the whole packet, not only the "header", maybe some packets are sent together, or idk what ?

Edit 2 :
You also need to send "c_close 1" after receiving the first "c_info" packet.
06/09/2019 20:53 Roxeez#3
Was an error from my WorldEncryption#Decrypt a IndexOutOfBoundException was throw but because the Decrypt method was called in a lambda task, no error printed in the console :/

Any way problem fixed !