@@ -65,22 +65,34 @@ def __setattr__(self, attr, value):
6565
6666 def send (self , * player_indexes , ** tokens ):
6767 """Send the user message."""
68+ self ._categorize_and_send (player_indexes , tokens , False )
69+
70+ def send_reliable (self , * player_indexes , ** tokens ):
71+ """Send the user message using reliable stream.
72+
73+ Use this if you need to guarantee transmission of the message.
74+ """
75+ self ._categorize_and_send (player_indexes , tokens , True )
76+
77+ def _categorize_and_send (self , player_indexes , tokens , reliable ):
6878 player_indexes = RecipientFilter (* player_indexes )
6979 for language , indexes in self ._categorize_players_by_language (
7080 player_indexes ).items ():
7181 translated_kwargs = AttrDict (self )
7282 translated_kwargs .update (
7383 self ._get_translated_kwargs (language , tokens ))
74- self ._send (indexes , translated_kwargs )
84+ self ._send (indexes , translated_kwargs , reliable )
7585
76- def _send (self , player_indexes , translated_kwargs ):
86+ def _send (self , player_indexes , translated_kwargs , reliable ):
7787 """Send the user message to the given players.
7888
7989 :param iterable player_indexes: All players with the same language
8090 setting.
8191 :param AttrDict translated_kwargs: The translated arguments.
92+ :param bool reliable: Whether to set `RecipientFilter.reliable`.
8293 """
8394 recipients = RecipientFilter (* player_indexes )
95+ recipients .reliable = reliable
8496 user_message = UserMessage (recipients , self .message_name )
8597
8698 if user_message .is_protobuf ():
@@ -200,12 +212,23 @@ def __init__(self, menu_string, valid_slots=1023, display_time=4):
200212 display_time = display_time )
201213
202214 def send (self , * player_indexes ):
215+ """Send the user message."""
216+ self ._send (player_indexes , False )
217+
218+ def send_reliable (self , * player_indexes ):
219+ """Send the user message using reliable stream.
220+
221+ Use this if you need to guarantee transmission of the message."""
222+ self ._send (player_indexes , True )
223+
224+ def _send (self , player_indexes , reliable ):
203225 """Send the user message."""
204226 # We need to handle the ShowMenu user message with bitbuffers
205227 # differently, because the maximum size is 255. If the message exceeds
206228 # this length, we need to sent it in several parts.
207229 if UserMessage .is_protobuf ():
208230 recipients = RecipientFilter (* player_indexes )
231+ recipients .reliable = reliable
209232 user_message = UserMessage (recipients , self .message_name )
210233 self .protobuf (user_message .buffer , self )
211234 user_message .send ()
0 commit comments