Giter Site home page Giter Site logo

samphook's Introduction

# Node.js SA-MP Server Query

This Node.js module allows you to query SA-MP (San Andreas Multiplayer) game servers to retrieve information about players and server details. It includes the following files:

## Files

### `request.js`

This file contains a function for sending SA-MP server queries using UDP. It takes an IP address, port, and an opcode as parameters to query the server. The available opcodes are:

- `'i'`: Retrieve server information.
- `'r'`: Retrieve server rules.
- `'d'`: Retrieve player list.

### `sa-mp.js`

This file provides three functions for querying SA-MP servers:

1. `async function listPlayer(ip, port)`: Queries the server for the list of players and returns an array of player objects or a failed status if there are no players or an error occurs.

2. `async function serverInformation(ip, port)`: Queries the server for general server information and returns an object containing server details.

3. `async function sampServers(ip, port, method)`: Combines the above two functions to query either player list or server information based on the specified method. It returns the respective data or an error if one occurs.

## Usage

1. Import the module:
   ```javascript
   const { sampServers } = require('./sa-mp');
  1. Use the functions to query SA-MP servers using async/await:

    try {
      const players = await sampServers('server-ip', server-port, 'player');
      console.log('Player list:', players);
    } catch (error) {
      console.error('Error:', error);
    }
    try {
      const serverInfo = await sampServers('server-ip', server-port, 'info');
      console.log('Server information:', serverInfo);
    } catch (error) {
      console.error('Error:', error);
    }

Dependencies

This module uses the dgram module for UDP communication.

Credit

Simplified Query API for SAMP. Original JJJ4n's repo

samphook's People

Contributors

jjj4n avatar muhraihan001 avatar derekmartinez18 avatar kaperstone avatar christianrank avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.