Raised This Month: $ Target: $400
 0% 

[Socket Read]


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-25-2010 , 08:39   Re: [Socket Read]
Reply With Quote #3

Try this

You can use this thread for reference: http://forums.alliedmods.net/showpos...06&postcount=4
PHP Code:
//added to be able to compile
//const TASK_RECV = 1234;

new bothost,botcmd[2049];
new 
socket_status[50]
 
public 
socket_init()
{
    new 
ip[64],port,erre,user[32],pass[100]
    new 
cmd[300];
    
    
get_cvar_string("cm_bot_host",ip,charsmax(ip))
    
port get_cvar_num("cm_bot_port")
    
get_cvar_string("cm_bot_user",user,charsmax(user))
    
get_cvar_string("cm_vot_pass",pass,charsmax(pass))
    
    
bothost socket_open(ip,port,SOCKET_TCP,erre)
    
    if ( 
bothost && !erre 
    {
        
server_print("Socket Reopened");
    
        
formatexcmd charsmax(cmd) , "USER asd^r^nPASS asd^r^n" )
        
socket_sendbothost cmd sizeofcmd ) )
    
        
set_task0.5 "socket_read" TASK_RECV+bothost , .flags="b" );
    }
}


public 
socket_readiTaskInfo )
{
    static 
bothost iDataRecv;
    
bothost iTaskInfo TASK_RECV;
    
    if ( 
socket_changebothost ) )
    {
        
iDataRecv socket_recvbothost botcmd charsmaxbotcmd ) );

        
//Not a good way to check if a connection was lost. Better to check when
        //the last response was recvd and if the duration exceeds X seconds, consider
        //connection timed out.
        
if ( !iDataRecv /* equal( botcmd , "" ) */ 
        {
            
server_print("[Network] Connection with Bot has been lost");
            
socket_closebothost );
            
remove_taskiTaskInfo );
            
            
socket_init();
        }
    }

__________________

Last edited by Bugsy; 11-25-2010 at 08:47.
Bugsy is offline
 



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:25.


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