示例#1
0
def get_server_db_connect(sid=None, server_id=None): 
    if sid:
        server = Server.load(id=sid)
    else:
        server = Server.load(server_id=server_id)
        
    db_connect = server.db_connect
    return str_to_dbconfig(db_connect)
示例#2
0
def get_server_db_connect(sid=None, server_id=None):
    if sid:
        server = Server.load(id=sid)
    else:
        server = Server.load(server_id=server_id)

    db_connect = server.db_connect
    return str_to_dbconfig(db_connect)
示例#3
0
 def get_server_list(self):
     servers = []
     if self.server_id is not None:
         server = Server.load(server_id=self.server_id)
         servers.append(server)
         return servers
     else:
         return server_business.get_all_server_list()
示例#4
0
 def get_server_list(self):
     servers = []
     if self.server_id is not None:
         server = Server.load(server_id = self.server_id)
         servers.append(server)
         return servers
     else:
         return server_business.get_all_server_list()
示例#5
0
def get_server_list(server_id):
        servers = []
#         servers = []
#         s1 = Server()
#         s1.db_connect = "server=118.244.198.81,3306;database=ldsg_h10;user=ldsg_h10_op;pwd=3e454ss3kd40e24;"
#         s1.server_id = 1
#         s2 = Server()
#         s2.db_connect = "server=118.244.198.86,3306;database=ldsg_h11;user=ldsg_h11_rd;pwd=e727484b3251bc;"
#         s2.server_id = 2
#         servers.append(s1)
#         servers.append(s2)
        if server_id != "all":
            server = Server.load(server_id = server_id)
            servers.append(server)
            return servers
        else:
            return server_business.get_all_server_list()
示例#6
0
def get_server_list(server_id):
    servers = []
    #         servers = []
    #         s1 = Server()
    #         s1.db_connect = "server=118.244.198.81,3306;database=ldsg_h10;user=ldsg_h10_op;pwd=3e454ss3kd40e24;"
    #         s1.server_id = 1
    #         s2 = Server()
    #         s2.db_connect = "server=118.244.198.86,3306;database=ldsg_h11;user=ldsg_h11_rd;pwd=e727484b3251bc;"
    #         s2.server_id = 2
    #         servers.append(s1)
    #         servers.append(s2)
    if server_id != "all":
        server = Server.load(server_id=server_id)
        servers.append(server)
        return servers
    else:
        return server_business.get_all_server_list()
示例#7
0
def add_forces(server_id, forces_info):
    server = Server.load(server_id=server_id)
    try:
        if server.server_host.index(':') > 0:
            url = "http://%s/gameApi/modifyForcesTimes.do?" % server.server_host
    except:
        url = "http://%s:8088/gameApi/modifyForcesTimes.do?" % server.server_host
    logging.info(url)
    #url = "http://localhost:8088/gameApi/modifyForcesTimes.do?"
    params = {}
    for k, v in forces_info.iteritems():
        if isbasestring(v):
            params[k] = v.encode("utf8")
        else:
            params[k] = v
    url = url + urllib.urlencode(params)
    data = None
    try:
        data = urllib.urlopen(url).read()
    except Exception, e:
        logging.info(e)
示例#8
0
def data_sync(server_id, sync_type=1, table=None, sqls=[]):
    """数据同步"
    @param sync_type: 同步类型1:修改 ;2:新增 ;3:删除;4:全表同步 
    @param table:同步的表
    @param sqls:同步的sql
    """
    server = Server.load(server_id=server_id)
    host = server.server_host

    path = "/gameApi/dataSync.do"
    logging.debug("host:[%s], path[%s]" % (host, path))
    data = {"syncType": sync_type, "table": table, "sqls": json.dumps(sqls)}

    post = Post(data, host, path, port=8088)
    content = post.submit(result_keyword=None, get_content=True, debug=True)
    try:
        info = json.loads(content)
        return info.get("rc", 3000) == 1000
    except:
        logging.debug("bad json format:[%s]" % content)
        return False
def data_sync(server_id, sync_type=1, table=None, sqls=[]):
    """数据同步"
    @param sync_type: 同步类型1:修改 ;2:新增 ;3:删除;4:全表同步 
    @param table:同步的表
    @param sqls:同步的sql
    """
    server = Server.load(server_id=server_id)
    host = server.server_host

    path = "/gameApi/dataSync.do"
    logging.debug("host:[%s], path[%s]" % (host, path))
    data = {"syncType": sync_type, "table": table, "sqls": json.dumps(sqls)}

    post = Post(data, host, path, port=8088)
    content = post.submit(result_keyword=None, get_content=True, debug=True)
    try:
        info = json.loads(content)
        return info.get("rc", 3000) == 1000
    except:
        logging.debug("bad json format:[%s]" % content)
        return False
