Getting started with multiplayer

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.
Post Reply
feelixe
Prole
Posts: 36
Joined: Tue Aug 20, 2013 10:29 am

Getting started with multiplayer

Post by feelixe »

Hey! I'm want to implement multiplayer in a game that i'm making and just have some questions.
First of all I'm just wondering if I've understood how it works right. My understanding is that every client send all nececery info to the server (positions etc.) and then the server sends out all changes to every client. Is that a correct describtion?

And is the server the kind of server that you just open on your computer and open a port or is it the kind where I (the maker of the game) hosts a server for everyone?

If you have any good links that will help it be very grateful.

Thanks in advance. //Feelixe
khamarr3524
Prole
Posts: 41
Joined: Thu Sep 05, 2013 8:48 pm

Re: Getting started with multiplayer

Post by khamarr3524 »

Check out http://love2d.org/wiki/LUBE
It's maintained by bartbes and it makes the whole process easier.

I recommend doing some research on the process of updating information, I don't have too much information on, sorry, hopefully someone else can fill that in for you.
feelixe
Prole
Posts: 36
Joined: Tue Aug 20, 2013 10:29 am

Re: Getting started with multiplayer

Post by feelixe »

I've got i working now!!
But I have another question, how much info is acceptabel to send over udp?
Say i have a table with enemies ex.

Code: Select all

Enemies = {
one{hp=1 etc. }
two{hp=1 etc. }
three{ hp=1 etc.
}
etc.
}
To send this whole table over udp like 5 times a second would cause crazy lag i belive, am I right?

So the solution I though of was to only send changes in the table. But then I though the might get out of sync (The server table and client table)?
So anyone with some expreince that could help me abit? :)
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Getting started with multiplayer

Post by Positive07 »

For multiplayer I recommend lua-enet, for your second problem, yes, you are right is a bad idea.

Usually when one makes a server and a client, client NEVER executes actions... instead clients pass the user actions to the server and the server executes them modifying the world enemy and such, then the newly updated information gets passed to the client.

This means that the server creates a World, with enemies the player position and such, then all the information is sent to the client.
The player moves, attack or something, the client sends the info to the server, the server updates the world, enemies and the character, it calculates damage, new positions and such and then sends all the new data over.

You just need to send the updates on the points, health and new position of the character, changes on the map if any, movement and disappearance (like dieing) of enemy but just the ones that are near the player, appearance of new enemy (spawn, walking from the side, due to player movement)... And that is, if you need something else then pass it too, just don't pass the whole World 'cause it would take ages, try to minimize the data as much as possible
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
feelixe
Prole
Posts: 36
Joined: Tue Aug 20, 2013 10:29 am

Re: Getting started with multiplayer

Post by feelixe »

Thanks for the reply! I've started over so it's done correctly.
But there's one thing I don't understand.
When using lube, you send a keypress for example. Then Lube will give that keypress an Id so it knows who it is from.
Then I use keypress in the server and the player data is returned.
The problem I have is that there's no ID when returning data so I can't compare anything to see if it's a specific clients player.

Thanks for repsone, hope you understand :)
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Getting started with multiplayer

Post by Positive07 »

Mmm I would give the client the same ID, and send just that client data to that client

For example Client connects to Server, Server assigns Id = 1 to this client, other client connects, it gets assigned id = 2.
Client 1 sends data to server, data is assigned Id = 1 (since its from client 1) Client 2 sends data, data gets id = 2
Calculate everything, send data that correspond to Id = 1 to client 1, send data with id = 2 to client 2

Is this what you meant?
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

Re: Getting started with multiplayer

Post by zell2002 »

*note * no code to hand, and havent looked at what i did for ages, and not sure if this is an over kill approach ...

you may want to look into how other games handle this stuff
replication, prediction etc..

i used LUBE and a lot of readings.

i did it by having the Server holding the game state, and each client having their own but server is boss.
the client only sent up player Position, Rotation and any Command

the server would then take all this and process the stuff server side (physics etc..), then send the new game state to each client, including their Locations, Rotations, and Commands (for each of their local players to perform)

i followed a bit from unreal's approach, so i had a Pawn and Controller/AiController class. the AiController class was inherited and modified from Controller.
so for each player that joins, it spawns a Pawn and an AiController, with a network id to reference for each client.
the AiController took it's commands from the Server for things like : fire etc..
the Pawn's location and rotation would update from the server directly

Code: Select all

-- client receives data from server
for _, data in pairs(server_data) do
	-- loop all my local pawns
	for i, player in pairs(Game_Pawns) do	
		
		-- find correct pawn/player to update
		if player.network_id = data.pId then
			player:UpdateLocation(data.loc)
			player:UpdateRotation(data.rot)
			
			-- commands
			if data.com ~= nil then
				for _, command in pairs(data.com) do
					player.Controller[command.name](command.params)
				end
			end
		end
	end
end
also to keep everything in sync, i would send a unique key + time stamp with my data to the server and from server to client they would keep sending this data until they had a "Received key" message sent back. - i can't remember if i removed this tbh, but i did add it as i needed a way to make sure everything got the correct updates
if a client/server received multiple data packs, it would put them in timestamp order and ditch the old ones, so everything was as up to date as possible

this is a mash of different ideas, and i thought i'd jsut throw my thoughts in, no idea if this is correct but worked for me lol
as positive07 said, you want to send as minimal data as possible, but you do want to keep all clients up to date

commands i would send :
Game Commands : Spawn Player, Spawn Particle, Play Alert Sound
Pawn commands : Fire, Dash

i guess you dont have to send the Pawn commands, that stuff can be handled with the server sending its Game Commands and player location updates
feelixe
Prole
Posts: 36
Joined: Tue Aug 20, 2013 10:29 am

Re: Getting started with multiplayer

Post by feelixe »

I'm not sure I understood that completly, I'm not very experienced yet heh.

But I have one question, when you send data from client to server in lube, then lube will attach an id. But in the client there's no way (built in) to keep track of which player is the clients. So i used this

Code: Select all

server:send( "getId"..id, id)
then the client will recive that and just do this:

Code: Select all

if string.find(data, "getId") then
	exclusiveID = tonumber(string.sub(data, "6"))
end
Then I'll use it like this basiclly, players[exclusiveID].x to translate camera etc.

I having get crashes on connection sometimes, could this be it? Is this a bad way to do it?
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Getting started with multiplayer

Post by Positive07 »

That's why I strongly suggest you look at lua-enet, it is really basic but you dont have to dig in someone elses code. You can implement that functionality really easy, by creating a table with the different ids, sending the id to the player on startup and send that id with every message to identify yourself as a player.
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests