Skip to content

Commit ca290f8

Browse files
committed
Update 2.1.0
1 parent 896371f commit ca290f8

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@ pip install -U pydustry.py
88
```python
99
import pydustry
1010

11-
status = pydustry.Server("easyplay.su").get_status()
11+
status = pydustry.Server("rcrms.ru").get_status()
1212

1313
print(status)
1414
```
1515

1616
- `Return`
1717
```python
18-
Status(name='[#3bffff][*] []EasyPlay Gaming + [#3dffcb]Rating-System', map='EasyPlay.HUB', players=56, wave=1, version=126, vertype='official', ping=35)
18+
Status(
19+
name='[gold]RCR [#B5B8B1]- [white]Ру[blue]сс[red]кий [#B5B8B1]Сервер',
20+
map='RCR HUB',
21+
players=7,
22+
wave=1,
23+
version=146,
24+
vertype='official',
25+
gamemode=0,
26+
limit=0,
27+
desc='...',
28+
modename='LOBBY',
29+
ping=37
30+
)
1931
```

pydustry/pydustry.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class Status:
1616
limit: int
1717
desc: int
1818
modename: int
19-
ping: float
19+
ping: int
2020

21+
# ! Main Class
2122
class Server:
2223
def __init__(
2324
self,
@@ -27,43 +28,55 @@ def __init__(
2728
) -> None:
2829
self.server: Tuple[str, int] = (server_host, server_port)
2930
self.input_server: Tuple[str, int] = (server_host, input_port)
30-
31-
def get_status(self, timeout: float=10.0) -> Status:
31+
32+
# ! Magic Methods
33+
def __str__(self) -> str:
34+
return f"{self.server[0]}:{self.server[1]}:{self.input_server[1]}"
35+
36+
def __repr__(self) -> str:
37+
return f"{self.__class__.__name__}({repr(self.__str__())})"
38+
39+
# ! Main Method
40+
def get_status(
41+
self,
42+
timeout: float=10.0,
43+
encoding: str='utf-8',
44+
errors: str='strict'
45+
) -> Status:
46+
info = {}
3247
s = socket(AF_INET, SOCK_DGRAM)
3348
s.connect(self.server)
3449
s.settimeout(timeout)
35-
info = {}
3650
s_time = time()
3751
s.send(b"\xfe\x01")
3852
data = s.recv(1024)
3953
e_time = time()
40-
# * Парсинг
41-
info["name"] = data[1:data[0]+1].decode("utf-8")
54+
info['name'] = data[1:data[0]+1].decode(encoding, errors)
4255
data = data[data[0]+1:]
43-
info["map"] = data[1:data[0]+1].decode("utf-8")
56+
info['map'] = data[1:data[0]+1].decode(encoding, errors)
4457
data = data[data[0]+1:]
45-
info["players"] = unpack(">i", data[:4])[0]
58+
info['players'] = unpack(">i", data[:4])[0]
4659
data = data[4:]
47-
info["wave"] = unpack(">i", data[:4])[0]
60+
info['wave'] = unpack(">i", data[:4])[0]
4861
data = data[4:]
49-
info["version"] = unpack(">i", data[:4])[0]
62+
info['version'] = unpack(">i", data[:4])[0]
5063
data = data[4:]
51-
info["vertype"] = data[1:data[0]+1].decode("utf-8")
64+
info['vertype'] = data[1:data[0]+1].decode(encoding, errors)
5265
data = data[data[0]+1:]
5366
info['gamemode'] = unpack('>b', data[:1])[0]
5467
data = data[1:]
5568
info['limit'] = unpack(">i", data[:4])[0]
5669
data = data[4:]
57-
info['desc'] = data[1:data[0]+1].decode("utf-8")
70+
info['desc'] = data[1:data[0]+1].decode(encoding, errors)
5871
data = data[data[0]+1:]
59-
info['modename'] = data[1:data[0]+1].decode("utf-8")
72+
info['modename'] = data[1:data[0]+1].decode(encoding, errors)
6073
data = data[data[0]+1:]
61-
info["ping"] = round((e_time - s_time) * 1000)
74+
info['ping'] = round((e_time - s_time) * 1000)
6275
return Status(**info)
6376

6477
def send_command(self, command: str) -> None:
6578
s = create_connection(self.input_server)
66-
s.sendall(command.encode(errors="ignore"))
79+
s.sendall(command.encode())
6780
s.close()
6881

6982
def ping(self, timeout: float=10.0) -> int:

pyproject.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
[tool.poetry]
22
name = "pydustry.py"
3-
version = "2.0.1"
3+
version = "2.1.0"
44
description = "Module for server information in the game Mindustry."
5-
authors = ["Romanin <[email protected]>"]
5+
repository = "https://github.com/RCR-OOP/pydustry.py"
6+
authors = [
7+
"Romanin <[email protected]>"
8+
]
69
license = "MIT"
710
readme = "README.md"
811
packages = [{include = "pydustry"}]
912
keywords = ["midnustry", "game", "server", "parser", "infomation"]
13+
classifiers = [
14+
"Development Status :: 5 - Production/Stable",
15+
"Operating System :: OS Independent"
16+
]
1017

1118
[tool.poetry.dependencies]
12-
python = "^3.9"
13-
19+
python = ">=3.6"
1420

1521
[build-system]
1622
requires = ["poetry-core"]

0 commit comments

Comments
 (0)