Full Code of xPaw/PHP-Source-Query for AI

master 2217e4040261 cached
44 files
120.8 KB
40.4k tokens
96 symbols
1 requests
Download .txt
Repository: xPaw/PHP-Source-Query
Branch: master
Commit: 2217e4040261
Files: 44
Total size: 120.8 KB

Directory structure:
gitextract_kr43fyxg/

├── .editorconfig
├── .gitattributes
├── .github/
│   ├── dependabot.yml
│   └── workflows/
│       └── ci.yml
├── .gitignore
├── CONTRIBUTING.md
├── Examples/
│   ├── Example.php
│   ├── RconExample.php
│   └── View.php
├── LICENSE
├── README.md
├── SourceQuery/
│   ├── BaseRcon.php
│   ├── BaseSocket.php
│   ├── Buffer.php
│   ├── Exception/
│   │   ├── AuthenticationException.php
│   │   ├── InvalidArgumentException.php
│   │   ├── InvalidPacketException.php
│   │   ├── SocketException.php
│   │   └── SourceQueryException.php
│   ├── GoldSourceRcon.php
│   ├── Socket.php
│   ├── SourceQuery.php
│   └── SourceRcon.php
├── Tests/
│   ├── Info/
│   │   ├── csgo.json
│   │   ├── csgo.raw
│   │   ├── gmod_cyrillic.json
│   │   ├── gmod_cyrillic.raw
│   │   ├── hltv.json
│   │   ├── hltv.raw
│   │   ├── svencoop_nonsteam.json
│   │   ├── svencoop_nonsteam.raw
│   │   ├── tf2.json
│   │   ├── tf2.raw
│   │   ├── theship.json
│   │   └── theship.raw
│   ├── Players/
│   │   ├── csgo.json
│   │   └── csgo.raw
│   ├── Rules/
│   │   ├── tf2_sourcemod.json
│   │   └── tf2_sourcemod.raw
│   ├── Tests.php
│   └── phpunit.xml
├── composer.json
├── phpstan.neon
└── psalm.xml

================================================
FILE CONTENTS
================================================

================================================
FILE: .editorconfig
================================================
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.yaml]
indent_style = space
indent_size = 2


================================================
FILE: .gitattributes
================================================
* text=auto


================================================
FILE: .github/dependabot.yml
================================================
version: 2
updates:
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "weekly"
    ignore:
      - dependency-name: "*"
        update-types: ["version-update:semver-minor", "version-update:semver-patch"]


================================================
FILE: .github/workflows/ci.yml
================================================
name: CI

permissions:
  contents: read

on: [push]

jobs:
  php:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        php: ['8.3', '8.4', '8.5']

    steps:
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php }}

    - name: Checkout
      uses: actions/checkout@v6

    - name: Install dependencies
      run: composer install --no-interaction --no-progress

    - name: Run tests
      run: composer run phpunit

    - name: Run phpstan
      run: composer run phpstan


================================================
FILE: .gitignore
================================================
vendor/
Tests/.phpunit.cache/


================================================
FILE: CONTRIBUTING.md
================================================
* **This library is intended for software developers**, if you do not know how write code in PHP, please do not create issues.
* Please do not create issues when you are unable to retrieve information from a server *(e.g. issues with UDP connectivity)*, unless you can prove that there is a bug within the library.


================================================
FILE: Examples/Example.php
================================================
<?php
declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';

use xPaw\SourceQuery\SourceQuery;

// For the sake of this example
header( 'Content-Type: text/plain' );
header( 'X-Content-Type-Options: nosniff' );

// Edit this ->
define( 'SQ_SERVER_ADDR', 'localhost' );
define( 'SQ_SERVER_PORT', 27015 );
define( 'SQ_TIMEOUT',     1 );
define( 'SQ_ENGINE',      SourceQuery::SOURCE );
// Edit this <-

$Query = new SourceQuery( );

try
{
	$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );

	print_r( $Query->GetInfo( ) );
	print_r( $Query->GetPlayers( ) );
	print_r( $Query->GetRules( ) );
}
catch( Exception $e )
{
	echo $e->getMessage( );
}
finally
{
	$Query->Disconnect( );
}


================================================
FILE: Examples/RconExample.php
================================================
<?php
declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';

use xPaw\SourceQuery\SourceQuery;

// For the sake of this example
header( 'Content-Type: text/plain' );
header( 'X-Content-Type-Options: nosniff' );

// Edit this ->
define( 'SQ_SERVER_ADDR', 'localhost' );
define( 'SQ_SERVER_PORT', 27015 );
define( 'SQ_TIMEOUT',     1 );
define( 'SQ_ENGINE',      SourceQuery::SOURCE );
// Edit this <-

$Query = new SourceQuery( );

try
{
	$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );

	$Query->SetRconPassword( 'my_awesome_password' );

	var_dump( $Query->Rcon( 'say hello' ) );
}
catch( Exception $e )
{
	echo $e->getMessage( );
}
finally
{
	$Query->Disconnect( );
}


================================================
FILE: Examples/View.php
================================================
<?php
	declare(strict_types=1);

	require __DIR__ . '/../vendor/autoload.php';

	use xPaw\SourceQuery\SourceQuery;

	// Edit this ->
	define( 'SQ_SERVER_ADDR', 'localhost' );
	define( 'SQ_SERVER_PORT', 27015 );
	define( 'SQ_TIMEOUT',     3 );
	define( 'SQ_ENGINE',      SourceQuery::SOURCE );
	// Edit this <-

	$Timer = microtime( true );

	$Query = new SourceQuery( );

	$Info    = null;
	$Rules   = [];
	$Players = [];
	$Exception = null;

	try
	{
		$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );
		//$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound

		$Info    = $Query->GetInfo( );
		$Players = $Query->GetPlayers( );
		$Rules   = $Query->GetRules( );
	}
	catch( Exception $e )
	{
		$Exception = $e;
	}
	finally
	{
		$Query->Disconnect( );
	}

	$Timer = number_format( microtime( true ) - $Timer, 4, '.', '' );
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Source Query PHP Library</title>

	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
	<style type="text/css">
		.table {
			table-layout: fixed;
			border-top-color: #428BCA;
		}

		.table td {
			overflow-x: auto;
		}

		.table thead th {
			background-color: #428BCA;
			border-color: #428BCA !important;
			color: #FFF;
		}

		.info-column {
			width: 120px;
		}

		.frags-column {
			width: 80px;
		}
	</style>
</head>

<body>
	<div class="jumbotron">
		<div class="container">
			<h1>Source Query PHP Library</h1>

			<p class="lead">This library was created to query game server which use the Source (Steamworks) query protocol.</p>

			<p>
				<a class="btn btn-large btn-primary" href="https://xpaw.me">Made by xPaw</a>
				<a class="btn btn-large btn-primary" href="https://github.com/xPaw/PHP-Source-Query">View on GitHub</a>
				<a class="btn btn-large btn-danger" href="https://github.com/xPaw/PHP-Source-Query/blob/master/LICENSE">LGPL v2.1</a>
			</p>
		</div>
	</div>

	<div class="container">
<?php if( $Exception !== null ): ?>
		<div class="panel panel-error">
			<pre class="panel-body"><?php echo htmlspecialchars( $Exception->__toString( ) ); ?></pre>
		</div>
<?php endif; ?>
		<div class="row">
			<div class="col-sm-6">
				<table class="table table-bordered table-striped">
					<thead>
						<tr>
							<th class="info-column">Server Info</th>
							<th><span class="label label-<?php echo $Timer > 1.0 ? 'danger' : 'success'; ?>"><?php echo $Timer; ?>s</span></th>
						</tr>
					</thead>
					<tbody>
<?php if( $Info !== null ): ?>
<?php foreach( $Info as $InfoKey => $InfoValue ): ?>
						<tr>
							<td><?php echo htmlspecialchars( $InfoKey ); ?></td>
							<td><?php
	if( is_array( $InfoValue ) )
	{
		echo "<pre>";
		print_r( $InfoValue );
		echo "</pre>";
	}
	else
	{
		if( $InfoValue === true )
		{
			echo 'true';
		}
		else if( $InfoValue === false )
		{
			echo 'false';
		}
		else
		{
			echo htmlspecialchars( (string)$InfoValue );
		}
	}
?></td>
						</tr>
<?php endforeach; ?>
<?php else: ?>
						<tr>
							<td colspan="2">No information received</td>
						</tr>
<?php endif; ?>
					</tbody>
				</table>
			</div>
			<div class="col-sm-6">
				<table class="table table-bordered table-striped">
					<thead>
						<tr>
							<th>Player <span class="label label-info"><?php echo count( $Players ); ?></span></th>
							<th class="frags-column">Frags</th>
							<th class="frags-column">Time</th>
						</tr>
					</thead>
					<tbody>
<?php if( count( $Players ) > 0 ): ?>
<?php foreach( $Players as $Player ): ?>
						<tr>
							<td><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></td>
							<td><?php echo $Player[ 'Frags' ]; ?></td>
							<td><?php echo $Player[ 'TimeF' ]; ?></td>
						</tr>
<?php endforeach; ?>
<?php else: ?>
						<tr>
							<td colspan="3">No players received</td>
						</tr>
<?php endif; ?>
					</tbody>
				</table>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-12">
				<table class="table table-bordered table-striped">
					<thead>
						<tr>
							<th colspan="2">Rules <span class="label label-info"><?php echo count( $Rules ); ?></span></th>
						</tr>
					</thead>
					<tbody>
<?php if( count( $Rules ) > 0 ): ?>
<?php foreach( $Rules as $Rule => $Value ): ?>
						<tr>
							<td><?php echo htmlspecialchars( $Rule ); ?></td>
							<td><?php echo htmlspecialchars( $Value ); ?></td>
						</tr>
<?php endforeach; ?>
<?php else: ?>
						<tr>
							<td colspan="2">No rules received</td>
						</tr>
<?php endif; ?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</body>
</html>


================================================
FILE: LICENSE
================================================
GNU LESSER GENERAL PUBLIC LICENSE
                       Version 2.1, February 1999

 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

(This is the first released version of the Lesser GPL.  It also counts
 as the successor of the GNU Library Public License, version 2, hence
 the version number 2.1.)

                            Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.

  This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it.  You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.

  When we speak of free software, we are referring to freedom of use,
not price.  Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.

  To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights.  These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.

  For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you.  You must make sure that they, too, receive or can get the source
code.  If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it.  And you must show them these terms so they know their rights.

  We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.

  To protect each distributor, we want to make it very clear that
there is no warranty for the free library.  Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.

  Finally, software patents pose a constant threat to the existence of
any free program.  We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder.  Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.

  Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License.  This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License.  We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.

  When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library.  The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom.  The Lesser General
Public License permits more lax criteria for linking other code with
the library.

  We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License.  It also provides other free software developers Less
of an advantage over competing non-free programs.  These disadvantages
are the reason we use the ordinary General Public License for many
libraries.  However, the Lesser license provides advantages in certain
special circumstances.

  For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard.  To achieve this, non-free programs must be
allowed to use the library.  A more frequent case is that a free
library does the same job as widely used non-free libraries.  In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.

  In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software.  For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.

  Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.

  The precise terms and conditions for copying, distribution and
modification follow.  Pay close attention to the difference between a
"work based on the library" and a "work that uses the library".  The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.

                  GNU LESSER GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".

  A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.

  The "Library", below, refers to any such software library or work
which has been distributed under these terms.  A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language.  (Hereinafter, translation is
included without limitation in the term "modification".)

  "Source code" for a work means the preferred form of the work for
making modifications to it.  For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.

  Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it).  Whether that is true depends on what the Library does
and what the program that uses the Library does.

  1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.

  You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.

  2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) The modified work must itself be a software library.

    b) You must cause the files modified to carry prominent notices
    stating that you changed the files and the date of any change.

    c) You must cause the whole of the work to be licensed at no
    charge to all third parties under the terms of this License.

    d) If a facility in the modified Library refers to a function or a
    table of data to be supplied by an application program that uses
    the facility, other than as an argument passed when the facility
    is invoked, then you must make a good faith effort to ensure that,
    in the event an application does not supply such function or
    table, the facility still operates, and performs whatever part of
    its purpose remains meaningful.

    (For example, a function in a library to compute square roots has
    a purpose that is entirely well-defined independent of the
    application.  Therefore, Subsection 2d requires that any
    application-supplied function or table used by this function must
    be optional: if the application does not supply it, the square
    root function must still compute square roots.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.

In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library.  To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License.  (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.)  Do not make any other change in
these notices.

  Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.

  This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.

  4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.

  If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.

  5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library".  Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.

  However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library".  The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.

  When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library.  The
threshold for this to be true is not precisely defined by law.

  If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work.  (Executables containing this object code plus portions of the
Library will still fall under Section 6.)

  Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.

  6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.

  You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License.  You must supply a copy of this License.  If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License.  Also, you must do one
of these things:

    a) Accompany the work with the complete corresponding
    machine-readable source code for the Library including whatever
    changes were used in the work (which must be distributed under
    Sections 1 and 2 above); and, if the work is an executable linked
    with the Library, with the complete machine-readable "work that
    uses the Library", as object code and/or source code, so that the
    user can modify the Library and then relink to produce a modified
    executable containing the modified Library.  (It is understood
    that the user who changes the contents of definitions files in the
    Library will not necessarily be able to recompile the application
    to use the modified definitions.)

    b) Use a suitable shared library mechanism for linking with the
    Library.  A suitable mechanism is one that (1) uses at run time a
    copy of the library already present on the user's computer system,
    rather than copying library functions into the executable, and (2)
    will operate properly with a modified version of the library, if
    the user installs one, as long as the modified version is
    interface-compatible with the version that the work was made with.

    c) Accompany the work with a written offer, valid for at
    least three years, to give the same user the materials
    specified in Subsection 6a, above, for a charge no more
    than the cost of performing this distribution.

    d) If distribution of the work is made by offering access to copy
    from a designated place, offer equivalent access to copy the above
    specified materials from the same place.

    e) Verify that the user has already received a copy of these
    materials or that you have already sent this user a copy.

  For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it.  However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.

  It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system.  Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.

  7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:

    a) Accompany the combined library with a copy of the same work
    based on the Library, uncombined with any other library
    facilities.  This must be distributed under the terms of the
    Sections above.

    b) Give prominent notice with the combined library of the fact
    that part of it is a work based on the Library, and explaining
    where to find the accompanying uncombined form of the same work.

  8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License.  Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License.  However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.

  9. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Library or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.

  10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.

  11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all.  For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.

If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded.  In such case, this License incorporates the limitation as if
written in the body of this License.

  13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number.  If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation.  If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.

  14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission.  For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this.  Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.

                            NO WARRANTY

  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

                     END OF TERMS AND CONDITIONS

           How to Apply These Terms to Your New Libraries

  If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change.  You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).

  To apply these terms, attach the following notices to the library.  It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

    {description}
    Copyright (C) {year} {fullname}

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
    USA

