def route_community_guild_join(gid, pid): user = current_user() found = False for player in user.players: if player.id == pid: found = True break if not found: return redirect(url_for('route_community_guild', id=gid)) invite = GuildInvite.query.filter(GuildInvite.guild_id == gid) invite = invite.filter(GuildInvite.player_id == pid).first() if not invite: return redirect(url_for('route_community_guild', id=gid)) rank = db.session().query(GuildRank.id).filter(GuildRank.guild_id == gid) rank = rank.filter(GuildRank.level == 1).first() if not rank: return redirect(url_for('route_community_guild', id=gid)) membership = GuildMembership() membership.player_id = pid membership.guild_id = gid membership.rank_id = rank.id membership.nick = '' db.session().delete(invite) db.session().add(membership) db.session().commit() flash('You have joined the guild.', 'success') return redirect(url_for('route_community_guild', id=gid))
def route_community_guild_create_post(): name = request.form.get('name', '', type=str) character = request.form.get('character', 0, type=int) motd = request.form.get('motd', '', type=str) user = current_user() error = False character = Player.query.filter(Player.id == character).first() if not character or character.account_id != user.id: flash('You can not create a guild with not your own character.', 'error') error = True if character and character.level < GUILD_LEVEL: flash( 'The character needs to be at least level {}.'.format(GUILD_LEVEL), 'error') error = True if character and character.getGuild(): flash('The character can not be a member of another guild.', 'error') error = True if len(name) < 4 or len(name) > 32: flash('The guild name must be between 4 and 32 characters long.', 'error') error = True if not GUILD_NAME_EXPR.match(name): flash( 'The guild name may only contain latin characters (A-Z, a-z and spaces).', 'error') error = True if len(name.split(' ')) > 3: flash('The guild name may only consist of 3 words.', 'error') error = True guild = Guild.query.filter(Guild.name == name).first() if guild: flash('The guild name is taken by another guild.', 'error') error = True if error: return redirect(url_for('route_community_guild_create')) guild = Guild() guild.name = name guild.ownerid = character.id guild.creationdata = int(time()) guild.motd = motd db.session().add(guild) db.session().commit() rank = db.session().query(GuildRank.id).filter( GuildRank.guild_id == guild.id).filter(GuildRank.level == 3).first() membership = GuildMembership() membership.player_id = character.id membership.guild_id = guild.id membership.rank_id = rank[0] db.session().add(membership) db.session().commit() flash('The guild has been created.', 'success') return redirect(url_for('route_community_guild', id=guild.id))
def route_community_guild_create_post(): name = request.form.get('name', '', type=str) character = request.form.get('character', 0, type=int) motd = request.form.get('motd', '', type=str) user = current_user() error = False character = Player.query.filter(Player.id == character).first() if not character or character.account_id != user.id: flash('You can not create a guild with not your own character.', 'error') error = True if character and character.level < GUILD_LEVEL: flash('The character needs to be at least level {}.'.format(GUILD_LEVEL), 'error') error = True if character and character.getGuild(): flash('The character can not be a member of another guild.', 'error') error = True if len(name) < 4 or len(name) > 32: flash('The guild name must be between 4 and 32 characters long.', 'error') error = True if not GUILD_NAME_EXPR.match(name): flash('The guild name may only contain latin characters (A-Z, a-z and spaces).', 'error') error = True if len(name.split(' ')) > 3: flash('The guild name may only consist of 3 words.', 'error') error = True guild = Guild.query.filter(Guild.name == name).first() if guild: flash('The guild name is taken by another guild.', 'error') error = True if error: return redirect(url_for('route_community_guild_create')) guild = Guild() guild.name = name guild.ownerid = character.id guild.creationdata = int(time()) guild.motd = motd db.session().add(guild) db.session().commit() rank = db.session().query(GuildRank.id).filter(GuildRank.guild_id == guild.id).filter(GuildRank.level == 3).first() membership = GuildMembership() membership.player_id = character.id membership.guild_id = guild.id membership.rank_id = rank[0] db.session().add(membership) db.session().commit() flash('The guild has been created.', 'success') return redirect(url_for('route_community_guild', id=guild.id))