npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bf4rcon

v1.0.1

Published

BF4 Rcon in pure JavaScript

Downloads

1

Readme

skuIIs/bf-rcon

GitHub release (latest SemVer) GitHub top language npm bundle size (scoped) GitHub Sponsors GitHub

BF4 RCon in pure JavaScript

Installation

You can use npm or yarn to install this package into your project

npm install bf4rcon
yarn add bf4rcon

Usage

const { BFrcon } = require('bf4rcon')

async function init () {
  const rcon = new BFrcon()

  // Connects to server(s), can be an object or an array of objects

  // *** Example for a single server ***
  const server = await rcon.connect({
    host: '127.0.0.1',
    port: 47200,
    password: 'password'
  })

  server.on('ready', async function () {
    console.log('Server: ' + this.server_id + ' added to listener!')

    // Run some command
    const players = await this.listPlayers()
    console.log(players)

    // Listen for some event
    this.on('player.onAuthenticated', function (player) {
      console.log(player)
    })
  }.bind(server))

  // *** Example for a multiple servers ***
  const servers = await rcon.connect([
    {
      host: '127.0.0.1',
      port: 47200,
      password: 'password'
    },
    {
      host: '127.0.0.1',
      port: 47201,
      password: 'password'
    },
  ])

  for (var i = 0, len = servers.length; i < len; i++) {
    servers[i].on('ready', async function () {
      console.log('Server: ' + this.server_id + ' added to listener!')

      // Run some command
      const players = await this.listPlayers()
      console.log(players)

      // Listen for some event
      this.on('player.onAuthenticated', function (player) {
        console.log(player)
      })
    }.bind(servers[i]))
  }
}

init()

Commands