Also add information on how to contact you by electronic and paper mail.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  library `Frob' (a library for tweaking knobs) written by James Random
  Hacker.

  {signature of Ty Coon}, 1 April 1990
  Ty Coon, President of Vice

That's all there is to it!


================================================
FILE: README.md
================================================
# PHP Source Query

[![Packagist Downloads](https://img.shields.io/packagist/dt/xpaw/php-source-query-class.svg)](https://packagist.org/packages/xpaw/php-source-query-class)
[![Packagist Version](https://img.shields.io/packagist/v/xpaw/php-source-query-class.svg)](https://packagist.org/packages/xpaw/php-source-query-class)

This class was created to query game server which use the Source query protocol, this includes all source games, and all the games that implement Steamworks.

The class also allows you to query servers using RCON although this only works for half-life 1 and source engine games.

[Minecraft](http://www.minecraft.net) also uses Source RCON protocol, and this means you can use this class to send commands to your minecraft server while having engine set to Source engine.

**:warning: Do not send me emails if this does not work for you, I will not help you.**

## Requirements
* [Modern PHP version](https://php.net/supported-versions.php)
* 64-bit PHP or [gmp module](https://secure.php.net/manual/en/book.gmp.php)
* Your server must allow UDP connections

## Protocol Specifications
* https://developer.valvesoftware.com/wiki/Server_queries
* https://developer.valvesoftware.com/wiki/Source_RCON_Protocol

## Supported Games
AppID | Game | Query | RCON | Notes
----- | ---- | :---: | :--: | ----
~ | All HL1/HL2 games and mods | :white_check_mark: | :white_check_mark: | 
10 | [Counter-Strike 1.6](http://store.steampowered.com/app/10/) | :white_check_mark: | :white_check_mark: | 
440 | [Team Fortress 2](http://store.steampowered.com/app/440/) | :white_check_mark: | :white_check_mark: | 
550 | [Left 4 Dead 2](http://store.steampowered.com/app/550/) | :white_check_mark: | :white_check_mark: | 
730 | [Counter-Strike 2](http://store.steampowered.com/app/730/) | :white_check_mark: | :white_check_mark: | `host_name_store 1; host_info_show 2; host_players_show 2`
1002 | [Rag Doll Kung Fu](http://store.steampowered.com/app/1002/) | :white_check_mark: | :white_check_mark: | 
2400 | [The Ship](http://store.steampowered.com/app/2400/) | :white_check_mark: | :white_check_mark: | 
4000 | [Garry's Mod](http://store.steampowered.com/app/4000/) | :white_check_mark: | :white_check_mark: | 
17710 | [Nuclear Dawn](http://store.steampowered.com/app/17710/) | :white_check_mark: | :white_check_mark: | 
70000 | [Dino D-Day](http://store.steampowered.com/app/70000/) | :white_check_mark: | :white_check_mark: | 
107410 | [Arma 3](http://store.steampowered.com/app/107410/) | :white_check_mark: | :x: | Add +1 to the server port
115300 | [Call of Duty: Modern Warfare 3](http://store.steampowered.com/app/115300/) | :white_check_mark: | :white_check_mark: | 
162107 | [DeadPoly](https://store.steampowered.com/app/1621070/) | :white_check_mark: | :x: |
211820 | [Starbound](http://store.steampowered.com/app/211820/) | :white_check_mark: | :white_check_mark: | Call `SetUseOldGetChallengeMethod` method after connecting
244850 | [Space Engineers](http://store.steampowered.com/app/244850/) | :white_check_mark: | :x: | Add +1 to the server port
304930 | [Unturned](https://store.steampowered.com/app/304930/) | :white_check_mark: | :x: | Add +1 to the server port
251570 | [7 Days to Die](http://store.steampowered.com/app/251570) | :white_check_mark: | :x: |
252490 | [Rust](http://store.steampowered.com/app/252490/) | :white_check_mark: | :x: |
282440 | [Quake Live](http://store.steampowered.com/app/282440) | :white_check_mark: | :x: | Quake Live uses the ZMQ messaging queue protocol for rcon control.
346110 | [ARK: Survival Evolved](http://store.steampowered.com/app/346110/) | :white_check_mark: | :white_check_mark: | 
~ | [Minecraft](http://www.minecraft.net/) | :x: | :white_check_mark: | 
108600 | [Project: Zomboid](https://store.steampowered.com/app/108600/) | :white_check_mark: | :white_check_mark: 
1874880 | [Arma Reforger](https://store.steampowered.com/app/1874880/) | :white_check_mark: | :white_check_mark: 

Open a pull request if you know another game which supports Source Query and/or RCON protocols.

## How to tell if the game supports Source Query Protocol?

Add your server to your favourites in Steam server browser, and if Steam can display information about your server, then the protocol is supported.

## Functions
<table>
	<tr>
		<td>Connect( $Ip, $Port, $Timeout, $Engine )</td>
		<td>Opens connection to a server</td>
	</tr>
	<tr>
		<td>Disconnect( )</td>
		<td>Closes all open connections</td>
	</tr>
	<tr>
		<td>Ping( )</td>
		<td>Ping the server to see if it exists<br><b>Warning:</b> Source engine may not answer to this</td>
	</tr>
	<tr>
		<td>GetInfo( )</td>
		<td>Returns server info in an array</td>
	</tr>
	<tr>
		<td>GetPlayers( )</td>
		<td>Returns players on the server in an array</td>
	</tr>
	<tr>
		<td>GetRules( )</td>
		<td>Returns public rules <i>(cvars)</i> in an array</td>
	</tr>
	<tr>
		<td>SetRconPassword( $Password )</td>
		<td>Sets rcon password for later use with <i>Rcon()</i></td>
	</tr>
	<tr>
		<td>Rcon( $Command )</td>
		<td>Execute rcon command on the server</td>
	</tr>
</table>

Also refer to [examples folder](Examples/) to work things out.

## License
    PHP Source Query
    Copyright (C) 2012-2025 Pavel Djundik

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA


================================================
FILE: SourceQuery/BaseRcon.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery;

/**
 * Base RCON interface
 */
abstract class BaseRcon
{
	abstract public function Close( ) : void;
	abstract public function Open( ) : void;
	abstract public function Write( int $Header, string $String = '' ) : bool;
	abstract public function Read( ) : Buffer;
	abstract public function Command( string $Command ) : string;
	abstract public function Authorize( string $Password ) : void;
}


================================================
FILE: SourceQuery/BaseSocket.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery;

use xPaw\SourceQuery\Exception\InvalidPacketException;
use xPaw\SourceQuery\Exception\SocketException;

/**
 * Base socket interface
 */
abstract class BaseSocket
{
	/** @var ?resource */
	public $Socket;
	public int $Engine;

	public string $Address;
	public int $Port;
	public int $Timeout;

	public function __destruct( )
	{
		$this->Close( );
	}

	abstract public function Close( ) : void;
	abstract public function Open( string $Address, int $Port, int $Timeout, int $Engine ) : void;
	abstract public function Write( int $Header, string $String = '' ) : bool;
	abstract public function Read( ) : Buffer;

	protected function ReadInternal( Buffer $Buffer, callable $SherlockFunction ) : Buffer
	{
		if( $Buffer->Remaining( ) === 0 )
		{
			throw new InvalidPacketException( 'Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY );
		}

		$Header = $Buffer->ReadInt32( );

		if( $Header === -1 ) // Single packet
		{
			// We don't have to do anything
		}
		else if( $Header === -2 ) // Split packet
		{
			$Packets      = [];
			$IsCompressed = false;
			$ReadMore     = false;
			$PacketChecksum = null;

			do
			{
				$RequestID = $Buffer->ReadInt32( );
				$PacketCount = 0;
				$PacketNumber = 0;

				switch( $this->Engine )
				{
					case SourceQuery::GOLDSOURCE:
					{
						$PacketCountAndNumber = $Buffer->ReadByte( );
						$PacketCount          = $PacketCountAndNumber & 0xF;
						$PacketNumber         = $PacketCountAndNumber >> 4;

						break;
					}
					case SourceQuery::SOURCE:
					{
						$IsCompressed         = ( $RequestID & 0x80000000 ) !== 0;
						$PacketCount          = $Buffer->ReadByte( );
						$PacketNumber         = $Buffer->ReadByte( ) + 1;

						if( $IsCompressed )
						{
							$Buffer->ReadInt32( ); // Split size

							$PacketChecksum = $Buffer->ReadUInt32( );
						}
						else
						{
							$Buffer->ReadInt16( ); // Split size
						}

						break;
					}
					default:
					{
						throw new SocketException( 'Unknown engine.', SocketException::INVALID_ENGINE );
					}
				}

				$Packets[ $PacketNumber ] = $Buffer->Read( );

				$ReadMore = $PacketCount > sizeof( $Packets );
			}
			while( $ReadMore && $SherlockFunction( $Buffer ) );

			$Data = implode( $Packets );

			// TODO: Test this
			if( $IsCompressed )
			{
				// Let's make sure this function exists, it's not included in PHP by default
				if( !function_exists( 'bzdecompress' ) )
				{
					throw new \RuntimeException( 'Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.' );
				}

				$Data = bzdecompress( $Data );

				if( !is_string( $Data ) || crc32( $Data ) !== $PacketChecksum )
				{
					throw new InvalidPacketException( 'CRC32 checksum mismatch of uncompressed packet data.', InvalidPacketException::CHECKSUM_MISMATCH );
				}
			}

			$Buffer->Set( substr( $Data, 4 ) );
		}
		else
		{
			throw new InvalidPacketException( 'Socket read: Raw packet header mismatch. (0x' . dechex( $Header ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
		}

		return $Buffer;
	}
}


================================================
FILE: SourceQuery/Buffer.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery;

use xPaw\SourceQuery\Exception\InvalidPacketException;

/**
 * Class Buffer
 */
class Buffer
{
	/**
	 * Buffer
	 */
	private string $Buffer = '';

	/**
	 * Buffer length
	 */
	private int $Length = 0;

	/**
	 * Current position in buffer
	 */
	private int $Position = 0;

	/**
	 * Sets buffer
	 */
	public function Set( string $Buffer ) : void
	{
		$this->Buffer   = $Buffer;
		$this->Length   = strlen( $Buffer );
		$this->Position = 0;
	}

	/**
	 * Get remaining bytes
	 *
	 * @return int Remaining bytes in buffer
	 *
	 * @phpstan-impure
	 */
	public function Remaining( ) : int
	{
		return $this->Length - $this->Position;
	}

	/**
	 * Reads the specified number of bytes.
	 *
	 * @param int $Length Bytes to read
	 */
	public function Read( int $Length = -1 ) : string
	{
		if( $Length === 0 )
		{
			return '';
		}

		$Remaining = $this->Remaining( );

		if( $Length === -1 )
		{
			$Length = $Remaining;
		}
		else if( $Length > $Remaining )
		{
			return '';
		}

		$Data = substr( $this->Buffer, $this->Position, $Length );

		$this->Position += $Length;

		return $Data;
	}

	/**
	 * Reads the next byte.
	 */
	public function ReadByte( ) : int
	{
		if( $this->Remaining( ) < 1 )
		{
			return 0;
		}

		return ord( $this->Read( 1 ) );
	}

	/**
	 * Reads a 2-byte signed integer.
	 */
	public function ReadInt16( ) : int
	{
		if( $this->Remaining( ) < 2 )
		{
			throw new InvalidPacketException( 'Not enough data to unpack.', InvalidPacketException::BUFFER_EMPTY );
		}

		$Data = unpack( 'v', $this->Read( 2 ) );

		if( $Data === false )
		{
			throw new InvalidPacketException( 'Failed to unpack.', InvalidPacketException::UNPACK_FAILED );
		}

		return (int)$Data[ 1 ];
	}

	/**
	 * Reads a 4-byte signed integer.
	 */
	public function ReadInt32( ) : int
	{
		if( $this->Remaining( ) < 4 )
		{
			throw new InvalidPacketException( 'Not enough data to unpack.', InvalidPacketException::BUFFER_EMPTY );
		}

		$Data = unpack( 'l', $this->Read( 4 ) );

		if( $Data === false )
		{
			throw new InvalidPacketException( 'Failed to unpack.', InvalidPacketException::UNPACK_FAILED );
		}

		return (int)$Data[ 1 ];
	}

	/**
	 * Reads a 4-byte floating point value.
	 */
	public function ReadFloat32( ) : float
	{
		if( $this->Remaining( ) < 4 )
		{
			throw new InvalidPacketException( 'Not enough data to unpack.', InvalidPacketException::BUFFER_EMPTY );
		}

		$Data = unpack( 'f', $this->Read( 4 ) );

		if( $Data === false )
		{
			throw new InvalidPacketException( 'Failed to unpack.', InvalidPacketException::UNPACK_FAILED );
		}

		return (float)$Data[ 1 ];
	}

	/**
	 * Reads a 4-byte unsigned integer.
	 */
	public function ReadUInt32( ) : int
	{
		if( $this->Remaining( ) < 4 )
		{
			throw new InvalidPacketException( 'Not enough data to unpack.', InvalidPacketException::BUFFER_EMPTY );
		}

		$Data = unpack( 'V', $this->Read( 4 ) );

		if( $Data === false )
		{
			throw new InvalidPacketException( 'Failed to unpack.', InvalidPacketException::UNPACK_FAILED );
		}

		return (int)$Data[ 1 ];
	}

	/**
	 * Read a null-terminated string.
	 */
	public function ReadNullTermString( ) : string
	{
		$ZeroBytePosition = strpos( $this->Buffer, "\0", $this->Position );

		if( $ZeroBytePosition === false )
		{
			return '';
		}

		$String = $this->Read( $ZeroBytePosition - $this->Position );

		$this->Position++;

		return $String;
	}
}


================================================
FILE: SourceQuery/Exception/AuthenticationException.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery\Exception;

class AuthenticationException extends SourceQueryException
{
	const BAD_PASSWORD = 1;
	const BANNED = 2;
}


================================================
FILE: SourceQuery/Exception/InvalidArgumentException.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery\Exception;

class InvalidArgumentException extends SourceQueryException
{
	const TIMEOUT_NOT_INTEGER = 1;
}


================================================
FILE: SourceQuery/Exception/InvalidPacketException.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery\Exception;

class InvalidPacketException extends SourceQueryException
{
	const PACKET_HEADER_MISMATCH = 1;
	const BUFFER_EMPTY = 2;
	const BUFFER_NOT_EMPTY = 3;
	const CHECKSUM_MISMATCH = 4;
	const UNPACK_FAILED = 5;
}


================================================
FILE: SourceQuery/Exception/SocketException.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery\Exception;

class SocketException extends SourceQueryException
{
	const COULD_NOT_CREATE_SOCKET = 1;
	const NOT_CONNECTED = 2;
	const CONNECTION_FAILED = 3;
	const INVALID_ENGINE = 4;
}


================================================
FILE: SourceQuery/Exception/SourceQueryException.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery\Exception;

abstract class SourceQueryException extends \Exception
{
	// Base exception class
}


================================================
FILE: SourceQuery/GoldSourceRcon.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery;

use xPaw\SourceQuery\Exception\AuthenticationException;
use xPaw\SourceQuery\Exception\InvalidPacketException;
use xPaw\SourceQuery\Exception\SocketException;

/**
 * Class GoldSourceRcon
 */
class GoldSourceRcon extends BaseRcon
{
	/**
	 * Points to socket class
	 */
	private BaseSocket $Socket;

	private string $RconPassword = '';
	private string $RconChallenge = '';

	public function __construct( BaseSocket $Socket )
	{
		$this->Socket = $Socket;
	}

	public function Close( ) : void
	{
		$this->RconChallenge = '';
		$this->RconPassword  = '';
	}

	public function Open( ) : void
	{
		//
	}

	public function Write( int $Header, string $String = '' ) : bool
	{
		if( $this->Socket->Socket === null )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		$Command = pack( 'cccca*', 0xFF, 0xFF, 0xFF, 0xFF, $String );
		$Length  = strlen( $Command );

		return $Length === fwrite( $this->Socket->Socket, $Command, $Length );
	}

	/**
	 * @throws AuthenticationException
	 */
	public function Read( ) : Buffer
	{
		// GoldSource RCON has same structure as Query
		$Buffer = $this->Socket->Read( );

		$StringBuffer = '';
		$ReadMore = false;

		// There is no indentifier of the end, so we just need to continue reading
		do
		{
			$ReadMore = $Buffer->Remaining( ) > 0;

			if( $ReadMore )
			{
				if( $Buffer->ReadByte( ) !== SourceQuery::S2A_RCON )
				{
					throw new InvalidPacketException( 'Invalid rcon response.', InvalidPacketException::PACKET_HEADER_MISMATCH );
				}

				$Packet = $Buffer->Read( );
				$StringBuffer .= $Packet;
				//$StringBuffer .= SubStr( $Packet, 0, -2 );

				// Let's assume if this packet is not long enough, there are no more after this one
				$ReadMore = strlen( $Packet ) > 1000; // use 1300?

				if( $ReadMore )
				{
					$Buffer = $this->Socket->Read( );
				}
			}
		}
		while( $ReadMore );

		$Trimmed = trim( $StringBuffer );

		if( $Trimmed === 'Bad rcon_password.' )
		{
			throw new AuthenticationException( $Trimmed, AuthenticationException::BAD_PASSWORD );
		}
		else if( $Trimmed === 'You have been banned from this server.' )
		{
			throw new AuthenticationException( $Trimmed, AuthenticationException::BANNED );
		}

		$Buffer->Set( $Trimmed );

		return $Buffer;
	}

	public function Command( string $Command ) : string
	{
		if( !$this->RconChallenge )
		{
			throw new AuthenticationException( 'Tried to execute a RCON command before successful authorization.', AuthenticationException::BAD_PASSWORD );
		}

		$this->Write( 0, 'rcon ' . $this->RconChallenge . ' "' . $this->RconPassword . '" ' . $Command . "\0" );
		$Buffer = $this->Read( );

		return $Buffer->Read( );
	}

	public function Authorize( string $Password ) : void
	{
		$this->RconPassword = $Password;

		$this->Write( 0, 'challenge rcon' );
		$Buffer = $this->Socket->Read( );

		if( $Buffer->Read( 14 ) !== 'challenge rcon' )
		{
			throw new AuthenticationException( 'Failed to get RCON challenge.', AuthenticationException::BAD_PASSWORD );
		}

		$this->RconChallenge = trim( $Buffer->Read( ) );
	}
}


================================================
FILE: SourceQuery/Socket.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery;

use xPaw\SourceQuery\Exception\InvalidPacketException;
use xPaw\SourceQuery\Exception\SocketException;

/**
 * Class Socket
 */
class Socket extends BaseSocket
{
	public function Close( ) : void
	{
		if( is_resource( $this->Socket ) )
		{
			fclose( $this->Socket );

			$this->Socket = null;
		}
	}

	public function Open( string $Address, int $Port, int $Timeout, int $Engine ) : void
	{
		$this->Timeout = $Timeout;
		$this->Engine  = $Engine;
		$this->Port    = $Port;
		$this->Address = $Address;

		$Socket = @fsockopen( 'udp://' . $Address, $Port, $ErrNo, $ErrStr, $Timeout );

		if( $ErrNo || $Socket === false )
		{
			throw new SocketException( 'Could not create socket: ' . $ErrStr, SocketException::COULD_NOT_CREATE_SOCKET );
		}

		$this->Socket = $Socket;
		stream_set_timeout( $this->Socket, $Timeout );
		stream_set_blocking( $this->Socket, true );
	}

	public function Write( int $Header, string $String = '' ) : bool
	{
		if( $this->Socket === null )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		$Command = pack( 'ccccca*', 0xFF, 0xFF, 0xFF, 0xFF, $Header, $String );
		$Length  = strlen( $Command );

		return $Length === fwrite( $this->Socket, $Command, $Length );
	}

	private const MaxPacketLength = 1 << 16;

	/**
	 * Reads from socket and returns Buffer.
	 *
	 * @throws InvalidPacketException
	 */
	public function Read( ) : Buffer
	{
		if( $this->Socket === null )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		$Data = fread( $this->Socket, self::MaxPacketLength );
		$Buffer = new Buffer( );
		$Buffer->Set( $Data === false ? '' : $Data );

		$this->ReadInternal( $Buffer, [ $this, 'Sherlock' ] );

		return $Buffer;
	}

	public function Sherlock( Buffer $Buffer ) : bool
	{
		if( $this->Socket === null )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		$Data = fread( $this->Socket, self::MaxPacketLength );

		if( $Data === false || strlen( $Data ) < 4 )
		{
			return false;
		}

		$Buffer->Set( $Data );

		return $Buffer->ReadInt32( ) === -2;
	}
}


================================================
FILE: SourceQuery/SourceQuery.php
================================================
<?php
declare(strict_types=1);

/**
 * This class provides the public interface to the PHP-Source-Query library.
 *
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 */

namespace xPaw\SourceQuery;

use xPaw\SourceQuery\Exception\AuthenticationException;
use xPaw\SourceQuery\Exception\InvalidArgumentException;
use xPaw\SourceQuery\Exception\InvalidPacketException;
use xPaw\SourceQuery\Exception\SocketException;

/**
 * Class SourceQuery
 */
class SourceQuery
{
	/**
	 * Engines
	 */
	const GOLDSOURCE = 0;
	const SOURCE     = 1;

	/**
	 * Packets sent
	 */
	const A2A_PING      = 0x69;
	const A2S_INFO      = 0x54;
	const A2S_PLAYER    = 0x55;
	const A2S_RULES     = 0x56;
	const A2S_SERVERQUERY_GETCHALLENGE = 0x57;

	/**
	 * Packets received
	 */
	const A2A_ACK       = 0x6A;
	const S2C_CHALLENGE = 0x41;
	const S2A_INFO_SRC  = 0x49;
	const S2A_INFO_OLD  = 0x6D; // Old GoldSource, HLTV uses it (actually called S2A_INFO_DETAILED)
	const S2A_PLAYER    = 0x44;
	const S2A_RULES     = 0x45;
	const S2A_RCON      = 0x6C;

	/**
	 * Source rcon sent
	 */
	const SERVERDATA_REQUESTVALUE   = 0;
	const SERVERDATA_EXECCOMMAND    = 2;
	const SERVERDATA_AUTH           = 3;

	/**
	 * Source rcon received
	 */
	const SERVERDATA_RESPONSE_VALUE = 0;
	const SERVERDATA_AUTH_RESPONSE  = 2;

	/**
	 * Points to rcon class
	 */
	private ?BaseRcon $Rcon = null;

	/**
	 * Points to socket class
	 */
	private BaseSocket $Socket;

	/**
	 * True if connection is open, false if not
	 */
	private bool $Connected = false;

	/**
	 * Contains challenge
	 */
	private string $Challenge = '';

	/**
	 * Use old method for getting challenge number
	 */
	private bool $UseOldGetChallengeMethod = false;

	public function __construct( ?BaseSocket $Socket = null )
	{
		$this->Socket = $Socket ?? new Socket( );
	}

	public function __destruct( )
	{
		$this->Disconnect( );
	}

	/**
	 * Opens connection to server
	 *
	 * @param string $Address Server ip
	 * @param int $Port Server port
	 * @param int $Timeout Timeout period
	 * @param int $Engine Engine the server runs on (goldsource, source)
	 *
	 * @throws InvalidArgumentException
	 * @throws SocketException
	 */
	public function Connect( string $Address, int $Port, int $Timeout = 3, int $Engine = self::SOURCE ) : void
	{
		$this->Disconnect( );

		if( $Timeout < 0 )
		{
			throw new InvalidArgumentException( 'Timeout must be a positive integer.', InvalidArgumentException::TIMEOUT_NOT_INTEGER );
		}

		$this->Socket->Open( $Address, $Port, $Timeout, $Engine );

		$this->Connected = true;
	}

	/**
	 * Forces GetChallenge to use old method for challenge retrieval because some games use outdated protocol (e.g Starbound)
	 *
	 * @param bool $Value Set to true to force old method
	 *
	 * @return bool Previous value
	 */
	public function SetUseOldGetChallengeMethod( bool $Value ) : bool
	{
		$Previous = $this->UseOldGetChallengeMethod;

		$this->UseOldGetChallengeMethod = $Value === true;

		return $Previous;
	}

	/**
	 * Closes all open connections
	 */
	public function Disconnect( ) : void
	{
		$this->Connected = false;
		$this->Challenge = '';

		$this->Socket->Close( );

		if( $this->Rcon !== null )
		{
			$this->Rcon->Close( );

			$this->Rcon = null;
		}
	}

	/**
	 * Sends ping packet to the server
	 * NOTE: This may not work on some games (TF2 for example)
	 *
	 * @throws InvalidPacketException
	 * @throws SocketException
	 *
	 * @return bool True on success, false on failure
	 */
	public function Ping( ) : bool
	{
		if( !$this->Connected )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		$this->Socket->Write( self::A2A_PING );
		$Buffer = $this->Socket->Read( );

		return $Buffer->ReadByte( ) === self::A2A_ACK;
	}

	/**
	 * Get server information
	 *
	 * @throws InvalidPacketException
	 * @throws SocketException
	 *
	 * @return array{
	 *     Protocol: int,
	 *     HostName: string,
	 *     Map: string,
	 *     ModDir: string,
	 *     ModDesc: string,
	 *     AppID?: int,
	 *     Players: int,
	 *     MaxPlayers: int,
	 *     Bots: int,
	 *     Dedicated: string,
	 *     Os: string,
	 *     Password: bool,
	 *     Secure: bool,
	 *     Version?: string,
	 *     ExtraDataFlags?: int,
	 *     GamePort?: int,
	 *     SteamID?: string|int,
	 *     SpecPort?: int,
	 *     SpecName?: string,
	 *     GameTags?: string,
	 *     GameID?: int,
	 *     Address?: string,
	 *     IsMod?: bool,
	 *     Mod?: array{
	 *         Url: string,
	 *         Download: string,
	 *         Version: int,
	 *         Size: int,
	 *         ServerSide: bool,
	 *         CustomDLL: bool
	 *     },
	 *     GameMode?: int,
	 *     WitnessCount?: int,
	 *     WitnessTime?: int
	 * } Returns an array with server information on success
	 */
	public function GetInfo( ) : array
	{
		if( !$this->Connected )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		if( $this->Challenge )
		{
			$this->Socket->Write( self::A2S_INFO, "Source Engine Query\0" . $this->Challenge );
		}
		else
		{
			$this->Socket->Write( self::A2S_INFO, "Source Engine Query\0" );
		}

		$Buffer = $this->Socket->Read( );
		$Type = $Buffer->ReadByte( );
		$Server = [];

		if( $Type === self::S2C_CHALLENGE )
		{
			$this->Challenge = $Buffer->Read( 4 );

			$this->Socket->Write( self::A2S_INFO, "Source Engine Query\0" . $this->Challenge );
			$Buffer = $this->Socket->Read( );
			$Type = $Buffer->ReadByte( );
		}

		// Old GoldSource protocol, HLTV still uses it
		if( $Type === self::S2A_INFO_OLD && $this->Socket->Engine === self::GOLDSOURCE )
		{
			/**
			 * If we try to read data again, and we get the result with type S2A_INFO (0x49)
			 * That means this server is running dproto,
			 * Because it sends answer for both protocols
			 */

			$Server[ 'Address' ]    = $Buffer->ReadNullTermString( );
			$Server[ 'HostName' ]   = $Buffer->ReadNullTermString( );
			$Server[ 'Map' ]        = $Buffer->ReadNullTermString( );
			$Server[ 'ModDir' ]     = $Buffer->ReadNullTermString( );
			$Server[ 'ModDesc' ]    = $Buffer->ReadNullTermString( );
			$Server[ 'Players' ]    = $Buffer->ReadByte( );
			$Server[ 'MaxPlayers' ] = $Buffer->ReadByte( );
			$Server[ 'Protocol' ]   = $Buffer->ReadByte( );
			$Server[ 'Dedicated' ]  = chr( $Buffer->ReadByte( ) );
			$Server[ 'Os' ]         = chr( $Buffer->ReadByte( ) );
			$Server[ 'Password' ]   = $Buffer->ReadByte( ) === 1;
			$Server[ 'IsMod' ]      = $Buffer->ReadByte( ) === 1;

			if( $Server[ 'IsMod' ] )
			{
				$Mod = [];
				$Mod[ 'Url' ]        = $Buffer->ReadNullTermString( );
				$Mod[ 'Download' ]   = $Buffer->ReadNullTermString( );
				$Buffer->Read( 1 ); // NULL byte
				$Mod[ 'Version' ]    = $Buffer->ReadInt32( );
				$Mod[ 'Size' ]       = $Buffer->ReadInt32( );
				$Mod[ 'ServerSide' ] = $Buffer->ReadByte( ) === 1;
				$Mod[ 'CustomDLL' ]  = $Buffer->ReadByte( ) === 1;
				$Server[ 'Mod' ] = $Mod;
			}

			$Server[ 'Secure' ]   = $Buffer->ReadByte( ) === 1;
			$Server[ 'Bots' ]     = $Buffer->ReadByte( );

			return $Server;
		}

		if( $Type !== self::S2A_INFO_SRC )
		{
			throw new InvalidPacketException( 'GetInfo: Packet header mismatch. (0x' . dechex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
		}

		$Server[ 'Protocol' ]   = $Buffer->ReadByte( );
		$Server[ 'HostName' ]   = $Buffer->ReadNullTermString( );
		$Server[ 'Map' ]        = $Buffer->ReadNullTermString( );
		$Server[ 'ModDir' ]     = $Buffer->ReadNullTermString( );
		$Server[ 'ModDesc' ]    = $Buffer->ReadNullTermString( );
		$Server[ 'AppID' ]      = $Buffer->ReadInt16( );
		$Server[ 'Players' ]    = $Buffer->ReadByte( );
		$Server[ 'MaxPlayers' ] = $Buffer->ReadByte( );
		$Server[ 'Bots' ]       = $Buffer->ReadByte( );
		$Server[ 'Dedicated' ]  = chr( $Buffer->ReadByte( ) );
		$Server[ 'Os' ]         = chr( $Buffer->ReadByte( ) );
		$Server[ 'Password' ]   = $Buffer->ReadByte( ) === 1;
		$Server[ 'Secure' ]     = $Buffer->ReadByte( ) === 1;

		// The Ship (they violate query protocol spec by modifying the response)
		if( $Server[ 'AppID' ] === 2400 )
		{
			$Server[ 'GameMode' ]     = $Buffer->ReadByte( );
			$Server[ 'WitnessCount' ] = $Buffer->ReadByte( );
			$Server[ 'WitnessTime' ]  = $Buffer->ReadByte( );
		}

		$Server[ 'Version' ] = $Buffer->ReadNullTermString( );

		// Extra Data Flags
		if( $Buffer->Remaining( ) > 0 )
		{
			$Server[ 'ExtraDataFlags' ] = $Flags = $Buffer->ReadByte( );

			// S2A_EXTRA_DATA_HAS_GAME_PORT - Next 2 bytes include the game port.
			if( $Flags & 0x80 )
			{
				$Server[ 'GamePort' ] = $Buffer->ReadInt16( );
			}

			// S2A_EXTRA_DATA_HAS_STEAMID - Next 8 bytes are the steamID
			// Want to play around with this?
			// You can use https://github.com/xPaw/SteamID.php
			if( $Flags & 0x10 )
			{
				$SteamIDLower    = $Buffer->ReadUInt32( );
				$SteamIDInstance = $Buffer->ReadUInt32( ); // This gets shifted by 32 bits, which should be steamid instance
				$SteamID = 0;

				if( PHP_INT_SIZE === 4 )
				{
					if( extension_loaded( 'gmp' ) )
					{
						$SteamIDLower    = gmp_abs( $SteamIDLower );
						$SteamIDInstance = gmp_abs( $SteamIDInstance );
						$SteamID         = gmp_strval( gmp_or( $SteamIDLower, gmp_mul( $SteamIDInstance, gmp_pow( 2, 32 ) ) ) );
					}
					else
					{
						throw new \RuntimeException( 'Either 64-bit PHP installation or "gmp" module is required to correctly parse server\'s steamid.' );
					}
				}
				else
				{
					$SteamID = $SteamIDLower | ( $SteamIDInstance << 32 );
				}

				$Server[ 'SteamID' ] = $SteamID;

				unset( $SteamIDLower, $SteamIDInstance, $SteamID );
			}

			// S2A_EXTRA_DATA_HAS_SPECTATOR_DATA - Next 2 bytes include the spectator port, then the spectator server name.
			if( $Flags & 0x40 )
			{
				$Server[ 'SpecPort' ] = $Buffer->ReadInt16( );
				$Server[ 'SpecName' ] = $Buffer->ReadNullTermString( );
			}

			// S2A_EXTRA_DATA_HAS_GAMETAG_DATA - Next bytes are the game tag string
			if( $Flags & 0x20 )
			{
				$Server[ 'GameTags' ] = $Buffer->ReadNullTermString( );
			}

			// S2A_EXTRA_DATA_GAMEID - Next 8 bytes are the gameID of the server
			if( $Flags & 0x01 )
			{
				$Server[ 'GameID' ] = $Buffer->ReadUInt32( ) | ( $Buffer->ReadUInt32( ) << 32 );
			}

			if( $Buffer->Remaining( ) > 0 )
			{
				throw new InvalidPacketException( 'GetInfo: unread data? ' . $Buffer->Remaining( ) . ' bytes remaining in the buffer. Please report it to the library developer.',
					InvalidPacketException::BUFFER_NOT_EMPTY );
			}
		}

		return $Server;
	}

	/**
	 * Get players on the server
	 *
	 * @throws InvalidPacketException
	 * @throws SocketException
	 *
	 * @return array<int, array{Id: int, Name: string, Frags: int, Time: int, TimeF: string}> Returns an array with players on success
	 */
	public function GetPlayers( ) : array
	{
		if( !$this->Connected )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		$this->GetChallenge( self::A2S_PLAYER, self::S2A_PLAYER );

		$this->Socket->Write( self::A2S_PLAYER, $this->Challenge );
		$Buffer = $this->Socket->Read( );

		$Type = $Buffer->ReadByte( );

		if( $Type !== self::S2A_PLAYER )
		{
			throw new InvalidPacketException( 'GetPlayers: Packet header mismatch. (0x' . dechex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
		}

		$Players = [];
		$Count   = $Buffer->ReadByte( );

		while( $Count-- > 0 && $Buffer->Remaining( ) > 0 )
		{
			$Player = [];
			$Player[ 'Id' ]    = $Buffer->ReadByte( ); // PlayerID, is it just always 0?
			$Player[ 'Name' ]  = $Buffer->ReadNullTermString( );
			$Player[ 'Frags' ] = $Buffer->ReadInt32( );
			$Player[ 'Time' ]  = (int)$Buffer->ReadFloat32( );
			$Player[ 'TimeF' ] = gmdate( ( $Player[ 'Time' ] > 3600 ? 'H:i:s' : 'i:s' ), $Player[ 'Time' ] );

			$Players[ ] = $Player;
		}

		return $Players;
	}

	/**
	 * Get rules (cvars) from the server
	 *
	 * @throws InvalidPacketException
	 * @throws SocketException
	 *
	 * @return array<string, string> Returns an array with rules on success
	 */
	public function GetRules( ) : array
	{
		if( !$this->Connected )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		$this->GetChallenge( self::A2S_RULES, self::S2A_RULES );

		$this->Socket->Write( self::A2S_RULES, $this->Challenge );
		$Buffer = $this->Socket->Read( );

		$Type = $Buffer->ReadByte( );

		if( $Type !== self::S2A_RULES )
		{
			throw new InvalidPacketException( 'GetRules: Packet header mismatch. (0x' . dechex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
		}

		$Rules = [];
		$Count = $Buffer->ReadInt16( );

		while( $Count-- > 0 && $Buffer->Remaining( ) > 0 )
		{
			$Rule  = $Buffer->ReadNullTermString( );
			$Value = $Buffer->ReadNullTermString( );

			if( strlen( $Rule ) > 0 )
			{
				$Rules[ $Rule ] = $Value;
			}
		}

		return $Rules;
	}

	/**
	 * Get challenge (used for players/rules packets)
	 *
	 * @throws InvalidPacketException
	 */
	private function GetChallenge( int $Header, int $ExpectedResult ) : void
	{
		if( $this->Challenge )
		{
			return;
		}

		if( $this->UseOldGetChallengeMethod )
		{
			$Header = self::A2S_SERVERQUERY_GETCHALLENGE;
		}

		$this->Socket->Write( $Header, "\xFF\xFF\xFF\xFF" );
		$Buffer = $this->Socket->Read( );

		$Type = $Buffer->ReadByte( );

		switch( $Type )
		{
			case self::S2C_CHALLENGE:
			{
				$this->Challenge = $Buffer->Read( 4 );

				return;
			}
			case $ExpectedResult:
			{
				// Goldsource (HLTV)

				return;
			}
			case 0:
			{
				throw new InvalidPacketException( 'GetChallenge: Failed to get challenge.' );
			}
			default:
			{
				throw new InvalidPacketException( 'GetChallenge: Packet header mismatch. (0x' . dechex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
			}
		}
	}

	/**
	 * Sets rcon password, for future use in Rcon()
	 *
	 * @param string $Password Rcon Password
	 *
	 * @throws AuthenticationException
	 * @throws InvalidPacketException
	 * @throws SocketException
	 */
	public function SetRconPassword( string $Password ) : void
	{
		if( !$this->Connected )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		switch( $this->Socket->Engine )
		{
			case SourceQuery::GOLDSOURCE:
			{
				$this->Rcon = new GoldSourceRcon( $this->Socket );

				break;
			}
			case SourceQuery::SOURCE:
			{
				$this->Rcon = new SourceRcon( $this->Socket );

				break;
			}
			default:
			{
				throw new SocketException( 'Unknown engine.', SocketException::INVALID_ENGINE );
			}
		}

		if( $this->Rcon === null ) // This should not happen, but makes phpstan happy.
		{
			throw new SocketException( 'Something went wrong.', SocketException::INVALID_ENGINE );
		}

		$this->Rcon->Open( );
		$this->Rcon->Authorize( $Password );
	}

	/**
	 * Sends a command to the server for execution.
	 *
	 * @param string $Command Command to execute
	 *
	 * @throws AuthenticationException
	 * @throws InvalidPacketException
	 * @throws SocketException
	 *
	 * @return string Answer from server in string
	 */
	public function Rcon( string $Command ) : string
	{
		if( !$this->Connected )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		if( $this->Rcon === null )
		{
			throw new SocketException( 'You must set a RCON password before trying to execute a RCON command.', SocketException::NOT_CONNECTED );
		}

		return $this->Rcon->Command( $Command );
	}
}


================================================
FILE: SourceQuery/SourceRcon.php
================================================
<?php
declare(strict_types=1);

/**
 * @author Pavel Djundik
 *
 * @link https://xpaw.me
 * @link https://github.com/xPaw/PHP-Source-Query
 *
 * @license GNU Lesser General Public License, version 2.1
 *
 * @internal
 */

namespace xPaw\SourceQuery;

use xPaw\SourceQuery\Exception\AuthenticationException;
use xPaw\SourceQuery\Exception\InvalidPacketException;
use xPaw\SourceQuery\Exception\SocketException;

/**
 * Class SourceRcon
 */
class SourceRcon extends BaseRcon
{
	/**
	 * Points to socket class
	 */
	private BaseSocket $Socket;

	/** @var ?resource */
	private $RconSocket;
	private int $RconRequestId = 0;

	public function __construct( BaseSocket $Socket )
	{
		$this->Socket = $Socket;
	}

	public function Close( ) : void
	{
		if( $this->RconSocket )
		{
			fclose( $this->RconSocket );

			$this->RconSocket = null;
		}

		$this->RconRequestId = 0;
	}

	public function Open( ) : void
	{
		if( !$this->RconSocket )
		{
			$RconSocket = @fsockopen( $this->Socket->Address, $this->Socket->Port, $ErrNo, $ErrStr, $this->Socket->Timeout );

			if( $ErrNo || !$RconSocket )
			{
				throw new SocketException( 'Can\'t connect to RCON server: ' . $ErrStr, SocketException::CONNECTION_FAILED );
			}

			$this->RconSocket = $RconSocket;
			stream_set_timeout( $this->RconSocket, $this->Socket->Timeout );
			stream_set_blocking( $this->RconSocket, true );
		}
	}

	public function Write( int $Header, string $String = '' ) : bool
	{
		if( $this->RconSocket === null )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		// Pack the packet together
		$Command = pack( 'VV', ++$this->RconRequestId, $Header ) . $String . "\x00\x00";

		// Prepend packet length
		$Command = pack( 'V', strlen( $Command ) ) . $Command;
		$Length  = strlen( $Command );

		return $Length === fwrite( $this->RconSocket, $Command, $Length );
	}

	public function Read( ) : Buffer
	{
		if( $this->RconSocket === null )
		{
			throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
		}

		$Data = fread( $this->RconSocket, 4 );
		$Buffer = new Buffer( );
		$Buffer->Set( $Data === false ? '' : $Data );

		if( $Buffer->Remaining( ) < 4 )
		{
			throw new InvalidPacketException( 'Rcon read: Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY );
		}

		$PacketSize = $Buffer->ReadInt32( );

		if( $PacketSize <= 0 )
		{
			throw new InvalidPacketException( 'Rcon read: Packet size was empty', InvalidPacketException::BUFFER_EMPTY );
		}

		$Data = fread( $this->RconSocket, $PacketSize );
		$Buffer->Set( $Data === false ? '' : $Data );

		$Data = $Buffer->Read( );

		$Remaining = $PacketSize - strlen( $Data );

		while( $Remaining > 0 )
		{
			$Data2 = fread( $this->RconSocket, $Remaining );

			if( $Data2 === false || strlen( $Data2 ) === 0 )
			{
				throw new InvalidPacketException( 'Read ' . strlen( $Data ) . ' bytes from socket, ' . $Remaining . ' remaining', InvalidPacketException::BUFFER_EMPTY );
			}

			$Data .= $Data2;
			$Remaining -= strlen( $Data2 );
		}

		$Buffer->Set( $Data );

		return $Buffer;
	}

	public function Command( string $Command ) : string
	{
		$this->Write( SourceQuery::SERVERDATA_EXECCOMMAND, $Command );
		$Buffer = $this->Read( );

		$Buffer->ReadInt32( ); // RequestID

		$Type = $Buffer->ReadInt32( );

		if( $Type === SourceQuery::SERVERDATA_AUTH_RESPONSE )
		{
			throw new AuthenticationException( 'Bad rcon_password.', AuthenticationException::BAD_PASSWORD );
		}
		else if( $Type !== SourceQuery::SERVERDATA_RESPONSE_VALUE )
		{
			throw new InvalidPacketException( 'Invalid rcon response.', InvalidPacketException::PACKET_HEADER_MISMATCH );
		}

		$Data = $Buffer->Read( );

		// We do this stupid hack to handle split packets
		// See https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Multiple-packet_Responses
		if( strlen( $Data ) >= 4000 )
		{
			$this->Write( SourceQuery::SERVERDATA_REQUESTVALUE );

			do
			{
				$Buffer = $this->Read( );

				$Buffer->ReadInt32( ); // RequestID

				if( $Buffer->ReadInt32( ) !== SourceQuery::SERVERDATA_RESPONSE_VALUE )
				{
					break;
				}

				$Data2 = $Buffer->Read( );

				if( $Data2 === "\x00\x01\x00\x00\x00\x00" )
				{
					break;
				}

				$Data .= $Data2;
			}
			while( true );
		}

		return rtrim( $Data, "\0" );
	}

	public function Authorize( string $Password ) : void
	{
		$this->Write( SourceQuery::SERVERDATA_AUTH, $Password );
		$Buffer = $this->Read( );

		$RequestID = $Buffer->ReadInt32( );
		$Type      = $Buffer->ReadInt32( );

		// If we receive SERVERDATA_RESPONSE_VALUE, then we need to read again
		// More info: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Additional_Comments

		if( $Type === SourceQuery::SERVERDATA_RESPONSE_VALUE )
		{
			$Buffer = $this->Read( );

			$RequestID = $Buffer->ReadInt32( );
			$Type      = $Buffer->ReadInt32( );
		}

		if( $RequestID === -1 || $Type !== SourceQuery::SERVERDATA_AUTH_RESPONSE )
		{
			throw new AuthenticationException( 'RCON authorization failed.', AuthenticationException::BAD_PASSWORD );
		}
	}
}


================================================
FILE: Tests/Info/csgo.json
================================================
{
    "Protocol": 17,
    "HostName": "BombGame by xPaw & Co.",
    "Map": "de_dust2",
    "ModDir": "csgo",
    "ModDesc": "Counter-Strike: Global Offensive",
    "AppID": 730,
    "Players": 0,
    "MaxPlayers": 16,
    "Bots": 0,
    "Dedicated": "d",
    "Os": "l",
    "Password": false,
    "Secure": true,
    "Version": "1.35.0.7",
    "ExtraDataFlags": 177,
    "GamePort": 27036,
    "SteamID": 90097713628897284,
    "GameTags": "empty,*grp:1105381i,bombgame,secure",
    "GameID": 730
}


================================================
FILE: Tests/Info/csgo.raw
================================================
ffffffff4911426f6d6247616d652062792078506177202620436f2e0064655f6475737432006373676f00436f756e7465722d537472696b653a20476c6f62616c204f6666656e7369766500da02001000646c0001312e33352e302e3700b19c6904e0eca764174001656d7074792c2a6772703a31313035333831692c626f6d6267616d652c73656375726500da02000000000000


================================================
FILE: Tests/Info/gmod_cyrillic.json
================================================
{
    "Protocol": 17,
    "HostName": "Город Инноваций | Русский DarkRP",
    "Map": "rp_bangclaw",
    "ModDir": "garrysmod",
    "ModDesc": "DarkRP",
    "AppID": 4000,
    "Players": 33,
    "MaxPlayers": 40,
    "Bots": 0,
    "Dedicated": "d",
    "Os": "l",
    "Password": false,
    "Secure": true,
    "Version": "15.08.10",
    "ExtraDataFlags": 177,
    "GamePort": 27015,
    "SteamID": 90097724371517447,
    "GameTags": " gm:darkrp",
    "GameID": 4000
}


================================================
FILE: Tests/Info/gmod_cyrillic.raw
================================================
ffffffff4911d093d0bed180d0bed0b420d098d0bdd0bdd0bed0b2d0b0d186d0b8d0b9207c20d0a0d183d181d181d0bad0b8d0b9204461726b52500072705f62616e67636c6177006761727279736d6f64004461726b525000a00f212800646c000131352e30382e313000b1876907403c286717400120676d3a6461726b727000a00f000000000000


================================================
FILE: Tests/Info/hltv.json
================================================
{
    "Address": "192.168.1.197:27020",
    "HostName": "Castle Mortimus:0",
    "Map": "op4_kbase",
    "ModDir": "gearbox",
    "ModDesc": "HLTV",
    "Players": 0,
    "MaxPlayers": 1,
    "Protocol": 48,
    "Dedicated": "p",
    "Os": "w",
    "Password": false,
    "IsMod": false,
    "Secure": false,
    "Bots": 0
}


================================================
FILE: Tests/Info/hltv.raw
================================================
ffffffff6d3139322e3136382e312e3139373a323730323000436173746c65204d6f7274696d75733a30006f70345f6b626173650067656172626f7800484c5456000001307077000000


================================================
FILE: Tests/Info/svencoop_nonsteam.json
================================================
{
    "Address": "127.0.0.1:27015",
    "HostName": "ClanSC #3 - Engage [Logros]",
    "Map": "sc_doc",
    "ModDir": "svencoop",
    "ModDesc": "Sven Co-op 4.8",
    "Players": 0,
    "MaxPlayers": 16,
    "Protocol": 47,
    "Dedicated": "d",
    "Os": "w",
    "Password": true,
    "IsMod": true,
    "Secure": false,
    "Bots": 0,
    "Mod": {
        "Url": "",
        "Download": "",
        "Version": 1,
        "Size": 0,
        "ServerSide": true,
        "CustomDLL": false
    }
}


================================================
FILE: Tests/Info/svencoop_nonsteam.raw
================================================
ffffffff6d3132372e302e302e313a323730313500436c616e5343202333202d20456e67616765205b4c6f67726f735d0073635f646f63007376656e636f6f70005376656e20436f2d6f7020342e380000102f64770101000000010000000000000001000000


================================================
FILE: Tests/Info/tf2.json
================================================
{
    "Protocol": 17,
    "HostName": " FirePowered.org | Unusual Trade | !jackpot",
    "Map": "trade_unusual_center_v3",
    "ModDir": "tf",
    "ModDesc": "Unusual Trading",
    "AppID": 440,
    "Players": 32,
    "MaxPlayers": 32,
    "Bots": 0,
    "Dedicated": "d",
    "Os": "l",
    "Password": false,
    "Secure": true,
    "Version": "3032525",
    "ExtraDataFlags": 241,
    "GamePort": 27045,
    "SteamID": 85568392920039468,
    "SpecPort": 27050,
    "SpecName": "ScamCam",
    "GameTags": "FirePowered,alltalk,backpack.tf,increased_maxplayers,no_ads,noads,nopinion,norespawntime,trade,trading,unusual",
    "GameID": 440
}


================================================
FILE: Tests/Info/tf2.raw
================================================
ffffffff49112046697265506f77657265642e6f7267207c20556e757375616c205472616465207c20216a61636b706f740074726164655f756e757375616c5f63656e7465725f763300746600556e757375616c2054726164696e6700b801202000646c00013330333235323500f1a5692c00000000003001aa695363616d43616d0046697265506f77657265642c616c6c74616c6b2c6261636b7061636b2e74662c696e637265617365645f6d6178706c61796572732c6e6f5f6164732c6e6f6164732c6e6f70696e696f6e2c6e6f7265737061776e74696d652c74726164652c74726164696e672c756e757375616c00b801000000000000


================================================
FILE: Tests/Info/theship.json
================================================
{
    "Protocol": 7,
    "HostName": "RKSzone.com | US Chicago | The Ship | Hunt",
    "Map": "atalanta",
    "ModDir": "ship",
    "ModDesc": "The Ship",
    "AppID": 2400,
    "Players": 27,
    "MaxPlayers": 32,
    "Bots": 16,
    "Dedicated": "d",
    "Os": "w",
    "Password": false,
    "Secure": true,
    "GameMode": 0,
    "WitnessCount": 2,
    "WitnessTime": 5,
    "Version": "1.0.0.16"
}


================================================
FILE: Tests/Info/theship.raw
================================================
ffffffff4907524b537a6f6e652e636f6d207c205553204368696361676f207c205468652053686970207c2048756e74006174616c616e746100736869700054686520536869700060091b201064770001000205312e302e302e313600


================================================
FILE: Tests/Players/csgo.json
================================================
[
    {
        "Id": 0,
        "Name": "Zien",
        "Frags": 0,
        "Time": 11538,
        "TimeF": "03:12:18"
    },
    {
        "Id": 0,
        "Name": "Doffy",
        "Frags": 0,
        "Time": 8919,
        "TimeF": "02:28:39"
    },
    {
        "Id": 0,
        "Name": "丶↑뮈지 这是什么鬼",
        "Frags": 0,
        "Time": 8804,
        "TimeF": "02:26:44"
    },
    {
        "Id": 0,
        "Name": "LiGGleS",
        "Frags": 0,
        "Time": 7561,
        "TimeF": "02:06:01"
    },
    {
        "Id": 0,
        "Name": "☣[AGC]Michael J. Caboose☣",
        "Frags": 0,
        "Time": 5675,
        "TimeF": "01:34:35"
    },
    {
        "Id": 0,
        "Name": "decision <vancity_dv>",
        "Frags": 0,
        "Time": 5339,
        "TimeF": "01:28:59"
    },
    {
        "Id": 0,
        "Name": "Mime ❝Matheo❞",
        "Frags": 0,
        "Time": 4296,
        "TimeF": "01:11:36"
    },
    {
        "Id": 0,
        "Name": "Szp@n3r",
        "Frags": 0,
        "Time": 3880,
        "TimeF": "01:04:40"
    },
    {
        "Id": 0,
        "Name": "Foxy | D:<",
        "Frags": 0,
        "Time": 3746,
        "TimeF": "01:02:26"
    },
    {
        "Id": 0,
        "Name": "Giguli",
        "Frags": 0,
        "Time": 3599,
        "TimeF": "59:59"
    },
    {
        "Id": 0,
        "Name": "Erkxalle",
        "Frags": 0,
        "Time": 2860,
        "TimeF": "47:40"
    },
    {
        "Id": 0,
        "Name": "[GlobalEdgelite]DaC0p#fuckturks",
        "Frags": 0,
        "Time": 2666,
        "TimeF": "44:26"
    },
    {
        "Id": 0,
        "Name": "Aluminiu",
        "Frags": 0,
        "Time": 2634,
        "TimeF": "43:54"
    },
    {
        "Id": 0,
        "Name": "BlackLounge-ZombieSOAD TwinBROS",
        "Frags": 0,
        "Time": 2499,
        "TimeF": "41:39"
    },
    {
        "Id": 0,
        "Name": "Captain Buster",
        "Frags": 0,
        "Time": 2420,
        "TimeF": "40:20"
    },
    {
        "Id": 0,
        "Name": "thirty seven",
        "Frags": 0,
        "Time": 2395,
        "TimeF": "39:55"
    },
    {
        "Id": 0,
        "Name": "!Bastardo!",
        "Frags": 0,
        "Time": 2274,
        "TimeF": "37:54"
    },
    {
        "Id": 0,
        "Name": "Saibot™",
        "Frags": 0,
        "Time": 2240,
        "TimeF": "37:20"
    },
    {
        "Id": 0,
        "Name": "OG W i l l y",
        "Frags": 0,
        "Time": 2182,
        "TimeF": "36:22"
    },
    {
        "Id": 0,
        "Name": "TriXterR",
        "Frags": 0,
        "Time": 2034,
        "TimeF": "33:54"
    },
    {
        "Id": 0,
        "Name": "ToadsMansion",
        "Frags": 0,
        "Time": 1974,
        "TimeF": "32:54"
    },
    {
        "Id": 0,
        "Name": "Moxshi™",
        "Frags": 0,
        "Time": 1924,
        "TimeF": "32:04"
    },
    {
        "Id": 0,
        "Name": "bish",
        "Frags": 0,
        "Time": 1831,
        "TimeF": "30:31"
    },
    {
        "Id": 0,
        "Name": "Arakismo",
        "Frags": 0,
        "Time": 1811,
        "TimeF": "30:11"
    },
    {
        "Id": 0,
        "Name": "Just_Dank",
        "Frags": 0,
        "Time": 1753,
        "TimeF": "29:13"
    },
    {
        "Id": 0,
        "Name": "Aftersh0ck",
        "Frags": 0,
        "Time": 1724,
        "TimeF": "28:44"
    },
    {
        "Id": 0,
        "Name": "Saibaman",
        "Frags": 0,
        "Time": 1635,
        "TimeF": "27:15"
    },
    {
        "Id": 0,
        "Name": "The Ultimate Gamer",
        "Frags": 0,
        "Time": 1610,
        "TimeF": "26:50"
    },
    {
        "Id": 0,
        "Name": "Butter Kaya no Peanut",
        "Frags": 0,
        "Time": 1549,
        "TimeF": "25:49"
    },
    {
        "Id": 0,
        "Name": "Lugiia",
        "Frags": 0,
        "Time": 1488,
        "TimeF": "24:48"
    },
    {
        "Id": 0,
        "Name": "Hoang Bao",
        "Frags": 0,
        "Time": 1387,
        "TimeF": "23:07"
    },
    {
        "Id": 0,
        "Name": "Eldo Prezidento",
        "Frags": 0,
        "Time": 1344,
        "TimeF": "22:24"
    },
    {
        "Id": 0,
        "Name": "Sky[C.Y.R]",
        "Frags": 0,
        "Time": 1306,
        "TimeF": "21:46"
    },
    {
        "Id": 0,
        "Name": "PunckChop",
        "Frags": 0,
        "Time": 995,
        "TimeF": "16:35"
    },
    {
        "Id": 0,
        "Name": "Elmoradian",
        "Frags": 0,
        "Time": 968,
        "TimeF": "16:08"
    },
    {
        "Id": 0,
        "Name": "friendshipz",
        "Frags": 0,
        "Time": 967,
        "TimeF": "16:07"
    },
    {
        "Id": 0,
        "Name": "Guardios",
        "Frags": 0,
        "Time": 897,
        "TimeF": "14:57"
    },
    {
        "Id": 0,
        "Name": "Samuel Luz",
        "Frags": 0,
        "Time": 779,
        "TimeF": "12:59"
    },
    {
        "Id": 0,
        "Name": "LordMerkx",
        "Frags": 0,
        "Time": 756,
        "TimeF": "12:36"
    },
    {
        "Id": 0,
        "Name": "zeroyjk",
        "Frags": 0,
        "Time": 698,
        "TimeF": "11:38"
    },
    {
        "Id": 0,
        "Name": "[yellow][@Rainbow@][blue](moon)",
        "Frags": 0,
        "Time": 633,
        "TimeF": "10:33"
    },
    {
        "Id": 0,
        "Name": "XiaoJim(Newbie)",
        "Frags": 0,
        "Time": 588,
        "TimeF": "09:48"
    },
    {
        "Id": 0,
        "Name": "George Costanza",
        "Frags": 0,
        "Time": 568,
        "TimeF": "09:28"
    },
    {
        "Id": 0,
        "Name": "Boring Bob",
        "Frags": 0,
        "Time": 565,
        "TimeF": "09:25"
    },
    {
        "Id": 0,
        "Name": "Chris",
        "Frags": 0,
        "Time": 559,
        "TimeF": "09:19"
    },
    {
        "Id": 0,
        "Name": "NLVN",
        "Frags": 0,
        "Time": 554,
        "TimeF": "09:14"
    },
    {
        "Id": 0,
        "Name": "Dan Rampage",
        "Frags": 0,
        "Time": 518,
        "TimeF": "08:38"
    },
    {
        "Id": 0,
        "Name": "Kikerini",
        "Frags": 0,
        "Time": 477,
        "TimeF": "07:57"
    },
    {
        "Id": 0,
        "Name": "waxor123",
        "Frags": 0,
        "Time": 382,
        "TimeF": "06:22"
    },
    {
        "Id": 0,
        "Name": "Uzu",
        "Frags": 0,
        "Time": 286,
        "TimeF": "04:46"
    },
    {
        "Id": 0,
        "Name": "chewin'_ma_BIC #FREE KAKAROT",
        "Frags": 0,
        "Time": 265,
        "TimeF": "04:25"
    },
    {
        "Id": 0,
        "Name": "Milk Tea.",
        "Frags": 0,
        "Time": 218,
        "TimeF": "03:38"
    },
    {
        "Id": 0,
        "Name": "Inglorious Bastard",
        "Frags": 0,
        "Time": 208,
        "TimeF": "03:28"
    },
    {
        "Id": 0,
        "Name": "Bloody Wolf",
        "Frags": 0,
        "Time": 184,
        "TimeF": "03:04"
    },
    {
        "Id": 0,
        "Name": "YurMum",
        "Frags": 0,
        "Time": 161,
        "TimeF": "02:41"
    },
    {
        "Id": 0,
        "Name": "Modica",
        "Frags": 0,
        "Time": 113,
        "TimeF": "01:53"
    },
    {
        "Id": 0,
        "Name": "[P].R.O.T.O.T.Y.P.E",
        "Frags": 0,
        "Time": 109,
        "TimeF": "01:49"
    },
    {
        "Id": 0,
        "Name": "69@War",
        "Frags": 0,
        "Time": 33,
        "TimeF": "00:33"
    }
]


================================================
FILE: Tests/Players/csgo.raw
================================================
feffffffff8400000200a404ffffffff443a005a69656e0000000000d948344600efbca4efbd8fefbd86efbd86efbd9900000000007a5c0b4600e4b8b6e28691ebae88eca78020e8bf99e698afe4bb80e4b988e9acbc00000000003a920946004c6947476c655300000000005348ec4500e298a35b4147435d4d69636861656c204a2e204361626f6f7365e298a30000000000905ab145006465636973696f6e203c76616e636974795f64763e00000000004edfa645004d696d6520e29d9d4d617468656fe29d9e00000000001940864500537a70406e33720000000000898c724500466f7879207c20443a3c0000000000622c6a4500476967756c690000000000ebfb60450045726b78616c6c65000000000048c93245005b476c6f62616c456467656c6974655d4461433070236675636b7475726b73000000000087a5264500416c756d696e69750000000000c6ac244500426c61636b4c6f756e67652d5a6f6d626965534f4144205477696e42524f530000000000c6381c45004361707461696e204275737465720000000000ac4917450074686972747920736576656e00000000006eb315450021426173746172646f210000000000ed260e4500536169626f74e284a20000000000ae000c45004f4720572069206c206c20790000000000836508450054726958746572520000000000855afe4400546f6164734d616e73696f6e000000000003d1f644004d6f78736869e284a200000000000483f0440062697368000000000096efe444004172616b69736d6f00000000009769e244004a7573745f44616e6b00000000009d27db44004166746572736830636b00000000002680d7440053616962616d616e00000000009274cc440054686520556c74696d6174652047616d65720000000000934bc94400427574746572204b617961206e6f205065616e7574000000000075a0c144004c75676969610000000000fd02ba4400486f616e672042616f0000000000677aad4400456c646f205072657a6964656e746f00000000006612a84400536b795b432e592e525d0000000000e758a3440050756e636b43686f7000000000007bee784400456c6d6f72616469616e00000000008e0b724400667269656e64736869707a000000000090d37144004775617264696f7300000000008e4a60440053616d75656c204c757a0000000000cbdb4244004c6f72644d65726b780000000000c9123d44007a65726f796a6b000000000083a92e44005b79656c6c6f775d5b405261696e626f77405d5b626c75655d286d6f6f6e29000000000088401e44005869616f4a696d284e6577626965290000000000a33c13440047656f72676520436f7374616e7a610000000000af040e4400426f72696e6720426f620000000000b7600d440043687269730000000000b6fa0b44004e4c564e0000000000b0870a440044616e2052616d7061676500000000008d900144004b696b6572696e690000000000dae3ee43007761786f723132330000000000d713bf4300557a750000000000276b8f430063686577696e275f6d615f424943202346524545204b414b41524f5400000000000df78443004d696c6b205465612e00000000002a025a4300496e676c6f72696f75732042617374617264000000000052
feffffffff8400000201a4040e504300426c6f6f647920576f6c66000000000014583843005975724d756d0000000000f6452143004d6f64696361000000000041e7e242005b505d2e522e4f2e542e4f2e542e592e502e4500000000005db8da4200363940576172000000000018f00742


================================================
FILE: Tests/Rules/tf2_sourcemod.json
================================================
{
    "anti_f2p_version": "2.1.0",
    "backpack_tf_version": "2.11.1A",
    "backpack_viewer_version": "1.1.2A",
    "bethehorsemann_version": "1.1",
    "connect_method_version": "1.2.0A",
    "connect_version": "1.2.0",
    "coop": "0",
    "custom_chat_colors_mysql_version": "1.1.3A",
    "custom_chat_colors_toggle_version": "2.0.0A",
    "custom_chat_colors_version": "3.1.0A",
    "deathmatch": "1",
    "decalfrequency": "10",
    "dynamicmotd_version": "2.2.3s",
    "enhanced_items_version": "1.1.0A",
    "falsemessages_version": "3.1",
    "goto_version": "1.2",
    "impersonate_version": "1.5.0",
    "kartify_version": "1.5.0A",
    "local_item_server_version": "1.1.5A",
    "metamod_version": "1.10.6-devV",
    "mp_allowNPCs": "1",
    "mp_autocrosshair": "1",
    "mp_autoteambalance": "0",
    "mp_disable_respawn_times": "1",
    "mp_fadetoblack": "0",
    "mp_falldamage": "0",
    "mp_flashlight": "0",
    "mp_footsteps": "1",
    "mp_forceautoteam": "0",
    "mp_forcerespawn": "1",
    "mp_fraglimit": "0",
    "mp_friendlyfire": "0",
    "mp_highlander": "0",
    "mp_holiday_nogifts": "0",
    "mp_match_end_at_timelimit": "1",
    "mp_maxrounds": "0",
    "mp_respawnwavetime": "10.0",
    "mp_scrambleteams_auto": "0",
    "mp_scrambleteams_auto_windifference": "3",
    "mp_stalemate_enable": "0",
    "mp_stalemate_meleeonly": "0",
    "mp_teamlist": "hgrunt;scientist",
    "mp_teamplay": "0",
    "mp_timelimit": "300",
    "mp_tournament": "0",
    "mp_tournament_readymode": "0",
    "mp_tournament_readymode_countdown": "10",
    "mp_tournament_readymode_min": "2",
    "mp_tournament_readymode_team_size": "0",
    "mp_tournament_stopwatch": "1",
    "mp_weaponstay": "0",
    "mp_windifference": "0",
    "mp_windifference_min": "0",
    "mp_winlimit": "0",
    "nextlevel": "",
    "no_enemy_in_spawn_version": "1.2.1A",
    "player_analytics_version": "1.3.1A",
    "rainbowize_version": "1.7.0A",
    "rplayer_version": "1.1",
    "r_AirboatViewDampenDamp": "1.0",
    "r_AirboatViewDampenFreq": "7.0",
    "r_AirboatViewZHeight": "0.0",
    "r_JeepViewDampenDamp": "1.0",
    "r_JeepViewDampenFreq": "7.0",
    "r_JeepViewZHeight": "10.0",
    "r_VehicleViewDampen": "1",
    "sbchecker_version": "1.0.2",
    "sb_version": "1.4.11",
    "scp_version": "2.1.0A",
    "setuber_version": "1.3",
    "smdj_version": "2.6.1",
    "sm_adminsmite_version": "2.1",
    "sm_aimnames_version": "0.8",
    "sm_al_version": "1.0",
    "sm_ammopackspawner_version": "1.0.0",
    "sm_anticolorabuse_version": "1.0.0",
    "sm_bgod_version": "1.0.1",
    "sm_bhs_version": "1.0.0",
    "sm_bleed_version": "1.0.0",
    "sm_destroy_version": "1.2.0",
    "sm_disco_version": "0.3.0",
    "sm_fakegifts_version": "1.0.1",
    "sm_fakeitem_version": "1.3.0",
    "sm_fcvar_version": "1.1",
    "sm_fia_version": "2.2.4",
    "sm_funcommandsx_version": "2.2",
    "sm_godmode_version": "2.3.1",
    "sm_healthpack_spawner_version": "1.0.0",
    "sm_horsemann_version": "1.1",
    "sm_merasmus_version": "1.4.2",
    "sm_monospawn_version": "1.1.1",
    "sm_mutecheck_version": "1.9.2A",
    "sm_nextmap": "trade_unusual_center_v3",
    "sm_noisemaker_version": "2.2.0",
    "sm_powerplay_version": "1.5.3m",
    "sm_raffle_version": "0.9",
    "sm_regen_version": "1.0",
    "sm_resize_version": "1.2.0",
    "sm_rweapons_version": "1.3",
    "sm_setammo_version": "1.1.0",
    "sm_setclass_chat": "1",
    "sm_setclass_log": "1",
    "sm_setclass_version": "1.2.0",
    "sm_setspeed_chat": "1",
    "sm_setspeed_log": "1",
    "sm_setspeed_version": "1.3.1",
    "sm_shutdown_countdown_version": "1.6.2A",
    "sm_spray_version": "5.8a",
    "sm_stunmod_version": "1.4.4.7",
    "sm_taunt_version": "0.3",
    "sm_tidychat_version": "0.4",
    "sm_traderep_version": "1.0.2A",
    "sm_updater_version": "1.2.2",
    "sourcecomms_version": "0.9.266",
    "sourcemod_version": "1.7.3-dev+5240",
    "steamrep_checker_version": "1.2.0A",
    "steamtools_version": "0.9.0+d5d0838",
    "stripper_version": "1.2.2",
    "st_gamedesc_override_version": "1.1.3A",
    "sv_accelerate": "10",
    "sv_airaccelerate": "10",
    "sv_alltalk": "1",
    "sv_bounce": "0",
    "sv_cheats": "0",
    "sv_contact": "service@firepoweredgaming.com",
    "sv_footsteps": "1",
    "sv_friction": "4",
    "sv_gravity": "800",
    "sv_maxspeed": "320",
    "sv_maxusrcmdprocessticks": "24",
    "sv_noclipaccelerate": "5",
    "sv_noclipspeed": "5",
    "sv_password": "0",
    "sv_pausable": "0",
    "sv_registration_message": "No account specified",
    "sv_registration_successful": "0",
    "sv_rollangle": "0",
    "sv_rollspeed": "200",
    "sv_specaccelerate": "5",
    "sv_specnoclip": "1",
    "sv_specspeed": "3",
    "sv_steamgroup": "",
    "sv_stepsize": "18",
    "sv_stopspeed": "100",
    "sv_tags": "FirePowered,alltalk,backpack.tf,increased_maxplayers,no_ads,noads,nopinion,norespawntime,trade,trading,unusual",
    "sv_voiceenable": "1",
    "sv_vote_quorum_ratio": "0.6",
    "sv_wateraccelerate": "10",
    "sv_waterfriction": "1",
    "teamswitch_version": "1.3",
    "tf2items_giveweapon_version": "3.14159",
    "tf2items_manager": "1",
    "tf2items_manager_version": "1.4.1",
    "tf2items_version": "1.6.2",
    "tfh_aprilfools": "0",
    "tfh_birthday": "1",
    "tfh_enabled": "1",
    "tfh_endoftheline": "0",
    "tfh_fullmoon": "1",
    "tfh_halloween": "0",
    "tfh_normalhealth": "0",
    "tfh_valentines": "0",
    "tfh_version": "1.10.2",
    "tfh_winter": "1",
    "tf_allow_player_use": "0",
    "tf_arena_change_limit": "1",
    "tf_arena_first_blood": "1",
    "tf_arena_force_class": "0",
    "tf_arena_max_streak": "3",
    "tf_arena_override_cap_enable_time": "-1",
    "tf_arena_preround_time": "10",
    "tf_arena_round_time": "0",
    "tf_arena_use_queue": "1",
    "tf_beta_content": "0",
    "tf_birthday": "0",
    "tf_bot_count": "0",
    "tf_classlimit": "0",
    "tf_ctf_bonus_time": "10",
    "tf_damage_disablespread": "1",
    "tf_force_holidays_off": "0",
    "tf_gamemode_arena": "0",
    "tf_gamemode_cp": "0",
    "tf_gamemode_ctf": "0",
    "tf_gamemode_mvm": "0",
    "tf_gamemode_passtime": "0",
    "tf_gamemode_payload": "0",
    "tf_gamemode_pd": "0",
    "tf_gamemode_rd": "0",
    "tf_gamemode_sd": "0",
    "tf_max_charge_speed": "750",
    "tf_medieval": "0",
    "tf_medieval_autorp": "1",
    "tf_mm_servermode": "1",
    "tf_mm_strict": "0",
    "tf_mm_trusted": "0",
    "tf_mvm_death_penalty": "0",
    "tf_mvm_min_players_to_start": "3",
    "tf_overtime_nag": "0",
    "tf_passtime_ball_carrier_regen_dmgtime": "3",
    "tf_passtime_ball_carrier_regen_interval": "1",
    "tf_passtime_ball_carrier_regen_maxpct": "1",
    "tf_passtime_ball_carrier_regen_scale": "0.1f",
    "tf_passtime_ball_damping_scale": "0.01f",
    "tf_passtime_ball_drag_coefficient": "0.01f",
    "tf_passtime_ball_inertia_scale": "1.0f",
    "tf_passtime_ball_mass": "1.0f",
    "tf_passtime_ball_model": "models/passtime/ball/passtime_ball.mdl",
    "tf_passtime_ball_radius": "7.2f",
    "tf_passtime_ball_reset_time": "15",
    "tf_passtime_ball_rotdamping_scale": "1.0f",
    "tf_passtime_ball_seek_range": "128",
    "tf_passtime_ball_seek_speed_factor": "1.5f",
    "tf_passtime_ball_takedamage": "1",
    "tf_passtime_ball_takedamage_force": "800.0f",
    "tf_passtime_flinch_boost": "0",
    "tf_passtime_mode_homing_lock_sec": "1.5f",
    "tf_passtime_mode_homing_speed": "1000.0f",
    "tf_passtime_player_reticles_enemies": "1",
    "tf_passtime_player_reticles_friends": "2",
    "tf_passtime_score_crit_sec": "5.0f",
    "tf_passtime_speedboost_on_get_ball_time": "2.0f",
    "tf_passtime_steal_on_melee": "1",
    "tf_passtime_teammate_steal_time": "45",
    "tf_passtime_throwarc_demoman": "0.3f",
    "tf_passtime_throwarc_engineer": "0.3f",
    "tf_passtime_throwarc_heavy": "0.3f",
    "tf_passtime_throwarc_medic": "0.3f",
    "tf_passtime_throwarc_pyro": "0.3f",
    "tf_passtime_throwarc_scout": "0.3f",
    "tf_passtime_throwarc_sniper": "0.3f",
    "tf_passtime_throwarc_soldier": "0.3f",
    "tf_passtime_throwarc_spy": "0.3f",
    "tf_passtime_throwspeed_demoman": "1000.0f",
    "tf_passtime_throwspeed_engineer": "1000.0f",
    "tf_passtime_throwspeed_heavy": "1000.0f",
    "tf_passtime_throwspeed_medic": "1000.0f",
    "tf_passtime_throwspeed_pyro": "1000.0f",
    "tf_passtime_throwspeed_scout": "1000.0f",
    "tf_passtime_throwspeed_sniper": "1000.0f",
    "tf_passtime_throwspeed_soldier": "1000.0f",
    "tf_passtime_throwspeed_spy": "1000.0f",
    "tf_passtime_throwspeed_velocity_scale": "0",
    "tf_playergib": "1",
    "tf_player_name_change_time": "60",
    "tf_powerup_mode": "0",
    "tf_server_identity_disable_quickplay": "0",
    "tf_spec_xray": "1",
    "tf_spells_enabled": "0",
    "tf_teamtalk": "1",
    "tf_use_fixed_weaponspreads": "0",
    "tf_weapon_criticals": "1",
    "tf_weapon_criticals_melee": "1",
    "thirdperson_version": "2.1.0",
    "tidykick_version": "1.1.5A",
    "tv_enable": "1",
    "tv_password": "1",
    "tv_relaypassword": "0",
    "uberpunisher_version": "1.5.2",
    "ufov_version": "1.2.0A",
    "voiceannounce_ex_version": "2.0.0",
    "votekick_switcher_version": "1.3.0A"
}


================================================
FILE: Tests/Rules/tf2_sourcemod.raw
================================================
feffffff570100000600e004ffffffff450501616e74695f6632705f76657273696f6e00322e312e30006261636b7061636b5f74665f76657273696f6e00322e31312e3141006261636b7061636b5f7669657765725f76657273696f6e00312e312e3241006265746865686f7273656d616e6e5f76657273696f6e00312e3100636f6e6e6563745f6d6574686f645f76657273696f6e00312e322e304100636f6e6e6563745f76657273696f6e00312e322e3000636f6f70003000637573746f6d5f636861745f636f6c6f72735f6d7973716c5f76657273696f6e00312e312e334100637573746f6d5f636861745f636f6c6f72735f746f67676c655f76657273696f6e00322e302e304100637573746f6d5f636861745f636f6c6f72735f76657273696f6e00332e312e30410064656174686d61746368003100646563616c6672657175656e63790031300064796e616d69636d6f74645f76657273696f6e00322e322e337300656e68616e6365645f6974656d735f76657273696f6e00312e312e30410066616c73656d657373616765735f76657273696f6e00332e3100676f746f5f76657273696f6e00312e3200696d706572736f6e6174655f76657273696f6e00312e352e30006b6172746966795f76657273696f6e00312e352e3041006c6f63616c5f6974656d5f7365727665725f76657273696f6e00312e312e3541006d6574616d6f645f76657273696f6e00312e31302e362d64657656006d705f616c6c6f774e5043730031006d705f6175746f63726f7373686169720031006d705f6175746f7465616d62616c616e63650030006d705f64697361626c655f7265737061776e5f74696d65730031006d705f66616465746f626c61636b0030006d705f66616c6c64616d6167650030006d705f666c6173686c696768740030006d705f666f6f7473746570730031006d705f666f7263656175746f7465616d0030006d705f666f7263657265737061776e0031006d705f667261676c696d69740030006d705f667269656e646c79666972650030006d705f686967686c616e6465720030006d705f686f6c696461795f6e6f67696674730030006d705f6d617463685f656e645f61745f74696d656c696d69740031006d705f6d6178726f756e64730030006d705f7265737061776e7761766574696d650031302e30006d705f736372616d626c657465616d735f6175746f0030006d705f736372616d626c657465616d735f6175746f5f77696e646966666572656e63650033006d705f7374616c656d6174655f656e61626c650030006d705f7374616c656d6174655f6d656c65656f6e6c790030006d705f7465616d6c69737400686772756e743b736369656e74697374006d705f7465616d706c61790030006d705f74696d656c696d697400333030006d705f746f75726e616d656e740030006d705f746f75726e616d656e745f72656164796d6f64650030006d705f746f75726e616d656e745f72656164796d6f64655f636f756e74646f776e003130006d705f746f75726e616d656e745f72656164796d6f64655f6d696e0032006d705f746f75726e616d656e745f72656164796d6f64655f7465616d5f73697a650030006d705f746f75726e616d656e745f73746f7077617463680031006d705f776561706f6e737461790030006d705f77696e646966666572656e63650030006d705f77696e646966666572656e63655f6d696e0030
feffffff570100000601e004006d705f77696e6c696d69740030006e6578746c6576656c00006e6f5f656e656d795f696e5f737061776e5f76657273696f6e00312e322e314100706c617965725f616e616c79746963735f76657273696f6e00312e332e3141007261696e626f77697a655f76657273696f6e00312e372e30410072706c617965725f76657273696f6e00312e3100725f416972626f61745669657744616d70656e44616d7000312e3000725f416972626f61745669657744616d70656e4672657100372e3000725f416972626f6174566965775a48656967687400302e3000725f4a6565705669657744616d70656e44616d7000312e3000725f4a6565705669657744616d70656e4672657100372e3000725f4a656570566965775a4865696768740031302e3000725f56656869636c655669657744616d70656e0031007362636865636b65725f76657273696f6e00312e302e320073625f76657273696f6e00312e342e3131007363705f76657273696f6e00322e312e304100736574756265725f76657273696f6e00312e3300736d646a5f76657273696f6e00322e362e3100736d5f61646d696e736d6974655f76657273696f6e00322e3100736d5f61696d6e616d65735f76657273696f6e00302e3800736d5f616c5f76657273696f6e00312e3000736d5f616d6d6f7061636b737061776e65725f76657273696f6e00312e302e3000736d5f616e7469636f6c6f7261627573655f76657273696f6e00312e302e3000736d5f62676f645f76657273696f6e00312e302e3100736d5f6268735f76657273696f6e00312e302e3000736d5f626c6565645f76657273696f6e00312e302e3000736d5f64657374726f795f76657273696f6e00312e322e3000736d5f646973636f5f76657273696f6e00302e332e3000736d5f66616b6567696674735f76657273696f6e00312e302e3100736d5f66616b656974656d5f76657273696f6e00312e332e3000736d5f66637661725f76657273696f6e00312e3100736d5f6669615f76657273696f6e00322e322e3400736d5f66756e636f6d6d616e6473785f76657273696f6e00322e3200736d5f676f646d6f64655f76657273696f6e00322e332e3100736d5f6865616c74687061636b5f737061776e65725f76657273696f6e00312e302e3000736d5f686f7273656d616e6e5f76657273696f6e00312e3100736d5f6d657261736d75735f76657273696f6e00312e342e3200736d5f6d6f6e6f737061776e5f76657273696f6e00312e312e3100736d5f6d757465636865636b5f76657273696f6e00312e392e324100736d5f6e6578746d61700074726164655f756e757375616c5f63656e7465725f763300736d5f6e6f6973656d616b65725f76657273696f6e00322e322e3000736d5f706f776572706c61795f76657273696f6e00312e352e336d00736d5f726166666c655f76657273696f6e00302e3900736d5f726567656e5f76657273696f6e00312e3000736d5f726573697a655f76657273696f6e00312e322e3000736d5f72776561706f6e735f76657273696f6e00312e3300736d5f736574616d6d6f5f76657273696f6e00312e312e3000736d5f736574636c6173735f63686174003100736d5f736574636c6173735f6c6f67003100736d5f736574636c6173735f76657273696f6e00312e322e3000736d5f73657473706565645f63686174003100736d5f736574737065
feffffff570100000602e00465645f6c6f67003100736d5f73657473706565645f76657273696f6e00312e332e3100736d5f73687574646f776e5f636f756e74646f776e5f76657273696f6e00312e362e324100736d5f73707261795f76657273696f6e00352e386100736d5f7374756e6d6f645f76657273696f6e00312e342e342e3700736d5f7461756e745f76657273696f6e00302e3300736d5f74696479636861745f76657273696f6e00302e3400736d5f74726164657265705f76657273696f6e00312e302e324100736d5f757064617465725f76657273696f6e00312e322e3200736f75726365636f6d6d735f76657273696f6e00302e392e32363600736f757263656d6f645f76657273696f6e00312e372e332d6465762b3532343000737465616d7265705f636865636b65725f76657273696f6e00312e322e304100737465616d746f6f6c735f76657273696f6e00302e392e302b643564303833380073747269707065725f76657273696f6e00312e322e320073745f67616d65646573635f6f766572726964655f76657273696f6e00312e312e33410073765f616363656c65726174650031300073765f616972616363656c65726174650031300073765f616c6c74616c6b00310073765f626f756e636500300073765f63686561747300300073765f636f6e7461637400736572766963654066697265706f776572656467616d696e672e636f6d0073765f666f6f74737465707300310073765f6672696374696f6e00340073765f67726176697479003830300073765f6d61787370656564003332300073765f6d6178757372636d6470726f636573737469636b730032340073765f6e6f636c6970616363656c657261746500350073765f6e6f636c6970737065656400350073765f70617373776f726400300073765f7061757361626c6500300073765f726567697374726174696f6e5f6d657373616765004e6f206163636f756e74207370656369666965640073765f726567697374726174696f6e5f7375636365737366756c00300073765f726f6c6c616e676c6500300073765f726f6c6c7370656564003230300073765f73706563616363656c657261746500350073765f737065636e6f636c697000310073765f73706563737065656400330073765f737465616d67726f7570000073765f7374657073697a650031380073765f73746f707370656564003130300073765f746167730046697265506f77657265642c616c6c74616c6b2c6261636b7061636b2e74662c696e637265617365645f6d6178706c61796572732c6e6f5f6164732c6e6f6164732c6e6f70696e696f6e2c6e6f7265737061776e74696d652c74726164652c74726164696e672c756e757375616c0073765f766f696365656e61626c6500310073765f766f74655f71756f72756d5f726174696f00302e360073765f7761746572616363656c65726174650031300073765f77617465726672696374696f6e0031007465616d7377697463685f76657273696f6e00312e33007466326974656d735f67697665776561706f6e5f76657273696f6e00332e3134313539007466326974656d735f6d616e616765720031007466326974656d735f6d616e616765725f76657273696f6e00312e342e31007466326974656d735f76657273696f6e00312e362e32007466685f617072696c666f6f6c730030007466685f62697274686461790031007466685f65
feffffff570100000603e0046e61626c65640031007466685f656e646f667468656c696e650030007466685f66756c6c6d6f6f6e0031007466685f68616c6c6f7765656e0030007466685f6e6f726d616c6865616c74680030007466685f76616c656e74696e65730030007466685f76657273696f6e00312e31302e32007466685f77696e74657200310074665f616c6c6f775f706c617965725f75736500300074665f6172656e615f6368616e67655f6c696d697400310074665f6172656e615f66697273745f626c6f6f6400310074665f6172656e615f666f7263655f636c61737300300074665f6172656e615f6d61785f73747265616b00330074665f6172656e615f6f766572726964655f6361705f656e61626c655f74696d65002d310074665f6172656e615f707265726f756e645f74696d650031300074665f6172656e615f726f756e645f74696d6500300074665f6172656e615f7573655f717565756500310074665f626574615f636f6e74656e7400300074665f626972746864617900300074665f626f745f636f756e7400300074665f636c6173736c696d697400300074665f6374665f626f6e75735f74696d650031300074665f64616d6167655f64697361626c6573707265616400310074665f666f7263655f686f6c69646179735f6f666600300074665f67616d656d6f64655f6172656e6100300074665f67616d656d6f64655f637000300074665f67616d656d6f64655f63746600300074665f67616d656d6f64655f6d766d00300074665f67616d656d6f64655f7061737374696d6500300074665f67616d656d6f64655f7061796c6f616400300074665f67616d656d6f64655f706400300074665f67616d656d6f64655f726400300074665f67616d656d6f64655f736400300074665f6d61785f6368617267655f7370656564003735300074665f6d6564696576616c00300074665f6d6564696576616c5f6175746f727000310074665f6d6d5f7365727665726d6f646500310074665f6d6d5f73747269637400300074665f6d6d5f7472757374656400300074665f6d766d5f64656174685f70656e616c747900300074665f6d766d5f6d696e5f706c61796572735f746f5f737461727400330074665f6f76657274696d655f6e616700300074665f7061737374696d655f62616c6c5f636172726965725f726567656e5f646d6774696d6500330074665f7061737374696d655f62616c6c5f636172726965725f726567656e5f696e74657276616c00310074665f7061737374696d655f62616c6c5f636172726965725f726567656e5f6d617870637400310074665f7061737374696d655f62616c6c5f636172726965725f726567656e5f7363616c6500302e31660074665f7061737374696d655f62616c6c5f64616d70696e675f7363616c6500302e3031660074665f7061737374696d655f62616c6c5f647261675f636f656666696369656e7400302e3031660074665f7061737374696d655f62616c6c5f696e65727469615f7363616c6500312e30660074665f7061737374696d655f62616c6c5f6d61737300312e30660074665f7061737374696d655f62616c6c5f6d6f64656c006d6f64656c732f7061737374696d652f62616c6c2f7061737374696d655f62616c6c2e6d646c0074665f7061737374696d655f62616c6c5f72616469757300372e32660074665f7061737374696d655f62616c6c5f7265736574
feffffff570100000604e0045f74696d650031350074665f7061737374696d655f62616c6c5f726f7464616d70696e675f7363616c6500312e30660074665f7061737374696d655f62616c6c5f7365656b5f72616e6765003132380074665f7061737374696d655f62616c6c5f7365656b5f73706565645f666163746f7200312e35660074665f7061737374696d655f62616c6c5f74616b6564616d61676500310074665f7061737374696d655f62616c6c5f74616b6564616d6167655f666f726365003830302e30660074665f7061737374696d655f666c696e63685f626f6f737400300074665f7061737374696d655f6d6f64655f686f6d696e675f6c6f636b5f73656300312e35660074665f7061737374696d655f6d6f64655f686f6d696e675f737065656400313030302e30660074665f7061737374696d655f706c617965725f72657469636c65735f656e656d69657300310074665f7061737374696d655f706c617965725f72657469636c65735f667269656e647300320074665f7061737374696d655f73636f72655f637269745f73656300352e30660074665f7061737374696d655f7370656564626f6f73745f6f6e5f6765745f62616c6c5f74696d6500322e30660074665f7061737374696d655f737465616c5f6f6e5f6d656c656500310074665f7061737374696d655f7465616d6d6174655f737465616c5f74696d650034350074665f7061737374696d655f7468726f776172635f64656d6f6d616e00302e33660074665f7061737374696d655f7468726f776172635f656e67696e65657200302e33660074665f7061737374696d655f7468726f776172635f686561767900302e33660074665f7061737374696d655f7468726f776172635f6d6564696300302e33660074665f7061737374696d655f7468726f776172635f7079726f00302e33660074665f7061737374696d655f7468726f776172635f73636f757400302e33660074665f7061737374696d655f7468726f776172635f736e6970657200302e33660074665f7061737374696d655f7468726f776172635f736f6c6469657200302e33660074665f7061737374696d655f7468726f776172635f73707900302e33660074665f7061737374696d655f7468726f7773706565645f64656d6f6d616e00313030302e30660074665f7061737374696d655f7468726f7773706565645f656e67696e65657200313030302e30660074665f7061737374696d655f7468726f7773706565645f686561767900313030302e30660074665f7061737374696d655f7468726f7773706565645f6d6564696300313030302e30660074665f7061737374696d655f7468726f7773706565645f7079726f00313030302e30660074665f7061737374696d655f7468726f7773706565645f73636f757400313030302e30660074665f7061737374696d655f7468726f7773706565645f736e6970657200313030302e30660074665f7061737374696d655f7468726f7773706565645f736f6c6469657200313030302e30660074665f7061737374696d655f7468726f7773706565645f73707900313030302e30660074665f7061737374696d655f7468726f7773706565645f76656c6f636974795f7363616c6500300074665f706c6179657267696200310074665f706c617965725f6e616d655f6368616e67655f74696d650036300074665f706f77657275705f6d6f646500300074665f
feffffff570100000605e0047365727665725f6964656e746974795f64697361626c655f717569636b706c617900300074665f737065635f7872617900310074665f7370656c6c735f656e61626c656400300074665f7465616d74616c6b00310074665f7573655f66697865645f776561706f6e7370726561647300300074665f776561706f6e5f637269746963616c7300310074665f776561706f6e5f637269746963616c735f6d656c65650031007468697264706572736f6e5f76657273696f6e00322e312e3000746964796b69636b5f76657273696f6e00312e312e35410074765f656e61626c6500310074765f70617373776f726400310074765f72656c617970617373776f72640030007562657270756e69736865725f76657273696f6e00312e352e320075666f765f76657273696f6e00312e322e304100766f696365616e6e6f756e63655f65785f76657273696f6e00322e302e3000766f74656b69636b5f73776974636865725f76657273696f6e00312e332e304100


================================================
FILE: Tests/Tests.php
================================================
<?php
declare(strict_types=1);

	use PHPUnit\Framework\Attributes\DataProvider;
	use xPaw\SourceQuery\BaseSocket;
	use xPaw\SourceQuery\SourceQuery;
	use xPaw\SourceQuery\Buffer;

	class TestableSocket extends BaseSocket
	{
		/** @var \SplQueue<string> */
		private \SplQueue $PacketQueue;

		public function __construct( )
		{
			$this->PacketQueue = new \SplQueue();
			$this->PacketQueue->setIteratorMode( \SplDoublyLinkedList::IT_MODE_DELETE );

		}

		public function Queue( string $Data ) : void
		{
			$this->PacketQueue->push( $Data );
		}

		public function Close( ) : void
		{
			//
		}

		public function Open( string $Address, int $Port, int $Timeout, int $Engine ) : void
		{
			$this->Timeout = $Timeout;
			$this->Engine  = $Engine;
			$this->Port    = $Port;
			$this->Address = $Address;
		}

		public function Write( int $Header, string $String = '' ) : bool
		{
			return true;
		}

		public function Read( ) : Buffer
		{
			$Buffer = new Buffer( );
			$Buffer->Set( $this->PacketQueue->shift() );

			$this->ReadInternal( $Buffer, [ $this, 'Sherlock' ] );

			return $Buffer;
		}

		public function Sherlock( Buffer $Buffer ) : bool
		{
			if( $this->PacketQueue->isEmpty() )
			{
				return false;
			}

			$Buffer->Set( $this->PacketQueue->shift() );

			return $Buffer->ReadInt32( ) === -2;
		}
	}

	class Tests extends \PHPUnit\Framework\TestCase
	{
		private TestableSocket $Socket;
		private SourceQuery $SourceQuery;

		public function setUp() : void
		{
			$this->Socket = new TestableSocket();
			$this->SourceQuery = new SourceQuery( $this->Socket );
			$this->SourceQuery->Connect( '', 2 );
		}

		public function tearDown() : void
		{
			$this->SourceQuery->Disconnect();

			unset( $this->Socket, $this->SourceQuery );
		}

		public function testInvalidTimeout() : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\InvalidArgumentException::class );
			$SourceQuery = new SourceQuery( );
			$SourceQuery->Connect( '', 2, -1 );
		}

		public function testNotConnectedGetInfo() : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\SocketException::class );
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->GetInfo();
		}

		public function testNotConnectedPing() : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\SocketException::class );
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->Ping();
		}

		public function testNotConnectedGetPlayers() : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\SocketException::class );
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->GetPlayers();
		}

		public function testNotConnectedGetRules() : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\SocketException::class );
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->GetRules();
		}

		public function testNotConnectedSetRconPassword() : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\SocketException::class );
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->SetRconPassword('a');
		}

		public function testNotConnectedRcon() : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\SocketException::class );
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->Rcon('a');
		}

		public function testRconWithoutPassword() : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\SocketException::class );
			$this->SourceQuery->Rcon('a');
		}

		#[DataProvider( 'InfoProvider' )]
		public function testGetInfo( string $RawInput, array $ExpectedOutput ) : void
		{
			if( isset( $ExpectedOutput[ 'IsMod' ] ) )
			{
				$this->Socket->Engine = SourceQuery::GOLDSOURCE;
			}

			$this->Socket->Queue( $RawInput );

			$RealOutput = $this->SourceQuery->GetInfo();

			self::assertEquals( $ExpectedOutput, $RealOutput );
		}

		public static function InfoProvider() : array
		{
			$DataProvider = [];

			$Files = glob( __DIR__ . '/Info/*.raw', GLOB_ERR );

			if( $Files === false )
			{
				throw new Exception();
			}

			foreach( $Files as $File )
			{
				$DataProvider[] =
				[
					hex2bin( trim( (string)file_get_contents( $File ) ) ),
					json_decode( (string)file_get_contents( str_replace( '.raw', '.json', $File ) ), true )
				];
			}

			return $DataProvider;
		}

		#[DataProvider( 'BadPacketProvider' )]
		public function testBadGetInfo( string $Data ) : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\InvalidPacketException::class );
			$this->Socket->Queue( $Data );

			$this->SourceQuery->GetInfo();
		}

		#[DataProvider( 'BadPacketProvider' )]
		public function testBadGetChallengeViaPlayers( string $Data ) : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\InvalidPacketException::class );
			$this->Socket->Queue( $Data );

			$this->SourceQuery->GetPlayers();
		}

		#[DataProvider( 'BadPacketProvider' )]
		public function testBadGetPlayersAfterCorrectChallenge( string $Data ) : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\InvalidPacketException::class );
			$this->Socket->Queue( "\xFF\xFF\xFF\xFF\x41\x11\x11\x11\x11" );
			$this->Socket->Queue( $Data );

			$this->SourceQuery->GetPlayers();
		}

		#[DataProvider( 'BadPacketProvider' )]
		public function testBadGetRulesAfterCorrectChallenge( string $Data ) : void
		{
			$this->expectException( xPaw\SourceQuery\Exception\InvalidPacketException::class );
			$this->Socket->Queue( "\xFF\xFF\xFF\xFF\x41\x11\x11\x11\x11" );
			$this->Socket->Queue( $Data );

			$this->SourceQuery->GetRules();
		}

		public static function BadPacketProvider( ) : array
		{
			return
			[
				[ "" ],
				[ "\xff\xff\xff\xff" ], // No type
				[ "\xff\xff\xff\xff\x49" ], // Correct type, but no data after
				[ "\xff\xff\xff\xff\x6D" ], // Old info packet, but tests are done for source
				[ "\xff\xff\xff\xff\x11" ], // Wrong type
				[ "\x11\x11\x11\x11" ], // Wrong header
				[ "\xff" ], // Should be 4 bytes, but it's 1
			];
		}

		public function testGetChallengeTwice( ) : void
		{
			$this->Socket->Queue( "\xFF\xFF\xFF\xFF\x41\x11\x11\x11\x11" );
			$this->Socket->Queue( "\xFF\xFF\xFF\xFF\x45\x01\x00ayy\x00lmao\x00" );
			self::assertEquals( [ 'ayy' => 'lmao' ], $this->SourceQuery->GetRules() );

			$this->Socket->Queue( "\xFF\xFF\xFF\xFF\x45\x01\x00wow\x00much\x00" );
			self::assertEquals( [ 'wow' => 'much' ], $this->SourceQuery->GetRules() );
		}

		/** @param array<string> $RawInput */
		#[DataProvider( 'RulesProvider' )]
		public function testGetRules( array $RawInput, array $ExpectedOutput ) : void
		{
			$this->Socket->Queue( (string)hex2bin( "ffffffff4104fce20e" ) ); // Challenge

			foreach( $RawInput as $Packet )
			{
				$this->Socket->Queue( (string)hex2bin( $Packet ) );
			}

			$RealOutput = $this->SourceQuery->GetRules();

			self::assertEquals( $ExpectedOutput, $RealOutput );
		}

		public static function RulesProvider() : array
		{
			$DataProvider = [];

			$Files = glob( __DIR__ . '/Rules/*.raw', GLOB_ERR );

			if( $Files === false )
			{
				throw new Exception();
			}

			foreach( $Files as $File )
			{
				$DataProvider[] =
				[
					file( $File, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES ),
					json_decode( (string)file_get_contents( str_replace( '.raw', '.json', $File ) ), true )
				];
			}

			return $DataProvider;
		}

		/** @param array<string> $RawInput */
		#[DataProvider( 'PlayersProvider' )]
		public function testGetPlayers( array $RawInput, array $ExpectedOutput ) : void
		{
			$this->Socket->Queue( (string)hex2bin( "ffffffff4104fce20e" ) ); // Challenge

			foreach( $RawInput as $Packet )
			{
				$this->Socket->Queue( (string)hex2bin( $Packet ) );
			}

			$RealOutput = $this->SourceQuery->GetPlayers();

			self::assertEquals( $ExpectedOutput, $RealOutput );
		}

		public static function PlayersProvider() : array
		{
			$DataProvider = [];

			$Files = glob( __DIR__ . '/Players/*.raw', GLOB_ERR );

			if( $Files === false )
			{
				throw new Exception();
			}

			foreach( $Files as $File )
			{
				$DataProvider[] =
				[
					file( $File, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES ),
					json_decode( (string)file_get_contents( str_replace( '.raw', '.json', $File ) ), true )
				];
			}

			return $DataProvider;
		}

		public function testPing() : void
		{
			$this->Socket->Queue( "\xFF\xFF\xFF\xFF\x6A\x00");
			self::assertTrue( $this->SourceQuery->Ping() );

			$this->Socket->Queue( "\xFF\xFF\xFF\xFF\xEE");
			self::assertFalse( $this->SourceQuery->Ping() );
		}
	}


================================================
FILE: Tests/phpunit.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
  <testsuites>
    <testsuite name="Tests">
      <file>./Tests.php</file>
    </testsuite>
  </testsuites>
  <source>
    <include>
      <directory suffix=".php">../SourceQuery</directory>
    </include>
  </source>
</phpunit>


================================================
FILE: composer.json
================================================
{
	"name": "xpaw/php-source-query-class",
	"description": "PHP library to query and send RCON commands to servers based on \"Source Engine Query\" protocol",
	"homepage": "https://github.com/xPaw/PHP-Source-Query",
	"type": "library",
	"license": "LGPL-2.1",
	"funding": [
        {
            "type": "github",
            "url": "https://github.com/sponsors/xPaw"
        }
	],
	"keywords":
	[
		"rcon",
		"minecraft",
		"csgo",
		"counter-strike",
		"team fortress",
		"starbound",
		"rust",
		"ark",
		"gmod"
	],
	"scripts":
	{
		"test":
		[
			"@phpunit",
			"@phpstan"
		],
		"phpunit": "phpunit --configuration Tests/phpunit.xml --fail-on-warning",
		"phpunit:coverage": "phpunit --configuration Tests/phpunit.xml --fail-on-warning --coverage-clover build/logs/clover.xml",
		"phpstan": "phpstan"
	},
	"require":
	{
		"php": ">=8.3"
	},
	"require-dev":
	{
		"phpunit/phpunit": "^12.0",
		"phpstan/phpstan": "^2.0",
		"phpstan/phpstan-strict-rules": "^2.0"
	},
	"autoload":
	{
		"psr-4":
		{
			"xPaw\\SourceQuery\\": "SourceQuery/"
		}
	}
}


================================================
FILE: phpstan.neon
================================================
includes:
    - vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
	checkFunctionNameCase: true
	level: max
	paths:
		- .
	excludePaths:
		- vendor
	strictRules:
		booleansInConditions: false
	ignoreErrors:
		- identifier: missingType.iterableValue
		  path: Tests/Tests.php
		- identifier: cast.int
		  path: SourceQuery/Buffer.php
		- identifier: cast.double
		  path: SourceQuery/Buffer.php


================================================
FILE: psalm.xml
================================================
<?xml version="1.0"?>
<psalm
    errorLevel="1"
    resolveFromConfigFile="true"
    findUnusedBaselineEntry="true"
    findUnusedCode="true"
    errorBaseline="Tests/psalm-baseline.xml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://getpsalm.org/schema/config"
    xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
    <projectFiles>
        <directory name="SourceQuery" />
        <directory name="Tests" />
        <ignoreFiles>
            <directory name="vendor" />
        </ignoreFiles>
    </projectFiles>
</psalm>
Download .txt
gitextract_kr43fyxg/

├── .editorconfig
├── .gitattributes
├── .github/
│   ├── dependabot.yml
│   └── workflows/
│       └── ci.yml
├── .gitignore
├── CONTRIBUTING.md
├── Examples/
│   ├── Example.php
│   ├── RconExample.php
│   └── View.php
├── LICENSE
├── README.md
├── SourceQuery/
│   ├── BaseRcon.php
│   ├── BaseSocket.php
│   ├── Buffer.php
│   ├── Exception/
│   │   ├── AuthenticationException.php
│   │   ├── InvalidArgumentException.php
│   │   ├── InvalidPacketException.php
│   │   ├── SocketException.php
│   │   └── SourceQueryException.php
│   ├── GoldSourceRcon.php
│   ├── Socket.php
│   ├── SourceQuery.php
│   └── SourceRcon.php
├── Tests/
│   ├── Info/
│   │   ├── csgo.json
│   │   ├── csgo.raw
│   │   ├── gmod_cyrillic.json
│   │   ├── gmod_cyrillic.raw
│   │   ├── hltv.json
│   │   ├── hltv.raw
│   │   ├── svencoop_nonsteam.json
│   │   ├── svencoop_nonsteam.raw
│   │   ├── tf2.json
│   │   ├── tf2.raw
│   │   ├── theship.json
│   │   └── theship.raw
│   ├── Players/
│   │   ├── csgo.json
│   │   └── csgo.raw
│   ├── Rules/
│   │   ├── tf2_sourcemod.json
│   │   └── tf2_sourcemod.raw
│   ├── Tests.php
│   └── phpunit.xml
├── composer.json
├── phpstan.neon
└── psalm.xml
Download .txt
SYMBOL INDEX (96 symbols across 13 files)

FILE: SourceQuery/BaseRcon.php
  class BaseRcon (line 20) | abstract class BaseRcon
    method Close (line 22) | abstract public function Close( ) : void;
    method Open (line 23) | abstract public function Open( ) : void;
    method Write (line 24) | abstract public function Write( int $Header, string $String = '' ) : b...
    method Read (line 25) | abstract public function Read( ) : Buffer;
    method Command (line 26) | abstract public function Command( string $Command ) : string;
    method Authorize (line 27) | abstract public function Authorize( string $Password ) : void;

FILE: SourceQuery/BaseSocket.php
  class BaseSocket (line 23) | abstract class BaseSocket
    method __destruct (line 33) | public function __destruct( )
    method Close (line 38) | abstract public function Close( ) : void;
    method Open (line 39) | abstract public function Open( string $Address, int $Port, int $Timeou...
    method Write (line 40) | abstract public function Write( int $Header, string $String = '' ) : b...
    method Read (line 41) | abstract public function Read( ) : Buffer;
    method ReadInternal (line 43) | protected function ReadInternal( Buffer $Buffer, callable $SherlockFun...

FILE: SourceQuery/Buffer.php
  class Buffer (line 22) | class Buffer
    method Set (line 42) | public function Set( string $Buffer ) : void
    method Remaining (line 56) | public function Remaining( ) : int
    method Read (line 66) | public function Read( int $Length = -1 ) : string
    method ReadByte (line 94) | public function ReadByte( ) : int
    method ReadInt16 (line 107) | public function ReadInt16( ) : int
    method ReadInt32 (line 127) | public function ReadInt32( ) : int
    method ReadFloat32 (line 147) | public function ReadFloat32( ) : float
    method ReadUInt32 (line 167) | public function ReadUInt32( ) : int
    method ReadNullTermString (line 187) | public function ReadNullTermString( ) : string

FILE: SourceQuery/Exception/AuthenticationException.php
  class AuthenticationException (line 17) | class AuthenticationException extends SourceQueryException

FILE: SourceQuery/Exception/InvalidArgumentException.php
  class InvalidArgumentException (line 17) | class InvalidArgumentException extends SourceQueryException

FILE: SourceQuery/Exception/InvalidPacketException.php
  class InvalidPacketException (line 17) | class InvalidPacketException extends SourceQueryException

FILE: SourceQuery/Exception/SocketException.php
  class SocketException (line 17) | class SocketException extends SourceQueryException

FILE: SourceQuery/Exception/SourceQueryException.php
  class SourceQueryException (line 17) | abstract class SourceQueryException extends \Exception

FILE: SourceQuery/GoldSourceRcon.php
  class GoldSourceRcon (line 24) | class GoldSourceRcon extends BaseRcon
    method __construct (line 34) | public function __construct( BaseSocket $Socket )
    method Close (line 39) | public function Close( ) : void
    method Open (line 45) | public function Open( ) : void
    method Write (line 50) | public function Write( int $Header, string $String = '' ) : bool
    method Read (line 66) | public function Read( ) : Buffer
    method Command (line 117) | public function Command( string $Command ) : string
    method Authorize (line 130) | public function Authorize( string $Password ) : void

FILE: SourceQuery/Socket.php
  class Socket (line 23) | class Socket extends BaseSocket
    method Close (line 25) | public function Close( ) : void
    method Open (line 35) | public function Open( string $Address, int $Port, int $Timeout, int $E...
    method Write (line 54) | public function Write( int $Header, string $String = '' ) : bool
    method Read (line 74) | public function Read( ) : Buffer
    method Sherlock (line 90) | public function Sherlock( Buffer $Buffer ) : bool

FILE: SourceQuery/SourceQuery.php
  class SourceQuery (line 25) | class SourceQuery
    method __construct (line 91) | public function __construct( ?BaseSocket $Socket = null )
    method __destruct (line 96) | public function __destruct( )
    method Connect (line 112) | public function Connect( string $Address, int $Port, int $Timeout = 3,...
    method SetUseOldGetChallengeMethod (line 133) | public function SetUseOldGetChallengeMethod( bool $Value ) : bool
    method Disconnect (line 145) | public function Disconnect( ) : void
    method Ping (line 169) | public function Ping( ) : bool
    method GetInfo (line 225) | public function GetInfo( ) : array
    method GetPlayers (line 404) | public function GetPlayers( ) : array
    method GetRules (line 449) | public function GetRules( ) : array
    method GetChallenge (line 490) | private function GetChallenge( int $Header, int $ExpectedResult ) : void
    method SetRconPassword (line 541) | public function SetRconPassword( string $Password ) : void
    method Rcon (line 588) | public function Rcon( string $Command ) : string

FILE: SourceQuery/SourceRcon.php
  class SourceRcon (line 24) | class SourceRcon extends BaseRcon
    method __construct (line 35) | public function __construct( BaseSocket $Socket )
    method Close (line 40) | public function Close( ) : void
    method Open (line 52) | public function Open( ) : void
    method Write (line 69) | public function Write( int $Header, string $String = '' ) : bool
    method Read (line 86) | public function Read( ) : Buffer
    method Command (line 134) | public function Command( string $Command ) : string
    method Authorize (line 186) | public function Authorize( string $Password ) : void

FILE: Tests/Tests.php
  class TestableSocket (line 9) | class TestableSocket extends BaseSocket
    method __construct (line 14) | public function __construct( )
    method Queue (line 21) | public function Queue( string $Data ) : void
    method Close (line 26) | public function Close( ) : void
    method Open (line 31) | public function Open( string $Address, int $Port, int $Timeout, int $E...
    method Write (line 39) | public function Write( int $Header, string $String = '' ) : bool
    method Read (line 44) | public function Read( ) : Buffer
    method Sherlock (line 54) | public function Sherlock( Buffer $Buffer ) : bool
  class Tests (line 67) | class Tests extends \PHPUnit\Framework\TestCase
    method setUp (line 72) | public function setUp() : void
    method tearDown (line 79) | public function tearDown() : void
    method testInvalidTimeout (line 86) | public function testInvalidTimeout() : void
    method testNotConnectedGetInfo (line 93) | public function testNotConnectedGetInfo() : void
    method testNotConnectedPing (line 100) | public function testNotConnectedPing() : void
    method testNotConnectedGetPlayers (line 107) | public function testNotConnectedGetPlayers() : void
    method testNotConnectedGetRules (line 114) | public function testNotConnectedGetRules() : void
    method testNotConnectedSetRconPassword (line 121) | public function testNotConnectedSetRconPassword() : void
    method testNotConnectedRcon (line 128) | public function testNotConnectedRcon() : void
    method testRconWithoutPassword (line 135) | public function testRconWithoutPassword() : void
    method testGetInfo (line 141) | #[DataProvider( 'InfoProvider' )]
    method InfoProvider (line 156) | public static function InfoProvider() : array
    method testBadGetInfo (line 179) | #[DataProvider( 'BadPacketProvider' )]
    method testBadGetChallengeViaPlayers (line 188) | #[DataProvider( 'BadPacketProvider' )]
    method testBadGetPlayersAfterCorrectChallenge (line 197) | #[DataProvider( 'BadPacketProvider' )]
    method testBadGetRulesAfterCorrectChallenge (line 207) | #[DataProvider( 'BadPacketProvider' )]
    method BadPacketProvider (line 217) | public static function BadPacketProvider( ) : array
    method testGetChallengeTwice (line 231) | public function testGetChallengeTwice( ) : void
    method testGetRules (line 242) | #[DataProvider( 'RulesProvider' )]
    method RulesProvider (line 257) | public static function RulesProvider() : array
    method testGetPlayers (line 281) | #[DataProvider( 'PlayersProvider' )]
    method PlayersProvider (line 296) | public static function PlayersProvider() : array
    method testPing (line 319) | public function testPing() : void
Condensed preview — 44 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (136K chars).
[
  {
    "path": ".editorconfig",
    "chars": 186,
    "preview": "# http://editorconfig.org\n\nroot = true\n\n[*]\ncharset = utf-8\nindent_style = tab\ninsert_final_newline = true\ntrim_trailing"
  },
  {
    "path": ".gitattributes",
    "chars": 12,
    "preview": "* text=auto\n"
  },
  {
    "path": ".github/dependabot.yml",
    "chars": 244,
    "preview": "version: 2\nupdates:\n  - package-ecosystem: \"github-actions\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n  "
  },
  {
    "path": ".github/workflows/ci.yml",
    "chars": 538,
    "preview": "name: CI\n\npermissions:\n  contents: read\n\non: [push]\n\njobs:\n  php:\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:"
  },
  {
    "path": ".gitignore",
    "chars": 30,
    "preview": "vendor/\nTests/.phpunit.cache/\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "chars": 315,
    "preview": "* **This library is intended for software developers**, if you do not know how write code in PHP, please do not create i"
  },
  {
    "path": "Examples/Example.php",
    "chars": 719,
    "preview": "<?php\ndeclare(strict_types=1);\n\nrequire __DIR__ . '/../vendor/autoload.php';\n\nuse xPaw\\SourceQuery\\SourceQuery;\n\n// For "
  },
  {
    "path": "Examples/RconExample.php",
    "chars": 713,
    "preview": "<?php\ndeclare(strict_types=1);\n\nrequire __DIR__ . '/../vendor/autoload.php';\n\nuse xPaw\\SourceQuery\\SourceQuery;\n\n// For "
  },
  {
    "path": "Examples/View.php",
    "chars": 4638,
    "preview": "<?php\n\tdeclare(strict_types=1);\n\n\trequire __DIR__ . '/../vendor/autoload.php';\n\n\tuse xPaw\\SourceQuery\\SourceQuery;\n\n\t// "
  },
  {
    "path": "LICENSE",
    "chars": 26443,
    "preview": "GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 2.1, February 1999\n\n Copyright (C) 1991, 1999 Free Soft"
  },
  {
    "path": "README.md",
    "chars": 5963,
    "preview": "# PHP Source Query\n\n[![Packagist Downloads](https://img.shields.io/packagist/dt/xpaw/php-source-query-class.svg)](https:"
  },
  {
    "path": "SourceQuery/BaseRcon.php",
    "chars": 642,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/BaseSocket.php",
    "chars": 3328,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/Buffer.php",
    "chars": 3604,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/Exception/AuthenticationException.php",
    "chars": 368,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/Exception/InvalidArgumentException.php",
    "chars": 357,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/Exception/InvalidPacketException.php",
    "chars": 468,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/Exception/SocketException.php",
    "chars": 435,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/Exception/SourceQueryException.php",
    "chars": 345,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/GoldSourceRcon.php",
    "chars": 3325,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/Socket.php",
    "chars": 2371,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "SourceQuery/SourceQuery.php",
    "chars": 15522,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * This class provides the public interface to the PHP-Source-Query library.\n *\n * @"
  },
  {
    "path": "SourceQuery/SourceRcon.php",
    "chars": 5083,
    "preview": "<?php\ndeclare(strict_types=1);\n\n/**\n * @author Pavel Djundik\n *\n * @link https://xpaw.me\n * @link https://github.com/xPa"
  },
  {
    "path": "Tests/Info/csgo.json",
    "chars": 499,
    "preview": "{\n    \"Protocol\": 17,\n    \"HostName\": \"BombGame by xPaw & Co.\",\n    \"Map\": \"de_dust2\",\n    \"ModDir\": \"csgo\",\n    \"ModDes"
  },
  {
    "path": "Tests/Info/csgo.raw",
    "chars": 299,
    "preview": "ffffffff4911426f6d6247616d652062792078506177202620436f2e0064655f6475737432006373676f00436f756e7465722d537472696b653a2047"
  },
  {
    "path": "Tests/Info/gmod_cyrillic.json",
    "chars": 469,
    "preview": "{\n    \"Protocol\": 17,\n    \"HostName\": \"Город Инноваций | Русский DarkRP\",\n    \"Map\": \"rp_bangclaw\",\n    \"ModDir\": \"garry"
  },
  {
    "path": "Tests/Info/gmod_cyrillic.raw",
    "chars": 275,
    "preview": "ffffffff4911d093d0bed180d0bed0b420d098d0bdd0bdd0bed0b2d0b0d186d0b8d0b9207c20d0a0d183d181d181d0bad0b8d0b9204461726b525000"
  },
  {
    "path": "Tests/Info/hltv.json",
    "chars": 325,
    "preview": "{\n    \"Address\": \"192.168.1.197:27020\",\n    \"HostName\": \"Castle Mortimus:0\",\n    \"Map\": \"op4_kbase\",\n    \"ModDir\": \"gear"
  },
  {
    "path": "Tests/Info/hltv.raw",
    "chars": 149,
    "preview": "ffffffff6d3139322e3136382e312e3139373a323730323000436173746c65204d6f7274696d75733a30006f70345f6b626173650067656172626f78"
  },
  {
    "path": "Tests/Info/svencoop_nonsteam.json",
    "chars": 497,
    "preview": "{\n    \"Address\": \"127.0.0.1:27015\",\n    \"HostName\": \"ClanSC #3 - Engage [Logros]\",\n    \"Map\": \"sc_doc\",\n    \"ModDir\": \"s"
  },
  {
    "path": "Tests/Info/svencoop_nonsteam.raw",
    "chars": 205,
    "preview": "ffffffff6d3132372e302e302e313a323730313500436c616e5343202333202d20456e67616765205b4c6f67726f735d0073635f646f63007376656e"
  },
  {
    "path": "Tests/Info/tf2.json",
    "chars": 641,
    "preview": "{\n    \"Protocol\": 17,\n    \"HostName\": \" FirePowered.org | Unusual Trade | !jackpot\",\n    \"Map\": \"trade_unusual_center_v3"
  },
  {
    "path": "Tests/Info/tf2.raw",
    "chars": 501,
    "preview": "ffffffff49112046697265506f77657265642e6f7267207c20556e757375616c205472616465207c20216a61636b706f740074726164655f756e7573"
  },
  {
    "path": "Tests/Info/theship.json",
    "chars": 403,
    "preview": "{\n    \"Protocol\": 7,\n    \"HostName\": \"RKSzone.com | US Chicago | The Ship | Hunt\",\n    \"Map\": \"atalanta\",\n    \"ModDir\": "
  },
  {
    "path": "Tests/Info/theship.raw",
    "chars": 187,
    "preview": "ffffffff4907524b537a6f6e652e636f6d207c205553204368696361676f207c205468652053686970207c2048756e74006174616c616e7461007368"
  },
  {
    "path": "Tests/Players/csgo.json",
    "chars": 7454,
    "preview": "[\n    {\n        \"Id\": 0,\n        \"Name\": \"Zien\",\n        \"Frags\": 0,\n        \"Time\": 11538,\n        \"TimeF\": \"03:12:18\"\n"
  },
  {
    "path": "Tests/Players/csgo.raw",
    "chars": 2628,
    "preview": "feffffffff8400000200a404ffffffff443a005a69656e0000000000d948344600efbca4efbd8fefbd86efbd86efbd9900000000007a5c0b4600e4b8"
  },
  {
    "path": "Tests/Rules/tf2_sourcemod.json",
    "chars": 9216,
    "preview": "{\n    \"anti_f2p_version\": \"2.1.0\",\n    \"backpack_tf_version\": \"2.11.1A\",\n    \"backpack_viewer_version\": \"1.1.2A\",\n    \"b"
  },
  {
    "path": "Tests/Rules/tf2_sourcemod.raw",
    "chars": 13370,
    "preview": "feffffff570100000600e004ffffffff450501616e74695f6632705f76657273696f6e00322e312e30006261636b7061636b5f74665f76657273696f"
  },
  {
    "path": "Tests/Tests.php",
    "chars": 8475,
    "preview": "<?php\ndeclare(strict_types=1);\n\n\tuse PHPUnit\\Framework\\Attributes\\DataProvider;\n\tuse xPaw\\SourceQuery\\BaseSocket;\n\tuse x"
  },
  {
    "path": "Tests/phpunit.xml",
    "chars": 453,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" colors=\"true\" xsi:"
  },
  {
    "path": "composer.json",
    "chars": 1049,
    "preview": "{\n\t\"name\": \"xpaw/php-source-query-class\",\n\t\"description\": \"PHP library to query and send RCON commands to servers based "
  },
  {
    "path": "phpstan.neon",
    "chars": 402,
    "preview": "includes:\n    - vendor/phpstan/phpstan-strict-rules/rules.neon\nparameters:\n\tcheckFunctionNameCase: true\n\tlevel: max\n\tpat"
  },
  {
    "path": "psalm.xml",
    "chars": 593,
    "preview": "<?xml version=\"1.0\"?>\n<psalm\n    errorLevel=\"1\"\n    resolveFromConfigFile=\"true\"\n    findUnusedBaselineEntry=\"true\"\n    "
  }
]

About this extraction

This page contains the full source code of the xPaw/PHP-Source-Query GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 44 files (120.8 KB), approximately 40.4k tokens, and a symbol index with 96 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!