Skip to content

Commit

Permalink
Parsing incoming network commands should not instantiate ObjectGuids (#…
Browse files Browse the repository at this point in the history
…1216)

* HandleActionStackableSplitTo3D cleanup

* Container: Remove duplicate TryRemoveFromInventoryWithoutClear()

* Always fix placement positions in Container SortWorldObjectsIntoInventory

* HandleActionStackableSplitToContainer cleanup

* Inventory cleanup

* Cleanup child object management (items held in hands)

* More player inventory progress

* Remove ActionChain.AddDelayTicks() (not used, we use time based)

* Fix opcode log warning in InboundMessageManager

* HandleActionDropItem looking good on the new system

* HandleActionDropItem comments

* Fix PlayerEnterWorld exception when player has null Location

* More inventory progress

* minor cleanups

* Remove IComparable from WorldObject

Only one WorldObject per ObjectGuid can exist at a time. The normal reference comparison is fine. IComparable gives the wrong impression that a WorldObject with the same ObjectGuid can be defined/instantiated by two different objects at the same time.

* Inventory Progress

* Fix stack size bug in Developer commands that use AddWeeniesToInventory

* more inventory progress

* More split progress

* more stack progress

* Use virtual MotionPickup

* Inventory improvements

* more inventory progress

* player/npc give refactored

* Convert some obsolete inventory functions over to TryConsumeFromInventoryWithNetworking

* All inventory functions converted

* Fix item decaying explosions

* Fix player trade

* More fixes

* Fix giving partial stacks

* Fix burden limitations when picking up items

* Fix selling items

* Inventory move to fixes

* Cleanup TrySetChild

* Don't decay IsStuck objects

* Don't allow pickup of IsStuck items

* Fix moving equipped items around

* Weapons now work

* Fix player location null restore

* Add back HeritageBonuses to Player_Skills

* Fix equipment spell/dispell on equip/dequip

* Fix non-selectable wielded items from showing on the player model

* Fix wield/unwield sound for equipped items that aren't childeren

* TrySetChild should ClearChild if it's not a valid child.

* Fix missile ammo as child

* Send DeleteObject instead of PickupEvent on Dequip. This fixes disappearing weapon on relog

* Couple notes where item recovieres should go

* Hopefully this fixes the ammo being displayed incorrectly

* Couple inventory fixes

Fix death items dropping properly
Fix giving equipped items appearing in targets inventory

* Allow close container that has no viewer

* Couple more log warnings for potential lost items

* Add static methods to ObjectGuid

* Use ObjectGuid.IsPlayer instead of creating a new ObjectGuid

* ACE.Server.Network.GameAction.Actions cosmetic cleanup

* Network GameActions no longer create and pass ObjectGuids. Now they pass uints

The idea here is that incoming network packet handlers should be doing the bare minimum to parse the packet.

The handler of the action should be what determines of an ObjectGuid is needed, or a uint is sufficient.

* Network.Handlers switched from ObjectGuid -> uint

* Another instance of ObjectGuid used in the network actions removed

* More networking ObjectGuids switched to uints

* missed a file

* Attuned check removed for GiveObjecttoNPC

* Don't consume unlimited use gems

* Fix HandleDestroyBonded

* Fix destroying equipped items when consumed
  • Loading branch information
Mag-nus committed Jan 4, 2019
1 parent 8fc7104 commit 5620d0a
Show file tree
Hide file tree
Showing 96 changed files with 284 additions and 300 deletions.
10 changes: 7 additions & 3 deletions Source/ACE.Entity/ObjectGuid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public struct ObjectGuid
public static uint DynamicMin { get; } = 0x80000000;
public static uint DynamicMax { get; } = 0xFFFFFFFE; // Ends at E because uint.Max is reserved for "invalid"

public static bool IsPlayer(uint guid) { return (guid >= PlayerMin && guid <= PlayerMax); }
public static bool IsStatic(uint guid) { return (guid >= StaticObjectMin && guid <= StaticObjectMax); }
public static bool IsDynamic(uint guid) { return (guid >= DynamicMin && guid <= DynamicMax); }

