Commit graph

103 commits

Author SHA1 Message Date
Kamron Batman
b475e17c92
fix: Forces InvariantCulture on server start for DefaultThreadCurrentCulture (#1988)
Co-authored-by: Stefano Merotta <97297186+stefanomerotta@users.noreply.github.com>
2024-11-01 21:21:10 -07: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
8639ed2210
fix: Fixes bad password with SHA1/SHA2 (#1952) 2024-09-12 17:20:44 -07:00
Kamron Batman
257825dc23
fix: Removes invalidation of tickcount and now in core (#1949) 2024-09-11 22:51:02 -07:00
Kamron Batman
2e6ddcd31a
fix: Removes profiling. Streamlines core tick count. (#1948)
### Summary
- Removes `Profiling` - Recommend using Visual Studio Performance Profiler,  [dotnet-trace](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace) or [JetBrains dotTrace](https://www.jetbrains.com/profiler/)
- Cleans up the core tick count, sampling, etc.
2024-09-11 00:55:18 -07:00
Kamron Batman
8ec203f387
feat: Updates serialization to use MMF (considerable memory savings) (#1841)
### Summary
Updates the serialization strategy to use `MemoryMappedFile` instead of thick buffers. This has the benefit of being on-par with the current implementation (based on hardware/OS), however won't incur the double-memory issue.

> [!Important]
> **Developer Note**
> The `BinaryFileWriter` and `BinaryFileReader` has been removed in favor of `MemoryMapFileWriter` and `UnmanagedDataReader`
2024-06-23 10:51:20 -07:00
Kamron Batman
1f8ab0e783
fix: Console Input is disabled on Linux when no standard input is attached. (#1809) 2024-06-06 21:20:22 -07:00
Kamron Batman
a8d3d2773e
fix: Fixes libdeflate threading issue (#1813) 2024-06-02 15:02:47 -07:00
Kamron Batman
60a3a6f501
feat: Splits Server in Core and Application (#1806)
> [!Note]
> **Developer Note**
> Now developers will only need to build/run the Application project instead of everything.
> When adding new projects, make sure to: 
> 1. Add a reference to that project in the Application project.
> 2. Add the dll file to the Distribution/Data/assemblies.json file

### Summary
- Adds an application project
- Consolidates process restarts to use `Core.Kill(true)`
- Removes some old messaging, for example processor optimization
- Fixes missing build cleanup
2024-05-30 23:34:03 -07:00
Kamron Batman
912eaab460
fix: Fixes unresponsive console input (#1720)
### Summary
Fixes an issue where the call priority of `Initialize` functions causes a dead lock because the console input handler was not initialized.
2024-04-05 15:07:43 -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
823023275b
fix: Stops trying to perform snapshots when the world is not saving (#1658) 2024-01-15 08:29:54 -08:00
Gnai
25a75fdf24
fix: Update Main.cs to accept utf8 on console (#1639) 2023-12-16 00:33:56 -08:00
Kamron Batman
a93a363c5f
fix: Fixes shutdown+save (#1614) 2023-11-25 10:11:24 -08:00
Kamron Batman
469b89370d
fix: Adds back Average CPS to Admin Gump (#1573) 2023-10-30 18:05:32 -07:00
Kamron Batman
629a5008c3
fix: Fixes hanging tests (#1535) 2023-10-09 00:22:59 -07:00
Kamron Batman
1f0acddc46
fix: Fixes serialization threading, moves world save to end of loop, and eliminates Parallel.ForEach. (#1530) 2023-10-03 00:42:49 -07: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
mdodkins
a9a2a89908
feat: Customize expansion and set maps on first boot (#1425) 2023-07-31 20:46:49 -07:00
Kamron Batman
51ecee6caa
fix: Overhauls champion titles & codegen champion system (#1430)
## MAJOR CHANGE

Added a champion title system to facilitate the existing champion titles. This should make it easier to extend or create other related game content. Champion titles will be saved in a folder called _ChampionTitles_.

### Motivation

The motivation to refactor was two-folder, but mostly related to performance in two ways.
First, every player had a ChampionTitleInfo object with an array of ChamptionTitleInfo. We want to eliminate the need for this information unless a player actually uses it. This should save a considerable amount of memory.

Second, to facilitate the atrophy mechanic, the champion titles would run atrophy post-world save, adding to the time that the server is frozen. Eliminating this post-world save side effect unlocks our ability to further optimize the world save process since there are no direct side effects.


### Bugs fixed

- [X] Fixed titles getting cut off on the paperdoll
- [X] Fixed champion title not displaying overhead (OPL)

### Screenshots
<img width="216" alt="image" src="https://github.com/modernuo/ModernUO/assets/3953314/8916f895-8d68-4fb0-892e-108a0c43be90">
2023-07-27 21:44:06 -07:00
mdodkins
d366e02251
fix: Fixes missing ordinal string comparisons arguments. (#1431)
---------

Co-authored-by: Kamron Batman <3953314+kamronbatman@users.noreply.github.com>
2023-07-23 20:12:38 -07:00
Kamron Batman
dda55889f6
fix: Fixes tick count calculcations (#1366) 2023-03-09 21:00:17 -08:00
Kamron Batman
18c4459e6b
fix: Fixes region priority and resolution. (#1254)
- [X] Fixes world location JSON deserializer.
- [X] Fixes region resolver and priorities.
- [X] Removes DynamicJson from regions.
- [X] Adds missing region music.
2022-11-21 10:38:20 -08:00
Kamron Batman
d8cfb6b935
fix: Makes logging more consistent (#1246) 2022-11-13 00:36:23 -08:00
Kamron Batman
49e6c6f2d1
fix: Adds AfterSerialize support. Removes BeforeSerialize support. (#1208)
### Changes
* Implements an AfterSerialize method that is executed synchronously.
* Removes `BeforeSerialize` support since it was dangerous in its current implementation.
* Moves PlayerMobile kill/virtual decay to AfterSerialize.
* Adds kill decay to after Deserialize.
2022-10-27 23:27:22 -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
12404ba6f6
fix: Fixes linux not enumerating directories, and wrong spelling for migration files (#1049) 2022-06-12 09:59:23 -07:00
Kamron Batman
3b7e3c2fb7
fix: Fixes ValueStringBuilder empty ctor issue (#1035) 2022-05-27 17:49:36 -07:00
Stefano Merotta
fe225003c6
fix: Adds multithread optional flag to ValueStringBuilder (#1033)
Added multithread optional flag to ValueStringBuilder for multithread contexts.
Enabled new flag for VerifyType method.

Resolves #1032
2022-05-27 10:25:30 -07:00
Kamron Batman
be7da3a3dc
feat: Adds cliloc support and fixes valuestringbuilder ctor (#1013)
- [X] Adds cliloc support using the following API:
```cs
public static class Localization
{
    string GetText(int number);
    string GetText(int number, string lang);
    string Format(int number, params object[] args);
    string Format(int number, string lang, params object[] args);

    string Format(int number, $"{arg1}{arg2}{arg3}");
    string Format(int number, lang, $"{arg1}{arg2}{arg3}");

    bool TryGetLocalization(int number, out LocalizationEntry entry);
    bool TryGetLocalization(int number, string lang, out LocalizationEntry entry);
}

public class LocalizationEntry
{
    string Language { get; }
    string Number { get; }
    string Text { get; }
    string?[] TextSlices { get; } // Used for string building
    string StringFormatter { get; }

    string Format(params object[] args);
    string Format($"{arg1}{arg2}{arg3}");
}
```

- [X] Fixes a bug with ValueStringBuilder and default initialization size
- [X] Optimizes ValueStringBuilder to use `ISpanFormattable`
- [X] Adds `Append<T>(T value);` support ValueStringBuilder
- [X] Adds `Append($"");` string interpolation support to ValueStringBuider
2022-05-08 21:24:32 -07:00
Kamron Batman
54d728a322
fix: Updates serialization to use v2.0 (#998)
- [X] Deletes serialization annotations
- [X] Updates to ModernUO.Serialization.Annotations nuget
- [X] Updates serializer to v2.0
- [X] Changes all `Serializable()` to `SerializationGenerator()`
- [X] Updates to schema generator v2.0
2022-04-17 08:02:15 -07:00
Kamron Batman
910549db84
fix: Fixes loading multi when client is missing (#996)
* Changes reading multi.mul/multi.idx so it is loaded entirely during bootup.
* Fixes finding files in Linux.
* Fixes handling HS format.
* Removes verdata support.

ModernUO will still have issues if there is a multi.mul that is pre-HS loaded when it detects a client that is 7.0.9+.
2022-04-14 16:52:45 -07: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
a845f8a1c0
feat: Networking v3 using epoll/kqueue (#813)
* Replaces networking internals with epoll/kqueue
2021-10-03 18:04:53 -07:00
Kamron Batman
3f6a87483b
feat: Adds auto archiving (#794)
## Adds Auto Archiving
Backups are archived once an hour, day, and month. Archives older than 60 days are pruned automatically.

_Note: Automatic pruning is off by default_

### Archive compression format
The following formats are supported:
* Zstd (The fastest with best compression ratio)
* GZip
* Zip
* None (Tar)

_Note: By default archives use [zstandard](http://facebook.github.io/zstd/) format.
The archive format can be changed in modernuo.json `autoArchive.compressionFormat`_

### Restoring world from archive
Move the archive to the Saves folder (tar.zst file). On startup the server will extract the file and restore the latest save. See pictures below.

### Manually extracting an archives
#### Windows
* Use the latest version of [7-zip w/ ZStandard](https://github.com/mcmilk/7-Zip-zstd/releases/latest)
  1. Extract the `.tar.zst` file.
  2. Extract the `.tar` file. (Yes you have to do it in two steps)
* On Windows 10 you can use the command line. `zstd.exe` is in the Assemblies folder after building ModernUO.
  1. `tar --use-compress-program "Distribution\Assemblies\zstd.exe -d" -xvf "Archives\Hourly\archivefile.tar.zst" -C "path to where you want to extract it"`
#### Mac
* Install [Keka](https://www.keka.io)
  1. Drop the .tar.zst onto the keka interface.
#### Linux
  1. Install zstd from a package manager
  2. Run `tar -I zstd -xvf "Archives\Hourly\archivefile.tar.zst" -C "path to where you want to extract it"`

### Other changes
* Changes Autosave to occur at the same time no matter when the server is booted.
* Adds `[SaveFrequency <delay> [warning]`command to set save frequency and warning frequency in-game.
* Adds support for time zones that are configurable. The system timezone can also be manually configured. Check `TimeZoneHandler.cs` for details.

<img width="257" alt="Screen Shot 2021-09-22 at 11 23 18 PM" src="https://user-images.githubusercontent.com/3953314/134464929-a5bf3cd8-2ef0-4476-a9ad-71d0816a19ac.png">
<img width="241" alt="Screen Shot 2021-09-22 at 11 23 39 PM" src="https://user-images.githubusercontent.com/3953314/134464945-5f6f96dc-3d1e-434d-8256-5c6b3705e786.png">
<img width="836" alt="Screen Shot 2021-09-22 at 11 34 39 PM" src="https://user-images.githubusercontent.com/3953314/134464957-625e57f2-ef47-4ca1-a0a7-cd40c9b6539c.png">
<img width="631" alt="Screen Shot 2021-09-22 at 11 34 50 PM" src="https://user-images.githubusercontent.com/3953314/134464969-b2d65c0d-f8f5-497a-a832-5d805e8e0b22.png">
2021-09-25 17:22:05 -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
54e56d2fc1
fix: Fixes assembly loading. (#759)
* `AssemblyHandler.Assemblies` will now only contain assemblies listed in `assemblies.json`
* `assemblies.json` has been updated to only contain asssemblies directly loaded by the server. Namely, only `UOContent.dll`.
  * Specifically assemblies loaded by assemblies.json are subject to check for `Configure` and `Initialize` methods.
* `modernuo.json` now has a new property called `assemblyDirectories`. This will be automatically set to `Distribution/Assemblies` (absolute path on your machine).
  * You can add more directories to this list.
* All assemblies in assemblies.json _AND_ dependents of any assembly will be searched for in the directories specified by `assemblyDirectories`.
2021-09-03 23:35:44 -07:00
Kamron Batman
f795ab4698
fix: Updates first load configuration (#680)
<img width="814" alt="Screen Shot 2021-08-08 at 11 33 24 PM" src="https://user-images.githubusercontent.com/3953314/128667907-be43bf24-df7b-481b-ab0a-8b9094f01188.png">
2021-08-08 23:42:10 -07:00
Kamron Batman
9b554f69b0
feat(timers): Adds timer pooling, fixes timer related bugs, and changes timer api (#667)
### Changes/Fixes:
* Adds timer pooling.
* Allows pool to be configurable in ModernUO.json
* Pool replenishes itself asynchronously if depleted.
* Fixes an issue with barkeeps and town criers
* Fixes an issue with incognito buff icons not being removed
* Fixes an issue with polymorph name mod not being removed
* Fixes several places where timers go on forever even after an object is deleted, keeping a reference (memory leak)
* Eliminates the timer for MiningCart altogether.
* Deletes `AcidSlime` since it is a duplicate of `PoolOfAcid`
* Fixes HonorableExecution and standardizes the code for other Bushido moves.

## Changes to the Timer API:
```cs
public class Timer
{
  // Creates a timer that will be returned to the pool once execution stops.
  public static void StartTimer(Action callback);
  public static void StartTimer(TimeSpan delay, Action callback);
  public static void StartTimer(TimeSpan delay, TimeSpan interval, Action callback);
  public static void StartTimer(TimeSpan interval, int count, Action callback);
  public static void StartTimer(TimeSpan delay, TimeSpan interval, int count, Action callback);

  // Creates a timer and returns a token for more control. Requires manual cancellation in order for the timer to be returned to the pool.
  // If the token is dereferenced, the timer will be dereferenced too. While not returning a timer to the pool is not considered hazardous, it does defeat the purpose of pooled timers.
  public static void StartTimer(Action callback, out TimerExecutionToken token);
  public static void StartTimer(TimeSpan delay, Action callback, out TimerExecutionToken token);
  public static void StartTimer(TimeSpan delay, TimeSpan interval, Action callback, out TimerExecutionToken token);
  public static void StartTimer(TimeSpan interval, int count, Action callback, out TimerExecutionToken token);
  public static void StartTimer(TimeSpan delay, TimeSpan interval, int count, Action callback, out TimerExecutionToken token);

  // If you aren't sure how to use the API above, or you don't care about performance, then you can use the old RunUO Timer.DelayCall
  public static DelayCallTimer DelayCall(Action callback);
  public static DelayCallTimer DelayCall(TimeSpan delay, Action callback);
  public static DelayCallTimer DelayCall(TimeSpan delay, TimeSpan interval, Action callback);
  public static DelayCallTimer DelayCall(TimeSpan interval, int count, Action callback);
  public static DelayCallTimer DelayCall(TimeSpan delay, TimeSpan interval, int count, Action callback);
}

public struct TimerExecutionToken
{
  public bool Running { get; }
  public int Index { get; }
  public int RemainingCount { get; }
  public DateTime Next { get; }
}
```

## When to use `TimerExecutionToken`?
Use tokens when you want to gain the performance benefit of using a pooled timer, but you need one of the following:
* Access to the next time the timer will tick:`token.Next`
* Access to which interval, how many intervals there are, or how many are remaining: `token.Index`, `token.Count`, and `token.RemainingCount`
* Stop a timer manually.
* Determine if the timer is running: `timer.Running`
* See notes below about requirements for using tokens!

## Notes about using the TimerExecutionToken:
When you opt-in to receive a token, you must call `Cancel()` to return the timer. This can be done inside of the callback, or outside of the callback at any time.
If this is not called and your timer is an infinite interval, then you will create a potential memory leak, or null pointer exception in your callback.
If the timer ends and is stopped, but cancel is not called, then the timer will never return to the pool and stay referenced until the token is deleted or cancel is called. (Memory leak)

## Is this thread safe?
No. The ModernUO timer system is not thread safe at all. If you require a thread safe timer system, contact me and I'll help adapt this system. Keep in mind that there is a massive performance hit to make this thread safe when there are literally no use cases for it.

If you need to synchronize execution, meaning you want to execute code from another thread on the core thread. Let's say you have a discord bot that is pushing commands to the game server. Then use `EventLoopContext.Post(SendOrPostCallback callback, object state);`.
2021-08-07 14:33:35 -07:00
Kamron Batman
06a577332d
fix(core): Fixes a timer bug where Stop wasn't called internally (#664) 2021-07-25 23:30:11 -07:00
Kamron Batman
c9ce597573
fix(core): Fixes bad check for verifying types (#662) 2021-07-19 21:50:29 -07:00
Kamron Batman
fb915992dd
fix(core): Adds Hashed & Hierarchical Timer Wheel (#655)
- Removes TimerPriority
- Removes TimerThread
- Adds a [Hashed & Hierarchical Timer Wheel](http://www.cs.columbia.edu/~nahum/w6998/papers/ton97-timing-wheels.pdf)
2021-07-11 22:42:06 -07:00
Kamron Batman
cc5a8dc4fa
fix(core): Fixes region base type (#635)
Fixes `Region` being loaded instead of `BaseRegion` as the default region type.
2021-06-02 23:12:52 -07:00
Kamron Batman
81e4087acc
fix(codegen): Adds manual dirty checking (#621)
- Adds `[ManualDirtyChecking]` for anyone that adds it themselves.
- Adds detection of `[Serializable]` and `[ManualDirtyChecking]` at startup to help identify scripts that need migration.
2021-05-27 00:54:21 -07:00
Kamron Batman
cb66bef0e5
fix(core): Cleans up serialization (#606) 2021-05-16 13:45:32 -07:00
Kamron Batman
edea1d4906
fix(core): Fixes core tick count for VMs (#600)
Some architectures (specifically docker) have an issue with tick count and high precision timing.
This handles those weird cases so instead of outright freezing, you may get timer precision loss.
2021-05-13 18:22:42 -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