示例#10
0
def add_server(server_info):
    server = Server()
    for k, v in server_info.iteritems():
        setattr(server, k, v)
    server.persist()
示例#11
0
def system_mail_approve(system_mail_id, approve_user, approve=False):
    system_mail = get_system_mail(system_mail_id)
    if system_mail.status != 0:
        return
    else:
        system_mail.status = 3
        system_mail.persist()
    system_mail.approve_user = approve_user
    system_mail.approve_time = datetime.now()
    result_map = {}
    if approve:
        server_ids = system_mail.server_ids.split(",")
        send_server_ids = []
        for server_id in server_ids:
            mail_info = {}
            mail_info["title"] = system_mail.title
            mail_info["content"] = system_mail.content
            mail_info["toolIds"] = system_mail.tool_ids
            mail_info["lodoIds"] = system_mail.lodo_ids
            mail_info["target"] = system_mail.target
            mail_info["sourceId"] = system_mail.system_mail_id
            if system_mail.date:
                mail_info["date"] = int(
                    time.mktime(system_mail.date.timetuple())) * 1000
            else:
                mail_info["date"] = int(time.time())

            mail_info["partner"] = system_mail.partner_id
            server = Server.load(server_id=server_id)
            url = "http://" + server.server_host + ":8088/gameApi/sendMail.do?"
            params = {}
            for k, v in mail_info.iteritems():
                if isbasestring(v):
                    params[k] = v.encode("utf8")
                else:
                    params[k] = v
            url = url + urllib.urlencode(params)
            logging.info("server:%s,url:%s" % (server_id, url))

            result_map[server_id] = 0
            approve_info = {}
            try:
                ret_val = urllib.urlopen(url).read()
                approve_info[server_id] = ret_val
                result = json.loads(ret_val)
                if result.get("rt") == 1000:
                    send_server_ids.append(server_id)
                    result_map[server_id] = 1
                else:
                    logging.warn(u"邮件发送失败.server_id[%s], msg[%s]" %
                                 (server_id, result.get("msg")))
            except:
                approve_info[server_id] = traceback.format_exc()
                logging.error(traceback.format_exc())

        system_mail.status = 1
        system_mail.send_server_ids = ",".join(send_server_ids)
        system_mail.approve_info = json.dumps(approve_info)
    else:
        system_mail.status = 2

    system_mail.persist()

    return 1, result_map
示例#12
0
def get_server(server_id):
    return Server.load(server_id=server_id)
示例#13
0
def get_all_server_list():
    return Server.query(condition="is_del=0")
示例#14
0
def get_all_server_list():
    return Server.query(condition="is_del=0")
示例#15
0
def get_server_list(page, pagesize, server_zone):
    return Server.paging(page, pagesize, condition="is_del=0 and server_zone=%s" % server_zone, order="open_time asc")
示例#16
0
def delete_server(sid):
    server = Server()
    server.id = sid
    server.is_del = 1 
    server.persist()
示例#17
0
def add_server(server_info):
    server = Server()
    for k, v in server_info.iteritems():
        setattr(server, k, v)
    server.persist()
示例#18
0
def add_activity(server_id, activity_info):
    server = Server.load(server_id=server_id)
    url = "http://" + server.server_host + ":8088//gameApi//modifyActivity.do"
    _, ret_val = http_util.request(url, activity_info)
    return ret_val
示例#19
0
def delete_server(sid):
    server = Server()
    server.id = sid
    server.is_del = 1
    server.persist()
示例#20
0
def get_server_list(page, pagesize, server_zone):
    return Server.paging(page,
                         pagesize,
                         condition="is_del=0 and server_zone=%s" % server_zone,
                         order="open_time asc")
