|
|
@ -14,15 +14,18 @@ |
|
|
|
******************************************************************************/ |
|
|
|
|
|
|
|
#include "gamescc.h" |
|
|
|
#include "tetris.c" // replace with game code |
|
|
|
|
|
|
|
#include "tetris.h" |
|
|
|
#ifndef STANDALONE |
|
|
|
int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector<uint8_t> payload); |
|
|
|
int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector<uint8_t> playerdata,uint256 gametxid,CPubKey pk); |
|
|
|
int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis); |
|
|
|
void games_packitemstr(char *packitemstr,struct games_packitem *item); |
|
|
|
int64_t games_cashout(struct games_player *P); |
|
|
|
char *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vector<uint8_t> &newdata,uint64_t &seed,uint256 &playertxid,struct CCcontract_info *cp,uint256 gametxid,char *gamesaddr); |
|
|
|
|
|
|
|
static int random_tetromino(void) |
|
|
|
{ |
|
|
|
return rand() % NUM_TETROMINOS; |
|
|
|
} |
|
|
|
#include "tetris.cpp" // replace with game specific functions |
|
|
|
|
|
|
|
#ifndef STANDALONE |
|
|
|
/*
|
|
|
|
./c cclib rng 17 \"[%229433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775%22,250]\" |
|
|
|
{ |
|
|
@ -55,12 +58,6 @@ static int random_tetromino(void) |
|
|
|
./c cclib events 17 \"[%226d%22,%229433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775%22,1]\" |
|
|
|
*/ |
|
|
|
|
|
|
|
int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector<uint8_t> payload); |
|
|
|
int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector<uint8_t> playerdata,uint256 gametxid,CPubKey pk); |
|
|
|
int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis); |
|
|
|
void games_packitemstr(char *packitemstr,struct games_packitem *item); |
|
|
|
int64_t games_cashout(struct games_player *P); |
|
|
|
|
|
|
|
|
|
|
|
CScript games_newgameopret(int64_t buyin,int32_t maxplayers) |
|
|
|
{ |
|
|
@ -1193,91 +1190,6 @@ UniValue games_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param |
|
|
|
} else return(cclib_error(result,"couldnt reparse params")); |
|
|
|
} |
|
|
|
|
|
|
|
char *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vector<uint8_t> &newdata,uint64_t &seed,uint256 &playertxid,struct CCcontract_info *cp,uint256 gametxid,char *gamesaddr) |
|
|
|
{ |
|
|
|
CPubKey gamespk; int32_t i,num,retval,maxplayers,gameheight,batonht,batonvout,numplayers,regslot,numkeys,err; std::string symbol,pname; CTransaction gametx; int64_t buyin,batonvalue; char fname[64],*keystrokes = 0; std::vector<uint8_t> playerdata; uint256 batontxid; FILE *fp; uint8_t newplayer[10000]; struct games_player P,endP; |
|
|
|
gamespk = GetUnspendable(cp,0); |
|
|
|
*numkeysp = 0; |
|
|
|
seed = 0; |
|
|
|
num = numkeys = 0; |
|
|
|
playertxid = zeroid; |
|
|
|
str[0] = 0; |
|
|
|
if ( (err= games_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0)) == 0 ) |
|
|
|
{ |
|
|
|
if ( (retval= games_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,gamesaddr,numplayers,symbol,pname)) == 0 ) |
|
|
|
{ |
|
|
|
UniValue obj; |
|
|
|
seed = games_gamefields(obj,maxplayers,buyin,gametxid,gamesaddr); |
|
|
|
//fprintf(stderr,"(%s) found baton %s numkeys.%d seed.%llu playerdata.%d playertxid.%s\n",pname.size()!=0?pname.c_str():Games_pname.c_str(),batontxid.ToString().c_str(),numkeys,(long long)seed,(int32_t)playerdata.size(),playertxid.GetHex().c_str());
|
|
|
|
memset(&P,0,sizeof(P)); |
|
|
|
if ( playerdata.size() > 0 ) |
|
|
|
{ |
|
|
|
for (i=0; i<playerdata.size(); i++) |
|
|
|
((uint8_t *)&P)[i] = playerdata[i]; |
|
|
|
} |
|
|
|
if ( keystrokes != 0 && numkeys != 0 ) |
|
|
|
{ |
|
|
|
if ( makefiles != 0 ) |
|
|
|
{ |
|
|
|
sprintf(fname,"%s.%llu.0",GAMENAME,(long long)seed); |
|
|
|
if ( (fp= fopen(fname,"wb")) != 0 ) |
|
|
|
{ |
|
|
|
if ( fwrite(keystrokes,1,numkeys,fp) != numkeys ) |
|
|
|
fprintf(stderr,"error writing %s\n",fname); |
|
|
|
fclose(fp); |
|
|
|
} |
|
|
|
sprintf(fname,"%s.%llu.player",GAMENAME,(long long)seed); |
|
|
|
if ( (fp= fopen(fname,"wb")) != 0 ) |
|
|
|
{ |
|
|
|
if ( fwrite(&playerdata[0],1,(int32_t)playerdata.size(),fp) != playerdata.size() ) |
|
|
|
fprintf(stderr,"error writing %s\n",fname); |
|
|
|
fclose(fp); |
|
|
|
} |
|
|
|
} |
|
|
|
//fprintf(stderr,"call replay2\n");
|
|
|
|
num = games_replay2(newplayer,seed,keystrokes,numkeys,playerdata.size()==0?0:&P,0); |
|
|
|
newdata.resize(num); |
|
|
|
for (i=0; i<num; i++) |
|
|
|
{ |
|
|
|
newdata[i] = newplayer[i]; |
|
|
|
((uint8_t *)&endP)[i] = newplayer[i]; |
|
|
|
} |
|
|
|
//fprintf(stderr,"back replay2 gold.%d\n",endP.gold);
|
|
|
|
if ( endP.gold <= 0 || endP.hitpoints <= 0 || (endP.strength&0xffff) <= 0 || endP.level <= 0 || endP.experience <= 0 || endP.dungeonlevel <= 0 ) |
|
|
|
{ |
|
|
|
sprintf(str,"zero value character was killed -> no playerdata\n"); |
|
|
|
newdata.resize(0); |
|
|
|
*numkeysp = numkeys; |
|
|
|
return(keystrokes); |
|
|
|
/* P.gold = (P.gold * 8) / 10;
|
|
|
|
if ( keystrokes != 0 ) |
|
|
|
{ |
|
|
|
free(keystrokes); |
|
|
|
keystrokes = 0; |
|
|
|
*numkeysp = 0; |
|
|
|
return(keystrokes); |
|
|
|
}*/ |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
sprintf(str,"$$$gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d",endP.gold,endP.hitpoints,endP.strength&0xffff,endP.strength>>16,endP.level,endP.experience,endP.dungeonlevel); |
|
|
|
//fprintf(stderr,"%s\n",str);
|
|
|
|
*numkeysp = numkeys; |
|
|
|
return(keystrokes); |
|
|
|
} |
|
|
|
} else num = 0; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
fprintf(stderr,"extractgame: couldnt find baton keystrokes.%p retval.%d\n",keystrokes,retval); |
|
|
|
if ( keystrokes != 0 ) |
|
|
|
free(keystrokes), keystrokes = 0; |
|
|
|
} |
|
|
|
} else fprintf(stderr,"extractgame: invalid game\n"); |
|
|
|
//fprintf(stderr,"extract %s\n",gametxid.GetHex().c_str());
|
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
UniValue games_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|
|
|
{ |
|
|
|
UniValue result(UniValue::VOBJ); CPubKey pk,gamespk; int32_t i,n,numkeys,flag = 0; uint64_t seed; char str[512],gamesaddr[64],*pubstr,*hexstr,*keystrokes = 0; std::vector<uint8_t> newdata; uint256 gametxid,playertxid; FILE *fp; uint8_t pub33[33]; |
|
|
@ -1556,11 +1468,5 @@ UniValue games_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|
|
|
return(result); |
|
|
|
} |
|
|
|
|
|
|
|
#include "tetris.cpp" |
|
|
|
|
|
|
|
#else // STANDALONE
|
|
|
|
|
|
|
|
#include "tetris.c" |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|