After connecting to a server(s) you can use the exec function to execute a command, or use the built-in API for commands made with promises. See ./services/commands/* for available commands.

...
  this.exec('serverInfo', function (error, response) {
    if (error) return reject(error)
    // Do something with response. Note here you must parse things yourself!
  })
...

Is the same as:

...
  const info = await this.serverInfo()
  // Already parsed for you!
  console.log(info)
...

Events

Listen for events from the server is simple. After connecting to the server(s) just use a standard on listener.

  this.on('player.onChat', function (chat) {
    console.log(chat)
  })

Caveats

  • This has only been tested for BF4. This could work for BF3 or BFH.

  • This package is meant for long-running processes and also doesn't handle reconnecting after disconnects or errors. You must handle those on your own. Example:

  const config = {
    host: '127.0.0.1',
    port: 47200,
    password: 'password'
  }

  // Initial connection
  const server = await rcon.connect(config)

  server.on('ready', async function () {
    // Code
  }.bind(server))

  // Socket connection was ended
  server.on('end', function () {
    // Reconnect!
    server = await rcon.connect(config)
  })
  • If you want to issue a command on a server and exit then it can be done, you just have to connect, issue the command after the connection is ready, and then manually disconnect. Example:
  const server = await rcon.connect({
    host: '127.0.0.1',
    port: 47200,
    password: 'password'
  })

  server.on('ready', async function () {

    // Run some command
    const players = await this.listPlayers()
    console.log(players)

    // Disconnect
    this.disconnect()
  }.bind(server))

Modules

Classes

Geo

Geo Helper module

module.exports(ip) ⇒ String | Null

Get the country from an IP address

Kind: Exported function
Returns: String | Null - returns a string of the country if found or null
Throws:

  • TypeError throws if ip is not a string

| Param | Type | Description | | --- | --- | --- | | ip | String | IP address to lookup |

Map

Map Helper module

module.exports(map) ⇒ String | Null

Converts rcon map to full map string

Kind: Exported function
Returns: String | Null - returns full map string or null if not found
Throws:

  • TypeError throws if map is not a string

| Param | Type | Description | | --- | --- | --- | | map | String | rcon map to convert |

Mode

Mode Helper module

module.exports(mode) ⇒ String | Null

Converts rcon mode to full mode string

Kind: Exported function
Returns: String | Null - returns full mode string or null if not found
Throws:

  • TypeError throws if mode is not a string

| Param | Type | Description | | --- | --- | --- | | mode | String | rcon mode to convert |

Weapon

Weapon Helper module

module.exports(weapon) ⇒ Object.<WeaponObject> | Null

Converts rcon weapon to full weapon object

Kind: Exported function
Returns: Object.<WeaponObject> | Null - returns full weapon object or null if not found
Throws:

  • TypeError throws if weapon is not a string

| Param | Type | Description | | --- | --- | --- | | weapon | String | rcon mode to convert |

module.exports~WeaponObject : Object

Kind: inner typedef of module.exports
Properties

| Name | Type | Description | | --- | --- | --- | | weapon_key | String | | | type | String | [primary, secondary, auxiliary] | | kit | String | [assault, engineer, support, recon, none] | | group | String | [suicide, melee, impact, nonlethal, assaultrifle, carbine, smg, lmg, shotgun, dmr, sniperrifle, handgun, explosive, projectileexplosive, vehiclepersonal, vehicletransport, vehiclestationary, vehiclelight, vehicleheavy, vehicleair, vehiclewater, none] |

BFRcon

BFRcon class

Kind: global class

bfRcon.connect(servers) ⇒ Object

Connects to server(s)

Kind: instance method of BFRcon

| Param | Type | Description | | --- | --- | --- | | servers | Array | Object | an array of servers or a single server to connect to |

bfRcon.exec(command, callback)

Executes a command

Kind: instance method of BFRcon

| Param | Type | Description | | --- | --- | --- | | command | String | command to execute | | callback | function | callback |

"player.onAuthenticated" ⇒ Object

Player authenticated event

Kind: event emitted by BFRcon
Returns: Object - {event: String, name: String, refresh: Boolean}

"player.onJoin" ⇒ Object

Player join event

Kind: event emitted by BFRcon
Returns: Object - {event: String, name: String, guid: String, refresh: Boolean}

"player.onLeave" ⇒ Object

Player leave event

Kind: event emitted by BFRcon
Returns: Object - {event: String, name: String, info: String, refresh: Boolean}

"player.onDisconnect" ⇒ Object

Player disconnect event

Kind: event emitted by BFRcon
Returns: Object - {event: String, name: String, refresh: Boolean}

"player.onSpawn" ⇒ Object

Player spawn event

Kind: event emitted by BFRcon
Returns: Object - {event: String, name: String, team: Number, refresh: Boolean}

"player.onKill" ⇒ Object

Player kill event

Kind: event emitted by BFRcon
Returns: Object - {event: String, name: String, victim: String, weapon: {weapon_key: String, type: String, kit: String, group: String}, headshot: Boolean, refresh: Boolean}

"player.onChat" ⇒ Object

Player chat event

Kind: event emitted by BFRcon
Returns: Object - {event: String, name: String, text: String, subset: String, refresh: Boolean}

"player.onSquadChange" ⇒ Object

Player squad change event

Kind: event emitted by BFRcon
Returns: Object - {event: String, name: String, team: Number, squad: Number, refresh: Boolean}

"player.onTeamChange" ⇒ Object

Player team change event

Kind: event emitted by BFRcon
Returns: Object - {event: String, name: String, team: Number, squad: Number, refresh: Boolean}

"server.onMaxPlayerCountChange" ⇒ Object

Server max player count change event

Kind: event emitted by BFRcon
Returns: Object - {event: String, count: Number, refresh: Boolean}

"server.onLevelLoaded" ⇒ Object

Server level loaded event

Kind: event emitted by BFRcon
Returns: Object - {event: String, level: String, mode: String, played: Number, total: Number, refresh: Boolean}

"server.onRoundOver" ⇒ Object

Server round over event

Kind: event emitted by BFRcon
Returns: Object - {event: String, winner: Number, refresh: Boolean}

"server.onRoundOverPlayers" ⇒ Object

Server round over players event

Kind: event emitted by BFRcon
Returns: Object - {event: String, players: Array, refresh: Boolean}

"server.onRoundOverTeamScores" ⇒ Object

Server round over team scores event

Kind: event emitted by BFRcon
Returns: Object - {event: String, scores: Array, refresh: Boolean}

"punkbuster.onComputed" ⇒ Object

Server punkbuster computed event

Kind: event emitted by BFRcon
Returns: Object - {event: String, message: String, name: String, guid: String, ip: String, country: String, refresh: Boolean}

"punkbuster.onViolation" ⇒ Object

Server punkbuster violation event

Kind: event emitted by BFRcon
Returns: Object - {event: String, message: String, name: String, guid: String, ip: String, country: String, type: String, number: Number, refresh: Boolean}

Contributing

Pull requests are welcome for bug fixes or feature requests.

Sponsors

Support this project and possibly other open-source projects by becoming a sponsor. Higher tier sponsor will appear here with a logo and link to your website. Become a sponsor

License

MIT