Beispiel #1
0
def kick_from_alliance():
    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)
    if alliance is None:
        return "You are not in an alliance, can't kick anyone"

    username = request.form['username']

    # Make sure user is in database and game world.
    api = screeps_client.get_client()
    auth = AuthPlayer(api)
    ign = auth.id_from_name(username)

    # # Check if user is not leader
    # leader_list = alliance['leaders']
    # if my_id not in leader_list:
    #     flash('Only the alliance leader can remove members.')
    #     return redirect(url_for("my_alliance"))

    if not ign:
        flash(
            'User not present in game - remember usernames are case sensitive.'
        )
        return redirect(url_for("my_alliance"))

    # Get database id
    user_id = users_model.user_id_from_db(username)

    if not user_id:
        flash('User not present in system - please try again later.')
        return redirect(url_for("my_alliance"))

    # Is user already in an alliance?
    current_alliance = users_model.alliance_of_user(user_id)
    if not current_alliance:
        flash('User is not in an alliance.')
        return redirect(url_for("my_alliance"))
    if current_alliance[1] != alliance[1]:
        flash('User is not in your alliance.')
        return redirect(url_for("my_alliance"))

    users_model.update_alliance_by_user_id(user_id, None)

    # # Remove user from leader list if there
    # if user_id in leader_list:
    #     leader_list.remove(user_id)
    #     alliances_model.update_leader_of_alliance(alliance['shortname'], leader_list)

    flash('Successfully kicked {} from your alliance'.format(username))
    kicker_name = users_model.user_name_from_db_id(my_id)

    # Get player id for message and send
    player_id = users_model.player_id_from_db(username)
    api.msg_send(
        player_id,
        'You have been removed from {} by {}.'.format(alliance['fullname'],
                                                      kicker_name))
    return redirect(url_for("my_alliance"))
Beispiel #2
0
def update_my_alliance_charter():
    charter = request.form['charter']
    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)

    alliances_model.update_charter_of_alliance(alliance['shortname'], charter)
    return (redirect(url_for('my_alliance')))
Beispiel #3
0
def upload_my_alliance_logo():
    # check if the post request has the file part
    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)

    if (alliance is None):
        return "You are not in an alliance, can't do this"

    if 'logo' not in request.files:
        #flash('No file part')
        return redirect(url_for('my'))
    file = request.files['logo']
    # if user does not select file, browser also
    # submit a empty part without filename
    if file.filename == '':
        #    flash('No selected file')
        return redirect(url_for('my'))
    if file and allowed_file(file.filename):
        filename = secure_filename(
            hashlib.sha512(os.urandom(128)).hexdigest()[0:15])
        ext = file.filename.rsplit('.', 1)[1]
        filename = filename + '.' + ext
        file.save(os.path.join(app.config['OBJECT_STORAGE'], filename))
        alliances_model.update_logo_of_alliance(alliance['shortname'],
                                                filename)
        return redirect(url_for('my_alliance'))
Beispiel #4
0
def invite_to_alliance():
    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)
    if alliance is None:
        return "You are not in an alliance."

    # # Check if user is not leader or if leader has not been set yet
    # leader_list = alliance['leader']
    # if my_id not in leader_list:
    #     flash('Only the alliance leaders can invite.')
    #     return redirect(url_for("my_alliance"))

    username = request.form['username']

    # Make sure user is in database and game world.
    api = screeps_client.get_client()
    auth = AuthPlayer(api)
    ign = auth.id_from_name(username)

    if not ign:
        flash(
            'User not present in game - remember usernames are case sensitive.'
        )
        return redirect(url_for("my_alliance"))

    # Get database id
    id = users_model.user_id_from_db(username)

    if not id:
        flash('User not present in system - please try again later.')
        return redirect(url_for("my_alliance"))

    # Is user already in an alliance?
    current_alliance = users_model.alliance_of_user(id)
    if current_alliance:
        flash('User is already in an alliance.')
        return redirect(url_for("my_alliance"))

    invites.add_invite(id, alliance['shortname'], my_id)
    api.msg_send(
        ign, "You are invited to join %s \n\n%s" %
        (alliance['fullname'], url_for('list_invites', _external=True)))

    flash('Successfully invited {} to your alliance'.format(username))
    return redirect(url_for("my_alliance"))
