How do I link multiplayer with Firebase?

Get help using Construct 2

Post » Fri Jul 22, 2016 5:58 pm

Hello,

I am going through the endeavor of creating an online text based game (think a simplified game like A Dark Room) but would like to incorporate some multiplayer aspects to it. After trying many of the tutorials and guides around, I decided on Firebase with Rex's plugins. I was able to create the registration and login system and everything is going fine.
A simple chat system is also in place (part of the multiplayer features I wanted to add). However, I am unsure how to link between Firebase and the multiplayer aspects of the game?

How do I save player stats, positions, progress, etc... so that when the player logs back in (from anywhere) he can continue from where he left off (just like MUDs used to do)?

NOTE: I am generally new to servers and Firebase, I do understand the multiplayer concepts, networking (basic and a bit advanced topics) and I am fairly familiar with Construct 2. I am not familiar with things related to AJAX, Node.JS, etc... that side of Construct I am not proficient with. I would welcome any guides, tutorials, readings, videos, etc... that would assist me to get from where I am to the final product.

Thank you very much in advance.
B
19
S
7
Posts: 161
Reputation: 1,751

Post » Fri Jul 22, 2016 6:09 pm

At the simplest level, Firebase is just an online database you can use to store and get information.

For a MUD type game, you might not even need to use the multiplayer plugin if you are using Firebase, depending on your setup. Basically each player will upload their own information and request data from the Firebase server as needed, thus getting information on all the other player states.

Otherwise, utilizing the multiplayer plugin, you would probably have a dedicated host which all peers connect to that handles all information. Then you wouldn't need Firebase...

To proceed with Firebase, you'll want to answer the questions: What does each peer need to know about other peers, and when do they need it? What information needs to be saved? Then its just a matter of syncing the relevant information to Firebase.

Generally speaking, if you can organize it properly, keeping all information that needs saving in an array would allow for a relatively simple import/export system via Save and Load Array as JSON (which is simply a standard format for saving certain types of information).
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Fri Jul 22, 2016 8:28 pm

@oosyrag Thanks for your reply. Just to note, the MUD I am trying to create has some graphics in it, not pure text -- albeit the graphics are mostly squares moving on top of a tiled (simple squares with some colors on it) background. To give a proper picture, imagine a very simple map in a game -- that is the graphical part. Along with inventory and character sheet.

Since I don't have much experience with Firebase, what I understand from this tutorial:
https://www.scirra.com/tutorials/5015/g ... h-firebase

The database is structured like the below with the "parent" part is the Subdomain provided in the ItemTable plugin:
appname
-parent
-- key1: value
-- key2: different value


So let's say I go through with Firebase, then I would need a "parent" called let's say "player" to store all player data; location, skills, inventory, etc... Another parent would be then required for mobs, another parent for stores within the game and so on.
But the way I understand it, I can't "add" a parent but only "change" the current parent so I can't have a structure like this:
-appname
--player
---locx
---locy
--mob
---locx
---locy
--store
---item1
---item2


On the other hand if I go with the multiplayer plugin, I won't have logins, so there are no accounts and I can't have dedicated players? Unless I am missing something...

Generally speaking, if you can organize it properly, keeping all information that needs saving in an array would allow for a relatively simple import/export system via Save and Load Array as JSON (which is simply a standard format for saving certain types of information).


I am sorry that just went over my head. I understand the part where you say that I would store all required data in an array (possibly 3 dimensional? X being the parent in the above example Y being the child and Z being the value of that child). But the JSON part, that I don't understand how can that be done.
B
19
S
7
Posts: 161
Reputation: 1,751

Post » Fri Jul 22, 2016 9:18 pm

Firstly, array as JSON:

https://www.scirra.com/manual/108/array
Code: Select all
AsJSON
Return the contents of the array as a string in JSON format. This can later be loaded in to the array with the Load action.

Load
Load the contents of the array from a string in JSON format. This must have been retrieved from either the Download action or the AsJSON expression. It could also be retrieved dynamically from the AJAX object.


So using the Array.AsJSON expression will give you the entire contents of an array as a single string. You can save this string to a variable, file, localstorage, firebase key ect.

Loading that same JSON string will populate the array with all the information that was saved.

About the multiplayer plugin, you would make your own login system. Peers can send a message to host, such as login information, and your host can pass back information to the peer (like the player's game data array in JSON format) after confirming the login info. Again, this is assuming you will have one dedicated host always running on a server.

Regarding Firebase, sorry I'm not too familiar with the specifics so I can't help you much with details. I just have an idea of the general concept of using it, and haven't worked with it myself yet.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Jul 23, 2016 6:12 am

@oosyrag Thanks again for your reply.

After reading around the forums for a while now about this, it seems there is an issue with the length of the string from the .AsJSON. If it is long then it would waste bandwidth so it may not be feasible with longer arrays. However I am unsure which length is considered long and therefore wasting bandwidth, I can't find a mention of that anywhere.
Any comments on that part?

Regarding Firebase, sorry I'm not too familiar with the specifics so I can't help you much with details. I just have an idea of the general concept of using it, and haven't worked with it myself yet.


I went into the web environment for Firebase and went through the Databse and found that while the structure is as follows:

appname
-parent
--child1
--child2

You can actually have children of children and multiple subchildren too but you can't have multiple parents (or so I understand it) so you can have something like this:

appname
-parent
--child1
---subchild
---subchild1
---subchild2
--child2
---subchild
---subchild2
----subchild of a subchild
----subchild of a subchild
-----more subchildren of subchildren

I am unsure why we can't have multiple parents, can have this tree structure like that, It also can be imported and exported as JSON. In theory if that is the case, so instead of arrays and multiplayer object one can use that database as the structure as you mentioned before. I am just missing the link in my mind on how one can structure this and make it work in a multiplayer (bearing in mind the JSON feature if that is useful).

Also, I am hoping for someone that worked with both could reply and give us some insight on the matter. Perhaps @rexrainbow can shed some light on how can we use Firebase in a MUD like situation, even? Should I ask this same question in another part of the forums?
B
19
S
7
Posts: 161
Reputation: 1,751

Post » Sat Jul 23, 2016 7:41 am

The whole of MMO/MUD is very - very complex.

Here is a demo I made before, to sync the position of players (only). It does not have inventory system...

Big map ( Capx )
- Enter display name at top text box, then click a character at bottom 5 characters to enter map.
- press arrow-key to move left/right/top/down, or dragging left/right/top/down to move.
- Online players will be shown at bottom with name and current position.
- You might try open more than one page to test it.
B
108
S
26
G
267
Posts: 4,455
Reputation: 149,745

Post » Sat Jul 23, 2016 3:26 pm

rexrainbow wrote:The whole of MMO/MUD is very - very complex.

Here is a demo I made before, to sync the position of players (only). It does not have inventory system...

Big map ( Capx )
- Enter display name at top text box, then click a character at bottom 5 characters to enter map.
- press arrow-key to move left/right/top/down, or dragging left/right/top/down to move.
- Online players will be shown at bottom with name and current position.
- You might try open more than one page to test it.


I agree MUDs are very complex -- I am not going to argue. Although, it seems people recommend to start with them when creating multiplayer games to learn. That said, this is more of a pet project I had in mind for a while and wanted to sink my teeth into something complex.

I have tried your demo and it looks amazing. I have looked into the CAPX but some of it went over my head. However, I saw that you can add a parent to the database in Firebase by using different ItemMonitor plugin into the layout (or so I understood from your CAPX).

This, however, had me question my choices; for a beginner with databases, multiplayer and servers, would you recommend using Multiplayer plugin or Firebase? I am trying to do something similar to:
http://revelationgame.blogspot.com.eg/ or this image http://www.godwars2.org/images/plugin_v115_3.png

Any info, guidance or tutorials are much, much appreciated
B
19
S
7
Posts: 161
Reputation: 1,751

Post » Sat Jul 23, 2016 4:55 pm

From what I understand, Firebase would be more suitable for a persistent mmo/mud type game, but again I don't have experience with it myself. There are bandwidth and other cost considerations when using a third party service.

The multiplayer plugin should also have all the functionality you need, but you may have to put in more legwork implementing basic data structures like a login system and database. You'll also need to have a system available to act as a dedicated host, with the network configuration that comes with that.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Jul 23, 2016 5:22 pm

Official MP plugin is for P2P connection network games, while Firebase is for C/S(Client-Server) connection network games. P2P is not suitable for MMO, it is more suitable for First Person Shooter.
Providence University, lecturer.

Tatung University, lecturer.



Consultant per question: USD$15 / time

Consultant by month: USD$300 / month

Customized project: USD$2500 / capx
B
78
S
16
G
4
Posts: 196
Reputation: 7,688

Post » Sat Jul 23, 2016 5:36 pm

@oosrag and @jomo thanks for your replies guys.

I read in another thread (I think it was called the Multiplayer Discussion Thread or some such) that the MP plugin while it is P2P, at the end of the day there is a host (server) and a peer. So essentially there is a server, albeit not quite authoritative but from the discussion it seems you can make it so.

On the other hand, what I was thinking if I use the MP is perhaps create the "server" part where it stores locally the values that needs to be synced like a login similar to the below tutorial:
https://www.scirra.com/tutorials/276/wh ... ct2/page-2

That is one method for it. However, another method I was thinking is using the Local Storage plugin to store the information that should be synced on the server machine. That server machine would have the game running all the time and within the game there is a check if the server machine is online and is the one currently being host. If that checks out, the data is pulled/pushed using the Local Storage plugin.
Another way I am thinking of is to store the data in Array as mentioned by you @oosyrag and use broadcast message when the a part of the array is altered and broadcast that alteration only. That way I don't have to get into the whole .AsJSON getting long = more bandwidth (not quite sure how all of this will pan out though).

Since they are all theories and ideas, how feasible they are or even logical is something I am unsure of. It seems legit in my mind but perhaps I am lacking some knowledge that renders what I am saying impossible. Any thoughts or insights?
B
19
S
7
Posts: 161
Reputation: 1,751

Next

Return to How do I....?

Who is online

Users browsing this forum: marcinkowski, plinkie, zenox98 and 11 guests