<li><aclass="reference internal"href="#activating-your-new-character-generation">Activating your new character generation</a></li>
<li><aclass="reference internal"href="#adding-a-no-capcha-recapcha-on-your-character-generation">Adding a no CAPCHA reCAPCHA on your character generation</a><ul>
<li><aclass="reference internal"href="#step-1-obtain-a-sitekey-and-secret-from-google">Step 1: Obtain a SiteKey and secret from Google</a></li>
<li><aclass="reference internal"href="#step-2-installing-and-configuring-the-dedicated-django-app">Step 2: installing and configuring the dedicated Django app</a></li>
<li><aclass="reference internal"href="#step-3-adding-the-capcha-to-our-form">Step 3: Adding the CAPCHA to our form</a></li>
<h1>Web Character Generation<aclass="headerlink"href="#web-character-generation"title="Permalink to this headline">¶</a></h1>
<sectionid="introduction">
<h2>Introduction<aclass="headerlink"href="#introduction"title="Permalink to this headline">¶</a></h2>
<p>This tutorial will create a simple web-based interface for generating a new in-game Character.
Accounts will need to have first logged into the website (with their <codeclass="docutils literal notranslate"><spanclass="pre">AccountDB</span></code> account). Once
finishing character generation the Character will be created immediately and the Accounts can then
log into the game and play immediately (the Character will not require staff approval or anything
like that). This guide does not go over how to create an AccountDB on the website with the right
permissions to transfer to their web-created characters.</p>
<p>It is probably most useful to set <codeclass="docutils literal notranslate"><spanclass="pre">MULTISESSION_MODE</span><spanclass="pre">=</span><spanclass="pre">2</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">3</span></code> (which gives you a character-
selection screen when you log into the game later). Other modes can be used with some adaptation to
auto-puppet the new Character.</p>
<p>You should have some familiarity with how Django sets up its Model Template View framework. You need
to understand what is happening in the basic [Web Character View tutorial](Web-Character-View-
Tutorial). If you don’t understand the listed tutorial or have a grasp of Django basics, please look
at the <aclass="reference external"href="https://docs.djangoproject.com/en/1.8/intro/">Django tutorial</a> to get a taste of what Django
does, before throwing Evennia into the mix (Evennia shares its API and attributes with the website
interface). This guide will outline the format of the models, views, urls, and html templates
needed.</p>
</section>
<sectionid="pictures">
<h2>Pictures<aclass="headerlink"href="#pictures"title="Permalink to this headline">¶</a></h2>
<p>Here are some screenshots of the simple app we will be making.</p>
<p>Index page, with no character application yet done:</p>
<hrclass="docutils"/>
<p><imgalt="Index page, with no character application yet done."src="https://lh3.googleusercontent.com/-57KuSWHXQ_M/VWcULN152tI/AAAAAAAAEZg/kINTmVlHf6M/w425-h189-no/webchargen_index2.gif"/></p>
<hrclass="docutils"/>
<p>Having clicked the “create” link you get to create your character (here we will only have name and
background, you can add whatever is needed to fit your game):</p>
<p>Back to the index page. Having entered our character application (we called our character “TestApp”)
you see it listed:</p>
<hrclass="docutils"/>
<p><imgalt="Having entered an application."src="https://lh6.googleusercontent.com/-HlxvkvAimj4/VWcUKjFxEiI/AAAAAAAAEZo/gLppebr05JI/w321-h194-no/webchargen_index1.gif"/></p>
<hrclass="docutils"/>
<p>We can also view an already written character application by clicking on it - this brings us to the
<em>detail</em> page:</p>
<hrclass="docutils"/>
<p><imgalt="Detail view of character application."src="https://lh6.googleusercontent.com/-2m1UhSE7s_k/VWcUKfLRfII/AAAAAAAAEZc/UFmBOqVya4k/w267-h175-no/webchargen_detail.gif"/></p>
</section>
<hrclass="docutils"/>
<sectionid="installing-an-app">
<h2>Installing an App<aclass="headerlink"href="#installing-an-app"title="Permalink to this headline">¶</a></h2>
<p>Assuming your game is named “mygame”, navigate to your <codeclass="docutils literal notranslate"><spanclass="pre">mygame/</span></code> directory, and type:</p>
<p>This will initialize a new Django app we choose to call “chargen”. It is directory containing some
basic starting things Django needs. You will need to move this directory: for the time being, it is
in your <codeclass="docutils literal notranslate"><spanclass="pre">mygame</span></code> directory. Better to move it in your <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web</span></code> directory, so you have
<codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen</span></code> in the end.</p>
<p>Next, navigate to <codeclass="docutils literal notranslate"><spanclass="pre">mygame/server/conf/settings.py</span></code> and add or edit the following line to make
<p>After this, we will get into defining our <em>models</em> (the description of the database storage),
<em>views</em> (the server-side website content generators), <em>urls</em> (how the web browser finds the pages)
and <em>templates</em> (how the web page should be structured).</p>
<sectionid="installing-checkpoint">
<h3>Installing - Checkpoint:<aclass="headerlink"href="#installing-checkpoint"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p>you should have a folder named <codeclass="docutils literal notranslate"><spanclass="pre">chargen</span></code> or whatever you chose in your mygame/web/ directory</p></li>
<li><p>you should have your application name added to your INSTALLED_APPS in <aclass="reference external"href="http://settings.py">settings.py</a></p></li>
</ul>
</section>
</section>
<sectionid="create-models">
<h2>Create Models<aclass="headerlink"href="#create-models"title="Permalink to this headline">¶</a></h2>
<p>Models are created in <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen/models.py</span></code>.</p>
<p>A <aclass="reference internal"href="../Concepts/New-Models.html"><spanclass="doc std std-doc">Django database model</span></a> is a Python class that describes the database storage of the
data you want to manage. Any data you choose to store is stored in the same database as the game and
you have access to all the game’s objects here.</p>
<p>We need to define what a character application actually is. This will differ from game to game so
for this tutorial we will define a simple character sheet with the following database fields:</p>
<ulclass="simple">
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">app_id</span></code> (AutoField): Primary key for this character application sheet.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">char_name</span></code> (CharField): The new character’s name.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">date_applied</span></code> (DateTimeField): Date that this application was received.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">background</span></code> (TextField): Character story background.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">account_id</span></code> (IntegerField): Which account ID does this application belong to? This is an
AccountID from the AccountDB object.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">submitted</span></code> (BooleanField): <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">False</span></code> depending on if the application has been submitted yet.</p></li>
</ul>
<blockquote>
<div><p>Note: In a full-fledged game, you’d likely want them to be able to select races, skills,
attributes and so on.</p>
</div></blockquote>
<p>Our <codeclass="docutils literal notranslate"><spanclass="pre">models.py</span></code> file should look something like this:</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># in mygame/web/chargen/models.py</span>
<p>You should consider how you are going to link your application to your account. For this tutorial,
we are using the account_id attribute on our character application model in order to keep track of
which characters are owned by which accounts. Since the account id is a primary key in Evennia, it
is a good candidate, as you will never have two of the same IDs in Evennia. You can feel free to use
anything else, but for the purposes of this guide, we are going to use account ID to join the
character applications with the proper account.</p>
<sectionid="model-checkpoint">
<h3>Model - Checkpoint:<aclass="headerlink"href="#model-checkpoint"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p>you should have filled out <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen/models.py</span></code> with the model class shown above
(eventually adding fields matching what you need for your game).</p></li>
</ul>
</section>
</section>
<sectionid="create-views">
<h2>Create Views<aclass="headerlink"href="#create-views"title="Permalink to this headline">¶</a></h2>
<p><em>Views</em> are server-side constructs that make dynamic data available to a web page. We are going to
add them to <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen.views.py</span></code>. Each view in our example represents the backbone of a
specific web page. We will use three views and three pages here:</p>
<ulclass="simple">
<li><p>The index (managing <codeclass="docutils literal notranslate"><spanclass="pre">index.html</span></code>). This is what you see when you navigate to
<li><p>The detail display sheet (manages <codeclass="docutils literal notranslate"><spanclass="pre">detail.html</span></code>). A page that passively displays the stats of a
given Character.</p></li>
<li><p>Character creation sheet (manages <codeclass="docutils literal notranslate"><spanclass="pre">create.html</span></code>). This is the main form with fields to fill in.</p></li>
</ul>
<sectionid="index-view">
<h3><em>Index</em> view<aclass="headerlink"href="#index-view"title="Permalink to this headline">¶</a></h3>
<p>Let’s get started with the index first.</p>
<p>We’ll want characters to be able to see their created characters so let’s</p>
<spanclass="n">current_user</span><spanclass="o">=</span><spanclass="n">request</span><spanclass="o">.</span><spanclass="n">user</span><spanclass="c1"># current user logged in</span>
<spanclass="n">p_id</span><spanclass="o">=</span><spanclass="n">current_user</span><spanclass="o">.</span><spanclass="n">id</span><spanclass="c1"># the account id</span>
<spanclass="c1"># submitted Characters by this account</span>
<spanclass="c1"># add the right locks for the character so the account can</span>
<spanclass="c1"># puppet it</span>
<spanclass="n">char</span><spanclass="o">.</span><spanclass="n">locks</span><spanclass="o">.</span><spanclass="n">add</span><spanclass="p">(</span><spanclass="s2">" or "</span><spanclass="o">.</span><spanclass="n">join</span><spanclass="p">([</span>
<spanclass="n">char</span><spanclass="o">.</span><spanclass="n">db</span><spanclass="o">.</span><spanclass="n">background</span><spanclass="o">=</span><spanclass="n">background</span><spanclass="c1"># set the character background</span>
<div><p>Note also that we basically create the character using the Evennia API, and we grab the proper
permissions from the <codeclass="docutils literal notranslate"><spanclass="pre">AccountDB</span></code> object and copy them to the character object. We take the user
permissions attribute and turn that list of strings into a string object in order for the
create_object function to properly process the permissions.</p>
</div></blockquote>
<p>Most importantly, the following attributes must be set on the created character object:</p>
<ulclass="simple">
<li><p>Evennia <aclass="reference internal"href="../Components/Permissions.html"><spanclass="doc std std-doc">permissions</span></a> (copied from the <codeclass="docutils literal notranslate"><spanclass="pre">AccountDB</span></code>).</p></li>
<li><p>The right <codeclass="docutils literal notranslate"><spanclass="pre">puppet</span></code><aclass="reference internal"href="../Components/Locks.html"><spanclass="doc std std-doc">locks</span></a> so the Account can actually play as this Character later.</p></li>
<li><p>The relevant Character <aclass="reference internal"href="../Components/Typeclasses.html"><spanclass="doc std std-doc">typeclass</span></a></p></li>
<li><p>Character name (key)</p></li>
<li><p>The Character’s home room location (<codeclass="docutils literal notranslate"><spanclass="pre">#2</span></code> by default)</p></li>
</ul>
<p>Other attributes are strictly speaking optional, such as the <codeclass="docutils literal notranslate"><spanclass="pre">background</span></code> attribute on our
character. It may be a good idea to decompose this function and create a separate _create_character
function in order to set up your character object the account owns. But with the Evennia API,
setting custom attributes is as easy as doing it in the meat of your Evennia game directory.</p>
<p>After all of this, our <codeclass="docutils literal notranslate"><spanclass="pre">views.py</span></code> file should look like something like this:</p>
<spanclass="n">current_user</span><spanclass="o">=</span><spanclass="n">request</span><spanclass="o">.</span><spanclass="n">user</span><spanclass="c1"># current user logged in</span>
<spanclass="n">p_id</span><spanclass="o">=</span><spanclass="n">current_user</span><spanclass="o">.</span><spanclass="n">id</span><spanclass="c1"># the account id</span>
<spanclass="c1"># submitted apps under this account</span>
<spanclass="c1"># add the right locks for the character so the account can</span>
<spanclass="c1"># puppet it</span>
<spanclass="n">char</span><spanclass="o">.</span><spanclass="n">locks</span><spanclass="o">.</span><spanclass="n">add</span><spanclass="p">(</span><spanclass="s2">" or "</span><spanclass="o">.</span><spanclass="n">join</span><spanclass="p">([</span>
<spanclass="n">char</span><spanclass="o">.</span><spanclass="n">db</span><spanclass="o">.</span><spanclass="n">background</span><spanclass="o">=</span><spanclass="n">background</span><spanclass="c1"># set the character background</span>
<h3>Create Views - Checkpoint:<aclass="headerlink"href="#create-views-checkpoint"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p>you’ve defined a <codeclass="docutils literal notranslate"><spanclass="pre">views.py</span></code> that has an index, detail, and creating functions.</p></li>
<li><p>you’ve defined a <aclass="reference external"href="http://forms.py">forms.py</a> with the <codeclass="docutils literal notranslate"><spanclass="pre">AppForm</span></code> class needed by the <codeclass="docutils literal notranslate"><spanclass="pre">creating</span></code> function of
<li><p>your <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen</span></code> directory should now have a <codeclass="docutils literal notranslate"><spanclass="pre">views.py</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">forms.py</span></code> file</p></li>
</ul>
</section>
</section>
<sectionid="create-urls">
<h2>Create URLs<aclass="headerlink"href="#create-urls"title="Permalink to this headline">¶</a></h2>
<p>URL patterns helps redirect requests from the web browser to the right views. These patterns are
created in <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen/urls.py</span></code>.</p>
<p>You could change the format as you desire. To make it more secure, you could remove app_id from the
“detail” url, and instead just fetch the account’s applications using a unifying field like
account_id to find all the character application objects to display.</p>
<p>To add this to our website, we must also update the main <codeclass="docutils literal notranslate"><spanclass="pre">mygame/website/urls.py</span></code> file; this
will help tying our new chargen app in with the rest of the website. <codeclass="docutils literal notranslate"><spanclass="pre">urlpatterns</span></code> variable, and
change it to include:</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># in file mygame/website/urls.py</span>
<h3>URLs - Checkpoint:<aclass="headerlink"href="#urls-checkpoint"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p>You’ve created a <aclass="reference external"href="http://urls.py">urls.py</a> file in the <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/chargen</span></code> directory</p></li>
<li><p>You have edited the main <codeclass="docutils literal notranslate"><spanclass="pre">mygame/web/urls.py</span></code> file to include urls to the <codeclass="docutils literal notranslate"><spanclass="pre">chargen</span></code> directory.</p></li>
</ul>
</section>
</section>
<sectionid="html-templates">
<h2>HTML Templates<aclass="headerlink"href="#html-templates"title="Permalink to this headline">¶</a></h2>
<p>So we have our url patterns, views, and models defined. Now we must define our HTML templates that
the actual user will see and interact with. For this tutorial we us the basic <em>prosimii</em> template
that comes with Evennia.</p>
<p>Take note that we use <codeclass="docutils literal notranslate"><spanclass="pre">user.is_authenticated</span></code> to make sure that the user cannot create a character
without logging in.</p>
<p>These files will all go into the <codeclass="docutils literal notranslate"><spanclass="pre">/mygame/web/chargen/templates/chargen/</span></code> directory.</p>
<sectionid="index-html">
<h3>index.html<aclass="headerlink"href="#index-html"title="Permalink to this headline">¶</a></h3>
<p>This HTML template should hold a list of all the applications the account currently has active. For
this demonstration, we will only list the applications that the account has submitted. You could
easily adjust this to include saved applications, or other types of applications if you have
different kinds.</p>
<p>Please refer back to <codeclass="docutils literal notranslate"><spanclass="pre">views.py</span></code> to see where we define the variables these templates make use of.</p>
<spanclass="p"><</span><spanclass="nt">p</span><spanclass="p">></span>You haven't submitted any character applications.<spanclass="p"></</span><spanclass="nt">p</span><spanclass="p">></span>
<spanclass="p"><</span><spanclass="nt">p</span><spanclass="p">></span>You didn't submit this character.<spanclass="p"></</span><spanclass="nt">p</span><spanclass="p">></span>
<h3>create.html<aclass="headerlink"href="#create-html"title="Permalink to this headline">¶</a></h3>
<p>Our create HTML template will use the Django form we defined back in <aclass="reference external"href="http://views.py/forms.py">views.py/forms.py</a> to drive the
majority of the application process. There will be a form input for every field we defined in
<aclass="reference external"href="http://forms.py">forms.py</a>, which is handy. We have used POST as our method because we are sending information to the
server that will update the database. As an alternative, GET would be much less secure. You can read
up on documentation elsewhere on the web for GET vs. POST.</p>
<h3>Templates - Checkpoint:<aclass="headerlink"href="#templates-checkpoint"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p>Create a <codeclass="docutils literal notranslate"><spanclass="pre">index.html</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">detail.html</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">create.html</span></code> template in your
<h2>Activating your new character generation<aclass="headerlink"href="#activating-your-new-character-generation"title="Permalink to this headline">¶</a></h2>
<p>After finishing this tutorial you should have edited or created the following files:</p>
<p>This will create and update the models. If you see any errors at this stage, read the traceback
carefully, it should be relatively easy to figure out where the error is.</p>
<p>Login to the website (you need to have previously registered an Player account with the game to do
this). Next you navigate to <codeclass="docutils literal notranslate"><spanclass="pre">http://yourwebsite.com/chargen</span></code> (if you are running locally this will
be something like <codeclass="docutils literal notranslate"><spanclass="pre">http://localhost:4001/chargen</span></code> and you will see your new app in action.</p>
<p>This should hopefully give you a good starting point in figuring out how you’d like to approach your
own web generation. The main difficulties are in setting the appropriate settings on your newly
created character object. Thankfully, the Evennia API makes this easy.</p>
<h2>Adding a no CAPCHA reCAPCHA on your character generation<aclass="headerlink"href="#adding-a-no-capcha-recapcha-on-your-character-generation"title="Permalink to this headline">¶</a></h2>
<p>As sad as it is, if your server is open to the web, bots might come to visit and take advantage of
your open form to create hundreds, thousands, millions of characters if you give them the
opportunity. This section shows you how to use the <aclass="reference external"href="https://www.google.com/recaptcha/intro/invisible.html">No CAPCHA
reCAPCHA</a> designed by Google. Not only is it
easy to use, it is user-friendly… for humans. A simple checkbox to check, except if Google has
some suspicion, in which case you will have a more difficult test with an image and the usual text
inside. It’s worth pointing out that, as long as Google doesn’t suspect you of being a robot, this
is quite useful, not only for common users, but to screen-reader users, to which reading inside of
an image is pretty difficult, if not impossible. And to top it all, it will be so easy to add in
<h3>Step 1: Obtain a SiteKey and secret from Google<aclass="headerlink"href="#step-1-obtain-a-sitekey-and-secret-from-google"title="Permalink to this headline">¶</a></h3>
<p>The first thing is to ask Google for a way to safely authenticate your website to their service. To
do it, we need to create a site key and a secret. Go to
<aclass="reference external"href="https://www.google.com/recaptcha/admin">https://www.google.com/recaptcha/admin</a> to create such a
site key. It’s quite easy when you have a Google account.</p>
<p>When you have created your site key, save it safely. Also copy your secret key as well. You should
find both information on the web page. Both would contain a lot of letters and figures.</p>
<h3>Step 2: installing and configuring the dedicated Django app<aclass="headerlink"href="#step-2-installing-and-configuring-the-dedicated-django-app"title="Permalink to this headline">¶</a></h3>
<p>Since Evennia runs on Django, the easiest way to add our CAPCHA and perform the proper check is to
<p>And add it to the installed apps in your settings. In your <codeclass="docutils literal notranslate"><spanclass="pre">mygame/server/conf/settings.py</span></code>, you
<h3>Step 3: Adding the CAPCHA to our form<aclass="headerlink"href="#step-3-adding-the-capcha-to-our-form"title="Permalink to this headline">¶</a></h3>
<p>Finally we have to add the CAPCHA to our form. It will be pretty easy too. First, open your
<codeclass="docutils literal notranslate"><spanclass="pre">web/chargen/forms.py</span></code> file. We’re going to add a new field, but hopefully, all the hard work has
been done for us. Update at your convenience, You might end up with something like this:</p>