Evennia now runs on its own Twisted webserver (no need for testserver or Apache if you don't want to). Evennia now also has an ajax long-polling web client running from Twisted. The web client requires no extra dependencies beyond jQuery which is included. The src/server structure has been r

cleaned up and rewritten to make it easier to add new protocols in the future - all new protocols need to inherit from server.session.Session, whi
ch implements a set of hooks that Evennia uses to communicate. The current web client protocol is functional but does not implement any of rcaskey
's suggestions as of yet - it uses a separate data object passed through msg() to communicate between the server and the various protocols. Also the client itself could probably need cleanup and 'prettification'. The fact that the system runs a hybrid of Django and Twisted, getting the best of both worlds should allow for many possibilities in the future. /Griatch
This commit is contained in:
Griatch 2010-12-07 02:34:59 +00:00
parent ecefbfac01
commit 251f94aa7a
118 changed files with 9049 additions and 593 deletions

View file

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/css/base.css

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/css/changelists.css

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/css/dashboard.css

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/css/forms.css

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/css/ie.css

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/css/login.css

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/css/rtl.css

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/css/widgets.css

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/arrow-down.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/arrow-up.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/changelist-bg.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/changelist-bg_rtl.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/chooser-bg.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/chooser_stacked-bg.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/default-bg-reverse.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/default-bg.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/deleted-overlay.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon-no.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon-unknown.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon-yes.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon_addlink.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon_alert.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon_calendar.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon_changelink.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon_clock.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon_deletelink.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon_error.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon_searchbox.png

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/icon_success.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/inline-delete-8bit.png

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/inline-delete.png

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/inline-restore-8bit.png

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/inline-restore.png

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/inline-splitter-bg.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/nav-bg-grabber.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/nav-bg-reverse.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/nav-bg.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/selector-add.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/selector-addall.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/selector-remove.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/selector-removeall.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/selector-search.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/selector_stacked-add.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/selector_stacked-remove.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/tool-left.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/tool-left_over.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/tool-right.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/tool-right_over.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/tooltag-add.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/tooltag-add_over.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/tooltag-arrowright.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/admin/tooltag-arrowright_over.gif

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/gis/move_vertex_off.png

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/img/gis/move_vertex_on.png

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/LICENSE-JQUERY.txt

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/SelectBox.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/SelectFilter2.js

View file

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/actions.js

1
src/web/media/admin/js/actions.min.js vendored Symbolic link
View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/actions.min.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/admin/DateTimeShortcuts.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/admin/RelatedObjectLookups.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/admin/ordering.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/calendar.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/collapse.js

1
src/web/media/admin/js/collapse.min.js vendored Symbolic link
View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/collapse.min.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/compress.py

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/core.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/dateparse.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/getElementsBySelector.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/inlines.js

1
src/web/media/admin/js/inlines.min.js vendored Symbolic link
View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/inlines.min.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/jquery.init.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/prepopulate.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/prepopulate.min.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/timeparse.js

View file

@ -0,0 +1 @@
/usr/share/pyshared/django/contrib/admin/media/js/urlify.js

View file

@ -0,0 +1,79 @@
/*
Style sheet for Evennia's web client.
Possibly this should somehow be incoorporated with the
overall website theme in the future?
*/
body{
background:#000;
color:#fff;
font-size:.9em;
}
/*Base style for new messages in the main message area.*/
.msg{
background:#000;
padding:.2em;
border-bottom:1px #000 solid
}
/*Utility messages (green)*/
.sys{
color:#0f0;
}
/*Messages echoed back after input*/
.inp{
color:#555;
}
/*Messages returned from the server (most messages) */
.out{
color:#aaa;
}
/*Error messages (red)*/
.err{
color:#f00;
}
/*Container surrounding entire chat*/
#wrapper{
margin-left:10px;
}
/*Main scrolling message area*/
#messagewindow{
overflow:auto;
height:400px;
bottom:10px
}
/*Input area containing input field and button*/
#inputform{
position:fixed;
bottom:0px;
}
/*Input field */
#inputfield{
background:#000;
color:#fff;
font-size:.9em;
width:120ex;
border:1px solid;
padding:4px;
border-color:#555;
outline-style:none;
margin-left:10px;
}
/*Input 'send' button*/
#inputsend{
background:#000;
color:#fff;
font-size:.9em;
border:1px solid;
padding: 3px;
border-color:#555;
}
/*No javascript warning*/
#noscript{
color:f00;
}
/*Example player count display */
#playercount{
margin-left:10px;
color: #555;
}

