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

Problem with sockets


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 02-06-2012 , 18:57   Problem with sockets
Reply With Quote #1

I've been using sockets_hz to transfer bans and log messages from one server to another. Now I want to use the default sockets module instead because some hosting companies don't allow uploading new modules via the game panel and also some clients who just download the plugin without reading the instructions spam me with questions why the plugin doesn't work.
But I can't get it to work now.

When you ban or unban a player, logtext and bantext are created (2 variables) which are then sent to all the servers specified in a file (gbanlist.txt). A password called gID is used to identify one network of servers.

The plugin has 2500 lines of code, these are only the functions for sending and receiving the data:

PHP Code:
#define LOKALNIPORT 1112
new posalji_socket
new gbanlog[255]

public 
plugin_end () 
    
socket_close(primi_socket)

public 
precache() {
// ...
// ...
    
new error
    primi_socket 
socket_open("127.0.0.1",LOKALNIPORT,SOCKET_UDP,error)
    if(
error 0) {
        new 
time[32]
        
get_time ("[%d.%m - %H:%M]"time31)
        new 
greska[128]
        
format(greska127"%s Greska sa otvoranjem porta za globalnu banlistu!"time
        
write_file(logfilegreska)
    }
    else
        
set_task(1.0,"primi",0,"",0,"b")
}

public 
cmd_mban(idlevelcid) {
// ...
// ...
    
format(sendtext128"%s %s -- %s -- %s -- +",minutesnameplayermID[player], mip)
    
format(gbanlog255"*%s Admin %s sa %s je banovao %s na %s minuta. Razlog: %s. ID: %s  mID: %s"timemadminservernameminutesreasonauthidplayermID[player])
    
set_task(0.3,"posalji_ban"0sendtext127)
// ...
}
public 
posalji_ban(sendtext[]) {
    if(!
get_cvar_num("amx_gban")) {
        
gbanlog[0] = 0
        
return PLUGIN_HANDLED
    
}
    new 
red 0duzina
    
new mip[32]
    new 
sendlog[256]
    new 
sendban[150]
    new 
time[32]
    new 
gID[12]
    
get_time ("[%d.%m - %H:%M]"time31)
    
get_cvar_string("setgID"gID11)
    
format(sendlog255"%s %s",gIDgbanlog)
    
format(sendban149"%s %s"gIDsendtext)
    new 
errortext[64]
    new 
error
    
while((red read_file(gbanlistfile,red,mip,31,duzina)) != ) {
        if (
duzina != 0) {
        
posalji_socketsocket_open(mip,LOKALNIPORTSOCKET_UDP,error)
        
format(errortext63"%s Greska sa slanjem bana na %s"timemip)
        switch(
error)
        {
            case 
1write_file(logfileerrortext)
            case 
2write_file(logfileerrortext)
            case 
3write_file(logfileerrortext)
        }
        
socket_send(posalji_socket,sendban,511)
        
socket_send(posalji_socket,sendlog,511)
        
socket_close(posalji_socket)
        }
    }
    
    
gbanlog[0] = 0
    write_file
("debug.txt""End^n///////////")
    return 
PLUGIN_HANDLED
}
public 
primi() {
    new 
password[32]
    new 
poruka[512]
    
get_cvar_string("setgID"password31)
    if(
socket_change(primi_socket)){
        
socket_recv(primi_socketporuka,511)
        if(
contain(porukapassword) != -1) {
            if(
delay == 1)
                return 
PLUGIN_HANDLED
            
if(contain(poruka" -- ") != -1) {
                new 
gID[9],vreme[9], text[100], text2[100]
                
strbreak(porukagID8text99)
                
strbreak(textvreme8text299)
                if(
str_to_num(vreme) > 40000)
                    
format(vreme7"40000")
                else if(
str_to_num(vreme) == 0)
                    
format(vreme7"40000")
                new 
banduritation get_cvar_num("mdb_banduritation") + str_to_num(vreme)
                new 
bantext[100]
                
format(bantext99"%s%d"text2banduritation)
                
write_file(banfilebantext)
                return 
PLUGIN_HANDLED
            
}
            if(
contain(poruka"Admin") != -1) {
                new 
gID[9], logtext[256]
                
strbreak(porukagID8logtext255)
                
write_file(logfilelogtext)
                return 
PLUGIN_HANDLED
            
}        
        }
    }
    return 
PLUGIN_HANDLED

It doesn't work. I've put debug messages on all the functions and I've noticed that the code under if(socket_change(primi_socket)) never gets executed.
With sockets_hz instead of
PHP Code:
primi_socket socket_open("127.0.0.1",LOKALNIPORT,SOCKET_UDP,error
there was
PHP Code:
primi_socket socket_listen("127.0.0.1",LOKALNIPORT,SOCKET_UDP,error)
socket_unblock(primi_socket
in the public precache() function. So I'm guessing that's the problem but I don't know how to fix it since there is no socket_listen in the default sockets module.
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-06-2012 , 21:17   Re: Problem with sockets
Reply With Quote #2

Quote:
Originally Posted by Desikac View Post
transfer bans
You can use Advanced Bans, AMXBans, or HLXBans using SQL for multiple server support.

As for the other part, you will have a much tougher workaround without having sockets_hz module.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 02-07-2012 , 05:13   Re: Problem with sockets
Reply With Quote #3

Quote:
Originally Posted by Exolent[jNr] View Post
You can use Advanced Bans, AMXBans, or HLXBans using SQL for multiple server support.
Not an option.
Quote:
Originally Posted by Exolent[jNr] View Post
As for the other part, you will have a much tougher workaround without having sockets_hz module.
Is there a plugin that does a similar thing with the default sockets module (so I can see the code)?

Last edited by Desikac; 02-07-2012 at 05:13.
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
RoaR
Member
Join Date: Dec 2011
Old 02-07-2012 , 05:29   Re: Problem with sockets
Reply With Quote #4

I didn't really understand the point. You want to transfer via sockets logfiles from one server to another?
RoaR is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 02-07-2012 , 06:54   Re: Problem with sockets
Reply With Quote #5

Quote:
Originally Posted by RoaR View Post
I didn't really understand the point. You want to transfer via sockets logfiles from one server to another?
Something like that.
One server sends a string of data to another and the second one writes it to a file.
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
RoaR
Member
Join Date: Dec 2011
Old 02-07-2012 , 07:38   Re: Problem with sockets
Reply With Quote #6

I dont think this is what you need but maybe it could help you.

https://amxmodx.org/showthread.php?p=1573388

I will still try to find a alternative way for socket_listen

Cheers.
RoaR is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 02-07-2012 , 07:48   Re: Problem with sockets
Reply With Quote #7

Quote:
Originally Posted by RoaR View Post
I dont think this is what you need but maybe it could help you.

https://amxmodx.org/showthread.php?p=1573388
Its a separate module so it can't do.
Quote:
Originally Posted by RoaR View Post
I will still try to find a alternative way for socket_listen
Thx
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
RoaR
Member
Join Date: Dec 2011
Old 02-07-2012 , 07:52   Re: Problem with sockets
Reply With Quote #8

Hmm, did you try reading this?

http://forums.alliedmods.net/showthread.php?t=151401
RoaR is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-07-2012 , 09:36   Re: Problem with sockets
Reply With Quote #9

Quote:
Originally Posted by Desikac View Post
Is there a plugin that does a similar thing with the default sockets module (so I can see the code)?
No, sockets_hz is the only method to have a listening socket.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
RoaR
Member
Join Date: Dec 2011
Old 02-07-2012 , 10:59   Re: Problem with sockets
Reply With Quote #10

Then i assume you must make a FONT big so users could notice to put the socket_hz module.
RoaR 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 12:05.


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