Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed Jul 1, 2023
1 parent 5aada61 commit 9af794f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 48 deletions.
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
betterproto==2.0.0b6
2 changes: 1 addition & 1 deletion rustplus/api/base_rust_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ async def send_wakeup_request(self) -> None:

app_request = self._generate_protobuf()
app_request.get_time = AppEmpty()
app_request.get_time._serialized_on_wire = True

await self.remote.add_ignored_response(app_request.seq)

Expand Down Expand Up @@ -445,6 +444,7 @@ async def hang() -> None:
while True:
await asyncio.sleep(1)

@deprecated("Implement this yourself. This will be removed in thed future")
def get_conversation_factory(self) -> ConversationFactory:
"""
Gets the current ConversationFactory object
Expand Down
9 changes: 3 additions & 6 deletions rustplus/api/remote/camera/camera_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from typing import Iterable, Union, List, Coroutine, TypeVar, Set, Callable
from typing import Iterable, Union, List, Coroutine, Set, Callable

from PIL import Image

Expand All @@ -14,14 +14,12 @@
from ...structures import Vector
from .structures import CameraInfo, Entity, LimitedQueue

RS = TypeVar("RS", bound="RustSocket")


class CameraManager:
def __init__(
self, rust_socket: RS, cam_id: str, cam_info_message: AppCameraInfo
self, rust_socket, cam_id: str, cam_info_message: AppCameraInfo
) -> None:
self.rust_socket: RS = rust_socket
self.rust_socket = rust_socket
self._cam_id: str = cam_id
self._last_packets: LimitedQueue = LimitedQueue(6)
self._cam_info_message: CameraInfo = CameraInfo(cam_info_message)
Expand Down Expand Up @@ -140,7 +138,6 @@ async def exit_camera(self) -> None:
await self.rust_socket._handle_ratelimit()
app_request: AppRequest = self.rust_socket._generate_protobuf()
app_request.camera_unsubscribe = AppEmpty()
app_request.camera_unsubscribe._serialized_on_wire = True

await self.rust_socket.remote.send_message(app_request)
await self.rust_socket.remote.add_ignored_response(app_request.seq)
Expand Down
16 changes: 4 additions & 12 deletions rustplus/api/remote/events/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,24 @@ async def run_entity_event(
return

for handler in handlers.copy():
coro, event_type = handler.data

await coro(EntityEvent(app_message, event_type))
await handler.get_coro()(EntityEvent(app_message, handler.get_entity_type()))

@staticmethod
async def run_team_event(app_message: AppMessage, server_id: ServerID) -> None:
handlers: Set[RegisteredListener] = TeamEvent.handlers.get_handlers(server_id)
for handler in handlers.copy():
coro = handler.data

await coro(TeamEvent(app_message))
await handler.get_coro()(TeamEvent(app_message))

@staticmethod
async def run_chat_event(app_message: AppMessage, server_id: ServerID) -> None:
handlers: Set[RegisteredListener] = ChatEvent.handlers.get_handlers(server_id)
for handler in handlers.copy():
coro = handler.data

await coro(ChatEvent(app_message))
await handler.get_coro()(ChatEvent(app_message))

@staticmethod
async def run_proto_event(byte_data: bytes, server_id: ServerID) -> None:
handlers: Set[RegisteredListener] = ProtobufEvent.handlers.get_handlers(
server_id
)
for handler in handlers.copy():
coro = handler.data

await coro(ProtobufEvent(byte_data))
await handler.get_coro()(ProtobufEvent(byte_data))
1 change: 1 addition & 0 deletions rustplus/api/remote/events/handler_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_handlers(

class EntityHandlerList(HandlerList):
def __init__(self) -> None:
super().__init__()
self._handlers: Dict[
ServerID, Dict[str, Set[RegisteredListener]]
] = defaultdict(dict)
Expand Down
30 changes: 14 additions & 16 deletions rustplus/api/remote/events/registered_listener.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
from typing import Union
from typing import Union, Coroutine


class RegisteredListener:
def __init__(self, listener_id: Union[str, int], data) -> None:
def __init__(self, listener_id: Union[str, int], coroutine: Coroutine, entity_type: int = None) -> None:
self.listener_id = str(listener_id)
self.data = data
self._coroutine = coroutine
self._entity_type = entity_type

def get_coro(self):
if isinstance(self.data, tuple):
return self.data[0]
return self.data
return self._coroutine

def get_entity_type(self):
return self._entity_type

def __eq__(self, other) -> bool:
if isinstance(other, RegisteredListener):
coro = self.data
if isinstance(self.data, tuple):
coro = self.data[0]
if not isinstance(other, RegisteredListener):
return False

return self.listener_id == other.listener_id and coro == coro
return False
return self.listener_id == other.listener_id and \
self._coroutine == other.get_coro() and \
self._entity_type == other.get_entity_type()

def __hash__(self):
coro = self.data
if isinstance(self.data, tuple):
coro = self.data[0]
return hash((self.listener_id, coro))
return hash((self.listener_id, self._coroutine, self._entity_type))
3 changes: 1 addition & 2 deletions rustplus/api/remote/rust_remote_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ async def get_entity_info(remote: RustRemote, eid):
app_request: AppRequest = remote.api._generate_protobuf()
app_request.entity_id = eid
app_request.get_entity_info = AppEmpty()
app_request.get_entity_info._serialized_on_wire = True

await remote.send_message(app_request)

Expand All @@ -196,7 +195,7 @@ def entity_event_callback(future_inner: Future) -> None:

EntityEvent.handlers.register(
RegisteredListener(
entity_id, (coroutine, entity_info.response.entity_info.type)
entity_id, coroutine, entity_info.response.entity_info.type
),
self.server_id,
)
Expand Down
8 changes: 0 additions & 8 deletions rustplus/api/rust_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ async def get_time(self) -> RustTime:

app_request = self._generate_protobuf()
app_request.get_time = AppEmpty()
app_request.get_time._serialized_on_wire = True

await self.remote.send_message(app_request)

Expand All @@ -102,7 +101,6 @@ async def get_info(self) -> RustInfo:

app_request = self._generate_protobuf()
app_request.get_info = AppEmpty()
app_request.get_info._serialized_on_wire = True

await self.remote.send_message(app_request)

Expand All @@ -115,7 +113,6 @@ async def get_team_chat(self) -> List[RustChatMessage]:

app_request = self._generate_protobuf()
app_request.get_team_chat = AppEmpty()
app_request.get_team_chat._serialized_on_wire = True

await self.remote.send_message(app_request)

Expand All @@ -130,7 +127,6 @@ async def get_team_info(self) -> RustTeamInfo:

app_request = self._generate_protobuf()
app_request.get_team_info = AppEmpty()
app_request.get_team_info._serialized_on_wire = True

await self.remote.send_message(app_request)

Expand All @@ -143,7 +139,6 @@ async def get_markers(self) -> List[RustMarker]:

app_request = self._generate_protobuf()
app_request.get_map_markers = AppEmpty()
app_request.get_map_markers._serialized_on_wire = True

await self.remote.send_message(app_request)

Expand All @@ -158,7 +153,6 @@ async def get_raw_map_data(self) -> RustMap:

app_request = self._generate_protobuf()
app_request.get_map = AppEmpty()
app_request.get_map._serialized_on_wire = True

await self.remote.send_message(app_request)

Expand Down Expand Up @@ -190,7 +184,6 @@ async def get_map(

app_request = self._generate_protobuf()
app_request.get_map = AppEmpty()
app_request.get_map._serialized_on_wire = True

await self.remote.send_message(app_request)

Expand Down Expand Up @@ -295,7 +288,6 @@ async def get_entity_info(self, eid: int = None) -> RustEntityInfo:
app_request = self._generate_protobuf()
app_request.entity_id = eid
app_request.get_entity_info = AppEmpty()
app_request.get_entity_info._serialized_on_wire = True

await self.remote.send_message(app_request)

Expand Down
4 changes: 2 additions & 2 deletions rustplus/utils/rust_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def entity_type_to_string(id) -> str:

def convert_xy_to_grid(
coords: tuple, map_size: float, catch_out_of_bounds: bool = True
) -> Tuple[int, int]:
grid_size = 146.3
) -> Tuple[str, int]:
grid_size = 146.28571428571428
grids = list(string.ascii_uppercase) + [
f"A{letter}" for letter in list(string.ascii_uppercase)
]
Expand Down

0 comments on commit 9af794f

Please sign in to comment.