示例#1
0
文件: u.py 项目: hw233/twisted_zdzl
class UserLog(db.Document):
    """ 用户登录,GM LOG """
    # 用户帐号
    u = db.StringField(db_field='u')
    # 类型:1=登录, 2=GM操作
    ty = db.IntField(db_field='ty')
    # 详细
    i = db.StringField(db_field='i', required=False, allow_none=True)
    # 时间
    t = db.FloatField(db_field='t')
    # 服务器id
    st = db.StringField(db_field='st', default='zl')
示例#2
0
文件: u.py 项目: hw233/twisted_zdzl
class RenRate(db.Document):
    """ 留存率比率 """
    t = db.FloatField(db_field='t')
    r = db.FloatField(db_field='r', default=1.0)
    s = db.StringField(db_field='s', default='app_1')

    @classmethod
    def get_r(cls, t, s):
        try:
            ret = cls.query.filter(cls.t == t, cls.s == s).first()
            if ret:
                return ret.r
            return 1.0
        except:
            return 1.0

    @classmethod
    def change_r(cls, t, r, s='app_1'):
        try:
            ret = cls.query.filter(cls.t == t, cls.s == s).first()
            if ret:
                ret.r = r
                ret.s = s
                ret.save()
                return True
            ret = cls()
            ret.s = s
            ret.t = t
            ret.r = r
            ret.save()
        except:
            return False
        return True
示例#3
0
class CCount(db.Document):
    """ 综合统计 """
    # 时间
    t = db.FloatField(db_field='t')
    # 服务器
    s = db.StringField(db_field='s')
    # 创号人数
    create = db.IntField(db_field='c', allow_none=True, required=False)
    # 登录人数
    login = db.IntField(db_field='l', allow_none=True, required=False)
    # 最大在线
    max_online = db.IntField(db_field='m', allow_none=True, required=False)
    # 平均在线
    avg_online = db.IntField(db_field='a', allow_none=True, required=False)
    # 充值金额
    pay = db.IntField(db_field='p', allow_none=True, required=False)
    # 充值笔数
    paynums = db.IntField(db_field='n', allow_none=True, required=False)
    # 充值人数
    payusers = db.IntField(db_field='u', allow_none=True, required=False)
    # 新增充值人数
    newnums = db.IntField(db_field='w', allow_none=True, required=False)
    # 最大登录数pid
    max_login_pid = db.IntField(db_field='lp', allow_none=True, required=False)
    # 最大登录数uid
    max_login_uid = db.IntField(db_field='lu', allow_none=True, required=False)
    #平台
    platform = db.IntField(db_field='pf')
示例#4
0
文件: u.py 项目: hw233/twisted_zdzl
class Mongos(db.Document):
    #服务器IP
    ip = db.StringField(db_field='i',
                        required=True,
                        allow_none=False,
                        default='127.0.0.1')
    #端口
    port = db.IntField(db_field='p',
                       required=True,
                       allow_none=False,
                       default=27017)
    #本地库名
    localdatabase = db.StringField(db_field='l',
                                   required=False,
                                   allow_none=True)
    #服务器库名
    database = db.StringField(db_field='d', required=False, allow_none=True)
    #(mtype=1时记录需要备份的collections, mtype=2 时记录需要恢复的collections)
    backup = db.StringField(db_field='c', required=False, allow_none=True)
    #用户名
    username = db.StringField(db_field='u',
                              required=False,
                              allow_none=True,
                              default=None)
    #密码
    password = db.StringField(db_field='w',
                              required=False,
                              allow_none=True,
                              default=None)
    #备注
    remark = db.StringField(db_field='r', required=False, allow_none=True)
    # 服务器
    st = db.StringField(db_field='st', default='zl')
    #is drop
    is_drop = db.IntField(db_field='dr', default=1)

    _tables = db.ObjectIdField(db_field='o', allow_none=True)

    @property
    def tables(self):
        tables = SyncTables.query.get_or_404(ObjectId(self._tables))
        return tables.title

    @property
    def tables_oid(self):
        return self._tables

    @tables.setter
    def tables(self, value):
        self._tables = ObjectId(value)

    @property
    def table_names(self):
        tables = SyncTables.query.get_or_404(ObjectId(self._tables))
        return tables.names
示例#5
0
文件: u.py 项目: hw233/twisted_zdzl
class FilterPlayer(db.Document):
    """ 过滤名单 """
    # 名单
    n = db.StringField(db_field='n')
    # 类型:1=pid, 2=uid
    t = db.IntField(db_field='t')

    @classmethod
    def get_uids(cls):
        tmp = cls.query.filter(cls.t == 2)
        return [item.n for item in tmp]

    @classmethod
    def get_pids(cls):
        tmp = cls.query.filter(cls.t == 1)
        return [item.n for item in tmp]
