Example #1
0
def rpc_add_wow(server, charname):
	try:
		wowchar = battlenet.Character(battlenet.UNITED_STATES, server, charname)
	except:
		return False

	thumbnail = 'https://us.battle.net/static-render/us/' + wowchar.thumbnail
	with transact:
		char = Character.create(
				user=session.user,  
				game=WOW, 
				name=wowchar.name.decode('utf-8'), 
				server=server, 
				avatar=thumbnail, 
				last_update=date.today(),
				attrs=json.dumps(dict(
					faction=wowchar.faction,
					level=wowchar.level,
					charclass=wowchar.get_class_name(),
					race=wowchar.get_race_name(),
					item_level=wowchar.equipment.average_item_level
				))
			)

	return get_index.url(char.id)
Example #2
0
def profile(request):
    characters = Character.objects.filter(player=request.user)
    new_character_form = NewCharacterForm()
    error_message = ''
    if request.method =='POST':
        char_form = NewCharacterForm(request.POST)
        if char_form.is_valid():
            name = char_form.cleaned_data['name']
            server = char_form.cleaned_data['server']
            try:
                c = battlenet.Character(battlenet.UNITED_STATES, server, name)
                character = Character(name=name, server=server, player=request.user, level=0, ilvl=0)
                character.save()
                update_character(character)
            except Exception as e:
                    error_message = "This character does not exist on this server."
        else:
            new_character_form = char_form
    return render_to_response('demo/profile.html', {'error_message': error_message, 'characters':characters, 'new_character_form':new_character_form}, context_instance=RequestContext(request))
Example #3
0
def post_login(username=None, password=None):
	user = User.find(username, password)
	if user == None:
		return dict(username=username, error='Login failed')
	
	session['userId'] = user.id
	
	#Check for Character updates
	CurrentDate = date.today()
	for UserCharacter in user.characters:
		if UserCharacter.last_update < CurrentDate:
			if UserCharacter.game==WOW:
				try:
					wowchar = battlenet.Character(battlenet.UNITED_STATES,
							UserCharacter.server,
							UserCharacter.name)
				except:
					continue
				
				thumbnail = 'https://us.battle.net/static-render/us/' + wowchar.thumbnail
				with transact:
					if UserCharacter.attrs in ('', None, 'null'):
						attrs = {}
					else:
						attrs = json.loads(UserCharacter.attrs)
					attrs = attrs.update(dict(
							faction = wowchar.faction,
							level = wowchar.level,
							charclass = wowchar.get_class_name(),
							race = wowchar.get_race_name(),
							item_level = wowchar.equipment.average_item_level
						))
					UserCharacter.update(
							avatar = thumbnail,
							last_update = CurrentDate,
							attrs = json.dumps(attrs)
					)
					#Add any other attributes that need to be updated.
				
			#if Character.game==SWTOR:
				#TODO Add SWTOR character info

	redirect(handler.index.get_index)
Example #4
0
def register_view(request):
    if request.method == 'POST':
        new_user_form = NewUserForm(request.POST)
        if new_user_form.is_valid():
            # make this actually secure later
            if request.POST['secret_word'] != 'do not eat':
                error_message = "Please ask an officer in the guild for the secret word"
                return register_failed(request, error_message)
            username = request.POST['username']
            for u in User.objects.all() :
                if username == u.username:
                    error_message = "Username is taken."
                    return register_failed(request, error_message)
            password = make_password(request.POST['password'])
            email = request.POST['email']
            character = request.POST['character']
            server = request.POST['server']
            try:
                c = battlenet.Character(battlenet.UNITED_STATES, server, character)
            except Exception as e:
                    error_message = "This character does not exist on this server."
                    return register_failed(request, error_message)
            user = User(username=username, password=password, email=email)
            user.save()
            login_user = authenticate(username=username, password=request.POST['password'])
            login(request, login_user)
            character = Character(name=character, server=server, player=user, class_name='', level=0, ilvl=0)
            character.save()
            update_character(character)
            player = Player(user=user, main=character)
            player.save()
            return redirect('home')
        else:
            error_message = "There was a problem with your application."
            return register_failed(request, error_message)
    else:
        return redirect('home')
Example #5
0
 def get_character(name):
     return battlenet.Character(battlenet.UNITED_STATES, 'Nazjatar',
                                name)