示例#21
0
def get_stat_server(begindate, enddate=None):
    statServerDatas = []
    if begindate == date_utils.get_date():
        statServerDate = StatServerDate(False)
        statServerDate.start()
        statServerDatas = statServerDate.statServerDatass
    elif enddate is not None:
        sql = "SELECT server_name,server_id, sum(new_register) as new_register, sum(create_user) as create_user, sum(date_active) as date_active, sum(pay_people) as pay_people, sum(pay_money) as pay_money, sum(max_online) as max_online, sum(new_user_pay) as new_user_pay\
        , sum(old_user_pay) as old_user_pay, sum(new_payer) as new_payer, sum(old_payer) as old_payer  FROM stat_server_data where stat_date>= '%s' and stat_date<='%s' group by server_id;" % (
            begindate, enddate)
        cursor = connection.cursor()
        try:
            datas = cursor.fetchall(sql)
            for data in datas:
                statServerDatas.append(data)
        finally:
            cursor.close()
    else:
        sql = "SELECT * from stat_server_data where stat_date = '%s'" % begindate
        cursor = connection.cursor()
        try:
            datas = cursor.fetchall(sql)
            for data in datas:
                statServerDatas.append(data)
        finally:
            cursor.close()
        #statServerDatas = StatServerData.query(condition="stat_date ='%s'" % begindate)

    total = 0
    statServerDatas_s = []
    for s in statServerDatas:
        if not s:
            continue
        try:
            server_id = s["server_id"]
        except:
            server_id = s.server_id
        server = Server.load(server_id=server_id)
        try:
            if server and server.is_test == 0:
                statServerDatas_s.append(s)
                total += s["pay_money"]
            if s["pay_people"] != 0 and s["date_active"] != 0:
                value = round(s["pay_people"] / (s["date_active"]), 5) * 100
                s.temp = value
            else:
                s.temp = 0
        except:
            if server and server.is_test == 0:
                total += s.pay_money
            if s.pay_money != 0 and s.date_active != 0:
                value = round(s.pay_money / (s.date_active), 5) * 100
                s.temp = value
            else:
                s.temp = 0
    stat_server_datas_map = {}
    for s in statServerDatas_s:
        if not s:
            continue
        try:
            server_id = s["server_id"]
        except:
            server_id = s.server_id
        server = Server.load(server_id=server_id)
        server_zone = server.server_zone
        server_zone_server_list = stat_server_datas_map.get(server_zone, [])
        server_zone_server_list.append(s)
        stat_server_datas_map[server_zone] = server_zone_server_list

    items = stat_server_datas_map.items()
    items.sort()
    for k, values in stat_server_datas_map.iteritems():
        try:
            server_id = s["server_id"]
            values = sorted(values,
                            cmp=lambda x, y: cmp(int(x["server_id"][1:]),
                                                 int(y["server_id"][1:])))
        except:
            values = sorted(values,
                            cmp=lambda x, y: cmp(int(x.server_id[1:]),
                                                 int(y.server_id[1:])))
        stat_server_datas_map[k] = values

    #statServerDatas_s.sort(cmp=lambda x,y:cmp(int(x.server_id[1:]), int(y.server_id[1:])))
    return stat_server_datas_map, total, server_zone_map
示例#22
0
def get_server_id_by_sid(sid):
    server = Server.load(id=sid)
    if server:
        return server.server_id
示例#23
0
def system_mail_approve(system_mail_id, approve_user, approve=False):
    system_mail = get_system_mail(system_mail_id)
    if system_mail.status != 0:
        return
    else:
        system_mail.status = 3
        system_mail.persist()
    system_mail.approve_user = approve_user
    system_mail.approve_time = datetime.now()
    result_map = {}
    if approve:
        server_ids = system_mail.server_ids.split(",")
        send_server_ids = []
        for server_id in server_ids:
            mail_info = {}
            mail_info["title"] = system_mail.title
            mail_info["content"] = system_mail.content
            mail_info["toolIds"] = system_mail.tool_ids
            mail_info["lodoIds"] = system_mail.lodo_ids
            mail_info["target"] = system_mail.target
            mail_info["sourceId"] = system_mail.system_mail_id 
            if system_mail.date:
                mail_info["date"] = int(time.mktime(system_mail.date.timetuple())) * 1000
            else:
                mail_info["date"] = int(time.time())
                
            mail_info["partner"] = system_mail.partner_id 
            server = Server.load(server_id=server_id)
            url = "http://" + server.server_host + ":8088/gameApi/sendMail.do?"
            params = {}
            for k, v in mail_info.iteritems():
                if isbasestring(v):
                    params[k] = v.encode("utf8")
                else:
                    params[k] = v
            url = url + urllib.urlencode(params)
            logging.info("server:%s,url:%s" % (server_id, url))
            
            result_map[server_id] = 0
            approve_info = {}
            try:
                ret_val = urllib.urlopen(url).read()
                approve_info[server_id] = ret_val
                result = json.loads(ret_val)
                if result.get("rt") == 1000:
                    send_server_ids.append(server_id)
                    result_map[server_id] = 1
                else:
                    logging.warn(u"邮件发送失败.server_id[%s], msg[%s]" % (server_id, result.get("msg")))
            except:
                approve_info[server_id] = traceback.format_exc()
                logging.error(traceback.format_exc())
                
                
                
        system_mail.status = 1
        system_mail.send_server_ids = ",".join(send_server_ids)
        system_mail.approve_info = json.dumps(approve_info)
    else:
        system_mail.status = 2
        
    system_mail.persist()
    
    return 1, result_map
