-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update map warp file downloads to use new in-game handling of init pa…
…ckets. Fixes crashes when warping to an undownloaded map.
- Loading branch information
1 parent
deb186a
commit e74e189
Showing
5 changed files
with
141 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Map; | ||
using EOLib.Domain.Notifiers; | ||
using EOLib.Domain.Protocol; | ||
using EOLib.IO.Map; | ||
using EOLib.IO.Repositories; | ||
using EOLib.IO.Services; | ||
using EOLib.IO.Services.Serializers; | ||
using EOLib.Net; | ||
using EOLib.Net.Communication; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace EOLib.PacketHandlers.Init | ||
{ | ||
[AutoMappedType] | ||
public class MapWarpFileDownloadHandler : IInitPacketHandler | ||
{ | ||
private readonly IMapFileRepository _mapFileRepository; | ||
private readonly IMapDeserializer<IMapFile> _mapFileDeserializer; | ||
private readonly IMapFileSaveService _mapFileSaveService; | ||
private readonly ICurrentMapStateProvider _currentMapStateProvider; | ||
private readonly IPacketSendService _packetSendService; | ||
|
||
public InitReply Reply => InitReply.WarpMap; | ||
|
||
public MapWarpFileDownloadHandler(IMapFileRepository mapFileRepository, | ||
IMapDeserializer<IMapFile> mapFileDeserializer, | ||
IMapFileSaveService mapFileSaveService, | ||
ICurrentMapStateProvider currentMapStateProvider, | ||
IPacketSendService packetSendService) | ||
{ | ||
_mapFileRepository = mapFileRepository; | ||
_mapFileDeserializer = mapFileDeserializer; | ||
_mapFileSaveService = mapFileSaveService; | ||
_currentMapStateProvider = currentMapStateProvider; | ||
_packetSendService = packetSendService; | ||
} | ||
|
||
public bool HandlePacket(IPacket packet) | ||
{ | ||
if (_currentMapStateProvider.MapWarpState != WarpState.WarpStarted) | ||
return false; | ||
|
||
if (!_currentMapStateProvider.MapWarpID.HasValue || | ||
!_currentMapStateProvider.MapWarpSession.HasValue) | ||
return false; | ||
|
||
_currentMapStateProvider.MapWarpID.MatchSome( | ||
mapID => | ||
{ | ||
var fileData = packet.ReadBytes(packet.Length - packet.ReadPosition); | ||
var mapFile = _mapFileDeserializer | ||
.DeserializeFromByteArray(fileData.ToArray()) | ||
.WithMapID(mapID); | ||
|
||
_mapFileRepository.MapFiles[mapID] = mapFile; | ||
_mapFileSaveService.SaveFileToDefaultDirectory(mapFile, rewriteChecksum: false); | ||
|
||
_currentMapStateProvider.MapWarpSession.MatchSome(sessionID => SendWarpAcceptToServer(mapID, sessionID)); | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
private void SendWarpAcceptToServer(short mapID, short sessionID) | ||
{ | ||
var response = new PacketBuilder(PacketFamily.Warp, PacketAction.Accept) | ||
.AddShort(mapID) | ||
.AddShort(sessionID) | ||
.Build(); | ||
_packetSendService.SendPacket(response); | ||
} | ||
} | ||
} |