Commit graph

56 commits

Author SHA1 Message Date
Mag-nus
c2ed2eab9a
Performance improvements with the help of Claude (#4472)
* Network performance improvements, limit boxing

* Polygon comment out redundant test code

* Transition remove duplicate Init()

* Creature_BodyPart and Monster_Melee comment out unused var
2026-08-03 11:48:37 +00:00
Mag-nus
e2e88b7e87
Network perf improvements (#4205)
* initial

* More networking improvements
2024-07-23 11:13:56 +00:00
Mag-nus
b8e039587a
Move packet retransmit to packetlog and reduce to debug (#4108) 2024-03-13 02:38:55 +00:00
Mag-nus
9d70b48380
Improve logging overhead by fixing string interpolation (#4107)
* First batch

* Second batch

* another batch

* last batch hopefully

* fix
2024-03-13 02:38:39 +00:00
Mag-nus
bb8e6a9ac3
Improvements to help garbage collection (#4104)
* Enum ToSentence improvements

* Network.EnqueueSend improvements

* Improve SerializePhysicsData

* GameMessage improvements

* GameEventMessage updates

* more initial sizes

* Few more GameMessages

* few more
2024-03-13 02:37:40 +00:00
Mag-nus
5639fac2d7
improving network resiliency (#4074) 2023-12-25 03:20:38 +00:00
Ty Conner
c09bea0358
Adjust connection flow (#3974)
* Adjust connection flow

Changed connection flow to better match retail PCAPs

* Update NetworkSession.cs

* endpoint split

* Update NetworkSession.cs

* Update NetworkSession.cs

* Update DeveloperCommands.cs

* Update DeveloperCommands.cs

* Update NetworkSession.cs

* Update NetworkSession.cs

* Update SessionConnectionData.cs

* Update NetworkSession.cs

* Update DeveloperCommands.cs

* Update NetworkSession.cs

* Update ConnectionListener.cs

* Update ConnectionListener.cs
2023-06-09 12:33:04 -04:00
Mag-nus
c718c10f29
Improve EnqueueSend (#3500)
Most uses of this function are a single message.

This removes the overhead of GroupBy() and ToList() for every call at the expense of retaking the lock in cases where multiple messages of the same group are sent.
2021-03-16 06:39:01 -05:00
Mag-nus
d87a5fce90
NetworkSession Sequence Exception Fix (#3367)
race condition between listener thread and NetworkManager parallel threads
2020-11-19 15:36:49 -06:00
Mag-nus
8d5914a905
PacketRejectRetransmit (#3312) 2020-10-26 20:03:01 -05:00
gmriggs
ec9284ba1e
adding PacketHeader.RejectRetransmit response for uncached packets (#3309)
* test

* finalizing
2020-10-18 05:47:24 -04:00
Mag-nus
bf884c9f34
NetworkSessionExceptionFix (#3280)
This fixes:  ERROR (ACE.Server.Program) System.InvalidOperationException: Sequence contains no elements
2020-10-09 07:26:27 -05:00
Mag-nus
48ef6b76cb
Make sure UIQueue NetworkMessages are sent in order (#3102)
This fixes out of order NPC emotes, like this one:

https://github.com/ACEmulator/ACE-World-16PY-Patches/blob/master/Database/Patches/2008-08-AncientPowers/9%20WeenieDefaults/Creature/Human/38388%20Kirina%20of%20the%20Celestial%20Hand.sql#L116
2020-08-09 19:01:33 -05:00
fartwhif
762dd072ec
fixed bug allowing a corrupt or malformed packet to crash the server when the fragment parser tries to read past the end of the data (#2903)
simplified CryptoSystem
removed unused counter from ISAAC
simplified client packet CRC verification call stack
2020-04-11 12:54:25 -04:00
fartwhif
0165f87046
limit the number of sequence IDs per S2C NAK packet: this should alleviate the problem of the client expecting huge packets and crashing (#2816)
fix possible problem with a C2S packet sequence received that is previous to the current position.
NAK packets aren't re-transmitted in AC protocol, don't store them in S2C cache
2020-03-14 01:06:45 -04:00
gmriggs
5c9f4d2f49
verify TimeSync (#2772) 2020-03-06 22:24:34 -05:00
fartwhif
22bb6143c6 remove network test helpers (#2603) 2020-01-19 12:52:57 -05:00
Mag-nus
13dc239be1
More verbose retransmit logging (#2591) 2020-01-06 07:57:58 -06:00
Mag-nus
fea5014c13
Network improvements (#2515)
* Fartwhifs "Removing unused pattern from CryptoSystem for slightly better performance." PR

* PacketHeader Improved Efficiency

* Improve ClientPacket.ParsePacketData() efficiency

* Packet.Data does not need to be disposed()

See here: ac99a1b716/src/Common/src/CoreLib/System/IO/MemoryStream.cs (L124)

Disposing simply sets _isOpen, _writable, _expandable to false. It doesn't even release the reference to the buffer passed in to the ctor.

* WIP

* revert the RangeAdvance stuff

* More improvements

* More improvements

* More naming improvements
2019-12-30 19:10:12 -06:00
fartwhif
2b606d505c Removing unused pattern from CryptoSystem for slightly better performance. (#2398)
* Adding .NET IDisposable pattern to CryptoSystem
Removing unused pattern from CryptoSystem for better performance.
Slightly improved CryptoSystem documentation

* convert IDisposable pattern to custom function
add cleanup for stream cipher
2019-12-21 08:29:05 -05:00
fartwhif
63dbd428a0 fixed an bug that occurs when client sends only a cleartext CRC NAK and ACE ignoring them, switch from honoring only ciphertext CRC NAK to honoring only cleartext CRC NAK (#2541) 2019-12-16 12:06:22 -05:00
gmriggs
750ece71ef
Fixing some gaps for DST (#2370) 2019-10-29 12:59:48 -04:00
Steven Snyder
4e32b9aae4 Fix for string buffer overrun / leaked memory in packet logger (#2149)
* Updated database instructions in README.md to prevent an error

The instructions in README.md now ask the reader to set up `ace_world`
with WorldBase.sql before applying incremental updates. This prevents more
recent `ace_shard` updates from producing an error due to a failed join.

* BuildPacketString() now pays heed to the startPosition and bytesToOutput arguments

* Packing debugging output no longer overflows the segment of the buffer pool allocated to the packet
2019-07-22 01:41:59 -04:00
Mag-nus
f1d325b1fc
Add multi-homed internet support (#2039) 2019-06-25 18:33:42 -05:00
Mag-nus
1b0043a691
NetworkSession.cachedPackets pruning (#1981)
* cachedPacketRetentionTime

* Remove the redundant SessionConnectionData.ServerTime

* Fix ushort wrapping

* 60 -> 120
2019-06-10 05:42:04 -05:00
Mag-nus
218f717c55
Move network/packet work from WorldManager to NetworkManager (#1929)
* Move network/packet work from WorldManager to NetworkManager

* merge fix
2019-06-02 21:04:15 -05:00
Mag-nus
7729174010
Release NetworkSession resources when a session drops (#1834)
This is a simple patch to help CE mem usage. The proper fix is to funnel NetworkSession work through Session, so that Session can manage it's state directly.

What is happening now, and can/will happen in the future, is that Player references are being held, and thus, their Session and NetworkSession objects aren't being released.

Even after a Session drops, work can still be enqueued onto NetworkSession through ActionChains and other means. This PR will now ignore that work. Currently, in master, that work is received and held indefinitely (until Player/Session are released)

This also fixes the case where NetworkSession work was being enqueued after a session dropped, but before the Player was fully logged out of the world. Now, that work will be ignored.
2019-05-01 07:55:44 -05:00
fartwhif
f60b7a6a17
sequence validation and negative response (#1791) 2019-04-23 21:47:45 -04:00
Mag-nus
171471264a
Network Stability Improvements (#1741)
* Network Stability Improvements

It was possible for packetQueue to get corrupt when clients request packet retransmits. At that point, multiple threads could be enqueing work.

This adds slight overhead by converting it to a ConcurrentQueue, but, should also (hopefully) fix the "corrupt sessions" issue people were seeing.

This should also fix the exception that was reported in NetowrkSession.FlushPackets()

* improve comment
2019-04-15 20:19:49 -05:00
Mag-nus
5ede969f3d
Fix session timeout values (basically adds 45s to timeout value) (#1740) 2019-04-15 20:19:39 -05:00
fartwhif
ce2b010e69
session termination and boot command enhancement (#1653)
improved session termination and logging
improved command parameter parsing
session termination due to network problems should not be sending anything
refactor session termination terminology
moved textual session termination reasons to the same file as the termination reasons enum
added optional reason to boot command
boot axe man, char, griefing and spamming chat
boot 0x5000000C, iid
boot 1342177292, iid
2019-04-12 18:07:45 -04:00
Mag-nus
8a5e113e4c
MemoryStream.ToArray() -> GetBuffer() (#1689)
* MemoryStream.ToArray() -> GetBuffer()

This is the partial implementation of the previous PR.

There is still one more MemoryStream.ToArray() in the code, but, the usage of MemoryStream in that area is a bit complex and will take some further work to get away from ToArray()

* This should fix the CreateReadyToSendPacket exception on retransmit
2019-04-11 08:09:28 -05:00
fartwhif
90e328660c move order-insensitive items earlier in packet processing pipeline (#1647)
* moved order-insensitive "half-processing" earlier in packet processing pipeline
added adaptive resiliency to CryptoSystem

* undo untested assumption
2019-04-06 00:52:07 -05:00
fartwhif
10498076d0 network stability (#1511)
* fixed bug causing disconnects due to NAK requests being dropped.
added asynchronous verification of encrypted CRCs
added checksum caching to ClientPacket
removed "generational ISAAC" debugging tools
fixed a bug causing session to enter an unspecified state when the connect request packet sent to the client was corrupted in transit
added handling of trusted packet with ClientSentNetErrorDisconnect flag
fixed bug during handshake causing defunct session to linger
fixed AccountSelectCallback was being called in both the try and catch sections of a try/catch block leading to crashes whenever a bad handshake occurs
implemented parsing of optional "flow" header data
added more network logging

* added packetLog to WorldManager
removed pre-processor definition NETDIAG and directives
2019-03-10 17:40:23 -04:00
Mag-nus
f1060089df
Account for all sitautions (#1359) 2019-01-23 21:21:49 -06:00
Mag-nus
d3e1c9b13e Network crash fix (#1353)
* temp fix for buffer too small

* Revert "temp fix for buffer too small"

This reverts commit f4c770d612.

* fix
2019-01-23 09:28:09 -06:00
Mag-nus
a7a2fd33ee
Network efficiency improvements (#1313)
* Remove RunActions() from IActor interface

* make Landblock an IActor

* Make WorldManager an IActor

* Remove AgressiveInlinding from ActionQueue.RunActions (Helps break up profiling results)

* Fix WorldManager EnqueueAction

* Split WorldObject ActionQueues into Landblock and Player

* Switch Landblock from o(n) to o(1)

* Loop in reverse order, no need to create a new list using FindAll.

* use an ArrayPool<byte> to conserve resources and improve performance

* cosmetic

* Update/Tick Age every 7 seconds for Players (Before, this was consuming 1% CPU)

* More packet transmission improvements
2019-01-22 22:09:59 -06:00
gmriggs
796bc35411
Improved EmoteManager timing (#1273)
* Improved EmoteManager timing

* Fix giving pyreals to TC

* Update SetSanctuaryPosition
2019-01-15 16:31:52 -05:00
Mag-nus
45fc2ad283
Various improvements resulting from excessive load testing (#1136)
* Add thread safety to ObjectMaint.ServerObjects

WorldObjects can be created by any thread, and, they update this collection

* Remove "tried to appraise object, couldn't find it" warning.

* Check for null landblock before trying to remove on logoff

* Cleanup more session edge cases

* Cleanup SocketManager

No need to use a list. It's a fixed array.

* Vector3 is a struct. It doesn't need to be member copied like a class.

* .NET core has native Vector3.Normalize that is 3x as fast

b90c49ce3c/src/System.Numerics.Vectors/src/System/Numerics/Vector3.cs (L204)

* Vector3.LengthSquared2D improvement

It's 3x faster just to perform the low level operation than to instantiate a new Vector2 and call that objects method.

b90c49ce3c/src/System.Numerics.Vectors/src/System/Numerics/Vector2.cs (L124)

* Vector3 IsEqual extension removed. Using == is 4x faster

* Vector3 IsMoved extension replaced with != (it's 4x faster)

* InterpolationManager PositionQueue should be a LinkedList

* Change a couple enum .HasFlag to & != 0 in performance critical areas

This just improves performance in debug mode when the optimize flag isn't checked.

* Use LinkedList.First != null instead of .Count > 0

* Revert "Use LinkedList.First != null instead of .Count > 0"

This reverts commit c643b73910.
2018-12-13 07:19:50 -06:00
Mag-nus
ac156bd19f
This fixes ServerPackets that were built with too many fragments, and thus too large (#1131)
Because of this bug, ACE has been sending packets with no size limit. While this works well on a local network, it could have had reliablity issues over a WAN.

ServerPacket has a MaxPacketSize of 464. This stems from the original days of ACE.

I suspect this is the maximum size of AC related data we can stuff into a UDP packet (before overhead is added) to keep the UDP packet sent over the WAN in a single fragment.

If we increase this value, it could reduce some server load and byte overhead, but, if a single fragment of the UDP is lost, all fragments will be lost and have to be resent.
2018-12-10 20:44:30 -06:00
fartwhif
edd269bcbf fixing: some clients unable to connect via WAN (#1122)
* it allows clients to connect from behind a specific rare firewall configuration
not sure which of these hacks is/are needed

* fixed a connection issue for some client firewalls guarding clients connecting over WAN by changing port strategy from two unidirectional ports to a single bidirectional port with the exception of the connect response packet
bolstered security by using random initialization vectors for the CRC stream ciphers instead of a constant and known IV
changed to using a random cookie for the three-way handshake, this adds a certain effectiveness of DoS attack, but is needed for the single bidirectional port strategy

* test for correct listener

* revert some minor changes
documentation changes

* check for same IP Address

* removed dependency of Physics.Common.Random from network code
using bare System.Random constructor without locking since the network processor is single threaded
documentation

* moved CICMDCommand conditional to listener 1 path
documentation

* use sessionLock for iteration of sessionMap
consolidate ban TO-DO comments

* minor log change

* curate usings
documentation
2018-12-09 13:13:34 -06:00
Mag-nus
d750664948
Fixed a network SendTo and update physics loop exception. (#1118)
* Rename Session.Id -> Session.AccountId

* Handle NetworkSession socket.SendTo exception

* Fix Missiles exceptions in physics loop
2018-12-04 08:58:50 -06:00
fartwhif
f0717d4d23 fixing networking bugs (#1104)
* adding @netstats admin command

* trying to figure out the issue

* fixing bug causing AcknowledgeSequence packets to increment the lastReceivedFragmentSequence variable, causing the Sequence to break and never recover for that session
fixing bug causing RequestTransmit packets to be ignored
fixing bug causing the server to crash when a C2S packet is corrupt or malformed
changing the C2S RequestForTransmit packet count to be per request packet instead of per requested sequence
adding Developer commands junk, junk_s2c, junk_c2s, trash_s2c, and trash_c2s to simulate bad connections and manually corrupt packets

* updating changelog.md

* Update changelog.md

fixed incorrect variable name referred to in change log

* Update changelog.md

fix formatting

* adding preprocessor definition NETDIAG and directives to ACE.Common and ACE.Server to help development by preserving troubleshooting tools without interference with the optimal solution

* Apply suggestions from code review

set accessor only needed for NETDIAG functionality
minor change log addition

* reverting some unnecessary source syntax and formatting changes.
removing an unused exception variable

* reverting some unnecessary source syntax and formatting changes

* minor optimization of a duplicate prevention check
2018-11-30 23:58:00 -05:00
fartwhif
d400bc200d adding @netstats admin command (#1088) 2018-11-07 12:40:25 -05:00
gmriggs
7622d272fd
Fixing jump in multiplayer, refactoring movement and animation systems for network and game layers (#1070)
* Fixing jump in multiplayer, refactoring movement and animation systems for network and game layers

* Fixing stamina dropping to 0 while running

* Fixing some monsters getting stuck if they wakeup during idle emote

* Reverting position

* Fixing magic aftercast speed
2018-10-23 00:16:53 -04:00
Mag-nus
118c890285 More profiling based improvements (#1067)
* RateMonitor created

* NetworkSession Update foreach change to help profiling

This just removes the lambda pattern for the foreach so profilers can monitor each line individually.

Functionality is unchanged.

* Reduce Landblock ctor async work to a single thread

This helps reduce ACE thread starvation

* NetworkSession cosmetic

* NetworkSession cosmetic

* NetworkSession currentBundles ConcurrentDictionary to Array

This significantly improves the performance of NetworkSession.

Arrays are faster than Dictionaries, and we manage concurrency to the elements via currentBundleLocks.

We're also able to get away with using an array because the number of elements is only 12.

Accessing the indexes of currentBundles should be atomic as it's an array of reference values, compiled as 64 bit.

* Add InParallel to database functions that do their underlying work in parallel

* DoSessionWork tick outbound messages in series, not in parallel.

* NetworkSession should not be interfacing with ActionChains

* Don't load landblock ctor resources in parallel

Save the threads in the pool for more important work

* LandblockManager removed check/recheck

This is legacy code from a pattern no longer used. It is no longer required.

* Cosmetic
2018-10-15 23:06:54 -04:00
Mag-nus
d2a4dcf49e
Fix Landblock loading. Portaling collisions are now much more responsive (#1054)
* Move DoSessionWork to follow the order in which it's called (last)

* We don't need to set player.Teleporting here. It's set in the Player.Teleport function

* Reduce Portal debug messages to a single line

* NetworkSession time comparisons should be >=

* NetworkSession removed outdated comment

* Removed LandBlockStatus. It was undeveloped

Furthermore, I believe we would be using different status values for the current state of ACE

* Removed Landblock IsActive. It was always true (never used)

* EmoteManager player is null check (fixes crash)

* Offload Landblock ctor work into separate tasks.

This makes portaling around the world onto new landblocks much more responsive.

* cosmetic ocd

* Fix Appraise Object warning
2018-10-09 15:53:10 -05:00
gmriggs
ead5e769ef
Adding detection for post-PY16 skills, installation instructions on player login (#1033)
* Adding detection for post-PY16 skills, installation instructions on player login

* Fix spacing
2018-09-29 13:40:39 -04:00
Mag-nus
32c70b7c1e
Centralize ACE Timers (#1030)
* Reimplementation of Timers class.

This centralizes all the timers in ACE to ACE.Server.Entity.Timers.

* Session Tick comment cleanup

* Sessions no longer maintain their own ServerTime

WorldManager.UpdateWorld was sending each ticks ElapsedTime to sessions. Sessions would add this to their own ServerTime value.

This is not needed. The only time Sessions reference this value is from within their TickInParallel functions, which are called from WorldManager.Update.

For now, we just point the existing variable that was being used (SessionConnectionData.ServerTime) to Timers.PortalYearTicks.

I suspect we thought this value might need thread safety at some point which is why we might have had each session maintain their own value.

* DerethDateTime UTCNowToLoreTime to UtcNowToLoreTime
2018-09-28 16:12:10 -05:00
Mag-nus
80124f2ca3
Session connecting log level improvements (#1021)
The info log level shouldn't be too verbose. Info sould just have 1 record for a connect and disconnect.

The other debugging messages have been moved to the Debug log level.
2018-09-16 07:21:57 -05:00