Connection between multiple servers

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Connection between multiple servers

Postby decompile » Fri Sep 23, 2016 10:40 pm

Hey Guys,

What are the current ways to work with an other server? Lets say I want to send a global announcement on all servers or print that player X joined server 1 in server 2.

MySQL with Delay every X seconds or even socket?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Connection between multiple servers

Postby iPlayer » Fri Sep 23, 2016 11:24 pm

Socket would be the way to go.

I'm currently working on a CCP - Custom Communication Port custom package. It will be the main dependency for MOTDPlayer package, but it suits your case perfectly.

With it, you would be able to do something like this (code on server #2):

Syntax: Select all

import json

from messages import SayText2

from ccp import RequestBasedCommunicator


@RequestBasedCommunicator('my_plugin')
def my_plugin_communicator(data):
dict_ = json.loads(data)

if dict_['action'] == "ANNOUNCE_NEW_PLAYER"
SayText2(
"Player {} has joined Server 1".format(dict_['player'])).send()

return "OK"

return "ERROR"


API for external apps (those who are connecting to the SRCDS - including other SRCDS's, too) has yet to be designed.

Either wait for CCP or make something with sockets on your own - for the sake of simply sending an announcement across servers, it should be not that difficult.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: Connection between multiple servers

Postby Doldol » Sat Sep 24, 2016 1:31 am

You could use a database, but that isn't optimal and not what a database is designed for.
Peer to peer also isn't optimal, because every server will have to keep a connection open to every other server, which is wasteful.

Best thing to do would be to have a centralized server to which all your servers connect & to design your own protocol to communicate between game server and your central server. One of the most useful advantages over using a plain db is that you can shove heavy calculations or i/o bound operations to this server, keeping your game server lag-free. Another advantage is that you also tighten the gaping security hole an open database connection on the game server is (for larger communities especially).

I like to use websockets and then communicate using JSON encoded strings, JSON & websockets (especially with modern libraries) take a lot of low-level work out of regular sockets and are supported virtually everywhere.

Personally I have this implemented using Django + Daphne on a web server and websocket-client with SourcePython on the game server.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Connection between multiple servers

Postby decompile » Sat Sep 24, 2016 11:47 am

Thank you for your responses, but im personally waiting for @iPlayer to finish CCP which sounds very interesting.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 9 guests