View file

@ -0,0 +1,212 @@
/*
Evennia ajax webclient (javascript component)
The client is composed of several parts:
templates/webclient.html - the main page
webclient/views.py - the django view serving the template (based on urls.py pattern)
src/server/webclient.py - the server component receiving requests from the client
this file - the javascript component handling dynamic ajax content
This implements an ajax mud client for use with Evennia, using jQuery
for simplicity. It communicates with the Twisted server on the address
/webclientdata through POST requests. Each request must at least
contain the 'mode' of the request to be handled by the protocol:
mode 'receive' - tell the server that we are ready to receive data. This is a
long-polling (comet-style) request since the server
will not reply until it actually has data available.
The returned data object has two variables 'msg' and 'data'
where msg should be output and 'data' is an arbitrary piece
of data the server and client understands (not used in default
client).
mode 'input' - the user has input data on some form. The POST request
should also contain variables 'msg' and 'data' where
the 'msg' is a string and 'data' is an arbitrary piece
of data from the client that the server knows how to
deal with (not used in this example client).
mode 'init' - starts the connection. All setup the server is requered to do
should happen at this point. The server returns a data object
with the 'msg' property containing the server address.
*/
// jQuery must be imported by the calling html page before this script
// (it comes with Evennia, in media/javascript/jquery-<version>.js)
// There are plenty of help on using the jQuery library on http://jquery.com/
// Server communications
function webclient_receive(){
// This starts an asynchronous long-polling request. It will either timeout
// or receive data from the 'receivedata' url. In both cases a new request will
// immediately be started.
$.ajax({
type: "POST",
url: "/webclientdata",
async: true, // Turns off browser loading indicator
cache: false, // Forces browser reload independent of cache
timeout:30000, // Timeout in ms. After this time a new long-poll will be started.
dataType:"json",
data: {mode:'receive'},
// callback methods
success: function(data){ // called when request to waitreceive completes
msg_display("out", data.msg); // Add response to the message area
webclient_receive(); // immediately start a new request
},
error: function(XMLHttpRequest, textStatus, errorThrown){
webclient_receive(); // A possible timeout. Resend request immediately
},
});
};
function webclient_input(){
// Send an input from the player to the server
var outmsg = $("#inputfield").val() // get data from form
$.ajax({
type: "POST",
url: "/webclientdata",
async: true,
cache: false,
timeout: 30000,
data: {mode:'input', msg:outmsg, data:'NoData'},
//callback methods
success: function(data){
//if (outmsg.length > 0 ) msg_display("inp", outmsg) // echo input on command line
history_add(outmsg);
HISTORY_POS = 0;
$('#inputform')[0].reset() // clear input field
},
error: function(XMLHttpRequest, textStatus, errorThrown){
msg_display("err", "Error: Server returned an error or timed out. Try resending.");
},
})
}
function webclient_init(){
// Start the connection by making sure the server is ready
$.ajax({
type: "POST",
url: "/webclientdata",
async: true,
cache: false,
timeout: 50000,
dataType:"json",
data: {mode:'init'},
// callback methods
success: function(data){ // called when request to initdata completes
$("#connecting").remove() // remove the "connecting ..." message.
setTimeout(function () { // a small timeout to stop 'loading' indicator in Chrome
$("#playercount").fadeOut('slow');
}, 10000);
// Report success
msg_display('sys',"Connected to " + data.msg + ".")
// Wait for input
webclient_receive();
},
error: function(XMLHttpRequest, textStatus, errorThrown){
msg_display("err", "Connection error ..." + " (" + errorThrown + ")");
setTimeout('webclient_receive()', 15000); // try again after 15 seconds
},
});
}
// Display messages
function msg_display(type, msg){
// Add a div to the message window.
// type givews the class of div to use.
$("#messagewindow").append(
"<div class='msg "+ type +"'>"+ msg +"</div>");
// scroll message window to bottom
$('#messagewindow').animate({scrollTop: $('#messagewindow')[0].scrollHeight});
}
// Input history mechanism
var HISTORY_MAX_LENGTH = 21
var HISTORY = new Array();
HISTORY[0] = '';
var HISTORY_POS = 0;
function history_step_back() {
// step backwards in history stack
HISTORY_POS = Math.min(++HISTORY_POS, HISTORY.length-1);
return HISTORY[HISTORY.length-1 - HISTORY_POS];
}
function history_step_fwd() {
// step forward in history stack
HISTORY_POS = Math.max(--HISTORY_POS, 0);
return HISTORY[HISTORY.length-1 - HISTORY_POS];
}
function history_add(input) {
// add an entry to history
if (input != HISTORY[HISTORY.length-1]) {
if (HISTORY.length >= HISTORY_MAX_LENGTH) {
HISTORY.shift() // kill oldest history entry
}
HISTORY[HISTORY.length-1] = input
HISTORY[HISTORY.length] = ''
}
}
// Catching keyboard shortcuts
$(document).keypress( function(event) {
var code = event.keyCode ? event.keyCode : event.which
// always focus input field
$("#inputfield")[0].focus();
if (code == 13) { // Enter key
webclient_input();
event.preventDefault();
return false;
}
else {
if (code == 38) { // arrow up
$("#inputfield").val(function(index, value){
return history_step_back();
});
}
else if (code == 40) { // arrow down
$("#inputfield").val(function(index, value){
return history_step_fwd();
});
}
}
});
// handler to avoid double-clicks until the ajax request finishes
$("#inputsend").one("click", webclient_input)
// Callback function - called when page has finished loading (gets things going)
$(document).ready(function(){
// remove the "no javascript" warning, since we obviously have javascript
$('#noscript').remove()
// set sizes of elements and reposition them
var win_h = $(document).height();
var win_w = $('#wrapper').width();
var inp_h = $('#inputform').height();
var inp_w = $('#inputsend').width()
$("#messagewindow").css({'height':win_h-inp_h - 20});
$("#inputfield").css({'width':win_w-inp_w - 20});
setTimeout(function () { // a small timeout to stop 'loading' indicator in Chrome
webclient_init();
}, 500);
});

