Skip to content

Commit

Permalink
Merge pull request #601 from caioavidal/build
Browse files Browse the repository at this point in the history
Fix threading blocking test attribute
  • Loading branch information
caioavidal authored Dec 17, 2024
2 parents ac1985f + 91540fb commit 3a962ab
Show file tree
Hide file tree
Showing 106 changed files with 574 additions and 591 deletions.
6 changes: 3 additions & 3 deletions benchmarks/NeoServer.Benchmarks/NeoServer.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0"/>
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0"/>
<PackageReference Include="MoonSharp" Version="2.0.0"/>
<PackageReference Include="NLua" Version="1.7.3" />
<PackageReference Include="NLua" Version="1.7.3"/>
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions data/extensions/NeoServer.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="System.Collections" Version="4.3.0"/>
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="9.0.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ApplicationServer\NeoServer.Server.Contracts\NeoServer.Server.Common.csproj"/>
Expand All @@ -24,7 +24,7 @@
<ProjectReference Include="..\..\src\ApplicationServer\NeoServer.Server.Commands\NeoServer.Server.Commands.csproj"/>
<ProjectReference Include="..\..\src\ApplicationServer\NeoServer.Server.Contracts\NeoServer.Server.Common.csproj"/>
<ProjectReference Include="..\..\src\ApplicationServer\NeoServer.Server.Events\NeoServer.Server.Events.csproj"/>
<ProjectReference Include="..\..\src\ApplicationServer\NeoServer.Server.Routines\NeoServer.Server.Routines.csproj" />
<ProjectReference Include="..\..\src\ApplicationServer\NeoServer.Server.Routines\NeoServer.Server.Routines.csproj"/>
<ProjectReference Include="..\..\src\ApplicationServer\NeoServer.Server\NeoServer.Server.csproj"/>
</ItemGroup>
<ItemGroup>
Expand Down
75 changes: 37 additions & 38 deletions data/extensions/Spells/Commands/BroadcastCommand.cs
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
using NeoServer.Game.Combat.Spells;
using System;
using System.Text.RegularExpressions;
using NeoServer.Game.Combat.Spells;
using NeoServer.Game.Common;
using NeoServer.Game.Common.Contracts.Creatures;
using NeoServer.Networking.Packets.Outgoing;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Helpers;

using System;
using System.Text.RegularExpressions;
namespace NeoServer.Extensions.Spells.Commands;

namespace NeoServer.Extensions.Spells.Commands
public class BroadcastCommand : CommandSpell
{
public class BroadcastCommand : CommandSpell
public override bool OnCast(ICombatActor actor, string words, out InvalidOperation error)
{
public override bool OnCast(ICombatActor actor, string words, out InvalidOperation error)
var ctx = IoC.GetInstance<IGameCreatureManager>();

if (Params.Length > 0)
{
var ctx = IoC.GetInstance<IGameCreatureManager>();

if (Params.Length > 0)
var regex = new Regex("^(\\w+).\"(.+)\"$", RegexOptions.Compiled, TimeSpan.FromSeconds(1));
var match = regex.Match(Params[0].ToString());

if (match.Groups.Count == 3)
{
var regex = new Regex("^(\\w+).\"(.+)\"$", RegexOptions.Compiled, TimeSpan.FromSeconds(1));
var match = regex.Match(Params[0].ToString());
var (color, message) = (match.Groups[1].Value, match.Groups[2].Value);

if (match.Groups.Count == 3)
foreach (var player in ctx.GetAllLoggedPlayers())
{
var (color, message) = (match.Groups[1].Value, match.Groups[2].Value);
if (player is null)
continue;

foreach (var player in ctx.GetAllLoggedPlayers())
{
if (player is null)
continue;
if (ctx.GetPlayerConnection(player.CreatureId, out var connection) is false) continue;

if (ctx.GetPlayerConnection(player.CreatureId, out var connection) is false) continue;

connection.OutgoingPackets.Enqueue(new TextMessagePacket(message, GetTextMessageOutgoingTypeFromColor(color)));
connection.Send();
}

error = InvalidOperation.None;
return true;
connection.OutgoingPackets.Enqueue(new TextMessagePacket(message,
GetTextMessageOutgoingTypeFromColor(color)));
connection.Send();
}
}

error = InvalidOperation.NotPossible;
return false;
error = InvalidOperation.None;
return true;
}
}

private TextMessageOutgoingType GetTextMessageOutgoingTypeFromColor(string color)
error = InvalidOperation.NotPossible;
return false;
}

