Page 1 of 2

online single player

Posted: Wed Jul 28, 2021 8:57 pm
by stepps
Can someone point me to a good tutorial or place to learn how to deal with online single player.

In other words, the main assets, code, algos are all done on the server or backend while the user mainly
just controls the player and does actions on the frontend (client). I think I saw some tutorials, but not sure
if they apply to this scenario, I think they are meant for actual multiplayer.

I just don't want the clients/users to use my algos/codes by simply looking in the archive/exe, I want to
protect at least something.

Thank you!

Re: online single player

Posted: Wed Jul 28, 2021 9:27 pm
by GVovkiv
https://love2d.org/forums/viewtopic.php?t=85955

Shortly:
There is no reason to protect code, just add to your project license, which doesn't allow to distribute your game by someone else

Re: online single player

Posted: Wed Jul 28, 2021 9:56 pm
by stepps
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!

Re: online single player

Posted: Wed Jul 28, 2021 10:18 pm
by grump
The basic concepts would be the same in both cases. You just have one player instead of many players.

You may be overestimating the ingenuity of your work if you're convinced that people will be so eager to steal it, even though you can't even figure out how to do it in the first place. You're in way over your head.

Re: online single player

Posted: Wed Jul 28, 2021 10:26 pm
by GVovkiv
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:

Code: Select all

playerX = 100
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

Re: online single player

Posted: Wed Jul 28, 2021 10:37 pm
by Gunroar:Cannon()
Woah woah woah. He just wants an anwser, no claims of superhuman coding :ultrahappy: .
I think simple enet works. It can be used with sock.lua to make things easier. Reading the tutorials at sync.lua might also help your understanding. It's simple sending and recieving of string values.

Edit: Dang it, GVovkiv beat me to it while I was typing :P

Re: online single player

Posted: Wed Jul 28, 2021 10:41 pm
by stepps
I actually appreciate all the help with sample code there and links guys! Thanks a ton! <3

Re: online single player

Posted: Wed Jul 28, 2021 10:42 pm
by togFox
I think it is effort misspent but if you insist then Google enet, Udp, Sockets.

Re: online single player

Posted: Wed Jul 28, 2021 11:06 pm
by GVovkiv
Gunroar:Cannon() wrote: Wed Jul 28, 2021 10:37 pm Woah woah woah. He just wants an anwser, no claims of superhuman coding :ultrahappy: .
I think simple enet works. It can be used with sock.lua to make things easier. Reading the tutorials at sync.lua might also help your understanding. It's simple sending and recieving of string values.

Edit: Dang it, GVovkiv beat me to it while I was typing :P
Yeah...
But it was better, if i know Engilsh so it will be easer to understand what i wrote

Re: online single player

Posted: Wed Jul 28, 2021 11:21 pm
by GVovkiv
Also, remember about rule:
"Never trust clients"