Skip to content

Commit

Permalink
Add a load of Implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed Jun 24, 2024
1 parent f706cbc commit 1fd4a76
Show file tree
Hide file tree
Showing 109 changed files with 1,080 additions and 80 deletions.
Binary file removed rustplus-old/api/icons/airfield.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/arctic_base.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/bandit.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/barn.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/cargo.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/chinook.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/chinook_blades.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/crate.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/desert_base.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/dome.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/excavator.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/explosion.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/ferryterminal.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/fishing.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/harbour.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/icon.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/junkyard.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/large_oil_rig.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/launchsite.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/lighthouse.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/military_tunnels.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/mining_outpost.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/mining_quarry_hqm.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/mining_quarry_stone.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/mining_quarry_sulfur.png
Binary file not shown.
Binary file removed rustplus-old/api/icons/missile_silo.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/outpost.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/oxums.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/patrol.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/power_plant.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/satellite.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/sewer.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/small_oil_rig.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/stables.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/supermarket.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/swamp.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/train.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/train_yard.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/underwater_lab.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/vending_machine.png
Diff not rendered.
Binary file removed rustplus-old/api/icons/water_treatment.png
Diff not rendered.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions rustplus/remote/camera/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def is_move_option_permissible(self, value: int) -> bool:

def __str__(self) -> str:
return (
f"CameraInfo(width={self.width}, height={self.height}, near_plane={self.near_plane}, "
f"far_plane={self.far_plane}, control_flags={self.control_flags})"
f"CameraInfo[width={self.width}, height={self.height}, near_plane={self.near_plane}, "
f"far_plane={self.far_plane}, control_flags={self.control_flags}]"
)


Expand All @@ -32,8 +32,8 @@ def __init__(self, entity_data: AppCameraRaysEntity) -> None:

def __str__(self) -> str:
return (
f"Entity(entity_id={self.entity_id}, type={self.type}, position={self.position}, "
f"rotation={self.rotation}, size={self.size}, name={self.name})"
f"Entity[entity_id={self.entity_id}, type={self.type}, position={self.position}, "
f"rotation={self.rotation}, size={self.size}, name={self.name}]"
)

def __repr__(self):
Expand All @@ -56,7 +56,7 @@ def __hash__(self):
return hash((self.x, self.y, self.z))

def __str__(self) -> str:
return f"Vector3(x={self.x}, y={self.y}, z={self.z})"
return f"Vector3[x={self.x}, y={self.y}, z={self.z}]"


class RayPacket:
Expand All @@ -69,8 +69,8 @@ def __init__(self, ray_packet: AppCameraRays) -> None:

def __str__(self) -> str:
return (
f"RayPacket(vertical_fov={self.vertical_fov}, sample_offset={self.sample_offset}, "
f"ray_data={self.ray_data}, distance={self.distance}, entities={self.entities})"
f"RayPacket[vertical_fov={self.vertical_fov}, sample_offset={self.sample_offset}, "
f"ray_data={self.ray_data}, distance={self.distance}, entities={self.entities}]"
)


Expand Down
58 changes: 29 additions & 29 deletions rustplus/remote/websocket/ws.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import base64

import betterproto
from websockets.exceptions import InvalidURI, InvalidHandshake
from websockets.legacy.client import WebSocketClientProtocol
Expand All @@ -23,17 +21,13 @@ def __init__(self, server_id: ServerID) -> None:
self.logger: logging.Logger = logging.getLogger("rustplus.py")
self.task: Union[Task, None] = None
self.debug: bool = True
self.use_test_server: bool = True
self.use_test_server: bool = False

self.responses_to_ignore: Set[int] = set()
self.responses: Dict[int, YieldingEvent] = {}

async def connect(self) -> bool:

if self.use_test_server:
address = "wss://" + self.server_id.ip
else:
address = "ws://" + self.server_id.get_server_string()
address = "ws://" + self.server_id.get_server_string()

