Raised This Month: $10 Target: $400
 2% 

Help with Online map and sockets2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Firuz
Member
Join Date: Dec 2014
Location: Tajikistan
Old 02-02-2020 , 18:13   Help with Online map and sockets2
Reply With Quote #1

Help with Online map and Sockets2
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 )
	}
}
Sockets2: https://forums.alliedmods.net/showthread.php?t=262924
He has new A list of all natives.
Help me rewrite it in the Online map plugin.
The last error was in the socket
When the card changed the server crashes
__________________
Firuz

Last edited by Firuz; 02-02-2020 at 18:14.
Firuz is offline
Send a message via Skype™ to Firuz
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 02-03-2020 , 13:39   Re: Help with Online map and sockets2
Reply With Quote #2

The author is still responsive in the the thread you speak of. Since the Nic card changed this crashes now? Stuff like that has a way of tracing back to the main board if it is hardware related.
__________________
"It's not the actual programming that's interesting. But it's what you can accomplish with the end results that are important." -Dennis Ritchie
"Mathematics, rightly viewed, possesses not only truth, but supreme beauty a beauty cold and austere, like that of sculpture..." -Bertrand Russell
DJEarthQuake is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:19.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode