Raised This Month: $32 Target: $400
 8% 

socket_* returns Bad Request


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-19-2021 , 17:03   socket_* returns Bad Request
Reply With Quote #1

Hello,

I am trying to sending some data to a websocket, but I only receive
PHP Code:
Data received"HTTP/1.1 400 Bad Request
Server: cloudflare
Date: Tue, 19 Jan 2021 21:56:07 GMT
Content-Type: text/html
Content-Length: 155
Connection: close
CF-RAY: -

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 
I am trying access only a specific link, without .php code and get the correct <html> output.

socket sent:
PHP Code:
GET bans/%s HTTP/1.1^nHostmywebsite.com^n^
Where '%s' is the player's IP.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-20-2021 , 02:59   Re: socket_* returns Bad Request
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=282949

Code:
#include <amxmodx>
#include <amxmisc>
#include <regex>
#include <httpx>

#define PLUGIN	"CSSERVERS Vote"
#define VERSION	"2.2"
#define AUTHOR	"LondoN eXtream"

#define REGEX_STRING	"voturi-azi^">(.*?)</a>"

native zp_get_user_ammo_packs(Player);
native zp_set_user_ammo_packs(Player, Packs);

new g_CurrentVotes, g_LastVotes;
new g_PlayerID;
new g_CvarServer;
new g_MaxPlayers;

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR);

	register_clcmd("say /vote", "VoteazaServer");

	g_CvarServer = register_cvar("csservers_server", "zm.darkland.ro");
	g_MaxPlayers = get_maxplayers();

	set_task(120.0, "VerificaOnline", .flags="b");

	set_task(120.0, "PrintMessage", .flags="b");
}

public PrintMessage()	Print(0, "^x04[BONUS]^x01 Daca doresti^x03 200^x01 Ammo Packs tasteaza^x04 /vote^x01 si voteaza serverul!");

public VerificaOnline()
{
	// Stocam voturile actuale
	new Server[32], URL[256];
	get_pcvar_string(g_CvarServer, Server, charsmax(Server));
	formatex(URL, charsmax(URL), "http://www.csservers.ro/evidenta/%s", Server);
	HTTPX_Download(URL, _, _, "SalveazaVoturile");
}	

public VoteazaServer(Player)
{
	// Stocam voturile actuale
	new Server[32], URL[256];
	get_pcvar_string(g_CvarServer, Server, charsmax(Server));
	formatex(URL, charsmax(URL), "http://www.csservers.ro/evidenta/%s", Server);
	HTTPX_Download(URL, _, _, "SalveazaVoturile");

	// Afisam pagina de votare
	formatex(URL, charsmax(URL), "http://www.csservers.ro/voteaza/%s", Server);
	show_motd(Player, URL);

	// Stocam jucatorul
	g_PlayerID = Player;

	// Verificam din nou peste ceva timp
	set_task(25.0, "VerificaVoturile", Player);
}

public SalveazaVoturile(DownloadID)
{
	new g_Buffer[1024], g_Error[64], g_Votes[16], iVotes, iNum;
	new Regex:Voturi;

	while(HTTPX_GetData(g_Buffer, charsmax(g_Buffer)))
	{
		Voturi = regex_match(g_Buffer, REGEX_STRING, iNum, g_Error, charsmax(g_Error));

		if(Voturi)
		{
			regex_substr(Voturi, 1, g_Votes, charsmax(g_Votes));
			iVotes = str_to_num(g_Votes);

			g_LastVotes = iVotes;
		
			server_print("[CSSERVERS] Serverul are %d voturi", iVotes);

			regex_free(Voturi);
		}
	}
}

public VerificaVoturile(Player)
{
	new g_Server[32], URL[256];
	get_pcvar_string(g_CvarServer, g_Server, charsmax(g_Server));
	formatex(URL, charsmax(URL), "http://www.csservers.ro/evidenta/%s", g_Server);

	new DownloadID = HTTPX_Download(URL, _, _, "VoturiCurente");
	HTTPX_SetCustom(DownloadID, Player);
}

