Пример #1
0
class ChatmessageIngame(db.Model):
    __tablename__ = 'chatmessages_ingame'
    id = db.Column(db.Integer, primary_key=True)
    game_hashid = db.Column(db.String(10), index=True)
    author = db.Column(db.Integer, db.ForeignKey('users.id'))
    message = db.Column(db.String(500))
    timestamp = db.Column(db.DateTime)
Пример #2
0
class Game(GameBase):
    __tablename__ = 'games_x01'
    __mapper_args__ = {'polymorphic_identity': 'x01'}
    id = db.Column(db.Integer, db.ForeignKey('games_all.id'), primary_key=True)
    type = db.Column(db.Integer)
    in_mode = db.Column(db.String(15))
    out_mode = db.Column(db.String(15))
Пример #3
0
class Game(db.Model):
    __tablename__ = 'games'
    id = db.Column(db.Integer, primary_key=True)
    hashid = db.Column(db.String(10), unique=True)
    player1 = db.Column(db.Integer, db.ForeignKey('users.id'))
    player2 = db.Column(db.Integer, db.ForeignKey('users.id'))
    bo_sets = db.Column(db.Integer, nullable=False)
    bo_legs = db.Column(db.Integer, nullable=False)
    two_clear_legs = db.Column(db.Boolean)
    p1_sets = db.Column(db.Integer)
    p2_sets = db.Column(db.Integer)
    p1_legs = db.Column(db.Integer)
    p2_legs = db.Column(db.Integer)
    p1_score = db.Column(db.Integer)
    p2_score = db.Column(db.Integer)
    p1_next_turn = db.Column(db.Boolean)
    closest_to_bull = db.Column(db.Boolean)
    closest_to_bull_json = db.Column(db.JSON)
    status = db.Column(db.String(20))
    type = db.Column(db.Integer)
    match_json = db.Column(db.JSON)
    in_mode = db.Column(db.String(15))
    out_mode = db.Column(db.String(15))
    begin = db.Column(db.DateTime)
    end = db.Column(db.DateTime)
    opponent_type = db.Column(db.String(10))

    def set_hashid(self):
        self.hashid = secrets.token_urlsafe(8)[:8]

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
Пример #4
0
class Notification(db.Model):
    __tablename__ = 'notifications'
    id = db.Column(db.Integer, primary_key=True)
    user = db.Column(db.Integer, db.ForeignKey('users.id'), index=True)
    message = db.Column(db.String(500))
    author = db.Column(db.String(30))
    type = db.Column(db.String(30))
Пример #5
0
class UsernameChange(db.Model):
    __tablename__ = 'username_changes'
    id = db.Column(db.Integer, primary_key=True)
    user = db.Column(db.Integer)
    old_name = db.Column(db.String(25))
    new_name = db.Column(db.String(25))
    timestamp = db.Column(db.DateTime)
Пример #6
0
class Tournament(db.Model):
    __tablename__ = 'tournaments'
    id = db.Column(db.Integer, primary_key=True)
    creator = db.Column(db.Integer, db.ForeignKey('users.id'))
    hashid = db.Column(db.String(10), unique=True)
    name = db.Column(db.String(50), nullable=False)
    public = db.Column(db.Boolean, default=False)
    registration_open = db.Column(db.Boolean, default=True)
    description = db.Column(db.String(1000))
    external_url = db.Column(db.String(120))
    start_timestamp = db.Column(db.DateTime)
    creation_timestamp = db.Column(db.DateTime, default=datetime.utcnow())
    api_key = db.Column(db.String(16), default=None)
    players = db.relationship(
        'User',
        secondary=tournament_players_association_table,
        lazy=True,
        backref=db.backref('tournaments', lazy=True),
    )
    banned_players = db.relationship(
        'User',
        secondary=tournament_banned_players_association_table,
        lazy=True,
        backref=db.backref('tournaments_banned', lazy=True),
    )

    def __init__(self, **kwargs):
        super(Tournament, self).__init__(**kwargs)
        self.hashid = secrets.token_urlsafe(8)[:8]
        self.api_key = secrets.token_urlsafe(16)[:16]
Пример #7
0
class Chatmessage(db.Model):
    __tablename__ = 'chatmessages'
    id = db.Column(db.Integer, primary_key=True)
    author = db.Column(db.Integer, db.ForeignKey('users.id'))
    message = db.Column(db.String(500))
    timestamp = db.Column(db.DateTime, index=True)
    tournament_hashid = db.Column(db.String(10), db.ForeignKey('tournaments.hashid'), default=None)
Пример #8
0
class TournamentStageRound(db.Model):
    __tablename__ = 'tournament_stage_rounds'
    id = db.Column(db.Integer, primary_key=True)
    stage_id = db.Column(db.Integer, db.ForeignKey('tournament_stages.id'))
    stage = db.relationship("TournamentStage", back_populates="rounds")
    games = db.relationship("Game", back_populates="tournament_round")
    variant = db.Column(db.String(50))
    bo_sets = db.Column(db.Integer, nullable=False)
    bo_legs = db.Column(db.Integer, nullable=False)
    two_clear_legs = db.Column(db.Boolean)
    starter = db.Column(db.String(30))
    score_input_delay = db.Column(db.Integer, default=0)
Пример #9
0
class CricketPresetting(db.Model):
    __tablename__ = 'cricket_presettings'
    user = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True)
    bo_sets = db.Column(db.Integer)
    bo_legs = db.Column(db.Integer)
    two_clear_legs = db.Column(db.Boolean)
    starter = db.Column(db.String(25))
    opponent_type = db.Column(db.String(10))
    level = db.Column(db.Integer)
    public_challenge = db.Column(db.Boolean)
    webcam = db.Column(db.Boolean)
    score_input_delay = db.Column(db.Integer)
Пример #10
0
class X01Presetting(db.Model):
    __tablename__ = 'x01_presettings'
    user = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True)
    bo_sets = db.Column(db.Integer)
    bo_legs = db.Column(db.Integer)
    two_clear_legs = db.Column(db.Boolean)
    starter = db.Column(db.String(25))
    type = db.Column(db.Integer)
    in_mode = db.Column(db.String(15))
    out_mode = db.Column(db.String(15))
    opponent_type = db.Column(db.String(10))
    level = db.Column(db.Integer)
    public_challenge = db.Column(db.Boolean)
Пример #11
0
class TournamentStage(db.Model):
    __tablename__ = 'tournament_stages'
    id = db.Column(db.Integer, primary_key=True)
    tournament_id = db.Column(db.Integer, db.ForeignKey('tournaments.id'))
    tournament = db.relationship("Tournament", back_populates="stages")
    format = db.Column(db.String(20), nullable=False)
    rounds = db.relationship("TournamentStageRound", back_populates="stage")
Пример #12
0
class Privatemessage(db.Model):
    __tablename__ = 'privatemessages'
    id = db.Column(db.Integer, primary_key=True)
    sender = db.Column(db.Integer, db.ForeignKey('users.id'))
    receiver = db.Column(db.Integer, db.ForeignKey('users.id'))
    message = db.Column(db.String(500))
    timestamp = db.Column(db.DateTime)
Пример #13
0
class GameBase(db.Model):
    __abstract__ = True

    id = db.Column(db.Integer, primary_key=True)
    hashid = db.Column(db.String(10), unique=True)
    variant = db.Column(db.String(50))
    bo_sets = db.Column(db.Integer, nullable=False)
    bo_legs = db.Column(db.Integer, nullable=False)
    two_clear_legs = db.Column(db.Boolean)
    p1_sets = db.Column(db.Integer)
    p2_sets = db.Column(db.Integer)
    p1_legs = db.Column(db.Integer)
    p2_legs = db.Column(db.Integer)
    p1_score = db.Column(db.Integer)
    p2_score = db.Column(db.Integer)
    p1_next_turn = db.Column(db.Boolean)
    closest_to_bull = db.Column(db.Boolean)
    closest_to_bull_json = db.Column(db.JSON)
    status = db.Column(db.String(20), index=True)
    match_json = db.Column(db.JSON)
    begin = db.Column(db.DateTime)
    end = db.Column(db.DateTime)
    opponent_type = db.Column(db.String(10))
    public_challenge = db.Column(db.Boolean)
    score_input_delay = db.Column(db.Integer, default=0)
    webcam = db.Column(db.Boolean, default=False)
    jitsi_hashid = db.Column(db.String(10), unique=True)

    @declared_attr
    def tournament(cls):
        return db.Column(db.String(10),
                         db.ForeignKey('tournaments.hashid'),
                         default=None)

    @declared_attr
    def player1(cls):
        return db.Column(db.Integer, db.ForeignKey('users.id'), index=True)

    @declared_attr
    def player2(cls):
        return db.Column(db.Integer, db.ForeignKey('users.id'), index=True)

    def set_hashid(self):
        self.hashid = secrets.token_urlsafe(8)[:8]

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
Пример #14
0
class UserSettings(db.Model):
    __tablename__ = 'user_settings'
    user = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True)
    match_alerts = db.Column(db.Boolean, default=True)
    allow_challenges = db.Column(db.Boolean, default=True)
    allow_private_messages = db.Column(db.Boolean, default=True)
    allow_friend_requests = db.Column(db.Boolean, default=True)
    notification_sound = db.Column(db.Boolean, default=True)
    country = db.Column(db.String, default=None)
    last_country_change = db.Column(db.DateTime, default=None)
    checkout_suggestions = db.Column(db.Boolean, default=False)
    show_average_in_chat_list = db.Column(db.Boolean, default=False)
    profile_text = db.Column(db.String(2000), default=None)
    channel_id = db.Column(db.String(30), default=None)
    caller = db.Column(db.String(30),
                       db.ForeignKey('callers.name'),
                       default='default')
Пример #15
0
class WebcamSettings(db.Model):
    __tablename__ = 'webcam_settings'
    user = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True)
    user_object = relationship("User", back_populates="webcam_settings")
    activated = db.Column(db.Boolean, default=False)
    stream_consent = db.Column(db.Boolean, default=False)
    mobile_app = db.Column(db.Boolean, default=False)
    mobile_follower_mode = db.Column(db.Boolean, default=False)
    force_scoreboard_page = db.Column(db.Boolean, default=False)
    latest_jitsi_hashid = db.Column(db.String(10), default=None)
Пример #16
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    alternative_id = db.Column(db.Integer, index=True, unique=True)
    username = db.Column(db.String(25), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password = db.Column(db.String(128))
    active = db.Column(db.Boolean)
    avatar = db.Column(db.String(15), default=None)
    last_seen = db.Column(db.DateTime, default=datetime.utcnow())
    last_seen_ingame = db.Column(db.DateTime, default=datetime.utcnow())
    is_online = db.Column(db.Boolean, default=False)
    active_sessions = db.Column(db.Integer, default=0)
    status = db.Column(db.String(15), default='online')
    caller = db.Column(db.String(20), default='default')
    cpu_delay = db.Column(db.Integer, default=0)
    roles = db.relationship('Role', secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))
    registration_timestamp = db.Column(db.DateTime, default=datetime.utcnow())

    requested_friend_reqs = db.relationship(
        'FriendshipRequest',
        foreign_keys='FriendshipRequest.requesting_user_id',
        backref='requesting_user'
    )
    received_friend_reqs = db.relationship(
        'FriendshipRequest',
        foreign_keys='FriendshipRequest.receiving_user_id',
        backref='receiving_user'
    )
    aspiring_friends = association_proxy('received_friend_reqs', 'requesting_user')
    desired_friends = association_proxy('requested_friend_reqs', 'receiving_user')

    requested_friend_confs = db.relationship(
        'Friendship',
        foreign_keys='Friendship.user1_id',
        backref='requesting_friend'
    )
    received_friend_confs = db.relationship(
        'Friendship',
        foreign_keys='Friendship.user2_id',
        backref='receiving_friend'
    )
    friends_requested = association_proxy('received_friend_confs', 'requesting_friend')
    friends_received = association_proxy('requested_friend_confs', 'receiving_friend')

    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)
        self.alternative_id = self.id

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

    def recently_online(self):
        return self.is_online or self.last_seen > datetime.utcnow() - timedelta(minutes=1)
Пример #17
0
class GameBase(db.Model):
    __tablename__ = 'games_all'

    id = db.Column(db.Integer, primary_key=True)
    variant = db.Column(db.String(50))
    __mapper_args__ = {'polymorphic_on': variant}

    hashid = db.Column(db.String(10), unique=True)
    bo_sets = db.Column(db.Integer, nullable=False)
    bo_legs = db.Column(db.Integer, nullable=False)
    two_clear_legs = db.Column(db.Boolean)
    p1_sets = db.Column(db.Integer)
    p2_sets = db.Column(db.Integer)
    p1_legs = db.Column(db.Integer)
    p2_legs = db.Column(db.Integer)
    p1_score = db.Column(db.Integer)
    p2_score = db.Column(db.Integer)
    p1_next_turn = db.Column(db.Boolean)
    closest_to_bull = db.Column(db.Boolean)
    closest_to_bull_json = db.Column(db.JSON)
    status = db.Column(db.String(20), index=True)
    match_json = db.Column(db.JSON)
    begin = db.Column(db.DateTime)
    end = db.Column(db.DateTime)
    opponent_type = db.Column(db.String(10))
    public_challenge = db.Column(db.Boolean)
    score_input_delay = db.Column(db.Integer, default=0)
    webcam = db.Column(db.Boolean, default=False)
    jitsi_hashid = db.Column(db.String(10), unique=True)
    jitsi_public_server = db.Column(db.Boolean, default=False)
    tournament_stage_game_id = db.Column(db.Integer, default=None)
    tournament_stage_game_bracket_id = db.Column(db.Integer, default=None)

    @declared_attr
    def tournament(cls):
        return db.Column(db.String(10),
                         db.ForeignKey('tournaments.hashid'),
                         default=None)

    @declared_attr
    def tournament_round_id(cls):
        return db.Column(db.Integer,
                         db.ForeignKey('tournament_stage_rounds.id'),
                         default=None)

    @declared_attr
    def tournament_round(cls):
        return db.relationship('TournamentStageRound', back_populates='games')

    @declared_attr
    def player1(cls):
        return db.Column(db.Integer, db.ForeignKey('users.id'), index=True)

    @declared_attr
    def player2(cls):
        return db.Column(db.Integer, db.ForeignKey('users.id'), index=True)

    def set_hashid(self):
        self.hashid = secrets.token_urlsafe(8)[:8]

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
Пример #18
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(25), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password = db.Column(db.String(128))
    active = db.Column(db.Boolean)
    avatar = db.Column(db.String(15), default=None)
    last_seen = db.Column(db.DateTime, default=datetime.utcnow)
    last_seen_ingame = db.Column(db.DateTime, default=datetime.utcnow)
    is_online = db.Column(db.Boolean, default=False)
    active_sessions = db.Column(db.Integer, default=0)
    status = db.Column(db.String(15), default='online')
    caller = db.Column(db.String(20), default='default')
    cpu_delay = db.Column(db.Integer, default=0)
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    requested_friend_reqs = db.relationship(
        'FriendshipRequest',
        foreign_keys='FriendshipRequest.requesting_user_id',
        backref='requesting_user')
    received_friend_reqs = db.relationship(
        'FriendshipRequest',
        foreign_keys='FriendshipRequest.receiving_user_id',
        backref='receiving_user')
    aspiring_friends = association_proxy('received_friend_reqs',
                                         'requesting_user')
    desired_friends = association_proxy('requested_friend_reqs',
                                        'receiving_user')

    requested_friend_confs = db.relationship(
        'Friendship',
        foreign_keys='Friendship.user1_id',
        backref='requesting_friend')
    received_friend_confs = db.relationship('Friendship',
                                            foreign_keys='Friendship.user2_id',
                                            backref='receiving_friend')
    friends_requested = association_proxy('received_friend_confs',
                                          'requesting_friend')
    friends_received = association_proxy('requested_friend_confs',
                                         'receiving_friend')

    # used to save the settings of a user during a game (e.g. hide statistics)
    # ingame_settings
    ingame_keypad_visibility = db.Column(db.Boolean, default=True)
    # keypad_position -> 0:default ; 1:full screen
    ingame_keypad_position = db.Column(db.Integer, default=0)
    ingame_statistics_visibility = db.Column(db.Boolean, default=True)
    # streamoverlay -> False:normal theme ; True:streamoverlay
    ingame_streamoverlay = db.Column(db.Boolean, default=False)
    ingame_caller_mute = db.Column(db.Boolean, default=False)

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

    def ping(self):
        self.last_seen = datetime.utcnow()
        last_online = self.is_online
        self.is_online = True
        db.session.commit()
        return last_online != self.is_online

    def recently_online(self):
        return self.is_online or self.last_seen > datetime.utcnow(
        ) - timedelta(minutes=1)
Пример #19
0
class Game(GameBase):
    __tablename__ = 'games'
    type = db.Column(db.Integer)
    in_mode = db.Column(db.String(15))
    out_mode = db.Column(db.String(15))
Пример #20
0
class Caller(db.Model):
    __tablename__ = 'callers'
    name = db.Column(db.String(30), primary_key=True)
    display_name = db.Column(db.String(50), default=None)
Пример #21
0
class Role(db.Model, RoleMixin):
    __tablename__ = 'roles'
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))
Пример #22
0
class StreamGame(db.Model):
    __tablename__ = 'stream_game'
    user = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True)
    hashid = db.Column(db.String(10), primary_key=True)
    jitsi_hashid = db.Column(db.String(10))
Пример #23
0
 def tournament(cls):
     return db.Column(db.String(10),
                      db.ForeignKey('tournaments.hashid'),
                      default=None)