<commit_before>srcds-tools
===
A set of tools for interacting with [Source Dedicated Server](https://developer.valvesoftware.com/wiki/Source_Dedicated_Server) in [node.js](http://nodejs.org).

Current version: v0.1.0

## Documentation

### RConClient

For issuing commands to SRCDS via the [Source RCON Protocol](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol), `srcds-tools` provides the `RConClient` type. Typical usage is as follows:

```js
var RConClient = require("srcds-tools").RConClient;

var rcon = new RConClient();

rcon.connect("127.0.0.1", 27015);

rcon.sendPassword("<PASSWORD>");

rcon.sendCommand("sv_cheats 1", function (response) {

	// Code to be executed when the server responds

});
```

#### .connect(address, port)

Establishes a TCP connection to the game server. The `port` can be passed as a second parameter, or as part of the `address` string. Once `connect()` is called, it is safe to call `sendPassword()` immediately.

```js
rcon.connect("127.0.0.1", 27015);

// or

rcon.connect("127.0.0.1:27015");
```

#### .sendPassword(password, [callback])

Sends an authentication request to the server using the given `password`. If `RConClient` is able to authenticate successfully, `callback` is invoked. If the server rejects the password, an `RConBadPasswordError` is thrown (asynchronously). The `callback` is optional, but highly advised since sending multiple commands before authenticating successfully can result in an RCON ban from the server.

```js
rcon.sendPassword("<PASSWORD>", function () {

	console.log("Authenticated successfully!");

});
```

#### .sendCommand(command, [callback])

Instructs the server to execute the specified `command`. The server's response will be passed to `callback` if it is specified. If the RCON password changes, `sendPassword()` will need to be called again or a `RConBadPasswordError` may be thrown.

```js
rcon.sendCommand("_restart", function () {

	console.log("Server is restarting...");

});
```

#### .setTimeout(duration)

Changes the maximum duration (in milliseconds) that `RConClient` will wait for a response before throwing an `RConTimeoutError`. Default is `1000` (1 second). Calling this method is usually unneccessary unless you want quicker/slower timeouts.

```js
// Future requests will time out in 1/2 second
rcon.setTimeout(500);
```

## Utilities

The `srcds-tools` module also provides a few utilites that can be used for debugging or independently of the module itself. They are located in the `util` directory.

### RConREPL

`RConCLI.js` is a simple command-line implementation of `RConClient`. To use it, simply run the file with node.

```
node ./util/RConCLI.js
```<commit_msg>Fixed one code example in the README<commit_after>srcds-tools
===
A set of tools for interacting with [Source Dedicated Server](https://developer.valvesoftware.com/wiki/Source_Dedicated_Server) in [node.js](http://nodejs.org).

Current version: v0.1.0

## Documentation

### RConClient

For issuing commands to SRCDS via the [Source RCON Protocol](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol), `srcds-tools` provides the `RConClient` type. Typical usage is as follows:

```js
var RConClient = require("srcds-tools").RConClient;

var rcon = new RConClient();

rcon.connect("127.0.0.1", 27015);

rcon.sendPassword("<PASSWORD>");

rcon.sendCommand("sv_cheats 1", function (response) {

	// Code to be executed when the server responds

});
```

#### .connect(address, port)

Establishes a TCP connection to the game server. The `port` can be passed as a second parameter, or as part of the `address` string. Once `connect()` is called, it is safe to call `sendPassword()` immediately.

```js
rcon.connect("127.0.0.1", 27015);

// or

rcon.connect("127.0.0.1:27015");
```

#### .sendPassword(password, [callback])

Sends an authentication request to the server using the given `password`. If `RConClient` is able to authenticate successfully, `callback` is invoked. If the server rejects the password, an `RConBadPasswordError` is thrown (asynchronously). The `callback` is optional, but highly advised since sending multiple commands before authenticating successfully can result in an RCON ban from the server.

```js
rcon.sendPassword("<PASSWORD>", function () {

	console.log("Authenticated successfully!");

});
```

#### .sendCommand(command, [callback])

Instructs the server to execute the specified `command`. The server's response will be passed to `callback` if it is specified. If the RCON password changes, `sendPassword()` will need to be called again or a `RConBadPasswordError` may be thrown.

```js
rcon.sendCommand("_restart", function (response) {

	console.log("Server says: " + response);

});
```

#### .setTimeout(duration)

Changes the maximum duration (in milliseconds) that `RConClient` will wait for a response before throwing an `RConTimeoutError`. Default is `1000` (1 second). Calling this method is usually unneccessary unless you want quicker/slower timeouts.

```js
// Future requests will time out in 1/2 second
rcon.setTimeout(500);
```

## Utilities

The `srcds-tools` module also provides a few utilites that can be used for debugging or independently of the module itself. They are located in the `util` directory.

### RConREPL

`RConCLI.js` is a simple command-line implementation of `RConClient`. To use it, simply run the file with node.

```
node ./util/RConCLI.js
```
{'fraction_non_alphanumeric': 0.12089331856773718, 'fraction_numerical': 0.017349575489110373, 'mean_word_length': 4.981236203090508, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '152878', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1572, 'n_words': 613}