-
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 #120 from ethanmoffat/whoisonline
Implement online players panel
- Loading branch information
Showing
17 changed files
with
424 additions
and
306 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace EOLib.Domain.Online | ||
{ | ||
public enum OnlineIcon | ||
{ | ||
Normal = 0, | ||
GM = 4, | ||
HGM = 5, | ||
Party = 6, | ||
GMParty = 9, | ||
HGMParty = 10, | ||
SLNBot = 20 | ||
} | ||
} |
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,20 @@ | ||
using EOLib.Net.Translators; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Online | ||
{ | ||
public class OnlineListData : IOnlineListData | ||
{ | ||
public IReadOnlyList<OnlinePlayerInfo> OnlineList { get; } | ||
|
||
public OnlineListData(IReadOnlyList<OnlinePlayerInfo> onlineList) | ||
{ | ||
OnlineList = onlineList; | ||
} | ||
} | ||
|
||
public interface IOnlineListData : ITranslatedData | ||
{ | ||
IReadOnlyList<OnlinePlayerInfo> OnlineList { get; } | ||
} | ||
} |
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 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<IOnlineListData> _onlineListPacketTranslator; | ||
|
||
public OnlinePlayerActions(IPacketSendService packetSendService, | ||
IPacketTranslator<IOnlineListData> onlineListPacketTranslator) | ||
{ | ||
_packetSendService = packetSendService; | ||
_onlineListPacketTranslator = onlineListPacketTranslator; | ||
} | ||
|
||
public async Task<IReadOnlyList<OnlinePlayerInfo>> GetOnlinePlayersAsync(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; | ||
} | ||
} | ||
|
||
public interface IOnlinePlayerActions | ||
{ | ||
Task<IReadOnlyList<OnlinePlayerInfo>> GetOnlinePlayersAsync(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,29 @@ | ||
namespace EOLib.Domain.Online | ||
{ | ||
public class OnlinePlayerInfo | ||
{ | ||
public string Name { get; } | ||
|
||
public string Title { get; } | ||
|
||
public string Guild { get; } | ||
|
||
public string Class { get; } | ||
|
||
public OnlineIcon Icon { get; } | ||
|
||
public OnlinePlayerInfo(string name) | ||
: this(name, string.Empty, string.Empty, string.Empty, OnlineIcon.Normal) | ||
{ | ||
} | ||
|
||
public OnlinePlayerInfo(string name, string title, string guild, string @class, OnlineIcon icon) | ||
{ | ||
Name = name; | ||
Title = title; | ||
Guild = guild; | ||
Class = @class; | ||
Icon = icon; | ||
} | ||
} | ||
} |
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,13 @@ | ||
using EOLib.Domain.Chat; | ||
using Optional; | ||
|
||
namespace EOLib.Extensions | ||
{ | ||
public static class ChatIconExtensions | ||
{ | ||
public static Option<(int X, int Y, int Width, int Height)> GetChatIconRectangleBounds(this ChatIcon icon) | ||
{ | ||
return icon == ChatIcon.None ? Option.None<(int, int, int, int)>() : Option.Some((0, (int)icon * 13, 13, 13)); | ||
} | ||
} | ||
} |
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,24 @@ | ||
using EOLib.Domain.Chat; | ||
using EOLib.Domain.Online; | ||
using System; | ||
|
||
namespace EOLib.Extensions | ||
{ | ||
public static class OnlineIconExtensions | ||
{ | ||
public static ChatIcon ToChatIcon(this OnlineIcon icon) | ||
{ | ||
switch (icon) | ||
{ | ||
case OnlineIcon.Normal: return ChatIcon.Player; | ||
case OnlineIcon.GM: return ChatIcon.GM; | ||
case OnlineIcon.HGM: return ChatIcon.HGM; | ||
case OnlineIcon.Party: return ChatIcon.PlayerParty; | ||
case OnlineIcon.GMParty: return ChatIcon.GMParty; | ||
case OnlineIcon.HGMParty: return ChatIcon.HGMParty; | ||
case OnlineIcon.SLNBot: return ChatIcon.PlayerPartyDark; | ||
default: throw new ArgumentOutOfRangeException(nameof(icon), "Invalid Icon type specified."); | ||
} | ||
} | ||
} | ||
} |
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,70 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Online; | ||
using EOLib.Domain.Protocol; | ||
using EOLib.IO.Repositories; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Net.Translators | ||
{ | ||
[AutoMappedType] | ||
public class OnlineListPacketTranslator : IPacketTranslator<IOnlineListData> | ||
{ | ||
private readonly IECFFileProvider _classFileProvider; | ||
|
||
public OnlineListPacketTranslator(IECFFileProvider classFileProvider) | ||
{ | ||
_classFileProvider = classFileProvider; | ||
} | ||
|
||
public IOnlineListData TranslatePacket(IPacket packet) | ||
{ | ||
var reply = (InitReply)packet.ReadChar(); | ||
|
||
if (reply != InitReply.AllPlayersList && reply != InitReply.FriendPlayersList) | ||
throw new MalformedPacketException($"Expected online list or friend list init data, but was {reply}", packet); | ||
|
||
short numTotal = packet.ReadShort(); | ||
if (packet.ReadByte() != 255) | ||
throw new MalformedPacketException("Expected break byte after number of entries", packet); | ||
|
||
var retList = new List<OnlinePlayerInfo>(numTotal); | ||
for (int i = 0; i < numTotal; ++i) | ||
{ | ||
string name = packet.ReadBreakString(); | ||
|
||
if (reply == InitReply.AllPlayersList) | ||
{ | ||
var title = packet.ReadBreakString(); | ||
if (packet.ReadChar() != 0) | ||
throw new MalformedPacketException("Expected 0 char after online entry title", packet); | ||
|
||
var iconType = (OnlineIcon)packet.ReadChar(); | ||
int clsId = packet.ReadChar(); | ||
var guild = packet.ReadBreakString(); | ||
|
||
name = char.ToUpper(name[0]) + name.Substring(1); | ||
|
||
if (string.IsNullOrWhiteSpace(title)) | ||
title = "-"; | ||
else | ||
title = char.ToUpper(title[0]) + title.Substring(1); | ||
|
||
var className = _classFileProvider.ECFFile.Length <= clsId | ||
? _classFileProvider.ECFFile[clsId].Name | ||
: "-"; | ||
|
||
if (string.IsNullOrWhiteSpace(guild)) | ||
guild = "-"; | ||
|
||
retList.Add(new OnlinePlayerInfo(name, title, guild, className, iconType)); | ||
} | ||
else | ||
{ | ||
retList.Add(new OnlinePlayerInfo(name)); | ||
} | ||
} | ||
|
||
return new OnlineListData(retList); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.