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

[NATIVE] Server Comm


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-19-2011 , 19:42   [NATIVE] Server Comm
Reply With Quote #1

Server Comm
Version 0.0.2
by Exolent



Introduction:

This idea is based on 2 or more servers sending data between each other and also making it very simple for the coders involved.
With this include, you need only 3 functions to be able to have your servers communicate however you want!


Requirements:

Engine Module
Sockets HZ Module


Sending Data:

To be able to even have data come in, someone has to send it.
Here is the first function to send data:
Code:
/*  * Sends data to a given IP  *  * @param      ip - The IP to send data to  * @param      data - The data to send  *  * @note        The port must be at the end of the IP address  * @note        To send data back to the same server, use "loopback" as the IP and no port at the end of it  *  * @return    Returns 1 on success, 0 on failure  *  */ native scomm_send(const ip[], const data[]);
Seems pretty straight-forward, right?
You send data to an IP address of the server you choose.

If you need to format the data for the send function, you don't have to format it into another variable and then send it.
Instead, you can use this function:
Code:
/*  * Sends formatted data to a given IP  *  * @param      ip - The IP to send data to  * @param      format - The format of the data  *  * @note        The port must be at the end of the IP address  * @note        To send data back to the same server, use "loopback" as the IP and no port at the end of it  *  * @return    Returns 1 on success, 0 on failure  *  */ native scomm_sendf(const ip[], const format[], any:...);
This reduces the formatting of the string to another variable and directly formats it into the send function.


Receiving Data:

To receive data from other servers, you need this forward in your plugin:
Code:
/*  * Called when the server receives data from another server  *  * @param      data - The string containing data  * @param      len - The length of the data  *  * @return    Return value is ignored  *  */ forward scomm_receive(data[], len);
That will provide you with the data that you received and the length of it.

Unfortunately, these functions cannot automatically detect the IP that the data is being sent from.
Therefore, if you want the IP to go to the receive function, you have to send the IP in the data you are sending to the server.


Notes:

The API plugin needs to be compiled with the sockets_hz.inc file attached to the bottom of this post.
Compiling locally: https://forums.alliedmods.net/showthread.php?t=130511


Be sure to set this cvar on servers running this plugin:
Code:
scomm_key "key"
The value of this cvar is used to protect the data being sent and received between servers.
If the value of this cvar does not match the value of the cvar on the server running Server Comm, then the data will be ignored.


All suggestions and comments are welcome.


Changelog:

Version 0.0.2
  • Modified to allow specific port listening and sending
  • Added "loopback" functionality to send data back to same server
Version 0.0.1
  • Original release
Attached Files
File Type: inc sockets_hz.inc (2.4 KB, 594 views)
File Type: inc server_comm.inc (1.5 KB, 720 views)
File Type: sma Get Plugin or Get Source (server_comm_api.sma - 1243 views - 4.7 KB)
File Type: sma Get Plugin or Get Source (server_comm_example.sma - 1594 views - 656 Bytes)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 02-20-2011 at 18:49. Reason: Updated to v0.0.2
Exolent[jNr] is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-19-2011 , 19:43   Re: [NATIVE] Server Comm
Reply With Quote #2

Example Plugin(s) Using Server Comm:

Cross-Server Chatting
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 02-20-2011 at 19:58.
Exolent[jNr] is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 02-19-2011 , 21:32   Re: [NATIVE] Server Comm
Reply With Quote #3

Awesome
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 02-20-2011 , 00:31   Re: [NATIVE] Server Comm
Reply With Quote #4

3x013n7 y0u 4r3 7h3 m4n
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 02-20-2011 , 15:22   Re: [NATIVE] Server Comm
Reply With Quote #5

Well what can I say this is a really nice example that shows how to use socket listen. Really neat job exolent.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 02-20-2011 , 15:54   Re: [NATIVE] Server Comm
Reply With Quote #6

This allows to send data even without a plugin, for example from php
__________________
xPaw is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 02-20-2011 , 15:58   Re: [NATIVE] Server Comm
Reply With Quote #7

Quote:
Originally Posted by xPaw View Post
This allows to send data even without a plugin, for example from php
True, but can you send info from a server to a php page?
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 02-20-2011 , 16:01   Re: [NATIVE] Server Comm
Reply With Quote #8

Quote:
Originally Posted by ot_207 View Post
True, but can you send info from a server to a php page?
You can pass your data in GET
__________________
xPaw is offline
LaineN
Veteran Member
Join Date: Mar 2008
Location: Sweden
Old 02-20-2011 , 17:22   Re: [NATIVE] Server Comm
Reply With Quote #9

What if you want to send data between servers on the same IP but on different ports?
__________________
Bollnas Team - HideNSeek

See all of Bollnas Team's HideNSeek
servers at
http://bollnasteam.se/!

LaineN is offline
mabaclu
Senior Member
Join Date: Jun 2010
Location: Portugal
Old 02-20-2011 , 17:26   Re: [NATIVE] Server Comm
Reply With Quote #10

Quote:
Originally Posted by LaineN View Post
What if you want to send data between servers on the same IP but on different ports?
x2

Nice job but please fix Linux link.

Last edited by mabaclu; 02-20-2011 at 17:32. Reason: Broken link
mabaclu 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 02:09.


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