How do I link multiplayer with Firebase?

0 favourites
From the Asset Store
Firebase: Analytics, Dynamic Links, Remote Config, Performance, Crashlytics on Android, iOS & Web Browser
  • 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.

  • 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).

  • 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:

    [quote:q6naj2lp]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:

    [quote:q6naj2lp]-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...

    [quote:q6naj2lp]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.

  • Firstly, array as JSON:

    https://www.scirra.com/manual/108/array

    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.[/code:2lnb9dg4]
    
    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.
  • 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?

    [quote:5cewj1xp]

    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?

  • 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.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.

  • 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.

  • 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?

  • Well nothing you are saying is really impossible.

    As I mentioned earlier, the most important step is to define for yourself what information each player will need from the server, what they need to provide to the server and when. If you can make a clear plan, then get working! As Jomo said, Firebase is more suitable for Client-Server, but if that is too hard to work with then it is definitely possible with the multiplayer plugin. When you get started and work through putting it together, you will run into more specific problems that people will be able to help you with rather than just trying to imagine the whole thing in your head at the moment.

    Basically - try it and learn!

  • Thanks for the motivation boost . I just sometimes find it hard to start. I did try the local storage idea, but it seems local storage is controlled by the browser and limited to 5MB and in some cases to 50MB which I believe won't be enough for this type of game. Unless I am mistaken. I'll try further and see what can come up with though.

    rexrainbow is there any chance of a guide or a tutorial that exists somewhere on how you did that CAPX with Firebase? The persistent world demo?

    EDIT: I am thinking a real time MUD might be a bit complicated, perhaps something like Kingdom of Loathing is easier to make using Firebase and Construct 2?

  • Vallar

    I do not have time to write completed tutorial for that capx of persistent world demo, because that I am busy to make new plugins or maintain them, sorry.

    You might try to contact to jomo who is a C2 teacher and had wrote some tutorials before.

  • You can try to make a prototype to lower down risk with limiting your goal to about 50 people simultaneously online. Then think about how to scale it up in later versions.

    I found some points to address in the last discussions:

    1. C2 MP uses webrtc, which might be blocked by some firewall.

    2. You will need more knowledge about how to make a network game before you going from arcade/console games to network game.

    Here is one book of my favorite (written in Japanese, Chinese version is also available)

    http://www.amazon.co.jp/%E4%B8%AD%E5%B6 ... B0050QL3S2

    3. Anyways, a 50 to 100 player would be a good starting point.

  • You can try to make a prototype to lower down risk with limiting your goal to about 50 people simultaneously online. Then think about how to scale it up in later versions.

    I found some points to address in the last discussions:

    1. C2 MP uses webrtc, which might be blocked by some firewall.

    2. You will need more knowledge about how to make a network game before you going from arcade/console games to network game.

    Here is one book of my favorite (written in Japanese, Chinese version is also available)

    http://www.amazon.co.jp/%E4%B8%AD%E5%B6 ... B0050QL3S2

    3. Anyways, a 50 to 100 player would be a good starting point.

    Thanks for your reply. That is the target actually, start with a MVP to see how far I can go then think about scaling it.

    I have read my way through the C2 MP tutorials and I understand the basics, and duplicated the Chat example too. As for the book recommendation, unfortunately that page is completely in Japanese and I couldn't understand anything (I am guessing the book isn't available in English). I don't read either languages would there be any book in English that you can recommend? Perhaps even tutorials or something that can assist with using Construct 2 even?

    Thank you very much in advance.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)