[Include] SA:MP IsUp Tool - API
#1

Greetings,

A while back I made an IsUp tool for SA:MP servers. Now I am introducting a beta SA:MP IsUp API. Its not perfect, and may have bugs as I tested it as fast as I could without totally screwing everything up.

It isn't the easiest to use; how-ever it shouldn't be that hard either. It has a few key functions which can be found below:

pawn Код:
public LoadServerInformation(ip[], port);
pawn Код:
stock IsServerOnline(index);
pawn Код:
stock ReleaseIndex(index);
You first have to load the server information using LoadServerInformation. Then; you'll have to use a timer or another method of waiting. I'd recommend waiting around 2 seconds, how-ever it may need a longer time depending on the ping it gets to the site. Then you'll use IsServerOnline which returns either true or false. Ofcourse, if online true is returned.

And don't forget to use ReleaseIndex when you're done using it.

Heres an example FS:
pawn Код:
#include <a_samp>
#include <serverdata>

public OnFilterScriptInit()
{
    new index = LoadServerInformation("server.ls-rp.com", 7777);
    return 1;
}

forward ServerIP_Process(index);
public ServerIP_Process(index)
{
    new bool: isonline = IsServerOnline(index);
    if(isonline == true)
    {
        print("server.ls-rp.com:7777 is online!");
    }
    else
    {
        print("server.ls-rp.com:7777 is not online!");
    }
    ReleaseIndex(index);
    return 1;
}
Direct Call Method example:
pawn Код:
#include <a_samp>
#include <serverdata>

public OnFilterScriptInit()
{
    new index = LoadServerInformation("server.ls-rp.com", 7777);
    return 1;
}

public ServerInformation_OnResponse(index, bool: IsOnline)
{
    if(IsOnline)
    {
        print("server.ls-rp.com:7777 is online!");
    }
    else
    {
        print("server.ls-rp.com:7777 is not online!");
    }
    ReleaseIndex(index);
}
Well; here it is!
DOWNLOAD - VIEW IN BROWSER
DOWNLOAD - DIRECT DOWNLOAD

DOWNLOAD - VIEW IN BROWSER(VERSION 2)

Thanks.
Reply
#2

The funny part is that you make profit of it.
Reply
#3

The API doesn't have any sort of ads; and currently I haven't even set up the ad payment yet; so I am actually making nothing at the moment.
Reply
#4

Using random values to check a free slot is not efficient, it could slow down if majority of the randomized values are used. Although random function on PAWN seeds randomized numbers, it's better to either loop and check for a free slot or use a variable to toggle next free slot.

To get the result soon as the data is received, you could've hooked "ServerInformation_Response". Lastly, I'm warning you about declaring arrays or enumerators without include prefixes. It could simply create conflicts, also, consider using static global arrays.
Reply
#5

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
Using random values to check a free slot is not efficient, it could slow down if majority of the randomized values are used. Although random function on PAWN seeds randomized numbers, it's better to either loop and check for a free slot or use a variable to toggle next free slot.

To get the result soon as the data is received, you could've hooked "ServerInformation_Response". Lastly, I'm warning you about declaring arrays or enumerators without include prefixes. It could simply create conflicts, also, consider using static global arrays.
I prefixed most; I remember you giving me this tip on one of my last includes I've done. And how would you suggest hooking ServerInformation_Response? Thanks!
Reply
#6

Quote:
Originally Posted by Abagail
Посмотреть сообщение
I prefixed most; I remember you giving me this tip on one of my last includes I've done. And how would you suggest hooking ServerInformation_Response? Thanks!
Just by hooking them like any other callbacks, but you might need an additional array to store the searched server name.

pawn Код:
forward ServerInformation_Response(index, response_code, data[]);
public ServerInformation_Response(index, response_code, data[])
{
    if(response_code == 200)
    {
        if(strcmp(data, "Online", true) == 0)
        {
            ServerData[index][s_iOnline] = true;
            return true;
        }
        else
        {
            ServerData[index][s_iOnline] = false;
        }
        printf("%s", data);
    }
    else printf("Unable to load server data(response code returned %d)", response_code);
    #if defined iUServerInformation_Response
        return iUServerInformation_Response(index, response_code, data);
    #else
        return 1;
    #endif
}

