Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Multiplayer Peer to Peer possible?

Author
Message
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 25th Jul 2017 20:40
Hi guys,

I'm coming from Blitz3D for the PC, which originated on the Amiga and was pretty cool, but now aging therefor I've just purchased the AGK.
So far I'm happily impressed: luv the x-platform, 3d and physics.

Only thing I'm missing is something similar as "The Code Archive" blitzbasic.com used to have, containing code snippets and examples of specific topics.
(which btw can now be found here: http://www.syntaxbomb.com/index.php/board,31.0.html for anyone interested ).

Anyway, my Question:
I'd like to do a Peer To Peer Multiplayer game, but I haven't found a coding example for this (yet), only someone mentioning that he actually managed to do so, and uses this in his game.
See here: https://forum.thegamecreators.com/thread/218395#msg2592573

Does anybody have a code example for this?

Kind regards & thanks,


Rick Nasher
Dybing
12
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 27th Jul 2017 03:16
If you go to 'Help' in the IDE, it'll open a (local) webpage in your default browser with all the documentation. From the help home-page, go to 'Examples' and then scroll down to 'Multiplayer'. There you'll find just the one entry called 'Getting started with multiplayer' and it'll walk you through making a simple 2 player P2P game. With full code-listing.

The one restriction though is that it is local network only - both host and client(s) need be on the same LAN/Subnet.

If intending to have P2P over WAN, you'll need a negotiation server that can feed the IP of the host to clients and vice versa. And keep track of available hosts, number of available slots per host and so on and so forth. It suddenly gets quite complicated really fast
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 27th Jul 2017 10:13 Edited at: 27th Jul 2017 11:00
Thanks, found that. Maybe I should specify bit more.
What I'm after is basically a LAN Multiplayer for a limited amount of players(5 or so) with host migration:
whenever the initial host quits, leaves or loses connection, the next client in line, with lowest ping and longest in the game, will become the host.

I read this should be possible and would love to see a code example of how to do this in AppGameKit Tier1, but so far haven't found any examples..
Unity can do it, but I really don't like Unity.

Anybody knows how to achieve this?
Coilwinder
11
Years of Service
User Offline
Joined: 28th Feb 2013
Location: Norway
Posted: 28th Jul 2017 05:05 Edited at: 28th Jul 2017 05:14
I'm kind of working on something like this (kind of.. I'm a better procrastinator than coder at times lol). There is a code snippet in AGK's example folder - (..\Multiplayer\GettingStarted). It should do just that

I'm not sure about the host migration thing though. I'm only trying to make a two-player game atm. I imagine you'd have to re-negotiate for a new host or something when a host leaves, making the game halt a bit.

As for LAN, I was super pleasantly surprised at how easy it was to make a wireless LAN type connection! All you have to do is to make a WiFi hotspot on one of the mobile devices (android), and just connect to that with the other device. No internet required! My tablet unfortunately couldn't make a hotspot afaik, but my mobile phones can (I have an old, ooold one with Android 2.3.5, as well as a newer one (Android 6.0), both works). Except for the WiFi hotspot thing it should the same for desktops (I've only tried between my desktop and a tablet, but I'm pretty sure it is, as long as the computers can reach each other via a network).

I changed the GettingStarted example slightly for a slightly better demonstration (imho). I uploaded it to the "code base entries" a while ago, here. It seems those pages are in a bit of a mess atm but the code does show. Just in case I'm also posting it below (media files exists in the GettingStarted\media folder, just copy this folder if you want to try this).




EDIT: Well from reading Dybing's answer above I se the same example is mentioned. Still, hope this is of some use to someone.
Apologies for any typos and strange grammar.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 28th Jul 2017 22:07 Edited at: 28th Jul 2017 22:09
I don't know off the top of my head exactly how to implement in AGK2 but it surely seems possible. If the example can handle 2 it should be able to handle 5 (with modifications to code of course). And if these can communicate (which they must be) then when the server goes down it can broadcast that (or alternately clients can detect no response on their end) and the clients can then all do a test figuring out which should fill the role of host now.

Basically just dig in and when you knock it out post the code and there will be an example. I think it is mainly just a case of people not getting to it yet. At least for me it is. When I do such an experiment I will gladly post source.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 30th Jul 2017 03:37
Hi Rick!

Check if this thread or this thread can help you with some ideas.

Best!
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 31st Jul 2017 23:54
Thanks, this is great stuff indeed if going for a dedicated server, which is very nice to have. However ideally I want the players to also be able to do some quick and instant death match LAN partying without the need for, or access to a real dedicated server:

Player1 initiates the game and behind the scene he/she becomes the host.
Player2 joins the game as a client.
Player3 joins the game as a client.
Player4 and so on, until max number of players is reached.

Then 2 possible scenario's can occur:

case1(clean departure).
Player1 decides he wants to go water his garden instead so leaves the game.
His program sent a neat closure message towards the next player in line, who's ping is also the lowest in the list(lets assume Player3).
Player3 becomes the new host, requests and gets all data from the host that's about to quit, that then sends a msg to all other players that Player3 is the new host.
Player3 takes over and is the new host.
Player1 leaves, disconnects.

case2(unclean departure).
Player1's mum comes in angry, for her son's gaming again instead of doing his homework, so she pulls the plug(or due to some other unforeseen reason): instantly the host is gone without notice.
A list has been maintained and shared with all players containing On-Game-Time, IP-number and Ping value, so all clients know who's to be the next host and start trying to connect to him.
Player3's application also knows this and starts to broadcast as host so the other players can connect to him as clients.
Once connected each player resents their last known positions/states and the host sends these to all other players so that the game can continue were left off.
This may cause a hiccup/jerk.

Alternative would be that the all players send all data to each other all the time as if all would be hosts, but don't know if this would generate too much traffic or is possible at all within the current framework.


I'd hoped someone already tried and found out by trial and error what is the best approach or any other way I've not considered here and also if it's actually possible using AGK's current commandset.






MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 1st Aug 2017 21:42
If you need a LAN multiplayer, basic networking commands of AppGameKit will do the trick easily. no need to check ping or be afraid of full push of all datas to everyone (Send message to "0" and every client will receive). On LAN it's almost transparent.

My vision :

If you want to change the "host" (due to a disconnection) , you have to constantly save all positions/variables (etc...) on each player's devices. And each device must have a priority order (1,2,3,4,5,...) set the first time with the first host (sorting them by ping if you want but for LAN games .. we really don't care).

If a disconnection really occurs, you have to find if it's due to the host (so other players will also be disconnected), or if it's the client itself ... (that is the hard part). Maybe you can retry a re-connection and if it fails , you can consider that the host is down.

The priority comes at this moment. All client will do the same verifications so if each device becomes the host, you will have a problem ... that's why the device with lower priority (or higher as you wish) for example priority 1 , should be the first to attempt to become host after PriorityNumber x 5 seconds (so ... 1x5 =5seconds). but before theses 5 seconds, it will try to find a broadcasted game (and it will find nothing).

The device with priority 2 will wait for PriorityNumber x 5 seconds (so ... 2x5 = 10 seconds).. theorically, it will never have the time to becomes host because it would find the first device with priority "1" ...

And so on ...

Do not forget to resync all positions from the new host with all clients. And you can try with different delay offset other than "5 seconds" of course :p

There is a lot of solutions.
--------------------------------
Join us on dedicated AppGameKit WeeKChat :
https://week.chat/room/AppGameKit
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 20th Aug 2017 14:07
Thanks guys(slow response, was bit held up), will try your suggestions.

Login to post a reply

Server time is: 2024-04-26 02:28:30
Your offset time is: 2024-04-26 02:28:30