Merge branch 'jl777' into add-nf-token-opret

This commit is contained in:
jl777
2019-02-10 04:25:29 -11:00
committed by GitHub
6 changed files with 106 additions and 56 deletions

View File

@@ -157,7 +157,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
{ {
Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey);
//fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s)\n",i,(double)utxovalues[i]/COIN,destaddr); //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s)\n",i,(double)utxovalues[i]/COIN,destaddr);
std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " for vin[" << i << "] satoshis=" << utxovalues[i] << std::endl; //std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " for vin[" << i << "] satoshis=" << utxovalues[i] << std::endl;
if( strcmp(destaddr, myaddr) == 0 ) if( strcmp(destaddr, myaddr) == 0 )
{ {
fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr); fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr);

View File

@@ -38,6 +38,8 @@ command(struct rogue_state *rs)
do_fuses(rs,BEFORE); do_fuses(rs,BEFORE);
while (ntimes--) while (ntimes--)
{ {
if ( rs->replaydone != 0 )
return;
again = FALSE; again = FALSE;
if (has_hit) if (has_hit)
{ {
@@ -117,6 +119,8 @@ command(struct rogue_state *rs)
* turn off count for commands which don't make sense * turn off count for commands which don't make sense
* to repeat * to repeat
*/ */
if ( rs->guiflag == 0 && rs->replaydone != 0 )
ch = 'Q';
switch (ch) switch (ch)
{ {
case CTRL('B'): case CTRL('H'): case CTRL('J'): case CTRL('B'): case CTRL('H'): case CTRL('J'):
@@ -263,9 +267,10 @@ over:
after = FALSE; after = FALSE;
q_comm = TRUE; q_comm = TRUE;
quit(0); quit(0);
if ( rs->needflush == 0 ) if ( rs->guiflag != 0 && rs->needflush == 0 )
rs->needflush = (uint32_t)time(NULL); rs->needflush = (uint32_t)time(NULL);
q_comm = FALSE; q_comm = FALSE;
return;
when 'i': after = FALSE; inventory(rs,pack, 0); when 'i': after = FALSE; inventory(rs,pack, 0);
when 'I': after = FALSE; picky_inven(rs); when 'I': after = FALSE; picky_inven(rs);
when 'd': drop(rs); when 'd': drop(rs);
@@ -280,11 +285,11 @@ over:
when 'c': call(rs); after = FALSE; when 'c': call(rs); after = FALSE;
when '>': after = FALSE; d_level(rs); when '>': after = FALSE; d_level(rs);
if ( rs->needflush == 0 ) if ( rs->guiflag != 0 && rs->needflush == 0 )
rs->needflush = (uint32_t)time(NULL); rs->needflush = (uint32_t)time(NULL);
when '<': after = FALSE; u_level(rs); when '<': after = FALSE; u_level(rs);
if ( rs->needflush == 0 ) if ( rs->guiflag != 0 && rs->needflush == 0 )
rs->needflush = (uint32_t)time(NULL); rs->needflush = (uint32_t)time(NULL);
when '?': after = FALSE; help(rs); when '?': after = FALSE; help(rs);
@@ -446,23 +451,23 @@ over:
/* /*
* If he ran into something to take, let him pick it up. * If he ran into something to take, let him pick it up.
*/ */
if (take != 0) if (take != 0)
pick_up(rs,take); pick_up(rs,take);
if (!running) if (!running)
door_stop = FALSE; door_stop = FALSE;
if (!after) if (!after)
ntimes++; ntimes++;
} }
do_daemons(rs,AFTER); do_daemons(rs,AFTER);
do_fuses(rs,AFTER); do_fuses(rs,AFTER);
if (ISRING(LEFT, R_SEARCH)) if (ISRING(LEFT, R_SEARCH))
search(rs); search(rs);
else if (ISRING(LEFT, R_TELEPORT) && rnd(50) == 0) else if (ISRING(LEFT, R_TELEPORT) && rnd(50) == 0)
teleport(rs); teleport(rs);
if (ISRING(RIGHT, R_SEARCH)) if (ISRING(RIGHT, R_SEARCH))
search(rs); search(rs);
else if (ISRING(RIGHT, R_TELEPORT) && rnd(50) == 0) else if (ISRING(RIGHT, R_TELEPORT) && rnd(50) == 0)
teleport(rs); teleport(rs);
} }
/* /*

View File

@@ -157,12 +157,16 @@ readchar(struct rogue_state *rs)
{ {
if ( rs->ind < rs->numkeys ) if ( rs->ind < rs->numkeys )
{ {
if ( rs->ind == rs->numkeys-1 ) //if ( rs->ind == rs->numkeys-1 )
rs->replaydone = (uint32_t)time(NULL); // rs->replaydone = (uint32_t)time(NULL);
//fprintf(stderr,"(%c) ",rs->keystrokes[rs->ind]);
return(rs->keystrokes[rs->ind++]); return(rs->keystrokes[rs->ind++]);
} }
fatal("replay finished but readchar called\n"); fprintf(stderr,"replay finished but readchar called\n");
return(' '); rs->replaydone = (uint32_t)time(NULL);
if ( (rand() & 1) == 0 )
return(ESCAPE);
else return('y');
} }
if ( rs == 0 || rs->guiflag != 0 ) if ( rs == 0 || rs->guiflag != 0 )
{ {
@@ -277,10 +281,18 @@ wait_for(struct rogue_state *rs,int ch)
if (ch == '\n') if (ch == '\n')
while ((c = readchar(rs)) != '\n' && c != '\r') while ((c = readchar(rs)) != '\n' && c != '\r')
continue; {
if ( rs->replaydone != 0 )
return;
continue;
}
else else
while (readchar(rs) != ch) while (readchar(rs) != ch)
continue; {
if ( rs->replaydone != 0 )
return;
continue;
}
} }
/* /*

View File

@@ -146,9 +146,9 @@ int32_t flushkeystrokes(struct rogue_state *rs)
uint8_t *OS_fileptr(long *allocsizep,char *fname); uint8_t *OS_fileptr(long *allocsizep,char *fname);
#define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True) #define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True)
void rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr)
{ {
char cmd[32768]; int32_t i,n; char *filestr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item; char cmd[32768]; int32_t i,n,retval=-1; char *filestr,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item;
sprintf(fname,"%s.gameinfo",gametxidstr); sprintf(fname,"%s.gameinfo",gametxidstr);
sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",gametxidstr,fname); sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",gametxidstr,fname);
if ( system(cmd) != 0 ) if ( system(cmd) != 0 )
@@ -163,16 +163,17 @@ void rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr)
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
item = jitem(array,i); item = jitem(array,i);
if ( is_cJSON_True(jobj(item,"ismine")) != 0 ) if ( is_cJSON_True(jobj(item,"ismine")) != 0 && (statusstr= jstr(item,"status")) != 0 )
{ {
fprintf(stderr,"found ismine:true\n"); if ( strcmp(statusstr,"registered") == 0 )
sleep(2);
if ( (item= jobj(item,"player")) != 0 && (datastr= jstr(item,"data")) != 0 )
{ {
decode_hex((uint8_t *)&rs->P,(int32_t)strlen(datastr)/2,datastr); retval = 0;
fprintf(stderr,"set datastr[%d]\n",(int32_t)strlen(datastr)); if ( (item= jobj(item,"player")) != 0 && (datastr= jstr(item,"data")) != 0 )
rs->restoring = 1; {
sleep(5); decode_hex((uint8_t *)&rs->P,(int32_t)strlen(datastr)/2,datastr);
//fprintf(stderr,"set datastr[%d]\n",(int32_t)strlen(datastr));
rs->restoring = 1;
}
} }
} }
} }
@@ -181,6 +182,7 @@ void rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr)
} }
free(filestr); free(filestr);
} }
return(retval);
} }
void rogue_progress(uint64_t seed,char *keystrokes,int32_t num) // use seed to lookup gametxid void rogue_progress(uint64_t seed,char *keystrokes,int32_t num) // use seed to lookup gametxid
@@ -212,7 +214,11 @@ int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu
rs->numkeys = num; rs->numkeys = num;
rs->sleeptime = 0; rs->sleeptime = 0;
if ( player != 0 ) if ( player != 0 )
{
rs->P = *player; rs->P = *player;
rs->restoring = 1;
fprintf(stderr,"restore player packsize.%d\n",rs->P.packsize);
}
uint32_t starttime = (uint32_t)time(NULL); uint32_t starttime = (uint32_t)time(NULL);
rogueiterate(rs); rogueiterate(rs);
/*fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime); /*fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime);
@@ -301,7 +307,11 @@ int rogue(int argc, char **argv, char **envp)
{ {
rs->seed = atol(argv[1]); rs->seed = atol(argv[1]);
strcpy(Gametxidstr,argv[2]); strcpy(Gametxidstr,argv[2]);
rogue_setplayerdata(rs,Gametxidstr); if ( rogue_setplayerdata(rs,Gametxidstr) < 0 )
{
fprintf(stderr,"invalid gametxid, or already started\n");
return(-1);
}
} else rs->seed = 777; } else rs->seed = 777;
rs->guiflag = 1; rs->guiflag = 1;
rs->sleeptime = 1; // non-zero to allow refresh() rs->sleeptime = 1; // non-zero to allow refresh()
@@ -533,7 +543,7 @@ playit(struct rogue_state *rs)
{ {
if ( rs->replaydone != 0 ) if ( rs->replaydone != 0 )
{ {
//fprintf(stderr,"replaydone\n"); sleep(3); fprintf(stderr,"replaydone\n"); sleep(3);
return; return;
} }
if ( rs->sleeptime != 0 ) if ( rs->sleeptime != 0 )
@@ -561,27 +571,38 @@ quit(int sig)
{ {
struct rogue_state *rs = &globalR; struct rogue_state *rs = &globalR;
int oy, ox; int oy, ox;
fprintf(stderr,"inside quit(%d)\n",sig);
NOOP(sig); if ( rs->guiflag != 0 )
{
/* NOOP(sig);
* Reset the signal in case we got here via an interrupt
*/ /*
if (!q_comm) * Reset the signal in case we got here via an interrupt
mpos = 0; */
getyx(curscr, oy, ox); if (!q_comm)
msg(rs,"really quit?"); mpos = 0;
getyx(curscr, oy, ox);
msg(rs,"really quit?");
}
if (readchar(rs) == 'y') if (readchar(rs) == 'y')
{ {
signal(SIGINT, leave); if ( rs->guiflag != 0 )
clear(); {
mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse); signal(SIGINT, leave);
move(LINES - 1, 0); clear();
if ( rs->sleeptime != 0 ) mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse);
refresh(); move(LINES - 1, 0);
score(purse, 1, 0); if ( rs->sleeptime != 0 )
flushkeystrokes(rs); refresh();
my_exit(0); score(purse, 1, 0);
flushkeystrokes(rs);
my_exit(0);
}
else
{
fprintf(stderr,"done!\n");
score(purse, 1, 0);
}
} }
else else
{ {
@@ -668,9 +689,14 @@ shell(struct rogue_state *rs)
void void
my_exit(int st) my_exit(int st)
{ {
uint32_t counter;
resetltchars(); resetltchars();
if ( globalR.guiflag != 0 ) if ( globalR.guiflag != 0 )
exit(st); exit(st);
else fprintf(stderr,"would have exit.(%d)\n",st); else if ( counter++ < 10 )
{
fprintf(stderr,"would have exit.(%d)\n",st);
globalR.replaydone = 1;
}
} }

View File

@@ -1351,6 +1351,7 @@ void rogue_restoreobject(THING *o,struct rogue_packitem *item)
o->_o._o_flags = item->flags; o->_o._o_flags = item->flags;
o->_o._o_group = item->group; o->_o._o_group = item->group;
o->o_flags |= ISKNOW; o->o_flags |= ISKNOW;
o->o_flags &= ~ISFOUND;
switch ( item->type ) switch ( item->type )
{ {
case SCROLL: case SCROLL:
@@ -1370,6 +1371,9 @@ void rogue_restoreobject(THING *o,struct rogue_packitem *item)
ws_info[item->which].oi_know = TRUE; ws_info[item->which].oi_know = TRUE;
break; break;
} }
char packitemstr[256];
strcpy(packitemstr,inv_name(o,FALSE));
fprintf(stderr,"packitem.(%s)\n",packitemstr);
} }
void rogue_packitemstr(char *packitemstr,struct rogue_packitem *item) void rogue_packitemstr(char *packitemstr,struct rogue_packitem *item)

