Skip to content

Commit 0716609

Browse files
author
mydicebot
committed
version 190122
1 parent 7fa6541 commit 0716609

File tree

11 files changed

+366
-18
lines changed

11 files changed

+366
-18
lines changed

src/api/models/bitsler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ export class BitslerDice extends BaseDice {
9393
let currency = req.body.Currency.toLowerCase();
9494
let game = 0;
9595
if(req.body.High == 1){
96-
game = 999999-Math.floor((req.body.Chance*10000));
96+
game = 999999-Math.floor((req.body.Chance*10000))+1;
9797
} else {
98-
game = Math.floor((req.body.Chance*10000));
98+
game = Math.floor((req.body.Chance*10000))-1;
9999
}
100100
console.log(game);
101101
formData.append('access_token', accessToken);

src/api/models/crypto.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ export class CryptoDice extends BaseDice {
7979
let currency = req.body.Currency.toLowerCase();
8080
let target = 0;
8181
if(req.body.High == 1){
82-
target = 999999-Math.floor((req.body.Chance*10000));
82+
target = 999999-Math.floor((req.body.Chance*10000))+1;
8383
} else {
84-
target = Math.floor((req.body.Chance*10000));
84+
target = Math.floor((req.body.Chance*10000))-1;
8585
}
8686
target = target/10000;
8787
let underOver = condition + ' ' + target;

src/api/models/nine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ export class NineDice extends BaseDice {
7272
formData.append('ProtocolVersion', 2);
7373
let betRoll = 0;
7474
if(req.body.High == 1){
75-
betRoll = 999999-Math.floor((req.body.Chance*10000));
75+
betRoll = 999999-Math.floor((req.body.Chance*10000))+1;
7676
formData.append('Low', betRoll);
7777
formData.append('High', 999999);
7878
} else {
79-
betRoll = Math.floor((req.body.Chance*10000));
79+
betRoll = Math.floor((req.body.Chance*10000))-1;
8080
formData.append('Low', 0);
8181
formData.append('High', betRoll);
8282
}

src/api/models/prime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ export class PrimeDice extends BaseDice {
113113
let currency = req.body.Currency.toLowerCase();
114114
let target = 0;
115115
if(req.body.High == 1){
116-
target = 999999-Math.floor((req.body.Chance*10000));
116+
target = 999999-Math.floor((req.body.Chance*10000))+1;
117117
} else {
118-
target = Math.floor((req.body.Chance*10000));
118+
target = Math.floor((req.body.Chance*10000))-1;
119119
}
120120
target = parseFloat(target/10000).toFixed(2);
121121
let data = " mutation{primediceRoll(amount:"+amount+",target:"+target+",condition:"+ condition +",currency:"+currency+ ") { id iid nonce currency amount payout state { ... on BetGamePrimedice { result target condition } } createdAt serverSeed{seedHash seed nonce} clientSeed{seed} user{balances{available{amount currency}} statistic{game bets wins losses amount profit currency}}}}";

src/api/models/simulator.js

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
'use strict';
2+
3+
import {BaseDice} from './base'
4+
import FormData from 'form-data';
5+
import {APIError} from '../errors/APIError';
6+
import request from 'request';
7+
import fetch from 'isomorphic-fetch';
8+
import crypto from 'crypto';
9+
10+
export class Simulator extends BaseDice {
11+
constructor(){
12+
super();
13+
this.url = 'https://magic-dice.com';
14+
this.benefit = '?ref=mydicebot'
15+
this.currencys = ["btc","eth","ltc","doge","dash","bch","xrp","zec","etc","neo","kmd","btg","lsk","dgb","qtum","strat","waves","burst"];
16+
}
17+
18+
async login(userName, password, twoFactor ,apiKey, req) {
19+
req.session.username = 'Simulator';
20+
return true;
21+
}
22+
23+
async getUserInfo(req) {
24+
let info = req.session.info;
25+
if(typeof info != 'undefined'){
26+
return true;
27+
}
28+
let userName = req.session.username;
29+
let userinfo = {
30+
'bets' : 0,
31+
'wins' : 0,
32+
'losses' : 0,
33+
'profit' : 0,
34+
'wagered' : 0,
35+
'balance' : 1000000,
36+
};
37+
info = {};
38+
let currentInfo = userinfo;
39+
info.info = userinfo;
40+
req.session.info = info;
41+
return info;
42+
}
43+
44+
async refresh(req) {
45+
let info = req.session.info;
46+
if(!info){
47+
return false;
48+
}
49+
return info;
50+
}
51+
52+
async clear(req) {
53+
let userName = req.session.username;
54+
let info = {};
55+
info.info = {
56+
'bets' : 0,
57+
'wins' : 0,
58+
'losses' : 0,
59+
'profit' : 0,
60+
'wagered' : 0,
61+
'balance' : 1000000,
62+
};
63+
info.currentInfo = {
64+
'bets' : 0,
65+
'wins' : 0,
66+
'losses' : 0,
67+
'profit' : 0,
68+
'wagered' : 0,
69+
'balance' : 1000000,
70+
}
71+
info.info.success = 'true';
72+
req.session.info = info;
73+
return info;
74+
}
75+
76+
async bet(req) {
77+
let info = req.session.info;
78+
let amount = (req.body.PayIn/100000000).toFixed(8);
79+
let condition = req.body.High == 1?'over':'under';
80+
let currency = req.body.Currency.toLowerCase();
81+
let houseEdge = req.body.HouseEdge;
82+
let target = 0;
83+
if(req.body.High == 1){
84+
target = 999999-Math.floor(req.body.Chance*10000)+1;
85+
} else {
86+
target = Math.floor(req.body.Chance*10000)-1;
87+
}
88+
let betInfo = await this._simulatorBet(amount, target, condition, houseEdge);
89+
betInfo.condition = req.body.High == 1?'>':'<';
90+
betInfo.target = target/10000;
91+
info.info.balance = (parseFloat(info.info.balance) + parseFloat(betInfo.profit)).toFixed(8);
92+
info.currentInfo.balance = (parseFloat(info.currentInfo.balance) + parseFloat(betInfo.profit)).toFixed(8);
93+
info.info.bets++;
94+
info.currentInfo.bets++;
95+
info.info.profit = (parseFloat(info.info.profit) + parseFloat(betInfo.profit)).toFixed(8);
96+
info.info.wagered = (parseFloat(info.info.wagered) + parseFloat(amount)).toFixed(8);
97+
info.currentInfo.wagered = (parseFloat(info.currentInfo.wagered) + parseFloat(amount)).toFixed(8);
98+
info.currentInfo.profit = (parseFloat(info.currentInfo.profit) + parseFloat(betInfo.profit)).toFixed(8);
99+
if(betInfo.win){
100+
info.info.wins++;
101+
info.currentInfo.wins++;
102+
} else {
103+
info.info.losses++;
104+
info.currentInfo.losses++; } let returnInfo = {};
105+
returnInfo.betInfo= betInfo;
106+
returnInfo.info = info;
107+
req.session.info = info;
108+
return returnInfo; }
109+
110+
async _simulatorBet(amount, target, condition, houseEdge ) {
111+
let betInfo = {};
112+
betInfo.id = 'MyDiceBot_'+Math.random().toString(16).substring(2).substr(0,10);
113+
betInfo.amount = parseFloat(amount);
114+
let serverSeed = Math.random().toString(36).substring(2);
115+
let clientSeed = Math.random().toString(36).substring(2);
116+
let cryptoHmac = crypto.createHmac('sha256', serverSeed);
117+
let resultSeed = cryptoHmac.update(`${clientSeed}`).digest('hex');
118+
let resultNumber = parseInt(resultSeed.substr(0, 10), 16);
119+
let diceRoll = (resultNumber % 1000000)+1;
120+
let factor = 1000000/(target+1);
121+
if(condition == 'over') {
122+
factor = 1000000/(999999-target+1);
123+
}
124+
let profit = (amount * factor) * (1 - houseEdge) - amount;
125+
console.log(amount,factor,betInfo.amount, houseEdge);
126+
betInfo.roll_number = diceRoll/10000;
127+
betInfo.win = false;
128+
if(condition == 'over') {
129+
if(target<diceRoll) {
130+
betInfo.win = true;
131+
}
132+
} else {
133+
if(target>diceRoll){
134+
betInfo.win = true;
135+
}
136+
}
137+
if(betInfo.win) {
138+
betInfo.payout = parseFloat((betInfo.amount+profit)).toFixed(8);
139+
betInfo.profit = parseFloat(profit).toFixed(8);
140+
} else {
141+
betInfo.payout = 0;
142+
betInfo.profit = parseFloat(-betInfo.amount).toFixed(8);
143+
}
144+
console.log(betInfo);
145+
return betInfo;
146+
}
147+
}

src/api/models/stake.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ export class StakeDice extends BaseDice {
113113
let currency = req.body.Currency.toLowerCase();
114114
let target = 0;
115115
if(req.body.High == 1){
116-
target = 999999-Math.floor((req.body.Chance*10000));
116+
target = 999999-Math.floor((req.body.Chance*10000))+1;
117117
} else {
118-
target = Math.floor((req.body.Chance*10000));
118+
target = Math.floor((req.body.Chance*10000))-1;
119119
}
120120
target = parseFloat(target/10000).toFixed(2);
121121
let data = " mutation{diceRoll(amount:"+amount+",target:"+target+",condition:"+ condition +",currency:"+currency+ ") { id iid nonce currency amount payout state { ... on BetGameDice { result target condition } } createdAt serverSeed{seedHash seed nonce} clientSeed{seed} user{balances{available{amount currency}} statistic{game bets wins losses amount profit currency}}}}";

src/api/models/yolo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ export class YoloDice extends BaseDice {
114114
let range = 'lo';
115115
if(req.body.High == 1){
116116
range = 'hi';
117-
betRoll = 999999-Math.floor((req.body.Chance*10000));
117+
betRoll = 999999-Math.floor((req.body.Chance*10000))+1;
118118
} else {
119119
range = 'lo';
120-
betRoll = Math.floor((req.body.Chance*10000));
120+
betRoll = Math.floor((req.body.Chance*10000))-1;
121121
}
122122
let options = {
123123
id:this.id++,

src/api/routes/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {PrimeDice} from '../models/prime';
88
import {StakeDice} from '../models/stake';
99
import {CryptoDice} from '../models/crypto';
1010
import {MagicDice} from '../models/magic';
11+
import {Simulator} from '../models/simulator';
1112
import {Factory} from '../models/factory';
1213
import fs from 'fs';
1314
import path from 'path';
@@ -37,6 +38,7 @@ function createDice (req, res, next) {
3738
Factory.register('Stake', new StakeDice());
3839
Factory.register('Crypto-Games', new CryptoDice());
3940
Factory.register('MagicDice', new MagicDice());
41+
Factory.register('Simulator', new Simulator());
4042
next();
4143
}
4244

src/public/js/Simulator/info.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
function init() {
2+
console.log('hello Simulator');
3+
$$("bet_currency_selection").define("options", [
4+
{id:1,value:"BTC"},
5+
]);
6+
minBetAmount = 0.1;
7+
$$("manual_bet_amount").setValue(minBetAmount);
8+
$$("auto_bet_base_amount").setValue(minBetAmount);
9+
$$("manual_bet_chance").setValue(49.5);
10+
$$("auto_bet_base_chance").setValue(49.5);
11+
$$("bet_currency_selection").refresh();
12+
$$("bet_house_edge_selection").show();
13+
}
14+
15+
function checkParams(p,ch){
16+
//console.log(p,ch);
17+
if(p < 0.00000001 || p > 1000000000*1000000000) {
18+
return false
19+
}
20+
if(ch>99 || ch<0.0001) {
21+
return false
22+
}
23+
return true;
24+
}
25+
26+
function initScriptBalance(currencyValue, cb){
27+
getInfo(function(userinfo){
28+
if(userinfo.info.success == 'true'){
29+
try {
30+
fengari.load('balance='+userinfo.info.balance)();
31+
fengari.load('bets='+userinfo.info.bets)();
32+
fengari.load('wins='+userinfo.info.wins)();
33+
fengari.load('losses='+userinfo.info.losses)();
34+
fengari.load('profit='+userinfo.info.profit)();
35+
} catch(err){
36+
console.error(err.message);
37+
webix.message({type: 'error', text: err.message});
38+
return false;
39+
}
40+
cb();
41+
}
42+
});
43+
}
44+
45+
function getBalance(userinfo){
46+
let balance = userinfo.info.balance
47+
return balance;
48+
}
49+
50+
function getActProfit(userinfo){
51+
let actProfit = userinfo.currentInfo.profit * 100000000;
52+
//console.log('actprofit:'+actProfit);
53+
return actProfit;
54+
}
55+
56+
function getCurrProfit(ret){
57+
let currProfit = ret.betInfo.profit
58+
//console.log('currprofit:'+currProfit);
59+
return currProfit;
60+
}
61+
62+
function getCurrentBetId(ret){
63+
let betId = ret.betInfo.id;
64+
//console.log('currentBetId:'+betId);
65+
return betId;
66+
}
67+
68+
function getCurrentRoll(ret){
69+
let roll = ret.betInfo.roll_number;
70+
//console.log('currentRoll:'+roll);
71+
return roll;
72+
}
73+
74+
async function outError(ret){
75+
let mess = ret.err;
76+
return await retryError(mess);
77+
}
78+
79+
function isError(ret){
80+
if(typeof ret.err != "undefined")
81+
return false;
82+
else
83+
return true;
84+
}
85+
86+
function getWinStatus(ret){
87+
return ret.betInfo.win;
88+
}
89+
90+
function setDatatable(ret){
91+
let chanceStr = '<font size="3" color="red">'+ ret.betInfo.condition + ' '+ ret.betInfo.target +'</font>';
92+
if(ret.betInfo.win){
93+
chanceStr = '<font size="3" color="green">'+ ret.betInfo.condition + ' '+ ret.betInfo.target +'</font>';
94+
}
95+
let profitStr = '<font size="3" color="red">' + ret.betInfo.profit+ '</font>';
96+
if(ret.betInfo.profit>0) {
97+
profitStr = '<font size="3" color="green">' + ret.betInfo.profit + '</font>';
98+
}
99+
$$('bet_datatable').add({
100+
bet_datatable_id:ret.betInfo.id,
101+
bet_datatable_amount:ret.betInfo.amount,
102+
bet_datatable_low_high:ret.betInfo.condition,
103+
bet_datatable_payout:ret.betInfo.payout,
104+
bet_datatable_bet_chance:chanceStr,
105+
bet_datatable_actual_chance:ret.betInfo.roll_number,
106+
bet_datatable_profit:profitStr,
107+
},0);
108+
}
109+
110+
function setStats(userinfo, cv){
111+
if(userinfo.info.success == 'true'){
112+
$$('bet_total_stats').setValues({
113+
bet_total_stats_balance:userinfo.info.balance,
114+
bet_total_stats_win:userinfo.info.wins,
115+
bet_total_stats_loss:userinfo.info.losses,
116+
bet_total_stats_bet:userinfo.info.bets,
117+
bet_total_stats_profit:userinfo.info.profit,
118+
bet_total_stats_wagered:userinfo.info.wagered,
119+
});
120+
$$('bet_current_stats').setValues({
121+
bet_current_stats_balance:userinfo.currentInfo.balance,
122+
bet_current_stats_win:userinfo.currentInfo.wins,
123+
bet_current_stats_loss:userinfo.currentInfo.losses,
124+
bet_current_stats_bet:userinfo.currentInfo.bets,
125+
bet_current_stats_profit:userinfo.currentInfo.profit,
126+
bet_current_stats_wagered:userinfo.currentInfo.wagered,
127+
});
128+
}
129+
}

0 commit comments

Comments
 (0)