|
1 | | -# opengsq-python |
| 1 | +# OpenGSQ Python Library |
| 2 | + |
| 3 | +The OpenGSQ Python library provides a convenient way to query servers |
| 4 | +from applications written in the Python language. |
| 5 | + |
| 6 | +## Installation |
| 7 | + |
| 8 | +The recommended installation method is using [pip](http://pip-installer.org/): |
| 9 | + |
| 10 | +```sh |
| 11 | +pip install --upgrade opengsq |
| 12 | +``` |
| 13 | + |
| 14 | +Install from source with: |
| 15 | + |
| 16 | +```sh |
| 17 | +python setup.py install |
| 18 | +``` |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +Query Mordhau server |
| 23 | + |
| 24 | +```py |
| 25 | +from opengsq import Mordhau |
| 26 | + |
| 27 | +mordhau = Mordhau(address='123.123.123.123', query_port=27015) |
| 28 | +server = mordhau.query() |
| 29 | + |
| 30 | +print(server.to_json()) |
| 31 | +``` |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "name": "Duke of York - USA - Duel/Roleplay - Rp Feitoria♛", |
| 36 | + "map": "RP Feitoria", |
| 37 | + "players": 33, |
| 38 | + "max_players": 55, |
| 39 | + "bots": 0, |
| 40 | + "player_list": [], |
| 41 | + "latency": 0.7420244216918945 |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +Query server using `A2S` |
| 46 | + |
| 47 | +```py |
| 48 | +from opengsq.protocols import A2S |
| 49 | + |
| 50 | +a2s = A2S(address='123.123.123.123', query_port=27015) |
| 51 | +server = a2s.query() |
| 52 | + |
| 53 | +print(server.to_json()) |
| 54 | +``` |
| 55 | + |
| 56 | +```json |
| 57 | +{ |
| 58 | + "name": "[HK] Doctor server | Dodgeball Practice | 歡樂躲避球", |
| 59 | + "map": "tfdb_spacebox_a2", |
| 60 | + "players": 2, |
| 61 | + "max_players": 14, |
| 62 | + "bots": 1, |
| 63 | + "player_list": [ |
| 64 | + { |
| 65 | + "name": "[BOT] DUCK's BOT", |
| 66 | + "score": 5, |
| 67 | + "time": 58525.1640625 |
| 68 | + }, |
| 69 | + { |
| 70 | + "name": "✅BattlefieldDuck", |
| 71 | + "score": 0, |
| 72 | + "time": 253.934814453125 |
| 73 | + } |
| 74 | + ], |
| 75 | + "latency": 0.05097603797912598 |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +### Command-line interface |
| 80 | + |
| 81 | +This library additionally provides an `opengsq` command-line utility |
| 82 | +which makes it easy to query game servers from your terminal. Run |
| 83 | +`opengsq -h` for usage. |
| 84 | + |
| 85 | +```sh |
| 86 | +# query server using protocol-a2s |
| 87 | +opengsq protocol-a2s --address 123.123.123.123 --query_port 27015 |
| 88 | + |
| 89 | +# query csgo server |
| 90 | +opengsq csgo --address 123.123.123.123 --query_port 27015 |
| 91 | +``` |
| 92 | + |
| 93 | +## Requirements |
| 94 | + |
| 95 | +- Python 3.6+ |
| 96 | + |
| 97 | +## Credit |
| 98 | + |
| 99 | +This library is based from the [OpenAI Python Library](https://github.com/openai/openai-python). |
0 commit comments