Commit graph

154 commits

Author SHA1 Message Date
Kamron Batman
8282b00ca2
feat: Moves gumps out of the core (#1916)
> [!Important]
> **Developer Note**
> This code change will **completely move gumps out of the core**


### Summary

- Adds `GetGumps()` convenience which exposes methods to Find/Close/Send multiple gumps. This helper is a performance improvement by eliminating the Dictionary<Player, List> lookup for gumps.
2024-08-09 19:07:32 -07:00
mdodkins
91e37fb8d4
fix: Hair and facial hair "teleporting" when mobile dies several times (#1901)
### Summary

* Added World.NewVirtual for creating virtual serial numbers
* Reserved range 0x7EEEEEEE to 0x7FFFFFFF for virtual serials
* Hair and Facial hair (for mobiles) now use virtual serials instead of FakeSerial() functions
* Consolidated virtual hair to a single `VirtualHairInfo` class.

Corpse hair and facial hair now persists across save/load and hair and facial hair no longer teleport to newest corpse.
2024-08-07 20:10:23 -07:00
Kamron Batman
f58117a877
fix: Moves ContextMenu out of core, streamlines code, fixes bugs (#1873)
## Summary
- Removes allocation of a `List<ContextMenuEntry>` every time a context menu is created.
- Moves packet/context menu creation logic out of the core
- Fixes tame entry

## BREAKING CHANGE
> [!Important]
> **Developer Note**
> ```cs
> public virtual void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
> ```
> and similar functions changed to
> ```cs
> public virtual void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
> ```
2024-07-20 21:33:23 -07:00
Kamron Batman
6f444488a5
fix: Fixes crashing due to bad packet assumptions. (#1829)
### Summary
- Fixes various exploits that can crash the shard when the client misbehaves.
- Clients will now be disconnected if they send packets that are marked as out of game only (new flag), while they are in-game.


> [!Note]
> **Developer Note**
> Added an `OutOfGameOnly` which should be used to flag packets as only available out of the game.
> This is the opposite of, yet not the converse to `InGameOnly`.
2024-06-07 18:08:07 -07:00
Kamron Batman
a4522b9d43
fix: Fixes stalled connections and infinite throttle (#1796)
> [!Warning]
> **Developer Warning**
> The `PacketThrottle` callback return value is now reversed. `true` indicates the connection is _throttled_.

### Summary
- Fixes an issue where connections get stalled forever
- Fixes an issue where the throttler is not working properly
- Removes account attack limiter
- Rewrites IP limiter
- Removes IP restrictions (they weren't used, and not practical)
- Fixes issue where IP limiter was counting before firewall was blocking.

View without whitespace:
https://github.com/modernuo/ModernUO/pull/1796/files?diff=split&w=1
2024-05-27 21:32:55 -07:00
Kamron Batman
1f701e7b55
feat: Replaces Zlib with LibDeflate (#1774)
> [!Warning]
> Users on Linux/OSX will need to follow the Readme
> and make sure `libdeflate` is properly installed

> [!Note]
> **Developer Note**
> The API for compression has changed. Use `Deflate.Standard` for the same functionality.

### Summary
* Replaces Zlib with LibDeflate for a 50% performance improvement!
* Adds MacOS 14 to properly test Arm64
2024-05-16 22:53:01 -07:00
Kamron Batman
4ea1d79cad
fix: Removes broken OrderedHashSet and adds a simple OrderedSet (#1756)
> [!CAUTION]
> **BREAKING CHANGE**
> Removed `OrderdHashSet` and `PooledOrderedHashSet` due to bugs.

> [!NOTE]
> **Developer Note**
> The OrderedSet is not a full data structure. It is not particularly efficient. Pull Requests are welcome for a better implementation, especially if it ends up supporting `ISet<T>` and `IReadOnlySet<T>`

## Summary

The ordered hash set was buggy. It's kind of painful to implement, so for now, I added a simple `OrderedSet` to suffice for gumps. Please reach out if this causes disruption!
2024-05-03 18:03:26 -07:00
Kamron Batman
9cd84ba3d6
fix: Removes support for v4 Client and old gump packet. (#1739)
### Summary
* Removes old gump packet support
* Removes support for v4 clients
* Removes `Unpack` flag and assumes it is always true.
* Removes StringToBuffer since this is built into .NET now.

> [!Note]
> View the file changes with white space off: https://github.com/modernuo/ModernUO/pull/1739/files?diff=split&w=1
2024-04-24 19:39:37 -07:00
Kamron Batman
7d9bc9ff0a
fix: Fixes thread guard and cleans up incoming packet reader (#1641)
### Summary
* Fixes syntax compile error when THREADGUARD is enabled.
* Removes `int packetLength` from incoming packet handles since they aren't needed.

### Developer Notes
Incoming packet handler `SpanReader` is now properly scoped to that packet by length.
2023-12-19 17:04:09 -08:00
Kamron Batman
6a0fcd62c1
fix: Fixes various mobile packets and setting serials (#1618)
### Summary
- Removes old death packet that isn't used. Doubtful this causes issues with clients that are v4+.
- Removes duplicate incoming packets. Again, probably to fix some old client issues, doubtful it affects clients v4+.
- Fixes setting serials and entities in props/commands. Note: Disabled setting `Parent` since the new sector code has issues. We shouldn't rely on it anyway!
- Reverts a recent change to healthbars that should not have been made. Oops!
2023-11-26 00:42:15 -08:00
Kamron Batman
d5253c2bae
chore: Cleans up unused imports (#1608) 2023-11-21 12:32:51 -08:00
Kamron Batman
03f850fe03
fix: Fixes sending packets and sidesteps a major issue with stackalloc and PGO in .NET 8 (#1607)
### Summary
- Works around a sneaky edge case bug in the JIT with stackalloc where sometimes the buffer is not zero'd.
- Fixes SendDisplayBoatHS
- Fixes sending health bars in the `SendEverything()` logic.
- Fixes a bug in sizing for some string helper functions.

### Developer Note
We are enabled `SkipLocalsInit` - do not rely on `stackalloc` to be zero'd. To zero the buffer, use `span.Clear();`

Closes #1606
2023-11-21 12:18:20 -08:00
Kamron Batman
10a69bf754
feat: Adds a memory mirrored ring buffer for networking. (#1533)
## Breaking Changes

Incoming packet registration signature has changed to:
```cs
delegate* void OnReceiveCallback(NetState state, SpanReader reader, int packetLength);

IncomingPackets.Register(int packetID, int length, bool ingame, OnReceiveCallback onReceive);
```

For example, an incoming packet handler signature would now look like this:
```cs
public static void SomeIncomingPacket(NetState state, SpanReader reader, int packetLength)
{
    // Parse the data
}
```

## Summary

Updates the network Pipe class to use a mirrored memory technique. This technique involves mapping the same physical memory to two contiguous virtual memory spaces so the byte buffer appears duplicated. This allows writing to a double-sized array to wrap around without the need for the `CircularBuffer` classes.

In practice this allows us to use `Span<byte>` as if the buffer was a regular array.


### Bug Fixes

- [X] Fixes bad fixed length string parsing
2023-10-09 00:57:53 -07:00
Kamron Batman
146abad36e
feat: Adds a movement throttle system. Removes Fastwalk system. (#1511)
### Summary

- Removes Fastwalk system
  - Removed the following settings:
    - `movement.enableFastWalkPrevention`
    - `movement.fastwalkExemptionLevel`
- Adds movement throttle system.
  - Adds the following settings:
    - `movement.throttleReset` - Default value is `1000` (1 second).
    - `movement.throttleThreshold` - Default value is `400` (400ms).

### Movement Throttling

This new system will trigger if a player requests 400ms (configurable) worth of movements quicker than wall clock time. When this happens, the player is throttled (all incoming packets to the server are halted) until wall clock time catches up with the requests. Upon each throttle, the player receives enough credit to handle up to 400ms of "lag" as a grace/catch-up.


### Developer Notes
We use two throttle queues to prevent an infinite loop.
2023-09-27 20:53:22 -07:00
Kamron Batman
2a3e048b86
fix: Fixes more packet initializations (#1507) 2023-09-19 00:02:17 -07:00
Kamron Batman
8389bfacfe
chore: Updates copyright (#1448) 2023-08-09 09:09:26 -07:00
mdodkins
a9a2a89908
feat: Customize expansion and set maps on first boot (#1425) 2023-07-31 20:46:49 -07:00
Marcelo Paez Sequeira
b46544d752
fix: Moves the rest of the Incoming packets (#1338) 2023-02-10 22:59:36 -08:00
Marcelo Paez Sequeira
a8d8db8f59
fix: Moves accounting, entity, 0xBF, and house packets to UOContent project (#1337) 2023-02-09 18:42:57 -08:00
Kamron Batman
44c69620a6
fix: Tidy up socket dispose. (#1334) 2023-02-07 21:22:04 -08:00
Kamron Batman
68bd9529f9
Adds hue support to StaticTile (#1321)
### Summary
Fixes missing properties while reading static tiles.

### Screenshots
<img width="463" alt="Screenshot 2023-01-21 093050" src="https://user-images.githubusercontent.com/3953314/213879788-05d2ad7c-c197-4690-9f5b-660bded416cc.png">

Closes #1320
2023-01-21 11:19:11 -08:00
Kamron Batman
bfb987c758
fix: Fixes client crash while selling items to NPC (#1296) 2022-12-05 20:16:31 -08:00
Kamron Batman
6426996f29
chore: Code Cleanup (#1239) 2022-11-10 22:49:25 -08:00
Kamron Batman
fd6f4239e2
fix: Adds FindItemOnLayer generic (#1223) 2022-11-01 00:49:20 -07:00
Kamron Batman
ca3b173c4c
fix: Removes timer error for world in initial state, and removes OPL requirement for spellbooks (#1197) 2022-10-19 02:32:04 -07:00
Kamron Batman
f268d5d4e2
fix: Cleans up core code (#1187)
**Only one functional change**
* Fixes a bug in LogFactory where `Warning` is being logged as `Information`

Non-functional changes:
* Updates/Fixes copyright headers
* Removes namespace scopes for core files.

View with [whitespace off](https://github.com/modernuo/ModernUO/pull/1187/files?w=1).
2022-10-10 21:47:08 -07:00
Kamron Batman
2d95fb20a6
fix: Adds expansion specific mobile status version (#1145) 2022-08-22 21:04:59 -07:00
Kamron Batman
38686c09b2
fix: Updates more logging to Serilog (#1105)
Adds more serilog logging and cleans up some server files.
2022-07-01 11:57:08 -07:00
Kamron Batman
a37b8b285c
fix: Adds AssistVersion packet support for Razor (#1094)
- [X] Fixes razor negotiations via 0xF0 packet (open negotiation)
- [X] Adds AssistVersion handling for Razor
- [X] Displays Assistant in Client/Admin gump
2022-06-28 01:05:00 -07:00
Kamron Batman
5343260895
fix: Fixes wrong amount cleared for mobiles (#1092) 2022-06-26 17:12:42 -07:00
Kamron Batman
8d3aaaeb2a
fix: Removes razor negotiations since they arent maintained (#1090) 2022-06-26 08:33:53 -07:00
Kamron Batman
4f28e1e3c4
fix: Adds back razor/assistuo negotiations (#1089)
* [X] Adds Razor negotiations
* [X] Adds AssistUO "handshake" 🙄
2022-06-25 01:47:45 -07:00
Kamron Batman
057cf87e60
fix: Updates encoded packet handler to use function pointers (#1066) 2022-06-15 17:20:36 -07:00
Stefano Merotta
f24b98f8e2
fix: Replaces throttlers and packet callbacks with function pointers (#1063)
Replaces multi-cast delegates with function pointers to gain 25% in performance and lower allocations.
2022-06-15 12:48:43 -07:00
Kamron Batman
b74b47159f
fix: Fixes localization corner cases with OPL (#1050)
## Changes
- [X] Adds OPL convenience methods
    - `opl.Add(cliloc, value)` and `opl.Add(value)` - value as an integer or string works just like `opl.Add(cliloc, $"{value}")`
    - `opl.AddLocalized(cliloc, clilocValue)` - works the same as `opl.Add(cliloc, $"#{clilocValue}");`
- [X] Simplifies basic `list.Add()` situations
- [X] Changes cliloc as an argument so it works with custom IPropertyList implementations (HTML)
- [X] Fixes plants so they support the old localization and new (changed in 7.0.12.0+)
- [X] Exposes more methods to override for Item to make creating custom OPL possible.

## Important Notes
* Using a ternary as an argument, like this `opl.Add(number, showType ? $"{type}\t{value}" : $"{value}");` _will not use the correct string interpolation_. This means if you use a custom PropertyList (for HTML or some other purpose), the property list won't be localized properly.
* All localization values must be interpolated, even if they are literal strings, or integers. Example: `opl.Add(number, $"{"Charges"}\t{m_Charges}");` is correct. Using the following: `$"Charges\t{m_Charges}"` will not work for custom PropertyList implementations!
2022-06-12 21:17:42 -07:00
Kamron Batman
6e69d25e33
fix: Fixes structured logging (#1043)
- [X] Fixes various bugs in logging.
2022-06-05 01:00:22 -07:00
Kamron Batman
ecbee17690
fix: Optimizes OPL using string interpolation (#1041)
## Breaking Changes (New API)
ObjectPropertyList supports the following API:
```cs
list.Add(500000);
list.Add(500001, stringArgument);
list.Add("Some text");
list.Add($"Some text with {argument}");
list.Add(500002, $"{arg1}\t{arg2}");
```

## Notes
1. All API uses that require a formatter like this:
    ```cs
    list.Add(500002, "{0}\t{1}", arg1, arg2);
    ```
    Should be changed to use string interpolation, for example:
    ```cs
    list.Add(500002, $"{arg1}\t{arg2}");
    ```
2. The following paradigm should no longer be used:
    ```cs
    list.Add(1061170, prop.ToString()); // strength requirement ~1_val~
    ```
    The new string interpolation API will avoid having to convert the argument to a string before writing it to the packet. Instead use the following:
    ```cs
    list.Add(1061170, $"{prop}"); // strength requirement ~1_val~
    ```

### Benchmarks
```cs
|                         Method |     Mean |   Error |  StdDev |  Gen 0 | Allocated |
|------------------------------- |---------:|--------:|--------:|-------:|----------:|
|                BenchmarkOldOPL | 241.0 ns | 0.56 ns | 0.47 ns | 0.0105 |      88 B |
| BenchmarkStringInterpolatedOPL | 199.9 ns | 2.44 ns | 2.39 ns |      - |         - |
```

### Changes
- [X] Removes crash in STArray.Return when array is null.
- [X] Fixes NPE in OPL when entity is null. Serial in packet will be 0 when entity is null.
- [X] Fixes NPE in AosAttributes when Parent is null.
- [X] Changes OPL to use string interpolation.
- [X] Introduces `IPropertyList` to allow extending PropertyList for other uses.
2022-06-02 10:09:53 -07:00
Kamron Batman
d261973cee
fix: Adds freeshard protocol to information list (#1038) 2022-05-30 09:35:46 -07:00
CA5A
9bbcb4b274
fix: Removes DropReq6017 (#1030) 2022-05-20 12:11:31 -07:00
Kamron Batman
8f1240d25e
fix: Fixes expansion flags for animations (#1009) 2022-05-01 18:35:42 -07:00
Kamron Batman
de0bf03f46
fix: Simplifies expansion checks (#994) 2022-04-12 20:52:53 -07:00
Kamron Batman
474427041f
feat: Adds a PooledRefList (#676) 2022-03-26 11:11:22 -07:00
Kamron Batman
14b63ca48e
fix: Updates ArrayPool to STArrayPool for performance. (#968) 2022-03-22 20:07:32 -07:00
Kamron Batman
58b907d39e
fix: Fixes packet length checks (#953)
Fixes an issue with DropReq where an old client was sending in 14 bytes, but the server was expecting 15 bytes.

To fix this we introduced a new packet handler, `ContainerGridPacketHandler` and changed the code to determine the length of the packet dynamically using `GetLength(NetState)`.

Also fixed throttling so dropped packets are properly skipped.
2022-03-04 12:32:25 -08:00
Kamron Batman
651cffa872
fix: Cleans up mobile status packets (#835)
* Removes Span2D for mobile moving. Instead uses pure math and simplifies the calculation.
* Cleans up the extended mobile status packet.
2022-02-27 03:10:35 -08:00
Kamron Batman
941452de4a
fix: Stops creating blocked packets entirely (#944)
Optimizes larger servers where users are logging in and packets are being created for no reason.
2022-02-27 00:13:49 -08:00
Kamron Batman
5db8b1354c
fix: Fixes various minor issues (#943) 2022-02-26 23:43:25 -08:00
Kamron Batman
63e1b02d93
chore: Cleans up pattern checks. (#892) 2021-12-24 15:53:59 -08:00
Kamron Batman
bfbe2a6512
fix: Updates professions & new player gargish equipment (#819)
* Now reads Prof.txt to get the professions
* The templated professions are based on profession `TrueName`
* Adds missing starting equipment
* Implements gargish starting equipment
* Consolidates some of the code
* Moves TC stuff to the TC file.
* Fixes some starting equipment that was wrong.

Note:
* Implementing the original T2A professions is possible on the client side, but requires moving the old clilocs to the current clilocs file. In the current file the entries are blank.
* Using the original LBR professions (they match AOS but without necromancy/chivalry) is kind of confusing because the profession indexes are ripped out of the UOTD/UOR ones and have non-sequential indexes. This will probably cause confusion and people will get no templated items when they select the wrong profession.
2021-10-16 10:48:58 -07:00
Kamron Batman
8eaa859332
fix: Fixes code genning armor, clothing, and BODs (#810)
* Fixes code genning clothing
* Fixes code genning armor
* Fixes code genning BODs
2021-09-28 22:09:34 -07:00