Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add otcv8 features to appsettings.json #630

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
using NeoServer.Networking.Packets.Outgoing.Item;
using NeoServer.Networking.Packets.Outgoing.Npc;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Items;

public class ContentModifiedOnContainerEventHandler
{
private readonly ICoinTypeStore _coinTypeStore;
private readonly ClientConfiguration _clientConfiguration;
private readonly IGameServer game;

public ContentModifiedOnContainerEventHandler(IGameServer game, ICoinTypeStore coinTypeStore)
public ContentModifiedOnContainerEventHandler(IGameServer game, ICoinTypeStore coinTypeStore, ClientConfiguration clientConfiguration)
{
this.game = game;
_coinTypeStore = coinTypeStore;
_clientConfiguration = clientConfiguration;
}

public void Execute(IPlayer player, ContainerOperation operation, byte containerId, byte slotIndex, IItem item)
Expand All @@ -32,13 +35,13 @@ public void Execute(IPlayer player, ContainerOperation operation, byte container
case ContainerOperation.ItemAdded:
connection.OutgoingPackets.Enqueue(new AddItemContainerPacket(containerId, item)
{
ShowItemDescription = connection.OtcV8Version > 0
ShowItemDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});
break;
case ContainerOperation.ItemUpdated:
connection.OutgoingPackets.Enqueue(new UpdateItemContainerPacket(containerId, slotIndex, item)
{
ShowItemDescription = connection.OtcV8Version > 0
ShowItemDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
using NeoServer.Game.Common.Contracts.Items.Types.Containers;
using NeoServer.Networking.Packets.Outgoing.Player;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Player.Containers;

public class PlayerOpenedContainerEventHandler
{
private readonly IGameServer game;
private readonly ClientConfiguration _clientConfiguration;

public PlayerOpenedContainerEventHandler(IGameServer game)
public PlayerOpenedContainerEventHandler(IGameServer game, ClientConfiguration clientConfiguration)
{
this.game = game;
_clientConfiguration = clientConfiguration;
}

public void Execute(IPlayer player, byte containerId, IContainer container)
Expand All @@ -25,7 +28,7 @@ private void SendContainerPacket(IPlayer player, byte containerId, IContainer co

connection.OutgoingPackets.Enqueue(new OpenContainerPacket(container, containerId)
{
WithDescription = connection.OtcV8Version > 0
WithDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});
connection.Send();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
using NeoServer.Networking.Packets.Outgoing.Npc;
using NeoServer.Networking.Packets.Outgoing.Player;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Player;

public class PlayerChangedInventoryEventHandler
{
private readonly ICoinTypeStore _coinTypeStore;
private readonly ClientConfiguration _clientConfiguration;
private readonly IGameServer game;

public PlayerChangedInventoryEventHandler(IGameServer game, ICoinTypeStore coinTypeStore)
public PlayerChangedInventoryEventHandler(IGameServer game, ICoinTypeStore coinTypeStore, ClientConfiguration clientConfiguration)
{
this.game = game;
_coinTypeStore = coinTypeStore;
_clientConfiguration = clientConfiguration;
}

public void Execute(IInventory inventory, IItem item, Slot slot, byte amount = 1)
Expand All @@ -30,7 +33,7 @@ public void Execute(IInventory inventory, IItem item, Slot slot, byte amount = 1

connection.OutgoingPackets.Enqueue(new PlayerInventoryItemPacket(player.Inventory, slot)
{
ShowItemDescription = connection.OtcV8Version > 0
ShowItemDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});

if (player.Shopping)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
using NeoServer.Networking.Packets.Outgoing.Player;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Common.Contracts.Network;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Player;

public class PlayerSelfAppearOnMapEventHandler : IEventHandler
{
private readonly IGameServer game;
private readonly IMap map;
private readonly IGameServer _game;
private readonly ClientConfiguration _clientConfiguration;
private readonly IMap _map;

public PlayerSelfAppearOnMapEventHandler(IMap map, IGameServer game)
public PlayerSelfAppearOnMapEventHandler(IMap map, IGameServer game, ClientConfiguration clientConfiguration)
{
this.map = map;
this.game = game;
_map = map;
_game = game;
_clientConfiguration = clientConfiguration;
}

public void Execute(IWalkableCreature creature)
Expand All @@ -29,24 +32,24 @@ public void Execute(IWalkableCreature creature)

if (creature is not IPlayer player) return;

if (!game.CreatureManager.GetPlayerConnection(creature.CreatureId, out var connection)) return;
if (!_game.CreatureManager.GetPlayerConnection(creature.CreatureId, out var connection)) return;

SendPacketsToPlayer(player, connection);
}

private void SendPacketsToPlayer(IPlayer player, IConnection connection)
{
connection.OutgoingPackets.Enqueue(new SelfAppearPacket(player));
connection.OutgoingPackets.Enqueue(new MapDescriptionPacket(player, map));
connection.OutgoingPackets.Enqueue(new MapDescriptionPacket(player, _map));
connection.OutgoingPackets.Enqueue(new MagicEffectPacket(player.Location, EffectT.BubbleBlue));
connection.OutgoingPackets.Enqueue(new PlayerInventoryPacket(player.Inventory)
{
ShowItemDescription = connection.OtcV8Version > 0
ShowItemDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});
connection.OutgoingPackets.Enqueue(new PlayerStatusPacket(player));
connection.OutgoingPackets.Enqueue(new PlayerSkillsPacket(player));

connection.OutgoingPackets.Enqueue(new WorldLightPacket(game.LightLevel, game.LightColor));
connection.OutgoingPackets.Enqueue(new WorldLightPacket(_game.LightLevel, _game.LightColor));

connection.OutgoingPackets.Enqueue(new CreatureLightPacket(player));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
using NeoServer.Networking.Packets.Outgoing.Trade;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Common.Contracts.Network;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Player.Trade;

public class TradeRequestedEventHandler : IEventHandler
{
private readonly IGameServer _gameServer;
private readonly ClientConfiguration _clientConfiguration;

public TradeRequestedEventHandler(IGameServer gameServer)
public TradeRequestedEventHandler(IGameServer gameServer, ClientConfiguration clientConfiguration)
{
_gameServer = gameServer;
_clientConfiguration = clientConfiguration;
}

public void Execute(TradeRequest tradeRequest)
Expand All @@ -29,7 +32,7 @@ public void Execute(TradeRequest tradeRequest)
playerRequestingConnection.OutgoingPackets.Enqueue(new TradeRequestPacket(tradeRequest.PlayerRequesting.Name,
tradeRequest.Items)
{
ShowItemDescription = playerRequestingConnection.OtcV8Version > 0
ShowItemDescription = playerRequestingConnection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});

SendTradeMessage(tradeRequest, playerRequestedConnection);
Expand All @@ -49,7 +52,7 @@ private static void SendTradeMessage(TradeRequest tradeRequest, IConnection play
TextMessageOutgoingType.Small));
}

private static void SendAcknowledgeTradeToBothPlayers(TradeRequest tradeRequest,
private void SendAcknowledgeTradeToBothPlayers(TradeRequest tradeRequest,
IConnection playerRequestingConnection,
IConnection playerRequestedConnection)
{
Expand All @@ -60,13 +63,13 @@ private static void SendAcknowledgeTradeToBothPlayers(TradeRequest tradeRequest,
playerRequestingConnection.OutgoingPackets.Enqueue(new TradeRequestPacket(tradeRequest.PlayerRequested.Name,
items, true)
{
ShowItemDescription = playerRequestingConnection.OtcV8Version > 0
ShowItemDescription = playerRequestingConnection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});

playerRequestedConnection.OutgoingPackets.Enqueue(new TradeRequestPacket(tradeRequest.PlayerRequesting.Name,
tradeRequest.Items, true)
{
ShowItemDescription = playerRequestedConnection.OtcV8Version > 0
ShowItemDescription = playerRequestedConnection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@
string HostnameOverride,
string Facility)
{
}

public record ClientConfiguration(ClientConfiguration.OtcV8Configuration OtcV8)

Check notice on line 44 in src/ApplicationServer/NeoServer.Server/Configurations/ServerConfiguration.cs

View check run for this annotation

codefactor.io / CodeFactor

src/ApplicationServer/NeoServer.Server/Configurations/ServerConfiguration.cs#L44

File may only contain a single type. (SA1402)
{
public record OtcV8Configuration(
bool GameExtendedOpcode,
bool GameEnvironmentEffect,
bool GameExtendedClientPing,
bool GameItemTooltip);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static Slot Get(IPlayer player, IItem itemToAdd, IItem itemToBeRemoved)
var existingItemOnSlot = player.Inventory[itemToAdd.Metadata.BodyPosition];

if (itemToAdd.IsCumulative &&
existingItemOnSlot.ServerId == itemToAdd.ServerId &&
existingItemOnSlot?.ServerId == itemToAdd.ServerId &&
itemToAdd.Amount + existingItemOnSlot.Amount == 100) return itemToAdd.Metadata.BodyPosition;

var slotDestination = GetTwoHandedWeaponSlotDestination(player, itemToAdd, itemToBeRemoved);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ public class PlayerLogInHandler : PacketHandler
private readonly IGameServer _game;
private readonly PlayerLogInCommand _playerLogInCommand;
private readonly PlayerLogOutCommand _playerLogOutCommand;
private readonly ClientConfiguration _clientConfiguration;
private readonly ServerConfiguration _serverConfiguration;

public PlayerLogInHandler(IAccountRepository repositoryNeo,
IGameServer game, ServerConfiguration serverConfiguration, PlayerLogInCommand playerLogInCommand,
PlayerLogOutCommand playerLogOutCommand)
PlayerLogOutCommand playerLogOutCommand, ClientConfiguration clientConfiguration)
{
_accountRepository = repositoryNeo;
_game = game;
_serverConfiguration = serverConfiguration;
_playerLogInCommand = playerLogInCommand;
_playerLogOutCommand = playerLogOutCommand;
_clientConfiguration = clientConfiguration;
}

public override void HandleMessage(IReadOnlyNetworkMessage message, IConnection connection)
Expand Down Expand Up @@ -89,7 +91,13 @@ private async Task Connect(IConnection connection, PlayerLogInPacket packet)

if (packet.OtcV8Version > 0 || packet.OperatingSystem >= OperatingSystem.OtcLinux)
{
if (packet.OtcV8Version > 0) connection.Send(new FeaturesPacket());
if (packet.OtcV8Version > 0) connection.Send(new FeaturesPacket
{
GameEnvironmentEffect = _clientConfiguration.OtcV8.GameEnvironmentEffect,
GameExtendedOpcode = _clientConfiguration.OtcV8.GameExtendedOpcode,
GameExtendedClientPing = _clientConfiguration.OtcV8.GameExtendedClientPing,
GameItemTooltip = _clientConfiguration.OtcV8.GameItemTooltip
});
connection.Send(new OpcodeMessagePacket());
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void AddItem(IItem item, bool showItemDescription = false)
return;

AddBytes(item.GetRaw().ToArray());

if (showItemDescription)
{
AddString("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,35 @@ namespace NeoServer.Networking.Packets.Outgoing.Custom;

public class FeaturesPacket : OutgoingPacket
{
public required bool GameExtendedOpcode { get; init; }
public required bool GameEnvironmentEffect { get; init; }
public required bool GameExtendedClientPing { get; init; }
public required bool GameItemTooltip { get; init; }
public override void WriteToMessage(INetworkMessage message)
{
message.AddByte(0x43);
message.AddUInt16(4);

var features = new Dictionary<byte, bool>
{
[80] = true,
[13] = false,
[25] = true,
[93] = true
[(byte)Feature.GameExtendedOpcode] = GameExtendedOpcode,
[(byte)Feature.GameEnvironmentEffect] = GameEnvironmentEffect,
[(byte)Feature.GameExtendedClientPing] = GameExtendedClientPing,
[(byte)Feature.GameItemTooltip] = GameItemTooltip
};

foreach (var feature in features)
{
message.AddByte(feature.Key);
message.AddByte((byte)(feature.Value ? 1 : 0));
}
}

private enum Feature : byte
{
GameExtendedOpcode = 80,
GameEnvironmentEffect = 13,
GameExtendedClientPing = 25,
GameItemTooltip = 93
}
}
3 changes: 3 additions & 0 deletions src/Standalone/IoC/Modules/ConfigurationInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ public static IServiceCollection AddConfigurations(this IServiceCollection build
new(0, null, null, null, string.Empty, string.Empty, string.Empty, 7171, 7172, new SaveConfiguration(3600));
GameConfiguration gameConfiguration = new();
LogConfiguration logConfiguration = new(null);
ClientConfiguration clientConfiguration = new(null);

configuration.GetSection("server").Bind(serverConfiguration);
configuration.GetSection("game").Bind(gameConfiguration);
configuration.GetSection("log").Bind(logConfiguration);
configuration.GetSection("client").Bind(clientConfiguration);

LoadEnvironmentVariables(ref serverConfiguration);

builder.AddSingleton(serverConfiguration);
builder.AddSingleton(gameConfiguration);
builder.AddSingleton(logConfiguration);
builder.AddSingleton(clientConfiguration);

return builder;
}
Expand Down
8 changes: 8 additions & 0 deletions src/Standalone/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
"fishing": 1.5
}
},
"client": {
"otcv8": {
"GameExtendedOpcode": false,
"GameEnvironmentEffect": false,
"GameExtendedClientPing": true,
"GameItemTooltip": false
}
},
"database": {
"connections": {
"INMEMORY": "neo",
Expand Down
Loading