예제 #1
0
파일: models.py 프로젝트: f4814/lamon
class UserRoles(db.Model):
    """ Many-to-many mapper between :class:`User` and :class:`Role` """
    __tabelname__ = 'user_roles'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer(),
                        db.ForeignKey('users.id', ondelete='CASCADE'))
    role_id = db.Column(db.Integer(),
                        db.ForeignKey('roles.id', ondelete='CASCADE'))
예제 #2
0
파일: models.py 프로젝트: f4814/lamon
class Event(db.Model):
    """ Events are used log keep a log of things happening. This includes events
    on watched servers (scores, kills), server events (unavailable) and
    watcher events (started, stopped).

    :param type: An :class:`EventType` specifies how to handle this event
    :param time: Time the event occurred
    :param info: Additional info. Changes with :attr:`type`
    :param watcher: Watcher the event occurred in (If any)
    :param game: Game the event occured in (If any)
    :param user: User connected to the event (If any)
    """
    __tablename__ = 'events'

    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.Integer)
    time = db.Column(DateTime())
    info = db.Column(db.String)

    watcherID = db.Column(db.Integer, db.ForeignKey('watchers.id'))
    watcher = db.relationship('Watcher', back_populates='events')

    gameID = db.Column(db.Integer, db.ForeignKey('games.id'))
    game = db.relationship('Game', back_populates='events')

    userID = db.Column(db.Integer, db.ForeignKey('users.id'))
    user = db.relationship('User', back_populates='events')

    def __init__(self, type=None, **kwargs):
        super().__init__(type=int(type), **kwargs)

    def __str__(self):
        msg = str(EventType(self.type)) + ": "

        if self.watcherID is not None:
            msg += f'Watcher = {self.watcher}; '

        if self.gameID is not None:
            msg += f'Game = {self.game}; '

        if self.userID is not None:
            msg += f'User = {self.user}; '

        if self.info is not None:
            msg += f'Info = {self.info}'

        return msg
예제 #3
0
파일: models.py 프로젝트: f4814/lamon
class Nickname(db.Model):
    """ The nickname of a user in a game

    :param nick: Nickname
    :param user: Associated user
    :param game: Associated game
    """
    __tablename__ = 'nicknames'

    id = db.Column(db.Integer, primary_key=True)
    nick = db.Column(db.String)

    userID = db.Column(db.Integer, db.ForeignKey('users.id',
                                                 ondelete='CASCADE'))
    user = db.relationship('User', back_populates='nicknames')

    gameID = db.Column(db.Integer, db.ForeignKey('games.id',
                                                 ondelete='CASCADE'))
    game = db.relationship('Game', back_populates='nicknames')

    def __repr__(self):
        return f'{self.user} is {self.nick} in {self.game}'
예제 #4
0
파일: models.py 프로젝트: f4814/lamon
class WatcherConfig(db.Model):
    """ A key value pair in a :class:`Watcher` configuration

    :param watcher: Associated watcher
    :param key: Key
    :param value: Value
    """
    __tablename__ = 'watcherconfig'

    id = db.Column(db.Integer, primary_key=True)

    watcherID = db.Column(db.Integer, db.ForeignKey('watchers.id'))
    watcher = db.relationship('Watcher', back_populates='config')

    key = db.Column(db.String)
    value = db.Column(db.String)

    def __repr__(self):
        return self.key + ": " + self.value
예제 #5
0
파일: models.py 프로젝트: f4814/lamon
class Watcher(db.Model):
    """ A Watcher is a process keeping track of one or more gameservers

    :param threadClass: Implementation of the process
    :param config: Configuration values the process needs (like server ip)
    :param info: Description of the watcher
    :param events: Events occured in the watcher
    :param game: Game watched by the watcher
    """
    __tablename__ = 'watchers'

    id = db.Column(db.Integer, primary_key=True)
    threadClass = db.Column(db.String)
    config = db.relationship('WatcherConfig', back_populates='watcher')
    info = db.Column(db.String)

    events = db.relationship('Event', back_populates='watcher')

    gameID = db.Column(db.Integer, db.ForeignKey('games.id'))
    game = db.relationship('Game', back_populates='watchers')

    def __repr__(self):
        return f'{self.game} ({self.info})'