1
This commit is contained in:
parent
8a72fdfb2e
commit
f95e431b49
@ -46,11 +46,9 @@ CREATE TABLE `user` (
|
||||
`kills` int(11) NOT NULL COMMENT '所有击杀',
|
||||
`harm` int(11) NOT NULL COMMENT '所有伤害',
|
||||
`score` bigint NOT NULL COMMENT '积分',
|
||||
`alive_time` int(11) NOT NULL COMMENT '所有生存时间',
|
||||
`coin_num` bigint NOT NULL COMMENT '角色金币',
|
||||
`diamond_num` bigint NOT NULL COMMENT '角色钻石',
|
||||
`kill_his` int(11) NOT NULL COMMENT '最高击杀',
|
||||
`alive_time_his` int(11) NOT NULL COMMENT '最长生存时间',
|
||||
`harm_his` int(11) NOT NULL COMMENT '最高伤害',
|
||||
`create_time` int(11) NOT NULL COMMENT '创建时间',
|
||||
`modify_time` int(11) NOT NULL COMMENT '修改时间',
|
||||
|
@ -27,21 +27,9 @@ else:
|
||||
def info(msg):
|
||||
print(str(datetime.datetime.now()) + '[INFO] ' + msg)
|
||||
|
||||
def take_kills(elem):
|
||||
def take_score(elem):
|
||||
return elem[3]
|
||||
|
||||
def take_alive_time(elem):
|
||||
return elem[4]
|
||||
|
||||
def take_harms(elem):
|
||||
return elem[5]
|
||||
|
||||
def take_win_times(elem):
|
||||
return elem[6]
|
||||
|
||||
def take_game_times(elem):
|
||||
return elem[7]
|
||||
|
||||
def safeDiv(a, b):
|
||||
if b == 0:
|
||||
return 0
|
||||
@ -71,35 +59,15 @@ def readMysqlData(rushtime):
|
||||
charset = 'utf8'
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time, harm, win_times, game_times FROM user;')
|
||||
cursor.execute('SELECT accountid, user_name, avatar_url, score FROM user;')
|
||||
for row in cursor:
|
||||
kill = safeDiv(row[3], row[7])
|
||||
alive_time = safeDiv(row[4], row[7])
|
||||
harm = safeDiv(row[5], row[7])
|
||||
win_times = safeDiv(row[6], row[7])
|
||||
array.append((row[0], row[1].decode('utf-8'), row[2], kill, alive_time, harm, win_times, row[6]))
|
||||
score = row[3]
|
||||
array.append((row[0], row[1].decode('utf-8'), row[2], score))
|
||||
|
||||
r = getRedis()
|
||||
array.sort(key=take_kills, reverse=True)
|
||||
kill_rank = json.dumps(array)
|
||||
r.set("game2002api: kill_rank", kill_rank)
|
||||
|
||||
array.sort(key=take_alive_time, reverse=True)
|
||||
alive_rank = json.dumps(array)
|
||||
r.set("game2002api: alive_rank", alive_rank)
|
||||
|
||||
array.sort(key=take_harms, reverse=True)
|
||||
harm_rank = json.dumps(array)
|
||||
r.set("game2002api: harm_rank", harm_rank)
|
||||
|
||||
array.sort(key=take_win_times, reverse=True)
|
||||
rate_rank = json.dumps(array)
|
||||
r.set("game2002api: rate_rank", rate_rank)
|
||||
|
||||
array.sort(key=take_game_times, reverse=True)
|
||||
|
||||
win_rank = json.dumps(array)
|
||||
r.set("game2002api: win_rank", win_rank)
|
||||
array.sort(key=take_score, reverse=True)
|
||||
score_rank = json.dumps(array)
|
||||
r.set("game2002api: score_rank", score_rank)
|
||||
|
||||
tornado.ioloop.IOLoop.current().call_later(rushtime,
|
||||
lambda : readMysqlData(rushtime)
|
||||
|
@ -10,14 +10,14 @@ class RankController{
|
||||
'port' => $mysql_conf['port'],
|
||||
'user' => $mysql_conf['user'],
|
||||
'passwd' => $mysql_conf['passwd'],
|
||||
'dbname' => 'gamedb2001_' . $mysql_conf['instance_id']
|
||||
'dbname' => 'gamedb2002_' . $mysql_conf['instance_id']
|
||||
));
|
||||
return $conn;
|
||||
}
|
||||
|
||||
protected function getRedis()
|
||||
{
|
||||
$key = 'game2001api';
|
||||
$key = 'game2002api';
|
||||
$redis_conf = getRedisConfig($key);
|
||||
$r = new phpcommon\Redis(array(
|
||||
'host' => $redis_conf['host'],
|
||||
@ -41,19 +41,11 @@ class RankController{
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||
return;
|
||||
}
|
||||
$kill_list = array();
|
||||
$kill_rank = 0;
|
||||
$alive_list = array();
|
||||
$alive_rank = 0;
|
||||
$harm_list = array();
|
||||
$harm_rank = 0;
|
||||
$rate_list = array();
|
||||
$rate_rank = 0;
|
||||
$win_list = array();
|
||||
$win_rank = 0;
|
||||
$score_list = array();
|
||||
$score_rank = 0;
|
||||
$user_list = array();
|
||||
//个人信息
|
||||
$row = $conn->execQueryOne('SELECT user_name, avatar_url, kills, alive_time, harm, win_times, game_times FROM user ' .
|
||||
$row = $conn->execQueryOne('SELECT user_name, avatar_url, score FROM user ' .
|
||||
' WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id
|
||||
@ -63,131 +55,27 @@ class RankController{
|
||||
'account_id' => $account_id,
|
||||
'name' => $row['user_name'],
|
||||
'avatar_url' => $row['avatar_url'],
|
||||
'kill' => phpcommon\safediv($row['kills'], $row['game_times']),
|
||||
'alive'=> phpcommon\safediv($row['alive_time'], $row['game_times']),
|
||||
'harm' => phpcommon\safediv($row['harm'], $row['game_times']),
|
||||
'win_rate' => phpcommon\safediv($row['win_times'], $row['game_times']),
|
||||
'win_game' => $row['win_times']
|
||||
'score' => $row['score']
|
||||
));
|
||||
}
|
||||
|
||||
//击杀榜
|
||||
//积分榜
|
||||
$r = $this->getRedis();
|
||||
$kill_rank_db = $r->get("game2001api: kill_rank");
|
||||
$kill_db = json_decode($kill_rank_db);
|
||||
$score_rank_db = $r->get("game2002api: score_rank");
|
||||
$score_db = json_decode($score_rank_db);
|
||||
$i = 0;
|
||||
foreach ($kill_db as $kill) {
|
||||
foreach ($score_db as $score) {
|
||||
if ($i > 49) {
|
||||
break;
|
||||
}
|
||||
if ($kill_db[$i][0] == $account_id) {
|
||||
$kill_rank = $i + 1;
|
||||
if ($score_db[$i][0] == $account_id) {
|
||||
$score_rank = $i + 1;
|
||||
}
|
||||
array_push($kill_list, array(
|
||||
'account_id' => $kill_db[$i][0],
|
||||
'name' => $kill_db[$i][1],
|
||||
'avatar_url' => $kill_db[$i][2],
|
||||
'kill' => $kill_db[$i][3],
|
||||
'alive'=> $kill_db[$i][4],
|
||||
'harm' => $kill_db[$i][5],
|
||||
'win_rate' => $kill_db[$i][6],
|
||||
'win_game' => $kill_db[$i][7]
|
||||
));
|
||||
$i++;
|
||||
}
|
||||
|
||||
//生存榜
|
||||
$alive_rank_db = $r->get("game2001api: alive_rank");
|
||||
$alive_db = json_decode($alive_rank_db);
|
||||
$i = 0;
|
||||
foreach ($alive_db as $alive) {
|
||||
if ($i > 49) {
|
||||
break;
|
||||
}
|
||||
if ($alive_db[$i][0] == $account_id) {
|
||||
$alive_rank = $i + 1;
|
||||
}
|
||||
array_push($alive_list, array(
|
||||
'account_id' => $alive_db[$i][0],
|
||||
'name' => $alive_db[$i][1],
|
||||
'avatar_url' => $alive_db[$i][2],
|
||||
'kill' => $alive_db[$i][3],
|
||||
'alive'=> $alive_db[$i][4],
|
||||
'harm' => $alive_db[$i][5],
|
||||
'win_rate' => $alive_db[$i][6],
|
||||
'win_game' => $alive_db[$i][7]
|
||||
));
|
||||
$i++;
|
||||
}
|
||||
|
||||
//伤害榜
|
||||
$harm_rank_db = $r->get("game2001api: harm_rank");
|
||||
$harm_db = json_decode($harm_rank_db);
|
||||
$i = 0;
|
||||
foreach ($harm_db as $harm) {
|
||||
if ($i > 49) {
|
||||
break;
|
||||
}
|
||||
if ($harm_db[$i][0] == $account_id) {
|
||||
$harm_rank = $i + 1;
|
||||
}
|
||||
array_push($harm_list, array(
|
||||
'account_id' => $harm_db[$i][0],
|
||||
'name' => $harm_db[$i][1],
|
||||
'avatar_url' => $harm_db[$i][2],
|
||||
'kill' => $harm_db[$i][3],
|
||||
'alive'=> $harm_db[$i][4],
|
||||
'harm' => $harm_db[$i][5],
|
||||
'win_rate' => $harm_db[$i][6],
|
||||
'win_game' => $harm_db[$i][7]
|
||||
));
|
||||
$i++;
|
||||
}
|
||||
|
||||
//胜率榜
|
||||
$rate_rank_db = $r->get("game2001api: rate_rank");
|
||||
$rate_db = json_decode($rate_rank_db);
|
||||
$i = 0;
|
||||
foreach ($rate_db as $rate) {
|
||||
if ($i > 49) {
|
||||
break;
|
||||
}
|
||||
if ($rate_db[$i][0] == $account_id) {
|
||||
$rate_rank = $i + 1;
|
||||
}
|
||||
array_push($rate_list, array(
|
||||
'account_id' => $rate_db[$i][0],
|
||||
'name' => $rate_db[$i][1],
|
||||
'avatar_url' => $rate_db[$i][2],
|
||||
'kill' => $rate_db[$i][3],
|
||||
'alive'=> $rate_db[$i][4],
|
||||
'harm' => $rate_db[$i][5],
|
||||
'win_rate' => $rate_db[$i][6],
|
||||
'win_game' => $rate_db[$i][7]
|
||||
));
|
||||
$i++;
|
||||
}
|
||||
|
||||
//胜场榜
|
||||
$win_rank_db = $r->get("game2001api: win_rank");
|
||||
$win_db = json_decode($win_rank_db);
|
||||
$i = 0;
|
||||
foreach ($win_db as $win) {
|
||||
if ($i > 49) {
|
||||
break;
|
||||
}
|
||||
if ($win_db[$i][0] == $account_id) {
|
||||
$win_rank = $i + 1;
|
||||
}
|
||||
array_push($win_list, array(
|
||||
'account_id' => $win_db[$i][0],
|
||||
'name' => $win_db[$i][1],
|
||||
'avatar_url' => $win_db[$i][2],
|
||||
'kill' => $win_db[$i][3],
|
||||
'alive'=> $win_db[$i][4],
|
||||
'harm' => $win_db[$i][5],
|
||||
'win_rate' => $win_db[$i][6],
|
||||
'win_game' => $win_db[$i][7]
|
||||
array_push($score_list, array(
|
||||
'account_id' => $score_db[$i][0],
|
||||
'name' => $score_db[$i][1],
|
||||
'avatar_url' => $score_db[$i][2],
|
||||
'score' => $score_db[$i][3],
|
||||
));
|
||||
$i++;
|
||||
}
|
||||
@ -196,16 +84,8 @@ class RankController{
|
||||
'errcode' => 0,
|
||||
'errmsg' => "",
|
||||
'user_list' => $user_list,
|
||||
'kill_rank' => $kill_rank,
|
||||
'kill_list' => $kill_list,
|
||||
'alive_rank' => $alive_rank,
|
||||
'alive_list' => $alive_list,
|
||||
'harm_rank' => $harm_rank,
|
||||
'harm_list' => $harm_list,
|
||||
'rate_rank' => $rate_rank,
|
||||
'rate_list' => $rate_list,
|
||||
'win_rank' => $win_rank,
|
||||
'win_list' => $win_list
|
||||
'score_rank' => $score_rank,
|
||||
'score_list' => $score_list,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -83,9 +83,9 @@ class RoleController{
|
||||
':accountid' => $account_id
|
||||
));
|
||||
if (!$row) {
|
||||
$ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, game_times, win_times, kills, harm, score, alive_time, coin_num, diamond_num, kill_his, alive_time_his, harm_his, create_time, modify_time, first_fight, collect_status, keys_num, battle_re_times, shop_flush_times, kefu_status, free_getbox) ' .
|
||||
' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0) ' .
|
||||
' ON DUPLICATE KEY UPDATE accountid=:accountid, user_name=:user_name, avatar_url=:avatar_url, game_times=0, win_times=0, kills=0, harm=0, score=0, alive_time=0, coin_num=0, diamond_num=0, kill_his=0, alive_time_his=0, harm_his=0, modify_time=:modify_time, first_fight=0, collect_status=0, keys_num=0, battle_re_times=0, shop_flush_times=0, kefu_status=0, free_getbox=0;',
|
||||
$ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, game_times, win_times, kills, harm, score, coin_num, diamond_num, kill_his, harm_his, create_time, modify_time, first_fight, collect_status, keys_num, battle_re_times, shop_flush_times, kefu_status, free_getbox) ' .
|
||||
' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 0, 0, 0, create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0) ' .
|
||||
' ON DUPLICATE KEY UPDATE accountid=:accountid, user_name=:user_name, avatar_url=:avatar_url, game_times=0, win_times=0, kills=0, harm=0, score=0, coin_num=0, diamond_num=0, kill_his=0, harm_his=0, modify_time=:modify_time, first_fight=0, collect_status=0, keys_num=0, battle_re_times=0, shop_flush_times=0, kefu_status=0, free_getbox=0;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
':user_name' => $user_name,
|
||||
@ -107,7 +107,6 @@ class RoleController{
|
||||
'high_harm' => 0,
|
||||
'harm' => 0,
|
||||
'score' => 0,
|
||||
'alive_time' => 0,
|
||||
'coin_num' => 0,
|
||||
'first_fight' => 0,
|
||||
'collect_status' => 0,
|
||||
@ -127,7 +126,6 @@ class RoleController{
|
||||
'high_harm' => $row['harm_his'],
|
||||
'harm' => $row['harm'],
|
||||
'score' => $row['score'],
|
||||
'alive_time' => $row['alive_time'],
|
||||
'coin_num' => $row['coin_num'],
|
||||
'first_fight' => $row['first_fight'],
|
||||
'collect_status' => $row['collect_status'],
|
||||
@ -156,7 +154,6 @@ class RoleController{
|
||||
$rank = $_REQUEST['rank']; //排名
|
||||
$kills = $_REQUEST['kills']; //击杀数
|
||||
$harm = $_REQUEST['harm']; //伤害
|
||||
$alive_time = $_REQUEST['alive_time']; //存活时间
|
||||
$skill = $_REQUEST['skill']; //技能释放数
|
||||
$tank1_kill = $_REQUEST['tank1_kill']; //坦克1击杀数
|
||||
$tank2_kill = $_REQUEST['tank2_kill']; //坦克2击杀数
|
||||
@ -164,7 +161,6 @@ class RoleController{
|
||||
$rescue_member = $_REQUEST['rescue_member']; //救起队友次数
|
||||
$kill_his = $kills;
|
||||
$harm_his = $harm;
|
||||
$alive_time_his = $alive_time;
|
||||
$coin_num = $_REQUEST['coin_num']; //金币
|
||||
$score = $_REQUEST['score']; //积分
|
||||
|
||||
@ -192,10 +188,7 @@ class RoleController{
|
||||
if ($rank == 1) {
|
||||
$row['win_times']++;
|
||||
}
|
||||
if ($alive_time_his < $row['alive_time_his']) {
|
||||
$alive_time_his = $row['alive_time_his'];
|
||||
}
|
||||
$ret = $conn->execScript('UPDATE user SET game_times=:game_times, win_times=:win_times, kills=:kills, harm=:harm, add_HP=:add_HP, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, score=:score, coin_num=:coin_num, modify_time=:modify_time, first_fight=1 ' .
|
||||
$ret = $conn->execScript('UPDATE user SET game_times=:game_times, win_times=:win_times, kills=:kills, harm=:harm, add_HP=:add_HP, kill_his=:kill_his, harm_his=:harm_his, score=:score, coin_num=:coin_num, modify_time=:modify_time, first_fight=1 ' .
|
||||
' WHERE accountid=:accountid;',
|
||||
array(
|
||||
':game_times' => $row['game_times'] + 1,
|
||||
@ -205,8 +198,6 @@ class RoleController{
|
||||
':harm_his' => $harm_his,
|
||||
':harm' => $row['harm'] + $harm,
|
||||
':add_HP' => $row['add_HP'] + $add_HP,
|
||||
':alive_time' => $row['alive_time'] + $alive_time,
|
||||
':alive_time_his' => $alive_time_his,
|
||||
':accountid' => $account_id,
|
||||
':coin_num' => $row['coin_num'] + $coin_num,
|
||||
':score' => $row['score'] + $score,
|
||||
@ -218,9 +209,9 @@ class RoleController{
|
||||
}
|
||||
|
||||
//插入历史记录
|
||||
$ret = $conn->execScript('INSERT INTO history_record(accountid, room_uuid, map_id, map_tpl_name, map_name, game_time, rank, kills, harms, hurts, alive_time, coin, status, create_time, modify_time) ' .
|
||||
$ret = $conn->execScript('INSERT INTO history_record(accountid, room_uuid, map_id, map_tpl_name, map_name, game_time, rank, kills, harms, hurts, coin, status, create_time, modify_time) ' .
|
||||
' VALUES(:accountid, :room_uuid, :map_id, :map_tpl_name, :map_name, :game_time, :rank, :kills, :harms, :hurts, :alive_time, :coin, 0, :create_time, :modify_time) ' .
|
||||
' ON DUPLICATE KEY UPDATE accountid=:accountid, room_uuid=:room_uuid, map_id=:map_id, map_tpl_name=:map_tpl_name, map_name=:map_name, game_time=:game_time, rank=:rank, kills=:kills, harms=:harms, hurts=:hurts, alive_time=:alive_time, coin=:coin, status=0, modify_time=:modify_time;',
|
||||
' ON DUPLICATE KEY UPDATE accountid=:accountid, room_uuid=:room_uuid, map_id=:map_id, map_tpl_name=:map_tpl_name, map_name=:map_name, game_time=:game_time, rank=:rank, kills=:kills, harms=:harms, hurts=:hurts, coin=:coin, status=0, modify_time=:modify_time;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
':room_uuid' => $room_uuid,
|
||||
@ -232,7 +223,6 @@ class RoleController{
|
||||
':kills' => $kills,
|
||||
':harms' => $harm,
|
||||
':hurts' => $hurt,
|
||||
':alive_time' => $alive_time,
|
||||
':coin' => $coin_num,
|
||||
':create_time' => time(),
|
||||
':modify_time' => time()
|
||||
@ -301,7 +291,6 @@ class RoleController{
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
'kill_his' => $kill_his,
|
||||
'alive_time_his' => $alive_time_his,
|
||||
'harm_his' => $harm_his,
|
||||
'extra_drop' => $extra_drop
|
||||
));
|
||||
@ -339,7 +328,6 @@ class RoleController{
|
||||
'kills' => $row['kills'],
|
||||
'harms' => $row['harms'],
|
||||
'hurts' => $row['hurts'],
|
||||
'alive_time' => $row['alive_time']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user