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

Solved gather data from game server


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-25-2021 , 23:13   Re: gather data from game server
Reply With Quote #11

Try sockets2, I am pretty sure I made the sockets non-blocking

PHP Code:

#include <amxmodx>
#include <sockets2>

new g_Socket;

public 
plugin_init() 
{
    new 
iError;
    
g_Socket Sock_Listen"localhost" 3434 SOCKET_UDP iError );
    
    if ( 
g_Socket && !iError 
    {
        
set_task0.5 "Listen" , .flags="b" );
    }
    else
    {
        
set_fail_state"Could not create socket - Error %d" iError );
    }
}

public 
plugin_end()
{
    new 
iError;
    
Sock_Closeg_Socket iError );
}

public 
Listen()
{
    new 
iError szData32 ] , iPlayers32 ] , iNum iPlayer szBuffer256 ] , iPos;
    
    if ( 
Sock_Changeg_Socket iError ) )
    {
        
Sock_Recvg_Socket szData sizeofszData ) );
        
        if ( 
equalszData "SEND_PLAYER_LIST" ) )
        {
            
get_playersiPlayers iNum "ch" );
            for ( new 
iNum i++ )
            {
                
iPlayer iPlayers];
                if ( !( 
get_user_flagsiPlayer ) & ADMIN_USER ) )
                {
                    
iPos += get_user_nameiPlayer szBuffer charsmaxszBuffer ) - iPos );
                    
szBufferiPos++ ] = ';';
                }
            }
            
            new 
iSocket Sock_Open"localhost" 3434 SOCKET_UDP iError );
            
Sock_SendiSocket szBuffer iPos iError );
            
Sock_CloseiSocket iError );
        }
    }

Attached Files
File Type: dll sockets2_amxx.dll (97.5 KB, 39 views)
File Type: inc sockets2.inc (1.2 KB, 37 views)
__________________

Last edited by Bugsy; 06-27-2021 at 11:15.
Bugsy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-29-2021 , 17:34   Re: gather data from game server
Reply With Quote #12

I could get it working with your module, that's great. I would need the linux as well, could you share? I found this one https://forums.alliedmods.net/showpo...3&postcount=19, but Socket_SendTo is not available.

Code:
#include <amxmodx> #include <sockets2> new g_Socket public plugin_init() {     register_plugin("UDP Server", "1.0", "Crazy")     new error, g_Socket = Sock_Listen("localhost", 11000, SOCKET_UDP, error)     server_print("^tsocket is %d", g_Socket)     if (g_Socket == -1)     {         switch (error)         {             case 1: server_print("^tsocket: error while creating g_Socket")             case 2: server_print("^tsocket: couldn't resolve hostname")             case 3: server_print("^tsocket: couldn't connect")         }     }     else     {         set_task(0.5, "Listen", .flags="b")     } } public Listen() {     server_print("Waiting for data...")     new error     if (Sock_Change(g_Socket, error))     {         new buf[64], addr[96], port         Sock_RecvFrom(g_Socket, buf, sizeof buf, addr, charsmax(addr), port, error)         server_print("Receive data from %s:%d", addr, port)         copy(buf, charsmax(buf), "RESPONSE")         Sock_SendTo(addr, port, buf, strlen(buf), error)     } }
__________________








CrazY. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-29-2021 , 22:02   Re: gather data from game server
Reply With Quote #13

I'm not sure, it's odd that other natives are defined but SendTo is not.
__________________
Bugsy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-29-2021 , 22:24   Re: gather data from game server
Reply With Quote #14

After a few more tries, could get it working with the sockets_hz module. To remove the lag, I had to set the timeout parameter to 0. Thank you for the help bugsy, will do some more tests to check if I can find any other problem.

Code:
if (socket_change(g_Sock, 0))
__________________








CrazY. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-29-2021 , 22:32   Re: gather data from game server
Reply With Quote #15

Cool, no problem.

With your above code
PHP Code:
        copy(bufcharsmax(buf), "RESPONSE")
        
Sock_SendTo(addrportbufstrlen(buf), error
You should send strlen( buf ) + 1 to include the null character, or use sizeof().
__________________
Bugsy is offline
Old 06-29-2021, 23:15
CrazY.
This message has been deleted by CrazY.. Reason: nvm
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 08-09-2021 , 02:13   Re: gather data from game server
Reply With Quote #16

Why not just parse users.ini? Send to SQL.
get_players, if ( (is_user_admin(Player) && ADMIN_KICK) && STEAM_ID_EXISTS_IN_SQL) ) set his status as online.
__________________
deprale is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-17-2021 , 08:48   Re: gather data from game server
Reply With Quote #17

That won't work if your hosting doesn't allow external connections, as in my case.
__________________








CrazY. 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 11:38.


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