@@ -57,6 +57,9 @@ class CommandID(IntEnum):
5757 # PC client is disconnecting
5858 DISCONNECT = auto ()
5959
60+ # PC client is sending slot information to wii
61+ AUTHENTICATE = auto ()
62+
6063 # PC client wants to display a message
6164 PRINT = auto ()
6265
@@ -159,7 +162,6 @@ async def disconnect(self):
159162
160163 self .established = False
161164
162-
163165 def handle_response (self , data ):
164166 """
165167 Handle incoming UDP response
@@ -374,6 +376,29 @@ def _cmd_check_locations(self, msg = "dummy") -> None:
374376
375377 Utils .async_start (self .ctx .check_locations ())
376378
379+ def _cmd_set_name (self , msg = "" ) -> None :
380+ """
381+ Set your slot name to authenticate the AP server with the game
382+
383+ @param self: WSRCommandProcessor
384+ @param msg: slot name
385+ """
386+ if not isinstance (self .ctx , WSRContext ):
387+ logger .info ("Please connect to the wii first" )
388+
389+ asyncio .create_task (self .ctx .write_slot_name (msg ))
390+ self .slot = msg
391+
392+ def _cmd_print_missing_locations (self , msg = "" ) -> None :
393+ """
394+ Docstring for _print_missing_locations
395+
396+ :param self: Description
397+ :param msg: Description
398+ """
399+ for location in self .ctx .missing_locations :
400+ logger .info (f"Missing Location: { location } " )
401+
377402# =============================================================================#
378403# Game context #
379404# =============================================================================#
@@ -387,6 +412,7 @@ class WSRContext(CommonContext):
387412
388413 command_processor = WSRCommandProcessor
389414 game : str = "Wii Sports Resort"
415+ items_handling : int = 0b001
390416
391417 def __init__ (self , server_address : Optional [str ], password : Optional [str ]) -> None :
392418 """
@@ -472,11 +498,13 @@ async def server_auth(self, password_requested: bool = False) -> None:
472498 await super ().server_auth (password_requested )
473499
474500 if not self .auth :
475- if not self .awaiting_rom :
476- self .awaiting_rom = True
477- self .log ("Waiting to connect to the game for player information." )
478- else :
479- await self .send_connect ()
501+ if self .awaiting_rom :
502+ return
503+ self .awaiting_rom = True
504+ logger .info ("Awaiting Slot Name..." )
505+ return
506+
507+ await self .send_connect ()
480508
481509
482510 def on_package (self , cmd : str , args : dict [str , Any ]) -> None :
@@ -503,7 +531,7 @@ def on_package(self, cmd: str, args: dict[str, Any]) -> None:
503531 pass
504532
505533 elif cmd == "PrintJSON" :
506- self .wii_client .send_print_cmd (args )
534+ Utils . async_start ( self .wii_client .send_print_cmd (args ) )
507535
508536
509537 async def give_items (self ) -> None :
@@ -530,27 +558,31 @@ async def check_locations(self) -> None:
530558 logger .info ("Please connect to the wii first" )
531559 return
532560
533- response = await self .wii_client .send_packet (bytes (), packet_type_id = CommandID .LOCATION )
561+ try :
562+ await self .wii_client .send_packet (bytes (), packet_type_id = CommandID .LOCATION )
563+ except Exception :
564+ return
534565
535566 p_data = self .wii_client .most_recent_packet_data
536567
537- if (int .from_bytes (( p_data ) , byteorder = "big" ) == 4294967295 ):
568+ if (int .from_bytes (p_data , byteorder = "big" ) == 0xFFFF ):
538569 return
539570
540- locations_checked = []
541- location = None
571+ new_locations_found = []
542572
543573 for i in range (0 , len (p_data ), 4 ):
544574 location = int .from_bytes (p_data [i :i + 4 ], byteorder = "big" )
545- for l in self .missing_locations :
546- logger .info (l )
547- if location in self .missing_locations :
548- self .locations_checked .add (WSRItem .get_apid (location ))
549- locations_checked .append (location )
550-
551- if locations_checked :
552- logger .info (f"Sending new check: { p_data } " )
553- await self .send_msgs ([{"cmd" : "LocationsChecks" , "locations" : locations_checked }])
575+
576+ logger .info (f"Location: { location } " )
577+
578+ if location in self .missing_locations and location not in self .locations_checked :
579+ self .locations_checked .add (location )
580+ new_locations_found .append (location )
581+
582+ logger .info (f"Found new location: { location } " )
583+
584+ if new_locations_found :
585+ await self .send_msgs ([{"cmd" : "LocationsChecks" , "locations" : new_locations_found }])
554586
555587
556588
@@ -580,6 +612,19 @@ async def _give_item(self, item_name: str) -> bool:
580612
581613 self .log ("failed to send item" )
582614 return False
615+
616+ async def write_slot_name (self , slot_name : str ):
617+ """
618+ Send the slot name to the wii
619+ """
620+ if not self .wii_client :
621+ return
622+
623+ packet = slot_name .encode ("utf-16-be" )
624+ packet += bytearray (2 )
625+
626+ if await self .wii_client .send_packet (packet , packet_type_id = CommandID .AUTHENTICATE ):
627+ self .auth = slot_name
583628
584629
585630 async def can_receive_items (self ) -> bool :
@@ -608,10 +653,12 @@ async def sync_loop(ctx: WSRContext) -> None:
608653
609654 try :
610655 if ctx .is_hooked ():
611- await ctx .give_items ()
612- await ctx .check_locations ()
613656 if ctx .awaiting_rom :
614657 await ctx .server_auth ()
658+
659+ await ctx .give_items ()
660+ await ctx .check_locations ()
661+
615662
616663 await asyncio .sleep (0.1 )
617664 else :
0 commit comments