Handle qui quit

This commit is contained in:
jl777
2019-02-02 07:40:55 -11:00
parent 2cf3d519aa
commit 4ffdae4135
5 changed files with 36 additions and 22 deletions

View File

@@ -58,9 +58,10 @@ CClib_methods[] =
{ (char *)"rogue", (char *)"txidinfo", (char *)"txid", 1, 1, 'I', EVAL_ROGUE }, { (char *)"rogue", (char *)"txidinfo", (char *)"txid", 1, 1, 'I', EVAL_ROGUE },
{ (char *)"rogue", (char *)"pending", (char *)"<no args>", 0, 0, 'P', EVAL_ROGUE }, { (char *)"rogue", (char *)"pending", (char *)"<no args>", 0, 0, 'P', EVAL_ROGUE },
{ (char *)"rogue", (char *)"register", (char *)"txid [inventory]", 1, 2, 'R', EVAL_ROGUE }, { (char *)"rogue", (char *)"register", (char *)"txid [inventory]", 1, 2, 'R', EVAL_ROGUE },
{ (char *)"rogue", (char *)"progress", (char *)"txid fname", 2, 2, 'K', EVAL_ROGUE }, { (char *)"rogue", (char *)"progress", (char *)"regtxid fname", 2, 2, 'K', EVAL_ROGUE },
{ (char *)"rogue", (char *)"claimwin", (char *)"txid", 1, 1, 'W', EVAL_ROGUE }, { (char *)"rogue", (char *)"saveandquit", (char *)"ptxid", 1, 1, 'Q', EVAL_ROGUE },
{ (char *)"rogue", (char *)"extract", (char *)"txid item", 2, 2, 'X', EVAL_ROGUE }, { (char *)"rogue", (char *)"claimwin", (char *)"ptxid", 1, 1, 'W', EVAL_ROGUE },
{ (char *)"rogue", (char *)"extract", (char *)"wtxid item", 2, 2, 'X', EVAL_ROGUE },
#else #else
{ (char *)"sudoku", (char *)"gen", (char *)"<no args>", 0, 0, 'G', EVAL_SUDOKU }, { (char *)"sudoku", (char *)"gen", (char *)"<no args>", 0, 0, 'G', EVAL_SUDOKU },
{ (char *)"sudoku", (char *)"txidinfo", (char *)"txid", 1, 1, 'T', EVAL_SUDOKU }, { (char *)"sudoku", (char *)"txidinfo", (char *)"txid", 1, 1, 'T', EVAL_SUDOKU },
@@ -83,6 +84,7 @@ UniValue rogue_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue rogue_txidinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue rogue_txidinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue rogue_progress(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue rogue_progress(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue rogue_saveandquit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue rogue_claimwin(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue rogue_claimwin(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
@@ -111,6 +113,8 @@ UniValue CClib_method(struct CCcontract_info *cp,char *method,cJSON *params)
return(rogue_register(txfee,cp,params)); return(rogue_register(txfee,cp,params));
else if ( strcmp(method,"progress") == 0 ) else if ( strcmp(method,"progress") == 0 )
return(rogue_progress(txfee,cp,params)); return(rogue_progress(txfee,cp,params));
else if ( strcmp(method,"saveandquit") == 0 )
return(rogue_saveandquit(txfee,cp,params));
else if ( strcmp(method,"claimwin") == 0 ) else if ( strcmp(method,"claimwin") == 0 )
return(rogue_claimwin(txfee,cp,params)); return(rogue_claimwin(txfee,cp,params));
else if ( strcmp(method,"extract") == 0 ) else if ( strcmp(method,"extract") == 0 )

View File

@@ -260,6 +260,8 @@ over:
after = FALSE; after = FALSE;
q_comm = TRUE; q_comm = TRUE;
quit(0); quit(0);
if ( rs->needflush == 0 )
rs->needflush = (uint32_t)time(NULL);
q_comm = FALSE; q_comm = FALSE;
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);

View File

@@ -410,6 +410,8 @@ playit(struct rogue_state *rs)
if ( flushkeystrokes(rs) == 0 ) if ( flushkeystrokes(rs) == 0 )
rs->needflush = 0; rs->needflush = 0;
} }
if ( rs->didquit != 0 )
my_exit(0);
} }
} }
endit(0); endit(0);
@@ -425,36 +427,36 @@ quit(int sig)
{ {
struct rogue_state *rs = &globalR; struct rogue_state *rs = &globalR;
int oy, ox; int oy, ox;
NOOP(sig); NOOP(sig);
/* /*
* Reset the signal in case we got here via an interrupt * Reset the signal in case we got here via an interrupt
*/ */
if (!q_comm) if (!q_comm)
mpos = 0; mpos = 0;
getyx(curscr, oy, ox); getyx(curscr, oy, ox);
msg(rs,"really quit?"); msg(rs,"really quit?");
if (readchar(rs) == 'y') if (readchar(rs) == 'y')
{ {
signal(SIGINT, leave); signal(SIGINT, leave);
clear(); clear();
mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse); mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse);
move(LINES - 1, 0); move(LINES - 1, 0);
refresh(); refresh();
score(purse, 1, 0); score(purse, 1, 0);
my_exit(0); rs->didquit = (uint32_t)time(NULL);
} }
else else
{ {
move(0, 0); move(0, 0);
clrtoeol(); clrtoeol();
status(rs); status(rs);
move(oy, ox); move(oy, ox);
refresh(); refresh();
mpos = 0; mpos = 0;
count = 0; count = 0;
to_death = FALSE; to_death = FALSE;
} }
} }

View File

@@ -317,7 +317,7 @@ struct rogue_state
{ {
uint64_t seed; uint64_t seed;
char *keystrokes; char *keystrokes;
uint32_t needflush,replaydone; uint32_t needflush,replaydone,didquit;
int32_t numkeys,ind,num,guiflag,counter; int32_t numkeys,ind,num,guiflag,counter;
char buffered[512]; char buffered[512];
}; };

View File

@@ -147,6 +147,12 @@ UniValue rogue_claimwin(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
return(result); return(result);
} }
UniValue rogue_saveandquit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
{
UniValue result(UniValue::VOBJ);
return(result);
}
UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
{ {
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);