stepps wrote: ↑Wed Jul 28, 2021 9:56 pm
Let's assume for a moment I didn't mention the part about protection, is there an answer to my actual question?
Is there a way to create a client that has basic features and gets info/assets/functions from a server? So basically
I press UP on keyboard, this is sent to server, server does processing based on what UP does in that situation and sends to
client to move character up by one.
That's literally all I am looking for. I saw something for multiplayer, but not sure it applies to this scenario. Just
wondering if anyone can guide me a bit here. Thanks!
https://www.love2d.org/wiki/socket
https://www.love2d.org/wiki/lua-enet
For assets you can serialize data and send it to user to download, for example, like in any Valve's Source game, when you connect to server with custom map, server send to user map data so they can connect and play
For multiplayer stuff, you can, on client side, generate from frame to frame table and send it to server where server checks if data is correct and after that, sending back data
For example:
On server you have x position of player:
and some other data, for example, map data:
Code: Select all
map = {obj1 = {x = 10, y = 10}, obj2 = {...}, etc
So, now, we need some client interaction
On client side, you can start generate controls data:
(in pseudo code)
Code: Select all
local xPlayer
love.update = function(dt)
local dataDromServer = deserializeData(serverGetData())
xPlayer = dataFromServer.playerX
local sendData = {}
if love.keyboard.isDown("w") then
sendData.up = true
end
sendDataToServer(serializeData(sendData))
end
So, when we sent data to server, whe want make sure, it wasn't corrupted, so we check it:
(still pseudo)
Code: Select all
local dataFromClient = deserializeData(getDataFromClient())
love.update = function(dt)
if type(dataFromClient.up) == "boolean" then
playerX = playerX + 1
end
sendDataToClient(serializeData({playerX, ..., ..., etc}))
end
So now, you have basic multiplayer
(but you should remember about: packages loss, high ping, cheating, etc, etc, which not covered in my example)
All that problems highly depends on type of your game, on server perfomance, etc
More about that you, probably, can learn from google
Just try searching: "multiplayer game code architecture"
https://www.reddit.com/r/gamedev/commen ... hitecture/
https://www.gabrielgambetta.com/client- ... cture.html