Skip to content

Commit

Permalink
Swapped ClientID to PlayerID
Browse files Browse the repository at this point in the history
Renamed AccountCreateID to SessionID
Use SessionID for Account, Character, and Welcome packets instead of PlayerID
  • Loading branch information
sorokya committed Mar 27, 2022
1 parent 4eb4cd0 commit 16b6953
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 31 deletions.
4 changes: 2 additions & 2 deletions EOLib/Domain/Account/AccountActions.cs
Expand Up @@ -71,7 +71,7 @@ public async Task<AccountReply> CheckAccountNameWithServer(string accountName)
var reply = (AccountReply)response.ReadShort();
if (reply >= AccountReply.OK_CodeRange)
{
_playerInfoRepository.AccountCreateID = (ushort)reply;
_playerInfoRepository.SessionID = (short)reply;

// Based on patch: https://github.com/eoserv/eoserv/commit/80dde6d4e7f440a93503aeec79f4a2f5931dc13d
// Account may change sequence start depending on the eoserv build being used
Expand All @@ -93,7 +93,7 @@ public async Task<AccountReply> CheckAccountNameWithServer(string accountName)
public async Task<AccountReply> CreateAccount(ICreateAccountParameters parameters)
{
var createAccountPacket = new PacketBuilder(PacketFamily.Account, PacketAction.Create)
.AddShort((short)_playerInfoRepository.AccountCreateID)
.AddShort((short)_playerInfoRepository.SessionID)
.AddByte(255)
.AddBreakString(parameters.AccountName)
.AddBreakString(parameters.Password)
Expand Down
4 changes: 2 additions & 2 deletions EOLib/Domain/Login/ILoginRequestGrantedData.cs
Expand Up @@ -6,7 +6,7 @@ namespace EOLib.Domain.Login
{
public interface ILoginRequestGrantedData : ITranslatedData
{
short PlayerID { get; }
short SessionID { get; }
int CharacterID { get; }

short MapID { get; }
Expand Down Expand Up @@ -38,7 +38,7 @@ public interface ILoginRequestGrantedData : ITranslatedData
short JailMap { get; }
bool FirstTimePlayer { get; }

ILoginRequestGrantedData WithPlayerID(short playerID);
ILoginRequestGrantedData WithSessionID(short playerID);
ILoginRequestGrantedData WithCharacterID(int characterID);
ILoginRequestGrantedData WithMapID(short mapID);
ILoginRequestGrantedData WithMapRID(IEnumerable<byte> mapRID);
Expand Down
4 changes: 2 additions & 2 deletions EOLib/Domain/Login/LoginActions.cs
Expand Up @@ -113,7 +113,7 @@ public async Task RequestCharacterLogin(ICharacter character)
.WithAdminLevel(data.AdminLevel)
.WithStats(data.CharacterStats);

_playerInfoRepository.PlayerID = data.PlayerID;
_playerInfoRepository.SessionID = data.SessionID;
_playerInfoRepository.IsFirstTimePlayer = data.FirstTimePlayer;
_currentMapStateRepository.CurrentMapID = data.MapID;

Expand All @@ -133,7 +133,7 @@ public async Task RequestCharacterLogin(ICharacter character)
public async Task<CharacterLoginReply> CompleteCharacterLogin()
{
var packet = new PacketBuilder(PacketFamily.Welcome, PacketAction.Message)
.AddThree((ushort)_playerInfoRepository.PlayerID)
.AddThree(_playerInfoRepository.SessionID)
.AddInt(_characterRepository.MainCharacter.ID)
.Build();

Expand Down
8 changes: 4 additions & 4 deletions EOLib/Domain/Login/LoginRequestGrantedData.cs
Expand Up @@ -7,7 +7,7 @@ namespace EOLib.Domain.Login
{
public class LoginRequestGrantedData : ILoginRequestGrantedData
{
public short PlayerID { get; private set; }
public short SessionID { get; private set; }
public int CharacterID { get; private set; }

public short MapID { get; private set; }
Expand Down Expand Up @@ -40,10 +40,10 @@ public class LoginRequestGrantedData : ILoginRequestGrantedData
public short JailMap { get; private set; }
public bool FirstTimePlayer { get; private set; }

public ILoginRequestGrantedData WithPlayerID(short playerID)
public ILoginRequestGrantedData WithSessionID(short sessionID)
{
var copy = MakeCopy(this);
copy.PlayerID = playerID;
copy.SessionID = sessionID;
return copy;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ private static LoginRequestGrantedData MakeCopy(LoginRequestGrantedData source)
{
return new LoginRequestGrantedData
{
PlayerID = source.PlayerID,
SessionID = source.SessionID,
CharacterID = source.CharacterID,

MapID = source.MapID,
Expand Down
8 changes: 4 additions & 4 deletions EOLib/Domain/Login/PlayerInfoRepository.cs
Expand Up @@ -10,7 +10,7 @@ public interface IPlayerInfoRepository

short PlayerID { get; set; }

ushort AccountCreateID { get; set; }
short SessionID { get; set; }

bool IsFirstTimePlayer { get; set; }

Expand All @@ -25,7 +25,7 @@ public interface IPlayerInfoProvider

short PlayerID { get; }

ushort AccountCreateID { get; set; }
short SessionID { get; set; }

bool IsFirstTimePlayer { get; }

Expand All @@ -41,7 +41,7 @@ public sealed class PlayerInfoRepository : IPlayerInfoRepository, IPlayerInfoPro

public short PlayerID { get; set; }

public ushort AccountCreateID { get; set; }
public short SessionID { get; set; }

public bool IsFirstTimePlayer { get; set; }

Expand All @@ -52,7 +52,7 @@ public void ResetState()
LoggedInAccountName = "";
PlayerPassword = "";
PlayerID = 0;
AccountCreateID = 0;
SessionID = 0;
IsFirstTimePlayer = false;
PlayerIsInGame = false;
}
Expand Down
2 changes: 1 addition & 1 deletion EOLib/Domain/Protocol/IInitializationData.cs
Expand Up @@ -16,7 +16,7 @@ public enum InitializationDataKey
SequenceByte2,
SendMultiple,
ReceiveMultiple,
ClientID,
PlayerID,
HashResponse,
//response: Out of Date
RequiredVersionNumber,
Expand Down
17 changes: 9 additions & 8 deletions EOLib/Domain/Protocol/InitReply.cs
Expand Up @@ -5,14 +5,15 @@ public enum InitReply
ClientOutOfDate = 1,
Success = 2,
BannedFromServer = 3,
MapFile = 4,
ItemFile = 5,
NpcFile = 6,
SpellFile = 7,
AllPlayersList = 8,
MapMutation = 9,
FriendPlayersList = 10,
ClassFile = 11,
WarpMap = 4,
MapFile = 5,
ItemFile = 6,
NpcFile = 7,
SpellFile = 8,
AllPlayersList = 9,
MapMutation = 10,
FriendPlayersList = 11,
ClassFile = 12,
ErrorState = 0
}
}
8 changes: 4 additions & 4 deletions EOLib/Domain/Protocol/InitializationSuccessData.cs
Expand Up @@ -9,21 +9,21 @@ public class InitializationSuccessData : IInitializationData
public int this[InitializationDataKey key] => GetValueHelper(key);

private readonly byte _seq1, _seq2, _sendMulti, _recvMulti;
private readonly short _clientID;
private readonly short _playerID;
private readonly int _hashResponse;

public InitializationSuccessData(byte sequence1,
byte sequence2,
byte receiveMultiple,
byte sendMultiple,
short clientID,
short playerID,
int hashResponse)
{
_seq1 = sequence1;
_seq2 = sequence2;
_recvMulti = receiveMultiple;
_sendMulti = sendMultiple;
_clientID = clientID;
_playerID = playerID;
_hashResponse = hashResponse;
}

Expand All @@ -35,7 +35,7 @@ private int GetValueHelper(InitializationDataKey key)
case InitializationDataKey.SequenceByte2: return _seq2;
case InitializationDataKey.SendMultiple: return _sendMulti;
case InitializationDataKey.ReceiveMultiple: return _recvMulti;
case InitializationDataKey.ClientID: return _clientID;
case InitializationDataKey.PlayerID: return _playerID;
case InitializationDataKey.HashResponse: return _hashResponse;
default: throw new ArgumentOutOfRangeException(nameof(key), key, null);
}
Expand Down
11 changes: 9 additions & 2 deletions EOLib/Net/Connection/NetworkConnectionActions.cs
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using AutomaticTypeMapper;
using EOLib.Config;
using EOLib.Domain.Login;
using EOLib.Domain.Protocol;
using EOLib.Net.Communication;
using EOLib.Net.PacketProcessing;
Expand All @@ -21,6 +22,8 @@ public class NetworkConnectionActions : INetworkConnectionActions
private readonly IPacketTranslator<IInitializationData> _initPacketTranslator;
private readonly INetworkClientFactory _networkClientFactory;
private readonly IPacketSendService _packetSendService;
private readonly IPlayerInfoRepository _playerInfoRepository;


public NetworkConnectionActions(INetworkClientRepository networkClientRepository,
IConnectionStateRepository connectionStateRepository,
Expand All @@ -30,7 +33,8 @@ public class NetworkConnectionActions : INetworkConnectionActions
IHDSerialNumberService hdSerialNumberService,
IPacketTranslator<IInitializationData> initPacketTranslator,
INetworkClientFactory networkClientFactory,
IPacketSendService packetSendService)
IPacketSendService packetSendService,
IPlayerInfoRepository playerInfoRepository)
{
_networkClientRepository = networkClientRepository;
_connectionStateRepository = connectionStateRepository;
Expand All @@ -41,6 +45,7 @@ public class NetworkConnectionActions : INetworkConnectionActions
_initPacketTranslator = initPacketTranslator;
_networkClientFactory = networkClientFactory;
_packetSendService = packetSendService;
_playerInfoRepository = playerInfoRepository;
}

public async Task<ConnectResult> ConnectToServer()
Expand Down Expand Up @@ -104,10 +109,12 @@ public async Task<IInitializationData> BeginHandshake()

public void CompleteHandshake(IInitializationData initializationData)
{
_playerInfoRepository.PlayerID = (short)initializationData[InitializationDataKey.PlayerID];

var packet = new PacketBuilder(PacketFamily.Connection, PacketAction.Accept)
.AddShort((short)initializationData[InitializationDataKey.SendMultiple])
.AddShort((short)initializationData[InitializationDataKey.ReceiveMultiple])
.AddShort((short)initializationData[InitializationDataKey.ClientID])
.AddShort(_playerInfoRepository.PlayerID)
.Build();

_packetSendService.SendPacket(packet);
Expand Down
4 changes: 2 additions & 2 deletions EOLib/Net/Translators/LoginRequestGrantedPacketTranslator.cs
Expand Up @@ -16,7 +16,7 @@ public ILoginRequestGrantedData TranslatePacket(IPacket packet)
if (reply != CharacterLoginReply.RequestGranted)
throw new MalformedPacketException("Unexpected welcome response in packet: " + reply, packet);

var playerID = packet.ReadShort();
var sessionID = packet.ReadShort();
var characterID = packet.ReadInt();

var mapID = packet.ReadShort();
Expand Down Expand Up @@ -111,7 +111,7 @@ public ILoginRequestGrantedData TranslatePacket(IPacket packet)
throw new MalformedPacketException("Missing terminating 255 byte", packet);

return new LoginRequestGrantedData()
.WithPlayerID(playerID)
.WithSessionID(sessionID)
.WithCharacterID(characterID)
.WithMapID(mapID)
.WithMapRID(mapRid)
Expand Down

0 comments on commit 16b6953

Please sign in to comment.