N
N
Nark Ebavich2014-02-05 22:07:13
Django
Nark Ebavich, 2014-02-05 22:07:13

How to implement communication between Garry's Mod server and Django?

Task : Implement communication between Garry's Mod server and Django.
Description :
I am developing a portal, I want to make it as connected to the server as possible. All MySql tables are described in Django for easy work with them. Game server and Django on the same machine (Debain). Plans to add WebSocket. Garry's Mode uses LUA.
Scheme :
The player enters the game server ->
We ask Django to give us data about him (Number of kills, last visit, etc.) ->
Django looks for this player in MySql and returns the data to the game server ->
We work on the game server with with this data (We display statistics in the chat) ->
An event occurred on the server (Player killed another player) ->
We inform Django about this and pass some data (SteamID of both players) ->
Django implements some logic (Searchs in MySql for both players) ->
The result is written to MySql (Added 1 kill to the first player, 1 death to the second)
Solutions :
1) The first one which TCP immediately came to mind, but since Django synchronous had to dig towards asynchronous implementations like Twisted, Tornado, etc. As a result, I found Orbited and everything resulted in such a scheme
1391626046-clip-33kb.jpg
. It seemed to me that this is too complicated, although perhaps the most correct solution.
2) Then I remembered about Redis, but again Django is synchronous, the same scheme arises.
3) The simplest solution is to implement the Django API and call it from the game server.
It is quite possible that I am mistaken somewhere , tk. I got into all this jungle only because of this need, before that I just didn’t play much with NodeJS and, when choosing an asynchronous server, I also thought about it, but quickly dismissed it. I don't want to use too many different technologies.
Also, if you still do it using an asynchronous server, I would like to immediately fasten WebSocket there.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nark Ebavich, 2014-02-07
@Narkeba

I will try to describe the solution in more detail.
NodeJS acts as an intermediary between the server and Django. When an event occurs on the server, it sends data over TCP to NodeJS, which in turn calls a hidden Django API and sends data over WebSockets. If some event occurs in Django, it also communicates with NodeJS via TCP. This makes it possible to use the necessary functionality without rewriting the code, in addition to all this, in the event of a NodeJS crash, the site or server will not suffer much (WebSocket will not work on the site, data will not be saved on the game server, but it will still be possible to play).

N
Nark Ebavich, 2014-02-11
@Narkeba

I will add. There are ready-made implementations of sockets for Win, with Linux there was no simple solution. After long and persistent attempts to do it myself, I decided to seek help from one of the developers of garrysmod socket'ov for wines, in the end it all worked.
1) Download g1.metastruct.org:20080/modules/gmsv_luasocket_lin... drop into "garrysmod/lua/bin"
2) Open srcds_run, look for LD_LIBRARY_PATH, change to LD_LIBRARY_PATH=".:bin:garrysmod/bin"
3) Make sure that gmsv_luasocket_linux.dll has access to lua_shared_srv.so which is in "/garrysmod/bin/"
4) Copy the file code.google.com/p/gmod-haza/source/browse/trunk/PI... to "garrysmod/ lua/includes/modules/socket.lua"
5) In your script we write "require('luasocket')" and call "luasocket_stuff.luaopen_socket_core()"
6) We use)
A simple example:

require("luasocket")
luasocket_stuff.luaopen_socket_core()

local host, port = "127.0.0.1", 5000
local tcp = assert(socket.tcp())
tcp:send("hello world\n");
local line = tcp:receive('*line')
print(line)
tcp:close()

N
Nark Ebavich, 2014-02-07
@Narkeba

In general, it came down to a solution with NodeJS as a proxy between the server and django.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question