27.11.2014, 13:00
(
Последний раз редактировалось n0minal; 27.11.2014 в 14:02.
)
Hmm i was looking for some way to GetServerIP without using bind method and had this idea, basically you can retrieve Server IP by sending an request for a PHP web page, its so simple to use and was made in few minutes.
Pawn Include:
PHP Source:
So now you can use the custom function RequestServerIP to ask for a ServerIP which will be returned on pubic OnHttpResponse and will format the var "serverip".
PS: The include is using a free hosting, if you want to be sure that php page will works, you can host it by yourself by creating the getip.php file, hosting it by your own and changing the URL on HTTP function:
#Pastebin for include: Download (updatedІ)
#Pastebin for PHP Page: Download
Updates:
-Added constantly checks for server ip automatically (thanks to Lordzy for suggestion).
-Added GetServerIP function which retrieves serverip on a string (thanks to Lordzy for suggestion).
-Added "Unkown" string when server can't connect to php page.
-Added strcpy method to copy HTTP Recieved data to serverip string.
Pawn Include:
Код:
#include <a_samp> #include <a_http> #define HTTP_GET_IP 10 new serverip[32]; strcpy(dest[], const source[], maxlength=sizeof dest) { strcat((dest[0] = EOS, dest), source, maxlength); } stock GetServerIP() { return serverip; } forward RequestServerIP(); public RequestServerIP() { HTTP(HTTP_GET_IP, HTTP_GET, "anticheater.honor.es/getip.php", "", "OnHttpResponse"); return 1; } forward OnHttpResponse(index, response_code, data[]); public OnHttpResponse(index, response_code, data[]) { if(response_code ^ 200) strcpy(serverip, "Unknown", sizeof(serverip)); switch(index) { case HTTP_GET_IP: strcpy(serverip, data, sizeof(serverip)); } return 1; } forward WhenGameModeInit(); public WhenGameModeInit() { return SetTimer("RequestServerIP", 3000, true); } #if defined _ALS_OnGameModeInit #undef OnGameModeInit #else #define _ALS_OnGameModeInit #endif #define OnGameModeInit WhenGameModeInit
Код:
<?php $ServerIP = $_SERVER['REMOTE_ADDR']; echo($ServerIP); ?>
PS: The include is using a free hosting, if you want to be sure that php page will works, you can host it by yourself by creating the getip.php file, hosting it by your own and changing the URL on HTTP function:
Код:
HTTP(HTTP_GET_IP, HTTP_GET, "puthereyoururl/getip.php", "", "OnHttpResponse");
#Pastebin for PHP Page: Download
Updates:
-Added constantly checks for server ip automatically (thanks to Lordzy for suggestion).
-Added GetServerIP function which retrieves serverip on a string (thanks to Lordzy for suggestion).
-Added "Unkown" string when server can't connect to php page.
-Added strcpy method to copy HTTP Recieved data to serverip string.