diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..d838996 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,64 @@ +# Contributing to Python-valve ##### + +Thank you for wanting to contribute to Python-valve. Whether you're +reporting an issue, submitting a pull request or anything else, please +be aware of this project's [Code of Conduct](../CODE_OF_CONDUCT.md). +To summarise: *be polite, be respectful, be empathetic*. + +Additionally, it is expected that English is used in all issues, pull +requests, code, commit messages, etc.. If English is not your first +language, your best effort attempt will be appreciated and treated with +the necessary patience. + +Finally, whether it's a bug report, pull request or a feature requests. +Please check to make sure that it is not a duplicate of an existing +discussion. If it is a duplicate, add to the existing discussion instead. + + +## Bug Reports #### + +When reporting issues with Python-valve, please follow the template that +is provided to the best of your ability. Sometimes the scope of the issue +means that the template isn't entirely relevant. In these cases it's cool +to ignore the irrelevant parts. :+1: + + +## Pull Requests #### + +Always feel free to submit pull requests. When doing so, please include, +at minimum, a short description of what the pull request is for. If the +pull request addresses a specific issue, please refer back to that issue. +However, entirely speculative pull requests are also appreciated. + +For more complex pull requests, please be more elaborate in your +description. + +A few criteria must be met before a pull request will be accepted: + +- When adding **new code**, it *must* have **accompanying tests**. It + *must* also **pass all linting checks**. +- Ideally **all tests must pass**, on all platforms. It's okay to modify + tests. It *might* be okay to skip tests or mark them as failing. If in + doubt, mention it in the pull request description or comments. +- If intentionally making non-backwards compatible, **breaking changes**, + you **must include a justification**. Ideally, please also demonstrate + that you've thought through the implications. +- If modifying or adding to the public API, the corresponding + **documentation must be updated**. + +Everyone deserves credit for their work. Therefore, in addition +to the above requirements, you may wish to add yourself to the formal +[list of contributors](../CONTRIBUTORS.md), with a very brief description +of your contribution(s). This is entirely optional though. + + +## Ideas and Feature Requests #### + +It's completely fine to open an issue for ideas and feature requests. +When creating such issues, please be as descriptive as possible and +include a concrete use case. + + +## If in doubt ... #### + +[Open an issue and ask](https://github.com/serverstf/python-valve/issues/new)! diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..bcff9f3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,9 @@ +Please describe your issue in detail. Please also include any relevant +stack traces or other error messages. Ideally, if possible, provide a +small snippet that recreates the problem. Finally, fill in the applicable +fields below which describe the environment you witnessed the issue in. + +- **Python-valve Version(s)**: ... +- **Python Version(s)**: ... +- **Operating System(s)/Platform(s)**: ... +- **Game Server(s) and Version(s)**: ... diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..73514af --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,48 @@ +# Contributor Code of Conduct ##### + + +## Our Pledge #### + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project +and our community a harassment-free experience for everyone, regardless of +age, body size, disability, ethnicity, gender identity and expression, level +of experience, nationality, personal appearance, race, religion, sexual +identity and orientation and so on. + + +## Our Standards #### + +Examples of behaviour that contributes to creating a positive +environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + + +## Our Responsibilities #### + +Project maintainers are responsible for clarifying the standards of +acceptable behaviour and are expected to take appropriate and fair +corrective action in response to any instances of unacceptable behaviour. + + +## Enforcement #### + +Instances of abusive, harassing, or otherwise unacceptable behaviour may be +reported by contacting [the maintainers][maintainers]. All complaints will +be reviewed and investigated and will result in a response that is deemed +necessary and appropriate to the circumstances. All reported incidents +will be treated with strict confidentiality. + + +## Attribution #### + +This Code of Conduct is adapted from the +[Contributor Covenant, version 1.4][original]. + +[maintainers]: https://github.com/Holiverh +[original]: https://www.contributor-covenant.org/version/1/4/code-of-conduct.html diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 0000000..5debce6 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,7 @@ +# Python-valve Contributors #### + +- **[Oliver Ainsworth](https://github.com/Holiverh)** + - Original author and maintainer. + +**[Unabridged list of contributors]( + https://github.com/serverstf/python-valve/graphs/contributors)**. diff --git a/README.rst b/README.rst index 21fb91f..f30dcfe 100644 --- a/README.rst +++ b/README.rst @@ -19,21 +19,28 @@ interface to various Valve products and services, including: To get started, install Python-valve with pip: ``pip install python-valve``. +UNMAINTAINED +------------ + +This project is no longer actively maintained. The server query part +has been rewritten and is available as +`python-a2s `__ to not break +compatibility with projects using the old API. RCON Example ------------ -In this example we connect to a Source servers remote console and issue +In this example we connect to a Source server's remote console and issue a simple ``echo`` command to it. .. code:: python - from valve.source.rcon import RCON + import valve.rcon - SERVER_ADDRESS = ("...", 27015) - PASSWORD = "top_secret" + server_address = ("...", 27015) + password = "top_secret" - with RCON(SERVER_ADDRESS, PASSWORD) as rcon: + with valve.rcon.RCON(server_address, password) as rcon: print(rcon("echo Hello, world!")) @@ -56,15 +63,23 @@ sorted by their score. for address in msq.find(region=[u"eu", u"as"], gamedir=u"tf", map=u"ctf_2fort"): - with valve.source.a2s.ServerQuerier(address) as server: - info = server.info() - players = server.players() + try: + with valve.source.a2s.ServerQuerier(address) as server: + info = server.info() + players = server.players() + + except valve.source.NoResponseError: + print("Server {}:{} timed out!".format(*address)) + continue + print("{player_count}/{max_players} {server_name}".format(**info)) for player in sorted(players["players"], key=lambda p: p["score"], reverse=True): print("{score} {name}".format(**player)) + except valve.source.NoResponseError: - print "Master server request timed out!" + print("Master server request timed out!") + Versioning @@ -113,7 +128,7 @@ dependencies, build the docs and then open them in a browser. Python 2 -------- -Python-valve supports Python 2.7! However, it's important to bare in +Python-valve supports Python 2.7! However, it's important to bear in mind that Python 2.7 will not be maintained past 2020. Python-valve *may* drop support for Python 2.7 in a future major release before 2020 in order to make use of new, non-backwards compatible Python 3 features. diff --git a/setup.py b/setup.py index 9c96914..9f9a78f 100644 --- a/setup.py +++ b/setup.py @@ -29,13 +29,14 @@ def install_requires(): setuptools.setup( name="python-valve", - version="0.2.0", - description=("Python implemntation RCON, A2S, VDF, the Steam Web " - "API and various other Valve products and services."), + version="0.2.1", + description=("Python implementation for Source servers, RCON, A2S, " + "VDF, the Steam Web API and various other Valve products " + "and services."), long_description=readme(), author="Oliver Ainsworth", author_email="ottajay@googlemail.com", - url="https://github.com/Holiverh/python-valve", + url="https://github.com/serverstf/python-valve", packages=setuptools.find_packages(exclude=["tests"]), install_requires=install_requires(), extras_require={ @@ -44,8 +45,7 @@ def install_requires(): ], "test": [ "mock==1.0.1", - "pytest>=2.8.0", - "pytest-capturelog", + "pytest>=3.6.0", "pytest-cov", "pytest-timeout", ], diff --git a/tests/conftest.py b/tests/conftest.py index 06e0bff..ac2615e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -95,12 +95,10 @@ def pytest_generate_tests(metafunc): metafunc.parametrize("address", server_addresses) -def pytest_namespace(): - return { - "Mock": mock.Mock, - "MagicMock": mock.MagicMock, - "srcds_functional": srcds_functional, - } +def pytest_configure(): + pytest.Mock = mock.Mock + pytest.MagicMock = mock.MagicMock + pytest.srcds_functional = srcds_functional @pytest.yield_fixture diff --git a/tox.ini b/tox.ini index 48513d2..1fc8b8c 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,6 @@ envlist = py27, py34, pypy deps = docopt>=0.6.2 mock==1.0.1 - pytest>=2.8.0 - pytest-capturelog + pytest>=3.6.0 pytest-timeout commands = py.test tests/ diff --git a/valve/rcon.py b/valve/rcon.py index 1ffe97e..ccd808f 100644 --- a/valve/rcon.py +++ b/valve/rcon.py @@ -733,6 +733,9 @@ def _disconnect(self): self._convars = () self.prompt = self._INITIAL_PROMPT + def _exit(self): + self._disconnect() + def default(self, command): """Issue a command as an RCON command. @@ -776,6 +779,11 @@ def do_exit(self, _): print("Use !exit to exit this shell or " "!shutdown to shutdown the server.") + def do_EOF(self, _): + """Exit by the Ctrl-D shortcut.""" + self._exit() + return True + def do_help(self, command): """Print out ConVar-specific or generic help. @@ -818,6 +826,7 @@ def do_shell(self, command_string): def do_shell_exit(self, argv): """Exit the shell.""" + self._exit() return True def do_shell_connect(self, argv): diff --git a/valve/source/__init__.py b/valve/source/__init__.py index 1b38712..b59a83c 100644 --- a/valve/source/__init__.py +++ b/valve/source/__init__.py @@ -120,7 +120,7 @@ def get_response(self): if not ready[0]: raise NoResponseError("Timed out waiting for response") try: - data = ready[0][0].recv(1400) + data = ready[0][0].recv(65536) except socket.error as exc: six.raise_from(NoResponseError(exc)) return data diff --git a/valve/source/a2s.py b/valve/source/a2s.py index 3322fa5..c19654c 100644 --- a/valve/source/a2s.py +++ b/valve/source/a2s.py @@ -49,7 +49,7 @@ def get_response(self): raise NotImplementedError("Fragments are compressed") fragments[fragment["fragment_id"]] = fragment while len(fragments) < fragment["fragment_count"]: - data = BaseQuerier.get_response(self) + data = valve.source.BaseQuerier.get_response(self) fragment = messages.Fragment.decode( messages.Header.decode(data).payload) fragments[fragment["fragment_id"]] = fragment @@ -65,11 +65,11 @@ def ping(self): be negligble. """ - time_sent = monontic.monotonic() + time_sent = monotonic.monotonic() self.request(messages.InfoRequest()) messages.InfoResponse.decode(self.get_response()) time_received = monotonic.monotonic() - return (time_received - t_sent) * 1000.0 + return (time_received - time_sent) * 1000.0 def info(self): """Retreive information about the server state