Moved webserver to Server and set up the webclient to work as a stand-alone program on the Portal side. The website link to the webclient is currently pointing to the wrong process, some way to direct that transparently to the Portal-side is needed.
This commit is contained in:
parent
812bdb0f73
commit
94f50fcf33
7 changed files with 77 additions and 46 deletions
|
|
@ -16,7 +16,7 @@ if os.name == 'nt':
|
||||||
|
|
||||||
from twisted.application import internet, service
|
from twisted.application import internet, service
|
||||||
from twisted.internet import protocol, reactor
|
from twisted.internet import protocol, reactor
|
||||||
from twisted.web import server, static
|
from twisted.web import server
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.utils.utils import get_evennia_version, mod_import, make_iter
|
from src.utils.utils import get_evennia_version, mod_import, make_iter
|
||||||
from src.server.portal.portalsessionhandler import PORTAL_SESSIONS
|
from src.server.portal.portalsessionhandler import PORTAL_SESSIONS
|
||||||
|
|
@ -240,29 +240,9 @@ if SSH_ENABLED:
|
||||||
|
|
||||||
if WEBSERVER_ENABLED:
|
if WEBSERVER_ENABLED:
|
||||||
|
|
||||||
# Start a django-compatible webserver.
|
# Start a reverse proxy to relay data to the Server-side webserver
|
||||||
|
|
||||||
from twisted.python import threadpool
|
from twisted.web import proxy
|
||||||
from src.server.webserver import DjangoWebRoot, WSGIWebServer
|
|
||||||
|
|
||||||
# start a thread pool and define the root url (/) as a wsgi resource
|
|
||||||
# recognized by Django
|
|
||||||
threads = threadpool.ThreadPool()
|
|
||||||
web_root = DjangoWebRoot(threads)
|
|
||||||
# point our media resources to url /media
|
|
||||||
web_root.putChild("media", static.File(settings.MEDIA_ROOT))
|
|
||||||
|
|
||||||
webclientstr = ""
|
|
||||||
if WEBCLIENT_ENABLED:
|
|
||||||
# create ajax client processes at /webclientdata
|
|
||||||
from src.server.portal.webclient import WebClient
|
|
||||||
webclient = WebClient()
|
|
||||||
webclient.sessionhandler = PORTAL_SESSIONS
|
|
||||||
web_root.putChild("webclientdata", webclient)
|
|
||||||
|
|
||||||
webclientstr = "/client"
|
|
||||||
|
|
||||||
web_site = server.Site(web_root, logPath=settings.HTTP_LOG_FILE)
|
|
||||||
|
|
||||||
for interface in WEBSERVER_INTERFACES:
|
for interface in WEBSERVER_INTERFACES:
|
||||||
if ":" in interface:
|
if ":" in interface:
|
||||||
|
|
@ -273,12 +253,22 @@ if WEBSERVER_ENABLED:
|
||||||
ifacestr = "-%s" % interface
|
ifacestr = "-%s" % interface
|
||||||
for port in WEBSERVER_PORTS:
|
for port in WEBSERVER_PORTS:
|
||||||
pstring = "%s:%s" % (ifacestr, port)
|
pstring = "%s:%s" % (ifacestr, port)
|
||||||
# create the webserver
|
web_root = proxy.ReverseProxyResource("localhost", port, '')
|
||||||
webserver = WSGIWebServer(threads, port, web_site, interface=interface)
|
|
||||||
webserver.setName('EvenniaWebServer%s' % pstring)
|
|
||||||
PORTAL.services.addService(webserver)
|
|
||||||
|
|
||||||
print " webserver%s%s: %s" % (webclientstr, ifacestr, port)
|
webclientstr = ""
|
||||||
|
if WEBCLIENT_ENABLED:
|
||||||
|
# create ajax client processes at /webclientdata
|
||||||
|
from src.server.portal.webclient import WebClient
|
||||||
|
webclient = WebClient()
|
||||||
|
webclient.sessionhandler = PORTAL_SESSIONS
|
||||||
|
web_root.putChild("webclientdata", webclient)
|
||||||
|
webclientstr = "/client"
|
||||||
|
|
||||||
|
web_root = server.Site(web_root, logPath=settings.HTTP_LOG_FILE)
|
||||||
|
proxy_service = internet.TCPServer(port+1, web_root)
|
||||||
|
proxy_service.setName('EvenniaWebProxy%s' % pstring)
|
||||||
|
PORTAL.services.addService(proxy_service)
|
||||||
|
print " webproxy%s%s: %s" % (webclientstr, ifacestr, port+1)
|
||||||
|
|
||||||
for plugin_module in PORTAL_SERVICES_PLUGIN_MODULES:
|
for plugin_module in PORTAL_SERVICES_PLUGIN_MODULES:
|
||||||
# external plugin services to start
|
# external plugin services to start
|
||||||
|
|
@ -286,7 +276,6 @@ for plugin_module in PORTAL_SERVICES_PLUGIN_MODULES:
|
||||||
|
|
||||||
print '-' * 50 # end of terminal output
|
print '-' * 50 # end of terminal output
|
||||||
|
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
# Windows only: Set PID file manually
|
# Windows only: Set PID file manually
|
||||||
f = open(os.path.join(settings.GAME_DIR, 'portal.pid'), 'w')
|
f = open(os.path.join(settings.GAME_DIR, 'portal.pid'), 'w')
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ if os.name == 'nt':
|
||||||
# For Windows batchfile we need an extra path insertion here.
|
# For Windows batchfile we need an extra path insertion here.
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(
|
sys.path.insert(0, os.path.dirname(os.path.dirname(
|
||||||
os.path.dirname(os.path.abspath(__file__)))))
|
os.path.dirname(os.path.abspath(__file__)))))
|
||||||
|
from twisted.web import server, static
|
||||||
from twisted.application import internet, service
|
from twisted.application import internet, service
|
||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
import django
|
import django
|
||||||
|
|
@ -57,10 +57,15 @@ AMP_HOST = settings.AMP_HOST
|
||||||
AMP_PORT = settings.AMP_PORT
|
AMP_PORT = settings.AMP_PORT
|
||||||
AMP_INTERFACE = settings.AMP_INTERFACE
|
AMP_INTERFACE = settings.AMP_INTERFACE
|
||||||
|
|
||||||
|
WEBSERVER_PORTS = settings.WEBSERVER_PORTS
|
||||||
|
WEBSERVER_INTERFACES = settings.WEBSERVER_INTERFACES
|
||||||
|
|
||||||
# server-channel mappings
|
# server-channel mappings
|
||||||
|
WEBSERVER_ENABLED = settings.WEBSERVER_ENABLED and WEBSERVER_PORTS and WEBSERVER_INTERFACES
|
||||||
IMC2_ENABLED = settings.IMC2_ENABLED
|
IMC2_ENABLED = settings.IMC2_ENABLED
|
||||||
IRC_ENABLED = settings.IRC_ENABLED
|
IRC_ENABLED = settings.IRC_ENABLED
|
||||||
RSS_ENABLED = settings.RSS_ENABLED
|
RSS_ENABLED = settings.RSS_ENABLED
|
||||||
|
WEBCLIENT_ENABLED = settings.WEBCLIENT_ENABLED
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
|
|
@ -334,6 +339,37 @@ if AMP_ENABLED:
|
||||||
amp_service.setName("EvenniaPortal")
|
amp_service.setName("EvenniaPortal")
|
||||||
EVENNIA.services.addService(amp_service)
|
EVENNIA.services.addService(amp_service)
|
||||||
|
|
||||||
|
if WEBSERVER_ENABLED:
|
||||||
|
|
||||||
|
# Start a django-compatible webserver.
|
||||||
|
|
||||||
|
from twisted.python import threadpool
|
||||||
|
from src.server.webserver import DjangoWebRoot, WSGIWebServer
|
||||||
|
|
||||||
|
# start a thread pool and define the root url (/) as a wsgi resource
|
||||||
|
# recognized by Django
|
||||||
|
threads = threadpool.ThreadPool()
|
||||||
|
web_root = DjangoWebRoot(threads)
|
||||||
|
# point our media resources to url /media
|
||||||
|
web_root.putChild("media", static.File(settings.MEDIA_ROOT))
|
||||||
|
web_site = server.Site(web_root, logPath=settings.HTTP_LOG_FILE)
|
||||||
|
|
||||||
|
for interface in WEBSERVER_INTERFACES:
|
||||||
|
if ":" in interface:
|
||||||
|
print " iPv6 interfaces not yet supported"
|
||||||
|
continue
|
||||||
|
ifacestr = ""
|
||||||
|
if interface != '0.0.0.0' or len(WEBSERVER_INTERFACES) > 1:
|
||||||
|
ifacestr = "-%s" % interface
|
||||||
|
for port in WEBSERVER_PORTS:
|
||||||
|
pstring = "%s:%s" % (ifacestr, port)
|
||||||
|
# create the webserver
|
||||||
|
webserver = WSGIWebServer(threads, port, web_site, interface=interface)
|
||||||
|
webserver.setName('EvenniaWebServer%s' % pstring)
|
||||||
|
EVENNIA.services.addService(webserver)
|
||||||
|
|
||||||
|
print " webserver%s: %s" % (ifacestr, port)
|
||||||
|
|
||||||
if IRC_ENABLED:
|
if IRC_ENABLED:
|
||||||
|
|
||||||
# IRC channel connections
|
# IRC channel connections
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ This structures the url tree for the news application.
|
||||||
It is imported from the root handler, game.web.urls.py.
|
It is imported from the root handler, game.web.urls.py.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.conf.urls.defaults import *
|
from django.conf.urls import *
|
||||||
|
|
||||||
urlpatterns = patterns('src.web.news.views',
|
urlpatterns = patterns('src.web.news.views',
|
||||||
(r'^show/(?P<entry_id>\d+)/$', 'show_news'),
|
(r'^show/(?P<entry_id>\d+)/$', 'show_news'),
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# http://diveintopython.org/regular_expressions/street_addresses.html#re.matching.2.3
|
# http://diveintopython.org/regular_expressions/street_addresses.html#re.matching.2.3
|
||||||
#
|
#
|
||||||
|
|
||||||
from django.conf.urls.defaults import *
|
from django.conf.urls import *
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.views.generic import RedirectView
|
from django.views.generic import RedirectView
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ page and serve it eventual static content.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response, redirect
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.server.sessionhandler import SESSIONS
|
from src.server.sessionhandler import SESSIONS
|
||||||
|
|
@ -15,6 +15,12 @@ def webclient(request):
|
||||||
Webclient page template loading.
|
Webclient page template loading.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# analyze request to find which port we are on
|
||||||
|
if int(request.META["SERVER_PORT"]) == 8000:
|
||||||
|
# we relay webclient to the portal port
|
||||||
|
print "Called from port 8000!"
|
||||||
|
#return redirect("http://localhost:8001/webclient/", permanent=True)
|
||||||
|
|
||||||
# as an example we send the number of connected players to the template
|
# as an example we send the number of connected players to the template
|
||||||
pagevars = {'num_players_connected': SESSIONS.player_count()}
|
pagevars = {'num_players_connected': SESSIONS.player_count()}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ This structures the (simple) structure of the
|
||||||
webpage 'application'.
|
webpage 'application'.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.conf.urls.defaults import *
|
from django.conf.urls import *
|
||||||
|
|
||||||
urlpatterns = patterns('src.web.website.views',
|
urlpatterns = patterns('src.web.website.views',
|
||||||
(r'^$', 'page_index'),
|
(r'^$', 'page_index'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue