astandy 0.3.0.2__tar.gz → 0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. {astandy-0.3.0.2 → astandy-0.4}/Astandy/__init__.py +4 -2
  2. {astandy-0.3.0.2 → astandy-0.4}/Astandy/client.py +78 -46
  3. astandy-0.4/Astandy/error_codes.py +182 -0
  4. astandy-0.4/Astandy/errors.py +46 -0
  5. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/__init__.py +3 -0
  6. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/events.py +1462 -1332
  7. astandy-0.4/Astandy/generated/metadata.py +5 -0
  8. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/achievement_message_pb2.py +43 -42
  9. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/achievement_message_pb2.pyi +64 -64
  10. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/ads_message_pb2.py +13 -12
  11. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/ads_message_pb2.pyi +4 -4
  12. astandy-0.4/Astandy/generated/protos/auth_message_pb2.py +203 -0
  13. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/auth_message_pb2.pyi +477 -335
  14. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/avatar_message_pb2.py +13 -12
  15. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/avatar_message_pb2.pyi +3 -3
  16. astandy-0.4/Astandy/generated/protos/challenges_message_pb2.py +83 -0
  17. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/challenges_message_pb2.pyi +171 -165
  18. astandy-0.4/Astandy/generated/protos/chat_message_pb2.py +104 -0
  19. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/chat_message_pb2.pyi +147 -157
  20. astandy-0.4/Astandy/generated/protos/clan_actions_message_pb2.py +174 -0
  21. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/clan_actions_message_pb2.pyi +278 -278
  22. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/clan_message_pb2.py +93 -92
  23. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/clan_message_pb2.pyi +264 -241
  24. astandy-0.4/Astandy/generated/protos/clan_messages_message_pb2.py +58 -0
  25. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/clan_messages_message_pb2.pyi +45 -45
  26. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/clan_stats_message_pb2.py +39 -38
  27. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/clan_stats_message_pb2.pyi +54 -54
  28. astandy-0.4/Astandy/generated/protos/cloud_code_message_pb2.py +49 -0
  29. astandy-0.4/Astandy/generated/protos/cloud_code_message_pb2.pyi +103 -0
  30. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/common_message_pb2.py +92 -91
  31. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/common_message_pb2.pyi +265 -228
  32. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/content_creator_message_pb2.py +25 -24
  33. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/content_creator_message_pb2.pyi +9 -9
  34. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/currency_message_pb2.py +13 -12
  35. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/currency_message_pb2.pyi +6 -6
  36. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/dlc_message_pb2.py +19 -18
  37. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/dlc_message_pb2.pyi +29 -29
  38. astandy-0.4/Astandy/generated/protos/friends_message_pb2.py +112 -0
  39. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/friends_message_pb2.pyi +179 -167
  40. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/game_event_message_pb2.py +113 -112
  41. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/game_event_message_pb2.pyi +246 -241
  42. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/game_settings_message_pb2.py +17 -16
  43. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/game_settings_message_pb2.pyi +23 -23
  44. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/gameserver_message_pb2.py +15 -14
  45. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/gameserver_message_pb2.pyi +6 -6
  46. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/gdpr_message_pb2.py +27 -26
  47. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/gdpr_message_pb2.pyi +39 -37
  48. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/groups_message_pb2.py +21 -20
  49. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/groups_message_pb2.pyi +18 -18
  50. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/hello_message_pb2.py +23 -22
  51. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/hello_message_pb2.pyi +11 -11
  52. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/id_token_message_pb2.py +11 -10
  53. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/id_token_message_pb2.pyi +2 -2
  54. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/inapps_message_pb2.py +61 -60
  55. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/inapps_message_pb2.pyi +117 -111
  56. astandy-0.4/Astandy/generated/protos/inventory_message_pb2.py +327 -0
  57. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/inventory_message_pb2.pyi +899 -856
  58. astandy-0.4/Astandy/generated/protos/leaderboard_message_pb2.py +39 -0
  59. astandy-0.4/Astandy/generated/protos/leaderboard_message_pb2.pyi +52 -0
  60. astandy-0.4/Astandy/generated/protos/marketplace_message_pb2.py +168 -0
  61. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/marketplace_message_pb2.pyi +456 -362
  62. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/matches_message_pb2.py +48 -47
  63. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/matches_message_pb2.pyi +120 -113
  64. astandy-0.4/Astandy/generated/protos/matchmaking_message_pb2.py +218 -0
  65. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/matchmaking_message_pb2.pyi +459 -448
  66. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/message_pb2.py +33 -32
  67. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/message_pb2.pyi +70 -64
  68. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/money_message_pb2.py +9 -8
  69. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/money_message_pb2.pyi +3 -3
  70. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/newsfeed_message_pb2.py +25 -24
  71. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/newsfeed_message_pb2.pyi +43 -43
  72. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/offers_message_pb2.py +27 -26
  73. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/offers_message_pb2.pyi +61 -59
  74. astandy-0.4/Astandy/generated/protos/player_message_pb2.py +152 -0
  75. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/player_message_pb2.pyi +334 -297
  76. astandy-0.4/Astandy/generated/protos/player_stats_message_pb2.py +74 -0
  77. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/player_stats_message_pb2.pyi +124 -122
  78. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/rate_message_pb2.py +25 -24
  79. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/rate_message_pb2.pyi +75 -75
  80. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/referral_message_pb2.py +61 -60
  81. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/referral_message_pb2.pyi +167 -162
  82. astandy-0.4/Astandy/generated/protos/relay_message_pb2.py +39 -0
  83. astandy-0.4/Astandy/generated/protos/relay_message_pb2.pyi +38 -0
  84. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/rent_market_message_pb2.py +95 -94
  85. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/rent_market_message_pb2.pyi +259 -259
  86. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/rpc_message_pb2.py +57 -56
  87. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/rpc_message_pb2.pyi +136 -136
  88. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/seasonal_stats_message_pb2.py +23 -22
  89. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/seasonal_stats_message_pb2.pyi +36 -36
  90. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/stats_message_pb2.py +9 -8
  91. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/stats_message_pb2.pyi +7 -4
  92. astandy-0.4/Astandy/generated/protos/storage_message_pb2.py +81 -0
  93. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/storage_message_pb2.pyi +120 -117
  94. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/system_messages_message_pb2.py +107 -106
  95. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/system_messages_message_pb2.pyi +319 -295
  96. astandy-0.4/Astandy/generated/services.py +4602 -0
  97. {astandy-0.3.0.2 → astandy-0.4}/Astandy/parser.py +6 -2
  98. {astandy-0.3.0.2 → astandy-0.4}/Astandy/services/bolt.py +1 -1
  99. {astandy-0.3.0.2 → astandy-0.4}/Astandy/services/hello.py +7 -12
  100. {astandy-0.3.0.2 → astandy-0.4}/Astandy/services/player.py +1 -1
  101. astandy-0.4/Astandy/somnia.py +180 -0
  102. {astandy-0.3.0.2 → astandy-0.4}/Astandy/types/rpc_target.py +1 -1
  103. astandy-0.4/PKG-INFO +165 -0
  104. astandy-0.4/README.md +149 -0
  105. astandy-0.4/astandy.egg-info/PKG-INFO +165 -0
  106. {astandy-0.3.0.2 → astandy-0.4}/astandy.egg-info/SOURCES.txt +11 -19
  107. astandy-0.4/astandy.egg-info/requires.txt +5 -0
  108. {astandy-0.3.0.2 → astandy-0.4}/pyproject.toml +4 -3
  109. astandy-0.4/tests/test_docs_generation.py +53 -0
  110. astandy-0.4/tests/test_rpc_errors.py +157 -0
  111. astandy-0.4/tests/test_somnia.py +165 -0
  112. astandy-0.3.0.2/Astandy/errors.py +0 -1
  113. astandy-0.3.0.2/Astandy/generated/protos/accusation_message_pb2.py +0 -29
  114. astandy-0.3.0.2/Astandy/generated/protos/accusation_message_pb2.pyi +0 -23
  115. astandy-0.3.0.2/Astandy/generated/protos/analytics_message_pb2.py +0 -30
  116. astandy-0.3.0.2/Astandy/generated/protos/analytics_message_pb2.pyi +0 -30
  117. astandy-0.3.0.2/Astandy/generated/protos/auth_message_pb2.py +0 -170
  118. astandy-0.3.0.2/Astandy/generated/protos/challenges_message_pb2.py +0 -82
  119. astandy-0.3.0.2/Astandy/generated/protos/chat_message_pb2.py +0 -107
  120. astandy-0.3.0.2/Astandy/generated/protos/clan_actions_message_pb2.py +0 -173
  121. astandy-0.3.0.2/Astandy/generated/protos/clan_member_stats_message_pb2.py +0 -39
  122. astandy-0.3.0.2/Astandy/generated/protos/clan_member_stats_message_pb2.pyi +0 -49
  123. astandy-0.3.0.2/Astandy/generated/protos/clan_messages_message_pb2.py +0 -57
  124. astandy-0.3.0.2/Astandy/generated/protos/friends_message_pb2.py +0 -109
  125. astandy-0.3.0.2/Astandy/generated/protos/game_season_message_pb2.py +0 -30
  126. astandy-0.3.0.2/Astandy/generated/protos/game_season_message_pb2.pyi +0 -24
  127. astandy-0.3.0.2/Astandy/generated/protos/gs_clan_stats_message_pb2.py +0 -33
  128. astandy-0.3.0.2/Astandy/generated/protos/gs_clan_stats_message_pb2.pyi +0 -43
  129. astandy-0.3.0.2/Astandy/generated/protos/gs_player_stats_message_pb2.py +0 -33
  130. astandy-0.3.0.2/Astandy/generated/protos/gs_player_stats_message_pb2.pyi +0 -31
  131. astandy-0.3.0.2/Astandy/generated/protos/hack_message_pb2.py +0 -26
  132. astandy-0.3.0.2/Astandy/generated/protos/hack_message_pb2.pyi +0 -18
  133. astandy-0.3.0.2/Astandy/generated/protos/inventory_message_pb2.py +0 -310
  134. astandy-0.3.0.2/Astandy/generated/protos/leaderboard_message_pb2.py +0 -47
  135. astandy-0.3.0.2/Astandy/generated/protos/leaderboard_message_pb2.pyi +0 -97
  136. astandy-0.3.0.2/Astandy/generated/protos/marketplace_message_pb2.py +0 -157
  137. astandy-0.3.0.2/Astandy/generated/protos/matchmaking_message_pb2.py +0 -217
  138. astandy-0.3.0.2/Astandy/generated/protos/player_message_pb2.py +0 -149
  139. astandy-0.3.0.2/Astandy/generated/protos/player_stats_message_pb2.py +0 -73
  140. astandy-0.3.0.2/Astandy/generated/protos/storage_message_pb2.py +0 -80
  141. astandy-0.3.0.2/Astandy/generated/protos/tournaments_message_pb2.py +0 -64
  142. astandy-0.3.0.2/Astandy/generated/protos/tournaments_message_pb2.pyi +0 -132
  143. astandy-0.3.0.2/Astandy/generated/protos/ugc_message_pb2.py +0 -40
  144. astandy-0.3.0.2/Astandy/generated/protos/ugc_message_pb2.pyi +0 -86
  145. astandy-0.3.0.2/Astandy/generated/services.py +0 -7046
  146. astandy-0.3.0.2/PKG-INFO +0 -71
  147. astandy-0.3.0.2/README.md +0 -56
  148. astandy-0.3.0.2/astandy.egg-info/PKG-INFO +0 -71
  149. astandy-0.3.0.2/astandy.egg-info/requires.txt +0 -4
  150. {astandy-0.3.0.2 → astandy-0.4}/Astandy/cipher.py +0 -0
  151. {astandy-0.3.0.2 → astandy-0.4}/Astandy/dispatcher.py +0 -0
  152. {astandy-0.3.0.2 → astandy-0.4}/Astandy/enums/__init__.py +0 -0
  153. {astandy-0.3.0.2 → astandy-0.4}/Astandy/enums/events.py +0 -0
  154. {astandy-0.3.0.2 → astandy-0.4}/Astandy/events/__init__.py +0 -0
  155. {astandy-0.3.0.2 → astandy-0.4}/Astandy/events/onConnect.py +0 -0
  156. {astandy-0.3.0.2 → astandy-0.4}/Astandy/generated/protos/__init__.py +0 -0
  157. {astandy-0.3.0.2 → astandy-0.4}/Astandy/listener.py +0 -0
  158. {astandy-0.3.0.2 → astandy-0.4}/Astandy/listeners/__init__.py +0 -0
  159. {astandy-0.3.0.2 → astandy-0.4}/Astandy/listeners/onConnect.py +0 -0
  160. {astandy-0.3.0.2 → astandy-0.4}/Astandy/logging.py +0 -0
  161. {astandy-0.3.0.2 → astandy-0.4}/Astandy/old_generated/__init__.py +0 -0
  162. {astandy-0.3.0.2 → astandy-0.4}/Astandy/old_generated/listeners.py +0 -0
  163. {astandy-0.3.0.2 → astandy-0.4}/Astandy/old_generated/schemes_pb2.py +0 -0
  164. {astandy-0.3.0.2 → astandy-0.4}/Astandy/old_generated/schemes_pb2.pyi +0 -0
  165. {astandy-0.3.0.2 → astandy-0.4}/Astandy/old_generated/services.py +0 -0
  166. {astandy-0.3.0.2 → astandy-0.4}/Astandy/schemes/messages_pb2.py +0 -0
  167. {astandy-0.3.0.2 → astandy-0.4}/Astandy/schemes/messages_pb2.pyi +0 -0
  168. {astandy-0.3.0.2 → astandy-0.4}/Astandy/services/__init__.py +0 -0
  169. {astandy-0.3.0.2 → astandy-0.4}/Astandy/services/handshake.py +0 -0
  170. {astandy-0.3.0.2 → astandy-0.4}/Astandy/types/__init__.py +0 -0
  171. {astandy-0.3.0.2 → astandy-0.4}/Astandy/types/extras.py +0 -0
  172. {astandy-0.3.0.2 → astandy-0.4}/Astandy/types/gmessage.py +0 -0
  173. {astandy-0.3.0.2 → astandy-0.4}/Astandy/types/service.py +0 -0
  174. {astandy-0.3.0.2 → astandy-0.4}/Astandy/types/update.py +0 -0
  175. {astandy-0.3.0.2 → astandy-0.4}/Astandy/updates/__init__.py +0 -0
  176. {astandy-0.3.0.2 → astandy-0.4}/Astandy/updates/connect.py +0 -0
  177. {astandy-0.3.0.2 → astandy-0.4}/Astandy/utils.py +0 -0
  178. {astandy-0.3.0.2 → astandy-0.4}/MANIFEST.in +0 -0
  179. {astandy-0.3.0.2 → astandy-0.4}/astandy.egg-info/dependency_links.txt +0 -0
  180. {astandy-0.3.0.2 → astandy-0.4}/astandy.egg-info/top_level.txt +0 -0
  181. {astandy-0.3.0.2 → astandy-0.4}/setup.cfg +0 -0