7179
src/web/media/javascript/jquery-1.4.4.js vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block sidebar %}
{% endblock %}
{% block header_ext %}
{% endblock %}
{% block content %}
<h1>Error 404 - Page not found</h1>
{% endblock %}

View file

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block sidebar %}
{% endblock %}
{% block header_ext %}
{% endblock %}
{% block content %}
<h1>Error 500 - A Server Error was encountered.</h1>
{% endblock %}

View file

@ -57,11 +57,15 @@
</div>
<div class="subHeader">
<span class="doNotDisplay">Navigation:</span>
<!--span class="doNotDisplay">Navigation:</span-->
<a href="/">Home</a> |
<a href="http://code.evennia.com/">About</a> |
<a href="http://code.google.com/p/evennia/wiki/Index">Documentation</a> |
<a href="/admin/">Admin Interface</a>
{% if webclient_enabled %}
| <a href="/webclient">Play Online</a>
{% endif %}
</div>
</div>

View file

@ -10,19 +10,23 @@
<div class="rowOfBoxes">
<div class="twoThirds noBorderOnLeft">
<h1>Welcome!</h1>
<p>Welcome to your new installation of Evennia, your friendly
<p>Welcome to your new installation of <a href="http://evennia.com">Evennia</a>, your friendly
neighborhood next-generation MUD server. You are looking at Evennia's web
presence, which can be expanded to a full-fledged site as
needed. Through the <a href="/admin">admin interface</a> you can view and edit the
database without logging into the game. Also take your time to
database without logging into the game.
{% if webclient_enabled %}
You can also connect to the game directly from your browser using our
<a href='/webclient'>online client</a>!<br></br>
{% endif %}
For more info, take your time to
peruse our extensive online <a href="http://code.google.com/p/evennia/wiki/Index">documentation</a>.
<p>
Should you have any questions, concerns, bug reports, or
if you want to help out, don't hesitate to come join the
<a href="http://evennia.com">Evennia community</a> and get
<a href="http://evennia.com/discussions">Evennia community</a> and get
your voice heard!
</p>
<i>(To edit this file, go to game/web/templates/prosimii/index.html.)</i>
</div>
<div class="oneThird">

