Raised This Month: $12 Target: $400
 3% 

[ socket_recv + json/data ]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Xablau
Member
Join Date: Dec 2014
Old 01-04-2015 , 14:49   [ socket_recv + json/data ]
Reply With Quote #1

See my code:

PHP Code:
public client_connect(id)
{
    
get_player_info(id)
}
public 
get_player_info(id
{
    new 
ip[64], nick[32], steamid[32], errorsendbuffer[512]
    
get_user_ip(0,ip,63,0// IP
    
get_user_name(id,nick31// Nick
    
get_user_authid(id,steamid,31// SteamID
    
    
g_Socket socket_open("site.com"80SOCKET_TCPerror
    
    
format(sendbuffer511"GET %s HTTP/1.1^nHost:site.com^r^n^r^n""/player.php?steamid=%s&server=%s&nick=%s"steamidipnick)
    
socket_send(g_Socketsendbuffer511)
    
    
// It changed? 
    
if (socket_change(g_Socket)) 
    { 
        
// Get the data 
        
socket_recv(g_Socketg_Data999)
    }
    
socket_close(g_Socket

site.com/player.php will return a data dictionary to player.
How do I interpret this dictionary?

I need the dictionary is in json. Or have another best method?

Last edited by Xablau; 01-04-2015 at 14:50.
Xablau is offline
MetalMessiah
Junior Member
Join Date: Aug 2012
Location: Odessa
Old 01-04-2015 , 15:12   Re: [ socket_recv + json/data ]
Reply With Quote #2

There is NO json parser at AmxmodX as I know.
Use signatures, CSV or any other simple format. Or write your own JSON parser.

P.S. do it at client_putinserver(id) otherwise you will have DoS on your web server or MYSQL in case of many connections / fake player flood etc.

P.S.2 server= ?? MAybe &ip= ???
MetalMessiah is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-04-2015 , 15:16   Re: [ socket_recv + json/data ]
Reply With Quote #3

There is a JSON parser written in pure Pawn by Exolent (search), and another one written as a module by Exeorb: https://forums.alliedmods.net/showthread.php?t=244605
klippy is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-04-2015 , 15:27   Re: [ socket_recv + json/data ]
Reply With Quote #4

Can you show us an example of the returned data?
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Xablau
Member
Join Date: Dec 2014
Old 01-04-2015 , 15:32   Re: [ socket_recv + json/data ]
Reply With Quote #5

Quote:
Originally Posted by YamiKaitou View Post
Can you show us an example of the returned data?
PHP Code:
{
      
server:
      {
            
"success":true
      
},
      
player:
      {
            
"maxhp":110,
            
"hat":"squash"
      
}


Last edited by Xablau; 01-04-2015 at 15:37.
Xablau is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-04-2015 , 15:35   Re: [ socket_recv + json/data ]
Reply With Quote #6

If you don't want to write your own parser, then try using https://forums.alliedmods.net/showthread.php?t=189772
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Xablau
Member
Join Date: Dec 2014
Old 01-04-2015 , 15:38   Re: [ socket_recv + json/data ]
Reply With Quote #7

Quote:
Originally Posted by YamiKaitou View Post
If you don't want to write your own parser, then try using https://forums.alliedmods.net/showthread.php?t=189772
Tanks :}
Xablau is offline
Xablau
Member
Join Date: Dec 2014
Old 01-04-2015 , 15:39   Re: [ socket_recv + json/data ]
Reply With Quote #8

Quote:
Originally Posted by MetalMessiah View Post
There is NO json parser at AmxmodX as I know.
Use signatures, CSV or any other simple format. Or write your own JSON parser.

P.S. do it at client_putinserver(id) otherwise you will have DoS on your web server or MYSQL in case of many connections / fake player flood etc.

P.S.2 server= ?? MAybe &ip= ???
Thank U. I changed to client_putinserver
Xablau is offline
Xablau
Member
Join Date: Dec 2014
Old 01-05-2015 , 06:15   Re: [ socket_recv + json/data ]
Reply With Quote #9

PHP Code:
public client_putinserver(id)
{
    
get_data(id)
}
public 
get_data(id
{
    new 
ip[16], server[16], nick[32],steamid[32], errorsendbuffer[512]
    
get_user_ip(0,ip,63,0)
    
get_user_name(id,nick31)
    
get_user_authid(id,steamid,31)
    
    
g_Socket socket_open("site.com"80SOCKET_TCPerror
    
    
format(sendbuffer511"GET %s HTTP/1.1^nHost:site.com^r^n^r^n""/player.php?steamid=%s&ip=%s&nick=%s"steamidipnick)
    
socket_send(g_Socketsendbuffer511)
    
    const 
SIZE 63
    
new line_variable[SIZE 1], line_value[SIZE 1]
    
    if (
socket_change(g_Socket))
    {
        new 
lines[30][100], count 0
        socket_recv
(g_Socketg_Data511)
        
count ExplodeString(lines50119g_Data13)
        for(new 
i=0;i<count;i++)
        {
            
parse(lines[i], line_variableSIZEline_valueSIZE)
            if (
equal(line_variable"max_hp"))
                
set_user_health(idline_value)
            if (
equal(line_variable"max_armor"))
                
set_user_armor(idline_value)
        }   
    }
    
socket_close(g_Socket
}
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

Work on player.php, example:

"max_hp" "110"
"max_armor" "120"
"value" "data"
...

I need error:

Error: Argument type mismatch (argument 2) on line 45
Line 45:
PHP Code:
set_user_health(idline_value
How to fix?

Last edited by Xablau; 01-05-2015 at 06:22.
Xablau is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-05-2015 , 08:53   Re: [ socket_recv + json/data ]
Reply With Quote #10

Line_value should be an integer, not an array/string
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou 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 16:26.


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