Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <regex>
#include <sockets2>
#define PLUGIN "Online Map"
#define VERSION "2.5"
#define AUTHOR "Sebastian Gross"
new Regex:RegexHandle;
new Socket;
new MapName[ 32 ];
new ServIp[ 64 ];
new ServPort[ 8 ];
new ServName[ 64 ];
new BombPos[ 4 ];
new MaxPlayers;
public plugin_init() {
register_plugin( PLUGIN, VERSION, AUTHOR );
new result, errorstr[ 2 ], errorno;
RegexHandle = regex_compile( "jsonp=(.+)&_=", result, errorstr, charsmax( errorstr ), "i" );
new PlugPort = register_cvar( "sv_onlinemap", "1107" );
Socket = socket_listen( "127.0.0.1", get_pcvar_num( PlugPort ), SOCKET_TCP, errorno );
server_print( "[Online Map] Waiting for requests on port %d", get_pcvar_num( PlugPort ) );
register_event( "BombDrop", "bombDrop", "a" );
register_logevent( "remBomb", 2, "1=Round_End" );
register_logevent( "remBomb", 2, "1=Round_Start" );
register_logevent( "remBomb", 3, "2=Defused_The_Bomb" )
get_mapname( MapName, charsmax( MapName ) );
get_cvar_string( "ip", ServIp, charsmax( ServIp ) );
get_cvar_string( "port", ServPort, charsmax( ServPort ) );
get_cvar_string( "hostname", ServName, charsmax( ServName ) );
MaxPlayers = get_maxplayers();
set_task( 0.1, "OnSocketReply", .flags = "b" );
}
public plugin_end() {
socket_close( Socket );
}
public bombDrop( const player ) {
BombPos[ 0 ] = read_data( 1 );
BombPos[ 1 ] = read_data( 2 );
BombPos[ 2 ] = read_data( 3 );
BombPos[ 3 ] = read_data( 4 );
}
public remBomb(id) {
BombPos[ 3 ] = 0;
}
public OnSocketReply() {
static const requestHeader [] = "HTTP/1.1 200 OK^r^nServer: Online Map^r^nConnection: close^r^nContent-Type: text/plain^r^n^r^n";
static const requestMapHeader [] = "({^r^n^t^"bombpos^": [ ^"%d^", ^"%d^", ^"%d^", ^"%d^" ],^r^n^t^"server^": [ ^"%s^", ^"%s^", ^"%s^", ^"%d^" ],^r^n^t^"map^": ^"%s^",^r^n^t^"users^": [";
static const requestPlayerHeader [] = "^r^n^t{^r^n^t^t^"name^": ^"%s^",^r^n^t^t^"status^": [ ^"%d^", ^"%d^", ^"%d^", ^"%d^" ],^r^n^t^t^"position^": [ ^"%d^", ^"%d^", ^"%d^" ],^r^n^t^t^"angle^": [ ^"%d^", ^"%d^", ^"%d^" ],^r^n^t^t^"stats^": [ ^"%d^", ^"%d^" ]^r^n^t},^r^n";
static const requestEndHeader [] = "]^r^n})";
static request;
static accErr;
if( ( request = socket_accept( Socket, accErr ) ) > 0 ) {
static requestData[ 8192 ];
static requestRecv[ 256 ];
static length;
static result;
socket_recv( request, requestRecv, charsmax( requestRecv ) );
length = copy( requestData, charsmax( requestData ), requestHeader );
if( regex_match_c( requestRecv, RegexHandle, result ) ) {
static match[ 64 ];
regex_substr( RegexHandle, 1, match, charsmax( match ) );
length += copy( requestData[ length ] , charsmax( requestData ) - length, match );
}
length += formatex( requestData [ length ], charsmax( requestData ), requestMapHeader, BombPos[0], BombPos[1], BombPos[2], BombPos[3], ServIp, ServPort, ServName, MaxPlayers, MapName );
static playersList[ 32 ], playersCount, player;
static playerName[ 32 ];
static angles[ 3 ];
static origin[ 3 ];
static i;
get_players( playersList, playersCount );
for( i = 0; i < playersCount; i++ ) {
player = playersList[i];
get_user_name( player, playerName, charsmax( playerName ) );
get_user_origin( player, origin, 0 );
get_user_origin( player, angles, 3 );
length += formatex( requestData[ length ], charsmax( requestData ) - length, requestPlayerHeader,
playerName,
is_user_alive( player ),
cs_get_user_team( player ),
get_user_weapon( player ),
get_user_health( player ),
origin[0], origin[1], origin[2],
angles[0], angles[1], angles[2],
get_user_frags( player ),
get_user_deaths( player ) );
}
length += copy( requestData[ length ] , charsmax( requestData ) - length, requestEndHeader );
socket_recv( request, requestRecv, charsmax( requestRecv ) );
socket_send( request, requestData, length );
socket_close( request )
}
}
He has new A list of all natives.
Help me rewrite it in the Online map plugin.