@@ -1,6 +1,7 @@
1
- version = "0.3"
1
+ version = "0.4"
2
2
 
3
3
  from .client import StandClient
4
+ from .somnia import SomniaClient
4
5
  from .updates import *
5
6
 
6
7
  import logging
@@ -40,5 +41,6 @@ logging.basicConfig(
40
41
  )
41
42
 
42
43
  __all__ = [
43
- "StandClient"
44
+ "StandClient",
45
+ "SomniaClient"
44
46
  ]
@@ -25,7 +25,7 @@ from .updates import Connected
25
25
  from .utils import run_on_uvloop
26
26
  from .parser import Parser
27
27
  from .schemes.messages_pb2 import Response, ServerMsg
28
- from .errors import AstandyRPCException
28
+ from .errors import AstandyRPCException, AstandyRPCTimeoutError, AstandyConnectionError
29
29
  from . import version
30
30
 
31
31
  REQUEST_TIMEOUT = 15
@@ -111,6 +111,7 @@ class StandClient(Services, BaseEvents, Generated):
111
111
 
112
112
  async def _connect(self):
113
113
  await self._disconnect()
114
+ self._sock = None
114
115
 
115
116
  context = ssl.create_default_context()
116
117
  if not CADATA:
@@ -138,6 +139,7 @@ class StandClient(Services, BaseEvents, Generated):
138
139
  self._running = True
