Commit graph

37 commits

Author SHA1 Message Date
Kamron Batman
2fded43888
feat: Adds exception message to logger for TCP Server and streamlines logger messages. (#2037) 2024-12-30 13:54:39 -08:00
Kamron Batman
60b97f80d8
chore(deps): Bumps xunit to 3.0, serialization generator to 2.12.18, high performance to 8.4, and mailkit to 4.9 (#2032) 2024-12-27 12:56:41 -08:00
Kamron Batman
e0fcde885c
fix: Fixes networking issues (#1958)
### Summary
- Puts back `EventSink.SocketConnect`.
- Reverts networking change to push the networking to a separate thread.
- Reverts changes to the firewall by removing the firewall queue.
- Fixes listeners not shutting down with the server.
- Fixes race condition causing connections to get stuck even after they are disposed.

> [!NOTE]
> **Developer Note**
> Networking has been reverted back to using the main thread instead of a background thread. This alleviated complexity and the requirement for concurrent queues all over the place.
2024-09-19 16:54:49 -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
ac562e67dc
fix: Adds back socket connected event (#1688)
### Summary
Adds back the `SocketConnected` event. This event only fires asynchronously! (TcpServer thread).

Example:
```cs

public static void Configure()
{
    TcpServer.EventSink.SocketConnected += OnSocketConnected;
}

// WARNING: Executed on the TcpServer thread!
private static void OnSocketConnected(TcpServer.SocketConnectedEventArgs args)
{
    if (... logic here...)
    {
        AdminFirewall.Add(((IPEndPoint)Socket.RemoteEndPoint)!.Address);
    }
}
```
2024-04-06 10:26:46 -07:00
Kamron Batman
183f6fa4ac
fix: Fixes stuck connections (#1708) 2024-04-03 08:14:41 -07:00
Kamron Batman
4cd668ef61
feat: Moves TcpServer to another thread. Rewrites Firewall (#1660)
## Breaking Changes
* The Firewall and IP Limiter have been rewritten. Please read the notes carefully!
* `TcpServer.Instances` moved back to `NetState.Instances` - sorry - it was stupid to move it to begin with.

> [!Note]
> Sockets that fail the IP Limiter or Firewall will be immediately and forcibly disconnected.
> This means they will be stuck at "Verifying account..." if it was a real client.

### Summary
- Removes firewall wildcard support.
- Removes `AccessRestrictions`.
- Moves Firewall/IPLimiter to the core.
- Moves `TcpServer` to its own thread.
- Removes the `SocketConnect` and `SocketDisconnect` event sinks.
- Moves `Instances` back to `NetState.Instances`.
- Fixes a long standing bug with bad handling of duplicate listener addresses.

#### Firewall
The firewall has been completely rewritten. There is now an "Admin Firewall" which saves to the config file. Secondarily, there is an internal firewall used exclusively by the TcpServer while processing sockets. The Admin firewall mirrors it's additions/deletions to the internal firewall by adding requests to a queue.

> [!IMPORTANT]  
> **Wildcard firewall entries, such as `X`, `*`, `?` are not allowed.**
> **Ranges in between IP classes or sextets are not allowed.**
> **Please make sure to use one of the following:**
> * IP Address - `192.168.1.1`
> * CIDR - `192.168.1.0/24`
> * Range - `192.168.1.1-192.168.1.100`

#### IP Limiter
The IP Limiter has been completely rewritten. The available configurations are:
```json
"ipLimiter.enable": "True",
"ipLimiter.maxConnectionsPerIP": 10,
"ipLimiter.clearConnectionAttemptsDuration": "00:00:00:10",
"ipLimiter.clearThrottledDuration": "00:00:02:00",
```

The IP Limiter is set up to prevent spamming connections from the same IP. Every time an IP connects, it is added to a connection list. After 10 attempts, the IP is added to the throttle list. To keep the system fast, the connection list is entirely wiped every 10 seconds, and the throttle list is entirely wiped every 2 minutes.
2024-01-20 14:25:12 -08:00
Kamron Batman
60a6796903
feat: Adds ping listener on port 12000 for server list (#1485) 2023-09-03 09:29:27 -07:00
Kamron Batman
8389bfacfe
chore: Updates copyright (#1448) 2023-08-09 09:09:26 -07:00
Kamron Batman
dda55889f6
fix: Fixes tick count calculcations (#1366) 2023-03-09 21:00:17 -08:00
Kamron Batman
3396338926
fix: Fixes blocking sockets (#1191) 2022-10-15 22:23:34 -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
6e69d25e33
fix: Fixes structured logging (#1043)
- [X] Fixes various bugs in logging.
2022-06-05 01:00:22 -07:00
Kamron Batman
1ac803e778
fix: Adds better client verification (#853)
* Adds MinRequired and MaxRequired settings
* Removes god client detection
* Streamlines the kick messaging
* Fixes detecting client version on mac/linux
2021-11-27 10:06:39 -08:00
Kamron Batman
81486772f6
fix: Fixes networking (#822)
* Fixes wepoll to be POSIX compliant.
2021-10-09 11:55:31 -07:00
Kamron Batman
a845f8a1c0
feat: Networking v3 using epoll/kqueue (#813)
* Replaces networking internals with epoll/kqueue
2021-10-03 18:04:53 -07:00
Kamron Batman
56c348ac68
fix: Adds idle cpu config and forces on in debug (#790)
* Adds `core.enableIdleCPU` to modernuo.json
* Forces idle CPU on in DEBUG
* Reverts idle detection back to CPS
2021-09-17 00:15:16 -07:00
Kamron Batman
9f9d990f85
chore(logging): Logging cleanup (#580) 2021-04-23 18:57:42 -07:00
Pedro Pardal
3a619e0103
feat(logging): Adds support for Serilog (#573)
Example:
```cs
public class SomeClass
{
  private static ILogger _logger;
  private static Logger => _logger ??= LogFactory.GetLogger(typeof(SomeClass));
  ...
}
```
2021-04-19 23:43:54 -07:00
Kamron Batman
952a3e0265
fix(core): Handles a rare NPE with LoginTimer (#508) 2021-02-11 23:47:02 -08:00
Kamron Batman
c502af274e
fix(core): Tightens the netstate connection (#490)
- [X] Tightens TCP Server rejection/limiting
- [X] Relaxes receive task erroring so it doesn't spam on debug
- [X] Fixes off-by-one with number of netstates connected
- [X] Moves NetState start() to after it is attached to the Instances list.

Notes:
- In debug mode you may get socket exceptions related to the RecvTask or SendTask attempting to send/receive from a dead/broken socket. This can happen naturally in situations where the client is having trouble maintaining the connection, or abruptly disconnects.
2021-02-08 13:33:36 -08:00
Kamron Batman
c6e93a6814
fix(core): Fixes a few netstate issues (#436)
- [X] Fixes the order of disconnect/dispose
- [X] Removes IsDisposing
2021-02-01 20:37:51 -08:00
Kamron Batman
6f0e1a22f9
fix(core): Core cleanup, adds event loop synchronization, and fixes gumps (#429)
- [X] Cleans up gump packets
- [X] Adds event loop task synchronization
- [X] Moves timer pause and cleans up the delay task timer class
- [X] Cleans up the conserve cpu
- [X] Renames variables to make them consistent with the new style
- [X] Removes process delta recursion checking.
- [X] Properly diposes net states. This fixes edge cases that may cause hanging connections to stay open longer than they should.
- [X] Fixes an issue with gump items not compiling properly

Users can now utilize `Timer.Pause()` since the code will be executed on the proper thread.

```cs
public void async void Talk()
{
    _canTalk = false;
    await Timer.Pause(Utility.RandomMinMax(5000, 8000)); // Talk after 5-8 seconds
    DoTalk();
    await Timer.Pause(Utility.RandomMinMax(12000, 25000)); // Reset ability to talk after 12-25 seconds
    _canTalk = true;
}
```
2021-01-25 21:06:46 -08:00
Kamron Batman
3551d962f7
C# 9 Cleanup (#325)
- [X] Removes EventArgs - not needed
- [X] Merges sequential checks
- [X] Removes redundant type declarations
2020-11-27 00:29:21 -08:00
Kamron Batman
525cda5413
Cleanup & Fixes for .NET 5 (#309)
- [X] Fixes several bugs
- [X] Updates more ordinal issues
- [X] Cleans up the code a bit
- [X] Turns classes static that should have been
- [X] Changes TcpServer.Instances to a HashSet

Bumps release version
2020-11-15 10:03:50 -08:00
Kamron Batman
0e02cf0821
Changes account packets to functional (#284)
- [X] Moved packets from objects to functions
- [X] Fixed bug where characters were showing up with their modded names in the character list

Bumps release version
2020-10-25 23:47:29 -07:00
Kamron Batman
369a27b800
Replacing Networking (#271)
- [X] Removing Kestrel & Libuv
- [X] Cleaning up NetState
- [X] Removing System.IO.Pipelines
- [X] Cleaning up packet reading
- [X] Adds a maximum of 5000 sockets (configurable) to prevent OOM
- [X] Replaces the AsyncState with a thread-safe wrapped boolean called NetworkState
- [X] Removes Parallel.ForEach (no perf gain)
- [X] Removes custom houses compression on another thread
- [X] Test high load scenarios

Bumps release version
2020-10-20 20:55:19 -07:00
Kamron Batman
741e8d8300
Cleanup/Housekeeping (#242) 2020-09-12 15:31:21 -07:00
Kamron Batman
55ae0f8778
Fixes exiting/crash handling/ctrl+c (#237)
- [X] Fixes handling of CTRL+C
- [X] Fixes crash guard (but should really be rewritten
- [X] Fixes exiting/restarting

Bumps release version
2020-09-12 00:05:38 -07:00
Kamron Batman
dad5997c85
Fixes copyright headers and live template (#216) 2020-09-03 01:47:20 -07:00
Kamron Batman
86b7b3aed1
Fixes formatting (#200) 2020-08-25 18:53:35 -07:00
Kamron Batman
f868c34678
Adds listening sockets to the configuration file (#172) 2020-07-03 20:45:37 -07:00
Kamron Batman
63bf71ea47
Fixes disconnect, and publishing to windows. (#114) 2020-04-26 01:43:53 -07:00
Kamron Batman
556a17aba8
Adds style cop (#109) 2020-04-26 00:16:02 -07:00
Kamron Batman
e4037d2541
Fixes readmes and adds some convenience scripts (#107) 2020-04-13 01:54:37 -07:00
Kamron Batman
038c3be258
Adds BufferReader and BufferWriter. Updates UOP handling. (#101) 2020-04-12 21:33:24 -07:00
Kamron Batman
2c0d97cd36
Switches to Kestrel (#102) 2020-04-12 20:57:48 -07:00