AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED]Socket_Send problem/question (https://forums.alliedmods.net/showthread.php?t=204209)

InfiniTy. 12-28-2012 14:34

[SOLVED]Socket_Send problem/question
 
So i have this code :

Code:

formatex( szData, charsmax( szData ), "GET /cs/page.php?n=%s HTTP/1.1^r^nHost:%s^r^nConnection: close^r^n^r^n", pName, gRedirectHost );
       
        socket_send( RedirectSocket, szData, charsmax( szData ) );

And the problem is it doesn't do nothing or something that i want.. the question is how would i corect this code in order to work ?
What i'm trying to do is this :
When the plugins starts access the link
mysite.mydomain/cs/page.php?n=ACvarName
And the rest is php which i know how to do.. also i don't know if socket_send is the thing for me or not..

LAMMPARD8_PRO 12-28-2012 15:47

Re: Socket_Send problem/question
 
AMXX Studio --> Generators --> Connection generator.
Create your connection via amxx generator.

InfiniTy. 12-28-2012 17:00

Re: Socket_Send problem/question
 
Quote:

Originally Posted by LAMMPARD8_PRO (Post 1862161)
AMXX Studio --> Generators --> Connection generator.
Create your connection via amxx generator.

I don't really .. understand the code that it makes..

LAMMPARD8_PRO 12-28-2012 17:26

Re: Socket_Send problem/question
 
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <sockets> // sockets include
#include <amxmisc>
new sckSTREAM //var socket name

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
/* Init CVars for the socket "STREAM"  */
    
if (cvar_exists("amx_STREAM_socket")) {
        
sckSTREAM get_cvar_num("amx_STREAM_socket"//value number
        
read_STREAM()
    }
    else
        
register_cvar("amx_STREAM_socket""0"FCVAR_PROTECTED&FCVAR_UNLOGGED)
    
/* up u change to readable value End */
}

/* Socket STREAM */

public connect_STREAM() { // called if you connect to ur socket connection
    
new error 0
    sckSTREAM 
socket_open("servecounterstrike.com"80SOCKET_TCPerror// the info (site, port usage, type)
    
if (sckSTREAM 0) {
        
/* Connect successful */
        
read_STREAM()
    }
    else {
        switch (
error) {
            case 
1: { /* Error creating socket */ //in cases when fails..
            
case 2: { /* Could not resolve hostname */ }
            case 
3: { /* Could not connect to given host:port */ }
        }
    }
}

public 
read_STREAM() { //called while socket is in use
    
if (socket_change(sckSTREAM100)) {
        new 
buf[512], lines[30][100], count 0
        socket_recv
(sckSTREAMbuf511)
        
count ExplodeString(lines2999buf13)
        for(new 
i=0;i<count;i++) {
            
/* Process items here  (functions etc..)*/
        
}
    }
    
    if (
sckSTREAM != 0)
        
set_task(0.5"read_STREAM")
    else {
        
set_cvar_num("amx_STREAM_socket"0)
        
disconnect_STREAM()
    }
}

public 
write_STREAM(text[512]) {
    
socket_send(sckSTREAMtext511)
}

public 
disconnect_STREAM() {
    
/* Disconnected */
}

stock ExplodeStringp_szOutput[][], p_nMaxp_nSizep_szInput[], p_szDelimiter ) { // Function by xeroblood
    
new nIdx 0strlen(p_szInput)
    new 
nLen = (copycp_szOutput[nIdx], p_nSizep_szInputp_szDelimiter ))
    while( (
nLen l) && (++nIdx p_nMax) )
        
nLen += (copycp_szOutput[nIdx], p_nSizep_szInput[nLen], p_szDelimiter ))
    return 
nIdx



LAMMPARD8_PRO 12-28-2012 17:28

Re: Socket_Send problem/question
 
you can pass in <sockets> #pragma also

YamiKaitou 12-28-2012 22:29

Re: Socket_Send problem/question
 
Quote:

Originally Posted by LAMMPARD8_PRO (Post 1862233)
you can pass in <sockets> #pragma also

Huh? What are you talking about?

LAMMPARD8_PRO 12-28-2012 22:57

Re: Socket_Send problem/question
 
Pragma Directives. but nvm.

InfiniTy. 12-29-2012 05:03

Re: Socket_Send problem/question
 
Quote:

Originally Posted by LAMMPARD8_PRO (Post 1862231)
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <sockets> // sockets include
#include <amxmisc>
new sckSTREAM //var socket name

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
/* Init CVars for the socket "STREAM"  */
    
if (cvar_exists("amx_STREAM_socket")) {
        
sckSTREAM get_cvar_num("amx_STREAM_socket"//value number
        
read_STREAM()
    }
    else
        
register_cvar("amx_STREAM_socket""0"FCVAR_PROTECTED&FCVAR_UNLOGGED)
    
/* up u change to readable value End */
}

/* Socket STREAM */

public connect_STREAM() { // called if you connect to ur socket connection
    
new error 0
    sckSTREAM 
socket_open("servecounterstrike.com"80SOCKET_TCPerror// the info (site, port usage, type)
    
if (sckSTREAM 0) {
        
/* Connect successful */
        
read_STREAM()
    }
    else {
        switch (
error) {
            case 
1: { /* Error creating socket */ //in cases when fails..
            
case 2: { /* Could not resolve hostname */ }
            case 
3: { /* Could not connect to given host:port */ }
        }
    }
}

public 
read_STREAM() { //called while socket is in use
    
if (socket_change(sckSTREAM100)) {
        new 
buf[512], lines[30][100], count 0
        socket_recv
(sckSTREAMbuf511)
        
count ExplodeString(lines2999buf13)
        for(new 
i=0;i<count;i++) {
            
/* Process items here  (functions etc..)*/
        
}
    }
    
    if (
sckSTREAM != 0)
        
set_task(0.5"read_STREAM")
    else {
        
set_cvar_num("amx_STREAM_socket"0)
        
disconnect_STREAM()
    }
}

public 
write_STREAM(text[512]) {
    
socket_send(sckSTREAMtext511)
}

public 
disconnect_STREAM() {
    
/* Disconnected */
}

stock ExplodeStringp_szOutput[][], p_nMaxp_nSizep_szInput[], p_szDelimiter ) { // Function by xeroblood
    
new nIdx 0strlen(p_szInput)
    new 
nLen = (copycp_szOutput[nIdx], p_nSizep_szInputp_szDelimiter ))
    while( (
nLen l) && (++nIdx p_nMax) )
        
nLen += (copycp_szOutput[nIdx], p_nSizep_szInput[nLen], p_szDelimiter ))
    return 
nIdx



Hm.. :-? thanks

fysiks 12-29-2012 13:42

Re: Socket_Send problem/question
 
Quote:

Originally Posted by LAMMPARD8_PRO (Post 1862407)
Pragma Directives. but nvm.

What does that have to do with SQL?

LAMMPARD8_PRO 12-29-2012 14:07

Re: [SOLVED]Socket_Send problem/question
 
i've heard that pragma can be used for optimization and making 1 include file to be only single.
It helps a lot in programs, maded by hex editor, but amxxstudio support that too.


All times are GMT -4. The time now is 13:23.

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