mirror of
https://github.com/evennia/evennia.git
synced 2026-03-21 15:26:30 +01:00
Indentation change 3-4 spaces.
Possible files that need to be cleanedup; commands/info.py:cmd_list commands/general.py:cmd_who commands/comsys.py:cmd_who cmdtable.py ansi.py
This commit is contained in:
parent
740d715c72
commit
3fe644ef17
31 changed files with 1856 additions and 1856 deletions
138
ansi.py
138
ansi.py
|
|
@ -3,92 +3,92 @@ import re
|
|||
ANSI related stuff.
|
||||
"""
|
||||
ansi = {}
|
||||
ansi["beep"] = "\07"
|
||||
ansi["beep"] = "\07"
|
||||
ansi["escape"] = "\033"
|
||||
ansi["normal"] = "\033[0m"
|
||||
|
||||
ansi["underline"] = "\033[4m"
|
||||
ansi["hilite"] = "\033[1m"
|
||||
ansi["blink"] = "\033[5m"
|
||||
ansi["inverse"] = "\033[7m"
|
||||
ansi["inv_hilite"] = "\033[1;7m"
|
||||
ansi["inv_blink"] = "\033[7;5m"
|
||||
ansi["blink_hilite"] = "\033[1;5m"
|
||||
ansi["underline"] = "\033[4m"
|
||||
ansi["hilite"] = "\033[1m"
|
||||
ansi["blink"] = "\033[5m"
|
||||
ansi["inverse"] = "\033[7m"
|
||||
ansi["inv_hilite"] = "\033[1;7m"
|
||||
ansi["inv_blink"] = "\033[7;5m"
|
||||
ansi["blink_hilite"] = "\033[1;5m"
|
||||
ansi["inv_blink_hilite"] = "\033[1;5;7m"
|
||||
|
||||
# Foreground colors
|
||||
ansi["black"] = "\033[30m"
|
||||
ansi["red"] = "\033[31m"
|
||||
ansi["green"] = "\033[32m"
|
||||
ansi["black"] = "\033[30m"
|
||||
ansi["red"] = "\033[31m"
|
||||
ansi["green"] = "\033[32m"
|
||||
ansi["yellow"] = "\033[33m"
|
||||
ansi["blue"] = "\033[34m"
|
||||
ansi["blue"] = "\033[34m"
|
||||
ansi["magenta"] = "\033[35m"
|
||||
ansi["cyan"] = "\033[36m"
|
||||
ansi["white"] = "\033[37m"
|
||||
ansi["cyan"] = "\033[36m"
|
||||
ansi["white"] = "\033[37m"
|
||||
|
||||
# Background colors
|
||||
ansi["back_black"] = "\033[40m"
|
||||
ansi["back_red"] = "\033[41m"
|
||||
ansi["back_green"] = "\033[42m"
|
||||
ansi["back_black"] = "\033[40m"
|
||||
ansi["back_red"] = "\033[41m"
|
||||
ansi["back_green"] = "\033[42m"
|
||||
ansi["back_yellow"] = "\033[43m"
|
||||
ansi["back_blue"] = "\033[44m"
|
||||
ansi["back_blue"] = "\033[44m"
|
||||
ansi["back_magenta"] = "\033[45m"
|
||||
ansi["back_cyan"] = "\033[46m"
|
||||
ansi["back_white"] = "\033[47m"
|
||||
ansi["back_cyan"] = "\033[46m"
|
||||
ansi["back_white"] = "\033[47m"
|
||||
|
||||
# Formatting Characters
|
||||
ansi["return"] = "\r\n"
|
||||
ansi["tab"] = "\t"
|
||||
ansi["tab"] = "\t"
|
||||
ansi["space"] = " "
|
||||
|
||||
def parse_ansi(string, strip_ansi=False, strip_formatting=False):
|
||||
"""
|
||||
Parses a string, subbing color codes as needed.
|
||||
"""
|
||||
if strip_formatting:
|
||||
char_return = ""
|
||||
char_tab = ""
|
||||
char_space = ""
|
||||
else:
|
||||
char_return = ansi["return"]
|
||||
char_tab = ansi["tab"]
|
||||
char_space = ansi["space"]
|
||||
|
||||
ansi_subs = [
|
||||
(r'%r', char_return),
|
||||
(r'%t', char_tab),
|
||||
(r'%b', char_space),
|
||||
(r'%cf', ansi["blink"]),
|
||||
(r'%ci', ansi["inverse"]),
|
||||
(r'%ch', ansi["hilite"]),
|
||||
(r'%cn', ansi["normal"]),
|
||||
(r'%cx', ansi["black"]),
|
||||
(r'%cX', ansi["back_black"]),
|
||||
(r'%cr', ansi["red"]),
|
||||
(r'%cR', ansi["back_red"]),
|
||||
(r'%cg', ansi["green"]),
|
||||
(r'%cG', ansi["back_green"]),
|
||||
(r'%cy', ansi["yellow"]),
|
||||
(r'%cY', ansi["back_yellow"]),
|
||||
(r'%cb', ansi["blue"]),
|
||||
(r'%cB', ansi["back_blue"]),
|
||||
(r'%cm', ansi["magenta"]),
|
||||
(r'%cM', ansi["back_magenta"]),
|
||||
(r'%cc', ansi["cyan"]),
|
||||
(r'%cC', ansi["back_cyan"]),
|
||||
(r'%cw', ansi["white"]),
|
||||
(r'%cW', ansi["back_white"]),
|
||||
]
|
||||
|
||||
for sub in ansi_subs:
|
||||
p = re.compile(sub[0], re.DOTALL)
|
||||
if strip_ansi:
|
||||
string = p.sub("", string)
|
||||
else:
|
||||
string = p.sub(sub[1], string)
|
||||
"""
|
||||
Parses a string, subbing color codes as needed.
|
||||
"""
|
||||
if strip_formatting:
|
||||
char_return = ""
|
||||
char_tab = ""
|
||||
char_space = ""
|
||||
else:
|
||||
char_return = ansi["return"]
|
||||
char_tab = ansi["tab"]
|
||||
char_space = ansi["space"]
|
||||
|
||||
ansi_subs = [
|
||||
(r'%r', char_return),
|
||||
(r'%t', char_tab),
|
||||
(r'%b', char_space),
|
||||
(r'%cf', ansi["blink"]),
|
||||
(r'%ci', ansi["inverse"]),
|
||||
(r'%ch', ansi["hilite"]),
|
||||
(r'%cn', ansi["normal"]),
|
||||
(r'%cx', ansi["black"]),
|
||||
(r'%cX', ansi["back_black"]),
|
||||
(r'%cr', ansi["red"]),
|
||||
(r'%cR', ansi["back_red"]),
|
||||
(r'%cg', ansi["green"]),
|
||||
(r'%cG', ansi["back_green"]),
|
||||
(r'%cy', ansi["yellow"]),
|
||||
(r'%cY', ansi["back_yellow"]),
|
||||
(r'%cb', ansi["blue"]),
|
||||
(r'%cB', ansi["back_blue"]),
|
||||
(r'%cm', ansi["magenta"]),
|
||||
(r'%cM', ansi["back_magenta"]),
|
||||
(r'%cc', ansi["cyan"]),
|
||||
(r'%cC', ansi["back_cyan"]),
|
||||
(r'%cw', ansi["white"]),
|
||||
(r'%cW', ansi["back_white"]),
|
||||
]
|
||||
|
||||
for sub in ansi_subs:
|
||||
p = re.compile(sub[0], re.DOTALL)
|
||||
if strip_ansi:
|
||||
string = p.sub("", string)
|
||||
else:
|
||||
string = p.sub(sub[1], string)
|
||||
|
||||
if strip_ansi:
|
||||
return '%s' % (string)
|
||||
else:
|
||||
return '%s%s' % (string, ansi["normal"])
|
||||
if strip_ansi:
|
||||
return '%s' % (string)
|
||||
else:
|
||||
return '%s%s' % (string, ansi["normal"])
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
from django.db import models
|
||||
|
||||
class CommandAlias(models.Model):
|
||||
"""
|
||||
Command aliases. If the player enters the value equal to user_input, the
|
||||
command denoted by equiv_command is used instead.
|
||||
"""
|
||||
user_input = models.CharField(max_length=50)
|
||||
equiv_command = models.CharField(max_length=50)
|
||||
|
||||
class Admin:
|
||||
list_display = ('user_input', 'equiv_command',)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Command aliases"
|
||||
ordering = ['user_input']
|
||||
"""
|
||||
Command aliases. If the player enters the value equal to user_input, the
|
||||
command denoted by equiv_command is used instead.
|
||||
"""
|
||||
user_input = models.CharField(max_length=50)
|
||||
equiv_command = models.CharField(max_length=50)
|
||||
|
||||
class Admin:
|
||||
list_display = ('user_input', 'equiv_command',)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Command aliases"
|
||||
ordering = ['user_input']
|
||||
|
||||
class ConfigValue(models.Model):
|
||||
"""
|
||||
Experimental new config model.
|
||||
"""
|
||||
conf_key = models.CharField(max_length=100)
|
||||
conf_value = models.TextField()
|
||||
|
||||
class Admin:
|
||||
list_display = ('conf_key', 'conf_value',)
|
||||
"""
|
||||
Experimental new config model.
|
||||
"""
|
||||
conf_key = models.CharField(max_length=100)
|
||||
conf_value = models.TextField()
|
||||
|
||||
class Admin:
|
||||
list_display = ('conf_key', 'conf_value',)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
from django.db import models
|
||||
|
||||
class GenericPerm(models.Model):
|
||||
"""
|
||||
This is merely a container class for some generic permissions that don't
|
||||
fit under a particular module.
|
||||
"""
|
||||
class Meta:
|
||||
permissions = (
|
||||
("announce", "May use @wall to make announcements"),
|
||||
("boot", "May use @boot to kick players"),
|
||||
("builder", "Can build and modify objects"),
|
||||
("chown_all", "Can @chown anything to anyone."),
|
||||
("free_money", "Has infinite money"),
|
||||
("long_fingers", "May get/look/examine etc. from a distance"),
|
||||
("steal", "May give negative money"),
|
||||
("set_hide", "May set themself invisible"),
|
||||
("tel_anywhere", "May @teleport anywhere"),
|
||||
("tel_anyone", "May @teleport anything"),
|
||||
("see_session_data", "May see detailed player session data"),
|
||||
("process_control", "May shutdown/restart/reload the game"),
|
||||
("manage_players", "Can change passwords, siteban, etc."),
|
||||
)
|
||||
"""
|
||||
This is merely a container class for some generic permissions that don't
|
||||
fit under a particular module.
|
||||
"""
|
||||
class Meta:
|
||||
permissions = (
|
||||
("announce", "May use @wall to make announcements"),
|
||||
("boot", "May use @boot to kick players"),
|
||||
("builder", "Can build and modify objects"),
|
||||
("chown_all", "Can @chown anything to anyone."),
|
||||
("free_money", "Has infinite money"),
|
||||
("long_fingers", "May get/look/examine etc. from a distance"),
|
||||
("steal", "May give negative money"),
|
||||
("set_hide", "May set themself invisible"),
|
||||
("tel_anywhere", "May @teleport anywhere"),
|
||||
("tel_anyone", "May @teleport anything"),
|
||||
("see_session_data", "May see detailed player session data"),
|
||||
("process_control", "May shutdown/restart/reload the game"),
|
||||
("manage_players", "Can change passwords, siteban, etc."),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,39 +2,39 @@ from django.db import models
|
|||
import ansi
|
||||
|
||||
class HelpEntry(models.Model):
|
||||
"""
|
||||
A generic help entry.
|
||||
"""
|
||||
topicname = models.CharField(max_length=255)
|
||||
entrytext = models.TextField(blank=True, null=True)
|
||||
staff_only = models.BooleanField(default=0)
|
||||
"""
|
||||
A generic help entry.
|
||||
"""
|
||||
topicname = models.CharField(max_length=255)
|
||||
entrytext = models.TextField(blank=True, null=True)
|
||||
staff_only = models.BooleanField(default=0)
|
||||
|
||||
class Admin:
|
||||
list_display = ('id', 'topicname', 'staff_only')
|
||||
list_filter = ('staff_only',)
|
||||
search_fields = ['entrytext']
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Help entries"
|
||||
ordering = ['topicname']
|
||||
|
||||
def __str__(self):
|
||||
return self.topicname
|
||||
|
||||
def get_topicname(self):
|
||||
"""
|
||||
Returns the topic's name.
|
||||
"""
|
||||
try:
|
||||
return self.topicname
|
||||
except:
|
||||
return None
|
||||
|
||||
def get_entrytext_ingame(self):
|
||||
"""
|
||||
Gets the entry text for in-game viewing.
|
||||
"""
|
||||
try:
|
||||
return ansi.parse_ansi(self.entrytext)
|
||||
except:
|
||||
return None
|
||||
class Admin:
|
||||
list_display = ('id', 'topicname', 'staff_only')
|
||||
list_filter = ('staff_only',)
|
||||
search_fields = ['entrytext']
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Help entries"
|
||||
ordering = ['topicname']
|
||||
|
||||
def __str__(self):
|
||||
return self.topicname
|
||||
|
||||
def get_topicname(self):
|
||||
"""
|
||||
Returns the topic's name.
|
||||
"""
|
||||
try:
|
||||
return self.topicname
|
||||
except:
|
||||
return None
|
||||
|
||||
def get_entrytext_ingame(self):
|
||||
"""
|
||||
Gets the entry text for in-game viewing.
|
||||
"""
|
||||
try:
|
||||
return ansi.parse_ansi(self.entrytext)
|
||||
except:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -2,43 +2,43 @@ from django.db import models
|
|||
from django.contrib.auth.models import User
|
||||
|
||||
class NewsTopic(models.Model):
|
||||
"""
|
||||
Represents a news topic.
|
||||
"""
|
||||
name = models.CharField(max_length=75, unique=True)
|
||||
description = models.TextField(blank=True)
|
||||
icon = models.ImageField(upload_to='newstopic_icons', default='newstopic_icons/default.png', blank=True, help_text="Image for the news topic.")
|
||||
"""
|
||||
Represents a news topic.
|
||||
"""
|
||||
name = models.CharField(max_length=75, unique=True)
|
||||
description = models.TextField(blank=True)
|
||||
icon = models.ImageField(upload_to='newstopic_icons', default='newstopic_icons/default.png', blank=True, help_text="Image for the news topic.")
|
||||
|
||||
def __str__(self):
|
||||
try:
|
||||
return self.name
|
||||
except:
|
||||
return "Invalid"
|
||||
def __str__(self):
|
||||
try:
|
||||
return self.name
|
||||
except:
|
||||
return "Invalid"
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
|
||||
class Admin:
|
||||
list_display = ('name', 'icon')
|
||||
class Admin:
|
||||
list_display = ('name', 'icon')
|
||||
|
||||
class NewsEntry(models.Model):
|
||||
"""
|
||||
An individual news entry.
|
||||
"""
|
||||
author = models.ForeignKey(User, related_name='author')
|
||||
title = models.CharField(max_length=255)
|
||||
body = models.TextField()
|
||||
topic = models.ForeignKey(NewsTopic, related_name='newstopic')
|
||||
date_posted = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
"""
|
||||
An individual news entry.
|
||||
"""
|
||||
author = models.ForeignKey(User, related_name='author')
|
||||
title = models.CharField(max_length=255)
|
||||
body = models.TextField()
|
||||
topic = models.ForeignKey(NewsTopic, related_name='newstopic')
|
||||
date_posted = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
ordering = ('-date_posted',)
|
||||
verbose_name_plural = "News entries"
|
||||
class Meta:
|
||||
ordering = ('-date_posted',)
|
||||
verbose_name_plural = "News entries"
|
||||
|
||||
class Admin:
|
||||
list_display = ('title', 'author', 'topic', 'date_posted')
|
||||
list_filter = ('topic',)
|
||||
search_fields = ['title']
|
||||
class Admin:
|
||||
list_display = ('title', 'author', 'topic', 'date_posted')
|
||||
list_filter = ('topic',)
|
||||
search_fields = ['title']
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('apps.news.views',
|
||||
(r'^show/(?P<entry_id>\d+)/$', 'show_news'),
|
||||
(r'^archive/$', 'news_archive'),
|
||||
(r'^search/$', 'search_form'),
|
||||
(r'^search/results/$', 'search_results'),
|
||||
(r'^show/(?P<entry_id>\d+)/$', 'show_news'),
|
||||
(r'^archive/$', 'news_archive'),
|
||||
(r'^search/$', 'search_form'),
|
||||
(r'^search/results/$', 'search_results'),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
This is a very simple news application, with most of the expected features
|
||||
like:
|
||||
|
||||
* News categories/topics
|
||||
* Searchable archives
|
||||
* News categories/topics
|
||||
* Searchable archives
|
||||
"""
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
|
|
@ -18,109 +18,109 @@ from apps.news.models import NewsTopic, NewsEntry
|
|||
# The sidebar text to be included as a variable on each page. There's got to
|
||||
# be a better, cleaner way to include this on every page.
|
||||
sidebar = """
|
||||
<p class='doNotDisplay doNotPrint'>This page’s menu:</p>
|
||||
<ul id='side-bar'>
|
||||
<li><a href='/news/archive'>News Archive</a></li>
|
||||
<li><a href='/news/search'>Search News</a></li>
|
||||
</ul>
|
||||
<p class='doNotDisplay doNotPrint'>This page’s menu:</p>
|
||||
<ul id='side-bar'>
|
||||
<li><a href='/news/archive'>News Archive</a></li>
|
||||
<li><a href='/news/search'>Search News</a></li>
|
||||
</ul>
|
||||
"""
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
"""
|
||||
Class to represent a news search form under Django's newforms. This is used
|
||||
to validate the input on the search_form view, as well as the search_results
|
||||
view when we're picking the query out of GET. This makes searching safe
|
||||
via the search form or by directly inputing values via GET key pairs.
|
||||
"""
|
||||
search_terms = forms.CharField(max_length=100, min_length=3, required=True)
|
||||
"""
|
||||
Class to represent a news search form under Django's newforms. This is used
|
||||
to validate the input on the search_form view, as well as the search_results
|
||||
view when we're picking the query out of GET. This makes searching safe
|
||||
via the search form or by directly inputing values via GET key pairs.
|
||||
"""
|
||||
search_terms = forms.CharField(max_length=100, min_length=3, required=True)
|
||||
|
||||
def show_news(request, entry_id):
|
||||
"""
|
||||
Show an individual news entry. Display some basic information along with
|
||||
the title and content.
|
||||
"""
|
||||
news_entry = get_object_or_404(NewsEntry, id=entry_id)
|
||||
"""
|
||||
Show an individual news entry. Display some basic information along with
|
||||
the title and content.
|
||||
"""
|
||||
news_entry = get_object_or_404(NewsEntry, id=entry_id)
|
||||
|
||||
pagevars = {
|
||||
"page_title": "News Entry",
|
||||
"news_entry": news_entry,
|
||||
"sidebar": sidebar
|
||||
}
|
||||
pagevars = {
|
||||
"page_title": "News Entry",
|
||||
"news_entry": news_entry,
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('news/show_entry.html', pagevars, context_instance)
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('news/show_entry.html', pagevars, context_instance)
|
||||
|
||||
def news_archive(request):
|
||||
"""
|
||||
Shows an archive of news entries.
|
||||
"""
|
||||
Shows an archive of news entries.
|
||||
|
||||
TODO: Expand this a bit to allow filtering by month/year.
|
||||
"""
|
||||
news_entries = NewsEntry.objects.all().order_by('-date_posted')
|
||||
# TODO: Move this to either settings.py or the SQL configuration.
|
||||
entries_per_page = 15
|
||||
TODO: Expand this a bit to allow filtering by month/year.
|
||||
"""
|
||||
news_entries = NewsEntry.objects.all().order_by('-date_posted')
|
||||
# TODO: Move this to either settings.py or the SQL configuration.
|
||||
entries_per_page = 15
|
||||
|
||||
pagevars = {
|
||||
"page_title": "News Archive",
|
||||
"browse_url": "/news/archive",
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
return gv_list_detail.object_list(request, news_entries, template_name='news/archive.html', extra_context=pagevars, paginate_by=entries_per_page)
|
||||
pagevars = {
|
||||
"page_title": "News Archive",
|
||||
"browse_url": "/news/archive",
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
return gv_list_detail.object_list(request, news_entries, template_name='news/archive.html', extra_context=pagevars, paginate_by=entries_per_page)
|
||||
|
||||
def search_form(request):
|
||||
"""
|
||||
Render the news search form. Don't handle much validation at all. If the
|
||||
user enters a search term that meets the minimum, send them on their way
|
||||
to the results page.
|
||||
"""
|
||||
if request.method == 'GET':
|
||||
# A GET request was sent to the search page, load the value and
|
||||
# validate it.
|
||||
search_form = SearchForm(request.GET)
|
||||
if search_form.is_valid():
|
||||
# If the input is good, send them to the results page with the
|
||||
# query attached in GET variables.
|
||||
return HttpResponseRedirect('/news/search/results/?search_terms='+ search_form.cleaned_data['search_terms'])
|
||||
else:
|
||||
# Brand new search, nothing has been sent just yet.
|
||||
search_form = SearchForm()
|
||||
"""
|
||||
Render the news search form. Don't handle much validation at all. If the
|
||||
user enters a search term that meets the minimum, send them on their way
|
||||
to the results page.
|
||||
"""
|
||||
if request.method == 'GET':
|
||||
# A GET request was sent to the search page, load the value and
|
||||
# validate it.
|
||||
search_form = SearchForm(request.GET)
|
||||
if search_form.is_valid():
|
||||
# If the input is good, send them to the results page with the
|
||||
# query attached in GET variables.
|
||||
return HttpResponseRedirect('/news/search/results/?search_terms='+ search_form.cleaned_data['search_terms'])
|
||||
else:
|
||||
# Brand new search, nothing has been sent just yet.
|
||||
search_form = SearchForm()
|
||||
|
||||
pagevars = {
|
||||
"page_title": "Search News",
|
||||
"search_form": search_form,
|
||||
"debug": debug,
|
||||
"sidebar": sidebar
|
||||
}
|
||||
pagevars = {
|
||||
"page_title": "Search News",
|
||||
"search_form": search_form,
|
||||
"debug": debug,
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('news/search_form.html', pagevars, context_instance)
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('news/search_form.html', pagevars, context_instance)
|
||||
|
||||
def search_results(request):
|
||||
"""
|
||||
Shows an archive of news entries. Use the generic news browsing template.
|
||||
"""
|
||||
# TODO: Move this to either settings.py or the SQL configuration.
|
||||
entries_per_page = 15
|
||||
"""
|
||||
Shows an archive of news entries. Use the generic news browsing template.
|
||||
"""
|
||||
# TODO: Move this to either settings.py or the SQL configuration.
|
||||
entries_per_page = 15
|
||||
|
||||
# Load the form values from GET to validate against.
|
||||
search_form = SearchForm(request.GET)
|
||||
# You have to call is_valid() or cleaned_data won't be populated.
|
||||
valid_search = search_form.is_valid()
|
||||
# This is the safe data that we can pass to queries without huge worry of
|
||||
# badStuff(tm).
|
||||
cleaned_get = search_form.cleaned_data
|
||||
# Load the form values from GET to validate against.
|
||||
search_form = SearchForm(request.GET)
|
||||
# You have to call is_valid() or cleaned_data won't be populated.
|
||||
valid_search = search_form.is_valid()
|
||||
# This is the safe data that we can pass to queries without huge worry of
|
||||
# badStuff(tm).
|
||||
cleaned_get = search_form.cleaned_data
|
||||
|
||||
# Perform searches that match the title and contents.
|
||||
# TODO: Allow the user to specify what to match against and in what
|
||||
# topics/categories.
|
||||
news_entries = NewsEntry.objects.filter(Q(title__contains=cleaned_get['search_terms']) | Q(body__contains=cleaned_get['search_terms']))
|
||||
# Perform searches that match the title and contents.
|
||||
# TODO: Allow the user to specify what to match against and in what
|
||||
# topics/categories.
|
||||
news_entries = NewsEntry.objects.filter(Q(title__contains=cleaned_get['search_terms']) | Q(body__contains=cleaned_get['search_terms']))
|
||||
|
||||
pagevars = {
|
||||
"page_title": "Search Results",
|
||||
"searchtext": cleaned_get['search_terms'],
|
||||
"browse_url": "/news/search/results",
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
return gv_list_detail.object_list(request, news_entries, template_name='news/archive.html', extra_context=pagevars, paginate_by=entries_per_page)
|
||||
pagevars = {
|
||||
"page_title": "Search Results",
|
||||
"searchtext": cleaned_get['search_terms'],
|
||||
"browse_url": "/news/search/results",
|
||||
"sidebar": sidebar
|
||||
}
|
||||
|
||||
return gv_list_detail.object_list(request, news_entries, template_name='news/archive.html', extra_context=pagevars, paginate_by=entries_per_page)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('apps.website.views',
|
||||
(r'^$', 'page_index'),
|
||||
(r'^$', 'page_index'),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,47 +11,47 @@ the other applications.
|
|||
"""
|
||||
|
||||
def page_index(request):
|
||||
"""
|
||||
Main root page.
|
||||
"""
|
||||
# Some misc. configurable stuff.
|
||||
# TODO: Move this to either SQL or settings.py based configuration.
|
||||
fpage_player_limit = 4
|
||||
fpage_news_entries = 2
|
||||
|
||||
# A QuerySet of recent news entries.
|
||||
news_entries = NewsEntry.objects.all().order_by('-date_posted')[:fpage_news_entries]
|
||||
# Dictionary containing database statistics.
|
||||
objstats = functions_db.object_totals()
|
||||
# A QuerySet of the most recently connected players.
|
||||
recent_players = functions_db.get_recently_connected_players()[:fpage_player_limit]
|
||||
|
||||
pagevars = {
|
||||
"page_title": "Front Page",
|
||||
"news_entries": news_entries,
|
||||
"players_connected_recent": recent_players,
|
||||
"num_players_connected": functions_db.get_connected_players().count(),
|
||||
"num_players_registered": functions_db.num_total_players(),
|
||||
"num_players_connected_recent": functions_db.get_recently_connected_players().count(),
|
||||
"num_players_registered_recent": functions_db.get_recently_created_players().count(),
|
||||
"num_players": objstats["players"],
|
||||
"num_rooms": objstats["rooms"],
|
||||
"num_things": objstats["things"],
|
||||
"num_exits": objstats["exits"],
|
||||
}
|
||||
"""
|
||||
Main root page.
|
||||
"""
|
||||
# Some misc. configurable stuff.
|
||||
# TODO: Move this to either SQL or settings.py based configuration.
|
||||
fpage_player_limit = 4
|
||||
fpage_news_entries = 2
|
||||
|
||||
# A QuerySet of recent news entries.
|
||||
news_entries = NewsEntry.objects.all().order_by('-date_posted')[:fpage_news_entries]
|
||||
# Dictionary containing database statistics.
|
||||
objstats = functions_db.object_totals()
|
||||
# A QuerySet of the most recently connected players.
|
||||
recent_players = functions_db.get_recently_connected_players()[:fpage_player_limit]
|
||||
|
||||
pagevars = {
|
||||
"page_title": "Front Page",
|
||||
"news_entries": news_entries,
|
||||
"players_connected_recent": recent_players,
|
||||
"num_players_connected": functions_db.get_connected_players().count(),
|
||||
"num_players_registered": functions_db.num_total_players(),
|
||||
"num_players_connected_recent": functions_db.get_recently_connected_players().count(),
|
||||
"num_players_registered_recent": functions_db.get_recently_created_players().count(),
|
||||
"num_players": objstats["players"],
|
||||
"num_rooms": objstats["rooms"],
|
||||
"num_things": objstats["things"],
|
||||
"num_exits": objstats["exits"],
|
||||
}
|
||||
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('index.html', pagevars, context_instance)
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('index.html', pagevars, context_instance)
|
||||
|
||||
def to_be_implemented(request):
|
||||
"""
|
||||
A notice letting the user know that this particular feature hasn't been
|
||||
implemented yet.
|
||||
"""
|
||||
"""
|
||||
A notice letting the user know that this particular feature hasn't been
|
||||
implemented yet.
|
||||
"""
|
||||
|
||||
pagevars = {
|
||||
"page_title": "To Be Implemented...",
|
||||
}
|
||||
pagevars = {
|
||||
"page_title": "To Be Implemented...",
|
||||
}
|
||||
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('tbi.html', pagevars, context_instance)
|
||||
context_instance = RequestContext(request)
|
||||
return render_to_response('tbi.html', pagevars, context_instance)
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ from django.conf import settings
|
|||
import gameconf
|
||||
|
||||
def general_context(request):
|
||||
"""
|
||||
Returns common Evennia-related context stuff.
|
||||
"""
|
||||
return {
|
||||
'game_name': gameconf.get_configvalue('site_name'),
|
||||
'media_url': settings.MEDIA_URL,
|
||||
}
|
||||
"""
|
||||
Returns common Evennia-related context stuff.
|
||||
"""
|
||||
return {
|
||||
'game_name': gameconf.get_configvalue('site_name'),
|
||||
'media_url': settings.MEDIA_URL,
|
||||
}
|
||||
|
|
|
|||
440
cmdhandler.py
440
cmdhandler.py
|
|
@ -14,245 +14,245 @@ something.
|
|||
"""
|
||||
|
||||
class UnknownCommand(Exception):
|
||||
"""
|
||||
Throw this when a user enters an an invalid command.
|
||||
"""
|
||||
"""
|
||||
Throw this when a user enters an an invalid command.
|
||||
"""
|
||||
|
||||
def match_exits(pobject, searchstr):
|
||||
"""
|
||||
See if we can find an input match to exits.
|
||||
"""
|
||||
exits = pobject.get_location().get_contents(filter_type=4)
|
||||
return functions_db.list_search_object_namestr(exits, searchstr, match_type="exact")
|
||||
"""
|
||||
See if we can find an input match to exits.
|
||||
"""
|
||||
exits = pobject.get_location().get_contents(filter_type=4)
|
||||
return functions_db.list_search_object_namestr(exits, searchstr, match_type="exact")
|
||||
|
||||
def parse_command(command_string):
|
||||
"""
|
||||
Tries to handle the most common command strings and returns a dictionary with various data.
|
||||
Common command types:
|
||||
- Complex:
|
||||
@pemit[/option] <target>[/option]=<data>
|
||||
- Simple:
|
||||
look
|
||||
look <target>
|
||||
"""
|
||||
Tries to handle the most common command strings and returns a dictionary with various data.
|
||||
Common command types:
|
||||
- Complex:
|
||||
@pemit[/option] <target>[/option]=<data>
|
||||
- Simple:
|
||||
look
|
||||
look <target>
|
||||
|
||||
I'm not married to either of these terms, but I couldn't think of anything better. If you can, lets change it :)
|
||||
I'm not married to either of these terms, but I couldn't think of anything better. If you can, lets change it :)
|
||||
|
||||
The only cases that I haven't handled is if someone enters something like:
|
||||
@pemit <target> <target>/<switch>=<data>
|
||||
- Ends up considering both targets as one with a space between them, and the switch as a switch.
|
||||
@pemit <target>/<switch> <target>=<data>
|
||||
- Ends up considering the first target a target, and the second target as part of the switch.
|
||||
The only cases that I haven't handled is if someone enters something like:
|
||||
@pemit <target> <target>/<switch>=<data>
|
||||
- Ends up considering both targets as one with a space between them, and the switch as a switch.
|
||||
@pemit <target>/<switch> <target>=<data>
|
||||
- Ends up considering the first target a target, and the second target as part of the switch.
|
||||
|
||||
|
||||
"""
|
||||
# Each of the bits of data starts off as None, except for the raw, original
|
||||
# command
|
||||
parsed_command = dict(
|
||||
raw_command=command_string,
|
||||
data=None,
|
||||
original_command=None,
|
||||
original_targets=None,
|
||||
base_command=None,
|
||||
command_switches=None,
|
||||
targets=None,
|
||||
target_switches=None
|
||||
)
|
||||
try:
|
||||
# If we make it past this next statement, then this is what we
|
||||
# consider a complex command
|
||||
(command_parts, data) = command_string.split('=', 1)
|
||||
parsed_command['data'] = data
|
||||
# First we deal with the command part of the command and break it
|
||||
# down into the base command, along with switches
|
||||
# If we make it past the next statement, then they must have
|
||||
# entered a command like:
|
||||
# p =<data>
|
||||
# So we should probably just let it get caught by the ValueError
|
||||
# again and consider it a simple command
|
||||
(total_command, total_targets) = command_parts.split(' ', 1)
|
||||
parsed_command['original_command'] = total_command
|
||||
parsed_command['original_targets'] = total_targets
|
||||
split_command = total_command.split('/')
|
||||
parsed_command['base_command'] = split_command[0]
|
||||
parsed_command['command_switches'] = split_command[1:]
|
||||
# Now we move onto the target data
|
||||
try:
|
||||
# Look for switches- if they give target switches, then we don't
|
||||
# accept multiple targets
|
||||
(target, switch_string) = total_targets.split('/', 1)
|
||||
parsed_command['targets'] = [target]
|
||||
parsed_command['target_switches'] = switch_string.split('/')
|
||||
except ValueError:
|
||||
# Alright, no switches, so lets consider multiple targets
|
||||
parsed_command['targets'] = total_targets.split()
|
||||
except ValueError:
|
||||
# Ok, couldn't find an =, so not a complex command
|
||||
try:
|
||||
(command, data) = command_string.split(' ', 1)
|
||||
parsed_command['base_command'] = command
|
||||
parsed_command['data'] = data
|
||||
except ValueError:
|
||||
# No arguments
|
||||
# ie:
|
||||
# - look
|
||||
parsed_command['base_command'] = command_string
|
||||
return parsed_command
|
||||
"""
|
||||
# Each of the bits of data starts off as None, except for the raw, original
|
||||
# command
|
||||
parsed_command = dict(
|
||||
raw_command=command_string,
|
||||
data=None,
|
||||
original_command=None,
|
||||
original_targets=None,
|
||||
base_command=None,
|
||||
command_switches=None,
|
||||
targets=None,
|
||||
target_switches=None
|
||||
)
|
||||
try:
|
||||
# If we make it past this next statement, then this is what we
|
||||
# consider a complex command
|
||||
(command_parts, data) = command_string.split('=', 1)
|
||||
parsed_command['data'] = data
|
||||
# First we deal with the command part of the command and break it
|
||||
# down into the base command, along with switches
|
||||
# If we make it past the next statement, then they must have
|
||||
# entered a command like:
|
||||
# p =<data>
|
||||
# So we should probably just let it get caught by the ValueError
|
||||
# again and consider it a simple command
|
||||
(total_command, total_targets) = command_parts.split(' ', 1)
|
||||
parsed_command['original_command'] = total_command
|
||||
parsed_command['original_targets'] = total_targets
|
||||
split_command = total_command.split('/')
|
||||
parsed_command['base_command'] = split_command[0]
|
||||
parsed_command['command_switches'] = split_command[1:]
|
||||
# Now we move onto the target data
|
||||
try:
|
||||
# Look for switches- if they give target switches, then we don't
|
||||
# accept multiple targets
|
||||
(target, switch_string) = total_targets.split('/', 1)
|
||||
parsed_command['targets'] = [target]
|
||||
parsed_command['target_switches'] = switch_string.split('/')
|
||||
except ValueError:
|
||||
# Alright, no switches, so lets consider multiple targets
|
||||
parsed_command['targets'] = total_targets.split()
|
||||
except ValueError:
|
||||
# Ok, couldn't find an =, so not a complex command
|
||||
try:
|
||||
(command, data) = command_string.split(' ', 1)
|
||||
parsed_command['base_command'] = command
|
||||
parsed_command['data'] = data
|
||||
except ValueError:
|
||||
# No arguments
|
||||
# ie:
|
||||
# - look
|
||||
parsed_command['base_command'] = command_string
|
||||
return parsed_command
|
||||
|
||||
def handle(cdat):
|
||||
"""
|
||||
Use the spliced (list) uinput variable to retrieve the correct
|
||||
command, or return an invalid command error.
|
||||
"""
|
||||
Use the spliced (list) uinput variable to retrieve the correct
|
||||
command, or return an invalid command error.
|
||||
|
||||
We're basically grabbing the player's command by tacking
|
||||
their input on to 'cmd_' and looking it up in the GenCommands
|
||||
class.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = cdat['server']
|
||||
|
||||
try:
|
||||
# TODO: Protect against non-standard characters.
|
||||
if cdat['uinput'] == '':
|
||||
return
|
||||
|
||||
parsed_input = {}
|
||||
parsed_input['parsed_command'] = parse_command(cdat['uinput'])
|
||||
|
||||
# First we split the input up by spaces.
|
||||
parsed_input['splitted'] = cdat['uinput'].split()
|
||||
# Now we find the root command chunk (with switches attached).
|
||||
parsed_input['root_chunk'] = parsed_input['splitted'][0].split('/')
|
||||
# And now for the actual root command. It's the first entry in root_chunk.
|
||||
parsed_input['root_cmd'] = parsed_input['root_chunk'][0].lower()
|
||||
# Keep around the full, raw input in case a command needs it
|
||||
cdat['raw_input'] = cdat['uinput']
|
||||
|
||||
# Now we'll see if the user is using an alias. We do a dictionary lookup,
|
||||
# if the key (the player's root command) doesn't exist on the dict, we
|
||||
# don't replace the existing root_cmd. If the key exists, its value
|
||||
# replaces the previously splitted root_cmd. For example, sa -> say.
|
||||
alias_list = server.cmd_alias_list
|
||||
parsed_input['root_cmd'] = alias_list.get(parsed_input['root_cmd'],parsed_input['root_cmd'])
|
||||
|
||||
# This will hold the reference to the command's function.
|
||||
cmd = None
|
||||
|
||||
if session.logged_in:
|
||||
# Store the timestamp of the user's last command.
|
||||
session.cmd_last = time.time()
|
||||
|
||||
# Lets the users get around badly configured NAT timeouts.
|
||||
if parsed_input['root_cmd'] == 'idle':
|
||||
We're basically grabbing the player's command by tacking
|
||||
their input on to 'cmd_' and looking it up in the GenCommands
|
||||
class.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = cdat['server']
|
||||
|
||||
try:
|
||||
# TODO: Protect against non-standard characters.
|
||||
if cdat['uinput'] == '':
|
||||
return
|
||||
|
||||
# Increment our user's command counter.
|
||||
session.cmd_total += 1
|
||||
# Player-visible idle time, not used in idle timeout calcs.
|
||||
session.cmd_last_visible = time.time()
|
||||
parsed_input = {}
|
||||
parsed_input['parsed_command'] = parse_command(cdat['uinput'])
|
||||
|
||||
# Just in case. Prevents some really funky-case crashes.
|
||||
if len(parsed_input['root_cmd']) == 0:
|
||||
raise UnknownCommand
|
||||
# First we split the input up by spaces.
|
||||
parsed_input['splitted'] = cdat['uinput'].split()
|
||||
# Now we find the root command chunk (with switches attached).
|
||||
parsed_input['root_chunk'] = parsed_input['splitted'][0].split('/')
|
||||
# And now for the actual root command. It's the first entry in root_chunk.
|
||||
parsed_input['root_cmd'] = parsed_input['root_chunk'][0].lower()
|
||||
# Keep around the full, raw input in case a command needs it
|
||||
cdat['raw_input'] = cdat['uinput']
|
||||
|
||||
# Shortened say alias.
|
||||
if parsed_input['root_cmd'][0] == '"':
|
||||
parsed_input['splitted'].insert(0, "say")
|
||||
parsed_input['splitted'][1] = parsed_input['splitted'][1][1:]
|
||||
parsed_input['root_cmd'] = 'say'
|
||||
# Shortened pose alias.
|
||||
elif parsed_input['root_cmd'][0] == ':':
|
||||
parsed_input['splitted'].insert(0, "pose")
|
||||
parsed_input['splitted'][1] = parsed_input['splitted'][1][1:]
|
||||
parsed_input['root_cmd'] = 'pose'
|
||||
# Pose without space alias.
|
||||
elif parsed_input['root_cmd'][0] == ';':
|
||||
parsed_input['splitted'].insert(0, "pose/nospace")
|
||||
parsed_input['root_chunk'] = ['pose', 'nospace']
|
||||
parsed_input['splitted'][1] = parsed_input['splitted'][1][1:]
|
||||
parsed_input['root_cmd'] = 'pose'
|
||||
# Channel alias match.
|
||||
elif functions_comsys.plr_has_channel(session,
|
||||
parsed_input['root_cmd'],
|
||||
alias_search=True,
|
||||
return_muted=True):
|
||||
|
||||
calias = parsed_input['root_cmd']
|
||||
cname = functions_comsys.plr_cname_from_alias(session, calias)
|
||||
cmessage = ' '.join(parsed_input['splitted'][1:])
|
||||
|
||||
if cmessage == "who":
|
||||
functions_comsys.msg_cwho(session, cname)
|
||||
return
|
||||
elif cmessage == "on":
|
||||
functions_comsys.plr_chan_on(session, calias)
|
||||
return
|
||||
elif cmessage == "off":
|
||||
functions_comsys.plr_chan_off(session, calias)
|
||||
return
|
||||
elif cmessage == "last":
|
||||
functions_comsys.msg_chan_hist(session, cname)
|
||||
return
|
||||
|
||||
second_arg = "%s=%s" % (cname, cmessage)
|
||||
parsed_input['splitted'] = ["@cemit/sendername", second_arg]
|
||||
parsed_input['root_chunk'] = ['@cemit', 'sendername', 'quiet']
|
||||
parsed_input['root_cmd'] = '@cemit'
|
||||
# Now we'll see if the user is using an alias. We do a dictionary lookup,
|
||||
# if the key (the player's root command) doesn't exist on the dict, we
|
||||
# don't replace the existing root_cmd. If the key exists, its value
|
||||
# replaces the previously splitted root_cmd. For example, sa -> say.
|
||||
alias_list = server.cmd_alias_list
|
||||
parsed_input['root_cmd'] = alias_list.get(parsed_input['root_cmd'],parsed_input['root_cmd'])
|
||||
|
||||
# Get the command's function reference (Or False)
|
||||
cmdtuple = cmdtable.return_cmdtuple(parsed_input['root_cmd'])
|
||||
if cmdtuple:
|
||||
# If there is a permissions element to the entry, check perms.
|
||||
if cmdtuple[1]:
|
||||
if not session.get_pobject().user_has_perm_list(cmdtuple[1]):
|
||||
session.msg(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
# If flow reaches this point, user has perms and command is ready.
|
||||
cmd = cmdtuple[0]
|
||||
|
||||
else:
|
||||
# Not logged in, look through the unlogged-in command table.
|
||||
cmdtuple = cmdtable.return_cmdtuple(parsed_input['root_cmd'], unlogged_cmd=True)
|
||||
if cmdtuple:
|
||||
cmd = cmdtuple[0]
|
||||
# This will hold the reference to the command's function.
|
||||
cmd = None
|
||||
|
||||
# Debugging stuff.
|
||||
#session.msg("ROOT : %s" % (parsed_input['root_cmd'],))
|
||||
#session.msg("SPLIT: %s" % (parsed_input['splitted'],))
|
||||
|
||||
if callable(cmd):
|
||||
cdat['uinput'] = parsed_input
|
||||
try:
|
||||
cmd(cdat)
|
||||
except:
|
||||
session.msg("Untrapped error, please file a bug report:\n%s" % (format_exc(),))
|
||||
functions_general.log_errmsg("Untrapped error, evoker %s: %s" %
|
||||
(session, format_exc()))
|
||||
return
|
||||
if session.logged_in:
|
||||
# Store the timestamp of the user's last command.
|
||||
session.cmd_last = time.time()
|
||||
|
||||
if session.logged_in:
|
||||
# If we're not logged in, don't check exits.
|
||||
pobject = session.get_pobject()
|
||||
exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted']))
|
||||
if exit_matches:
|
||||
targ_exit = exit_matches[0]
|
||||
if targ_exit.get_home():
|
||||
cdat['uinput'] = parsed_input
|
||||
|
||||
# SCRIPT: See if the player can traverse the exit
|
||||
if not targ_exit.get_scriptlink().default_lock({
|
||||
"pobject": pobject
|
||||
}):
|
||||
session.msg("You can't traverse that exit.")
|
||||
else:
|
||||
pobject.move_to(targ_exit.get_home())
|
||||
session.execute_cmd("look")
|
||||
else:
|
||||
session.msg("That exit leads to nowhere.")
|
||||
# Lets the users get around badly configured NAT timeouts.
|
||||
if parsed_input['root_cmd'] == 'idle':
|
||||
return
|
||||
|
||||
# Increment our user's command counter.
|
||||
session.cmd_total += 1
|
||||
# Player-visible idle time, not used in idle timeout calcs.
|
||||
session.cmd_last_visible = time.time()
|
||||
|
||||
# Just in case. Prevents some really funky-case crashes.
|
||||
if len(parsed_input['root_cmd']) == 0:
|
||||
raise UnknownCommand
|
||||
|
||||
# Shortened say alias.
|
||||
if parsed_input['root_cmd'][0] == '"':
|
||||
parsed_input['splitted'].insert(0, "say")
|
||||
parsed_input['splitted'][1] = parsed_input['splitted'][1][1:]
|
||||
parsed_input['root_cmd'] = 'say'
|
||||
# Shortened pose alias.
|
||||
elif parsed_input['root_cmd'][0] == ':':
|
||||
parsed_input['splitted'].insert(0, "pose")
|
||||
parsed_input['splitted'][1] = parsed_input['splitted'][1][1:]
|
||||
parsed_input['root_cmd'] = 'pose'
|
||||
# Pose without space alias.
|
||||
elif parsed_input['root_cmd'][0] == ';':
|
||||
parsed_input['splitted'].insert(0, "pose/nospace")
|
||||
parsed_input['root_chunk'] = ['pose', 'nospace']
|
||||
parsed_input['splitted'][1] = parsed_input['splitted'][1][1:]
|
||||
parsed_input['root_cmd'] = 'pose'
|
||||
# Channel alias match.
|
||||
elif functions_comsys.plr_has_channel(session,
|
||||
parsed_input['root_cmd'],
|
||||
alias_search=True,
|
||||
return_muted=True):
|
||||
|
||||
calias = parsed_input['root_cmd']
|
||||
cname = functions_comsys.plr_cname_from_alias(session, calias)
|
||||
cmessage = ' '.join(parsed_input['splitted'][1:])
|
||||
|
||||
if cmessage == "who":
|
||||
functions_comsys.msg_cwho(session, cname)
|
||||
return
|
||||
elif cmessage == "on":
|
||||
functions_comsys.plr_chan_on(session, calias)
|
||||
return
|
||||
elif cmessage == "off":
|
||||
functions_comsys.plr_chan_off(session, calias)
|
||||
return
|
||||
elif cmessage == "last":
|
||||
functions_comsys.msg_chan_hist(session, cname)
|
||||
return
|
||||
|
||||
second_arg = "%s=%s" % (cname, cmessage)
|
||||
parsed_input['splitted'] = ["@cemit/sendername", second_arg]
|
||||
parsed_input['root_chunk'] = ['@cemit', 'sendername', 'quiet']
|
||||
parsed_input['root_cmd'] = '@cemit'
|
||||
|
||||
# Get the command's function reference (Or False)
|
||||
cmdtuple = cmdtable.return_cmdtuple(parsed_input['root_cmd'])
|
||||
if cmdtuple:
|
||||
# If there is a permissions element to the entry, check perms.
|
||||
if cmdtuple[1]:
|
||||
if not session.get_pobject().user_has_perm_list(cmdtuple[1]):
|
||||
session.msg(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
# If flow reaches this point, user has perms and command is ready.
|
||||
cmd = cmdtuple[0]
|
||||
|
||||
else:
|
||||
# Not logged in, look through the unlogged-in command table.
|
||||
cmdtuple = cmdtable.return_cmdtuple(parsed_input['root_cmd'], unlogged_cmd=True)
|
||||
if cmdtuple:
|
||||
cmd = cmdtuple[0]
|
||||
|
||||
# Debugging stuff.
|
||||
#session.msg("ROOT : %s" % (parsed_input['root_cmd'],))
|
||||
#session.msg("SPLIT: %s" % (parsed_input['splitted'],))
|
||||
|
||||
if callable(cmd):
|
||||
cdat['uinput'] = parsed_input
|
||||
try:
|
||||
cmd(cdat)
|
||||
except:
|
||||
session.msg("Untrapped error, please file a bug report:\n%s" % (format_exc(),))
|
||||
functions_general.log_errmsg("Untrapped error, evoker %s: %s" %
|
||||
(session, format_exc()))
|
||||
return
|
||||
|
||||
# If we reach this point, we haven't matched anything.
|
||||
raise UnknownCommand
|
||||
if session.logged_in:
|
||||
# If we're not logged in, don't check exits.
|
||||
pobject = session.get_pobject()
|
||||
exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted']))
|
||||
if exit_matches:
|
||||
targ_exit = exit_matches[0]
|
||||
if targ_exit.get_home():
|
||||
cdat['uinput'] = parsed_input
|
||||
|
||||
# SCRIPT: See if the player can traverse the exit
|
||||
if not targ_exit.get_scriptlink().default_lock({
|
||||
"pobject": pobject
|
||||
}):
|
||||
session.msg("You can't traverse that exit.")
|
||||
else:
|
||||
pobject.move_to(targ_exit.get_home())
|
||||
session.execute_cmd("look")
|
||||
else:
|
||||
session.msg("That exit leads to nowhere.")
|
||||
return
|
||||
|
||||
except UnknownCommand:
|
||||
session.msg("Huh? (Type \"help\" for help.)")
|
||||
# If we reach this point, we haven't matched anything.
|
||||
raise UnknownCommand
|
||||
|
||||
except UnknownCommand:
|
||||
session.msg("Huh? (Type \"help\" for help.)")
|
||||
|
||||
|
|
|
|||
122
cmdtable.py
122
cmdtable.py
|
|
@ -18,73 +18,73 @@ permissions tuple.
|
|||
"""
|
||||
|
||||
# -- Unlogged-in Command Table --
|
||||
# Command Name Command Function Privilege Tuple
|
||||
# Command Name Command Function Privilege Tuple
|
||||
uncon_ctable = {
|
||||
"connect": (commands.unloggedin.cmd_connect, None),
|
||||
"create": (commands.unloggedin.cmd_create, None),
|
||||
"quit": (commands.unloggedin.cmd_quit, None),
|
||||
"connect": (commands.unloggedin.cmd_connect, None),
|
||||
"create": (commands.unloggedin.cmd_create, None),
|
||||
"quit": (commands.unloggedin.cmd_quit, None),
|
||||
}
|
||||
|
||||
|
||||
# -- Command Table --
|
||||
# Command Name Command Function Privilege Tuple
|
||||
# Command Name Command Function Privilege Tuple
|
||||
ctable = {
|
||||
"addcom": (commands.comsys.cmd_addcom, None),
|
||||
"comlist": (commands.comsys.cmd_comlist, None),
|
||||
"delcom": (commands.comsys.cmd_delcom, None),
|
||||
"drop": (commands.general.cmd_drop, None),
|
||||
"examine": (commands.general.cmd_examine, None),
|
||||
"get": (commands.general.cmd_get, None),
|
||||
"help": (commands.general.cmd_help, None),
|
||||
"idle": (commands.general.cmd_idle, None),
|
||||
"inventory": (commands.general.cmd_inventory, None),
|
||||
"look": (commands.general.cmd_look, None),
|
||||
"page": (commands.general.cmd_page, None),
|
||||
"pose": (commands.general.cmd_pose, None),
|
||||
"quit": (commands.general.cmd_quit, None),
|
||||
"say": (commands.general.cmd_say, None),
|
||||
"time": (commands.general.cmd_time, None),
|
||||
"uptime": (commands.general.cmd_uptime, None),
|
||||
"version": (commands.general.cmd_version, None),
|
||||
"who": (commands.general.cmd_who, None),
|
||||
"@alias": (commands.objmanip.cmd_alias, None),
|
||||
"@boot": (commands.privileged.cmd_boot, ("genperms.manage_players")),
|
||||
"@ccreate": (commands.comsys.cmd_ccreate, ("objects.add_commchannel")),
|
||||
"@cdestroy": (commands.comsys.cmd_cdestroy, ("objects.delete_commchannel")),
|
||||
"@cemit": (commands.comsys.cmd_cemit, None),
|
||||
"@clist": (commands.comsys.cmd_clist, None),
|
||||
"@create": (commands.objmanip.cmd_create, ("genperms.builder")),
|
||||
"@describe": (commands.objmanip.cmd_description, None),
|
||||
"@destroy": (commands.objmanip.cmd_destroy, ("genperms.builder")),
|
||||
"@dig": (commands.objmanip.cmd_dig, ("genperms.builder")),
|
||||
"@emit": (commands.general.cmd_emit, ("genperms.announce")),
|
||||
# "@pemit": (commands.general.cmd_pemit, None),
|
||||
"@find": (commands.objmanip.cmd_find, ("genperms.builder")),
|
||||
"@link": (commands.objmanip.cmd_link, ("genperms.builder")),
|
||||
"@list": (commands.info.cmd_list, ("genperms.process_control")),
|
||||
"@name": (commands.objmanip.cmd_name, None),
|
||||
"@nextfree": (commands.objmanip.cmd_nextfree, ("genperms.builder")),
|
||||
"@newpassword": (commands.privileged.cmd_newpassword, ("genperms.manage_players")),
|
||||
"@open": (commands.objmanip.cmd_open, ("genperms.builder")),
|
||||
"@password": (commands.general.cmd_password, None),
|
||||
"@ps": (commands.info.cmd_ps, ("genperms.process_control")),
|
||||
"@reload": (commands.privileged.cmd_reload, ("genperms.process_control")),
|
||||
"@set": (commands.objmanip.cmd_set, None),
|
||||
"@shutdown": (commands.privileged.cmd_shutdown, ("genperms.process_control")),
|
||||
"@stats": (commands.info.cmd_stats, None),
|
||||
"@teleport": (commands.objmanip.cmd_teleport, ("genperms.builder")),
|
||||
"@unlink": (commands.objmanip.cmd_unlink, ("genperms.builder")),
|
||||
"@wall": (commands.general.cmd_wall, ("genperms.announce")),
|
||||
"@wipe": (commands.objmanip.cmd_wipe, None),
|
||||
"addcom": (commands.comsys.cmd_addcom, None),
|
||||
"comlist": (commands.comsys.cmd_comlist, None),
|
||||
"delcom": (commands.comsys.cmd_delcom, None),
|
||||
"drop": (commands.general.cmd_drop, None),
|
||||
"examine": (commands.general.cmd_examine, None),
|
||||
"get": (commands.general.cmd_get, None),
|
||||
"help": (commands.general.cmd_help, None),
|
||||
"idle": (commands.general.cmd_idle, None),
|
||||
"inventory": (commands.general.cmd_inventory, None),
|
||||
"look": (commands.general.cmd_look, None),
|
||||
"page": (commands.general.cmd_page, None),
|
||||
"pose": (commands.general.cmd_pose, None),
|
||||
"quit": (commands.general.cmd_quit, None),
|
||||
"say": (commands.general.cmd_say, None),
|
||||
"time": (commands.general.cmd_time, None),
|
||||
"uptime": (commands.general.cmd_uptime, None),
|
||||
"version": (commands.general.cmd_version, None),
|
||||
"who": (commands.general.cmd_who, None),
|
||||
"@alias": (commands.objmanip.cmd_alias, None),
|
||||
"@boot": (commands.privileged.cmd_boot, ("genperms.manage_players")),
|
||||
"@ccreate": (commands.comsys.cmd_ccreate, ("objects.add_commchannel")),
|
||||
"@cdestroy": (commands.comsys.cmd_cdestroy, ("objects.delete_commchannel")),
|
||||
"@cemit": (commands.comsys.cmd_cemit, None),
|
||||
"@clist": (commands.comsys.cmd_clist, None),
|
||||
"@create": (commands.objmanip.cmd_create, ("genperms.builder")),
|
||||
"@describe": (commands.objmanip.cmd_description, None),
|
||||
"@destroy": (commands.objmanip.cmd_destroy, ("genperms.builder")),
|
||||
"@dig": (commands.objmanip.cmd_dig, ("genperms.builder")),
|
||||
"@emit": (commands.general.cmd_emit, ("genperms.announce")),
|
||||
# "@pemit": (commands.general.cmd_pemit, None),
|
||||
"@find": (commands.objmanip.cmd_find, ("genperms.builder")),
|
||||
"@link": (commands.objmanip.cmd_link, ("genperms.builder")),
|
||||
"@list": (commands.info.cmd_list, ("genperms.process_control")),
|
||||
"@name": (commands.objmanip.cmd_name, None),
|
||||
"@nextfree": (commands.objmanip.cmd_nextfree, ("genperms.builder")),
|
||||
"@newpassword": (commands.privileged.cmd_newpassword, ("genperms.manage_players")),
|
||||
"@open": (commands.objmanip.cmd_open, ("genperms.builder")),
|
||||
"@password": (commands.general.cmd_password, None),
|
||||
"@ps": (commands.info.cmd_ps, ("genperms.process_control")),
|
||||
"@reload": (commands.privileged.cmd_reload, ("genperms.process_control")),
|
||||
"@set": (commands.objmanip.cmd_set, None),
|
||||
"@shutdown": (commands.privileged.cmd_shutdown, ("genperms.process_control")),
|
||||
"@stats": (commands.info.cmd_stats, None),
|
||||
"@teleport": (commands.objmanip.cmd_teleport, ("genperms.builder")),
|
||||
"@unlink": (commands.objmanip.cmd_unlink, ("genperms.builder")),
|
||||
"@wall": (commands.general.cmd_wall, ("genperms.announce")),
|
||||
"@wipe": (commands.objmanip.cmd_wipe, None),
|
||||
}
|
||||
|
||||
def return_cmdtuple(func_name, unlogged_cmd=False):
|
||||
"""
|
||||
Returns a reference to the command's tuple. If there are no matches,
|
||||
returns false.
|
||||
"""
|
||||
if not unlogged_cmd:
|
||||
cfunc = ctable.get(func_name, False)
|
||||
else:
|
||||
cfunc = uncon_ctable.get(func_name, False)
|
||||
return cfunc
|
||||
"""
|
||||
Returns a reference to the command's tuple. If there are no matches,
|
||||
returns false.
|
||||
"""
|
||||
if not unlogged_cmd:
|
||||
cfunc = ctable.get(func_name, False)
|
||||
else:
|
||||
cfunc = uncon_ctable.get(func_name, False)
|
||||
return cfunc
|
||||
|
|
|
|||
|
|
@ -13,281 +13,281 @@ now.
|
|||
"""
|
||||
|
||||
def cmd_addcom(cdat):
|
||||
"""
|
||||
addcom
|
||||
"""
|
||||
addcom
|
||||
|
||||
Adds an alias for a channel.
|
||||
addcom foo=Bar
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("You need to specify a channel alias and name.")
|
||||
return
|
||||
|
||||
eq_args = args[0].split('=')
|
||||
Adds an alias for a channel.
|
||||
addcom foo=Bar
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("You need to specify a channel alias and name.")
|
||||
return
|
||||
|
||||
eq_args = args[0].split('=')
|
||||
|
||||
if len(eq_args) < 2:
|
||||
session.msg("You need to specify a channel name.")
|
||||
return
|
||||
|
||||
chan_alias = eq_args[0]
|
||||
chan_name = eq_args[1]
|
||||
if len(eq_args) < 2:
|
||||
session.msg("You need to specify a channel name.")
|
||||
return
|
||||
|
||||
chan_alias = eq_args[0]
|
||||
chan_name = eq_args[1]
|
||||
|
||||
if len(chan_name) == 0:
|
||||
session.msg("You need to specify a channel name.")
|
||||
return
|
||||
if len(chan_name) == 0:
|
||||
session.msg("You need to specify a channel name.")
|
||||
return
|
||||
|
||||
if chan_alias in session.channels_subscribed:
|
||||
session.msg("You are already on that channel.")
|
||||
return
|
||||
if chan_alias in session.channels_subscribed:
|
||||
session.msg("You are already on that channel.")
|
||||
return
|
||||
|
||||
name_matches = functions_comsys.cname_search(chan_name, exact=True)
|
||||
name_matches = functions_comsys.cname_search(chan_name, exact=True)
|
||||
|
||||
if name_matches:
|
||||
chan_name_parsed = name_matches[0].get_name()
|
||||
session.msg("You join %s, with an alias of %s." % \
|
||||
(chan_name_parsed, chan_alias))
|
||||
functions_comsys.plr_set_channel(session, chan_alias, chan_name_parsed, True)
|
||||
if name_matches:
|
||||
chan_name_parsed = name_matches[0].get_name()
|
||||
session.msg("You join %s, with an alias of %s." % \
|
||||
(chan_name_parsed, chan_alias))
|
||||
functions_comsys.plr_set_channel(session, chan_alias, chan_name_parsed, True)
|
||||
|
||||
# Announce the user's joining.
|
||||
join_msg = "[%s] %s has joined the channel." % \
|
||||
(chan_name_parsed, pobject.get_name(show_dbref=False))
|
||||
functions_comsys.send_cmessage(chan_name_parsed, join_msg)
|
||||
else:
|
||||
session.msg("Could not find channel %s." % (chan_name,))
|
||||
# Announce the user's joining.
|
||||
join_msg = "[%s] %s has joined the channel." % \
|
||||
(chan_name_parsed, pobject.get_name(show_dbref=False))
|
||||
functions_comsys.send_cmessage(chan_name_parsed, join_msg)
|
||||
else:
|
||||
session.msg("Could not find channel %s." % (chan_name,))
|
||||
|
||||
def cmd_delcom(cdat):
|
||||
"""
|
||||
delcom
|
||||
"""
|
||||
delcom
|
||||
|
||||
Removes the specified alias to a channel. If this is the last alias,
|
||||
the user is effectively removed from the channel.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
uinput= cdat['uinput']['splitted']
|
||||
chan_alias = ' '.join(uinput[1:])
|
||||
Removes the specified alias to a channel. If this is the last alias,
|
||||
the user is effectively removed from the channel.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
uinput= cdat['uinput']['splitted']
|
||||
chan_alias = ' '.join(uinput[1:])
|
||||
|
||||
if len(chan_alias) == 0:
|
||||
session.msg("You must specify a channel alias.")
|
||||
return
|
||||
if len(chan_alias) == 0:
|
||||
session.msg("You must specify a channel alias.")
|
||||
return
|
||||
|
||||
if chan_alias not in session.channels_subscribed:
|
||||
session.msg("You are not on that channel.")
|
||||
return
|
||||
if chan_alias not in session.channels_subscribed:
|
||||
session.msg("You are not on that channel.")
|
||||
return
|
||||
|
||||
chan_name = session.channels_subscribed[chan_alias][0]
|
||||
session.msg("You have left %s." % (chan_name,))
|
||||
functions_comsys.plr_del_channel(session, chan_alias)
|
||||
chan_name = session.channels_subscribed[chan_alias][0]
|
||||
session.msg("You have left %s." % (chan_name,))
|
||||
functions_comsys.plr_del_channel(session, chan_alias)
|
||||
|
||||
# Announce the user's leaving.
|
||||
leave_msg = "[%s] %s has left the channel." % \
|
||||
(chan_name, pobject.get_name(show_dbref=False))
|
||||
functions_comsys.send_cmessage(chan_name, leave_msg)
|
||||
# Announce the user's leaving.
|
||||
leave_msg = "[%s] %s has left the channel." % \
|
||||
(chan_name, pobject.get_name(show_dbref=False))
|
||||
functions_comsys.send_cmessage(chan_name, leave_msg)
|
||||
|
||||
def cmd_comlist(cdat):
|
||||
"""
|
||||
Lists the channels a user is subscribed to.
|
||||
"""
|
||||
session = cdat['session']
|
||||
"""
|
||||
Lists the channels a user is subscribed to.
|
||||
"""
|
||||
session = cdat['session']
|
||||
|
||||
session.msg("Alias Channel Status")
|
||||
for chan in session.channels_subscribed:
|
||||
if session.channels_subscribed[chan][1]:
|
||||
chan_on = "On"
|
||||
else:
|
||||
chan_on = "Off"
|
||||
|
||||
session.msg("%-9.9s %-19.19s %s" %
|
||||
(chan, session.channels_subscribed[chan][0], chan_on))
|
||||
session.msg("-- End of comlist --")
|
||||
|
||||
session.msg("Alias Channel Status")
|
||||
for chan in session.channels_subscribed:
|
||||
if session.channels_subscribed[chan][1]:
|
||||
chan_on = "On"
|
||||
else:
|
||||
chan_on = "Off"
|
||||
|
||||
session.msg("%-9.9s %-19.19s %s" %
|
||||
(chan, session.channels_subscribed[chan][0], chan_on))
|
||||
session.msg("-- End of comlist --")
|
||||
|
||||
def cmd_allcom(cdat):
|
||||
"""
|
||||
allcom
|
||||
"""
|
||||
allcom
|
||||
|
||||
Allows the user to universally turn off or on all channels they are on,
|
||||
as well as perform a "who" for all channels they are on.
|
||||
"""
|
||||
pass
|
||||
Allows the user to universally turn off or on all channels they are on,
|
||||
as well as perform a "who" for all channels they are on.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_clearcom(cdat):
|
||||
"""
|
||||
clearcom
|
||||
"""
|
||||
clearcom
|
||||
|
||||
Effectively runs delcom on all channels the user is on. It will remove their aliases,
|
||||
remove them from the channel, and clear any titles they have set.
|
||||
"""
|
||||
pass
|
||||
Effectively runs delcom on all channels the user is on. It will remove their aliases,
|
||||
remove them from the channel, and clear any titles they have set.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_clist(cdat):
|
||||
"""
|
||||
@clist
|
||||
"""
|
||||
@clist
|
||||
|
||||
Lists all available channels on the game.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg("** Channel Owner Description")
|
||||
for chan in functions_comsys.get_all_channels():
|
||||
session.msg("%s%s %-13.13s %-15.15s %-45.45s" %
|
||||
('-', '-', chan.get_name(), chan.get_owner().get_name(), 'No Description'))
|
||||
session.msg("-- End of Channel List --")
|
||||
Lists all available channels on the game.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg("** Channel Owner Description")
|
||||
for chan in functions_comsys.get_all_channels():
|
||||
session.msg("%s%s %-13.13s %-15.15s %-45.45s" %
|
||||
('-', '-', chan.get_name(), chan.get_owner().get_name(), 'No Description'))
|
||||
session.msg("-- End of Channel List --")
|
||||
|
||||
def cmd_cdestroy(cdat):
|
||||
"""
|
||||
@cdestroy
|
||||
"""
|
||||
@cdestroy
|
||||
|
||||
Destroys a channel.
|
||||
"""
|
||||
session = cdat['session']
|
||||
uinput= cdat['uinput']['splitted']
|
||||
cname = ' '.join(uinput[1:])
|
||||
Destroys a channel.
|
||||
"""
|
||||
session = cdat['session']
|
||||
uinput= cdat['uinput']['splitted']
|
||||
cname = ' '.join(uinput[1:])
|
||||
|
||||
if cname == '':
|
||||
session.msg("You must supply a name!")
|
||||
return
|
||||
if cname == '':
|
||||
session.msg("You must supply a name!")
|
||||
return
|
||||
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
|
||||
if not name_matches:
|
||||
session.msg("Could not find channel %s." % (cname,))
|
||||
else:
|
||||
session.msg("Channel %s destroyed." % (name_matches[0],))
|
||||
name_matches.delete()
|
||||
|
||||
if not name_matches:
|
||||
session.msg("Could not find channel %s." % (cname,))
|
||||
else:
|
||||
session.msg("Channel %s destroyed." % (name_matches[0],))
|
||||
name_matches.delete()
|
||||
|
||||
def cmd_cset(cdat):
|
||||
"""
|
||||
@cset
|
||||
"""
|
||||
@cset
|
||||
|
||||
Sets various flags on a channel.
|
||||
"""
|
||||
pass
|
||||
Sets various flags on a channel.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def cmd_ccharge(cdat):
|
||||
"""
|
||||
@ccharge
|
||||
"""
|
||||
@ccharge
|
||||
|
||||
Sets the cost to transmit over a channel. Default is free.
|
||||
"""
|
||||
pass
|
||||
Sets the cost to transmit over a channel. Default is free.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_cboot(cdat):
|
||||
"""
|
||||
@cboot
|
||||
"""
|
||||
@cboot
|
||||
|
||||
Kicks a player or object from the channel.
|
||||
"""
|
||||
pass
|
||||
Kicks a player or object from the channel.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_cemit(cdat):
|
||||
"""
|
||||
@cemit
|
||||
@cemit/noheader <message>
|
||||
@cemit/sendername <message>
|
||||
"""
|
||||
@cemit
|
||||
@cemit/noheader <message>
|
||||
@cemit/sendername <message>
|
||||
|
||||
Allows the user to send a message over a channel as long as
|
||||
they own or control it. It does not show the user's name unless they
|
||||
provide the /sendername switch.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
switches = cdat['uinput']['root_chunk'][1:]
|
||||
Allows the user to send a message over a channel as long as
|
||||
they own or control it. It does not show the user's name unless they
|
||||
provide the /sendername switch.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
switches = cdat['uinput']['root_chunk'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Channel emit what?")
|
||||
return
|
||||
if len(args) == 0:
|
||||
session.msg("Channel emit what?")
|
||||
return
|
||||
|
||||
# Combine the arguments into one string, split it by equal signs into
|
||||
# channel (entry 0 in the list), and message (entry 1 and above).
|
||||
eq_args = ' '.join(args).split('=')
|
||||
cname = eq_args[0]
|
||||
cmessage = ' '.join(eq_args[1:])
|
||||
if len(eq_args) != 2:
|
||||
session.msg("You must provide a channel name and a message to emit.")
|
||||
return
|
||||
if len(cname) == 0:
|
||||
session.msg("You must provide a channel name to emit to.")
|
||||
return
|
||||
if len(cmessage) == 0:
|
||||
session.msg("You must provide a message to emit.")
|
||||
return
|
||||
# Combine the arguments into one string, split it by equal signs into
|
||||
# channel (entry 0 in the list), and message (entry 1 and above).
|
||||
eq_args = ' '.join(args).split('=')
|
||||
cname = eq_args[0]
|
||||
cmessage = ' '.join(eq_args[1:])
|
||||
if len(eq_args) != 2:
|
||||
session.msg("You must provide a channel name and a message to emit.")
|
||||
return
|
||||
if len(cname) == 0:
|
||||
session.msg("You must provide a channel name to emit to.")
|
||||
return
|
||||
if len(cmessage) == 0:
|
||||
session.msg("You must provide a message to emit.")
|
||||
return
|
||||
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
|
||||
try:
|
||||
# Safety first, kids!
|
||||
cname_parsed = name_matches[0].get_name()
|
||||
except:
|
||||
session.msg("Could not find channel %s." % (cname,))
|
||||
return
|
||||
try:
|
||||
# Safety first, kids!
|
||||
cname_parsed = name_matches[0].get_name()
|
||||
except:
|
||||
session.msg("Could not find channel %s." % (cname,))
|
||||
return
|
||||
|
||||
if "noheader" in switches:
|
||||
if not pobject.user_has_perm("objects.emit_commchannel"):
|
||||
session.msg(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
final_cmessage = cmessage
|
||||
else:
|
||||
if "sendername" in switches:
|
||||
if not functions_comsys.plr_has_channel(session, cname_parsed, return_muted=False):
|
||||
session.msg("You must be on %s to do that." % (cname_parsed,))
|
||||
return
|
||||
final_cmessage = "[%s] %s: %s" % (cname_parsed, pobject.get_name(show_dbref=False), cmessage)
|
||||
else:
|
||||
if not pobject.user_has_perm("objects.emit_commchannel"):
|
||||
if "noheader" in switches:
|
||||
if not pobject.user_has_perm("objects.emit_commchannel"):
|
||||
session.msg(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
final_cmessage = "[%s] %s" % (cname_parsed, cmessage)
|
||||
final_cmessage = cmessage
|
||||
else:
|
||||
if "sendername" in switches:
|
||||
if not functions_comsys.plr_has_channel(session, cname_parsed, return_muted=False):
|
||||
session.msg("You must be on %s to do that." % (cname_parsed,))
|
||||
return
|
||||
final_cmessage = "[%s] %s: %s" % (cname_parsed, pobject.get_name(show_dbref=False), cmessage)
|
||||
else:
|
||||
if not pobject.user_has_perm("objects.emit_commchannel"):
|
||||
session.msg(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
final_cmessage = "[%s] %s" % (cname_parsed, cmessage)
|
||||
|
||||
if not "quiet" in switches:
|
||||
session.msg("Sent - %s" % (name_matches[0],))
|
||||
functions_comsys.send_cmessage(cname_parsed, final_cmessage)
|
||||
if not "quiet" in switches:
|
||||
session.msg("Sent - %s" % (name_matches[0],))
|
||||
functions_comsys.send_cmessage(cname_parsed, final_cmessage)
|
||||
|
||||
def cmd_cwho(cdat):
|
||||
"""
|
||||
@cwho
|
||||
"""
|
||||
@cwho
|
||||
|
||||
Displays the name, status and object type for a given channel.
|
||||
Adding /all after the channel name will list disconnected players
|
||||
as well.
|
||||
"""
|
||||
pass
|
||||
Displays the name, status and object type for a given channel.
|
||||
Adding /all after the channel name will list disconnected players
|
||||
as well.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_ccreate(cdat):
|
||||
"""
|
||||
@ccreate
|
||||
"""
|
||||
@ccreate
|
||||
|
||||
Creates a new channel with the invoker being the default owner.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
uinput= cdat['uinput']['splitted']
|
||||
cname = ' '.join(uinput[1:])
|
||||
Creates a new channel with the invoker being the default owner.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
uinput= cdat['uinput']['splitted']
|
||||
cname = ' '.join(uinput[1:])
|
||||
|
||||
if cname == '':
|
||||
session.msg("You must supply a name!")
|
||||
return
|
||||
if cname == '':
|
||||
session.msg("You must supply a name!")
|
||||
return
|
||||
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
|
||||
if name_matches:
|
||||
session.msg("A channel with that name already exists.")
|
||||
else:
|
||||
# Create and set the object up.
|
||||
cdat = {"name": cname, "owner": pobject}
|
||||
new_chan = functions_comsys.create_channel(cdat)
|
||||
session.msg("Channel %s created." % (new_chan.get_name(),))
|
||||
if name_matches:
|
||||
session.msg("A channel with that name already exists.")
|
||||
else:
|
||||
# Create and set the object up.
|
||||
cdat = {"name": cname, "owner": pobject}
|
||||
new_chan = functions_comsys.create_channel(cdat)
|
||||
session.msg("Channel %s created." % (new_chan.get_name(),))
|
||||
|
||||
def cmd_cchown(cdat):
|
||||
"""
|
||||
@cchown
|
||||
"""
|
||||
@cchown
|
||||
|
||||
Changes the owner of a channel.
|
||||
"""
|
||||
pass
|
||||
Changes the owner of a channel.
|
||||
"""
|
||||
pass
|
||||
|
|
|
|||
116
commands/info.py
116
commands/info.py
|
|
@ -1,70 +1,70 @@
|
|||
import gameconf
|
||||
if not gameconf.host_os_is('nt'):
|
||||
# Don't import the resource module if the host OS is Windows.
|
||||
import resource
|
||||
# Don't import the resource module if the host OS is Windows.
|
||||
import resource
|
||||
import os
|
||||
|
||||
import functions_db
|
||||
import scheduler
|
||||
|
||||
def cmd_list(cdat):
|
||||
"""
|
||||
Shows some game related information.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
argstr = ''.join(args)
|
||||
|
||||
msg_invalid = "Unknown option. Use one of: commands, flags, process"
|
||||
|
||||
if len(argstr) == 0:
|
||||
session.msg(msg_invalid)
|
||||
elif argstr == "commands":
|
||||
session.msg('Commands: '+ ' '.join(session.server.command_list()))
|
||||
elif argstr == "process":
|
||||
if not gameconf.host_os_is('nt'):
|
||||
loadvg = os.getloadavg()
|
||||
psize = resource.getpagesize()
|
||||
rusage = resource.getrusage(resource.RUSAGE_SELF)
|
||||
session.msg("Process ID: %10d %10d bytes per page" % (os.getpid(), psize))
|
||||
session.msg("Time used: %10d user %10d sys" % (rusage[0],rusage[1]))
|
||||
session.msg("Integral mem:%10d shared %10d private%10d stack" % (rusage[3], rusage[4], rusage[5]))
|
||||
session.msg("Max res mem: %10d pages %10d bytes" % (rusage[2],rusage[2] * psize))
|
||||
session.msg("Page faults: %10d hard %10d soft %10d swapouts" % (rusage[7], rusage[6], rusage[8]))
|
||||
session.msg("Disk I/O: %10d reads %10d writes" % (rusage[9], rusage[10]))
|
||||
session.msg("Network I/O: %10d in %10d out" % (rusage[12], rusage[11]))
|
||||
session.msg("Context swi: %10d vol %10d forced %10d sigs" % (rusage[14], rusage[15], rusage[13]))
|
||||
else:
|
||||
session.msg("Feature not available on Windows.")
|
||||
return
|
||||
elif argstr == "flags":
|
||||
session.msg("Flags: "+" ".join(defines_global.SERVER_FLAGS))
|
||||
else:
|
||||
session.msg(msg_invalid)
|
||||
"""
|
||||
Shows some game related information.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
argstr = ''.join(args)
|
||||
|
||||
msg_invalid = "Unknown option. Use one of: commands, flags, process"
|
||||
|
||||
if len(argstr) == 0:
|
||||
session.msg(msg_invalid)
|
||||
elif argstr == "commands":
|
||||
session.msg('Commands: '+ ' '.join(session.server.command_list()))
|
||||
elif argstr == "process":
|
||||
if not gameconf.host_os_is('nt'):
|
||||
loadvg = os.getloadavg()
|
||||
psize = resource.getpagesize()
|
||||
rusage = resource.getrusage(resource.RUSAGE_SELF)
|
||||
session.msg("Process ID: %10d %10d bytes per page" % (os.getpid(), psize))
|
||||
session.msg("Time used: %10d user %10d sys" % (rusage[0],rusage[1]))
|
||||
session.msg("Integral mem:%10d shared %10d private%10d stack" % (rusage[3], rusage[4], rusage[5]))
|
||||
session.msg("Max res mem: %10d pages %10d bytes" % (rusage[2],rusage[2] * psize))
|
||||
session.msg("Page faults: %10d hard %10d soft %10d swapouts" % (rusage[7], rusage[6], rusage[8]))
|
||||
session.msg("Disk I/O: %10d reads %10d writes" % (rusage[9], rusage[10]))
|
||||
session.msg("Network I/O: %10d in %10d out" % (rusage[12], rusage[11]))
|
||||
session.msg("Context swi: %10d vol %10d forced %10d sigs" % (rusage[14], rusage[15], rusage[13]))
|
||||
else:
|
||||
session.msg("Feature not available on Windows.")
|
||||
return
|
||||
elif argstr == "flags":
|
||||
session.msg("Flags: "+" ".join(defines_global.SERVER_FLAGS))
|
||||
else:
|
||||
session.msg(msg_invalid)
|
||||
|
||||
def cmd_ps(cdat):
|
||||
"""
|
||||
Shows the process/event table.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg("-- Interval Events --")
|
||||
for event in scheduler.schedule:
|
||||
session.msg(" [%d/%d] %s" % (scheduler.get_event_nextfire(event),
|
||||
scheduler.get_event_interval(event),
|
||||
scheduler.get_event_description(event)))
|
||||
session.msg("Totals: %d interval events" % (len(scheduler.schedule),))
|
||||
"""
|
||||
Shows the process/event table.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg("-- Interval Events --")
|
||||
for event in scheduler.schedule:
|
||||
session.msg(" [%d/%d] %s" % (scheduler.get_event_nextfire(event),
|
||||
scheduler.get_event_interval(event),
|
||||
scheduler.get_event_description(event)))
|
||||
session.msg("Totals: %d interval events" % (len(scheduler.schedule),))
|
||||
|
||||
def cmd_stats(cdat):
|
||||
"""
|
||||
Shows stats about the database.
|
||||
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
|
||||
"""
|
||||
session = cdat['session']
|
||||
stats_dict = functions_db.object_totals()
|
||||
session.msg("%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)" % (stats_dict["objects"],
|
||||
stats_dict["rooms"],
|
||||
stats_dict["exits"],
|
||||
stats_dict["things"],
|
||||
stats_dict["players"],
|
||||
stats_dict["garbage"]))
|
||||
"""
|
||||
Shows stats about the database.
|
||||
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
|
||||
"""
|
||||
session = cdat['session']
|
||||
stats_dict = functions_db.object_totals()
|
||||
session.msg("%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)" % (stats_dict["objects"],
|
||||
stats_dict["rooms"],
|
||||
stats_dict["exits"],
|
||||
stats_dict["things"],
|
||||
stats_dict["players"],
|
||||
stats_dict["garbage"]))
|
||||
|
|
|
|||
|
|
@ -9,122 +9,122 @@ are generally @-prefixed commands, but there are exceptions.
|
|||
"""
|
||||
|
||||
def cmd_reload(cdat):
|
||||
"""
|
||||
Reloads all modules.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = session.server.reload(session)
|
||||
"""
|
||||
Reloads all modules.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = session.server.reload(session)
|
||||
|
||||
def cmd_boot(cdat):
|
||||
"""
|
||||
Boot a player object from the server.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
eq_args = ' '.join(args).split('=')
|
||||
searchstring = ''.join(eq_args[0])
|
||||
switches = cdat['uinput']['root_chunk'][1:]
|
||||
switch_quiet = False
|
||||
switch_port = False
|
||||
"""
|
||||
Boot a player object from the server.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
eq_args = ' '.join(args).split('=')
|
||||
searchstring = ''.join(eq_args[0])
|
||||
switches = cdat['uinput']['root_chunk'][1:]
|
||||
switch_quiet = False
|
||||
switch_port = False
|
||||
|
||||
if not pobject.is_staff():
|
||||
session.msg("You do not have permission to do that.")
|
||||
return
|
||||
if not pobject.is_staff():
|
||||
session.msg("You do not have permission to do that.")
|
||||
return
|
||||
|
||||
if "quiet" in switches:
|
||||
switch_quiet = True
|
||||
if "quiet" in switches:
|
||||
switch_quiet = True
|
||||
|
||||
if "port" in switches:
|
||||
switch_port = True
|
||||
if "port" in switches:
|
||||
switch_port = True
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Who would you like to boot?")
|
||||
return
|
||||
else:
|
||||
boot_list = []
|
||||
if switch_port:
|
||||
sessions = session_mgr.get_session_list(True)
|
||||
for sess in sessions:
|
||||
if sess.getClientAddress()[1] == int(searchstring):
|
||||
boot_list.append(sess)
|
||||
# We're done here
|
||||
break
|
||||
else:
|
||||
# Grab the objects that match
|
||||
objs = functions_db.global_object_name_search(searchstring)
|
||||
|
||||
if len(objs) < 1:
|
||||
session.msg("Who would you like to boot?")
|
||||
if len(args) == 0:
|
||||
session.msg("Who would you like to boot?")
|
||||
return
|
||||
else:
|
||||
boot_list = []
|
||||
if switch_port:
|
||||
sessions = session_mgr.get_session_list(True)
|
||||
for sess in sessions:
|
||||
if sess.getClientAddress()[1] == int(searchstring):
|
||||
boot_list.append(sess)
|
||||
# We're done here
|
||||
break
|
||||
else:
|
||||
# Grab the objects that match
|
||||
objs = functions_db.global_object_name_search(searchstring)
|
||||
|
||||
if len(objs) < 1:
|
||||
session.msg("Who would you like to boot?")
|
||||
return
|
||||
|
||||
if not objs[0].is_player():
|
||||
session.msg("You can only boot players.")
|
||||
return
|
||||
|
||||
if not pobject.controls_other(objs[0]):
|
||||
if objs[0].is_superuser():
|
||||
session.msg("You cannot boot a Wizard.")
|
||||
return
|
||||
else:
|
||||
session.msg("You do not have permission to boot that player.")
|
||||
return
|
||||
|
||||
if objs[0].is_connected_plr():
|
||||
boot_list.append(session_mgr.session_from_object(objs[0]))
|
||||
|
||||
for boot in boot_list:
|
||||
if not switch_quiet:
|
||||
boot.msg("You have been disconnected by %s." % (pobject.name))
|
||||
boot.disconnectClient()
|
||||
session_mgr.remove_session(boot)
|
||||
return
|
||||
|
||||
if not objs[0].is_player():
|
||||
session.msg("You can only boot players.")
|
||||
return
|
||||
|
||||
if not pobject.controls_other(objs[0]):
|
||||
if objs[0].is_superuser():
|
||||
session.msg("You cannot boot a Wizard.")
|
||||
return
|
||||
else:
|
||||
session.msg("You do not have permission to boot that player.")
|
||||
return
|
||||
|
||||
if objs[0].is_connected_plr():
|
||||
boot_list.append(session_mgr.session_from_object(objs[0]))
|
||||
|
||||
for boot in boot_list:
|
||||
if not switch_quiet:
|
||||
boot.msg("You have been disconnected by %s." % (pobject.name))
|
||||
boot.disconnectClient()
|
||||
session_mgr.remove_session(boot)
|
||||
return
|
||||
|
||||
def cmd_newpassword(cdat):
|
||||
"""
|
||||
Set a player's password.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
eq_args = ' '.join(args).split('=')
|
||||
searchstring = ''.join(eq_args[0])
|
||||
newpass = ''.join(eq_args[1:])
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("What player's password do you want to change")
|
||||
return
|
||||
if len(newpass) == 0:
|
||||
session.msg("You must supply a new password.")
|
||||
return
|
||||
"""
|
||||
Set a player's password.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
eq_args = ' '.join(args).split('=')
|
||||
searchstring = ''.join(eq_args[0])
|
||||
newpass = ''.join(eq_args[1:])
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("What player's password do you want to change")
|
||||
return
|
||||
if len(newpass) == 0:
|
||||
session.msg("You must supply a new password.")
|
||||
return
|
||||
|
||||
target_obj = functions_db.standard_plr_objsearch(session, searchstring)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
target_obj = functions_db.standard_plr_objsearch(session, searchstring)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if not target_obj.is_player():
|
||||
session.msg("You can only change passwords on players.")
|
||||
elif not pobject.controls_other(target_obj):
|
||||
session.msg("You do not control %s." % (target_obj.get_name(),))
|
||||
else:
|
||||
uaccount = target_obj.get_user_account()
|
||||
if len(newpass) == 0:
|
||||
uaccount.set_password()
|
||||
else:
|
||||
uaccount.set_password(newpass)
|
||||
uaccount.save()
|
||||
session.msg("%s - PASSWORD set." % (target_obj.get_name(),))
|
||||
target_obj.emit_to("%s has changed your password." % (pobject.get_name(show_dbref=False),))
|
||||
if not target_obj.is_player():
|
||||
session.msg("You can only change passwords on players.")
|
||||
elif not pobject.controls_other(target_obj):
|
||||
session.msg("You do not control %s." % (target_obj.get_name(),))
|
||||
else:
|
||||
uaccount = target_obj.get_user_account()
|
||||
if len(newpass) == 0:
|
||||
uaccount.set_password()
|
||||
else:
|
||||
uaccount.set_password(newpass)
|
||||
uaccount.save()
|
||||
session.msg("%s - PASSWORD set." % (target_obj.get_name(),))
|
||||
target_obj.emit_to("%s has changed your password." % (pobject.get_name(show_dbref=False),))
|
||||
|
||||
def cmd_shutdown(cdat):
|
||||
"""
|
||||
Shut the server down gracefully.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = cdat['server']
|
||||
pobject = session.get_pobject()
|
||||
|
||||
session.msg('Shutting down...')
|
||||
print 'Server shutdown by %s' % (pobject.get_name(show_dbref=False),)
|
||||
server.shutdown()
|
||||
"""
|
||||
Shut the server down gracefully.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = cdat['server']
|
||||
pobject = session.get_pobject()
|
||||
|
||||
session.msg('Shutting down...')
|
||||
print 'Server shutdown by %s' % (pobject.get_name(show_dbref=False),)
|
||||
server.shutdown()
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
# Do not mess with the default types (0-5). This is passed to the Object
|
||||
# model's 'choices' argument.
|
||||
OBJECT_TYPES = (
|
||||
(0, 'NOTHING'),
|
||||
(1, 'PLAYER'),
|
||||
(2, 'ROOM'),
|
||||
(3, 'THING'),
|
||||
(4, 'EXIT'),
|
||||
(5, 'GOING'),
|
||||
(6, 'GARBAGE'),
|
||||
(0, 'NOTHING'),
|
||||
(1, 'PLAYER'),
|
||||
(2, 'ROOM'),
|
||||
(3, 'THING'),
|
||||
(4, 'EXIT'),
|
||||
(5, 'GOING'),
|
||||
(6, 'GARBAGE'),
|
||||
)
|
||||
|
||||
# Hate to duplicate the above, but it's the easiest way.
|
||||
|
|
|
|||
|
|
@ -9,247 +9,247 @@ Comsys functions.
|
|||
"""
|
||||
|
||||
def plr_get_cdict(session):
|
||||
"""
|
||||
Returns the users's channel subscription dictionary. Use this instead of
|
||||
directly referring to the session object.
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
"""
|
||||
return session.channels_subscribed
|
||||
"""
|
||||
Returns the users's channel subscription dictionary. Use this instead of
|
||||
directly referring to the session object.
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
"""
|
||||
return session.channels_subscribed
|
||||
|
||||
def plr_listening_channel(session, cstr, alias_search=False):
|
||||
"""
|
||||
Returns a player's listening status for a channel.
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
cstr: (str) The channel name or alias (depending on alias_search).
|
||||
alias_search: (bool) If true, search by alias. Else search by full name.
|
||||
"""
|
||||
return plr_has_channel(session, cstr, alias_search=alias_search,
|
||||
return_muted=False)
|
||||
|
||||
"""
|
||||
Returns a player's listening status for a channel.
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
cstr: (str) The channel name or alias (depending on alias_search).
|
||||
alias_search: (bool) If true, search by alias. Else search by full name.
|
||||
"""
|
||||
return plr_has_channel(session, cstr, alias_search=alias_search,
|
||||
return_muted=False)
|
||||
|
||||
def plr_cname_from_alias(session, calias):
|
||||
"""
|
||||
Returns a channel name given a channel alias.
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
calias: (str) The channel alias.
|
||||
"""
|
||||
return plr_get_cdict(session).get(calias, None)[0]
|
||||
"""
|
||||
Returns a channel name given a channel alias.
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
calias: (str) The channel alias.
|
||||
"""
|
||||
return plr_get_cdict(session).get(calias, None)[0]
|
||||
|
||||
def plr_chan_off(session, calias):
|
||||
"""
|
||||
Turn a channel off for a player.
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
calias: (str) The channel alias.
|
||||
"""
|
||||
if not plr_listening_channel(session, calias, alias_search=True):
|
||||
session.msg("You're already not listening to that channel.")
|
||||
return
|
||||
else:
|
||||
cname = plr_cname_from_alias(session, calias)
|
||||
cobj = get_cobj_from_name(cname)
|
||||
plr_set_channel_listening(session, calias, False)
|
||||
session.msg("You have left %s." % (cname,))
|
||||
send_cmessage(cname, "%s %s has left the channel." % (cobj.get_header(),
|
||||
session.get_pobject().get_name(show_dbref=False)))
|
||||
"""
|
||||
Turn a channel off for a player.
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
calias: (str) The channel alias.
|
||||
"""
|
||||
if not plr_listening_channel(session, calias, alias_search=True):
|
||||
session.msg("You're already not listening to that channel.")
|
||||
return
|
||||
else:
|
||||
cname = plr_cname_from_alias(session, calias)
|
||||
cobj = get_cobj_from_name(cname)
|
||||
plr_set_channel_listening(session, calias, False)
|
||||
session.msg("You have left %s." % (cname,))
|
||||
send_cmessage(cname, "%s %s has left the channel." % (cobj.get_header(),
|
||||
session.get_pobject().get_name(show_dbref=False)))
|
||||
|
||||
def plr_chan_on(session, calias):
|
||||
"""
|
||||
Turn a channel on for a player.
|
||||
"""
|
||||
Turn a channel on for a player.
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
calias: (str) The channel alias.
|
||||
"""
|
||||
plr_listening = plr_listening_channel(session, calias, alias_search=True)
|
||||
if plr_listening:
|
||||
session.msg("You're already listening to that channel.")
|
||||
return
|
||||
else:
|
||||
cname = plr_cname_from_alias(session, calias)
|
||||
cobj = get_cobj_from_name(cname)
|
||||
send_cmessage(cname, "%s %s has joined the channel." % (cobj.get_header(),
|
||||
session.get_pobject().get_name(show_dbref=False)))
|
||||
plr_set_channel_listening(session, calias, True)
|
||||
session.msg("You have joined %s." % (cname,))
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
calias: (str) The channel alias.
|
||||
"""
|
||||
plr_listening = plr_listening_channel(session, calias, alias_search=True)
|
||||
if plr_listening:
|
||||
session.msg("You're already listening to that channel.")
|
||||
return
|
||||
else:
|
||||
cname = plr_cname_from_alias(session, calias)
|
||||
cobj = get_cobj_from_name(cname)
|
||||
send_cmessage(cname, "%s %s has joined the channel." % (cobj.get_header(),
|
||||
session.get_pobject().get_name(show_dbref=False)))
|
||||
plr_set_channel_listening(session, calias, True)
|
||||
session.msg("You have joined %s." % (cname,))
|
||||
|
||||
def plr_has_channel(session, cname, alias_search=False, return_muted=False):
|
||||
"""
|
||||
Is this session subscribed to the named channel?
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
cname: (str) The channel name or alias (depending on alias_search)
|
||||
alias_search: (bool) If False, search by full name. Else search by alias.
|
||||
return_muted: (bool) Take the user's enabling/disabling of the channel
|
||||
into consideration?
|
||||
"""
|
||||
has_channel = False
|
||||
"""
|
||||
Is this session subscribed to the named channel?
|
||||
|
||||
session: (SessionProtocol) Reference to a player session.
|
||||
cname: (str) The channel name or alias (depending on alias_search)
|
||||
alias_search: (bool) If False, search by full name. Else search by alias.
|
||||
return_muted: (bool) Take the user's enabling/disabling of the channel
|
||||
into consideration?
|
||||
"""
|
||||
has_channel = False
|
||||
|
||||
if alias_search:
|
||||
# Search by aliases only.
|
||||
cdat = plr_get_cdict(session).get(cname, False)
|
||||
# No key match, fail immediately.
|
||||
if not cdat:
|
||||
return False
|
||||
|
||||
# If channel status is taken into consideration, see if the user
|
||||
# has the channel muted or not.
|
||||
if return_muted:
|
||||
return True
|
||||
else:
|
||||
return cdat[1]
|
||||
if alias_search:
|
||||
# Search by aliases only.
|
||||
cdat = plr_get_cdict(session).get(cname, False)
|
||||
# No key match, fail immediately.
|
||||
if not cdat:
|
||||
return False
|
||||
|
||||
# If channel status is taken into consideration, see if the user
|
||||
# has the channel muted or not.
|
||||
if return_muted:
|
||||
return True
|
||||
else:
|
||||
return cdat[1]
|
||||
|
||||
else:
|
||||
# Search by complete channel name.
|
||||
chan_list = plr_get_cdict(session).values()
|
||||
for chan in chan_list:
|
||||
# Check for a name match
|
||||
if cname == chan[0]:
|
||||
has_channel = True
|
||||
else:
|
||||
# Search by complete channel name.
|
||||
chan_list = plr_get_cdict(session).values()
|
||||
for chan in chan_list:
|
||||
# Check for a name match
|
||||
if cname == chan[0]:
|
||||
has_channel = True
|
||||
|
||||
# If channel status is taken into consideration, see if the user
|
||||
# has the channel muted or not.
|
||||
if return_muted is False and not chan[1]:
|
||||
has_channel = False
|
||||
break
|
||||
# If channel status is taken into consideration, see if the user
|
||||
# has the channel muted or not.
|
||||
if return_muted is False and not chan[1]:
|
||||
has_channel = False
|
||||
break
|
||||
|
||||
return has_channel
|
||||
return has_channel
|
||||
|
||||
def plr_set_channel_listening(session, alias, listening):
|
||||
"""
|
||||
Add a channel to a session's channel list.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
alias: (str) The channel alias.
|
||||
listening: (bool) A True or False value to determine listening status.
|
||||
"""
|
||||
plr_get_cdict(session).get(alias)[1] = listening
|
||||
plr_pickle_channels(session)
|
||||
|
||||
"""
|
||||
Add a channel to a session's channel list.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
alias: (str) The channel alias.
|
||||
listening: (bool) A True or False value to determine listening status.
|
||||
"""
|
||||
plr_get_cdict(session).get(alias)[1] = listening
|
||||
plr_pickle_channels(session)
|
||||
|
||||
def plr_set_channel(session, alias, cname, listening):
|
||||
"""
|
||||
Set a channels alias, name, and listening status in one go, or add the
|
||||
channel if it doesn't already exist on a user's list.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
alias: (str) The channel alias (also the key in the user's cdict)
|
||||
cname: (str) Desired channel name to set.
|
||||
listening: (bool) A True or False value to determine listening status.
|
||||
"""
|
||||
plr_get_cdict(session)[alias] = [cname, listening]
|
||||
plr_pickle_channels(session)
|
||||
"""
|
||||
Set a channels alias, name, and listening status in one go, or add the
|
||||
channel if it doesn't already exist on a user's list.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
alias: (str) The channel alias (also the key in the user's cdict)
|
||||
cname: (str) Desired channel name to set.
|
||||
listening: (bool) A True or False value to determine listening status.
|
||||
"""
|
||||
plr_get_cdict(session)[alias] = [cname, listening]
|
||||
plr_pickle_channels(session)
|
||||
|
||||
def plr_pickle_channels(session):
|
||||
"""
|
||||
Save the player's channel list to the CHANLIST attribute.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
"""
|
||||
session.get_pobject().set_attribute("CHANLIST", pickle.dumps(plr_get_cdict(session)))
|
||||
"""
|
||||
Save the player's channel list to the CHANLIST attribute.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
"""
|
||||
session.get_pobject().set_attribute("CHANLIST", pickle.dumps(plr_get_cdict(session)))
|
||||
|
||||
def plr_del_channel(session, alias):
|
||||
"""
|
||||
Remove a channel from a session's channel list.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
alias: (str) The channel alias (also the key in the user's cdict)
|
||||
"""
|
||||
del plr_get_cdict(session)[alias]
|
||||
"""
|
||||
Remove a channel from a session's channel list.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
alias: (str) The channel alias (also the key in the user's cdict)
|
||||
"""
|
||||
del plr_get_cdict(session)[alias]
|
||||
|
||||
def msg_chan_hist(session, channel_name):
|
||||
"""
|
||||
Sends a listing of subscribers to a channel given a channel name.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
channel_name: (str) The channel's full name.
|
||||
"""
|
||||
cobj = get_cobj_from_name(channel_name)
|
||||
hist_list = CommChannelMessage.objects.filter(channel=cobj).order_by('date_sent')[0:20]
|
||||
for entry in hist_list:
|
||||
delta_days = datetime.datetime.now() - entry.date_sent
|
||||
days_elapsed = delta_days.days
|
||||
if days_elapsed > 0:
|
||||
time_str = entry.date_sent.strftime("%m.%d / %H:%M")
|
||||
else:
|
||||
time_str = entry.date_sent.strftime("%H:%M")
|
||||
session.msg("[%s] %s" % (time_str, entry.message))
|
||||
|
||||
"""
|
||||
Sends a listing of subscribers to a channel given a channel name.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
channel_name: (str) The channel's full name.
|
||||
"""
|
||||
cobj = get_cobj_from_name(channel_name)
|
||||
hist_list = CommChannelMessage.objects.filter(channel=cobj).order_by('date_sent')[0:20]
|
||||
for entry in hist_list:
|
||||
delta_days = datetime.datetime.now() - entry.date_sent
|
||||
days_elapsed = delta_days.days
|
||||
if days_elapsed > 0:
|
||||
time_str = entry.date_sent.strftime("%m.%d / %H:%M")
|
||||
else:
|
||||
time_str = entry.date_sent.strftime("%H:%M")
|
||||
session.msg("[%s] %s" % (time_str, entry.message))
|
||||
|
||||
def msg_cwho(session, channel_name):
|
||||
"""
|
||||
Sends a listing of subscribers to a channel given a channel name.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
channel_name: (str) The channel's full name.
|
||||
"""
|
||||
session.msg("--- Users Listening to %s ---" % (channel_name,))
|
||||
for plr_sess in get_cwho_list(channel_name):
|
||||
session.msg(plr_sess.get_pobject().get_name(show_dbref=False))
|
||||
session.msg("--- End Channel Listeners ---")
|
||||
|
||||
"""
|
||||
Sends a listing of subscribers to a channel given a channel name.
|
||||
|
||||
session: (SessionProtocol) A reference to the player session.
|
||||
channel_name: (str) The channel's full name.
|
||||
"""
|
||||
session.msg("--- Users Listening to %s ---" % (channel_name,))
|
||||
for plr_sess in get_cwho_list(channel_name):
|
||||
session.msg(plr_sess.get_pobject().get_name(show_dbref=False))
|
||||
session.msg("--- End Channel Listeners ---")
|
||||
|
||||
def get_cwho_list(channel_name, return_muted=False):
|
||||
"""
|
||||
Get all users on a channel.
|
||||
"""
|
||||
Get all users on a channel.
|
||||
|
||||
channel_name: (string) The name of the channel.
|
||||
return_muted: (bool) Return those who have the channel muted if True.
|
||||
"""
|
||||
sess_list = session_mgr.get_session_list()
|
||||
return [sess for sess in sess_list if plr_has_channel(sess, channel_name, return_muted)]
|
||||
channel_name: (string) The name of the channel.
|
||||
return_muted: (bool) Return those who have the channel muted if True.
|
||||
"""
|
||||
sess_list = session_mgr.get_session_list()
|
||||
return [sess for sess in sess_list if plr_has_channel(sess, channel_name, return_muted)]
|
||||
|
||||
def send_cmessage(channel_name, message):
|
||||
"""
|
||||
Sends a message to all players on the specified channel.
|
||||
"""
|
||||
Sends a message to all players on the specified channel.
|
||||
|
||||
channel_name: (string) The name of the channel.
|
||||
message: (string) Message to send.
|
||||
"""
|
||||
for user in get_cwho_list(channel_name, return_muted=False):
|
||||
user.msg(message)
|
||||
channel_name: (string) The name of the channel.
|
||||
message: (string) Message to send.
|
||||
"""
|
||||
for user in get_cwho_list(channel_name, return_muted=False):
|
||||
user.msg(message)
|
||||
|
||||
try:
|
||||
chan_message = CommChannelMessage()
|
||||
chan_message.channel = get_cobj_from_name(channel_name)
|
||||
chan_message.message = message
|
||||
chan_message.save()
|
||||
except:
|
||||
print "send_cmessage(): Can't find channel: %s" % (channel_name,)
|
||||
try:
|
||||
chan_message = CommChannelMessage()
|
||||
chan_message.channel = get_cobj_from_name(channel_name)
|
||||
chan_message.message = message
|
||||
chan_message.save()
|
||||
except:
|
||||
print "send_cmessage(): Can't find channel: %s" % (channel_name,)
|
||||
|
||||
|
||||
def get_all_channels():
|
||||
"""
|
||||
Returns all channel objects.
|
||||
"""
|
||||
return CommChannel.objects.all()
|
||||
"""
|
||||
Returns all channel objects.
|
||||
"""
|
||||
return CommChannel.objects.all()
|
||||
|
||||
def get_cobj_from_name(cname):
|
||||
"""
|
||||
Returns the channel's object when given a name.
|
||||
"""
|
||||
return CommChannel.objects.get(name=cname)
|
||||
"""
|
||||
Returns the channel's object when given a name.
|
||||
"""
|
||||
return CommChannel.objects.get(name=cname)
|
||||
|
||||
def create_channel(cdat):
|
||||
"""
|
||||
Create a new channel. cdat is a dictionary that contains the following keys.
|
||||
REQUIRED KEYS:
|
||||
* name: The name of the new channel.
|
||||
* owner: The creator of the channel.
|
||||
"""
|
||||
new_chan = CommChannel()
|
||||
new_chan.name = ansi.parse_ansi(cdat["name"], strip_ansi=True)
|
||||
new_chan.ansi_name = "[%s]" % (ansi.parse_ansi(cdat["name"]),)
|
||||
new_chan.set_owner(cdat["owner"])
|
||||
new_chan.save()
|
||||
return new_chan
|
||||
"""
|
||||
Create a new channel. cdat is a dictionary that contains the following keys.
|
||||
REQUIRED KEYS:
|
||||
* name: The name of the new channel.
|
||||
* owner: The creator of the channel.
|
||||
"""
|
||||
new_chan = CommChannel()
|
||||
new_chan.name = ansi.parse_ansi(cdat["name"], strip_ansi=True)
|
||||
new_chan.ansi_name = "[%s]" % (ansi.parse_ansi(cdat["name"]),)
|
||||
new_chan.set_owner(cdat["owner"])
|
||||
new_chan.save()
|
||||
return new_chan
|
||||
|
||||
def cname_search(search_text, exact=False):
|
||||
"""
|
||||
Searches for a particular channel name. Returns a QuerySet with the
|
||||
results.
|
||||
|
||||
exact: (bool) Do an exact (case-insensitive) name match if true.
|
||||
"""
|
||||
if exact:
|
||||
return CommChannel.objects.filter(name__iexact=search_text)
|
||||
else:
|
||||
return CommChannel.objects.filter(name__istartswith=search_text)
|
||||
"""
|
||||
Searches for a particular channel name. Returns a QuerySet with the
|
||||
results.
|
||||
|
||||
exact: (bool) Do an exact (case-insensitive) name match if true.
|
||||
"""
|
||||
if exact:
|
||||
return CommChannel.objects.filter(name__iexact=search_text)
|
||||
else:
|
||||
return CommChannel.objects.filter(name__istartswith=search_text)
|
||||
|
|
|
|||
|
|
@ -7,134 +7,134 @@ General commonly used functions.
|
|||
"""
|
||||
|
||||
def wildcard_to_regexp(instring):
|
||||
"""
|
||||
Converts a player-supplied string that may have wildcards in it to regular
|
||||
expressions. This is useful for name matching.
|
||||
"""
|
||||
Converts a player-supplied string that may have wildcards in it to regular
|
||||
expressions. This is useful for name matching.
|
||||
|
||||
instring: (string) A string that may potentially contain wildcards (* or ?).
|
||||
"""
|
||||
regexp_string = ""
|
||||
instring: (string) A string that may potentially contain wildcards (* or ?).
|
||||
"""
|
||||
regexp_string = ""
|
||||
|
||||
# If the string starts with an asterisk, we can't impose the beginning of
|
||||
# string (^) limiter.
|
||||
if instring[0] != "*":
|
||||
regexp_string += "^"
|
||||
# If the string starts with an asterisk, we can't impose the beginning of
|
||||
# string (^) limiter.
|
||||
if instring[0] != "*":
|
||||
regexp_string += "^"
|
||||
|
||||
# Replace any occurances of * or ? with the appropriate groups.
|
||||
regexp_string += instring.replace("*","(.*)").replace("?", "(.{1})")
|
||||
# Replace any occurances of * or ? with the appropriate groups.
|
||||
regexp_string += instring.replace("*","(.*)").replace("?", "(.{1})")
|
||||
|
||||
# If there's an asterisk at the end of the string, we can't impose the
|
||||
# end of string ($) limiter.
|
||||
if instring[-1] != "*":
|
||||
regexp_string += "$"
|
||||
# If there's an asterisk at the end of the string, we can't impose the
|
||||
# end of string ($) limiter.
|
||||
if instring[-1] != "*":
|
||||
regexp_string += "$"
|
||||
|
||||
return regexp_string
|
||||
return regexp_string
|
||||
|
||||
def cmd_check_num_args(session, arg_list, min_args, errortext="Missing arguments!"):
|
||||
"""
|
||||
Check a player command's splitted argument list to make sure it contains
|
||||
the minimum allowable number of arguments.
|
||||
"""
|
||||
if len(arg_list) < min_args+1:
|
||||
session.msg(errortext)
|
||||
return False
|
||||
return True
|
||||
"""
|
||||
Check a player command's splitted argument list to make sure it contains
|
||||
the minimum allowable number of arguments.
|
||||
"""
|
||||
if len(arg_list) < min_args+1:
|
||||
session.msg(errortext)
|
||||
return False
|
||||
return True
|
||||
|
||||
def log_errmsg(errormsg):
|
||||
"""
|
||||
Prints/logs an error message to the server log.
|
||||
"""
|
||||
Prints/logs an error message to the server log.
|
||||
|
||||
errormsg: (string) The message to be logged.
|
||||
"""
|
||||
log.err('ERROR: %s' % (errormsg,))
|
||||
#functions_comsys.send_cmessage("Errors", "[Errors] "+ errormsg)
|
||||
errormsg: (string) The message to be logged.
|
||||
"""
|
||||
log.err('ERROR: %s' % (errormsg,))
|
||||
#functions_comsys.send_cmessage("Errors", "[Errors] "+ errormsg)
|
||||
|
||||
def log_infomsg(infomsg):
|
||||
"""
|
||||
Prints any generic debugging/informative info that should appear in the log.
|
||||
"""
|
||||
Prints any generic debugging/informative info that should appear in the log.
|
||||
|
||||
debugmsg: (string) The message to be logged.
|
||||
"""
|
||||
log.msg('%s' % (infomsg,))
|
||||
#functions_comsys.send_cmessage("Info", "[Info] "+ infomsg)
|
||||
|
||||
debugmsg: (string) The message to be logged.
|
||||
"""
|
||||
log.msg('%s' % (infomsg,))
|
||||
#functions_comsys.send_cmessage("Info", "[Info] "+ infomsg)
|
||||
|
||||
def time_format(seconds, style=0):
|
||||
"""
|
||||
Function to return a 'prettified' version of a value in seconds.
|
||||
|
||||
Style 0: 1d 08:30
|
||||
Style 1: 1d
|
||||
Style 2: 1 day, 8 hours, 30 minutes, 10 seconds
|
||||
"""
|
||||
if seconds < 0:
|
||||
seconds = 0
|
||||
else:
|
||||
# We'll just use integer math, no need for decimal precision.
|
||||
seconds = int(seconds)
|
||||
|
||||
days = seconds / 86400
|
||||
seconds -= days * 86400
|
||||
hours = seconds / 3600
|
||||
seconds -= hours * 3600
|
||||
minutes = seconds / 60
|
||||
seconds -= minutes * 60
|
||||
|
||||
if style is 0:
|
||||
"""
|
||||
Standard colon-style output.
|
||||
"""
|
||||
if days > 0:
|
||||
retval = '%id %02i:%02i' % (days, hours, minutes,)
|
||||
else:
|
||||
retval = '%02i:%02i' % (hours, minutes,)
|
||||
|
||||
return retval
|
||||
elif style is 1:
|
||||
"""
|
||||
Simple, abbreviated form that only shows the highest time amount.
|
||||
"""
|
||||
if days > 0:
|
||||
return '%id' % (days,)
|
||||
elif hours > 0:
|
||||
return '%ih' % (hours,)
|
||||
elif minutes > 0:
|
||||
return '%im' % (minutes,)
|
||||
else:
|
||||
return '%is' % (seconds,)
|
||||
|
||||
elif style is 2:
|
||||
"""
|
||||
Full-detailed, long-winded format.
|
||||
"""
|
||||
days_str = hours_str = minutes_str = ''
|
||||
if days > 0:
|
||||
days_str = '%i days, ' % (days,)
|
||||
if days or hours > 0:
|
||||
hours_str = '%i hours, ' % (hours,)
|
||||
if hours or minutes > 0:
|
||||
minutes_str = '%i minutes, ' % (minutes,)
|
||||
seconds_str = '%i seconds' % (seconds,)
|
||||
|
||||
retval = '%s%s%s%s' % (days_str, hours_str, minutes_str, seconds_str,)
|
||||
return retval
|
||||
"""
|
||||
Function to return a 'prettified' version of a value in seconds.
|
||||
|
||||
Style 0: 1d 08:30
|
||||
Style 1: 1d
|
||||
Style 2: 1 day, 8 hours, 30 minutes, 10 seconds
|
||||
"""
|
||||
if seconds < 0:
|
||||
seconds = 0
|
||||
else:
|
||||
# We'll just use integer math, no need for decimal precision.
|
||||
seconds = int(seconds)
|
||||
|
||||
days = seconds / 86400
|
||||
seconds -= days * 86400
|
||||
hours = seconds / 3600
|
||||
seconds -= hours * 3600
|
||||
minutes = seconds / 60
|
||||
seconds -= minutes * 60
|
||||
|
||||
if style is 0:
|
||||
"""
|
||||
Standard colon-style output.
|
||||
"""
|
||||
if days > 0:
|
||||
retval = '%id %02i:%02i' % (days, hours, minutes,)
|
||||
else:
|
||||
retval = '%02i:%02i' % (hours, minutes,)
|
||||
|
||||
return retval
|
||||
elif style is 1:
|
||||
"""
|
||||
Simple, abbreviated form that only shows the highest time amount.
|
||||
"""
|
||||
if days > 0:
|
||||
return '%id' % (days,)
|
||||
elif hours > 0:
|
||||
return '%ih' % (hours,)
|
||||
elif minutes > 0:
|
||||
return '%im' % (minutes,)
|
||||
else:
|
||||
return '%is' % (seconds,)
|
||||
|
||||
elif style is 2:
|
||||
"""
|
||||
Full-detailed, long-winded format.
|
||||
"""
|
||||
days_str = hours_str = minutes_str = ''
|
||||
if days > 0:
|
||||
days_str = '%i days, ' % (days,)
|
||||
if days or hours > 0:
|
||||
hours_str = '%i hours, ' % (hours,)
|
||||
if hours or minutes > 0:
|
||||
minutes_str = '%i minutes, ' % (minutes,)
|
||||
seconds_str = '%i seconds' % (seconds,)
|
||||
|
||||
retval = '%s%s%s%s' % (days_str, hours_str, minutes_str, seconds_str,)
|
||||
return retval
|
||||
|
||||
def announce_all(message, with_ann_prefix=True):
|
||||
"""
|
||||
Announces something to all connected players.
|
||||
"""
|
||||
if with_ann_prefix:
|
||||
prefix = 'Announcement:'
|
||||
else:
|
||||
prefix = ''
|
||||
"""
|
||||
Announces something to all connected players.
|
||||
"""
|
||||
if with_ann_prefix:
|
||||
prefix = 'Announcement:'
|
||||
else:
|
||||
prefix = ''
|
||||
|
||||
for session in session_mgr.get_session_list():
|
||||
session.msg('%s %s' % (prefix, message))
|
||||
for session in session_mgr.get_session_list():
|
||||
session.msg('%s %s' % (prefix, message))
|
||||
|
||||
def word_wrap(text, width=78):
|
||||
"""
|
||||
Wrap text to a certain number of characters.
|
||||
"""
|
||||
Wrap text to a certain number of characters.
|
||||
|
||||
text: (str) The text to wrap.
|
||||
width: (int) The number of characters to wrap to.
|
||||
"""
|
||||
return '\r\n'.join(textwrap.wrap(text, width))
|
||||
text: (str) The text to wrap.
|
||||
width: (int) The number of characters to wrap to.
|
||||
"""
|
||||
return '\r\n'.join(textwrap.wrap(text, width))
|
||||
|
|
|
|||
|
|
@ -3,27 +3,27 @@ from apps.helpsys.models import HelpEntry
|
|||
Help system functions.
|
||||
"""
|
||||
def find_topicmatch(pobject, topicstr):
|
||||
"""
|
||||
Searches for matching topics based on player's input.
|
||||
"""
|
||||
is_staff = pobject.is_staff()
|
||||
if topicstr.isdigit():
|
||||
if is_staff:
|
||||
return HelpEntry.objects.filter(id=topicstr)
|
||||
else:
|
||||
return HelpEntry.objects.filter(id=topicstr).exclude(staff_only=1)
|
||||
else:
|
||||
if is_staff:
|
||||
return HelpEntry.objects.filter(topicname__istartswith=topicstr)
|
||||
else:
|
||||
return HelpEntry.objects.filter(topicname__istartswith=topicstr).exclude(staff_only=1)
|
||||
|
||||
"""
|
||||
Searches for matching topics based on player's input.
|
||||
"""
|
||||
is_staff = pobject.is_staff()
|
||||
if topicstr.isdigit():
|
||||
if is_staff:
|
||||
return HelpEntry.objects.filter(id=topicstr)
|
||||
else:
|
||||
return HelpEntry.objects.filter(id=topicstr).exclude(staff_only=1)
|
||||
else:
|
||||
if is_staff:
|
||||
return HelpEntry.objects.filter(topicname__istartswith=topicstr)
|
||||
else:
|
||||
return HelpEntry.objects.filter(topicname__istartswith=topicstr).exclude(staff_only=1)
|
||||
|
||||
def find_topicsuggestions(pobject, topicstr):
|
||||
"""
|
||||
Do a fuzzier "contains" match.
|
||||
"""
|
||||
is_staff = pobject.is_staff()
|
||||
if is_staff:
|
||||
return HelpEntry.objects.filter(topicname__icontains=topicstr)
|
||||
else:
|
||||
return HelpEntry.objects.filter(topicname__icontains=topicstr).exclude(staff_only=1)
|
||||
"""
|
||||
Do a fuzzier "contains" match.
|
||||
"""
|
||||
is_staff = pobject.is_staff()
|
||||
if is_staff:
|
||||
return HelpEntry.objects.filter(topicname__icontains=topicstr)
|
||||
else:
|
||||
return HelpEntry.objects.filter(topicname__icontains=topicstr).exclude(staff_only=1)
|
||||
|
|
|
|||
38
gameconf.py
38
gameconf.py
|
|
@ -8,26 +8,26 @@ Handle the setting/retrieving of server config directives.
|
|||
"""
|
||||
|
||||
def host_os_is(osname):
|
||||
"""
|
||||
Check to see if the host OS matches the query.
|
||||
"""
|
||||
if os.name == osname:
|
||||
return True
|
||||
return False
|
||||
"""
|
||||
Check to see if the host OS matches the query.
|
||||
"""
|
||||
if os.name == osname:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_configvalue(configname):
|
||||
"""
|
||||
Retrieve a configuration value.
|
||||
"""
|
||||
try:
|
||||
return ConfigValue.objects.get(conf_key__iexact=configname).conf_value
|
||||
except:
|
||||
functions_general.log_errmsg("Unable to get config value for %s:\n%s" % (configname, (format_exc())))
|
||||
"""
|
||||
Retrieve a configuration value.
|
||||
"""
|
||||
try:
|
||||
return ConfigValue.objects.get(conf_key__iexact=configname).conf_value
|
||||
except:
|
||||
functions_general.log_errmsg("Unable to get config value for %s:\n%s" % (configname, (format_exc())))
|
||||
|
||||
def set_configvalue(configname, newvalue):
|
||||
"""
|
||||
Sets a configuration value with the specified name.
|
||||
"""
|
||||
conf = ConfigValue.objects.get(conf_key=configname)
|
||||
conf.conf_value = newvalue
|
||||
conf.save()
|
||||
"""
|
||||
Sets a configuration value with the specified name.
|
||||
"""
|
||||
conf = ConfigValue.objects.get(conf_key=configname)
|
||||
conf.conf_value = newvalue
|
||||
conf.save()
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@ from apps.objects.models import Object
|
|||
import gameconf
|
||||
|
||||
def handle_setup():
|
||||
# Set the initial user's username on the #1 object.
|
||||
god_user = User.objects.filter(id=1)[0]
|
||||
god_user_obj = Object.objects.filter(id=1)[0]
|
||||
god_user_obj.set_name(god_user.username)
|
||||
# Set the initial user's username on the #1 object.
|
||||
god_user = User.objects.filter(id=1)[0]
|
||||
god_user_obj = Object.objects.filter(id=1)[0]
|
||||
god_user_obj.set_name(god_user.username)
|
||||
|
||||
groups = ("Immortals", "Wizards", "Builders", "Player Helpers")
|
||||
for group in groups:
|
||||
newgroup = Group()
|
||||
newgroup.name = group
|
||||
newgroup.save()
|
||||
groups = ("Immortals", "Wizards", "Builders", "Player Helpers")
|
||||
for group in groups:
|
||||
newgroup = Group()
|
||||
newgroup.name = group
|
||||
newgroup.save()
|
||||
|
||||
# We don't want to do initial setup tasks every startup, only the first.
|
||||
gameconf.set_configvalue('game_firstrun', '0')
|
||||
# We don't want to do initial setup tasks every startup, only the first.
|
||||
gameconf.set_configvalue('game_firstrun', '0')
|
||||
|
|
|
|||
10
manage.py
10
manage.py
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
from django.core.management import execute_manager
|
||||
try:
|
||||
import settings # Assumed to be in the same directory.
|
||||
import settings # Assumed to be in the same directory.
|
||||
except ImportError:
|
||||
import sys
|
||||
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
|
||||
sys.exit(1)
|
||||
import sys
|
||||
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
execute_manager(settings)
|
||||
execute_manager(settings)
|
||||
|
|
|
|||
30
mixins.py
30
mixins.py
|
|
@ -3,20 +3,20 @@ The ReloadMixin class is meant as an example, but should work
|
|||
for basic purposes as a mixin inheritance.
|
||||
"""
|
||||
class ReloadMixin():
|
||||
"""
|
||||
This class is a generic reload mixin providing the two
|
||||
methods required to cache and reload an object.
|
||||
"""
|
||||
def cache(self, reloader, do_save=True):
|
||||
if do_save:
|
||||
if self.save and callable(self.save):
|
||||
self.save()
|
||||
else:
|
||||
raise ValueError("This object does not have a save function, you must pass do_save=False for this object type.")
|
||||
"""
|
||||
This class is a generic reload mixin providing the two
|
||||
methods required to cache and reload an object.
|
||||
"""
|
||||
def cache(self, reloader, do_save=True):
|
||||
if do_save:
|
||||
if self.save and callable(self.save):
|
||||
self.save()
|
||||
else:
|
||||
raise ValueError("This object does not have a save function, you must pass do_save=False for this object type.")
|
||||
|
||||
reloader.cache_object(self)
|
||||
reloader.cache_object(self)
|
||||
|
||||
def reload(self, cache):
|
||||
for key, value in cache.iteritems():
|
||||
if self.__dict__[key] != value:
|
||||
self.__dict__[key] = value
|
||||
def reload(self, cache):
|
||||
for key, value in cache.iteritems():
|
||||
if self.__dict__[key] != value:
|
||||
self.__dict__[key] = value
|
||||
|
|
|
|||
|
|
@ -9,19 +9,19 @@ modules to be reloaded at @reload.
|
|||
# These are custom modules that have classes requiring state-saving.
|
||||
# These modules are reloaded before those in no_cache.
|
||||
cache = {
|
||||
# This should be a dict of lists of tuples
|
||||
# with the module name as a key, a list of tuples
|
||||
# with the class name as the first element of the
|
||||
# tuple, and True or False if this is a model
|
||||
# for the database, like so:
|
||||
#
|
||||
# 'modulename' : [ ('ModelA', True), ('ClassA', False) ],
|
||||
# 'anothermod' : [ ('ClassB', False), ('ClassC', False) ],
|
||||
}
|
||||
# This should be a dict of lists of tuples
|
||||
# with the module name as a key, a list of tuples
|
||||
# with the class name as the first element of the
|
||||
# tuple, and True or False if this is a model
|
||||
# for the database, like so:
|
||||
#
|
||||
# 'modulename' : [ ('ModelA', True), ('ClassA', False) ],
|
||||
# 'anothermod' : [ ('ClassB', False), ('ClassC', False) ],
|
||||
}
|
||||
|
||||
# This is a list of modules that need to be reloaded at @reload. There
|
||||
# is no state-saving, and these are reloaded after those cached above.
|
||||
no_cache = [
|
||||
# 'modulename',
|
||||
# 'anothermod',
|
||||
]
|
||||
# 'modulename',
|
||||
# 'anothermod',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,51 +1,51 @@
|
|||
import functions_general
|
||||
|
||||
class ReloadManager(object):
|
||||
objects_cache = {}
|
||||
failed = []
|
||||
objects_cache = {}
|
||||
failed = []
|
||||
|
||||
models = {}
|
||||
models = {}
|
||||
|
||||
def __init__(self, server):
|
||||
self.server = server
|
||||
def __init__(self, server):
|
||||
self.server = server
|
||||
|
||||
def do_cache(self):
|
||||
for module, info in self.models.iteritems():
|
||||
module_obj = __import__(module)
|
||||
for ituple in info:
|
||||
mclass = getattr(module_obj, info[0])
|
||||
for instance in mclass.__instances__():
|
||||
instance.cache(self, do_save=ituple[1])
|
||||
def do_cache(self):
|
||||
for module, info in self.models.iteritems():
|
||||
module_obj = __import__(module)
|
||||
for ituple in info:
|
||||
mclass = getattr(module_obj, info[0])
|
||||
for instance in mclass.__instances__():
|
||||
instance.cache(self, do_save=ituple[1])
|
||||
|
||||
def do_reload(self):
|
||||
self.do_cache()
|
||||
self.server.reload()
|
||||
self.reload_objects()
|
||||
def do_reload(self):
|
||||
self.do_cache()
|
||||
self.server.reload()
|
||||
self.reload_objects()
|
||||
|
||||
def cache_object(self, obj):
|
||||
obj_dict = {}
|
||||
for key, value in obj.__dict__.iteritems():
|
||||
if not callable(obj[key]):
|
||||
obj_dict[key] = value
|
||||
def cache_object(self, obj):
|
||||
obj_dict = {}
|
||||
for key, value in obj.__dict__.iteritems():
|
||||
if not callable(obj[key]):
|
||||
obj_dict[key] = value
|
||||
|
||||
self.objects_cache[obj] = obj_dict
|
||||
self.objects_cache[obj] = obj_dict
|
||||
|
||||
def reload_objects(self):
|
||||
for obj, cache in self.objects_cache.iteritems():
|
||||
try:
|
||||
obj.reload(cache)
|
||||
except:
|
||||
functions_general.log_errmsg("Failed to reload cache for object: %s." % (obj,))
|
||||
self.failed.append(obj)
|
||||
raise
|
||||
def reload_objects(self):
|
||||
for obj, cache in self.objects_cache.iteritems():
|
||||
try:
|
||||
obj.reload(cache)
|
||||
except:
|
||||
functions_general.log_errmsg("Failed to reload cache for object: %s." % (obj,))
|
||||
self.failed.append(obj)
|
||||
raise
|
||||
|
||||
self.objects_cache = {}
|
||||
self.objects_cache = {}
|
||||
|
||||
for obj in self.failed:
|
||||
try:
|
||||
obj.__dict__.update(cache)
|
||||
except:
|
||||
functions_general.log_errmsg("Failed to update object %s, giving up." %s (obj,))
|
||||
raise
|
||||
for obj in self.failed:
|
||||
try:
|
||||
obj.__dict__.update(cache)
|
||||
except:
|
||||
functions_general.log_errmsg("Failed to update object %s, giving up." %s (obj,))
|
||||
raise
|
||||
|
||||
self.failed = []
|
||||
self.failed = []
|
||||
|
|
|
|||
124
scheduler.py
124
scheduler.py
|
|
@ -13,96 +13,96 @@ ADDING AN EVENT:
|
|||
# Dictionary of events with a list in the form of:
|
||||
# [<function>, <interval>, <lastrantime>, <taskobject>, <description>]
|
||||
schedule = {
|
||||
'evt_check_sessions': [events.evt_check_sessions, 60, time.time(), None, "Session consistency checks."]
|
||||
'evt_check_sessions': [events.evt_check_sessions, 60, time.time(), None, "Session consistency checks."]
|
||||
}
|
||||
|
||||
def start_events():
|
||||
"""
|
||||
Start the event system, which is built on Twisted's framework.
|
||||
"""
|
||||
for event in schedule:
|
||||
event_func = get_event_function(event)
|
||||
"""
|
||||
Start the event system, which is built on Twisted's framework.
|
||||
"""
|
||||
for event in schedule:
|
||||
event_func = get_event_function(event)
|
||||
|
||||
if callable(event_func):
|
||||
# Set the call-back function for the task to trigger_event, but pass
|
||||
# a reference to the event function.
|
||||
event_task = task.LoopingCall(trigger_event, event_func, event)
|
||||
# Start the task up with the specified interval.
|
||||
event_task.start(get_event_interval(event), now=False)
|
||||
# Set a reference to the event's task object in the dictionary so we
|
||||
# can re-schedule, start, and stop events from elsewhere.
|
||||
set_event_taskobj(event, event_task)
|
||||
if callable(event_func):
|
||||
# Set the call-back function for the task to trigger_event, but pass
|
||||
# a reference to the event function.
|
||||
event_task = task.LoopingCall(trigger_event, event_func, event)
|
||||
# Start the task up with the specified interval.
|
||||
event_task.start(get_event_interval(event), now=False)
|
||||
# Set a reference to the event's task object in the dictionary so we
|
||||
# can re-schedule, start, and stop events from elsewhere.
|
||||
set_event_taskobj(event, event_task)
|
||||
|
||||
def get_event(event_name):
|
||||
"""
|
||||
Return the relevant entry in the schedule dictionary for the named event.
|
||||
"""
|
||||
Return the relevant entry in the schedule dictionary for the named event.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return schedule.get(event_name, None)
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return schedule.get(event_name, None)
|
||||
|
||||
def get_event_function(event_name):
|
||||
"""
|
||||
Return a reference to the event's function.
|
||||
"""
|
||||
Return a reference to the event's function.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[0]
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[0]
|
||||
|
||||
def get_event_interval(event_name):
|
||||
"""
|
||||
Return the event's execution interval.
|
||||
"""
|
||||
Return the event's execution interval.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[1]
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[1]
|
||||
|
||||
def get_event_nextfire(event_name):
|
||||
"""
|
||||
Returns a value in seconds when the event is going to fire off next.
|
||||
"""
|
||||
Returns a value in seconds when the event is going to fire off next.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return (get_event(event_name)[2]+get_event_interval(event_name))-time.time()
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return (get_event(event_name)[2]+get_event_interval(event_name))-time.time()
|
||||
|
||||
def get_event_taskobj(event_name):
|
||||
"""
|
||||
Returns an event's task object.
|
||||
"""
|
||||
Returns an event's task object.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[3]
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[3]
|
||||
|
||||
def get_event_description(event_name):
|
||||
"""
|
||||
Returns an event's description.
|
||||
"""
|
||||
Returns an event's description.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[4]
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[4]
|
||||
|
||||
def set_event_taskobj(event_name, taskobj):
|
||||
"""
|
||||
Sets an event's task object.
|
||||
"""
|
||||
Sets an event's task object.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
get_event(event_name)[3] = taskobj
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
get_event(event_name)[3] = taskobj
|
||||
|
||||
def set_event_lastfired(event_name):
|
||||
"""
|
||||
Sets an event's last fired time.
|
||||
"""
|
||||
Sets an event's last fired time.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
get_event(event_name)[2] = time.time()
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
get_event(event_name)[2] = time.time()
|
||||
|
||||
def trigger_event(event_func, event_name):
|
||||
"""
|
||||
Update the last ran time and fire off the event.
|
||||
"""
|
||||
Update the last ran time and fire off the event.
|
||||
|
||||
event_func: (func_reference) Reference to the event function to fire.
|
||||
eventname: (string) The name of the event (as per schedule dict).
|
||||
"""
|
||||
event_func()
|
||||
set_event_lastfired(event_name)
|
||||
event_func: (func_reference) Reference to the event function to fire.
|
||||
eventname: (string) The name of the event (as per schedule dict).
|
||||
"""
|
||||
event_func()
|
||||
set_event_lastfired(event_name)
|
||||
|
|
|
|||
|
|
@ -15,54 +15,54 @@ interaction with actual script methods should happen via calls to Objects.
|
|||
cached_scripts = {}
|
||||
|
||||
def scriptlink(source_obj, scriptname):
|
||||
"""
|
||||
Each Object will refer to this function when trying to execute a function
|
||||
contained within a scripted module. For the sake of ease of management,
|
||||
modules are cached and compiled as they are requested and stored in
|
||||
the cached_scripts dictionary.
|
||||
|
||||
Returns a reference to an instance of the script's class as per it's
|
||||
class_factory() method.
|
||||
|
||||
source_obj: (Object) A reference to the object being scripted.
|
||||
scriptname: (str) Name of the module to load (minus 'scripts').
|
||||
"""
|
||||
# The module is already cached, just return it rather than re-load.
|
||||
retval = cached_scripts.get(scriptname, False)
|
||||
if retval:
|
||||
return retval.class_factory(source_obj)
|
||||
"""
|
||||
Each Object will refer to this function when trying to execute a function
|
||||
contained within a scripted module. For the sake of ease of management,
|
||||
modules are cached and compiled as they are requested and stored in
|
||||
the cached_scripts dictionary.
|
||||
|
||||
Returns a reference to an instance of the script's class as per it's
|
||||
class_factory() method.
|
||||
|
||||
source_obj: (Object) A reference to the object being scripted.
|
||||
scriptname: (str) Name of the module to load (minus 'scripts').
|
||||
"""
|
||||
# The module is already cached, just return it rather than re-load.
|
||||
retval = cached_scripts.get(scriptname, False)
|
||||
if retval:
|
||||
return retval.class_factory(source_obj)
|
||||
|
||||
##
|
||||
## NOTE: Only go past here when the script isn't already cached.
|
||||
##
|
||||
|
||||
# Split the script name up by periods to give us the directory we need
|
||||
# to change to. I really wish we didn't have to do this, but there's some
|
||||
# strange issue with __import__ and more than two directories worth of
|
||||
# nesting.
|
||||
path_split = scriptname.split('.')
|
||||
newpath_str = '/'.join(path_split[:-1])
|
||||
# Lop the module name off the end.
|
||||
modname = path_split[-1]
|
||||
##
|
||||
## NOTE: Only go past here when the script isn't already cached.
|
||||
##
|
||||
|
||||
# Split the script name up by periods to give us the directory we need
|
||||
# to change to. I really wish we didn't have to do this, but there's some
|
||||
# strange issue with __import__ and more than two directories worth of
|
||||
# nesting.
|
||||
path_split = scriptname.split('.')
|
||||
newpath_str = '/'.join(path_split[:-1])
|
||||
# Lop the module name off the end.
|
||||
modname = path_split[-1]
|
||||
|
||||
try:
|
||||
# Change the working directory to the location of the script and import.
|
||||
os.chdir('%s/%s/' % (settings.SCRIPT_ROOT, newpath_str))
|
||||
functions_general.log_infomsg("SCRIPT: Caching and importing %s." % (modname))
|
||||
modreference = __import__(modname)
|
||||
# Store the module reference for later fast retrieval.
|
||||
cached_scripts[scriptname] = modreference
|
||||
except ImportError:
|
||||
functions_general.log_infomsg('Error importing %s: %s' % (modname, format_exc()))
|
||||
os.chdir(settings.BASE_PATH)
|
||||
return
|
||||
except OSError:
|
||||
functions_general.log_infomsg('Invalid module path: %s' % (format_exc()))
|
||||
os.chdir(settings.BASE_PATH)
|
||||
return
|
||||
try:
|
||||
# Change the working directory to the location of the script and import.
|
||||
os.chdir('%s/%s/' % (settings.SCRIPT_ROOT, newpath_str))
|
||||
functions_general.log_infomsg("SCRIPT: Caching and importing %s." % (modname))
|
||||
modreference = __import__(modname)
|
||||
# Store the module reference for later fast retrieval.
|
||||
cached_scripts[scriptname] = modreference
|
||||
except ImportError:
|
||||
functions_general.log_infomsg('Error importing %s: %s' % (modname, format_exc()))
|
||||
os.chdir(settings.BASE_PATH)
|
||||
return
|
||||
except OSError:
|
||||
functions_general.log_infomsg('Invalid module path: %s' % (format_exc()))
|
||||
os.chdir(settings.BASE_PATH)
|
||||
return
|
||||
|
||||
# Change back to the original working directory.
|
||||
os.chdir(settings.BASE_PATH)
|
||||
# Change back to the original working directory.
|
||||
os.chdir(settings.BASE_PATH)
|
||||
|
||||
# The new script module has been cached, return the reference.
|
||||
return modreference.class_factory(source_obj)
|
||||
# The new script module has been cached, return the reference.
|
||||
return modreference.class_factory(source_obj)
|
||||
|
|
|
|||
164
server.py
164
server.py
|
|
@ -21,102 +21,102 @@ import initial_setup
|
|||
|
||||
class EvenniaService(service.Service):
|
||||
|
||||
def __init__(self, filename="blah"):
|
||||
self.cmd_alias_list = {}
|
||||
self.game_running = True
|
||||
sys.path.append('.')
|
||||
def __init__(self, filename="blah"):
|
||||
self.cmd_alias_list = {}
|
||||
self.game_running = True
|
||||
sys.path.append('.')
|
||||
|
||||
# Database-specific startup optimizations.
|
||||
if settings.DATABASE_ENGINE == "sqlite3":
|
||||
self.sqlite3_prep()
|
||||
# Database-specific startup optimizations.
|
||||
if settings.DATABASE_ENGINE == "sqlite3":
|
||||
self.sqlite3_prep()
|
||||
|
||||
# Wipe our temporary flags on all of the objects.
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("UPDATE objects_object SET nosave_flags=''")
|
||||
# Wipe our temporary flags on all of the objects.
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("UPDATE objects_object SET nosave_flags=''")
|
||||
|
||||
print '-'*50
|
||||
# Load command aliases into memory for easy/quick access.
|
||||
self.load_cmd_aliases()
|
||||
print '-'*50
|
||||
# Load command aliases into memory for easy/quick access.
|
||||
self.load_cmd_aliases()
|
||||
|
||||
if gameconf.get_configvalue('game_firstrun') == '1':
|
||||
print ' Game started for the first time, setting defaults.'
|
||||
initial_setup.handle_setup()
|
||||
if gameconf.get_configvalue('game_firstrun') == '1':
|
||||
print ' Game started for the first time, setting defaults.'
|
||||
initial_setup.handle_setup()
|
||||
|
||||
self.start_time = time.time()
|
||||
self.start_time = time.time()
|
||||
|
||||
print ' %s started on port(s):' % (gameconf.get_configvalue('site_name'),)
|
||||
for port in settings.GAMEPORTS:
|
||||
print ' * %s' % (port)
|
||||
print '-'*50
|
||||
scheduler.start_events()
|
||||
print ' %s started on port(s):' % (gameconf.get_configvalue('site_name'),)
|
||||
for port in settings.GAMEPORTS:
|
||||
print ' * %s' % (port)
|
||||
print '-'*50
|
||||
scheduler.start_events()
|
||||
|
||||
"""
|
||||
BEGIN SERVER STARTUP METHODS
|
||||
"""
|
||||
def load_cmd_aliases(self):
|
||||
"""
|
||||
Load up our command aliases.
|
||||
"""
|
||||
alias_list = CommandAlias.objects.all()
|
||||
for alias in alias_list:
|
||||
self.cmd_alias_list[alias.user_input] = alias.equiv_command
|
||||
print ' Command Aliases Loaded: %i' % (len(self.cmd_alias_list),)
|
||||
pass
|
||||
"""
|
||||
BEGIN SERVER STARTUP METHODS
|
||||
"""
|
||||
def load_cmd_aliases(self):
|
||||
"""
|
||||
Load up our command aliases.
|
||||
"""
|
||||
alias_list = CommandAlias.objects.all()
|
||||
for alias in alias_list:
|
||||
self.cmd_alias_list[alias.user_input] = alias.equiv_command
|
||||
print ' Command Aliases Loaded: %i' % (len(self.cmd_alias_list),)
|
||||
pass
|
||||
|
||||
def sqlite3_prep(self):
|
||||
"""
|
||||
Optimize some SQLite stuff at startup since we can't save it to the
|
||||
database.
|
||||
"""
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("PRAGMA cache_size=10000")
|
||||
cursor.execute("PRAGMA synchronous=OFF")
|
||||
cursor.execute("PRAGMA count_changes=OFF")
|
||||
cursor.execute("PRAGMA temp_store=2")
|
||||
def sqlite3_prep(self):
|
||||
"""
|
||||
Optimize some SQLite stuff at startup since we can't save it to the
|
||||
database.
|
||||
"""
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("PRAGMA cache_size=10000")
|
||||
cursor.execute("PRAGMA synchronous=OFF")
|
||||
cursor.execute("PRAGMA count_changes=OFF")
|
||||
cursor.execute("PRAGMA temp_store=2")
|
||||
|
||||
"""
|
||||
BEGIN GENERAL METHODS
|
||||
"""
|
||||
def shutdown(self, message='The server has been shutdown. Please check back soon.'):
|
||||
functions_general.announce_all(message)
|
||||
session_mgr.disconnect_all_sessions()
|
||||
reactor.callLater(0, reactor.stop)
|
||||
"""
|
||||
BEGIN GENERAL METHODS
|
||||
"""
|
||||
def shutdown(self, message='The server has been shutdown. Please check back soon.'):
|
||||
functions_general.announce_all(message)
|
||||
session_mgr.disconnect_all_sessions()
|
||||
reactor.callLater(0, reactor.stop)
|
||||
|
||||
def command_list(self):
|
||||
"""
|
||||
Return a string representing the server's command list.
|
||||
"""
|
||||
clist = cmdtable.ctable.keys()
|
||||
clist.sort()
|
||||
return clist
|
||||
def command_list(self):
|
||||
"""
|
||||
Return a string representing the server's command list.
|
||||
"""
|
||||
clist = cmdtable.ctable.keys()
|
||||
clist.sort()
|
||||
return clist
|
||||
|
||||
def reload(self, session):
|
||||
"""
|
||||
Reload modules that don't have any variables that can be reset.
|
||||
For changes to the scheduler, server, or session_mgr modules, a cold
|
||||
restart is needed.
|
||||
"""
|
||||
reload_list = ['ansi', 'cmdhandler', 'commands.comsys', 'commands.general',
|
||||
'commands.privileged', 'commands.unloggedin', 'defines_global',
|
||||
'events', 'functions_db', 'functions_general', 'functions_comsys',
|
||||
'functions_help', 'gameconf', 'session', 'apps.objects.models',
|
||||
'apps.helpsys.models', 'apps.config.models']
|
||||
def reload(self, session):
|
||||
"""
|
||||
Reload modules that don't have any variables that can be reset.
|
||||
For changes to the scheduler, server, or session_mgr modules, a cold
|
||||
restart is needed.
|
||||
"""
|
||||
reload_list = ['ansi', 'cmdhandler', 'commands.comsys', 'commands.general',
|
||||
'commands.privileged', 'commands.unloggedin', 'defines_global',
|
||||
'events', 'functions_db', 'functions_general', 'functions_comsys',
|
||||
'functions_help', 'gameconf', 'session', 'apps.objects.models',
|
||||
'apps.helpsys.models', 'apps.config.models']
|
||||
|
||||
for mod in reload_list:
|
||||
reload(sys.modules[mod])
|
||||
for mod in reload_list:
|
||||
reload(sys.modules[mod])
|
||||
|
||||
session.msg("Modules reloaded.")
|
||||
functions_general.log_infomsg("Modules reloaded by %s." % (session,))
|
||||
session.msg("Modules reloaded.")
|
||||
functions_general.log_infomsg("Modules reloaded by %s." % (session,))
|
||||
|
||||
def getEvenniaServiceFactory(self):
|
||||
f = protocol.ServerFactory()
|
||||
f.protocol = SessionProtocol
|
||||
f.server = self
|
||||
return f
|
||||
def getEvenniaServiceFactory(self):
|
||||
f = protocol.ServerFactory()
|
||||
f.protocol = SessionProtocol
|
||||
f.server = self
|
||||
return f
|
||||
|
||||
"""
|
||||
END Server CLASS
|
||||
"""
|
||||
"""
|
||||
END Server CLASS
|
||||
"""
|
||||
|
||||
application = service.Application('Evennia')
|
||||
mud_service = EvenniaService('Evennia Server')
|
||||
|
|
@ -124,4 +124,4 @@ mud_service = EvenniaService('Evennia Server')
|
|||
# Sheet sheet, fire ze missiles!
|
||||
serviceCollection = service.IServiceCollection(application)
|
||||
for port in settings.GAMEPORTS:
|
||||
internet.TCPServer(port, mud_service.getEvenniaServiceFactory()).setServiceParent(serviceCollection)
|
||||
internet.TCPServer(port, mud_service.getEvenniaServiceFactory()).setServiceParent(serviceCollection)
|
||||
|
|
|
|||
302
session.py
302
session.py
|
|
@ -14,166 +14,166 @@ import ansi
|
|||
import gameconf
|
||||
|
||||
class SessionProtocol(StatefulTelnetProtocol):
|
||||
"""
|
||||
This class represents a player's sesssion. From here we branch down into
|
||||
other various classes, please try to keep this one tidy!
|
||||
"""
|
||||
"""
|
||||
This class represents a player's sesssion. From here we branch down into
|
||||
other various classes, please try to keep this one tidy!
|
||||
"""
|
||||
|
||||
def connectionMade(self):
|
||||
"""
|
||||
What to do when we get a connection.
|
||||
"""
|
||||
self.prep_session()
|
||||
functions_general.log_infomsg('Connection: %s' % (self,))
|
||||
session_mgr.add_session(self)
|
||||
self.game_connect_screen()
|
||||
def connectionMade(self):
|
||||
"""
|
||||
What to do when we get a connection.
|
||||
"""
|
||||
self.prep_session()
|
||||
functions_general.log_infomsg('Connection: %s' % (self,))
|
||||
session_mgr.add_session(self)
|
||||
self.game_connect_screen()
|
||||
|
||||
def getClientAddress(self):
|
||||
"""
|
||||
Returns the client's address and port in a tuple. For example
|
||||
('127.0.0.1', 41917)
|
||||
"""
|
||||
return self.transport.client
|
||||
def getClientAddress(self):
|
||||
"""
|
||||
Returns the client's address and port in a tuple. For example
|
||||
('127.0.0.1', 41917)
|
||||
"""
|
||||
return self.transport.client
|
||||
|
||||
def prep_session(self):
|
||||
self.server = self.factory.server
|
||||
self.address = self.getClientAddress()
|
||||
self.name = None
|
||||
self.uid = None
|
||||
self.logged_in = False
|
||||
# The time the user last issued a command.
|
||||
self.cmd_last = time.time()
|
||||
# Player-visible idle time, excluding the IDLE command.
|
||||
self.cmd_last_visible = time.time()
|
||||
# Total number of commands issued.
|
||||
self.cmd_total = 0
|
||||
# The time when the user connected.
|
||||
self.conn_time = time.time()
|
||||
self.channels_subscribed = {}
|
||||
def prep_session(self):
|
||||
self.server = self.factory.server
|
||||
self.address = self.getClientAddress()
|
||||
self.name = None
|
||||
self.uid = None
|
||||
self.logged_in = False
|
||||
# The time the user last issued a command.
|
||||
self.cmd_last = time.time()
|
||||
# Player-visible idle time, excluding the IDLE command.
|
||||
self.cmd_last_visible = time.time()
|
||||
# Total number of commands issued.
|
||||
self.cmd_total = 0
|
||||
# The time when the user connected.
|
||||
self.conn_time = time.time()
|
||||
self.channels_subscribed = {}
|
||||
|
||||
def disconnectClient(self):
|
||||
"""
|
||||
Manually disconnect the client.
|
||||
"""
|
||||
self.transport.loseConnection()
|
||||
def disconnectClient(self):
|
||||
"""
|
||||
Manually disconnect the client.
|
||||
"""
|
||||
self.transport.loseConnection()
|
||||
|
||||
def connectionLost(self, reason):
|
||||
"""
|
||||
Execute this when a client abruplty loses their connection.
|
||||
"""
|
||||
functions_general.log_infomsg('Disconnect: %s' % (self,))
|
||||
self.handle_close()
|
||||
def connectionLost(self, reason):
|
||||
"""
|
||||
Execute this when a client abruplty loses their connection.
|
||||
"""
|
||||
functions_general.log_infomsg('Disconnect: %s' % (self,))
|
||||
self.handle_close()
|
||||
|
||||
def load_user_channels(self):
|
||||
"""
|
||||
Un-pickle a user's channel list from their CHANLIST attribute.
|
||||
"""
|
||||
chan_list = self.get_pobject().get_attribute_value("CHANLIST")
|
||||
if chan_list:
|
||||
self.channels_subscribed = pickle.loads(chan_list)
|
||||
|
||||
def lineReceived(self, data):
|
||||
"""
|
||||
Any line return indicates a command for the purpose of a MUD. So we take
|
||||
the user input and pass it to our command handler.
|
||||
"""
|
||||
line = (''.join(data))
|
||||
line = line.strip('\r')
|
||||
uinput = line
|
||||
|
||||
# Stuff anything we need to pass in this dictionary.
|
||||
cdat = {"server": self.factory.server, "uinput": uinput, "session": self}
|
||||
cmdhandler.handle(cdat)
|
||||
def load_user_channels(self):
|
||||
"""
|
||||
Un-pickle a user's channel list from their CHANLIST attribute.
|
||||
"""
|
||||
chan_list = self.get_pobject().get_attribute_value("CHANLIST")
|
||||
if chan_list:
|
||||
self.channels_subscribed = pickle.loads(chan_list)
|
||||
|
||||
def lineReceived(self, data):
|
||||
"""
|
||||
Any line return indicates a command for the purpose of a MUD. So we take
|
||||
the user input and pass it to our command handler.
|
||||
"""
|
||||
line = (''.join(data))
|
||||
line = line.strip('\r')
|
||||
uinput = line
|
||||
|
||||
# Stuff anything we need to pass in this dictionary.
|
||||
cdat = {"server": self.factory.server, "uinput": uinput, "session": self}
|
||||
cmdhandler.handle(cdat)
|
||||
|
||||
def execute_cmd(self, cmdstr):
|
||||
"""
|
||||
Executes a command as this session.
|
||||
"""
|
||||
self.lineReceived(data=cmdstr)
|
||||
|
||||
def handle_close(self):
|
||||
def execute_cmd(self, cmdstr):
|
||||
"""
|
||||
Break the connection and do some accounting.
|
||||
Executes a command as this session.
|
||||
"""
|
||||
pobject = self.get_pobject()
|
||||
if pobject:
|
||||
pobject.set_flag("CONNECTED", False)
|
||||
pobject.get_location().emit_to_contents("%s has disconnected." % (pobject.get_name(show_dbref=False),), exclude=pobject)
|
||||
uaccount = pobject.get_user_account()
|
||||
uaccount.last_login = datetime.now()
|
||||
uaccount.save()
|
||||
|
||||
self.disconnectClient()
|
||||
self.logged_in = False
|
||||
session_mgr.remove_session(self)
|
||||
|
||||
def get_pobject(self):
|
||||
"""
|
||||
Returns the object associated with a session.
|
||||
"""
|
||||
try:
|
||||
result = Object.objects.get(id=self.uid)
|
||||
return result
|
||||
except:
|
||||
return False
|
||||
|
||||
def game_connect_screen(self):
|
||||
"""
|
||||
Show the banner screen. Grab from the 'connect_screen' config directive.
|
||||
"""
|
||||
buffer = ansi.parse_ansi(gameconf.get_configvalue('connect_screen'))
|
||||
self.msg(buffer)
|
||||
self.lineReceived(data=cmdstr)
|
||||
|
||||
def handle_close(self):
|
||||
"""
|
||||
Break the connection and do some accounting.
|
||||
"""
|
||||
pobject = self.get_pobject()
|
||||
if pobject:
|
||||
pobject.set_flag("CONNECTED", False)
|
||||
pobject.get_location().emit_to_contents("%s has disconnected." % (pobject.get_name(show_dbref=False),), exclude=pobject)
|
||||
uaccount = pobject.get_user_account()
|
||||
uaccount.last_login = datetime.now()
|
||||
uaccount.save()
|
||||
|
||||
self.disconnectClient()
|
||||
self.logged_in = False
|
||||
session_mgr.remove_session(self)
|
||||
|
||||
def get_pobject(self):
|
||||
"""
|
||||
Returns the object associated with a session.
|
||||
"""
|
||||
try:
|
||||
result = Object.objects.get(id=self.uid)
|
||||
return result
|
||||
except:
|
||||
return False
|
||||
|
||||
def game_connect_screen(self):
|
||||
"""
|
||||
Show the banner screen. Grab from the 'connect_screen' config directive.
|
||||
"""
|
||||
buffer = ansi.parse_ansi(gameconf.get_configvalue('connect_screen'))
|
||||
self.msg(buffer)
|
||||
|
||||
def is_loggedin(self):
|
||||
"""
|
||||
Returns a boolean True if the session is logged in.
|
||||
"""
|
||||
try:
|
||||
return self.logged_in
|
||||
except:
|
||||
return False
|
||||
|
||||
def login(self, user):
|
||||
"""
|
||||
After the user has authenticated, handle logging him in.
|
||||
"""
|
||||
self.uid = user.id
|
||||
self.name = user.username
|
||||
self.logged_in = True
|
||||
self.conn_time = time.time()
|
||||
pobject = self.get_pobject()
|
||||
session_mgr.disconnect_duplicate_session(self)
|
||||
pobject.set_flag("CONNECTED", True)
|
||||
def is_loggedin(self):
|
||||
"""
|
||||
Returns a boolean True if the session is logged in.
|
||||
"""
|
||||
try:
|
||||
return self.logged_in
|
||||
except:
|
||||
return False
|
||||
|
||||
def login(self, user):
|
||||
"""
|
||||
After the user has authenticated, handle logging him in.
|
||||
"""
|
||||
self.uid = user.id
|
||||
self.name = user.username
|
||||
self.logged_in = True
|
||||
self.conn_time = time.time()
|
||||
pobject = self.get_pobject()
|
||||
session_mgr.disconnect_duplicate_session(self)
|
||||
pobject.set_flag("CONNECTED", True)
|
||||
|
||||
self.msg("You are now logged in as %s." % (self.name,))
|
||||
pobject.get_location().emit_to_contents("%s has connected." % (pobject.get_name(show_dbref=False),), exclude=pobject)
|
||||
self.execute_cmd("look")
|
||||
functions_general.log_infomsg("Login: %s" % (self,))
|
||||
|
||||
# Update their account's last login time.
|
||||
user.last_login = datetime.now()
|
||||
user.save()
|
||||
pobject.set_attribute("Last", "%s" % (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()),))
|
||||
pobject.set_attribute("Lastsite", "%s" % (self.address[0],))
|
||||
self.msg("You are now logged in as %s." % (self.name,))
|
||||
pobject.get_location().emit_to_contents("%s has connected." % (pobject.get_name(show_dbref=False),), exclude=pobject)
|
||||
self.execute_cmd("look")
|
||||
functions_general.log_infomsg("Login: %s" % (self,))
|
||||
|
||||
# Update their account's last login time.
|
||||
user.last_login = datetime.now()
|
||||
user.save()
|
||||
pobject.set_attribute("Last", "%s" % (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()),))
|
||||
pobject.set_attribute("Lastsite", "%s" % (self.address[0],))
|
||||
|
||||
# Load their channel selection from a pickled attribute.
|
||||
self.load_user_channels()
|
||||
|
||||
def msg(self, message):
|
||||
"""
|
||||
Sends a message to the session.
|
||||
"""
|
||||
if isinstance(message, unicode):
|
||||
message = message.encode("utf-8")
|
||||
self.sendLine("%s" % (message,))
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
String representation of the user session class. We use
|
||||
this a lot in the server logs and stuff.
|
||||
"""
|
||||
if self.is_loggedin():
|
||||
symbol = '#'
|
||||
else:
|
||||
symbol = '?'
|
||||
return "<%s> %s@%s" % (symbol, self.name, self.address,)
|
||||
# Load their channel selection from a pickled attribute.
|
||||
self.load_user_channels()
|
||||
|
||||
def msg(self, message):
|
||||
"""
|
||||
Sends a message to the session.
|
||||
"""
|
||||
if isinstance(message, unicode):
|
||||
message = message.encode("utf-8")
|
||||
self.sendLine("%s" % (message,))
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
String representation of the user session class. We use
|
||||
this a lot in the server logs and stuff.
|
||||
"""
|
||||
if self.is_loggedin():
|
||||
symbol = '#'
|
||||
else:
|
||||
symbol = '?'
|
||||
return "<%s> %s@%s" % (symbol, self.name, self.address,)
|
||||
|
|
|
|||
152
session_mgr.py
152
session_mgr.py
|
|
@ -9,94 +9,94 @@ Session manager, handles connected players.
|
|||
session_list = []
|
||||
|
||||
def add_session(session):
|
||||
"""
|
||||
Adds a session to the session list.
|
||||
"""
|
||||
session_list.insert(0, session)
|
||||
functions_general.log_infomsg('Sessions active: %d' % (len(get_session_list(return_unlogged=True),)))
|
||||
|
||||
"""
|
||||
Adds a session to the session list.
|
||||
"""
|
||||
session_list.insert(0, session)
|
||||
functions_general.log_infomsg('Sessions active: %d' % (len(get_session_list(return_unlogged=True),)))
|
||||
|
||||
def get_session_list(return_unlogged=False):
|
||||
"""
|
||||
Lists the connected session objects.
|
||||
"""
|
||||
if return_unlogged:
|
||||
return session_list
|
||||
else:
|
||||
return [sess for sess in session_list if sess.is_loggedin()]
|
||||
"""
|
||||
Lists the connected session objects.
|
||||
"""
|
||||
if return_unlogged:
|
||||
return session_list
|
||||
else:
|
||||
return [sess for sess in session_list if sess.is_loggedin()]
|
||||
|
||||
def disconnect_all_sessions():
|
||||
"""
|
||||
Cleanly disconnect all of the connected sessions.
|
||||
"""
|
||||
for sess in get_session_list():
|
||||
sess.handle_close()
|
||||
"""
|
||||
Cleanly disconnect all of the connected sessions.
|
||||
"""
|
||||
for sess in get_session_list():
|
||||
sess.handle_close()
|
||||
|
||||
def disconnect_duplicate_session(session):
|
||||
"""
|
||||
Disconnects any existing session under the same object. This is used in
|
||||
connection recovery to help with record-keeping.
|
||||
"""
|
||||
sess_list = get_session_list()
|
||||
new_pobj = session.get_pobject()
|
||||
for sess in sess_list:
|
||||
if new_pobj == sess.get_pobject() and sess != session:
|
||||
sess.msg("Your account has been logged in from elsewhere, disconnecting.")
|
||||
sess.disconnectClient()
|
||||
return True
|
||||
return False
|
||||
"""
|
||||
Disconnects any existing session under the same object. This is used in
|
||||
connection recovery to help with record-keeping.
|
||||
"""
|
||||
sess_list = get_session_list()
|
||||
new_pobj = session.get_pobject()
|
||||
for sess in sess_list:
|
||||
if new_pobj == sess.get_pobject() and sess != session:
|
||||
sess.msg("Your account has been logged in from elsewhere, disconnecting.")
|
||||
sess.disconnectClient()
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def check_all_sessions():
|
||||
"""
|
||||
Check all currently connected sessions and see if any are dead.
|
||||
"""
|
||||
idle_timeout = int(gameconf.get_configvalue('idle_timeout'))
|
||||
"""
|
||||
Check all currently connected sessions and see if any are dead.
|
||||
"""
|
||||
idle_timeout = int(gameconf.get_configvalue('idle_timeout'))
|
||||
|
||||
if len(session_list) <= 0:
|
||||
return
|
||||
if len(session_list) <= 0:
|
||||
return
|
||||
|
||||
if idle_timeout <= 0:
|
||||
return
|
||||
|
||||
for sess in get_session_list(return_unlogged=True):
|
||||
if (time.time() - sess.cmd_last) > idle_timeout:
|
||||
sess.msg("Idle timeout exceeded, disconnecting.")
|
||||
sess.handle_close()
|
||||
if idle_timeout <= 0:
|
||||
return
|
||||
|
||||
for sess in get_session_list(return_unlogged=True):
|
||||
if (time.time() - sess.cmd_last) > idle_timeout:
|
||||
sess.msg("Idle timeout exceeded, disconnecting.")
|
||||
sess.handle_close()
|
||||
|
||||
def remove_session(session):
|
||||
"""
|
||||
Removes a session from the session list.
|
||||
"""
|
||||
try:
|
||||
session_list.remove(session)
|
||||
functions_general.log_infomsg('Sessions active: %d' % (len(get_session_list()),))
|
||||
except:
|
||||
#functions_general.log_errmsg("Unable to remove session: %s" % (session,))
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
Removes a session from the session list.
|
||||
"""
|
||||
try:
|
||||
session_list.remove(session)
|
||||
functions_general.log_infomsg('Sessions active: %d' % (len(get_session_list()),))
|
||||
except:
|
||||
#functions_general.log_errmsg("Unable to remove session: %s" % (session,))
|
||||
pass
|
||||
|
||||
|
||||
def session_from_object(targobject):
|
||||
"""
|
||||
Return the session object given a object (if there is one open).
|
||||
|
||||
session_list: (list) The server's session_list attribute.
|
||||
targobject: (Object) The object to match.
|
||||
"""
|
||||
results = [prospect for prospect in session_list if prospect.get_pobject() == targobject]
|
||||
if results:
|
||||
return results[0]
|
||||
else:
|
||||
return False
|
||||
"""
|
||||
Return the session object given a object (if there is one open).
|
||||
|
||||
session_list: (list) The server's session_list attribute.
|
||||
targobject: (Object) The object to match.
|
||||
"""
|
||||
results = [prospect for prospect in session_list if prospect.get_pobject() == targobject]
|
||||
if results:
|
||||
return results[0]
|
||||
else:
|
||||
return False
|
||||
|
||||
def session_from_dbref(dbstring):
|
||||
"""
|
||||
Return the session object given a dbref (if there is one open).
|
||||
|
||||
dbstring: (int) The dbref number to match against.
|
||||
"""
|
||||
if is_dbref(dbstring):
|
||||
results = [prospect for prospect in session_list if prospect.get_pobject().dbref_match(dbstring)]
|
||||
if results:
|
||||
return results[0]
|
||||
else:
|
||||
return False
|
||||
"""
|
||||
Return the session object given a dbref (if there is one open).
|
||||
|
||||
dbstring: (int) The dbref number to match against.
|
||||
"""
|
||||
if is_dbref(dbstring):
|
||||
results = [prospect for prospect in session_list if prospect.get_pobject().dbref_match(dbstring)]
|
||||
if results:
|
||||
return results[0]
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
28
urls.py
28
urls.py
|
|
@ -10,21 +10,21 @@ from django.conf.urls.defaults import *
|
|||
import settings
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# User Authentication
|
||||
(r'^accounts/login', 'django.contrib.auth.views.login'),
|
||||
(r'^accounts/logout', 'django.contrib.auth.views.logout'),
|
||||
# User Authentication
|
||||
(r'^accounts/login', 'django.contrib.auth.views.login'),
|
||||
(r'^accounts/logout', 'django.contrib.auth.views.logout'),
|
||||
|
||||
# Admin interface
|
||||
(r'^admin/', include('django.contrib.admin.urls')),
|
||||
# Admin interface
|
||||
(r'^admin/', include('django.contrib.admin.urls')),
|
||||
|
||||
# Front page
|
||||
(r'^', include('apps.website.urls')),
|
||||
# Front page
|
||||
(r'^', include('apps.website.urls')),
|
||||
|
||||
# News stuff
|
||||
(r'^news/', include('apps.news.urls')),
|
||||
# News stuff
|
||||
(r'^news/', include('apps.news.urls')),
|
||||
|
||||
# Page place-holder for things that aren't implemented yet.
|
||||
(r'^tbi/', 'apps.website.views.to_be_implemented'),
|
||||
# Page place-holder for things that aren't implemented yet.
|
||||
(r'^tbi/', 'apps.website.views.to_be_implemented'),
|
||||
)
|
||||
|
||||
# If you'd like to serve media files via Django (strongly not recommended!),
|
||||
|
|
@ -33,6 +33,6 @@ urlpatterns = patterns('',
|
|||
# test server. Normally you want a webserver that is optimized for serving
|
||||
# static content to handle media files (apache, lighttpd).
|
||||
if settings.SERVE_MEDIA:
|
||||
urlpatterns += patterns('',
|
||||
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
|
||||
)
|
||||
urlpatterns += patterns('',
|
||||
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue