From f411fcb40473ca3b3e4f8d20e11befca1bb682ce Mon Sep 17 00:00:00 2001 From: wangwei01 Date: Tue, 14 May 2019 19:39:07 +0800 Subject: [PATCH] add rankserver --- tools/rankserver/app.py | 46 ++++++++++++++++++++++ webapp/controller/RankController.class.php | 10 +++++ webapp/controller/RoleController.class.php | 10 +++-- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 tools/rankserver/app.py diff --git a/tools/rankserver/app.py b/tools/rankserver/app.py new file mode 100644 index 0000000..35b067a --- /dev/null +++ b/tools/rankserver/app.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/python + +import pymysql +import hashlib +import json +import urllib.request +import base64 +import tornado.ioloop +import tornado.web +import time +import datetime + +#定时读取mysql里的数据生成排行榜写入redis后php读取redis返回客户端显示 + +def info(msg): + print(str(datetime.datetime.now()) + '[INFO] ' + msg) + +def updateRedis(): + pass + +def readMysqlData(): + pass + + +class SelfCheckingHandler(tornado.web.RequestHandler): + + def get(self): + self.write(json.dumps({ + 'errcode': 0, + 'errmsg': '', + 'healthy': 1, + 'max_rundelay': 10 + })) + +def make_app(): + return tornado.web.Application([ + (r"/webapp/index[\.]php", SelfCheckingHandler), + ]) + +if __name__ == "__main__": + conf = json.loads(open('/var/data/conf_test/game2001api_rankserver/config/rankserver.json', 'r').read()) + + app = make_app() + app.listen(conf['listen_port']) + tornado.ioloop.IOLoop.current().start() diff --git a/webapp/controller/RankController.class.php b/webapp/controller/RankController.class.php index b742340..ac31f88 100644 --- a/webapp/controller/RankController.class.php +++ b/webapp/controller/RankController.class.php @@ -44,6 +44,8 @@ class RankController{ } array_push($kill_list, array( 'account_id' => $row['accountid'], + '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']), @@ -64,6 +66,8 @@ class RankController{ } array_push($alive_list, array( 'account_id' => $row['accountid'], + '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']), @@ -84,6 +88,8 @@ class RankController{ } array_push($harm_list, array( 'account_id' => $row['accountid'], + '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']), @@ -104,6 +110,8 @@ class RankController{ } array_push($rate_list, array( 'account_id' => $row['accountid'], + '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']), @@ -124,6 +132,8 @@ class RankController{ } array_push($win_list, array( 'account_id' => $row['accountid'], + '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']), diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php index 1fbe63a..194130a 100644 --- a/webapp/controller/RoleController.class.php +++ b/webapp/controller/RoleController.class.php @@ -20,6 +20,8 @@ class RoleController{ public function roleInfo() { $account_id = $_REQUEST['account_id']; + $user_name = $_REQUEST['name']; + $avatar_url = $_REQUEST['avatar_url']; $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); @@ -30,10 +32,12 @@ class RoleController{ ':accountid' => $account_id )); if (!$row) { - $ret = $conn->execScript('INSERT INTO user(accountid, rank, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his) ' . - ' VALUES(:accountid, 0, 0, 0, 0, 0, 0, 0, 100000, 0, 0, 0, 0, 0);', + $ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, rank, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his) ' . + ' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 0, 100000, 0, 0, 0, 0, 0);', array( - ':accountid' => $account_id + ':accountid' => $account_id, + ':user_name' => $user_name, + ':avatar_url' => $avatar_url )); if (!$ret) { die();