public uint Full { get; }
public uint Low => Full & 0xFFFFFF;
public uint High => (Full >> 24);
Expand All @@ -42,11 +46,11 @@ public ObjectGuid(uint full)
{
Full = full;

if (Full >= PlayerMin && Full <= PlayerMax)
if (IsPlayer(full))
Type = GuidType.Player;
else if (Full >= StaticObjectMin && Full <= StaticObjectMax)
else if (IsStatic(full))
Type = GuidType.Static;
else if (Full >= DynamicMin && Full <= DynamicMax)
else if (IsDynamic(full))
Type = GuidType.Dynamic;
else
Type = GuidType.Undef;
Expand Down
2 changes: 1 addition & 1 deletion Source/ACE.Server/Command/Handlers/DeveloperCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public static void MoveTo(Session session, params string[] parameters)
WorldObject loot = WorldObjectFactory.CreateNewWorldObject(trainingWandTarget);
LootGenerationFactory.Spawn(loot, session.Player.Location.InFrontOf(distance));

session.Player.HandleActionPutItemInContainer(loot.Guid, session.Player.Guid);
session.Player.HandleActionPutItemInContainer(loot.Guid.Full, session.Player.Guid.Full);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Source/ACE.Server/Entity/ItemProfile.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using ACE.Entity;
using ACE.Entity;

namespace ACE.Server.Entity
{
public class ItemProfile
{
public uint Amount;
public ObjectGuid Guid;
public uint ObjectGuid;
public uint WeenieClassId;
}
}
5 changes: 5 additions & 0 deletions Source/ACE.Server/Entity/Landblock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ public WorldObject GetObject(ObjectGuid guid)
return null;
}

public WorldObject GetWieldedObject(uint objectGuid, bool searchAdjacents = true)
{
return GetWieldedObject(new ObjectGuid(objectGuid), searchAdjacents); // todo fix
}

/// <summary>
/// Searches this landblock (and possibly adjacents) for an ObjectGuid wielded by a creature
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace ACE.Server.Network.GameAction.Actions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using ACE.Entity;
using ACE.Server.Managers;