Beispiel #5
0
def list_invites():
    # Is user already in an alliance?
    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)
    if alliance:
        return redirect(url_for("my_alliance"))

    my_invites = invites.get_invites_by_user(session['my_id'])
    return render_template("my_invites.html", invites=my_invites)
Beispiel #6
0
def update_my_alliance_charter():
    charter = request.form['charter']
    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)

    # # Check if user is not leader or if leader has not been set yet
    # leader_list = alliance['leader']
    # if my_id not in leader_list:
    #     flash('Only the alliance leaders can update the charter.')
    #     return redirect(url_for("my_alliance"))

    alliances_model.update_charter_of_alliance(alliance['shortname'], charter)
    return redirect(url_for('my_alliance'))
Beispiel #7
0
def leave_alliance():
    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)
    if alliance is None:
        return "You are not in an alliance."

    # # Check if user is not leader or if leader has not been set yet
    # leader_list = alliance['leader']
    #
    # # Remove user from leader list if there
    # if my_id in leader_list:
    #     leader_list.remove(my_id)
    #     alliances_model.update_leader_of_alliance(alliance['shortname'], leader_list)
    users_model.update_alliance_by_screeps_id(session['screeps_id'], None)
    return redirect(url_for("my_alliance"))
Beispiel #8
0
def update_my_alliance_profile():

    if re.match('^[\w|\s|-]+$', request.form['fullname']):
        fullname = request.form['fullname']

    if re.match('^\w+$', request.form['shortname']):
        shortname = request.form['shortname']

    if re.match('^[\w|-]+$', request.form['slack_channel']):
        slack_channel = request.form['slack_channel']
    else:
        slack_channel = None

    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)
    alliances_model.update_all_alliances_info(alliance['shortname'], shortname,
                                              fullname, slack_channel)
    return (redirect(url_for('my_alliance')))
Beispiel #9
0
def update_my_alliance_profile():
    if re.match('^[\w|\s|-]+$', request.form['fullname']):
        fullname = request.form['fullname']

    if re.match('^\w+$', request.form['shortname']):
        shortname = request.form['shortname']

    if re.match('^[\w|-]+$', request.form['slack_channel']):
        slack_channel = request.form['slack_channel']
    else:
        slack_channel = None

    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)

    # # Check if user is not leader or if leader has not been set yet
    # leader_list = alliance['leader']
    # if my_id not in leader_list:
    #     flash('Only the alliance leaders can update this information.')
    #     return redirect(url_for("my_alliance"))

    alliances_model.update_all_alliances_info(alliance['shortname'], shortname,
                                              fullname, slack_channel)
    return redirect(url_for('my_alliance'))
Beispiel #10
0
def send_message():
    my_id = session['my_id']
    message = request.form['alliance-message']
    alliance = users_model.alliance_of_user(my_id)
    if alliance is None:
        return "You are not in an alliance."

    # # Check if user is not leader or if leader has not been set yet
    # leader_list = alliance['leader']
    # if my_id not in leader_list:
    #     flash('Only the alliance leaders can send alliance wide messages.')
    #     return redirect(url_for("my_alliance"))

    alliance_members = users_model.find_player_id_by_alliance(
        alliance['shortname'])
    api = screeps_client.get_client()

    sender_name = users_model.user_name_from_db_id(my_id)
    for player_id in alliance_members:
        api.msg_send(player_id,
                     '{}\n\nSent By: {}'.format(message, sender_name))

    flash('Message sent.')
    return redirect(url_for("my_alliance"))
Beispiel #11
0
def my_alliance():
    my_id = session['my_id']
    alliance = users_model.alliance_of_user(my_id)
    if (alliance is None):
        return render_template("alliance_creation.html")
    return render_template('my.html', alliance=alliance)