public VoturiCurente(DownloadID)
{
	new g_Buffer[1024], g_Error[64], g_Votes[16], iVotes, iNum;
	new Regex:Voturi;

	while(HTTPX_GetData(g_Buffer, charsmax(g_Buffer)))
	{
		Voturi = regex_match(g_Buffer, REGEX_STRING, iNum, g_Error, charsmax(g_Error));

		if(Voturi)
		{
			regex_substr(Voturi, 1, g_Votes, charsmax(g_Votes));
			iVotes = str_to_num(g_Votes);

			g_CurrentVotes = iVotes;

			if(g_CurrentVotes > g_LastVotes)
			{
				new Player = g_PlayerID;

				if(!(1 <= Player <= g_MaxPlayers))
					return;

				zp_set_user_ammo_packs(Player, zp_get_user_ammo_packs(Player) + 200);
				Print(Player, "^x04[CSSERVERS]^x01 Felicitari! Ai votat serverul si ai primit^x03 200^x01 Ammo Packs");
			}

			regex_free(Voturi);
		}
	}
}

stock Print(const id, const input[], any:...) {
	new count = 1, players[32];
	static msg[191];
	vformat(msg, 190, input, 3);
	
	if(id) players[0] = id;
	else get_players(players, count, "ch"); {
		for(new i = 0; i < count; i++) {
			if(is_user_connected(players)) {
				message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players);
				write_byte(players);
				write_string(msg);
				message_end();
			}
		}
	}
}
Code:
Author: LondoN eXtream (credits Bugsy, JoCanys, BlackRose from alliedmodders)
__________________
LondoN is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-20-2021 , 08:54   Re: socket_* returns Bad Request
Reply With Quote #3

Quote:
Originally Posted by LondoN View Post
https://forums.alliedmods.net/showthread.php?t=282949

Code:
#include <amxmodx>
#include <amxmisc>
#include <regex>
#include <httpx>

#define PLUGIN	"CSSERVERS Vote"
#define VERSION	"2.2"
#define AUTHOR	"LondoN eXtream"

#define REGEX_STRING	"voturi-azi^">(.*?)</a>"

native zp_get_user_ammo_packs(Player);
native zp_set_user_ammo_packs(Player, Packs);

new g_CurrentVotes, g_LastVotes;
new g_PlayerID;
new g_CvarServer;
new g_MaxPlayers;

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR);

	register_clcmd("say /vote", "VoteazaServer");

	g_CvarServer = register_cvar("csservers_server", "zm.darkland.ro");
	g_MaxPlayers = get_maxplayers();

	set_task(120.0, "VerificaOnline", .flags="b");

	set_task(120.0, "PrintMessage", .flags="b");
}

public PrintMessage()	Print(0, "^x04[BONUS]^x01 Daca doresti^x03 200^x01 Ammo Packs tasteaza^x04 /vote^x01 si voteaza serverul!");

public VerificaOnline()
{
	// Stocam voturile actuale
	new Server[32], URL[256];
	get_pcvar_string(g_CvarServer, Server, charsmax(Server));
	formatex(URL, charsmax(URL), "http://www.csservers.ro/evidenta/%s", Server);
	HTTPX_Download(URL, _, _, "SalveazaVoturile");
}	

public VoteazaServer(Player)
{
	// Stocam voturile actuale
	new Server[32], URL[256];
	get_pcvar_string(g_CvarServer, Server, charsmax(Server));
	formatex(URL, charsmax(URL), "http://www.csservers.ro/evidenta/%s", Server);
	HTTPX_Download(URL, _, _, "SalveazaVoturile");

	// Afisam pagina de votare
	formatex(URL, charsmax(URL), "http://www.csservers.ro/voteaza/%s", Server);
	show_motd(Player, URL);

	// Stocam jucatorul
	g_PlayerID = Player;

	// Verificam din nou peste ceva timp
	set_task(25.0, "VerificaVoturile", Player);
}

