初始化垛垛牌
commit
914bc3923d
|
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
log4j.rootLogger = INFO,consoleAppender,fileAppender
|
||||||
|
|
||||||
|
# ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n
|
||||||
|
|
||||||
|
|
||||||
|
# Regular FileAppender
|
||||||
|
log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.fileAppender.File=${WORKDIR}/logs/evt_mgr.log
|
||||||
|
log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n
|
||||||
|
log4j.appender.fileAppender.Encoding=UTF-8
|
||||||
|
log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd
|
||||||
|
log4j.appender.dailyFile.Append=true
|
||||||
|
|
||||||
|
# The file is rolled over very day
|
||||||
|
log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serverSetting>
|
||||||
|
<dbSetting>
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxActive>80</maxActive>
|
||||||
|
<!-- 初始连接池大小, 默认0个 -->
|
||||||
|
<initialSize>2</initialSize>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>10</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认-1 -->
|
||||||
|
<maxWait>-1</maxWait>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 配置连接在池中最小生存的时间,默认180000-->
|
||||||
|
<minEvictableIdleTimeMillis>180000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒, 默认60000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>60000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 配置发生错误时多久重连,默认300000 -->
|
||||||
|
<timeBetweenConnectErrorMillis>30000</timeBetweenConnectErrorMillis>
|
||||||
|
<!-- 是否打开连接泄露自动检测, 默认false -->
|
||||||
|
<removeAbandoned>false</removeAbandoned>
|
||||||
|
<!-- 连接长时间没有使用,被认为发生泄露时长, 默认300000 -->
|
||||||
|
<removeAbandonedTimeoutMillis>300000</removeAbandonedTimeoutMillis>
|
||||||
|
<!-- 发生泄露时是否需要输出 log,建议在开启连接泄露检测时开启,方便排错 -->
|
||||||
|
<logAbandoned>false</logAbandoned>
|
||||||
|
<!-- 只要maxPoolPreparedStatementPerConnectionSize>0,poolPreparedStatements就会被自动设定为true,使用oracle时可以设定此值。 默认 10-->
|
||||||
|
<maxPoolPreparedStatementPerConnectionSize>-1</maxPoolPreparedStatementPerConnectionSize>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<dbList>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.jdbc.Driver</driverName>
|
||||||
|
<connectionString>jdbc:mysql://127.0.0.1:8060/wb_game</connectionString>
|
||||||
|
<userName>root</userName>
|
||||||
|
<password>root</password>
|
||||||
|
</db>
|
||||||
|
</dbList>
|
||||||
|
</dbSetting>
|
||||||
|
|
||||||
|
<redisSetting>
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>8</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>2</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="127.0.0.1" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="127.0.0.1" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="127.0.0.1" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db9" host="127.0.0.1" password="cssq@2020" port="6379" database="9" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="127.0.0.1" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
<info name="group1_db11" host="127.0.0.1" password="cssq@2020" port="6379" database="11" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
</redisSetting>
|
||||||
|
</serverSetting>
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.data</groupId>
|
||||||
|
<artifactId>data_cache</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-core</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用redis时导入 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>data_cache</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* account bean class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountBean extends BaseBean{
|
||||||
|
|
||||||
|
public String nick;
|
||||||
|
public String portrait;
|
||||||
|
public int type;
|
||||||
|
public int mng;
|
||||||
|
public int sex;
|
||||||
|
public String ip;
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> redis_map) {
|
||||||
|
String _id = redis_map.get("id");
|
||||||
|
if(StringUtil.isEmpty(_id)) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.id =Integer.parseInt(_id);
|
||||||
|
this.nick = redis_map.get("nick");
|
||||||
|
this.portrait = redis_map.get("portrait");
|
||||||
|
this.ip = redis_map.get("ip");
|
||||||
|
this.type = Integer.parseInt(redis_map.get("type"));
|
||||||
|
this.sex = Integer.parseInt(redis_map.get("sex"));
|
||||||
|
if(this.sex == 0)this.sex = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* base bean class.
|
||||||
|
*/
|
||||||
|
public class BaseBean {
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
public int id;
|
||||||
|
/**
|
||||||
|
* redis key
|
||||||
|
*/
|
||||||
|
public String redis_key;
|
||||||
|
/**
|
||||||
|
* cache version.
|
||||||
|
*/
|
||||||
|
public volatile long cache_ver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cache last time.
|
||||||
|
*/
|
||||||
|
public volatile long cache_time;
|
||||||
|
/**
|
||||||
|
* 标记是否删除
|
||||||
|
*/
|
||||||
|
public volatile boolean del;
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> map) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* game bean class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GameBean extends BaseBean{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* name
|
||||||
|
*/
|
||||||
|
public String name;
|
||||||
|
/**
|
||||||
|
* 最大人数
|
||||||
|
*/
|
||||||
|
public int maxPlayers;
|
||||||
|
/**
|
||||||
|
* 体力值类型
|
||||||
|
*/
|
||||||
|
public int hpType;
|
||||||
|
/**
|
||||||
|
* 包名
|
||||||
|
*/
|
||||||
|
public String bundle;
|
||||||
|
/**
|
||||||
|
* 局数设置
|
||||||
|
*/
|
||||||
|
public Map<Integer,Integer> opt;
|
||||||
|
/**
|
||||||
|
* 版本
|
||||||
|
*/
|
||||||
|
public String version;
|
||||||
|
|
||||||
|
public int gameType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务器列表
|
||||||
|
*/
|
||||||
|
public Set<String> svr_list;
|
||||||
|
/**
|
||||||
|
* 支付设置
|
||||||
|
*/
|
||||||
|
public Map<String,Integer> pay;
|
||||||
|
/**不可负分*/
|
||||||
|
public int isNonnegative ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> redis_map) {
|
||||||
|
// Map<String,String> redis_map = jedis.hgetAll(redis_key);
|
||||||
|
if(redis_map.isEmpty()) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.id = Integer.parseInt(redis_map.get("id"));
|
||||||
|
this.name = redis_map.get("name");
|
||||||
|
this.bundle = redis_map.get("bundle");
|
||||||
|
this.maxPlayers =Integer.parseInt(redis_map.get("maxPlayers"));
|
||||||
|
this.hpType =Integer.parseInt(redis_map.get("hpType"));
|
||||||
|
this.opt = new HashMap<>();
|
||||||
|
for(int i=1;i<=5;++i) {
|
||||||
|
String key = "opt"+i;
|
||||||
|
this.opt.put(i, Integer.parseInt(redis_map.get(key)));
|
||||||
|
}
|
||||||
|
this.version = redis_map.get("version");
|
||||||
|
this.gameType =Integer.parseInt( redis_map.get("gameType"));
|
||||||
|
this.isNonnegative = Integer.parseInt(redis_map.get("isNonnegative"));
|
||||||
|
this.svr_list = Redis.use("group1_db1").smembers("game_svr:" + id);
|
||||||
|
|
||||||
|
this.pay = new HashMap<>();
|
||||||
|
for (Entry<String, String> entry : redis_map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
if(key.startsWith("pay")) {
|
||||||
|
this.pay.put(key, Integer.parseInt(entry.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITObject getTObject() {
|
||||||
|
ITObject obj = TObject.newInstance();
|
||||||
|
obj.putInt("game_id", id);
|
||||||
|
obj.putString("name", name);
|
||||||
|
obj.putString("bundle", bundle);
|
||||||
|
obj.putInt("hpType", hpType);
|
||||||
|
obj.putString("version", version);
|
||||||
|
obj.putInt("gameType", gameType);
|
||||||
|
obj.putInt("isNonnegative", isNonnegative);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid) {
|
||||||
|
return "game:" + gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.data.cache.GroupPlayCache;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
|
public class GroupBean extends BaseBean {
|
||||||
|
|
||||||
|
private final static Logger log;
|
||||||
|
|
||||||
|
static {
|
||||||
|
log = Logger.getLogger(GroupBean.class);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* name
|
||||||
|
*/
|
||||||
|
public String name;
|
||||||
|
public int owner;
|
||||||
|
public int type;
|
||||||
|
public int create_time;
|
||||||
|
public int ban;
|
||||||
|
public int gms;
|
||||||
|
public int pay_type;
|
||||||
|
public int stop;
|
||||||
|
public int ban_apply;
|
||||||
|
public int dissolve_opt;
|
||||||
|
public int kick_opt;
|
||||||
|
public boolean ban_chat1;
|
||||||
|
public boolean ban_chat2;
|
||||||
|
public int exit_opt;
|
||||||
|
public int option;
|
||||||
|
public int show_num;
|
||||||
|
public GroupMemberCache memberCache;
|
||||||
|
|
||||||
|
public GroupPlayCache playCache;
|
||||||
|
public int isShow;
|
||||||
|
public int isOpenChatRoom;
|
||||||
|
public int isShowBeginRoom = 0;
|
||||||
|
|
||||||
|
// 微信号
|
||||||
|
public String wechatId;
|
||||||
|
|
||||||
|
public int isWatch;
|
||||||
|
|
||||||
|
public void fillData(Map<String, String> map) {
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int opt = Integer.parseInt(map.get("opt"));
|
||||||
|
if (opt != 1) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.id = Integer.parseInt(map.get("id"));
|
||||||
|
this.name = map.get("name");
|
||||||
|
this.type = Integer.parseInt(map.get("type"));
|
||||||
|
this.create_time = Integer.parseInt(map.get("create_time"));
|
||||||
|
this.ban = Integer.parseInt(map.get("ban"));
|
||||||
|
this.gms = Integer.parseInt(map.get("gms"));
|
||||||
|
this.owner = Integer.parseInt(map.get("owner"));
|
||||||
|
this.pay_type = Integer.parseInt(map.get("pay_type"));
|
||||||
|
this.wechatId = map.get("wechatId");
|
||||||
|
// this.messageCount =map.get("messageCount");
|
||||||
|
if (map.containsKey("wechatId")) {
|
||||||
|
this.wechatId = map.get("wechatId");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.containsKey("isOpenChatRoom")) {
|
||||||
|
this.isOpenChatRoom = Integer.parseInt(map.get("isOpenChatRoom"));
|
||||||
|
}
|
||||||
|
if (map.containsKey("isShowBeginRoom")) {
|
||||||
|
this.isShowBeginRoom = Integer.parseInt(map.get("isShowBeginRoom"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.containsKey("isWatch")) {
|
||||||
|
this.isWatch = Integer.parseInt(map.get("isWatch"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.containsKey("isShow")) {
|
||||||
|
this.isShow = Integer.parseInt(map.get("isShow"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.containsKey("stop")) {
|
||||||
|
this.stop = Integer.parseInt(map.get("stop"));
|
||||||
|
}
|
||||||
|
if (map.containsKey("ban_apply")) {
|
||||||
|
this.ban_apply = Integer.parseInt(map.get("ban_apply"));
|
||||||
|
}
|
||||||
|
kick_opt = Integer.parseInt(map.get("kick_opt"));
|
||||||
|
dissolve_opt = Integer.parseInt(map.get("dissolve_opt"));
|
||||||
|
if (map.containsKey("ban_chat1")) {
|
||||||
|
this.ban_chat1 = Boolean.parseBoolean(map.get("ban_chat1"));
|
||||||
|
}
|
||||||
|
if (map.containsKey("ban_chat2")) {
|
||||||
|
this.ban_chat2 = Boolean.parseBoolean(map.get("ban_chat2"));
|
||||||
|
}
|
||||||
|
if (map.containsKey("exit_opt")) {
|
||||||
|
this.exit_opt = Integer.parseInt(map.get("exit_opt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.containsKey("option")) {
|
||||||
|
this.option = Integer.parseInt(map.get("option"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.containsKey("show_num")) {
|
||||||
|
this.show_num = Integer.parseInt(map.get("show_num"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class GroupMemberBean extends BaseBean{
|
||||||
|
public int groupId;
|
||||||
|
public int parentId;
|
||||||
|
public int partnerLev;
|
||||||
|
public int lev;
|
||||||
|
public int ban;
|
||||||
|
public int top_time;
|
||||||
|
public int join_time;
|
||||||
|
public int last_time;
|
||||||
|
public int permission;
|
||||||
|
public int score;
|
||||||
|
public int mj_score;
|
||||||
|
public int pk_score;
|
||||||
|
public GroupMemberBean(int gid) {
|
||||||
|
this.groupId = gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> map) {
|
||||||
|
if(map.isEmpty()) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int opt = Integer.parseInt(map.get("opt"));
|
||||||
|
if(opt!=1) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.id = Integer.parseInt(map.get("uid"));
|
||||||
|
this.parentId = Integer.parseInt(map.get("parentId"));
|
||||||
|
this.partnerLev = Integer.parseInt(map.get("partnerLev"));
|
||||||
|
this.lev = Integer.parseInt(map.get("lev"));
|
||||||
|
this.ban = Integer.parseInt(map.get("ban"));
|
||||||
|
this.top_time = Integer.parseInt(map.get("top_time"));
|
||||||
|
this.join_time = Integer.parseInt(map.get("join_time"));
|
||||||
|
if(map.containsKey("last_time")) {
|
||||||
|
this.last_time = Integer.parseInt(map.get("last_time"));
|
||||||
|
}
|
||||||
|
if(map.containsKey("permission")) {
|
||||||
|
this.permission = Integer.parseInt(map.get("permission"));
|
||||||
|
}
|
||||||
|
if(map.containsKey("score")) {
|
||||||
|
this.score = Integer.parseInt(map.get("score"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,141 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.data.cache.GameCache;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
public class GroupPlayBean extends BaseBean {
|
||||||
|
public ITObject data = null;
|
||||||
|
public ITObject simp_data = null;
|
||||||
|
public int pay_type;
|
||||||
|
public int gameType;
|
||||||
|
public int gameId;
|
||||||
|
public int maxPlayers;
|
||||||
|
public String config;
|
||||||
|
public String hpConfig;
|
||||||
|
public int hp_times;
|
||||||
|
public int hpOnOff;
|
||||||
|
public int ban;
|
||||||
|
public boolean mark;
|
||||||
|
public String name;
|
||||||
|
public int deskId;
|
||||||
|
public int reward;
|
||||||
|
public int xipai_reward;
|
||||||
|
public int rewardType;
|
||||||
|
public int rewardValueType;
|
||||||
|
public int xipai_rewardType;
|
||||||
|
public int xipai_rewardValueType;
|
||||||
|
public int robot_room;
|
||||||
|
public ITObject configData;
|
||||||
|
|
||||||
|
public int BanChat;
|
||||||
|
public int BanMissile;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> map) {
|
||||||
|
if(!map.get("opt").equals("1")) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ITObject obj = data;
|
||||||
|
if(obj==null) {
|
||||||
|
obj = TObject.newInstance();
|
||||||
|
this.data = obj;
|
||||||
|
}
|
||||||
|
this.id = Integer.parseInt(map.get("id"));
|
||||||
|
this.name = map.get("name");
|
||||||
|
this.gameId = Integer.parseInt(map.get("gameId"));
|
||||||
|
this.config = map.get("config");
|
||||||
|
this.hpConfig = map.get("hpData");
|
||||||
|
this.hpOnOff = Integer.parseInt(map.get("hpOnOff"));
|
||||||
|
this.hp_times = Integer.parseInt(map.get("hp_times"));
|
||||||
|
this.ban = map.containsKey("ban") ? Integer.parseInt(map.get("ban")) : 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int iMark = map.containsKey("mark") ? Integer.parseInt(map.get("mark")) : 0;
|
||||||
|
this.mark = iMark==1 ? true : false;
|
||||||
|
|
||||||
|
this.reward = Integer.parseInt(map.get("reward"));
|
||||||
|
this.xipai_reward = 100000000;
|
||||||
|
if(map.get("xipai_reward") != null) {
|
||||||
|
this.xipai_reward = Integer.parseInt(map.get("xipai_reward"));
|
||||||
|
}
|
||||||
|
this.rewardType = Integer.parseInt(map.get("rewardType"));
|
||||||
|
this.rewardValueType = 1;
|
||||||
|
if(map.get("rewardValueType") != null) {
|
||||||
|
this.rewardValueType = Integer.parseInt(map.get("rewardValueType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.xipai_rewardType = 1;
|
||||||
|
if(map.get("xipai_rewardType") != null) {
|
||||||
|
this.xipai_rewardType = Integer.parseInt(map.get("xipai_rewardType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.xipai_rewardValueType = 1;
|
||||||
|
if(map.get("xipai_rewardValueType") != null) {
|
||||||
|
this.xipai_rewardValueType = Integer.parseInt(map.get("xipai_rewardValueType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.robot_room = 0;
|
||||||
|
if(map.get("robot_room") != null) {
|
||||||
|
this.robot_room = Integer.parseInt(map.get("robot_room"));
|
||||||
|
}
|
||||||
|
if(map.get("deskId") != null) {
|
||||||
|
this.deskId = Integer.parseInt(map.get("deskId"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.get("BanMissile") != null){
|
||||||
|
this.BanMissile = Integer.parseInt(map.get("BanMissile"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.get("BanChat") != null){
|
||||||
|
this.BanChat = Integer.parseInt(map.get("BanChat"));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.putInt("id", this.id);
|
||||||
|
obj.putString("name", this.name);
|
||||||
|
obj.putInt("gameId", gameId);
|
||||||
|
obj.putInt("deskId", this.deskId);
|
||||||
|
obj.putString("config", config);
|
||||||
|
obj.putString("hpData", hpConfig);
|
||||||
|
obj.putInt("hp_times", hp_times);
|
||||||
|
obj.putInt("hpOnOff", hpOnOff);
|
||||||
|
obj.putInt("reward", reward);
|
||||||
|
obj.putInt("xipai_reward", xipai_reward);
|
||||||
|
obj.putInt("rewardType", rewardType);
|
||||||
|
obj.putInt("rewardValueType", rewardValueType);
|
||||||
|
obj.putInt("xipai_rewardType", xipai_rewardType);
|
||||||
|
obj.putInt("xipai_rewardValueType", xipai_rewardValueType);
|
||||||
|
obj.putInt("ban", ban);
|
||||||
|
obj.putBoolean("mark", mark);
|
||||||
|
|
||||||
|
GameBean gb = GameCache.getGame(gameId);
|
||||||
|
obj.putString("game_name", gb.name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
configData = TObject.newFromJsonData(map.get("config"));
|
||||||
|
maxPlayers = gb.maxPlayers;
|
||||||
|
if(configData.containsKey("maxPlayers")) {
|
||||||
|
maxPlayers = configData.getInt("maxPlayers");
|
||||||
|
}
|
||||||
|
obj.putInt("maxPlayers", maxPlayers);
|
||||||
|
|
||||||
|
if(simp_data==null) {
|
||||||
|
simp_data = TObject.newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
simp_data.putInt("gameId", gameId);
|
||||||
|
simp_data.putInt("id", this.id);
|
||||||
|
simp_data.putInt("hpOnOff", obj.getInt("hpOnOff"));
|
||||||
|
simp_data.putInt("maxPlayers", maxPlayers);
|
||||||
|
simp_data.putString("name", obj.getString("name"));
|
||||||
|
simp_data.putInt("deskId", this.deskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import com.data.bean.AccountBean;
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* account cache class.
|
||||||
|
*/
|
||||||
|
public class AccountCache extends BaseCache{
|
||||||
|
|
||||||
|
protected AccountCache() {
|
||||||
|
super("{user}:","group1_db0");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static AccountCache inst;
|
||||||
|
|
||||||
|
|
||||||
|
public static AccountBean getAccount(int id) {
|
||||||
|
if(inst==null)inst = new AccountCache();
|
||||||
|
return inst.getBean(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AccountBean getAccount(String session) {
|
||||||
|
if(inst==null)inst = new AccountCache();
|
||||||
|
return inst.getBean(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
return new AccountBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearData() {
|
||||||
|
if(inst==null)inst = new AccountCache();
|
||||||
|
inst.clearExpireData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid) {
|
||||||
|
return "{user}:" + gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,229 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.data.bean.GroupBean;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* base cache class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class BaseCache {
|
||||||
|
private final static Logger log;
|
||||||
|
|
||||||
|
static {
|
||||||
|
log = Logger.getLogger(BaseCache.class);
|
||||||
|
}
|
||||||
|
private static final String VER_KEY= "cache_ver";
|
||||||
|
private static final String MAIN_KEY= "id";
|
||||||
|
protected ConcurrentMap<String, BaseBean> mapByKey = new ConcurrentHashMap<>();
|
||||||
|
protected ConcurrentMap<Integer, BaseBean> mapById = new ConcurrentHashMap<>();
|
||||||
|
protected String key;
|
||||||
|
protected String cacheKey;
|
||||||
|
protected int fillSize;
|
||||||
|
/**默认1秒*/
|
||||||
|
protected int readTime = 1000;
|
||||||
|
|
||||||
|
protected BaseCache(String key,String cacheKey) {
|
||||||
|
this.key = key;
|
||||||
|
this.cacheKey = cacheKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long readVersion(String str_ver) {
|
||||||
|
if(StringUtil.isEmpty(str_ver)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int cache_ver = Integer.parseInt(str_ver);
|
||||||
|
return cache_ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本KEY更新
|
||||||
|
* @param jedis
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
public static void updateCacheVer(Jedis jedis,String key) {
|
||||||
|
jedis.hincrBy(key, VER_KEY, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* new bean class
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract BaseBean newBean();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键KEY
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String mainKey() {
|
||||||
|
return MAIN_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BaseBean fillBean(BaseBean bean){
|
||||||
|
Jedis jedis = Redis.use(cacheKey).getJedis();
|
||||||
|
try {
|
||||||
|
String str_ver = null;
|
||||||
|
long cache_ver = -1;
|
||||||
|
if(System.currentTimeMillis() - bean.cache_time >= readTime) {
|
||||||
|
List<String> list = jedis.hmget(bean.redis_key, mainKey(),VER_KEY);
|
||||||
|
if(StringUtil.isEmpty(list.get(0))) {
|
||||||
|
bean.del = true;
|
||||||
|
}else {
|
||||||
|
str_ver = list.get(1);
|
||||||
|
cache_ver = readVersion(str_ver);
|
||||||
|
if(bean.cache_ver > 0 && cache_ver==-1) {
|
||||||
|
cache_ver = bean.cache_ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
bean.cache_time = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
cache_ver = bean.cache_ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!bean.del && (cache_ver == -1 || bean.cache_ver < cache_ver)) {
|
||||||
|
Map<String,String> map = jedis.hgetAll(bean.redis_key);
|
||||||
|
try {
|
||||||
|
if(map==null || map.size() == 0){
|
||||||
|
bean.del = true;
|
||||||
|
}else {
|
||||||
|
bean.fillData(map);
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new RuntimeException(bean.redis_key, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!bean.del) {
|
||||||
|
mapById.put(bean.id, bean);
|
||||||
|
mapByKey.put(bean.redis_key, bean);
|
||||||
|
bean.del = false;
|
||||||
|
str_ver = map.get(VER_KEY);
|
||||||
|
cache_ver = readVersion(str_ver);
|
||||||
|
bean.cache_ver = bean.cache_ver > cache_ver ? bean.cache_ver : cache_ver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bean.del) {
|
||||||
|
mapById.remove(bean.id);
|
||||||
|
mapByKey.remove(bean.redis_key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
jedis.close();
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String genKey(int id) {
|
||||||
|
String s_id = fillSize>0?(String.format("%0"+fillSize+"d", id)):(id+StringUtil.Empty);
|
||||||
|
String key = this.key + s_id;
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get bean by id
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends BaseBean> T getBean(int id){
|
||||||
|
String key = genKey(id);
|
||||||
|
synchronized (key) {
|
||||||
|
BaseBean bean = mapById.get(id);
|
||||||
|
if(bean==null) {
|
||||||
|
bean = newBean();
|
||||||
|
bean.id = id;
|
||||||
|
bean.redis_key = key;
|
||||||
|
}else {
|
||||||
|
if(bean.del) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (T) fillBean(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get bean by key
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends BaseBean> T getBean(String key){
|
||||||
|
synchronized (key) {
|
||||||
|
BaseBean bean = mapByKey.get(key);
|
||||||
|
if(bean==null) {
|
||||||
|
bean = newBean();
|
||||||
|
bean.redis_key = key;
|
||||||
|
}else {
|
||||||
|
if(bean.del) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (T) fillBean(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete bean by id
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean delBean(int id) {
|
||||||
|
BaseBean bean = mapById.get(id);
|
||||||
|
if(bean!=null) {
|
||||||
|
bean.del = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete bean by key
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean delBean(String key) {
|
||||||
|
BaseBean bean = mapByKey.get(key);
|
||||||
|
if(bean!=null) {
|
||||||
|
bean.del = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clear expire data
|
||||||
|
*/
|
||||||
|
public synchronized void clearExpireData() {
|
||||||
|
List<BaseBean> list = new ArrayList<>(mapById.values());
|
||||||
|
for(BaseBean bean : list) {
|
||||||
|
if(bean.del || System.currentTimeMillis() - bean.cache_time > 180000) {
|
||||||
|
bean.del = true;
|
||||||
|
mapById.remove(bean.id);
|
||||||
|
mapByKey.remove(bean.redis_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clear all
|
||||||
|
*/
|
||||||
|
public synchronized void clear() {
|
||||||
|
this.mapById.clear();
|
||||||
|
this.mapByKey.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.data.bean.GameBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* game cache class.
|
||||||
|
*/
|
||||||
|
public class GameCache extends BaseCache{
|
||||||
|
|
||||||
|
protected GameCache() {
|
||||||
|
super("game:","group1_db1");
|
||||||
|
}
|
||||||
|
|
||||||
|
static GameCache inst;
|
||||||
|
|
||||||
|
public static GameBean getGame(int id) {
|
||||||
|
if(inst==null) {
|
||||||
|
inst = new GameCache();
|
||||||
|
}
|
||||||
|
return inst.getBean(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GameBean getGame(String key) {
|
||||||
|
if(inst==null) {
|
||||||
|
inst = new GameCache();
|
||||||
|
}
|
||||||
|
return inst.getBean(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
return new GameBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearData() {
|
||||||
|
if(inst==null)inst = new GameCache();
|
||||||
|
inst.clearExpireData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid) {
|
||||||
|
return "game_" + gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,125 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.data.bean.GroupBean;
|
||||||
|
import com.data.bean.GroupMemberBean;
|
||||||
|
import com.data.bean.GroupPlayBean;
|
||||||
|
|
||||||
|
public class GroupCache extends BaseCache{
|
||||||
|
static GroupCache inst;
|
||||||
|
|
||||||
|
protected GroupCache() {
|
||||||
|
super("group:", "group1_db11");
|
||||||
|
this.readTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
return new GroupBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GroupCache me() {
|
||||||
|
if (inst == null) {
|
||||||
|
inst = new GroupCache();
|
||||||
|
}
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearData() {
|
||||||
|
me().clearExpireData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroupBean getGroup(int id) {
|
||||||
|
return me().getBean(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroupBean getGroup(String key) {
|
||||||
|
return me().getBean(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroupMemberBean getMember(int gid, int uid) {
|
||||||
|
GroupBean gb = getGroup(gid);
|
||||||
|
if (gb != null) {
|
||||||
|
synchronized (gb) {
|
||||||
|
if (gb.memberCache == null) {
|
||||||
|
gb.memberCache = new GroupMemberCache(gid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gb.memberCache.getBean(uid);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroupPlayBean getPlay(int gid, int pid) {
|
||||||
|
GroupBean gb = getGroup(gid);
|
||||||
|
if (gb != null) {
|
||||||
|
synchronized (gb) {
|
||||||
|
if (gb.playCache == null) {
|
||||||
|
gb.playCache = new GroupPlayCache(gid,gb.pay_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gb.playCache.getBean(pid);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genGroupsKey(int uid) {
|
||||||
|
return "groups:" + uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid) {
|
||||||
|
return "group:" + gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genRewardKey(int gid,int pid) {
|
||||||
|
return "g{" + gid+"}:reward:"+pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genXiPaiRewardKey(int gid,int pid) {
|
||||||
|
return "g{" + gid+"}:xipai_reward:"+pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genRoomsKey(int gid) {
|
||||||
|
return "g{" + gid+"}:rooms";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genPidsKey(int gid) {
|
||||||
|
return "g{" + gid + "}:pids";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genPlayKey(int gid,int pid) {
|
||||||
|
return "g{" + gid + "}:play:" + pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genBanKey(int gid,int uid) {
|
||||||
|
return "g{" + gid+"}:ban:"+uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genMemberListKey(int gid,int uid) {
|
||||||
|
return "g{"+gid+"}:member_list:"+uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genParListKey(int gid,int uid) {
|
||||||
|
return "g{"+gid+"}:par_list:"+uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genJoinsKey(int gid) {
|
||||||
|
return "gmjs_"+gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genRemarkKey(int gid) {
|
||||||
|
return "g{"+gid+"}:gremark";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genReadStatusKey(int gid) {
|
||||||
|
return "g{"+gid+"}:greadStatus";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genMailKey(int gid,int uid) {
|
||||||
|
return "g{"+gid+"}:mail:"+uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genMailTipKey(int gid) {
|
||||||
|
return "g{"+gid+"}:mail_tip";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.data.bean.GroupMemberBean;
|
||||||
|
|
||||||
|
public class GroupMemberCache extends BaseCache{
|
||||||
|
private static final String MAIN_KEY= "join_time";
|
||||||
|
private int groupId;
|
||||||
|
|
||||||
|
public GroupMemberCache(int gid) {
|
||||||
|
super("g{"+gid+"}:m", "group1_db10");
|
||||||
|
this.groupId = gid;
|
||||||
|
this.readTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
return new GroupMemberBean(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键KEY
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String mainKey() {
|
||||||
|
return MAIN_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid, int uid) {
|
||||||
|
return String.format("g{%s}:m%s", gid, uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,106 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.data.bean.GroupPlayBean;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
public class GroupPlayCache extends BaseCache{
|
||||||
|
private ITArray playList;
|
||||||
|
private ITArray simpPlayList;
|
||||||
|
private int groupId;
|
||||||
|
private long last_time;
|
||||||
|
private int pay_type;
|
||||||
|
private int gameType;
|
||||||
|
|
||||||
|
public GroupPlayCache(int groupId,int pay_type) {
|
||||||
|
super("g{"+groupId+"}:play:","group1_db11");
|
||||||
|
this.groupId = groupId;
|
||||||
|
this.pay_type = pay_type;
|
||||||
|
playList = TArray.newInstance();
|
||||||
|
simpPlayList = TArray.newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
GroupPlayBean p = new GroupPlayBean();
|
||||||
|
p.pay_type = pay_type;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update play data.
|
||||||
|
* @param play_data
|
||||||
|
*/
|
||||||
|
public void updatePlay() {
|
||||||
|
playList.clear();
|
||||||
|
simpPlayList.clear();
|
||||||
|
Set<Entry<Integer, BaseBean>> set = this.mapById.entrySet();
|
||||||
|
for(Entry<Integer, BaseBean> entry : set) {
|
||||||
|
GroupPlayBean gp =(GroupPlayBean)entry.getValue();
|
||||||
|
if(!gp.del) {
|
||||||
|
playList.addTObject(gp.data);
|
||||||
|
simpPlayList.addTObject(gp.simp_data);
|
||||||
|
}else {
|
||||||
|
this.mapById.remove(gp.id);
|
||||||
|
this.mapByKey.remove(gp.redis_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取玩法列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public final ITArray getPlayList(int lev){
|
||||||
|
/*if(System.currentTimeMillis() - last_time < 180000) {
|
||||||
|
if(lev < 3) {
|
||||||
|
return playList;
|
||||||
|
}else {
|
||||||
|
return simpPlayList;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
last_time = System.currentTimeMillis();
|
||||||
|
playList.clear();
|
||||||
|
simpPlayList.clear();
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
Jedis jedis1 = Redis.use("group1_db1").getJedis();
|
||||||
|
try {
|
||||||
|
String gpids_key = GroupCache.genPidsKey(groupId);
|
||||||
|
Set<String> pids = jedis11.zrangeByScore(gpids_key, 10, 11);
|
||||||
|
String key = "g{"+this.groupId + "}:play:";
|
||||||
|
for(String tem : pids) {
|
||||||
|
String gp_key = key+tem;
|
||||||
|
GroupPlayBean gp = this.getBean(gp_key);
|
||||||
|
if(gp!=null) {
|
||||||
|
String gkey = "game:"+gp.gameId ;
|
||||||
|
int gameType = Integer.parseInt(jedis1.hget(gkey,"gameType"));
|
||||||
|
//gp.gameType = gameType;
|
||||||
|
gp.data.putInt("gameType",gameType);
|
||||||
|
playList.addTObject(gp.data);
|
||||||
|
simpPlayList.addTObject(gp.simp_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}finally {
|
||||||
|
jedis11.close();
|
||||||
|
jedis1.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if(lev < 3) {
|
||||||
|
// return playList;
|
||||||
|
// }else {
|
||||||
|
// return simpPlayList;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return playList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
public class ConsumeCode {
|
||||||
|
|
||||||
|
/** 普通创建房间 **/
|
||||||
|
public final static int DIAMO_CREAT_ROOM = 1;
|
||||||
|
/** AA加入房 **/
|
||||||
|
public final static int DIAMO_JOIN_ROOM = 4;
|
||||||
|
/** 反还**/
|
||||||
|
public final static int DIAMO_REFUND = 5;
|
||||||
|
/** 代开房 **/
|
||||||
|
public final static int DIAMO_AGENT_ROOM = 2;
|
||||||
|
/** 结算 **/
|
||||||
|
public final static int HP_CLEARING = 6;
|
||||||
|
/** 抽水 **/
|
||||||
|
public final static int HP_PUMP = 7;
|
||||||
|
/** 管理员上分 **/
|
||||||
|
public final static int HP_MGR_UPPER = 8;
|
||||||
|
/** 管理员下分 **/
|
||||||
|
public final static int HP_MGR_SUB = 9;
|
||||||
|
/** 合伙人上分 **/
|
||||||
|
public final static int HP_PARTNER_UPPER = 10;
|
||||||
|
/** 合伙人下分 **/
|
||||||
|
public final static int HP_PARTNER_SUB = 11;
|
||||||
|
/** 合伙人奖励 **/
|
||||||
|
public final static int HP_PARTNER_REWARD = 12;
|
||||||
|
/** 转账 **/
|
||||||
|
public final static int HP_TRADE = 13;
|
||||||
|
/** 体力值提取 **/
|
||||||
|
public final static int HP_TAKE_REWARD = 14;
|
||||||
|
/**大局游戏hp的变化总值*/
|
||||||
|
public final static int HP_PUMP_TOTAL = 15;
|
||||||
|
/***/
|
||||||
|
public final static int HP_TAKE_BANK = 16;
|
||||||
|
|
||||||
|
public final static int HP_SAVE_BANK = 17;
|
||||||
|
|
||||||
|
/** 洗牌 **/
|
||||||
|
public final static int HP_XIPAI_PUMP = 20;
|
||||||
|
/** 合伙人洗牌奖励 **/
|
||||||
|
public final static int HP_PARTNER_XIPAI_REWARD = 21;
|
||||||
|
|
||||||
|
/** 邮件 **/
|
||||||
|
public final static int DIAMO_MAIL = 50;
|
||||||
|
/** 转盘**/
|
||||||
|
public final static int DIAMO_WHEEL = 51;
|
||||||
|
/** 分享**/
|
||||||
|
public final static int DIAMO_SH = 52;
|
||||||
|
/** 后台充值**/
|
||||||
|
public final static int DIAMO_ADD = 99;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,262 @@
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class CountUtil {
|
||||||
|
|
||||||
|
public static final int LOG_FOREVER = 0;
|
||||||
|
public static final int LOG_DAY = 1;
|
||||||
|
public static final int LOG_LASTDAY = 2;
|
||||||
|
public static final int LOG_WEEK = 3;
|
||||||
|
public static final int LOG_LASTWEEK = 4;
|
||||||
|
public static final int LOG_MONTH = 5;
|
||||||
|
public static final int LOG_LASTMONTH = 6;
|
||||||
|
|
||||||
|
private static final int DAY2 = 172800;
|
||||||
|
private static final int DAY3 = 259200;
|
||||||
|
private static final int DAY10 = 864000;
|
||||||
|
private static final int MONTH = 2592000;
|
||||||
|
// private static final int WEEK2 = 1209600;
|
||||||
|
private static final int MONTH2 = 2678400;
|
||||||
|
|
||||||
|
public static int getCountLog(String key,int type,Jedis jedis) {
|
||||||
|
String value = jedis.get(key);
|
||||||
|
if(StringUtil.isNotEmpty(value)) {
|
||||||
|
return Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取天数据
|
||||||
|
* @param key
|
||||||
|
* @param jedis
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getCountLogByDay(String key,Jedis jedis) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
String value = jedis.get(day_key);
|
||||||
|
if(StringUtil.isEmpty(value))return 0;
|
||||||
|
return Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLog(String key,int num,Jedis jedis) {
|
||||||
|
countLog(key,num,jedis,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void countLog(String key,int num,Pipeline pipeline) {
|
||||||
|
countLog(key,num,pipeline,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
* @param day_expire_month 天数据保存一个月
|
||||||
|
*/
|
||||||
|
public static void countLog(String key,int num,Jedis jedis,boolean day_expire_month) {
|
||||||
|
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
// String week_key = key + ":w"+DateUtils.getBeginWeek();
|
||||||
|
// String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
jedis.incrBy(day_key,num);
|
||||||
|
jedis.expire(day_key, day_expire_month?MONTH2:DAY10);
|
||||||
|
// jedis.incrBy(week_key,num);
|
||||||
|
// jedis.expire(week_key, WEEK2);
|
||||||
|
// jedis.incrBy(month_key,num);
|
||||||
|
// jedis.expire(month_key, MONTH2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
* @param day_expire_month 天数据保存一个月
|
||||||
|
*/
|
||||||
|
public static void countLog(String key,int num,Pipeline pipeline,boolean day_expire_month) {
|
||||||
|
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
// String week_key = key + ":w"+DateUtils.getBeginWeek();
|
||||||
|
// String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
pipeline.incrBy(day_key,num);
|
||||||
|
pipeline.expire(day_key, day_expire_month?MONTH2:DAY10);
|
||||||
|
// pipeline.incrBy(week_key,num);
|
||||||
|
// pipeline.expire(week_key, WEEK2);
|
||||||
|
// pipeline.incrBy(month_key,num);
|
||||||
|
// pipeline.expire(month_key, MONTH2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void countLog(String key,int num,Jedis jedis,boolean day_expire_month,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
jedis.incrBy(key,num);
|
||||||
|
}
|
||||||
|
countLog(key,num,jedis,day_expire_month);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void countLog(String key,int num,Pipeline pipeline,boolean day_expire_month,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
pipeline.incrBy(key,num);
|
||||||
|
}
|
||||||
|
countLog(key,num,pipeline,day_expire_month);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay(String key,int num,Jedis jedis) {
|
||||||
|
return countLogByDay(key,num,jedis,DAY10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay(String key,int num,Pipeline pipeline) {
|
||||||
|
countLogByDay(key,num,pipeline,DAY10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay30(String key,int num,Pipeline pipeline) {
|
||||||
|
|
||||||
|
countLogByDay(key,num,pipeline,MONTH);
|
||||||
|
|
||||||
|
String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
pipeline.incrBy(month_key,num);
|
||||||
|
pipeline.expire(month_key, MONTH2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay(String key,int num,Pipeline pipeline,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
pipeline.incrBy(key,num);
|
||||||
|
}
|
||||||
|
|
||||||
|
countLogByDay(key,num,pipeline,DAY10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存30天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay30(String key,int num,Pipeline pipeline,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
pipeline.incrBy(key,num);
|
||||||
|
}
|
||||||
|
|
||||||
|
countLogByDay(key,num,pipeline,MONTH);
|
||||||
|
|
||||||
|
String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
pipeline.incrBy(month_key,num);
|
||||||
|
pipeline.expire(month_key, MONTH2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay(String key,int num,Jedis jedis,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
jedis.incrBy(key,num);
|
||||||
|
}
|
||||||
|
|
||||||
|
return countLogByDay(key,num,jedis,DAY10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay(String key,int num,Jedis jedis,int time) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
|
||||||
|
long value = jedis.incrBy(day_key,num);
|
||||||
|
jedis.expire(day_key, time);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay(String key,int num,Pipeline pipeline,int time) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
|
||||||
|
pipeline.incrBy(day_key,num);
|
||||||
|
pipeline.expire(day_key, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存2天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay2(String key,int num,Jedis jedis) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
long value = jedis.incrBy(day_key,num);
|
||||||
|
jedis.expire(day_key, DAY2);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存2天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay3(String key,int num,Jedis jedis) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
long value = jedis.incrBy(day_key,num);
|
||||||
|
jedis.expire(day_key, DAY3);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,172 @@
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
public class ErrorCode {
|
||||||
|
// 成功
|
||||||
|
public final static int _SUCC = 0;
|
||||||
|
// 失败
|
||||||
|
public final static int _FAILED = 1;
|
||||||
|
/** session 不存在 */
|
||||||
|
public final static int _NO_SESSION = 2;
|
||||||
|
// 已经在房间可重连(创建房间协议)
|
||||||
|
public final static int BE_IN_ROOM = 3;
|
||||||
|
// 已创建房间可进入(创建房间协议)
|
||||||
|
public final static int CREATED_ROOM = 4;
|
||||||
|
// 不可选游<E98089>?
|
||||||
|
public final static int NO_GAME = 5;
|
||||||
|
// 无游戏服<E6888F>?
|
||||||
|
public final static int NO_SERVICE = 6;
|
||||||
|
// 缺钻<E7BCBA>?
|
||||||
|
public final static int NO_DIAMO = 7;
|
||||||
|
// 房间不可进入
|
||||||
|
public final static int ROOM_CLOSE = 10;
|
||||||
|
// 房间号错<E58FB7>?
|
||||||
|
public final static int NO_ROOM_NUM = 11;
|
||||||
|
// 邮件不存<E4B88D>?
|
||||||
|
public final static int NO_MAIL = 12;
|
||||||
|
// 邮件已领<E5B7B2>?
|
||||||
|
public final static int RECEIVED_MAIL = 13;
|
||||||
|
// 任务不存<E4B88D>?
|
||||||
|
public final static int NO_TASK = 14;
|
||||||
|
// 任务已领<E5B7B2>?
|
||||||
|
public final static int TASK_COMPLETE = 16;
|
||||||
|
// 缺奖<E7BCBA>?
|
||||||
|
public final static int NO_RAFFLE = 17;
|
||||||
|
// 没有战绩
|
||||||
|
public final static int NO_MILITARY = 19;
|
||||||
|
// 没有回放
|
||||||
|
public final static int NO_REC = 25;
|
||||||
|
//多次登录失败,禁止登录, 半个小时后再试
|
||||||
|
public final static int BAN_LOGIN = 28;
|
||||||
|
|
||||||
|
/** 无效的手机号码 **/
|
||||||
|
public final static int INVALID_PHONE = 58;
|
||||||
|
/** 无效的验证码 **/
|
||||||
|
public final static int INVALID_CODE = 59;
|
||||||
|
/** 手机号码已发短信手机不一致 **/
|
||||||
|
public final static int ATYPISM_PHONE = 60;
|
||||||
|
/** 手机号码已绑定玩家 **/
|
||||||
|
public final static int BINDED_PHONE = 61;
|
||||||
|
/** 该手机号码未绑定游戏 **/
|
||||||
|
public final static int NO_BINDED_PHONE = 62;
|
||||||
|
/** ACC已存在 **/
|
||||||
|
public final static int EXIST_ACC = 63;
|
||||||
|
|
||||||
|
|
||||||
|
/** 房间已删除 */
|
||||||
|
public final static int ROOM_DEL = 80;
|
||||||
|
/** 是圈子房间 */
|
||||||
|
public final static int ROOM_IS_GROUP = 81;
|
||||||
|
/** 玩家申请解散已达上限次数 **/
|
||||||
|
public final static int ROOM_DIS_UPPER_LIMIT = 82;
|
||||||
|
/** 坐下体力值不足*/
|
||||||
|
public final static int ROOM_NOT_HP = 83;
|
||||||
|
/** 是否禁止解散房间*/
|
||||||
|
public final static int ROOM_DIS_NOT_ALLOWED = 84;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** 是否已申请加入 */
|
||||||
|
public final static int GROUP_JOIN_EXIST = 1000;
|
||||||
|
/** 成员已存在 */
|
||||||
|
public final static int GROUP_MEMBER_EXIST = 1001;
|
||||||
|
/** 成员不存在 */
|
||||||
|
public final static int GROUP_NOT_MEMBER = 1002;
|
||||||
|
/** 成员存在上级合伙人 */
|
||||||
|
public final static int GROUP_MEMBER_EXIST_PARTENER = 1003;
|
||||||
|
/** 玩法已满 */
|
||||||
|
public final static int GROUP_PLAY_FULL = 1004;
|
||||||
|
/** 房间被删除 */
|
||||||
|
public final static int GROUP_ROOM_DEL = 1005;
|
||||||
|
/** 玩法不存在 */
|
||||||
|
public final static int GROUP_PLAY_EXIST = 1007;
|
||||||
|
/** 不是管理员 */
|
||||||
|
public final static int GROUP_MGR_EXIST = 1008;
|
||||||
|
/** 合伙人有成员 */
|
||||||
|
public final static int GROUP_PARTNER_MEMBERS = 1009;
|
||||||
|
/** 目标是管理员 */
|
||||||
|
public final static int GROUP_TAG_ISMGR = 1010;
|
||||||
|
/** 目标是合伙人 */
|
||||||
|
public final static int GROUP_TAG_ISPARTENER = 1011;
|
||||||
|
/** 目标体力值不够 */
|
||||||
|
public final static int GROUP_TAG_NO_HP = 1012;
|
||||||
|
/** 操作人体力值不够 */
|
||||||
|
public final static int GROUP_TAG_MGR_HP = 1013;
|
||||||
|
/** 没有权限 */
|
||||||
|
public final static int GROUP_NOT_PERMISSION = 1014;
|
||||||
|
/** 体力值不为0 */
|
||||||
|
public final static int GROUP_HP_NOT_0 = 1015;
|
||||||
|
/** 成员在房间内 */
|
||||||
|
public final static int GROUP_MEMBER_ROOM_EXIST = 1016;
|
||||||
|
/** 成员体力值事件正在执行 */
|
||||||
|
public final static int GROUP_MEMBER_HPEVT_RUNING = 1017;
|
||||||
|
/** 圈子不存在 */
|
||||||
|
public final static int GROUP_NO_EXIST = 1018;
|
||||||
|
/** 圈子已满 */
|
||||||
|
public final static int GROUP_FULL = 1019;
|
||||||
|
/** 圈子还有房间 */
|
||||||
|
public final static int GROUP_EXIST_ROOMS = 1020;
|
||||||
|
/** 圈子禁止娱乐 */
|
||||||
|
public final static int GROUP_BAN = 1021;
|
||||||
|
/** 不是圈主 */
|
||||||
|
public final static int GROUP_NOT_OWNER = 1022;
|
||||||
|
/** 目標玩家是合伙人 */
|
||||||
|
public final static int GROUP_ALREADY_PARTNER = 1023;
|
||||||
|
/** 目標玩家不是合伙人 */
|
||||||
|
public final static int GROUP_NOT_PARTNER = 1024;
|
||||||
|
/** 圈子成员禁止娱乐 */
|
||||||
|
public final static int GROUP_MEMBER_BAN = 1025;
|
||||||
|
/** 进入房间体力值不足 */
|
||||||
|
public final static int GROUP_LIMIT_NO_HP = 1026;
|
||||||
|
/** 大联盟只能创建一个 */
|
||||||
|
/** 大联盟只能创建5个 */
|
||||||
|
public final static int GROUP_TYPE2_ONLY_1 = 1027;
|
||||||
|
/** 大联盟必须开启体力值 */
|
||||||
|
public final static int GROUP_TYPE2_MUST_HP = 1028;
|
||||||
|
/** 改玩法还存在房间 */
|
||||||
|
public final static int GROUP_PLAY_EXIST_ROOM = 1029;
|
||||||
|
/** 不在此圈子房间中 */
|
||||||
|
public final static int GROUP_NOT_CURGROUP_ROOM = 1030;
|
||||||
|
/** 玩家关闭被邀请 */
|
||||||
|
public final static int GROUP_CLOSE_INVITATION = 1031;
|
||||||
|
/** 圈子已满 */
|
||||||
|
public final static int GROUP_IS_FULL = 1032;
|
||||||
|
/** 圈子成员已满 */
|
||||||
|
public final static int GROUP_MEMBER_IS_FULL = 1033;
|
||||||
|
/** 玩家正在游戏 不能上下分 **/
|
||||||
|
public final static int GROUP_DONOT_SUB_HP = 1034;
|
||||||
|
/** 奖励池体力值不足 **/
|
||||||
|
public final static int GROUP_REWARD_NO_HP = 1035;
|
||||||
|
/** 奖励池没提取 **/
|
||||||
|
public final static int GROUP_REWARD_NO_TAKE = 1036;
|
||||||
|
/** 禁止同桌 **/
|
||||||
|
public final static int GROUP_BAN_DESK = 1037;
|
||||||
|
/** 玩法禁止娱乐 **/
|
||||||
|
public final static int GROUP_BAN_PLAY = 1038;
|
||||||
|
/** 禁止申请加入圈子 **/
|
||||||
|
public final static int GROUP_BAN_APPLY = 1039;
|
||||||
|
/** 圈子停止服务 **/
|
||||||
|
public final static int GROUP_STOP_SERVICE = 1040;
|
||||||
|
/** 大联盟不能退出 **/
|
||||||
|
public final static int GROUP_TYPE2_NOT_EXIT = 1041;
|
||||||
|
/** 玩法存在推广奖励 **/
|
||||||
|
public final static int GROUP_PAY_TYPE3_EXIST = 1042;
|
||||||
|
/** 全民推广已开启,不能转移 **/
|
||||||
|
public final static int GROUP_PROMOTION_ACTIVE = 1043;
|
||||||
|
/** 全民推广为开启 **/
|
||||||
|
public final static int GROUP_PROMOTION_NOT_ACTIVE = 1044;
|
||||||
|
/** 有下级合伙人给其合伙人的分成高于此比例 **/
|
||||||
|
public final static int GROUP_HAS_MEMBER_OVERFLOW = 1045;
|
||||||
|
/** 合伙人体力值不足 **/
|
||||||
|
public final static int GROUP_PARTNER_HP_NOT_ENOUGH = 1046;
|
||||||
|
/** 体力值超越上线, 请保存到保险箱里 **/
|
||||||
|
public final static int GROUP_PARTNER_HP_THAN_LIMIET = 1047;
|
||||||
|
/** 玩家体力值超越上线, 请提醒他保存到上线 **/
|
||||||
|
public final static int GROUP_PARTNER_OTHER_HP_THAN_LIMIET = 1048;
|
||||||
|
|
||||||
|
//禁止表情
|
||||||
|
public final static int GROUP_BAN_EMOJI = 1049;
|
||||||
|
|
||||||
|
|
||||||
|
//禁止聊天
|
||||||
|
public final static int GROUP_BAN_CHAT = 1050;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
public class EventType {
|
||||||
|
/**
|
||||||
|
* 扣房卡事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_PAY = 1;
|
||||||
|
/**
|
||||||
|
* 反还房卡事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_BACK_PAY = 4;
|
||||||
|
/**
|
||||||
|
* 赢事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_WIN = 2;
|
||||||
|
/**
|
||||||
|
* 输事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_LOSE = 3;
|
||||||
|
/**
|
||||||
|
* 游戏结束事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_OVER = 5;
|
||||||
|
/**
|
||||||
|
* 牌友圈局数事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_ROUND = 6;
|
||||||
|
/**
|
||||||
|
* 牌友圈成员局数事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_MEMBER_ROUND = 7;
|
||||||
|
/**
|
||||||
|
* 牌友圈体力值事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_HP = 8;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_HP_DB = 90;
|
||||||
|
/**
|
||||||
|
* 邮件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_MAIL = 95;
|
||||||
|
/**
|
||||||
|
* 转盘
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_WHEEL = 96;
|
||||||
|
/**
|
||||||
|
* 圈子创房
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_ROOM = 97;
|
||||||
|
/**
|
||||||
|
* 普通创房
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_CREATE_ROOM = 98;
|
||||||
|
/**
|
||||||
|
* 后台充钻石
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_ADDPAY = 99;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,399 @@
|
||||||
|
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.data.bean.GameBean;
|
||||||
|
import com.data.bean.GroupMemberBean;
|
||||||
|
import com.data.cache.GameCache;
|
||||||
|
import com.data.cache.GroupCache;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import jdk.nashorn.internal.objects.Global;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
public class Utility {
|
||||||
|
/**
|
||||||
|
* API 版本
|
||||||
|
*/
|
||||||
|
public static int API_VER = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取战绩数据
|
||||||
|
*
|
||||||
|
* @param jedis5
|
||||||
|
* @param key
|
||||||
|
* @param platform
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public final static ITObject getMilitaryList(Jedis jedis5, String key, String platform) {
|
||||||
|
Map<String, String> military = jedis5.hgetAll(key);
|
||||||
|
if (military == null || military.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ITObject obj = TObject.newInstance();
|
||||||
|
obj.putString("military_id", key);
|
||||||
|
String strData = military.get("game_id");
|
||||||
|
if (strData == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
obj.putString("game_id", strData);
|
||||||
|
obj.putString("room_id", military.get("room_id"));
|
||||||
|
obj.putString("round", military.get("round"));
|
||||||
|
obj.putString("agreeDismisUserId", military.get("agreeDismisUserId"));
|
||||||
|
obj.putString("applyDismisUserId", military.get("applyDismisUserId"));
|
||||||
|
obj.putInt("dismisType", military.get("dismisType") == null ? 0 : Integer.parseInt(military.get("dismisType")));
|
||||||
|
|
||||||
|
// obj.putString("is_read", military.get("is_read"));
|
||||||
|
String totalScore = military.get("totalScore");
|
||||||
|
ITArray players = TArray.newFromJsonData(totalScore);
|
||||||
|
for (int j = 0; j < players.size(); j++) {
|
||||||
|
ITObject player = players.getTObject(j);
|
||||||
|
int playerId = player.getInt("accId");
|
||||||
|
obj.putString("is_read_" + playerId, military.get("is_read_" + playerId));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int hp_times = 10;
|
||||||
|
if (military.containsKey("hp_times")) {
|
||||||
|
hp_times = Integer.parseInt(military.get("hp_times"));
|
||||||
|
}
|
||||||
|
int groupPid = 0;
|
||||||
|
String pname = "";
|
||||||
|
if (military.containsKey("groupPid")) {
|
||||||
|
groupPid = Integer.parseInt(military.get("groupPid"));
|
||||||
|
pname = military.get("groupPname");
|
||||||
|
}
|
||||||
|
obj.putString("pname", pname);
|
||||||
|
|
||||||
|
obj.putDouble("valid_diamo",
|
||||||
|
military.get("valid_diamo") == null ? 0 : Double.parseDouble(military.get("valid_diamo")));
|
||||||
|
|
||||||
|
obj.putInt("hp_times", hp_times);
|
||||||
|
obj.putInt("groupPid", groupPid);
|
||||||
|
GameBean gb = GameCache.getGame(Integer.parseInt(strData));
|
||||||
|
ITObject gameObj = gb.getTObject();
|
||||||
|
obj.putTObject("game_info", gameObj);
|
||||||
|
obj.putString("create_time", military.get("create_time"));
|
||||||
|
strData = military.get("totalScore");
|
||||||
|
String strDatas = military.get("hpData");
|
||||||
|
obj.putString("hpData", strDatas);
|
||||||
|
if (strData != null) {
|
||||||
|
obj.putString("totalScore", strData);
|
||||||
|
}
|
||||||
|
String hpOnOff = military.get("hpOnOff");
|
||||||
|
if (StringUtil.isNotEmpty(hpOnOff)) {
|
||||||
|
obj.putInt("hpOnOff", Integer.parseInt(hpOnOff));
|
||||||
|
} else {
|
||||||
|
obj.putInt("hpOnOff", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
strData = military.get("groupId");
|
||||||
|
if (strData == null) {
|
||||||
|
strData = "0";
|
||||||
|
}
|
||||||
|
obj.putString("groupId", strData);
|
||||||
|
for (int i = 1; i <= Integer.parseInt(military.get("round")); i++) {
|
||||||
|
String roundKey = "round_" + i;
|
||||||
|
try {
|
||||||
|
obj.putString(roundKey, military.get(roundKey));
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成员上级列表
|
||||||
|
*
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getMemberParents(int groupId, int uid) {
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
return getMemberParents(jedis10, groupId, uid, false);
|
||||||
|
} finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成员上级列表
|
||||||
|
*
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getMemberParents(Jedis jedis10, int groupId, int uid, boolean self) {
|
||||||
|
return getMemberParents(jedis10, groupId, uid, self, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getParentsinfo(int groupId, int uid) {
|
||||||
|
// Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
GroupMemberBean gmb = GroupCache.getMember(groupId, uid);
|
||||||
|
if (gmb == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int parentId = 0;
|
||||||
|
parentId = gmb.parentId;
|
||||||
|
return parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成员上级列表
|
||||||
|
*
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getMemberParents(Jedis jedis10, int groupId, int uid, boolean self, int start_par_lev) {
|
||||||
|
GroupMemberBean gmb = GroupCache.getMember(groupId, uid);
|
||||||
|
if (gmb == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int partnerLev = 0;
|
||||||
|
int parentId = 0;
|
||||||
|
if (self) {
|
||||||
|
partnerLev = gmb.partnerLev;
|
||||||
|
if (partnerLev > 0) {
|
||||||
|
parentId = uid;
|
||||||
|
} else {
|
||||||
|
parentId = gmb.parentId;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
parentId = gmb.parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentId > 0) {
|
||||||
|
if (parentId != uid) {
|
||||||
|
gmb = GroupCache.getMember(groupId, parentId);
|
||||||
|
partnerLev = gmb.partnerLev;
|
||||||
|
}
|
||||||
|
if (partnerLev == 0)
|
||||||
|
return null;
|
||||||
|
List<Integer> list = new ArrayList<Integer>(partnerLev);
|
||||||
|
for (int i = start_par_lev - 1; i < partnerLev; ++i) {
|
||||||
|
list.add(parentId);
|
||||||
|
parentId = gmb.parentId;
|
||||||
|
gmb = GroupCache.getMember(groupId, parentId);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子合伙人Sql
|
||||||
|
*
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getChildParentSql(int groupId, int uid, boolean self) {
|
||||||
|
String pl_key = String.format("g{%s}:par_list:%s", groupId, uid);
|
||||||
|
Set<String> child_list = Redis.use("group1_db10").smembers(pl_key);
|
||||||
|
String p = self ? uid + "" : StringUtil.Empty;
|
||||||
|
for (String str : child_list) {
|
||||||
|
p += "," + str;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子合伙人Sql
|
||||||
|
*
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getChildParentList(int groupId, int uid, boolean self) {
|
||||||
|
String pl_key = String.format("g{%s}:par_list:%s", groupId, uid);
|
||||||
|
Set<String> child_list = Redis.use("group1_db10").smembers(pl_key);
|
||||||
|
List<Integer> list = new ArrayList<>();
|
||||||
|
if (self) {
|
||||||
|
list.add(uid);
|
||||||
|
}
|
||||||
|
for (String str : child_list) {
|
||||||
|
list.add(Integer.parseInt(str));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param type 1 update 2 call
|
||||||
|
* @param sql
|
||||||
|
*/
|
||||||
|
public static void evtdb(int gid, int type, String sql) {
|
||||||
|
if (StringUtil.isEmpty(sql))
|
||||||
|
return;
|
||||||
|
String str = type + sql;
|
||||||
|
Redis.use(CHACHE_KEY).lpush("evt_db_" + (gid % 10), str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param type 1 update 2 call 插入不是很重要的LOG, 可以走随机线程
|
||||||
|
* @param sql
|
||||||
|
*/
|
||||||
|
public static void evtdbLog(int gid, int type, String sql) {
|
||||||
|
if (StringUtil.isEmpty(sql))
|
||||||
|
return;
|
||||||
|
String str = type + sql;
|
||||||
|
int id = (int) (gid * Math.random() * 100);
|
||||||
|
id = id % 10;
|
||||||
|
Redis.use(CHACHE_KEY).lpush("evt_db_" + (id), str);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static String EVT_TYPE = "E";
|
||||||
|
private final static String EVT_UID = "uid";
|
||||||
|
private final static String CHACHE_KEY = "group1_db8";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付钻石事件
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param uid
|
||||||
|
* @param game
|
||||||
|
* @param pay
|
||||||
|
* @param gid
|
||||||
|
* @param pid
|
||||||
|
*/
|
||||||
|
public static void payDiamo(int type, int uid, int game, int pay, int gid, int pid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pay", pay);
|
||||||
|
data.putInt("game", game);
|
||||||
|
data.putInt("group", gid);
|
||||||
|
if (pid > 0) {
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
}
|
||||||
|
data.putInt(EVT_UID, uid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(CHACHE_KEY).lpush("event_" + (uid % 10), data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付钻石事件
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param uid
|
||||||
|
* @param game
|
||||||
|
* @param pay
|
||||||
|
* @param cur_diamo
|
||||||
|
* @param gid
|
||||||
|
* @param pid
|
||||||
|
*/
|
||||||
|
public static void payDiamo(int type, int uid, int game, int pay, int cur_diamo, int gid, int pid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pay", pay);
|
||||||
|
data.putInt("game", game);
|
||||||
|
data.putInt("diamo", cur_diamo);
|
||||||
|
data.putInt("group", gid);
|
||||||
|
if (pid > 0) {
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
}
|
||||||
|
data.putInt(EVT_UID, uid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(CHACHE_KEY).lpush("event_" + (uid % 10), data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
final static String pay_lua = "local diamo = tonumber(redis.call('hget', KEYS[1],'diamo'))\n"
|
||||||
|
+ "local pay = tonumber(ARGV[1]) \n" + "if pay > diamo then \n" + "return {2,0}\n" + "end\n"
|
||||||
|
+ "diamo = redis.call('hincrBy',KEYS[1],'diamo',-pay)\n" + "return {0,diamo}";
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static ArrayList<Long> payDiamo(Jedis jedis0, String session, int pay) {
|
||||||
|
Object obj = jedis0.eval(pay_lua, Arrays.asList(session), Arrays.asList(pay + ""));
|
||||||
|
if (obj == null)
|
||||||
|
return null;
|
||||||
|
return (ArrayList<Long>) obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测房间钻石
|
||||||
|
*
|
||||||
|
* @param jedis0
|
||||||
|
* @param session
|
||||||
|
* @param pay
|
||||||
|
* @param opt
|
||||||
|
* @param AA
|
||||||
|
* @param maxPlayers
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static int checkRoomDiamo(Jedis jedis0, String session, int pay) throws Exception {
|
||||||
|
if (pay <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int p_diamo = Integer.parseInt(jedis0.hget(session, "diamo"));
|
||||||
|
if (p_diamo < pay) {
|
||||||
|
return ErrorCode.NO_DIAMO;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取session 已在房间
|
||||||
|
*
|
||||||
|
* @param jedis0
|
||||||
|
* @param groupId
|
||||||
|
* @param session
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final String getOldRoomV2(Jedis jedis0, int groupId, String session, int uid) {
|
||||||
|
String oldRoom = jedis0.hget(session, "room");
|
||||||
|
boolean enter_old = false;
|
||||||
|
if (StringUtil.isNotEmpty(oldRoom)) {
|
||||||
|
enter_old = true;
|
||||||
|
}
|
||||||
|
if (enter_old) {
|
||||||
|
List<String> _list = jedis0.hmget(oldRoom, "status", "score_" + uid);
|
||||||
|
String status = _list.get(0);
|
||||||
|
if (StringUtil.isEmpty(status) || status.equals("2") || status.equals("3")) {
|
||||||
|
jedis0.hdel(session, "room");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String s_uid = _list.get(1);
|
||||||
|
if (StringUtil.isNotEmpty(s_uid)) {
|
||||||
|
return oldRoom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除session房间
|
||||||
|
*
|
||||||
|
* @param jedis0
|
||||||
|
* @param session_key
|
||||||
|
* @param room_key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final boolean delRoomBySession(Jedis jedis0, String session_key, String room_key) {
|
||||||
|
String cur_room = jedis0.hget(session_key, "room");
|
||||||
|
if (StringUtil.isNotEmpty(cur_room)) {
|
||||||
|
if (cur_room.equals(room_key)) {
|
||||||
|
if (API_VER == 1) {
|
||||||
|
jedis0.hdel(session_key, "room", "seat");
|
||||||
|
} else {
|
||||||
|
jedis0.hdel(session_key, "room");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>database</id>
|
||||||
|
<class>com.taurus.core.plugin.database.DataBasePlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认10个 -->
|
||||||
|
<maxPool>100</maxPool>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>10</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认180000 -->
|
||||||
|
<maxLifetime>180000</maxLifetime>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 连接超时时间,默认30000-->
|
||||||
|
<connectionTimeout>10000</connectionTimeout>
|
||||||
|
<!-- 待机超时时间,单位是毫秒, 默认60000 -->
|
||||||
|
<idleTimeout>60000</idleTimeout>
|
||||||
|
|
||||||
|
<!-- jdbc 属性 -->
|
||||||
|
<props>
|
||||||
|
<useSSL>false</useSSL>
|
||||||
|
<useUnicode>true</useUnicode>
|
||||||
|
<characterEncoding>utf-8</characterEncoding>
|
||||||
|
<!-- 服务器时区 -->
|
||||||
|
<serverTimezone>UTC</serverTimezone>
|
||||||
|
<!-- 预编译缓存 -->
|
||||||
|
<cachePrepStmts>true</cachePrepStmts>
|
||||||
|
<!-- 预编译缓存大小 -->
|
||||||
|
<prepStmtCacheSize>250</prepStmtCacheSize>
|
||||||
|
<!-- 控制长度多大的sql可以被缓存 -->
|
||||||
|
<prepStmtCacheSqlLimit>2048</prepStmtCacheSqlLimit>
|
||||||
|
</props>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<databases>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.cj.jdbc.Driver</driverName>
|
||||||
|
<jdbcUrl>jdbc:mysql://123.207.203.115:8060/wb_game</jdbcUrl>
|
||||||
|
<userName>wb_game</userName>
|
||||||
|
<password>363b76546c</password>
|
||||||
|
</db>
|
||||||
|
</databases>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>20</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="123.207.203.115" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="123.207.203.115" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="123.207.203.115" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="123.207.203.115" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="123.207.203.115" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
log4j.rootLogger = INFO,consoleAppender,fileAppender
|
||||||
|
|
||||||
|
# ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n
|
||||||
|
|
||||||
|
|
||||||
|
# Regular FileAppender
|
||||||
|
log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log
|
||||||
|
log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n
|
||||||
|
log4j.appender.fileAppender.Encoding=UTF-8
|
||||||
|
log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd
|
||||||
|
log4j.appender.dailyFile.Append=true
|
||||||
|
|
||||||
|
# The file is rolled over very day
|
||||||
|
log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>database</id>
|
||||||
|
<class>com.taurus.core.plugin.database.DataBasePlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认10个 -->
|
||||||
|
<maxPool>100</maxPool>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>10</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认180000 -->
|
||||||
|
<maxLifetime>180000</maxLifetime>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 连接超时时间,默认30000-->
|
||||||
|
<connectionTimeout>10000</connectionTimeout>
|
||||||
|
<!-- 待机超时时间,单位是毫秒, 默认60000 -->
|
||||||
|
<idleTimeout>60000</idleTimeout>
|
||||||
|
|
||||||
|
<!-- jdbc 属性 -->
|
||||||
|
<props>
|
||||||
|
<useSSL>false</useSSL>
|
||||||
|
<useUnicode>true</useUnicode>
|
||||||
|
<characterEncoding>utf-8</characterEncoding>
|
||||||
|
<!-- 服务器时区 -->
|
||||||
|
<serverTimezone>UTC</serverTimezone>
|
||||||
|
<!-- 预编译缓存 -->
|
||||||
|
<cachePrepStmts>true</cachePrepStmts>
|
||||||
|
<!-- 预编译缓存大小 -->
|
||||||
|
<prepStmtCacheSize>250</prepStmtCacheSize>
|
||||||
|
<!-- 控制长度多大的sql可以被缓存 -->
|
||||||
|
<prepStmtCacheSqlLimit>2048</prepStmtCacheSqlLimit>
|
||||||
|
</props>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<databases>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.cj.jdbc.Driver</driverName>
|
||||||
|
<jdbcUrl>jdbc:mysql://123.207.203.115:8060/wb_game</jdbcUrl>
|
||||||
|
<userName>wb_game</userName>
|
||||||
|
<password>363b76546c</password>
|
||||||
|
</db>
|
||||||
|
</databases>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>20</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="123.207.203.115" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="123.207.203.115" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="123.207.203.115" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="123.207.203.115" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="123.207.203.115" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
log4j.rootLogger = INFO,consoleAppender,fileAppender
|
||||||
|
|
||||||
|
# ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n
|
||||||
|
|
||||||
|
|
||||||
|
# Regular FileAppender
|
||||||
|
log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log
|
||||||
|
log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n
|
||||||
|
log4j.appender.fileAppender.Encoding=UTF-8
|
||||||
|
log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd
|
||||||
|
log4j.appender.dailyFile.Append=true
|
||||||
|
|
||||||
|
# The file is rolled over very day
|
||||||
|
log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>database</id>
|
||||||
|
<class>com.taurus.core.plugin.database.DataBasePlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认10个 -->
|
||||||
|
<maxPool>100</maxPool>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>10</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认180000 -->
|
||||||
|
<maxLifetime>180000</maxLifetime>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 连接超时时间,默认30000-->
|
||||||
|
<connectionTimeout>10000</connectionTimeout>
|
||||||
|
<!-- 待机超时时间,单位是毫秒, 默认60000 -->
|
||||||
|
<idleTimeout>60000</idleTimeout>
|
||||||
|
|
||||||
|
<!-- jdbc 属性 -->
|
||||||
|
<props>
|
||||||
|
<useSSL>false</useSSL>
|
||||||
|
<useUnicode>true</useUnicode>
|
||||||
|
<characterEncoding>utf-8</characterEncoding>
|
||||||
|
<!-- 服务器时区 -->
|
||||||
|
<serverTimezone>UTC</serverTimezone>
|
||||||
|
<!-- 预编译缓存 -->
|
||||||
|
<cachePrepStmts>true</cachePrepStmts>
|
||||||
|
<!-- 预编译缓存大小 -->
|
||||||
|
<prepStmtCacheSize>250</prepStmtCacheSize>
|
||||||
|
<!-- 控制长度多大的sql可以被缓存 -->
|
||||||
|
<prepStmtCacheSqlLimit>2048</prepStmtCacheSqlLimit>
|
||||||
|
</props>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<databases>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.cj.jdbc.Driver</driverName>
|
||||||
|
<jdbcUrl>jdbc:mysql://123.207.203.115:8060/wb_game</jdbcUrl>
|
||||||
|
<userName>wb_game</userName>
|
||||||
|
<password>363b76546c</password>
|
||||||
|
</db>
|
||||||
|
</databases>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>20</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="123.207.203.115" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="123.207.203.115" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="123.207.203.115" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="123.207.203.115" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="123.207.203.115" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.evt</groupId>
|
||||||
|
<artifactId>event_mgr</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<build.type>pro</build.type>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 data_cache -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.data</groupId>
|
||||||
|
<artifactId>data_cache</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-core</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-web -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-web</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用redis时导入 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用HikariCP时导入 ,自己在项目中添加 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用mysql时导入 ,自己在项目中添加 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.16</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/jdom/jdom -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jdom</groupId>
|
||||||
|
<artifactId>jdom</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.quartz-scheduler</groupId>
|
||||||
|
<artifactId>quartz</artifactId>
|
||||||
|
<version>2.2.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-webapp -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-webapp</artifactId>
|
||||||
|
<version>8.2.0.v20160908</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>ROOT</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<warSourceExcludes>logs/**,config/**</warSourceExcludes>
|
||||||
|
<webResources>
|
||||||
|
<resource>
|
||||||
|
<targetPath>config/</targetPath>
|
||||||
|
<directory>${project.basedir}/build/${build.type}/</directory>
|
||||||
|
</resource>
|
||||||
|
</webResources>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,149 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
public class EventController {
|
||||||
|
private static final String EVENT_TYPE = "E";
|
||||||
|
private static final String EVENT_GID = "gid";
|
||||||
|
private static final String EVENT_UID = "uid";
|
||||||
|
|
||||||
|
public static final int execEvt(String key,boolean isGroupEvt) {
|
||||||
|
int count = 0;
|
||||||
|
do {
|
||||||
|
String jsonStr = Redis.use(EventReceiver.CHACHE_KEY).rpop(key);
|
||||||
|
if(StringUtil.isEmpty(jsonStr))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
ITObject data = null;
|
||||||
|
try {
|
||||||
|
data = TObject.newFromJsonData(jsonStr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
EventServer.log.error(jsonStr + ":event json error!", e);
|
||||||
|
}
|
||||||
|
int type = 0;
|
||||||
|
int uid = 0;
|
||||||
|
int groupId =0;
|
||||||
|
int reulst = 0;
|
||||||
|
try {
|
||||||
|
type = data.getInt(EVENT_TYPE);
|
||||||
|
|
||||||
|
if(isGroupEvt) {
|
||||||
|
groupId = data.getInt(EVENT_GID);
|
||||||
|
}else {
|
||||||
|
uid = data.getInt(EVENT_UID);
|
||||||
|
}
|
||||||
|
|
||||||
|
IHandler handler = EventServer.eventReceiver.getHandler(type);
|
||||||
|
if(handler!=null) {
|
||||||
|
if(isGroupEvt) {
|
||||||
|
reulst = handler.processGroup(groupId, data);
|
||||||
|
EventServer.log.info(jsonStr + " use time:" + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
|
}else {
|
||||||
|
reulst = handler.process(uid, data);
|
||||||
|
EventServer.log.info(jsonStr + " use time:" + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
|
}
|
||||||
|
if(reulst!=0) {
|
||||||
|
if(reulst == -1) {
|
||||||
|
jsonStr = data.toJson();
|
||||||
|
}
|
||||||
|
Redis.use(EventReceiver.CHACHE_KEY).lpush(key, jsonStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Redis.use("group1_db15").lpush(key, jsonStr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reulst == 0) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
} while(true);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param uid
|
||||||
|
* @param pay
|
||||||
|
* @param cur_diamo
|
||||||
|
* @param reason
|
||||||
|
* @param gameId
|
||||||
|
* @param groupId
|
||||||
|
* @param pid
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public static final void payDiamo(int uid,int pay,int cur_diamo,int reason,int gameId,int groupId,int pid) throws SQLException{
|
||||||
|
ITArray data = TArray.newInstance();
|
||||||
|
data.addInt(uid);
|
||||||
|
data.addInt(pay);
|
||||||
|
data.addInt(reason);
|
||||||
|
data.addInt(gameId);
|
||||||
|
data.addInt(groupId);
|
||||||
|
data.addInt(cur_diamo);
|
||||||
|
DataBase.use().prepareCallNonResult("sp_transfer_diamo", data);
|
||||||
|
if(groupId>0) {
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
CountUtil.countLog(String.format("g%s:diamo_cost",groupId), pay, jedis9);
|
||||||
|
if(pid > 0) {
|
||||||
|
CountUtil.countLog(String.format("g%s:diamo_cost:p%s",groupId,pid), pay, jedis9,false,true);
|
||||||
|
}
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final int execSql(String key) {
|
||||||
|
int count = 0;
|
||||||
|
do {
|
||||||
|
String str = Redis.use(EventReceiver.CHACHE_KEY).rpop(key);
|
||||||
|
// EventServer.log.info( " execsql:"+str);
|
||||||
|
if(StringUtil.isEmpty(str))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int reulst = 0;
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
int type = Integer.parseInt(str.substring(0,1));
|
||||||
|
String sql = str.substring(1);
|
||||||
|
if(type==1) {
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
EventServer.log.info(sql + " use time:" + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
|
}else {
|
||||||
|
DataBase.use().executeCall(sql, false);
|
||||||
|
EventServer.log.info(sql + " use time:" + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Redis.use("group1_db15").lpush(key, str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reulst == 0) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
} while(true);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
|
public class EventReceiver {
|
||||||
|
private final static String GROUP_EVT_KEY = "evt_group_";
|
||||||
|
private final static String EVT_KEY = "event_";
|
||||||
|
private final static String EVT_DB_KEY = "evt_db_";
|
||||||
|
public final static String CHACHE_KEY = "group1_db8";
|
||||||
|
|
||||||
|
Map<Integer, IHandler> handlerMap;
|
||||||
|
volatile boolean run;
|
||||||
|
|
||||||
|
public EventReceiver() {
|
||||||
|
handlerMap = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
run = true;
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
new GroupRunnable(i, this, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
new GroupRunnable(i, this, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
new GroupRunnable(i, this, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy() {
|
||||||
|
run = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
IHandler getHandler(int type) {
|
||||||
|
IHandler handler = handlerMap.get(type);
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class GroupRunnable implements Runnable {
|
||||||
|
private Logger log = Logger.getLogger(GroupRunnable.class);
|
||||||
|
EventReceiver receiver;
|
||||||
|
int type;
|
||||||
|
int id;
|
||||||
|
Thread thread;
|
||||||
|
|
||||||
|
public GroupRunnable(int id, EventReceiver receiver, int type) {
|
||||||
|
this.receiver = receiver;
|
||||||
|
this.type = type;
|
||||||
|
this.id = id;
|
||||||
|
this.thread = new Thread(this, id + "");
|
||||||
|
this.thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (receiver.run) {
|
||||||
|
int count=0;
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
switch (type) {
|
||||||
|
case 1:
|
||||||
|
count = EventController.execEvt(GROUP_EVT_KEY + this.id, true);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
count = EventController.execEvt(EVT_KEY + id, false);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
count = EventController.execSql(EVT_DB_KEY+id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
long useTime = (System.currentTimeMillis() - startTime);
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
EventServer.log.info("handle event:" + count + " use time:" + useTime + " ms");
|
||||||
|
}
|
||||||
|
if (useTime >= 30 || count >= 30)
|
||||||
|
{
|
||||||
|
Thread.sleep(1);
|
||||||
|
}
|
||||||
|
else if (count > 0){
|
||||||
|
Thread.sleep(5);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Thread.sleep(20);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import static org.quartz.CronScheduleBuilder.cronSchedule;
|
||||||
|
import static org.quartz.JobBuilder.newJob;
|
||||||
|
import static org.quartz.TriggerBuilder.newTrigger;
|
||||||
|
|
||||||
|
import com.evt.mgr.job.CleanGroupLogJob;
|
||||||
|
import org.quartz.CronTrigger;
|
||||||
|
import org.quartz.JobDetail;
|
||||||
|
import org.quartz.Scheduler;
|
||||||
|
import org.quartz.SchedulerFactory;
|
||||||
|
import org.quartz.impl.StdSchedulerFactory;
|
||||||
|
|
||||||
|
import com.data.util.ConsumeCode;
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.evt.mgr.handler.HandlerGroupMemberRound;
|
||||||
|
import com.evt.mgr.handler.HandlerGroupRound;
|
||||||
|
import com.evt.mgr.handler.HandlerHpConsume;
|
||||||
|
import com.evt.mgr.handler.HandlerLose;
|
||||||
|
import com.evt.mgr.handler.HandlerOver;
|
||||||
|
import com.evt.mgr.handler.HandlerPay;
|
||||||
|
import com.evt.mgr.handler.HandlerWin;
|
||||||
|
import com.evt.mgr.job.CleanTimeOutRoomJob;
|
||||||
|
import com.taurus.core.routes.Extension;
|
||||||
|
import com.taurus.core.routes.Routes;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
|
public class EventServer extends Extension{
|
||||||
|
static EventReceiver eventReceiver;
|
||||||
|
public static Logger log;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
log = Logger.getLogger(EventServer.class);
|
||||||
|
eventReceiver = new EventReceiver();
|
||||||
|
initHandler();
|
||||||
|
|
||||||
|
initJob();
|
||||||
|
|
||||||
|
eventReceiver.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configRoute(Routes me) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initJob() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("clean invalid room, no diamond");
|
||||||
|
|
||||||
|
SchedulerFactory sf = new StdSchedulerFactory();
|
||||||
|
Scheduler sched = sf.getScheduler();
|
||||||
|
|
||||||
|
JobDetail job = newJob(CleanTimeOutRoomJob.class).withIdentity("clean_group_room", "group").build();
|
||||||
|
CronTrigger trigger= newTrigger().withIdentity("clean_group_room_trigger", "group").withSchedule(cronSchedule("0 0 5 * * ? ")).build();
|
||||||
|
sched.scheduleJob(job, trigger);
|
||||||
|
|
||||||
|
job = newJob(CleanTimeOutRoomJob.class).withIdentity("clean_invalid_room", "group").build();
|
||||||
|
trigger= newTrigger().withIdentity("clean_invalid_room_trigger", "group").withSchedule(cronSchedule("0 30 5 * * ? ")).build();
|
||||||
|
sched.scheduleJob(job, trigger);
|
||||||
|
|
||||||
|
JobDetail log_job = newJob(CleanGroupLogJob.class).withIdentity("clean_group_member_log", "group").build();
|
||||||
|
CronTrigger log_trigger= newTrigger().withIdentity("clean_group_member_log_trigger", "group").withSchedule(cronSchedule("0 0 0/1 * * ? ")).build();
|
||||||
|
sched.scheduleJob(log_job, log_trigger);
|
||||||
|
|
||||||
|
log_job = newJob(CleanGroupLogJob.class).withIdentity("clean_group_hp_log", "group").build();
|
||||||
|
log_trigger= newTrigger().withIdentity("clean_group_hp_log_trigger", "group").withSchedule(cronSchedule("0 0 0/1 * * ? ")).build();
|
||||||
|
sched.scheduleJob(log_job, log_trigger);
|
||||||
|
|
||||||
|
log_job = newJob(CleanGroupLogJob.class).withIdentity("clean_rec_room_log", "group").build();
|
||||||
|
log_trigger= newTrigger().withIdentity("clean_rec_room_log_trigger", "group").withSchedule(cronSchedule("0 0 0/1 * * ? ")).build();
|
||||||
|
sched.scheduleJob(log_job, log_trigger);
|
||||||
|
|
||||||
|
sched.start();
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void initHandler() {
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_OVER, new HandlerOver());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_LOSE, new HandlerLose());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_WIN, new HandlerWin());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_PAY, new HandlerPay(ConsumeCode.DIAMO_JOIN_ROOM,true));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_BACK_PAY, new HandlerPay(ConsumeCode.DIAMO_REFUND,false));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_GROUP_ROOM, new HandlerPay(ConsumeCode.DIAMO_AGENT_ROOM,true));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_CREATE_ROOM, new HandlerPay(ConsumeCode.DIAMO_CREAT_ROOM,true));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_MAIL, new HandlerPay(ConsumeCode.DIAMO_MAIL,false));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_WHEEL, new HandlerPay(ConsumeCode.DIAMO_WHEEL,false));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_GROUP_ROUND, new HandlerGroupRound());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_GROUP_MEMBER_ROUND, new HandlerGroupMemberRound());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_GROUP_HP, new HandlerHpConsume());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_ADDPAY, new HandlerPay(ConsumeCode.DIAMO_ADD,false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
eventReceiver.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
public class GroupPublisherService {
|
||||||
|
public static final String CHANNEL_NAME = "mgr_group";
|
||||||
|
|
||||||
|
private static final String CMD_UPDATE_MEMBER = "update_member";
|
||||||
|
|
||||||
|
private static final String CMD_DEL_ROOM = "del_room";
|
||||||
|
|
||||||
|
private final static String EVT_TYPE = "E";
|
||||||
|
private final static String EVT_UID = "uid";
|
||||||
|
|
||||||
|
private final static String EVT_KEY = "event_";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1 hp 2 等级 3 合伙人等级
|
||||||
|
*
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public static void updateMemberEvt(int groupId, int uid, int type, int value) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("gid", groupId);
|
||||||
|
data.putInt("uid", uid);
|
||||||
|
data.putInt("type", type);
|
||||||
|
data.putInt("value", value);
|
||||||
|
data.putString("cmd", CMD_UPDATE_MEMBER);
|
||||||
|
Jedis jedis11 =Redis.use("group1_db11").getJedis();
|
||||||
|
jedis11.publish(CHANNEL_NAME, data.toJson());
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void delRoomEvt(int groupId, String roomid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("gid", groupId);
|
||||||
|
data.putString("roomid", roomid);
|
||||||
|
data.putString("cmd", CMD_DEL_ROOM);
|
||||||
|
Jedis jedis11 =Redis.use("group1_db11").getJedis();
|
||||||
|
jedis11.publish(CHANNEL_NAME, data.toJson());
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返还钻石
|
||||||
|
*
|
||||||
|
* @param uid
|
||||||
|
* @param pay
|
||||||
|
* @param groupId
|
||||||
|
*/
|
||||||
|
public static void refundDiamo(int uid, int pay, int groupId, int gameId) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pay", -pay);
|
||||||
|
data.putInt("game", gameId);
|
||||||
|
if (groupId > 0) {
|
||||||
|
data.putInt("group", groupId);
|
||||||
|
}
|
||||||
|
//sendEvt(EventType.REDIS_EVENT_BACK_PAY, uid, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendEvt(int type, int uid, ITObject data) {
|
||||||
|
int id = uid % 10;
|
||||||
|
data.putInt(EVT_UID, uid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(EventReceiver.CHACHE_KEY).lpush(EVT_KEY + id, data.toJson());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
|
||||||
|
public interface IHandler {
|
||||||
|
|
||||||
|
public int process(int uid,ITObject param) throws Exception;
|
||||||
|
|
||||||
|
public int processGroup(int groupId,ITObject param) throws Exception;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,221 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
|
||||||
|
import com.data.cache.GroupCache;
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.handler.HandlerHpConsume;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
static Logger log = Logger.getLogger(Utils.class);
|
||||||
|
|
||||||
|
public static final void countValidAndTotal(Jedis jedis10, Pipeline pipeline9, int uid, int groupId, int pid,
|
||||||
|
int valid_count, int valid_diamo, int all_count) {
|
||||||
|
|
||||||
|
if (valid_count > 0) {
|
||||||
|
String gmv = String.format("g{%s}:m%s:valid_round", groupId, uid);
|
||||||
|
CountUtil.countLogByDay30(gmv, valid_count, pipeline9);
|
||||||
|
CountUtil.countLogByDay30(gmv + "_self", valid_count, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valid_diamo > 0) {
|
||||||
|
String gmv = String.format("g{%s}:m%s:valid_diamo", groupId, uid);
|
||||||
|
CountUtil.countLogByDay30(gmv, valid_diamo, pipeline9);
|
||||||
|
CountUtil.countLogByDay30(gmv + "_self", valid_diamo, pipeline9);
|
||||||
|
|
||||||
|
// CountUtil.countLogByDay30(groupDiamo + "_self", valid_diamo, pipeline9);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
String gmr = String.format("g{%s}:m%s:round_log", groupId, uid);
|
||||||
|
CountUtil.countLogByDay30(gmr, 1, pipeline9, true);
|
||||||
|
CountUtil.countLogByDay30(gmr + "_self", 1, pipeline9, true);
|
||||||
|
|
||||||
|
List<Integer> temp = Utility.getMemberParents(jedis10, groupId, uid, true);
|
||||||
|
if (temp != null && temp.size() > 0) {
|
||||||
|
|
||||||
|
if (valid_count > 0) {
|
||||||
|
|
||||||
|
for (int i = 0; i < temp.size(); ++i) {
|
||||||
|
|
||||||
|
int par = temp.get(i);
|
||||||
|
if (par != uid) {
|
||||||
|
String gmv = String.format("g{%s}:m%s:valid_round", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(gmv, valid_count, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
String gmvp = String.format("g{%s}:m%s:valid_round:p%s", groupId, par, pid);
|
||||||
|
CountUtil.countLogByDay30(gmvp, valid_count, pipeline9);
|
||||||
|
|
||||||
|
String gmvp2 = String.format("g{%s}:m%s:valid_round2:p%s", groupId, par, pid);
|
||||||
|
CountUtil.countLogByDay30(gmvp2, valid_count, pipeline9);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == par || i == 0);
|
||||||
|
if (add_uid == true) {
|
||||||
|
String gmv = String.format("g{%s}:m%s:d_valid_round", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(gmv, valid_count, pipeline9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < temp.size(); ++i) {
|
||||||
|
int par = temp.get(i);
|
||||||
|
if (par != uid) {
|
||||||
|
gmr = String.format("g{%s}:m%s:round_log", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(gmr, 1, pipeline9, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
gmr = String.format("g{%s}:m%s:valid_diamo:p%s", groupId, par, pid);
|
||||||
|
CountUtil.countLogByDay30(gmr, valid_diamo, pipeline9);
|
||||||
|
|
||||||
|
gmr = String.format("g{%s}:m%s:all_count:p%s", groupId, par, pid);
|
||||||
|
CountUtil.countLogByDay30(gmr, all_count, pipeline9, true);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == par || i == 0);
|
||||||
|
if (add_uid == true) {
|
||||||
|
gmr = String.format("g{%s}:m%s:d_round_log", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(gmr, 1, pipeline9, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void countValidAndTotal(Pipeline pipeline9, ITArray playerList, int groupId, int pid,
|
||||||
|
int valid_count, int valid_diamo, int all_count) {
|
||||||
|
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
|
||||||
|
for (int i = 0; i < playerList.size(); i++) {
|
||||||
|
|
||||||
|
int uid = playerList.getInt(i);
|
||||||
|
countValidAndTotal(jedis10, pipeline9, uid, groupId, pid, valid_count, valid_diamo, all_count);
|
||||||
|
}
|
||||||
|
log.info("消耗房卡:"+valid_diamo);
|
||||||
|
//保存消耗房卡
|
||||||
|
String groupDiamo = String.format("g{%s}:valid_diamo", groupId);
|
||||||
|
CountUtil.countLogByDay30(groupDiamo, valid_diamo, pipeline9);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计合伙人局数和赢
|
||||||
|
*
|
||||||
|
* @param jedis9
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @param win
|
||||||
|
*/
|
||||||
|
public static final void countRoundWin(Pipeline pipeline9, int groupId, int pid, int uid, boolean win, int score) {
|
||||||
|
List<Integer> par_list = null;
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
par_list = Utility.getMemberParents(jedis10, groupId, uid, true);
|
||||||
|
|
||||||
|
Pipeline pipeline10 = jedis10.pipelined();
|
||||||
|
|
||||||
|
if (par_list == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String key = String.format("g{%s}:m%s:total_win", groupId, uid);
|
||||||
|
CountUtil.countLogByDay30(key, score, pipeline9);
|
||||||
|
CountUtil.countLogByDay30(key + "_self", score, pipeline9);
|
||||||
|
|
||||||
|
for (int i = 0; i < par_list.size(); ++i) {
|
||||||
|
|
||||||
|
int par = par_list.get(i);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == par || i == 0);
|
||||||
|
if (add_uid == true) {
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:d_total_win", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(key, score, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
String mlk = GroupCache.genMemberListKey(groupId, par);
|
||||||
|
pipeline10.sadd(mlk, uid + "");
|
||||||
|
|
||||||
|
if (par != uid) {
|
||||||
|
key = String.format("g{%s}:m%s:total_win", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(key, score, pipeline9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline10.sync();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计合伙人体力值消耗,输赢统计
|
||||||
|
*
|
||||||
|
* @param jedis9
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @param pump
|
||||||
|
* @param hp
|
||||||
|
*/
|
||||||
|
public static final void countHpconsume(Pipeline pipeline9, int groupId, int uid, int pump, int hp) {
|
||||||
|
List<Integer> par_list = null;
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
par_list = Utility.getMemberParents(jedis10, groupId, uid, true);
|
||||||
|
} finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
if (par_list == null)
|
||||||
|
return;
|
||||||
|
String key;
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:hp_consume_log", groupId, uid);
|
||||||
|
CountUtil.countLogByDay(key, hp, pipeline9);
|
||||||
|
|
||||||
|
int day = DateUtils.getBeginDay();
|
||||||
|
boolean self = par_list.get(0) == uid;
|
||||||
|
for (int i = 0; i < par_list.size(); ++i) {
|
||||||
|
|
||||||
|
int par = par_list.get(i);
|
||||||
|
boolean add_uid = i == 0 || (i <= 1 && self);
|
||||||
|
|
||||||
|
if (pump > 0) {
|
||||||
|
|
||||||
|
key = String.format("g%s:hp_cost:par%s_%s", groupId, par, day);
|
||||||
|
pipeline9.hincrBy(key, "total", pump);
|
||||||
|
if (add_uid) {
|
||||||
|
pipeline9.hincrBy(key, uid + "", pump);
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline9.expire(key, 3600 * 24 * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uid != par) {
|
||||||
|
key = String.format("g{%s}:m%s:hp_consume_log", groupId, par);
|
||||||
|
CountUtil.countLogByDay(key, hp, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
key = String.format("g%s:hp_consume:par%s_%s", groupId, par, day);
|
||||||
|
pipeline9.hincrBy(key, "total", hp);
|
||||||
|
if (add_uid) {
|
||||||
|
pipeline9.hincrBy(key, uid + "", hp);
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline9.expire(key, 3600 * 24 * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import com.data.util.ConsumeCode;
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.evt.mgr.Utils;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class HandlerGroupMemberRound implements IHandler{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean addMemberLog(int gid, int pid,int uid, int score, int win, int time, int perfectRound,int valid_count) throws SQLException {
|
||||||
|
String sql = String.format("{call sp_add_member_log(%s,%s,%s,%s,%s,%s,%s,%s)}",
|
||||||
|
gid,pid,uid,score,win,time,perfectRound,valid_count);
|
||||||
|
Utility.evtdbLog(gid, 2, sql);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
|
||||||
|
int pid = param.getInt("pid");
|
||||||
|
int score = param.getInt("score");
|
||||||
|
int uid = param.getInt("uid");
|
||||||
|
int win = param.getInt("win");
|
||||||
|
int time = DateUtils.getBeginDay();
|
||||||
|
int perfectRound = param.getInt("perfect_round");
|
||||||
|
int valid_count = param.getInt("valid_count");
|
||||||
|
int pump = param.getInt("pump");
|
||||||
|
int cur_hp = param.getInt("cur_hp");
|
||||||
|
int xipai_total = param.getInt("xi_pai_total");
|
||||||
|
String roomid = param.getString("room");
|
||||||
|
int cur_time = (int)(System.currentTimeMillis() / 1000);
|
||||||
|
if (param.containsKey("time"))
|
||||||
|
{
|
||||||
|
cur_time = param.getInt("time");
|
||||||
|
}
|
||||||
|
|
||||||
|
//ITArray param1 = TArray.newInstance();
|
||||||
|
//param1.addInt(groupId);
|
||||||
|
//param1.addInt(pid);
|
||||||
|
//param1.addInt(uid);
|
||||||
|
//param1.addInt(score - pump - xipai_total);
|
||||||
|
//param1.addInt(win);
|
||||||
|
//param1.addInt(time);
|
||||||
|
//param1.addInt(perfectRound);
|
||||||
|
//param1.addInt(valid_count);
|
||||||
|
//DataBase.use().prepareCallNonResult("sp_add_member_log", param1);
|
||||||
|
// addMemberLog(groupId, pid, uid, score - pump - xipai_total, win, time, perfectRound, valid_count);
|
||||||
|
addMemberLog(groupId, pid, uid, score, win, time, perfectRound, valid_count);
|
||||||
|
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
int gameid = 0;
|
||||||
|
try {
|
||||||
|
String gameIdstr = jedis11.hget("g{" + groupId + "}:play:" + pid, "gameId");
|
||||||
|
gameid = StringUtil.isEmpty(gameIdstr)?0:Integer.parseInt(gameIdstr);
|
||||||
|
}finally {
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
String sql = String.format("INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,gameid,roomid,time) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)",
|
||||||
|
groupId,uid,ConsumeCode.HP_PUMP_TOTAL,score - pump - xipai_total,
|
||||||
|
cur_hp,pid,gameid,roomid,(int) (cur_time));
|
||||||
|
Utility.evtdb(groupId, 1, sql);
|
||||||
|
//DataBase.use().executeUpdate(sql);
|
||||||
|
|
||||||
|
String gmrp_key = String.format("g%s:m%s:round:p%s",groupId,uid,pid);
|
||||||
|
String gmr_key = String.format("g%s:m%s:round",groupId,uid);
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
|
||||||
|
try {
|
||||||
|
CountUtil.countLog(gmrp_key, 1, jedis9);
|
||||||
|
CountUtil.countLog(gmr_key, 1, jedis9);
|
||||||
|
|
||||||
|
Pipeline pipeline9 = jedis9.pipelined();
|
||||||
|
Utils.countRoundWin(pipeline9, groupId, pid, uid, win==1,score - pump);
|
||||||
|
pipeline9.sync();
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.evt.mgr.Utils;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class HandlerGroupRound implements IHandler{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
int pid = param.getInt("pid");
|
||||||
|
int valid = param.getInt("valid");
|
||||||
|
ITArray playerList = param.getTArray("player_list");
|
||||||
|
int valid_count = param.getInt("valid_count");
|
||||||
|
int valid_diamo = 0;
|
||||||
|
int all_count = 0;
|
||||||
|
if (param.containsKey("valid_diamo"))
|
||||||
|
{
|
||||||
|
valid_diamo = param.getInt("valid_diamo");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.containsKey("all_count"))
|
||||||
|
{
|
||||||
|
all_count = param.getInt("all_count");
|
||||||
|
}
|
||||||
|
|
||||||
|
String rp_key = String.format("g%s:round:p%s",groupId,pid);
|
||||||
|
String round_key = String.format("g%s:round",groupId);
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
Pipeline pipeline9 = jedis9.pipelined();
|
||||||
|
|
||||||
|
CountUtil.countLog(rp_key, 1, pipeline9,false,true);
|
||||||
|
CountUtil.countLog(round_key, 1, pipeline9,true);
|
||||||
|
|
||||||
|
if(valid == 1) {
|
||||||
|
|
||||||
|
String valid_key = String.format("g%s:valid_room",groupId);
|
||||||
|
String p_valid_key = String.format("g%s:valid_room:p%s",groupId,pid);
|
||||||
|
CountUtil.countLogByDay(p_valid_key, 1, pipeline9,true);
|
||||||
|
CountUtil.countLog(valid_key, 1, pipeline9);
|
||||||
|
}else {
|
||||||
|
|
||||||
|
String no_valid_key = String.format("g%s:no_valid_room",groupId);
|
||||||
|
String p_no_valid_key = String.format("g%s:no_valid_room:p%s",groupId,pid);
|
||||||
|
CountUtil.countLogByDay(p_no_valid_key, 1, pipeline9,true);
|
||||||
|
CountUtil.countLog(no_valid_key, 1, pipeline9);
|
||||||
|
}
|
||||||
|
Utils.countValidAndTotal(pipeline9, playerList, groupId, pid, valid_count, valid_diamo, all_count);
|
||||||
|
|
||||||
|
pipeline9.sync();
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,551 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import com.data.bean.GroupBean;
|
||||||
|
import com.data.cache.GroupCache;
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.data.util.ConsumeCode;
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class HandlerHpConsume implements IHandler{
|
||||||
|
static Logger log = Logger.getLogger(HandlerHpConsume.class);
|
||||||
|
final static String DB = "group1_db10";
|
||||||
|
|
||||||
|
private static boolean hpConsume(int gid, int uid,int pid, int hp,int cur_hp,int reason, String roomid, int time,String desc) throws SQLException {
|
||||||
|
String sql = String.format("{call sp_update_hp(%s,%s,%s,%s,%s,%s,'%s',%s,'%s')}",
|
||||||
|
gid,uid,hp,cur_hp,reason,pid,roomid,time,desc);
|
||||||
|
Utility.evtdb(gid, 2, sql);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void to_reward(Pipeline pipeline, int uid, String prs,int rewardType, int valueType, int real_pump, int pump,int groupId,int pid,String roomid,int time,int max_player) throws Exception {
|
||||||
|
|
||||||
|
int useValue = 0;
|
||||||
|
if(StringUtil.isNotEmpty(prs)) {
|
||||||
|
|
||||||
|
int round = 100 / max_player;
|
||||||
|
ITArray list = TArray.newFromJsonData(prs);
|
||||||
|
|
||||||
|
for(int i=list.size()-1;i>=0;--i) {
|
||||||
|
|
||||||
|
ITObject obj1 = list.getTObject(i);
|
||||||
|
int parentId = obj1.getInt("p");
|
||||||
|
int rewardPercent = 0;
|
||||||
|
if (obj1.containsKey("r"))
|
||||||
|
{
|
||||||
|
rewardPercent = obj1.getInt("r");
|
||||||
|
}
|
||||||
|
int rv = 0;
|
||||||
|
if(i > 0) {
|
||||||
|
ITObject obj2 = list.getTObject(i - 1);
|
||||||
|
if (!obj2.containsKey("r"))
|
||||||
|
{
|
||||||
|
rv =rewardPercent - 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rv =rewardPercent -obj2.getInt("r");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
|
||||||
|
rv=rewardPercent;
|
||||||
|
}
|
||||||
|
int reward_value = rv;
|
||||||
|
if(valueType == 1) {
|
||||||
|
reward_value = Math.round(pump * (rv / 100f));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(rewardType == 2) {
|
||||||
|
reward_value = reward_value / max_player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reward_value < 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = String.format("g{%s}:m%s:reward_hp", groupId,parentId);
|
||||||
|
Redis.use(DB).incrBy(key, reward_value);
|
||||||
|
String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s", Redis.use(DB).get(key), parentId,groupId);
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
//String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,parentId);
|
||||||
|
//Redis.use(DB).incrBy(all_key, reward_value);
|
||||||
|
useValue += reward_value;
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
String desc = "" + uid;
|
||||||
|
long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s",groupId,parentId), reward_value, jedis9);
|
||||||
|
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
int gameid = 0;
|
||||||
|
try {
|
||||||
|
String gameIdstr = jedis11.hget("g{" + groupId + "}:play:" + pid, "gameId");
|
||||||
|
gameid = StringUtil.isEmpty(gameIdstr)?0:Integer.parseInt(gameIdstr);
|
||||||
|
}finally {
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
String sql = String.format("INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,gameid,roomid,time,round, info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", groupId,parentId,ConsumeCode.HP_PARTNER_REWARD,reward_value,cur_hp,pid,gameid,roomid,time,round, desc);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录代理每天的推广奖励
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:reward_log", groupId,parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:p%s:reward_log", groupId,parentId,pid);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
// 记录每个人对上级的推广奖励是多少
|
||||||
|
key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,uid, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == parentId || i == 0);
|
||||||
|
if(add_uid == true) {
|
||||||
|
key = String.format("g{%s}:m%s:d_reward", groupId,parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i>0) {
|
||||||
|
|
||||||
|
for(int j = i - 1; j >= 0; j--) {
|
||||||
|
|
||||||
|
ITObject obj2 = list.getTObject(j);
|
||||||
|
int temp = obj2.getInt("p");
|
||||||
|
if(temp != uid) {
|
||||||
|
key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,temp, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//某个玩法的抽水总值
|
||||||
|
CountUtil.countLogByDay30(String.format("g%s:hp_cost:m%s:p%s",groupId,parentId,pid),pump,pipeline);
|
||||||
|
|
||||||
|
CountUtil.countLogByDay30(String.format("g%s:hp_reward",groupId), reward_value, pipeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupBean gb = GroupCache.getGroup(groupId);
|
||||||
|
if (gb != null) {
|
||||||
|
int round = 100 / max_player;
|
||||||
|
int leftValue = real_pump - useValue;
|
||||||
|
String key = String.format("g{%s}:m%s:reward_hp", groupId,gb.owner);
|
||||||
|
Redis.use(DB).incrBy(key, leftValue);
|
||||||
|
String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s", Redis.use(DB).get(key), gb.owner,groupId);
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
//String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,gb.owner);
|
||||||
|
//Redis.use(DB).incrBy(all_key, leftValue);
|
||||||
|
// 记录代理每天的推广奖励
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:reward_log", groupId,gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:p%s:reward_log", groupId,gb.owner,pid);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
// 记录每个人对上级的推广奖励是多少
|
||||||
|
key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,uid, gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == gb.owner);
|
||||||
|
if(add_uid == true) {
|
||||||
|
key = String.format("g{%s}:m%s:d_reward", groupId,gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
}
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
String desc = "" + uid;
|
||||||
|
long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s",groupId,gb.owner), leftValue, jedis9);
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
int gameid = 0;
|
||||||
|
try {
|
||||||
|
String gameIdstr = jedis11.hget("g{" + groupId + "}:play:" + pid, "gameId");
|
||||||
|
gameid = StringUtil.isEmpty(gameIdstr)?0:Integer.parseInt(gameIdstr);
|
||||||
|
}finally {
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
String sql = String.format("INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,gameid,roomid,time,round,info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", groupId,gb.owner,ConsumeCode.HP_PARTNER_REWARD,leftValue,cur_hp,pid,gameid,roomid,time,round,desc);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void xipai_to_reward(Pipeline pipeline, int uid, String prs,int rewardType, int valueType, int real_pump, int pump,int groupId,int pid,String roomid,int time,int max_player) throws Exception {
|
||||||
|
|
||||||
|
int useValue = 0;
|
||||||
|
if(StringUtil.isNotEmpty(prs)) {
|
||||||
|
|
||||||
|
int round = 100 / max_player;
|
||||||
|
ITArray list = TArray.newFromJsonData(prs);
|
||||||
|
|
||||||
|
for(int i=list.size()-1;i>=0;--i) {
|
||||||
|
|
||||||
|
ITObject obj1 = list.getTObject(i);
|
||||||
|
int parentId = obj1.getInt("p");
|
||||||
|
int rewardPercent = 0;
|
||||||
|
if (obj1.containsKey("x"))
|
||||||
|
{
|
||||||
|
rewardPercent = obj1.getInt("x");
|
||||||
|
}
|
||||||
|
int rv = 0;
|
||||||
|
if(i > 0) {
|
||||||
|
ITObject obj2 = list.getTObject(i - 1);
|
||||||
|
if (!obj2.containsKey("x"))
|
||||||
|
{
|
||||||
|
rv = rewardPercent - 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rv = rewardPercent -obj2.getInt("x");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
|
||||||
|
rv=rewardPercent;
|
||||||
|
}
|
||||||
|
int reward_value = rv;
|
||||||
|
if(valueType == 1) {
|
||||||
|
reward_value = Math.round(pump * (rv / 100f));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reward_value < 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = String.format("g{%s}:m%s:reward_hp", groupId,parentId);
|
||||||
|
Redis.use(DB).incrBy(key, reward_value);
|
||||||
|
String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s", Redis.use(DB).get(key), parentId,groupId);
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
//String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,parentId);
|
||||||
|
//Redis.use(DB).incrBy(all_key, reward_value);
|
||||||
|
useValue += reward_value;
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
String desc = "" + uid;
|
||||||
|
long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s",groupId,parentId), reward_value, jedis9);
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
int gameid = 0;
|
||||||
|
try {
|
||||||
|
String gameIdstr = jedis11.hget("g{" + groupId + "}:play:" + pid, "gameId");
|
||||||
|
gameid = StringUtil.isEmpty(gameIdstr)?0:Integer.parseInt(gameIdstr);
|
||||||
|
}finally {
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
String sql = String.format("INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,gameid,roomid,time,round,info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", groupId,parentId,ConsumeCode.HP_PARTNER_XIPAI_REWARD,reward_value,cur_hp,pid,gameid,roomid,time,round,desc);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录代理每天的推广奖励
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:xipai_reward_log", groupId,parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:p%s:xipai_reward_log", groupId,parentId,pid);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
// 记录每个人对上级的推广奖励是多少
|
||||||
|
key = String.format("g{%s}:m%s:xipai_reward_log_to:par%s", groupId,uid, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == parentId || i == 0);
|
||||||
|
if(add_uid == true) {
|
||||||
|
key = String.format("g{%s}:m%s:d_xipai_reward", groupId,parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i>0) {
|
||||||
|
|
||||||
|
for(int j = i - 1; j >= 0; j--) {
|
||||||
|
|
||||||
|
ITObject obj2 = list.getTObject(j);
|
||||||
|
int temp = obj2.getInt("p");
|
||||||
|
if(temp != uid) {
|
||||||
|
key = String.format("g{%s}:m%s:xipai_reward_log_to:par%s", groupId,temp, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//某个玩法的抽水总值
|
||||||
|
CountUtil.countLogByDay30(String.format("g%s:xipai_hp_cost:m%s:p%s",groupId,parentId,pid),pump,pipeline);
|
||||||
|
|
||||||
|
CountUtil.countLogByDay30(String.format("g%s:xipai_hp_reward",groupId), reward_value, pipeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GroupBean gb = GroupCache.getGroup(groupId);
|
||||||
|
if (gb != null) {
|
||||||
|
int round = 100 / max_player;
|
||||||
|
int leftValue = real_pump - useValue;
|
||||||
|
String key = String.format("g{%s}:m%s:reward_hp", groupId,gb.owner);
|
||||||
|
Redis.use(DB).incrBy(key, leftValue);
|
||||||
|
String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s", Redis.use(DB).get(key), gb.owner,groupId);
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
//String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,gb.owner);
|
||||||
|
//Redis.use(DB).incrBy(all_key, leftValue);
|
||||||
|
// 记录代理每天的推广奖励
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:xipai_reward_log", groupId,gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:p%s:xipai_reward_log", groupId,gb.owner,pid);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
// 记录每个人对上级的推广奖励是多少
|
||||||
|
key = String.format("g{%s}:m%s:xipai_reward_log_to:par%s", groupId,uid, gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == gb.owner);
|
||||||
|
if(add_uid == true) {
|
||||||
|
key = String.format("g{%s}:m%s:d_xipai_reward", groupId,gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
}
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
String desc = "" + uid;
|
||||||
|
long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s",groupId,gb.owner), leftValue, jedis9);
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
int gameid = 0;
|
||||||
|
try {
|
||||||
|
String gameIdstr = jedis11.hget("g{" + groupId + "}:play:" + pid, "gameId");
|
||||||
|
gameid = StringUtil.isEmpty(gameIdstr)?0:Integer.parseInt(gameIdstr);
|
||||||
|
}finally {
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
String sql = String.format("INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,gameid,roomid,time,round,info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", groupId,gb.owner,ConsumeCode.HP_PARTNER_XIPAI_REWARD,leftValue,cur_hp,pid,gameid,roomid,time,round,desc);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void to_mengzhu_reward(Pipeline pipeline, int uid, String prs,int rewardType, int valueType, int real_pump, int pump,int groupId,int pid,String roomid,int time,int max_player) throws Exception {
|
||||||
|
GroupBean gb = GroupCache.getGroup(groupId);
|
||||||
|
if (gb != null) {
|
||||||
|
int round = 100 / max_player;
|
||||||
|
int leftValue = real_pump;
|
||||||
|
String key = String.format("g{%s}:m%s:reward_hp", groupId,gb.owner);
|
||||||
|
Redis.use(DB).incrBy(key, leftValue);
|
||||||
|
String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s", Redis.use(DB).get(key), gb.owner,groupId);
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
//String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,gb.owner);
|
||||||
|
//Redis.use(DB).incrBy(all_key, leftValue);
|
||||||
|
// 记录代理每天的推广奖励
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:reward_log", groupId,gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:p%s:reward_log", groupId,gb.owner,pid);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
// 记录每个人对上级的推广奖励是多少
|
||||||
|
key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,uid, gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == gb.owner);
|
||||||
|
if(add_uid == true) {
|
||||||
|
key = String.format("g{%s}:m%s:d_reward", groupId,gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
}
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
String desc = "" + uid;
|
||||||
|
long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s",groupId,gb.owner), leftValue, jedis9);
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
int gameid = 0;
|
||||||
|
try {
|
||||||
|
String gameIdstr = jedis11.hget("g{" + groupId + "}:play:" + pid, "gameId");
|
||||||
|
gameid = StringUtil.isEmpty(gameIdstr)?0:Integer.parseInt(gameIdstr);
|
||||||
|
}finally {
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
String sql = String.format("INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,gameid,roomid,time,round,info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", groupId,gb.owner,ConsumeCode.HP_PARTNER_REWARD,leftValue,cur_hp,pid,gameid,roomid,time,round,desc);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
int uid = param.getInt("uid");
|
||||||
|
try {
|
||||||
|
int hp = param.getInt("hp");
|
||||||
|
int cur_hp = param.getInt("cur_hp");
|
||||||
|
boolean is_pump = param.containsKey("pump");
|
||||||
|
int pump = 0;
|
||||||
|
String roomid = param.getString("room");
|
||||||
|
int pid = param.getInt("pid");
|
||||||
|
int time = param.getInt("time");
|
||||||
|
int reward_value = 0;
|
||||||
|
int xipai_reward_value = 0;
|
||||||
|
int max_player = 0;
|
||||||
|
int rewardValueType = 0;
|
||||||
|
int xipai_rewardValueType = 0;
|
||||||
|
int rewardType = 1;
|
||||||
|
int xipai_rewardType = 1;
|
||||||
|
|
||||||
|
boolean is_xipai = param.containsKey("xipai");
|
||||||
|
int xipai = 0;
|
||||||
|
|
||||||
|
String prs =null;
|
||||||
|
if(is_pump) {
|
||||||
|
pump = param.getInt("pump");
|
||||||
|
max_player = param.getInt("max_player");
|
||||||
|
if(param.containsKey("reward_value")) {
|
||||||
|
reward_value = param.getInt("reward_value");
|
||||||
|
prs = param.getString("prs");
|
||||||
|
}
|
||||||
|
if(param.containsKey("reward_type")) {
|
||||||
|
rewardType = param.getInt("reward_type");
|
||||||
|
}
|
||||||
|
if(param.containsKey("rewardValueType")) {
|
||||||
|
rewardValueType = param.getInt("rewardValueType");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_xipai)
|
||||||
|
{
|
||||||
|
xipai = param.getInt("xipai");
|
||||||
|
max_player = param.getInt("max_player");
|
||||||
|
if(param.containsKey("xipai_reward_value")) {
|
||||||
|
xipai_reward_value = param.getInt("xipai_reward_value");
|
||||||
|
prs = param.getString("prs");
|
||||||
|
}
|
||||||
|
if(param.containsKey("xipai_reward_type")) {
|
||||||
|
xipai_rewardType = param.getInt("xipai_reward_type");
|
||||||
|
}
|
||||||
|
if(param.containsKey("xipai_rewardValueType")) {
|
||||||
|
xipai_rewardValueType = param.getInt("xipai_rewardValueType");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.containsKey("hp_than_max_value"))
|
||||||
|
{
|
||||||
|
int more_hp = param.getInt("hp_than_max_value");
|
||||||
|
String gm_key = GroupMemberCache.genKey(groupId, uid);
|
||||||
|
String bank_hp = Redis.use("group1_db10").hget(gm_key, "bank_hp");
|
||||||
|
String sql = String.format("{call sp_bank_hp(%s,%s,%s,%s)}", groupId, uid, more_hp, cur_hp);
|
||||||
|
Utility.evtdb(groupId, 2, sql);
|
||||||
|
String sql2 = String.format("update group_member set bank_hp = %s where uid = %s AND groupId = %s", bank_hp, uid, groupId);
|
||||||
|
Utility.evtdb(groupId, 1, sql2);
|
||||||
|
}
|
||||||
|
|
||||||
|
String desc = param.getString("desc");
|
||||||
|
desc = StringUtil.isNotEmpty(desc) ? desc : StringUtil.Empty;
|
||||||
|
if(hp!=0) {
|
||||||
|
hpConsume(groupId, uid,pid, hp,cur_hp + pump,ConsumeCode.HP_CLEARING, roomid,time, desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
|
||||||
|
String key = String.format("g%s:m%s:consume_hp", groupId,uid);
|
||||||
|
if(hp!=0) {
|
||||||
|
CountUtil.countLogByDay(key, hp, jedis9, 691200);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pump>0) {
|
||||||
|
|
||||||
|
CountUtil.countLogByDay(key, -pump, jedis9, 691200);
|
||||||
|
time += 1;
|
||||||
|
hpConsume(groupId, uid,pid, -pump,cur_hp, ConsumeCode.HP_PUMP, roomid,time, desc);
|
||||||
|
|
||||||
|
CountUtil.countLog(String.format("g%s:hp_cost",groupId), pump, jedis9);
|
||||||
|
CountUtil.countLogByDay(String.format("g%s:hp_cost:p%s",groupId,pid),pump,jedis9);
|
||||||
|
CountUtil.countLogByDay(String.format("g%s:hp_cost:m%s",groupId,uid),pump,jedis9);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xipai > 0)
|
||||||
|
{
|
||||||
|
CountUtil.countLogByDay(key, -xipai, jedis9, 691200);
|
||||||
|
time += 1;
|
||||||
|
hpConsume(groupId, uid,pid, -xipai,cur_hp, ConsumeCode.HP_XIPAI_PUMP, roomid,time, desc);
|
||||||
|
|
||||||
|
CountUtil.countLog(String.format("g%s:hp_cost",groupId), xipai, jedis9);
|
||||||
|
CountUtil.countLogByDay(String.format("g%s:hp_cost:p%s",groupId,pid),xipai,jedis9);
|
||||||
|
CountUtil.countLogByDay(String.format("g%s:hp_cost:m%s",groupId,uid),xipai,jedis9);
|
||||||
|
}
|
||||||
|
|
||||||
|
Pipeline pipeline = jedis9.pipelined();
|
||||||
|
if(reward_value > 0 || (rewardValueType == 2 && is_pump)) {
|
||||||
|
|
||||||
|
time += 1;
|
||||||
|
to_reward(pipeline,uid,prs,rewardType,rewardValueType, pump, reward_value ,groupId,pid,roomid,time,max_player);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
else {
|
||||||
|
if (is_pump && pump > 0)
|
||||||
|
{
|
||||||
|
log.error("pump to_mengzhu_reward:"+pump+" uid:" + uid + " groupId:" + groupId);
|
||||||
|
to_mengzhu_reward(pipeline,uid,prs,rewardType,rewardValueType, pump, reward_value ,groupId,pid,roomid,time,max_player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if(xipai_reward_value > 0 || (xipai_rewardValueType == 2 && is_xipai)) {
|
||||||
|
|
||||||
|
time += 1;
|
||||||
|
xipai_to_reward(pipeline,uid,prs,xipai_rewardType,xipai_rewardValueType, xipai, xipai_reward_value ,groupId,pid,roomid,time,max_player);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
else {
|
||||||
|
if (is_xipai && xipai > 0)
|
||||||
|
{
|
||||||
|
log.error("xipai to_mengzhu_reward:"+pump+" uid:" + uid + " groupId:" + groupId);
|
||||||
|
to_mengzhu_reward(pipeline,uid,prs,xipai_rewardType,xipai_rewardValueType, xipai, xipai_reward_value ,groupId,pid,roomid,time,max_player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
pipeline.sync();
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
|
||||||
|
public class HandlerLose implements IHandler{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import java.awt.Event;
|
||||||
|
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.evt.mgr.EventServer;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
public class HandlerOver implements IHandler {
|
||||||
|
|
||||||
|
public static final int _SHARE_NUM = 20;
|
||||||
|
|
||||||
|
private static void share(String id) throws Exception {
|
||||||
|
if (!Redis.use("group1_db1").sismember("shares", id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String sql = "SELECT succ,playtimes FROM shares WHERE uid = " + id;
|
||||||
|
ITArray resultArray = DataBase.use().executeQueryByTArray(sql);
|
||||||
|
if (resultArray.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ITObject dbData = resultArray.getTObject(0);
|
||||||
|
if (dbData.getInt("succ") != 0) {
|
||||||
|
Redis.use("group1_db1").srem("shares", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int playTimes = dbData.getInt("playtimes") + 1;
|
||||||
|
dbData.putInt("playtimes", playTimes);
|
||||||
|
if (playTimes >= _SHARE_NUM) {
|
||||||
|
dbData.putInt("succ", 1);
|
||||||
|
Redis.use("group1_db1").srem("shares", id);
|
||||||
|
}
|
||||||
|
DataBase.use().update("shares", dbData, "uid=" + id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
int is_rec = param.getInt("is_rec");
|
||||||
|
if (is_rec == 1) {
|
||||||
|
String roomid = param.getString("roomid");
|
||||||
|
String rec_key = param.getString("rec_key");
|
||||||
|
int gid = param.containsKey("gid") ? param.getInt("gid") : 0;
|
||||||
|
int time = param.getInt("time");
|
||||||
|
int par = 0;
|
||||||
|
if (gid > 0) {
|
||||||
|
String gm_key = GroupMemberCache.genKey(gid, uid);
|
||||||
|
String parentId = Redis.use("group1_db10").hget(gm_key, "parentId");
|
||||||
|
par = StringUtil.isEmpty(parentId) ? 0 : Integer.parseInt(parentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String sql = String.format(
|
||||||
|
"insert into room_rec_log(roomid,gid,uid,rec_key,time,parentId) values('%s',%s,%s,'%s',%s,%s)",
|
||||||
|
roomid, gid, uid, rec_key, time, par);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
ITArray array = param.getTArray("tagIds");
|
||||||
|
EventServer.log.info("param:" + param);
|
||||||
|
EventServer.log.info("array:" + array);
|
||||||
|
|
||||||
|
String sqls = "";
|
||||||
|
for (int i = 0; i < array.size(); i++) {
|
||||||
|
EventServer.log.info("array.getInt(i):" + array.getInt(i));
|
||||||
|
|
||||||
|
sqls = String.format(
|
||||||
|
"insert into room_rec_log_new(roomid,gid,uid,rec_key,time,parentId,tagId) values('%s',%s,%s,'%s',%s,%s,%s)",
|
||||||
|
roomid, gid, uid, rec_key, time, par, array.getInt(i));
|
||||||
|
EventServer.log.info("sqls:" + sqls);
|
||||||
|
|
||||||
|
DataBase.use().executeUpdate(sqls);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
share(uid + "");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.data.cache.AccountCache;
|
||||||
|
import com.data.util.ConsumeCode;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.EventController;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
public class HandlerPay implements IHandler{
|
||||||
|
|
||||||
|
int reason;
|
||||||
|
boolean isPay;
|
||||||
|
public HandlerPay(int reason,boolean isPay) {
|
||||||
|
this.reason = reason;
|
||||||
|
this.isPay = isPay;
|
||||||
|
}
|
||||||
|
private static final Logger log = Logger.getLogger(HandlerPay.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
int pay = param.getInt("pay");
|
||||||
|
if(pay==0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int result = 1;
|
||||||
|
int gameId =param.getInt("game");
|
||||||
|
int groupId = 0;
|
||||||
|
int pid = 0;
|
||||||
|
if(param.containsKey("group")) {
|
||||||
|
groupId = param.getInt("group");
|
||||||
|
}
|
||||||
|
if(param.containsKey("pid")) {
|
||||||
|
pid = param.getInt("pid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reason == ConsumeCode.DIAMO_JOIN_ROOM) {
|
||||||
|
pay = Math.abs(pay);
|
||||||
|
}
|
||||||
|
if(reason == ConsumeCode.DIAMO_REFUND) {
|
||||||
|
pay = -Math.abs(pay);
|
||||||
|
}
|
||||||
|
if(reason == ConsumeCode.DIAMO_ADD) {
|
||||||
|
pay = -pay;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isPay) {
|
||||||
|
int cur_diamo = param.getInt("diamo");
|
||||||
|
EventController.payDiamo(uid, pay, cur_diamo, reason, gameId, groupId, pid);
|
||||||
|
result = 0;
|
||||||
|
}else {
|
||||||
|
String session = AccountCache.genKey(uid);
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
try {
|
||||||
|
ArrayList<Long> result_list = Utility.payDiamo(jedis0, session,pay);
|
||||||
|
if(result_list!=null) {
|
||||||
|
result = result_list.get(0).intValue();
|
||||||
|
if(result ==0) {
|
||||||
|
long cur_diamo = result_list.get(1);
|
||||||
|
EventController.payDiamo(uid, pay, (int)cur_diamo, reason, gameId, groupId, pid);
|
||||||
|
}
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
}finally {
|
||||||
|
jedis0.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
|
||||||
|
public class HandlerWin implements IHandler{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
package com.evt.mgr.job;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobKey;
|
||||||
|
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.GroupPublisherService;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.plugin.redis.RedisLock;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.ScanParams;
|
||||||
|
import redis.clients.jedis.ScanResult;
|
||||||
|
|
||||||
|
public class CleanGroupLogJob implements Job {
|
||||||
|
private Logger logger = Logger.getLogger(CleanGroupLogJob.class);
|
||||||
|
|
||||||
|
public CleanGroupLogJob() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除亲友圈中无效的房间
|
||||||
|
*/
|
||||||
|
private void cleanGroupMemberLog() {
|
||||||
|
int time = DateUtils.getBeginDay() - 5 * 24 * 3600;
|
||||||
|
String deleteSql = String.format("delete from group_member_log where time < %s", time);
|
||||||
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
DataBase.use().executeUpdate(deleteSql);
|
||||||
|
// logger.info("cleanGroupMemberLog use time:"+(System.currentTimeMillis()-startTime)+ " " + deleteSql);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CleanGroupHpLog() {
|
||||||
|
int time = DateUtils.getBeginDay() - 20 * 24 * 3600;
|
||||||
|
String deleteSql3 = String.format("delete from group_hp_log where time < %s limit 1000000", time);
|
||||||
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
DataBase.use().executeUpdate(deleteSql3);
|
||||||
|
// logger.info("CleanGroupHpLog use time:"+(System.currentTimeMillis()-startTime)+ " " + deleteSql3);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CleanRecRoomLog() {
|
||||||
|
int time = DateUtils.getBeginDay() - 5 * 24 * 3600;
|
||||||
|
String deleteSql2 = String.format("delete from room_rec_log where time < %s limit 1000000", time);
|
||||||
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
DataBase.use().executeUpdate(deleteSql2);
|
||||||
|
// logger.info("CleanRecRoomLog use time:"+(System.currentTimeMillis()-startTime) + " " + deleteSql2);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(JobExecutionContext context) {
|
||||||
|
JobKey jobKey = context.getJobDetail().getKey();
|
||||||
|
if(jobKey.getName().equals("clean_group_member_log")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
cleanGroupMemberLog();
|
||||||
|
}
|
||||||
|
if(jobKey.getName().equals("clean_group_hp_log")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
CleanGroupHpLog();
|
||||||
|
}
|
||||||
|
if(jobKey.getName().equals("clean_rec_room_log")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
CleanRecRoomLog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,323 @@
|
||||||
|
package com.evt.mgr.job;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobKey;
|
||||||
|
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.GroupPublisherService;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.plugin.redis.RedisLock;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.ScanParams;
|
||||||
|
import redis.clients.jedis.ScanResult;
|
||||||
|
|
||||||
|
public class CleanTimeOutRoomJob implements Job{
|
||||||
|
|
||||||
|
private Logger logger = Logger.getLogger(CleanTimeOutRoomJob.class);
|
||||||
|
|
||||||
|
public CleanTimeOutRoomJob() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteRoomFromRedis(String tag_key,Jedis jedis0) {
|
||||||
|
|
||||||
|
RedisLock room_lock = new RedisLock(tag_key, jedis0);
|
||||||
|
try {
|
||||||
|
// 0 1 2 3 4 5 6 7 8 9
|
||||||
|
List<String> paramList = jedis0.hmget(tag_key, "AA", "payer", "pay", "group","game","delete_status","status","create_time","id","players");
|
||||||
|
|
||||||
|
if(StringUtil.isEmpty(paramList.get(4))) {
|
||||||
|
Redis.use().expire(tag_key, 20);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String delete_status = paramList.get(5);
|
||||||
|
if(StringUtil.isEmpty(delete_status)) {
|
||||||
|
|
||||||
|
String status = paramList.get(6);
|
||||||
|
int _status = Integer.parseInt(status);
|
||||||
|
if(_status == 2 || _status == 3) {
|
||||||
|
// logger.info(tag_key + "房间的状态不对,此时房间的状态["+status + "]");
|
||||||
|
Redis.use().expire(tag_key, 20);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果房间的存活时间小于4个小时,考虑到游戏服务器也在删除 所以延时10分钟
|
||||||
|
String create_time = paramList.get(7);
|
||||||
|
String roomid = paramList.get(8);
|
||||||
|
long now = System.currentTimeMillis() / 1000;
|
||||||
|
if((now - Long.parseLong(create_time)) > 14400 + 600) {
|
||||||
|
|
||||||
|
deleteRoomFromServer(tag_key,jedis0,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean pay_AA = Integer.parseInt(paramList.get(0)) == 1;
|
||||||
|
int payer = Integer.parseInt(paramList.get(1));
|
||||||
|
int pay = Integer.parseInt(paramList.get(2));
|
||||||
|
int gameId = Integer.parseInt(paramList.get(4));
|
||||||
|
String group = paramList.get(3);
|
||||||
|
int _gid = 0;
|
||||||
|
if(StringUtil.isNotEmpty(group)) {
|
||||||
|
_gid = Integer.parseInt(group);
|
||||||
|
}
|
||||||
|
int _delete_status = Integer.parseInt(delete_status);
|
||||||
|
if(_delete_status == 0) {
|
||||||
|
|
||||||
|
// 如果需要支付钻石
|
||||||
|
if(pay > 0) {
|
||||||
|
|
||||||
|
if (pay_AA) {
|
||||||
|
|
||||||
|
String players_json = paramList.get(9);
|
||||||
|
if(StringUtil.isEmpty(players_json) == false) {
|
||||||
|
ITArray players = TArray.newFromJsonData(players_json);
|
||||||
|
for (int i = 0; i < players.size(); i++) {
|
||||||
|
//GroupPublisherService.refundDiamo(players.getInt(i), pay, _gid, gameId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
|
||||||
|
if(_gid == 0) {
|
||||||
|
//GroupPublisherService.refundDiamo(payer, pay, _gid, gameId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Redis.use().hset(tag_key, "status", 3 + "");
|
||||||
|
Redis.use().hincrBy(tag_key, "cache_ver", 1);
|
||||||
|
Redis.use().expire(tag_key, 20);
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
logger.info(tag_key + "删除房间发生异常["+e.getMessage() + "]");
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
room_lock.unlock(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean deleteRoomFromServer(String roomid,Jedis jedis0,boolean lock) {
|
||||||
|
|
||||||
|
String tag_key = roomid;
|
||||||
|
RedisLock room_lock = null;
|
||||||
|
|
||||||
|
if(lock) {
|
||||||
|
room_lock = new RedisLock(tag_key, jedis0);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if( jedis0.exists(tag_key) == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 0 1 2 3 4 5 6 7
|
||||||
|
List<String> paramList = jedis0.hmget(tag_key, "AA", "payer", "pay", "group","game","status","create_time","id");
|
||||||
|
|
||||||
|
String status = paramList.get(5);
|
||||||
|
int _status = Integer.parseInt(status);
|
||||||
|
if(_status == 2 || _status == 3) {
|
||||||
|
logger.info("删除房间" + roomid + "失败,原因状态不对,此时的状态是[" + _status +"]");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String group = paramList.get(3);
|
||||||
|
int _gid = 0;
|
||||||
|
if(StringUtil.isNotEmpty(group)) {
|
||||||
|
_gid = Integer.parseInt(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果房间的存活时间小于4个小时,考虑到游戏服务器也在删除 所以延时10分钟
|
||||||
|
String create_time = paramList.get(6);
|
||||||
|
long now = System.currentTimeMillis() / 1000;
|
||||||
|
if((now - Long.parseLong(create_time)) < 14400 + 600) {
|
||||||
|
logger.info("删除房间" + roomid + "失败,房间距离创建没有超过4个小时");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_gid != 0) {
|
||||||
|
|
||||||
|
// 如果游戏没有开始_status = 0
|
||||||
|
// 不是aa支付,则退出回创建者创建钻石的费用
|
||||||
|
// aa支付,设置status=2之后,则交给游戏服务器去做(如果游戏服务器挂了呢,或者房间在游戏服务器中根本就不存在呢),
|
||||||
|
// 如果游戏已经开始_status = 1,则不用考虑钻石回退的问题,下一次执行的时候,如果redis还存在房间的信息,则直接从redis删除就可以了
|
||||||
|
if(_status==0) {
|
||||||
|
|
||||||
|
int gameId = Integer.parseInt(paramList.get(4));
|
||||||
|
boolean pay_AA = Integer.parseInt(paramList.get(0)) == 1;
|
||||||
|
if (!pay_AA) {
|
||||||
|
int payer = Integer.parseInt(paramList.get(1));
|
||||||
|
int pay = Integer.parseInt(paramList.get(2));
|
||||||
|
//Utility.payDiamo(EventType.REDIS_EVENT_BACK_PAY, payer, gameId, pay, _gid,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String strRoomID = "";
|
||||||
|
if(StringUtil.isNotEmpty(paramList.get(7))) {
|
||||||
|
strRoomID =paramList.get(7);
|
||||||
|
}
|
||||||
|
GroupPublisherService.delRoomEvt(_gid, strRoomID);
|
||||||
|
}
|
||||||
|
|
||||||
|
jedis0.hset(tag_key, "status", "2");
|
||||||
|
jedis0.hset(tag_key, "delete_status", "" + status);
|
||||||
|
jedis0.hincrBy(tag_key, "cache_ver", 1);
|
||||||
|
|
||||||
|
logger.info("删除房间" + roomid + "成功");
|
||||||
|
}
|
||||||
|
catch(Exception e){
|
||||||
|
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
|
||||||
|
if(room_lock != null) {
|
||||||
|
room_lock.unlock(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除无效的房间
|
||||||
|
*/
|
||||||
|
private void cleanInvalidRoom() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
try {
|
||||||
|
|
||||||
|
String cursor = ScanParams.SCAN_POINTER_START;
|
||||||
|
String key = "room:*";
|
||||||
|
ScanParams scanParams = new ScanParams();
|
||||||
|
scanParams.match(key);
|
||||||
|
scanParams.count(1000);
|
||||||
|
|
||||||
|
// 处理所有redis的房间
|
||||||
|
while (true){
|
||||||
|
|
||||||
|
ScanResult<String> scanResult = jedis0.scan(cursor, scanParams);
|
||||||
|
cursor = scanResult.getStringCursor();
|
||||||
|
List<String> list = scanResult.getResult();
|
||||||
|
|
||||||
|
for(int m = 0; m < list.size(); m++){
|
||||||
|
|
||||||
|
String mapentry = list.get(m);
|
||||||
|
logger.info("正在检查房间 " + mapentry);
|
||||||
|
deleteRoomFromRedis(mapentry,jedis0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("0".equals(cursor)){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
jedis0.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除亲友圈中无效的房间
|
||||||
|
*/
|
||||||
|
private void cleanGroupRoom() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
|
||||||
|
RedisLock lock = new RedisLock("room_clean", jedis11);
|
||||||
|
try {
|
||||||
|
|
||||||
|
String cursor = ScanParams.SCAN_POINTER_START;
|
||||||
|
String key = "*:rooms*";
|
||||||
|
ScanParams scanParams = new ScanParams();
|
||||||
|
scanParams.match(key);
|
||||||
|
scanParams.count(1000);
|
||||||
|
|
||||||
|
// 处理亲友圈的房间
|
||||||
|
while (true){
|
||||||
|
|
||||||
|
ScanResult<String> scanResult = jedis11.scan(cursor, scanParams);
|
||||||
|
cursor = scanResult.getStringCursor();
|
||||||
|
List<String> list = scanResult.getResult();
|
||||||
|
|
||||||
|
for(int m = 0; m < list.size(); m++){
|
||||||
|
|
||||||
|
|
||||||
|
String mapentry = list.get(m);
|
||||||
|
logger.info("正在查询群" +mapentry + "的无效房间");
|
||||||
|
Set<String> rooms = jedis11.zrangeByScore(mapentry, 100000, 1000000);
|
||||||
|
|
||||||
|
for (String roomId : rooms) {
|
||||||
|
logger.info("正在查询群" +mapentry + "的无效房间" + roomId);
|
||||||
|
boolean existed = deleteRoomFromServer(roomId,jedis0,true);
|
||||||
|
if(!existed) {
|
||||||
|
jedis11.zrem(mapentry, roomId);
|
||||||
|
logger.info("删除群" +mapentry + "的无效房间" + roomId + "因为房间不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("0".equals(cursor)){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
jedis0.close();
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除亲友圈中无效的房间
|
||||||
|
*/
|
||||||
|
private void cleanGroupMemberLog() {
|
||||||
|
int time = DateUtils.getBeginDay() - 5 * 24 * 3600;
|
||||||
|
String deleteSql = String.format("delete from group_member_log where time < %s", time);
|
||||||
|
Utility.evtdbLog(1, 1, deleteSql);
|
||||||
|
String deleteSql2 = String.format("delete from room_rec_log where time < %s and time > %s", time, time - 24 * 3600);
|
||||||
|
Utility.evtdbLog(1, 1, deleteSql2);
|
||||||
|
String deleteSql3 = String.format("delete from group_hp_log where time < %s and time > %s", time, time - 24 * 3600);
|
||||||
|
Utility.evtdbLog(1, 1, deleteSql3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(JobExecutionContext context) {
|
||||||
|
|
||||||
|
JobKey jobKey = context.getJobDetail().getKey();
|
||||||
|
if(jobKey.getName().equals("clean_group_room") || jobKey.getName().equals("clean_group_room1")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
cleanGroupRoom();
|
||||||
|
logger.info("执行成功cleanGroupMemberLog");
|
||||||
|
cleanGroupMemberLog();
|
||||||
|
}
|
||||||
|
else if(jobKey.getName().equals("clean_invalid_room")|| jobKey.getName().equals("clean_invalid_room1")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
cleanInvalidRoom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<!DOCTYPE web-app PUBLIC
|
||||||
|
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||||
|
"http://java.sun.com/dtd/web-app_2_3.dtd" >
|
||||||
|
|
||||||
|
<web-app>
|
||||||
|
<filter>
|
||||||
|
<filter-name>taurus-web</filter-name>
|
||||||
|
<filter-class>com.taurus.web.WebFilter</filter-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>main</param-name>
|
||||||
|
<param-value>com.evt.mgr.EventServer</param-value>
|
||||||
|
</init-param>
|
||||||
|
</filter>
|
||||||
|
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>taurus-web</filter-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
</web-app>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
log4j.rootLogger = INFO,consoleAppender,fileAppender
|
||||||
|
|
||||||
|
# ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n
|
||||||
|
|
||||||
|
|
||||||
|
# Regular FileAppender
|
||||||
|
log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log
|
||||||
|
log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n
|
||||||
|
log4j.appender.fileAppender.Encoding=UTF-8
|
||||||
|
log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd
|
||||||
|
log4j.appender.dailyFile.Append=true
|
||||||
|
|
||||||
|
# The file is rolled over very day
|
||||||
|
log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>database</id>
|
||||||
|
<class>com.taurus.core.plugin.database.DataBasePlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认10个 -->
|
||||||
|
<maxPool>100</maxPool>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>10</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认180000 -->
|
||||||
|
<maxLifetime>180000</maxLifetime>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 连接超时时间,默认30000-->
|
||||||
|
<connectionTimeout>10000</connectionTimeout>
|
||||||
|
<!-- 待机超时时间,单位是毫秒, 默认60000 -->
|
||||||
|
<idleTimeout>60000</idleTimeout>
|
||||||
|
|
||||||
|
<!-- jdbc 属性 -->
|
||||||
|
<props>
|
||||||
|
<useSSL>false</useSSL>
|
||||||
|
<useUnicode>true</useUnicode>
|
||||||
|
<characterEncoding>utf-8</characterEncoding>
|
||||||
|
<!-- 服务器时区 -->
|
||||||
|
<serverTimezone>UTC</serverTimezone>
|
||||||
|
<!-- 预编译缓存 -->
|
||||||
|
<cachePrepStmts>true</cachePrepStmts>
|
||||||
|
<!-- 预编译缓存大小 -->
|
||||||
|
<prepStmtCacheSize>250</prepStmtCacheSize>
|
||||||
|
<!-- 控制长度多大的sql可以被缓存 -->
|
||||||
|
<prepStmtCacheSqlLimit>2048</prepStmtCacheSqlLimit>
|
||||||
|
</props>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<databases>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.cj.jdbc.Driver</driverName>
|
||||||
|
<jdbcUrl>jdbc:mysql://123.207.203.115:8060/wb_game</jdbcUrl>
|
||||||
|
<userName>wb_game</userName>
|
||||||
|
<password>363b76546c</password>
|
||||||
|
</db>
|
||||||
|
</databases>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>20</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="123.207.203.115" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="123.207.203.115" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="123.207.203.115" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="123.207.203.115" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db9" host="123.207.203.115" password="cssq@2020" port="6379" database="9" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="123.207.203.115" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
<info name="group1_db11" host="123.207.203.115" password="cssq@2020" port="6379" database="11" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
|
||||||
|
import com.taurus.web.JettyServer;
|
||||||
|
|
||||||
|
public class MainEventMgr {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new JettyServer("src/main/webapp",8083,"/").start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="game_common" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.game</groupId>
|
||||||
|
<artifactId>game_common</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>game_common</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!--依赖 data_cache -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.data</groupId>
|
||||||
|
<artifactId>data_cache</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-core</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-permanent -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-permanent</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用redis时导入 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/jdom/jdom -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jdom</groupId>
|
||||||
|
<artifactId>jdom</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>game_common-${version}</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
<configuration>
|
||||||
|
<!-- <compilerArgument>-parameters</compilerArgument> -->
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务器内部事件常量表
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ActionEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备
|
||||||
|
*/
|
||||||
|
public static final String EVENT_READY = "ready";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备洗牌
|
||||||
|
*/
|
||||||
|
public static final String EVENT_READY_AND_XIPAI = "ready_and_xipai";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始游戏
|
||||||
|
*/
|
||||||
|
public static final String EVENT_START_GAME = "start_game";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出房间
|
||||||
|
*/
|
||||||
|
public static final String EVENT_EXIT_ROOM = "exit_room";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动
|
||||||
|
*/
|
||||||
|
public static final String EVENT_TIMER_AUTO = "timer_auto";
|
||||||
|
/**
|
||||||
|
* 托管
|
||||||
|
*/
|
||||||
|
public static final String EVENT_ENTRUST = "entrust";
|
||||||
|
/**
|
||||||
|
* 离线
|
||||||
|
*/
|
||||||
|
public static final String EVENT_OFFLINE = "offline";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 洗牌
|
||||||
|
*/
|
||||||
|
public static final String EVENT_XIPAI = "xi_pai";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 观战
|
||||||
|
*/
|
||||||
|
public static final String EVENT_SPECTATOR = "spectator";
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
public interface Constant {
|
||||||
|
/**
|
||||||
|
* 当局大结算
|
||||||
|
*/
|
||||||
|
int ENTRUST_CURREN_RESULT = 1;
|
||||||
|
/**
|
||||||
|
* 满2局大结算
|
||||||
|
*/
|
||||||
|
int ENTRUST_TWO_RESULT = 2;
|
||||||
|
/**
|
||||||
|
* 满3局大结算
|
||||||
|
*/
|
||||||
|
int ENTRUST_THREE_RESULT = 3;
|
||||||
|
/**
|
||||||
|
* 满局大结算
|
||||||
|
*/
|
||||||
|
int ENTRUST_TOTAL_RESULT1 = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未开始
|
||||||
|
*/
|
||||||
|
int ROOM_STATUS_NOBEGIN = 0;
|
||||||
|
/**
|
||||||
|
* 游戏中
|
||||||
|
*/
|
||||||
|
int ROOM_STATUS_PLAYING = 1;
|
||||||
|
/**
|
||||||
|
* 正准备删除
|
||||||
|
*/
|
||||||
|
int ROOM_STATUS_DEL_FALG = 2;
|
||||||
|
/**
|
||||||
|
* 已删除
|
||||||
|
*/
|
||||||
|
int ROOM_STATUS_DEL = 3;
|
||||||
|
/**
|
||||||
|
* 正常大结算
|
||||||
|
*/
|
||||||
|
int END_TYPE_NORMAL = 1;
|
||||||
|
/**
|
||||||
|
* 托管当局大结算
|
||||||
|
*/
|
||||||
|
int END_TYPE_ENTRUST = 2;
|
||||||
|
/**
|
||||||
|
* 体力值不足大结算
|
||||||
|
*/
|
||||||
|
int END_TYPE_HP = 3;
|
||||||
|
/**
|
||||||
|
* 申请解散大结算
|
||||||
|
*/
|
||||||
|
int END_TYPE_DISSMISS = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员解散大结算
|
||||||
|
*/
|
||||||
|
int END_TYPE_ADMIN = 5;
|
||||||
|
/**
|
||||||
|
* 体力值不足
|
||||||
|
*/
|
||||||
|
int HP_NOT_ENOUGH = -1;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,376 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.data.bean.GameBean;
|
||||||
|
import com.data.bean.GroupPlayBean;
|
||||||
|
import com.data.cache.GameCache;
|
||||||
|
import com.data.cache.GroupCache;
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis 事件控制器
|
||||||
|
*/
|
||||||
|
public class EventController {
|
||||||
|
private final static String GROUP_EVT_KEY = "evt_group_";
|
||||||
|
private final static String EVT_KEY = "event_";
|
||||||
|
private final static String CHACHE_KEY = "group1_db8";
|
||||||
|
|
||||||
|
private final static String EVT_TYPE = "E";
|
||||||
|
private final static String EVT_GID = "gid";
|
||||||
|
private final static String EVT_UID = "uid";
|
||||||
|
|
||||||
|
private static void sendGroupEvt(int type, int gid, ITObject data) {
|
||||||
|
int id = gid % 10;
|
||||||
|
data.putInt(EVT_GID, gid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(CHACHE_KEY).lpush(GROUP_EVT_KEY + id, data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendEvt(int type, int uid, ITObject data) {
|
||||||
|
int id = uid % 10;
|
||||||
|
data.putInt(EVT_UID, uid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(CHACHE_KEY).lpush(EVT_KEY + id, data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册redis事件
|
||||||
|
*
|
||||||
|
* @param uid
|
||||||
|
* @param type
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
|
public void redisEvent(int uid, int type, int num) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("N", num);
|
||||||
|
sendEvt(type, uid, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 圈子一局结束事件
|
||||||
|
*
|
||||||
|
* @param gid
|
||||||
|
* @param pid
|
||||||
|
* @param valid
|
||||||
|
*/
|
||||||
|
public void redisGroupRound(Room room, int gid, int pid, int valid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
data.putInt("valid", valid);
|
||||||
|
data.putTArray("player_list", room.getValidPlayerList());
|
||||||
|
data.putInt("perfect_round", room.endType == Constant.END_TYPE_NORMAL ? 1 : 0);
|
||||||
|
int maxPlayer = room.getValidPlayer();
|
||||||
|
if (valid == 1 && maxPlayer > 0) {
|
||||||
|
data.putInt("valid_count", 100 / maxPlayer);
|
||||||
|
} else {
|
||||||
|
data.putInt("valid_count", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxPlayer > 0) {
|
||||||
|
data.putInt("all_count", 100 / maxPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
GroupPlayBean gpb = GroupCache.getPlay(gid, pid);
|
||||||
|
if (gpb != null) {
|
||||||
|
int maxPlayers = gpb.maxPlayers;
|
||||||
|
ITObject configData = TObject.newFromJsonData(gpb.config);
|
||||||
|
int opt = configData.getInt("opt");
|
||||||
|
int gameId = gpb.gameId;
|
||||||
|
GameBean gb = GameCache.getGame(gameId);
|
||||||
|
if (gb != null) {
|
||||||
|
|
||||||
|
int score = 0;
|
||||||
|
for (Entry<Integer, Player> entry : room.playerMapById.entrySet()) {
|
||||||
|
Player player = entry.getValue();
|
||||||
|
|
||||||
|
if (player.score.total_score > score) {
|
||||||
|
score += Math.abs(player.score.total_score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
int diamo = Integer.parseInt(jedis10.hget("g{" + gid + "}:diamo", "diamo"));
|
||||||
|
if (room.round <= 1 && score == 0) {
|
||||||
|
data.putInt("valid_diamo", 0);
|
||||||
|
Integer pay = gb.pay.get("pay" + opt + "_" + maxPlayers);
|
||||||
|
jedis10.hset("g{" + gid + "}:diamo", "diamo", (diamo + pay) + "");
|
||||||
|
// 保存预扣房卡消息
|
||||||
|
Global.logger.info("返回全部房卡-----------------------");
|
||||||
|
|
||||||
|
String messagesql = String.format(
|
||||||
|
"insert into diamo_message(group_id,diamo_type,diamo_cur,diamo_num,m_time,m_state,uid,group_name,user_nick)"
|
||||||
|
+ " values(%s,%s,%s,%s,%s,%s,%s,'%s','%s')",
|
||||||
|
gid, 1, diamo + pay, pay, System.currentTimeMillis(),0, 0,gb.name,"");
|
||||||
|
if (DataBase.use() != null) {
|
||||||
|
DataBase.use().executeUpdate(messagesql);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Integer pay = gb.pay.get("pay" + opt + "_" + maxPlayers);
|
||||||
|
if (pay != null && pay > 0 && maxPlayer > 0) {
|
||||||
|
int maxRound = room.hpData.getInt("maxRound");
|
||||||
|
|
||||||
|
if (maxRound > room.round) {
|
||||||
|
double payDiamo = Math.ceil((double) pay / room.hpData.getInt("maxRound") * room.round);
|
||||||
|
data.putInt("valid_diamo", (int) payDiamo * 100);
|
||||||
|
int backDiamo = (pay - (int) payDiamo);
|
||||||
|
jedis10.hset("g{" + gid + "}:diamo", "diamo", (diamo + backDiamo) + "");
|
||||||
|
// 保存预扣房卡消息
|
||||||
|
Global.logger.info("返回部分房卡-----------------------");
|
||||||
|
|
||||||
|
String messagesql = String.format(
|
||||||
|
"insert into diamo_message(group_id,diamo_type,diamo_cur,diamo_num,m_time,m_state,uid,group_name,user_nick)"
|
||||||
|
+ " values(%s,%s,%s,%s,%s,%s,%s,'%s','%s')",
|
||||||
|
gid, 1, diamo+backDiamo, backDiamo, System.currentTimeMillis(),0, 0,gb.name,"");
|
||||||
|
|
||||||
|
DataBase.use().executeUpdate(messagesql);
|
||||||
|
} else {
|
||||||
|
data.putInt("valid_diamo", pay * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendGroupEvt(EventType.REDIS_EVENT_GROUP_ROUND, gid, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 圈子玩家一局结束事件
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* @param pid
|
||||||
|
* @param win
|
||||||
|
*/
|
||||||
|
public void redisGroupMemberRound(Player owner, int pid, boolean win, boolean hpPump, int cur_hp) {
|
||||||
|
|
||||||
|
Room room = owner.room;
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
data.putInt("uid", owner.playerid);
|
||||||
|
// if (owner.hp != null) {
|
||||||
|
// data.putInt("score", owner.hp.total_hp);
|
||||||
|
// } else {
|
||||||
|
// data.putInt("score", owner.score.total_score);
|
||||||
|
// }
|
||||||
|
data.putInt("score", owner.score.total_score);
|
||||||
|
data.putInt("time", (int) (System.currentTimeMillis() / 1000));
|
||||||
|
data.putInt("pump", owner.practicalHpPump);
|
||||||
|
data.putInt("xi_pai_total", owner.xi_pai_total);
|
||||||
|
data.putInt("win", win ? 1 : 0);
|
||||||
|
data.putInt("perfect_round", owner.room.endType == Constant.END_TYPE_NORMAL ? 1 : 0);
|
||||||
|
data.putInt("cur_hp", cur_hp);
|
||||||
|
data.putUtfString("room", room.roomid);
|
||||||
|
int maxPlayer = owner.room.getValidPlayer();
|
||||||
|
if (hpPump && maxPlayer > 0) {
|
||||||
|
data.putInt("valid_count", 100 / maxPlayer);
|
||||||
|
} else {
|
||||||
|
data.putInt("valid_count", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendGroupEvt(EventType.REDIS_EVENT_GROUP_MEMBER_ROUND, owner.room.groupId, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册redis体力值事件 reward以前没有用到,现在表示抽水值只给盟主,不给合伙人参与分成
|
||||||
|
*/
|
||||||
|
public long redisFag(Player owner, int hp, boolean hpPump, boolean mengzhu_reward, int xipai_score, boolean xipai,
|
||||||
|
String desc) {
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
Room room = owner.room;
|
||||||
|
String gm_key = GroupMemberCache.genKey(room.groupId, owner.playerid);
|
||||||
|
|
||||||
|
long cur_hp = 0;
|
||||||
|
if (hpPump) {
|
||||||
|
String strCurHp = Redis.use("group1_db10").hget(gm_key, "hp");
|
||||||
|
if (StringUtil.isNotEmpty(strCurHp)) {
|
||||||
|
cur_hp = Long.parseLong(strCurHp);
|
||||||
|
if (cur_hp < owner.practicalHpPump) {
|
||||||
|
owner.practicalHpPump = (int) cur_hp;
|
||||||
|
if (owner.practicalHpPump < 0) {
|
||||||
|
owner.practicalHpPump = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", -owner.practicalHpPump);
|
||||||
|
} else if (xipai) {
|
||||||
|
String strCurHp = Redis.use("group1_db10").hget(gm_key, "hp");
|
||||||
|
if (StringUtil.isNotEmpty(strCurHp)) {
|
||||||
|
cur_hp = Long.parseLong(strCurHp);
|
||||||
|
if (cur_hp < xipai_score) {
|
||||||
|
xipai_score = (int) cur_hp;
|
||||||
|
if (xipai_score < 0) {
|
||||||
|
xipai_score = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", -xipai_score);
|
||||||
|
} else {
|
||||||
|
cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", hp);
|
||||||
|
}
|
||||||
|
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
if (cur_hp > Integer.MAX_VALUE) {
|
||||||
|
long del_value = cur_hp - (long) Integer.MAX_VALUE;
|
||||||
|
cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", -del_value);
|
||||||
|
Redis.use("group1_db10").hincrBy(gm_key, "bank_hp", del_value);
|
||||||
|
data.putInt("hp_than_max_value", (int) del_value);
|
||||||
|
}
|
||||||
|
data.putInt("hp", hp);
|
||||||
|
data.putInt("cur_hp", (int) cur_hp);
|
||||||
|
data.putInt("pid", room.groupPid);
|
||||||
|
data.putInt("uid", owner.playerid);
|
||||||
|
data.putInt("time", (int) (System.currentTimeMillis() / 1000));
|
||||||
|
data.putUtfString("room", room.roomid);
|
||||||
|
// 临时处理
|
||||||
|
data.putUtfString("desc", StringUtil.isNotEmpty(desc) ? desc : Global.gameName + " " + room.roomid);
|
||||||
|
data.putInt("rewardType", room.rewardType);
|
||||||
|
data.putInt("rewardValueType", room.rewardValueType);
|
||||||
|
data.putInt("xipai_rewardType", room.xipai_rewardType);
|
||||||
|
data.putInt("xipai_rewardValueType", room.xipai_rewardValueType);
|
||||||
|
if (xipai) {
|
||||||
|
data.putInt("xipai", xipai_score);
|
||||||
|
int xipai_reward_value = 0;
|
||||||
|
if (room.xipai_rewardValueType == 1) {
|
||||||
|
xipai_reward_value = xipai_score;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.putInt("max_player", room.maxPlayers);
|
||||||
|
data.putInt("xipai_reward_type", room.xipai_rewardType);
|
||||||
|
data.putInt("xipai_reward_value", xipai_reward_value);
|
||||||
|
if (StringUtil.isNotEmpty(owner.prs) && !mengzhu_reward) {
|
||||||
|
data.putUtfString("prs", owner.prs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hpPump) {
|
||||||
|
data.putInt("pump", owner.practicalHpPump);
|
||||||
|
int reward_value = 0;
|
||||||
|
int max_player = room.getValidPlayer();
|
||||||
|
if (room.rewardValueType == 1) {
|
||||||
|
|
||||||
|
if (room.rewardType == 1) {
|
||||||
|
if (room.totalPump + room.basePump != 0) {
|
||||||
|
reward_value = owner.practicalHpPump
|
||||||
|
- room.basePump * owner.practicalHpPump / (room.totalPump + room.basePump);
|
||||||
|
} else {
|
||||||
|
reward_value = owner.practicalHpPump;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reward_value = room.totalPump / max_player;
|
||||||
|
if (room.basePump > 0) {
|
||||||
|
if (reward_value + (room.basePump / max_player) > owner.practicalHpPump) {
|
||||||
|
reward_value = owner.practicalHpPump - (room.basePump / max_player);
|
||||||
|
if (reward_value < 0) {
|
||||||
|
reward_value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (reward_value > owner.practicalHpPump) {
|
||||||
|
reward_value = owner.practicalHpPump;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.putInt("max_player", room.getValidPlayer());
|
||||||
|
data.putInt("reward_type", room.rewardType);
|
||||||
|
data.putInt("reward_value", reward_value);
|
||||||
|
if (StringUtil.isNotEmpty(owner.prs) && !mengzhu_reward) {
|
||||||
|
data.putUtfString("prs", owner.prs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendGroupEvt(EventType.REDIS_EVENT_GROUP_HP, room.groupId, data);
|
||||||
|
return cur_hp;
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返还钻石
|
||||||
|
*
|
||||||
|
* @param uid
|
||||||
|
* @param pay
|
||||||
|
* @param groupId
|
||||||
|
*/
|
||||||
|
public void refundDiamo(int uid, int pay, int groupId, int pid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pay", -pay);
|
||||||
|
data.putInt("game", Global.gameId);
|
||||||
|
if (groupId > 0) {
|
||||||
|
data.putInt("group", groupId);
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
}
|
||||||
|
// Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
// try {
|
||||||
|
// int diamo = Integer.parseInt(jedis0.hget("{user}:" + uid, "diamo"));
|
||||||
|
// String sql = String.format("insert into diamo_message(group_id,diamo_type,diamo_cur,diamo_num,m_time,m_state,uid)"
|
||||||
|
// + " values(%s,%s,%s,%s,%s,%s,%s)", 0, 1, diamo, pay, System.currentTimeMillis(), 0,uid);
|
||||||
|
// DataBase.use().executeUpdate(sql);
|
||||||
|
//
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// // TODO Auto-generated catch block
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }finally {
|
||||||
|
// jedis0.close();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// sendEvt(EventType.REDIS_EVENT_BACK_PAY, uid, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大局结束事件
|
||||||
|
*
|
||||||
|
* @param
|
||||||
|
* @param
|
||||||
|
* @param
|
||||||
|
*/
|
||||||
|
public void redisOver(Player owner, int time, String rec_key) {
|
||||||
|
Room room = owner.room;
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
if (StringUtil.isNotEmpty(rec_key)) {
|
||||||
|
data.putInt("is_rec", 1);
|
||||||
|
data.putUtfString("roomid", room.roomid);
|
||||||
|
data.putInt("gid", room.groupId);
|
||||||
|
data.putUtfString("rec_key", rec_key);
|
||||||
|
data.putInt("time", time);
|
||||||
|
} else {
|
||||||
|
data.putInt("is_rec", 0);
|
||||||
|
}
|
||||||
|
// 保存聊天室在线人员
|
||||||
|
String groupIdKey = "g{" + room.groupId + "}:onlines";
|
||||||
|
Map<String, String> onlines = Redis.use("group1_db10").hgetAll(groupIdKey);
|
||||||
|
ITArray array = TArray.newInstance();
|
||||||
|
Set<String> keys = onlines.keySet();
|
||||||
|
for (String key : keys) {
|
||||||
|
int uid = Integer.parseInt(key);
|
||||||
|
array.addInt(uid);
|
||||||
|
}
|
||||||
|
data.putTArray("tagIds", array);
|
||||||
|
|
||||||
|
sendEvt(EventType.REDIS_EVENT_OVER, owner.playerid, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dong.teng
|
||||||
|
*/
|
||||||
|
public class GPSUtil {
|
||||||
|
// 地球半径
|
||||||
|
private static final double EARTH_RADIUS = 6378137;
|
||||||
|
|
||||||
|
private static double radian(double lngLat) {
|
||||||
|
return lngLat * Math.PI / 180.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据两点间经纬度坐标,计算直线距离 单位 :米
|
||||||
|
*/
|
||||||
|
public static double getDistance(String gps1, String gps2) {
|
||||||
|
double distance = 0;
|
||||||
|
if (isOpenGPS(gps1) && isOpenGPS(gps2)) {
|
||||||
|
String[] gps1Arr = gps1.split(",");
|
||||||
|
String[] gps2Arr = gps2.split(",");
|
||||||
|
Double lat1 = Double.parseDouble(gps1Arr[1]);
|
||||||
|
Double lng1 = Double.parseDouble(gps1Arr[0]);
|
||||||
|
Double lat2 = Double.parseDouble(gps2Arr[1]);
|
||||||
|
Double lng2 = Double.parseDouble(gps2Arr[0]);
|
||||||
|
double radLat1 = radian(lat1);
|
||||||
|
double radLat2 = radian(lat2);
|
||||||
|
double a = radLat1 - radLat2;
|
||||||
|
double b = radian(lng1) - radian(lng2);
|
||||||
|
distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
|
||||||
|
distance *= EARTH_RADIUS;
|
||||||
|
distance = Math.round(distance * 10000) / 10000;
|
||||||
|
}
|
||||||
|
return distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两位置是否过近
|
||||||
|
*
|
||||||
|
* @param gps1
|
||||||
|
* @param gps2
|
||||||
|
* @param measure
|
||||||
|
* 衡量过近米
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isDistanceNear(String gps1, String gps2, int measure) {
|
||||||
|
return getDistance(gps1, gps2) <= measure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否打开gps
|
||||||
|
*/
|
||||||
|
public static boolean isOpenGPS(String gps) {
|
||||||
|
return StringUtil.isNotEmpty(gps) && gps.contains(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(isDistanceNear("109.19300079346,27.710248947144", "100.23030090332,25.59494972229",50));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.routes.Action;
|
||||||
|
import com.taurus.core.routes.IController;
|
||||||
|
import com.taurus.core.routes.Interceptor;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
public class GameInterceptor implements Interceptor{
|
||||||
|
public final static int NOT_PLAYER = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void intercept(Action action, IController controller,Object... args) throws Exception{
|
||||||
|
int validate = action.getActionKeyObj().validate();
|
||||||
|
Session sender = (Session)args[0];
|
||||||
|
TObject params = (TObject)args[1];
|
||||||
|
int gid = (int)args[2];
|
||||||
|
Method method = action.getMethod();
|
||||||
|
if((validate&NOT_PLAYER)!=0) {
|
||||||
|
method.invoke(controller,sender,params,gid);
|
||||||
|
}else {
|
||||||
|
Player player = Global.sessionMgr.getPlayer(sender);
|
||||||
|
if (player != null) {
|
||||||
|
Room room = player.room;
|
||||||
|
if (room == null)return;
|
||||||
|
if (room.isDestroy)return;
|
||||||
|
room.enqueueRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(player.isDestroy)return;
|
||||||
|
if(player.room.playerMapById.containsKey(player.playerid)) {
|
||||||
|
try {
|
||||||
|
method.invoke(controller, sender,params,gid,player);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(player.room.playerMapBySpectator.containsKey(player.playerid)) {
|
||||||
|
try {
|
||||||
|
method.invoke(controller, sender,params,gid,player);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.game.manager.RoomManager;
|
||||||
|
import com.game.manager.SessionManager;
|
||||||
|
import com.game.player.state.PlayerEndState;
|
||||||
|
import com.game.player.state.PlayerInitState;
|
||||||
|
import com.game.player.state.PlayerPauseState;
|
||||||
|
import com.game.player.state.PlayerPopupState;
|
||||||
|
import com.game.player.state.PlayerReadyState;
|
||||||
|
import com.game.player.state.PlayerReloadState;
|
||||||
|
import com.game.player.state.PlayerSpectatorState;
|
||||||
|
import com.game.player.state.PlayerWaitState;
|
||||||
|
import com.game.room.state.RoomDestoryGameState;
|
||||||
|
import com.game.room.state.RoomEndState;
|
||||||
|
import com.game.room.state.RoomInitState;
|
||||||
|
import com.game.room.state.RoomReloadState;
|
||||||
|
import com.game.room.state.RoomStartGameState;
|
||||||
|
import com.game.room.state.RoomWaitState;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
|
public class Global {
|
||||||
|
/**
|
||||||
|
* debug模式
|
||||||
|
*/
|
||||||
|
public static boolean loggerDebug = false;
|
||||||
|
// 日志
|
||||||
|
public static Logger logger;
|
||||||
|
// session管理器
|
||||||
|
public static SessionManager sessionMgr;
|
||||||
|
// 桌子管理器
|
||||||
|
public static RoomManager roomMgr;
|
||||||
|
|
||||||
|
public static GameController gameCtr;
|
||||||
|
|
||||||
|
public static EventController eventCtr;
|
||||||
|
/**
|
||||||
|
* 游戏ID
|
||||||
|
*/
|
||||||
|
public static int gameId = 1;
|
||||||
|
/**
|
||||||
|
* 游戏名字
|
||||||
|
*/
|
||||||
|
public static String gameName = "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
|
||||||
|
Global.sessionMgr = new SessionManager();
|
||||||
|
Global.roomMgr = new RoomManager();
|
||||||
|
Global.eventCtr = new EventController();
|
||||||
|
|
||||||
|
registerState(RoomInitState.class, new RoomInitState());
|
||||||
|
registerState(RoomEndState.class, new RoomEndState());
|
||||||
|
registerState(RoomDestoryGameState.class, new RoomDestoryGameState());
|
||||||
|
registerState(RoomWaitState.class, new RoomWaitState());
|
||||||
|
registerState(RoomReloadState.class, new RoomReloadState());
|
||||||
|
registerState(RoomStartGameState.class, new RoomStartGameState());
|
||||||
|
|
||||||
|
registerState(PlayerInitState.class, new PlayerInitState());
|
||||||
|
registerState(PlayerPauseState.class, new PlayerPauseState());
|
||||||
|
registerState(PlayerReadyState.class, new PlayerReadyState());
|
||||||
|
registerState(PlayerReloadState.class, new PlayerReloadState());
|
||||||
|
registerState(PlayerWaitState.class, new PlayerWaitState());
|
||||||
|
registerState(PlayerSpectatorState.class, new PlayerSpectatorState());
|
||||||
|
registerState(PlayerPopupState.class, new PlayerPopupState());
|
||||||
|
registerState(PlayerEndState.class, new PlayerEndState());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<Class<?>, StateBase<?>> state_map = new HashMap<>();
|
||||||
|
|
||||||
|
public static void registerState(Class<?> cls, StateBase<?> state) {
|
||||||
|
state_map.put(cls, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StateBase<?> getState(Class<?> cls) {
|
||||||
|
StateBase<?> state = state_map.get(cls);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void info(String msg, Object... params) {
|
||||||
|
if (loggerDebug) {
|
||||||
|
logger.info(Util.stringFormat(msg, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warn(String msg, Object... params) {
|
||||||
|
if (loggerDebug) {
|
||||||
|
logger.warn(Util.stringFormat(msg, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(String msg, Object... params) {
|
||||||
|
if (loggerDebug) {
|
||||||
|
logger.error(Util.stringFormat(msg, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.permanent.TPServer;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 圈子订阅服务
|
||||||
|
*/
|
||||||
|
public class GroupPublisherService {
|
||||||
|
public static final String CHANNEL_NAME = "mgr_group";
|
||||||
|
|
||||||
|
private static final String CMD_DEL_ROOM = "del_room";
|
||||||
|
private static final String CMD_UPDATE_ROOM = "update_room";
|
||||||
|
// 实时推送数据
|
||||||
|
public static final String CMD_PUSH_CHAT_ROOM = "push_chat_room";
|
||||||
|
|
||||||
|
// 玩家游戏状态推送
|
||||||
|
public static final String CMD_PLAYER_GAME_STATE = "player_game_state";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除房间事件
|
||||||
|
*
|
||||||
|
* @param groupId
|
||||||
|
* @param roomid
|
||||||
|
*/
|
||||||
|
public static void delRoomEvt(int groupId, String roomid) {
|
||||||
|
if (groupId == 0)
|
||||||
|
return;
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("gid", groupId);
|
||||||
|
data.putUtfString("roomid", roomid);
|
||||||
|
data.putUtfString("cmd", CMD_DEL_ROOM);
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
jedis11.publish(CHANNEL_NAME, data.toJson());
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新房间事件
|
||||||
|
*
|
||||||
|
* @param groupId
|
||||||
|
* @param roomid
|
||||||
|
*/
|
||||||
|
public static void updateRoomEvt(int groupId, String roomid) {
|
||||||
|
if (groupId == 0)
|
||||||
|
return;
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("gid", groupId);
|
||||||
|
data.putUtfString("roomid", roomid);
|
||||||
|
data.putUtfString("cmd", CMD_UPDATE_ROOM);
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
|
||||||
|
jedis11.publish(CHANNEL_NAME, data.toJson());
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void pushChatRoom(int groupId, ITObject data, String messageCount) {
|
||||||
|
if (groupId == 0)
|
||||||
|
return;
|
||||||
|
ITObject datas = TObject.newInstance();
|
||||||
|
datas.putInt("gid", groupId);
|
||||||
|
datas.putUtfString("messageCount", messageCount);
|
||||||
|
// datas.putInt("uid",);
|
||||||
|
datas.putTObject("datas", data);
|
||||||
|
datas.putUtfString("cmd", CMD_PUSH_CHAT_ROOM);
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
|
||||||
|
jedis11.publish(CHANNEL_NAME, datas.toJson());
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 游戏中状态推送
|
||||||
|
public static void playerGameState(int groupId, ITObject data) {
|
||||||
|
if (groupId == 0)
|
||||||
|
return;
|
||||||
|
ITObject datas = TObject.newInstance();
|
||||||
|
datas.putString("uid", data.getString("uid"));
|
||||||
|
datas.putInt("gid", groupId);
|
||||||
|
datas.putString("playing", data.getString("online"));
|
||||||
|
datas.putUtfString("cmd", CMD_PLAYER_GAME_STATE);
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
jedis11.publish(CHANNEL_NAME, datas.toJson());
|
||||||
|
jedis11.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,172 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jdom.Document;
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.input.SAXBuilder;
|
||||||
|
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.events.Event;
|
||||||
|
import com.taurus.core.events.IEventListener;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.routes.Extension;
|
||||||
|
import com.taurus.core.routes.Routes;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.permanent.TPServer;
|
||||||
|
import com.taurus.permanent.core.TPEvents;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class MainServer extends Extension implements IEventListener{
|
||||||
|
|
||||||
|
public static MainServer instance;
|
||||||
|
|
||||||
|
private static final String GMAE_CONFIG = "config/game-config.xml";
|
||||||
|
public GameSetting gameSetting;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
Global.logger = Logger.getLogger(getClass());
|
||||||
|
try {
|
||||||
|
loadConfig();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Global.init();
|
||||||
|
|
||||||
|
TPServer.me().getEventManager().addEventListener(TPEvents.EVENT_SESSION_DISCONNECT, this);
|
||||||
|
|
||||||
|
Map<String, String> svr_info = new HashMap<>();
|
||||||
|
svr_info.put("ip", gameSetting.host);
|
||||||
|
svr_info.put("port", gameSetting.port + "");
|
||||||
|
svr_info.put("intranet", gameSetting.intranet);
|
||||||
|
svr_info.put("conns", "0");
|
||||||
|
String svr_key = "svr" +gameSetting.serverId;
|
||||||
|
Global.gameId = gameSetting.gameId;
|
||||||
|
Global.gameName = Redis.use("group1_db1").hget("game:" + Global.gameId, "name");
|
||||||
|
Global.loggerDebug = gameSetting.loggerDebug;
|
||||||
|
Redis.use().hmset(svr_key, svr_info);
|
||||||
|
Redis.use().expire(svr_key, 60);
|
||||||
|
TPServer.me().getTimerPool().scheduleAtFixedRate(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
svr_info.put("conns", Global.sessionMgr.size() + "");
|
||||||
|
Redis.use().hmset(svr_key, svr_info);
|
||||||
|
Redis.use().expire(svr_key, 60);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 30, 30, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
List<Player> list = Global.sessionMgr.getPlayerList();
|
||||||
|
for (Player p : list) {
|
||||||
|
Global.sessionMgr.deleteSession(p.sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Room newRoom(String roomid, Map<String, String> redis_room_map);
|
||||||
|
|
||||||
|
public abstract Player newPlayer(int playerid, Room room, String session_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建游戏控制器
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract GameController newController();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送事件给单一客户端
|
||||||
|
* @param cmdName 事件协议号
|
||||||
|
* @param params 数据参数
|
||||||
|
* @param recipient 客户端session
|
||||||
|
*/
|
||||||
|
public void sendEvent(String cmdName, ITObject params, Session recipient) {
|
||||||
|
TPServer.me().getController().sendEvent(cmdName, params, recipient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送事件给客户端
|
||||||
|
* @param cmdName 事件协议号
|
||||||
|
* @param params 数据参数
|
||||||
|
* @param recipients 客户端session列表
|
||||||
|
*/
|
||||||
|
public void sendEvent(String cmdName, ITObject params, List<Session> recipients) {
|
||||||
|
TPServer.me().getController().sendEvent(cmdName, params, recipients);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态响应客户端请示
|
||||||
|
* @param gid 响应标识ID
|
||||||
|
* @param result 响应结果 0成功
|
||||||
|
* @param params 数据参数
|
||||||
|
* @param recipient 客户端session
|
||||||
|
*/
|
||||||
|
public void sendResponse(int gid, int result, ITObject params, Session recipient) {
|
||||||
|
TPServer.me().getController().sendResponse(gid, result, params, recipient);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void loadConfig() throws Exception {
|
||||||
|
FileInputStream is = new FileInputStream(GMAE_CONFIG);
|
||||||
|
SAXBuilder builder = new SAXBuilder();
|
||||||
|
Document document = builder.build(is);
|
||||||
|
Element root = document.getRootElement();
|
||||||
|
GameSetting config = new GameSetting();
|
||||||
|
config.host = root.getChildTextTrim("host");
|
||||||
|
config.port = Integer.parseInt(root.getChildTextTrim("port"));
|
||||||
|
config.serverId = Integer.parseInt(root.getChildTextTrim("serverId"));
|
||||||
|
config.gameId = Integer.parseInt(root.getChildTextTrim("gameId"));
|
||||||
|
config.loggerDebug =Boolean.parseBoolean(root.getChildTextTrim("loggerDebug"));
|
||||||
|
config.intranet = root.getChildTextTrim("intranet");
|
||||||
|
this.gameSetting = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEvent(Event event) {
|
||||||
|
if (event.getName() == TPEvents.EVENT_SESSION_DISCONNECT) {
|
||||||
|
Session session = (Session) event.getParameter(TPEvents.PARAM_SESSION);
|
||||||
|
Global.sessionMgr.disconnect(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configRoute(Routes me) {
|
||||||
|
me.setInterceptor(new GameInterceptor());
|
||||||
|
Global.gameCtr = newController();
|
||||||
|
me.add("",Global.gameCtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class GameSetting {
|
||||||
|
public String host = "127.0.0.1";
|
||||||
|
public String intranet = "127.0.0.1";
|
||||||
|
public int port = 6379;
|
||||||
|
public int serverId = 1;
|
||||||
|
public int gameId = 1;
|
||||||
|
public boolean loggerDebug = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,183 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网络路由处理
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class Router {
|
||||||
|
/**
|
||||||
|
* 删除房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_REMOVE_ROOM = "1000";
|
||||||
|
/**
|
||||||
|
* 更新GPS位置
|
||||||
|
*/
|
||||||
|
public static final String GAME_UPDATE_POS = "1001";
|
||||||
|
/**
|
||||||
|
* 更新GPS位置事件
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_UPDATE_POS = "2000";
|
||||||
|
/**
|
||||||
|
* 进入房
|
||||||
|
*/
|
||||||
|
public static final String GAME_JOIN_ROOM = "1002";
|
||||||
|
/**
|
||||||
|
* 玩家进入房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_PLAYER_JOIN = "2001";
|
||||||
|
/**
|
||||||
|
* 玩家退出
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_PLAYER_EXIT = "2002";
|
||||||
|
/**
|
||||||
|
* 玩家网络状态
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_PLAYER_NET_STATE = "2003";
|
||||||
|
/**
|
||||||
|
* 发送聊天
|
||||||
|
*/
|
||||||
|
public static final String GAME_INTERACTION = "1006";
|
||||||
|
/**
|
||||||
|
* 聊天事件
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_INTERACTION = "2017";
|
||||||
|
/**
|
||||||
|
* 退出房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_EXIT_ROOM = "1005";
|
||||||
|
/**
|
||||||
|
* 房主退出房间解散
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_EXIT_ROOM_DISMISS = "2008";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送准备
|
||||||
|
*/
|
||||||
|
public static final String GAME_READY = "1003";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送准备加洗牌
|
||||||
|
*/
|
||||||
|
public static final String GAME_READY_AND_XIPAI = "201004";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备加洗牌 返回
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_READY_AND_XIPAI = "202009";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备事件
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_READY = "2009";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知托管倒计时
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_READY_ENTRUST = "22010";
|
||||||
|
public static final String GAME_EVT_CANCEL_READY_ENTRUST = "22011";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String GAME_XIPAI = "20836";
|
||||||
|
|
||||||
|
public static final String GAME_EVENT_XIPAI = "20837";
|
||||||
|
|
||||||
|
public static final String GAME_EVENT_NOTIFY_XIPAI = "20838";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求开始游戏
|
||||||
|
*/
|
||||||
|
public static final String GAME_START = "1004";
|
||||||
|
/**
|
||||||
|
* 请求解散房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_ASK_DISMISS_ROOM = "1007";
|
||||||
|
/**
|
||||||
|
* 解散房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_DISMISS_ROOM = "2005";
|
||||||
|
/**
|
||||||
|
* 请求解散房间投票
|
||||||
|
*/
|
||||||
|
public static final String GAME_DISMISS_ROOM_VOTE = "1008";
|
||||||
|
/**
|
||||||
|
* 解散房间投票事件
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_DISMISS_ROOM_VOTE = "2006";
|
||||||
|
/**
|
||||||
|
* 解散房间失败
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_DISMISS_ROOM_FAIL= "2027";
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_SEND_REDPACKET= "3000";
|
||||||
|
/**
|
||||||
|
* 玩家被退出
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_KICK_PLAYER= "3001";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家缺体力值弹起
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_STAND_UP= "3004";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 托管
|
||||||
|
*/
|
||||||
|
public static final String GAME_ENTRUST= "1301";
|
||||||
|
/**
|
||||||
|
* 入座
|
||||||
|
*/
|
||||||
|
public static final String GAME_JOIN_SEAT= "1302";
|
||||||
|
/**
|
||||||
|
* 自动
|
||||||
|
*/
|
||||||
|
public static final String GAME_AUTO_CARD = "1303";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家进入观众席
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_JOIN_SPECTATOR= "3012";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家退出观众席
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_OUT_SPECTATOR= "3022";
|
||||||
|
/**
|
||||||
|
* 玩家进入观众席
|
||||||
|
*/
|
||||||
|
public static final String GAME_JOIN_SPECTATOR= "3013";
|
||||||
|
/**
|
||||||
|
* 玩家退出观众席
|
||||||
|
*/
|
||||||
|
public static final String GAME_OUT_SPECTATOR= "3023";
|
||||||
|
// public static final String SET_HOME_MEMBER_COUNT= "3009";
|
||||||
|
//推送
|
||||||
|
// public static final String GAME_PUSH_HOME_MEMBER_COUNT= "3010";
|
||||||
|
/**
|
||||||
|
* 更新玩家信息
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_UPDATE_PLAYERINFO= "3003";
|
||||||
|
/**
|
||||||
|
* 客户端数据出错,需要重连服务器,更新关键数据
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT__UPDATE_RECONECT = "3005";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void handel(Session sender, ITObject params, int gid){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void handelRoom(Player owner, ITObject params, int gid);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,302 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
public final static Random random = new Random();
|
||||||
|
static {
|
||||||
|
random.setSeed(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list to TArray
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final ITArray toTArray(List<Integer> list) {
|
||||||
|
ITArray result = new TArray();
|
||||||
|
for (Integer card : list) {
|
||||||
|
result.addInt(card);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* call checkCard
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static boolean cardInList(int eventCard, List<Integer> cardList) {
|
||||||
|
return checkCard(eventCard, cardList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static final ITArray toMPGroup(List<int[]> list) {
|
||||||
|
ITArray result = new TArray();
|
||||||
|
for (int[] card : list) {
|
||||||
|
result.addInt(card[0]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list to mod 100 list
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final List<Integer> toModList(List<Integer> list){
|
||||||
|
List<Integer> tem = new ArrayList<Integer>();
|
||||||
|
for(Integer card : list) {
|
||||||
|
tem.add(card % 100);
|
||||||
|
}
|
||||||
|
return tem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TArray to mod 100 list
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final List<Integer> toModList(ITArray list){
|
||||||
|
List<Integer> tem = new ArrayList<>();
|
||||||
|
for(int i=0;i<list.size();++i) {
|
||||||
|
tem.add(list.getInt(i) % 100);
|
||||||
|
}
|
||||||
|
return tem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取已自己为起点的位置
|
||||||
|
* @param self_seat
|
||||||
|
* @param seat
|
||||||
|
* @param people_num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final int getPos(int self_seat, int seat, int people_num) {
|
||||||
|
int cur_seat = self_seat;
|
||||||
|
int tem = seat - (cur_seat - 1);
|
||||||
|
if (tem <= 0)
|
||||||
|
tem += people_num;
|
||||||
|
return tem - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取列表中牌数量
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final int cardNum(int eventCard, List<Integer> cardList) {
|
||||||
|
int result = 0;
|
||||||
|
for (Integer card : cardList) {
|
||||||
|
if (card == eventCard) {
|
||||||
|
result += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测牌是否存在
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final boolean checkCard(int eventCard, List<Integer> cardList) {
|
||||||
|
for (Integer card : cardList) {
|
||||||
|
if (card == eventCard) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测牌数量
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @param num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final boolean checkCard(int eventCard, List<Integer> cardList, int num) {
|
||||||
|
int result = 0;
|
||||||
|
for (Integer card : cardList) {
|
||||||
|
if (card == eventCard) {
|
||||||
|
result++;
|
||||||
|
if (result == num)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测牌数量并将满足条件的删除
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @param num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final boolean checkCardAndRomve(int eventCard, List<Integer> cardList, int num) {
|
||||||
|
if (checkCard(eventCard, cardList, num)) {
|
||||||
|
removeCard(cardList, eventCard, num);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取每张牌的数量MAP
|
||||||
|
* @param cardList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final Map<Integer, Integer> getCardNumMap(List<Integer> cardList) {
|
||||||
|
Map<Integer, Integer> result = new HashMap<Integer, Integer>();
|
||||||
|
for (Integer card : cardList) {
|
||||||
|
if (!result.containsKey(card)) {
|
||||||
|
result.put(card, 1);
|
||||||
|
} else {
|
||||||
|
int num = result.get(card);
|
||||||
|
result.put(card, (num + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测牌数量
|
||||||
|
* @param map
|
||||||
|
* @param card
|
||||||
|
* @param num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean cardNum(Map<Integer, Integer> map, int card, int num) {
|
||||||
|
Integer _num = map.get(card);
|
||||||
|
if (_num != null && _num >= num) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除指定数量的牌
|
||||||
|
* @param cardList
|
||||||
|
* @param card
|
||||||
|
* @param count
|
||||||
|
*/
|
||||||
|
public static final void removeCard(List<Integer> cardList, int card, int count) {
|
||||||
|
int curCount = 0;
|
||||||
|
for (int i = 0; i < cardList.size(); i++) {
|
||||||
|
if (cardList.get(i) == card) {
|
||||||
|
cardList.remove(i);
|
||||||
|
i--;
|
||||||
|
curCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == curCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final public void addCard(ITArray opcard, int card, int num) {
|
||||||
|
for (int i = 0; i < num; ++i) {
|
||||||
|
opcard.addInt(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final public void addCard(List<Integer> cardList, int card, int num) {
|
||||||
|
for (int i = 0; i < num; ++i) {
|
||||||
|
cardList.add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取今天凌晨0点时间戳
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int todayTimeSec() {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
|
||||||
|
int timeSec = (int) (cal.getTimeInMillis() / 1000);
|
||||||
|
return timeSec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据时间戳获取指定当天凌晨10位时间戳
|
||||||
|
* @param timeSec
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int todayTimeSec(Long timeSec) {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
// 指定日期
|
||||||
|
cal.setTime(new Date(timeSec));
|
||||||
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
cal.set(Calendar.MINUTE, 0);
|
||||||
|
cal.set(Calendar.SECOND, 0);
|
||||||
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
|
return (int) (cal.getTimeInMillis() / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* msg ps : param:{},param:{}
|
||||||
|
* ==> param: abc,param:abced
|
||||||
|
* @param msg
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String stringFormat(String msg, Object... params) {
|
||||||
|
try {
|
||||||
|
if (StringUtil.isNotEmpty(msg)) {
|
||||||
|
msg = msg.replaceAll("\\{}", "\\%s");
|
||||||
|
return String.format(msg, params);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static void countLog(String key,int num,Jedis jedis) {
|
||||||
|
// String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
// String week_key = key + ":w"+DateUtils.getBeginWeek();
|
||||||
|
// String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
// jedis.incrBy(day_key,num);
|
||||||
|
// jedis.expire(day_key, 11*3600*24);
|
||||||
|
// jedis.incrBy(week_key,num);
|
||||||
|
// jedis.expire(week_key, 15*3600*24);
|
||||||
|
// jedis.incrBy(month_key,num);
|
||||||
|
// jedis.expire(month_key, 63*3600*24);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取玩家体力值
|
||||||
|
* @param gid
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static long readRedisHp(int gid,int uid) {
|
||||||
|
String key = GroupMemberCache.genKey(gid, uid);
|
||||||
|
String hp = Redis.use("group1_db10").hget(key, "hp");
|
||||||
|
long cur_hp = StringUtil.isNotEmpty(hp) ? Long.parseLong(hp) : 0;
|
||||||
|
return cur_hp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.Global;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.util.Utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回放数据记录
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class BasePlayBack {
|
||||||
|
/**
|
||||||
|
* 房间信息
|
||||||
|
*/
|
||||||
|
protected ITObject info;
|
||||||
|
/**
|
||||||
|
* 指令列表
|
||||||
|
*/
|
||||||
|
protected ITArray cmdList;
|
||||||
|
|
||||||
|
protected BasePlayBack(Room room) {
|
||||||
|
info = TObject.newInstance();
|
||||||
|
cmdList = TArray.newInstance();
|
||||||
|
info.putUtfString("roomid", room.roomid);
|
||||||
|
info.putInt("round", room.round);
|
||||||
|
info.putTObject("config", room.config);
|
||||||
|
info.putInt("banker_seat", room.bankerSeat);
|
||||||
|
info.putInt("active_seat", room.activeSeat);
|
||||||
|
info.putInt("game_id", Global.gameId);
|
||||||
|
|
||||||
|
ITArray infoList = new TArray();
|
||||||
|
for (Entry<Integer, Player> entry : room.playerMapByPlaying.entrySet()) {
|
||||||
|
Player player = entry.getValue();
|
||||||
|
if(player.already_round==0)continue;
|
||||||
|
ITObject obj = getPlayerInfo(player);
|
||||||
|
infoList.addTObject(obj);
|
||||||
|
}
|
||||||
|
info.putTArray("playerData", infoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ITObject getPlayerInfo(Player player) {
|
||||||
|
ITObject obj = TObject.newInstance();
|
||||||
|
obj.putInt("aid", player.playerid);
|
||||||
|
obj.putUtfString("nick", player.nick);
|
||||||
|
obj.putInt("sex", player.sex);
|
||||||
|
obj.putUtfString("portrait", player.portrait);
|
||||||
|
obj.putInt("seat", player.seat);
|
||||||
|
player.hp_info(obj);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addCommand(String cmd, int seat, ITObject data) {
|
||||||
|
ITObject cmdObj = TObject.newInstance();
|
||||||
|
cmdObj.putUtfString("cmd", cmd);
|
||||||
|
cmdObj.putInt("seat", seat);
|
||||||
|
cmdObj.putTObject("data", data);
|
||||||
|
cmdList.addTObject(cmdObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取战绩回放数据,保存到redisd
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ITObject getData() {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putTObject("info", info);
|
||||||
|
data.putTArray("cmdList", cmdList);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 给客户端的提示按钮
|
||||||
|
* @param seat
|
||||||
|
* @param cmdData
|
||||||
|
*/
|
||||||
|
public void addTipCommand(int seat, ITObject cmdData) {
|
||||||
|
addCommand("Tip", seat, cmdData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家操作点击的提示
|
||||||
|
* @param seat
|
||||||
|
* @param type
|
||||||
|
* @param weight
|
||||||
|
*/
|
||||||
|
public void addClickTipCommand(int seat, int type, int weight) {
|
||||||
|
ITObject cmdData = TObject.newInstance();
|
||||||
|
cmdData.putInt("weight", weight);
|
||||||
|
cmdData.putInt("type", type);
|
||||||
|
addCommand("ClickTip", seat, cmdData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小结算数据
|
||||||
|
*/
|
||||||
|
public void addResult(ITObject resultData) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
Utils.objectCopyDeep(resultData, data);
|
||||||
|
data.putInt("type", 0);
|
||||||
|
addCommand("Result", 0, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
public class Hp {
|
||||||
|
/**
|
||||||
|
* 当前体力值,每局更新,用于判断当局能输赢多少
|
||||||
|
*/
|
||||||
|
public long cur_hp = 0;
|
||||||
|
/**
|
||||||
|
* 牌局开始到结束,总输赢体力值,不包括奖励体力值。因命名之前没有奖励一说
|
||||||
|
*/
|
||||||
|
public int total_hp = 0;
|
||||||
|
/**
|
||||||
|
* 当局实际输赢体力值
|
||||||
|
*/
|
||||||
|
public int round_actual_hp = 0;
|
||||||
|
/**
|
||||||
|
* 当局本应输赢体力值
|
||||||
|
*/
|
||||||
|
public int round_answer_hp = 0;
|
||||||
|
/**
|
||||||
|
* 输赢是否已达上限
|
||||||
|
*/
|
||||||
|
public boolean upper_limit = false;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
public class JoinRoomData {
|
||||||
|
public Room room;
|
||||||
|
public String session_key;
|
||||||
|
public Session sender;
|
||||||
|
public String gps_pos;
|
||||||
|
public boolean test_user;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,614 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.MainServer;
|
||||||
|
import com.game.player.state.PlayerPopupState;
|
||||||
|
import com.game.player.state.PlayerReloadState;
|
||||||
|
import com.game.state.StateMachine;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import com.taurus.permanent.TPServer;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基本玩家对象
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Player {
|
||||||
|
/**
|
||||||
|
* 所在房间对象
|
||||||
|
*/
|
||||||
|
public Room room = null;
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
public int playerid = 0;
|
||||||
|
|
||||||
|
public String ip = null;
|
||||||
|
/**
|
||||||
|
* redis session id
|
||||||
|
*/
|
||||||
|
public String session_id = StringUtil.Empty;
|
||||||
|
public String score_key = StringUtil.Empty;
|
||||||
|
public String net_key = StringUtil.Empty;
|
||||||
|
/**
|
||||||
|
* 玩家状态机
|
||||||
|
*/
|
||||||
|
public StateMachine stateMachine = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mpnet session
|
||||||
|
*/
|
||||||
|
public volatile Session sender = null;
|
||||||
|
/**
|
||||||
|
* 是否正在链接
|
||||||
|
*/
|
||||||
|
public volatile boolean isConnect = false;
|
||||||
|
/**
|
||||||
|
* 是否是重连
|
||||||
|
*/
|
||||||
|
public boolean isReload = false;
|
||||||
|
/**
|
||||||
|
* 是否被摧毁
|
||||||
|
*/
|
||||||
|
public volatile boolean isDestroy = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前座位号
|
||||||
|
*/
|
||||||
|
public int seat = 0;
|
||||||
|
public int nextSeat = 0;
|
||||||
|
public int lastSeat = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 昵称
|
||||||
|
*/
|
||||||
|
public String nick = StringUtil.Empty;
|
||||||
|
/**
|
||||||
|
* 性别
|
||||||
|
*/
|
||||||
|
public int sex = 1;
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
public String portrait = StringUtil.Empty;
|
||||||
|
/**
|
||||||
|
* GPS位置
|
||||||
|
*/
|
||||||
|
public String gps_pos = StringUtil.Empty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0 无 1 胡 2 输
|
||||||
|
*/
|
||||||
|
public int winer = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 胡牌统计
|
||||||
|
*/
|
||||||
|
public int winCount = 0;
|
||||||
|
/**
|
||||||
|
* 准备状态
|
||||||
|
*/
|
||||||
|
public boolean ready = false;
|
||||||
|
|
||||||
|
public boolean is_white = false;
|
||||||
|
|
||||||
|
public int black_white_status = 0;
|
||||||
|
|
||||||
|
public double black_white_rate = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解散房间状态
|
||||||
|
*/
|
||||||
|
public int dismissState = 0;
|
||||||
|
/**
|
||||||
|
* 申请解散次数
|
||||||
|
*/
|
||||||
|
public int dismissCount = 0;
|
||||||
|
/**
|
||||||
|
* 计分统计
|
||||||
|
*/
|
||||||
|
public Score score;
|
||||||
|
/**
|
||||||
|
* action计时器
|
||||||
|
*/
|
||||||
|
public Timer actionTimer;
|
||||||
|
/**
|
||||||
|
* 计时器
|
||||||
|
*/
|
||||||
|
public Timer timer;
|
||||||
|
public volatile long offlineTime;
|
||||||
|
/**
|
||||||
|
* 抽水值
|
||||||
|
*/
|
||||||
|
public int practicalHpPump = 0;
|
||||||
|
/**
|
||||||
|
* 奖励数据
|
||||||
|
*/
|
||||||
|
public String prs = StringUtil.Empty;
|
||||||
|
/**
|
||||||
|
* 托管
|
||||||
|
*/
|
||||||
|
public volatile boolean entrust = false;
|
||||||
|
/**
|
||||||
|
* 自动出牌
|
||||||
|
*/
|
||||||
|
public volatile boolean manualAutoCard = false;
|
||||||
|
/**
|
||||||
|
* 是否正在观看
|
||||||
|
*/
|
||||||
|
public volatile boolean spectator = false;
|
||||||
|
/**
|
||||||
|
* 已玩局数
|
||||||
|
*/
|
||||||
|
public int already_round = 0;
|
||||||
|
/**
|
||||||
|
* 体力值
|
||||||
|
*/
|
||||||
|
public Hp hp;
|
||||||
|
/**
|
||||||
|
* 托管局数
|
||||||
|
*/
|
||||||
|
public int entrust_round = 0;
|
||||||
|
/**
|
||||||
|
* 是否检测退出限制
|
||||||
|
*/
|
||||||
|
public boolean check_exit_limit = true;
|
||||||
|
|
||||||
|
public boolean xi_pai = false;
|
||||||
|
/**
|
||||||
|
* 抽水值total
|
||||||
|
*/
|
||||||
|
public int xi_pai_total = 0;
|
||||||
|
|
||||||
|
public Player(int playerid, Room table, String session_id) {
|
||||||
|
this.room = table;
|
||||||
|
this.playerid = playerid;
|
||||||
|
this.session_id = session_id;
|
||||||
|
this.score_key = "score_" + playerid;
|
||||||
|
this.net_key = "net_" + playerid;
|
||||||
|
this.score = newScore();
|
||||||
|
this.stateMachine = new StateMachine(this);
|
||||||
|
this.isReload = false;
|
||||||
|
this.hp = new Hp();
|
||||||
|
this.xi_pai = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Score newScore() {
|
||||||
|
return new Score(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置玩家session
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
*/
|
||||||
|
public void setSender(Session sender) {
|
||||||
|
// 服务器从崩溃中重启
|
||||||
|
if (sender == null) {
|
||||||
|
this.isReload = true;
|
||||||
|
this.isConnect = false;
|
||||||
|
this.stateMachine.changeState(Global.getState(PlayerReloadState.class));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.isConnect && this.sender != null && this.sender != sender) {
|
||||||
|
Global.sessionMgr.deleteSession(this.sender);
|
||||||
|
TPServer.me().getController().disconnect(this.sender);
|
||||||
|
}
|
||||||
|
// 已经连接
|
||||||
|
this.sender = sender;
|
||||||
|
Global.sessionMgr.putPlayer(sender, this);
|
||||||
|
this.isConnect = true;
|
||||||
|
// if (this.stateMachine.curState == null || this.isReload) {
|
||||||
|
// this.stateMachine.changeState(Global.getState(PlayerInitState.class));
|
||||||
|
this.isReload = false;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计时器,Ps 到某状态自动执行某操作
|
||||||
|
*
|
||||||
|
* @param time 时间 ms
|
||||||
|
* @param cmd 计时完执行事件
|
||||||
|
* @param param 执行事件参数
|
||||||
|
*/
|
||||||
|
public void startTimer(int time, String cmd, Object param) {
|
||||||
|
stopTimer();
|
||||||
|
this.timer = new Timer(time, new Timer.ITaskHandler() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void doTask(Timer timer) {
|
||||||
|
Global.info("{} [{}] Timer Excute ActionEvent [{}] param :{}", Player.this.toString(),
|
||||||
|
stateMachine.curState.getClass().getSimpleName(), cmd,
|
||||||
|
param == null ? "null" : param.toString());
|
||||||
|
stateMachine.curState.execute(Player.this, cmd, 0, param);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
room.addTimer(this.timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定时间计时, cmd :timer_auto
|
||||||
|
*
|
||||||
|
* @param time
|
||||||
|
*/
|
||||||
|
public void startTimer(int time) {
|
||||||
|
startTimer(time, ActionEvent.EVENT_TIMER_AUTO, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认配置计时器 time : 1000ms cmd : timer_auto
|
||||||
|
*/
|
||||||
|
public void startTimer() {
|
||||||
|
startTimer(room.def_actionTimer_time, ActionEvent.EVENT_TIMER_AUTO, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopTimer() {
|
||||||
|
if (this.timer != null) {
|
||||||
|
this.timer.stop();
|
||||||
|
this.timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止所有计时器,如玩家退出某状态时
|
||||||
|
*/
|
||||||
|
public void stopAllTimer() {
|
||||||
|
stopTimer();
|
||||||
|
stopActionTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 托管计时器
|
||||||
|
*
|
||||||
|
* @param time 单位毫秒
|
||||||
|
*/
|
||||||
|
public void startActionTimer(int time, Object param) {
|
||||||
|
stopActionTimer();
|
||||||
|
this.actionTimer = new Timer(time, new Timer.ITaskHandler() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void doTask(Timer timer) {
|
||||||
|
String type = "";
|
||||||
|
if (param != null) {
|
||||||
|
ITObject netParam = (ITObject) param;
|
||||||
|
if (netParam.containsKey("type")) {
|
||||||
|
type = netParam.getUtfString("type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ActionEvent.EVENT_ENTRUST.equals(type) && !entrust) {
|
||||||
|
entrust = true;
|
||||||
|
Global.gameCtr.updatePlayerEntrust(Player.this);
|
||||||
|
}
|
||||||
|
Global.info("{} [{}] Entrust Auto Execute ActionEvent", Player.this.toString(),
|
||||||
|
stateMachine.curState.getClass().getSimpleName());
|
||||||
|
stateMachine.curState.execute(Player.this, ActionEvent.EVENT_TIMER_AUTO, 0, param);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
String type = "";
|
||||||
|
int broad = 0;
|
||||||
|
if (param != null) {
|
||||||
|
ITObject netParam = (ITObject) param;
|
||||||
|
if (netParam.containsKey("type")) {
|
||||||
|
type = netParam.getUtfString("type");
|
||||||
|
}
|
||||||
|
if (netParam.containsKey("broad")) {
|
||||||
|
broad = netParam.getInt("broad");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ActionEvent.EVENT_ENTRUST.equals(type) && broad == 1) {
|
||||||
|
this.actionTimer.parameters.put("param", param);
|
||||||
|
}
|
||||||
|
room.addTimer(this.actionTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param time 单位毫秒
|
||||||
|
*/
|
||||||
|
public void startActionTimer(int time) {
|
||||||
|
startActionTimer(time, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEntrust() {
|
||||||
|
return this.room.isEntrust() && this.entrust;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 托管.
|
||||||
|
*/
|
||||||
|
public void startActionTimer() {
|
||||||
|
stopActionTimer();
|
||||||
|
if (room.isEntrust()) {
|
||||||
|
ITObject param = TObject.newInstance();
|
||||||
|
param.putUtfString("type", ActionEvent.EVENT_ENTRUST);
|
||||||
|
if (isEntrust()) {
|
||||||
|
param.putInt("broad", 0);
|
||||||
|
startActionTimer(this.room.default_entrust_time, param);
|
||||||
|
} else {
|
||||||
|
param.putInt("broad", 1);
|
||||||
|
startActionTimer(this.room.entrustTime, param);
|
||||||
|
Global.gameCtr.entrust(Player.this, this.room.entrustTime / 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopActionTimer() {
|
||||||
|
if (this.actionTimer != null) {
|
||||||
|
if (this.actionTimer.parameters.containsKey("param")) {
|
||||||
|
ITObject param = (ITObject) this.actionTimer.parameters.get("param");
|
||||||
|
String type = "";
|
||||||
|
if (param != null) {
|
||||||
|
ITObject netParam = (ITObject) param;
|
||||||
|
if (netParam.containsKey("type")) {
|
||||||
|
type = netParam.getUtfString("type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ActionEvent.EVENT_ENTRUST.equals(type)) {
|
||||||
|
Global.gameCtr.cancelEntrust(Player.this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.actionTimer.stop();
|
||||||
|
this.actionTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getActionLeftTime() {
|
||||||
|
if (this.actionTimer != null) {
|
||||||
|
return Math.abs(this.actionTimer.getCountdownTime() / 1000);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEntrustActionLeftTime() {
|
||||||
|
if (this.actionTimer != null) {
|
||||||
|
if (this.actionTimer.parameters.containsKey("param")) {
|
||||||
|
ITObject param = (ITObject) this.actionTimer.parameters.get("param");
|
||||||
|
String type = "";
|
||||||
|
if (param != null) {
|
||||||
|
ITObject netParam = (ITObject) param;
|
||||||
|
if (netParam.containsKey("type")) {
|
||||||
|
type = netParam.getUtfString("type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ActionEvent.EVENT_ENTRUST.equals(type)) {
|
||||||
|
return Math.abs(this.actionTimer.getCountdownTime() / 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回结果
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @param gid
|
||||||
|
* @param error
|
||||||
|
*/
|
||||||
|
public void response(ITObject params, int gid, int error) {
|
||||||
|
if (!this.isConnect)
|
||||||
|
return;
|
||||||
|
if (error == 0) {
|
||||||
|
MainServer.instance.sendResponse(gid, error, params, this.sender);
|
||||||
|
} else {
|
||||||
|
MainServer.instance.sendResponse(gid, error, null, this.sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回结果
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @param gid
|
||||||
|
* @param error
|
||||||
|
*/
|
||||||
|
public void responseSpectator(ITObject params, int gid, int error) {
|
||||||
|
if (error == 0) {
|
||||||
|
MainServer.instance.sendResponse(gid, error, params, this.sender);
|
||||||
|
} else {
|
||||||
|
MainServer.instance.sendResponse(gid, error, null, this.sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送事件给客户端
|
||||||
|
*
|
||||||
|
* @param cmd
|
||||||
|
* @param param
|
||||||
|
*/
|
||||||
|
public void sendEvent(String cmd, ITObject param) {
|
||||||
|
if (!this.isConnect)
|
||||||
|
return;
|
||||||
|
MainServer.instance.sendEvent(cmd, param, this.sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取玩家信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ITObject getInfo() {
|
||||||
|
ITObject playerData = new TObject();
|
||||||
|
playerData.putInt("aid", this.playerid);
|
||||||
|
playerData.putUtfString("nick", this.nick);
|
||||||
|
playerData.putInt("sex", this.sex);
|
||||||
|
playerData.putUtfString("portrait", this.portrait);
|
||||||
|
if (StringUtil.isNotEmpty(gps_pos)) {
|
||||||
|
playerData.putUtfString("pos", gps_pos);
|
||||||
|
}
|
||||||
|
String ip = this.ip;
|
||||||
|
if (this.ip == null && this.sender != null) {
|
||||||
|
ip = sender.getAddress();
|
||||||
|
}
|
||||||
|
playerData.putInt("ready", this.ready ? 1 : 0);
|
||||||
|
playerData.putUtfString("ip", ip);
|
||||||
|
playerData.putInt("seat", this.seat);
|
||||||
|
playerData.putInt("online", this.isConnect ? 1 : 0);
|
||||||
|
playerData.putBoolean("spectator", spectator);
|
||||||
|
if (this.room.openEntrust) {
|
||||||
|
playerData.putBoolean("entrust", this.entrust);
|
||||||
|
playerData.putInt("entrust_time", getEntrustActionLeftTime());
|
||||||
|
}
|
||||||
|
hp_info(playerData);
|
||||||
|
// if (Redis.use().hexists(this.session_id, "offLineTime")) {
|
||||||
|
// int offLineTime = Integer.parseInt(Redis.use().hget(this.session_id,
|
||||||
|
// "offLineTime"));
|
||||||
|
// playerData.putInt("offLineTime", Utils.differSecond(offLineTime));
|
||||||
|
// }
|
||||||
|
return playerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITObject getReloadInfo() {
|
||||||
|
ITObject playerData = new TObject();
|
||||||
|
playerData.putInt("playerid", playerid);
|
||||||
|
if (this.room.openEntrust && this.room.isEntrust) {
|
||||||
|
playerData.putBoolean("entrust", this.entrust);
|
||||||
|
playerData.putInt("entrust_time", getEntrustActionLeftTime());
|
||||||
|
|
||||||
|
// Global.logger.info("entrust_time getEntrustActionLeftTime() : " + getEntrustActionLeftTime());
|
||||||
|
}
|
||||||
|
playerData.putBoolean("popup", this.stateMachine.curState instanceof PlayerPopupState);
|
||||||
|
hp_info(playerData);
|
||||||
|
return playerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家销毁时调用
|
||||||
|
*
|
||||||
|
* @param sysredis
|
||||||
|
*/
|
||||||
|
public void destroy(boolean sysredis) {
|
||||||
|
if (isDestroy)
|
||||||
|
return;
|
||||||
|
isDestroy = true;
|
||||||
|
stopActionTimer();
|
||||||
|
this.room.removePlayer(this, sysredis);
|
||||||
|
if (this.sender != null) {
|
||||||
|
Global.sessionMgr.deleteSession(sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int __checkSeat(int seat, int count, boolean add) {
|
||||||
|
if (seat > this.room.maxPlayers) {
|
||||||
|
seat = 1;
|
||||||
|
} else if (seat <= 0) {
|
||||||
|
seat = this.room.maxPlayers;
|
||||||
|
}
|
||||||
|
if (count == this.room.maxPlayers)
|
||||||
|
return seat;
|
||||||
|
Player player = this.room.playerMapBySeat.get(seat);
|
||||||
|
if (player == null || player.spectator) {
|
||||||
|
if (add)
|
||||||
|
seat = seat + 1;
|
||||||
|
else
|
||||||
|
seat = seat - 1;
|
||||||
|
count++;
|
||||||
|
return __checkSeat(seat, count, add);
|
||||||
|
}
|
||||||
|
return seat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化座位信息
|
||||||
|
*/
|
||||||
|
public void initSeat() {
|
||||||
|
this.nextSeat = __checkSeat(this.seat + 1, 1, true);
|
||||||
|
this.lastSeat = __checkSeat(this.seat - 1, 1, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理玩家数据
|
||||||
|
*/
|
||||||
|
public void clear() {
|
||||||
|
this.winer = 0;
|
||||||
|
this.check_exit_limit = true;
|
||||||
|
this.is_white = false;
|
||||||
|
this.manualAutoCard = false;
|
||||||
|
|
||||||
|
stopActionTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册redis事件,总服处理
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
|
public void redisEvent(int type, int num) {
|
||||||
|
Global.eventCtr.redisEvent(playerid, type, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return session_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hp_info(ITObject param) {
|
||||||
|
ITObject hp_info = TObject.newInstance();
|
||||||
|
// 下局体力值
|
||||||
|
hp_info.putLong("cur_hp", hp.cur_hp);
|
||||||
|
// 本局实际输赢体力值
|
||||||
|
hp_info.putInt("round_actual_hp", hp.round_actual_hp);
|
||||||
|
// 输赢是否已达上限
|
||||||
|
hp_info.putBoolean("upper_limit", hp.upper_limit);
|
||||||
|
// 总输赢体力值
|
||||||
|
hp_info.putInt("total_hp", hp.total_hp);
|
||||||
|
param.putTObject("hp_info", hp_info);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前体力值
|
||||||
|
*/
|
||||||
|
public Long getHp() {
|
||||||
|
return this.hp.cur_hp + (long) this.hp.round_actual_hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void updateHp() {
|
||||||
|
// this.hp.cur_hp = this.hp.cur_hp + this.hp.round_actual_hp;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public void clearHp() {
|
||||||
|
this.hp.round_actual_hp = 0;
|
||||||
|
this.hp.round_answer_hp = 0;
|
||||||
|
this.hp.upper_limit = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置托管数据
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
public void setEntrustData(ITObject data) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exitEntrust() {
|
||||||
|
if (this.room.isEntrust()) {
|
||||||
|
this.entrust_round = 0;
|
||||||
|
stopActionTimer();
|
||||||
|
this.entrust = false;
|
||||||
|
if (room.activeSeat == this.seat) {
|
||||||
|
startActionTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 牌局结束输赢总体力值,包括奖励体力值
|
||||||
|
*/
|
||||||
|
public int totalHp() {
|
||||||
|
return hp.total_hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需要抽水的具体体力值,不可负分 - 实际赢体力值,可负分 - 实际赢积分 换算成赢总体力值
|
||||||
|
*/
|
||||||
|
public int hpPumpValue() {
|
||||||
|
return hp.total_hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,158 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.data.util.ErrorCode;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Timer.ITaskHandler;
|
||||||
|
import com.game.room.state.RoomDestoryGameState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间解散处理
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomDismiss {
|
||||||
|
private Room owner;
|
||||||
|
public boolean start = false;
|
||||||
|
private boolean agree = true;
|
||||||
|
/**
|
||||||
|
* 最多申请次数,超过次数,该玩家不能申请解散
|
||||||
|
*/
|
||||||
|
private final int MAX_ASK_COUNT = 3;
|
||||||
|
|
||||||
|
private Timer timer;
|
||||||
|
private Player askPlayer;
|
||||||
|
// public int maxTime = 90;
|
||||||
|
/**
|
||||||
|
* 申请间隔
|
||||||
|
*/
|
||||||
|
public int maxTime = 3;
|
||||||
|
private List<Player> playerList;
|
||||||
|
|
||||||
|
public RoomDismiss(Room owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
playerList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void askDismiss(Player player, int gid) {
|
||||||
|
if (start) {
|
||||||
|
player.response(null, gid, 3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// if (player.dismissCount >= MAX_ASK_COUNT) {
|
||||||
|
// player.response(null, gid, ErrorCode.ROOM_DIS_UPPER_LIMIT);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (player.room.isBanDismiss) {
|
||||||
|
player.response(null, gid, ErrorCode.ROOM_DIS_NOT_ALLOWED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
askPlayer = player;
|
||||||
|
startDismiss(player);
|
||||||
|
|
||||||
|
this.dismissCallback(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void responseDismiss(Player player, boolean agree) {
|
||||||
|
if (start == false || player.dismissState != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (agree) {
|
||||||
|
player.dismissState = 1;
|
||||||
|
} else {
|
||||||
|
player.dismissState = 2;
|
||||||
|
}
|
||||||
|
dismissCallback(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dismissCallback(Player player) {
|
||||||
|
int agreeCount = 0;
|
||||||
|
int notAgreeCount = 0;
|
||||||
|
for (Player p : playerList) {
|
||||||
|
if (p.dismissState == 1) {
|
||||||
|
agreeCount += 1;
|
||||||
|
} else if (p.dismissState == 2) {
|
||||||
|
notAgreeCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
agree = notAgreeCount == 0 && agreeCount == playerList.size();
|
||||||
|
|
||||||
|
if (agree) {
|
||||||
|
|
||||||
|
interruptTimer();
|
||||||
|
} else {
|
||||||
|
if (notAgreeCount > 0) {
|
||||||
|
Global.gameCtr.dismisRoomFail(owner,playerList,askPlayer,getLeftTime());
|
||||||
|
interruptTimer();
|
||||||
|
} else {
|
||||||
|
Global.gameCtr.dismissRoom(askPlayer, null, playerList, getLeftTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void interruptTimer() {
|
||||||
|
if (timer != null)
|
||||||
|
timer.stop();
|
||||||
|
timer = null;
|
||||||
|
checkDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startDismiss(Player player) {
|
||||||
|
playerList.clear();
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
||||||
|
Player p = entry.getValue();
|
||||||
|
if (p.already_round > 0) {
|
||||||
|
playerList.add(p);
|
||||||
|
p.dismissState = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timer = new Timer(maxTime * 1000, new ITaskHandler() {
|
||||||
|
@Override
|
||||||
|
public void doTask(Timer timer) {
|
||||||
|
disMissTimeOutCallback();
|
||||||
|
Global.logger.error("[" + owner.room_key + "] room dismiss time out destroy!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
owner.addTimer(timer);
|
||||||
|
start = true;
|
||||||
|
player.dismissState = 1;
|
||||||
|
player.dismissCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload(Player owner) {
|
||||||
|
if (start) {
|
||||||
|
if (playerList.contains(owner)) {
|
||||||
|
Global.gameCtr.dismissRoom(askPlayer, owner, playerList, getLeftTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLeftTime() {
|
||||||
|
return Math.abs(timer.getCountdownTime() / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkDestroy() {
|
||||||
|
start = false;
|
||||||
|
|
||||||
|
if (agree) {
|
||||||
|
owner.saveMilitaryTotal(true);
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomDestoryGameState.class));
|
||||||
|
}
|
||||||
|
agree = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disMissTimeOutCallback() {
|
||||||
|
for (Player p : playerList) {
|
||||||
|
p.dismissState = 1;
|
||||||
|
}
|
||||||
|
agree = true;
|
||||||
|
checkDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.game.Global;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家积分统计
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* 2017年9月19日
|
||||||
|
*/
|
||||||
|
public class Score {
|
||||||
|
|
||||||
|
public Map<Integer, Integer> round_log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每局的积分统计
|
||||||
|
*/
|
||||||
|
public int round_score;
|
||||||
|
/**
|
||||||
|
* 每局的积分统计 对方积分不够的情况下, 会存在小数点问题
|
||||||
|
*/
|
||||||
|
public double d_real_score;
|
||||||
|
/**
|
||||||
|
* 总积分统计
|
||||||
|
*/
|
||||||
|
public int total_score;
|
||||||
|
|
||||||
|
public boolean negative_score;
|
||||||
|
|
||||||
|
protected Player owner;
|
||||||
|
|
||||||
|
public Score(Player owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.round_log = new HashMap<>();
|
||||||
|
this.negative_score = false;
|
||||||
|
this.d_real_score = 0;
|
||||||
|
this.initLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initLog() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetRound() {
|
||||||
|
this.round_log.clear();
|
||||||
|
this.initLog();
|
||||||
|
round_score = 0;
|
||||||
|
this.d_real_score = 0;
|
||||||
|
negative_score = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Room timer class
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Timer {
|
||||||
|
private volatile boolean _start;
|
||||||
|
private int _time;
|
||||||
|
private long _lastTime;
|
||||||
|
private ITaskHandler _task;
|
||||||
|
public Map<Object, Object> parameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param time 单位毫秒
|
||||||
|
* @param task
|
||||||
|
*/
|
||||||
|
public Timer(int time, ITaskHandler task) {
|
||||||
|
_lastTime = System.currentTimeMillis();
|
||||||
|
_time = time;
|
||||||
|
_task = task;
|
||||||
|
this.parameters = new HashMap<Object, Object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
if (_start)
|
||||||
|
return;
|
||||||
|
_start = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void restart() {
|
||||||
|
_lastTime = System.currentTimeMillis();
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void executeTask() {
|
||||||
|
if (!_start)
|
||||||
|
return;
|
||||||
|
if (System.currentTimeMillis() - _lastTime >= _time) {
|
||||||
|
_start = false;
|
||||||
|
if (_task != null) {
|
||||||
|
_task.doTask(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取倒计时,单位毫秒
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getCountdownTime() {
|
||||||
|
return (int) (_time - (System.currentTimeMillis() - _lastTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
if (!_start)
|
||||||
|
return;
|
||||||
|
_start = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRuning() {
|
||||||
|
return _start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ITaskHandler {
|
||||||
|
|
||||||
|
public void doTask(Timer timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,302 @@
|
||||||
|
package com.game.manager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import com.data.util.ErrorCode;
|
||||||
|
import com.game.Constant;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.MainServer;
|
||||||
|
import com.game.Router;
|
||||||
|
import com.game.data.JoinRoomData;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.room.state.RoomReloadState;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.plugin.redis.RedisLock;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间管理类
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomManager {
|
||||||
|
|
||||||
|
public ConcurrentHashMap<String, Room> tableMap;
|
||||||
|
|
||||||
|
public RoomManager() {
|
||||||
|
this.tableMap = new ConcurrentHashMap<String, Room>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进入房间
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
* @param session_key
|
||||||
|
* @param gid
|
||||||
|
*/
|
||||||
|
public void joinRoom(Session sender, String session_key, int gid, String gps_pos) {
|
||||||
|
Jedis jedis = Redis.use().getJedis();
|
||||||
|
try {
|
||||||
|
if (!jedis.exists(session_key)) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._NO_SESSION, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String room_key = jedis.hget(session_key, "room");
|
||||||
|
if (StringUtil.isEmpty(room_key)) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.NO_ROOM_NUM, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, String> room_map = null;
|
||||||
|
RedisLock lock = new RedisLock(room_key, jedis);
|
||||||
|
try {
|
||||||
|
lock.lock();
|
||||||
|
room_map = jedis.hgetAll(room_key);
|
||||||
|
String status = room_map.get("status");
|
||||||
|
if (StringUtil.isEmpty(status)) {
|
||||||
|
Global.gameCtr.delRoomSeat(session_key, room_key);
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.NO_ROOM_NUM, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (status.equals("3") || status.equals("2")) {
|
||||||
|
Global.gameCtr.delRoomSeat(session_key, room_key);
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.GROUP_ROOM_DEL, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Global.gameId != Integer.parseInt(room_map.get("game"))) {
|
||||||
|
Global.logger.error("joinRoom gameId:" + Global.gameId + " != gameId:"
|
||||||
|
+ Integer.parseInt(room_map.get("game")));
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.NO_SERVICE, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String room_id = room_map.get("id");
|
||||||
|
Room room = null;
|
||||||
|
if (this.tableMap.containsKey(room_id)) {
|
||||||
|
room = this.tableMap.get(room_id);
|
||||||
|
if (room.isDestroy) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._FAILED, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
room = MainServer.instance.newRoom(room_id, room_map);
|
||||||
|
room.loadRedisPlayer();
|
||||||
|
|
||||||
|
this.tableMap.put(room_id, room);
|
||||||
|
room.start();
|
||||||
|
room.stateMachine.changeState(Global.getState(RoomReloadState.class));
|
||||||
|
}
|
||||||
|
if (room.isActive() == false) {
|
||||||
|
room.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.setHashId(session_key);
|
||||||
|
final JoinRoomData jrd = new JoinRoomData();
|
||||||
|
jrd.room = room;
|
||||||
|
jrd.session_key = session_key;
|
||||||
|
jrd.sender = sender;
|
||||||
|
jrd.gps_pos = gps_pos;
|
||||||
|
room.enqueueRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
int result = Global.gameCtr.joinRoom(jrd, gid);
|
||||||
|
if (result != 0) {
|
||||||
|
MainServer.instance.sendResponse(gid, result, null, sender);
|
||||||
|
}
|
||||||
|
Global.logger.info(session_key + " join [" + jrd.room.room_key + "]!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
MainServer.instance.sendResponse(gid, 500, null, sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
lock.unlock(false);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
MainServer.instance.sendResponse(gid, 500, null, sender);
|
||||||
|
} finally {
|
||||||
|
jedis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进入房间(观战)
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
* @param session_key
|
||||||
|
* @param gid
|
||||||
|
*/
|
||||||
|
public void joinRoomOfSpectator(Session sender, String session_key, int gid, String gps_pos) {
|
||||||
|
Jedis jedis = Redis.use().getJedis();
|
||||||
|
try {
|
||||||
|
if (!jedis.exists(session_key)) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._NO_SESSION, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String room_key = jedis.hget(session_key, "spectator_room");
|
||||||
|
|
||||||
|
if (StringUtil.isEmpty(room_key)) {
|
||||||
|
Global.logger.info("找不到观战房间");
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.NO_ROOM_NUM, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, String> room_map = null;
|
||||||
|
RedisLock lock = new RedisLock(room_key, jedis);
|
||||||
|
try {
|
||||||
|
lock.lock();
|
||||||
|
room_map = jedis.hgetAll(room_key);
|
||||||
|
String status = room_map.get("status");
|
||||||
|
// if (StringUtil.isEmpty(status)) {
|
||||||
|
// Global.gameCtr.delRoomSeat(session_key, room_key);
|
||||||
|
// MainServer.instance.sendResponse(gid, ErrorCode.NO_ROOM_NUM, null, sender);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
if (status.equals("3") || status.equals("2")) {
|
||||||
|
Global.gameCtr.delRoomSeat(session_key, room_key);
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.GROUP_ROOM_DEL, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Global.gameId != Integer.parseInt(room_map.get("game"))) {
|
||||||
|
Global.logger.error("joinRoom gameId:" + Global.gameId + " != gameId:"
|
||||||
|
+ Integer.parseInt(room_map.get("game")));
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.NO_SERVICE, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String room_id = room_map.get("id");
|
||||||
|
Room room = null;
|
||||||
|
if (this.tableMap.containsKey(room_id)) {
|
||||||
|
room = this.tableMap.get(room_id);
|
||||||
|
if (room.isDestroy) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._FAILED, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.setHashId(session_key);
|
||||||
|
final JoinRoomData jrd = new JoinRoomData();
|
||||||
|
jrd.room = room;
|
||||||
|
jrd.session_key = session_key;
|
||||||
|
jrd.sender = sender;
|
||||||
|
jrd.gps_pos = gps_pos;
|
||||||
|
|
||||||
|
room.enqueueRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Global.logger.info(session_key + " join [" + jrd.room.room_key + "] begin!");
|
||||||
|
|
||||||
|
int result = Global.gameCtr.joinRoomOfSpectator(jrd, gid);
|
||||||
|
if (result != 0) {
|
||||||
|
MainServer.instance.sendResponse(gid, result, null, sender);
|
||||||
|
}
|
||||||
|
Global.logger.info(session_key + " join [" + jrd.room.room_key + "]! end");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
MainServer.instance.sendResponse(gid, 500, null, sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
lock.unlock(false);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
MainServer.instance.sendResponse(gid, 500, null, sender);
|
||||||
|
} finally {
|
||||||
|
jedis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出房间(观战)
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
* @param session_key
|
||||||
|
* @param gid
|
||||||
|
*/
|
||||||
|
public void outRoomOfSpectator(Session sender, String session_key, int gid, int uid) {
|
||||||
|
Jedis jedis = Redis.use().getJedis();
|
||||||
|
try {
|
||||||
|
if (!jedis.exists(session_key)) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._NO_SESSION, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String room_key = jedis.hget(session_key, "spectator_room");
|
||||||
|
if (StringUtil.isEmpty(room_key)) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.NO_ROOM_NUM, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, String> room_map = null;
|
||||||
|
RedisLock lock = new RedisLock(room_key, jedis);
|
||||||
|
try {
|
||||||
|
lock.lock();
|
||||||
|
room_map = jedis.hgetAll(room_key);
|
||||||
|
|
||||||
|
String room_id = room_map.get("id");
|
||||||
|
Room room = null;
|
||||||
|
if (this.tableMap.containsKey(room_id)) {
|
||||||
|
room = this.tableMap.get(room_id);
|
||||||
|
if (room.isDestroy) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._FAILED, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ITObject data = new TObject();
|
||||||
|
data.putInt("player", uid);
|
||||||
|
|
||||||
|
room.playerMapBySpectator.remove(uid);
|
||||||
|
room.broadCastToClient(0, Router.GAME_EVT_OUT_SPECTATOR, data);
|
||||||
|
room.broadCastToClientOfSpectator(Router.GAME_EVT_OUT_SPECTATOR, data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.setHashId(session_key);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
lock.unlock(false);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
MainServer.instance.sendResponse(gid, 500, null, sender);
|
||||||
|
} finally {
|
||||||
|
jedis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解散房间
|
||||||
|
*
|
||||||
|
* @param roomid 房间ID
|
||||||
|
*/
|
||||||
|
public void dismissRoom(String roomid, boolean sendEvt) {
|
||||||
|
Room room = this.tableMap.get(roomid);
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
if (room == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RedisLock lock = new RedisLock(room.room_key, jedis0);
|
||||||
|
try {
|
||||||
|
lock.lock();
|
||||||
|
room.endType = Constant.END_TYPE_ADMIN;
|
||||||
|
room.dismisType = 2;
|
||||||
|
room.destroy(sendEvt);
|
||||||
|
this.tableMap.remove(roomid);
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
package com.game.manager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.Router;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前节点 玩家session管理类
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SessionManager {
|
||||||
|
|
||||||
|
private ConcurrentMap<Session, Player> sessionMap = null;
|
||||||
|
|
||||||
|
public SessionManager() {
|
||||||
|
this.sessionMap = new ConcurrentHashMap<Session, Player>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过sessionid获取玩家
|
||||||
|
*
|
||||||
|
* @param sessionid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Player getPlayer(Session sessionid) {
|
||||||
|
return this.sessionMap.get(sessionid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加session
|
||||||
|
*
|
||||||
|
* @param sessionid
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
public void putPlayer(Session sessionid, Player player) {
|
||||||
|
this.sessionMap.put(sessionid, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除session
|
||||||
|
*
|
||||||
|
* @param sessionid
|
||||||
|
*/
|
||||||
|
public Player deleteSession(Session sessionid) {
|
||||||
|
if (sessionid == null)
|
||||||
|
return null;
|
||||||
|
sessionid.setHashId(null);
|
||||||
|
Player player = this.getPlayer(sessionid);
|
||||||
|
if (player != null) {
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("id", player.playerid);
|
||||||
|
player.room.broadCastToClientOfSpectator(Router.GAME_OUT_SPECTATOR, param);
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
jedis0.hdel("{user}:" + player.playerid, "spectator_room");
|
||||||
|
jedis0.close();
|
||||||
|
Global.logger.info("player.playerid:" + player.playerid);
|
||||||
|
}
|
||||||
|
this.sessionMap.remove(sessionid);
|
||||||
|
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前服务器在线人数
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int size() {
|
||||||
|
return this.sessionMap.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Player> getPlayerList() {
|
||||||
|
List<Player> list = new ArrayList<Player>();
|
||||||
|
list.addAll(sessionMap.values());
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断线
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
*/
|
||||||
|
public synchronized void disconnect(Session sender) {
|
||||||
|
Player player = this.deleteSession(sender);
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.room.enqueueRunnable(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (player.isDestroy)
|
||||||
|
return;
|
||||||
|
if (player.sender == sender) {
|
||||||
|
player.isConnect = false;
|
||||||
|
Global.gameCtr.playerNetState(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.Router;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
|
||||||
|
public class PlayerEndState extends StateBase<Player> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(Player owner) {
|
||||||
|
// owner.clear();
|
||||||
|
owner.startActionTimer();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void exit(Player owner) {
|
||||||
|
owner.stopActionTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
switch(cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
case ActionEvent.EVENT_TIMER_AUTO:
|
||||||
|
case ActionEvent.EVENT_ENTRUST:
|
||||||
|
Global.gameCtr.ready(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_READY_AND_XIPAI:
|
||||||
|
Global.gameCtr.readyAndXipai(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_XIPAI:
|
||||||
|
if (owner.xi_pai == false)
|
||||||
|
{
|
||||||
|
owner.xi_pai = true;
|
||||||
|
ITObject param1 = new TObject();
|
||||||
|
param1.putInt("result", 0);
|
||||||
|
owner.sendEvent(Router.GAME_EVENT_XIPAI, param1);
|
||||||
|
|
||||||
|
owner.room.redisUpdateXiPaiPlayer(owner);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ITObject param1 = new TObject();
|
||||||
|
param1.putInt("result", 1);
|
||||||
|
owner.sendEvent(Router.GAME_EVENT_XIPAI, param1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家进房间的初始状态
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerInitState extends StateBase<Player> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(Player owner) {
|
||||||
|
if(owner.room.round==0&&owner.room.kickTime>0) {
|
||||||
|
owner.startActionTimer(owner.room.kickTime * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exit(Player owner) {
|
||||||
|
owner.stopActionTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
Global.gameCtr.ready(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_READY_AND_XIPAI:
|
||||||
|
Global.gameCtr.readyAndXipai(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_EXIT_ROOM:
|
||||||
|
if(owner.room.round>0)return;
|
||||||
|
Global.gameCtr.exitRoom(owner, gid,false);
|
||||||
|
break;
|
||||||
|
// case ActionEvent.EVENT_TIMER_AUTO:
|
||||||
|
// if(owner.room.round>0)return;
|
||||||
|
// Global.gameCtr.exitRoom(owner, gid,true);
|
||||||
|
// break;
|
||||||
|
case ActionEvent.EVENT_SPECTATOR:
|
||||||
|
if(owner.room.round>0)return;
|
||||||
|
Global.gameCtr.spectator(owner, gid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家暂停状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerPauseState extends StateBase<Player> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void toNextState(Player owner) {
|
||||||
|
owner.stateMachine.lastState.toNextState(owner);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.Router;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家缺体力值弹出状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerPopupState extends StateBase<Player>{
|
||||||
|
/**
|
||||||
|
* 进入状态时处理
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void enter(Player owner) {
|
||||||
|
owner.spectator = true;
|
||||||
|
ITObject msg = TObject.newInstance();
|
||||||
|
msg.putInt("seat", owner.seat);
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_STAND_UP, msg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出状态时处理
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void exit(Player owner) {
|
||||||
|
owner.spectator = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家准备状态
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerReadyState extends StateBase<Player> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(Player owner) {
|
||||||
|
owner.ready = true;
|
||||||
|
owner.room.stateMachine.execute(ActionEvent.EVENT_READY, 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
if(owner.room.round>0)return;
|
||||||
|
if(cmd.equals(ActionEvent.EVENT_EXIT_ROOM)) {
|
||||||
|
Global.gameCtr.exitRoom(owner, gid,false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家重连状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerReloadState extends StateBase<Player> {
|
||||||
|
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
Global.gameCtr.ready(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_READY_AND_XIPAI:
|
||||||
|
Global.gameCtr.readyAndXipai(owner);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 观看状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerSpectatorState extends StateBase<Player> {
|
||||||
|
/**
|
||||||
|
* 进入状态时处理
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void enter(Player owner) {
|
||||||
|
owner.spectator = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出状态时处理
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void exit(Player owner) {
|
||||||
|
owner.spectator = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_EXIT_ROOM:
|
||||||
|
Global.gameCtr.exitRoom(owner, gid,false);
|
||||||
|
break;
|
||||||
|
// case ActionEvent.EVENT_READY:
|
||||||
|
// if(owner.room.playerMapBySeat.containsKey(owner.seat)) {
|
||||||
|
// Global.gameCtr.ready(owner);
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家等待状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerWaitState extends StateBase<Player> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间结束状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomDestoryGameState extends StateBase<Room> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(Room owner) {
|
||||||
|
Global.roomMgr.dismissRoom(owner.roomid,true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerEndState;
|
||||||
|
import com.game.player.state.PlayerPopupState;
|
||||||
|
import com.game.player.state.PlayerReadyState;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
|
||||||
|
public class RoomEndState extends StateBase<Room>{
|
||||||
|
@Override
|
||||||
|
public void enter(Room owner) {
|
||||||
|
owner.saveSocre();
|
||||||
|
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
||||||
|
Player player = entry.getValue();
|
||||||
|
player.stateMachine.changeState( Global.getState(PlayerEndState.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(Room owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
||||||
|
Player player = entry.getValue();
|
||||||
|
if(player.stateMachine.curState instanceof PlayerPopupState) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!(player.stateMachine.curState instanceof PlayerReadyState)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomStartGameState.class));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerReadyState;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间初始状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomInitState extends StateBase<Room> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Room owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapByPlaying.entrySet()) {
|
||||||
|
if (!(entry.getValue().stateMachine.curState instanceof PlayerReadyState)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (owner.maxPlayers == owner.playerMapByPlaying.size()) {
|
||||||
|
owner.redis_room_map.put("open","0");
|
||||||
|
Redis.use().hmset(owner.room_key, owner.redis_room_map);
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomWaitState.class));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerPopupState;
|
||||||
|
import com.game.player.state.PlayerReadyState;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间重连状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomReloadState extends StateBase<Room>{
|
||||||
|
|
||||||
|
public void execute(Room owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
||||||
|
Player p = entry.getValue();
|
||||||
|
if (!(p.stateMachine.curState instanceof PlayerReadyState || p.stateMachine.curState instanceof PlayerPopupState)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(owner.round == 0 &&owner.startGameNum == 0 && owner.playerMapBySeat.size()>1) {
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomWaitState.class));
|
||||||
|
}else {
|
||||||
|
int num = owner.startGameNum ==0 ? 2 :owner.startGameNum;
|
||||||
|
if(owner.playerMapBySeat.size() >= num) {
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomStartGameState.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间开始游戏
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomStartGameState extends StateBase<Room>{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间等待状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomWaitState extends StateBase<Room> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Room owner, String cmd, int gid, Object param) {
|
||||||
|
switch(cmd) {
|
||||||
|
case ActionEvent.EVENT_START_GAME:
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
Player player = entry.getValue();
|
||||||
|
player.clear();
|
||||||
|
}
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomStartGameState.class));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.game.state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态基类
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
public abstract class StateBase<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进入状态时处理
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void enter(T owner) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出状态时处理
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void exit(T owner) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从该状态转向下一个状态的处理
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void toNextState(T owner) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行事件处理
|
||||||
|
* @param owner
|
||||||
|
* @param cmd
|
||||||
|
* @param gid
|
||||||
|
* @param param
|
||||||
|
*/
|
||||||
|
public void execute(T owner, String cmd, int gid, Object param) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重连
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void reload(T owner) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.game.state;
|
||||||
|
|
||||||
|
import com.game.Global;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态机
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public class StateMachine {
|
||||||
|
|
||||||
|
private Object owner = null;
|
||||||
|
/**
|
||||||
|
* 当前状态
|
||||||
|
*/
|
||||||
|
public StateBase curState = null;
|
||||||
|
public StateBase lastState = null;
|
||||||
|
|
||||||
|
public StateMachine(Object owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 改变状态
|
||||||
|
* @param state
|
||||||
|
*/
|
||||||
|
public void changeState(StateBase state) {
|
||||||
|
if (curState != null) {
|
||||||
|
this.curState.exit(this.owner);
|
||||||
|
}
|
||||||
|
if (this.lastState != this.curState) {
|
||||||
|
this.lastState = this.curState;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Global.loggerDebug) {
|
||||||
|
String old_log = this.curState != null ? curState.getClass().getSimpleName() : "null";
|
||||||
|
Global.logger.info(owner + " [" + old_log + "]to[" + state.getClass().getSimpleName() + "]");
|
||||||
|
}
|
||||||
|
this.curState = state;
|
||||||
|
this.curState.enter(this.owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toLastState() {
|
||||||
|
if (lastState == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.changeState(this.lastState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toNextState() {
|
||||||
|
this.curState.toNextState(this.owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行服务器内部事件
|
||||||
|
* @param cmd
|
||||||
|
* @param gid
|
||||||
|
* @param param
|
||||||
|
*/
|
||||||
|
public void execute(String cmd, int gid, Object param) {
|
||||||
|
this.curState.execute(this.owner, cmd, gid, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
|
||||||
|
<gameSetting>
|
||||||
|
<host>192.168.3.31</host>
|
||||||
|
<intranet>192.168.3.31</intranet>
|
||||||
|
<port>8842</port>
|
||||||
|
<serverId>8840</serverId>
|
||||||
|
<gameId>10</gameId>
|
||||||
|
<loggerDebug>true</loggerDebug>
|
||||||
|
</gameSetting>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
log4j.rootLogger = INFO,consoleAppender,fileAppender
|
||||||
|
|
||||||
|
# ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n
|
||||||
|
|
||||||
|
|
||||||
|
# Regular FileAppender
|
||||||
|
log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log
|
||||||
|
log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n
|
||||||
|
log4j.appender.fileAppender.Encoding=UTF-8
|
||||||
|
log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd
|
||||||
|
log4j.appender.dailyFile.Append=true
|
||||||
|
|
||||||
|
# The file is rolled over very day
|
||||||
|
log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>20</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="123.207.203.115" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="123.207.203.115" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="123.207.203.115" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="123.207.203.115" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db9" host="123.207.203.115" password="cssq@2020" port="6379" database="9" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="123.207.203.115" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
<info name="group1_db11" host="123.207.203.115" password="cssq@2020" port="6379" database="11" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
<server>
|
||||||
|
<!-- 计时器线程池大小-->
|
||||||
|
<timerThreadPoolSize>1</timerThreadPoolSize>
|
||||||
|
<!-- 协议包压缩门槛 (单位字节),当协议包大于设定的值则会进行压缩 -->
|
||||||
|
<protocolCompression>512</protocolCompression>
|
||||||
|
<!-- 读缓冲区类型 nio Direct Buffer 或者 Heap Buffer-->
|
||||||
|
<readBufferType>Heap</readBufferType>
|
||||||
|
<!-- 写入冲区类型 nio Direct Buffer 或者 Heap Buffer-->
|
||||||
|
<writeBufferType>Heap</writeBufferType>
|
||||||
|
<!-- 最大的数据包大小 -->
|
||||||
|
<maxPacketSize>524288</maxPacketSize>
|
||||||
|
<!-- 最大读取缓存大小 -->
|
||||||
|
<maxReadBufferSize>1024</maxReadBufferSize>
|
||||||
|
<!-- 最大写入缓存大小 -->
|
||||||
|
<maxWriteBufferSize>32768</maxWriteBufferSize>
|
||||||
|
<!-- 会话队列的大小-->
|
||||||
|
<sessionPacketQueueSize>160</sessionPacketQueueSize>
|
||||||
|
|
||||||
|
<!-- Thread Pool Size of the 3 main stages of the Bitswarm Engine -->
|
||||||
|
<socketAcceptorThreadPoolSize>1</socketAcceptorThreadPoolSize>
|
||||||
|
<socketReaderThreadPoolSize>2</socketReaderThreadPoolSize>
|
||||||
|
<socketWriterThreadPoolSize>1</socketWriterThreadPoolSize>
|
||||||
|
|
||||||
|
<!-- Enable disable Nagle algorithm on sockets, true == disable -->
|
||||||
|
<tcpNoDelay>true</tcpNoDelay>
|
||||||
|
<!-- 会话超时时间(单位秒)-->
|
||||||
|
<sessionTimeout>15</sessionTimeout>
|
||||||
|
|
||||||
|
<!-- Bind socket addresses -->
|
||||||
|
<socketAddresses>
|
||||||
|
<socket address="0.0.0.0" port="8861" type="TCP" />
|
||||||
|
</socketAddresses>
|
||||||
|
|
||||||
|
<!-- Ip addresses filter-->
|
||||||
|
<ipFilter>
|
||||||
|
<addressBlackList>
|
||||||
|
<string>1.2.3.4</string>
|
||||||
|
</addressBlackList>
|
||||||
|
<addressWhiteList>
|
||||||
|
<string>127.0.0.1</string>
|
||||||
|
</addressWhiteList>
|
||||||
|
<maxConnectionsPerAddress>10000</maxConnectionsPerAddress>
|
||||||
|
</ipFilter>
|
||||||
|
|
||||||
|
<webSocket>
|
||||||
|
<isActive>false</isActive>
|
||||||
|
<address>0.0.0.0</address>
|
||||||
|
<port>80</port>
|
||||||
|
</webSocket>
|
||||||
|
|
||||||
|
<!-- Main extension class -->
|
||||||
|
<extensionConfig>
|
||||||
|
<name>extension - test</name>
|
||||||
|
<className>extend.mj.EXMainServer</className>
|
||||||
|
</extensionConfig>
|
||||||
|
|
||||||
|
<!-- The system thread pool config -->
|
||||||
|
<systemThreadPoolConfig>
|
||||||
|
<name>Sys</name>
|
||||||
|
<corePoolSize>2</corePoolSize>
|
||||||
|
<maxPoolSize>8</maxPoolSize>
|
||||||
|
<keepAliveTime>60000</keepAliveTime>
|
||||||
|
<maxQueueSize>20000</maxQueueSize>
|
||||||
|
</systemThreadPoolConfig>
|
||||||
|
|
||||||
|
<!-- The extension thread pool config -->
|
||||||
|
<extensionThreadPoolConfig>
|
||||||
|
<name>Ext</name>
|
||||||
|
<corePoolSize>2</corePoolSize>
|
||||||
|
<maxPoolSize>8</maxPoolSize>
|
||||||
|
<keepAliveTime>60000</keepAliveTime>
|
||||||
|
<maxQueueSize>20000</maxQueueSize>
|
||||||
|
</extensionThreadPoolConfig>
|
||||||
|
|
||||||
|
</server>
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.game</groupId>
|
||||||
|
<artifactId>game_mj_hongzhong</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>game_mj_hongzhong</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!--依赖 game_common -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.game</groupId>
|
||||||
|
<artifactId>game_common</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>game_mj_hongzhong</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
<configuration>
|
||||||
|
<!-- <compilerArgument>-parameters</compilerArgument> -->
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
public class CardNiao {
|
||||||
|
public int card;
|
||||||
|
|
||||||
|
public int playerId=0;
|
||||||
|
public int score = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public ITObject toMP(){
|
||||||
|
ITObject obj = TObject.newInstance();
|
||||||
|
obj.putInt("card", card);
|
||||||
|
obj.putInt("score", score);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
public static final int HONGZHONG = 412;
|
||||||
|
public static final int XIPAI_SCORE = 10;
|
||||||
|
|
||||||
|
public static final String ROOM_CONFIG_DIANPAO = "dianpao";
|
||||||
|
public static final String ROOM_CONFIG_ZHUANGXIAN = "zhuangxian";
|
||||||
|
public static final String ROOM_CONFIG_FENGDING = "fengding";
|
||||||
|
public static final String ROOM_CONFIG_FENGDING_SCORE = "fengding_score";
|
||||||
|
public static final String ROOM_CONFIG_PIAO_NIAO = "piao_niao"; //0:不嫖 1:自由票 2:固定票
|
||||||
|
public static final String ROOM_CONFIG_PIAO_NIAO_AUTO = "auto_piao"; //piao fen
|
||||||
|
public static final String ROOM_CONFIG_PIAO_NIAO_OPT = "piao_niao_opt"; //piao fen
|
||||||
|
public static final String ROOM_CONFIG_QIDUI = "qidui";
|
||||||
|
public static final String ROOM_CONFIG_NIAO = "niao";
|
||||||
|
public static final String ROOM_CONFIG_NIAO_OPT = "niao_opt";
|
||||||
|
public static final String ROOM_CONFIG_NIAO_OPT_SCORE = "niao_opt_score";
|
||||||
|
public static final String ROOM_CONFIG_HONGZHONG = "laizi";
|
||||||
|
public static final String ROOM_CONFIG_WUGUI_JIABEI = "wuguijiabei";
|
||||||
|
public static final String ROOM_CONFIG_WUGUI_ZHUOPAO_JIABEI = "wuguizhuopaojiabei";
|
||||||
|
public static final String ROOM_CONFIG_QIANGKONG = "qiangkong";
|
||||||
|
public static final String ROOM_CONFIG_QIANGKONG_NIAO = "qiangkong_niao";
|
||||||
|
public static final String ROOM_CONFIG_HONGZHONG8 = "laizi8";
|
||||||
|
public static final String ROOM_CONFIG_NONEALL = "none_is_all";
|
||||||
|
public static final String ROOM_CONFIG_NIAO_SCORE = "niao_score";
|
||||||
|
public static final String ROOM_CONFIG_QG_TYPE = "qianggang_type";
|
||||||
|
public static final String ROOM_CONFIG_JIANGMA = "jiangma";
|
||||||
|
public static final String ROOM_CONFIG_HZ_HU = "hz_hu";
|
||||||
|
public static final String ROOM_CONFIG_XIPAI = "xi_pai";
|
||||||
|
public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score";
|
||||||
|
public static final String ROOM_CONFIG_DI_FEN = "di_fen"; //低分
|
||||||
|
public static final String ROOM_CONFIG_LAIZI4_HU = "laizi4_hu"; //四鬼胡牌
|
||||||
|
|
||||||
|
public static final String SETTLE_DIAN_PAO = "dian_pao";
|
||||||
|
public static final String SETTLE_JIE_PAO = "jie_pao";
|
||||||
|
public static final String SETTLE_ZIMO = "zimo";
|
||||||
|
public static final String SETTLE_AN_KONG = "an_kong";
|
||||||
|
public static final String SETTLE_MING_KONG = "ming_kong";
|
||||||
|
|
||||||
|
public static final int NIAO_TYPE_159 =1;
|
||||||
|
public static final int NIAO_TYPE_ALL =2;
|
||||||
|
public static final int NIAO_TYPE_WOWO =3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_PLAYER_DEAL = "811";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_DIS_CARD = "611";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_DISCARD = "812";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_DISCARD_TIP = "813";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_FZTIPS = "814";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_ACTION = "612";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final String GAME_EVT_ACTION = "815";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_HU = "816";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_RESULT1 = "817";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大结算
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_RESULT2 = "818";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_DRAW = "819";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_CHANGE_ACTIVE_PLAYER = "820";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_NIAO = "821";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_PIAONIAO_TIP = "833";
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_PIAONIAO = "834";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
public class EXActionEvent {
|
||||||
|
|
||||||
|
public static final String EVENT_ACTION = "action";
|
||||||
|
|
||||||
|
public static final String EVENT_DISCARD = "discard";
|
||||||
|
|
||||||
|
public static final String EVENT_OTHER_DISCARD = "other_discard";
|
||||||
|
|
||||||
|
public static final String EVENT_START_GAME ="start_game";
|
||||||
|
|
||||||
|
public static final String EVENT_EXIT_ROOM = "exit_room";
|
||||||
|
|
||||||
|
public static final String EVENT_KONG_WIN = "kong_win";
|
||||||
|
|
||||||
|
public static final String EVENT_PIAO_NIAO = "piao_niao";
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,279 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.GameController;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.Util;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.player.state.PlayerWaitState;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.routes.ActionKey;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
import extend.mj.tip.Tip;
|
||||||
|
import extend.mj.tip.TipManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* EXGameController.java
|
||||||
|
*/
|
||||||
|
public class EXGameController extends GameController {
|
||||||
|
|
||||||
|
public EXGameController() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActionKey(Config.GAME_ACTION)
|
||||||
|
public void RouterAction(Session sender,ITObject params,int gid,Player owner) {
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
int id = params.getInt("id");
|
||||||
|
if(id ==0) {
|
||||||
|
Global.logger.info(owner + " pass!");
|
||||||
|
}else {
|
||||||
|
TipManager tipMgr =((EXPlayer)owner).tipMgr;
|
||||||
|
if(tipMgr.tipMap.containsKey(id)) {
|
||||||
|
Tip tip = tipMgr.tipMap.get(id);
|
||||||
|
Global.logger.info(owner + " select_action type:"+tip.weight+" card:"+tip.card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
owner.stateMachine.execute(EXActionEvent.EVENT_ACTION, 0, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActionKey(Config.GAME_DIS_CARD)
|
||||||
|
public void RouterDisCard(Session sender,ITObject params,int gid,Player owner) {
|
||||||
|
owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeActiveSeat(EXRoom owner,int activeSeat) {
|
||||||
|
owner.activeSeat = activeSeat;
|
||||||
|
TObject param = new TObject();
|
||||||
|
param.putInt("seat", activeSeat);
|
||||||
|
owner.broadCastToClient(0, Config.GAME_EVT_CHANGE_ACTIVE_PLAYER, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getCard(EXPlayer player,int leftCount){
|
||||||
|
ITObject otherParam = new TObject();
|
||||||
|
otherParam.putInt("card", 0);
|
||||||
|
otherParam.putInt("seat", player.room.activeSeat);
|
||||||
|
otherParam.putInt("left_count", leftCount);
|
||||||
|
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt( "card", player.drawCard );
|
||||||
|
param.putInt("seat", player.room.activeSeat);
|
||||||
|
param.putInt("left_count", leftCount);
|
||||||
|
player.sendEvent(Config.GAME_EVT_DRAW, param);
|
||||||
|
player.cardInhand.add(player.drawCard);
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(player + " drawcard["+player.drawCard+"]");
|
||||||
|
}
|
||||||
|
player.room.broadCastToClient(player.playerid, Config.GAME_EVT_DRAW, otherParam);
|
||||||
|
((EXPlayBack)player.getRoom().playBackData).addGetCardCommand(player.room.activeSeat, player.drawCard,leftCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void outCard(EXPlayer player,int discard){
|
||||||
|
ITObject response = new TObject();
|
||||||
|
response.putInt("seat", player.seat);
|
||||||
|
response.putInt("card", discard);
|
||||||
|
player.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response);
|
||||||
|
EXRoom room = player.getRoom();
|
||||||
|
((EXPlayBack)room.playBackData).addOutCardCommand(player.seat, discard);
|
||||||
|
|
||||||
|
room.activeCard = discard;
|
||||||
|
room.lastDiscardSeat = player.seat;
|
||||||
|
room.currenDiscardSeat = 0;
|
||||||
|
player.outcardList.add(discard);
|
||||||
|
Util.removeCard(player.cardInhand, discard, 1);
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(player + " outcard["+discard+"]");
|
||||||
|
}
|
||||||
|
room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void actionCard(EXPlayer player,int card,int type,int from_seat,ITArray opcardArray){
|
||||||
|
ITObject paramBroadCast = new TObject();
|
||||||
|
paramBroadCast.putInt("playerid", player.playerid);
|
||||||
|
paramBroadCast.putInt("card", card);
|
||||||
|
paramBroadCast.putInt("type", type);
|
||||||
|
paramBroadCast.putInt("from_seat", from_seat);
|
||||||
|
if(opcardArray!=null){
|
||||||
|
paramBroadCast.putTArray("opcard", opcardArray);
|
||||||
|
}
|
||||||
|
EXRoom room = player.getRoom();
|
||||||
|
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(String.format("%s from_seat:%d card:%d type:%d ", player,from_seat,card,type));
|
||||||
|
}
|
||||||
|
room.broadCastToClient(0, Config.GAME_EVT_ACTION, paramBroadCast);
|
||||||
|
((EXPlayBack)room.playBackData).addActionCommand(player.seat, type, card, from_seat,opcardArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dealCard(EXRoom owner) {
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer)entry.getValue();
|
||||||
|
//Global.logger.info("playerid:"+player.playerid+" isw: "+player.is_white);
|
||||||
|
|
||||||
|
player.cardInhand = owner.card.deal(player.is_white);
|
||||||
|
Collections.sort(player.cardInhand);
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(player + " cardlist:" + player.cardInhand);
|
||||||
|
}
|
||||||
|
ITObject param = new TObject();
|
||||||
|
ITArray handCard = Util.toTArray(player.cardInhand);
|
||||||
|
param.putTArray("card_list", handCard);
|
||||||
|
param.putInt("bank_seat", player.room.bankerSeat);
|
||||||
|
param.putInt("round", player.room.round);
|
||||||
|
player.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param);
|
||||||
|
player.stateMachine.changeState(Global.getState(PlayerWaitState.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
Global.logger.info("dealCard() ===> round = "+owner.round);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tipEvent(EXPlayer owner) {
|
||||||
|
ITObject param = owner.tipMgr.toMP();
|
||||||
|
owner.sendEvent(Config.GAME_EVT_FZTIPS, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void discardTipEvent(EXPlayer owner) {
|
||||||
|
owner.getRoom().currenDiscardSeat = owner.seat;
|
||||||
|
owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void winEvent(EXPlayer owner,int from_seat,int win_card) {
|
||||||
|
ITArray cardInHand = TArray.newInstance();
|
||||||
|
for (int card1 : owner.cardInhand) {
|
||||||
|
cardInHand.addInt(card1);
|
||||||
|
}
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putTArray("card", cardInHand);
|
||||||
|
param.putInt("seat", owner.seat);
|
||||||
|
param.putInt("win_card", win_card);
|
||||||
|
param.putInt("from_seat", from_seat);
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(owner + " hupai!["+(owner.seat == from_seat?"self":"other")+"]");
|
||||||
|
}
|
||||||
|
EXRoom room = owner.getRoom();
|
||||||
|
room.broadCastToClient(0, Config.GAME_EVT_HU, param);
|
||||||
|
((EXPlayBack)room.playBackData).addWinCardCommand(owner.seat, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendNiaoEvt(EXPlayer owner, int seat) {
|
||||||
|
EXRoom room = owner.getRoom();
|
||||||
|
ITObject param = new TObject();
|
||||||
|
// param.putInt("playerid", owner.playerid);
|
||||||
|
ITArray array = new TArray();
|
||||||
|
for (int index = 0; index < room.niao.size(); index++) {
|
||||||
|
array.addTObject(room.niao.get(index).toMP());
|
||||||
|
}
|
||||||
|
param.putTArray("niao", array);
|
||||||
|
param.putInt("start_seat", seat);
|
||||||
|
|
||||||
|
room.broadCastToClient(0, Config.GAME_EVT_NIAO, param);
|
||||||
|
((EXPlayBack)room.playBackData).addNiaoCommand(owner.seat, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ʊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void piaoNiaoTipEvent(EXPlayer owner) {
|
||||||
|
owner.sendEvent(Config.GAME_EVT_PIAONIAO_TIP, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ʊ<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void piaoNiaoEvent(EXPlayer owner) {
|
||||||
|
// if(owner.piaoNiao==0)return;
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("seat", owner.seat);
|
||||||
|
param.putInt("num", owner.piaoNiao);
|
||||||
|
owner.room.broadCastToClient(0, Config.GAME_EVT_PIAONIAO, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITObject getRoomResultData(EXRoom owner) {
|
||||||
|
ITObject mp = TObject.newInstance();
|
||||||
|
mp.putBoolean("liuju", owner.liuju);
|
||||||
|
mp.putInt("xipai_score", owner.xi_pai_score);
|
||||||
|
mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid);
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
long t = time / 1000;
|
||||||
|
mp.putLong("time", t);
|
||||||
|
ITArray niao = new TArray();
|
||||||
|
for (int index = 0; index < owner.niao.size(); index++) {
|
||||||
|
niao.addTObject(owner.niao.get(index).toMP());
|
||||||
|
}
|
||||||
|
mp.putTArray("niao", niao);
|
||||||
|
ITArray infoList = new TArray();
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("seat", player.seat);
|
||||||
|
param.putInt("win_card", player.winCard);
|
||||||
|
param.putBoolean("is_win", player.winer == 1);
|
||||||
|
param.putInt("hu_score", player.score.round_log.get(EXScore.WIN));
|
||||||
|
param.putInt("niao_score", player.score.round_log.get(EXScore.NIAO));
|
||||||
|
param.putInt("gang_score", player.score.round_log.get(EXScore.KONG));
|
||||||
|
param.putInt("piao_niao_score", player.score.round_log.get(EXScore.PIAO_NIAO));
|
||||||
|
player.hp_info(param);
|
||||||
|
param.putInt("round_score", player.score.round_score);
|
||||||
|
param.putInt("total_score", player.score.total_score);
|
||||||
|
ITArray handCard = Util.toTArray(player.cardInhand);
|
||||||
|
param.putTArray("hand_card", handCard);
|
||||||
|
infoList.addTObject(param);
|
||||||
|
}
|
||||||
|
mp.putTArray("info_list", infoList);
|
||||||
|
return mp;
|
||||||
|
}
|
||||||
|
public void roomResult(EXRoom owner) {
|
||||||
|
ITObject mp = TObject.newInstance();
|
||||||
|
mp.putInt("type", 0);
|
||||||
|
ITObject result = getRoomResultData(owner);
|
||||||
|
owner.playBackData.addResult(result);
|
||||||
|
mp.putTObject("result", result);
|
||||||
|
owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void roomTotalResult(EXRoom owner,boolean dissmiss) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
long t = System.currentTimeMillis() / 1000;
|
||||||
|
data.putLong("time", t);
|
||||||
|
ITArray infoList = new TArray();
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("seat", player.seat);
|
||||||
|
param.putTObject("settle_log", player.settleLog.toTObject());
|
||||||
|
param.putInt("total_score", player.score.total_score);
|
||||||
|
player.hp_info(param);
|
||||||
|
infoList.addTObject(param);
|
||||||
|
}
|
||||||
|
data.putTArray("info_list", infoList);
|
||||||
|
|
||||||
|
ITObject mp = TObject.newInstance();
|
||||||
|
mp.putInt("type", dissmiss?2:1);
|
||||||
|
if(!dissmiss) {
|
||||||
|
ITObject result = getRoomResultData(owner);
|
||||||
|
owner.playBackData.addResult(result);
|
||||||
|
mp.putTObject("result", result);
|
||||||
|
}
|
||||||
|
mp.putTObject("total_result", data);
|
||||||
|
|
||||||
|
owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.game.GameController;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.MainServer;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerWaitState;
|
||||||
|
import com.game.room.state.RoomStartGameState;
|
||||||
|
|
||||||
|
import extend.mj.player.rulestate.PROtherKongState;
|
||||||
|
import extend.mj.player.rulestate.PROtherWinState;
|
||||||
|
import extend.mj.player.rulestate.PRPongKongState;
|
||||||
|
import extend.mj.player.rulestate.PRPongState;
|
||||||
|
import extend.mj.player.rulestate.PRSelfKongState;
|
||||||
|
import extend.mj.player.rulestate.PRSelfWinState;
|
||||||
|
import extend.mj.player.state.EXPlayerDisCardTipState;
|
||||||
|
import extend.mj.player.state.EXPlayerDiscardState;
|
||||||
|
import extend.mj.player.state.EXPlayerDrawState;
|
||||||
|
import extend.mj.player.state.EXPlayerDrawTipState;
|
||||||
|
import extend.mj.player.state.EXPlayerKongWinState;
|
||||||
|
import extend.mj.player.state.EXPlayerPiaoNiaoTipState;
|
||||||
|
import extend.mj.player.state.EXPlayerWaitKongWinState;
|
||||||
|
import extend.mj.player.state.EXPlayerWaitState;
|
||||||
|
import extend.mj.room.state.EXRoomDealState;
|
||||||
|
import extend.mj.room.state.EXRoomSetpState;
|
||||||
|
import extend.mj.room.state.EXRoomStartGameState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* EXMainServer.java
|
||||||
|
*/
|
||||||
|
public class EXMainServer extends MainServer{
|
||||||
|
|
||||||
|
|
||||||
|
public static PlayerRuleManager playerRuleMgr;
|
||||||
|
|
||||||
|
public static EXGameController gameCtr;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
gameCtr = (EXGameController)Global.gameCtr;
|
||||||
|
|
||||||
|
registerState();
|
||||||
|
|
||||||
|
playerRuleMgr = new PlayerRuleManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final void registerState() {
|
||||||
|
Global.registerState(RoomStartGameState.class, new EXRoomStartGameState());
|
||||||
|
Global.registerState(EXRoomSetpState.class, new EXRoomSetpState());
|
||||||
|
Global.registerState(EXRoomDealState.class, new EXRoomDealState());
|
||||||
|
|
||||||
|
Global.registerState(PlayerWaitState.class, new EXPlayerWaitState());
|
||||||
|
Global.registerState(EXPlayerDrawState.class, new EXPlayerDrawState());
|
||||||
|
Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState());
|
||||||
|
Global.registerState(EXPlayerDisCardTipState.class, new EXPlayerDisCardTipState());
|
||||||
|
Global.registerState(EXPlayerDrawTipState.class, new EXPlayerDrawTipState());
|
||||||
|
Global.registerState(EXPlayerWaitKongWinState.class, new EXPlayerWaitKongWinState());
|
||||||
|
Global.registerState(EXPlayerKongWinState.class, new EXPlayerKongWinState());
|
||||||
|
Global.registerState(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState());
|
||||||
|
|
||||||
|
Global.registerState(PROtherKongState.class, new PROtherKongState());
|
||||||
|
Global.registerState(PROtherWinState.class, new PROtherWinState());
|
||||||
|
Global.registerState(PRPongKongState.class, new PRPongKongState());
|
||||||
|
Global.registerState(PRPongState.class, new PRPongState());
|
||||||
|
Global.registerState(PRSelfKongState.class, new PRSelfKongState());
|
||||||
|
Global.registerState(PRSelfWinState.class, new PRSelfWinState());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Room newRoom(String roomid, Map<String, String> redis_room_map) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return new EXRoom(roomid, redis_room_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player newPlayer(int playerid, Room room, String session_id) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return new EXPlayer(playerid, room, session_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GameController newController() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return new EXGameController();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import com.game.Util;
|
||||||
|
import com.game.data.BasePlayBack;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
public class EXPlayBack extends BasePlayBack{
|
||||||
|
|
||||||
|
|
||||||
|
public EXPlayBack(EXRoom room){
|
||||||
|
super(room);
|
||||||
|
info.putInt("left_card", room.card.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ITObject getPlayerInfo(Player player) {
|
||||||
|
ITObject obj =super.getPlayerInfo(player);
|
||||||
|
EXPlayer p = (EXPlayer)player;
|
||||||
|
ITArray cardInhand = Util.toTArray(p.cardInhand);
|
||||||
|
obj.putTArray("hand_card", cardInhand);
|
||||||
|
obj.putInt("score", player.score.total_score);
|
||||||
|
obj.putInt("piao_niao", p.piaoNiao);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addGetCardCommand(int seat,int card,int left_count){
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("card", card);
|
||||||
|
data.putInt("left_count", left_count);
|
||||||
|
addCommand("GetCard",seat,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addOutCardCommand(int seat,int card){
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("card", card);
|
||||||
|
addCommand("OutCard",seat,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOutCardKongCommand(int seat,ITArray card){
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putTArray("cardList", card);
|
||||||
|
addCommand("OutCardKong",seat,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addActionCommand(int seat,int type,int card,int from_seat,ITArray opcardArray){
|
||||||
|
ITObject cmdData = TObject.newInstance();
|
||||||
|
cmdData.putInt("card", card);
|
||||||
|
cmdData.putInt("type", type);
|
||||||
|
cmdData.putInt("from_seat", from_seat);
|
||||||
|
if(opcardArray!=null)
|
||||||
|
cmdData.putTArray("opcard", opcardArray);
|
||||||
|
addCommand("Action",seat,cmdData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addWinCardCommand(int seat,boolean zimo){
|
||||||
|
ITObject cmdData = TObject.newInstance();
|
||||||
|
addCommand("Win",seat,cmdData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNiaoCommand(int seat,ITObject param){
|
||||||
|
addCommand("Niao",seat,param);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.game.Util;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.data.Score;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
import extend.mj.tip.TipManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* 2017<EFBFBD><EFBFBD>8<EFBFBD><EFBFBD>30<EFBFBD><EFBFBD>
|
||||||
|
* EXPlayer.java
|
||||||
|
*/
|
||||||
|
public class EXPlayer extends Player {
|
||||||
|
// <20><><EFBFBD><EFBFBD>
|
||||||
|
public List<Integer> cardInhand;
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
public List<Integer> outcardList;
|
||||||
|
|
||||||
|
public ITArray opCard;
|
||||||
|
|
||||||
|
public List<int[]> pongGroup;
|
||||||
|
public List<int[]> kongGroup;
|
||||||
|
public List<int[]> selfKongGroup;
|
||||||
|
public List<OpCard> opCardList;
|
||||||
|
|
||||||
|
public int drawCard = 0;
|
||||||
|
public int winCard = 0;
|
||||||
|
|
||||||
|
public TipManager tipMgr;
|
||||||
|
|
||||||
|
public SettleLog settleLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ©<EFBFBD><EFBFBD>
|
||||||
|
*/
|
||||||
|
public boolean louhu = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ǿ<EFBFBD>Ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
*/
|
||||||
|
public boolean forceCheckWin = false;
|
||||||
|
/**
|
||||||
|
* 0 С<EFBFBD><EFBFBD> 1 <EFBFBD><EFBFBD><EFBFBD>ܺ<EFBFBD>
|
||||||
|
*/
|
||||||
|
public int winType = 0;
|
||||||
|
public List<Integer> notPongKongList = new ArrayList<>();
|
||||||
|
|
||||||
|
public int niaoCount;
|
||||||
|
public int piaoNiao;
|
||||||
|
public boolean fengding;
|
||||||
|
|
||||||
|
public EXPlayer(int playerid, Room table, String session_id) {
|
||||||
|
super(playerid, table, session_id);
|
||||||
|
|
||||||
|
cardInhand = new ArrayList<>();
|
||||||
|
outcardList = new ArrayList<>();
|
||||||
|
|
||||||
|
pongGroup = new ArrayList<>();
|
||||||
|
kongGroup = new ArrayList<>();
|
||||||
|
selfKongGroup = new ArrayList<>();
|
||||||
|
opCardList = new ArrayList<>();
|
||||||
|
|
||||||
|
opCard = new TArray();
|
||||||
|
|
||||||
|
tipMgr = new TipManager(this);
|
||||||
|
|
||||||
|
settleLog = new SettleLog();
|
||||||
|
settleLog.put(Config.SETTLE_DIAN_PAO, 0);
|
||||||
|
settleLog.put(Config.SETTLE_JIE_PAO, 0);
|
||||||
|
settleLog.put(Config.SETTLE_ZIMO, 0);
|
||||||
|
settleLog.put(Config.SETTLE_AN_KONG, 0);
|
||||||
|
settleLog.put(Config.SETTLE_MING_KONG, 0);
|
||||||
|
fengding = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Score newScore() {
|
||||||
|
return new EXScore(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initOpCard(ITArray opcard) {
|
||||||
|
this.opCard.clear();
|
||||||
|
for (int i = 0; i < opcard.size(); ++i) {
|
||||||
|
this.opCard.addInt(opcard.getInt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITObject getReloadInfo() {
|
||||||
|
ITObject playerData = super.getReloadInfo();
|
||||||
|
ITArray disCard = Util.toTArray(this.outcardList);
|
||||||
|
playerData.putTArray("outcard_list", disCard);
|
||||||
|
playerData.putInt("card_count", cardInhand.size());
|
||||||
|
playerData.putInt("score", score.total_score);
|
||||||
|
playerData.putInt("piao_niao", this.piaoNiao);
|
||||||
|
ITArray opcards = TArray.newInstance();
|
||||||
|
for (OpCard opcard : opCardList) {
|
||||||
|
ITObject opcardParam = new TObject();
|
||||||
|
opcardParam.putInt("type", opcard.type);
|
||||||
|
opcardParam.putInt("card", opcard.card);
|
||||||
|
opcards.addTObject(opcardParam);
|
||||||
|
}
|
||||||
|
playerData.putTArray("opcard", opcards);
|
||||||
|
|
||||||
|
return playerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
super.clear();
|
||||||
|
this.cardInhand.clear();
|
||||||
|
this.notPongKongList.clear();
|
||||||
|
this.winer = 0;
|
||||||
|
this.louhu = false;
|
||||||
|
this.outcardList.clear();
|
||||||
|
this.drawCard = 0;
|
||||||
|
this.kongGroup.clear();
|
||||||
|
this.pongGroup.clear();
|
||||||
|
this.selfKongGroup.clear();
|
||||||
|
this.opCardList.clear();
|
||||||
|
this.score.resetRound();
|
||||||
|
this.niaoCount = 0;
|
||||||
|
this.piaoNiao = 0;
|
||||||
|
this.fengding = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public EXRoom getRoom() {
|
||||||
|
return (EXRoom) room;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue