From 0bd95356b7f25a6701b25973c9691ba9d9508005 Mon Sep 17 00:00:00 2001 From: wangwei01 Date: Mon, 8 Jul 2019 15:01:32 +0800 Subject: [PATCH] 1 --- .gitignore | 11 + .gitmodules | 3 + boundle.sh | 10 + config | 1 + reload.sh | 1 + reloadres.sh | 1 + res | 1 + restart.sh | 1 + sql/gamedb.sql | 272 ++++++++ tools/rankserver/app.py | 134 ++++ webapp/bootstrap/config_loader.php | 144 ++++ webapp/bootstrap/init.php | 74 ++ webapp/classes/AddReward.php | 78 +++ webapp/classes/Quest.php | 137 ++++ .../controller/ActivityController.class.php | 370 ++++++++++ webapp/controller/EquipController.class.php | 297 ++++++++ webapp/controller/HangController.class.php | 165 +++++ webapp/controller/OpsController.class.php | 15 + webapp/controller/QuestController.class.php | 443 ++++++++++++ webapp/controller/RankController.class.php | 214 ++++++ webapp/controller/RoleController.class.php | 645 ++++++++++++++++++ webapp/controller/ShareController.class.php | 501 ++++++++++++++ webapp/controller/ShopController.class.php | 378 ++++++++++ webapp/controller/SignController.class.php | 268 ++++++++ webapp/controller/SkinController.class.php | 517 ++++++++++++++ .../controller/SupplyBoxController.class.php | 403 +++++++++++ webapp/controller/TeamController.class.php | 307 +++++++++ webapp/controller/VoiceController.class.php | 52 ++ webapp/index.php | 29 + webapp/phpcommon | 1 + 30 files changed, 5473 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100755 boundle.sh create mode 120000 config create mode 100644 reload.sh create mode 100644 reloadres.sh create mode 120000 res create mode 100644 restart.sh create mode 100644 sql/gamedb.sql create mode 100644 tools/rankserver/app.py create mode 100644 webapp/bootstrap/config_loader.php create mode 100644 webapp/bootstrap/init.php create mode 100644 webapp/classes/AddReward.php create mode 100644 webapp/classes/Quest.php create mode 100644 webapp/controller/ActivityController.class.php create mode 100644 webapp/controller/EquipController.class.php create mode 100644 webapp/controller/HangController.class.php create mode 100644 webapp/controller/OpsController.class.php create mode 100644 webapp/controller/QuestController.class.php create mode 100644 webapp/controller/RankController.class.php create mode 100644 webapp/controller/RoleController.class.php create mode 100644 webapp/controller/ShareController.class.php create mode 100644 webapp/controller/ShopController.class.php create mode 100644 webapp/controller/SignController.class.php create mode 100644 webapp/controller/SkinController.class.php create mode 100644 webapp/controller/SupplyBoxController.class.php create mode 100644 webapp/controller/TeamController.class.php create mode 100644 webapp/controller/VoiceController.class.php create mode 100644 webapp/index.php create mode 120000 webapp/phpcommon diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7ae74b --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.*\~ +*.*~ +*.*\# +*.*# +~*.* +\#*.* +*.out +*.tar +*.tar.gz +target +config/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ce08b16 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "third_party/phpcommon"] + path = third_party/phpcommon + url = git@git.kingsome.cn:server_common/phpcommon.git diff --git a/boundle.sh b/boundle.sh new file mode 100755 index 0000000..6e96dd6 --- /dev/null +++ b/boundle.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +tag_name=`git status |grep '# On branch '|sed 's/# On branch //g'` +dir_name=`basename $PWD` +package_name=${dir_name}.tar.gz +#echo $tag_name +#echo $dir_name +#echo $package_name + +tar --exclude=*.git -chzf target/${package_name} webapp config res reload.sh restart.sh reloadres.sh diff --git a/config b/config new file mode 120000 index 0000000..975ca33 --- /dev/null +++ b/config @@ -0,0 +1 @@ +../conf_test/game2002api/webapp/config \ No newline at end of file diff --git a/reload.sh b/reload.sh new file mode 100644 index 0000000..6941f67 --- /dev/null +++ b/reload.sh @@ -0,0 +1 @@ +echo 'success' diff --git a/reloadres.sh b/reloadres.sh new file mode 100644 index 0000000..6941f67 --- /dev/null +++ b/reloadres.sh @@ -0,0 +1 @@ +echo 'success' diff --git a/res b/res new file mode 120000 index 0000000..49b0c71 --- /dev/null +++ b/res @@ -0,0 +1 @@ +../conf_test/game2002api/webapp/res \ No newline at end of file diff --git a/restart.sh b/restart.sh new file mode 100644 index 0000000..6941f67 --- /dev/null +++ b/restart.sh @@ -0,0 +1 @@ +echo 'success' diff --git a/sql/gamedb.sql b/sql/gamedb.sql new file mode 100644 index 0000000..3192f60 --- /dev/null +++ b/sql/gamedb.sql @@ -0,0 +1,272 @@ +-- MySQL dump 10.14 Distrib 5.5.41-MariaDB, for Linux (x86_64) +-- +-- Host: localhost Database: accountdb +-- ------------------------------------------------------ +-- Server version 5.5.41-MariaDB + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `version` +-- + +DROP TABLE IF EXISTS `version`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `version` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `version` int(11) NOT NULL DEFAULT '0' COMMENT '版本号', + PRIMARY KEY (`idx`), + UNIQUE KEY `version` (`version`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- +-- Table structure for table `user` +-- + +DROP TABLE IF EXISTS `user`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `user_name` tinyblob COMMENT '用户名字', + `avatar_url` varchar(256) NOT NULL DEFAULT '' COMMENT '用户头像', + `game_times` int(11) NOT NULL COMMENT '游戏场次', + `win_times` int(11) NOT NULL COMMENT '胜场', + `kills` int(11) NOT NULL COMMENT '所有击杀', + `harm` int(11) NOT NULL COMMENT '所有伤害', + `add_HP` int(11) NOT NULL COMMENT '所有治疗量', + `alive_time` int(11) NOT NULL COMMENT '所有生存时间', + `coin_num` bigint NOT NULL COMMENT '角色金币', + `integral` 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 '最高伤害', + `add_HP_his` int(11) NOT NULL COMMENT '最多治疗量', + `act_share_status` int(11) NOT NULL COMMENT '分享好礼活动状态', + `act_share_time` int(11) NOT NULL COMMENT '分享好礼活动时间', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + `first_fight` int(11) NOT NULL COMMENT '是否是第一次战斗', + `collect_status` int(11) NOT NULL COMMENT '收藏状态', + `keys_num` int(11) NOT NULL COMMENT '钥匙数量', + `battle_re_times` int(11) NOT NULL COMMENT '每日战斗奖励次数', + `shop_flush_times` int(11) NOT NULL COMMENT '每日商店刷新次数', + `kefu_status` int(11) NOT NULL COMMENT '客服奖励状态(0:未领取,1:已领取)', + PRIMARY KEY (`idx`), + UNIQUE KEY `accountid` (`accountid`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- +-- Table structure for table `skin` +-- + +DROP TABLE IF EXISTS `skin`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `skin` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `skin_id` int(11) NOT NULL COMMENT '皮肤id', + `skin_status` int(11) NOT NULL COMMENT '皮肤状态(0:上阵中,1:已获得)', + `fragment_id` int(11) NOT NULL COMMENT '碎片id', + `fragment_num` int(11) NOT NULL COMMENT '碎片数量', + `active_time` varchar(50) NOT NULL DEFAULT '有效时间(体验时间)', + `fragment_status` int(11) NOT NULL COMMENT '碎片收集状态(活动相关)', + `skin_type` int(11) NOT NULL COMMENT '皮肤类型', + `skin_level` int(11) NOT NULL COMMENT '皮肤等级', + `skin_experience_level` int(11) NOT NULL COMMENT '皮肤体验等级', + `skin_experience_type` int(11) NOT NULL COMMENT '皮肤试用类型(0:没试用,1:皮肤体验,2:满级体验)', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `skin_uuid` (`accountid`, `skin_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +-- +-- Table structure for table `equip` +-- + +DROP TABLE IF EXISTS `equip`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `equip` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `equip_id` int(11) NOT NULL COMMENT '装备id', + `equip_level` int(11) NOT NULL COMMENT '装备等级', + `equip_experience_level` int(11) NOT NULL COMMENT '装备体验等级', + `active_time` varchar(50) NOT NULL DEFAULT '有效时间', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `equip_uuid` (`accountid`, `equip_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +-- +-- Table structure for table `supplybox` +-- + +DROP TABLE IF EXISTS `supplybox`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `supplybox` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `box_id` int(11) NOT NULL COMMENT '补给箱id', + `buy_times` int(11) NOT NULL COMMENT '购买次数', + `free_times` int(11) NOT NULL COMMENT '免费获得次数', + `last_buy_time` varchar(50) NOT NULL DEFAULT '最后一次购买', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `box_uuid` (`accountid`, `box_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +-- +-- Table structure for table `sign` +-- + +DROP TABLE IF EXISTS `sign`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `sign` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `sign_days` int(11) NOT NULL COMMENT '已签天数', + `sign_time` varchar(50) NOT NULL DEFAULT '签到时间', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `accountid` (`accountid`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +-- +-- Table structure for table `hang` +-- + +DROP TABLE IF EXISTS `hang`; +/*!40101 SET @saved_cs_client = @@character_set_client*/; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `hang` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `hang_time` varchar(50) NOT NULL DEFAULT '领取时间', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `accountid` (`accountid`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +-- +-- Table structrure for table `quest` +-- + +DROP TABLE IF EXISTS `quest`; +/*!40101 SET @saved_cs_client = @@character_set_client*/; +/*!40101 SET character_set_client = utf8*/; +CREATE TABLE `quest` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `quest_id` int(11) NOT NULL COMMENT '任务id', + `quest_num` int(11) NOT NULL COMMENT '任务进度', + `quest_type` int(11) NOT NULL COMMENT '任务类型', + `quest_state` int(11) NOT NULL COMMENT '任务状态', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `quest_uuid` (`accountid`, `quest_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- +-- Table structrure for table `active` +-- + +DROP TABLE IF EXISTS `active`; +/*!40101 SET @saved_cs_client = @@character_set_client*/; +/*!40101 SET character_set_client = utf8*/; +CREATE TABLE `active` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `active_num` int(11) NOT NULL COMMENT '日活跃度', + `num_time` varchar(50) NOT NULL DEFAULT '日活跃度时间', + `active_sum` int(11) NOT NULL COMMENT '周活跃度', + `sum_time` varchar(50) NOT NULL DEFAULT '周活跃度时间', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `accountid` (`accountid`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +-- +-- Table structrure for table `history_record` +-- + +DROP TABLE IF EXISTS `history_record`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `history_record`( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `room_uuid` varchar(60) NOT NULL DEFAULT '' COMMENT '战斗id', + `map_id` int(11) NOT NULL COMMENT '地图id', + `map_tpl_name` varchar(50) NOT NULL DEFAULT '' COMMENT '地图模板名字', + `map_name` varchar(50) DEFAULT '' COMMENT '地图名字', + `game_time` int(11) NOT NULL COMMENT '游戏完成时间', + `rank` int(11) NOT NULL COMMENT '游戏排名', + `kills` int(11) NOT NULL COMMENT '游戏击杀', + `harms` int(11) NOT NULL COMMENT '游戏伤害', + `hurts` int(11) NOT NULL COMMENT '承受伤害', + `alive_time` int(11) NOT NULL COMMENT '游戏生存时间', + `coin` bigint NOT NULL COMMENT '战斗结算金币', + `status` int(11) NOT NULL COMMENT '结算金币领取状态', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `history_record_uuid` (`accountid`, `room_uuid`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- +-- Table structure for table `share_achievement` +-- + +DROP TABLE IF EXISTS `share_achievement`; +/*!40101 SET @saved_cs_client = @@character_set_client*/; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `share_achievement` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `ach_id` int(11) NOT NULL COMMENT '分享邀请成就id', + `status` int(11) NOT NULL COMMENT '状态(0:未领取,1:已领取)', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `accountid_ach_id` (`accountid`, `ach_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2015-08-19 18:51:22 diff --git a/tools/rankserver/app.py b/tools/rankserver/app.py new file mode 100644 index 0000000..6e40eda --- /dev/null +++ b/tools/rankserver/app.py @@ -0,0 +1,134 @@ +# -*- 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 +import redis +import os +CONFIG_DIR = '' + +def IsOnlineEnv(): + return os.getenv("SERVER_ENV"); + +if (IsOnlineEnv()): + CONFIG_DIR = '/var/data/conf_test/game2002api_rankserver/config' +else: + CONFIG_DIR = '../config' + +#定时读取mysql里的数据生成排行榜写入redis后php读取redis返回客户端显示 + +def info(msg): + print(str(datetime.datetime.now()) + '[INFO] ' + msg) + +def take_kills(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 + else: + return a / b + +def getRedis(): + redis_conf = json.loadsmysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.redis.cluster.json', 'r').read()) + for conf in redis_conf: + r = redis.Redis(host = conf['host'], + port = conf['port'], + password = conf['passwd'], + charset = 'utf8' + ) + return r; + + +def readMysqlData(rushtime): + mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read()) + array = [] + for conf in mysql_conf: + conn = pymysql.connect(host = conf['host'], + port = conf['port'], + user = conf['user'], + passwd = conf['passwd'], + db = 'gamedb2002_' + str(conf['instance_id']), + charset = 'utf8' + ) + cursor = conn.cursor() + cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time, harm, win_times, game_times 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])) + + 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) + + tornado.ioloop.IOLoop.current().call_later(rushtime, + lambda : readMysqlData(rushtime) + ) + + +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(CONFIG_DIR + '/rankserver.json', 'r').read()) + + app = make_app() + app.listen(conf['listen_port']) + conf['rushtime'] = 300 + + tornado.ioloop.IOLoop.current().call_later(conf['rushtime'], + lambda : readMysqlData(conf['rushtime']) + ) + tornado.ioloop.IOLoop.current().start() diff --git a/webapp/bootstrap/config_loader.php b/webapp/bootstrap/config_loader.php new file mode 100644 index 0000000..b38ad7f --- /dev/null +++ b/webapp/bootstrap/config_loader.php @@ -0,0 +1,144 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + public function addReward($item_id, $item_num, $account_id) + { + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + die(); + } + if ($item_id == 10001) { + $row1 = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $item_num + $row1['coin_num'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } else if ($item_id > 13000 && $item_id < 14000) { + $rowSkin = $conn->execQueryOne('SELECT fragment_num FROM skin WHERE accountid=:accountid AND fragment_id=:fragment_id;', + array( + ':accountid' => $account_id, + ':fragment_id' => $item_id + )); + $ret = $conn->execScript('UPDATE skin SET fragment_num=:fragment_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND fragment_id=:fragment_id;', + array( + ':accountid' => $account_id, + ':fragment_id' => $item_id, + ':fragment_num' => $item_num + $rowSkin['fragment_num'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } else if ($item_id == 10002) { + $rowkey = $conn->execQueryOne('SELECT keys_num FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $ret = $conn->execScript('UPDATE user SET keys_num=:keys_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':keys_num' => $item_num + $rowkey['keys_num'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } + } +} +?> diff --git a/webapp/classes/Quest.php b/webapp/classes/Quest.php new file mode 100644 index 0000000..ec766cd --- /dev/null +++ b/webapp/classes/Quest.php @@ -0,0 +1,137 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getQuest($quest_id) + { + $g_conf_quest_cluster = require('../res/task@task.php'); + $quest_conf = getQuestConfig($g_conf_quest_cluster, $quest_id); + $q = array( + 'id' => $quest_conf['id'], + 'type' => $quest_conf['type'], + 'condition' => $quest_conf['condition'], + 'value' => $quest_conf['value'], + 'active_value' => $quest_conf['active_value'], + ); + return $q; + } + + public function triggerQuest($quest_id, $quest_type, $quest_num, $account_id) + { + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $q = $this->getQuest($quest_id); + if (!$q) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM quest WHERE accountid=:accountid AND quest_id =:quest_id AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_type' => $quest_type, + )); + if ($row) { + if ($row['quest_state'] == 0) { + if ($q['condition'] == 7 && $quest_type == 1) { + if($quest_num <= $q['value']) { + $quest_state = 1; + $this->triggerQuest(QUEST_DAY_COMPLETE, 1, 1, $account_id); + } + } else if ($q['condition'] == 13 && $quest_type == 1){ + if ($row['quest_num'] + $quest_num >= $q['value']) { + $quest_num = $q['value']; + $quest_state = 1; + } else { + $quest_num = $row['quest_num'] + $quest_num; + $quest_state = 0; + } + } else { + if ($row['quest_num'] + $quest_num >= $q['value']) { + $quest_num = $q['value']; + $quest_state = 1; + if ($quest_type == 1) { + $this->triggerQuest(QUEST_DAY_COMPLETE, 1, 1, $account_id); + } + } else { + $quest_num = $row['quest_num'] + $quest_num; + $quest_state = 0; + } + } + $ret = $conn->execScript('UPDATE quest SET quest_num=:quest_num, quest_state=:quest_state, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_id =:quest_id AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_type' => $quest_type, + ':quest_num' => $quest_num, + ':quest_state' => $quest_state, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + + } else { + $quest_state = 0; + if ($q['condition'] == 7 && $quest_type == 1) { + if($quest_num <= $q['value']) { + $quest_state = 1; + $this->triggerQuest(QUEST_DAY_COMPLETE, 1, 1, $account_id); + } + } else if ($q['condition'] == 13 && $quest_type == 1){ + if ($row['quest_num'] >= $q['value']) { + $quest_num = $q['value']; + $quest_state = 1; + } + } else { + if ($quest_num >= $q['value']) { + $quest_num = $q['value']; + $quest_state = 1; + if ($quest_type == 1) { + $this->triggerQuest(QUEST_DAY_COMPLETE, 1, 1, $account_id); + } + } + } + $ret = $conn->execScript('INSERT INTO quest(accountid, quest_id, quest_num, quest_type, quest_state, create_time, modify_time) ' . + ' VALUES(:accountid, :quest_id, :quest_num, :quest_type, :quest_state, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, quest_id=:quest_id, quest_num=:quest_num, quest_type=:quest_type, quest_state=:quest_state, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_num' => $quest_num, + ':quest_type' => $quest_type, + ':quest_state'=> $quest_state, + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + } +} +?> diff --git a/webapp/controller/ActivityController.class.php b/webapp/controller/ActivityController.class.php new file mode 100644 index 0000000..2e6fe41 --- /dev/null +++ b/webapp/controller/ActivityController.class.php @@ -0,0 +1,370 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + + protected function getActivityConfig($activity_id) + { + $g_conf_activity_cluster = require('../res/activity@activity.php'); + $activity_conf = getActivityConfig($g_conf_activity_cluster, $activity_id); + $a = array( + 'id' => $activity_conf['id'], + 'name' => $activity_conf['name'], + 'des' => $activity_conf['des'], + 'start_date' => $activity_conf['start_date'], + 'end_date' => $activity_conf['end_date'], + ); + return $a; + } + + protected function getActivityRewardConfig($activityReward_id) + { + $g_conf_activityReward_cluster = require('../res/activityReward@activityReward.php'); + $activityReward_conf = getActivityRewardConfig($g_conf_activityReward_cluster, $activityReward_id); + $act = array( + 'id' => $activityReward_conf['id'], + 'activity_id' => $activityReward_conf['activity_id'], + 'condition' => $activityReward_conf['condition'], + 'parameter' => $activityReward_conf['parameter'], + 'start_end_time' => $activityReward_conf['start_end_time'], + 'activity_reward' => $activityReward_conf['activity_reward'], + 'exchange_num' => $activityReward_conf['exchange_num'], + 'exchange_item' => $activityReward_conf['exchange_item'] + ); + return $act; + } + + protected function getExplode($string) + { + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; + } + + public function activityInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $activity_list = array(); + $activity_skin_list = array(); + $activity_quest_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + //活动列表 + $g_conf_activity_cluster = require('../res/activity@activity.php'); + for ($i = 1; $i <= count($g_conf_activity_cluster); $i++) { + $start_status = 0; + $a = $this->getActivityConfig($i); + if (time() >= $a['start_date'] && time() < $a['end_date']) { + $start_status = 1; + } else { + $ret = $conn->execScript('UPDATE skin SET fragment_num=:fragment_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND skin_type=2;', + array( + ':accountid' => $account_id, + ':fragment_num' => 0, + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + } + array_push($activity_list, array( + 'activity_id' => $a['id'], + 'start_time' => $a['start_date'], + 'end_time' => $a['end_date'], + 'status' => $start_status + )); + } + //求生庆典活动 + $rowSkin = $conn->execQuery('SELECT * FROM skin WHERE accountid=:accountid AND skin_type=:skin_type;', + array( + ':accountid' => $account_id, + ':skin_type' => 2 + )); + foreach ($rowSkin as $skin) { + array_push($activity_skin_list, array( + 'id' => $skin['skin_id'], + 'num' => $skin['fragment_num'], + 'exchange_status' => $skin['skin_status'], + 'collect_status' => $skin['fragment_status'] + )); + } + //分享好礼活动 + $row = $conn->execQueryOne('SELECT act_share_status, act_share_time FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $receive_status = $row['act_share_status']; + if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row['act_share_time']) > 0 + && $row['act_share_status'] == 1) + { + $receive_status = 0; + $ret = $conn->execScript('UPDATE user SET act_share_status=:act_share_status, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':act_share_status' => $receive_status, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + //任务活动 + $rows = $conn->execQuery('SELECT * FROM quest WHERE accountid=:accountid AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_type' => 3 + )); + foreach ($rows as $r) { + array_push($activity_quest_list, array( + 'id' => $r['quest_id'], + 'num' => $r['quest_num'], + 'status' => $r['quest_state'] + )); + } + + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'activity_list' => $activity_list, + 'activity_id1' => 1, + 'activity_skin_list' => $activity_skin_list, + 'activity_id2' => 2, + 'receive_status' => $receive_status, + 'activity_id3' => 3, + 'activity_quest_list' => $activity_quest_list + )); + } + + public function triggerActivity() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $activity_id = $_REQUEST['activity_id']; + $type = $_REQUEST['type']; + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + + $act = $this->getActivityRewardConfig($activity_id); + $array = $this->getExplode($act['activity_reward']); + switch ($type) + { + case 1: //活动皮肤碎片收集 + { + $item_id = $array[0][0]; + $item_num = $array[0][1]; + $rowSkin = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:accountid AND fragment_id=:fragment_id;', + array( + ':accountid' => $account_id, + ':fragment_id' => $item_id + )); + if ($rowSkin['fragment_status'] != 0) { + phpcommon\sendError(ERR_USER_BASE + 2, '今天已收集'); + return; + } + if ($rowSkin['fragment_num'] + $item_num >= $act['exchange_num']) { + $skin_status = 2; + } else { + $skin_status = 3; + } + $ret = $conn->execScript('UPDATE skin SET fragment_num=:fragment_num, skin_status=:skin_status, fragment_status=1, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND fragment_id=:fragment_id;', + array( + ':accountid' => $account_id, + ':skin_status' => $skin_status, + ':fragment_id' => $item_id, + ':fragment_num' => $item_num + $rowSkin['fragment_num'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + break; + } + case 2: //活动皮肤兑换 + { + $arr = $this->getExplode($act['exchange_item']); + $row = $conn->execQueryOne('SELECT * FROM skin WHERE accountid = :account_id AND skin_id = :skin_id;', + array( + ':account_id' => $account_id, + ':skin_id' => $arr[0][0] + )); + if(!$row){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤'); + return; + } + if ($row['skin_status'] == 2) { + $fragment_num = $row['fragment_num'] - $act['exchange_num']; + $time = time(); + $ret = $conn->execScript('UPDATE skin SET fragment_num=:fragment_num, skin_status=1, active_time=:active_time, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND skin_id=:skin_id;', + array( + ':account_id' => $account_id, + ':skin_id' => $arr[0][0], + ':active_time' => $time, + ':fragment_num' => $fragment_num, + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + } + break; + } + case 3: //活动补给箱领取 + { + $ret = $conn->execScript('UPDATE user SET act_share_status=1, act_share_time=:act_share_time, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':act_share_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + for ($i = 0; $i < count($array); $i++) { + $item_id = $array[$i][0]; + $item_num = $array[$i][1]; + $row = $conn->execQueryOne('SELECT * FROM supplybox WHERE accountid=:account_id AND box_id=:box_id;', + array( + ':account_id' => $account_id, + ':box_id' => $item_id + )); + if (!$row) { + $ret = $conn->execScript('INSERT INTO supplybox(accountid, box_id, box_num, buy_times, last_buy_time, create_time, modify_time) ' . + ' VALUES(:accountid, :box_id, :box_num, 0, 0, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, box_id=:box_id, box_num=:box_num, buy_times=0, last_buy_time=0, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':box_id' => $item_id, + ':box_num' => 1, + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } else { + $ret = $conn->execScript('UPDATE supplybox SET box_num=:box_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND box_id=:box_id;', + array( + ':accountid' => $account_id, + ':box_id' => $item_id, + ':box_num' => $row['box_num'] + $item_num, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + } + break; + } + case 4: //活动任务奖励 + { + $row = $conn->execQueryOne('SELECT * FROM quest WHERE accountid=:accountid AND quest_id=:quest_id AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_id' => $activity_id, + ':quest_type' => 3 + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); + return; + } + if ($row['quest_state'] == 1) { + $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_id =:quest_id AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_id' => $activity_id, + ':quest_type' => 3, + ':quest_state' => 2, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $item_id = $array[0][0]; + $item_num = $array[0][1]; + $row1 = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $item_num + $row1['coin_num'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + break; + } + default: + break; + } + + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } +} +?> diff --git a/webapp/controller/EquipController.class.php b/webapp/controller/EquipController.class.php new file mode 100644 index 0000000..1c08865 --- /dev/null +++ b/webapp/controller/EquipController.class.php @@ -0,0 +1,297 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getEquip($equip_id) + { + $g_conf_equip_cluster = require('../res/equipUpgrade@equipUpgrade.php'); + $equip_conf = getEquipConfig($g_conf_equip_cluster, $equip_id); + $e = array( + 'equip_id' => $equip_conf['id'], + 'equip_name' => $equip_conf['name'], + 'equip_type' => $equip_conf['equip_page'], + 'cost_int' => $equip_conf['cost_int'], + 'max_lv' => $equip_conf['max_lv'], + 'equip_cost' => $equip_conf['cost'], + 'equip_attr_type' => $equip_conf['attr_type'], + ); + return $e; + } + + protected function getParameter($para_id) + { + $g_conf_para_cluster = require('../res/parameter@parameter.php'); + $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); + $p = array( + 'id' => $para_conf['id'], + 'param_name' => $para_conf['param_name'], + 'param_value' => $para_conf['param_value'], + ); + return $p; + } + + protected function subCoin($account_id, $equip_id, $equip_level, $free) + { + $e = $this->getEquip($equip_id); + if (!$e) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); + die(); + } + if ($e['max_lv'] <= $equip_level) { + phpcommon\sendError(ERR_USER_BASE + 4, '装备已到满级'); + die(); + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + die(); + } + $coin_num = $e['equip_cost'] * ceil($equip_level / 5) + $e['cost_int']; + if ($free == 1) { + $coin_num = 0; + } + $rowCoin = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if ($rowCoin['coin_num'] < $coin_num) { + phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); + die(); + } + $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $rowCoin['coin_num'] - $coin_num, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + return $e; + } + + public function equipInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $equip_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $rowCount = $conn->execQueryRowCount('SELECT * FROM equip WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + if ($rowCount != 0) { + $active_time = 0; + $equip_level = 0; + $rows = $conn->execQuery('SELECT * FROM equip WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + foreach ($rows as $row) { + if (time() >= $row['active_time'] && $row['active_time'] != 0) { + $ret = $conn->execScript('UPDATE equip SET active_time=0, equip_experience_level=0, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND equip_id=:equip_id;', + array( + ':account_id' => $account_id, + ':equip_id' => $row['equip_id'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $equip_level = $row['equip_level']; + $active_time = 0; + } else { + if ($row['active_time'] != 0) { + $active_time = $row['active_time']; + $equip_level = $row['equip_experience_level']; + } else { + $active_time = 0; + $equip_level = $row['equip_level']; + } + } + array_push($equip_list, array( + 'equip_id' => $row['equip_id'], + 'equip_level' => $equip_level, + 'active_time' => $active_time + )); + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'equip_list' => $equip_list + )); + } + + + public function updateEquip() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $skin_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $equip_id = $_REQUEST['equip_id']; + $free = $_REQUEST['free']; + $equip_level = 0; + $row = $conn->execQueryOne('SELECT * FROM equip WHERE accountid=:account_id AND equip_id=:equip_id;', + array( + ':account_id' => $account_id, + ':equip_id' => $equip_id + )); + + if (!$row) { + $e = $this->subCoin($account_id, $equip_id, 1, $free); + $ret = $conn->execScript('INSERT INTO equip(accountid, equip_id, equip_level, equip_experience_level, active_time, create_time, modify_time) ' . + ' VALUES(:accountid, :equip_id, :equip_level, :equip_experience_level, :active_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, equip_id=:equip_id, equip_level=:equip_level, equip_experience_level=:equip_experience_level, active_time=:active_time, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':equip_id' => $equip_id, + ':equip_level' => 2, + ':equip_experience_level' => 0, + ':active_time' => 0, + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $equip_level = 2; + } else { + $e = $this->subCoin($account_id, $equip_id, $row['equip_level'], $free); + $ret = $conn->execScript('UPDATE equip SET equip_level=:equip_level, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND equip_id=:equip_id;', + array( + ':account_id' => $account_id, + ':equip_id' => $equip_id, + ':equip_level' => $row['equip_level'] + 1, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $equip_level = $row['equip_level'] + 1; + } + $quest = new classes\Quest(); + $quest->triggerQuest(QUEST_DAY_UPDATEEQUIP, 1, 1, $account_id); + if ($row['equip_level'] + 1 >= $e['max_lv']) { + $quest->triggerQuest(QUEST_SUM_EQUIPMAX, 2, 1, $account_id); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + /*'equip_id' => $equip_id, + 'equip_level' => $equip_level, + 'equip_time' => 0, + 'coin_num' => -($e['equip_cost'] * ceil($equip_level / 5) + $e['cost_int'])*/ + )); + } + + + public function freeTryEquip() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $equip_id = $_REQUEST['equip_id']; + $equip_level = $_REQUEST['equip_level']; + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个角色'); + return; + } + $e = $this->getEquip($equip_id); + if (!$e) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); + return; + } + $p = $this->getParameter(WEAPON_TRIAL); + $time = $p['param_value']; + $row = $conn->execQueryOne('SELECT * FROM equip WHERE accountid=:account_id AND equip_id=:equip_id;', + array( + ':account_id' => $account_id, + ':equip_id' => $equip_id + )); + if (!$row) { + $ret = $conn->execScript('INSERT INTO equip(accountid, equip_id, equip_level, equip_experience_level, active_time, create_time, modify_time) ' . + ' VALUES(:accountid, :equip_id, 1, :equip_experience_level, :active_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, equip_id=:equip_id, equip_level=1, equip_experience_level=9, active_time=:active_time, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':equip_id' => $equip_id, + ':active_time' => time() + $time, + ':create_time' => time(), + ':modify_time' => time(), + ':equip_experience_level' => $e['max_lv'] + )); + if (!$ret) { + die(); + return; + } + } else { + $ret = $conn->execScript('UPDATE equip SET active_time=:active_time, equip_experience_level=:equip_experience_level, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND equip_id=:equip_id;', + array( + ':account_id' => $account_id, + ':equip_id' => $equip_id, + ':active_time' => time() + $time, + ':modify_time' => time(), + ':equip_experience_level' => $e['max_lv'] + )); + if (!$ret) { + die(); + return; + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + /*'equip_id' => $equip_id, + 'equip_level' => $e['max_lv'], + 'equip_time' => time() + $time,*/ + )); + } +} +?> diff --git a/webapp/controller/HangController.class.php b/webapp/controller/HangController.class.php new file mode 100644 index 0000000..9e4f2dc --- /dev/null +++ b/webapp/controller/HangController.class.php @@ -0,0 +1,165 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getParameter($para_id) + { + $g_conf_para_cluster = require('../res/parameter@parameter.php'); + $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); + $p = array( + 'id' => $para_conf['id'], + 'param_name' => $para_conf['param_name'], + 'param_value' => $para_conf['param_value'], + ); + return $p; + } + + public function getHangReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $item_id = 0; + $num = 0; + $weight = $_REQUEST['weight']; + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if ($row) { + $ret = $conn->execScript('UPDATE hang SET hang_time=:hang_time, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':hang_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $item_id = 10001; + $p_num = $this->getParameter(GOLD); + $p_time_limit = $this->getParameter(TIME_LIMIT); + $num = floor((time() - $row['hang_time']) / 5 * $p_num['param_value']); + if ((time() - $row['hang_time']) >= $p_time_limit['param_value']) { + $num = floor($p_time_limit['param_value'] / 5 * $p_num['param_value']); + } + if ($weight != 0) { + $times = $this->getRewardTimes($num); + $num = $num * $times; + } + $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $num + $row['coin_num'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_id' => $item_id, + 'num' => $num, + 'time' => time() + )); + } + + public function getTime() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $num = 0; + $row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + $ret = $conn->execScript('INSERT INTO hang(accountid, hang_time, create_time, modify_time) ' . + ' VALUES(:accountid, :hang_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, hang_time=:hang_time, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':hang_time' => time(), + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } else { + $p_num = $this->getParameter(GOLD); + $p_time_limit = $this->getParameter(TIME_LIMIT); + $num = floor((time() - $row['hang_time']) / 5 * $p_num['param_value']); + if ((time() - $row['hang_time']) >= $p_time_limit['param_value']) { + $num = floor($p_time_limit['param_value'] / 5 * $p_num['param_value']); + } + } + + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'time' => time(), + 'num' => $num + )); + } + + protected function getRewardTimes($coin_num) + { + $g_conf_reward_cluster = require('../res/rewardTimes@rewardTimes.php'); + $times = 1; + $reward_conf = array(); + for ($i = 0; $i < 4; $i++) { + $reward_id = $i + 91000; + $reward_conf = getRewardTimesConfig($g_conf_reward_cluster, $reward_id); + if ((int)$coin_num >= $reward_conf['minGold'] && (int)$coin_num <= $reward_conf['maxGold']) { + $times = $reward_conf['times']; + break; + } + } + return $times; + } +} +?> diff --git a/webapp/controller/OpsController.class.php b/webapp/controller/OpsController.class.php new file mode 100644 index 0000000..d0dbba9 --- /dev/null +++ b/webapp/controller/OpsController.class.php @@ -0,0 +1,15 @@ + 0, + 'errmsg' => '', + 'healthy' => 1, + 'max_rundelay' => 1, + )); + } + +} diff --git a/webapp/controller/QuestController.class.php b/webapp/controller/QuestController.class.php new file mode 100644 index 0000000..24a4d05 --- /dev/null +++ b/webapp/controller/QuestController.class.php @@ -0,0 +1,443 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getQuest($quest_id) + { + $g_conf_quest_cluster = require('../res/task@task.php'); + $quest_conf = getQuestConfig($g_conf_quest_cluster, $quest_id); + $q = array( + 'id' => $quest_conf['id'], + 'type' => $quest_conf['type'], + 'condition' => $quest_conf['condition'], + 'value' => $quest_conf['value'], + 'active_value' => $quest_conf['active_value'], + 'reward' => $quest_conf['reward'], + ); + return $q; + } + + protected function getTaskReward($taskReward_id) + { + $g_conf_taskReward_cluster = require('../res/taskReward@taskReward.php'); + $taskReward_conf = getTaskRewardConfig($g_conf_taskReward_cluster, $taskReward_id); + $t = array( + 'id' => $taskReward_conf['id'], + 'type' => $taskReward_conf['type'], + 'value' => $taskReward_conf['value'], + 'reward' => $taskReward_conf['reward'] + ); + return $t; + } + + protected function getExplode($string) + { + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; + } + + protected function getDrop($drop_id) + { + $g_conf_drop_cluster = require('../res/drop@drop.php'); + $drop_conf = getDropConfig($g_conf_drop_cluster, $drop_id); + $d = array( + 'drop_id' => $drop_conf['drop_id'], + 'item_id' => $drop_conf['item_id'], + 'num' => $drop_conf['num'], + 'weight' => $drop_conf['weight'], + 'type' => $drop_conf['type'] + ); + return $d; + } + + protected function insertActive($account_id, $active_id, $task_num) + { + $conn = $this->getMysql($account_id); + for ($i = $active_id; $i < $active_id + $task_num; $i++) { + $ret = $conn->execScript('INSERT INTO quest(accountid, quest_id, quest_type, quest_state, create_time, modify_time) ' . + ' VALUES(:accountid, :quest_id, :quest_type, :quest_state, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, quest_id=:quest_id, quest_type=:quest_type, quest_state=:quest_state, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':quest_id' => $i, + ':quest_type' => 0, + ':quest_state'=> 0, + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } + } + + public function updateActive($account_id, $active_num, $active_sum) + { + $conn = $this->getMysql($account_id); + for ($i = 73001; $i < 73006; $i++) { + $quest_id = $i; + $row = $conn->execQueryOne('SELECT * FROM quest WHERE accountid=:accountid AND quest_id=:quest_id;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id + )); + $t = $this->getTaskReward($quest_id); + if ($row['quest_state'] != 0 || $active_num < $t['value']) { + continue; + } + $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_id =:quest_id;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_state' => 1, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } + + for ($j = 74001; $j < 74004; $j++) { + $quest_id = $j; + $row = $conn->execQueryOne('SELECT * FROM quest WHERE accountid=:accountid AND quest_id=:quest_id;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id + )); + $t = $this->getTaskReward($j); + if ($row['quest_state'] != 0 || $active_sum < $t['value']) { + continue; + } + $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_id =:quest_id;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_state' => 1, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } + } + + protected function updateActiveTime($account_id, $quest_id, $flag) + { + $conn = $this->getMysql($account_id); + if ($flag == 2) { + $ret = $conn->execScript('UPDATE active SET sum_time=:sum_time, active_sum=:active_sum, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':sum_time' => time(), + ':active_sum' => 0, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } else if ($flag == 1) { + $ret = $conn->execScript('UPDATE active SET num_time=:num_time, active_num=:active_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':num_time' => time(), + ':active_num' => 0, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } + $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_type=:quest_type AND quest_id<:quest_id;', + array( + ':accountid' => $account_id, + ':quest_type' => 0, + ':quest_id' => $quest_id, + ':quest_state' => 0, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } + + public function questInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $quest_list = array(); + $active_list = array(); + $achievement_list = array(); + $active_sum = 0; + $active_num = 0; + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT active_sum, sum_time FROM active WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if ($row) { + //每周更新活跃度 + if (phpcommon\getMondayseconds(time()) - phpcommon\getMondayseconds($row['sum_time']) > 0) { + $this->updateActiveTime($account_id, 75000, 2); + } else { + $active_sum = $row['active_sum']; + } + } + $row = $conn->execQueryOne('SELECT active_num, num_time FROM active WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if ($row) { + //每日更新活跃度 + if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row['num_time']) > 0) { + $this->updateActiveTime($account_id, 74000, 1); + } else { + $active_num = $row['active_num']; + } + } + $rowCount = $conn->execQueryRowCount('SELECT * FROM quest WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if ($rowCount != 0) { + $rows = $conn->execQuery('SELECT * FROM quest WHERE accountid=:accountid AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_type' => 1 + )); + if ($rows) { + foreach ($rows as $row) { + array_push($quest_list, array( + 'type' => $row['quest_type'], + 'quest_id' => $row['quest_id'], + 'quest_num' => $row['quest_num'], + 'quest_state' => $row['quest_state'] + )); + } + } + $rows = $conn->execQuery('SELECT * FROM quest WHERE accountid=:accountid AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_type' => 2 + )); + if ($rows) { + foreach ($rows as $row) { + array_push($achievement_list, array( + 'type' => $row['quest_type'], + 'achievement_id' => $row['quest_id'], + 'achievement_num' => $row['quest_num'], + 'achievement_state' => $row['quest_state'] + )); + } + } + $rows = $conn->execQuery('SELECT * FROM quest WHERE accountid=:accountid AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_type' => 0 + )); + if ($rows) { + foreach ($rows as $row) { + array_push($active_list, array( + 'type' => $row['quest_type'], + 'active_id' => $row['quest_id'], + 'active_state' => $row['quest_state'] + )); + } + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'active_num' => $active_num, + 'active_sum' => $active_sum, + 'active_list' => $active_list, + 'quest_list' => $quest_list, + 'achievement_list' => $achievement_list + )); + } + + public function submitQuest() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $quest_id = $_REQUEST['quest_id']; + $quest_type = $_REQUEST['type']; + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM quest WHERE accountid=:accountid AND quest_id=:quest_id AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_type' => $quest_type + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); + return; + } + $item_list = array(); + if ($row['quest_state'] == 1) { + $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_id =:quest_id AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_type' => $quest_type, + ':quest_state' => 2, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + + //发奖励 + if ($quest_type == 0) { + $t = $this->getTaskReward($quest_id); + if (!$t) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); + return; + } + $d = $this->getDrop($t['reward']); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $weight_sum = 0; + $weight_array = $this->getExplode($d['weight']); + for ($i = 0; $i < count($weight_array); $i++) { + $weight_sum += $weight_array[$i][0]; + } + + $random = Rand(0, $weight_sum); + $weight = 0; + for ($i = 0; $i < count($weight_array); $i++) { + $weight += $weight_array[$i][0]; + if ($weight > $random) { + $key = $i; + break; + } + } + $item_id_array = $this->getExplode($d['item_id']); + $num_array = $this->getExplode($d['num']); + $item_id = $item_id_array[$key][0]; + $item_num = $num_array[$key][0]; + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + )); + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + } else { + $q = $this->getQuest($quest_id); + if (!$q) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); + return; + } + $array = $this->getExplode($q['reward']); + $reward_id = $array[0][0]; + $reward_num = $array[0][1]; + $addreward = new classes\AddReward(); + $addreward->addReward($reward_id, $reward_num, $account_id); + array_push($item_list, array( + 'item_id' => $reward_id, + 'item_num' => $reward_num, + )); + } + if ($row['quest_type'] == 1) { + $active = $conn->execQueryOne('SELECT active_num, active_sum FROM active WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + //增加活跃度 + if (!$active) { + $this->insertActive($account_id, 73001, 5); + $this->insertActive($account_id, 74001, 3); + $ret = $conn->execScript('INSERT INTO active(accountid, active_num, num_time, active_sum, sum_time, create_time, modify_time) ' . + ' VALUES(:accountid, :active_num, :num_time, :active_sum, :sum_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, active_num=:active_num, num_time=:num_time, active_sum=:active_sum, sum_time=:sum_time, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':active_num' => $q['active_value'], + ':num_time' => time(), + ':active_sum' => $q['active_value'], + ':sum_time' => time(), + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $this->updateActive($account_id, $q['active_value'], $q['active_value']); + } else { + $active['active_num'] = $q['active_value'] + $active['active_num']; + $active['active_sum'] = $q['active_value'] + $active['active_sum']; + $ret = $conn->execScript('UPDATE active SET active_num=:active_num, active_sum=:active_sum, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':active_num' => $active['active_num'], + ':active_sum' => $active['active_sum'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $this->updateActive($account_id, $active['active_num'], $active['active_sum']); + } + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_list' => $item_list + )); + } + +} +?> diff --git a/webapp/controller/RankController.class.php b/webapp/controller/RankController.class.php new file mode 100644 index 0000000..a6b73cc --- /dev/null +++ b/webapp/controller/RankController.class.php @@ -0,0 +1,214 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getRedis() + { + $key = 'game2001api'; + $redis_conf = getRedisConfig($key); + $r = new phpcommon\Redis(array( + 'host' => $redis_conf['host'], + 'port' => $redis_conf['port'], + 'passwd' => $redis_conf['passwd'], + )); + return $r; + } + + public function rankInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + 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; + $user_list = array(); + //个人信息 + $row = $conn->execQueryOne('SELECT user_name, avatar_url, kills, alive_time, harm, win_times, game_times FROM user ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if ($row) { + array_push($user_list, array( + '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'] + )); + } + + //击杀榜 + $r = $this->getRedis(); + $kill_rank_db = $r->get("game2001api: kill_rank"); + $kill_db = json_decode($kill_rank_db); + $i = 0; + foreach ($kill_db as $kill) { + if ($i > 49) { + break; + } + if ($kill_db[$i][0] == $account_id) { + $kill_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] + )); + $i++; + } + + echo json_encode(array( + '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 + )); + } +} + + +?> diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php new file mode 100644 index 0000000..49f6e6f --- /dev/null +++ b/webapp/controller/RoleController.class.php @@ -0,0 +1,645 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getActivityRewardConfig($activityReward_id) + { + $g_conf_activityReward_cluster = require('../res/activityReward@activityReward.php'); + $activityReward_conf = getActivityRewardConfig($g_conf_activityReward_cluster, $activityReward_id); + $act = array( + 'id' => $activityReward_conf['id'], + 'activity_id' => $activityReward_conf['activity_id'], + 'condition' => $activityReward_conf['condition'], + 'parameter' => $activityReward_conf['parameter'], + 'start_end_time' => $activityReward_conf['start_end_time'], + 'activity_reward' => $activityReward_conf['activity_reward'], + 'exchange_num' => $activityReward_conf['exchange_num'], + 'exchange_item' => $activityReward_conf['exchange_item'] + ); + return $act; + } + + protected function getDrop($drop_id) + { + $g_conf_drop_cluster = require('../res/drop@drop.php'); + $drop_conf = getDropConfig($g_conf_drop_cluster, $drop_id); + $d = array( + 'drop_id' => $drop_conf['drop_id'], + 'item_id' => $drop_conf['item_id'], + 'num' => $drop_conf['num'], + 'weight' => $drop_conf['weight'], + 'type' => $drop_conf['type'] + ); + return $d; + } + + protected function getExplode($string) + { + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; + } + + + protected function getParameter($para_id) + { + $g_conf_para_cluster = require('../res/parameter@parameter.php'); + $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); + $p = array( + 'id' => $para_conf['id'], + 'param_name' => $para_conf['param_name'], + 'param_value' => $para_conf['param_value'], + ); + return $p; + } + + public function roleInfo() + { + $account_id = $_REQUEST['account_id']; + $user_name = $_REQUEST['name']; + $avatar_url = $_REQUEST['avatar_url']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + if (empty($_REQUEST['account_id'])) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + $ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his, act_share_time, act_share_status, create_time, modify_time, first_fight, collect_status, keys_num, battle_re_times, shop_flush_times, kefu_status) ' . + ' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, create_time, :modify_time, 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, add_HP=0, alive_time=0, coin_num=0, integral=0, kill_his=0, alive_time_his=0, harm_his=0, add_HP_his=0, act_share_time=0, act_share_status=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;', + array( + ':accountid' => $account_id, + ':user_name' => $user_name, + ':avatar_url' => $avatar_url, + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'game_times' => 0, + 'win_times' => 0, + 'high_kill' => 0, + 'kills' => 0, + 'high_harm' => 0, + 'harm' => 0, + 'add_HP' => 0, + 'alive_time' => 0, + 'coin_num' => 0, + 'first_fight' => 0, + 'collect_status' => 0, + 'keys_num' => 0, + 'kefu_status' => 0 + )); + } else { + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'game_times' => $row['game_times'], + 'win_times' => $row['win_times'], + 'high_kill' => $row['kill_his'], + 'kills' => $row['kills'], + 'high_harm' => $row['harm_his'], + 'harm' => $row['harm'], + 'add_HP' => $row['add_HP'], + 'alive_time' => $row['alive_time'], + 'coin_num' => $row['coin_num'], + 'first_fight' => $row['first_fight'], + 'collect_status' => $row['collect_status'], + 'keys_num' => $row['keys_num'], + 'kefu_status' => $row['kefu_status'], + )); + } + } + + public function battleReport() + { + $account_id = $_REQUEST['account_id']; //账号 + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $map_id = $_REQUEST['map_id']; + $map_tpl_name = $_REQUEST['map_tpl_name']; + $room_uuid = $_REQUEST['room_uuid']; //战斗id + $map_name = $_REQUEST['map_name']; //地图名 + $game_time = $_REQUEST['game_time']; //游戏结束时间 + $hurt = $_REQUEST['hurt']; //承受伤害 + $rank = $_REQUEST['rank']; //排名 + $kills = $_REQUEST['kills']; //击杀数 + $harm = $_REQUEST['harm']; //伤害 + $add_HP = $_REQUEST['add_HP']; //治疗量 + $alive_time = $_REQUEST['alive_time']; //存活时间 + $team_status = $_REQUEST['team_status']; //是否是组队状态 + $snipe_kill = $_REQUEST['snipe_kill']; //狙击枪击杀数 + $rifle_kill = $_REQUEST['rifle_kill']; //步枪击杀数 + $pistol_kill = $_REQUEST['pistol_kill']; //手枪击杀数 + $submachine_kill = $_REQUEST['submachine_kill'];//冲锋枪击杀数 + $rescue_member = $_REQUEST['rescue_member']; //救起队友次数 + $kill_his = $kills; + $harm_his = $harm; + $alive_time_his = $alive_time; + $add_HP_his = $add_HP; + $coin_num = $_REQUEST['coin_num']; //金币 + $integral = $_REQUEST['score']; //积分 + + if (!$map_id) { + $map_id = 0; + } + if (!$map_tpl_name) { + $map_tpl_name = ''; + } + + $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家1'); + return; + } + if ($kill_his < $row['kill_his']) { + $kill_his = $row['kill_his']; + } + if ($harm_his < $row['harm_his']) { + $harm_his = $row['harm_his']; + } + if ($rank == 1) { + $row['win_times']++; + } + if ($alive_time_his < $row['alive_time_his']) { + $alive_time_his = $row['alive_time_his']; + } + if ($add_HP_his < $row['add_HP_his']) { + $add_HP_his = $row['add_HP_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, add_HP_his=:add_HP_his, coin_num=:coin_num, integral=:integral, modify_time=:modify_time, first_fight=1 ' . + ' WHERE accountid=:accountid;', + array( + ':game_times' => $row['game_times'] + 1, + ':win_times' => $row['win_times'], + ':kill_his' => $kill_his, + ':kills' => $row['kills'] + $kills, + ':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, + ':add_HP_his' => $add_HP_his, + ':accountid' => $account_id, + ':coin_num' => $row['coin_num'] + $coin_num, + ':integral' => $row['integral'] + $integral, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + + //插入历史记录 + $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) ' . + ' 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;', + array( + ':accountid' => $account_id, + ':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' => $harm, + ':hurts' => $hurt, + ':alive_time' => $alive_time, + ':coin' => $coin_num, + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + //刷新任务 + $quest = new classes\Quest(); + $quest->triggerQuest(QUEST_DAY_FIGHT, 1, 1, $account_id); + $quest->triggerQuest(QUEST_DAY_ALIVE, 1, (int)($alive_time / 1000 / 60), $account_id); + $quest->triggerQuest(QUEST_DAY_HARM, 1, $harm, $account_id); + $quest->triggerQuest(QUEST_DAY_KILL, 1, $kills, $account_id); + $quest->triggerQuest(QUEST_DAY_HELP, 1, $rescue_member, $account_id); + $quest->triggerQuest(QUEST_SUM_FIGHT, 2, 1, $account_id); + $quest->triggerQuest(QUEST_SUM_ALIVE, 2, (int)($alive_time / 1000 / 60), $account_id); + $quest->triggerQuest(QUEST_SUM_HARM, 2, $harm, $account_id); + $quest->triggerQuest(QUEST_SUM_KILL, 2, $kills, $account_id); + $quest->triggerQuest(QUEST_SUM_HELP, 2, $rescue_member, $account_id); + $quest->triggerQuest(QUEST_SUM_SNIPEKILL, 2, $snipe_kill, $account_id); + $quest->triggerQuest(QUEST_SUM_RIFLEKILL, 2, $rifle_kill, $account_id); + $quest->triggerQuest(QUEST_SUM_PISTOLKILL, 2, $pistol_kill, $account_id); + $quest->triggerQuest(QUEST_SUM_SUBMACKILL, 2, $submachine_kill, $account_id); + if ($team_status == 1 && $rank <= 5) { + $quest->triggerQuest(QUEST_DAY_RANK, 1, 1, $account_id); + } + if ($team_status == 0 && $rank == 1) { + $quest->triggerQuest(QUEST_SUM_WIM, 2, 1, $account_id); + } + if ($team_status == 1) { + $quest->triggerQuest(QUEST_DAY_TEAM, 1, 1, $account_id); + $quest->triggerQuest(QUEST_SUM_TEAM, 2, 1, $account_id); + if ($rank == 1) { + $quest->triggerQuest(QUEST_SUM_TEAMWIN, 2, 1, $account_id); + } + } + //触发活动任务 + /*$act = $this->getActivityRewardConfig(QUEST_ACTIVITY_LOGIN); + $array = $this->getExplode($act['start_end_time']); + $nowTime = phpcommon\getdayseconds(time()); + $start_time = $array[0][0] * 3600 + $array[0][1] * 60 + $nowTime; + $end_time = $array[1][0] * 3600 + $array[1][1] * 60 + $nowTime; + if (time() >= $start_time && time() < $start_time) { + $quest->triggerQuest(QUEST_ACTIVITY_GAME, 3, 1, $account_id); + }*/ + //额外奖励 + $times = $this->getRewardTimes($coin_num); + $extra_coin = $coin_num * ($times - 1); + $d = $this->getDrop(24004); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $skin_id_array = $this->getExplode($d['item_id']); + $weight_sum = 0; + $keys = 0; + $skin_num_array = $this->getExplode($d['num']); + $weight_array = $this->getExplode($d['weight']); + for ($i = 0; $i < count($weight_array); $i++) { + $weight_sum += $weight_array[$i][0]; + } + srand($room_uuid); + $random = Rand(0, $weight_sum); + $weight = 0; + for ($i = 0; $i < count($weight_array); $i++) { + $weight += $weight_array[$i][0]; + if ($weight > $random) { + $keys = $i; + break; + } + } + $extra_drop = ""; + $skin_id = $skin_id_array[$keys][0]; + $skin_num = $skin_num_array[$keys][0]; + $p_battle_reward = $this->getParameter(MAX_BATTLE_REWARD); + if ($row['battle_re_times'] >= $p_battle_reward['param_value']) { + $extra_drop = '10001:' . $extra_coin; + } else { + $extra_drop = '10001:' . $extra_coin . '|10002:1' . '|' . $skin_id . ':' . $skin_num; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'kill_his' => $kill_his, + 'alive_time_his' => $alive_time_his, + 'harm_his' => $harm_his, + 'add_HP_his' => $add_HP_his, + 'extra_drop' => $extra_drop + )); + } + + public function historyRecord() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $record_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $rowCount = $conn->execQueryRowCount('SELECT * FROM history_record WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if ($rowCount != 0) { + $rows = $conn->execQuery('SELECT * FROM history_record WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + foreach ($rows as $row) { + array_push($record_list, array( + 'map_name' => $row['map_name'], + 'game_time' => $row['game_time'], + 'rank' => $row['rank'], + 'kills' => $row['kills'], + 'harms' => $row['harms'], + 'hurts' => $row['hurts'], + 'alive_time' => $row['alive_time'] + )); + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'record_list' => $record_list + )); + } + + public function shareGame() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $quest = new classes\Quest(); + $quest->triggerQuest(QUEST_DAY_SHARE, 1, 1, $account_id); + $quest->triggerQuest(QUEST_SUM_SHARE, 2, 1, $account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + public function historyInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'kill_his' => $row['kill_his'], + 'alive_time_his' => $row['alive_time_his'], + 'harm_his' => $row['harm_his'], + 'add_HP_his' => $row['add_HP_his'] + )); + } + + public function fightReward() + { + $account_id = $_REQUEST['account_id']; + $room_uuid = $_REQUEST['room_uuid']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $record_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM history_record WHERE accountid=:accountid AND room_uuid=:room_uuid;', + array( + ':accountid' => $account_id, + ':room_uuid' => $room_uuid + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这场战斗记录'); + return; + } + + if ($row['status'] == 1) { + phpcommon\sendError(ERR_USER_BASE + 3, '战斗奖励已领取'); + return; + } + $coin_num = $row['coin']; + $times = $this->getRewardTimes($coin_num); + $coin_num = $row['coin'] * ($times - 1); + $d = $this->getDrop(24004); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $skin_id_array = $this->getExplode($d['item_id']); + $weight_sum = 0; + $keys = 0; + $skin_num_array = $this->getExplode($d['num']); + $weight_array = $this->getExplode($d['weight']); + for ($i = 0; $i < count($weight_array); $i++) { + $weight_sum += $weight_array[$i][0]; + } + srand($room_uuid); + $random = Rand(0, $weight_sum); + $weight = 0; + for ($i = 0; $i < count($weight_array); $i++) { + $weight += $weight_array[$i][0]; + if ($weight > $random) { + $keys = $i; + break; + } + } + $skin_id = $skin_id_array[$keys][0]; + $skin_num = $skin_num_array[$keys][0]; + $p_battle_reward = $this->getParameter(MAX_BATTLE_REWARD); + $addreward = new classes\AddReward(); + $addreward->addReward(10001, $coin_num, $account_id); + $rowUser = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if ($rowUser['battle_re_times'] < $p_battle_reward['param_value']) { + $keys_num = $rowUser['keys_num'] + 1; + $battle_re_times = $rowUser['battle_re_times'] + 1; + $addreward->addReward($skin_id, $skin_num, $account_id); + $ret = $conn->execScript('UPDATE user SET battle_re_times=:battle_re_times, keys_num=:keys_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':keys_num' => $keys_num, + ':battle_re_times' => $battle_re_times, + ':modify_time' => time(), + ':accountid' => $account_id + )); + if (!$ret) { + die(); + return; + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + protected function getRewardTimes($coin_num) + { + $g_conf_reward_cluster = require('../res/rewardTimes@rewardTimes.php'); + $times = 1; + $reward_conf = array(); + for ($i = 0; $i < 4; $i++) { + $reward_id = $i + 91100; + $reward_conf = getRewardTimesConfig($g_conf_reward_cluster, $reward_id); + if ((int)$coin_num >= $reward_conf['minGold'] && (int)$coin_num <= $reward_conf['maxGold']) { + $times = $reward_conf['times']; + break; + } + } + return $times; + } + + public function collectReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $record_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $ret = $conn->execScript('UPDATE user SET collect_status=1, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':modify_time' => time(), + ':accountid' => $account_id + )); + if (!$ret) { + die(); + return; + } + $d = $this->getDrop(24003); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $item_id_array = $this->getExplode($d['item_id']); + $num_array = $this->getExplode($d['num']); + $weight_array = $this->getExplode($d['weight']); + $i = 0; + $item_list = array(); + foreach ($weight_array as $item) { + if ($item[0] >= Rand(0, 10000)) { + $item_id = $item_id_array[0]; + $item_num = $num_array[0]; + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num + )); + } + $i++; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_list' => $item_list + )); + } + + public function collectDoubleReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $record_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $d = $this->getDrop(24003); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $item_id_array = $this->getExplode($d['item_id']); + $num_array = $this->getExplode($d['num']); + $weight_array = $this->getExplode($d['weight']); + $i = 0; + $item_list = array(); + foreach ($weight_array as $item) { + if ($item[$i][0] >= Rand(0, 10000)) { + $item_id = $item_id_array[$i][0]; + $item_num = $num_array[$i][0]; + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + } + $i++; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } +} +?> diff --git a/webapp/controller/ShareController.class.php b/webapp/controller/ShareController.class.php new file mode 100644 index 0000000..ce220c8 --- /dev/null +++ b/webapp/controller/ShareController.class.php @@ -0,0 +1,501 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getDrop($drop_id) + { + $drop_meta_table = require('../res/drop@drop.php'); + $drop_meta = getDropConfig($drop_meta_table, $drop_id); + $d = array( + 'drop_id' => $drop_meta['drop_id'], + 'item_id' => $drop_meta['item_id'], + 'num' => $drop_meta['num'], + 'weight' => $drop_meta['weight'], + 'type' => $drop_meta['type'] + ); + return $d; + } + + protected function getShare($share_id) + { + $share_meta_table = require('../res/share@share.php'); + $share_meta = getShareConfig($share_meta_table, $share_id); + $sh = array( + 'id' => $share_meta['id'], + 'rewards' => $share_meta['rewards'], + 'people' => $share_meta['people'], + ); + return $sh; + } + + protected function getExplode($string) + { + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; + } + + + protected function getParameter($para_id) + { + $parameter_meta_cluster = require('../res/parameter@parameter.php'); + $parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id); + $p = array( + 'id' => $parameter_meta['id'], + 'param_name' => $parameter_meta['param_name'], + 'param_value' => $parameter_meta['param_value'], + ); + return $p; + } + + public function keyBoxInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + //扣除钥匙 + $row = $conn->execQueryOne('SELECT keys_num FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + if ($row['keys_num'] < 1) { + phpcommon\sendError(ERR_USER_BASE + 3, '钥匙不足'); + die(); + return; + } + $ret = $conn->execScript('UPDATE user SET keys_num=:keys_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':keys_num' => $row['keys_num'] - 1, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + //随机奖励 + $free = $_REQUEST['free']; + $drop_id = 0; + if ($free != 0) { + $drop_id = 24002; + } else { + $drop_id = 24001; + } + $d = $this->getDrop($drop_id); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $item_id_array = $this->getExplode($d['item_id']); + $weight_sum = 0; + $keys = 0; + $item_num_array = $this->getExplode($d['num']); + $weight_array = $this->getExplode($d['weight']); + for ($i = 0; $i < count($weight_array); $i++) { + $weight_sum += $weight_array[$i][0]; + } + srand(crc32($account_id . $row['keys_num'])); + $random = Rand(0, $weight_sum); + $weight = 0; + for ($i = 0; $i < count($weight_array); $i++) { + $weight += $weight_array[$i][0]; + if ($weight > $random) { + $keys = $i; + break; + } + } + $item_id = $item_id_array[$keys][0]; + $item_num = $item_num_array[$keys][0]; + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + $item_list = array(); + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + )); + $quest = new classes\Quest(); + $quest->triggerQuest(71004, 1, 1, $account_id); + $quest->triggerQuest(72004, 2, 1, $account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_list' => $item_list, + 'keys_num' => $row['keys_num'] - 1 + )); + } + + public function keyBoxReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT keys_num FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + //随机奖励 + $free = $_REQUEST['free']; + $drop_id = 0; + if ($free != 0) { + $drop_id = 24002; + } else { + $drop_id = 24001; + } + $d = $this->getDrop($drop_id); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $item_id_array = $this->getExplode($d['item_id']); + $weight_sum = 0; + $keys = 0; + $item_num_array = $this->getExplode($d['num']); + $weight_array = $this->getExplode($d['weight']); + for ($i = 0; $i < count($weight_array); $i++) { + $weight_sum += $weight_array[$i][0]; + } + srand(crc32($account_id . $row['keys_num'])); + $random = Rand(0, $weight_sum); + $weight = 0; + for ($i = 0; $i < count($weight_array); $i++) { + $weight += $weight_array[$i][0]; + if ($weight > $random) { + $keys = $i; + break; + } + } + $item_id = $item_id_array[$keys][0]; + $item_num = $item_num_array[$keys][0]; + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + public function shareFriendInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $info_list = array(); + $rows = $conn->execQuery('SELECT ach_id, status FROM share_achievement WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (count($rows) == 0) { + $share_meta_table = require('../res/share@share.php'); + for ($i = 1; $i <= count($share_meta_table); $i++) { + $ret = $conn->execScript('INSERT INTO share_achievement(accountid, ach_id, status, create_time, modify_time) ' . + ' VALUES(:account_id, :ach_id, :status, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:account_id, ach_id=:ach_id, status=:status, modify_time=:modify_time;', + array( + ':account_id' => $account_id, + ':ach_id' => $i, + ':status' => 0, + ':create_time' => time(), + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + array_push($info_list, array( + 'achivement_id' => $i, + 'status' => 0 + )); + } + } else { + foreach ($rows as $row) { + array_push($info_list, array( + 'achivement_id' => $row['ach_id'], + 'status' => $row['status'] + )); + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'info_list' => $info_list + )); + } + + public function shareFriendReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $ach_id = $_REQUEST['ach_id']; + $double = $_REQUEST['double']; + $row = $conn->execQueryOne('SELECT status FROM share_achievement WHERE accountid=:accountid AND ach_id=:ach_id;', + array( + ':accountid' => $account_id, + ':ach_id' => $ach_id, + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + if ($row['status'] != 0) { + phpcommon\sendError(ERR_USER_BASE + 3, '奖励已领取'); + return; + } + //获取奖励信息 + $url = ''; + if (SERVER_ENV == _ONLINE) { + $url = 'https://service.kingsome.cn/webapp/index.php?c=AchievementShare&a=getInviteeNumSvr&'; + } else { + $url = 'https://service-test.kingsome.cn/webapp/index.php?c=AchievementShare&a=getInviteeNumSvr&'; + } + $timestamp = time(); + $params = array( + 'account_id' => $_REQUEST['account_id'], + 'achievement_ids' => $ach_id, + ); + $sign = phpcommon\md5Sign($params, + '70e32abc60367adccaa9eb7b56ed821b', + $timestamp); + $params['sign'] = $sign; + $params['timestamp'] = $timestamp; + $response = ''; + if (!phpcommon\HttpClient::get($url, $params, $response)) { + phpcommon\sendError(ERR_RETRY, '系统繁忙'); + return; + } + //领取奖励 + $data = json_decode($response, true); + $ach_list = $data['invitee_nums']; + $peo_num = 0; + $sh = $this->getShare($ach_id); + $num = 0; + if ($double != 0) { + $num = 2; + } else { + $num = 1; + } + foreach($ach_list as $ach){ + $ach_id = $ach['achievement_id']; + $peo_num = $ach['invitee_num']; + } + if ($peo_num == 0) { + phpcommon\sendError(ERR_USER_BASE + 4, '未达到人数要求'); + return; + } + $array = $this->getExplode($sh['rewards']); + $addreward = new classes\AddReward(); + $addreward->addReward($array[0][0], $array[0][1] * $num, $account_id); + //更新状态 + $ret = $conn->execScript('UPDATE share_achievement SET status=1, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND ach_id=:ach_id;', + array( + ':accountid' => $account_id, + ':modify_time' => time(), + ':ach_id' => $ach_id + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + public function getKefuReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $mail_id = $_REQUEST['mail_ids']; + + $url = ''; + if (SERVER_ENV == _ONLINE) { + $url = 'https://gamemail.kingsome.cn/webapp/index.php?c=Mail&a=getAttachment&'; + } else { + $url = 'https://gamemail-test.kingsome.cn/webapp/index.php?c=Mail&a=getAttachment&'; + } + $params = array( + 'account_id' => $_REQUEST['account_id'], + 'mail_ids' => $mail_id, + 'session_id' => $_REQUEST['session_id'] + ); + if (!phpcommon\HttpClient::get($url, $params, $response)) { + phpcommon\sendError(ERR_RETRY, '系统繁忙'); + return; + } + $row = $conn->execQueryOne('SELECT kefu_status FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + if ($row['kefu_status'] != 0) { + phpcommon\sendError(ERR_USER_BASE + 3, '客服奖励已领取'); + die(); + return; + } + $item_list = array(); + $item_id = 0; + $item_num = 0; + $data = json_decode($response, true); + $errcode = $data['errcode']; + $errmsg = $data['errmsg']; + if ($errcode == 0) { + foreach($data['attachments'] as $kefu){ + $item_id = $kefu['itemid']; + $item_num = $kefu['itemnum']; + } + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + )); + //更新状态 + $ret = $conn->execScript('UPDATE user SET kefu_status=1, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => time(), + )); + if (!$ret) { + die(); + return; + } + } + echo json_encode(array( + 'errcode' => $errcode, + 'errmsg' => $errmsg, + 'item_list' => $item_list + )); + } + + public function kefuDoubleReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $mail_id = $_REQUEST['mail_ids']; + $d = $this->getDrop(24005); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $item_id_array = $this->getExplode($d['item_id']); + $weight_sum = 0; + $keys = 0; + $item_num_array = $this->getExplode($d['num']); + $weight_array = $this->getExplode($d['weight']); + for ($i = 0; $i < count($weight_array); $i++) { + $weight_sum += $weight_array[$i][0]; + } + srand(crc32($account_id . $mail_id)); + $random = Rand(0, $weight_sum); + $weight = 0; + for ($i = 0; $i < count($weight_array); $i++) { + $weight += $weight_array[$i][0]; + if ($weight > $random) { + $keys = $i; + break; + } + } + $item_id = $item_id_array[$keys][0]; + $item_num = $item_num_array[$keys][0]; + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } +} +?> diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php new file mode 100644 index 0000000..be53dd8 --- /dev/null +++ b/webapp/controller/ShopController.class.php @@ -0,0 +1,378 @@ + $redis_conf['host'], + 'port' => $redis_conf['port'], + 'passwd' => $redis_conf['passwd'] + + )); + return $r; + } + + protected function getMysql($account_id) + { + $mysql_conf = getMysqlConfig(crc32($account_id)); + $conn = new phpcommon\Mysql(array( + 'host' => $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getItem($item_id) + { + $g_conf_item_cluster = require('../res/item@item.php'); + $item_conf = getItemConfig($g_conf_item_cluster, $item_id); + $it = array( + 'id' => $item_conf['id'], + 'price' => $item_conf['price'], + ); + return $it; + } + + protected function getShop($shop_id) + { + $g_conf_shop_cluster = require('../res/shop@shop.php'); + $shop_conf = getShopConfig($g_conf_shop_cluster, $shop_id); + $s = array( + 'shop_id' => $shop_conf['shop_id'], + 'item_id' => $shop_conf['item_id'], + 'num' => $shop_conf['num'], + 'item_weight' => $shop_conf['item_weight'], + 'discount' => $shop_conf['discount'], + 'discount_weight' => $shop_conf['discount_weight'], + 'tip' => $shop_conf['tip'], + ); + return $s; + } + + protected function getParameter($para_id) + { + $g_conf_para_cluster = require('../res/parameter@parameter.php'); + $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); + $p = array( + 'id' => $para_conf['id'], + 'param_name' => $para_conf['param_name'], + 'param_value' => $para_conf['param_value'], + ); + return $p; + } + + protected function getExplode($string) + { + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; + } + + public function shopInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $shop_uuid = 'game2001api_shop_uuid: ' . md5($_REQUEST['account_id']); + $shop_list = array(); + $r = $this->getRedis($shop_uuid); + if (!$r) { + die(); + return; + } + $user_db_str = $r->get($shop_uuid); + if (empty($user_db_str)) { + $shop_list = $this->randomShop(); + $shop_db = array( + 'shop_uuid' => $shop_uuid, + 'shop_list' => $shop_list, + ); + $r -> set($shop_uuid, json_encode($shop_db)); + $r -> pexpire($shop_uuid, 1000 * 3600 * 24); + } else { + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); + return; + } + foreach ($user_db['shop_list'] as $shop) { + array_push($shop_list, array( + 'shop_id' => $shop['shop_id'], + 'item_id' => $shop['item_id'], + 'item_num' => $shop['item_num'], + 'discount' => $shop['discount'], + 'price' => $shop['price'], + 'tip' => $shop['tip'], + 'status' => $shop['status'], + )); + } + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT shop_flush_times FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'shop_uuid' => $shop_uuid, + 'shop_list' => $shop_list, + 'shop_flush_times' => $row['shop_flush_times'], + )); + } + + public function buyItem() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $shop_id = $_REQUEST['shop_id']; + $shop_uuid = $_REQUEST['shop_uuid']; + $item_id = 0; + $item_num = 0; + $price = 0; + $status = 0; + $flag = 0; + $r = $this->getRedis($shop_uuid); + $user_db_str = $r->get($shop_uuid); + if (empty($user_db_str)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); + return; + } + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); + return; + } + foreach ($user_db['shop_list'] as $shop) { + if ($shop['shop_id'] == $shop_id) { + $item_id = $shop['item_id']; + $item_num = $shop['item_num']; + $price = $shop['price']; + $status = $shop['status']; + $flag = 1; + break; + } + } + if ($flag == 0) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个商品'); + return; + } + if ($status == 1) { + phpcommon\sendError(ERR_USER_BASE + 4, '商品已购买'); + return; + } + //扣除货币 + $this->SubCoin($price, $account_id); + //修改购买状态 + foreach ($user_db['shop_list'] as &$shop) { + if ($shop['shop_id'] == $shop_id) { + $shop['status'] = 1; + } + } + $r->set($shop_uuid, json_encode($user_db)); + //增加奖励 + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + )); + } + + public function flushShop() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $shop_uuid = $_REQUEST['shop_uuid']; + $shop_list = array(); + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT shop_flush_times FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $p_flush = $this->getParameter(MAX_SHOP_REFRESH); + if ($p_flush['param_value'] <= $row['shop_flush_times']) { + phpcommon\sendError(ERR_USER_BASE + 3, '今日刷新次数已满'); + return; + } + $ret = $conn->execScript('UPDATE user SET shop_flush_times=:shop_flush_times, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':shop_flush_times' => $row['shop_flush_times'] + 1, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $r = $this->getRedis($shop_uuid); + $user_db_str = $r->get($shop_uuid); + if (empty($user_db_str)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); + return; + } + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); + return; + } + if ($_REQUEST['type'] == 3) { + $p = $this->getParameter(RAND_SHOP_GOLD); + $this->SubCoin($p['param_value'], $account_id); + } + unset($user_db['shop_list']); + $shop_list = $this->randomShop(); + $user_db['shop_list'] = $shop_list; + $r -> set($shop_uuid, json_encode($user_db)); + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'shop_uuid' => $shop_uuid, + 'shop_list' => $shop_list, + 'shop_flush_times' => $row['shop_flush_times'] + 1 + )); + } + + protected function randomShop() + { + $shop_list = array(); + $g_conf_shop_cluster = require('../res/shop@shop.php'); + for ($i = 1; $i <= count($g_conf_shop_cluster); $i++) + { + $item_id = 0; + $item_num = 0; + $discount = 0; + $price = 0; + $key = 0; + $s = $this->getShop($i); + //确定商品id和数量 + $weight_sum = 0; + $weight_array = $this->getExplode($s['item_weight']); + for ($ii = 0; $ii < count($weight_array); $ii++) { + $weight_sum += $weight_array[$ii][0]; + } + $random = Rand(0, $weight_sum); + $weight = 0; + for ($ii = 0; $ii < count($weight_array); $ii++) { + $weight += $weight_array[$ii][0]; + if ($weight > $random) { + $key = $ii; + break; + } + } + $item_id_array = $this->getExplode($s['item_id']); + $num_array = $this->getExplode($s['num']); + $item_id = $item_id_array[$key][0]; + $item_num = $num_array[$key][0]; + //确定折扣和价格 + $it = $this->getItem($item_id); + if ($s['tip'] != 3) { + $discount = $s['discount']; + $price = $it['price']; + } else { + $keys = 0; + $weight_sum = 0; + $weight_array = $this->getExplode($s['discount_weight']); + for ($ii = 0; $ii < count($weight_array); $ii++) { + $weight_sum += $weight_array[$ii][0]; + } + $random = Rand(0, $weight_sum); + $weight = 0; + for ($ii = 0; $ii < count($weight_array); $ii++) { + $weight += $weight_array[$ii][0]; + if ($weight > $random) { + $keys = $ii; + break; + } + } + $discount_array = $this->getExplode($s['discount']); + $discount = $discount_array[$keys][0]; + $price = round($it['price'] * $item_num * ($discount * 1.0 / 10)); + } + array_push($shop_list, array( + 'shop_id' => $s['shop_id'], + 'item_id' => $item_id, + 'item_num' => $item_num, + 'discount' => $discount, + 'price' => $price, + 'tip' => $s['tip'], + 'status' => 0, + )); + } + return $shop_list; + } + + protected function subCoin($coin_num, $account_id) + { + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + //扣除货币 + $rowCoin = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if ($rowCoin['coin_num'] < $coin_num) { + phpcommon\sendError(ERR_USER_BASE + 5, '金币不足'); + die(); + } + $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $rowCoin['coin_num'] - $coin_num, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } +} +?> diff --git a/webapp/controller/SignController.class.php b/webapp/controller/SignController.class.php new file mode 100644 index 0000000..95a2f68 --- /dev/null +++ b/webapp/controller/SignController.class.php @@ -0,0 +1,268 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getSign($sign_id) + { + $g_conf_sign_cluster = require('../res/signDaily@signDaily.php'); + $sign_conf = getSignConfig($g_conf_sign_cluster, $sign_id); + $s = array( + 'sign_id' => $sign_conf['sign_id'], + 'condition' => $sign_conf['condition'], + 'item_id' => $sign_conf['item_id'], + 'num' => $sign_conf['num'], + ); + return $s; + } + + protected function getActivityRewardConfig($activityReward_id) + { + $g_conf_activityReward_cluster = require('../res/activityReward@activityReward.php'); + $activityReward_conf = getActivityRewardConfig($g_conf_activityReward_cluster, $activityReward_id); + $act = array( + 'id' => $activityReward_conf['id'], + 'activity_id' => $activityReward_conf['activity_id'], + 'condition' => $activityReward_conf['condition'], + 'parameter' => $activityReward_conf['parameter'], + 'start_end_time' => $activityReward_conf['start_end_time'], + 'activity_reward' => $activityReward_conf['activity_reward'], + 'exchange_num' => $activityReward_conf['exchange_num'], + 'exchange_item' => $activityReward_conf['exchange_item'] + ); + return $act; + } + + protected function getExplode($string) + { + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; + } + + protected function getParameter($para_id) + { + $g_conf_para_cluster = require('../res/parameter@parameter.php'); + $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); + $p = array( + 'id' => $para_conf['id'], + 'param_name' => $para_conf['param_name'], + 'param_value' => $para_conf['param_value'], + ); + return $p; + } + + public function signInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $sign_days = 0; + $signable = 1; + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $row1 = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + + $row = $conn->execQueryOne('SELECT * FROM sign WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $nowTime = phpcommon\getdayseconds(time()); + //触发活动任务 + /*$act = $this->getActivityRewardConfig(QUEST_ACTIVITY_LOGIN); + $array = $this->getExplode($act['start_end_time']); + $nowTime = phpcommon\getdayseconds(time()); + $start_time = $array[0][0] * 3600 + $array[0][1] * 60 + $nowTime; + $end_time = $array[1][0] * 3600 + $array[1][1] * 60 + $nowTime;*/ + if (!$row) { + $ret = $conn->execScript('INSERT INTO sign(accountid, sign_days, sign_time, create_time, modify_time) ' . + ' VALUES(:accountid, :sign_days, :sign_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, sign_days=:sign_days, sign_time=:sign_time, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':sign_days' => 0, + ':sign_time' => 0, + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $sign_days = 1; + $signable = 0; + $quest = new classes\Quest(); + $quest->triggerQuest(QUEST_DAY_LOGIN, 1, 1, $account_id); + $quest->triggerQuest(QUEST_SUM_LOGIN, 2, 1, $account_id); + /*if (time() >= $start_time && time() < $end_time) { + $quest->triggerQuest(QUEST_ACTIVITY_LOGIN, 3, 1, $account_id); + }*/ + } else { + if ($nowTime - phpcommon\getdayseconds($row['sign_time']) > 0) { + $sign_days = $row['sign_days'] + 1; + $signable = 0; + + //刷新每日任务和活动任务 + $rowCount = $conn->execQueryRowCount('SELECT * FROM quest WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if ($rowCount != 0) { + for ($i = 0; $i < $rowCount; $i++) { + $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, quest_num=:quest_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_type=:quest_type1 OR quest_type=:quest_type2;', + array( + ':accountid' => $account_id, + ':quest_num' => 0, + ':quest_type1' => 1, + ':quest_type2' => 3, + ':quest_state' => 0, + ':modify_time' => time() + )); + } + if (!$ret) { + die(); + return; + } + } + $quest = new classes\Quest(); + $quest->triggerQuest(QUEST_DAY_LOGIN, 1, 1, $account_id); + $quest->triggerQuest(QUEST_SUM_LOGIN, 2, 1, $account_id); + //刷新战斗结算奖励次数,商店刷新次数,客服 + $battle_ret = $conn->execScript('UPDATE user SET battle_re_times=0, shop_flush_times=0, kefu_status=0, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => time() + )); + if (!$battle_ret) { + die(); + return; + } + //刷新活动皮肤碎片收集状态 + /*$rowSkinCount = $conn->execQueryRowCount('SELECT * FROM skin WHERE accountid=:accountid AND skin_type=:skin_type;', + array( + ':accountid' => $account_id, + ':skin_type' => 2 + )); + if ($rowSkinCount != 0) { + for ($i = 0; $i < $rowSkinCount; $i++) { + $ret = $conn->execScript('UPDATE skin SET fragment_status=:fragment_status, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':fragment_status' => 0, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + }*/ + } else { + $sign_days = $row['sign_days']; + $signable = 1; + /*if (time() >= $start_time && time() < $end_time) { + $quest = new classes\Quest(); + $quest->triggerQuest(QUEST_ACTIVITY_LOGIN, 3, 1, $account_id); + }*/ + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'sign_days' => $sign_days, + 'signable' => $signable + )); + } + + public function signReward() + { + $account_id = $_REQUEST['account_id']; + $double = $_REQUEST['double']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM sign WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row || phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row['sign_time']) <= 0) { + phpcommon\sendError(ERR_USER_BASE + 2, '今日已签到'); + return; + } + $sign_days = $row['sign_days'] + 1; + $ret = $conn->execScript('UPDATE sign SET sign_time=:sign_time, sign_days=:sign_days, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':sign_days' => $sign_days, + ':sign_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + //获得奖励 + $g_conf_sign_cluster = require('../res/signDaily@signDaily.php'); + $day = $sign_days % count($g_conf_sign_cluster); + if ($day == 0) { + $day = count($g_conf_sign_cluster); + } + $s = $this->getSign($day + 90000); + $item_id = $s['item_id']; + $num = $s['num']; + if ($double == 1) { + $p_gold = $this->getParameter(DOUBLE_SIGN_IN); + $num = $num * $p_gold['param_value']; + } + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $num, $account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } +} +?> diff --git a/webapp/controller/SkinController.class.php b/webapp/controller/SkinController.class.php new file mode 100644 index 0000000..b9b23b1 --- /dev/null +++ b/webapp/controller/SkinController.class.php @@ -0,0 +1,517 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getSkin($skin_id) + { + $g_conf_skin_cluster = require('../res/dress@dress.php'); + $skin_conf = getSkinConfig($g_conf_skin_cluster, $skin_id); + $s = array( + 'skin_id' => $skin_conf['id'], + 'skin_name' => $skin_conf['name'], + 'skin_skillid' => $skin_conf['skill_id'], + 'skin_compose' => $skin_conf['compose'], + 'skin_experience' => $skin_conf['is_experience'], + 'skin_type' => $skin_conf['type'], + 'duration' => $skin_conf['duration'], + 'debris_id' => $skin_conf['debris'], + 'cost' => $skin_conf['cost'], + 'cost_int' => $skin_conf['cost_int'], + 'max_lv' => $skin_conf['max_lv'], + ); + return $s; + } + + protected function getExplode($string) + { + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; + } + + protected function getParameter($para_id) + { + $g_conf_para_cluster = require('../res/parameter@parameter.php'); + $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); + $p = array( + 'id' => $para_conf['id'], + 'param_name' => $para_conf['param_name'], + 'param_value' => $para_conf['param_value'], + ); + return $p; + } + + protected function updateActiveTime($row, $conn) + { + $skin_status = 0; + if ($row['skin_type'] == 1) { + $skin_status = 2; + } else if ($row['skin_type'] == 2) { + $skin_status = 3; + } + $ret = $conn->execScript('UPDATE skin SET active_time=0, skin_experience_level=0, skin_experience_type=0, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND skin_id=:skin_id;', + array( + ':account_id' => $row['accountid'], + ':skin_id' => $row['skin_id'], + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + if ($row['skin_status'] == 0 && $row['skin_experience_type'] == 1) { + $ret = $conn->execScript('UPDATE skin SET skin_status=:skin_status, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND skin_id=:skin_id;', + array( + ':account_id' => $row['accountid'], + ':skin_id' => $row['skin_id'], + ':skin_status' => $skin_status, + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + $ret = $conn->execScript('UPDATE skin SET skin_status=0, modify_time=:modify_time ' . + ' WHERE accountid = :account_id AND skin_id = 14001;', + array( + ':account_id' => $row['accountid'], + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + } + } + public function skinInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $skin_list = array(); + if(!$conn){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); + return; + } + $g_conf_skin_cluster = require('../res/dress@dress.php'); + $s = $this->getSkin(14001); + if(!$s){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤'); + return; + } + $rowCount = $conn->execQueryRowCount('SELECT * FROM skin WHERE accountid = :account_id;', + array( + ':account_id' => $account_id + )); + if ($rowCount == 0) { + for ($i = 14001; $i <= count($g_conf_skin_cluster) + 14000; $i++) { + $s = $this->getSkin($i); + if(!$s){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤'); + return; + } + if ($i == 14001) { + $skin_status = 0; + } else if ($s['skin_type'] == 2){ + $skin_status = 3; + } else { + $skin_status = 2; + } + $ret = $conn->execScript('INSERT INTO skin(accountid, skin_id, skin_status, fragment_id, fragment_num, active_time, fragment_status, skin_type, skin_level, skin_experience_level, skin_experience_type, create_time, modify_time) ' . + ' VALUES(:account_id, :skin_id, :skin_status, :fragment_id, 0, 0, 0, :skin_type, 1, 0, 0, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:account_id, skin_id=:skin_id, skin_status=:skin_status, fragment_id=:fragment_id, fragment_num=0, active_time=0, fragment_status=0, skin_type=:skin_type, skin_level=1, skin_experience_level=0, skin_experience_type=0, modify_time=:modify_time;', + array( + ':account_id' => $account_id, + ':skin_id' => $i, + ':skin_status' => $skin_status, + ':fragment_id' => $s['debris_id'], + ':skin_type' => $s['skin_type'], + ':create_time' => time(), + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + } + } + $time = 0; + $skin_level = 0; + $skin_experience_type = 0; + $skin_status = 0; + $rows = $conn->execQuery('SELECT * FROM skin WHERE accountid = :account_id;', + array( + ':account_id' => $account_id, + )); + + foreach ($rows as $row) { + $s = $this->getSkin($row['skin_id']); + if(time() >= $row['active_time'] && $row['active_time'] != 0){ + $this->updateActiveTime($row, $conn); + } + } + $rowsSkin = $conn->execQuery('SELECT * FROM skin WHERE accountid = :account_id;', + array( + ':account_id' => $account_id, + )); + $skin_id = 0; + foreach ($rowsSkin as $rowSkin) { + $s = $this->getSkin($rowSkin['skin_id']); + if ($skin_id == $rowSkin['skin_id']) { + continue; + } + $skin_id = $rowSkin['skin_id']; + if ($rowSkin['active_time'] != 0) { + $skin_level = $s['max_lv']; + $skin_experience_type = 2; + } else { + $skin_level = $rowSkin['skin_level']; + $skin_experience_type = 0; + } + array_push($skin_list, array( + 'skin_id' => $rowSkin['skin_id'], + 'skin_status' => $rowSkin['skin_status'], + 'fragment_num' => $rowSkin['fragment_num'], + 'active_time' => $rowSkin['active_time'], + 'skin_level' => $skin_level, + 'skin_experience_type' => $skin_experience_type + )); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'skin_list' => $skin_list + )); + } + + + public function unlockSkin() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $skin_id = $_REQUEST['skin_id']; + if(!$conn){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); + return; + } + $s = $this->getSkin($skin_id); + if(!$s){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤1'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM skin WHERE accountid = :account_id AND skin_id = :skin_id;', + array( + ':account_id' => $account_id, + ':skin_id' => $skin_id + )); + if(!$row){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤'); + return; + } + if ($row['skin_type'] != 1) { + phpcommon\sendError(ERR_USER_BASE + 2,'皮肤无法解锁'); + return; + } + $fragment_num = 0; + $array = $this->getExplode($s['skin_compose']); + if ($row['fragment_num'] < $array[0][1]) { + phpcommon\sendError(ERR_USER_BASE + 2,'皮肤碎片数量不足'); + return; + } + $fragment_num = $row['fragment_num'] - $array[0][1]; + + $skin_status = 1; + $active_time = 0; + $skin_experience_type = 0; + if ($row['skin_status'] == 0) { + $skin_status = 0; + } + if ($row['active_time'] != 0) { + $active_time = $row['active_time']; + $skin_experience_type = 2; + } + $ret = $conn->execScript('UPDATE skin SET fragment_num=:fragment_num ,skin_status=:skin_status, active_time=:active_time, skin_experience_type=:skin_experience_type, modify_time=:modify_time ' . + ' WHERE accountid = :account_id AND skin_id = :skin_id;', + array( + ':account_id' => $account_id, + ':skin_id' => $skin_id, + ':fragment_num' => $fragment_num, + ':skin_status' => $skin_status, + ':active_time' => $active_time, + ':skin_experience_type' => $skin_experience_type, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + /*"skin_id" => $skin_id, + "skin_status" => $skin_status, + "fragment_num" => $fragment_num, + "time" => $active_time, + "skin_level" => 1, + "skin_experience_type" => $skin_experience_type,*/ + )); + } + + public function exchangeSkin() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $usingskin_id = $_REQUEST['usingskin_id']; + $exchangeskin_id = $_REQUEST['exchangeskin_id']; + $conn = $this->getMysql($account_id); + if(!$conn){ + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $skin_status = 0; + $row = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:accountid AND skin_id=:skin_id;', + array( + ':accountid' => $account_id, + ':skin_id' => $usingskin_id, + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个皮肤'); + return; + } + if ($row['skin_experience_type'] == 0 || $row['skin_experience_type'] == 2) { + $skin_status = 1; + } else if ($row['skin_experience_type'] == 1) { + if ($row['skin_type'] == 1) { + $skin_status = 2; + } else if ($row['skin_type'] == 2) { + $skin_status = 3; + } + } + $using_ret = $conn->execScript('UPDATE skin SET skin_status=:skin_status, modify_time=:modify_time ' . + ' WHERE accountid = :account_id AND skin_id = :skin_id;', + array( + ':account_id' => $account_id, + ':skin_id' => $usingskin_id, + ':skin_status' => $skin_status, + ':modify_time' => time() + )); + + if(!$using_ret){ + die(); + return; + } + $exchange_ret = $conn->execScript('UPDATE skin SET skin_status=0, modify_time=:modify_time ' . + ' WHERE accountid = :account_id AND skin_id = :skin_id;', + array( + ':account_id' => $account_id, + ':skin_id' => $exchangeskin_id, + ':modify_time' => time() + )); + if(!$exchange_ret){ + die(); + return; + } + /*$skin_list = array(); + array_push($skin_list, array( + 'skin_id' => $row['skin_id'], + 'skin_status' => $skin_status, + 'fragment_num' => $row['fragment_num'], + 'active_time' => $row['active_time'], + 'skin_level' => $row['skin_level'], + 'skin_experience_type' => $row['skin_experience_type'] + )); + $row_exchange = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:accountid AND skin_id=:skin_id;', + array( + ':accountid' => $account_id, + ':skin_id' => $exchangeskin_id, + )); + array_push($skin_list, array( + 'skin_id' => $row_exchange['skin_id'], + 'skin_status' => 0, + 'fragment_num' => $row_exchange['fragment_num'], + 'active_time' => $row_exchange['active_time'], + 'skin_level' => $row_exchange['skin_level'], + 'skin_experience_type' => $row_exchange['skin_experience_type'] + )); + */ + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + //"skin_list" => $skin_list, + )); + } + + public function freetryskin() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $skin_id = $_REQUEST['skin_id']; + $row = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:accountid AND skin_id=:skin_id;', + array( + ':accountid' => $account_id, + ':skin_id' => $skin_id, + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个角色'); + return; + } + if(!$conn){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个角色'); + return; + } + $s = $this->getSkin($skin_id); + if(!$s){ + phpcommon\sendError(ERR_USER_BASE + 2,'没有这个皮肤'); + return; + } + $time = 0; + $ex_level = 0; + $ex_type = 0; + if ($s['skin_type'] == 2) { + $time = $s['duration']; + } + $ex_level = $s['max_lv']; + $p = $this->getParameter(SKIN_SKILL_TIME); + $time = $p['param_value']; + if ($row['skin_status'] <= 1) { + $ex_type = 2; + } else { + $ex_type = 1; + } + $ret = $conn->execScript('UPDATE skin SET active_time=:active_time, skin_experience_level=:skin_experience_level, skin_experience_type=:skin_experience_type, modify_time=:modify_time ' . + ' WHERE accountid = :account_id AND skin_id = :skin_id;', + array( + ':account_id' => $account_id, + ':skin_id' => $skin_id, + ':active_time' => time() + $time, + ':skin_experience_level' => $ex_level, + ':skin_experience_type' => $ex_type, + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + /*'skin_id' => $row['skin_id'], + 'skin_status' => $row['skin_status'], + 'fragment_num' => $row['fragment_num'], + 'active_time' => time() + $time, + 'skin_level' => $ex_level, + 'skin_experience_type' => 2*/ + )); + } + + public function updateSkin() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个角色'); + return; + } + $skin_id = $_REQUEST['skin_id']; + $free = $_REQUEST['free']; + $row = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:account_id AND skin_id=:skin_id;', + array( + ':account_id' => $account_id, + ':skin_id' => $skin_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 1, '皮肤不存在'); + return; + } + $s = $this->getSkin($skin_id); + if (!$s) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个皮肤'); + return; + } + if ($row['skin_level'] >= $s['max_lv']) { + phpcommon\sendError(ERR_USER_BASE + 3, '皮肤已到满级'); + return; + } + $debris_num = $s['cost'] * ceil($row['skin_level'] / 5) + $s['cost_int']; + if ($free == 1) { + $debris_num = 0; + } + if ($debris_num > $row['fragment_num']) { + phpcommon\sendError(ERR_USER_BASE + 4, '皮肤碎片数量不足'); + return; + } + $ret = $conn->execScript('UPDATE skin SET skin_level=:skin_level, fragment_num=:fragment_num, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND skin_id=:skin_id;', + array( + ':account_id' => $account_id, + ':skin_id' => $skin_id, + ':skin_level' => $row['skin_level'] + 1, + ':fragment_num' => $row['fragment_num'] - $debris_num, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + /*'skin_id' => $row['skin_id'], + 'skin_status' => $row['skin_status'], + 'fragment_num' => $row['fragment_num'] - $debris_num, + 'active_time' => $row['active_time'], + 'skin_level' => $row['skin_level'] + 1, + 'skin_experience_type' => $row['skin_experience_type']*/ + )); + } +} +?> diff --git a/webapp/controller/SupplyBoxController.class.php b/webapp/controller/SupplyBoxController.class.php new file mode 100644 index 0000000..551c913 --- /dev/null +++ b/webapp/controller/SupplyBoxController.class.php @@ -0,0 +1,403 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getSupplyBox($box_id) + { + $g_conf_supply_cluster = require('../res/supply@supply.php'); + $supply_conf = getSupplyConfig($g_conf_supply_cluster, $box_id); + $s = array( + 'id' => $supply_conf['id'], + 'drop' => $supply_conf['drop'], + 'num' => $supply_conf['num'], + 'drop_free' => $supply_conf['drop_free'], + 'num_free' => $supply_conf['num_free'], + 'price' => $supply_conf['price'], + 'parameter' => $supply_conf['parameter'], + ); + return $s; + } + + protected function getDrop($drop_id) + { + $g_conf_drop_cluster = require('../res/drop@drop.php'); + $drop_conf = getDropConfig($g_conf_drop_cluster, $drop_id); + $d = array( + 'drop_id' => $drop_conf['drop_id'], + 'item_id' => $drop_conf['item_id'], + 'num' => $drop_conf['num'], + 'weight' => $drop_conf['weight'], + 'type' => $drop_conf['type'] + ); + return $d; + } + + protected function getExplode($string) + { + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; + } + + protected function getParameter($para_id) + { + $g_conf_para_cluster = require('../res/parameter@parameter.php'); + $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); + $p = array( + 'id' => $para_conf['id'], + 'param_name' => $para_conf['param_name'], + 'param_value' => $para_conf['param_value'], + ); + return $p; + } + + public function supplyBoxInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + $box_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $rowCount = $conn->execQueryRowCount('SELECT * FROM supplybox WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + if ($rowCount != 0) { + $rows = $conn->execQuery('SELECT * FROM supplybox WHERE accountid = :account_id;', + array( + ':account_id' => $account_id + )); + foreach ($rows as $row) { + if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row['last_buy_time']) > 0) { + $ret = $conn->execScript('UPDATE supplybox SET free_times=0, buy_times=0, last_buy_time=:time, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND box_id=:box_id;', + array( + ':accountid' => $account_id, + ':box_id' => $row['box_id'], + ':time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + array_push($box_list, array( + 'box_id' => $row['box_id'], + 'buy_times' => $row['buy_times'], + 'free_times' => $row['free_times'] + )); + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'supplybox_list' => $box_list + )); + } + + + public function openSupplyBox() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $box_id = $_REQUEST['box_id']; + $free_open = $_REQUEST['free_open']; + $free_times = 0; + $buy_times = 0; + $s = $this->getSupplyBox($box_id); + if (!$s) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个宝箱'); + return; + } + $drop_id = 0; + if ($free_open == 0) { + $drop_id = $s['drop']; + } else { + $drop_id = $s['drop_free']; + } + $d = $this->getDrop($drop_id); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $item_list = array(); + $row = $conn->execQueryOne('SELECT * FROM supplybox WHERE accountid=:accountid AND box_id=:box_id;', + array( + ':accountid' => $account_id, + ':box_id' => $box_id + )); + if (!$row) { + if ($free_open == 0) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个宝箱'); + return; + } else if ($free_open == 1) { + $free_times = 1; + $buy_times = 0; + $ret = $conn->execScript('INSERT INTO supplybox(accountid, box_id, buy_times, free_times, last_buy_time, create_time, modify_time) ' . + ' VALUES(:accountid, :box_id, 0, 1, :last_buy_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, box_id=:box_id, buy_times=0, free_times=1, last_buy_time=:last_buy_time, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':box_id' => $box_id, + ':last_buy_time' => time(), + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + } + if ($free_open == 1) { + $p_times = $this->getParameter(FREE_DRESS_MAX_TIME); + if ($row['free_times'] >= $p_times['param_value']) { + phpcommon\sendError(ERR_USER_BASE + 3, '免费次数不足'); + return; + } + $free_times = $row['free_times'] + 1; + $buy_times = $row['buy_times']; + $ret = $conn->execScript('UPDATE supplybox SET free_times=:free_times, last_buy_time=:last_buy_time, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND box_id=:box_id;', + array( + ':accountid' => $account_id, + ':box_id' => $box_id, + ':free_times' => $free_times, + ':last_buy_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + //确定奖励倍数 + $sum = 0; + $mul = 0; + $array = $this->getExplode($s['num']); + for ($i = 0; $i < count($array); $i++) { + $sum += $array[$i][1]; + } + $rand = Rand(0, $sum); + $multiply = 0; + for ($i = 0; $i < count($array); $i++) { + $multiply += $array[$i][1]; + if ($multiply > $rand) { + $mul = $array[$i][0]; + break; + } + } + //发送奖励 + $weight_sum = 0; + $weight_array = $this->getExplode($d['weight']); + for ($i = 0; $i < count($weight_array); $i++) { + $weight_sum += $weight_array[$i][0]; + } + $random = Rand(0, $weight_sum); + $weight = 0; + for ($i = 0; $i < count($weight_array); $i++) { + $weight += $weight_array[$i][0]; + if ($weight > $random) { + $key = $i; + break; + } + } + + $item_id_array = $this->getExplode($d['item_id']); + + $num_array = $this->getExplode($d['num']); + $item_id = $item_id_array[$key][0]; + $item_num = $num_array[$key][0] * $mul; + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + )); + + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + + $quest = new classes\Quest(); + $quest->triggerQuest(71004, 1, 1, $account_id); + $quest->triggerQuest(72004, 2, 1, $account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_list' => $item_list, + /*'box_id' => $box_id, + 'buy_times' => $buy_times, + 'free_times' => $free_times*/ + )); + } + + public function buySupplyBox() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $box_id = $_REQUEST['box_id']; + $coin_num = 0; + $buy_times = 0; + $free_times = 0; + $s = $this->getSupplyBox($box_id); + if (!$s) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个宝箱'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM supplybox WHERE accountid=:account_id AND box_id=:box_id;', + array( + ':account_id' => $account_id, + ':box_id' => $box_id + )); + if (!$row) { + $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if ($row['coin_num'] < $s['price']) { + phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); + return; + } + $coin_num = $s['price']; + $buy_times = 1; + $free_times = 0; + $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $row['coin_num'] - $s['price'], + ':modify_time' => time() + )); + $ret = $conn->execScript('INSERT INTO supplybox(accountid, box_id, buy_times, free_times, last_buy_time, create_time, modify_time) ' . + ' VALUES(:accountid, :box_id, 1, 0, :last_buy_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, box_id=:box_id, buy_times=1, free_times=0, last_buy_time=0, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':box_id' => $box_id, + ':last_buy_time' => time(), + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } else { + $row1 = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + + if ($row1['coin_num'] < $s['price'] * pow($s['parameter'], ($row['buy_times']))) { + phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); + return; + } + $coin_num = $s['price'] * pow($s['parameter'], ($row['buy_times'])); + $buy_times = $row['buy_times'] + 1; + $free_times = $row['free_times']; + $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $row1['coin_num'] - $coin_num, + ':modify_time' => time() + )); + $ret = $conn->execScript('UPDATE supplybox SET buy_times=:buy_times, last_buy_time=:time, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND box_id=:box_id;', + array( + ':accountid' => $account_id, + ':box_id' => $box_id, + ':buy_times' => $row['buy_times'] + 1, + ':time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + /*"box_id" => $box_id, + "buy_times" => $buy_times, + "free_times" => $free_times, + "coin_num" => -$coin_num,*/ + )); + } + + public function supplyReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $item_id = $_REQUEST['item_id']; + $p_num = $this->getParameter(DOUBLE_BOX); + $item_num = $_REQUEST['item_num'] * ($p_num['param_value'] - 1); + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } +} +?> diff --git a/webapp/controller/TeamController.class.php b/webapp/controller/TeamController.class.php new file mode 100644 index 0000000..2daae7b --- /dev/null +++ b/webapp/controller/TeamController.class.php @@ -0,0 +1,307 @@ + $redis_conf['host'], + 'port' => $redis_conf['port'], + 'passwd' => $redis_conf['passwd'] + + )); + return $r; + } + + public function createTeam() + { + $node_id = 1; + if (isset($_REQUEST['node_id'])) { + $node_id = (int)$_REQUEST['node_id']; + } + $team_uuid = $node_id . '_' . md5($_REQUEST['account_id']) . time(); + + $team_db = array( + 'team_uuid' => $team_uuid, + 'auto_fill' => $_REQUEST['auto_fill'], + 'state' => 0, + 'member_list' => array( + array( + 'idx' => 1, + 'account_id' => $_REQUEST['account_id'], + 'name' => $_REQUEST['name'], + 'avatar_url' => $_REQUEST['avatar_url'], + ) + )); + + $r = $this->getRedis($team_uuid); + $r -> set(TEAMID_KEY . $team_uuid, json_encode($team_db)); + $r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600); + + echo json_encode (array( + 'errcode' => 0, + 'errmsg' => '', + 'team_uuid' => $team_uuid + )); + } + + public function teamInfo() + { + $team_uuid = $_REQUEST['team_uuid']; + $r = $this->getRedis($team_uuid); + + + $accountid = $_REQUEST['account_id']; + $sessionid = $_REQUEST['session_id']; + $user_db_str = $r->get(TEAMID_KEY . $team_uuid); + if (empty($user_db_str)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效1'); + return; + } + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效2'); + return; + } + $member_list = array(); + foreach ($user_db['member_list'] as $member) { + array_push($member_list, array( + 'idx' => $member['idx'], + 'account_id' => $member['account_id'], + 'name' => $member['name'], + 'avatar_url' => $member['avatar_url'], + )); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'team_uuid' => $team_uuid, + 'auto_fill' => $user_db['auto_fill'], + 'state' => $user_db['state'], + 'member_list' => $member_list, + )); + } + + + public function joinTeam() + { + $team_uuid = $_REQUEST['team_uuid']; + + $r = $this->getRedis($team_uuid); + + + $user_db_str = $r->get(TEAMID_KEY.$team_uuid); + + if (empty($user_db_str)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效1'); + return; + } + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session失效2'); + return; + } + $member_num = count($user_db['member_list']); + + if ($member_num >= 4) { + phpcommon\sendError(ERR_USER_BASE + 2,'队伍人数已满'); + return; + } + $flag = 0; + foreach ($user_db['member_list'] as $member) { + if ($member['account_id'] == $_REQUEST['account_id']) { + $flag = 1; + break; + } + } + if ($flag == 1) { + phpcommon\sendError(ERR_USER_BASE + 3,'已在队伍中'); + return; + } + + array_push ($user_db['member_list'], array( + 'idx' => $member_num + 1, + 'account_id' => $_REQUEST['account_id'], + 'name' => $_REQUEST['name'], + 'avatar_url' => $_REQUEST['avatar_url'], + )); + $r->set(TEAMID_KEY . $team_uuid, json_encode($user_db)); + + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + public function kickoutMember() + { + $team_uuid = $_REQUEST['team_uuid']; + $r = $this->getRedis($team_uuid); + if (!$r) { + echo 'is null'; + } else { + $user_db_str = $r->get(TEAMID_KEY . $team_uuid); + if (empty($user_db_str)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效1'); + return; + } + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效2'); + return; + } + $flag = 0; + foreach ($user_db['member_list'] as $member) { + if ($member['account_id'] == $_REQUEST['account_id']) { + if ($member['idx'] != 1) { + phpcommon\sendError(ERR_USER_BASE + 4,'你不是队长'); + return; + } + foreach ($user_db['member_list'] as $member) { + if ($member['account_id'] == $_REQUEST['member_id']) { + $flag = $member['idx'] - 1; + break; + } + } + break; + } + } + + unset($user_db['member_list'][$flag]); + $user_db['member_list'] = array_values($user_db['member_list']); + + $i = 1; + foreach ($user_db['member_list'] as &$memberlist) { + $memberlist['idx'] = $i; + $i++; + } + + $r->set(TEAMID_KEY . $team_uuid, json_encode($user_db)); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + public function leaveTeam() + { + $team_uuid = $_REQUEST['team_uuid']; + $r = $this->getRedis($team_uuid); + + if (!$r) { + echo 'is null'; + } else { + $user_db_str = $r->get(TEAMID_KEY . $team_uuid); + if (empty($user_db_str)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效1'); + return; + } + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效2'); + return; + } + $flag = 0; + foreach ($user_db['member_list'] as $member) { + if ($member['account_id'] == $_REQUEST['account_id']) { + $flag = $member['idx'] - 1; + break; + } + } + unset($user_db['member_list'][$flag]); + $user_db['member_list'] = array_values($user_db['member_list']); + + $i = 1; + foreach ($user_db['member_list'] as &$memberlist) { + $memberlist['idx'] = $i; + $i++; + } + + $r->set(TEAMID_KEY . $team_uuid, json_encode($user_db)); + if (count($user_db['member_list']) == 0) { + $r->del(TEAMID_KEY . $team_uuid, json_encode($user_db)); + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + public function updateTeam() + { + $team_uuid = $_REQUEST['team_uuid']; + $r = $this->getRedis($team_uuid); + + if (!$r){ + echo 'is null'; + } else { + $user_db_str = $r->get(TEAMID_KEY . $team_uuid); + + if (empty($user_db_str)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效1'); + return; + } + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效2'); + return; + } + foreach ($user_db['member_list'] as $member) { + if ($member['account_id'] == $_REQUEST['account_id']) { + if($member['idx'] != 1){ + phpcommon\sendError(ERR_USER_BASE + 4,'你不是队长'); + return; + } + } + } + $user_db['auto_fill'] = $_REQUEST['auto_fill']; + $r->set(TEAMID_KEY . $team_uuid, json_encode($user_db)); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + public function startGame() + { + $team_uuid = $_REQUEST['team_uuid']; + $r = $this->getRedis($team_uuid); + + if (!$r) { + echo 'is null'; + } else { + $user_db_str = $r->get(TEAMID_KEY . $team_uuid); + + if (empty($user_db_str)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效1'); + return; + } + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效2'); + return; + } + foreach ($user_db['member_list'] as $member) { + if ($member['account_id'] == $_REQUEST['account_id']) { + if($member['idx'] != 1) { + phpcommon\sendError(ERR_USER_BASE + 4,'你不是队长'); + return; + } + } + } + $user_db['state'] = $_REQUEST['state']; + $r->set(TEAMID_KEY . $team_uuid, json_encode($user_db)); + $r->pexpire(TEAMID_KEY . $team_uuid, 10 * 1000); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } +} +?> diff --git a/webapp/controller/VoiceController.class.php b/webapp/controller/VoiceController.class.php new file mode 100644 index 0000000..bca63b9 --- /dev/null +++ b/webapp/controller/VoiceController.class.php @@ -0,0 +1,52 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getRedis($accountid) + { + $redis_conf = getRedisConfig(crc32($accountid)); + $r = new phpcommon\Redis(array( + 'host' => $redis_conf['host'], + 'port' => $redis_conf['port'], + 'passwd' => $redis_conf['passwd'] + )); + return $r; + } + + public function upload() + { + $raw_data = file_get_contents('php://input'); + $data = base64_encode($raw_data); + $md5 = md5($data); + $r = $this->getRedis($md5); + $r->set('game2001:voice:' . $md5, $data); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'download_url' => "https://game2001api.kingsome.cn/webapp/index.php?c=Voice&a=download&res_id=" . $md5 + )); + } + + public function download() + { + $r = $this->getRedis($_REQUEST['res_id']); + $data = $r->get('game2001:voice:' . $_REQUEST['res_id']); + echo base64_decode($data); + } + +} + + diff --git a/webapp/index.php b/webapp/index.php new file mode 100644 index 0000000..19efba1 --- /dev/null +++ b/webapp/index.php @@ -0,0 +1,29 @@ +$a();'); +} catch (Exception $e){ + echo($e); +} diff --git a/webapp/phpcommon b/webapp/phpcommon new file mode 120000 index 0000000..0ee1d84 --- /dev/null +++ b/webapp/phpcommon @@ -0,0 +1 @@ +../third_party/phpcommon/ \ No newline at end of file