139
140
 
140
141
  async def _disconnect(self):
142
+ self._fail_pending_requests()
141
143
  try:
142
144
  if self._writer:
143
145
  self._writer.close()
@@ -152,6 +154,14 @@ class StandClient(Services, BaseEvents, Generated):
152
154
  self._authenticated.clear()
153
155
  self._connected.clear()
154
156
 
157
+ def _fail_pending_requests(self):
158
+ for request_id, future in list(self._pending_requests.items()):
159
+ if not future.done():
160
+ future.set_exception(AstandyConnectionError(
161
+ "Connection closed before the RPC response arrived.",
162
+ request_id=request_id,
163
+ ))
164
+
155
165
  async def start(self):
156
166
  """
157
167
  Start the client.
@@ -206,10 +216,14 @@ class StandClient(Services, BaseEvents, Generated):
206
216
 
207
217
  await self._disconnect()
208
218
 
219
+ async def _before_connected(self):
220
+ """Await session setup after hello, before start() and OnConnect."""
221
+ pass
222
+
209
223
  async def _initialize(self):
210
224
  try:
211
225
  await self.hello()
212
- await self.handshake(self._handshake)
226
+ await self._before_connected()
213
227
  asyncio.create_task(self._ping_loop())
214
228
  self._authenticated.set()
215
229
 
@@ -221,23 +235,28 @@ class StandClient(Services, BaseEvents, Generated):
221
235
  except AstandyRPCException as ex:
222
236
  self.logger.critical(f'Failed to authorize {ex}!')
223
237
  self._running = False
224
-
238
+ except Exception:
239
+ self.logger.exception('Failed to initialize session')
240
+ self._running = False
225
241
 
226
242
  async def _read_loop(self):
227
- while self._running:
228
- await asyncio.sleep(0.001)
229
- msg_leng = await self._read_header()
230
- if msg_leng <= 0: continue
243
+ try:
244
+ while self._running:
245
+ await asyncio.sleep(0.001)
246
+ msg_leng = await self._read_header()
247
+ if msg_leng <= 0: continue
231
248
 
232
- msg = await self._read_exactly(msg_leng, timeout=1)
233
- if not msg: continue
249
+ msg = await self._read_exactly(msg_leng, timeout=1)
250
+ if not msg: continue
234
251
 
235
- if msg == b'\x01':
236
- self._pending_ping.set()
237
- continue
252
+ if msg == b'\x01':
253
+ self._pending_ping.set()
254
+ continue
238
255
 
239
- asyncio.create_task(self._handle_msg(Parser.parse_response(msg)))
240
- self._running = False
256
+ asyncio.create_task(self._handle_msg(Parser.parse_response(msg)))
257
+ finally:
258
+ self._running = False
259
+ self._fail_pending_requests()
241
260
 
242
261
  async def _ping_loop(self):
243
262
  self._logger.extra = self._connect_info
@@ -279,8 +298,9 @@ class StandClient(Services, BaseEvents, Generated):
279
298
 
280
299
  async def _handle_msg(self, server_msg: ServerMsg):
281
300
  for response in server_msg.responses:
282
- if response.id in self._pending_requests:
283
- self._pending_requests[response.id].set_result(response)
301
+ future = self._pending_requests.get(response.id)
302
+ if future is not None and not future.done():
303
+ future.set_result(response)
284
304
  else:
285
305
  self._logger.warning(f"Skipped {response.id} response!")
286
306
 
@@ -297,45 +317,57 @@ class StandClient(Services, BaseEvents, Generated):
297
317
  data = lz4.block.decompress(compressed.compressed, uncompressed_size=compressed.uncompressed_size)
298
318
  await self._handle_msg(Parser.parse_response(data))
299
319
 
300
- async def rpc_call(self, target: RpcTarget, timeout: int = REQUEST_TIMEOUT) -> Response:
301
- """
302
- Sending request to game servers and waiting for response
320
+ async def rpc_call(self, target: RpcTarget, timeout: float | None = REQUEST_TIMEOUT) -> Response:
321
+ """Send an RPC and raise server, timeout, or connection errors.
303
322
 
304
- :param target: RPC target
305
- :parama timeout: Timeout for waiting response
323
+ :param target: RPC target.
324
+ :param timeout: Total seconds allowed for sending and receiving, or None.
325
+ :raises AstandyRPCException: The server rejected the request.
326
+ :raises AstandyRPCTimeoutError: The RPC exceeded its total timeout.
327
+ :raises AstandyConnectionError: The transport failed or disconnected.
306
328
  """
