online single player

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

online single player

Post 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!
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: online single player

Post 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
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: online single player

Post 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!
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: online single player

Post 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.
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: online single player

Post 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
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: online single player

Post 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
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: online single player

Post by stepps »

I actually appreciate all the help with sample code there and links guys! Thanks a ton! <3
User avatar
togFox
Party member
Posts: 764
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: online single player

Post by togFox »

I think it is effort misspent but if you insist then Google enet, Udp, Sockets.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: online single player

Post 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
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: online single player

Post by GVovkiv »

Also, remember about rule:
"Never trust clients"
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 17 guests