namespace ACE.Server.Network.GameAction.Actions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class GameActionAddChannel
public static void Handle(ClientMessage message, Session session)
{
var chatChannelID = (Channel)message.Payload.ReadUInt32();

// Probably need some IsAdvocate and IsSentinel type thing going on here as well. leaving for now
if (!session.Player.IsAdmin && !session.Player.IsArch && !session.Player.IsPsr)
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using ACE.Server.Network.Structure;

namespace ACE.Server.Network.GameAction.Actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace ACE.Server.Network.GameAction.Actions
{
public static class GameActionAddSpellFavorite
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using ACE.Entity;
using ACE.Server.Network.GameEvent.Events;

namespace ACE.Server.Network.GameAction.Actions
{
Expand All @@ -8,10 +6,10 @@ public static class GameActionAddToTrade
[GameAction(GameActionType.AddToTrade)]
public static void Handle(ClientMessage message, Session session)
{
ObjectGuid item = new ObjectGuid(message.Payload.ReadUInt32());
uint tradeSlot = message.Payload.ReadUInt32();
var itemGuid = message.Payload.ReadUInt32();
var tradeSlot = message.Payload.ReadUInt32();

session.Player.HandleActionAddToTrade(session, item, tradeSlot);
session.Player.HandleActionAddToTrade(session, itemGuid, tradeSlot);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System;

using ACE.Common.Extensions;
using ACE.Entity.Enum;
using ACE.Server.Entity;
using ACE.Server.Physics.Common;

using Position = ACE.Entity.Position;

namespace ACE.Server.Network.GameAction.Actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ACE.Entity;

namespace ACE.Server.Network.GameAction.Actions
{
Expand All @@ -7,8 +6,7 @@ public static class GameActionAllegianceBreakAllegiance
[GameAction(GameActionType.BreakAllegiance)]
public static void Handle(ClientMessage message, Session session)
{
var target = message.Payload.ReadUInt32();
var targetGuid = new ObjectGuid(target);
var targetGuid = message.Payload.ReadUInt32();

session.Player.HandleActionBreakAllegiance(targetGuid);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ACE.Entity;

namespace ACE.Server.Network.GameAction.Actions
{
Expand All @@ -7,8 +6,7 @@ public static class GameActionAllegianceSwearAllegiance
[GameAction(GameActionType.SwearAllegiance)]
public static void Handle(ClientMessage message, Session session)
{
var target = message.Payload.ReadUInt32();
var targetGuid = new ObjectGuid(target);
var targetGuid = message.Payload.ReadUInt32();

session.Player.HandleActionSwearAllegiance(targetGuid);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

using ACE.Server.Network.GameEvent.Events;

namespace ACE.Server.Network.GameAction.Actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

using ACE.Entity;

namespace ACE.Server.Network.GameAction.Actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ACE.Entity;

namespace ACE.Server.Network.GameAction.Actions
{
Expand All @@ -7,12 +6,10 @@ public static class GameActionBookPageData
[GameAction(GameActionType.BookPageData)]
public static void Handle(ClientMessage message, Session session)
{
var objectId = message.Payload.ReadUInt32();
var bookGuid = message.Payload.ReadUInt32();
var pageNum = message.Payload.ReadUInt32();

ObjectGuid guid = new ObjectGuid(objectId);

session.Player.ReadBookPage(guid, pageNum);
session.Player.ReadBookPage(bookGuid, pageNum);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using ACE.Entity;

using ACE.Server.Entity;

namespace ACE.Server.Network.GameAction.Actions
Expand All @@ -9,7 +9,7 @@ public static class GameActionBuyItems
[GameAction(GameActionType.Buy)]
public static void Handle(ClientMessage message, Session session)
{
ObjectGuid vendorId = new ObjectGuid(message.Payload.ReadUInt32());
var vendorGuid = message.Payload.ReadUInt32();

uint itemcount = message.Payload.ReadUInt32();

Expand All @@ -22,15 +22,15 @@ public static void Handle(ClientMessage message, Session session)
item.Amount = message.Payload.ReadUInt32();
// item.Amount = item.Amount & 0xFFFFFF;

item.Guid = message.Payload.ReadGuid();
item.ObjectGuid = message.Payload.ReadUInt32();
items.Add(item);
}

// curancy 0 default, if else then currancy is set other then money
uint i_alternateCurrencyID = message.Payload.ReadUInt32();

// todo: take into account other currencyIds other then assuming default
session.Player.HandleActionBuyItem(vendorId, items);
session.Player.HandleActionBuyItem(vendorGuid, items);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static void Handle(ClientMessage clientMessage, Session session)
{
var groupChatType = (Channel)clientMessage.Payload.ReadUInt32();
var message = clientMessage.Payload.ReadString16L();

switch (groupChatType)
{
case Channel.Abuse:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static void Handle(ClientMessage message, Session session)
//Close the trade window for the trade partner
target.HandleActionCloseTradeNegotiations(target.Session);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
using System.Collections.Generic;

using ACE.Entity;
using ACE.Server.Entity;

namespace ACE.Server.Network.GameAction.Actions
{
public static class GameActionCreateTinkeringTool
{
[GameAction(GameActionType.CreateTinkeringTool)]
public static void Handle(ClientMessage message, Session session)
{
ObjectGuid vendorId = new ObjectGuid(message.Payload.ReadUInt32());
var vendorGuid = message.Payload.ReadUInt32();
uint itemcount = message.Payload.ReadUInt32();

List<ObjectGuid> items = new List<ObjectGuid>();
var items = new List<uint>();

while (itemcount > 0)
{
itemcount--;
ObjectGuid item = new ObjectGuid();
item = new ObjectGuid(message.Payload.ReadUInt32());
items.Add(item);
items.Add(message.Payload.ReadUInt32());
}

session.Player.HandleTinkeringTool(items);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ACE.Server.Managers;

namespace ACE.Server.Network.GameAction.Actions
{
Expand All @@ -7,7 +6,7 @@ public static class GameActionDeclineTrade
[GameAction(GameActionType.DeclineTrade)]
public static void Handle(ClientMessage message, Session session)
{
session.Player.HandleActionDeclineTrade(session);
session.Player.HandleActionDeclineTrade(session);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace ACE.Server.Network.GameAction.Actions
{
// Death feels is less morbid then suicide as a human, used "Die" instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace ACE.Server.Network.GameAction.Actions
{
public static class GameActionDisplayPlayerConsentList
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ACE.Entity;

namespace ACE.Server.Network.GameAction.Actions
{
Expand All @@ -8,9 +7,9 @@ public static class GameActionDropItem

public static void Handle(ClientMessage message, Session session)
{
var objectGuid = new ObjectGuid(message.Payload.ReadUInt32());
var itemGuid = message.Payload.ReadUInt32();

session.Player.HandleActionDropItem(objectGuid);
session.Player.HandleActionDropItem(itemGuid);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

namespace ACE.Server.Network.GameAction.Actions
{

public static class GameActionFellowshipChangeOpenness
{
[GameAction(GameActionType.FellowshipChangeOpenness)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ACE.Common.Extensions;
using ACE.Server.Network.GameEvent.Events;
using ACE.Server.Network.GameMessages.Messages;

namespace ACE.Server.Network.GameAction.Actions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace ACE.Server.Network.GameAction.Actions
{
public class GameActionFellowshipQuit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using ACE.Entity;
using ACE.Server.WorldObjects;
using ACE.Server.Managers;

namespace ACE.Server.Network.GameAction.Actions
Expand All @@ -9,9 +7,8 @@ public static class GameActionFellowshipRecruit
[GameAction(GameActionType.FellowshipRecruit)]
public static void Handle(ClientMessage message, Session session)
{
uint newMemberId = message.Payload.ReadUInt32();
ObjectGuid newMember = new ObjectGuid(newMemberId);
Player newPlayer = PlayerManager.GetOnlinePlayer(newMemberId);
uint newMemberGuid = message.Payload.ReadUInt32();
var newPlayer = PlayerManager.GetOnlinePlayer(newMemberGuid);

session.Player.FellowshipRecruit(newPlayer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ public static class GameActionGameJoin
[GameAction(GameActionType.Join)]
public static void Handle(ClientMessage message, Session session)
{
var gameId = message.Payload.ReadGuid(); // object id of gameboard
var gameGuid = message.Payload.ReadUInt32(); // object id of gameboard
var whichTeam = message.Payload.ReadUInt32(); // expecting 0xFFFFFFFF here

Game wo = session.Player.CurrentLandblock?.GetObject(gameId) as Game;
if (wo != null)
{
wo.ActOnJoin(session.Player.Guid);
}
if (session.Player.CurrentLandblock?.GetObject(gameGuid) is Game game)
game.ActOnJoin(session.Player.Guid);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace ACE.Server.Network.GameAction.Actions
{
public static class GameActionGameQuit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace ACE.Server.Network.GameAction.Actions
{
public static class GameActionGetAndWieldItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ACE.Entity;

namespace ACE.Server.Network.GameAction.Actions
{
Expand All @@ -7,11 +6,9 @@ public static class GameActionGiveObjectRequest
[GameAction(GameActionType.GiveObjectRequest)]
public static void Handle(ClientMessage message, Session session)
{
uint targetID = message.Payload.ReadUInt32();
uint objectID = message.Payload.ReadUInt32();
uint targetGuid = message.Payload.ReadUInt32();
uint objectGuid = message.Payload.ReadUInt32();
int amount = message.Payload.ReadInt32();
ObjectGuid targetGuid = new ObjectGuid(targetID);
ObjectGuid objectGuid = new ObjectGuid(objectID);

session.Player.HandleActionGiveObjectRequest(targetGuid, objectGuid, amount);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

using ACE.Server.Network.GameEvent.Events;

namespace ACE.Server.Network.GameAction.Actions
Expand Down
Loading

0 comments on commit 5620d0a

Please sign in to comment.