Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into feat/implement_nexus
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed May 22, 2024
2 parents 5e748de + 9443aec commit 532755a
Show file tree
Hide file tree
Showing 42 changed files with 340 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
with:
options: "--check --verbose --exclude 'rustplus/api/remote/camera/camera_constants.py'"
src: "./rustplus"
version: "~= 22.0"
version: "~= 24.4.2"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ You can also join me on my discord server:
GitHub ⭐'s are always welcome :)

Have Fun!

## Special Thanks:
Thanks to [JetBrains](https://www.jetbrains.com/?from=rustplus) for providing me with a free Open Source License for
PyCharm Professional, which is what I use to develop this project.

<a href="https://jb.gg/OpenSourceSupport"><img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg" width="150"></a>
Binary file modified docs/.gitbook/assets/Untitled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ Head over to our GitHub repository [here](https://github.com/olijeffers0n/rustpl
## Need some help?

Head over to our discord server [here](https://lt.ollieee.xyz/rplusdiscord)

5 changes: 4 additions & 1 deletion docs/api-methods/getting-team-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ death_time: int

class RustTeamNote with fields:

type
type: int
x: float
y: float
icon: int
colour_index: int
label: string
```

So, to get the name of the first member in the team you can do:
Expand Down
2 changes: 1 addition & 1 deletion docs/api-methods/getting-the-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Getting the Image

Calling `rust_socket.get_map(add_icons: bool, add_events: bool, add_vending_machines: bool, override_images: dict)` will return a `PIL.Image` with the respective additions.
Calling `rust_socket.get_map(add_icons: bool, add_events: bool, add_vending_machines: bool, add_team_positions: bool, override_images: dict, add_grid: bool)` will return a `PIL.Image` with the respective additions.

### Getting the Map Data

Expand Down
3 changes: 1 addition & 2 deletions docs/getting-started/getting-player-details/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ In order to get your data, you need to:
"name": "",
"playerId": "", <- This is your steam player ID
"playerToken": "", <- This is your unique token
"port": "", <- This is the token
"port": "", <- This is the port
"type": "",
"url": ""
}
Expand All @@ -65,4 +65,3 @@ You can then use these details in the Python Wrapper here:
```python
rust_socket = RustSocket("IPADDRESS", "PORT", 64BITSTEAMID, PLAYERTOKEN)
```

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ http-ece
requests
numpy
scipy
betterproto==2.0.0b6
betterproto==2.0.0b6
3 changes: 3 additions & 0 deletions rustplus.proto
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ message AppTeamInfo {
required int32 type = 2;
required float x = 3;
required float y = 4;
optional int32 icon = 5;
optional int32 colourIndex = 6;
optional string label = 7;
}
}

Expand Down
2 changes: 1 addition & 1 deletion rustplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@

__name__ = "rustplus"
__author__ = "olijeffers0n"
__version__ = "5.6.10"
__version__ = "5.6.17"
__support__ = "Discord: https://discord.gg/nQqJe8qvP8"
43 changes: 33 additions & 10 deletions rustplus/api/base_rust_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from typing import List, Callable, Union
from typing import List, Union, Coroutine, Callable, Dict, Tuple
from PIL import Image

from .remote.events.event_loop_manager import EventLoopManager
Expand Down Expand Up @@ -38,6 +38,7 @@ def __init__(
use_test_server: bool = False,
event_loop: asyncio.AbstractEventLoop = None,
rate_limiter: RateLimiter = None,
debug: bool = False,
) -> None:
if ip is None:
raise ValueError("Ip cannot be None")
Expand All @@ -46,6 +47,16 @@ def __init__(
if player_token is None:
raise ValueError("PlayerToken cannot be None")

try:
steam_id = int(steam_id)
except ValueError:
raise ValueError("SteamID must be an integer")

try:
player_token = int(player_token)
except ValueError:
raise ValueError("PlayerToken must be an integer")

self.server_id = ServerID(ip, port, steam_id, player_token)
self.seq = 1
self.command_options = command_options
Expand All @@ -65,6 +76,7 @@ def __init__(
api=self,
use_test_server=use_test_server,
rate_limiter=rate_limiter,
debug=debug,
)

if heartbeat is None:
Expand Down Expand Up @@ -113,8 +125,10 @@ async def connect(
self,
retries: int = float("inf"),
delay: int = 20,
on_failure=None,
on_success=None,
on_failure: Union[Coroutine, Callable[[], None], None] = None,
on_success: Union[Coroutine, Callable[[], None], None] = None,
on_success_args_kwargs: Tuple[List, Dict] = ([], {}),
on_failure_args_kwargs: Tuple[List, Dict] = ([], {}),
) -> None:
"""
Attempts to open a connection to the rust game server specified in the constructor
Expand All @@ -123,24 +137,31 @@ async def connect(
:param delay: The delay (in seconds) between reconnection attempts.
:param on_failure: Optional function to be called when connecting fails.
:param on_success: Optional function to be called when connecting succeeds.
:param on_success_args_kwargs: Optional tuple holding keyword and regular arguments
for on_success in this format (args, kwargs)
:param on_failure_args_kwargs: Optional tuple holding keyword and regular arguments
for on_failure in this format (args, kwargs)
:return: None
"""
EventLoopManager.set_loop(
self.event_loop
if self.event_loop is not None
else asyncio.get_event_loop(),
(
self.event_loop
if self.event_loop is not None
else asyncio.get_event_loop()
),
self.server_id,
)

if not self.use_test_server:
ServerChecker(self.server_id.ip, self.server_id.port).run()

EventLoopManager.set_loop(
self.event_loop
if self.event_loop is not None
else asyncio.get_event_loop(),
(
self.event_loop
if self.event_loop is not None
else asyncio.get_event_loop()
),
self.server_id,
)

Expand All @@ -151,6 +172,8 @@ async def connect(
delay=delay,
on_failure=on_failure,
on_success=on_success,
on_success_args_kwargs=on_success_args_kwargs,
on_failure_args_kwargs=on_failure_args_kwargs,
)
await self.heartbeat.start_beat()
except ConnectionRefusedError:
Expand Down
Binary file modified rustplus/api/icons/arctic_base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rustplus/api/icons/desert_base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rustplus/api/icons/ferryterminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rustplus/api/icons/harbour.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rustplus/api/icons/mining_quarry_hqm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rustplus/api/icons/mining_quarry_stone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rustplus/api/icons/mining_quarry_sulfur.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rustplus/api/icons/missile_silo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rustplus/api/icons/patrol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed rustplus/api/icons/quarry.png
Binary file not shown.
Binary file removed rustplus/api/icons/stable.png
Binary file not shown.
Binary file added rustplus/api/icons/stables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions rustplus/api/remote/camera/camera_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ async def _create_frame(
last_packet.vertical_fov,
self._cam_info_message.far_plane,
entity_render_distance,
max_entity_amount
if max_entity_amount is not None
else len(self._last_packets.get_last().entities),
(
max_entity_amount
if max_entity_amount is not None
else len(self._last_packets.get_last().entities)
),
)

async def get_frame(
Expand Down
6 changes: 3 additions & 3 deletions rustplus/api/remote/camera/camera_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def process_rays_batch(self) -> bool:
] = (208, 230, 252)
distance = float("inf")

self.depth_output[
x : x + self.scale_factor, y : y + self.scale_factor
] = distance
self.depth_output[x : x + self.scale_factor, y : y + self.scale_factor] = (
distance
)

return False

Expand Down
6 changes: 3 additions & 3 deletions rustplus/api/remote/events/handler_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def get_handlers(
class EntityHandlerList(HandlerList):
def __init__(self) -> None:
super().__init__()
self._handlers: Dict[
ServerID, Dict[str, Set[RegisteredListener]]
] = defaultdict(dict)
self._handlers: Dict[ServerID, Dict[str, Set[RegisteredListener]]] = (
defaultdict(dict)
)

def unregister(self, listener: RegisteredListener, server_id: ServerID) -> None:
if listener.listener_id in self._handlers.get(server_id):
Expand Down
20 changes: 19 additions & 1 deletion rustplus/api/remote/rust_remote_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(
api=None,
use_test_server: bool = False,
rate_limiter: RateLimiter = None,
debug: bool = False,
) -> None:
self.server_id = server_id
self.api = api
Expand Down Expand Up @@ -65,8 +66,17 @@ def __init__(
self.use_test_server = use_test_server
self.pending_entity_subscriptions = []
self.camera_manager: Union[CameraManager, None] = None
self.debug = debug

async def connect(self, retries, delay, on_failure=None, on_success=None) -> None:
async def connect(
self,
retries,
delay,
on_failure,
on_success,
on_success_args_kwargs,
on_failure_args_kwargs,
) -> None:
self.ws = RustWebsocket(
server_id=self.server_id,
remote=self,
Expand All @@ -76,6 +86,9 @@ async def connect(self, retries, delay, on_failure=None, on_success=None) -> Non
on_failure=on_failure,
on_success=on_success,
delay=delay,
on_success_args_kwargs=on_success_args_kwargs,
on_failure_args_kwargs=on_failure_args_kwargs,
debug=self.debug,
)
await self.ws.connect(retries=retries)

Expand All @@ -102,6 +115,11 @@ async def send_message(self, request: AppRequest) -> None:
if self.ws is None:
raise ClientNotConnectedError("No Current Websocket Connection")

if self.debug:
self.logger.info(
f"[RustPlus.py] Sending Message with seq {request.seq}: {request}"
)

self.pending_response_events[request.seq] = YieldingEvent()
await self.ws.send_message(request)

Expand Down
3 changes: 3 additions & 0 deletions rustplus/api/remote/rustplus_proto/rustplus.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 532755a

Please sign in to comment.