307
- uuid = str(uuid4())
308
- future = asyncio.get_event_loop().create_future()
309
- self._pending_requests[uuid] = future
310
-
311
- payload = target.request
312
- if target.secure: payload = self.cipher.encrypt(payload)
313
-
314
- result: Response = Response()
315
- if not await self._send_payload(
316
- Parser.new_msg(uuid, target.code, payload, target.service, target.method)
317
- ):
318
- self._pending_requests.pop(uuid)
319
- raise ConnectionError("Failed to send payload: Connection lost or closed.")
320
-
329
+ request_id = str(uuid4())
330
+ future = asyncio.get_running_loop().create_future()
331
+ self._pending_requests[request_id] = future
332
+
333
+ async def exchange():
334
+ if not await self._send_payload(Parser.new_msg(
335
+ request_id, target.code, target.request, target.service, target.method
336
+ )):
337
+ raise AstandyConnectionError(
338
+ "Failed to send RPC: connection lost or closed.",
339
+ request_id=request_id, service=target.service, method=target.method,
340
+ )
341
+ return await future
342
+
321
343
  try:
322
- result = await asyncio.wait_for(future, timeout=timeout)
323
- if target.secure:
324
- for i in range(len(result.data)):
325
- result.data[i].one = self.cipher.decrypt(result.data[i].one)
326
- except asyncio.TimeoutError:
327
- self._logger.warning(f"Request {uuid} timeout after {timeout} seconds")
344
+ response = await asyncio.wait_for(exchange(), timeout=timeout)
345
+ Parser.raise_for_exception(response, target=target)
346
+ return response
347
+ except asyncio.TimeoutError as exc:
348
+ raise AstandyRPCTimeoutError(target, request_id, timeout) from exc
349
+ except AstandyConnectionError as exc:
350
+ exc.service = target.service
351
+ exc.method = target.method
352
+ raise
353
+ except OSError as exc:
354
+ raise AstandyConnectionError(
355
+ "Transport failed during RPC.", request_id=request_id,
356
+ service=target.service, method=target.method,
357
+ ) from exc
328
358
  finally:
