From 6f6a9d28b20e188024e2a9d3a01353c055fc3d54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Mar 2019 01:18:03 -1100 Subject: [PATCH] Initseed --- src/cc/gamescc.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 25088d7fc..a079df2cf 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -36,7 +36,7 @@ UniValue games_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastf UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - UniValue result(UniValue::VOBJ); int32_t i,invertflag=0,n,playerid=0; uint16_t seeds[4]; uint64_t seed; bits256 hash; + UniValue result(UniValue::VOBJ); int32_t i,invertflag=0,n,playerid=0; uint16_t seeds[4]; uint64_t seed,initseed; bits256 hash; if ( params != 0 && ((n= cJSON_GetArraySize(params)) == 2 || n == 3) ) { hash = jbits256(jitem(params,0),0); @@ -60,21 +60,22 @@ UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) playerid--; } for (i=0; i<8; i++) + { if ( ((1 << i) & playerid) != 0 ) seed ^= hash.uints[i]; - } - else - { - for (i=0; i<4; i++) - { - seeds[i] = (seed >> (i*16)); - seeds[i] = (seeds[i]*11109 + 13849); + if ( invertflag != 0 ) + seed ^= (uint64_t)-1; } - seed = ((uint64_t)seeds[3] << 48) | ((uint64_t)seeds[2] << 24) | ((uint64_t)seeds[1] << 16) | seeds[0]; - if ( invertflag != 0 ) - seed ^= -1; } + initseed = seed; + for (i=0; i<4; i++) + { + seeds[i] = (seed >> (i*16)); + seeds[i] = (seeds[i]*11109 + 13849); + } + seed = ((uint64_t)seeds[3] << 48) | ((uint64_t)seeds[2] << 24) | ((uint64_t)seeds[1] << 16) | seeds[0]; result.push_back(Pair("playerid",(int64_t)(playerid - 1 + invertflag))); + result.push_back(Pair("initseed",initseed)); result.push_back(Pair("seed",seed)); result.push_back(Pair("result","success")); }