private TextMessageOutgoingType GetTextMessageOutgoingTypeFromColor(string color)
{
return color switch
{
return color switch
{
"white" => TextMessageOutgoingType.MESSAGE_EVENT_LEVEL_CHANGE,
"red" => TextMessageOutgoingType.MESSAGE_STATUS_WARNING,
"green" => TextMessageOutgoingType.Description,
_ => TextMessageOutgoingType.Description
};
}
"white" => TextMessageOutgoingType.MESSAGE_EVENT_LEVEL_CHANGE,
"red" => TextMessageOutgoingType.MESSAGE_STATUS_WARNING,
"green" => TextMessageOutgoingType.Description,
_ => TextMessageOutgoingType.Description
};
}
}
}
68 changes: 34 additions & 34 deletions data/extensions/Spells/Commands/InfoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,43 @@ public class InfoCommand : CommandSpell
{
public override bool OnCast(ICombatActor actor, string words, out InvalidOperation error)
{
error = InvalidOperation.NotPossible;

if (Params.Length != 1)
error = InvalidOperation.NotPossible;

if (Params.Length != 1)
return false;

var ctx = IoC.GetInstance<IGameCreatureManager>();
ctx.TryGetPlayer(Params[0].ToString(), out var target);

if (target is null)
return false;

var ctx = IoC.GetInstance<IGameCreatureManager>();
ctx.TryGetPlayer(Params[0].ToString(), out var target);

if (target is null)
return false;

var info = CreateItemInfo();

var message =
$"""
AccountId: {target.AccountId}
Position: {target.Location.X}, {target.Location.Y}, {target.Location.Z}
Capacity: {target.TotalCapacity}
PremiumTime: {target.PremiumTime}
Level: {target.Level}
Skills:
{target.Skills.Where(item => item.Key != SkillType.Level).Select(Item => " * " + Item.Key + ": " + Item.Value.Level + "\n").Aggregate((a, b) => a + b)}
""";

var window = new ListCommandsCommand.TextWindow(info, target.Location, message);
var serverConfiguration = IoC.GetInstance<ServerConfiguration>();

window.WrittenBy = $"{serverConfiguration.ServerName} - SERVER";
window.WrittenOn = DateTime.Now;

var player = actor as IPlayer;

player.Read(window);

return true;
var info = CreateItemInfo();

var message =
$"""
AccountId: {target.AccountId}
Position: {target.Location.X}, {target.Location.Y}, {target.Location.Z}
Capacity: {target.TotalCapacity}
PremiumTime: {target.PremiumTime}
Level: {target.Level}
Skills:
{target.Skills.Where(item => item.Key != SkillType.Level).Select(Item => " * " + Item.Key + ": " + Item.Value.Level + "\n").Aggregate((a, b) => a + b)}
""";

var window = new ListCommandsCommand.TextWindow(info, target.Location, message);
var serverConfiguration = IoC.GetInstance<ServerConfiguration>();

window.WrittenBy = $"{serverConfiguration.ServerName} - SERVER";
window.WrittenOn = DateTime.Now;

var player = actor as IPlayer;

player.Read(window);

return true;
}

private static IItemType CreateItemInfo()
{
var item = new ItemType();
Expand Down
4 changes: 2 additions & 2 deletions data/extensions/Spells/Commands/ItemCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ private bool CreateItem(ICombatActor actor, IItem item)
if (actor is not IPlayer player) return false;

var itemCanBeAddedToSlot = item.Metadata.BodyPosition != Slot.None &&
(item.Metadata.BodyPosition == Slot.TwoHanded && !player.Inventory.HasShield &&
!player.Inventory.IsUsingWeapon)
item.Metadata.BodyPosition == Slot.TwoHanded && !player.Inventory.HasShield &&
!player.Inventory.IsUsingWeapon
&& player.Inventory[item.Metadata.BodyPosition] is null;

if (itemCanBeAddedToSlot)
Expand Down
2 changes: 1 addition & 1 deletion data/extensions/Spells/Commands/ListCommandsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static string BuildTextFromSpells(List<IDictionary<string, object>> spel
lines.Add($"{words} {name}");
continue;
}

lines.Add($"{words} {name} - {description}");
}

Expand Down
17 changes: 8 additions & 9 deletions data/extensions/Spells/Commands/SpyPlayerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,24 @@ public override bool OnCast(ICombatActor actor, string words, out InvalidOperati
return false;

var stringBuilder = new StringBuilder(1000);

stringBuilder.AppendLine($"*** Name: {player.Name} *****");

foreach (var inventoryDressingItem in player.Inventory.DressingItems)
{
stringBuilder.AppendLine($"ClientId: {inventoryDressingItem.Metadata.ClientId}-{inventoryDressingItem.FullName}");
}
stringBuilder.AppendLine(
$"ClientId: {inventoryDressingItem.Metadata.ClientId}-{inventoryDressingItem.FullName}");

var item = new ItemType();
item.SetClientId(2821);

var window = new ListCommandsCommand.TextWindow(item, player.Location, stringBuilder.ToString());
var serverConfiguration = IoC.GetInstance<ServerConfiguration>();

window.WrittenBy = $"{serverConfiguration.ServerName} - SERVER";
window.WrittenOn = DateTime.Now;

player.Read(window);

return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using NeoServer.Game.Common.Contracts.Creatures;
using NeoServer.Game.Common.Location.Structs;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Common.Contracts.Tasks;
using NeoServer.Server.Tasks;

Expand All @@ -25,9 +24,11 @@ public void WalkTo(IPlayer player, Action action, Location toLocation, bool seco
player.WalkTo(toLocation, CallBack);
return;

void CallBack(ICreature _) =>
void CallBack(ICreature _)
{
_scheduler.AddEvent(
new SchedulerEvent(player.StepDelay, () => WalkTo(player, action, toLocation, true)));
}
}

action?.Invoke();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog" Version="4.2.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@ public ItemFinderService(HotkeyService hotkeyService, IGameServer gameServer)

public IItem Find(IPlayer player, Location itemLocation, ushort clientId)
{
if (itemLocation.IsHotkey)
{
return _hotkeyService.GetItem(player, clientId);
}
if (itemLocation.IsHotkey) return _hotkeyService.GetItem(player, clientId);

if (itemLocation.Type == LocationType.Ground)
{
return _gameServer.Map[itemLocation] is not { } tile ? null : tile.TopItemOnStack;
}

if (itemLocation.Slot == Slot.Backpack)
{
Expand All @@ -44,10 +39,7 @@ public IItem Find(IPlayer player, Location itemLocation, ushort clientId)
return item;
}

if (itemLocation.Type == LocationType.Slot)
{
return player.Inventory[itemLocation.Slot];
}
if (itemLocation.Type == LocationType.Slot) return player.Inventory[itemLocation.Slot];

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace NeoServer.Server.Commands.Trade;
public class TradeRequestCommand : ICommand
{
private readonly IGameCreatureManager _creatureManager;
private readonly SafeTradeSystem _tradeSystem;
private readonly IMap _map;
private readonly SafeTradeSystem _tradeSystem;

public TradeRequestCommand(SafeTradeSystem tradeSystem, IGameCreatureManager creatureManager, IMap map)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageReference Include="System.Reactive.Linq" Version="6.0.1" />
<PackageReference Include="System.Reactive.Linq" Version="6.0.1"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog" Version="4.2.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ namespace NeoServer.Server.Events.Items;

public class ItemUsedOnTileEventHandler
{
private readonly IMap _map;
private readonly IGameCreatureManager _creatureManager;
private readonly IMap _map;

public ItemUsedOnTileEventHandler(IGameCreatureManager creatureManager, IMap map)
{
_creatureManager = creatureManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog" Version="4.2.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 3a962ab

Please sign in to comment.