From 1d15b8e714b9f5d8ba2344dcb6913dc5513ca75c Mon Sep 17 00:00:00 2001 From: Trever Fischer Date: Wed, 4 Apr 2012 22:54:01 -0400 Subject: [PATCH 1/2] Fix ban handling --- api/handlers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/handlers.py b/api/handlers.py index 36d3b08..820fe62 100644 --- a/api/handlers.py +++ b/api/handlers.py @@ -70,6 +70,8 @@ class NewPlayerSessionHandler(BaseHandler): except IndexError, e: return {'valid': False, 'error': 'User not found', 'permissions': []} if profile.user.is_active: + if profile.isBanned(): + return {'valid': False, 'error': 'Your account is banned.', 'permissions': []} ip = request.POST['ip'] server = request.server profile = MinecraftProfile.objects.get(mc_username__exact=playername) From f831ce7dbe5afeb6649679ebbdc4408e10b0c8d3 Mon Sep 17 00:00:00 2001 From: Trever Fischer Date: Thu, 5 Apr 2012 15:27:26 -0400 Subject: [PATCH 2/2] Add commands for drawing the invite graph, and importing from drupal --- local/management/commands/__init__.py | 0 .../commands/create_invite_graph.py | 20 ++++++++++ .../commands/import_invite_graph.py | 38 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 local/management/commands/__init__.py create mode 100644 local/management/commands/create_invite_graph.py create mode 100644 local/management/commands/import_invite_graph.py diff --git a/local/management/commands/__init__.py b/local/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/local/management/commands/create_invite_graph.py b/local/management/commands/create_invite_graph.py new file mode 100644 index 0000000..162c057 --- /dev/null +++ b/local/management/commands/create_invite_graph.py @@ -0,0 +1,20 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth.models import User +from django.core.exceptions import ObjectDoesNotExist +from datetime import datetime +from django.db import connections, connection +from local.models import Invite + +class Command(BaseCommand): + help = 'Generate a dot graph of invited users' + + def handle(self, *args, **options): + print "digraph G {" + print "rankdir=\"LR\"" + for i in Invite.objects.all(): + if i.claimer is None: + continue + if i.creator is None: + continue + print "\"%s\" -> \"%s\""%(i.creator.__unicode__(), i.claimer.__unicode__()) + print "}" diff --git a/local/management/commands/import_invite_graph.py b/local/management/commands/import_invite_graph.py new file mode 100644 index 0000000..b178e20 --- /dev/null +++ b/local/management/commands/import_invite_graph.py @@ -0,0 +1,38 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth.models import User +from django.core.exceptions import ObjectDoesNotExist +from datetime import datetime +from django.db import connections, connection +from local.models import Invite + +class Command(BaseCommand): + args = 'dbConfig' + help = 'Synchronize from a drupal mysql database' + + def handle(self, *args, **options): + if len(args) == 0: + c = connection.cursor() + else: + c = connections[args[0]].cursor() + c.execute("SELECT src.name AS inviter, dst.name AS invitee FROM users AS src LEFT JOIN invite ON invite.uid=src.uid LEFT JOIN users AS dst ON invite.invitee=dst.uid WHERE src.name IS NOT null AND dst.name IS NOT null") + for link in c: + if len(link[0]) == 0 or len(link[1]) == 0: + continue + try: + sourceUser = User.objects.get(username__iexact=link[0]) + except ObjectDoesNotExist, e: + print "Source user not found: %s"%(link[0]) + continue + try: + destUser = User.objects.get(username__iexact=link[1]) + except ObjectDoesNotExist, e: + print "Destination user not found: %s"%(link[1]) + continue + try: + i = Invite.objects.get(creator=sourceUser, claimer=destUser) + except ObjectDoesNotExist, e: + Invite.objects.create(creator=sourceUser, claimer=destUser) + print "Linked %s -> %s"%(sourceUser, destUser) + continue + print "Users already linked: %s -> %s"%(sourceUser, destUser) +