mirror of
https://github.com/evennia/evennia.git
synced 2026-04-01 13:37:17 +02:00
EGD renamed to EGI. Backwards compatibility preserved for now.
This commit is contained in:
parent
7e0b372273
commit
64db01c7ec
5 changed files with 68 additions and 39 deletions
|
|
@ -1,20 +1,20 @@
|
|||
# Evennia Game Directory Client
|
||||
# Evennia Game Index Client
|
||||
|
||||
Greg Taylor 2016
|
||||
|
||||
This contrib features a client for the [Evennia Game Directory]
|
||||
(http://evennia-game-directory.appspot.com/), a listing of games built on
|
||||
Evennia. By listing your game on the directory, you make it easy for other
|
||||
This contrib features a client for the [Evennia Game Index]
|
||||
(http://evennia-game-index.appspot.com/), a listing of games built on
|
||||
Evennia. By listing your game on the index, you make it easy for other
|
||||
people in the community to discover your creation.
|
||||
|
||||
*Note: Since this is still an early experiment, there is no notion of
|
||||
ownership for a game listing. As a consequence, we rely on the good behavior
|
||||
of our users in the early goings. If the directory is a success, we'll work
|
||||
of our users in the early goings. If the index is a success, we'll work
|
||||
on remedying this.*
|
||||
|
||||
## Listing your Game
|
||||
|
||||
To list your game, you'll need to enable the Evennia Game Directory client.
|
||||
To list your game, you'll need to enable the Evennia Game Index client.
|
||||
Start by `cd`'ing to your game directory. From there, open up
|
||||
`server/conf/server_services_plugins.py`. It might look something like this
|
||||
if you don't have any other optional add-ons enabled:
|
||||
|
|
@ -43,7 +43,7 @@ if you don't have any other optional add-ons enabled:
|
|||
pass
|
||||
|
||||
|
||||
To enable the client, import `EvenniaGameDirService` and fire it up after the
|
||||
To enable the client, import `EvenniaGameIndexService` and fire it up after the
|
||||
Evennia server has finished starting:
|
||||
|
||||
"""
|
||||
|
|
@ -60,7 +60,7 @@ Evennia server has finished starting:
|
|||
services are started last in the Server startup process.
|
||||
"""
|
||||
|
||||
from evennia.contrib.gamedir_client import EvenniaGameDirService
|
||||
from evennia.contrib.egi_client import EvenniaGameIndexService
|
||||
|
||||
def start_plugin_services(server):
|
||||
"""
|
||||
|
|
@ -68,8 +68,8 @@ Evennia server has finished starting:
|
|||
|
||||
server - a reference to the main server application.
|
||||
"""
|
||||
gamedir_service = EvenniaGameDirService()
|
||||
server.services.addService(gamedir_service)
|
||||
egi_service = EvenniaGameIndexService()
|
||||
server.services.addService(egi_service)
|
||||
|
||||
|
||||
Next, configure your game listing by opening up `server/conf/settings.py` and
|
||||
|
|
@ -79,7 +79,7 @@ Next, configure your game listing by opening up `server/conf/settings.py` and
|
|||
# Contrib config
|
||||
######################################################################
|
||||
|
||||
GAME_DIRECTORY_LISTING = {
|
||||
GAME_INDEX_LISTING = {
|
||||
'game_status': 'pre-alpha',
|
||||
# Optional, comment out or remove if N/A
|
||||
'game_website': 'http://my-game.com',
|
||||
|
|
@ -105,7 +105,7 @@ At this point, you should be all set! Simply restart your game and check the
|
|||
server logs for errors. Your listing and some game state will be sent every
|
||||
half hour.
|
||||
|
||||
## Possible GAMEDIR_DIRECTORY_LISTING settings
|
||||
## Possible GAME_INDEX_LISTING settings
|
||||
|
||||
### game_status
|
||||
|
||||
1
evennia/contrib/egi_client/__init__.py
Normal file
1
evennia/contrib/egi_client/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from evennia.contrib.egi_client.service import EvenniaGameIndexService
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import urllib
|
||||
import platform
|
||||
import warnings
|
||||
|
||||
import django
|
||||
from django.conf import settings
|
||||
|
|
@ -17,10 +18,10 @@ from evennia.server.sessionhandler import SESSIONS
|
|||
from evennia.utils import get_evennia_version, logger
|
||||
|
||||
|
||||
class EvenniaGameDirClient(object):
|
||||
class EvenniaGameIndexClient(object):
|
||||
"""
|
||||
This client class is used for gathering and sending game details to the
|
||||
Evennia Game Directory. Since EGD is in the early goings, this isn't
|
||||
Evennia Game Index. Since EGI is in the early goings, this isn't
|
||||
incredibly configurable as far as what is being sent.
|
||||
"""
|
||||
def __init__(self, on_bad_request=None):
|
||||
|
|
@ -28,7 +29,7 @@ class EvenniaGameDirClient(object):
|
|||
:param on_bad_request: Optional callable to trigger when a bad request
|
||||
was sent. This is almost always going to be due to bad config.
|
||||
"""
|
||||
self.report_host = 'http://evennia-game-directory.appspot.com'
|
||||
self.report_host = 'http://evennia-game-index.appspot.com'
|
||||
self.report_path = '/api/v1/game/check_in'
|
||||
self.report_url = self.report_host + self.report_path
|
||||
self.logged_first_connect = False
|
||||
|
|
@ -42,19 +43,19 @@ class EvenniaGameDirClient(object):
|
|||
def send_game_details(self):
|
||||
"""
|
||||
This is where the magic happens. Send details about the game to the
|
||||
Evennia Game Directory.
|
||||
Evennia Game Index.
|
||||
"""
|
||||
status_code, response_body = yield self._form_and_send_request()
|
||||
if status_code == 200:
|
||||
if not self.logged_first_connect:
|
||||
logger.log_infomsg(
|
||||
"Successfully sent game details to Evennia Game Directory.")
|
||||
"Successfully sent game details to Evennia Game Index.")
|
||||
self.logged_first_connect = True
|
||||
return
|
||||
# At this point, either EGD is having issues or the payload we sent
|
||||
# is improperly formed (probably due to mis-configuration).
|
||||
logger.log_errmsg(
|
||||
'Failed to send game details to Evennia Game Directory. HTTP '
|
||||
'Failed to send game details to Evennia Game Index. HTTP '
|
||||
'status code was %s. Message was: %s' % (status_code, response_body)
|
||||
)
|
||||
if status_code == 400 and self._on_bad_request:
|
||||
|
|
@ -63,28 +64,37 @@ class EvenniaGameDirClient(object):
|
|||
# to EGD, though.
|
||||
self._on_bad_request()
|
||||
|
||||
def _get_config_dict(self):
|
||||
egi_config = getattr(settings, 'GAME_DIRECTORY_LISTING', None)
|
||||
if egi_config:
|
||||
warnings.warn(
|
||||
"settings.GAME_DIRECTORY_LISTING is deprecated. Rename this to "
|
||||
"GAME_INDEX_LISTING in your settings file.", DeprecationWarning)
|
||||
return egi_config
|
||||
return settings.GAME_INDEX_LISTING
|
||||
|
||||
def _form_and_send_request(self):
|
||||
agent = Agent(reactor, pool=self._conn_pool)
|
||||
headers = {
|
||||
'User-Agent': ['Evennia Game Directory Client'],
|
||||
'User-Agent': ['Evennia Game Index Client'],
|
||||
'Content-Type': ['application/x-www-form-urlencoded'],
|
||||
}
|
||||
gd_config = settings.GAME_DIRECTORY_LISTING
|
||||
egi_config = self._get_config_dict()
|
||||
# We are using `or` statements below with dict.get() to avoid sending
|
||||
# stringified 'None' values to the server.
|
||||
values = {
|
||||
# Game listing stuff
|
||||
'game_name': settings.SERVERNAME,
|
||||
'game_status': gd_config['game_status'],
|
||||
'game_website': gd_config.get('game_website') or '',
|
||||
'short_description': gd_config['short_description'],
|
||||
'long_description': gd_config.get('long_description') or '',
|
||||
'listing_contact': gd_config['listing_contact'],
|
||||
'game_status': egi_config['game_status'],
|
||||
'game_website': egi_config.get('game_website') or '',
|
||||
'short_description': egi_config['short_description'],
|
||||
'long_description': egi_config.get('long_description') or '',
|
||||
'listing_contact': egi_config['listing_contact'],
|
||||
|
||||
# How to play
|
||||
'telnet_hostname': gd_config.get('telnet_hostname') or '',
|
||||
'telnet_port': gd_config.get('telnet_port') or '',
|
||||
'web_client_url': gd_config.get('web_client_url') or '',
|
||||
'telnet_hostname': egi_config.get('telnet_hostname') or '',
|
||||
'telnet_port': egi_config.get('telnet_port') or '',
|
||||
'web_client_url': egi_config.get('web_client_url') or '',
|
||||
|
||||
# Game stats
|
||||
'connected_player_count': SESSIONS.player_count(),
|
||||
|
|
@ -2,29 +2,31 @@ from twisted.internet import reactor
|
|||
from twisted.internet.task import LoopingCall
|
||||
from twisted.application.service import Service
|
||||
|
||||
from evennia.contrib.gamedir_client.client import EvenniaGameDirClient
|
||||
from evennia.contrib.egi_client.client import EvenniaGameIndexClient
|
||||
from evennia.utils import logger
|
||||
|
||||
# How many seconds to wait before triggering the first EGD check-in.
|
||||
# How many seconds to wait before triggering the first EGI check-in.
|
||||
_FIRST_UPDATE_DELAY = 10
|
||||
# How often to sync to the server
|
||||
_CLIENT_UPDATE_RATE = 60 * 30
|
||||
|
||||
|
||||
class EvenniaGameDirService(Service):
|
||||
class EvenniaGameIndexService(Service):
|
||||
"""
|
||||
Twisted Service that contains a LoopingCall for sending details on a
|
||||
game to the Evennia Game Directory.
|
||||
game to the Evennia Game Index.
|
||||
"""
|
||||
name = 'GameDirectoryClient'
|
||||
# We didn't stick the Evennia prefix on here because it'd get marked as
|
||||
# a core system service.
|
||||
name = 'GameIndexClient'
|
||||
|
||||
def __init__(self):
|
||||
self.client = EvenniaGameDirClient(
|
||||
self.client = EvenniaGameIndexClient(
|
||||
on_bad_request=self._die_on_bad_request)
|
||||
self.loop = LoopingCall(self.client.send_game_details)
|
||||
|
||||
def startService(self):
|
||||
super(EvenniaGameDirService, self).startService()
|
||||
super(EvenniaGameIndexService, self).startService()
|
||||
# TODO: Check to make sure that the client is configured.
|
||||
# Start the loop, but only after a short delay. This allows the
|
||||
# portal and the server time to sync up as far as total player counts.
|
||||
|
|
@ -36,16 +38,16 @@ class EvenniaGameDirService(Service):
|
|||
if self.running == 0:
|
||||
# @reload errors if we've stopped this service.
|
||||
return
|
||||
super(EvenniaGameDirService, self).stopService()
|
||||
super(EvenniaGameIndexService, self).stopService()
|
||||
self.loop.stop()
|
||||
|
||||
def _die_on_bad_request(self):
|
||||
"""
|
||||
If it becomes apparent that our configuration is generating improperly
|
||||
formed messages to EGD, we don't want to keep sending bad messages.
|
||||
formed messages to EGI, we don't want to keep sending bad messages.
|
||||
Stop the service so we're not wasting resources.
|
||||
"""
|
||||
logger.log_infomsg(
|
||||
"Shutting down Evennia Game Directory client service due to "
|
||||
"Shutting down Evennia Game Index client service due to "
|
||||
"invalid configuration.")
|
||||
self.stopService()
|
||||
|
|
@ -1 +1,17 @@
|
|||
from evennia.contrib.gamedir_client.service import EvenniaGameDirService
|
||||
import warnings
|
||||
|
||||
from evennia.contrib.egi_client import EvenniaGameIndexService
|
||||
|
||||
|
||||
class EvenniaGameDirService(EvenniaGameIndexService):
|
||||
"""
|
||||
This is a compatibility shim to get us through the EGD to EGI rename.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
warnings.warn(
|
||||
"evennia.contrib.gamedir_client is deprecated and pending immediate "
|
||||
"removal. Please update your game's server_services_plugins.py to use "
|
||||
"evennia.contrib.egi_client.EvenniaGameIndexService instead.",
|
||||
DeprecationWarning)
|
||||
super(EvenniaGameDirService, self).__init__()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue