Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h3>Dragons Bless Online Verifier</h3>	
<div id="container" class="container">	
	
	<div id="form" class="block">
		
		<div class="field">
			<label for="server_seed">Server seed</label>
			<input id="server_seed" type="text" class="form_text"/>
		</div>
		
		<div class="field">
			<label for="client_seed">Client seed</label>
			<input id="client_seed" type="text" class="form_text"/>
		</div>
		
		<div class="field">
			<label for="nonce">Nonce</label>
			<input id="nonce" type="text" class="form_text"/>
		</div>
		
		<div class="field">
			<label for="config">Config</label>
			<input id="config" type="text" class="form_text"/>					
		</div>
		
		<div class="field">
			<label for="configDescription">Config Description</label>
			<div id="configDescription" class="configDescription"></div>
		</div>
		
		<div class="field">
			<label for="hash">Server seed SHA512</label>
			<textarea id="hash" type="text" class="form_text" disabled></textarea>
		</div>
		
	</div>
	
	<div class="block">
		<label for="resultPanel">Result</label>
		<div id="resultPanel" class="resultPanel"></div>
	</div>	
	
</div>
              
            
!

CSS

              
                body {
	font-family: "Roboto Mono", monospace !important;
	min-width: 320px;
	box-sizing: border-box;
	padding: 10px;
	h3 {
		margin-left: 2.5px;
	}
	.container {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		box-sizing: border-box;
		.block {
			flex: 1;
			min-width: 250px;
			margin: 0 2.5px;
			box-sizing: border-box;
			label {
				font-weight: bold;
				font-size: 20px;
				box-sizing: border-box;
			}
			.field {
				display: flex;
				flex-direction: column;
				box-sizing: border-box;
				margin-bottom: 5px;
				textarea,
				input {
					outline: none;
					font-size: 13px;
					padding: 5px;
					width: 100%;
					border-radius: 5px;
					border: 1px solid #888888;
					box-sizing: border-box;
					background-color: #ffffe1;
				}
				textarea {
					resize: none;
					height: 80px;
				}
				.configDescription {
					display: inline-block;
					font-size: 15px;
				}
			}
		}
	}
}


img {
	height: 32px;
	margin-right: 2px;
}
.img {
	height: 32px;
	margin-bottom: 2px;
}
.red{ color:#ff0000; }
.green{ color:#008800; }
              
            
!

JS

              
                const params = {
	server_seed:"",
	client_seed:"",
	nonce:"",
	config:""
};

const modes = [
	{ win: 3, lose: 1, name:"Very easy" },
	{ win: 2, lose: 1, name:"Easy" },
	{ win: 1, lose: 1, name:"Normal" },
	{ win: 1, lose: 2, name:"Hard" },
	{ win: 1, lose: 3, name:"Very hard" }
];

const roll = (serverSeed, clientSeed, nonce, step) => {
	const keyString = clientSeed + "-" + nonce + "-" + step;
	const hash = sha512.hmac(serverSeed, keyString);	
	const random = parseInt(hash.substring(0, 5), 16) / 1048576;
	//between min - max values	
	const mode = modes[params.config];	
	const max = mode.win + mode.lose;	
	return Math.floor(random * max);	
};

function showRandomResult(random){		
	let icons = [
		"<img src='https://res.cloudinary.com/dez0s9s32/image/upload/v1570365610/pandora/games/dragonsBless/btnLose.png' />",
		"<img src='https://res.cloudinary.com/dez0s9s32/image/upload/v1570365610/pandora/games/dragonsBless/btnGold.png'/>"
	];
	const mode = modes[params.config];
	let count = mode.win + mode.lose;
	let html = "";	
	if(mode.lose > mode.win) icons.reverse();
	for(let i = random.length - 1; i >= 0; i--){		
		html += "<div class='img'>";
		for(let k = 0; k < count; k++)			
				html += k === random[i] ? icons[0] : icons[1];			
		html += "</div>";
	}
	let config_text = $("#config").val();
	let description = 'Mode name: <b>' + mode.name + '</b>';
	if(config_text !== "") $("#config").val(params.config);
	else {
		html = "";
		description = "";
	}
	$("#resultPanel").html(html);
	
	$("#configDescription").html(description);	
}

const calculateResult = () => {	
	for(let k in params) params[k] = $("#" + k).val().trim();
	$("#hash").val(sha512(params.server_seed));
	
	//check parameters
	params.config = Math.max(Math.min(TryParseInt(params.config, 0), 4), 0);
	
	//let random = roll(params.server_seed, params.client_seed, params.nonce);
	let random = [];
	for(let i = 0; i < 10; i++)	random.push(roll(params.server_seed, params.client_seed, params.nonce, i));
	showRandomResult(random);
}

window.onload = function(){
	try{
		let url_string = (window.location.href);
		let url = new URL(url_string);		
		for(let k in params) {
			let value = url.searchParams.get(k);
			if(value){
				value = atob(value).trim();
				params[k] = value;
				$("#" + k).val(value);
			}
		}
		calculateResult();
	}
	catch{}
}

$('#form').keyup(()=>calculateResult());

const TryParseInt = (str, defaultValue) => {
     var retValue = defaultValue;
     if(str !== null && str.length > 0 && !isNaN(str)) retValue = parseInt(str);
     return retValue;
}




              
            
!
999px

Console