View Single Post
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