-
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.
Merge pull request #195 from ethanmoffat/map_mutate
Re-implement map mutate and refactor in-game handling of init packets
- Loading branch information
Showing
30 changed files
with
443 additions
and
352 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,36 +1,28 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Net; | ||
using EOLib.Net.Communication; | ||
using EOLib.Net.Translators; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace EOLib.Domain.Online | ||
{ | ||
[AutoMappedType] | ||
public class OnlinePlayerActions : IOnlinePlayerActions | ||
{ | ||
private readonly IPacketSendService _packetSendService; | ||
private readonly IPacketTranslator<OnlineListData> _onlineListPacketTranslator; | ||
|
||
public OnlinePlayerActions(IPacketSendService packetSendService, | ||
IPacketTranslator<OnlineListData> onlineListPacketTranslator) | ||
public OnlinePlayerActions(IPacketSendService packetSendService) | ||
{ | ||
_packetSendService = packetSendService; | ||
_onlineListPacketTranslator = onlineListPacketTranslator; | ||
} | ||
|
||
public async Task<IReadOnlyList<OnlinePlayerInfo>> GetOnlinePlayersAsync(bool fullList) | ||
public void RequestOnlinePlayers(bool fullList) | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Players, fullList ? PacketAction.Request : PacketAction.List).Build(); | ||
var response = await _packetSendService.SendEncodedPacketAndWaitAsync(packet); | ||
|
||
return _onlineListPacketTranslator.TranslatePacket(response).OnlineList; | ||
_packetSendService.SendPacket(packet); | ||
} | ||
} | ||
|
||
public interface IOnlinePlayerActions | ||
{ | ||
Task<IReadOnlyList<OnlinePlayerInfo>> GetOnlinePlayersAsync(bool fullList); | ||
void RequestOnlinePlayers(bool fullList); | ||
} | ||
} |
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,33 @@ | ||
using AutomaticTypeMapper; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Online | ||
{ | ||
public interface IOnlinePlayerRepository : IResettable | ||
{ | ||
HashSet<OnlinePlayerInfo> OnlinePlayers { get; } | ||
} | ||
|
||
public interface IOnlinePlayerProvider | ||
{ | ||
IReadOnlyCollection<OnlinePlayerInfo> OnlinePlayers { get; } | ||
} | ||
|
||
[AutoMappedType(IsSingleton = true)] | ||
public class OnlinePlayerRepository : IOnlinePlayerRepository, IOnlinePlayerProvider | ||
{ | ||
public HashSet<OnlinePlayerInfo> OnlinePlayers { get; private set; } | ||
|
||
IReadOnlyCollection<OnlinePlayerInfo> IOnlinePlayerProvider.OnlinePlayers => OnlinePlayers; | ||
|
||
public OnlinePlayerRepository() | ||
{ | ||
ResetState(); | ||
} | ||
|
||
public void ResetState() | ||
{ | ||
OnlinePlayers = new HashSet<OnlinePlayerInfo>(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
using EOLib.Domain.Online; | ||
using EOLib.Domain.Protocol; | ||
using EOLib.Net; | ||
|
||
namespace EOLib.PacketHandlers.Init | ||
{ | ||
public abstract class BasePlayersListHandler : IInitPacketHandler | ||
{ | ||
private readonly IOnlinePlayerRepository _onlinePlayerRepository; | ||
|
||
public abstract InitReply Reply { get; } | ||
|
||
protected BasePlayersListHandler(IOnlinePlayerRepository onlinePlayerRepository) | ||
{ | ||
_onlinePlayerRepository = onlinePlayerRepository; | ||
} | ||
|
||
public bool HandlePacket(IPacket packet) | ||
{ | ||
var numTotal = packet.ReadShort(); | ||
|
||
if (packet.ReadByte() != 255) | ||
return false; | ||
|
||
_onlinePlayerRepository.OnlinePlayers.Clear(); | ||
for (int i = 0; i < numTotal; ++i) | ||
{ | ||
_onlinePlayerRepository.OnlinePlayers.Add(GetNextRecord(packet)); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
protected abstract OnlinePlayerInfo GetNextRecord(IPacket packet); | ||
} | ||
} |
Oops, something went wrong.