try:
self.connection = await connect(
Expand Down Expand Up @@ -78,36 +72,42 @@ async def run(self) -> None:
"An Error occurred whilst handling the message from the server"
)

async def send_message(self, request: AppRequest) -> None:
async def send_and_get(self, request: AppRequest) -> AppMessage:
await self.send_message(request)
return await self.get_response(request)

async def send_message(self, request: AppRequest, ignore_response: bool = False) -> None:
if self.connection is None:
raise ClientNotConnectedError("No Current Websocket Connection")

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

self.responses[request.seq] = YieldingEvent()
if not ignore_response:
self.responses[request.seq] = YieldingEvent()

try:
if self.use_test_server:
await self.connection.send(
base64.b64encode(bytes(request)).decode("utf-8")
)
else:
await self.connection.send(bytes(request))
except Exception:
self.logger.exception("An exception occurred whilst sending a message")
await self.connection.send(bytes(request))
except Exception as err:
self.logger.warning("WebSocket connection error: %s", err)

async def get_response(self, request: AppRequest) -> AppMessage:

response = await self.responses[request.seq].wait()
del self.responses[request.seq]

return response

async def handle_message(self, app_message: AppMessage) -> None:
if self.debug:
self.logger.info(
f"[RustPlus.py] Received Message with seq {app_message.response.seq}: {app_message}"
f"Received Message with seq {app_message.response.seq}: {app_message}"
)

if app_message.response.seq in self.responses_to_ignore:
self.responses_to_ignore.remove(app_message.response.seq)
return
if self.error_present(app_message.response.error.error):
raise Exception(app_message.response.error.error)

prefix = self.get_prefix(
str(app_message.broadcast.team_message.message.message)
Expand All @@ -118,7 +118,7 @@ async def handle_message(self, app_message: AppMessage) -> None:

if self.debug:
self.logger.info(
f"[RustPlus.py] Attempting to run Command: {app_message}"
f"Attempting to run Command: {app_message}"
)

message = RustChatMessage(app_message.broadcast.team_message.message)
Expand All @@ -128,7 +128,7 @@ async def handle_message(self, app_message: AppMessage) -> None:
# This means that an entity has changed state

if self.debug:
self.logger.info(f"[RustPlus.py] Running Entity Event: {app_message}")
self.logger.info(f"Running Entity Event: {app_message}")

# TODO
# await EventHandler.run_entity_event(
Expand All @@ -139,7 +139,7 @@ async def handle_message(self, app_message: AppMessage) -> None:

elif self.is_camera_broadcast(app_message):
if self.debug:
self.logger.info(f"[RustPlus.py] Running Camera Event: {app_message}")
self.logger.info(f"Running Camera Event: {app_message}")

# TODO
# if self.remote.camera_manager is not None:
Expand All @@ -149,7 +149,7 @@ async def handle_message(self, app_message: AppMessage) -> None:

elif self.is_team_broadcast(app_message):
if self.debug:
self.logger.info(f"[RustPlus.py] Running Team Event: {app_message}")
self.logger.info(f"Running Team Event: {app_message}")

# This means that the team of the current player has changed
# TODO await EventHandler.run_team_event(app_message, self.server_id)
Expand All @@ -158,7 +158,7 @@ async def handle_message(self, app_message: AppMessage) -> None:
# This means that a message has been sent to the team chat

if self.debug:
self.logger.info(f"[RustPlus.py] Running Chat Event: {app_message}")
self.logger.info(f"Running Chat Event: {app_message}")

steam_id = int(app_message.broadcast.team_message.message.steam_id)
message = str(app_message.broadcast.team_message.message.message)
Expand All @@ -171,7 +171,7 @@ async def handle_message(self, app_message: AppMessage) -> None:
if event is not None:
if self.debug:
self.logger.info(
f"[RustPlus.py] Running Response Event: {app_message}"
f"Running Response Event: {app_message}"
)

event.set_with_value(app_message)
Expand Down
Loading

0 comments on commit 1fd4a76

Please sign in to comment.