diff --git a/EOBot/BotHelper.cs b/EOBot/BotHelper.cs index 5dce10c21..705746460 100644 --- a/EOBot/BotHelper.cs +++ b/EOBot/BotHelper.cs @@ -28,7 +28,8 @@ public async Task CreateAccountAsync(string name, string password) { var accountActions = DependencyMaster.TypeRegistry[_botIndex].Resolve(); var accParams = new CreateAccountParameters(name, password, password, name, name, name + "@eobot.net"); - return await accountActions.CreateAccount(accParams); + var nameResult = await accountActions.CheckAccountNameWithServer(name); + return await accountActions.CreateAccount(accParams, (short)nameResult); } public async Task LoginToAccountAsync(string name, string password) @@ -56,7 +57,7 @@ public async Task LoginToCharacterAsync(string name) await CreateCharacterAsync(name); var character = characters.Characters.Single(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)); - await loginActions.RequestCharacterLogin(character); + var sessionID = await loginActions.RequestCharacterLogin(character); var unableToLoadMap = false; try @@ -71,21 +72,21 @@ public async Task LoginToCharacterAsync(string name) var fileRequestActions = DependencyMaster.TypeRegistry[_botIndex].Resolve(); if (unableToLoadMap || fileRequestActions.NeedsFileForLogin(InitFileType.Map, mapStateProvider.CurrentMapID)) - await fileRequestActions.GetMapFromServer(mapStateProvider.CurrentMapID); + await fileRequestActions.GetMapFromServer(mapStateProvider.CurrentMapID, sessionID); if (fileRequestActions.NeedsFileForLogin(InitFileType.Item)) - await fileRequestActions.GetItemFileFromServer(); + await fileRequestActions.GetItemFileFromServer(sessionID); if (fileRequestActions.NeedsFileForLogin(InitFileType.Npc)) - await fileRequestActions.GetNPCFileFromServer(); + await fileRequestActions.GetNPCFileFromServer(sessionID); if (fileRequestActions.NeedsFileForLogin(InitFileType.Spell)) - await fileRequestActions.GetSpellFileFromServer(); + await fileRequestActions.GetSpellFileFromServer(sessionID); if (fileRequestActions.NeedsFileForLogin(InitFileType.Class)) - await fileRequestActions.GetClassFileFromServer(); + await fileRequestActions.GetClassFileFromServer(sessionID); - await loginActions.CompleteCharacterLogin(); + await loginActions.CompleteCharacterLogin(sessionID); } public async Task ChangePasswordAsync(string name, string oldPass, string newPass) diff --git a/EOLib.Test/Net/FileTransfer/FileRequestServiceTest.cs b/EOLib.Test/Net/FileTransfer/FileRequestServiceTest.cs index 8c3fa7fc6..97072da30 100644 --- a/EOLib.Test/Net/FileTransfer/FileRequestServiceTest.cs +++ b/EOLib.Test/Net/FileTransfer/FileRequestServiceTest.cs @@ -168,7 +168,7 @@ private static byte[] CreateFilePacket(InitFileType type) { case InitFileType.Item: packetBuilder = packetBuilder - .AddChar((byte) InitReply.ItemFile).AddChar(1) //spacer + .AddByte((byte) InitReply.ItemFile).AddChar(1) //spacer .AddString("EIF").AddInt(1) //RID .AddShort(2) //Len .AddByte(1) //filler byte @@ -177,7 +177,7 @@ private static byte[] CreateFilePacket(InitFileType type) break; case InitFileType.Npc: packetBuilder = packetBuilder - .AddChar((byte) InitReply.NpcFile).AddChar(1) //spacer + .AddByte((byte) InitReply.NpcFile).AddChar(1) //spacer .AddString("ENF").AddInt(1) //RID .AddShort(2) //Len .AddByte(1) //filler byte @@ -186,7 +186,7 @@ private static byte[] CreateFilePacket(InitFileType type) break; case InitFileType.Spell: packetBuilder = packetBuilder - .AddChar((byte) InitReply.SpellFile).AddChar(1) //spacer + .AddByte((byte) InitReply.SpellFile).AddChar(1) //spacer .AddString("ESF").AddInt(1) //RID .AddShort(2) //Len .AddByte(1) //filler byte @@ -195,7 +195,7 @@ private static byte[] CreateFilePacket(InitFileType type) break; case InitFileType.Class: packetBuilder = packetBuilder - .AddChar((byte) InitReply.ClassFile).AddChar(1) //spacer + .AddByte((byte) InitReply.ClassFile).AddChar(1) //spacer .AddString("ECF").AddInt(1) //RID .AddShort(2) //Len .AddByte(1) //filler byte diff --git a/EOLib/Domain/Account/AccountActions.cs b/EOLib/Domain/Account/AccountActions.cs index 8fb8be073..e6e19a7bb 100644 --- a/EOLib/Domain/Account/AccountActions.cs +++ b/EOLib/Domain/Account/AccountActions.cs @@ -71,8 +71,6 @@ public async Task CheckAccountNameWithServer(string accountName) var reply = (AccountReply)response.ReadShort(); if (reply >= AccountReply.OK_CodeRange) { - _playerInfoRepository.AccountCreateID = (ushort)reply; - // Based on patch: https://github.com/eoserv/eoserv/commit/80dde6d4e7f440a93503aeec79f4a2f5931dc13d // Account may change sequence start depending on the eoserv build being used // Official software always updates sequence number @@ -90,10 +88,10 @@ public async Task CheckAccountNameWithServer(string accountName) return reply; } - public async Task CreateAccount(ICreateAccountParameters parameters) + public async Task CreateAccount(ICreateAccountParameters parameters, short sessionID) { var createAccountPacket = new PacketBuilder(PacketFamily.Account, PacketAction.Create) - .AddShort((short)_playerInfoRepository.AccountCreateID) + .AddShort(sessionID) .AddByte(255) .AddBreakString(parameters.AccountName) .AddBreakString(parameters.Password) @@ -151,7 +149,7 @@ public interface IAccountActions Task CheckAccountNameWithServer(string accountName); - Task CreateAccount(ICreateAccountParameters parameters); + Task CreateAccount(ICreateAccountParameters parameters, short sessionID); Task ChangePassword(IChangePasswordParameters parameters); } diff --git a/EOLib/Domain/Login/ILoginRequestGrantedData.cs b/EOLib/Domain/Login/ILoginRequestGrantedData.cs index c93735f07..b9058a2ed 100644 --- a/EOLib/Domain/Login/ILoginRequestGrantedData.cs +++ b/EOLib/Domain/Login/ILoginRequestGrantedData.cs @@ -6,7 +6,7 @@ namespace EOLib.Domain.Login { public interface ILoginRequestGrantedData : ITranslatedData { - short PlayerID { get; } + short SessionID { get; } int CharacterID { get; } short MapID { get; } @@ -38,7 +38,7 @@ public interface ILoginRequestGrantedData : ITranslatedData short JailMap { get; } bool FirstTimePlayer { get; } - ILoginRequestGrantedData WithPlayerID(short playerID); + ILoginRequestGrantedData WithSessionID(short sessionID); ILoginRequestGrantedData WithCharacterID(int characterID); ILoginRequestGrantedData WithMapID(short mapID); ILoginRequestGrantedData WithMapRID(IEnumerable mapRID); diff --git a/EOLib/Domain/Login/LoginActions.cs b/EOLib/Domain/Login/LoginActions.cs index 4a9572939..606b18b87 100644 --- a/EOLib/Domain/Login/LoginActions.cs +++ b/EOLib/Domain/Login/LoginActions.cs @@ -89,7 +89,7 @@ public async Task LoginToServer(ILoginParameters parameters) return data.Response; } - public async Task RequestCharacterLogin(ICharacter character) + public async Task RequestCharacterLogin(ICharacter character) { var packet = new PacketBuilder(PacketFamily.Welcome, PacketAction.Request) .AddInt(character.ID) @@ -113,7 +113,6 @@ public async Task RequestCharacterLogin(ICharacter character) .WithAdminLevel(data.AdminLevel) .WithStats(data.CharacterStats); - _playerInfoRepository.PlayerID = data.PlayerID; _playerInfoRepository.IsFirstTimePlayer = data.FirstTimePlayer; _currentMapStateRepository.CurrentMapID = data.MapID; @@ -128,12 +127,13 @@ public async Task RequestCharacterLogin(ICharacter character) _loginFileChecksumRepository.ESFLength = data.EsfLen; _loginFileChecksumRepository.ECFChecksum = data.EcfRid; _loginFileChecksumRepository.ECFLength = data.EcfLen; + return data.SessionID; } - public async Task CompleteCharacterLogin() + public async Task CompleteCharacterLogin(short sessionID) { var packet = new PacketBuilder(PacketFamily.Welcome, PacketAction.Message) - .AddThree((ushort)_playerInfoRepository.PlayerID) + .AddThree((ushort)sessionID) .AddInt(_characterRepository.MainCharacter.ID) .Build(); @@ -164,7 +164,7 @@ public async Task CompleteCharacterLogin() .WithNewStat(CharacterStat.MaxTP, mainCharacter.Stats[CharacterStat.MaxTP]); _characterRepository.MainCharacter = _characterRepository.MainCharacter - .WithID(mainCharacter.ID) + .WithID(_playerInfoRepository.PlayerID) .WithName(mainCharacter.Name) .WithMapID(mainCharacter.MapID) .WithGuildTag(mainCharacter.GuildTag) @@ -201,8 +201,8 @@ public interface ILoginActions Task LoginToServer(ILoginParameters parameters); - Task RequestCharacterLogin(ICharacter character); + Task RequestCharacterLogin(ICharacter character); - Task CompleteCharacterLogin(); + Task CompleteCharacterLogin(short sessionID); } } \ No newline at end of file diff --git a/EOLib/Domain/Login/LoginRequestGrantedData.cs b/EOLib/Domain/Login/LoginRequestGrantedData.cs index a7926fa7a..bc43bfbb1 100644 --- a/EOLib/Domain/Login/LoginRequestGrantedData.cs +++ b/EOLib/Domain/Login/LoginRequestGrantedData.cs @@ -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; } @@ -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; } @@ -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, diff --git a/EOLib/Domain/Login/PlayerInfoRepository.cs b/EOLib/Domain/Login/PlayerInfoRepository.cs index 023b8443c..a3aba345d 100644 --- a/EOLib/Domain/Login/PlayerInfoRepository.cs +++ b/EOLib/Domain/Login/PlayerInfoRepository.cs @@ -10,8 +10,6 @@ public interface IPlayerInfoRepository short PlayerID { get; set; } - ushort AccountCreateID { get; set; } - bool IsFirstTimePlayer { get; set; } bool PlayerIsInGame { get; set; } @@ -25,8 +23,6 @@ public interface IPlayerInfoProvider short PlayerID { get; } - ushort AccountCreateID { get; set; } - bool IsFirstTimePlayer { get; } bool PlayerIsInGame { get; } @@ -41,8 +37,6 @@ public sealed class PlayerInfoRepository : IPlayerInfoRepository, IPlayerInfoPro public short PlayerID { get; set; } - public ushort AccountCreateID { get; set; } - public bool IsFirstTimePlayer { get; set; } public bool PlayerIsInGame { get; set; } @@ -52,7 +46,6 @@ public void ResetState() LoggedInAccountName = ""; PlayerPassword = ""; PlayerID = 0; - AccountCreateID = 0; IsFirstTimePlayer = false; PlayerIsInGame = false; } diff --git a/EOLib/Domain/Protocol/IInitializationData.cs b/EOLib/Domain/Protocol/IInitializationData.cs index 034511b5e..6b09764eb 100644 --- a/EOLib/Domain/Protocol/IInitializationData.cs +++ b/EOLib/Domain/Protocol/IInitializationData.cs @@ -16,7 +16,7 @@ public enum InitializationDataKey SequenceByte2, SendMultiple, ReceiveMultiple, - ClientID, + PlayerID, HashResponse, //response: Out of Date RequiredVersionNumber, diff --git a/EOLib/Domain/Protocol/InitReply.cs b/EOLib/Domain/Protocol/InitReply.cs index fd03a946b..efc2c4775 100644 --- a/EOLib/Domain/Protocol/InitReply.cs +++ b/EOLib/Domain/Protocol/InitReply.cs @@ -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 } } diff --git a/EOLib/Domain/Protocol/InitializationSuccessData.cs b/EOLib/Domain/Protocol/InitializationSuccessData.cs index 62f05b7cc..e44b8a4b3 100644 --- a/EOLib/Domain/Protocol/InitializationSuccessData.cs +++ b/EOLib/Domain/Protocol/InitializationSuccessData.cs @@ -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; } @@ -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); } diff --git a/EOLib/Net/Connection/NetworkConnectionActions.cs b/EOLib/Net/Connection/NetworkConnectionActions.cs index d31938fea..77b0917b4 100644 --- a/EOLib/Net/Connection/NetworkConnectionActions.cs +++ b/EOLib/Net/Connection/NetworkConnectionActions.cs @@ -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; @@ -21,6 +22,8 @@ public class NetworkConnectionActions : INetworkConnectionActions private readonly IPacketTranslator _initPacketTranslator; private readonly INetworkClientFactory _networkClientFactory; private readonly IPacketSendService _packetSendService; + private readonly IPlayerInfoRepository _playerInfoRepository; + public NetworkConnectionActions(INetworkClientRepository networkClientRepository, IConnectionStateRepository connectionStateRepository, @@ -30,7 +33,8 @@ public NetworkConnectionActions(INetworkClientRepository networkClientRepository IHDSerialNumberService hdSerialNumberService, IPacketTranslator initPacketTranslator, INetworkClientFactory networkClientFactory, - IPacketSendService packetSendService) + IPacketSendService packetSendService, + IPlayerInfoRepository playerInfoRepository) { _networkClientRepository = networkClientRepository; _connectionStateRepository = connectionStateRepository; @@ -41,6 +45,7 @@ public NetworkConnectionActions(INetworkClientRepository networkClientRepository _initPacketTranslator = initPacketTranslator; _networkClientFactory = networkClientFactory; _packetSendService = packetSendService; + _playerInfoRepository = playerInfoRepository; } public async Task ConnectToServer() @@ -104,10 +109,12 @@ public async Task 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); diff --git a/EOLib/Net/FileTransfer/FileRequestActions.cs b/EOLib/Net/FileTransfer/FileRequestActions.cs index 9b7f08261..f67a23208 100644 --- a/EOLib/Net/FileTransfer/FileRequestActions.cs +++ b/EOLib/Net/FileTransfer/FileRequestActions.cs @@ -58,42 +58,42 @@ public bool NeedsMapForWarp(short mapID, byte[] mapRid, int fileSize) return NeedMap(mapID, expectedChecksum, fileSize); } - public async Task GetMapFromServer(short mapID) + public async Task GetMapForWarp(short mapID, short sessionID) { - var mapFile = await _fileRequestService.RequestMapFile(mapID, _playerInfoProvider.PlayerID); + var mapFile = await _fileRequestService.RequestMapFileForWarp(mapID, sessionID); SaveAndCacheMapFile(mapID, mapFile); } - public async Task GetMapForWarp(short mapID) + public async Task GetMapFromServer(short mapID, short sessionID) { - var mapFile = await _fileRequestService.RequestMapFileForWarp(mapID); + var mapFile = await _fileRequestService.RequestMapFile(mapID, sessionID); SaveAndCacheMapFile(mapID, mapFile); } - public async Task GetItemFileFromServer() + public async Task GetItemFileFromServer(short sessionID) { - var itemFile = await _fileRequestService.RequestFile(InitFileType.Item, _playerInfoProvider.PlayerID); + var itemFile = await _fileRequestService.RequestFile(InitFileType.Item, sessionID); _pubFileSaveService.SaveFile(PubFileNameConstants.PathToEIFFile, itemFile, rewriteChecksum: false); _pubFileRepository.EIFFile = (EIFFile)itemFile; } - public async Task GetNPCFileFromServer() + public async Task GetNPCFileFromServer(short sessionID) { - var npcFile = await _fileRequestService.RequestFile(InitFileType.Npc, _playerInfoProvider.PlayerID); + var npcFile = await _fileRequestService.RequestFile(InitFileType.Npc, sessionID); _pubFileSaveService.SaveFile(PubFileNameConstants.PathToENFFile, npcFile, rewriteChecksum: false); _pubFileRepository.ENFFile = (ENFFile)npcFile; } - public async Task GetSpellFileFromServer() + public async Task GetSpellFileFromServer(short sessionID) { - var spellFile = await _fileRequestService.RequestFile(InitFileType.Spell, _playerInfoProvider.PlayerID); + var spellFile = await _fileRequestService.RequestFile(InitFileType.Spell, sessionID); _pubFileSaveService.SaveFile(PubFileNameConstants.PathToESFFile, spellFile, rewriteChecksum: false); _pubFileRepository.ESFFile = (ESFFile)spellFile; } - public async Task GetClassFileFromServer() + public async Task GetClassFileFromServer(short sessionID) { - var classFile = await _fileRequestService.RequestFile(InitFileType.Class, _playerInfoProvider.PlayerID); + var classFile = await _fileRequestService.RequestFile(InitFileType.Class, sessionID); _pubFileSaveService.SaveFile(PubFileNameConstants.PathToECFFile, classFile, rewriteChecksum: false); _pubFileRepository.ECFFile = (ECFFile)classFile; } @@ -151,16 +151,16 @@ public interface IFileRequestActions bool NeedsMapForWarp(short mapID, byte[] mapRid, int fileSize); - Task GetMapFromServer(short mapID); + Task GetMapForWarp(short mapID, short sessionID); - Task GetMapForWarp(short mapID); + Task GetMapFromServer(short mapID, short sessionID); - Task GetItemFileFromServer(); + Task GetItemFileFromServer(short sessionID); - Task GetNPCFileFromServer(); + Task GetNPCFileFromServer(short sessionID); - Task GetSpellFileFromServer(); + Task GetSpellFileFromServer(short sessionID); - Task GetClassFileFromServer(); + Task GetClassFileFromServer(short sessionID); } } \ No newline at end of file diff --git a/EOLib/Net/FileTransfer/FileRequestService.cs b/EOLib/Net/FileTransfer/FileRequestService.cs index 573aae5a8..5b8ae1a1c 100644 --- a/EOLib/Net/FileTransfer/FileRequestService.cs +++ b/EOLib/Net/FileTransfer/FileRequestService.cs @@ -26,29 +26,33 @@ public FileRequestService(IPacketSendService packetSendService, _pubFileDeserializer = pubFileDeserializer; } - public async Task RequestMapFile(short mapID, short playerID) + public async Task RequestMapFile(short mapID, short sessionID) { var request = new PacketBuilder(PacketFamily.Welcome, PacketAction.Agree) .AddChar((byte)InitFileType.Map) - .AddShort(playerID) + .AddShort(sessionID) .AddShort(mapID) .Build(); - return await GetMapFile(request, mapID, false); + return await GetMapFile(request, mapID); } - public async Task RequestMapFileForWarp(short mapID) + public async Task RequestMapFileForWarp(short mapID, short sessionID) { - var request = new PacketBuilder(PacketFamily.Warp, PacketAction.Take).Build(); - return await GetMapFile(request, mapID, true); + var request = new PacketBuilder(PacketFamily.Warp, PacketAction.Take) + .AddShort(mapID) + .AddShort(sessionID) + .Build(); + + return await GetMapFile(request, mapID); } - public async Task> RequestFile(InitFileType fileType, short playerID) + public async Task> RequestFile(InitFileType fileType, short sessionID) where TRecord : class, IPubRecord, new() { var request = new PacketBuilder(PacketFamily.Welcome, PacketAction.Agree) .AddChar((byte)fileType) - .AddShort(playerID) + .AddShort(sessionID) .AddChar(1) // file id (for chunking oversize pub files) .Build(); @@ -56,7 +60,7 @@ public async Task> RequestFile(InitFileType fileType, if (!PacketIsValid(response)) throw new EmptyPacketReceivedException(); - var responseFileType = (InitReply) response.ReadChar(); + var responseFileType = (InitReply) response.ReadByte(); var extraByte = response.ReadChar(); if (extraByte != 1) @@ -79,14 +83,14 @@ public async Task> RequestFile(InitFileType fileType, return _pubFileDeserializer.DeserializeFromByteArray(responseBytes, factory); } - private async Task GetMapFile(IPacket request, int mapID, bool isWarp) + private async Task GetMapFile(IPacket request, int mapID) { var response = await _packetSendService.SendEncodedPacketAndWaitAsync(request); if (!PacketIsValid(response)) throw new EmptyPacketReceivedException(); - var fileType = (InitReply)(isWarp ? response.ReadByte() : response.ReadChar()); - if (fileType != InitReply.MapFile) + var fileType = (InitReply)response.ReadByte(); + if (fileType != InitReply.MapFile && fileType != InitReply.WarpMap) throw new MalformedPacketException("Invalid file type " + fileType + " when requesting a map file", response); var fileData = response.ReadBytes(response.Length - response.ReadPosition); @@ -106,11 +110,11 @@ private static bool PacketIsValid(IPacket packet) public interface IFileRequestService { - Task RequestMapFile(short mapID, short playerID); + Task RequestMapFile(short mapID, short sessionID); - Task RequestMapFileForWarp(short mapID); + Task RequestMapFileForWarp(short mapID, short sessionID); - Task> RequestFile(InitFileType fileType, short playerID) + Task> RequestFile(InitFileType fileType, short sessionID) where TRecord : class, IPubRecord, new(); } } \ No newline at end of file diff --git a/EOLib/Net/Translators/LoginRequestGrantedPacketTranslator.cs b/EOLib/Net/Translators/LoginRequestGrantedPacketTranslator.cs index fb6a87365..7d2c7b92a 100644 --- a/EOLib/Net/Translators/LoginRequestGrantedPacketTranslator.cs +++ b/EOLib/Net/Translators/LoginRequestGrantedPacketTranslator.cs @@ -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(); @@ -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) diff --git a/EOLib/PacketHandlers/BeginPlayerWarpHandler.cs b/EOLib/PacketHandlers/BeginPlayerWarpHandler.cs index 990d9a711..c836f13fc 100644 --- a/EOLib/PacketHandlers/BeginPlayerWarpHandler.cs +++ b/EOLib/PacketHandlers/BeginPlayerWarpHandler.cs @@ -50,15 +50,18 @@ public override bool HandlePacket(IPacket packet) _mapStateRepository.MapWarpState = WarpState.WarpStarted; var warpType = packet.ReadChar(); + var mapID = packet.ReadShort(); + short sessionID; switch (warpType) { case WARP_SAME_MAP: - SendWarpAcceptToServer(packet); + sessionID = packet.ReadShort(); + SendWarpAcceptToServer(mapID, sessionID); break; case WARP_NEW_MAP: - var mapID = packet.ReadShort(); var mapRid = packet.ReadBytes(4).ToArray(); var fileSize = packet.ReadThree(); + sessionID = packet.ReadShort(); var mapIsDownloaded = true; try @@ -69,9 +72,9 @@ public override bool HandlePacket(IPacket packet) catch (IOException) { mapIsDownloaded = false; } if (!mapIsDownloaded || _fileRequestActions.NeedsMapForWarp(mapID, mapRid, fileSize)) - _fileRequestActions.GetMapForWarp(mapID).Wait(5000); + _fileRequestActions.GetMapForWarp(mapID, sessionID).Wait(5000); - SendWarpAcceptToServer(packet); + SendWarpAcceptToServer(mapID, sessionID); break; default: _mapStateRepository.MapWarpState = WarpState.None; @@ -81,10 +84,11 @@ public override bool HandlePacket(IPacket packet) return true; } - private void SendWarpAcceptToServer(IPacket packet) + private void SendWarpAcceptToServer(short mapID, short sessionID) { var response = new PacketBuilder(PacketFamily.Warp, PacketAction.Accept) - .AddShort(packet.ReadShort()) + .AddShort(mapID) + .AddShort(sessionID) .Build(); _packetSendService.SendPacket(response); } diff --git a/EndlessClient/Controllers/AccountController.cs b/EndlessClient/Controllers/AccountController.cs index de01103b6..e04587460 100644 --- a/EndlessClient/Controllers/AccountController.cs +++ b/EndlessClient/Controllers/AccountController.cs @@ -60,7 +60,11 @@ public async Task CreateAccount(ICreateAccountParameters createAccountParameters return; var createAccountOperation = _networkOperationFactory.CreateSafeBlockingOperation( - async () => await _accountActions.CreateAccount(createAccountParameters), + async () => + { + short sessionID = (short)nameResult; + return await _accountActions.CreateAccount(createAccountParameters, sessionID); + }, SetInitialStateAndShowError, SetInitialStateAndShowError); if (!await createAccountOperation.Invoke()) diff --git a/EndlessClient/Controllers/LoginController.cs b/EndlessClient/Controllers/LoginController.cs index 3c6e6a099..b6edd3143 100644 --- a/EndlessClient/Controllers/LoginController.cs +++ b/EndlessClient/Controllers/LoginController.cs @@ -104,6 +104,8 @@ public async Task LoginToCharacter(ICharacter character) if (!await requestCharacterLoginOperation.Invoke()) return; + var sessionID = requestCharacterLoginOperation.Result; + var unableToLoadMap = false; try { @@ -127,7 +129,7 @@ public async Task LoginToCharacter(ICharacter character) if (unableToLoadMap || _fileRequestActions.NeedsFileForLogin(InitFileType.Map, _currentMapStateProvider.CurrentMapID)) { gameLoadingDialog.SetState(GameLoadingDialogState.Map); - if (!await SafeGetFile(async () => await _fileRequestActions.GetMapFromServer(_currentMapStateProvider.CurrentMapID))) + if (!await SafeGetFile(() => _fileRequestActions.GetMapFromServer(_currentMapStateProvider.CurrentMapID, sessionID))) return; await Task.Delay(1000); } @@ -135,7 +137,7 @@ public async Task LoginToCharacter(ICharacter character) if (_fileRequestActions.NeedsFileForLogin(InitFileType.Item)) { gameLoadingDialog.SetState(GameLoadingDialogState.Item); - if (!await SafeGetFile(_fileRequestActions.GetItemFileFromServer)) + if (!await SafeGetFile(() => _fileRequestActions.GetItemFileFromServer(sessionID))) return; await Task.Delay(1000); } @@ -143,7 +145,7 @@ public async Task LoginToCharacter(ICharacter character) if (_fileRequestActions.NeedsFileForLogin(InitFileType.Npc)) { gameLoadingDialog.SetState(GameLoadingDialogState.NPC); - if (!await SafeGetFile(_fileRequestActions.GetNPCFileFromServer)) + if (!await SafeGetFile(() => _fileRequestActions.GetNPCFileFromServer(sessionID))) return; await Task.Delay(1000); } @@ -151,7 +153,7 @@ public async Task LoginToCharacter(ICharacter character) if (_fileRequestActions.NeedsFileForLogin(InitFileType.Spell)) { gameLoadingDialog.SetState(GameLoadingDialogState.Spell); - if (!await SafeGetFile(_fileRequestActions.GetSpellFileFromServer)) + if (!await SafeGetFile(() => _fileRequestActions.GetSpellFileFromServer(sessionID))) return; await Task.Delay(1000); } @@ -159,7 +161,7 @@ public async Task LoginToCharacter(ICharacter character) if (_fileRequestActions.NeedsFileForLogin(InitFileType.Class)) { gameLoadingDialog.SetState(GameLoadingDialogState.Class); - if (!await SafeGetFile(_fileRequestActions.GetClassFileFromServer)) + if (!await SafeGetFile(() => _fileRequestActions.GetClassFileFromServer(sessionID))) return; await Task.Delay(1000); } @@ -167,7 +169,7 @@ public async Task LoginToCharacter(ICharacter character) gameLoadingDialog.SetState(GameLoadingDialogState.LoadingGame); var completeCharacterLoginOperation = _networkOperationFactory.CreateSafeBlockingOperation( - _loginActions.CompleteCharacterLogin, + (async () => await _loginActions.CompleteCharacterLogin(sessionID)), SetInitialStateAndShowError, SetInitialStateAndShowError); if (!await completeCharacterLoginOperation.Invoke())