View File

@@ -808,7 +808,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
{ {
UniValue obj; struct rogue_player P; UniValue obj; struct rogue_player P;
seed = rogue_gamefields(obj,maxplayers,buyin,gametxid,myrogueaddr); seed = rogue_gamefields(obj,maxplayers,buyin,gametxid,myrogueaddr);
fprintf(stderr,"found baton %s numkeys.%d seed.%llu\n",batontxid.ToString().c_str(),numkeys,(long long)seed); fprintf(stderr,"found baton %s numkeys.%d seed.%llu playerdata.%d\n",batontxid.ToString().c_str(),numkeys,(long long)seed,(int32_t)playerdata.size());
memset(&P,0,sizeof(P)); memset(&P,0,sizeof(P));
if ( playerdata.size() > 0 ) if ( playerdata.size() > 0 )
{ {
@@ -840,9 +840,12 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
return(cclib_error(result,"highlander must be a winner or last one standing")); return(cclib_error(result,"highlander must be a winner or last one standing"));
cashout += numplayers * buyin; cashout += numplayers * buyin;
} }
if ( (inputsum= AddCClibInputs(cp,mtx,roguepk,cashout,16,cp->unspendableCCaddr)) > (uint64_t)P.gold*mult ) if ( cashout >= txfee )
CCchange = (inputsum - cashout); {
mtx.vout.push_back(CTxOut(cashout,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( (inputsum= AddCClibInputs(cp,mtx,roguepk,cashout,16,cp->unspendableCCaddr)) > (uint64_t)P.gold*mult )
CCchange = (inputsum - cashout);
mtx.vout.push_back(CTxOut(cashout,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
}
//for (i=0; i<P.packsize; i++) //for (i=0; i<P.packsize; i++)
// fprintf(stderr,"object (%s) type.%d pack.(%c:%d)\n",inv_name(o,FALSE),o->_o._o_type,o->_o._o_packch,o->_o._o_packch); // fprintf(stderr,"object (%s) type.%d pack.(%c:%d)\n",inv_name(o,FALSE),o->_o._o_type,o->_o._o_packch,o->_o._o_packch);
} }