Skip to content

Commit

Permalink
Keep track of user's groups in their session
Browse files Browse the repository at this point in the history
  • Loading branch information
SaladDais committed Dec 31, 2023
1 parent e9d7ee7 commit 5ad8ee9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
5 changes: 2 additions & 3 deletions addon_examples/pixel_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ async def import_pixel_art(self, session: Session, region: ProxiedRegion):
) as get_events:
# Create a pool of prims to use for building the pixel art
for _ in range(needed_prims):
# TODO: We don't track the land group or user's active group, so
# "anyone can build" must be on for rezzing to work.
group_id = UUID()
# TODO: Can't get land group atm, just tries to rez with the user's active group
group_id = session.active_group
region.circuit.send(Message(
'ObjectAdd',
Block('AgentData', AgentID=session.agent_id, SessionID=session.id, GroupID=group_id),
Expand Down
1 change: 0 additions & 1 deletion client_examples/hello_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ async def _respond_to_chat(message: Message):
print("I'm here")
await client.send_chat("Hello World!", chat_type=ChatType.SHOUT)
client.session.message_handler.subscribe("ChatFromSimulator", _respond_to_chat)

# Example of how to work with caps
async with client.main_caps_client.get("SimulatorFeatures") as features_resp:
print("Features:", await features_resp.read_llsd())
Expand Down
10 changes: 10 additions & 0 deletions hippolyzer/apps/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ def handle_http_request(self, session_manager, flow):
selected.task_item = parsed["item-id"]


class AgentUpdaterAddon(BaseAddon):
def handle_eq_event(self, session: Session, region: ProxiedRegion, event: dict):
if event['message'] != 'AgentGroupDataUpdate':
return
session.groups.clear()
for group in event['body']['GroupData']:
session.groups.add(group['GroupID'])


class REPLAddon(BaseAddon):
@handle_command()
async def spawn_repl(self, session: Session, region: ProxiedRegion):
Expand All @@ -103,6 +112,7 @@ def start_proxy(session_manager: SessionManager, extra_addons: Optional[list] =
extra_addon_paths = extra_addon_paths or []
extra_addons.append(SelectionManagerAddon())
extra_addons.append(REPLAddon())
extra_addons.append(AgentUpdaterAddon())

root_log = logging.getLogger()
root_log.addHandler(logging.StreamHandler())
Expand Down
10 changes: 10 additions & 0 deletions hippolyzer/lib/client/hippo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ async def login(

self.session.transport, self.session.protocol = await self._create_transport()
self._resend_task = asyncio.create_task(self._attempt_resends())
self.session.message_handler.subscribe("AgentDataUpdate", self._handle_agent_data_update)
self.session.message_handler.subscribe("AgentGroupDataUpdate", self._handle_agent_group_data_update)

assert self.session.open_circuit(self.session.regions[-1].circuit_addr)
region = self.session.regions[-1]
Expand Down Expand Up @@ -729,3 +731,11 @@ async def _attempt_resends(self):
continue
region.circuit.resend_unacked()
await asyncio.sleep(0.5)

def _handle_agent_data_update(self, msg: Message):
self.session.active_group = msg["AgentData"]["ActiveGroupID"]

def _handle_agent_group_data_update(self, msg: Message):
self.session.groups.clear()
for block in msg["GroupData"]:
self.session.groups.add(block["GroupID"])
4 changes: 4 additions & 0 deletions hippolyzer/lib/client/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class BaseClientSession(abc.ABC):
id: UUID
agent_id: UUID
secure_session_id: UUID
active_group: UUID
groups: Set[UUID]
message_handler: MessageHandler[Message, str]
regions: MutableSequence[BaseClientRegion]
region_by_handle: Callable[[int], Optional[BaseClientRegion]]
Expand All @@ -100,6 +102,8 @@ def __init__(self, id, secure_session_id, agent_id, circuit_code,
self.circuit_code = circuit_code
self.global_caps = {}
self.session_manager = session_manager
self.active_group: UUID = UUID.ZERO
self.groups: Set[UUID] = set()
self.regions = []
self._main_region = None
self.message_handler: MessageHandler[Message, str] = MessageHandler()
Expand Down
2 changes: 2 additions & 0 deletions hippolyzer/lib/proxy/lludp_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def handle_proxied_packet(self, packet: UDPPacket):
region.mark_dead()
elif message.name == "RegionHandshake":
region.name = str(message["RegionInfo"][0]["SimName"])
elif message.name == "AgentDataUpdate" and self.session:
self.session.active_group = message["AgentData"]["ActiveGroupID"]

# Send the message if it wasn't explicitly dropped or sent before
if not message.finalized:
Expand Down

0 comments on commit 5ad8ee9

Please sign in to comment.