Raised This Month: $62 Target: $400
 15% 

[help] sockets_hz


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 10-29-2010 , 22:44   [help] sockets_hz
Reply With Quote #1

Im not very experienced with sockets but i need to make a listener to packets from any host ip (so recieve from any ip packets). I want to filter some commands from rcon.
so what i need basically g_myAwesomeSocket = socket_listen(any host?, 27015, SOCKET_TCP, szError)
Thank you :]
__________________
okay
ARES[ro] is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-30-2010 , 01:26   Re: [help] sockets_hz
Reply With Quote #2

I modified the code of a plugin that does what you are asking to fit as an example.

Code:
#include <amxmodx> #include <engine> #include <sockets_hz> #define IP      "127.0.0.1" #define PORT            1337 #define THINK_DELAY  0.01 #define RECEIVE_DELAY      1.0 new g_socket; new g_entity; public plugin_init() {     register_plugin("Listening Socket Example", "-0.1", "Exolent");         new error;     g_socket = socket_listen(IP, PORT, SOCKET_TCP, error);         if( error )     {         switch( error )         {             case 1:    log_amx("Error creating a TCP socket to %s:%i", IP, PORT);             case 2:    log_amx("Error resolving the hostname for %s:%i", IP, PORT);             case 3:    log_amx("Error connecting a TCP socket to %s:%i", IP, PORT);         }                 return;     }         socket_unblock(g_socket);         g_entity = create_entity("info_target");         if( is_valid_ent(g_entity) )     {         entity_set_string(g_entity, EV_SZ_classname, "TCP_Socket_Reader");         entity_set_float(g_entity, EV_FL_nextthink, get_gametime() + THINK_DELAY);                 register_think("TCP_Socket_Reader", "FwdThink");     }     else     {         log_amx("Could not create TCP Socket Receiver entity.");                 plugin_end();     } } public plugin_end() {     if( g_socket > 0 )     {         socket_close(g_socket);     } } public FwdThink(entity) {     if( entity != g_entity ) return;         static socket;         if( (socket = socket_accept(g_socket)) > 0 )     {         socket_unblock(socket);                 set_task(RECEIVE_DELAY, "TaskReceiveData", socket);     }         entity_set_float(entity, EV_FL_nextthink, get_gametime() + THINK_DELAY); } public TaskReceiveData(socket) {     // socket_recv(socket, ...); }

Hope this helped.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 10-30-2010 , 14:33   Re: [help] sockets_hz
Reply With Quote #3

Wow that is the best reply ever <3
and haha using the engine think would be epic too ! thanks
__________________
okay
ARES[ro] is offline
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 10-30-2010 , 15:13   Re: [help] sockets_hz
Reply With Quote #4

yeah but how to listen all ips not just loopback?
__________________
okay
ARES[ro] is offline
issen1
Member
Join Date: Jan 2010
Old 10-30-2010 , 16:13   Re: [help] sockets_hz
Reply With Quote #5

Maybe using "0.0.0.0" as ip works.
__________________
greets (:
issen1 is offline
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 10-30-2010 , 17:41   Re: [help] sockets_hz
Reply With Quote #6

no
__________________
okay
ARES[ro] is offline
Old 10-30-2010, 21:33
ARES[ro]
This message has been deleted by Exolent[jNr]. Reason: Don't bump until 2 weeks have passed since last post.
Drak
Veteran Member
Join Date: Jul 2005
Old 10-30-2010 , 22:03   Re: [help] sockets_hz
Reply With Quote #7

Quote:
Originally Posted by ARES[ro] View Post
can really nobody help me to get packets from all ips?
Don't bump so soon. And this LISTENS on a single ip (the host) and will accept any data sent to it, aslong as it's sent properly.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 10-30-2010 , 22:37   Re: [help] sockets_hz
Reply With Quote #8

so there is no way to set up a raw socket?
also*** i know hackinzer did it in his irc plugin but i cant really understand it
__________________
okay

Last edited by ARES[ro]; 10-30-2010 at 22:54.
ARES[ro] is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-31-2010 , 00:40   Re: [help] sockets_hz
Reply With Quote #9

Don't bump until 2 weeks have passed since last post.

Quote:
Originally Posted by ARES[ro] View Post
yeah but how to listen all ips not just loopback?
That does listen for all IPs on the specified port. That code receives data, not sends.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
issen1
Member
Join Date: Jan 2010
Old 10-31-2010 , 04:56   Re: [help] sockets_hz
Reply With Quote #10

The parameter IP for socket_listen specifies the network interface to listen on. So you either pass the public ip address of your server with this param or try 0.0.0.0 which means that the socket will listen on ALL network interfaces. If you specify localhost, the server will only accept connections coming from the host system.

So IP doesn't mean which remote IPs are allowed to connect, but on which network interface the server is listening.
__________________
greets (:
issen1 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 20:54.


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