329
- self._pending_requests.pop(uuid)
359
+ self._pending_requests.pop(request_id, None)
360
+ if not future.done():
361
+ future.cancel()
362
+ elif not future.cancelled():
363
+ future.exception() # Retrieve disconnect errors even if sending failed.
330
364
 
331
- return result
332
-
333
365
  async def send_request(self, code: int, request:bytes):
334
366
  """
335
367
  Sending request to game servers and waiting for response
336
368
 
337
- :param target: Rpc method code
338
- :parama request: Request data
369
+ :param code: RPC method code
370
+ :param request: Request data
339
371
  """
340
372
  return await self.rpc_call(
341
373
  RpcTarget(
@@ -0,0 +1,182 @@
1
+ """RPC descriptions from https://github.com/BonePolk/AstandyClient/pull/1.
2
+
3
+ Code 405 comes from the existing project documentation.
4
+ """
5
+
6
+ RPC_ERROR_DESCRIPTIONS = {400: 'Request failed. Please try again later.',
7
+ 401: "You haven't logged in yet. Sign in to your game account.",
8
+ 404: 'Request not found or expired. Refresh the screen and try again.',
9
+ 405: 'Encryption error.',
10
+ 500: 'A server error has occurred.\n'
11
+ "We'll have all the issues fixed very soon. Please try again later.\n"
12
+ 'Code: 500',
13
+ 600: 'Failed to connect to servers. Code: 600',
14
+ 1001: 'Invalid data. Please try again.',
15
+ 1002: 'Hacking app detected! (Game Guardian, Game Killer, or other)',
16
+ 1003: 'Your device is rooted so you cannot connect. Please, unroot the device and try again.',
17
+ 1006: 'It seems that you have a third-party version of Standoff 2 installed on your device. '
18
+ 'Please, download the game from official sources (App Store, Google Play, GetApps or '
19
+ 'AppGallery).',
20
+ 1007: 'Google security check failed. Restart the game and try again.',
21
+ 1100: 'Action blocked or not available right now. Check the requirements and try again.',
22
+ 1200: 'Please enter a valid email address',
23
+ 1201: 'A data export request has already been made for this account. Please wait for the results '
24
+ 'to be sent to the specified email address.',
25
+ 1202: 'Account recovery failed. Deletion request not found. Make sure you are using the right '
26
+ 'account.',
27
+ 1500: 'This feature has been temporarily disabled. We are working on restoring it. Please try '
28
+ 'again later.',
29
+ 1501: 'This authorization method is currently unavailable. Please, wait a while or choose another '
30
+ 'method.',
31
+ 1511: 'This feature has been temporarily disabled. We are working on restoring it. Please try '
32
+ 'again later.',
33
+ 1512: 'This feature has been temporarily disabled. We are working on restoring it. Please try '
34
+ 'again later.',
35
+ 1513: 'This feature has been temporarily disabled. We are working on restoring it. Please try '
36
+ 'again later.',
37
+ 1514: 'This feature has been temporarily disabled. We are working on restoring it. Please try '
38
+ 'again later.',
39
+ 2000: 'A new version of Standoff 2 is available. You can download the update in your application '
40
+ 'store.',
41
+ 2001: 'Match not found or no longer available.',
42
+ 2002: 'Not enough Clan rights. Message the Clan Leader or an Officer for help.',
43
+ 2003: 'Session time expired. Please restart the game.',
44
+ 2007: 'Could not connect to the server. Try again later or restart the game.',
45
+ 2008: 'Clan not found',
46
+ 2009: 'This player is not in your Clan. Action not available.',
47
+ 2010: 'You have already sent an application to this clan.',
48
+ 2011: 'You already invited this player to the Clan. Wait for their reply or cancel the invite.',
49
+ 2013: 'You cannot add a player because the clan is full.\n'
50
+ 'Increase the max number of clan members and try again.',
51
+ 2015: 'Cannot expand the lobby. Player limit reached.',
52
+ 2016: 'Invalid clan tag',
53
+ 2017: 'Invalid clan name',
54
+ 2018: 'Clan name is already in use',
55
+ 2019: 'Tag is already in use',
56
+ 2020: 'You already sent a clan invitation.',
57
+ 2022: 'Restricted words are used',
58
+ 2023: 'Leadership can be transferred only 14 days after the creation of the clan.',
59
+ 2024: 'This player is not in your Clan. Action not available.',
60
+ 2025: 'You can’t leave the clan while other members are in there',
61
+ 2026: 'The action is unavailable because this clan is blocked',
62
+ 2101: 'Account linked to this login service not found. Make sure you are using the right profile.',
63
+ 2104: 'Unable to sign in through that service. Please try again later.',
64
+ 2105: 'This service is already linked to an account. Please use a different login method.',
65
+ 2107: 'Unable to link account. The account selected is already linked to another Standoff 2 '
66
+ 'profile.',
67
+ 2201: 'Google Play authentication failed',
68
+ 2202: 'Google Play authentication failed',
69
+ 2203: 'Google Play authentication failed',
70
+ 2204: 'Google sign in failed. Please try again later.',
71
+ 2205: 'Something went wrong with Google sign in. Try again later or use a different login method.',
72
+ 2211: 'We had a problem logging you in via Game Center.',
73
+ 2221: 'Could not confirm your Apple ID/Huawei login. Sign out and sign back in.',
74
+ 2231: 'VK sign in failed. Please try again later.',
75
+ 2301: 'This statistic is not available right now. Update the game and try again.',
76
+ 2501: 'This player has restricted conversations in their privacy settings. Your message cannot be '
77
+ 'delivered.',
78
+ 2502: "This player isn't accepting clan invitations.",
79
+ 2503: "This player isn't accepting lobby invitations.",
80
+ 2504: "This player isn't accepting friend requests.",
81
+ 2505: 'This player made their match history private.',
82
+ 2506: 'This player made their statistics private.',
83
+ 2601: 'You have reached your friend limit. Please unfriend someone from your list and try again.',
84
+ 2602: "You've sent too many friend requests in the last 24 hours. Please try again later.",
85
+ 3002: 'You are currently in a match. Please finish it before starting another.',
86
+ 3003: 'Match not started. You can only do this during a match.',
87
+ 3005: 'Team size is not right for a Clan match. Get the right number of players and try again.',
88
+ 3006: 'No competitive filters selected. Please try again.',
89
+ 3007: 'You are not in this Clan. Cannot join a Clan match.',
90
+ 3008: 'This mode requires a higher account level.',
91
+ 3101: 'Player not found',
92
+ 3102: 'This player has blocked you.',
93
+ 3104: 'Too many messages. Please wait and try again.',
94
+ 3105: 'Invalid name or tag.',
95
+ 3106: 'Chat with this player not found. Send them a message again.',
96
+ 3107: 'This avatar is not available. Please choose a different one.',
97
+ 3108: 'In the past 24 hours, you have sent too many messages to users who are not on your friend '
98
+ 'list. Try again later.',
99
+ 3109: 'Invalid nickname. Check length and allowed characters.',
100
+ 3110: 'Failed to upload an avatar picture. You’re changing your avatar image too often. Try again '
101
+ 'later.',
102
+ 3202: 'The item was not found.\n'
103
+ 'It may have been used in crafting or put up for sale in the Marketplace.',
104
+ 3204: 'Failed to list item. Wrong item selection or data mismatch. Try selecting the item again.',
105
+ 3205: 'You are trying to list too many items at once. Try listing fewer items.',
106
+ 3301: 'This currency is not available right now. Try again later.',
107
+ 3302: "This item can't be purchased",
108
+ 3303: 'Not enough currency for this action.',
109
+ 3304: 'You do not have the required items for this action.',
110
+ 3305: 'Invalid operation. Check your action and try again.',
111
+ 3306: 'The lot was not found.\nIt may already have been sold or removed from the Marketplace.',
112
+ 3307: 'Your price is below the Marketplace minimum. Please set a higher price.',
113
+ 3308: 'You cannot sell this item on the Marketplace.',
114
+ 3311: 'Invalid operation. Check your action and try again.',
115
+ 3312: 'You already made a purchase request for this item.',
116
+ 3313: 'You cannot buy or sell this item on the Marketplace.',
117
+ 3314: 'Please enter a valid number of items.',
118
+ 3315: 'This item is already listed for sale.',
119
+ 3321: "You can't perform that operation with a negative balance.",
120
+ 3322: 'This modification is not found or not available. Please choose another and retry.',
121
+ 3323: 'You cannot remove this modification from the item.',
122
+ 3324: 'You cannot sell an item with a charm attached. Remove it first and try again.',
123
+ 3325: 'You cannot use this item as a modification.',
124
+ 3326: 'This modification does not fit that item or slot.',
125
+ 3327: "The Rental Market is closed. Your request can't be fulfilled.",
126
+ 3328: 'You’ve reached the limit of transactions on the market. Try again later.',
127
+ 3401: 'Crafting recipe not found.',
128
+ 3402: 'You need more resources to do that.',
129
+ 3403: 'Not enough resources to complete this action.',
130
+ 3404: 'Too many components selected. Please choose the right amount.',
131
+ 3405: 'Too many attempts. Please wait and try again.',
132
+ 3406: 'Too many attempts in a row. Please wait and try again.',
133
+ 3407: 'Operation declined. Try again later.',
134
+ 3411: 'This action does not support multipliers. Remove it and try again.',
135
+ 3501: 'Event not found or no longer available. Check the current events in the game.',
136
+ 3502: 'Could not claim reward. Please try again.',
137
+ 3601: 'Challenge not found or no longer available. Refresh the challenge list and try again.',
138
+ 3701: 'Challenge not found or no longer available.',
139
+ 3704: 'This task expired. Progress not saved.',
140
+ 3705: 'Could not update quest progress. Restart the game and try again.',
141
+ 3801: 'Invalid code.',
142
+ 3802: 'This code has already been activated on your account.',
143
+ 3803: 'This code has reached its activation limit.',
144
+ 3804: 'Too many code activation attempts. Try again later.',
145
+ 4002: 'Could not find the match. It might be over or unavailable.',
146
+ 4101: 'System message not found.',
147
+ 5001: 'Lobby not found',
148
+ 5002: 'Only the lobby owner can do this.',
149
+ 5003: 'You are not a member of this lobby',
150
+ 5004: 'You are not in a lobby.',
151
+ 5005: 'No access to lobby',
152
+ 5006: 'Lobby is full',
153
+ 5007: 'That player is already in a lobby.',
154
+ 5008: 'Invalid settings. Cannot create lobby. Try again.',
155
+ 5011: 'Group chat not found. It may have been deleted.',
156
+ 5012: 'This is a friends only lobby. Add this player to your friends or ask them for an invite.',
157
+ 5013: 'An error occurred while connecting to the lobby.',
158
+ 5101: 'Match not found',
159
+ 5300: 'You already follow another Commander. Unsubscribe from them first.',
160
+ 5301: 'Recruit not found',
161
+ 5302: 'Recruit already in squad',
162
+ 5303: 'Only squad recruits can do this.',
163
+ 5304: 'You cannot subscribe to yourself.',
164
+ 5305: 'You installed the game more than 24 hours ago, and can no longer choose a Commander.',
165
+ 6001: 'Game server not found. Check your internet connection and try again later.',
166
+ 6102: 'Ad reward is not available right now. Try again later.',
167
+ 6201: 'You can only rate the app once.',
168
+ 6301: 'Could not save the image. Check your device storage.',
169
+ 7001: 'Failed to save changes. Try again.',
170
+ 7002: 'Data changed while processing. Please try again.',
171
+ 8001: 'Could not confirm your purchase. Try again later.',
172
+ 8002: 'Item not found.',
173
+ 8003: 'Purchase failed because of a data error. Please try again later.',
174
+ 8021: 'Invalid code',
175
+ 8022: 'Subscribing to this creator is not available right now.',
176
+ 9901: 'Saved data missing. Please try again later.',
177
+ 9902: 'Cannot save this data type.',
178
+ 9903: 'Failed to save. Invalid data format.',
179
+ 9904: 'Cannot save more of this data type. Remove some and try again.',
180
+ 9905: 'Failed to save. Data size is too big. Adjust your settings and try again.',
181
+ 9998: 'Your device has been banned',
182
+ 9999: 'Your account is banned'}
@@ -0,0 +1,46 @@
1
+ """Exceptions raised by RPC calls and the response parser."""
2
+ from .error_codes import RPC_ERROR_DESCRIPTIONS
3
+
4
+
5
+ class AstandyRPCException(Exception):
6
+ """A server-reported error, preserving the original protobuf in args[0]."""
7
+
8
+ def __init__(self, error, *, request_id=None, service=None, method=None):
9
+ super().__init__(error)
10
+ self.error = error
11
+ self.code = int(error.code)
12
+ self.at = error.at
13
+ self.properties = dict(error.properties)
14
+ self.description = RPC_ERROR_DESCRIPTIONS.get(
15
+ self.code, "Unknown RPC error."
16
+ )
17
+ self.request_id = request_id
18
+ self.service = service
19
+ self.method = method
20
+
21
+ def __str__(self):
22
+ location = f" ({self.service}.{self.method})" if self.service else ""
23
+ return f"RPC {self.code}{location}: {self.description}"
24
+
25
+
26
+ class AstandyRPCTimeoutError(TimeoutError):
27
+ """The request did not complete within its total timeout."""
28
+
29
+ def __init__(self, target, request_id, timeout):
30
+ self.service = target.service
31
+ self.method = target.method
32
+ self.request_id = request_id
33
+ self.timeout = timeout
34
+ super().__init__(
35
+ f"RPC {self.service}.{self.method} timed out after {timeout} seconds"
36
+ )
37
+
38
+
39
+ class AstandyConnectionError(ConnectionError):
40
+ """An RPC could not be sent or its connection was lost."""
41
+
42
+ def __init__(self, message, *, request_id=None, service=None, method=None):
43
+ super().__init__(message)
44
+ self.request_id = request_id
45
+ self.service = service
46
+ self.method = method
@@ -1,3 +1,4 @@
1
+ from .metadata import API_METHODS, API_METHODS_BY_SERVICE
1
2
  from Astandy.types.rpc_target import RpcTarget
2
3
  from .events import (
3
4
  GENERATED_UPDATES,
@@ -49,6 +50,8 @@ class Generated(GeneratedServices, GeneratedEvents):
49
50
 
50
51
 
51
52
  __all__ = [
53
+ "API_METHODS",
54
+ "API_METHODS_BY_SERVICE",
52
55
  "GENERATED_UPDATES",
53
56
  "GENERATED_UPDATES_BY_NAME",
54
57
  "UPDATE_INDEX",