Commit graph

213 commits

Author SHA1 Message Date
Cain
65909f983c
[Buffer] Add helper to find string delimiters
Co-authored-by: Douile <25043847+Douile@users.noreply.github.com>
2023-09-27 14:20:42 +01:00
Douile
e2414b197e
[Protocol] Add latin1 string decoder for gamespy1 2023-09-27 14:03:33 +01:00
Tom
c3281be419
[Protocol] Retry failed requests (#95)
* Add retry count to TimeoutSettings

This can be used to specify how many times to re-send requests that
fail. The default value is "1" so the if the first request fails, 1 more
attempt will be made.

* Add retries to valve queries

* [Protocol] &Optional<TimeoutSettings> add get_retries_or_default

Allow fetching the number of retries or the default retries value from a
borrowed optional TimeoutSettings.

* [Protocol] Add retries to minecraft protocol

* [Protocol] Add retries to quake

* [Protocol] Add retries to gamespy

* [Protocol] Update TimeoutSettings docs, and change default retries to 0

* Remove logging from retry_on_timeout

* [Protocol] TimeoutSettings make retries non-optional

* [Protocol] Move retry logic into lower level query functions

Retries are now implemented as wrappers on the single function that
would need to be retried on timeout.

In order to avoid cloning of TimeoutSettings, Socket::apply_timeouts()
was changed to accept a borrowed TimeoutSettings. And extra helpers were
added to the TimeoutSettings impl to reduce repetition.

* [Examples] Add retries to the generic example

* Also retry on PacketSend error

Sending packets could also timeout and until error_generic_member_access
is stable we have no way of determining the type of the underlying
`std::error::Error`.

* Add retry unit tests

* [Docs] Update changelog
2023-09-25 22:12:54 +03:00
Tom
52750fba76
[Games] Update game definitions to match node-gamedig names (#100)
* [Games] Update game definitions to match node-gamedig names

* Update game file names to match definitions

* [Games] rename minecraft definitions to better match node

* [Games] Add test that all game files match definition name

* Update SteamApp to match node names

* [Games] Update the forest to match node-GameDig#367

* Clippy fix in games test

* [Docs] Update GAMES.md with new names

* [DOCS] Update changelog
2023-09-23 00:20:01 +03:00
CosminPerRam
6179532065 [Crate] Changeup a doc comment 2023-09-10 23:27:06 +03:00
CosminPerRam
cb0486bded [Crate] Solve Cargo Doc redundant explicit link target 2023-09-10 23:14:13 +03:00
CosminPerRam
995ab23b51 [Crate] Separate error code into different files. 2023-09-10 23:12:18 +03:00
CosminPerRam
edbb0e6cf5 [Protocol] Valve: Rename compressed field to decompressed 2023-09-10 22:32:02 +03:00
CosminPerRam
b418319e01 [Protocol] GameSpy 3: Removed instance on unchecked .unwrap 2023-09-06 14:17:37 +03:00
CosminPerRam
527f8f6369 [Protocol] Valve: change up compressed packages structure to use Options 2023-09-06 13:46:52 +03:00
CosminPerRam
7cfecbfff9 [Game] Remove instances of using unwrap without handling the panics 2023-09-06 13:37:48 +03:00
Tom
6c1fdb1159
[Generic] Add struct for all extra request settings (#93)
* [Generic] Add struct for all extra request settings

Adds a new struct `ExtraRequestSettings` that contains all possible
extra settings for all protocols, and can be implicitly converted with
`.into()` into each protocol's extra settings type.

This is then used in a new query method
`query_with_timeout_and_extra_settings()` that passes the object on to
the selected protocol.

This also updates the generic example to set some of these generic
settings so that it can be used for certain queries like
"mc.hypixel.net".

* [Minecraft] Add `request_settings` parameter to auto query

This allows generic queries to pass through request settings when using
the `mc` game so that servers like `mc.hypixel.net` will still work when
using auto query.

* Fix generic examples tests (and enable example tests in pre-commit)
2023-09-05 01:13:12 +03:00
CosminPerRam
76a3ac2f78 [Game] Add Creativerse support. 2023-09-03 12:12:14 +03:00
CosminPerRam
a56ca45de6
[Protocol] Fix Minecraft Java query not being able to specify a hostname (#91)
* Make initial fix

* Fix imports

* Rename query_address to hostname and add this to the mc example

* Fix master_querant example not compiling

* Add extra safety on converting strings to Minecraft Varint strings

* Add docs to RequestSettings

* Fix formatting
2023-09-01 22:21:08 +03:00
CosminPerRam
a8fc67412c [Protocol] Fix an instance of unwrapping in The Ship 2023-08-17 23:08:59 +03:00
CosminPerRam
7e028ce97d [Protocol] Remove Minecraft unused function to convert a string to bytes 2023-08-17 22:50:23 +03:00
CosminPerRam
f50c50f0f1 [Protocol] Apply many nursery clippy lints 2023-08-17 22:37:17 +03:00
CosminPerRam
b35e52f795
[Protocol] Add app id checking to valve protocol in gather settings (#87) 2023-08-15 22:00:20 +03:00
CosminPerRam
071fc367df [Protocol] Add buffer comment to refactor at some point remaining_bytes 2023-08-15 21:36:40 +03:00
CosminPerRam
9d8fb1ba94
[Protocol] Standardize fields (#84)
* [Protocol] Standardize The Ship fields

* [Protocol] Standardize FFOW fields

* [Protocol] Rename Valve's protocol field to protocol_version

* [Protocol] Rename Minecraft's version_protocol field to protocol_version

* [Protocol] Rename Valve's version field to game_version

* [Protocol] Rename Minecraft java version_name to game_version

* [Crate] Reformat RESPONSES.md

* [Protocol] Renamed Minecraft Java players_sample to players

* [Protocol] Rename Quake (1,2,3) version field to game_version

* [Protocol] Rename quake (1 and 2) game_type field to game_mode

* [Protocol] Rename Valve, FFOW, TS game field to game_mode

* [Generics] Rename game field/function to game_mode

* [Protocol] Change players_minimum, _maximum and _bots from those who werent u8 or u32 to u32

* [Protocol] Change instances of player score field type from u32 to i32

* [Crate] Nicer gramar in CHANGELOG

* [Protocol] Apply clippy fixes
2023-08-15 20:44:18 +03:00
CosminPerRam
65c56dc196 [Service] Fix valve master server ip gatherer being broken (again) 2023-08-08 18:43:33 +03:00
CosminPerRam
c10555a9d7 [Service] Fix valve master server ip gatherer being broken 2023-08-08 18:42:43 +03:00
CosminPerRam
b509a6dcc4 [Crate] Convert pub(crate) to pub in buffer as its not exported externally 2023-08-06 21:55:39 +03:00
CosminPerRam
5aa2ce99ec [Crate] Apply strict clippy on buffer 2023-08-06 21:54:19 +03:00
CosminPerRam
4ff50ea711 [Crate] Apply strict clippy suggestions and fix doc line. 2023-08-06 21:50:17 +03:00
CosminPerRam
47547a77bd [Crate] Remove unnecessary path prefix in error code 2023-08-06 21:32:44 +03:00
Tom
5e7e010d24
[Crate] Add rich error type (#80)
* Add rich error type with source and backtrace

Adds a rich error type that will take a backtrace and allow capturing
the source of the error. The best way to use this is with the included
helpers that will automatically capture the backtrace and convert the
source error:

```
GDRichError::packet_bad_from_into("Reason packet was bad")
```

* [Crate] Bump MSRV to 1.65.0

This is required for backtraces in rich errors.

* Remove leftover debug logging

* [Errors] Replace variant overloads with single .rich method on kind enum

This overhaul replaces the exhaustive impls of each variant as multiple
methods on the rich error type with a singular .rich() method on the
kind enum. This consumes the variant and converts it to a rich error
with a source (.into() can be used if a source is not needed).

I also took the liberty of replacing all usages with the this new method
as I saw fit (adding various error messages) and converting a few
PacketBad errors to TypeParse errors when they are the result of parse
failing.

* Fix problem with rustdoc

* Remove BadGame's owned string

* Rename GDError to GDErrorKind

* Rename GDRichError to GDError

* Remove error impl from GDErrorKind

* Fix tests not passing

* Use error context everywhere map_err is used

* Improve GDError display formatter

* Add tests for new error type
2023-08-05 12:36:48 +03:00
CosminPerRam
ada60f2376 [Protocol] Fixed quake 2 bug that version wouldn't always be present 2023-07-22 16:17:52 +03:00
CosminPerRam
a81a6ef968 [Protocol] GS 1 rename Player's frags field to score to be more inline with the other protocols 2023-07-20 19:27:06 +03:00
CosminPerRam
23669531b6 [Crate] Fix clippy lints 2023-07-18 15:31:35 +03:00
Cain
66cc39eb26
[Crate] Refactor: Buffer (#62)
* merge: local -> fresh pr

* fix: utf16 bugs + clean up

* docs: buffer

* [feat/buffer] Replaced errors, partial valve protocol ported

* fix: change buffer name + add endian switch

* chore: update module

* refactor: valve_master

* refactor: mc bedrock

* refactor: mc java

* refactor: mc types

* refactor: mc legacy 1.8

* refactor: mc legacy 1.4

* refactor: valve

* refactor: valve types

* refactor: quake

* refactor: mc legacy 1.6

* refactor: gamespy 1

* fix: make switch endian move cursor

* fix: reset cursor on switch

* chore: add switch endian tests

* chore: remove todo comment

* chore: clean up buffer generic types

* refactor: prop len when switching in mc bedrock

* fix: tests and current pos fn

* refactor: ffow

* refactor: jc2mp

* refactor: gs 3

* refactor: gs 2

* fix: mc bedrock prop on move + move data

* fix: mc java lifetime error

* fix: mc legacy 1.6 using pub not pub crate

* fix: quake client lifetime

* fix: quake 2 clippy warning

* fix: valve lifetime issue

* fix: buffer test

* chore: format to keep ci happy

* fix: buffer move_cursor

* fix: quake client

* feat: GameSpy 1 small optimization

* fix: incomplete gamespy 3 fix

* fix: gamespy 3 fix

* fix: minecraft java

* fix: minecraft bedrock

* feat: update the CHANGELOG to mention the buffer rewrite and thank @cainthebest for it

* fix: minecraft legacy 1.6

---------

Co-authored-by: CosminPerRam <cosmin.p@live.com>
2023-07-18 11:46:53 +03:00
Tom
fb9d15f0cc
[Crate] Bump rustfmt version to 1.6.0 (#69) 2023-07-10 18:32:17 +03:00
Tom
e207e8dc95
[Games] Add timeout settings for proprietary games (#67)
Adding query functions with timeout settings to proprietary games allows
the generic query with timeout function to pass the timeout settings
through.

This does change how the pre-existing FFOW query_with_timeout function
worked: it accepted a non-optional timeout settings, this was changed to
optional to be consistent with other query_with_timeout functions and to
move deciding what to do if the user doesn't provide timeout settings to
a more central location.

Closes #64
2023-07-10 16:17:49 +03:00
Tom
f3a792e325
[Crate] Swap no_games, no_services for games, services (#61) 2023-06-27 02:12:57 +03:00
CosminPerRam
0f9a10f2fb [Games] Add Warsow support. 2023-06-27 01:15:04 +03:00
CosminPerRam
58f7ff8aab [Protocol] Fix common quake 2 player score conversion 2023-06-27 01:08:42 +03:00
CosminPerRam
f7e93fd7cd [Protocol] Renamed quake 2's player's frags field to score to be more inline with the other protocols 2023-06-27 01:06:16 +03:00
CosminPerRam
84ebeb8065 [Protocol] Add optional address field to quake 2 player 2023-06-27 00:58:38 +03:00
Tom
8316dac2cc
[Games] Add method to query with timeout options (#60) 2023-06-27 00:50:06 +03:00
CosminPerRam
dd80d6309f [Protocol] Replace some usage of remaining_length with the more appropiate is_remaining_empty 2023-06-27 00:23:19 +03:00
CosminPerRam
8fe521749a [Protocol] Remove bufferer::remaining_data_vec function and replace its usage 2023-06-27 00:18:56 +03:00
CosminPerRam
d61085b1ab [Protocol] Remove bufferer::data_length function and replace its usage 2023-06-27 00:17:33 +03:00
CosminPerRam
c55254aaf6
[Protocol] Add PROPRIETARY to protocol enumeration (#59)
* [Protocol] Add CUSTOM to protocol enumeration

* [Protocol] Rename CUSTOM to PROPRIETARY

* [Protocol] Rename struct to ProprietaryProtocol and do the same thing to generic response

* [Protocol] Revert proprietary change on generic response
2023-06-26 23:52:40 +03:00
Tom
b368877031
[Protocol] Implement generic response with dyn (#56)
* Implement generic response as enum

* First draft of implementing into_common()

* Make common response type generic

* Use macros and generics to reduce repetition

* [Games] Add dynamically dispatched CommonResponse trait

This adds two traits: "CommonResponse", and "CommonPlayer", when the
generic game query function returns a response it returns a pointer to
its original response type that implements "CommonResponse".

Both common traits require that "as_original()" be implemented, this
returns an enum containing a pointer to the original type.

Both traits have a concrete method "as_json()" that returns a struct
containing data fetched from all of its methods as. This struct
implements serde and can hence be serialized as required.

The traits require a few other methods be implemented, those being the
fields that are common across all types. All other methods have a
default None implementation so that each response type only needs to
implement methods for fields that it has.

* [Game] Implement common traits for JCMP2 response

* [Fmt] Run cargo fmt

* Fix doctest failing

* Run cargo fmt
2023-06-25 16:31:23 +03:00
CosminPerRam
c3e2d948e8
[Game] Add JC2MP support. (#54)
* [Game] Add JC2MP support.

* [Game] Add game to changelog and games

* [Games] Add generic support to JC2MP.

* [Game] Add players_maximum and players_online
2023-06-19 22:10:49 +03:00
Tom
4b081371f4
[Crate] Add better documentation for generic game implementation (#49) 2023-06-14 23:25:26 +03:00
CosminPerRam
a377b76a55 [Games] Generic query add support for GS2 protocol and Halo:CE game 2023-06-13 22:09:51 +03:00
Tom
d853189e06
[Games] Programmatic games by storing information as data (#45)
* Define games as structs

* Create table of response types

* Ensure serde is always included

* Remove server_ prefix in GenericResponse

* Make players online/max non-optional in generic response

* Use already existing minecraft server enum

* Implement ExtraResponses to prevent cloning when creating generic

* Add game definitions

* Add doc comments to generic types

* Include players in gamespy extra responses

* Add custom response types for TheShip and FFOW

* Cargo format differing files

* Final cleanup
2023-06-13 21:49:58 +03:00
CosminPerRam
26ad1f5d19
[Protocol] Add GameSpy 2 support. (#47)
* [Protocol] Add initial files

* [Protocol] Add test to test the request

* [Protocol] Add initial query response type

* [Protocol] Parse teams

* [Protocol] Add players parse and add nice macro

* [Protocol] Add proper derives to structs

* [Protocol] Change to get all informations from one request

* [Protocol] Add Halo: CE support and update CHANGELOG.md

* [Protocol] Remove a .clone usage

* [Protocol] Add todo comment regarding code performance

* [Protocol] Use iterator instead of index range
2023-06-12 19:38:34 +03:00
CosminPerRam
80637f2398 [Crate] Apply clippy fixes 2023-06-11 13:16:22 +03:00