public SalveazaVoturile(DownloadID)
{
	new g_Buffer[1024], g_Error[64], g_Votes[16], iVotes, iNum;
	new Regex:Voturi;

	while(HTTPX_GetData(g_Buffer, charsmax(g_Buffer)))
	{
		Voturi = regex_match(g_Buffer, REGEX_STRING, iNum, g_Error, charsmax(g_Error));

		if(Voturi)
		{
			regex_substr(Voturi, 1, g_Votes, charsmax(g_Votes));
			iVotes = str_to_num(g_Votes);

			g_LastVotes = iVotes;
		
			server_print("[CSSERVERS] Serverul are %d voturi", iVotes);

			regex_free(Voturi);
		}
	}
}

public VerificaVoturile(Player)
{
	new g_Server[32], URL[256];
	get_pcvar_string(g_CvarServer, g_Server, charsmax(g_Server));
	formatex(URL, charsmax(URL), "http://www.csservers.ro/evidenta/%s", g_Server);

	new DownloadID = HTTPX_Download(URL, _, _, "VoturiCurente");
	HTTPX_SetCustom(DownloadID, Player);
}

public VoturiCurente(DownloadID)
{
	new g_Buffer[1024], g_Error[64], g_Votes[16], iVotes, iNum;
	new Regex:Voturi;

	while(HTTPX_GetData(g_Buffer, charsmax(g_Buffer)))
	{
		Voturi = regex_match(g_Buffer, REGEX_STRING, iNum, g_Error, charsmax(g_Error));

		if(Voturi)
		{
			regex_substr(Voturi, 1, g_Votes, charsmax(g_Votes));
			iVotes = str_to_num(g_Votes);

			g_CurrentVotes = iVotes;

			if(g_CurrentVotes > g_LastVotes)
			{
				new Player = g_PlayerID;

				if(!(1 <= Player <= g_MaxPlayers))
					return;

				zp_set_user_ammo_packs(Player, zp_get_user_ammo_packs(Player) + 200);
				Print(Player, "^x04[CSSERVERS]^x01 Felicitari! Ai votat serverul si ai primit^x03 200^x01 Ammo Packs");
			}

			regex_free(Voturi);
		}
	}
}

stock Print(const id, const input[], any:...) {
	new count = 1, players[32];
	static msg[191];
	vformat(msg, 190, input, 3);
	
	if(id) players[0] = id;
	else get_players(players, count, "ch"); {
		for(new i = 0; i < count; i++) {
			if(is_user_connected(players)) {
				message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players);
				write_byte(players);
				write_string(msg);
				message_end();
			}
		}
	}
}
Code:
Author: LondoN eXtream (credits Bugsy, JoCanys, BlackRose from alliedmodders)
This not respond to my question, and I don't wanna use httpx because it may waste some memory, and I don't need too much data from socket's return.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-20-2021 , 21:16   Re: socket_* returns Bad Request
Reply With Quote #4

Have you tested this website by manually going to the URL with an IP at the end?

http://mywebsite.com/bans/123.45.67.89

If it works, you may need to pass it differently. Check to see how your browser sends/receives it.
__________________
Bugsy is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-21-2021 , 02:08   Re: socket_* returns Bad Request
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Have you tested this website by manually going to the URL with an IP at the end?

http://mywebsite.com/bans/123.45.67.89

If it works, you may need to pass it differently. Check to see how your browser sends/receives it.
Yes, I've tested and it works properly. How can I check my browser's data?
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-21-2021 , 08:10   Re: socket_* returns Bad Request
Reply With Quote #6

Google it.. "how to see http packets in [browser name]"
__________________
Bugsy is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 01-21-2021 , 11:00   Re: socket_* returns Bad Request
Reply With Quote #7

bans/%s
->
/bans/%s
__________________
Black Rose is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-22-2021 , 03:32   Re: socket_* returns Bad Request
Reply With Quote #8

Quote:
Originally Posted by Black Rose View Post
bans/%s
->
/bans/%s
Thanks, but it doesn't solved it.

I thought I make a mistake somewhere, so I tried this code from a tutorial:
PHP Code:
#include <amxmodx>
#include <sockets>