#if defined _ALS_ServerInformation_Response
    #undef ServerInformation_Response
#else
    #define _ALS_ServerInformation_Response
#endif

#define ServerInformation_Response iUServerInformation_Response

#if defined iUServerInformation_Response
forward iUServerInformation_Response(index, response_code, data[]);
#endif

//So then, once if the data is received, they can check like:
public ServerInformation_Response(index, response_code, data[])
{
    if(IsServerOnline(index))
    {
        print("It's online!");
    }
    else
        print("It's not!");
    }
    return 1;
}
Or else another tip is that you can use CallLocalFunction as soon as the data is received, with additional parameters to check if the data is received or not. Mostly like the way zcmd handles.
Reply
#7

I am amazed at how fast it is when directly calling the function, so I have added a second version. It also has the following new functions:

pawn Код:
stock GetServerIPFromIndex(index)
- Returns as a string.
pawn Код:
stock GetServerPortFromIndex(index)
- Returns as an integer.

I have added a second example FS for the second version.
Reply
#8



Do you even isset()?
Reply
#9

Not really; the webpage isn't meant for direct access; and if your going to provide a bad IP/port(or even none at all) the server will return offline like it should; so thats for me not an issue.
Reply
#10

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Not really; the webpage isn't meant for direct access; and if your going to provide a bad IP/port(or even none at all) the server will return offline like it should; so thats for me not an issue.
Still not an excuse for writing poor code.
Reply
#11

It's not "poor" code; the webpage isn't meant for any direct access, and frankly I don't care if it's poor or not it works exactly like it should.

But anyways, I've added a check.
Reply
#12

Quote:
Originally Posted by Abagail
Посмотреть сообщение
But anyways, I've added a check.
Parse error: syntax error, unexpected ']' in C:\xampp\htdocs\isup\api\index.php on line 2
Reply
#13

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
Parse error: syntax error, unexpected ']' in C:\xampp\htdocs\isup\api\index.php on line 2
Should be fixed now...
Reply
#14

I have moved hosts, and that being said you'll need to either download it again(from the same URL / link), or change the IP to 167.114.113.66.

It will NOT work if you don't change the IP address!
Reply
#15

I'm not quite sure what this does. But good job anyways.
Reply
#16

Quote:
Originally Posted by ViperAssasin11
Посмотреть сообщение
I'm not quite sure what this does. But good job anyways.
Its an API for my isup tool. It allows you to get a servers status within PAWN / in a SAMP server.
Reply
#17

What are we to do if your API were to suddenly go down?
Reply
#18

If I was unable to maintain the API / site, I'd release the source code how-ever as of now I have two hosts with it up, and running just in-case.

Feel free to private message me if it goes down and I'll get it fixed ASAP.
Reply
#19

Quote:
Originally Posted by Ryan_Bowe
Посмотреть сообщение
What are we to do if your API were to suddenly go down?
Quick somebody make an api to monitor the api!


But on topic.. Seems like a neat idea. I personally don't think many would use this unless they would have a gaming community with multiple servers and they would like to show status's of all their servers, on each server.

And as for not wanting direct access to the api i am sure you could look into http headers as i am fairly certain the samp server has a different header compared to regular browsers. Just tested myself....
Код:
[07/Jan/2015:18:27:32 +0000] "HEAD /test/test.php HTTP/1.1" 200 "http://sa-mp.com" "SAMP/0.3" "192.***.**.***"
That's what is shown in my access log. So you can get this same info in php and use it to only allow access with requests containing certain things like SAMP/0.3

Also audio streams for clients show the same except the ip is the users ip.
Reply
#20

I am not too concerned about it being directly accessed, used for things other than SA:MP. It is an API that very well could be re'purposed to be used with something such as PHP.

All it does is say if it's online; or not so I probably as of now won't restrict access to SA:MP servers. Thanks anyway!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)