View file

@ -0,0 +1,37 @@
<html>
<head>
<title>Evennia web MUD client</title>
<!--CSS style sheet -->
<link rel='stylesheet' type="text/css" media="screen" href="/media/css/webclient.css">
<!-- Importing the jQuery javascript library -->
<!--script src="http://code.jquery.com/jquery-1.4.4.js" type="text/javascript" charset="utf-8"></script-->
<script src="/media/javascript/jquery-1.4.4.js" type="text/javascript" charset="utf-8"></script>
<!-- Importing the Evennia ajax webclient component (requires jQuery) -->
<script src="/media/javascript/evennia_webclient.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="wrapper">
<div id="messagewindow">
<!--javascript kills this when page has finished loading: -->
<span id="connecting"> Connecting ...</span>
<!--this is supplied by django view - webclient/views.py: -->
<span id="noscript"><h3>Javascript Error: The Evennia MUD client requires that you have Javascript activated.</h3>
<p>Turn off eventual script blockers and/or switch to a web
browser supporting javascript.</p>
</span>
</div>
<form id="inputform">
<span id="playercount">Logged in Players: {{num_players_connected}}</span> <br>
<input type="text" id="inputfield" autocomplete='off'><input id="inputsend" type="button" value="send" onClick="sendMsg()">
</form>
</div>
</body>
</html>

View file

@ -33,10 +33,12 @@ urlpatterns = patterns('',
# Admin interface
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
#url(r'^admin/(.*)', admin.site.root, name='admin'),
# favicon
url(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url':'/media/images/favicon.ico'}),
# ajax stuff
url(r'^webclient/',include('src.web.webclient.urls')),
)
# If you'd like to serve media files via Django (strongly not recommended!),

View file

@ -42,5 +42,6 @@ def general_context(request):
'evennia_entityapps': GAME_ENTITIES,
'evennia_setupapps': GAME_SETUP,
'evennia_connectapps': CONNECTIONS,
'evennia_websiteapps':WEBSITE
'evennia_websiteapps':WEBSITE,
"webclient_enabled" : settings.WEBCLIENT_ENABLED
}

View file

View file

@ -0,0 +1,7 @@
#
# Define database entities for the app.
#
from django.db import models

10
src/web/webclient/urls.py Normal file
View file

@ -0,0 +1,10 @@
"""
This structures the (simple) structure of the
webpage 'application'.
"""
from django.views.generic.simple import direct_to_template
from django.conf.urls.defaults import *
urlpatterns = patterns('',
url(r'^$', 'src.web.webclient.views.webclient'),)
#url(r'^$', direct_to_template, {'template': 'webclient.html'}),)

View file

@ -0,0 +1,23 @@
"""
This contains a simple view for rendering the webclient
page and serve it eventual static content.
"""
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.conf import settings
from src.server import sessionhandler
from src.config.models import ConfigValue
def webclient(request):
"""
Webclient page template loading.
"""
# as an example we send the number of connected players to the template
pagevars = {'num_players_connected': ConfigValue.objects.conf('nr_sessions')}
context_instance = RequestContext(request)
return render_to_response('webclient.html', pagevars, context_instance)

View file

@ -1,3 +1,11 @@
"""
This file contains the generic, assorted views that don't fall under one of
the other applications. Views are django's way of processing e.g. html
templates on the fly.
"""
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib.auth.models import User
@ -9,11 +17,6 @@ from src.typeclasses.models import TypedObject
from src.players.models import PlayerDB
from src.web.news.models import NewsEntry
"""
This file contains the generic, assorted views that don't fall under one of
the other applications.
"""
def page_index(request):
"""
Main root page.
@ -30,7 +33,7 @@ def page_index(request):
exits = ObjectDB.objects.get_objs_with_attr('_destination')
rooms = [room for room in ObjectDB.objects.filter(db_home=None) if room not in exits]
pagevars = {
"page_title": "Front Page",
"news_entries": news_entries,