-2
\$\begingroup\$

I enjoy playing a lot of text-based PBBGs (Persisent Browsing Based Games). A good example of the style of game I'm referring to is lyrania. I would like to work on developing this style game but have had a hard time researching everything required to create such a game from scratch.

The front-end development I know how to do or can easily learn.

The first specific thing that I am unsure how to do is:

1) Hooking up to a server that would allow constant updates of player data as well as retrieve data from the server. Finding information on how to create a server proves difficult because every guide seems to assume I have knowledge of things that I don't, I'm completely self-taught.

I would like to do as much of this in Javascript as possible but am willing to learn other languages and have some experience with Python, Java, C#, C++, PHP, mySQL

\$\endgroup\$
  • 1
    \$\begingroup\$ Hi Shniper. Our Q&A format here works best with a single, focused question at a time, rather than an omnibus list of questions or a thread that evolves through discussion. If you'd prefer to work in that format, a discussion forum like GDNet might be more suitable. For now, I've trimmed your question to just the first point. You can always post additional questions separately. Even after the trim, this question is at risk of being marked "Too Broad" as there is a lot involved in setting up a server. Please consider editing to go into detail about the first step or question you're tackling. \$\endgroup\$ – DMGregory Feb 9 '18 at 14:34
  • \$\begingroup\$ @DMGregory I am aware of how Stack Overflow/ Stack Exchange works however the information I was looking for is more a broad overview of how everything works together so I have something to look back on when I need to know what else needs to be worked on. There is very limited information on how to actually tie the front and back end with each other or I was searching for the wrong things. So I wanted a generalized answer to this question so that in the future I can search more accurately for answers to specific questions. \$\endgroup\$ – Shniper Feb 10 '18 at 3:49
1
\$\begingroup\$

I'm not a professional game developer myself (developing my first game) but I would like to just give my opinion on some points here as I'm a web application developer as professional.

  1. Well that straight comes to my suggestion. You need to create a frontEnd and a Backend part for your game. Meaning you create an application in Java,ASP.NET,PHP or whatever floats your boat. It will handle all business logic as authorization, registering, the game itself etc. The frontend will just display and request data. You can find informations about this structure under terms like RESTful API and searching for backend and frontend development. ( Full-Stack Web Development ).

    1.1. The way this works is that the backend offers points to request data like asking for the current task when calling this server url: /game/{player-ID}/activeTask ( just a example. There are best practies on how to style the URL's ) The client ( Browser, mobile whatever ) just has to interprete the data and show it correctly. You will divide responsibilitys, which will have an additional pro explained in point 4.

  2. That's really hard to answer. There are a lot of possible ways to design/structure this. However it depends on the kind of requirements you have for such an system. Maybe this is a good starting point. Generally get to know what system there are and then decide on which to use and study it.

  3. Very difficult point in generall. I will only scratch it to give you a starting point because I would need to write a blog article to answer it. You need to use existing components and librarys. Don't. Don't invent your own. That will likely be a security hole more than an improvement. Store the user with all informations you like in the database and then store the password encrypted, so it can never be decrypted to cleartext again. A good starting point for this are the keywords. bcrypt,scrypt, and PBKDF2. With these you will garuanteed find everything needed. ( I prefer to use bcrypt and pbkdf2 )

  4. And voilá. When you decide to create the game in a backend and frontend style you can easily create an application for any device that will just call the url's as the website and interprete the receiving data. Sounds great doesn't it?

Notes: So I maybe made it sound pretty easy but it's going to be a heavy task. You need to take a lot into consideration and it's a lot of work to make your backend hardened so nobody can just request the URL's manually and cheat or worse...Hack your server. You need to sanitize every input from users and never trust their data. Optionally but recommend is additionall encryption of the data before it leaves the client or the server. ( Keyword: private/public Key communication encryption ) And very essential is a correctly set up SSL communication/certificate for your server so all communication is over HTTPS.

I wish you best of luck and more over fun in developing that game!!

\$\endgroup\$
  • 4
    \$\begingroup\$ Hi Nico, and welcome to GameDev.StackExchange! As a general guide, if you find you have to answer with "well, that's hard to answer... it depends... I'll only scratch the surface" then it's a good sign the question might be too broad in its current form to answer in depth. In these cases, it's often more helpful to work with the asker to edit the question into a clearer focus, so deep constructive answers can follow. \$\endgroup\$ – DMGregory Feb 9 '18 at 14:39
2
\$\begingroup\$

I would recommend taking a look at Flask, a web framework for Python that's fairly easy to set up and comes with a development server you can run locally. The code snippets below are from a Flask based browser RPG.

The two most pouplar methods of exchanging data between the frontend and backend in a web application are

  • Templates and forms
  • Asynchronous requests fom JS (AJAX)

These are typically used in combination, each serving a different role.

Templates

A template is, put simply, a HTML page with placeholders that the server replaces with data before the page gets sent to the client. Flask uses Jinja2 for this task.

Assuming you want to go to http://servername/character/1 and see a list of the first character's items, a basic Jinja2 template could look like this:

<body>
  Your inventory:<br/>
  <div>
    {% for item in pc.inventory.items %}
      <a href="/items/{{loop.index}}">{{item.name}}</a>
    {% endfor %}
  </div>
</body>

And the Python code to serve the page:

app = Flask(__name__)

@app.route('/character/<int:index>')
def show_character(index):
    chara = party.characters[index-1]
    return render_template('character.html', pc=chara)

POST Requests

I'll assume you're familiar with forms. If you set method="post", the form will forward the data entered to the web server. Flask extracts this data into a dictionary. The following code reads data from an input field named "description" and forwards it to a template to display it back to the user. Note that in practice, you'll probably want to save that data somewhere, ideally in a database.

@app.route('/profile/description', methods=['POST'])
def set_description():
    description = request.form['description']
    return render_template('profile.html', description=description)

AJAX

Asynchronous requests work basically the same, except that they are called from JavaScript and you usually don't want to return a template but rather a string containing JSON, which JavaScript can easily digest and turn into an object, if needed. The idea is that the "consumer" of an AJAX/REST call is not the user but your script, which will process the data and add it to the DOM.

If you want to exchange complex objects or even object hierarchies between front- and backend, I recommend jsonpickle. However, keep in mind that any AJAX requests eat up bandwidth, while filling out a template server side is free from a bandwidth standpoint.

Use Ajax when you need to refresh data without reloading the entire page, for example for a chat window.

Things to look out for

  • Client side (i.e. JS) input validation is good for the user experience, but never trust any data that comes from the client, always validate server side.
  • A database is recommended for storing your data.
  • Look into session handling. The server side code is "global", by default there is one scope for all users. You'll probably want an encrypted session cookie or at least a session ID so people can't just login as someone else. I can add examples later if you need them.
  • Keep in mind that some users don't allow scripts for every domain. If some core functions absolutely require JS, that's ok, just communicate that. If you can make it work without, even with less functionality, that's better.

Hope that serves as a good starting point. Feel free to ask more specific questions if you get stuck somewhere, that's what the site is for :)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.