listByGameType(
21 | @Param("_gameType0") int gameType0,
22 | @Param("_gameType1") int gameType1
23 | );
24 | }
25 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/dao/ICostRoomCardConfDao.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
30 |
31 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/IHuPatternTest.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongChiPengGang;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
5 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
6 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * 胡牌模式测试
12 | */
13 | public interface IHuPatternTest {
14 | /**
15 | * 测试胡牌牌型,
16 | * 胡牌牌型和胡牌公式不一样,
17 | * 胡牌公式是计算当前麻将牌的排列组合方式是否可以胡牌?
18 | * 可以根据固定算法计算得到...
19 | *
20 | * 而胡牌牌型是不固定的, 会根据地方玩法不同而变化.
21 | * 另外, 在测试胡牌牌型的时候会检查吃、碰、杠分组, 甚至是胡的哪一张牌?
22 | *
23 | * XXX 注意: 要进行胡牌模式测试,
24 | * 必须满足 null != currPlayer.getCurrState().getHuPai() 这个条件!
25 | * 也就是说必须得记录胡牌...
26 | * 而这个胡牌是在 MJ_weihai_BizLogic#hu 函数中设置的.
27 | *
28 | * @param currRound 当前牌局
29 | * @param currPlayer 当前玩家
30 | * @return true = 模式成立, false = 不是该模式
31 | */
32 | default boolean test(Round currRound, Player currPlayer) {
33 | if (null == currPlayer) {
34 | return false;
35 | }
36 |
37 | if (null == currPlayer.getCurrState().getMahjongZiMo() &&
38 | null == currPlayer.getCurrState().getMahjongHu()) {
39 | return false;
40 | }
41 |
42 | // 获取自摸麻将牌
43 | MahjongTileDef mahjongAtLast = currPlayer.getCurrState().getMahjongZiMo();
44 |
45 | if (null == mahjongAtLast) {
46 | // 获取胡牌麻将牌
47 | mahjongAtLast = currPlayer.getCurrState().getMahjongHu();
48 | }
49 |
50 | return test(
51 | currPlayer.getMahjongChiPengGangListCopy(),
52 | currPlayer.getMahjongInHandCopy(),
53 | mahjongAtLast
54 | );
55 | }
56 |
57 | /**
58 | * 测试胡牌牌型
59 | *
60 | * @param mahjongChiPengGangList 麻将吃碰杠胡列表
61 | * @param mahjongInHand 麻将手牌列表
62 | * @param mahjongAtLast 最后一张麻将牌
63 | * @return true = 模式成立, false = 不是该模式
64 | */
65 | default boolean test(
66 | List mahjongChiPengGangList, List mahjongInHand, MahjongTileDef mahjongAtLast) {
67 | return false;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_DiHu.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongChiPengGang;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
5 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 地胡
11 | */
12 | public class Pattern_DiHu implements IHuPatternTest {
13 | @Override
14 | public boolean test(Round currRound, Player currPlayer) {
15 | if (null == currRound ||
16 | null == currPlayer ||
17 | null == currPlayer.getCurrState().getMahjongZiMo() || // XXX 注意: 地胡必须是自摸
18 | currPlayer.getCurrState().isZhuangJia()) {
19 | // 庄家不可能是地胡
20 | return false;
21 | }
22 |
23 | if (currRound.getTakeCardNum() == 1) {
24 | // 如果只发出一张牌,
25 | // 算地胡
26 | return true;
27 | }
28 |
29 | if (currRound.getTakeCardNum() == 2) {
30 | // 如果已经取出两张麻将牌,
31 | // 那么就得看看玩家是否有明杠?
32 | // 也就是说庄家抓到第一张牌之后打出,
33 | // 闲家杠牌 ( 只可能是明杠 ), 之后抓到的牌胡牌了
34 | //
35 | // 获取麻将吃碰杠列表
36 | final List mahjongChiPengGangList = currPlayer.getMahjongChiPengGangListCopy();
37 |
38 | return mahjongChiPengGangList.size() == 1 &&
39 | mahjongChiPengGangList.get(0).getKind() == MahjongChiPengGang.KindDef.MING_GANG;
40 | }
41 |
42 | return false;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_GangHouPao.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
5 |
6 | /**
7 | * 杠后炮
8 | */
9 | public class Pattern_GangHouPao implements IHuPatternTest {
10 | @Override
11 | public boolean test(Round currRound, Player currPlayer) {
12 | if (null == currRound ||
13 | null == currPlayer ||
14 | null == currPlayer.getCurrState().getMahjongHu()) {
15 | // 如果当前玩家不是胡牌玩家,
16 | return false;
17 | }
18 |
19 | for (Player dianPaoPlayer : currRound.getPlayerListCopy()) {
20 | if (null != dianPaoPlayer &&
21 | dianPaoPlayer.getCurrState().isDianPao() &&
22 | dianPaoPlayer.getCurrState().getJustGangNum() > 0) {
23 | // 找到这个点炮的玩家,
24 | // 看看这个玩家刚好有杠的数量是否满足条件?
25 | return true;
26 | }
27 | }
28 |
29 | return false;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_GangShangKaiHua.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
5 |
6 | /**
7 | * 杠上开花
8 | */
9 | public class Pattern_GangShangKaiHua implements IHuPatternTest {
10 | @Override
11 | public boolean test(Round currRound, Player currPlayer) {
12 | return null != currPlayer
13 | && null != currPlayer.getCurrState().getMahjongZiMo()
14 | && currPlayer.getCurrState().getJustGangNum() > 0;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_HaiDiLaoYue.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
5 |
6 | /**
7 | * 海底捞月
8 | */
9 | public class Pattern_HaiDiLaoYue implements IHuPatternTest {
10 | @Override
11 | public boolean test(Round currRound, Player currPlayer) {
12 | if (null == currRound ||
13 | null == currPlayer) {
14 | return false;
15 | }
16 |
17 | return null != currPlayer.getCurrState().getMahjongZiMo()
18 | && currRound.getRemainCardNum() <= 0;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_HaoHuaQiXiaoDui.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongChiPengGang;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * 豪华七小对
10 | */
11 | public class Pattern_HaoHuaQiXiaoDui implements IHuPatternTest {
12 | /**
13 | * 七小对牌型
14 | */
15 | static private final Pattern_QiXiaoDui PATTERN_QI_XIAO_DUI = new Pattern_QiXiaoDui();
16 |
17 | @Override
18 | public boolean test(
19 | List mahjongChiPengGangList, List mahjongInHand, MahjongTileDef mahjongAtLast) {
20 |
21 | if (!PATTERN_QI_XIAO_DUI.test(mahjongChiPengGangList, mahjongInHand, mahjongAtLast)) {
22 | // 如果不是七小对牌型,
23 | return false;
24 | }
25 |
26 | for (int i = 0; i < mahjongInHand.size() - 4; i += 2) {
27 | // 获取前三张麻将牌
28 | final MahjongTileDef t0 = mahjongInHand.get(i);
29 | final MahjongTileDef t1 = mahjongInHand.get(i + 1);
30 | final MahjongTileDef t2 = mahjongInHand.get(i + 2);
31 |
32 | if (null != t0 &&
33 | t0 == t1 &&
34 | t0 == t2) {
35 | // 如果前三张牌都一样
36 | if (t0 == mahjongAtLast) {
37 | // 如果最后一张牌也一样,
38 | // 这说明能凑成 4 张相同的牌
39 | return true;
40 | }
41 |
42 | // 获取第四张牌
43 | final MahjongTileDef t3 = mahjongInHand.get(i + 3);
44 |
45 | if (t0 == t3) {
46 | // 如果第四张牌也一样
47 | return true;
48 | }
49 | }
50 | }
51 |
52 | return false;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_JiaWu.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
5 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
6 |
7 | /**
8 | * 夹五
9 | */
10 | public class Pattern_JiaWu implements IHuPatternTest {
11 | /**
12 | * 夹胡
13 | */
14 | static private final Pattern_JiaHu PATTERN_JIA_HU = new Pattern_JiaHu();
15 |
16 | @Override
17 | public boolean test(Round currRound, Player currPlayer) {
18 | if (null == currRound ||
19 | null == currPlayer ||
20 | null == currPlayer.getCurrState().getMahjongHu()) {
21 | return false;
22 | }
23 |
24 | if (!currRound.getRuleSetting().isJiaWu()) {
25 | // 如果规则中没有勾选夹五,
26 | // 那么不计算夹五...
27 | return false;
28 | }
29 |
30 | if (currPlayer.getCurrState().getMahjongHu() != MahjongTileDef._5_WAN &&
31 | currPlayer.getCurrState().getMahjongHu() != MahjongTileDef._5_TIAO &&
32 | currPlayer.getCurrState().getMahjongHu() != MahjongTileDef._5_BING) {
33 | return false;
34 | }
35 |
36 | return PATTERN_JIA_HU.test(currRound, currPlayer);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_MenQing.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongChiPengGang;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
5 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 门清
11 | */
12 | public class Pattern_MenQing implements IHuPatternTest {
13 | @Override
14 | public boolean test(Round currRound, Player currPlayer) {
15 | if (null == currRound ||
16 | null == currPlayer ||
17 | null == currPlayer.getCurrState().getMahjongZiMo()) {
18 | return false;
19 | }
20 |
21 | // 获取麻将吃碰杠列表
22 | List mahjongChiPengGangList = currPlayer.getMahjongChiPengGangListCopy();
23 |
24 | if (null != mahjongChiPengGangList &&
25 | !mahjongChiPengGangList.isEmpty()) {
26 | for (MahjongChiPengGang mahjongChiPengGang : mahjongChiPengGangList) {
27 | if (null == mahjongChiPengGang ||
28 | mahjongChiPengGang.getKind() != MahjongChiPengGang.KindDef.AN_GANG) {
29 | // 只有暗杠不破门清,
30 | // 有吃、碰、明杠、补杠都不算门清
31 | return false;
32 | }
33 | }
34 | }
35 |
36 | return true;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_PengPengHu.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongChiPengGang;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
5 |
6 | import java.util.HashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | /**
11 | * 碰碰胡
12 | */
13 | public class Pattern_PengPengHu implements IHuPatternTest {
14 | @Override
15 | public boolean test(
16 | List mahjongChiPengGangList, List mahjongInHand, MahjongTileDef mahjongAtLast) {
17 |
18 | if (null == mahjongInHand ||
19 | mahjongInHand.isEmpty() ||
20 | null == mahjongAtLast) {
21 | return false;
22 | }
23 |
24 | int counter = 0;
25 |
26 | for (MahjongChiPengGang mahjongChiPengGang : mahjongChiPengGangList) {
27 | if (null == mahjongChiPengGang ||
28 | mahjongChiPengGang.getKind() == MahjongChiPengGang.KindDef.CHI) {
29 | // 如果有吃牌那不可能是碰碰胡,
30 | // 因为碰碰胡要求有 4 副刻子...
31 | return false;
32 | }
33 |
34 | ++counter;
35 | }
36 |
37 | Map tempMap = new HashMap<>();
38 |
39 | for (MahjongTileDef tCurr : mahjongInHand) {
40 | if (null == tCurr) {
41 | continue;
42 | }
43 |
44 | int num = tempMap.getOrDefault(tCurr, 0);
45 | tempMap.put(tCurr, ++num);
46 | }
47 |
48 | for (Integer num : tempMap.values()) {
49 | if (3 == num) {
50 | ++counter;
51 | }
52 | }
53 |
54 | return 4 == counter;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_PingHu.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
5 |
6 | /**
7 | * 平胡
8 | */
9 | public class Pattern_PingHu implements IHuPatternTest {
10 | @Override
11 | public boolean test(Round currRound, Player currPlayer) {
12 | return null != currPlayer && (
13 | currPlayer.getCurrState().isZiMo() || currPlayer.getCurrState().isHu()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_QiXiaoDui.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongChiPengGang;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * 七小对
10 | */
11 | public class Pattern_QiXiaoDui implements IHuPatternTest {
12 | @Override
13 | public boolean test(
14 | List mahjongChiPengGangList, List mahjongInHand, MahjongTileDef mahjongAtLast) {
15 |
16 | if (null != mahjongChiPengGangList &&
17 | !mahjongChiPengGangList.isEmpty()) {
18 | // 不能有吃、碰、杠
19 | return false;
20 | }
21 |
22 | if (13 != mahjongInHand.size() ||
23 | null == mahjongAtLast) {
24 | // 必须是 14 张牌
25 | return false;
26 | }
27 |
28 | // 特殊索引
29 | int specialIndex = mahjongInHand.indexOf(mahjongAtLast);
30 |
31 | if (specialIndex < 0) {
32 | // 手牌里找不到最后的这张麻将牌,
33 | // 凑不成一对
34 | return false;
35 | }
36 |
37 | for (int i = 0; i < mahjongInHand.size(); i += 2) {
38 | if (i == specialIndex) {
39 | // XXX 注意: 如果是特殊位置则跳过,
40 | // 例如这样的牌型 AA B CC DD EE FF GG [B],
41 | // 最后一张牌是 B,
42 | // 那么第一个 B 出现的位置 ( specialIndex = 2 ) 会被跳过!
43 | ++i;
44 | }
45 |
46 | if ((i + 1) >= mahjongInHand.size()) {
47 | // 事先判断一下是否会越界
48 | return false;
49 | }
50 |
51 | final MahjongTileDef t0 = mahjongInHand.get(i);
52 | final MahjongTileDef t1 = mahjongInHand.get(i + 1);
53 |
54 | if (null == t0 ||
55 | t0 != t1) {
56 | return false;
57 | }
58 | }
59 |
60 | return true;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_QingYiSe.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongChiPengGang;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * 清一色
10 | */
11 | public class Pattern_QingYiSe implements IHuPatternTest {
12 | @Override
13 | public boolean test(
14 | List mahjongChiPengGangList, List mahjongInHand, MahjongTileDef mahjongAtLast) {
15 |
16 | if (null == mahjongInHand ||
17 | mahjongInHand.size() <= 0 ||
18 | null == mahjongAtLast) {
19 | return false;
20 | }
21 |
22 | // 获取花色
23 | final MahjongTileDef.Suit suit = mahjongAtLast.getSuit();
24 |
25 | for (MahjongTileDef tCurr : mahjongInHand) {
26 | if (null == tCurr ||
27 | tCurr.getSuit() != suit) {
28 | return false;
29 | }
30 | }
31 |
32 | if (null != mahjongChiPengGangList &&
33 | mahjongChiPengGangList.size() > 0) {
34 | // 所有的吃、碰、明杠、暗杠都得是同一花色
35 | for (MahjongChiPengGang mahjongChiPengGang : mahjongChiPengGangList) {
36 | if (null == mahjongChiPengGang) {
37 | continue;
38 | }
39 |
40 | // 获取麻将牌
41 | MahjongTileDef t = mahjongChiPengGang.getTX();
42 |
43 | if (null != t &&
44 | t.getSuit() != suit) {
45 | return false;
46 | }
47 | }
48 | }
49 |
50 | return true;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_ShouBaYi.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongChiPengGang;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * 手把一
10 | */
11 | public class Pattern_ShouBaYi implements IHuPatternTest {
12 | @Override
13 | public boolean test(
14 | List mahjongChiPengGangList, List mahjongInHand, MahjongTileDef mahjongAtLast) {
15 | if (null == mahjongChiPengGangList ||
16 | mahjongChiPengGangList.size() < 3) {
17 | // 因为威海有亮风玩法,
18 | // 亮风之后吃碰杠的数量最大就只能是 3 了,
19 | // 那么手把一的条件也就变成了:
20 | // 1、至少吃碰杠数量 >= 3 ( 注意不是 4 );
21 | // 2、手里只能剩下一张麻将牌;
22 | return false;
23 | }
24 |
25 | return null != mahjongInHand
26 | && mahjongInHand.size() == 1;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_TianHu.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
5 |
6 | /**
7 | * 天胡
8 | */
9 | public class Pattern_TianHu implements IHuPatternTest {
10 | @Override
11 | public boolean test(Round currRound, Player currPlayer) {
12 | if (null == currRound ||
13 | null == currPlayer ||
14 | null == currPlayer.getCurrState().getMahjongZiMo()) {
15 | return false;
16 | }
17 |
18 | // 庄家起手胡牌
19 | return currRound.getTakeCardNum() == 1
20 | && currPlayer.getCurrState().isZhuangJia();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_ZhuangJia.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
5 |
6 | /**
7 | * 庄家
8 | */
9 | public class Pattern_ZhuangJia implements IHuPatternTest {
10 | @Override
11 | public boolean test(Round currRound, Player currPlayer) {
12 | return null != currPlayer
13 | && null != currPlayer.getCurrState().getMahjongHu()
14 | && currPlayer.getCurrState().isZhuangJia();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_ZiMo.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Player;
4 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.Round;
5 |
6 | /**
7 | * 自摸
8 | */
9 | public class Pattern_ZiMo implements IHuPatternTest {
10 | @Override
11 | public boolean test(Round currRound, Player currPlayer) {
12 | return null != currRound
13 | && null != currPlayer
14 | && null != currPlayer.getCurrState().getMahjongZiMo();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/report/AReporter.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.report;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * 记者
8 | */
9 | public class AReporter {
10 | /**
11 | * 报告词条列表
12 | */
13 | private final List _wordzList = new ArrayList<>();
14 |
15 | /**
16 | * 添加词条
17 | *
18 | * @param w 词条
19 | * @return 当前词条
20 | */
21 | public IWordz addWordz(IWordz w) {
22 | if (null != w) {
23 | _wordzList.add(w);
24 | }
25 |
26 | return w;
27 | }
28 |
29 | /**
30 | * 获取词条列表
31 | *
32 | * @return 词条列表
33 | */
34 | public List getWordzList() {
35 | return _wordzList;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/report/IWordz.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.report;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import com.google.protobuf.GeneratedMessageV3;
5 |
6 | /**
7 | * 词条,
8 | * 主要用于记录游戏中的事件, 之后用于消息发送和广播
9 | */
10 | public interface IWordz {
11 | /**
12 | * 获取用户 Id
13 | *
14 | * @return 用户 Id
15 | */
16 | default int getUserId() {
17 | return -1;
18 | }
19 |
20 | /**
21 | * 构建结果消息
22 | *
23 | * @return 结果消息
24 | */
25 | GeneratedMessageV3 buildResultMsg();
26 |
27 | /**
28 | * 构建广播消息
29 | *
30 | * @return 广播消息
31 | */
32 | GeneratedMessageV3 buildBroadcastMsg();
33 |
34 | /**
35 | * 构建 JSON 对象
36 | *
37 | * @return JSON 对象
38 | */
39 | default JSONObject buildJSONObj() {
40 | return null;
41 | }
42 |
43 | /**
44 | * 创建遮挡拷贝
45 | *
46 | * @return 词条
47 | */
48 | default IWordz createMaskCopy() {
49 | return this;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/report/ReporterTeam.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.report;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * 记者小队,
7 | * 主要用于消息群发和战报记录
8 | */
9 | public class ReporterTeam {
10 | /**
11 | * 所属房间 Id
12 | */
13 | private final int _roomId;
14 |
15 | /**
16 | * 私人事件记者
17 | */
18 | private final AReporter _rptr0 = new AReporter();
19 |
20 | /**
21 | * 公共事件记者
22 | */
23 | private final AReporter _rptr1 = new AReporter();
24 |
25 | /**
26 | * 回放事件记者
27 | */
28 | private final AReporter _rptr2 = new AReporter();
29 |
30 | /**
31 | * 类参数构造器
32 | *
33 | * @param roomId 所属房间 Id
34 | */
35 | public ReporterTeam(int roomId) {
36 | _roomId = roomId;
37 | }
38 |
39 | /**
40 | * 获取所属房间 Id
41 | *
42 | * @return 房间 Id
43 | */
44 | public int getRoomId() {
45 | return _roomId;
46 | }
47 |
48 | /**
49 | * 添加私人词条
50 | *
51 | * @param w 词条
52 | * @return 当前添加的词条
53 | */
54 | public IWordz addPrivateWordz(
55 | IWordz w) {
56 | return _rptr0.addWordz(w);
57 | }
58 |
59 | /**
60 | * 获取私人词条列表
61 | *
62 | * @return 词条列表
63 | */
64 | public List getPrivateWordzList() {
65 | return _rptr0.getWordzList();
66 | }
67 |
68 | /**
69 | * 添加公共词条
70 | *
71 | * @param w 词条
72 | * @return 当前添加的词条
73 | */
74 | public IWordz addPublicWordz(
75 | IWordz w) {
76 | return _rptr1.addWordz(w);
77 | }
78 |
79 | /**
80 | * 获取公共词条列表
81 | *
82 | * @return 词条列表
83 | */
84 | public List getPublicWordzList() {
85 | return _rptr1.getWordzList();
86 | }
87 |
88 | /**
89 | * 添加回放词条
90 | *
91 | * @param w 当前添加的词条
92 | * @return 当前添加的词条
93 | */
94 | public IWordz addPlaybackWordz(
95 | IWordz w) {
96 | return _rptr2.addWordz(w);
97 | }
98 |
99 | /**
100 | * 获取回放词条列表
101 | *
102 | * @return 词条列表
103 | */
104 | public List getPlaybackWordzList() {
105 | return _rptr2.getWordzList();
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/report/Wordz_DingPiao.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.report;
2 |
3 | import com.google.protobuf.GeneratedMessageV3;
4 | import org.mj.bizserver.allmsg.MJ_weihai_Protocol;
5 |
6 | /**
7 | * 定飘词条
8 | */
9 | public class Wordz_DingPiao implements IWordz {
10 | /**
11 | * 用户 Id
12 | */
13 | private final int _userId;
14 |
15 | /**
16 | * 飘数值
17 | */
18 | private final int _piaoX;
19 |
20 | /**
21 | * 类参数构造器
22 | *
23 | * @param userId 用户 Id
24 | * @param piaoX 飘几
25 | */
26 | public Wordz_DingPiao(int userId, int piaoX) {
27 | _userId = userId;
28 | _piaoX = piaoX;
29 | }
30 |
31 | @Override
32 | public int getUserId() {
33 | return _userId;
34 | }
35 |
36 | /**
37 | * 获取飘几
38 | *
39 | * @return 0 = 不飘, 1 = 飘_1, 2 = 飘_2, 3 = 飘_3, 4 = 飘_4
40 | */
41 | public int getPiaoX() {
42 | return _piaoX;
43 | }
44 |
45 | @Override
46 | public GeneratedMessageV3 buildResultMsg() {
47 | return MJ_weihai_Protocol.DingPiaoResult.newBuilder()
48 | .setPiaoX(_piaoX)
49 | .setOk(true)
50 | .build();
51 | }
52 |
53 | @Override
54 | public GeneratedMessageV3 buildBroadcastMsg() {
55 | return MJ_weihai_Protocol.DingPiaoBroadcast.newBuilder()
56 | .setUserId(_userId)
57 | .setPiaoX(_piaoX)
58 | .setOk(true)
59 | .build();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/report/Wordz_MahjongChuPai.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.report;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import com.google.protobuf.GeneratedMessageV3;
5 | import org.mj.bizserver.allmsg.MJ_weihai_Protocol;
6 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
7 |
8 | /**
9 | * 麻将出牌
10 | */
11 | public class Wordz_MahjongChuPai implements IWordz {
12 | /**
13 | * 用户 Id
14 | */
15 | private final int _userId;
16 |
17 | /**
18 | * 麻将出牌
19 | */
20 | private final MahjongTileDef _t;
21 |
22 | /**
23 | * 类参数构造器
24 | *
25 | * @param userId 用户 Id
26 | * @param t 麻将出牌
27 | */
28 | public Wordz_MahjongChuPai(int userId, MahjongTileDef t) {
29 | _userId = userId;
30 | _t = t;
31 | }
32 |
33 | @Override
34 | public int getUserId() {
35 | return _userId;
36 | }
37 |
38 | /**
39 | * 获取麻将出牌
40 | *
41 | * @return 麻将出牌
42 | */
43 | public MahjongTileDef getT() {
44 | return _t;
45 | }
46 |
47 | /**
48 | * 获取麻将出牌整数值
49 | *
50 | * @return 整数值
51 | */
52 | public int getTIntVal() {
53 | return (null == _t) ? -1 : _t.getIntVal();
54 | }
55 |
56 | @Override
57 | public GeneratedMessageV3 buildResultMsg() {
58 | return MJ_weihai_Protocol.MahjongChuPaiResult.newBuilder()
59 | .setT(getTIntVal())
60 | .build();
61 | }
62 |
63 | @Override
64 | public GeneratedMessageV3 buildBroadcastMsg() {
65 | return MJ_weihai_Protocol.MahjongChuPaiBroadcast.newBuilder()
66 | .setUserId(_userId)
67 | .setT(getTIntVal())
68 | .build();
69 | }
70 |
71 | @Override
72 | public JSONObject buildJSONObj() {
73 | final JSONObject jsonObj = new JSONObject(true);
74 | jsonObj.put("clazzName", this.getClass().getSimpleName());
75 | jsonObj.put("userId", _userId);
76 | jsonObj.put("t", getTIntVal());
77 |
78 | return jsonObj;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/report/Wordz_MahjongHuangZhuang.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.report;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import com.google.protobuf.GeneratedMessageV3;
5 | import org.mj.bizserver.allmsg.MJ_weihai_Protocol;
6 |
7 | /**
8 | * 麻将荒庄
9 | */
10 | public class Wordz_MahjongHuangZhuang implements IWordz {
11 | @Override
12 | public GeneratedMessageV3 buildResultMsg() {
13 | return null;
14 | }
15 |
16 | @Override
17 | public GeneratedMessageV3 buildBroadcastMsg() {
18 | return MJ_weihai_Protocol.MahjongHuangZhuangBroadcast.newBuilder().build();
19 | }
20 |
21 | @Override
22 | public JSONObject buildJSONObj() {
23 | final JSONObject jsonObj = new JSONObject();
24 | jsonObj.put("clazzName", this.getClass().getSimpleName());
25 | return jsonObj;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/report/Wordz_MahjongLiangGangDing.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.report;
2 |
3 | import com.google.protobuf.GeneratedMessageV3;
4 | import org.mj.bizserver.allmsg.MJ_weihai_Protocol;
5 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
6 |
7 | /**
8 | * 麻将亮杠腚词条
9 | */
10 | public class Wordz_MahjongLiangGangDing implements IWordz {
11 | /**
12 | * 第一张牌
13 | */
14 | private final MahjongTileDef _t0;
15 |
16 | /**
17 | * 第二张牌
18 | */
19 | private MahjongTileDef _t1;
20 |
21 | /**
22 | * 类参数构造器
23 | *
24 | * @param t0 第一张牌
25 | */
26 | public Wordz_MahjongLiangGangDing(MahjongTileDef t0) {
27 | _t0 = t0;
28 | }
29 |
30 | /**
31 | * 获取第一张麻将牌
32 | *
33 | * @return 第一张麻将牌
34 | */
35 | public MahjongTileDef getT0() {
36 | return _t0;
37 | }
38 |
39 | /**
40 | * 获取第一张麻将牌整数值
41 | *
42 | * @return 第一张麻将牌整数值
43 | */
44 | public int getT0IntVal() {
45 | return null == _t0 ? -1 : _t0.getIntVal();
46 | }
47 |
48 | /**
49 | * 获取第二张麻将牌
50 | *
51 | * @return 第二张麻将牌
52 | */
53 | public MahjongTileDef getT1() {
54 | return _t1;
55 | }
56 |
57 | /**
58 | * 获取第一张麻将牌整数值
59 | *
60 | * @return 第一张麻将牌整数值
61 | */
62 | public int getT1IntVal() {
63 | return null == _t1 ? -1 : _t1.getIntVal();
64 | }
65 |
66 | /**
67 | * 设置第二张牌
68 | *
69 | * @param val 枚举对象
70 | */
71 | public void setT1(MahjongTileDef val) {
72 | _t1 = val;
73 | }
74 |
75 | @Override
76 | public GeneratedMessageV3 buildResultMsg() {
77 | return null;
78 | }
79 |
80 | @Override
81 | public GeneratedMessageV3 buildBroadcastMsg() {
82 | return MJ_weihai_Protocol.MahjongLiangGangDingBroadcast.newBuilder()
83 | .setT0(getT0IntVal())
84 | .setT1(getT1IntVal())
85 | .build();
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/report/Wordz_Prepare.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.report;
2 |
3 | import com.google.protobuf.GeneratedMessageV3;
4 | import org.mj.bizserver.allmsg.MJ_weihai_Protocol;
5 |
6 | /**
7 | * 准备词条
8 | */
9 | public class Wordz_Prepare implements IWordz {
10 | /**
11 | * 用户 Id
12 | */
13 | private final int _userId;
14 |
15 | /**
16 | * 是否准备好, 0 = 取消准备, 1 = 准备好
17 | */
18 | private final int _yes;
19 |
20 | /**
21 | * 是否全部准备好
22 | */
23 | private boolean _allReady = false;
24 |
25 | /**
26 | * 类参数构造器
27 | *
28 | * @param userId 用户 Id
29 | * @param yes 是否准备好, 0 = 取消准备, 1 = 准备好
30 | */
31 | public Wordz_Prepare(int userId, int yes) {
32 | this._userId = userId;
33 | this._yes = yes;
34 | }
35 |
36 | @Override
37 | public int getUserId() {
38 | return _userId;
39 | }
40 |
41 | /**
42 | * 是否准备好
43 | *
44 | * @return 0 = 取消准备, 1 = 准备好
45 | */
46 | public int getYes() {
47 | return _yes;
48 | }
49 |
50 | /**
51 | * 是否全部准备好
52 | *
53 | * @return true = 全部准备好
54 | */
55 | public boolean isAllReady() {
56 | return _allReady;
57 | }
58 |
59 | /**
60 | * 设置全部准备好
61 | *
62 | * @param val 布尔值
63 | */
64 | public void setAllReady(boolean val) {
65 | _allReady = val;
66 | }
67 |
68 | @Override
69 | public GeneratedMessageV3 buildResultMsg() {
70 | return MJ_weihai_Protocol.PrepareResult.newBuilder()
71 | .setYes(_yes)
72 | .setOk(true)
73 | .build();
74 | }
75 |
76 | @Override
77 | public GeneratedMessageV3 buildBroadcastMsg() {
78 | return MJ_weihai_Protocol.PrepareBroadcast.newBuilder()
79 | .setUserId(_userId)
80 | .setYes(_yes)
81 | .setAllReady(_allReady)
82 | .build();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/report/Wordz_RoundStarted.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.report;
2 |
3 | import com.google.protobuf.GeneratedMessageV3;
4 | import org.mj.bizserver.allmsg.MJ_weihai_Protocol;
5 |
6 | /**
7 | * 开局词条
8 | */
9 | public class Wordz_RoundStarted implements IWordz {
10 | /**
11 | * 当前牌局索引
12 | */
13 | private final int _currRoundIndex;
14 |
15 | /**
16 | * 庄家用户 Id
17 | */
18 | private final int _zhuangJiaUserId;
19 |
20 | /**
21 | * 类参数构造器
22 | *
23 | * @param currRoundIndex 当前牌局索引
24 | * @param zhuangJiaUserId 庄家用户 Id
25 | */
26 | public Wordz_RoundStarted(int currRoundIndex, int zhuangJiaUserId) {
27 | _currRoundIndex = currRoundIndex;
28 | _zhuangJiaUserId = zhuangJiaUserId;
29 | }
30 |
31 | /**
32 | * 获取当前牌局索引
33 | *
34 | * @return 当前牌局索引
35 | */
36 | public int getCurrRoundIndex() {
37 | return _currRoundIndex;
38 | }
39 |
40 | /**
41 | * 获取庄家用户 Id
42 | *
43 | * @return 庄家用户 Id
44 | */
45 | public int getZhuangJiaUserId() {
46 | return _zhuangJiaUserId;
47 | }
48 |
49 | @Override
50 | public GeneratedMessageV3 buildResultMsg() {
51 | return null;
52 | }
53 |
54 | @Override
55 | public GeneratedMessageV3 buildBroadcastMsg() {
56 | return MJ_weihai_Protocol.RoundStartedBroadcast.newBuilder()
57 | .setCurrRoundIndex(_currRoundIndex)
58 | .setZhuangJiaUserId(_zhuangJiaUserId)
59 | .build();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/game/MJ_weihai_/timertask/ITimerTask.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.timertask;
2 |
3 | /**
4 | * 定时任务接口
5 | */
6 | public interface ITimerTask {
7 | /**
8 | * 获取在什么时候运行
9 | *
10 | * @return 时间戳
11 | */
12 | long getRunAtTime();
13 |
14 | /**
15 | * 执行任务
16 | */
17 | void doTask();
18 | }
19 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/oauth/IOAuthProc.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.oauth;
2 |
3 | /**
4 | * 登录过程接口
5 | */
6 | public interface IOAuthProc {
7 | /**
8 | * 异步操作 Id, 主要用于分派登录线程
9 | *
10 | * @return 临时 Id
11 | */
12 | int getAsyncOpId();
13 |
14 | /**
15 | * 获取临时 Id
16 | *
17 | * @return 临时 Id
18 | */
19 | String getTempId();
20 |
21 | /**
22 | * 执行授权
23 | *
24 | * @return 用户 Id
25 | */
26 | int doAuth();
27 | }
28 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/oauth/MethodDef.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.oauth;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * ( 登录 ) 方式定义
8 | */
9 | enum MethodDef {
10 | /**
11 | * 测试员登录
12 | */
13 | TESTER_LOGIN(0, "testerLogin"),
14 |
15 | /**
16 | * 游客登录
17 | */
18 | GUEST_LOGIN(1, "guestLogin"),
19 |
20 | /**
21 | * Ukey 登录
22 | */
23 | UKEY_LOGIN(2, "ukeyLogin"),
24 |
25 | /**
26 | * 手机号+验证码登录
27 | */
28 | PHONE_NUMBER_LOGIN(1000, "phoneNumberLogin"),
29 |
30 | /**
31 | * 微信登录
32 | */
33 | WEI_XIN_LOGIN(2000, "weiXinLogin"),
34 |
35 | /**
36 | * 微信公众号登录
37 | */
38 | WEI_XIN_GONG_ZHONG_HAO_LOGIN(2010, "weiXinGongZhongHaoLogin"),
39 | ;
40 |
41 | /**
42 | * 整数值字典
43 | */
44 | static private final Map INT_VAL_MAP = new HashMap<>();
45 |
46 | /**
47 | * 整数值
48 | */
49 | private final int _intVal;
50 |
51 | /**
52 | * 字符串值
53 | */
54 | private final String _strVal;
55 |
56 | /**
57 | * 枚举参数构造器
58 | *
59 | * @param intVal 整数值
60 | * @param strVal 字符串值
61 | */
62 | MethodDef(int intVal, String strVal) {
63 | _intVal = intVal;
64 | _strVal = strVal;
65 | }
66 |
67 | /**
68 | * 获取整数值
69 | *
70 | * @return 整数值
71 | */
72 | public int getIntVal() {
73 | return _intVal;
74 | }
75 |
76 | /**
77 | * 获取字符串值
78 | *
79 | * @return 字符值
80 | */
81 | public String getStrVal() {
82 | return _strVal;
83 | }
84 |
85 | /**
86 | * 根据整数值获取枚举值
87 | *
88 | * @param intVal 整数值
89 | * @return 枚举值
90 | */
91 | static public MethodDef valueOf(int intVal) {
92 | if (INT_VAL_MAP.isEmpty()) {
93 | for (MethodDef $enum : values()) {
94 | INT_VAL_MAP.put($enum.getIntVal(), $enum);
95 | }
96 | }
97 |
98 | return INT_VAL_MAP.getOrDefault(
99 | intVal,
100 | null
101 | );
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/oauth/OAuthProcFactory.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.oauth;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import org.mj.bizserver.def.WorkModeDef;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | /**
9 | * 登录过程工厂类
10 | */
11 | public final class OAuthProcFactory {
12 | /**
13 | * 日志对象
14 | */
15 | static private final Logger LOGGER = LoggerFactory.getLogger(OAuthProcFactory.class);
16 |
17 | /**
18 | * 类默认构造器
19 | */
20 | private OAuthProcFactory() {
21 | }
22 |
23 | /**
24 | * 创建登录方式
25 | *
26 | * @param loginOrAuthMethod 登录或者授权方式
27 | * @param joProperty JSON 属性
28 | * @return 登录方式
29 | */
30 | static public IOAuthProc create(int loginOrAuthMethod, JSONObject joProperty) {
31 | // 获取登录方式
32 | final MethodDef m = MethodDef.valueOf(loginOrAuthMethod);
33 |
34 | if (MethodDef.TESTER_LOGIN == m) {
35 | if (WorkModeDef.currIsDevMode()) {
36 | // 只有开发模式才允许测试员登录
37 | return new TesterAuthProc(joProperty);
38 | } else {
39 | LOGGER.error(
40 | "服务器不是开发模式, 无法执行测试用户授权过程"
41 | );
42 | return null;
43 | }
44 | } else if (MethodDef.GUEST_LOGIN == m) {
45 | // 执行游客登录
46 | return new GuestAuthProc(joProperty);
47 | } else if (MethodDef.UKEY_LOGIN == m) {
48 | // 执行 Ukey 登录
49 | return new UkeyAuthProc(joProperty);
50 | } else if (MethodDef.PHONE_NUMBER_LOGIN == m) {
51 | // 执行手机号登录
52 | return new PhoneNumberAuthProc(joProperty);
53 | } else if (MethodDef.WEI_XIN_GONG_ZHONG_HAO_LOGIN == m) {
54 | // 微信公众号登录
55 | return new WeiXinGongZhongHaoAuthProc();
56 | } else {
57 | return null;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/oauth/UserIdPump.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.oauth;
2 |
3 | import org.mj.bizserver.def.RedisKeyDef;
4 | import org.mj.comm.util.RedisXuite;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import redis.clients.jedis.Jedis;
8 |
9 | /**
10 | * 用户 Id 泵
11 | */
12 | final class UserIdPump {
13 | /**
14 | * 日志对象
15 | */
16 | static private final Logger LOGGER = LoggerFactory.getLogger(UserIdPump.class);
17 |
18 | /**
19 | * 私有化类默认构造器
20 | */
21 | private UserIdPump() {
22 | }
23 |
24 | /**
25 | * 从用户 Id 泵中弹出一个用户 Id!
26 | * XXX 注意: 用户 Id 泵需要运行 devdoc/tool/gen_user_id.py 脚本,
27 | * 需要克隆 devdoc 代码库
28 | *
29 | * @return 用户 Id
30 | */
31 | static int popUpUserId() {
32 | try (Jedis redisCache = RedisXuite.getRedisCache()) {
33 | // 从用户 Id 泵中弹出一个用户 Id
34 | String strUserId = redisCache.lpop(RedisKeyDef.USER_ID_PUMP);
35 |
36 | if (null == strUserId) {
37 | LOGGER.error("用户 Id 泵失效, 弹出用户 Id 为空");
38 | return -1;
39 | }
40 |
41 | return Integer.parseInt(strUserId);
42 | } catch (Exception ex) {
43 | // 记录错误日志
44 | LOGGER.error(ex.getMessage(), ex);
45 | return -1;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/oauth/WeiXinGongZhongHaoAuthProc.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.oauth;
2 |
3 | /**
4 | * 微信公众号授权过程
5 | */
6 | class WeiXinGongZhongHaoAuthProc implements IOAuthProc {
7 | @Override
8 | public int getAsyncOpId() {
9 | return 0;
10 | }
11 |
12 | @Override
13 | public String getTempId() {
14 | return "";
15 | }
16 |
17 | @Override
18 | public int doAuth() {
19 | return -1;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/oauth/dao/IUserDao.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.oauth.dao;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import org.mj.comm.util.MySqlXuite;
5 |
6 | /**
7 | * 用户 DAO
8 | */
9 | @MySqlXuite.DAO
10 | public interface IUserDao {
11 | /**
12 | * 根据列 X 获取用户 Id
13 | *
14 | * @param columnName 列 X
15 | * @param columnVal 列数值
16 | * @return 用户 Id
17 | */
18 | UserEntity getEntityByColumnX(
19 | @Param("_columnName") String columnName,
20 | @Param("_columnVal") String columnVal
21 | );
22 |
23 | /**
24 | * 添加或更新用户实体
25 | *
26 | * @param newEntity 新实体
27 | */
28 | void insertOrUpdate(UserEntity newEntity);
29 |
30 | /**
31 | * 根据用户 Id 更新列
32 | *
33 | * @param userId 用户 Id
34 | * @param columnName 列名称
35 | * @param columnVal 列数值
36 | */
37 | void updateColumnXByUserId(
38 | @Param("_userId") int userId,
39 | @Param("_columnName") String columnName,
40 | @Param("_columnVal") String columnVal
41 | );
42 | }
43 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/oauth/dao/IUserDao.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
21 |
22 | INSERT INTO t_user (
23 | user_id,
24 | user_name,
25 | head_img,
26 | sex,
27 | room_card,
28 | create_time,
29 | client_ver,
30 | last_login_time,
31 | last_login_ip,
32 | state
33 | )
34 | VALUE (
35 | #{_userId},
36 | #{_userName},
37 | #{_headImg},
38 | #{_sex},
39 | #{_roomCard},
40 | #{_createTime},
41 | #{_clientVer},
42 | #{_lastLoginTime},
43 | #{_lastLoginIp},
44 | #{_state}
45 | ) ON DUPLICATE KEY UPDATE
46 | user_name = #{_userName},
47 | head_img = #{_headImg},
48 | sex = #{_sex},
49 | client_ver = #{_clientVer},
50 | last_login_time = #{_lastLoginTime},
51 | last_login_ip = #{_lastLoginIp};
52 |
53 |
54 |
55 | UPDATE t_user SET ${_columnName} = #{_columnVal} WHERE user_id = #{_userId}
56 |
57 |
58 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/record/RecordBizLogic$saveARecord.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.record;
2 |
3 | import org.apache.ibatis.session.SqlSession;
4 | import org.mj.bizserver.mod.record.dao.IRoomLogDao;
5 | import org.mj.bizserver.mod.record.dao.IRoundLogDao;
6 | import org.mj.bizserver.mod.record.dao.RoomLogEntity;
7 | import org.mj.bizserver.mod.record.dao.RoundLogEntity;
8 | import org.mj.comm.util.MySqlXuite;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | /**
13 | * 保存一条记录
14 | */
15 | public interface RecordBizLogic$saveARecord {
16 | /**
17 | * 日志对象
18 | */
19 | Logger LOGGER = LoggerFactory.getLogger(RecordBizLogic$saveARecord.class);
20 |
21 | /**
22 | * 保存一条记录
23 | *
24 | * @param roomLogEntity 房间日志实体
25 | */
26 | default void saveARecord(RoomLogEntity roomLogEntity) {
27 | if (null == roomLogEntity ||
28 | null == roomLogEntity.getRoomUUId() ||
29 | null == roomLogEntity.getCreateTime() ||
30 | roomLogEntity.getCreateTime() <= 0) {
31 | return;
32 | }
33 |
34 | try (SqlSession sessionX = MySqlXuite.openLogDbSession()) {
35 | // 插入或更新日志
36 | sessionX.getMapper(IRoomLogDao.class).insertOrElseUpdate(roomLogEntity);
37 | } catch (Exception ex) {
38 | // 记录错误日志
39 | LOGGER.error(ex.getMessage(), ex);
40 | }
41 | }
42 |
43 | /**
44 | * 保存一条记录
45 | *
46 | * @param roundLogEntity 牌局日志实体
47 | */
48 | default void saveARecord(RoundLogEntity roundLogEntity) {
49 | if (null == roundLogEntity ||
50 | null == roundLogEntity.getRoomUUId()) {
51 | return;
52 | }
53 |
54 | try (SqlSession sessionX = MySqlXuite.openLogDbSession()) {
55 | // 插入或更新日志
56 | sessionX.getMapper(IRoundLogDao.class).insertOrElseUpdate(roundLogEntity);
57 | } catch (Exception ex) {
58 | // 记录错误日志
59 | LOGGER.error(ex.getMessage(), ex);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/record/RecordBizLogic.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.record;
2 |
3 | /**
4 | * 战绩业务逻辑
5 | */
6 | public final class RecordBizLogic implements
7 | RecordBizLogic$getRecordDetailz_async,
8 | RecordBizLogic$getRecordList_async,
9 | RecordBizLogic$saveARecord {
10 | /**
11 | * 单例对象
12 | */
13 | static private final RecordBizLogic _instance = new RecordBizLogic();
14 |
15 | /**
16 | * 私有化类默认构造器
17 | */
18 | private RecordBizLogic() {
19 | }
20 |
21 | /**
22 | * 获取单例对象
23 | *
24 | * @return 单例对象
25 | */
26 | static public RecordBizLogic getInstance() {
27 | return _instance;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/record/dao/IRoundLogDao.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.record.dao;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import org.mj.comm.util.MySqlXuite;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * 牌局日志 DAO
10 | */
11 | @MySqlXuite.DAO
12 | public interface IRoundLogDao {
13 | /**
14 | * 插入否则更新数据
15 | *
16 | * @param newEntity 牌局日志实体
17 | */
18 | void insertOrElseUpdate(RoundLogEntity newEntity);
19 |
20 | /**
21 | * 是否存在本周数据表?
22 | * 如果有, 就返回数据表名称;
23 | * 如果没有, 则返回空值;
24 | *
25 | * @param thisWeekTableNamePrefix 本周数据表名称前缀
26 | * @return 数据表名称
27 | */
28 | String existThisWeekTable(
29 | @Param("_thisWeekTableNamePrefix") String thisWeekTableNamePrefix
30 | );
31 |
32 | /**
33 | * 根据房间 UUId 获取牌局日志实体列表
34 | *
35 | * @param thisWeekTableNamePrefix 本周数据表名称前缀
36 | * @param roomUUId 房间 UUId
37 | * @return 牌局日志实体列表
38 | */
39 | List getEntityListByRoomUUId(
40 | @Param("_thisWeekTableNamePrefix") String thisWeekTableNamePrefix,
41 | @Param("_roomUUId") String roomUUId
42 | );
43 | }
44 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/stat/StatBizLogic.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.stat;
2 |
3 | import org.apache.ibatis.session.SqlSession;
4 | import org.mj.bizserver.mod.stat.dao.IUserGameLogDao;
5 | import org.mj.bizserver.mod.stat.dao.UserGameLogEntity;
6 | import org.mj.comm.util.MySqlXuite;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | import java.util.List;
11 |
12 | /**
13 | * 统计业务逻辑
14 | */
15 | public final class StatBizLogic {
16 | /**
17 | * 日志对象
18 | */
19 | static private final Logger LOGGER = LoggerFactory.getLogger(StatBizLogic.class);
20 |
21 | /**
22 | * 单例对象
23 | */
24 | static private final StatBizLogic _instance = new StatBizLogic();
25 |
26 | /**
27 | * 私有化类默认构造器
28 | */
29 | private StatBizLogic() {
30 | }
31 |
32 | /**
33 | * 获取单例对象
34 | *
35 | * @return 单例对象
36 | */
37 | static public StatBizLogic getInstance() {
38 | return _instance;
39 | }
40 |
41 | /**
42 | * 保存日志实体列表
43 | *
44 | * @param logEntityList 日志实体列表
45 | */
46 | public void saveLogEntityList(List logEntityList) {
47 | if (null == logEntityList ||
48 | logEntityList.size() <= 0) {
49 | return;
50 | }
51 |
52 | try (SqlSession sessionX = MySqlXuite.openLogDbSession()) {
53 | // 获取 DAO 并执行插入操作
54 | IUserGameLogDao daoX = sessionX.getMapper(IUserGameLogDao.class);
55 | logEntityList.forEach(daoX::insertOrElseUpdate);
56 | } catch (Exception ex) {
57 | // 记录错误日志
58 | LOGGER.error(ex.getMessage(), ex);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/stat/dao/IUserGameLogDao.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.stat.dao;
2 |
3 | import org.mj.comm.util.MySqlXuite;
4 |
5 | /**
6 | * 用户游戏日志 DAO
7 | */
8 | @MySqlXuite.DAO
9 | public interface IUserGameLogDao {
10 | /**
11 | * 插入实体对象
12 | *
13 | * @param entity 实体对象
14 | */
15 | void insertOrElseUpdate(UserGameLogEntity entity);
16 | }
17 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/stat/dao/IUserGameLogDao.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | CREATE TABLE IF NOT EXISTS t_${thisWeekTableNamePrefix}_user_game_log LIKE mj_log_template.t_template_user_game_log;
7 | CREATE TABLE IF NOT EXISTS t_${nextWeekTableNamePrefix}_user_game_log LIKE mj_log_template.t_template_user_game_log;
8 |
9 |
10 | INSERT INTO t_${thisWeekTableNamePrefix}_user_game_log (
11 | `room_uuid`,
12 | `user_id`,
13 | `club_id`,
14 | `room_id`,
15 | `game_type_0`,
16 | `game_type_1`,
17 | `create_time`,
18 | `total_score`,
19 | `is_winner`
20 | ) VALUE (
21 | #{_roomUUId},
22 | #{_userId},
23 | #{_clubId},
24 | #{_roomId},
25 | #{_gameType0},
26 | #{_gameType1},
27 | #{_createTime},
28 | #{_totalScore},
29 | #{_isWinner}
30 | ) ON DUPLICATE KEY UPDATE
31 | total_score = #{_totalScore},
32 | is_winner = #{_isWinner};
33 |
34 |
35 | INSERT INTO t_${thisWeekTableNamePrefix}_user_game_log (
36 | `room_uuid`,
37 | `user_id`,
38 | `club_id`,
39 | `room_id`,
40 | `game_type_0`,
41 | `game_type_1`,
42 | `create_time`,
43 | `total_score`,
44 | `is_winner`
45 | ) VALUE (
46 | #{_roomUUId},
47 | #{_userId},
48 | #{_clubId},
49 | #{_roomId},
50 | #{_gameType0},
51 | #{_gameType1},
52 | #{_createTime},
53 | #{_totalScore},
54 | #{_isWinner}
55 | ) ON DUPLICATE KEY UPDATE
56 | total_score = #{_totalScore},
57 | is_winner = #{_isWinner};
58 |
59 |
60 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/userinfo/UserInfoBizLogic$costRoomCard.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.userinfo;
2 |
3 | import org.apache.ibatis.session.SqlSession;
4 | import org.mj.bizserver.def.RedisKeyDef;
5 | import org.mj.bizserver.foundation.BizResultWrapper;
6 | import org.mj.bizserver.mod.userinfo.dao.IUserDao;
7 | import org.mj.comm.util.MySqlXuite;
8 | import org.mj.comm.util.RedisXuite;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 | import redis.clients.jedis.Jedis;
12 |
13 | /**
14 | * 消耗房卡
15 | */
16 | interface UserInfoBizLogic$costRoomCard {
17 | /**
18 | * 日志对象
19 | */
20 | Logger LOGGER = LoggerFactory.getLogger(UserInfoBizLogic$costRoomCard.class);
21 |
22 | /**
23 | * 消耗房卡
24 | *
25 | * @param userId 用户 Id
26 | * @param deltaVal 变化值
27 | * @param resultX 业务结果
28 | */
29 | default void costRoomCard(int userId, int deltaVal, BizResultWrapper resultX) {
30 | if (userId <= 0 ||
31 | deltaVal <= 0) {
32 | return;
33 | }
34 |
35 | try (SqlSession sessionX = MySqlXuite.openGameDbSession()) {
36 | // 消耗房卡
37 | final int effectRowNum = sessionX.getMapper(IUserDao.class).costRoomCard(userId, deltaVal);
38 |
39 | if (null != resultX) {
40 | resultX.setFinalResult(effectRowNum > 0);
41 | }
42 |
43 | try (Jedis redisCache = RedisXuite.getRedisCache()) {
44 | redisCache.hdel(
45 | RedisKeyDef.USER_X_PREFIX + userId,
46 | RedisKeyDef.USER_DETAILZ
47 | );
48 | }
49 | } catch (Exception ex) {
50 | // 记录错误日志
51 | LOGGER.error(ex.getMessage(), ex);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/userinfo/UserInfoBizLogic.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.userinfo;
2 |
3 | /**
4 | * 用户信息业务逻辑
5 | */
6 | public final class UserInfoBizLogic implements
7 | UserInfoBizLogic$costRoomCard,
8 | UserInfoBizLogic$getUserDetailzByUserId {
9 | /**
10 | * 单例对象
11 | */
12 | static private final UserInfoBizLogic _instance = new UserInfoBizLogic();
13 |
14 | /**
15 | * 类默认构造器
16 | */
17 | private UserInfoBizLogic() {
18 | }
19 |
20 | /**
21 | * 获取单例对象
22 | *
23 | * @return 单例对象
24 | */
25 | static public UserInfoBizLogic getInstance() {
26 | return _instance;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/userinfo/dao/IUserDao.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.userinfo.dao;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import org.mj.comm.util.MySqlXuite;
5 |
6 | /**
7 | * 用户 DAO
8 | */
9 | @MySqlXuite.DAO
10 | public interface IUserDao {
11 | /**
12 | * 根据用户 Id 获取用户实体
13 | *
14 | * @param userId 用户 Id
15 | * @return 用户实体
16 | */
17 | UserEntity getEntityByUserId(@Param("_userId") int userId);
18 |
19 | /**
20 | * 消耗房卡
21 | *
22 | * @param userId 用户 Id
23 | * @param deltaVal 变化值
24 | * @return 返回影响行数
25 | */
26 | int costRoomCard(
27 | @Param("_userId") int userId,
28 | @Param("_deltaVal") int deltaVal
29 | );
30 | }
31 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/userinfo/dao/IUserDao.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
21 |
22 | UPDATE
23 | t_user
24 | SET
25 | room_card = room_card - #{_deltaVal}
26 | WHERE
27 | user_id = #{_userId} AND room_card >= ${_deltaVal}
28 |
29 |
30 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/userlogin/TicketGen.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.userlogin;
2 |
3 | import org.mj.bizserver.def.RedisKeyDef;
4 | import org.mj.comm.util.RedisXuite;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import redis.clients.jedis.Jedis;
8 |
9 | import java.util.UUID;
10 |
11 | /**
12 | * 登录票据生成器
13 | */
14 | class TicketGen {
15 | /**
16 | * 日志对象
17 | */
18 | static private final Logger LOGGER = LoggerFactory.getLogger(TicketGen.class);
19 |
20 | /**
21 | * 私有化类默认构造器
22 | */
23 | private TicketGen() {
24 | }
25 |
26 | /**
27 | * 生成票据, 20 秒有效期
28 | *
29 | * @param userId 用户 Id
30 | * @return 票据
31 | */
32 | static String genTicket(int userId) {
33 | if (userId <= 0) {
34 | return null;
35 | }
36 |
37 | // 创建票据
38 | final String newTicket = UUID.randomUUID().toString();
39 | // 票据关键字
40 | final String redisKey = RedisKeyDef.TICKET_X_PREFIX + newTicket;
41 |
42 | try (Jedis redisCache = RedisXuite.getRedisCache()) {
43 | // 将票据保存到 Redis,
44 | // 20 秒有效期
45 | redisCache.set(redisKey, String.valueOf(userId));
46 | redisCache.pexpire(redisKey, 20000);
47 |
48 | return newTicket;
49 | } catch (Exception ex) {
50 | // 记录错误日志
51 | LOGGER.error(ex.getMessage(), ex);
52 | }
53 |
54 | return null;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/userlogin/UserLoginBizLogic.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.userlogin;
2 |
3 | /**
4 | * 用户登录业务逻辑
5 | */
6 | public final class UserLoginBizLogic implements
7 | UserLoginBizLogic$doUserLogin {
8 | /**
9 | * 单例对象
10 | */
11 | static private final UserLoginBizLogic _instance = new UserLoginBizLogic();
12 |
13 | /**
14 | * 类默认构造器
15 | */
16 | private UserLoginBizLogic() {
17 | }
18 |
19 | /**
20 | * 获取单例对象
21 | *
22 | * @return 单例对象
23 | */
24 | static public UserLoginBizLogic getInstance() {
25 | return _instance;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/bizserver/src/main/java/org/mj/bizserver/mod/userlogin/bizdata/LoginResult.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.userlogin.bizdata;
2 |
3 | import java.util.Objects;
4 |
5 | /**
6 | * 登陆票据
7 | */
8 | public class LoginResult {
9 | /**
10 | * 用户 Id
11 | */
12 | private int _userId;
13 |
14 | /**
15 | * 用户名称
16 | */
17 | private String _userName;
18 |
19 | /**
20 | * 票据
21 | */
22 | private String _ticket;
23 |
24 | /**
25 | * 数字证书字符串
26 | */
27 | private String _ukeyStr;
28 |
29 | /**
30 | * 数字证书过期时间
31 | */
32 | private long _ukeyExpireAt;
33 |
34 | /**
35 | * 获取用户 Id
36 | *
37 | * @return 用户 Id
38 | */
39 | public int getUserId() {
40 | return _userId;
41 | }
42 |
43 | /**
44 | * 设置用户 Id
45 | *
46 | * @param val 用户 Id
47 | */
48 | public void setUserId(int val) {
49 | _userId = val;
50 | }
51 |
52 | /**
53 | * 获取用户名称
54 | *
55 | * @return 用户名称
56 | */
57 | public String getUserName() {
58 | return Objects.requireNonNullElse(_userName, "");
59 | }
60 |
61 | /**
62 | * 设置用户名称
63 | *
64 | * @param val 用户名称
65 | */
66 | public void setUserName(String val) {
67 | _userName = val;
68 | }
69 |
70 | /**
71 | * 获取票据
72 | *
73 | * @return 票据
74 | */
75 | public String getTicket() {
76 | return Objects.requireNonNullElse(_ticket, "");
77 | }
78 |
79 | /**
80 | * 设置票据
81 | *
82 | * @param val 票据
83 | */
84 | public void setTicket(String val) {
85 | _ticket = val;
86 | }
87 |
88 | /**
89 | * 获取数字证书字符串
90 | *
91 | * @return 数字证书字符串
92 | */
93 | public String getUkeyStr() {
94 | return _ukeyStr;
95 | }
96 |
97 | /**
98 | * 设置数字证书字符串
99 | *
100 | * @param val 字符串值
101 | */
102 | public void setUkeyStr(String val) {
103 | _ukeyStr = val;
104 | }
105 |
106 | /**
107 | * 获取数字证书过期时间
108 | *
109 | * @return 数字证书过期时间
110 | */
111 | public long getUkeyExpireAt() {
112 | return _ukeyExpireAt;
113 | }
114 |
115 | /**
116 | * 设置数字证书过期时间
117 | *
118 | * @param val 整数值
119 | */
120 | public void setUkeyExpireAt(long val) {
121 | _ukeyExpireAt = val;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/bizserver/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=info,stdout,all
2 |
3 | # --- stdout ---
4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
5 | log4j.appender.stdout.encoding=UTF-8
6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7 | log4j.appender.stdout.layout.conversionPattern=[%d{HH:mm:ss,SSS}] [%p] %C{1}.%M --> %m%n
8 |
9 | # --- all ---
10 | log4j.appender.all=org.apache.log4j.DailyRollingFileAppender
11 | log4j.appender.all.encoding=UTF-8
12 | log4j.appender.all.append=true
13 | log4j.appender.all.datePattern='.'yyyy-MM-dd
14 | log4j.appender.all.file=log/all.log
15 | log4j.appender.all.layout=org.apache.log4j.PatternLayout
16 | log4j.appender.all.layout.conversionPattern=[%d{HH:mm:ss,SSS}] [%p] %C{1}.%M --> %m%n
17 |
--------------------------------------------------------------------------------
/bizserver/src/test/java/org/mj/bizserver/TestIniter.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import org.apache.log4j.PropertyConfigurator;
5 | import org.mj.bizserver.def.RedisKeyDef;
6 | import org.mj.bizserver.mod.club.adminctrl.AdminCtrlBizLogicTest;
7 | import org.mj.comm.util.DLock;
8 | import org.mj.comm.util.MySqlXuite;
9 | import org.mj.comm.util.RedisXuite;
10 |
11 | import java.io.BufferedReader;
12 | import java.io.FileReader;
13 | import java.util.stream.Collectors;
14 |
15 | /**
16 | * 测试初始化
17 | */
18 | public final class TestIniter {
19 | /**
20 | * 私有化类默认构造器
21 | */
22 | private TestIniter() {
23 | }
24 |
25 | /**
26 | * 初始化
27 | */
28 | static public void init() {
29 | // 设置 log4j 属性文件
30 | PropertyConfigurator.configure(AdminCtrlBizLogicTest.class.getClassLoader().getResourceAsStream("log4j.properties"));
31 |
32 | // 获取服务器配置
33 | JSONObject joBizServerConf = loadBizServerConf(
34 | "../etc/bizserver_all.conf.json"
35 | );
36 |
37 | if (joBizServerConf.containsKey("redisXuite")) {
38 | // 初始化 Redis
39 | RedisXuite.Config redisXuiteConf = RedisXuite.Config.fromJSONObj(joBizServerConf);
40 | RedisXuite.init(redisXuiteConf);
41 | DLock._redisKeyPrefix = RedisKeyDef.DLOCK_X_PREFIX;
42 | }
43 |
44 | if (joBizServerConf.containsKey("mySqlXuite")) {
45 | // 初始化 MySql
46 | MySqlXuite.Config mySqlXuiteConf = MySqlXuite.Config.fromJSONObj(joBizServerConf);
47 | MySqlXuite.init(mySqlXuiteConf, BizServer.class);
48 | }
49 | }
50 |
51 | /**
52 | * 加载业务服务器配置
53 | *
54 | * @param filePath 文件路径
55 | * @return JSON 对象
56 | */
57 | static private JSONObject loadBizServerConf(final String filePath) {
58 | if (null == filePath ||
59 | filePath.isEmpty()) {
60 | throw new IllegalArgumentException("filePath is null or empty");
61 | }
62 |
63 | try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
64 | // 获取 JSON 文本
65 | final String jsonText = br.lines().collect(Collectors.joining());
66 | // 解析 JSON 对象
67 | return JSONObject.parseObject(jsonText);
68 | } catch (Exception ex) {
69 | // 记录错误日志
70 | throw new RuntimeException(ex);
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/bizserver/src/test/java/org/mj/bizserver/mod/club/adminctrl/AdminCtrlBizLogicTest.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.club.adminctrl;
2 |
3 | import org.mj.bizserver.TestIniter;
4 | import org.mj.bizserver.def.GameType0Enum;
5 | import org.mj.bizserver.def.GameType1Enum;
6 | import org.mj.bizserver.mod.club.membercenter.bizdata.FixGameX;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 | import java.util.concurrent.CountDownLatch;
11 |
12 | /**
13 | * 亲友圈管理员控制逻辑测试
14 | */
15 | public class AdminCtrlBizLogicTest {
16 | //@Test
17 | public void allTest() {
18 | TestIniter.init();
19 |
20 | final CountDownLatch cd = new CountDownLatch(1);
21 |
22 | // // 创建亲友圈
23 | // AdminCtrlBizLogic.getInstance().createClub_async(
24 | // 7929621, "AfrX's Club", (resultX) -> {
25 | // cd.countDown();
26 | // });
27 |
28 | // // 同意申请
29 | // AdminCtrlBizLogic.getInstance().approvalToJoin_async(
30 | // 7929621, 8344532, 414984, true, (resultX) -> {
31 | // cd.countDown();
32 | // });
33 |
34 | // // 修改角色
35 | // AdminCtrlBizLogic.getInstance().changeRole_async(
36 | // 7929621, 8344532, 414984, RoleDef.ADMIN, (resultX) -> {
37 | // cd.countDown();
38 | // });
39 |
40 | // // 开除成员
41 | // AdminCtrlBizLogic.getInstance().dismissAMember_async(
42 | // 7929621, 8344532, 414984, (resultX) -> {
43 | // cd.countDown();
44 | // });
45 |
46 | // // 充值房卡
47 | // AdminCtrlBizLogic.getInstance().exchangeRoomCard_async(
48 | // 7929621, 414984, 99, (resultX) -> {
49 | // cd.countDown();
50 | // });
51 |
52 | final Map ruleMap = new HashMap<>();
53 | ruleMap.put(1001, 1);
54 | ruleMap.put(1002, 2);
55 | FixGameX fixGameX = new FixGameX();
56 | fixGameX.setIndex(3);
57 | fixGameX.setGameType0(GameType0Enum.MAHJONG);
58 | fixGameX.setGameType1(GameType1Enum.MJ_weihai_);
59 | fixGameX.setRuleMap(ruleMap);
60 |
61 | // 修改默认玩法
62 | AdminCtrlBizLogic.getInstance().modifyFixGameX_async(
63 | 7929621, 414984, fixGameX, (resultX) -> {
64 | cd.countDown();
65 | }
66 | );
67 |
68 | try {
69 | cd.await();
70 | } catch (Exception ex) {
71 | // 打印错误日志
72 | ex.printStackTrace();
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/bizserver/src/test/java/org/mj/bizserver/mod/club/membercenter/MemberCenterBizLogicTest.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.club.membercenter;
2 |
3 | import org.junit.Test;
4 | import org.mj.bizserver.TestIniter;
5 |
6 | import java.util.concurrent.CountDownLatch;
7 |
8 | /**
9 | * 亲友圈成员中心业务逻辑测试
10 | */
11 | public class MemberCenterBizLogicTest {
12 | //@Test
13 | public void allTest() {
14 | TestIniter.init();
15 |
16 | final CountDownLatch cd = new CountDownLatch(1);
17 |
18 | MemberCenterBizLogic.getInstance().joinClub_async(8344532, 414984, (resultX) -> {
19 | cd.countDown();
20 | });
21 |
22 | try {
23 | cd.await();
24 | } catch (Exception ex) {
25 | // 打印错误日志
26 | ex.printStackTrace();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/bizserver/src/test/java/org/mj/bizserver/mod/game/MJ_weihai_/hupattern/Pattern_JiaHuTest.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.game.MJ_weihai_.hupattern;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 | import org.mj.bizserver.mod.game.MJ_weihai_.bizdata.MahjongTileDef;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 夹胡测试
11 | */
12 | public class Pattern_JiaHuTest {
13 | @Test
14 | public void test1() {
15 | boolean yes = new Pattern_JiaHu().test(null, List.of(
16 | MahjongTileDef._1_WAN,
17 | MahjongTileDef._1_WAN,
18 | MahjongTileDef._1_WAN,
19 | MahjongTileDef._4_TIAO,
20 | MahjongTileDef._6_TIAO,
21 | MahjongTileDef._3_BING,
22 | MahjongTileDef._3_BING,
23 | MahjongTileDef._3_BING,
24 | MahjongTileDef._4_BING,
25 | MahjongTileDef._4_BING,
26 | MahjongTileDef._4_BING,
27 | MahjongTileDef._5_BING,
28 | MahjongTileDef._5_BING
29 |
30 | ), MahjongTileDef._5_TIAO);
31 |
32 | Assert.assertTrue(yes);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/bizserver/src/test/java/org/mj/bizserver/mod/record/RecordBizLogicTest.java:
--------------------------------------------------------------------------------
1 | package org.mj.bizserver.mod.record;
2 |
3 | import org.mj.bizserver.TestIniter;
4 | import org.mj.bizserver.def.GameType0Enum;
5 | import org.mj.bizserver.mod.record.bizdata.RecordSummary;
6 | import org.mj.comm.util.OutParam;
7 |
8 | import java.util.List;
9 | import java.util.concurrent.CountDownLatch;
10 |
11 | /**
12 | * 战绩业务逻辑测试
13 | */
14 | public class RecordBizLogicTest {
15 | //@Test
16 | public void allTest() {
17 | TestIniter.init();
18 |
19 | final CountDownLatch cd = new CountDownLatch(1);
20 | final OutParam out_totalCount = new OutParam<>();
21 |
22 | RecordBizLogic.getInstance().getRecordList_async(
23 | 7929621, -1, GameType0Enum.MAHJONG, null, 0, 20,
24 | out_totalCount,
25 | (resultX) -> {
26 | if (null == resultX ||
27 | null == resultX.getFinalResult()) {
28 | throw new RuntimeException("error");
29 | }
30 |
31 | List recordSummaryList = resultX.getFinalResult();
32 |
33 | for (RecordSummary recordSummary : recordSummaryList) {
34 | recordSummary.getPlayerList();
35 | }
36 |
37 | cd.countDown();
38 | }
39 | );
40 |
41 | try {
42 | cd.await();
43 | } catch (Exception ex) {
44 | // 打印错误日志
45 | ex.printStackTrace();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/bizserver/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=info,stdout,all
2 |
3 | # --- stdout ---
4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
5 | log4j.appender.stdout.encoding=UTF-8
6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7 | log4j.appender.stdout.layout.conversionPattern=[%d{HH:mm:ss,SSS}] [%p] %C{1}.%M --> %m%n
8 |
9 | # --- all ---
10 | log4j.appender.all=org.apache.log4j.DailyRollingFileAppender
11 | log4j.appender.all.encoding=UTF-8
12 | log4j.appender.all.append=true
13 | log4j.appender.all.datePattern='.'yyyy-MM-dd
14 | log4j.appender.all.file=log/all.log
15 | log4j.appender.all.layout=org.apache.log4j.PatternLayout
16 | log4j.appender.all.layout.conversionPattern=[%d{HH:mm:ss,SSS}] [%p] %C{1}.%M --> %m%n
17 |
--------------------------------------------------------------------------------
/comm/src/main/java/org/mj/comm/async/IAsyncOperation.java:
--------------------------------------------------------------------------------
1 | package org.mj.comm.async;
2 |
3 | /**
4 | * 异步操作接口
5 | */
6 | @FunctionalInterface
7 | public interface IAsyncOperation {
8 | /**
9 | * 执行异步操作
10 | */
11 | void doAsync();
12 | }
13 |
--------------------------------------------------------------------------------
/comm/src/main/java/org/mj/comm/async/IContinueWith.java:
--------------------------------------------------------------------------------
1 | package org.mj.comm.async;
2 |
3 | /**
4 | * 异步操作之后回到主线程继续执行
5 | */
6 | @FunctionalInterface
7 | public interface IContinueWith {
8 | /**
9 | * 继续执行
10 | */
11 | void doContinue();
12 | }
13 |
--------------------------------------------------------------------------------
/comm/src/main/java/org/mj/comm/cmdhandler/ICmdHandler.java:
--------------------------------------------------------------------------------
1 | package org.mj.comm.cmdhandler;
2 |
3 | import com.google.protobuf.GeneratedMessageV3;
4 | import io.netty.channel.ChannelHandlerContext;
5 |
6 | /**
7 | * 命令处理器接口
8 | */
9 | public interface ICmdHandler {
10 | /**
11 | * 处理命令
12 | *
13 | * @param ctx 信道上下文
14 | * @param remoteSessionId 远程会话 Id
15 | * @param fromUserId 来自用户 Id
16 | * @param cmdObj 命令对象
17 | */
18 | void handle(ChannelHandlerContext ctx, int remoteSessionId, int fromUserId, TCmd cmdObj);
19 |
20 | /**
21 | * 处理命令
22 | *
23 | * @param ctx 命令处理器上下文
24 | * @param cmdObj 命令对象
25 | */
26 | default void handle(AbstractCmdHandlerContext ctx, TCmd cmdObj) {
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/comm/src/main/java/org/mj/comm/pubsub/MyPublisher.java:
--------------------------------------------------------------------------------
1 | package org.mj.comm.pubsub;
2 |
3 | import org.mj.comm.util.RedisXuite;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import redis.clients.jedis.Jedis;
7 |
8 | /**
9 | * 自定义发布者
10 | */
11 | public final class MyPublisher {
12 | /**
13 | * 日志对象
14 | */
15 | static private final Logger LOGGER = LoggerFactory.getLogger(MyPublisher.class);
16 |
17 | /**
18 | * 类默认构造器
19 | */
20 | public MyPublisher() {
21 | }
22 |
23 | /**
24 | * 发布
25 | *
26 | * @param channel 频道
27 | * @param strMsg 字符串消息
28 | */
29 | public void publish(String channel, String strMsg) {
30 | if (null == channel ||
31 | null == strMsg) {
32 | return;
33 | }
34 |
35 | try (Jedis redisPubsub = RedisXuite.getRedisPubSub()) {
36 | redisPubsub.publish(
37 | channel, strMsg
38 | );
39 | } catch (Exception ex) {
40 | // 记录错误日志
41 | LOGGER.error(ex.getMessage(), ex);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/comm/src/main/java/org/mj/comm/util/CustomDataSourceFactory.java:
--------------------------------------------------------------------------------
1 | package org.mj.comm.util;
2 |
3 | import com.alibaba.druid.pool.DruidDataSourceFactory;
4 | import org.apache.ibatis.datasource.DataSourceFactory;
5 |
6 | import javax.sql.DataSource;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 | import java.util.Properties;
10 |
11 | /**
12 | * 自定义数据源工厂类
13 | */
14 | public class CustomDataSourceFactory implements DataSourceFactory {
15 | /**
16 | * 属性字典
17 | */
18 | private final Map