feat: change LoginInfo/Response to be more concise
This commit is contained in:
parent
dd855675f9
commit
adaa74470e
2 changed files with 28 additions and 12 deletions
|
@ -1,9 +1,12 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetCoreServer;
|
||||
using Newtonsoft.Json;
|
||||
using Server.DB;
|
||||
using Server.DB.Documents;
|
||||
using Server.Packets;
|
||||
using Server.Packets.Incoming;
|
||||
using Server.Packets.Outgoing;
|
||||
|
||||
namespace Server.PacketHandlers;
|
||||
|
||||
|
@ -39,8 +42,22 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
|||
}
|
||||
}
|
||||
|
||||
var accounts = _wonderkingContext.Accounts.ToArray();
|
||||
Parallel.ForEach(accounts.AsParallel(),
|
||||
(x, i) => { _logger.LogInformation("Account {Data}", JsonConvert.SerializeObject(x)); });
|
||||
var loginResponsePacket = new LoginResponsePacket
|
||||
{
|
||||
LoginResponseReason = LoginResponseReason.OK,
|
||||
ChannelData = new[]
|
||||
{
|
||||
new ServerChannelData
|
||||
{
|
||||
ChannelId = 0,
|
||||
LoadPercentage = 200,
|
||||
ServerId = 0
|
||||
}
|
||||
},
|
||||
UnknownFlag = 1,
|
||||
IsGameMaster = true
|
||||
};
|
||||
var sess = session as AuthSession;
|
||||
sess.Send(loginResponsePacket);
|
||||
}
|
||||
}
|
|
@ -1,23 +1,22 @@
|
|||
namespace Server.Packets.Outgoing;
|
||||
|
||||
[PacketId(OperationCode.LoginResponse)]
|
||||
public class LoginResponse : IPacket
|
||||
public class LoginResponsePacket : IPacket
|
||||
{
|
||||
public LoginResponseReason LoginResponseReason;
|
||||
public byte UnknownFlag = 1;
|
||||
public bool IsGameMaster;
|
||||
public ushort ChannelAmount;
|
||||
|
||||
private ServerChannelData[] ChannelData;
|
||||
public ServerChannelData[] ChannelData;
|
||||
|
||||
public void Deserialize(byte[] data)
|
||||
{
|
||||
LoginResponseReason = (LoginResponseReason)data[0];
|
||||
UnknownFlag = data[1];
|
||||
IsGameMaster = BitConverter.ToBoolean(data, 2);
|
||||
ChannelAmount = BitConverter.ToUInt16(data, 3);
|
||||
var channelAmount = BitConverter.ToUInt16(data, 3);
|
||||
var sizeOfServerChannelData = 5;
|
||||
ChannelData = Enumerable.Repeat(0, ChannelAmount).Select(i => new ServerChannelData
|
||||
ChannelData = Enumerable.Repeat(0, channelAmount).Select(i => new ServerChannelData
|
||||
{
|
||||
ServerId = BitConverter.ToUInt16(data, 5 + 0 + i * sizeOfServerChannelData),
|
||||
ChannelId = BitConverter.ToUInt16(data, 5 + 2 + i * sizeOfServerChannelData),
|
||||
|
@ -28,16 +27,16 @@ public class LoginResponse : IPacket
|
|||
public byte[] Serialize()
|
||||
{
|
||||
var sizeOfServerChannelData = 5;
|
||||
Span<byte> dataSpan = stackalloc byte[5 + ChannelAmount * sizeOfServerChannelData];
|
||||
dataSpan.Fill(0);
|
||||
Span<byte> dataSpan = stackalloc byte[5 + ChannelData.Length * sizeOfServerChannelData];
|
||||
dataSpan.Clear();
|
||||
dataSpan[0] = (byte)LoginResponseReason;
|
||||
dataSpan[1] = UnknownFlag;
|
||||
dataSpan[2] = BitConverter.GetBytes(IsGameMaster)[0];
|
||||
var bytesOfChannelAmount = BitConverter.GetBytes(ChannelAmount);
|
||||
var bytesOfChannelAmount = BitConverter.GetBytes((ushort)ChannelData.Length);
|
||||
dataSpan[3] = bytesOfChannelAmount[0];
|
||||
dataSpan[4] = bytesOfChannelAmount[1];
|
||||
|
||||
for (var i = 0; i < ChannelAmount; i++)
|
||||
for (var i = 0; i < ChannelData.Length; i++)
|
||||
{
|
||||
var bytesOfServerId = BitConverter.GetBytes(ChannelData[i].ServerId);
|
||||
var bytesOfChannelId = BitConverter.GetBytes(ChannelData[i].ChannelId);
|
Loading…
Reference in a new issue