def update_hex(col, row, **kargs):
    """
    ヘックスのレコードを更新
    :param col: 該当ヘックスcol
    :param row: 該当ヘックスrow
    :param kargs: {key : value, ...}
    :return: 成功 ? True : False
    """

    try:
        db = DBSingleton()

        sentence = "update hex_grid set"

        for key, value in kargs.items():
            sentence = sentence + " " + str(key) + " = \"" + str(value) + "\""

        sentence += " where col = " + str(col) + " and row = " + str(row)

        db.exec(sentence)
        return True

    except DBError as e:
        logging.error(e.message, detailed_error.get_error())
        return False
def update_visible_area(visibility, division_id, switch):
    """
    部隊の視界内のヘックスの可視性を変更
    :param visibility: 可視権
    :param division_id: 部隊ID
    :param switch: True ? 可算 : 減算
    :return: 成功 ? True : False
    """

    try:

        # 部隊の情報
        from lib.DB.division_controller import get_division_info
        division = get_division_info(division_id)

        # 兵科の情報
        from lib.DB.branch_controller import get_branch_info
        branch = get_branch_info(division["branch_id"])

        # 現在の部隊の視界
        visible_area = get_adjacent_area(division["col"], division["row"],
                                         branch["visible_range"])
        visible_area.append({"col": division["col"], "row": division["row"]})

        # 更新
        if switch: switch = str("+")
        else: switch = str("-")

        where = "where "
        for hex in visible_area:
            where = where + "(col=" + str(hex["col"]) + " and row=" + str(
                hex["row"]) + ") or"
        where = where[:-3]

        query = "update hex_grid set " + \
                visibility + " = " + visibility + " " + switch + " 1 " + where
        db = DBSingleton()
        db.exec(query)

        print("update p6")
    except DBError as e:
        logging.error(e.message, detailed_error.get_error())
        return False

    except Exception as e:
        logging.error(e, detailed_error.get_error())
        return False

    return True
def update_bbs_country(_cls, _self, data):

    payload = { "event" : "update_bbs_country"}
    send_data = None
    country = None

    try:

        #DBから最新の会議室への書き込みを取得
        user_id = _self.get_secure_cookie("user_id").decode('utf-8')
        db = DBSingleton()
        country = db.select("country_id", table="user", where="user_id=" + "\""+str(user_id) + "\"")
        country = country[0]["country_id"]
        query = "select user.user_name, user.icon_id, bbs_country.date, bbs_country.article from user " \
                "inner join bbs_country "\
                "on user.user_id=bbs_country.user_id "\
                "where bbs_country.country_id = " + str(country) + \
                " order by bbs_country.date desc limit 1;"
        result = db.exec(query, True)

        send_data= {"name" : result[0][0],
                "icon" : result[0][1],
                "date" : result[0][2].strftime("%Y-%m-%d %H:%M:%S"),
                "article" : result[0][3]}

    except DBError as e:
        logging.error(u"init_bbs_country.py: 会議室の情報取得失敗。\nmessage = " + e.message)
        raise Exception(u"会議室の情報取得失敗")

    #送信するデータ組み立て
    payload["data"] = send_data
    print(payload)
    _cls.send_member_by_country(payload, country)
def init_bbs_country(_cls, _self, data):

    payload = {"event": "init_bbs_country"}
    data = []

    #DBから会議室の内容を集める
    try:
        user_id = _self.get_secure_cookie("user_id").decode('utf-8')
        db = DBSingleton()
        country = db.select("country_id",
                            table="user",
                            where="user_id=" + "\"" + str(user_id) + "\"")
        country = country[0]["country_id"]
        query = "select user.user_name, user.icon_id, bbs_country.date, bbs_country.article from user " \
                "inner join bbs_country "\
                "on user.user_id=bbs_country.user_id "\
                "where bbs_country.country_id = " + str(country) + \
                " order by bbs_country.date desc limit 20;"
        result = db.exec(query, True)

        for article in result:
            data.append({
                "name": article[0],
                "icon": article[1],
                "date": article[2].strftime("%Y-%m-%d %H:%M:%S"),
                "article": article[3]
            })

    except DBError as e:
        logging.error(u"init_bbs_country.py: 会議室の情報取得失敗。\nmessage = " + str(e))
        raise Exception("会議室の情報取得失敗")

    #送信するデータ組み立て
    payload["data"] = data
    _self.send_you(payload)
Exemple #5
0
def move_division(division_id, dest_col, dest_row):
    """
    部隊を移動させる
    :param division_id: 部隊ID
    :param dest_col: 目的地col
    :param dest_row: 目的地row
    :return: 成功 ? True : False
    """

    try:
        db = DBSingleton()
        query = "update division set col=" + dest_col + ", row=" + dest_row
        where = " where division_id = \"" + division_id + "\""
        db.exec(query + where, False)
        return True

    except DBError as e:
        logging.error(e.message)
        return False
def move_user(user_id, dest_col, dest_row):
    """
        プレイヤーを移動させる
        :param user_id: ユーザーID
        :param dest_col: 目的地col
        :param dest_row: 目的地row
        :return: 成功 ? True : False
        """

    try:
        db = DBSingleton()
        query = "update user set col=" + dest_col + ", row=" + dest_row
        where = " where user_id = \"" + user_id + "\""
        db.exec(query + where, False)
        return True

    except DBError as e:
        logging.error(e.message)
        return False
