-
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 #340 from ethanmoffat/reports
Implement handling for reports and ADMININTERACT packet family.
- Loading branch information
Showing
33 changed files
with
987 additions
and
100 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
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,42 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Net; | ||
using EOLib.Net.Communication; | ||
|
||
namespace EOLib.Domain.Report | ||
{ | ||
[AutoMappedType] | ||
public class ReportActions : IReportActions | ||
{ | ||
private readonly IPacketSendService _packetSendService; | ||
|
||
public ReportActions(IPacketSendService packetSendService) | ||
{ | ||
_packetSendService = packetSendService; | ||
} | ||
|
||
public void ReportPlayer(string player, string message) | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.AdminInteract, PacketAction.Report) | ||
.AddString(player) | ||
.AddByte(255) | ||
.AddString(message) | ||
.Build(); | ||
_packetSendService.SendPacket(packet); | ||
} | ||
|
||
public void SpeakToAdmin(string message) | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.AdminInteract, PacketAction.Tell) | ||
.AddString(message) | ||
.Build(); | ||
_packetSendService.SendPacket(packet); | ||
} | ||
} | ||
|
||
public interface IReportActions | ||
{ | ||
void ReportPlayer(string player, string message); | ||
|
||
void SpeakToAdmin(string message); | ||
} | ||
} |
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,67 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Notifiers; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.PacketHandlers.AdminInteract | ||
{ | ||
/// <summary> | ||
/// Response to $inventory <character> command. | ||
/// </summary> | ||
[AutoMappedType] | ||
public class AdminInteractList: InGameOnlyPacketHandler | ||
{ | ||
private readonly IEnumerable<IUserInterfaceNotifier> _userInterfaceNotifiers; | ||
|
||
public override PacketFamily Family => PacketFamily.AdminInteract; | ||
|
||
public override PacketAction Action => PacketAction.List; | ||
|
||
public AdminInteractList(IPlayerInfoProvider playerInfoProvider, | ||
IEnumerable<IUserInterfaceNotifier> userInterfaceNotifiers) | ||
: base(playerInfoProvider) | ||
{ | ||
_userInterfaceNotifiers = userInterfaceNotifiers; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var name = packet.ReadBreakString(); | ||
|
||
var usage = packet.ReadInt(); | ||
if (packet.ReadByte() != 255) | ||
return false; | ||
|
||
var gold_bank = packet.ReadInt(); | ||
if (packet.ReadByte() != 255) | ||
return false; | ||
|
||
var inventory = new List<InventoryItem>(); | ||
while (packet.PeekByte() != 255) | ||
{ | ||
var id = packet.ReadShort(); | ||
var amount = packet.ReadInt(); | ||
inventory.Add(new InventoryItem(id, amount)); | ||
} | ||
packet.ReadByte(); | ||
|
||
var bank = new List<InventoryItem>(); | ||
while (packet.ReadPosition < packet.Length) | ||
{ | ||
var id = packet.ReadShort(); | ||
var amount = packet.ReadThree(); | ||
bank.Add(new InventoryItem(id, amount)); | ||
} | ||
|
||
foreach (var notifier in _userInterfaceNotifiers) | ||
{ | ||
notifier.NotifyCharacterInventory(name, usage, gold_bank, inventory, bank); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
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,55 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Chat; | ||
using EOLib.Domain.Login; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
|
||
namespace EOLib.PacketHandlers.AdminInteract | ||
{ | ||
/// <summary> | ||
/// Received by admins when a report is made by another player. | ||
/// </summary> | ||
[AutoMappedType] | ||
public class AdminInteractReply : InGameOnlyPacketHandler | ||
{ | ||
private readonly IChatRepository _chatRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.AdminInteract; | ||
|
||
public override PacketAction Action => PacketAction.Reply; | ||
|
||
public AdminInteractReply(IPlayerInfoProvider playerInfoProvider, | ||
IChatRepository chatRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_chatRepository = chatRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var messageType = (AdminMessageType)packet.ReadChar(); | ||
packet.ReadByte(); | ||
|
||
var playerName = packet.ReadBreakString(); | ||
var message = packet.ReadBreakString(); | ||
|
||
ChatData chatData; | ||
switch (messageType) | ||
{ | ||
case AdminMessageType.Message: | ||
chatData = new ChatData(ChatTab.Group, playerName, $"needs help: {message}", ChatIcon.Information, ChatColor.ServerGlobal, filter: false); | ||
break; | ||
case AdminMessageType.Report: | ||
var reporteeName = packet.ReadBreakString(); | ||
chatData = new ChatData(ChatTab.Group, playerName, $"reports: {reporteeName}, {message}", ChatIcon.Information, ChatColor.ServerGlobal, filter: false); | ||
break; | ||
default: | ||
return false; | ||
} | ||
|
||
_chatRepository.AllChat[ChatTab.Group].Add(chatData); | ||
|
||
return true; | ||
} | ||
} | ||
} |
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,82 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Domain.Notifiers; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.PacketHandlers.AdminInteract | ||
{ | ||
/// <summary> | ||
/// Response to $info <character> command. | ||
/// </summary> | ||
[AutoMappedType] | ||
public class AdminInteractTell: InGameOnlyPacketHandler | ||
{ | ||
private readonly IEnumerable<IUserInterfaceNotifier> _userInterfaceNotifiers; | ||
|
||
public override PacketFamily Family => PacketFamily.AdminInteract; | ||
|
||
public override PacketAction Action => PacketAction.Tell; | ||
|
||
public AdminInteractTell(IPlayerInfoProvider playerInfoProvider, | ||
IEnumerable<IUserInterfaceNotifier> userInterfaceNotifiers) | ||
: base(playerInfoProvider) | ||
{ | ||
_userInterfaceNotifiers = userInterfaceNotifiers; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var name = packet.ReadBreakString(); | ||
|
||
var stats = new Dictionary<CharacterStat, int>(); | ||
stats[CharacterStat.Usage] = packet.ReadInt(); | ||
if (packet.ReadByte() != 255 || packet.ReadByte() != 255) | ||
return false; | ||
|
||
stats[CharacterStat.Experience] = packet.ReadInt(); | ||
stats[CharacterStat.Level] = packet.ReadChar(); | ||
|
||
var mapId = packet.ReadShort(); | ||
var mapCoords = new MapCoordinate(packet.ReadShort(), packet.ReadShort()); | ||
|
||
stats[CharacterStat.HP] = packet.ReadShort(); | ||
stats[CharacterStat.MaxHP] = packet.ReadShort(); | ||
stats[CharacterStat.TP] = packet.ReadShort(); | ||
stats[CharacterStat.MaxTP] = packet.ReadShort(); | ||
|
||
stats[CharacterStat.Strength] = packet.ReadShort(); | ||
stats[CharacterStat.Intelligence] = packet.ReadShort(); | ||
stats[CharacterStat.Wisdom] = packet.ReadShort(); | ||
stats[CharacterStat.Agility] = packet.ReadShort(); | ||
stats[CharacterStat.Constitution] = packet.ReadShort(); | ||
stats[CharacterStat.Charisma] = packet.ReadShort(); | ||
|
||
stats[CharacterStat.MaxDam] = packet.ReadShort(); | ||
stats[CharacterStat.MinDam] = packet.ReadShort(); | ||
stats[CharacterStat.Accuracy] = packet.ReadShort(); | ||
stats[CharacterStat.Evade] = packet.ReadShort(); | ||
stats[CharacterStat.Armor] = packet.ReadShort(); | ||
|
||
stats[CharacterStat.Light] = packet.ReadShort(); | ||
stats[CharacterStat.Dark] = packet.ReadShort(); | ||
stats[CharacterStat.Fire] = packet.ReadShort(); | ||
stats[CharacterStat.Water] = packet.ReadShort(); | ||
stats[CharacterStat.Earth] = packet.ReadShort(); | ||
stats[CharacterStat.Wind] = packet.ReadShort(); | ||
|
||
stats[CharacterStat.Weight] = packet.ReadChar(); | ||
stats[CharacterStat.MaxWeight] = packet.ReadChar(); | ||
|
||
foreach (var notifier in _userInterfaceNotifiers) | ||
{ | ||
notifier.NotifyCharacterInfo(name, mapId, mapCoords, new CharacterStats(stats)); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
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,8 @@ | ||
namespace EOLib.PacketHandlers.AdminInteract | ||
{ | ||
public enum AdminMessageType | ||
{ | ||
Message = 1, | ||
Report = 2, | ||
} | ||
} |
Oops, something went wrong.