This commit is contained in:
jl777
2019-03-22 01:53:15 -11:00
parent e74277a934
commit 21684cfa77
2 changed files with 30 additions and 11 deletions

View File

@@ -34,7 +34,7 @@ UniValue games_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastf
return(result);
}
uint64_t games_rngnext(uint64_t initseed)
uint64_t _games_rngnext(uint64_t initseed)
{
uint16_t seeds[4]; int32_t i;
seeds[0] = initseed;
@@ -48,6 +48,25 @@ uint64_t games_rngnext(uint64_t initseed)
return(((uint64_t)seeds[3] << 48) | ((uint64_t)seeds[2] << 24) | ((uint64_t)seeds[1] << 16) | seeds[0]);
}
UniValue games_rngnext(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
{
UniValue result(UniValue::VOBJ); int32_t n; uint64_t seed;
if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 )
{
seed = jdouble(jitem(params,0),0);
result.push_back(Pair("seed",seed));
seed = games_rngnext(seed);
result.push_back(Pair("rng",seed));
result.push_back(Pair("result","success"));
}
else
{
result.push_back(Pair("result","error"));
result.push_back(Pair("error","not enough params"));
}
return(result);
}
UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
{
UniValue result(UniValue::VOBJ); int32_t i,n,playerid=0; uint64_t seed,initseed; bits256 hash;
@@ -75,13 +94,13 @@ UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
}
}
initseed = seed;
seed = games_rngnext(initseed);
seed = _games_rngnext(initseed);
result.push_back(Pair("playerid",(int64_t)(playerid - 1)));
result.push_back(Pair("initseed",initseed));
result.push_back(Pair("seed",seed));
result.push_back(Pair("seed",initseed));
result.push_back(Pair("rng",seed));
for (i=0; i<GAMES_MAXRNGS; i++)
seed = games_rngnext(seed);
result.push_back(Pair("lastseed",seed));
seed = _games_rngnext(seed);
result.push_back(Pair("lastrng",seed));
result.push_back(Pair("maxrngs",GAMES_MAXRNGS));
result.push_back(Pair("result","success"));
}

View File

@@ -11,20 +11,20 @@ std::string MYCCLIBNAME = (char *)"gamescc";
#define MYCCNAME "games"
#define RPC_FUNCS \
{ (char *)MYCCNAME, (char *)"rng", (char *)"hash,seed,playerid", 2, 3, '0', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"func1", (char *)"<no args>", 0, 0, '1', EVAL_GAMES },
{ (char *)MYCCNAME, (char *)"rng", (char *)"hash,seed,playerid", 2, 3, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"rngnext", (char *)"seed", 1, 1, ' ', EVAL_GAMES },
bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx);
UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_rngnext(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
#define CUSTOM_DISPATCH \
if ( cp->evalcode == EVAL_GAMES ) \
{ \
if ( strcmp(method,"rng") == 0 ) \
return(games_rng(txfee,cp,params)); \
else if ( strcmp(method,"func1") == 0 ) \
return(games_func1(txfee,cp,params)); \
else if ( strcmp(method,"rngnext") == 0 ) \
return(games_rngnext(txfee,cp,params)); \
else \
{ \
result.push_back(Pair("result","error")); \