Commit Graph

77 Commits

Author SHA1 Message Date
Robin C. Ladiges 4de654b6e4 ignore & crash instead of disconnect clients after reaching the MaxPlayers limit
Otherwise they'll enter an endless disconnect-reconnnect loop spamming the server with new TCP connections.
2024-04-27 15:14:38 -04:00
Robin C. Ladiges 082e480b1e crash ignored players
Otherwise they keep sending all their packets (including positional updates) to the server which costs bandwidth and processing power.
2024-04-27 15:14:38 -04:00
Robin C. Ladiges 9511d07f09 send server init after the client init
To make service discovery by internet scan bots harder.
2024-04-27 15:14:38 -04:00
Robin C. Ladiges dc20a9c831 small refactorings
- use brackets when possible
- set client.Id and client.Name earlier
- use client.Id instead of header.Id
- rename firstConn to isClientNew
2024-04-27 15:14:38 -04:00
Robin C. Ladiges 20ee74d0d6 fix: construct tag packet instead of caching it in memory
Because the tag packet received from the client could have an UpdateType that isn't both State and Time.
(Though currently the client always updates both together.)
2024-04-27 14:45:41 -04:00
Robin C. Ladiges d6a8df448c
Refactoring ban command (#48)
* rename command: `ban ...` => `ban player ...`

To enable adding other subcommands starting with `ban`.

Moving ban list and crash related code into its own class to tidy the Program class up.

Change Id values of the crash cmds, to fit into the 16 byte max length imposed by ChangeStagePacket.IdSize.

* add command: `ban ip <ipv4-address>`

To add an IPv4 address to the ban list.

* add command: `ban profile <profile-id>`

To add a profile ID to the ban list.

* add command: `unban ip <ipv4-address>`

To remove a banned IPv4 address from the ban list.

* add command: `unban profile <profile-id>`

To remove a banned profile ID from the ban list.

* add commands: `ban enable` and `ban disable`

To set the value of `BanList.Enabled` to `true` or `false` without editing the `settings.json` file.

* add command: `ban list`

To show the current ban list settings.

* fix: actually working ban functionality

Changes:
- ignore new sockets from banned IP addresses way earlier.
- ignore all packets by banned profiles.

Intentionally keeping the connection open instead of d/c banned clients.
This is to prevent endless server logs due to automatically reconnecting clients.

Before:
Reconnecting clients aren't entering `ClientJoined` and therefore the d/c is only working on first connections.
Effectively banned clients got a d/c and then automatically reconnected again without getting a d/c again.
Therefore allowing them to play normally.

* use SortedSet instead of List for settings

To enforce unique entries and maintain a stable order inside of the `settings.json`.

* add commands: `ban stage <stage-name>` and `unban stage <stage-name>`

To kick players from the server when they enter a banned stage.

<stage-name> can also be a kingdom alias, which bans/unbans all stages in that kingdom.

Because we aren't banning the player, d/c them would be no good, because of the client auto reconnect.
Instead send them the crash and ignore all packets by them until they d/c on their own.

This is an alternative solution for issue #43.

* Update Server.cs

---------

Co-authored-by: Sanae <32604996+Sanae6@users.noreply.github.com>
2023-09-05 17:14:54 -06:00
Robin C. Ladiges 86c79177fd fix: synchronization issues
- Send empty `TagPacket` and `CapturePacket` on new connections, to reset old data back that other players might still have in their puppet from an
earlier connection.
- Cache and send `CostumePacket`, `CapturePacket`, `TagPacket`, `GamePacket` and `PlayerPacket` to (re-)connecting players.
- Clear Metadata cache for existing clients that connect fresh (after a game restart).
2023-09-05 16:51:58 -06:00
Robin C. Ladiges 122a3cd80d fix: don't output empty player IDs or RemoteEndPoints in the log
Make and use a copy of the RemoteEndPoint at the start of the HandleSocket method.
Because in some cases when the socket is disposed, the RemoteEndPoint inside of it is cleared and isn't available for the following disconnect log entries.
Also: port scanners on the internet don't introduce themselves with a name and ID.

(cherry picked from commit 2f4cd0509a)
2022-10-10 11:13:32 -06:00
Robin C. Ladiges 69cef89953 fix: on reconnect do not disconnect the new client
Currently when a client connects that is already there,
the old socket is closed, and the code tries to reuse the existing client object by exchanging its socket.

Reusing the same client object and just changing its socket does cause issues though with copies of the client in other threads.
In the situations that I could reproduce, it always disconnected both sockets, the old one and then the new one.

Instead I make a copy of the client object, use the new socket, remove the old object and add the new object to the collection.

(cherry picked from commit 9e6c312c8e)
2022-10-10 11:12:28 -06:00
Robin C. Ladiges 472c8856bc move the client.CurrentCostume update to the PacketHandler and log the packet
(cherry picked from commit 47505dbdd5)
2022-10-10 11:09:39 -06:00
Robin C. Ladiges c41499f953 remove unused label
git cherry-pick accidentially picked up a line from another commit for the JSON API
2022-09-07 10:35:26 -06:00
Robin C. Ladiges 76fc4a80a6 only broadcast the DisconnectPacket if the client was connected
Otherwise port scans, banned players or clients failing to initialize correctly,
will cause the server to send unnecessary packets to all connected clients.

They currently are informed about a disconnect for a client that hasn't even connected correctly.

(cherry picked from commit 4b04a3d5be)
2022-09-07 10:35:26 -06:00
Sanae e7a3347a37
Merge pull request #19 from TheUbMunster/restart-command 2022-07-29 13:19:04 -06:00
TheUbMunster 95c918b5c4 Removed fire-and-forget warnings, null-forgave some metadata. 2022-07-29 12:55:01 -06:00
TheUbMunster 068cc7c06d Added restart server command 2022-07-27 23:56:50 -06:00
Sanae 66114bdecb
Always update client's name on connect
Since the client variable would be changed in a reconnect, the name is not set on the old client object.
2022-07-27 14:00:58 -06:00
CraftyBoss 11015bd445 only send game packet on join to connected clients 2022-07-08 23:13:35 +00:00
Sanae 99aabeffc9 Add init packet 2022-05-08 16:04:57 -06:00
Sanae ab318db1b8 Clean up logging from testing 2022-04-27 21:32:52 -06:00
Sanae 605be3947f I'm going to commit war crimes 2022-04-27 14:17:02 -06:00
Sanae a775e593c3 Absurd logging 2022-04-27 14:02:26 -06:00
Sanae bddce48f9d Stop using MemoryMarshal for header serde 2022-04-27 00:24:11 -06:00
Sanae 6964c3bbf4 Add max players to connect packet 2022-04-26 23:24:40 -06:00
Sanae 1a82666d93 Disconnect previous client instead of throwing on new client (rejoins) 2022-04-04 14:43:44 -06:00
Sanae a0a53ff7bf ReuseAddress requires Socket level 2022-04-02 20:58:57 -06:00
Sanae cc5c86091e Try using tcp to not require sudo? 2022-04-02 20:14:35 -06:00
Sanae 50adf23be3 Use correct maxplayers field 2022-03-22 03:20:49 -06:00
Sanae 8645db12fa Improving rejoins and other changes 2022-03-22 03:19:06 -06:00
Sanae 27d2d9acd9 Bye send buffer stuff 2022-03-15 20:25:36 -06:00
Sanae 709af8d3ec Send buffer 1 on another oscket 2022-03-15 17:28:15 -06:00
Sanae 206bbd5d4c Set send buffer to 1 2022-03-15 17:23:53 -06:00
Sanae a288e5b7a8 Rejoyne 2022-03-15 15:37:23 -06:00
Sanae 8d11623ada Various useful changes 2022-03-15 14:44:46 -06:00
Sanae ad0a40878d Add tag commands and improve command handling 2022-03-14 23:59:23 -06:00
Sanae 217dc2765e Remove test exception when disconnecting 2022-03-13 15:27:53 -06:00
Sanae c778d15644 Packet cleanup and refactoring 2022-03-13 05:14:01 -06:00
Sanae 3b13e1f86d Fixing variable packet sizes once and for all 2022-03-11 23:42:51 -06:00
Sanae 93143a80ef Another log 2022-03-11 20:56:58 -06:00
Sanae cf5ba12861 One more log 2022-03-11 20:29:17 -06:00
Sanae ebf5080a00 More log changes 2022-03-11 20:16:10 -06:00
Sanae 4c5682e59b Read better 2022-03-11 20:06:47 -06:00
Sanae 89dcb7f6c9 More changes to reading varsize packets 2022-03-11 19:08:50 -06:00
Sanae 8c5cd0ced2 Untested conversion to variable size packets 2022-03-10 23:59:02 -06:00
Sanae 134437eec9 Set client name regardless of connection type 2022-03-06 17:19:49 -06:00
Sanae 00626ab12f Add scenario merging and run reformatting on solution 2022-03-01 15:08:53 -06:00
Sanae 557a926a68 Handle max player count correctly 2022-02-22 14:33:59 -06:00
Sanae 31e70a08b9 Add proper exit handling 2022-02-21 22:05:13 -06:00
Sanae 821301e756 Implement console commands and settings (flip list broken) 2022-02-17 19:56:12 -06:00
Sanae 78af568603 Add RentZero extension as rented memory can be non-zero 2022-02-16 15:20:03 -06:00
Sanae 18bd69338f Improve packet processing and send function 2022-02-16 14:33:21 -06:00