Add api to query server info

This commit is contained in:
Trever Fischer
2012-03-03 18:29:24 -05:00
parent dda78c0711
commit 8687e034ac
2 changed files with 10 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
from piston.handler import AnonymousBaseHandler, BaseHandler
from profiles.models import MinecraftProfile, Quote
from minecraft.models import MOTD
from minecraft.models import MOTD, Server
from django.http import HttpResponse
class WhitelistHandler(AnonymousBaseHandler):
@@ -33,3 +33,10 @@ class BalanceHandler(BaseHandler):
def read(self, request):
user = request.user
return {"balance":user.get_profile().currencyaccount.balance}
class ServerHandler(AnonymousBaseHandler):
allowed_methods = ('GET',)
def read(self, request, hostname):
s = Server.objects.get(hostname__exact=hostname)
return {"hostname":hostname, "port":s.port, "players": map(lambda x:x.mc_username, s.online_players())}