Exemple #1
0
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'))
Exemple #2
0
class Role(db.Model):
    """ A user role on the system

    :param name: Name of the role
    """
    __tablename__ = 'roles'

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

    def __repr__(self):
        return self.name
Exemple #3
0
class Game(db.Model):
    """ A game or gamemode played by the users

    :param name: Name of the game, can be anything
    :param nicknames: Nicknames registered for this game
    :param events: Events in the Game
    :param watchers: Watchers watching the game
    """
    __tablename__ = 'games'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True)
    nicknames = db.relationship('Nickname', back_populates='game')
    events = db.relationship('Event', back_populates='game')
    watchers = db.relationship('Watcher', back_populates='game')

    def __repr__(self):
        return self.name
Exemple #4
0
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
Exemple #5
0
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}'
Exemple #6
0
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})'
Exemple #7
0
class User(db.Model, UserMixin):
    """ A User

    :param username: Username to authenticate with lamon
    :param password: Hashed password
    :param nicknames: :class:`Nickname` s of the User
    :param events: Events concerning the user (like scores, joins, etc.)
    :param roles: System roles of the user
    """
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(255))
    is_enabled = True

    nicknames = db.relationship('Nickname', back_populates='user')
    events = db.relationship('Event', back_populates='user')
    roles = db.relationship('Role',
                            secondary='user_roles',
                            backref=db.backref('users', lazy='dynamic'))

    def __repr__(self):
        return self.username
Exemple #8
0
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