Hello everyone, I'm developing a custom Shaiya client in Unity 6 and I'm currently having problems with the login phase. I'm currently working with the provided files:
What I've accomplished so far isn't much:
I've successfully established a TCP connection with the login server.
I've handled the initial handshake exchange.
I've constructed the login packet with a header [Size 2 bytes][Opcode 2 bytes] (Little Endian).
The problem:
When I send the login packet (Opcode 0x02, 0xA1), the server immediately responds with a "Connection Reset by Server" (SocketException).
Technical details:
I'm using Aes.Create() with CipherMode.ECB and PaddingMode.None.
My packet structure: [Size][0x02][0xA1][Encrypted data (48 bytes)].
Iniciando conexión...
UnityEngine.Debug:Log (object)
ShaiyaNetworkManager/<Start>d__4:MoveNext () (at Assets/Scripts/Network/ShaiyaNetworkManager.cs:21)
System.Runtime.CompilerServices.AsyncVoidMethodBui lder:Start<ShaiyaNetworkManager/<Start>d__4> (ShaiyaNetworkManager/<Start>d__4&)
ShaiyaNetworkManager:Start ()
Intentando conectar a 127.0.0.1:30800...
UnityEngine.Debug:Log (object)
ShaiyaNetworkManager/<ConnectAndLogin>d__5:MoveNext () (at Assets/Scripts/Network/ShaiyaNetworkManager.cs:30)
System.Runtime.CompilerServices.AsyncTaskMethodBui lder:Start<ShaiyaNetworkManager/<ConnectAndLogin>d__5> (ShaiyaNetworkManager/<ConnectAndLogin>d__5&)
ShaiyaNetworkManager:ConnectAndLogin (string,string)
ShaiyaNetworkManager/<Start>d__4:MoveNext () (at Assets/Scripts/Network/ShaiyaNetworkManager.cs:22)
System.Runtime.CompilerServices.AsyncVoidMethodBui lder:Start<ShaiyaNetworkManager/<Start>d__4> (ShaiyaNetworkManager/<Start>d__4&)
ShaiyaNetworkManager:Start ()
¡Conectado al servidor!
UnityEngine.Debug:Log (object)
ShaiyaNetworkManager/<ConnectAndLogin>d__5:MoveNext () (at Assets/Scripts/Network/ShaiyaNetworkManager.cs:34)
UnityEngine.UnitySynchronizationContext:ExecuteTas ks ()
Handshake recibido: 199 bytes.
UnityEngine.Debug:Log (object)
ShaiyaNetworkManager/<ConnectAndLogin>d__5:MoveNext () (at Assets/Scripts/Network/ShaiyaNetworkManager.cs:41)
UnityEngine.UnitySynchronizationContext:ExecuteTas ks ()
HEXDUMP: 34 00 02 A1 5C D9 8A 43 54 7D D3 88 CA 15 E4 BA 63 C7 91 38 5C D9 8A 43 54 7D D3 88 CA 15 E4 BA 63 C7 91 38 66 E9 4B D4 EF 8A 2C 3B 88 4C FA 59 CA 34 2B 2E
UnityEngine.Debug:Log (object)
ShaiyaNetworkManager:PrintHex (byte[]) (at Assets/Scripts/Network/ShaiyaNetworkManager.cs:63)
ShaiyaNetworkManager/<ConnectAndLogin>d__5:MoveNext () (at Assets/Scripts/Network/ShaiyaNetworkManager.cs:49)
UnityEngine.UnitySynchronizationContext:ExecuteTas ks ()
Login enviado. Esperando respuesta...
UnityEngine.Debug:Log (object)
ShaiyaNetworkManager/<ConnectAndLogin>d__5:MoveNext () (at Assets/Scripts/Network/ShaiyaNetworkManager.cs:52)
UnityEngine.UnitySynchronizationContext:ExecuteTas ks ()
I suspect the server is rejecting the login due to the encryption key initialization or the specific padding required for the login structure.
My questions:
Are there any additional steps or packets after the initial handshake and before the login packet that I'm missing?
How does the current server implementation handle deriving the session key from the initial handshake? Any suggestions regarding the specific AES/RSA padding expected for the login data?
I don't know much about this topic, so I would appreciate any guidance on the protocol flow or relevant documentation for current server versions. Thank you!
[SOLVED] Connection Reset Issue Resolved - Shaiya Login Protocol
Hi everyone,
I wanted to provide an update regarding the "Connection Reset" issue I was facing with the login packet. After digging deep into the packet structure and the server's expected format, I’ve successfully authenticated with the login server.
For those encountering similar issues, here is the summary of what was causing the disconnects:
Encryption Sync: The primary issue was not the AES mode itself, but ensuring that the SendIV and RecvIV are derived correctly and independently after the RSA handshake. The server expects the counter to persist and increment correctly for every subsequent packet.
Data Encoding (Crucial): I was mistakenly using Unicode/UTF-8 for the credentials. The Shaiya login server expects ASCII (matching the varchar type in the Users_Master SQL table). Using the wrong encoding resulted in the server rejecting the packet as malformed, leading to an immediate socket reset.
BigInteger Handling: When performing the RSA ModPow for the handshake response, ensure your BigInteger implementation handles the exponent/modulus correctly as positive integers (you may need to prepend a 0x00 byte if the most significant bit is set, otherwise, you'll trigger exceptions in C#).
Everything is now working, and I am receiving the correct login response and UserID.