Skip to content

Commit 55dfd5f

Browse files
bcgameProjectbc
authored andcommitted
verify
1 parent 960648c commit 55dfd5f

28 files changed

+5527
-265
lines changed

baccarat.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ <h2 class="text-center pb-5">Results</h2>
297297
amount: 10,
298298
initHash: qs.hash,
299299
salt:
300-
"00000000000000000009c6d5d13f0bf616e9601ab9b7f2dce635492700aaa773",
300+
"0000000000000000000301e2801a9a9598bfb114e574a91a887f2132f33047e6",
301301
result: [],
302302
},
303303
computed: {},

baccaratsingle.html

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Baccarat Single Verify</title>
8+
<link rel="stylesheet" href="./lib/main.css">
9+
<link rel="stylesheet" href="./lib/bootstrap/css/bootstrap.min.css">
10+
<script src="./lib/react.production.min.js"></script>
11+
<script src="./lib/react-dom.production.min.js"></script>
12+
<script src="./lib/crypto-js.js"></script>
13+
<script src="./lib/tools.js"></script>
14+
<script src="./lib/hooks.js"></script>
15+
<script src="./lib/babel.min.js"></script>
16+
<style>
17+
.cards-list {
18+
margin-bottom: 12px;
19+
display: flex;
20+
align-items: center;
21+
}
22+
.cards-list .card {
23+
margin-right: 20px;
24+
}
25+
.card.red {
26+
color: #f00;
27+
}
28+
</style>
29+
</head>
30+
<body>
31+
<div id="app"></div>
32+
<script type="text/babel">
33+
let qs = tools.queryString();
34+
let { useEffect, useMemo } = React;
35+
const { useSetState } = hooks;
36+
function useInputControl (initState) {
37+
const [state, setState] = useSetState(initState);
38+
const bind = key => ({
39+
value: state[key],
40+
onChange: v => setState({[key]: v})
41+
});
42+
return [
43+
state,
44+
setState,
45+
bind
46+
];
47+
}
48+
function Input ({value, onChange, ...others}) {
49+
return (
50+
<div class="form-group">
51+
<input value={value}
52+
onChange={e => onChange(e.target.value)}
53+
class="form-control"
54+
{...others}
55+
/>
56+
</div>
57+
);
58+
}
59+
60+
const allNums = [
61+
161, 180, 199, 218, 162, 205, 181, 200, 219, 163, 182, 220, 201, 177, 196,
62+
215, 170, 178, 221, 197, 216, 171, 179, 198, 172, 217, 193, 212, 167, 186,
63+
194, 173, 213, 168, 187, 195, 214, 188, 169, 209, 164, 183, 202, 210, 189,
64+
165, 184, 203, 211, 166, 204, 185,
65+
];
66+
67+
function createCards (hash, times, cards, hashList) {
68+
hashList.push(hash);
69+
if (times <= 0) return
70+
let h = hash;
71+
allNums.forEach((c) => {
72+
cards.push({card: c, hash: h});
73+
h = h.substring(1) + h.charAt(0);
74+
});
75+
76+
hash = String(CryptoJS.SHA256(hash));
77+
times--;
78+
createCards(hash, times, cards, hashList);
79+
}
80+
81+
function create (hash, times) {
82+
times = times || 2;
83+
let cards = [];
84+
let hashList = [];
85+
createCards(hash, times, cards, hashList);
86+
cards.sort(function (o1, o2) {
87+
if (o1.hash < o2.hash) {
88+
return -1;
89+
} else if (o1.hash == o2.hash) {
90+
return 0;
91+
} else {
92+
return 1;
93+
}
94+
})
95+
return cards;
96+
}
97+
98+
function canBankerGetCard (point, palyerPoint, thirdCardPoint) {
99+
if(palyerPoint >= 8) return false;
100+
if(point <= 2) return true;
101+
else if(point === 3) {
102+
return thirdCardPoint !=8 ;
103+
} else if(point === 4) {
104+
return [0, 1, 8, 9].indexOf(thirdCardPoint) < 0;
105+
} else if(point === 5) {
106+
return [0, 1, 2, 3, 8, 9].indexOf(thirdCardPoint) < 0;
107+
} else if(point === 6) {
108+
return [6, 7].indexOf(thirdCardPoint) >= 0;
109+
}
110+
return false;
111+
}
112+
113+
function getPoint (list) {
114+
const result = list.reduce((pre, item) => {
115+
const currPoint = item.pointNum > 10 ? 10 : item.pointNum;
116+
return pre + currPoint;
117+
}, 0)
118+
return result % 10;
119+
}
120+
121+
function getRestlt (hash) {
122+
let beginHash = String(tools.sha256(hash));
123+
const resultList = create(beginHash);
124+
return resultList.map((m) => m.card);
125+
}
126+
127+
function createCardFram(card) {
128+
const CARDS = " ,A,2,3,4,5,6,7,8,9,10,J,Q,K".split(",");
129+
const SUITS = ["♠", "♥", "♣", "♦"];
130+
let suitsIndex = (card & 240) / 16 - 10;
131+
let suits = SUITS[suitsIndex];
132+
let point = CARDS[card % 16];
133+
let pointNum = card % 16;
134+
let style = suitsIndex % 2 === 0 ? "black" : "red";
135+
let classNames = ["cardbox", style];
136+
return {
137+
style,
138+
suits,
139+
point,
140+
pointNum: pointNum > 10 ? 10 : pointNum
141+
};
142+
}
143+
144+
function encode(suit, point) {
145+
return ((suit + 10) << 4) + point;
146+
}
147+
148+
function BaccaratSingle () {
149+
const [state, setState, bind] = useInputControl({
150+
clientSeed: qs.c||'',
151+
serverSeed: qs.s||'',
152+
nonce: qs.n||''
153+
});
154+
155+
const result = useMemo(() => {
156+
const serverSeedHash = tools.sha256(state.serverSeed);
157+
const resultArr = [state.clientSeed, state.nonce];
158+
const hmacSha256Result = String(CryptoJS.HmacSHA256(resultArr.join(":"), state.serverSeed));
159+
const resultList = getRestlt(hmacSha256Result);
160+
const player = [createCardFram(resultList[0]), createCardFram(resultList[2])];
161+
const banker = [createCardFram(resultList[1]), createCardFram(resultList[3])];
162+
const palyerPoint = getPoint(player);
163+
const bankerPoint = getPoint(banker);
164+
const isPlayerGetCard = palyerPoint % 10 < 6;
165+
const isBankerEnd = bankerPoint % 10 >= 8;
166+
if(isPlayerGetCard && !isBankerEnd) {
167+
player.push(new Card(resultList[4]));
168+
}
169+
const thirdCardPoint = player[2] ? getPoint([player[2]]) % 10 : -1;
170+
const flag = canBankerGetCard(bankerPoint % 10, palyerPoint % 10, thirdCardPoint);
171+
if(flag) banker.push(isPlayerGetCard ? createCardFram(resultList[5]) : createCardFram(resultList[4]));
172+
const playerPointFinal = getPoint(player);
173+
const bankerPointFinal = getPoint(banker);
174+
return {
175+
player,
176+
banker,
177+
playerPointFinal,
178+
bankerPointFinal,
179+
hmacSha256Result,
180+
181+
}
182+
}, [state]);
183+
const {player, banker, playerPointFinal, bankerPointFinal} = result;
184+
return (
185+
<div className="main">
186+
<h1 className="text-center pb-5">Baccarat single verify</h1>
187+
<hr />
188+
<h2 class="text-center">Input</h2>
189+
<form className="py-5">
190+
<Input placeholder="Server Seed" {...bind('serverSeed')} />
191+
<Input placeholder="Client Seed (Hashed)" {...bind('clientSeed')} />
192+
<Input placeholder="Nonce" {...bind('nonce')} />
193+
</form>
194+
<h2 class="text-center">Output</h2>
195+
<form className="py-5">
196+
<Input placeholder="HmacSHA256(clientSeed, serverSeed)" readOnly value={result.hmacSha256Result} />
197+
<h5 style={{marginTop: 20}}>Result</h5>
198+
<div className="result-list">
199+
<div className="player-cards">
200+
<p>Player: {playerPointFinal % 10}</p>
201+
<div className="cards-list">
202+
{player.map((item, index) => {
203+
const clname = "result-card-item" + (index+1);
204+
return (
205+
<div className={clname + " card " + item.style} key={item.pointNum + "-" + index}>
206+
<div className="flower">{item.suits}</div>
207+
<div className="point">{item.point}</div>
208+
</div>
209+
)
210+
})}
211+
</div>
212+
</div>
213+
<div className="banker-cards">
214+
<p>Banker: {bankerPointFinal % 10}</p>
215+
<div className="cards-list">
216+
{banker.map((item, index) => {
217+
const clname = "result-card-item" + (index+1);
218+
return (
219+
<div className={clname + " card " + item.style} key={item.pointNum + "-" + index}>
220+
<div className="flower">{item.suits}</div>
221+
<div className="point">{item.point}</div>
222+
</div>
223+
)
224+
})}
225+
</div>
226+
</div>
227+
</div>
228+
</form>
229+
</div>
230+
);
231+
}
232+
ReactDOM.render(<BaccaratSingle />, document.getElementById("app"));
233+
</script>
234+
</body>
235+
</html>

0 commit comments

Comments
 (0)