add rankserver
This commit is contained in:
parent
76e66b4b77
commit
f411fcb404
46
tools/rankserver/app.py
Normal file
46
tools/rankserver/app.py
Normal file
@ -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()
|
@ -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']),
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user