Exemple #7
0
def update_division_before_move(division_id, food, money, status="moving"):
    """
    移動に伴う部隊情報の更新
    :param division_id: 部隊ID
    :param food: 消費物資
    :param money: 消費資金
    :return: 更新成功 ? True : False
    """
    try:
        db = DBSingleton()
        query = "update division set"  + \
                " food = food - " + str(food) + \
                ", money =money-" + str(money) + \
                " where division_id = \"" + str(division_id) + "\""
        db.exec(query)
        return True

    except DBError as e:
        logging.error(e.message)
        return False
Exemple #8
0
def update_division(division_id, **kwargs):
    """
    部隊の情報更新
    :param division_id:
    :param kwargs:
    :return: 成功 ? True : False
    """
    try:
        db = DBSingleton()

        sentence = "update division set "
        for key, value in kwargs.items():
            sentence = sentence + key + " = \"" + str(value) + "\","
        sentence = sentence[:-1]
        sentence + " where division_id = \"" + str(division_id) + "\""
        db.exec(sentence)
        return True

    except DBError as e:
        return False
Exemple #9
0
def update_division_status(division_id, status):
    """
    部隊のステータスを変更
    :param division_id:
    :param status:新しいステータス
    :return: 成功 ? True : False
    """
    if len(status) == 0:
        logging.error(u"statusが空")
        return False

    try:
        db = DBSingleton()
        query = "update division set"  + \
                " status = \"" + str(status) + "\"" \
                " where division_id = \"" + str(division_id) + "\""
        db.exec(query)
        return True

    except DBError as e:
        return False
def get_players_by_visibility(visibility, isVisible, hexes=None):
    """
    可視権から可視範囲上のプレイヤー情報を取得
    :param visibility: 可視権
    :param isVisible: true ? 可視なプレイヤー : 不可視なプレイヤー
    :param [hexes]: 指定されたグリッド [ [col, row, ...], ... ]
    :return: [{user_name, col, row, icon_id, country_id}]
    """

    print("on get_players_by_visibility")
    logger = logging.getLogger(sys._getframe().f_code.co_name)
    results = None
    try:
        db = DBSingleton()

        where = "where hex_grid." + visibility
        if isVisible:
            where += " > 0 "
        else:
            where += " = 0 "
        # ヘックスが指定されていれば条件追加
        print("hexes = ", hexes)
        if hexes is not None:
            print(hexes)
            where += "and ("
            for hex in hexes:
                where = where + " (hex_grid.col=" + str(
                    hex["col"]) + " and hex_grid.row=" + str(
                        hex["row"]) + ") or"
            where = where[:-3]
            where += ");"

        query  = "select user_name, user.col, user.row, icon_id, user.country_id from user " \
                "inner join hex_grid "\
                "on user.col=hex_grid.col and user.row=hex_grid.row " \
                + where
        results = db.exec(query, True)

    except DBError as e:
        logging.error(" message = " + e.message)
        return False

    result = []
    for player in results:
        record = {
            "user_name": player[0],
            "col": player[1],
            "row": player[2],
            "icon_id": player[3],
            "country_id": player[4]
        }
        result.append(record)
    return result
def update_user_before_move(user_id, wait_untill):
    """
    移動に伴うユーザー情報の更新
    :param user_id:
    :param wait_untill: 到着予定時刻を表す時刻オブジェクト
    :param status: 移動中の状態
    :return: 更新成功 ?  : Exception
    """

    try:
        db = DBSingleton()
        query = "update user set"  + \
                " wait_untill = \"" +  BJTime.encode_to_sql(wait_untill)+ "\"" \
                " where user_id = \"" + str(user_id) + "\""
        result = db.exec(query)

    except DBError as e:
        logging.error(e.message)
        raise Exception("DBエラー : 移動前のユーザー情報更新失敗")
        user_id = _self.get_secure_cookie("user_id").decode('utf-8')
        db = DBSingleton()
        country = db.select("country_id", table="user", where="user_id=" + "\""+str(user_id) + "\"")
        country = country[0]
        data = data.replace("\n", "<br>")
        db.insert(table="bbs_country",
                  user_id=str(user_id),
                  country_id=str(country["country_id"]),
                  article=str(data))

    except DBError as e:
        logging.error(u"init_bbs_country.write_bbs_country: 会議室への書き込み失敗。\nmessage = " + e.message)
        raise Exception(u"会議室への書き込み失敗")

    #更新を通知
    update_bbs_country(_cls, _self, {})


if __name__ == "__main__":

        db = DBSingleton()
        country = 0
        query = "select user.user_name, user.icon_id, bbs_country.date, bbs_country.article from user " \
                "inner join bbs_country "\
                "on user.user_id=bbs_country.user_id "\
                "where bbs_country.country_id = " + str(country) + \
                " order by bbs_country.date limit 20;"
        result = db.exec(query, True)

        print(result[0][2])
        print(result[0][2].strftime("%Y-%m-%d %H:%M:%S"))