// The info about the plugin, we will use the VERSION define for coparison.
#define PLUGIN    "BW Version Checker"
#define AUTHOR    "OT"
#define VERSION    "8.0"

// Host and topics
#define PLUGIN_TOPIC                "/showthread.php?t=100886"
#define PLUGIN_HOST                    "forums.alliedmods.net"

// Tasks
#define TASKID_GETANSWER            0
#define TASKID_CLOSECONNECTION        1

// The socket handle
new g_Socket

// Data buffer
new g_Data[1000]
// Version string buffer
new g_StringVersion[10]

// Needed to update the plugin?
new bool:g_NeedToUpdate

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}
public 
plugin_cfg()
{
    
// Connect
    
new errorsendbuffer[512]
    
g_Socket socket_open(PLUGIN_HOST80SOCKET_TCPerror)
 
    
// If we get error
    
switch (error)
    {
        case 
1:
        {
            
log_amx("[BW Version Checker] Unable to create socket.")
            return
        }
        case 
2:
        {
            
log_amx("[BW Version Checker] Unable to connect to hostname.")
            return
        }
        case 
3:
        {
            
log_amx("[BW Version Checker] Unable to connect to the HTTP port.")
            return
        }
    }
    
    
log_amx("[BW Version Checker] Connection with %s has been established"PLUGIN_HOST)
    
    
// Send page request
    
format(sendbuffer511"GET %s HTTP/1.1^nHost:%s^r^n^r^n"PLUGIN_TOPICPLUGIN_HOST)
    
socket_send(g_Socketsendbuffer511)
    
    
log_amx("[BW Version Checker] Sending Block Wallhack page request.")
    
    
// Setting the tasks for handeling the response
    
set_task(1.0"task_waitanswer"TASKID_GETANSWER""0"a"15)
    
set_task(16.0"task_closeconnection"TASKID_CLOSECONNECTION""0""0)
}

public 
task_waitanswer(id)
{
    
// It changed?
    
if (socket_change(g_Socket))
    {
        
// Get the data
        
socket_recv(g_Socketg_Data999)
        
        
// We seach for the title
        
new Position containi(g_Data"Block Wallhack v")
        
        
// Title found
        
if (Position >= 0)
        {
            
log_amx("[BW Version Checker] Page found, comparing versions.")
            
            
// Now we start processing the buffer
            
            // We get the start of the numbers of the version
            
Position += strlen("Block Wallhack v")
            
            new 
length
            
            
// We copy the valid version characters in another string
            
for (new i=0;i<10;i++)
            {
                if (
'0' <= g_Data[Position i] <= '9' || g_Data[Position i] == '.')
                {
                    
g_StringVersion[length] = g_Data[Position i]
                    
length++
                }
            }
            
            
// Compare the plugin version with the internet version
            
g_NeedToUpdate = (str_to_float(g_StringVersion) > str_to_float(VERSION))
            
            
log_amx("[BW Version Checker] Versions has been compared, closing connection. %s!"g_NeedToUpdate "Plugin is old" "Plugin is updated")
            
            
// Close the connection
            
socket_close(g_Socket)
            
            
// Remove the tasks
            
remove_task(TASKID_GETANSWER)
            
remove_task(TASKID_CLOSECONNECTION)
        }
    }
}

public 
task_closeconnection(id)
{
    
// Close connection if no response in 16 seconds.
    
socket_close(g_Socket)

This code as well returns me Bad request, with same HTML error code.
https://forums.alliedmods.net/showthread.php?t=151401
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-22-2021 , 05:03   Re: socket_* returns Bad Request
Reply With Quote #9

Can you tell us what's the purpose of the plugin?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-22-2021 , 08:05   Re: socket_* returns Bad Request
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
Can you tell us what's the purpose of the plugin?
It should open a socket connection and send player's IP through it.
But how did I said upper:

Quote:
Originally Posted by Shadows Adi View Post
This code as well returns me Bad request, with same HTML error code.
https://forums.alliedmods.net/showthread.php?t=151401
This code should connect to alliedmods.net forums and get topic's title, but it returns 'Bad Request'
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Reply



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 17:37.


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