Implement login packets.

This commit is contained in:
Ray Koopa 2018-12-25 23:09:22 +01:00
parent dfae4ef3de
commit c5db3266d3
4 changed files with 104 additions and 22 deletions

View File

@ -40,29 +40,36 @@ namespace Syroot.Worms.OnlineWorms.Server
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
private Packet HandleConnect(ConnectQueryPacket connectPacket)
private Packet HandleConnect(ConnectQueryPacket connectPacket) => new ConnectReplyPacket
{
return new ConnectReplyPacket
Unknown = _server.Name,
Unknown2 = _server.RegionName,
Version = _server.Version
};
private Packet HandleLogin(LoginQueryPacket loginPacket)
{
LoginPlayerInfo[] playerInfos = new LoginPlayerInfo[loginPacket.Logins.Length];
for (int i = 0; i < loginPacket.Logins.Length; i++)
{
Unknown = _server.Name,
Unknown2 = _server.RegionName,
Version = _server.Version
LoginCredentials credentials = loginPacket.Logins[i];
playerInfos[i] = new LoginPlayerInfo
{
ID = credentials.ID,
Rank = 19
};
}
return new LoginReplyPacket
{
Unknown1 = 1,
LoginResult = LoginResult.Success,
PlayerInfos = playerInfos
};
}
//private Packet HandleLogin(LoginQueryPacket loginPacket)
//{
// return new LoginReplyPacket
// {
// LoginResult = LoginResult.Success
// };
//}
#if DEBUG
private Packet HandleRaw(RawQueryPacket rawPacket)
{
return null;
}
private Packet HandleRaw(RawQueryPacket rawPacket) => null;
#endif
}
}

View File

@ -90,7 +90,12 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
internal string ReadString()
{
return _baseStream.ReadString(StringCoding.Int16CharCount);
return _baseStream.ReadString(StringCoding.Int16CharCount, _win949Encoding);
}
internal byte[] ReadToEnd()
{
return _baseStream.ReadBytes((int)(Length - Position));
}
internal void WriteString(string value)

View File

@ -0,0 +1,46 @@
using System;
using System.Net;
using Syroot.BinaryData;
namespace Syroot.Worms.OnlineWorms.Server.Net
{
/// <summary>
/// Represents the client request for a <see cref="LoginReplyPacket"/>.
/// </summary>
[Packet(0x8000)]
internal class LoginQueryPacket : Packet
{
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
internal ushort Unknown1 { get; set; }
internal LoginCredentials[] Logins { get; set; }
internal IPAddress ClientIP { get; set; }
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
internal override void Deserialize(PacketStream stream)
{
Unknown1 = stream.ReadUInt16();
Logins = new LoginCredentials[stream.ReadUInt16()];
for (int i = 0; i < Logins.Length; i++)
{
Logins[i] = new LoginCredentials
{
ID = stream.ReadString(),
Password = stream.ReadString()
};
}
ClientIP = IPAddress.Parse(stream.ReadString());
}
internal override void Serialize(PacketStream stream) => throw new NotImplementedException();
}
internal class LoginCredentials
{
internal string ID { get; set; }
internal string Password { get; set; }
}
}

View File

@ -11,7 +11,11 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
{
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
public LoginResult LoginResult { get; set; }
internal LoginResult LoginResult { get; set; }
internal ushort Unknown1 { get; set; }
internal LoginPlayerInfo[] PlayerInfos { get; set; }
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
@ -19,14 +23,28 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
internal override void Serialize(PacketStream stream)
{
stream.WriteBoolean(LoginResult == LoginResult.Success);
stream.WriteEnum(LoginResult);
bool loginSuccessful = LoginResult == LoginResult.Success;
stream.WriteBoolean(loginSuccessful);
if (loginSuccessful)
{
stream.WriteUInt16(Unknown1);
stream.WriteUInt16((ushort)PlayerInfos.Length);
foreach (LoginPlayerInfo playerInfo in PlayerInfos)
{
stream.WriteString(playerInfo.ID);
stream.WriteUInt16(playerInfo.Rank);
}
}
else
{
stream.WriteEnum(LoginResult);
}
}
}
internal enum LoginResult : byte
{
Success,
Success = 0,
IDAlreadyInUse = 3,
UnqualifiedID = 4,
IncorrectID = 6,
@ -37,4 +55,10 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
PublicAccessBanned = 12,
TemporarilyBannedID = 13
}
internal class LoginPlayerInfo
{
internal string ID { get; set; }
internal ushort Rank { get; set; }
}
}