@@ -76,78 +76,16 @@ def __init__(self, sock: socket.socket) -> None:
7676 self ._sock = sock
7777 self ._protocols = {}
7878
79+ # Connection methods
80+
7981 def __enter__ (self ) -> Self :
8082 self ._sock .__enter__ ()
8183 return self
8284
8385 def __exit__ (self , exc_type , exc_val , tb ) -> None :
8486 return self ._sock .__exit__ (exc_type , exc_val , tb )
8587
86- def info (self , addr : Address | None = None ) -> ClientEventInfo :
87- """Send an A2S_INFO request and wait for a response.
88-
89- .. versionchanged:: 0.5.0
90-
91- addr can now be a positional argument.
92-
93- :param addr:
94- The address to send the request to.
95- Does not apply if socket is already connected to an address,
96- such as from :meth:`from_addr()`.
97-
98- .. versionadded:: 0.4.0
99-
100- :raises ChallengeError: The server sent too many challenges.
101- :raises PayloadError: The server sent a malformed packet.
102- :raises TimeoutError: The socket timed out.
103-
104- """
105- proto = self ._get_protocol (addr )
106- return self ._send (ClientEventInfo , addr , proto .info )
107-
108- def players (self , addr : Address | None = None ) -> ClientEventPlayers :
109- """Send an A2S_PLAYER request and wait for a response.
110-
111- .. versionchanged:: 0.5.0
112-
113- addr can now be a positional argument.
114-
115- :param addr:
116- The address to send the request to.
117- Does not apply if socket is already connected to an address,
118- such as from :meth:`from_addr()`.
119-
120- .. versionadded:: 0.4.0
121-
122- :raises ChallengeError: The server sent too many challenges.
123- :raises PayloadError: The server sent a malformed packet.
124- :raises TimeoutError: The socket timed out.
125-
126- """
127- proto = self ._get_protocol (addr )
128- return self ._send (ClientEventPlayers , addr , proto .players )
129-
130- def rules (self , addr : Address | None = None ) -> ClientEventRules :
131- """Send an A2S_RULES request and wait for a response.
132-
133- .. versionchanged:: 0.5.0
134-
135- addr can now be a positional argument.
136-
137- :param addr:
138- The address to send the request to.
139- Does not apply if socket is already connected to an address,
140- such as from :meth:`from_addr()`.
141-
142- .. versionadded:: 0.4.0
143-
144- :raises ChallengeError: The server sent too many challenges.
145- :raises PayloadError: The server sent a malformed packet.
146- :raises TimeoutError: The socket timed out.
147-
148- """
149- proto = self ._get_protocol (addr )
150- return self ._send (ClientEventRules , addr , proto .rules )
88+ # Constructor methods
15189
15290 @classmethod
15391 def from_addr (
@@ -231,6 +169,74 @@ def from_ipv6(cls, timeout: float | None = DEFAULT_TIMEOUT) -> Self:
231169 sock .settimeout (timeout )
232170 return cls (sock )
233171
172+ # Request methods
173+
174+ def info (self , addr : Address | None = None ) -> ClientEventInfo :
175+ """Send an A2S_INFO request and wait for a response.
176+
177+ .. versionchanged:: 0.5.0
178+
179+ addr can now be a positional argument.
180+
181+ :param addr:
182+ The address to send the request to.
183+ Does not apply if socket is already connected to an address,
184+ such as from :meth:`from_addr()`.
185+
186+ .. versionadded:: 0.4.0
187+
188+ :raises ChallengeError: The server sent too many challenges.
189+ :raises PayloadError: The server sent a malformed packet.
190+ :raises TimeoutError: The socket timed out.
191+
192+ """
193+ proto = self ._get_protocol (addr )
194+ return self ._send (ClientEventInfo , addr , proto .info )
195+
196+ def players (self , addr : Address | None = None ) -> ClientEventPlayers :
197+ """Send an A2S_PLAYER request and wait for a response.
198+
199+ .. versionchanged:: 0.5.0
200+
201+ addr can now be a positional argument.
202+
203+ :param addr:
204+ The address to send the request to.
205+ Does not apply if socket is already connected to an address,
206+ such as from :meth:`from_addr()`.
207+
208+ .. versionadded:: 0.4.0
209+
210+ :raises ChallengeError: The server sent too many challenges.
211+ :raises PayloadError: The server sent a malformed packet.
212+ :raises TimeoutError: The socket timed out.
213+
214+ """
215+ proto = self ._get_protocol (addr )
216+ return self ._send (ClientEventPlayers , addr , proto .players )
217+
218+ def rules (self , addr : Address | None = None ) -> ClientEventRules :
219+ """Send an A2S_RULES request and wait for a response.
220+
221+ .. versionchanged:: 0.5.0
222+
223+ addr can now be a positional argument.
224+
225+ :param addr:
226+ The address to send the request to.
227+ Does not apply if socket is already connected to an address,
228+ such as from :meth:`from_addr()`.
229+
230+ .. versionadded:: 0.4.0
231+
232+ :raises ChallengeError: The server sent too many challenges.
233+ :raises PayloadError: The server sent a malformed packet.
234+ :raises TimeoutError: The socket timed out.
235+
236+ """
237+ proto = self ._get_protocol (addr )
238+ return self ._send (ClientEventRules , addr , proto .rules )
239+
234240 def _get_protocol (self , addr : Address | None ) -> A2SClientProtocol :
235241 """Get the A2S protocol for the given address, creating a new one
236242 if it doesn't already exist.
0 commit comments