Coder Social home page Coder Social logo

samp-geoip's Introduction

samp-geoip

sampctl

A simple library that provides information from IPHub for connected players.

This package is built using the Requests package which is used to perform a web request to IPHub's API when a player connects.

Currently the results are not cached so you may encounter rate limits if your server has many players connecting per minute. This may be addressed in future by using Redis as a cache.

Installation

Simply install to your project:

sampctl package install Southclaws/samp-geoip

Include in your code and begin using the library:

#include <geoip>

Usage

When a player connects, their details are automatically requested. Once the response has arrived, the API can be used.

bool:IsGeoDataReady(playerid) Checks if the data is ready, requests should only take milliseconds but this ensures your code doesn't attempt to request data that isn't ready yet.

The rest of the API corresponds directly to the IPHub documentation:

  • GetPlayerCountryCode(playerid, output[], len = sizeof output)
  • GetPlayerCountryName(playerid, output[], len = sizeof output)
  • GetPlayerASN(playerid, &asn)
  • GetPlayerISP(playerid, output[], len = sizeof output)
  • GetPlayerIPBlock(playerid, &block)

There is also an event that is called when the data is available:

  • OnGeoDataReady(playerid)

Testing

To test, first you must build build the package with the file iphub_key.inc which should consist of:

#define IPHUB_KEY your_api_key

You can get a free API key from this page by clicking Looking for the free plan (2000 req/day)? Here!

Then just run as normal and connect to localhost:7777:

sampctl package run

If you connect locally, you'll see no useful data because you'll be sending the loopback interface address, but a response will still appear:

text="requesting ip data" addr="127.0.0.1" playerid=0
text="received ip data" request=0 status=200
text="determined target player for ip data" playerid=0
text="extracted ip data for player" code="ZZ" name="Unknown" asn=0 isp="Private/local IP" block=0

You can also type /ip in-game to see a message containing the data.

samp-geoip's People

Contributors

adrfranklin avatar samp-pinch avatar southclaws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

samp-geoip's Issues

Unknown include issue

mpiHNX
#include <map>

I can't seem to find any information on this include, its nowhere in any of your repositories. Is this referring to the pawn-memory mapping plugin? Although that plugin is named memory.inc

GMT Suggestion!

Hey southclaws, small suggestion here do add GetPlayerGMT function.

Output? Either as
GetPlayerGMT(playerid,Hour,Min);
or HourMin=GetPlayerGMT(playerid); (In Seconds here)

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.