示例#6
0
文件: u.py 项目: hw233/twisted_zdzl
class AdminUser(db.Document):
    # 角色,待激活会员
    UNACTIVE = 1
    # 角色,普通会员
    MEMBER = 100
    # 角色,网站编辑
    MODERATOR = 200
    # 角色, 测试帐号
    TEST = 210
    # 角色, 客服帐号
    CUSTOMER = 220
    # 角色,管理员
    ADMIN = 300
    # other
    OTHER = 400

    query_class = UserQuery

    username_index = Index().ascending('u').unique(drop_dups=True)

    # 登录帐号
    username = db.StringField(db_field='u', required=True, allow_none=False)
    # 密码
    _pwd = db.StringField(db_field='p', required=True, allow_none=False)
    # 昵称
    nickname = db.StringField(db_field='n',
                              required=False,
                              allow_none=True,
                              default=None)
    # 注册时间
    regdate = db.FloatField(db_field='g',
                            required=False,
                            allow_none=True,
                            default=time())
    # 最后一次登录时间
    lastlogin = db.FloatField(db_field='l',
                              required=False,
                              allow_none=True,
                              default=time())
    # 是否已经禁用
    ban = db.BoolField(db_field='b', required=False, default=False)
    # 角色
    role = db.IntField(db_field='r', required=False, default=MODERATOR)
    # 权限, index = 0:基础数据查看,1:基础数据修改,2:用户数据查看
    # 3:用户数据修发, 4:服务器备份恢复, 5:GM管理,6:角色查询, 7:数据统计
    right = db.ListField(db.IntField(),
                         db_field='i',
                         required=False,
                         default=[0, 0, 0, 0, 0, 0, 0, 0, 0])
    # 经验值
    value = db.IntField(db_field='v', required=False, default=0)
    # 性别  0:男,1:女
    sex = db.IntField(db_field='s', required=False, default=0)
    # default server
    server = db.ObjectIdField(db_field='sr',
                              required=False,
                              allow_none=True,
                              default=None)
    # 服务器组
    server_group = db.StringField(db_field='sg',
                                  required=True,
                                  allow_none=False,
                                  default="td_res")

    def __init__(self, *args, **kwargs):
        super(AdminUser, self).__init__(*args, **kwargs)

    def new_login(self):
        """ 注意,此方法会自动保存用户数据 """
        self.lastlogin = time()
        self.value += 1
        self.save()

    @cached_property
    def message(self):
        """ 用户信息辅助类 """
        return str(self.mongo_id)

    def new_msg(self, msg, *nickname):
        """ 新信息,可以批量指定用户昵称 """
        for n in nickname:
            u = AdminUser.query.filter(AdminUser.nickname == n).first()
            if u.mongo_id != self.mongo_id:
                self.message.new(u.mongo_id, msg)
        return True

    @cached_property
    def role_name(self):
        if self.role == self.UNACTIVE:
            return u'待激活'
        elif self.role == self.MEMBER:
            return u'普通会员'
        elif self.role == self.MODERATOR:
            return u'编辑'
        elif self.role == self.ADMIN:
            return u'管理员'
        elif self.role == self.OTHER:
            return u'other'
        else:
            return u'未知'

    @cached_property
    def ban_cn(self):
        if self.ban: return u'是'
        else: return u'否'

    @property
    def password(self):
        return self._pwd

    @password.setter
    def password(self, value):
        self._pwd = md5(value)

    @property
    def is_moderator(self):
        """ 是否网站编辑 """
        return self.role >= self.MODERATOR

    @property
    def is_admin(self):
        """ 是否管理员 """
        return self.role >= self.ADMIN

    @property
    def is_other(self):
        """ """
        return self.role >= self.OTHER

    @cached_property
    def provides(self):
        """ 用于登录验证提供 """
        needs = [RoleNeed('authenticated'), UserNeed(self.mongo_id)]
        if self.is_moderator:
            needs.append(RoleNeed('moderator'))
        if self.is_admin:
            needs.append(RoleNeed('admin'))
        if self.is_other:
            needs.append(RoleNeed('other'))
        return needs

    @cached_property
    def usex(self):
        """ 用户的性别-中文显示 """
        if self.sex == 0:
            return u'男'
        else:
            return u'女'

    def check_password(self, password):
        '检查密码是否一致'
        if self.password is None:
            return False
        return self.password == md5(password)
示例#7
0
文件: u.py 项目: hw233/twisted_zdzl
class SyncTables(db.Document):
    title = db.StringField(db_field='t')
    names = db.StringField(db_field='n')
    remark = db.StringField(db_field='r')
示例#8
0
文件: u.py 项目: hw233/twisted_zdzl
class Servers(db.Document):
    """ 服务器列表 """
    # 名
    name = db.StringField(db_field='n', required=False, allow_none=True)
    # ip
    ip = db.StringField(db_field='i', required=False, allow_none=True)
    # 端口
    port = db.IntField(db_field='p', required=False, allow_none=True)
    # 用户名
    username = db.StringField(db_field='u', required=False, allow_none=True)
    # 密码
    _pwd = db.StringField(db_field='w', required=False, allow_none=True)
    # GRPC端口
    gport = db.StringField(db_field='g',
                           required=True,
                           default='127.0.0.1:8001')
    # 类型, 1
    t = db.IntField(db_field='t', required=True, default=1)
    # 简繁体
    tf = db.StringField(db_field='tf', required=True, default='zh-CN')
    # 资源库
    db_res = db.StringField(db_field='r',
                            required=False,
                            allow_none=True,
                            default='td_res')
    # 用户库
    db_user = db.StringField(db_field='s',
                             required=False,
                             allow_none=True,
                             default='td')
    # 日志库
    db_log = db.StringField(db_field='l',
                            required=False,
                            allow_none=True,
                            default='td_log')
    # sid
    sid = db.StringField(db_field='sid', required=False, default='')
    # 服务器
    st = db.StringField(db_field='st', default='td_count')
    # res path
    res = db.StringField(db_field='res', default='')

    @property
    def password(self):
        return self._pwd

    @password.setter
    def password(self, value):
        self._pwd = value
示例#9
0
class BaseRetention(db.Document):
    t = db.FloatField(db_field='t')
    # 服务器
    s = db.StringField(db_field='s')
    # 留存率
    r = db.FloatField(db_field='r')