示例#24
0
def get_server_id_by_sid(sid):
    server = Server.load(id=sid)
    if server:
        return server.server_id
def get_stat_server(begindate, enddate=None):
    statServerDatas = []
    if begindate == date_utils.get_date():
        statServerDate = StatServerDate(False)
        statServerDate.start()
        statServerDatas = statServerDate.statServerDatass
    elif enddate is not None:
        sql = (
            "SELECT server_name,server_id, sum(new_register) as new_register, sum(create_user) as create_user, sum(date_active) as date_active, sum(pay_people) as pay_people, sum(pay_money) as pay_money, sum(max_online) as max_online, sum(new_user_pay) as new_user_pay\
        , sum(old_user_pay) as old_user_pay, sum(new_payer) as new_payer, sum(old_payer) as old_payer  FROM stat_server_data where stat_date>= '%s' and stat_date<='%s' group by server_id;"
            % (begindate, enddate)
        )
        cursor = connection.cursor()
        try:
            datas = cursor.fetchall(sql)
            for data in datas:
                statServerDatas.append(data)
        finally:
            cursor.close()
    else:
        sql = "SELECT * from stat_server_data where stat_date = '%s'" % begindate
        cursor = connection.cursor()
        try:
            datas = cursor.fetchall(sql)
            for data in datas:
                statServerDatas.append(data)
        finally:
            cursor.close()
        # statServerDatas = StatServerData.query(condition="stat_date ='%s'" % begindate)

    total = 0
    statServerDatas_s = []
    for s in statServerDatas:
        if not s:
            continue
        try:
            server_id = s["server_id"]
        except:
            server_id = s.server_id
        server = Server.load(server_id=server_id)
        try:
            if server and server.is_test == 0:
                statServerDatas_s.append(s)
                total += s["pay_money"]
            if s["pay_people"] != 0 and s["date_active"] != 0:
                value = round(s["pay_people"] / (s["date_active"]), 5) * 100
                s.temp = value
            else:
                s.temp = 0
        except:
            if server and server.is_test == 0:
                total += s.pay_money
            if s.pay_money != 0 and s.date_active != 0:
                value = round(s.pay_money / (s.date_active), 5) * 100
                s.temp = value
            else:
                s.temp = 0
    stat_server_datas_map = {}
    for s in statServerDatas_s:
        if not s:
            continue
        try:
            server_id = s["server_id"]
        except:
            server_id = s.server_id
        server = Server.load(server_id=server_id)
        server_zone = server.server_zone
        server_zone_server_list = stat_server_datas_map.get(server_zone, [])
        server_zone_server_list.append(s)
        stat_server_datas_map[server_zone] = server_zone_server_list

    items = stat_server_datas_map.items()
    items.sort()
    for k, values in stat_server_datas_map.iteritems():
        try:
            server_id = s["server_id"]
            values = sorted(values, cmp=lambda x, y: cmp(int(x["server_id"][1:]), int(y["server_id"][1:])))
        except:
            values = sorted(values, cmp=lambda x, y: cmp(int(x.server_id[1:]), int(y.server_id[1:])))
        stat_server_datas_map[k] = values

    # statServerDatas_s.sort(cmp=lambda x,y:cmp(int(x.server_id[1:]), int(y.server_id[1:])))
    return stat_server_datas_map, total, server_zone_map
示例#26
0
def add_activity(server_id,activity_info):
    server = Server.load(server_id=server_id)
    url = "http://" + server.server_host + ":8088//gameApi//modifyActivity.do"
    _, ret_val = http_util.request(url, activity_info)
    return ret_val
示例#27
0
def get_server(server_id):
    return Server.load(server_id=server_id)