From 05977b8af6de99402eef31f2145d49ce388a1969 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 13 Mar 2019 22:58:20 -1100 Subject: [PATCH 001/111] Jl777 (#1333) * Slow down clock * Faster and slower * A0/50 * Fix dilithium inputs scan to compare for the voutpubtxids[vout] * Prevent use of uninitialized ignoredAddresses * Filter out amount=0 UTXOs from getsnapshot results * rogue msvc build (#1327) * + msvc 2015 deps headers * + msvc deps build script this script builds only deps, to build rogue binary, open *.sln file in MSVC 2015 and build x64 Release version. * + msvc solution (*.sln) update * + msvc build fix * fix libcurl deps install (msvc) * Fix wrong dilithium compare * Port getchaintxstats from BTC master (#1328) This will allow explorers to present interesting analytics about transaction volume in various time frames. * customcc * Make custom * Syntax * update * Patch rogue msvc (#1330) * + msvc 2015 deps headers * + msvc deps build script this script builds only deps, to build rogue binary, open *.sln file in MSVC 2015 and build x64 Release version. * + msvc solution (*.sln) update * + msvc build fix * fix libcurl deps install (msvc) * [msvc] fix seed str -> uint64 conversion * [msvc] fix config file name issue + debug print for send raw tx * + comment debug printouts * [ msvc ] display compiler version and build date on startup * +pritns * +prints * I, * Print hex * Allow gold mismatch for validate * Stricter player data validation * Change data source * Allow claiming less than cashout value * 50902 exemption * Taxied * Print * Debug file * Log seed * Potion file * ; * Log seed * Commands log * Fp * Test * Prints * static FILE *fp; * Fp2 * Daemons or fuses * Fuse prints * All funcs * Logfp * turn_see is a daemon! * 'void (*)(struct rogue_state *, int) * -prints * -file fp * -potions file * Test * -log * -print replay2 gold * Test * D'oh! --- .gitignore | 1 + src/cc/cclib.cpp | 15 +- src/cc/customcc.cpp | 88 + src/cc/customcc.h | 45 + src/cc/dilithium.c | 2 +- src/cc/makecustom | 7 + src/cc/rogue/command.c | 8 +- src/cc/rogue/daemon.c | 37 +- src/cc/rogue/daemons.c | 151 +- src/cc/rogue/extern.h | 9 +- src/cc/rogue/io.c | 2 +- src/cc/rogue/main.c | 102 +- src/cc/rogue/misc.c | 18 +- src/cc/rogue/new_level.c | 14 +- src/cc/rogue/potions.c | 60 +- src/cc/rogue/rogue.c | 37 +- src/cc/rogue/rogue.h | 3 +- src/cc/rogue/rogue54.sln | 14 +- src/cc/rogue/rogue54.vcxproj | 257 +++ src/cc/rogue/rogue_build_msvc.cmd | 64 + .../deps/install/include/acs_defs.h | 265 +++ .../deps/install/include/curses.h | 1846 +++++++++++++++++ .../deps/install/include/curspriv.h | 134 ++ .../deps/install/include/getopt.h | 93 + .../deps/install/include/panel.h | 56 + .../deps/install/include/term.h | 48 + .../deps/install/include/unistd.h | 56 + src/cc/rogue_rpc.cpp | 87 +- src/cc/tetris.cpp | 5 +- src/rpc/blockchain.cpp | 82 + src/rpc/client.cpp | 1 + src/txdb.cpp | 42 +- 32 files changed, 3485 insertions(+), 164 deletions(-) create mode 100644 src/cc/customcc.cpp create mode 100644 src/cc/customcc.h create mode 100755 src/cc/makecustom create mode 100644 src/cc/rogue/rogue54.vcxproj create mode 100644 src/cc/rogue/rogue_build_msvc.cmd create mode 100644 src/cc/rogue/x86_64-w64-msvc/deps/install/include/acs_defs.h create mode 100644 src/cc/rogue/x86_64-w64-msvc/deps/install/include/curses.h create mode 100644 src/cc/rogue/x86_64-w64-msvc/deps/install/include/curspriv.h create mode 100644 src/cc/rogue/x86_64-w64-msvc/deps/install/include/getopt.h create mode 100644 src/cc/rogue/x86_64-w64-msvc/deps/install/include/panel.h create mode 100644 src/cc/rogue/x86_64-w64-msvc/deps/install/include/term.h create mode 100644 src/cc/rogue/x86_64-w64-msvc/deps/install/include/unistd.h diff --git a/.gitignore b/.gitignore index d05db4c67..6cebf87fe 100644 --- a/.gitignore +++ b/.gitignore @@ -154,3 +154,4 @@ src/ROGUE.conf src/rogue.scr src/cc/rogue/confdefs.h +src/cc/rogue/x64 diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 651723e44..c783eb4d0 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -33,8 +33,12 @@ #ifdef BUILD_ROGUE #define EVAL_ROGUE 17 std::string MYCCLIBNAME = (char *)"rogue"; -#else + +#elif BUILD_CUSTOMCC +#include "customcc.h" + +#else #define EVAL_SUDOKU 17 #define EVAL_MUSIG 18 #define EVAL_DILITHIUM 19 @@ -67,6 +71,8 @@ CClib_methods[] = { (char *)"rogue", (char *)"games", (char *)"", 0, 0, 'F', EVAL_ROGUE }, { (char *)"rogue", (char *)"setname", (char *)"pname", 1, 1, 'N', EVAL_ROGUE }, { (char *)"rogue", (char *)"extract", (char *)"gametxid [pubkey]", 1, 2, 'X', EVAL_ROGUE }, +#elif BUILD_CUSTOMCC + RPC_FUNCS #else { (char *)"sudoku", (char *)"gen", (char *)"", 0, 0, 'G', EVAL_SUDOKU }, { (char *)"sudoku", (char *)"txidinfo", (char *)"txid", 1, 1, 'T', EVAL_SUDOKU }, @@ -214,6 +220,8 @@ UniValue CClib_method(struct CCcontract_info *cp,char *method,char *jsonstr) return(result); } } +#elif BUILD_CUSTOMCC + CUSTOM_DISPATCH #else if ( cp->evalcode == EVAL_SUDOKU ) { @@ -410,6 +418,8 @@ bool CClib_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C { #ifdef BUILD_ROGUE return(rogue_validate(cp,height,eval,tx)); +#elif BUILD_CUSTOMCC + return(custom_validate(cp,height,eval,tx)); #else if ( cp->evalcode == EVAL_SUDOKU ) return(sudoku_validate(cp,height,eval,tx)); @@ -660,6 +670,9 @@ int32_t cclib_parsehash(uint8_t *hash32,cJSON *item,int32_t len) #include "rogue/weapons.c" #include "rogue/wizard.c" +#elif BUILD_CUSTOMCC +#include "customcc.cpp" + #else #include "sudoku.cpp" #include "musig.cpp" diff --git a/src/cc/customcc.cpp b/src/cc/customcc.cpp new file mode 100644 index 000000000..9f58c5c8b --- /dev/null +++ b/src/cc/customcc.cpp @@ -0,0 +1,88 @@ +/* + simple stub custom cc + + Just update the functions in this file, then from ~/komodo/src/cc + + ../komodo-cli -ac_name=CUSTOM stop + ./makecustom + ../komodod -ac_name=CUSTOM -ac_cclib=custom -ac_cc=2 ... + + The above will rebuild komodod and get it running again + */ + +CScript custom_opret(uint8_t funcid,CPubKey pk) +{ + CScript opret; uint8_t evalcode = EVAL_CUSTOM; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk); + return(opret); +} + +uint8_t custom_opretdecode(CPubKey &pk,CScript scriptPubKey) +{ + std::vector vopret; uint8_t e,f; + GetOpReturnData(scriptPubKey,vopret); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk) != 0 && e == EVAL_CUSTOM ) + { + return(f); + } + return(0); +} + +UniValue custom_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastflag) +{ + CTransaction tx; + if ( rawtx.size() > 0 ) + { + result.push_back(Pair("hex",rawtx)); + if ( DecodeHexTx(tx,rawtx) != 0 ) + { + if ( broadcastflag != 0 && myAddtomempool(tx) != 0 ) + RelayTransaction(tx); + result.push_back(Pair("txid",tx.GetHash().ToString())); + result.push_back(Pair("result","success")); + } else result.push_back(Pair("error","decode hex")); + } else result.push_back(Pair("error","couldnt finalize CCtx")); + return(result); +} + +UniValue custom_func0(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + result.push_back(Pair("message","just an example of an information returning rpc")); + return(result); +} + +// send yourself 1 coin to your CC address using normal utxo from your -pubkey + +UniValue custom_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); std::string rawtx; + UniValue result(UniValue::VOBJ); CPubKey mypk; int64_t amount = COIN; int32_t broadcastflag=0; + if ( txfee == 0 ) + txfee = CUSTOM_TXFEE; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,COIN+txfee,64) >= COIN+txfee ) // add utxo to mtx + { + mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,mypk)); // make vout0 + // add opreturn, change is automatically added and tx is properly signed + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,custom_opret('1',mypk)); + return(custom_rawtxresult(result,rawtx,broadcastflag)); + } + return(result); +} + +bool custom_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) +{ + char expectedaddress[64]; CPubKey pk; + if ( tx.vout.size() != 2 ) // make sure the tx only has 2 outputs + return eval->Invalid("invalid number of vouts"); + else if ( custom_opretdecode(pk,tx.vout[1].scriptPubKey) != '1' ) // verify has opreturn + return eval->Invalid("invalid opreturn"); + GetCCaddress(cp,expectedaddress,pk); + if ( IsCClibvout(cp,tx,0,expectedaddress) == COIN ) // make sure amount and destination matches + return(true); + else return eval->Invalid("invalid vout0 amount"); +} + + diff --git a/src/cc/customcc.h b/src/cc/customcc.h new file mode 100644 index 000000000..436937391 --- /dev/null +++ b/src/cc/customcc.h @@ -0,0 +1,45 @@ +/* + to create a custom libcc.so: + + 1. change "func0" and "func1" to method names that fit your custom cc. Of course, you can create more functions by adding another entry to RPC_FUNCS. there is not any practical limit to the number of methods. + + 2. For each method make sure there is a UniValue function declaration and CUSTOM_DISPATCH has an if statement checking for it that calls the custom_func + + 3. write the actual custom_func0, custom_func1 and custom_validate in customcc.cpp + + 4. ./makecustom, which builds cclib.cpp with -DBUILD_CUSTOMCC and puts the libcc.so in ~/komodo/src and rebuilds komodod + + 5. launch your chain with -ac_cclib=customcc -ac_cc=2 + + */ + +std::string MYCCLIBNAME = (char *)"customcc"; + +#define EVAL_CUSTOM (EVAL_FAUCET2+1) +#define CUSTOM_TXFEE 10000 + +#define MYCCNAME "custom" + +#define RPC_FUNCS \ + { (char *)MYCCNAME, (char *)"func0", (char *)"", 1, 1, '0', EVAL_CUSTOM }, \ + { (char *)MYCCNAME, (char *)"func1", (char *)"", 0, 0, '1', EVAL_CUSTOM }, + +bool custom_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx); +UniValue custom_func0(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue custom_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); + +#define CUSTOM_DISPATCH \ +if ( cp->evalcode == EVAL_CUSTOM ) \ +{ \ + if ( strcmp(method,"func0") == 0 ) \ + return(custom_func0(txfee,cp,params)); \ + else if ( strcmp(method,"func1") == 0 ) \ + return(custom_func1(txfee,cp,params)); \ + else \ + { \ + result.push_back(Pair("result","error")); \ + result.push_back(Pair("error","invalid customcc method")); \ + result.push_back(Pair("method",method)); \ + return(result); \ + } \ +} diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index d4b75bf38..0854236ec 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3352,7 +3352,7 @@ int64_t dilithium_inputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu { if ( (nValue= IsCClibvout(cp,vintx,vout,cmpaddr)) > DILITHIUM_TXFEE && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { - if ( (dilithium_Qsendopretdecode(checktxid,tmpsig,voutpubtxids,vintx.vout[numvouts-1].scriptPubKey) == 'Q' || dilithium_sendopretdecode(checktxid,vintx.vout[numvouts-1].scriptPubKey) == 'x') && destpubtxid == checktxid ) + if ( (dilithium_Qsendopretdecode(checktxid,tmpsig,voutpubtxids,vintx.vout[numvouts-1].scriptPubKey) == 'Q' && vout < voutpubtxids.size() && destpubtxid == voutpubtxids[vout]) || (dilithium_sendopretdecode(checktxid,vintx.vout[numvouts-1].scriptPubKey) == 'x' && destpubtxid == checktxid) ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); diff --git a/src/cc/makecustom b/src/cc/makecustom new file mode 100755 index 000000000..61b251e6e --- /dev/null +++ b/src/cc/makecustom @@ -0,0 +1,7 @@ +#!/bin/sh +gcc -O3 -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o customcc.so cclib.cpp +cp customcc.so ../libcc.so +cd .. +make +cd cc + diff --git a/src/cc/rogue/command.c b/src/cc/rogue/command.c index 84281c5a7..568f4b8f8 100644 --- a/src/cc/rogue/command.c +++ b/src/cc/rogue/command.c @@ -344,7 +344,7 @@ over: if (wizard) { wizard = FALSE; - turn_see(TRUE); + turn_see(rs,TRUE); msg(rs,"not wizard any more"); } else @@ -353,7 +353,7 @@ over: if (wizard) { noscore = TRUE; - turn_see(FALSE); + turn_see(rs,FALSE); msg(rs,"you are suddenly as smart as Ken Arnold in dungeon #%d", dnum); } else @@ -403,7 +403,7 @@ over: when CTRL('T'): teleport(); when CTRL('E'): msg(rs,"food left: %d", food_left); when CTRL('C'): add_pass(); - when CTRL('X'): turn_see(on(player, SEEMONST)); + when CTRL('X'): turn_see(rs,on(player, SEEMONST)); when CTRL('~'): { THING *item; @@ -455,7 +455,7 @@ over: if (!running) door_stop = FALSE; } - /* +/* * If he ran into something to take, let him pick it up. */ if (take != 0) diff --git a/src/cc/rogue/daemon.c b/src/cc/rogue/daemon.c index 1da06d499..81bdd0a73 100644 --- a/src/cc/rogue/daemon.c +++ b/src/cc/rogue/daemon.c @@ -160,10 +160,43 @@ extinguish(void (*func)(struct rogue_state *rs,int)) * do_fuses: * Decrement counters and start needed fuses */ + +/*char *actionfunc_str(char *str,void *ptr) +{ + if ( ptr == (void *)runners ) + strcpy(str,"runners"); + else if ( ptr == (void *)doctor ) + strcpy(str,"doctor"); + else if ( ptr == (void *)stomach ) + strcpy(str,"stomach"); + else if ( ptr == (void *)nohaste ) + strcpy(str,"nohaste"); + else if ( ptr == (void *)unconfuse ) + strcpy(str,"unconfuse"); + else if ( ptr == (void *)swander ) + strcpy(str,"swander"); + else if ( ptr == (void *)come_down ) + strcpy(str,"come_down"); + else if ( ptr == (void *)unsee ) + strcpy(str,"unsee"); + else if ( ptr == (void *)sight ) + strcpy(str,"sight"); + else if ( ptr == (void *)land ) + strcpy(str,"land"); + else if ( ptr == (void *)rollwand ) + strcpy(str,"rollwand"); + else if ( ptr == (void *)visuals ) + strcpy(str,"visuals"); + else if ( ptr == (void *)turn_see ) + strcpy(str,"turn_see"); + else strcpy(str,"no match"); + return(str); +}*/ + void do_fuses(struct rogue_state *rs,int flag) { - register struct delayed_action *wire; + register struct delayed_action *wire; char str[64]; /* * Step though the list @@ -175,6 +208,8 @@ do_fuses(struct rogue_state *rs,int flag) */ if (flag == wire->d_type && wire->d_time > 0 && --wire->d_time == 0) { + //if ( fp != 0 ) + // fprintf(fp,"t.%d %d %s, ",wire->d_type,wire->d_time,actionfunc_str(str,wire->d_func)); wire->d_type = EMPTY; (*wire->d_func)(rs,wire->d_arg); } diff --git a/src/cc/rogue/daemons.c b/src/cc/rogue/daemons.c index 42e685320..c9c16448d 100644 --- a/src/cc/rogue/daemons.c +++ b/src/cc/rogue/daemons.c @@ -21,6 +21,8 @@ void doctor(struct rogue_state *rs,int arg) { register int lv, ohp; + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"doctor\n"); lv = pstats.s_lvl; ohp = pstats.s_hpt; @@ -52,6 +54,8 @@ doctor(struct rogue_state *rs,int arg) void swander(struct rogue_state *rs,int arg) { + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"swander\n"); start_daemon(rollwand, 0, BEFORE); } @@ -63,6 +67,8 @@ int between = 0; void rollwand(struct rogue_state *rs,int arg) { + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"rollwand\n"); if (++between >= 4) { if (roll(1, 6) == 4) @@ -82,6 +88,8 @@ rollwand(struct rogue_state *rs,int arg) void unconfuse(struct rogue_state *rs,int arg) { + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"unconfuse\n"); player.t_flags &= ~ISHUH; msg(rs,"you feel less %s now", choose_str("trippy", "confused")); } @@ -94,6 +102,8 @@ void unsee(struct rogue_state *rs,int arg) { register THING *th; + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"unsee\n"); for (th = mlist; th != NULL; th = next(th)) if (on(*th, ISINVIS) && see_monst(th)) @@ -108,6 +118,8 @@ unsee(struct rogue_state *rs,int arg) void sight(struct rogue_state *rs,int arg) { + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"sight\n"); if (on(player, ISBLIND)) { extinguish(sight); @@ -126,6 +138,8 @@ sight(struct rogue_state *rs,int arg) void nohaste(struct rogue_state *rs,int arg) { + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"nohaste\n"); player.t_flags &= ~ISHASTE; msg(rs,"you feel yourself slowing down"); } @@ -139,6 +153,8 @@ stomach(struct rogue_state *rs,int arg) { register int oldfood; int orig_hungry = hungry_state; + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"stomach\n"); if (food_left <= 0) { @@ -194,41 +210,43 @@ come_down(struct rogue_state *rs,int arg) { register THING *tp; register bool seemonst; - + + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"come_down\n"); if (!on(player, ISHALU)) - return; - + return; + kill_daemon(visuals); player.t_flags &= ~ISHALU; - + if (on(player, ISBLIND)) - return; - + return; + /* * undo the things */ for (tp = lvl_obj; tp != NULL; tp = next(tp)) - if (cansee(rs,tp->o_pos.y, tp->o_pos.x)) - mvaddch(tp->o_pos.y, tp->o_pos.x, tp->o_type); - + if (cansee(rs,tp->o_pos.y, tp->o_pos.x)) + mvaddch(tp->o_pos.y, tp->o_pos.x, tp->o_type); + /* * undo the monsters */ seemonst = on(player, SEEMONST); for (tp = mlist; tp != NULL; tp = next(tp)) { - move(tp->t_pos.y, tp->t_pos.x); - if (cansee(rs,tp->t_pos.y, tp->t_pos.x)) - if (!on(*tp, ISINVIS) || on(player, CANSEE)) - addch(tp->t_disguise); - else - addch(chat(tp->t_pos.y, tp->t_pos.x)); - else if (seemonst) - { - standout(); - addch(tp->t_type); - standend(); - } + move(tp->t_pos.y, tp->t_pos.x); + if (cansee(rs,tp->t_pos.y, tp->t_pos.x)) + if (!on(*tp, ISINVIS) || on(player, CANSEE)) + addch(tp->t_disguise); + else + addch(chat(tp->t_pos.y, tp->t_pos.x)); + else if (seemonst) + { + standout(); + addch(tp->t_type); + standend(); + } } msg(rs,"Everything looks SO boring now."); } @@ -242,42 +260,44 @@ visuals(struct rogue_state *rs,int arg) { register THING *tp; register bool seemonst; - + if (!after || (running && jump)) - return; + return; + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"visuals\n"); /* * change the things */ for (tp = lvl_obj; tp != NULL; tp = next(tp)) - if (cansee(rs,tp->o_pos.y, tp->o_pos.x)) - mvaddch(tp->o_pos.y, tp->o_pos.x, rnd_thing()); - + if (cansee(rs,tp->o_pos.y, tp->o_pos.x)) + mvaddch(tp->o_pos.y, tp->o_pos.x, rnd_thing()); + /* * change the stairs */ if (!seenstairs && cansee(rs,stairs.y, stairs.x)) - mvaddch(stairs.y, stairs.x, rnd_thing()); - + mvaddch(stairs.y, stairs.x, rnd_thing()); + /* * change the monsters */ seemonst = on(player, SEEMONST); for (tp = mlist; tp != NULL; tp = next(tp)) { - move(tp->t_pos.y, tp->t_pos.x); - if (see_monst(tp)) - { - if (tp->t_type == 'X' && tp->t_disguise != 'X') - addch(rnd_thing()); - else - addch(rnd(26) + 'A'); - } - else if (seemonst) - { - standout(); - addch(rnd(26) + 'A'); - standend(); - } + move(tp->t_pos.y, tp->t_pos.x); + if (see_monst(tp)) + { + if (tp->t_type == 'X' && tp->t_disguise != 'X') + addch(rnd_thing()); + else + addch(rnd(26) + 'A'); + } + else if (seemonst) + { + standout(); + addch(rnd(26) + 'A'); + standend(); + } } } @@ -288,7 +308,54 @@ visuals(struct rogue_state *rs,int arg) void land(struct rogue_state *rs,int arg) { + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"land\n"); player.t_flags &= ~ISLEVIT; msg(rs,choose_str("bummer! You've hit the ground", "you float gently to the ground")); } + +/* + * turn_see: + * Put on or off seeing monsters on this level + */ +bool +turn_see(struct rogue_state *rs,bool turn_off) +{ + THING *mp; + bool can_see, add_new; + if ( rs->logfp != 0 ) + fprintf(rs->logfp,"turn_see\n"); + + add_new = FALSE; + for (mp = mlist; mp != NULL; mp = next(mp)) + { + move(mp->t_pos.y, mp->t_pos.x); + can_see = see_monst(mp); + if (turn_off) + { + if (!can_see) + addch(mp->t_oldch); + } + else + { + if (!can_see) + standout(); + if (!on(player, ISHALU)) + addch(mp->t_type); + else + addch(rnd(26) + 'A'); + if (!can_see) + { + standend(); + add_new ^= 1;//add_new++; + } + } + } + if (turn_off) + player.t_flags &= ~SEEMONST; + else + player.t_flags |= SEEMONST; + return add_new; +} + diff --git a/src/cc/rogue/extern.h b/src/cc/rogue/extern.h index 7fba842f3..c62646b67 100644 --- a/src/cc/rogue/extern.h +++ b/src/cc/rogue/extern.h @@ -107,6 +107,12 @@ #include #include +#ifdef _WIN32 +#ifdef _MSC_VER +#include +#endif +#endif + #undef SIGTSTP #define MAXSTR 1024 /* maximum length of strings */ @@ -142,7 +148,8 @@ void leave(int); void my_exit(int st); void playltchars(void); void quit(int); -int32_t _quit(); +int32_t _quit(); + void resetltchars(void); void set_order(int *order, int numthings); void tstp(int ignored); diff --git a/src/cc/rogue/io.c b/src/cc/rogue/io.c index 4c289ad7d..ad22407f6 100644 --- a/src/cc/rogue/io.c +++ b/src/cc/rogue/io.c @@ -167,7 +167,7 @@ readchar(struct rogue_state *rs) fp = fopen("log","wb"); if ( fp != 0 ) { - fprintf(fp,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs)); + fprintf(fp,"%d: (%c) hp.%d num.%d gold.%d seed.%llu\n",counter,c,pstats.s_hpt,num_packitems(rs),purse,(long long)seed); fflush(fp); counter++; } diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index c2155a085..f146cfb4d 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -38,6 +38,31 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uin typedef union _bits256 bits256; #endif +#ifdef _WIN32 +#ifdef _MSC_VER +int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + time = ((uint64_t)file_time.dwLowDateTime); + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long)((time - EPOCH) / 10000000L); + tp->tv_usec = (long)(system_time.wMilliseconds * 1000); + return 0; +} +#endif // _MSC_VER +#endif + + + double OS_milliseconds() { struct timeval tv; double millis; @@ -392,6 +417,12 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char * } #endif +#ifdef _WIN32 +#ifdef _MSC_VER +#define sleep(x) Sleep(1000*(x)) +#endif +#endif + /************************************************************************ * * perform the query @@ -736,6 +767,17 @@ int32_t rogue_sendrawtransaction(char *rawtx) } free_json(retjson); } + + /* log sendrawtx result in file */ + + /* + FILE *debug_file; + debug_file = fopen("tx_debug.log", "a"); + fprintf(debug_file, "%s\n", retstr); + fflush(debug_file); + fclose(debug_file); + */ + free(retstr); } free(params); @@ -899,9 +941,46 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) return(retval); } +#ifdef _WIN32 +#ifdef _MSC_VER +__inline int msver(void) { + switch (_MSC_VER) { + case 1500: return 2008; + case 1600: return 2010; + case 1700: return 2012; + case 1800: return 2013; + case 1900: return 2015; + //case 1910: return 2017; + default: return (_MSC_VER / 100); + } +} + +static inline bool is_x64(void) { +#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) + return 1; +#elif defined(__amd64__) || defined(__amd64) || defined(_M_X64) || defined(_M_IA64) + return 1; +#else + return 0; +#endif +} + +#define BUILD_DATE __DATE__ " " __TIME__ +#endif // _WIN32 +#endif // _MSC_VER + int main(int argc, char **argv, char **envp) { uint64_t seed; FILE *fp = 0; int32_t i,j,c; char userpass[8192]; + + #ifdef _WIN32 + #ifdef _MSC_VER + printf("*** rogue for Windows [ Build %s ] ***\n", BUILD_DATE); + const char* arch = is_x64() ? "64-bits" : "32-bits"; + printf(" Built with VC++ %d (%ld) %s\n\n", msver(), _MSC_FULL_VER, arch); + #endif + #endif + for (i=j=0; argv[0][i]!=0&&j max_level) max_level = level; @@ -95,7 +105,7 @@ new_level(struct rogue_state *rs) enter_room(rs,&hero); mvaddch(hero.y, hero.x, PLAYER); if (on(player, SEEMONST)) - turn_see(FALSE); + turn_see(rs,FALSE); if (on(player, ISHALU)) visuals(rs,0); } diff --git a/src/cc/rogue/potions.c b/src/cc/rogue/potions.c index b10f83bd4..2425b051f 100644 --- a/src/cc/rogue/potions.c +++ b/src/cc/rogue/potions.c @@ -78,7 +78,6 @@ quaff(struct rogue_state *rs) } if (obj == cur_weapon) cur_weapon = NULL; - /* * Calculate the effect it has on the poor guy. */ @@ -91,7 +90,7 @@ quaff(struct rogue_state *rs) do_pot(rs,P_CONFUSE, !trip); when P_POISON: pot_info[P_POISON].oi_know = TRUE; - if (ISWEARING(R_SUSTSTR)) + if (ISWEARING(R_SUSTSTR)) msg(rs,"you feel momentarily sick"); else { @@ -112,7 +111,7 @@ quaff(struct rogue_state *rs) when P_MFIND: player.t_flags |= SEEMONST; fuse((void(*)(struct rogue_state *rs,int))turn_see, TRUE, HUHDURATION, AFTER); - if (!turn_see(FALSE)) + if (!turn_see(rs,FALSE)) msg(rs,"you have a %s feeling for a moment, then it passes", choose_str("normal", "strange")); when P_TFIND: @@ -158,7 +157,7 @@ quaff(struct rogue_state *rs) if (!trip) { if (on(player, SEEMONST)) - turn_see(FALSE); + turn_see(rs,FALSE); start_daemon(visuals, 0, BEFORE); seenstairs = seen_stairs(); } @@ -263,47 +262,6 @@ invis_on() mvaddch(mp->t_pos.y, mp->t_pos.x, mp->t_disguise); } -/* - * turn_see: - * Put on or off seeing monsters on this level - */ -bool -turn_see(bool turn_off) -{ - THING *mp; - bool can_see, add_new; - - add_new = FALSE; - for (mp = mlist; mp != NULL; mp = next(mp)) - { - move(mp->t_pos.y, mp->t_pos.x); - can_see = see_monst(mp); - if (turn_off) - { - if (!can_see) - addch(mp->t_oldch); - } - else - { - if (!can_see) - standout(); - if (!on(player, ISHALU)) - addch(mp->t_type); - else - addch(rnd(26) + 'A'); - if (!can_see) - { - standend(); - add_new ^= 1;//add_new++; - } - } - } - if (turn_off) - player.t_flags &= ~SEEMONST; - else - player.t_flags |= SEEMONST; - return add_new; -} /* * seen_stairs: @@ -358,18 +316,18 @@ do_pot(struct rogue_state *rs,int type, bool knowit) { PACT *pp; int t; - + pp = &p_actions[type]; if (!pot_info[type].oi_know) - pot_info[type].oi_know = knowit; + pot_info[type].oi_know = knowit; t = spread(pp->pa_time); if (!on(player, pp->pa_flags)) { - player.t_flags |= pp->pa_flags; - fuse(pp->pa_daemon, 0, t, AFTER); - look(rs,FALSE); + player.t_flags |= pp->pa_flags; + fuse(pp->pa_daemon, 0, t, AFTER); + look(rs,FALSE); } else - lengthen(pp->pa_daemon, t); + lengthen(pp->pa_daemon, t); msg(rs,choose_str(pp->pa_high, pp->pa_straight)); } diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 352e950ec..7a8e38c15 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -13,6 +13,7 @@ #include //#include //#include + #include "rogue.h" #ifdef STANDALONE #include "../komodo/src/komodo_cJSON.h" @@ -196,6 +197,12 @@ void rogue_bailout(struct rogue_state *rs) fprintf(stderr,"error issuing (%s)\n",cmd);*/ } +#ifdef _WIN32 +#ifdef _MSC_VER +#define sleep(x) Sleep(1000*(x)) +#endif +#endif + int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player,int32_t sleepmillis) { struct rogue_state *rs; FILE *fp; int32_t i,n; @@ -215,6 +222,14 @@ int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu globalR = *rs; uint32_t starttime = (uint32_t)time(NULL); rogueiterate(rs); + + /* + // keypress after replay + printf("[Press return to continue]"); + fflush(stdout); + if (fgets(prbuf, 10, stdin) != 0); + */ + if ( 0 ) { fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime); @@ -328,7 +343,15 @@ int rogue(int argc, char **argv, char **envp) rs->sleeptime = 1; // non-zero to allow refresh() if ( argc == 3 && strlen(argv[2]) == 64 ) { - rs->seed = atol(argv[1]); + #ifdef _WIN32 + #ifdef _MSC_VER + rs->seed = _strtoui64(argv[1], NULL, 10); + #else + rs->seed = atol(argv[1]); // windows, but not MSVC + #endif // _MSC_VER + #else + rs->seed = atol(argv[1]); // non-windows + #endif // _WIN32 strcpy(Gametxidstr,argv[2]); fprintf(stderr,"setplayerdata\n"); if ( rogue_setplayerdata(rs,Gametxidstr) < 0 ) @@ -526,6 +549,18 @@ tstp(int ignored) #endif*/ } + +#ifdef _WIN32 +#ifdef _MSC_VER +void usleep(int32_t micros) +{ + if (micros < 1000) + Sleep(1); + else Sleep(micros / 1000); +} +#endif +#endif + /* * playit: * The main loop of the program. Loop until the game is over, diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index ba57adbe6..5540da2da 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -365,6 +365,7 @@ struct rogue_state char *keystrokes,*keystrokeshex; uint32_t needflush,replaydone; int32_t numkeys,ind,num,guiflag,counter,sleeptime,playersize,restoring,lastnum; + FILE *logfp; struct rogue_player P; char buffered[10000]; uint8_t playerdata[10000]; @@ -770,7 +771,7 @@ bool roll_em(THING *thatt, THING *thdef, THING *weap, bool hurl); bool see_monst(THING *mp); bool seen_stairs(void); bool turn_ok(int y, int x); -bool turn_see(bool turn_off); +bool turn_see(struct rogue_state *rs,bool turn_off); bool is_current(struct rogue_state *rs,THING *obj); int passwd(void); diff --git a/src/cc/rogue/rogue54.sln b/src/cc/rogue/rogue54.sln index da1c58f07..751959465 100644 --- a/src/cc/rogue/rogue54.sln +++ b/src/cc/rogue/rogue54.sln @@ -1,17 +1,25 @@ -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C++ Express 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rogue54", "rogue54.vcproj", "{9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}" +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rogue54", "rogue54.vcxproj", "{9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}.Debug|Win32.ActiveCfg = Debug|Win32 {9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}.Debug|Win32.Build.0 = Debug|Win32 + {9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}.Debug|x64.ActiveCfg = Debug|x64 + {9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}.Debug|x64.Build.0 = Debug|x64 {9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}.Release|Win32.ActiveCfg = Release|Win32 {9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}.Release|Win32.Build.0 = Release|Win32 + {9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}.Release|x64.ActiveCfg = Release|x64 + {9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/cc/rogue/rogue54.vcxproj b/src/cc/rogue/rogue54.vcxproj new file mode 100644 index 000000000..344598dd8 --- /dev/null +++ b/src/cc/rogue/rogue54.vcxproj @@ -0,0 +1,257 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {9EA0D326-8097-4ADA-82EA-4DB1F5CAA8F6} + Win32Proj + 8.1 + + + + Application + v140 + MultiByte + + + Application + v140 + MultiByte + false + + + Application + v140 + MultiByte + + + Application + v140 + MultiByte + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>14.0.25431.1 + + + Debug\ + Debug\ + true + + + true + + + Release\ + Release\ + false + + + false + + + + Disabled + Default + ../pdcurses;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;ALLSCORES;MASTER;SCOREFILE="rogue54.scr";LOCKFILE="rogue54.lck";%(PreprocessorDefinitions) + true + false + + EnableFastChecks + MultiThreaded + true + true + false + true + + + Level4 + EditAndContinue + CompileAsC + + + Ws2_32.lib;pdcurses.lib;advapi32.lib;shfolder.lib;user32.lib;%(AdditionalDependencies) + $(OutDir)rogue54.exe + ..\pdcurses;%(AdditionalLibraryDirectories) + false + true + $(OutDir)rogue54.pdb + Console + MachineX86 + + + + + Disabled + Default + $(ProjectDir)x86_64-w64-msvc\deps\install\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;PDC_DLL_BUILD;PDC_WIDE;PDCDEBUG;_CRT_SECURE_NO_DEPRECATE;ALLSCORES;SCOREFILE="rogue54.scr";LOCKFILE="rogue54.lck";%(PreprocessorDefinitions) + true + false + + + EnableFastChecks + MultiThreaded + true + true + false + true + + + + + Level4 + ProgramDatabase + CompileAsC + + + Ws2_32.lib;wincon\pdcurses.lib;libcurl_imp.lib;advapi32.lib;shfolder.lib;user32.lib;%(AdditionalDependencies) + $(OutDir)rogue54.exe + $(ProjectDir)x86_64-w64-msvc\deps\install\lib;$(ProjectDir)x86_64-w64-msvc\deps\install\Release\lib;%(AdditionalLibraryDirectories) + false + true + $(OutDir)rogue54.pdb + Console + + + + + MaxSpeed + OnlyExplicitInline + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + MultiThreaded + true + NotUsing + Level3 + ProgramDatabase + $(ProjectDir)\x86_64-w64-msvc\include\ncursesw;$(ProjectDir)\x86_64-w64-msvc\include;%(AdditionalIncludeDirectories) + + + $(OutDir)rogue54.exe + true + Windows + true + true + MachineX86 + %(AdditionalLibraryDirectories) + %(AdditionalDependencies) + + + + + MaxSpeed + OnlyExplicitInline + true + WIN32;_WINDOWS;NDEBUG;PDC_DLL_BUILD;PDC_WIDE;PDCDEBUG;_CRT_SECURE_NO_DEPRECATE;ALLSCORES;SCOREFILE="rogue54.scr";LOCKFILE="rogue54.lck";%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + ProgramDatabase + $(ProjectDir)x86_64-w64-msvc\deps\install\include;%(AdditionalIncludeDirectories) + stdafx.h + CompileAsC + + + + + $(OutDir)rogue54.exe + true + Console + true + true + $(ProjectDir)x86_64-w64-msvc\deps\install\lib;$(ProjectDir)x86_64-w64-msvc\deps\install\Release\lib;%(AdditionalLibraryDirectories) + Ws2_32.lib;wincon\pdcurses.lib;libcurl_imp.lib;advapi32.lib;shfolder.lib;user32.lib;%(AdditionalDependencies) + %(IgnoreSpecificDefaultLibraries) + false + %(ForceSymbolReferences) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/cc/rogue/rogue_build_msvc.cmd b/src/cc/rogue/rogue_build_msvc.cmd new file mode 100644 index 000000000..77e7cd852 --- /dev/null +++ b/src/cc/rogue/rogue_build_msvc.cmd @@ -0,0 +1,64 @@ +@echo off +echo Rogue Build Script by Decker (c) 2019 + +@REM Check for Visual Studio +call set "VSPATH=" +if defined VS140COMNTOOLS ( if not defined VSPATH ( + call set "VSPATH=%%VS140COMNTOOLS%%" +) ) + +@REM check if we already have the tools in the environment +if exist "%VCINSTALLDIR%" ( + goto compile +) + +if not defined VSPATH ( + echo You need Microsoft Visual Studio 15 installed + pause + exit +) + +@REM set up the environment +if exist "%VSPATH%..\..\vc\vcvarsall.bat" ( + call "%%VSPATH%%..\..\vc\vcvarsall.bat" amd64 + goto compile +) + +echo Unable to set up the environment +pause +exit + +:compile + +mkdir x86_64-w64-msvc\deps +mkdir x86_64-w64-msvc\deps\install + +pushd x86_64-w64-msvc\deps + +:compile_pdcurses +rem git clone https://github.com/wmcbrine/PDCurses PDCurses.org +git clone https://github.com/Bill-Gray/PDCurses + +set PREFIX_DIR=%CD%\install + +pushd PDCurses +mkdir build64 & pushd build64 +rem cmake -G"Visual Studio 14 2015 Win64" -DPDC_WIDE=ON -DCMAKE_INSTALL_PREFIX=%PREFIX_DIR% -DCMAKE_BUILD_TYPE=Debug -DPDCDEBUG=ON .. +cmake -G"Visual Studio 14 2015 Win64" -DPDC_WIDE=ON -DCMAKE_INSTALL_PREFIX=%PREFIX_DIR% -DCMAKE_BUILD_TYPE=Release .. +popd +rem cmake --build build64 --config Debug --target install +cmake --build build64 --config Release --target install +popd + +:compile_curl + +git clone https://github.com/curl/curl +pushd curl + +mkdir build64 & pushd build64 +cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=%PREFIX_DIR% -DCMAKE_USE_WINSSL:BOOL=ON .. +cmake --build . --config Release --target libcurl +cmake --build . --config Release --target install +popd +popd + diff --git a/src/cc/rogue/x86_64-w64-msvc/deps/install/include/acs_defs.h b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/acs_defs.h new file mode 100644 index 000000000..c8c02a737 --- /dev/null +++ b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/acs_defs.h @@ -0,0 +1,265 @@ +/* Many of the following #defines are completely unused for the +nonce. For each character, its code point in code page 437, +Unicode, and page 8859-1 are given. The first is used for +non-wide builds in Win32 console, DOS, SDL, and OS/2. +Unicode is used for all wide builds, and for the non-wide +build of WinGUI. Code page 8859-1 is used for non-wide X11. + + All of these characters exist in CP437 and Unicode. Some +don't exist in 8859-1, in which case the last column is 'TBD'. +Only 32 are used in ncurses. So caution is advised. */ + +#ifdef USE_ISO8859_CHARSET + #define CHOOSE( A, B, C) (C) + #define TBD '!' +#else + #define CHOOSE( A, B, C) (USE_UNICODE_ACS_CHARS ? B : A) +#endif + +/* Codes found from https://en.wikipedia.org/wiki/Code_page_437 */ + +#define SMILE CHOOSE( 0x01, 0x263a, 'O') +#define REV_SMILE CHOOSE( 0x02, 0x263b, 'O') +#define HEART CHOOSE( 0x03, 0x2665, 'H') +#define DIAMOND CHOOSE( 0x04, 0x2666, 0x01) +#define CLUB CHOOSE( 0x05, 0x2663, 'C') +#define SPADE CHOOSE( 0x06, 0x2660, 'S') +#define MEDIUM_BULLET CHOOSE( 0x07, 0x2022, 0xb7) +#define REV_BULLET CHOOSE( 0x08, 0x2508, 0xb7) +#define WHITE_BULLET CHOOSE( 0x09, 0x25cb, 7) +#define REV_WHITE_BULLET CHOOSE( 0x0a, 0x25D9, 7) +#define MALE_SYM CHOOSE( 0x0b, 0x2642, 'm') +#define FEMALE_SYM CHOOSE( 0x0c, 0x2640, 'f') +#define QTR_NOTE CHOOSE( 0x0d, 0x266a, 0xbc) +#define EIGHTH_NOTE CHOOSE( 0x0e, 0x266b, 0xbd) +#define SPLAT CHOOSE( 0x0f, 0xa4 , 0xa4) +#define RIGHT_TRIANGLE CHOOSE( 0x10, 0x25b6, '>') +#define LEFT_TRIANGLE CHOOSE( 0x11, 0x25c0, '<') +#define UP_DOWN_ARROW CHOOSE( 0x12, 0x2195, 0x19) +#define DBL_BANG CHOOSE( 0x13, 0x203c, '!') +#define PILCROW CHOOSE( 0x14, 0xb6 , 0xb6) +#define SECTION_SIGN CHOOSE( 0x15, 0xa7 , 0xa7) +#define LOW_QTR_BLOCK CHOOSE( 0x16, 0x25b2, '_') +#define UP_DOWN_ARROW_UNDERSCORED CHOOSE( 0x17, 0x21ab, 0x19) +#define UP_ARROW CHOOSE( 0x18, 0x2191, '^') +#define DOWN_ARROW CHOOSE( 0x19, 0x2193, 'v') +#define RIGHT_ARROW CHOOSE( 0x1a, 0x2192, '>') +#define LEFT_ARROW CHOOSE( 0x1b, 0x2190, '<') +#define RIGHT_ANGLE CHOOSE( 0x1c, 0x221f, 0xe) +#define LEFT_RIGHT_ARROW CHOOSE( 0x1d, 0x2194, '-') +#define UP_TRIANGLE CHOOSE( 0x1e, 0x25b2, '^') +#define DOWN_TRIANGLE CHOOSE( 0x1f, 0x25bc, 'v') + +#define UPPERCASE_C_CEDILLA CHOOSE( 0x80, 0xc7 , 0xc7) +#define LOWERCASE_U_UMLAUT CHOOSE( 0x81, 0xfc , 0xfc) +#define LOWERCASE_E_ACUTE CHOOSE( 0x82, 0xe9 , 0xe9) +#define LOWERCASE_A_CIRCUMFLEX CHOOSE( 0x83, 0xe2 , 0xe2) +#define LOWERCASE_A_UMLAUT CHOOSE( 0x84, 0xe4 , 0xe4) +#define LOWERCASE_A_GRAVE CHOOSE( 0x85, 0xe0 , 0xea) +#define LOWERCASE_A_RING CHOOSE( 0x86, 0xe5 , 0xe5) +#define LOWERCASE_C_CEDILLA CHOOSE( 0x87, 0xe7 , 0xe7) +#define LOWERCASE_E_CIRCUMFLEX CHOOSE( 0x88, 0xea , 0xea) +#define LOWERCASE_E_UMLAUT CHOOSE( 0x89, 0xeb , 0xeb) +#define LOWERCASE_E_GRAVE CHOOSE( 0x8a, 0xe8 , 0xe8) +#define LOWERCASE_I_UMLAUT CHOOSE( 0x8b, 0xef , 0xef) +#define LOWERCASE_I_CIRCUMFLEX CHOOSE( 0x8c, 0xee , 0xee) +#define LOWERCASE_I_GRAVE CHOOSE( 0x8d, 0xec , 0xce) +#define UPPERCASE_A_UMLAUT CHOOSE( 0x8e, 0xc4 , 0xc4) +#define UPPERCASE_A_RING CHOOSE( 0x8f, 0xc5 , 0xc5) + +#define UPPERCASE_E_ACUTE CHOOSE( 0x90, 0xc9 , 0xc9) +#define LOWERCASE_AE_LIGATURE CHOOSE( 0x91, 0xe6 , 0xe6) +#define UPPERCASE_AE_LIGATURE CHOOSE( 0x92, 0xc6 , 0xc6) +#define LOWERCASE_O_CIRCUMFLEX CHOOSE( 0x93, 0xf4 , 0xf4) +#define LOWERCASE_O_UMLAUT CHOOSE( 0x94, 0xf6 , 0xf6) +#define LOWERCASE_O_GRAVE CHOOSE( 0x95, 0xf2 , 0xf2) +#define LOWERCASE_U_CIRCUMFLEX CHOOSE( 0x96, 0xfb , 0xfb) +#define LOWERCASE_U_GRAVE CHOOSE( 0x97, 0xf9 , 0xf9) +#define LOWERCASE_Y_UMLAUT CHOOSE( 0x98, 0xff , 0xff) +#define UPPERCASE_O_UMLAUT CHOOSE( 0x99, 0xd6 , 0xd6) +#define UPPERCASE_U_UMLAUT CHOOSE( 0x9a, 0xdc , 0xdc) +#define CENT_SIGN CHOOSE( 0x9b, 0xa2 , 0xa2) +#define STERLING_SIGN CHOOSE( 0x9c, 0xa3 , 30) +#define YEN_SIGN CHOOSE( 0x9d, 0xa5 , 0xa5) +#define PESETA_SIGN CHOOSE( 0x9e, 0x20a7, TBD) +#define F_WITH_HOOK CHOOSE( 0x9f, 0x0192, TBD) + +#define LOWERCASE_A_ACUTE CHOOSE( 0xa0, 0xe1 , 0xe1) +#define LOWERCASE_I_ACUTE CHOOSE( 0xa1, 0xed , 0xed) +#define LOWERCASE_O_ACUTE CHOOSE( 0xa2, 0xf3 , 0xf3) +#define LOWERCASE_U_ACUTE CHOOSE( 0xa3, 0xfa , 0xfa) +#define LOWERCASE_N_TILDE CHOOSE( 0xa4, 0xf1 , 0xf1) +#define UPPERCASE_N_TILDE CHOOSE( 0xa5, 0xd1 , 0xd1) +#define A_ORDINAL CHOOSE( 0xa6, 0xaa , 0xaa) +#define O_ORDINAL CHOOSE( 0xa7, 0xba , 0xba) +#define INVERTED_QUESTION_MARK CHOOSE( 0xa8, 0xbf , 0xbf) +#define REVERSED_NOT_SIGN CHOOSE( 0xa9, 0x2310, TBD) +#define NOT_SIGN CHOOSE( 0xaa, 0xac , 0xac) +#define VULGAR_HALF CHOOSE( 0xab, 0xbd , 0xbd) +#define VULGAR_QUARTER CHOOSE( 0xac, 0xbc , 0xbc) +#define INVERTED_EXCLAMATION_MARK CHOOSE( 0xad, 0xa1 , 0xa1) +#define LEFT_ANGLE_QUOTE_MARK CHOOSE( 0xae, 0xab , 0xab) +#define RIGHT_ANGLE_QUOTE_MARK CHOOSE( 0xaf, 0xbb , 0xbb) + +#define LIGHT_SHADE CHOOSE( 0xb0, 0x2591, '#' ) +#define MEDIUM_SHADE CHOOSE( 0xb1, 0x2592, 2) +#define DARK_SHADE CHOOSE( 0xb2, 0x2593, TBD) +#define BOX_VLINE CHOOSE( 0xb3, 0x2502, 25) +#define BOX_RTEE CHOOSE( 0xb4, 0x2524, 22) +#define BOX_SD_RTEE CHOOSE( 0xb5, 0x2561, 22) +#define BOX_DS_RTEE CHOOSE( 0xb6, 0x2562, 22) +#define BOX_DS_URCORNER CHOOSE( 0xb7, 0x2556, 12) +#define BOX_SD_URCORNER CHOOSE( 0xb8, 0x2555, 12) +#define BOX_D_RTEE CHOOSE( 0xb9, 0x2563, 22) +#define BOX_D_VLINE CHOOSE( 0xba, 0x2551, 25) +#define BOX_D_URCORNER CHOOSE( 0xbb, 0x2557, 12) +#define BOX_D_LRCORNER CHOOSE( 0xbc, 0x255D, 11) +#define BOX_DS_LRCORNER CHOOSE( 0xbd, 0x255c, 11) +#define BOX_SD_LRCORNER CHOOSE( 0xbe, 0x255b, 11) +#define BOX_URCORNER CHOOSE( 0xbf, 0x2510, 12) + +#define BOX_LLCORNER CHOOSE( 0xc0, 0x2514, 14) +#define BOX_BTEE CHOOSE( 0xc1, 0x2534, 23) +#define BOX_TTEE CHOOSE( 0xc2, 0x252c, 24) +#define BOX_LTEE CHOOSE( 0xc3, 0x251c, 21) +#define BOX_HLINE CHOOSE( 0xc4, 0x2500, 18) +#define BOX_PLUS CHOOSE( 0xc5, 0x253c, 15) +#define BOX_SD_LTEE CHOOSE( 0xc6, 0x255e, 21) +#define BOX_DS_LTEE CHOOSE( 0xc7, 0x255f, 21) +#define BOX_D_LLCORNER CHOOSE( 0xc8, 0x255A, 14) +#define BOX_D_ULCORNER CHOOSE( 0xc9, 0x2554, 13) +#define BOX_D_BTEE CHOOSE( 0xca, 0x2569, 23) +#define BOX_D_TTEE CHOOSE( 0xcb, 0x2566, 24) +#define BOX_D_LTEE CHOOSE( 0xcc, 0x2560, 21) +#define BOX_D_HLINE CHOOSE( 0xcd, 0x2550, 18) +#define BOX_D_PLUS CHOOSE( 0xce, 0x256C, 15) +#define BOX_SD_BTEE CHOOSE( 0xcf, 0x2567, 23) + +#define BOX_DS_BTEE CHOOSE( 0xd0, 0x2568, 23) +#define BOX_SD_TTEE CHOOSE( 0xd1, 0x2564, 24) +#define BOX_DS_TTEE CHOOSE( 0xd2, 0x2565, 24) +#define BOX_DS_LLCORNER CHOOSE( 0xd3, 0x2559, 14) +#define BOX_SD_LLCORNER CHOOSE( 0xd4, 0x2558, 14) +#define BOX_SD_ULCORNER CHOOSE( 0xd5, 0x2552, 13) +#define BOX_DS_ULCORNER CHOOSE( 0xd6, 0x2553, 13) +#define BOX_DS_PLUS CHOOSE( 0xd7, 0x256b, 15) +#define BOX_SD_PLUS CHOOSE( 0xd8, 0x256a, 15) +#define BOX_LRCORNER CHOOSE( 0xd9, 0x2518, 11) +#define BOX_ULCORNER CHOOSE( 0xda, 0x250c, 13) +#define FULL_BLOCK CHOOSE( 0xdb, 0x2588, 0) +#define LOWER_HALF_BLOCK CHOOSE( 0xdc, 0x2584, TBD) +#define LEFT_HALF_BLOCK CHOOSE( 0xdd, 0x258c, TBD) +#define RIGHT_HALF_BLOCK CHOOSE( 0xde, 0x2590, TBD) +#define UPPER_HALF_BLOCK CHOOSE( 0xdf, 0x2580, TBD) + +#define ALPHA CHOOSE( 0xe0, 0x03b1, TBD) +#define BETA CHOOSE( 0xe1, 0x00df, TBD) +#define GAMMA CHOOSE( 0xe2, 0x0393, TBD) +#define PI CHOOSE( 0xe3, 0x03c0, 28) +#define UPPERCASE_SIGMA CHOOSE( 0xe4, 0x03a3, TBD) +#define LOWERCASE_SIGMA CHOOSE( 0xe5, 0x03c3, TBD) +#define MU CHOOSE( 0xe6, 0x00b5, 0xb5) +#define TAU CHOOSE( 0xe7, 0x03c4, TBD) +#define UPPERCASE_PHI CHOOSE( 0xe8, 0x03a6, TBD) +#define THETA CHOOSE( 0xe9, 0x0398, TBD) +#define OMEGA CHOOSE( 0xea, 0x03a9, TBD) +#define DELTA CHOOSE( 0xeb, 0x03b4, TBD) +#define INFINITY_SIGN CHOOSE( 0xec, 0x221e, TBD) +#define LOWERCASE_PHI CHOOSE( 0xed, 0x03c6, TBD) +#define EPSILON CHOOSE( 0xee, 0x03b5, TBD) +#define INTERSECTION CHOOSE( 0xef, 0x2229, TBD) + +#define TRIPLE_BAR CHOOSE( 0xf0, 0x2261, TBD) +#define PLUS_OR_MINUS CHOOSE( 0xf1, 0x00b1, 8) +#define GREATER_THAN_OR_EQUAL_TO CHOOSE( 0xf2, 0x2265, 27) +#define LESSER_THAN_OR_EQUAL_TO CHOOSE( 0xf3, 0x2264, 26) +#define UPPER_HALF_INTEGRAL_SIGN CHOOSE( 0xf4, 0x2320, TBD) +#define LOWER_HALF_INTEGRAL_SIGN CHOOSE( 0xf5, 0x2321, TBD) +#define DIVISION_SIGN CHOOSE( 0xf6, 0x00f7, 0xf7) +#define APPROXIMATELY_EQUALS_SIGN CHOOSE( 0xf7, 0x2248, TBD) +#define DEGREE_SIGN CHOOSE( 0xf8, 0x00b0, 0xb0) +#define LARGE_BULLET CHOOSE( 0xf9, 0x2219, 7) +#define SMALL_BULLET CHOOSE( 0xfa, 0x00b7, 0xb7) +#define SQUARE_ROOT CHOOSE( 0xfb, 0x221a, TBD) +#define SUPERSCRIPT_N CHOOSE( 0xfc, 0x207f, TBD) +#define SUPERSCRIPT_2 CHOOSE( 0xfd, 0x00b2, 0xb2) +#define CENTERED_SQUARE CHOOSE( 0xfe, 0x25a0, TBD) +#define NON_BREAKING_SPACE CHOOSE( 0xff, 0x00a0, TBD) + + + + /* It says at http://unicode.org/charts/PDF/U2300.pdf */ + /* that '...the scan line numbers here refer to old, */ + /* low-resolution technology for terminals, with only */ + /* nine scan lines per fixed-size character glyph. */ + /* Even-numbered scan lines are unified with box */ + /* drawing graphics." */ + /* The utility of these is questionable; they'd */ + /* work Just Fine in wingdi (_if_ the appropriate */ + /* glyphs are available), but not elsewhere. */ +#define HORIZ_SCAN_LINE_1 CHOOSE( 0x2d, 0x23ba, 16) +#define HORIZ_SCAN_LINE_3 CHOOSE( 0x2d, 0x23bb, 17) +#define HORIZ_SCAN_LINE_7 CHOOSE( 0x2d, 0x23bc, 19) +#define HORIZ_SCAN_LINE_9 CHOOSE( '_', 0x23bd, 20) + + /* Code page 437 lacks a 'for real' not-equals, so for that, */ + /* we use the double-horizontal single-vertical box drawing : */ +#define NOT_EQUALS_SIGN CHOOSE( 0xd8, 0x2260, 29) + +# define A(x) ((chtype)x | A_ALTCHARSET) + +chtype acs_map[128] = +{ + A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), + A(9), A(10), + CLUB, HEART, SPADE, SMILE, REV_SMILE, /* 11 12 13 14 15 */ + MEDIUM_BULLET, WHITE_BULLET, PILCROW, SECTION_SIGN, /* 16 17 18 19 */ + A_ORDINAL, O_ORDINAL, LOWERCASE_PHI, /* 20 21 22 */ + INVERTED_EXCLAMATION_MARK, INVERTED_QUESTION_MARK, /* 23 24 */ + REVERSED_NOT_SIGN, NOT_SIGN, /* 25 26 */ + UPPER_HALF_INTEGRAL_SIGN, LOWER_HALF_INTEGRAL_SIGN, /* 27 28 */ + SUPERSCRIPT_N, CENTERED_SQUARE, F_WITH_HOOK, /* 29 30 31 */ + + RIGHT_ARROW, LEFT_ARROW, UP_ARROW, DOWN_ARROW, /* 32 !"# */ + + PI, NOT_EQUALS_SIGN, VULGAR_HALF, VULGAR_QUARTER, /* $%&' */ + '(', + LEFT_ANGLE_QUOTE_MARK, RIGHT_ANGLE_QUOTE_MARK, /* )* */ + DARK_SHADE, SUPERSCRIPT_2, INFINITY_SIGN, /* +,- */ + ALPHA, BETA, GAMMA, UPPERCASE_SIGMA, LOWERCASE_SIGMA, /* ./012 */ + '3', + MU, TAU, UPPERCASE_PHI, THETA, OMEGA, DELTA, EPSILON, /* 456789: */ + + BOX_SD_LRCORNER, BOX_SD_URCORNER, BOX_SD_ULCORNER, /* ;<= */ + BOX_SD_LLCORNER, BOX_SD_PLUS, /* >? */ + BOX_SD_LTEE, BOX_SD_RTEE, BOX_SD_BTEE, BOX_SD_TTEE, /* @ABC */ + + BOX_D_LRCORNER, BOX_D_URCORNER, BOX_D_ULCORNER, /* DEF */ + BOX_D_LLCORNER, BOX_D_PLUS, /* GH */ + BOX_D_LTEE, BOX_D_RTEE, BOX_D_BTEE, BOX_D_TTEE, /* IJKL */ + + BOX_DS_LRCORNER, BOX_DS_URCORNER, BOX_DS_ULCORNER, /* MNO */ + BOX_DS_LLCORNER, BOX_DS_PLUS, /* PQ */ + BOX_DS_LTEE, BOX_DS_RTEE, BOX_DS_BTEE, BOX_DS_TTEE, /* RSTU */ + + BOX_LRCORNER, BOX_URCORNER, BOX_ULCORNER, /* VWX */ + BOX_LLCORNER, BOX_PLUS, /* YZ */ + BOX_LTEE, BOX_RTEE, BOX_BTEE, BOX_TTEE, /* [\]^ */ + + BOX_HLINE, BOX_VLINE, BOX_D_HLINE, BOX_D_VLINE, /* _`ab */ + + DIVISION_SIGN, APPROXIMATELY_EQUALS_SIGN, /* cd */ + INTERSECTION, TRIPLE_BAR, /* ef */ + SMALL_BULLET, LARGE_BULLET, SQUARE_ROOT, /* ghi */ + DIAMOND, MEDIUM_SHADE, /* jk */ + HORIZ_SCAN_LINE_1, HORIZ_SCAN_LINE_3, /* lm */ + HORIZ_SCAN_LINE_7, HORIZ_SCAN_LINE_9, /* no */ + UPPER_HALF_BLOCK, LOWER_HALF_BLOCK, /* pq */ + LEFT_HALF_BLOCK, RIGHT_HALF_BLOCK, FULL_BLOCK, /* rst */ + LESSER_THAN_OR_EQUAL_TO, GREATER_THAN_OR_EQUAL_TO, /* uv */ + DEGREE_SIGN, PLUS_OR_MINUS, LIGHT_SHADE, SPLAT, /* wxyz */ + CENT_SIGN, YEN_SIGN, PESETA_SIGN, STERLING_SIGN, /* {|}~ */ + A(127) +}; + +# undef A diff --git a/src/cc/rogue/x86_64-w64-msvc/deps/install/include/curses.h b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/curses.h new file mode 100644 index 000000000..9ee3f08a6 --- /dev/null +++ b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/curses.h @@ -0,0 +1,1846 @@ +/* Public Domain Curses */ + +/*----------------------------------------------------------------------* + * PDCurses * + *----------------------------------------------------------------------*/ + +#ifndef __PDCURSES__ +#define __PDCURSES__ 1 + +/*man-start************************************************************** + +PDCurses definitions list: (Only define those needed) + + XCURSES True if compiling for X11. + PDC_RGB True if you want to use RGB color definitions + (Red = 1, Green = 2, Blue = 4) instead of BGR. + PDC_WIDE True if building wide-character support. + PDC_DLL_BUILD True if building a Windows DLL. + PDC_NCMOUSE Use the ncurses mouse API instead + of PDCurses' traditional mouse API. + +PDCurses portable platform definitions list: + + PDC_BUILD Defines API build version. + PDCURSES Enables access to PDCurses-only routines. + XOPEN Always true. + SYSVcurses True if you are compiling for SYSV portability. + BSDcurses True if you are compiling for BSD portability. + +**man-end****************************************************************/ + +#define PDCURSES 1 /* PDCurses-only routines */ +#define XOPEN 1 /* X/Open Curses routines */ +#define SYSVcurses 1 /* System V Curses routines */ +#define BSDcurses 1 /* BSD Curses routines */ +#if defined( CHTYPE_32) + #define CHTYPE_LONG 1 /* chtypes will be 32 bits */ +#elif !defined( CHTYPE_16) + #define CHTYPE_LONG 2 /* chtypes will be (default) 64 bits */ +#endif + +/*----------------------------------------------------------------------*/ + +#ifdef NO_STDINT_H + #define uint64_t unsigned long long + #define uint32_t unsigned long + #define uint16_t unsigned short +#else + #include +#endif +#include +#include +#include /* Required by X/Open usage below */ + +#ifdef PDC_WIDE +# include +#endif + +#if defined(__STDC_VERSION__) && __STDC_VERSION >= 199901L && \ + !defined(__bool_true_false_are_defined) +# include +#endif + +#ifdef __cplusplus +extern "C" +{ +# define bool _bool +#endif + +/*---------------------------------------------------------------------- + * + * Constants and Types + * + */ + +#undef FALSE +#undef TRUE + +#ifdef __bool_true_false_are_defined + +# define FALSE false +# define TRUE true + +#else + +typedef unsigned char bool; + +# define FALSE 0 +# define TRUE 1 + +#endif + +#undef ERR +#define ERR (-1) + +#undef OK +#define OK 0 + +#ifdef CHTYPE_LONG + #if(CHTYPE_LONG >= 2) /* "non-standard" 64-bit chtypes */ + typedef uint64_t chtype; + #else /* "Standard" CHTYPE_LONG case, 32-bit: */ + typedef uint32_t chtype; + # endif +#else +typedef uint16_t chtype; /* 8-bit attr + 8-bit char */ +#endif + +#ifdef PDC_WIDE +typedef chtype cchar_t; +#endif + +typedef chtype attr_t; + +/* Version constants, available as of version 4.0 : */ +/* Don't forget to update 'version.mif' if MAJOR/MINOR changes! */ + +#define PDC_VER_MAJOR 4 +#define PDC_VER_MINOR 0 +#define PDC_VER_CHANGE 4 +#define PDC_VER_YEAR 2019 +#define PDC_VER_MONTH 1 +#define PDC_VER_DAY 20 + +#define PDC_BUILD (PDC_VER_MAJOR*1000 + PDC_VER_MINOR *100 + PDC_VER_CHANGE) + +/* When using PDCurses as a DLL (Windows) or shared library (BSD or *nix), +it's possible to switch the DLL or shared library. One may therefore want +to inquire of the DLL/shared library the port, version numbers, and +chtype_size used, and make sure they're what one was expecting. The +'PDC_version' structure lets you do just that. */ + +enum PDC_port +{ + PDC_PORT_X11 = 0, + PDC_PORT_WIN32 = 1, + PDC_PORT_WINGUI = 2, + PDC_PORT_DOS = 3, + PDC_PORT_OS2 = 4, + PDC_PORT_SDL1 = 5, + PDC_PORT_SDL2 = 6, + PDC_PORT_VT = 7 +}; + +/* Detailed PDC version information */ +#define PDC_HAS_VERSION_INFO 1 +typedef struct +{ + const enum PDC_port port; + const int ver_major; + const int ver_minor; + const int ver_change; + const size_t chtype_size; + const bool is_wide; + const bool is_forced_utf8; +} PDC_version_info; + +/*---------------------------------------------------------------------- + * + * Mouse Interface -- SYSVR4, with extensions + * + */ + +/* Most flavors of PDCurses support three buttons. WinGUI supports */ +/* these plus two "extended" buttons. But we'll set this macro to */ +/* six, allowing future versions to support up to nine total buttons. */ +/* (The button states are broken up into two arrays to allow for the */ +/* possibility of backward compatibility to DLLs compiled with only */ +/* three mouse buttons.) */ + +#define PDC_MAX_MOUSE_BUTTONS 9 +#define PDC_N_EXTENDED_MOUSE_BUTTONS 6 + +typedef struct +{ + int x; /* absolute column, 0 based, measured in characters */ + int y; /* absolute row, 0 based, measured in characters */ + short button[3]; /* state of three "normal" buttons */ + int changes; /* flags indicating what has changed with the mouse */ + short xbutton[PDC_N_EXTENDED_MOUSE_BUTTONS]; /* state of ext buttons */ +} MOUSE_STATUS; + +#define BUTTON_RELEASED 0x0000 +#define BUTTON_PRESSED 0x0001 +#define BUTTON_CLICKED 0x0002 +#define BUTTON_DOUBLE_CLICKED 0x0003 +#define BUTTON_TRIPLE_CLICKED 0x0004 +#define BUTTON_MOVED 0x0005 /* PDCurses */ +#define WHEEL_SCROLLED 0x0006 /* PDCurses */ +#define BUTTON_ACTION_MASK 0x0007 /* PDCurses */ + +#define PDC_BUTTON_SHIFT 0x0008 /* PDCurses */ +#define PDC_BUTTON_CONTROL 0x0010 /* PDCurses */ +#define PDC_BUTTON_ALT 0x0020 /* PDCurses */ +#define BUTTON_MODIFIER_MASK 0x0038 /* PDCurses */ + +#define MOUSE_X_POS (Mouse_status.x) +#define MOUSE_Y_POS (Mouse_status.y) + +/* + * Bits associated with the .changes field: + * 3 2 1 0 + * 210987654321098765432109876543210 + * 1 <- button 1 has changed 0 + * 10 <- button 2 has changed 1 + * 100 <- button 3 has changed 2 + * 1000 <- mouse has moved 3 + * 10000 <- mouse position report 4 + * 100000 <- mouse wheel up 5 + * 1000000 <- mouse wheel down 6 + * 10000000 <- mouse wheel left 7 + * 100000000 <- mouse wheel right 8 + * 1000000000 <- button 4 has changed 9 + * (NOTE: buttons 6 to 10000000000 <- button 5 has changed 10 + * 9 aren't implemented 100000000000 <- button 6 has changed 11 + * in any flavor of 1000000000000 <- button 7 has changed 12 + * PDCurses yet!) 10000000000000 <- button 8 has changed 13 + * 100000000000000 <- button 9 has changed 14 + */ + +#define PDC_MOUSE_MOVED 0x0008 +#define PDC_MOUSE_POSITION 0x0010 +#define PDC_MOUSE_WHEEL_UP 0x0020 +#define PDC_MOUSE_WHEEL_DOWN 0x0040 +#define PDC_MOUSE_WHEEL_LEFT 0x0080 +#define PDC_MOUSE_WHEEL_RIGHT 0x0100 + +#define A_BUTTON_CHANGED (Mouse_status.changes & 7) +#define MOUSE_MOVED (Mouse_status.changes & PDC_MOUSE_MOVED) +#define MOUSE_POS_REPORT (Mouse_status.changes & PDC_MOUSE_POSITION) +#define BUTTON_CHANGED(x) (Mouse_status.changes & (1 << ((x) - ((x)<4 ? 1 : -5)))) +#define BUTTON_STATUS(x) (Mouse_status.button[(x) - 1]) +#define MOUSE_WHEEL_UP (Mouse_status.changes & PDC_MOUSE_WHEEL_UP) +#define MOUSE_WHEEL_DOWN (Mouse_status.changes & PDC_MOUSE_WHEEL_DOWN) +#define MOUSE_WHEEL_LEFT (Mouse_status.changes & PDC_MOUSE_WHEEL_LEFT) +#define MOUSE_WHEEL_RIGHT (Mouse_status.changes & PDC_MOUSE_WHEEL_RIGHT) + +/* mouse bit-masks */ + +#define BUTTON1_RELEASED 0x00000001L +#define BUTTON1_PRESSED 0x00000002L +#define BUTTON1_CLICKED 0x00000004L +#define BUTTON1_DOUBLE_CLICKED 0x00000008L +#define BUTTON1_TRIPLE_CLICKED 0x00000010L +#define BUTTON1_MOVED 0x00000010L /* PDCurses */ + +#define BUTTON2_RELEASED 0x00000020L +#define BUTTON2_PRESSED 0x00000040L +#define BUTTON2_CLICKED 0x00000080L +#define BUTTON2_DOUBLE_CLICKED 0x00000100L +#define BUTTON2_TRIPLE_CLICKED 0x00000200L +#define BUTTON2_MOVED 0x00000200L /* PDCurses */ + +#define BUTTON3_RELEASED 0x00000400L +#define BUTTON3_PRESSED 0x00000800L +#define BUTTON3_CLICKED 0x00001000L +#define BUTTON3_DOUBLE_CLICKED 0x00002000L +#define BUTTON3_TRIPLE_CLICKED 0x00004000L +#define BUTTON3_MOVED 0x00004000L /* PDCurses */ + +/* For the ncurses-compatible functions only, BUTTON4_PRESSED and + BUTTON5_PRESSED are returned for mouse scroll wheel up and down; + otherwise PDCurses doesn't support buttons 4 and 5... except + as described above for WinGUI, and perhaps to be extended to + other PDCurses flavors */ + +#define BUTTON4_RELEASED 0x00008000L +#define BUTTON4_PRESSED 0x00010000L +#define BUTTON4_CLICKED 0x00020000L +#define BUTTON4_DOUBLE_CLICKED 0x00040000L +#define BUTTON4_TRIPLE_CLICKED 0x00080000L + +#define BUTTON5_RELEASED 0x00100000L +#define BUTTON5_PRESSED 0x00200000L +#define BUTTON5_CLICKED 0x00400000L +#define BUTTON5_DOUBLE_CLICKED 0x00800000L +#define BUTTON5_TRIPLE_CLICKED 0x01000000L + +#define MOUSE_WHEEL_SCROLL 0x02000000L /* PDCurses */ +#define BUTTON_MODIFIER_SHIFT 0x04000000L /* PDCurses */ +#define BUTTON_MODIFIER_CONTROL 0x08000000L /* PDCurses */ +#define BUTTON_MODIFIER_ALT 0x10000000L /* PDCurses */ + +#define ALL_MOUSE_EVENTS 0x1fffffffL +#define REPORT_MOUSE_POSITION 0x20000000L + +/* ncurses mouse interface */ + +typedef unsigned long mmask_t; + +typedef struct +{ + short id; /* unused, always 0 */ + int x, y, z; /* x, y same as MOUSE_STATUS; z unused */ + mmask_t bstate; /* equivalent to changes + button[], but + in the same format as used for mousemask() */ +} MEVENT; + +#if defined(PDC_NCMOUSE) && !defined(NCURSES_MOUSE_VERSION) +# define NCURSES_MOUSE_VERSION 2 +#endif + +#ifdef NCURSES_MOUSE_VERSION +# define BUTTON_SHIFT BUTTON_MODIFIER_SHIFT +# define BUTTON_CONTROL BUTTON_MODIFIER_CONTROL +# define BUTTON_CTRL BUTTON_MODIFIER_CONTROL +# define BUTTON_ALT BUTTON_MODIFIER_ALT +#else +# define BUTTON_SHIFT PDC_BUTTON_SHIFT +# define BUTTON_CONTROL PDC_BUTTON_CONTROL +# define BUTTON_ALT PDC_BUTTON_ALT +#endif + +/*---------------------------------------------------------------------- + * + * Window and Screen Structures + * + */ + +typedef struct _win /* definition of a window */ +{ + int _cury; /* current pseudo-cursor */ + int _curx; + int _maxy; /* max window coordinates */ + int _maxx; + int _begy; /* origin on screen */ + int _begx; + int _flags; /* window properties */ + chtype _attrs; /* standard attributes and colors */ + chtype _bkgd; /* background, normally blank */ + bool _clear; /* causes clear at next refresh */ + bool _leaveit; /* leaves cursor where it is */ + bool _scroll; /* allows window scrolling */ + bool _nodelay; /* input character wait flag */ + bool _immed; /* immediate update flag */ + bool _sync; /* synchronise window ancestors */ + bool _use_keypad; /* flags keypad key mode active */ + chtype **_y; /* pointer to line pointer array */ + int *_firstch; /* first changed character in line */ + int *_lastch; /* last changed character in line */ + int _tmarg; /* top of scrolling region */ + int _bmarg; /* bottom of scrolling region */ + int _delayms; /* milliseconds of delay for getch() */ + int _parx, _pary; /* coords relative to parent (0,0) */ + struct _win *_parent; /* subwin's pointer to parent win */ +} WINDOW; + +/* Avoid using the SCREEN struct directly -- use the corresponding + functions if possible. This struct may eventually be made private. */ + +typedef struct +{ + bool alive; /* if initscr() called, and not endwin() */ + bool autocr; /* if cr -> lf */ + bool cbreak; /* if terminal unbuffered */ + bool echo; /* if terminal echo */ + bool raw_inp; /* raw input mode (v. cooked input) */ + bool raw_out; /* raw output mode (7 v. 8 bits) */ + bool audible; /* FALSE if the bell is visual */ + bool mono; /* TRUE if current screen is mono */ + bool resized; /* TRUE if TERM has been resized */ + bool orig_attr; /* TRUE if we have the original colors */ + short orig_fore; /* original screen foreground color */ + short orig_back; /* original screen foreground color */ + int cursrow; /* position of physical cursor */ + int curscol; /* position of physical cursor */ + int visibility; /* visibility of cursor */ + int orig_cursor; /* original cursor size */ + int lines; /* new value for LINES */ + int cols; /* new value for COLS */ + unsigned long _trap_mbe; /* trap these mouse button events */ + unsigned long _map_mbe_to_key; /* map mouse buttons to slk */ + int mouse_wait; /* time to wait (in ms) for a + button release after a press, in + order to count it as a click */ + int slklines; /* lines in use by slk_init() */ + WINDOW *slk_winptr; /* window for slk */ + int linesrippedoff; /* lines ripped off via ripoffline() */ + int linesrippedoffontop; /* lines ripped off on + top via ripoffline() */ + int delaytenths; /* 1/10ths second to wait block + getch() for */ + bool _preserve; /* TRUE if screen background + to be preserved */ + int _restore; /* specifies if screen background + to be restored, and how */ + bool save_key_modifiers; /* TRUE if each key modifiers saved + with each key press */ + bool return_key_modifiers; /* TRUE if modifier keys are + returned as "real" keys */ + bool key_code; /* TRUE if last key is a special key; + used internally by get_wch() */ +#ifdef XCURSES + int XcurscrSize; /* size of Xcurscr shared memory block */ + bool sb_on; + int sb_viewport_y; + int sb_viewport_x; + int sb_total_y; + int sb_total_x; + int sb_cur_y; + int sb_cur_x; + int exit_key; +#endif + short line_color; /* color of line attributes - default -1 */ +} SCREEN; + +/*---------------------------------------------------------------------- + * + * External Variables + * + */ + +#ifdef PDC_DLL_BUILD +# ifdef CURSES_LIBRARY +# define PDCEX __declspec(dllexport) extern +# else +# define PDCEX __declspec(dllimport) +# endif +#else +# define PDCEX extern +#endif + +PDCEX int LINES; /* terminal height */ +PDCEX int COLS; /* terminal width */ +PDCEX WINDOW *stdscr; /* the default screen window */ +PDCEX WINDOW *curscr; /* the current screen image */ +PDCEX SCREEN *SP; /* curses variables */ +PDCEX MOUSE_STATUS Mouse_status; +PDCEX int COLORS; +PDCEX int COLOR_PAIRS; +PDCEX int TABSIZE; +PDCEX chtype acs_map[]; /* alternate character set map */ +PDCEX char ttytype[]; /* terminal name/description */ +PDCEX PDC_version_info PDC_version; + +/*man-start************************************************************** + +Text Attributes +=============== + +Originally, PDCurses used a short (16 bits) for its chtype. To include +color, a number of things had to be sacrificed from the strict Unix and +System V support. The main problem was fitting all character attributes +and color into an unsigned char (all 8 bits!). + +Today, PDCurses by default uses a long (32 bits) for its chtype, as in +System V. The short chtype is still available, by undefining CHTYPE_LONG +and rebuilding the library. + +The following is the structure of a win->_attrs chtype: + +short form: + + +-----------------------------------------------+ + |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + +-----------------------------------------------+ + color number | attrs | character eg 'a' + +The available non-color attributes are bold, reverse and blink. Others +have no effect. The high order char is an index into an array of +physical colors (defined in color.c) -- 32 foreground/background color +pairs (5 bits) plus 3 bits for other attributes. + +long form: + + +--------------------------------------------------------------------+ + |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|..| 2| 1| 0| + +--------------------------------------------------------------------+ + color number | modifiers | character eg 'a' + +The available non-color attributes are bold, underline, invisible, +right-line, left-line, protect, reverse and blink. 256 color pairs (8 +bits), 8 bits for other attributes, and 16 bits for character data. + + Note that there is now a "super-long" 64-bit form, available by +defining CHTYPE_LONG to be 2: + +------------------------------------------------------------------------------- +|63|62|61|60|59|..|34|33|32|31|30|29|28|..|22|21|20|19|18|17|16|..| 3| 2| 1| 0| +------------------------------------------------------------------------------- + color number | modifiers | character eg 'a' + + + We take five more bits for the character (thus allowing Unicode values +past 64K; UTF-16 can go up to 0x10ffff, requiring 21 bits total), and +four more bits for attributes. Three are currently used as A_OVERLINE, A_DIM, +and A_STRIKEOUT; one more is reserved for future use. 31 bits are then used +for color. These are usually just treated as the usual palette +indices, and range from 0 to 255. However, if bit 63 is +set, the remaining 30 bits are interpreted as foreground RGB (first +fifteen bits, five bits for each of the three channels) and background RGB +(same scheme using the remaining 15 bits.) + +**man-end****************************************************************/ + +/*** Video attribute macros ***/ + +#define A_NORMAL (chtype)0 + +#ifdef CHTYPE_LONG + +# if(CHTYPE_LONG >= 2) /* 64-bit chtypes */ + # define PDC_CHARTEXT_BITS 21 + # define A_CHARTEXT (chtype)( ((chtype)0x1 << PDC_CHARTEXT_BITS) - 1) + # define A_ALTCHARSET ((chtype)0x001 << PDC_CHARTEXT_BITS) + # define A_RIGHTLINE ((chtype)0x002 << PDC_CHARTEXT_BITS) + # define A_LEFTLINE ((chtype)0x004 << PDC_CHARTEXT_BITS) + # define A_INVIS ((chtype)0x008 << PDC_CHARTEXT_BITS) + # define A_UNDERLINE ((chtype)0x010 << PDC_CHARTEXT_BITS) + # define A_REVERSE ((chtype)0x020 << PDC_CHARTEXT_BITS) + # define A_BLINK ((chtype)0x040 << PDC_CHARTEXT_BITS) + # define A_BOLD ((chtype)0x080 << PDC_CHARTEXT_BITS) + # define A_OVERLINE ((chtype)0x100 << PDC_CHARTEXT_BITS) + # define A_STRIKEOUT ((chtype)0x200 << PDC_CHARTEXT_BITS) + # define A_DIM ((chtype)0x400 << PDC_CHARTEXT_BITS) +#if 0 + /* May come up with a use for this bit */ + /* someday; reserved for the future: */ + # define A_FUTURE_2 ((chtype)0x800 << PDC_CHARTEXT_BITS) +#endif + # define PDC_COLOR_SHIFT (PDC_CHARTEXT_BITS + 12) + # define A_COLOR ((chtype)0x7fffffff << PDC_COLOR_SHIFT) + # define A_RGB_COLOR ((chtype)0x40000000 << PDC_COLOR_SHIFT) + # define A_ATTRIBUTES (((chtype)0xfff << PDC_CHARTEXT_BITS) | A_COLOR) + # define A_RGB( rfore, gfore, bfore, rback, gback, bback) \ + (( (((chtype)(bfore) << 25) \ + | ((chtype)(gfore) << 20) \ + | ((chtype)(rfore) << 15) \ + | ((chtype)(bback) << 10) \ + | ((chtype)(gback) << 5) \ + | ((chtype)(rback) )) << PDC_COLOR_SHIFT) | A_RGB_COLOR) +# else /* plain ol' 32-bit chtypes */ + # define A_ALTCHARSET (chtype)0x00010000 + # define A_RIGHTLINE (chtype)0x00020000 + # define A_LEFTLINE (chtype)0x00040000 + # define A_INVIS (chtype)0x00080000 + # define A_UNDERLINE (chtype)0x00100000 + # define A_REVERSE (chtype)0x00200000 + # define A_BLINK (chtype)0x00400000 + # define A_BOLD (chtype)0x00800000 + # define A_COLOR (chtype)0xff000000 + # define A_RGB_COLOR A_NORMAL +#ifdef PDC_WIDE + # define A_CHARTEXT (chtype)0x0000ffff + # define A_ATTRIBUTES (chtype)0xffff0000 + # define A_DIM A_NORMAL + # define A_OVERLINE A_NORMAL + # define A_STRIKEOUT A_NORMAL +#else /* with 8-bit chars, we have bits for these attribs : */ + # define A_CHARTEXT (chtype)0x000000ff + # define A_ATTRIBUTES (chtype)0xffffe000 + # define A_DIM (chtype)0x00008000 + # define A_OVERLINE (chtype)0x00004000 + # define A_STRIKEOUT (chtype)0x00002000 +#endif + # define PDC_COLOR_SHIFT 24 +#endif + + +# define A_ITALIC A_INVIS +# define A_PROTECT (A_UNDERLINE | A_LEFTLINE | A_RIGHTLINE) + +#else /* 16-bit chtypes */ +# define A_BOLD (chtype)0x0100 /* X/Open */ +# define A_REVERSE (chtype)0x0200 /* X/Open */ +# define A_BLINK (chtype)0x0400 /* X/Open */ + +# define A_ATTRIBUTES (chtype)0xff00 /* X/Open */ +# define A_CHARTEXT (chtype)0x00ff /* X/Open */ +# define A_COLOR (chtype)0xf800 /* System V */ + +# define A_ALTCHARSET A_NORMAL /* X/Open */ +# define A_PROTECT A_NORMAL /* X/Open */ +# define A_UNDERLINE A_NORMAL /* X/Open */ +# define A_OVERLINE A_NORMAL /* X/Open */ +# define A_STRIKEOUT A_NORMAL /* X/Open */ + +# define A_LEFTLINE A_NORMAL +# define A_RIGHTLINE A_NORMAL +# define A_ITALIC A_NORMAL +# define A_INVIS A_NORMAL +# define A_RGB_COLOR A_NORMAL +# define A_DIM A_NORMAL + +# define PDC_COLOR_SHIFT 11 +#endif + +#define A_STANDOUT (A_REVERSE | A_BOLD) /* X/Open */ + +#define CHR_MSK A_CHARTEXT /* Obsolete */ +#define ATR_MSK A_ATTRIBUTES /* Obsolete */ +#define ATR_NRM A_NORMAL /* Obsolete */ + +/* For use with attr_t -- X/Open says, "these shall be distinct", so + this is a non-conforming implementation. */ + +#define WA_NORMAL A_NORMAL + +#define WA_ALTCHARSET A_ALTCHARSET +#define WA_BLINK A_BLINK +#define WA_BOLD A_BOLD +#define WA_DIM A_DIM +#define WA_INVIS A_INVIS +#define WA_LEFT A_LEFTLINE +#define WA_PROTECT A_PROTECT +#define WA_REVERSE A_REVERSE +#define WA_RIGHT A_RIGHTLINE +#define WA_STANDOUT A_STANDOUT +#define WA_UNDERLINE A_UNDERLINE + +#define WA_HORIZONTAL A_NORMAL +#define WA_LOW A_NORMAL +#define WA_TOP A_NORMAL +#define WA_VERTICAL A_NORMAL + +#define WA_ATTRIBUTES A_ATTRIBUTES + +/*** Alternate character set macros ***/ + +/* 'w' = 32-bit chtype; acs_map[] index | A_ALTCHARSET + 'n' = 16-bit chtype; it gets the fallback set because no bit is + available for A_ALTCHARSET */ + +#ifdef CHTYPE_LONG +# define PDC_ACS(w, n) ((chtype)w | A_ALTCHARSET) +#else +# define PDC_ACS(w, n) ((chtype)n) +#endif + +/* VT100-compatible symbols -- box chars */ + +#define ACS_LRCORNER PDC_ACS('V', '+') +#define ACS_URCORNER PDC_ACS('W', '+') +#define ACS_ULCORNER PDC_ACS('X', '+') +#define ACS_LLCORNER PDC_ACS('Y', '+') +#define ACS_PLUS PDC_ACS('Z', '+') +#define ACS_LTEE PDC_ACS('[', '+') +#define ACS_RTEE PDC_ACS('\\', '+') +#define ACS_BTEE PDC_ACS(']', '+') +#define ACS_TTEE PDC_ACS('^', '+') +#define ACS_HLINE PDC_ACS('_', '-') +#define ACS_VLINE PDC_ACS('`', '|') + +/* PDCurses-only ACS chars. Don't use if ncurses compatibility matters. +Some won't work in non-wide X11 builds (see 'acs_defs.h' for details). */ + +#define ACS_CENT PDC_ACS('{', 'c') +#define ACS_YEN PDC_ACS('|', 'y') +#define ACS_PESETA PDC_ACS('}', 'p') +#define ACS_HALF PDC_ACS('&', '/') +#define ACS_QUARTER PDC_ACS('\'', '/') +#define ACS_LEFT_ANG_QU PDC_ACS(')', '<') +#define ACS_RIGHT_ANG_QU PDC_ACS('*', '>') +#define ACS_D_HLINE PDC_ACS('a', '-') +#define ACS_D_VLINE PDC_ACS('b', '|') +#define ACS_CLUB PDC_ACS( 11, 'C') +#define ACS_HEART PDC_ACS( 12, 'H') +#define ACS_SPADE PDC_ACS( 13, 'S') +#define ACS_SMILE PDC_ACS( 14, 'O') +#define ACS_REV_SMILE PDC_ACS( 15, 'O') +#define ACS_MED_BULLET PDC_ACS( 16, '.') +#define ACS_WHITE_BULLET PDC_ACS( 17, 'O') +#define ACS_PILCROW PDC_ACS( 18, 'O') +#define ACS_SECTION PDC_ACS( 19, 'O') + +#define ACS_SUP2 PDC_ACS(',', '2') +#define ACS_ALPHA PDC_ACS('.', 'a') +#define ACS_BETA PDC_ACS('/', 'b') +#define ACS_GAMMA PDC_ACS('0', 'y') +#define ACS_UP_SIGMA PDC_ACS('1', 'S') +#define ACS_LO_SIGMA PDC_ACS('2', 's') +#define ACS_MU PDC_ACS('4', 'u') +#define ACS_TAU PDC_ACS('5', 't') +#define ACS_UP_PHI PDC_ACS('6', 'F') +#define ACS_THETA PDC_ACS('7', 't') +#define ACS_OMEGA PDC_ACS('8', 'w') +#define ACS_DELTA PDC_ACS('9', 'd') +#define ACS_INFINITY PDC_ACS('-', 'i') +#define ACS_LO_PHI PDC_ACS( 22, 'f') +#define ACS_EPSILON PDC_ACS(':', 'e') +#define ACS_INTERSECT PDC_ACS('e', 'u') +#define ACS_TRIPLE_BAR PDC_ACS('f', '=') +#define ACS_DIVISION PDC_ACS('c', '/') +#define ACS_APPROX_EQ PDC_ACS('d', '~') +#define ACS_SM_BULLET PDC_ACS('g', '.') +#define ACS_SQUARE_ROOT PDC_ACS('i', '!') +#define ACS_UBLOCK PDC_ACS('p', '^') +#define ACS_BBLOCK PDC_ACS('q', '_') +#define ACS_LBLOCK PDC_ACS('r', '<') +#define ACS_RBLOCK PDC_ACS('s', '>') + +#define ACS_A_ORDINAL PDC_ACS(20, 'a') +#define ACS_O_ORDINAL PDC_ACS(21, 'o') +#define ACS_INV_QUERY PDC_ACS(24, '?') +#define ACS_REV_NOT PDC_ACS(25, '!') +#define ACS_NOT PDC_ACS(26, '!') +#define ACS_INV_BANG PDC_ACS(23, '!') +#define ACS_UP_INTEGRAL PDC_ACS(27, '|') +#define ACS_LO_INTEGRAL PDC_ACS(28, '|') +#define ACS_SUP_N PDC_ACS(29, 'n') +#define ACS_CENTER_SQU PDC_ACS(30, 'x') +#define ACS_F_WITH_HOOK PDC_ACS(31, 'f') + +#define ACS_SD_LRCORNER PDC_ACS(';', '+') +#define ACS_SD_URCORNER PDC_ACS('<', '+') +#define ACS_SD_ULCORNER PDC_ACS('=', '+') +#define ACS_SD_LLCORNER PDC_ACS('>', '+') +#define ACS_SD_PLUS PDC_ACS('?', '+') +#define ACS_SD_LTEE PDC_ACS('@', '+') +#define ACS_SD_RTEE PDC_ACS('A', '+') +#define ACS_SD_BTEE PDC_ACS('B', '+') +#define ACS_SD_TTEE PDC_ACS('C', '+') + +#define ACS_D_LRCORNER PDC_ACS('D', '+') +#define ACS_D_URCORNER PDC_ACS('E', '+') +#define ACS_D_ULCORNER PDC_ACS('F', '+') +#define ACS_D_LLCORNER PDC_ACS('G', '+') +#define ACS_D_PLUS PDC_ACS('H', '+') +#define ACS_D_LTEE PDC_ACS('I', '+') +#define ACS_D_RTEE PDC_ACS('J', '+') +#define ACS_D_BTEE PDC_ACS('K', '+') +#define ACS_D_TTEE PDC_ACS('L', '+') + +#define ACS_DS_LRCORNER PDC_ACS('M', '+') +#define ACS_DS_URCORNER PDC_ACS('N', '+') +#define ACS_DS_ULCORNER PDC_ACS('O', '+') +#define ACS_DS_LLCORNER PDC_ACS('P', '+') +#define ACS_DS_PLUS PDC_ACS('Q', '+') +#define ACS_DS_LTEE PDC_ACS('R', '+') +#define ACS_DS_RTEE PDC_ACS('S', '+') +#define ACS_DS_BTEE PDC_ACS('T', '+') +#define ACS_DS_TTEE PDC_ACS('U', '+') + +/* VT100-compatible symbols -- other */ + +#define ACS_S1 PDC_ACS('l', '-') +#define ACS_S9 PDC_ACS('o', '_') +#define ACS_DIAMOND PDC_ACS('j', '+') +#define ACS_CKBOARD PDC_ACS('k', ':') +#define ACS_DEGREE PDC_ACS('w', '\'') +#define ACS_PLMINUS PDC_ACS('x', '#') +#define ACS_BULLET PDC_ACS('h', 'o') + +/* Teletype 5410v1 symbols -- these are defined in SysV curses, but + are not well-supported by most terminals. Stick to VT100 characters + for optimum portability. */ + +#define ACS_LARROW PDC_ACS('!', '<') +#define ACS_RARROW PDC_ACS(' ', '>') +#define ACS_DARROW PDC_ACS('#', 'v') +#define ACS_UARROW PDC_ACS('"', '^') +#define ACS_BOARD PDC_ACS('+', '#') +#define ACS_LTBOARD PDC_ACS('y', '#') +#define ACS_LANTERN PDC_ACS('z', '*') +#define ACS_BLOCK PDC_ACS('t', '#') + +/* That goes double for these -- undocumented SysV symbols. Don't use + them. */ + +#define ACS_S3 PDC_ACS('m', '-') +#define ACS_S7 PDC_ACS('n', '-') +#define ACS_LEQUAL PDC_ACS('u', '<') +#define ACS_GEQUAL PDC_ACS('v', '>') +#define ACS_PI PDC_ACS('$', 'n') +#define ACS_NEQUAL PDC_ACS('%', '+') +#define ACS_STERLING PDC_ACS('~', 'L') + +/* Box char aliases */ + +#define ACS_BSSB ACS_ULCORNER +#define ACS_SSBB ACS_LLCORNER +#define ACS_BBSS ACS_URCORNER +#define ACS_SBBS ACS_LRCORNER +#define ACS_SBSS ACS_RTEE +#define ACS_SSSB ACS_LTEE +#define ACS_SSBS ACS_BTEE +#define ACS_BSSS ACS_TTEE +#define ACS_BSBS ACS_HLINE +#define ACS_SBSB ACS_VLINE +#define ACS_SSSS ACS_PLUS + +/* cchar_t aliases */ + +#ifdef PDC_WIDE +# define WACS_LRCORNER (&(acs_map['V'])) +# define WACS_URCORNER (&(acs_map['W'])) +# define WACS_ULCORNER (&(acs_map['X'])) +# define WACS_LLCORNER (&(acs_map['Y'])) +# define WACS_PLUS (&(acs_map['Z'])) +# define WACS_LTEE (&(acs_map['['])) +# define WACS_RTEE (&(acs_map['\\'])) +# define WACS_BTEE (&(acs_map[']'])) +# define WACS_TTEE (&(acs_map['^'])) +# define WACS_HLINE (&(acs_map['_'])) +# define WACS_VLINE (&(acs_map['`'])) + +# define WACS_CENT (&(acs_map['{'])) +# define WACS_YEN (&(acs_map['|'])) +# define WACS_PESETA (&(acs_map['}'])) +# define WACS_HALF (&(acs_map['&'])) +# define WACS_QUARTER (&(acs_map['\''])) +# define WACS_LEFT_ANG_QU (&(acs_map[')'])) +# define WACS_RIGHT_ANG_QU (&(acs_map['*'])) +# define WACS_D_HLINE (&(acs_map['a'])) +# define WACS_D_VLINE (&(acs_map['b'])) +# define WACS_CLUB (&(acs_map[ 11])) +# define WACS_HEART (&(acs_map[ 12])) +# define WACS_SPADE (&(acs_map[ 13])) +# define WACS_SMILE (&(acs_map[ 14])) +# define WACS_REV_SMILE (&(acs_map[ 15])) +# define WACS_MED_BULLET (&(acs_map[ 16])) +# define WACS_WHITE_BULLET (&(acs_map[ 17])) +# define WACS_PILCROW (&(acs_map[ 18])) +# define WACS_SECTION (&(acs_map[ 19])) + +# define WACS_SUP2 (&(acs_map[','])) +# define WACS_ALPHA (&(acs_map['.'])) +# define WACS_BETA (&(acs_map['/'])) +# define WACS_GAMMA (&(acs_map['0'])) +# define WACS_UP_SIGMA (&(acs_map['1'])) +# define WACS_LO_SIGMA (&(acs_map['2'])) +# define WACS_MU (&(acs_map['4'])) +# define WACS_TAU (&(acs_map['5'])) +# define WACS_UP_PHI (&(acs_map['6'])) +# define WACS_THETA (&(acs_map['7'])) +# define WACS_OMEGA (&(acs_map['8'])) +# define WACS_DELTA (&(acs_map['9'])) +# define WACS_INFINITY (&(acs_map['-'])) +# define WACS_LO_PHI (&(acs_map[ 22])) +# define WACS_EPSILON (&(acs_map[':'])) +# define WACS_INTERSECT (&(acs_map['e'])) +# define WACS_TRIPLE_BAR (&(acs_map['f'])) +# define WACS_DIVISION (&(acs_map['c'])) +# define WACS_APPROX_EQ (&(acs_map['d'])) +# define WACS_SM_BULLET (&(acs_map['g'])) +# define WACS_SQUARE_ROOT (&(acs_map['i'])) +# define WACS_UBLOCK (&(acs_map['p'])) +# define WACS_BBLOCK (&(acs_map['q'])) +# define WACS_LBLOCK (&(acs_map['r'])) +# define WACS_RBLOCK (&(acs_map['s'])) + +# define WACS_A_ORDINAL (&(acs_map[20])) +# define WACS_O_ORDINAL (&(acs_map[21])) +# define WACS_INV_QUERY (&(acs_map[24])) +# define WACS_REV_NOT (&(acs_map[25])) +# define WACS_NOT (&(acs_map[26])) +# define WACS_INV_BANG (&(acs_map[23])) +# define WACS_UP_INTEGRAL (&(acs_map[27])) +# define WACS_LO_INTEGRAL (&(acs_map[28])) +# define WACS_SUP_N (&(acs_map[29])) +# define WACS_CENTER_SQU (&(acs_map[30])) +# define WACS_F_WITH_HOOK (&(acs_map[31])) + +# define WACS_SD_LRCORNER (&(acs_map[';'])) +# define WACS_SD_URCORNER (&(acs_map['<'])) +# define WACS_SD_ULCORNER (&(acs_map['='])) +# define WACS_SD_LLCORNER (&(acs_map['>'])) +# define WACS_SD_PLUS (&(acs_map['?'])) +# define WACS_SD_LTEE (&(acs_map['@'])) +# define WACS_SD_RTEE (&(acs_map['A'])) +# define WACS_SD_BTEE (&(acs_map['B'])) +# define WACS_SD_TTEE (&(acs_map['C'])) + +# define WACS_D_LRCORNER (&(acs_map['D'])) +# define WACS_D_URCORNER (&(acs_map['E'])) +# define WACS_D_ULCORNER (&(acs_map['F'])) +# define WACS_D_LLCORNER (&(acs_map['G'])) +# define WACS_D_PLUS (&(acs_map['H'])) +# define WACS_D_LTEE (&(acs_map['I'])) +# define WACS_D_RTEE (&(acs_map['J'])) +# define WACS_D_BTEE (&(acs_map['K'])) +# define WACS_D_TTEE (&(acs_map['L'])) + +# define WACS_DS_LRCORNER (&(acs_map['M'])) +# define WACS_DS_URCORNER (&(acs_map['N'])) +# define WACS_DS_ULCORNER (&(acs_map['O'])) +# define WACS_DS_LLCORNER (&(acs_map['P'])) +# define WACS_DS_PLUS (&(acs_map['Q'])) +# define WACS_DS_LTEE (&(acs_map['R'])) +# define WACS_DS_RTEE (&(acs_map['S'])) +# define WACS_DS_BTEE (&(acs_map['T'])) +# define WACS_DS_TTEE (&(acs_map['U'])) + +# define WACS_S1 (&(acs_map['l'])) +# define WACS_S9 (&(acs_map['o'])) +# define WACS_DIAMOND (&(acs_map['j'])) +# define WACS_CKBOARD (&(acs_map['k'])) +# define WACS_DEGREE (&(acs_map['w'])) +# define WACS_PLMINUS (&(acs_map['x'])) +# define WACS_BULLET (&(acs_map['h'])) + + +# define WACS_LARROW (&(acs_map['!'])) +# define WACS_RARROW (&(acs_map[' '])) +# define WACS_DARROW (&(acs_map['#'])) +# define WACS_UARROW (&(acs_map['"'])) +# define WACS_BOARD (&(acs_map['+'])) +# define WACS_LTBOARD (&(acs_map['y'])) +# define WACS_LANTERN (&(acs_map['z'])) +# define WACS_BLOCK (&(acs_map['t'])) + +# define WACS_S3 (&(acs_map['m'])) +# define WACS_S7 (&(acs_map['n'])) +# define WACS_LEQUAL (&(acs_map['u'])) +# define WACS_GEQUAL (&(acs_map['v'])) +# define WACS_PI (&(acs_map['$'])) +# define WACS_NEQUAL (&(acs_map['%'])) +# define WACS_STERLING (&(acs_map['~'])) + +# define WACS_BSSB WACS_ULCORNER +# define WACS_SSBB WACS_LLCORNER +# define WACS_BBSS WACS_URCORNER +# define WACS_SBBS WACS_LRCORNER +# define WACS_SBSS WACS_RTEE +# define WACS_SSSB WACS_LTEE +# define WACS_SSBS WACS_BTEE +# define WACS_BSSS WACS_TTEE +# define WACS_BSBS WACS_HLINE +# define WACS_SBSB WACS_VLINE +# define WACS_SSSS WACS_PLUS +#endif + +/*** Color macros ***/ + +#define COLOR_BLACK 0 + +#ifdef PDC_RGB /* RGB */ +# define COLOR_RED 1 +# define COLOR_GREEN 2 +# define COLOR_BLUE 4 +#else /* BGR */ +# define COLOR_BLUE 1 +# define COLOR_GREEN 2 +# define COLOR_RED 4 +#endif + +#define COLOR_CYAN (COLOR_BLUE | COLOR_GREEN) +#define COLOR_MAGENTA (COLOR_RED | COLOR_BLUE) +#define COLOR_YELLOW (COLOR_RED | COLOR_GREEN) + +#define COLOR_WHITE 7 + +/*---------------------------------------------------------------------- + * + * Function and Keypad Key Definitions + * Many are just for compatibility + * + */ + +#ifdef PDC_WIDE + #define KEY_OFFSET 0xec00 +#else + #define KEY_OFFSET 0x100 +#endif + +#define KEY_CODE_YES (KEY_OFFSET + 0x00) /* If get_wch() gives a key code */ + +#define KEY_BREAK (KEY_OFFSET + 0x01) /* Not on PC KBD */ +#define KEY_DOWN (KEY_OFFSET + 0x02) /* Down arrow key */ +#define KEY_UP (KEY_OFFSET + 0x03) /* Up arrow key */ +#define KEY_LEFT (KEY_OFFSET + 0x04) /* Left arrow key */ +#define KEY_RIGHT (KEY_OFFSET + 0x05) /* Right arrow key */ +#define KEY_HOME (KEY_OFFSET + 0x06) /* home key */ +#define KEY_BACKSPACE (KEY_OFFSET + 0x07) /* not on pc */ +#define KEY_F0 (KEY_OFFSET + 0x08) /* function keys; 64 reserved */ + +#define KEY_DL (KEY_OFFSET + 0x48) /* delete line */ +#define KEY_IL (KEY_OFFSET + 0x49) /* insert line */ +#define KEY_DC (KEY_OFFSET + 0x4a) /* delete character */ +#define KEY_IC (KEY_OFFSET + 0x4b) /* insert char or enter ins mode */ +#define KEY_EIC (KEY_OFFSET + 0x4c) /* exit insert char mode */ +#define KEY_CLEAR (KEY_OFFSET + 0x4d) /* clear screen */ +#define KEY_EOS (KEY_OFFSET + 0x4e) /* clear to end of screen */ +#define KEY_EOL (KEY_OFFSET + 0x4f) /* clear to end of line */ +#define KEY_SF (KEY_OFFSET + 0x50) /* scroll 1 line forward */ +#define KEY_SR (KEY_OFFSET + 0x51) /* scroll 1 line back (reverse) */ +#define KEY_NPAGE (KEY_OFFSET + 0x52) /* next page */ +#define KEY_PPAGE (KEY_OFFSET + 0x53) /* previous page */ +#define KEY_STAB (KEY_OFFSET + 0x54) /* set tab */ +#define KEY_CTAB (KEY_OFFSET + 0x55) /* clear tab */ +#define KEY_CATAB (KEY_OFFSET + 0x56) /* clear all tabs */ +#define KEY_ENTER (KEY_OFFSET + 0x57) /* enter or send (unreliable) */ +#define KEY_SRESET (KEY_OFFSET + 0x58) /* soft/reset (partial/unreliable) */ +#define KEY_RESET (KEY_OFFSET + 0x59) /* reset/hard reset (unreliable) */ +#define KEY_PRINT (KEY_OFFSET + 0x5a) /* print/copy */ +#define KEY_LL (KEY_OFFSET + 0x5b) /* home down/bottom (lower left) */ +#define KEY_ABORT (KEY_OFFSET + 0x5c) /* abort/terminate key (any) */ +#define KEY_SHELP (KEY_OFFSET + 0x5d) /* short help */ +#define KEY_LHELP (KEY_OFFSET + 0x5e) /* long help */ +#define KEY_BTAB (KEY_OFFSET + 0x5f) /* Back tab key */ +#define KEY_BEG (KEY_OFFSET + 0x60) /* beg(inning) key */ +#define KEY_CANCEL (KEY_OFFSET + 0x61) /* cancel key */ +#define KEY_CLOSE (KEY_OFFSET + 0x62) /* close key */ +#define KEY_COMMAND (KEY_OFFSET + 0x63) /* cmd (command) key */ +#define KEY_COPY (KEY_OFFSET + 0x64) /* copy key */ +#define KEY_CREATE (KEY_OFFSET + 0x65) /* create key */ +#define KEY_END (KEY_OFFSET + 0x66) /* end key */ +#define KEY_EXIT (KEY_OFFSET + 0x67) /* exit key */ +#define KEY_FIND (KEY_OFFSET + 0x68) /* find key */ +#define KEY_HELP (KEY_OFFSET + 0x69) /* help key */ +#define KEY_MARK (KEY_OFFSET + 0x6a) /* mark key */ +#define KEY_MESSAGE (KEY_OFFSET + 0x6b) /* message key */ +#define KEY_MOVE (KEY_OFFSET + 0x6c) /* move key */ +#define KEY_NEXT (KEY_OFFSET + 0x6d) /* next object key */ +#define KEY_OPEN (KEY_OFFSET + 0x6e) /* open key */ +#define KEY_OPTIONS (KEY_OFFSET + 0x6f) /* options key */ +#define KEY_PREVIOUS (KEY_OFFSET + 0x70) /* previous object key */ +#define KEY_REDO (KEY_OFFSET + 0x71) /* redo key */ +#define KEY_REFERENCE (KEY_OFFSET + 0x72) /* ref(erence) key */ +#define KEY_REFRESH (KEY_OFFSET + 0x73) /* refresh key */ +#define KEY_REPLACE (KEY_OFFSET + 0x74) /* replace key */ +#define KEY_RESTART (KEY_OFFSET + 0x75) /* restart key */ +#define KEY_RESUME (KEY_OFFSET + 0x76) /* resume key */ +#define KEY_SAVE (KEY_OFFSET + 0x77) /* save key */ +#define KEY_SBEG (KEY_OFFSET + 0x78) /* shifted beginning key */ +#define KEY_SCANCEL (KEY_OFFSET + 0x79) /* shifted cancel key */ +#define KEY_SCOMMAND (KEY_OFFSET + 0x7a) /* shifted command key */ +#define KEY_SCOPY (KEY_OFFSET + 0x7b) /* shifted copy key */ +#define KEY_SCREATE (KEY_OFFSET + 0x7c) /* shifted create key */ +#define KEY_SDC (KEY_OFFSET + 0x7d) /* shifted delete char key */ +#define KEY_SDL (KEY_OFFSET + 0x7e) /* shifted delete line key */ +#define KEY_SELECT (KEY_OFFSET + 0x7f) /* select key */ +#define KEY_SEND (KEY_OFFSET + 0x80) /* shifted end key */ +#define KEY_SEOL (KEY_OFFSET + 0x81) /* shifted clear line key */ +#define KEY_SEXIT (KEY_OFFSET + 0x82) /* shifted exit key */ +#define KEY_SFIND (KEY_OFFSET + 0x83) /* shifted find key */ +#define KEY_SHOME (KEY_OFFSET + 0x84) /* shifted home key */ +#define KEY_SIC (KEY_OFFSET + 0x85) /* shifted input key */ + +#define KEY_SLEFT (KEY_OFFSET + 0x87) /* shifted left arrow key */ +#define KEY_SMESSAGE (KEY_OFFSET + 0x88) /* shifted message key */ +#define KEY_SMOVE (KEY_OFFSET + 0x89) /* shifted move key */ +#define KEY_SNEXT (KEY_OFFSET + 0x8a) /* shifted next key */ +#define KEY_SOPTIONS (KEY_OFFSET + 0x8b) /* shifted options key */ +#define KEY_SPREVIOUS (KEY_OFFSET + 0x8c) /* shifted prev key */ +#define KEY_SPRINT (KEY_OFFSET + 0x8d) /* shifted print key */ +#define KEY_SREDO (KEY_OFFSET + 0x8e) /* shifted redo key */ +#define KEY_SREPLACE (KEY_OFFSET + 0x8f) /* shifted replace key */ +#define KEY_SRIGHT (KEY_OFFSET + 0x90) /* shifted right arrow */ +#define KEY_SRSUME (KEY_OFFSET + 0x91) /* shifted resume key */ +#define KEY_SSAVE (KEY_OFFSET + 0x92) /* shifted save key */ +#define KEY_SSUSPEND (KEY_OFFSET + 0x93) /* shifted suspend key */ +#define KEY_SUNDO (KEY_OFFSET + 0x94) /* shifted undo key */ +#define KEY_SUSPEND (KEY_OFFSET + 0x95) /* suspend key */ +#define KEY_UNDO (KEY_OFFSET + 0x96) /* undo key */ + +/* PDCurses-specific key definitions -- PC only */ + +#define ALT_0 (KEY_OFFSET + 0x97) +#define ALT_1 (KEY_OFFSET + 0x98) +#define ALT_2 (KEY_OFFSET + 0x99) +#define ALT_3 (KEY_OFFSET + 0x9a) +#define ALT_4 (KEY_OFFSET + 0x9b) +#define ALT_5 (KEY_OFFSET + 0x9c) +#define ALT_6 (KEY_OFFSET + 0x9d) +#define ALT_7 (KEY_OFFSET + 0x9e) +#define ALT_8 (KEY_OFFSET + 0x9f) +#define ALT_9 (KEY_OFFSET + 0xa0) +#define ALT_A (KEY_OFFSET + 0xa1) +#define ALT_B (KEY_OFFSET + 0xa2) +#define ALT_C (KEY_OFFSET + 0xa3) +#define ALT_D (KEY_OFFSET + 0xa4) +#define ALT_E (KEY_OFFSET + 0xa5) +#define ALT_F (KEY_OFFSET + 0xa6) +#define ALT_G (KEY_OFFSET + 0xa7) +#define ALT_H (KEY_OFFSET + 0xa8) +#define ALT_I (KEY_OFFSET + 0xa9) +#define ALT_J (KEY_OFFSET + 0xaa) +#define ALT_K (KEY_OFFSET + 0xab) +#define ALT_L (KEY_OFFSET + 0xac) +#define ALT_M (KEY_OFFSET + 0xad) +#define ALT_N (KEY_OFFSET + 0xae) +#define ALT_O (KEY_OFFSET + 0xaf) +#define ALT_P (KEY_OFFSET + 0xb0) +#define ALT_Q (KEY_OFFSET + 0xb1) +#define ALT_R (KEY_OFFSET + 0xb2) +#define ALT_S (KEY_OFFSET + 0xb3) +#define ALT_T (KEY_OFFSET + 0xb4) +#define ALT_U (KEY_OFFSET + 0xb5) +#define ALT_V (KEY_OFFSET + 0xb6) +#define ALT_W (KEY_OFFSET + 0xb7) +#define ALT_X (KEY_OFFSET + 0xb8) +#define ALT_Y (KEY_OFFSET + 0xb9) +#define ALT_Z (KEY_OFFSET + 0xba) + +#define CTL_LEFT (KEY_OFFSET + 0xbb) /* Control-Left-Arrow */ +#define CTL_RIGHT (KEY_OFFSET + 0xbc) +#define CTL_PGUP (KEY_OFFSET + 0xbd) +#define CTL_PGDN (KEY_OFFSET + 0xbe) +#define CTL_HOME (KEY_OFFSET + 0xbf) +#define CTL_END (KEY_OFFSET + 0xc0) + +#define KEY_A1 (KEY_OFFSET + 0xc1) /* upper left on Virtual keypad */ +#define KEY_A2 (KEY_OFFSET + 0xc2) /* upper middle on Virt. keypad */ +#define KEY_A3 (KEY_OFFSET + 0xc3) /* upper right on Vir. keypad */ +#define KEY_B1 (KEY_OFFSET + 0xc4) /* middle left on Virt. keypad */ +#define KEY_B2 (KEY_OFFSET + 0xc5) /* center on Virt. keypad */ +#define KEY_B3 (KEY_OFFSET + 0xc6) /* middle right on Vir. keypad */ +#define KEY_C1 (KEY_OFFSET + 0xc7) /* lower left on Virt. keypad */ +#define KEY_C2 (KEY_OFFSET + 0xc8) /* lower middle on Virt. keypad */ +#define KEY_C3 (KEY_OFFSET + 0xc9) /* lower right on Vir. keypad */ + +#define PADSLASH (KEY_OFFSET + 0xca) /* slash on keypad */ +#define PADENTER (KEY_OFFSET + 0xcb) /* enter on keypad */ +#define CTL_PADENTER (KEY_OFFSET + 0xcc) /* ctl-enter on keypad */ +#define ALT_PADENTER (KEY_OFFSET + 0xcd) /* alt-enter on keypad */ +#define PADSTOP (KEY_OFFSET + 0xce) /* stop on keypad */ +#define PADSTAR (KEY_OFFSET + 0xcf) /* star on keypad */ +#define PADMINUS (KEY_OFFSET + 0xd0) /* minus on keypad */ +#define PADPLUS (KEY_OFFSET + 0xd1) /* plus on keypad */ +#define CTL_PADSTOP (KEY_OFFSET + 0xd2) /* ctl-stop on keypad */ +#define CTL_PADCENTER (KEY_OFFSET + 0xd3) /* ctl-enter on keypad */ +#define CTL_PADPLUS (KEY_OFFSET + 0xd4) /* ctl-plus on keypad */ +#define CTL_PADMINUS (KEY_OFFSET + 0xd5) /* ctl-minus on keypad */ +#define CTL_PADSLASH (KEY_OFFSET + 0xd6) /* ctl-slash on keypad */ +#define CTL_PADSTAR (KEY_OFFSET + 0xd7) /* ctl-star on keypad */ +#define ALT_PADPLUS (KEY_OFFSET + 0xd8) /* alt-plus on keypad */ +#define ALT_PADMINUS (KEY_OFFSET + 0xd9) /* alt-minus on keypad */ +#define ALT_PADSLASH (KEY_OFFSET + 0xda) /* alt-slash on keypad */ +#define ALT_PADSTAR (KEY_OFFSET + 0xdb) /* alt-star on keypad */ +#define ALT_PADSTOP (KEY_OFFSET + 0xdc) /* alt-stop on keypad */ +#define CTL_INS (KEY_OFFSET + 0xdd) /* ctl-insert */ +#define ALT_DEL (KEY_OFFSET + 0xde) /* alt-delete */ +#define ALT_INS (KEY_OFFSET + 0xdf) /* alt-insert */ +#define CTL_UP (KEY_OFFSET + 0xe0) /* ctl-up arrow */ +#define CTL_DOWN (KEY_OFFSET + 0xe1) /* ctl-down arrow */ +#define CTL_TAB (KEY_OFFSET + 0xe2) /* ctl-tab */ +#define ALT_TAB (KEY_OFFSET + 0xe3) +#define ALT_MINUS (KEY_OFFSET + 0xe4) +#define ALT_EQUAL (KEY_OFFSET + 0xe5) +#define ALT_HOME (KEY_OFFSET + 0xe6) +#define ALT_PGUP (KEY_OFFSET + 0xe7) +#define ALT_PGDN (KEY_OFFSET + 0xe8) +#define ALT_END (KEY_OFFSET + 0xe9) +#define ALT_UP (KEY_OFFSET + 0xea) /* alt-up arrow */ +#define ALT_DOWN (KEY_OFFSET + 0xeb) /* alt-down arrow */ +#define ALT_RIGHT (KEY_OFFSET + 0xec) /* alt-right arrow */ +#define ALT_LEFT (KEY_OFFSET + 0xed) /* alt-left arrow */ +#define ALT_ENTER (KEY_OFFSET + 0xee) /* alt-enter */ +#define ALT_ESC (KEY_OFFSET + 0xef) /* alt-escape */ +#define ALT_BQUOTE (KEY_OFFSET + 0xf0) /* alt-back quote */ +#define ALT_LBRACKET (KEY_OFFSET + 0xf1) /* alt-left bracket */ +#define ALT_RBRACKET (KEY_OFFSET + 0xf2) /* alt-right bracket */ +#define ALT_SEMICOLON (KEY_OFFSET + 0xf3) /* alt-semi-colon */ +#define ALT_FQUOTE (KEY_OFFSET + 0xf4) /* alt-forward quote */ +#define ALT_COMMA (KEY_OFFSET + 0xf5) /* alt-comma */ +#define ALT_STOP (KEY_OFFSET + 0xf6) /* alt-stop */ +#define ALT_FSLASH (KEY_OFFSET + 0xf7) /* alt-forward slash */ +#define ALT_BKSP (KEY_OFFSET + 0xf8) /* alt-backspace */ +#define CTL_BKSP (KEY_OFFSET + 0xf9) /* ctl-backspace */ +#define PAD0 (KEY_OFFSET + 0xfa) /* keypad 0 */ + +#define CTL_PAD0 (KEY_OFFSET + 0xfb) /* ctl-keypad 0 */ +#define CTL_PAD1 (KEY_OFFSET + 0xfc) +#define CTL_PAD2 (KEY_OFFSET + 0xfd) +#define CTL_PAD3 (KEY_OFFSET + 0xfe) +#define CTL_PAD4 (KEY_OFFSET + 0xff) +#define CTL_PAD5 (KEY_OFFSET + 0x100) +#define CTL_PAD6 (KEY_OFFSET + 0x101) +#define CTL_PAD7 (KEY_OFFSET + 0x102) +#define CTL_PAD8 (KEY_OFFSET + 0x103) +#define CTL_PAD9 (KEY_OFFSET + 0x104) + +#define ALT_PAD0 (KEY_OFFSET + 0x105) /* alt-keypad 0 */ +#define ALT_PAD1 (KEY_OFFSET + 0x106) +#define ALT_PAD2 (KEY_OFFSET + 0x107) +#define ALT_PAD3 (KEY_OFFSET + 0x108) +#define ALT_PAD4 (KEY_OFFSET + 0x109) +#define ALT_PAD5 (KEY_OFFSET + 0x10a) +#define ALT_PAD6 (KEY_OFFSET + 0x10b) +#define ALT_PAD7 (KEY_OFFSET + 0x10c) +#define ALT_PAD8 (KEY_OFFSET + 0x10d) +#define ALT_PAD9 (KEY_OFFSET + 0x10e) + +#define CTL_DEL (KEY_OFFSET + 0x10f) /* clt-delete */ +#define ALT_BSLASH (KEY_OFFSET + 0x110) /* alt-back slash */ +#define CTL_ENTER (KEY_OFFSET + 0x111) /* ctl-enter */ + +#define SHF_PADENTER (KEY_OFFSET + 0x112) /* shift-enter on keypad */ +#define SHF_PADSLASH (KEY_OFFSET + 0x113) /* shift-slash on keypad */ +#define SHF_PADSTAR (KEY_OFFSET + 0x114) /* shift-star on keypad */ +#define SHF_PADPLUS (KEY_OFFSET + 0x115) /* shift-plus on keypad */ +#define SHF_PADMINUS (KEY_OFFSET + 0x116) /* shift-minus on keypad */ +#define SHF_UP (KEY_OFFSET + 0x117) /* shift-up on keypad */ +#define SHF_DOWN (KEY_OFFSET + 0x118) /* shift-down on keypad */ +#define SHF_IC (KEY_OFFSET + 0x119) /* shift-insert on keypad */ +#define SHF_DC (KEY_OFFSET + 0x11a) /* shift-delete on keypad */ + +#define KEY_MOUSE (KEY_OFFSET + 0x11b) /* "mouse" key */ +#define KEY_SHIFT_L (KEY_OFFSET + 0x11c) /* Left-shift */ +#define KEY_SHIFT_R (KEY_OFFSET + 0x11d) /* Right-shift */ +#define KEY_CONTROL_L (KEY_OFFSET + 0x11e) /* Left-control */ +#define KEY_CONTROL_R (KEY_OFFSET + 0x11f) /* Right-control */ +#define KEY_ALT_L (KEY_OFFSET + 0x120) /* Left-alt */ +#define KEY_ALT_R (KEY_OFFSET + 0x121) /* Right-alt */ +#define KEY_RESIZE (KEY_OFFSET + 0x122) /* Window resize */ +#define KEY_SUP (KEY_OFFSET + 0x123) /* Shifted up arrow */ +#define KEY_SDOWN (KEY_OFFSET + 0x124) /* Shifted down arrow */ + + /* The following were added 2011 Sep 14, and are */ + /* not returned by most flavors of PDCurses: */ + +#define CTL_SEMICOLON (KEY_OFFSET + 0x125) +#define CTL_EQUAL (KEY_OFFSET + 0x126) +#define CTL_COMMA (KEY_OFFSET + 0x127) +#define CTL_MINUS (KEY_OFFSET + 0x128) +#define CTL_STOP (KEY_OFFSET + 0x129) +#define CTL_FSLASH (KEY_OFFSET + 0x12a) +#define CTL_BQUOTE (KEY_OFFSET + 0x12b) + +#define KEY_APPS (KEY_OFFSET + 0x12c) +#define KEY_SAPPS (KEY_OFFSET + 0x12d) +#define CTL_APPS (KEY_OFFSET + 0x12e) +#define ALT_APPS (KEY_OFFSET + 0x12f) + +#define KEY_PAUSE (KEY_OFFSET + 0x130) +#define KEY_SPAUSE (KEY_OFFSET + 0x131) +#define CTL_PAUSE (KEY_OFFSET + 0x132) + +#define KEY_PRINTSCREEN (KEY_OFFSET + 0x133) +#define ALT_PRINTSCREEN (KEY_OFFSET + 0x134) +#define KEY_SCROLLLOCK (KEY_OFFSET + 0x135) +#define ALT_SCROLLLOCK (KEY_OFFSET + 0x136) + +#define CTL_0 (KEY_OFFSET + 0x137) +#define CTL_1 (KEY_OFFSET + 0x138) +#define CTL_2 (KEY_OFFSET + 0x139) +#define CTL_3 (KEY_OFFSET + 0x13a) +#define CTL_4 (KEY_OFFSET + 0x13b) +#define CTL_5 (KEY_OFFSET + 0x13c) +#define CTL_6 (KEY_OFFSET + 0x13d) +#define CTL_7 (KEY_OFFSET + 0x13e) +#define CTL_8 (KEY_OFFSET + 0x13f) +#define CTL_9 (KEY_OFFSET + 0x140) + +#define KEY_BROWSER_BACK (KEY_OFFSET + 0x141) +#define KEY_SBROWSER_BACK (KEY_OFFSET + 0x142) +#define KEY_CBROWSER_BACK (KEY_OFFSET + 0x143) +#define KEY_ABROWSER_BACK (KEY_OFFSET + 0x144) +#define KEY_BROWSER_FWD (KEY_OFFSET + 0x145) +#define KEY_SBROWSER_FWD (KEY_OFFSET + 0x146) +#define KEY_CBROWSER_FWD (KEY_OFFSET + 0x147) +#define KEY_ABROWSER_FWD (KEY_OFFSET + 0x148) +#define KEY_BROWSER_REF (KEY_OFFSET + 0x149) +#define KEY_SBROWSER_REF (KEY_OFFSET + 0x14A) +#define KEY_CBROWSER_REF (KEY_OFFSET + 0x14B) +#define KEY_ABROWSER_REF (KEY_OFFSET + 0x14C) +#define KEY_BROWSER_STOP (KEY_OFFSET + 0x14D) +#define KEY_SBROWSER_STOP (KEY_OFFSET + 0x14E) +#define KEY_CBROWSER_STOP (KEY_OFFSET + 0x14F) +#define KEY_ABROWSER_STOP (KEY_OFFSET + 0x150) +#define KEY_SEARCH (KEY_OFFSET + 0x151) +#define KEY_SSEARCH (KEY_OFFSET + 0x152) +#define KEY_CSEARCH (KEY_OFFSET + 0x153) +#define KEY_ASEARCH (KEY_OFFSET + 0x154) +#define KEY_FAVORITES (KEY_OFFSET + 0x155) +#define KEY_SFAVORITES (KEY_OFFSET + 0x156) +#define KEY_CFAVORITES (KEY_OFFSET + 0x157) +#define KEY_AFAVORITES (KEY_OFFSET + 0x158) +#define KEY_BROWSER_HOME (KEY_OFFSET + 0x159) +#define KEY_SBROWSER_HOME (KEY_OFFSET + 0x15A) +#define KEY_CBROWSER_HOME (KEY_OFFSET + 0x15B) +#define KEY_ABROWSER_HOME (KEY_OFFSET + 0x15C) +#define KEY_VOLUME_MUTE (KEY_OFFSET + 0x15D) +#define KEY_SVOLUME_MUTE (KEY_OFFSET + 0x15E) +#define KEY_CVOLUME_MUTE (KEY_OFFSET + 0x15F) +#define KEY_AVOLUME_MUTE (KEY_OFFSET + 0x160) +#define KEY_VOLUME_DOWN (KEY_OFFSET + 0x161) +#define KEY_SVOLUME_DOWN (KEY_OFFSET + 0x162) +#define KEY_CVOLUME_DOWN (KEY_OFFSET + 0x163) +#define KEY_AVOLUME_DOWN (KEY_OFFSET + 0x164) +#define KEY_VOLUME_UP (KEY_OFFSET + 0x165) +#define KEY_SVOLUME_UP (KEY_OFFSET + 0x166) +#define KEY_CVOLUME_UP (KEY_OFFSET + 0x167) +#define KEY_AVOLUME_UP (KEY_OFFSET + 0x168) +#define KEY_NEXT_TRACK (KEY_OFFSET + 0x169) +#define KEY_SNEXT_TRACK (KEY_OFFSET + 0x16A) +#define KEY_CNEXT_TRACK (KEY_OFFSET + 0x16B) +#define KEY_ANEXT_TRACK (KEY_OFFSET + 0x16C) +#define KEY_PREV_TRACK (KEY_OFFSET + 0x16D) +#define KEY_SPREV_TRACK (KEY_OFFSET + 0x16E) +#define KEY_CPREV_TRACK (KEY_OFFSET + 0x16F) +#define KEY_APREV_TRACK (KEY_OFFSET + 0x170) +#define KEY_MEDIA_STOP (KEY_OFFSET + 0x171) +#define KEY_SMEDIA_STOP (KEY_OFFSET + 0x172) +#define KEY_CMEDIA_STOP (KEY_OFFSET + 0x173) +#define KEY_AMEDIA_STOP (KEY_OFFSET + 0x174) +#define KEY_PLAY_PAUSE (KEY_OFFSET + 0x175) +#define KEY_SPLAY_PAUSE (KEY_OFFSET + 0x176) +#define KEY_CPLAY_PAUSE (KEY_OFFSET + 0x177) +#define KEY_APLAY_PAUSE (KEY_OFFSET + 0x178) +#define KEY_LAUNCH_MAIL (KEY_OFFSET + 0x179) +#define KEY_SLAUNCH_MAIL (KEY_OFFSET + 0x17A) +#define KEY_CLAUNCH_MAIL (KEY_OFFSET + 0x17B) +#define KEY_ALAUNCH_MAIL (KEY_OFFSET + 0x17C) +#define KEY_MEDIA_SELECT (KEY_OFFSET + 0x17D) +#define KEY_SMEDIA_SELECT (KEY_OFFSET + 0x17E) +#define KEY_CMEDIA_SELECT (KEY_OFFSET + 0x17F) +#define KEY_AMEDIA_SELECT (KEY_OFFSET + 0x180) +#define KEY_LAUNCH_APP1 (KEY_OFFSET + 0x181) +#define KEY_SLAUNCH_APP1 (KEY_OFFSET + 0x182) +#define KEY_CLAUNCH_APP1 (KEY_OFFSET + 0x183) +#define KEY_ALAUNCH_APP1 (KEY_OFFSET + 0x184) +#define KEY_LAUNCH_APP2 (KEY_OFFSET + 0x185) +#define KEY_SLAUNCH_APP2 (KEY_OFFSET + 0x186) +#define KEY_CLAUNCH_APP2 (KEY_OFFSET + 0x187) +#define KEY_ALAUNCH_APP2 (KEY_OFFSET + 0x188) + +#define KEY_MIN KEY_BREAK /* Minimum curses key value */ +#define KEY_MAX KEY_ALAUNCH_APP2 /* Maximum curses key */ + +#define KEY_F(n) (KEY_F0 + (n)) + +/*---------------------------------------------------------------------- + * + * PDCurses Function Declarations + * + */ + +/* Standard */ + +PDCEX int addch(const chtype); +PDCEX int addchnstr(const chtype *, int); +PDCEX int addchstr(const chtype *); +PDCEX int addnstr(const char *, int); +PDCEX int addstr(const char *); +PDCEX int attroff(chtype); +PDCEX int attron(chtype); +PDCEX int attrset(chtype); +PDCEX int attr_get(attr_t *, short *, void *); +PDCEX int attr_off(attr_t, void *); +PDCEX int attr_on(attr_t, void *); +PDCEX int attr_set(attr_t, short, void *); +PDCEX int baudrate(void); +PDCEX int beep(void); +PDCEX int bkgd(chtype); +PDCEX void bkgdset(chtype); +PDCEX int border(chtype, chtype, chtype, chtype, + chtype, chtype, chtype, chtype); +PDCEX int box(WINDOW *, chtype, chtype); +PDCEX bool can_change_color(void); +PDCEX int cbreak(void); +PDCEX int chgat(int, attr_t, short, const void *); +PDCEX int clearok(WINDOW *, bool); +PDCEX int clear(void); +PDCEX int clrtobot(void); +PDCEX int clrtoeol(void); +PDCEX int color_content(short, short *, short *, short *); +PDCEX int color_set(short, void *); +PDCEX int copywin(const WINDOW *, WINDOW *, int, int, int, + int, int, int, int); +PDCEX int curs_set(int); +PDCEX int def_prog_mode(void); +PDCEX int def_shell_mode(void); +PDCEX int delay_output(int); +PDCEX int delch(void); +PDCEX int deleteln(void); +PDCEX void delscreen(SCREEN *); +PDCEX int delwin(WINDOW *); +PDCEX WINDOW *derwin(WINDOW *, int, int, int, int); +PDCEX int doupdate(void); +PDCEX WINDOW *dupwin(WINDOW *); +PDCEX int echochar(const chtype); +PDCEX int echo(void); +PDCEX int endwin(void); +PDCEX char erasechar(void); +PDCEX int erase(void); +PDCEX void filter(void); +PDCEX int flash(void); +PDCEX int flushinp(void); +PDCEX chtype getbkgd(WINDOW *); +PDCEX int getnstr(char *, int); +PDCEX int getstr(char *); +PDCEX WINDOW *getwin(FILE *); +PDCEX int halfdelay(int); +PDCEX bool has_colors(void); +PDCEX bool has_ic(void); +PDCEX bool has_il(void); +PDCEX int hline(chtype, int); +PDCEX void idcok(WINDOW *, bool); +PDCEX int idlok(WINDOW *, bool); +PDCEX void immedok(WINDOW *, bool); +PDCEX int inchnstr(chtype *, int); +PDCEX int inchstr(chtype *); +PDCEX chtype inch(void); +PDCEX int init_color(short, short, short, short); +PDCEX int init_pair(short, short, short); +PDCEX WINDOW *initscr(void); +PDCEX int innstr(char *, int); +PDCEX int insch(chtype); +PDCEX int insdelln(int); +PDCEX int insertln(void); +PDCEX int insnstr(const char *, int); +PDCEX int insstr(const char *); +PDCEX int instr(char *); +PDCEX int intrflush(WINDOW *, bool); +PDCEX bool isendwin(void); +PDCEX bool is_linetouched(WINDOW *, int); +PDCEX bool is_wintouched(WINDOW *); +PDCEX char *keyname(int); +PDCEX int keypad(WINDOW *, bool); +PDCEX char killchar(void); +PDCEX int leaveok(WINDOW *, bool); +PDCEX char *longname(void); +PDCEX int meta(WINDOW *, bool); +PDCEX int move(int, int); +PDCEX int mvaddch(int, int, const chtype); +PDCEX int mvaddchnstr(int, int, const chtype *, int); +PDCEX int mvaddchstr(int, int, const chtype *); +PDCEX int mvaddnstr(int, int, const char *, int); +PDCEX int mvaddstr(int, int, const char *); +PDCEX int mvchgat(int, int, int, attr_t, short, const void *); +PDCEX int mvcur(int, int, int, int); +PDCEX int mvdelch(int, int); +PDCEX int mvderwin(WINDOW *, int, int); +PDCEX int mvgetch(int, int); +PDCEX int mvgetnstr(int, int, char *, int); +PDCEX int mvgetstr(int, int, char *); +PDCEX int mvhline(int, int, chtype, int); +PDCEX chtype mvinch(int, int); +PDCEX int mvinchnstr(int, int, chtype *, int); +PDCEX int mvinchstr(int, int, chtype *); +PDCEX int mvinnstr(int, int, char *, int); +PDCEX int mvinsch(int, int, chtype); +PDCEX int mvinsnstr(int, int, const char *, int); +PDCEX int mvinsstr(int, int, const char *); +PDCEX int mvinstr(int, int, char *); +PDCEX int mvprintw(int, int, const char *, ...); +PDCEX int mvscanw(int, int, const char *, ...); +PDCEX int mvvline(int, int, chtype, int); +PDCEX int mvwaddchnstr(WINDOW *, int, int, const chtype *, int); +PDCEX int mvwaddchstr(WINDOW *, int, int, const chtype *); +PDCEX int mvwaddch(WINDOW *, int, int, const chtype); +PDCEX int mvwaddnstr(WINDOW *, int, int, const char *, int); +PDCEX int mvwaddstr(WINDOW *, int, int, const char *); +PDCEX int mvwchgat(WINDOW *, int, int, int, attr_t, short, const void *); +PDCEX int mvwdelch(WINDOW *, int, int); +PDCEX int mvwgetch(WINDOW *, int, int); +PDCEX int mvwgetnstr(WINDOW *, int, int, char *, int); +PDCEX int mvwgetstr(WINDOW *, int, int, char *); +PDCEX int mvwhline(WINDOW *, int, int, chtype, int); +PDCEX int mvwinchnstr(WINDOW *, int, int, chtype *, int); +PDCEX int mvwinchstr(WINDOW *, int, int, chtype *); +PDCEX chtype mvwinch(WINDOW *, int, int); +PDCEX int mvwinnstr(WINDOW *, int, int, char *, int); +PDCEX int mvwinsch(WINDOW *, int, int, chtype); +PDCEX int mvwinsnstr(WINDOW *, int, int, const char *, int); +PDCEX int mvwinsstr(WINDOW *, int, int, const char *); +PDCEX int mvwinstr(WINDOW *, int, int, char *); +PDCEX int mvwin(WINDOW *, int, int); +PDCEX int mvwprintw(WINDOW *, int, int, const char *, ...); +PDCEX int mvwscanw(WINDOW *, int, int, const char *, ...); +PDCEX int mvwvline(WINDOW *, int, int, chtype, int); +PDCEX int napms(int); +PDCEX WINDOW *newpad(int, int); +PDCEX SCREEN *newterm(const char *, FILE *, FILE *); +PDCEX WINDOW *newwin(int, int, int, int); +PDCEX int nl(void); +PDCEX int nocbreak(void); +PDCEX int nodelay(WINDOW *, bool); +PDCEX int noecho(void); +PDCEX int nonl(void); +PDCEX void noqiflush(void); +PDCEX int noraw(void); +PDCEX int notimeout(WINDOW *, bool); +PDCEX int overlay(const WINDOW *, WINDOW *); +PDCEX int overwrite(const WINDOW *, WINDOW *); +PDCEX int pair_content(short, short *, short *); +PDCEX int pechochar(WINDOW *, chtype); +PDCEX int pnoutrefresh(WINDOW *, int, int, int, int, int, int); +PDCEX int prefresh(WINDOW *, int, int, int, int, int, int); +PDCEX int printw(const char *, ...); +PDCEX int putwin(WINDOW *, FILE *); +PDCEX void qiflush(void); +PDCEX int raw(void); +PDCEX int redrawwin(WINDOW *); +PDCEX int refresh(void); +PDCEX int reset_prog_mode(void); +PDCEX int reset_shell_mode(void); +PDCEX int resetty(void); +PDCEX int ripoffline(int, int (*)(WINDOW *, int)); +PDCEX int savetty(void); +PDCEX int scanw(const char *, ...); +PDCEX int scr_dump(const char *); +PDCEX int scr_init(const char *); +PDCEX int scr_restore(const char *); +PDCEX int scr_set(const char *); +PDCEX int scrl(int); +PDCEX int scroll(WINDOW *); +PDCEX int scrollok(WINDOW *, bool); +PDCEX SCREEN *set_term(SCREEN *); +PDCEX int setscrreg(int, int); +PDCEX int slk_attroff(const chtype); +PDCEX int slk_attr_off(const attr_t, void *); +PDCEX int slk_attron(const chtype); +PDCEX int slk_attr_on(const attr_t, void *); +PDCEX int slk_attrset(const chtype); +PDCEX int slk_attr_set(const attr_t, short, void *); +PDCEX int slk_clear(void); +PDCEX int slk_color(short); +PDCEX int slk_init(int); +PDCEX char *slk_label(int); +PDCEX int slk_noutrefresh(void); +PDCEX int slk_refresh(void); +PDCEX int slk_restore(void); +PDCEX int slk_set(int, const char *, int); +PDCEX int slk_touch(void); +PDCEX int standend(void); +PDCEX int standout(void); +PDCEX int start_color(void); +PDCEX WINDOW *subpad(WINDOW *, int, int, int, int); +PDCEX WINDOW *subwin(WINDOW *, int, int, int, int); +PDCEX int syncok(WINDOW *, bool); +PDCEX chtype termattrs(void); +PDCEX attr_t term_attrs(void); +PDCEX char *termname(void); +PDCEX void timeout(int); +PDCEX int touchline(WINDOW *, int, int); +PDCEX int touchwin(WINDOW *); +PDCEX int typeahead(int); +PDCEX int untouchwin(WINDOW *); +PDCEX void use_env(bool); +PDCEX int vidattr(chtype); +PDCEX int vid_attr(attr_t, short, void *); +PDCEX int vidputs(chtype, int (*)(int)); +PDCEX int vid_puts(attr_t, short, void *, int (*)(int)); +PDCEX int vline(chtype, int); +PDCEX int vw_printw(WINDOW *, const char *, va_list); +PDCEX int vwprintw(WINDOW *, const char *, va_list); +PDCEX int vw_scanw(WINDOW *, const char *, va_list); +PDCEX int vwscanw(WINDOW *, const char *, va_list); +PDCEX int waddchnstr(WINDOW *, const chtype *, int); +PDCEX int waddchstr(WINDOW *, const chtype *); +PDCEX int waddch(WINDOW *, const chtype); +PDCEX int waddnstr(WINDOW *, const char *, int); +PDCEX int waddstr(WINDOW *, const char *); +PDCEX int wattroff(WINDOW *, chtype); +PDCEX int wattron(WINDOW *, chtype); +PDCEX int wattrset(WINDOW *, chtype); +PDCEX int wattr_get(WINDOW *, attr_t *, short *, void *); +PDCEX int wattr_off(WINDOW *, attr_t, void *); +PDCEX int wattr_on(WINDOW *, attr_t, void *); +PDCEX int wattr_set(WINDOW *, attr_t, short, void *); +PDCEX void wbkgdset(WINDOW *, chtype); +PDCEX int wbkgd(WINDOW *, chtype); +PDCEX int wborder(WINDOW *, chtype, chtype, chtype, chtype, + chtype, chtype, chtype, chtype); +PDCEX int wchgat(WINDOW *, int, attr_t, short, const void *); +PDCEX int wclear(WINDOW *); +PDCEX int wclrtobot(WINDOW *); +PDCEX int wclrtoeol(WINDOW *); +PDCEX int wcolor_set(WINDOW *, short, void *); +PDCEX void wcursyncup(WINDOW *); +PDCEX int wdelch(WINDOW *); +PDCEX int wdeleteln(WINDOW *); +PDCEX int wechochar(WINDOW *, const chtype); +PDCEX int werase(WINDOW *); +PDCEX int wgetch(WINDOW *); +PDCEX int wgetnstr(WINDOW *, char *, int); +PDCEX int wgetstr(WINDOW *, char *); +PDCEX int whline(WINDOW *, chtype, int); +PDCEX int winchnstr(WINDOW *, chtype *, int); +PDCEX int winchstr(WINDOW *, chtype *); +PDCEX chtype winch(WINDOW *); +PDCEX int winnstr(WINDOW *, char *, int); +PDCEX int winsch(WINDOW *, chtype); +PDCEX int winsdelln(WINDOW *, int); +PDCEX int winsertln(WINDOW *); +PDCEX int winsnstr(WINDOW *, const char *, int); +PDCEX int winsstr(WINDOW *, const char *); +PDCEX int winstr(WINDOW *, char *); +PDCEX int wmove(WINDOW *, int, int); +PDCEX int wnoutrefresh(WINDOW *); +PDCEX int wprintw(WINDOW *, const char *, ...); +PDCEX int wredrawln(WINDOW *, int, int); +PDCEX int wrefresh(WINDOW *); +PDCEX int wscanw(WINDOW *, const char *, ...); +PDCEX int wscrl(WINDOW *, int); +PDCEX int wsetscrreg(WINDOW *, int, int); +PDCEX int wstandend(WINDOW *); +PDCEX int wstandout(WINDOW *); +PDCEX void wsyncdown(WINDOW *); +PDCEX void wsyncup(WINDOW *); +PDCEX void wtimeout(WINDOW *, int); +PDCEX int wtouchln(WINDOW *, int, int, int); +PDCEX int wvline(WINDOW *, chtype, int); + +/* Wide-character functions */ + +#ifdef PDC_WIDE +PDCEX int addnwstr(const wchar_t *, int); +PDCEX int addwstr(const wchar_t *); +PDCEX int add_wch(const cchar_t *); +PDCEX int add_wchnstr(const cchar_t *, int); +PDCEX int add_wchstr(const cchar_t *); +PDCEX int border_set(const cchar_t *, const cchar_t *, const cchar_t *, + const cchar_t *, const cchar_t *, const cchar_t *, + const cchar_t *, const cchar_t *); +PDCEX int box_set(WINDOW *, const cchar_t *, const cchar_t *); +PDCEX int echo_wchar(const cchar_t *); +PDCEX int erasewchar(wchar_t *); +PDCEX int getbkgrnd(cchar_t *); +PDCEX int getcchar(const cchar_t *, wchar_t *, attr_t *, short *, void *); +PDCEX int getn_wstr(wint_t *, int); +PDCEX int get_wch(wint_t *); +PDCEX int get_wstr(wint_t *); +PDCEX int hline_set(const cchar_t *, int); +PDCEX int innwstr(wchar_t *, int); +PDCEX int ins_nwstr(const wchar_t *, int); +PDCEX int ins_wch(const cchar_t *); +PDCEX int ins_wstr(const wchar_t *); +PDCEX int inwstr(wchar_t *); +PDCEX int in_wch(cchar_t *); +PDCEX int in_wchnstr(cchar_t *, int); +PDCEX int in_wchstr(cchar_t *); +PDCEX char *key_name(wchar_t); +PDCEX int killwchar(wchar_t *); +PDCEX int mvaddnwstr(int, int, const wchar_t *, int); +PDCEX int mvaddwstr(int, int, const wchar_t *); +PDCEX int mvadd_wch(int, int, const cchar_t *); +PDCEX int mvadd_wchnstr(int, int, const cchar_t *, int); +PDCEX int mvadd_wchstr(int, int, const cchar_t *); +PDCEX int mvgetn_wstr(int, int, wint_t *, int); +PDCEX int mvget_wch(int, int, wint_t *); +PDCEX int mvget_wstr(int, int, wint_t *); +PDCEX int mvhline_set(int, int, const cchar_t *, int); +PDCEX int mvinnwstr(int, int, wchar_t *, int); +PDCEX int mvins_nwstr(int, int, const wchar_t *, int); +PDCEX int mvins_wch(int, int, const cchar_t *); +PDCEX int mvins_wstr(int, int, const wchar_t *); +PDCEX int mvinwstr(int, int, wchar_t *); +PDCEX int mvin_wch(int, int, cchar_t *); +PDCEX int mvin_wchnstr(int, int, cchar_t *, int); +PDCEX int mvin_wchstr(int, int, cchar_t *); +PDCEX int mvvline_set(int, int, const cchar_t *, int); +PDCEX int mvwaddnwstr(WINDOW *, int, int, const wchar_t *, int); +PDCEX int mvwaddwstr(WINDOW *, int, int, const wchar_t *); +PDCEX int mvwadd_wch(WINDOW *, int, int, const cchar_t *); +PDCEX int mvwadd_wchnstr(WINDOW *, int, int, const cchar_t *, int); +PDCEX int mvwadd_wchstr(WINDOW *, int, int, const cchar_t *); +PDCEX int mvwgetn_wstr(WINDOW *, int, int, wint_t *, int); +PDCEX int mvwget_wch(WINDOW *, int, int, wint_t *); +PDCEX int mvwget_wstr(WINDOW *, int, int, wint_t *); +PDCEX int mvwhline_set(WINDOW *, int, int, const cchar_t *, int); +PDCEX int mvwinnwstr(WINDOW *, int, int, wchar_t *, int); +PDCEX int mvwins_nwstr(WINDOW *, int, int, const wchar_t *, int); +PDCEX int mvwins_wch(WINDOW *, int, int, const cchar_t *); +PDCEX int mvwins_wstr(WINDOW *, int, int, const wchar_t *); +PDCEX int mvwin_wch(WINDOW *, int, int, cchar_t *); +PDCEX int mvwin_wchnstr(WINDOW *, int, int, cchar_t *, int); +PDCEX int mvwin_wchstr(WINDOW *, int, int, cchar_t *); +PDCEX int mvwinwstr(WINDOW *, int, int, wchar_t *); +PDCEX int mvwvline_set(WINDOW *, int, int, const cchar_t *, int); +PDCEX int pecho_wchar(WINDOW *, const cchar_t*); +PDCEX int setcchar(cchar_t*, const wchar_t*, const attr_t, + short, const void*); +PDCEX int slk_wset(int, const wchar_t *, int); +PDCEX int unget_wch(const wchar_t); +PDCEX int vline_set(const cchar_t *, int); +PDCEX int waddnwstr(WINDOW *, const wchar_t *, int); +PDCEX int waddwstr(WINDOW *, const wchar_t *); +PDCEX int wadd_wch(WINDOW *, const cchar_t *); +PDCEX int wadd_wchnstr(WINDOW *, const cchar_t *, int); +PDCEX int wadd_wchstr(WINDOW *, const cchar_t *); +PDCEX int wbkgrnd(WINDOW *, const cchar_t *); +PDCEX void wbkgrndset(WINDOW *, const cchar_t *); +PDCEX int wborder_set(WINDOW *, const cchar_t *, const cchar_t *, + const cchar_t *, const cchar_t *, const cchar_t *, + const cchar_t *, const cchar_t *, const cchar_t *); +PDCEX int wecho_wchar(WINDOW *, const cchar_t *); +PDCEX int wgetbkgrnd(WINDOW *, cchar_t *); +PDCEX int wgetn_wstr(WINDOW *, wint_t *, int); +PDCEX int wget_wch(WINDOW *, wint_t *); +PDCEX int wget_wstr(WINDOW *, wint_t *); +PDCEX int whline_set(WINDOW *, const cchar_t *, int); +PDCEX int winnwstr(WINDOW *, wchar_t *, int); +PDCEX int wins_nwstr(WINDOW *, const wchar_t *, int); +PDCEX int wins_wch(WINDOW *, const cchar_t *); +PDCEX int wins_wstr(WINDOW *, const wchar_t *); +PDCEX int winwstr(WINDOW *, wchar_t *); +PDCEX int win_wch(WINDOW *, cchar_t *); +PDCEX int win_wchnstr(WINDOW *, cchar_t *, int); +PDCEX int win_wchstr(WINDOW *, cchar_t *); +PDCEX wchar_t *wunctrl(cchar_t *); +PDCEX int wvline_set(WINDOW *, const cchar_t *, int); +#endif + +/* Quasi-standard */ + +PDCEX chtype getattrs(WINDOW *); +PDCEX int getbegx(WINDOW *); +PDCEX int getbegy(WINDOW *); +PDCEX int getmaxx(WINDOW *); +PDCEX int getmaxy(WINDOW *); +PDCEX int getparx(WINDOW *); +PDCEX int getpary(WINDOW *); +PDCEX int getcurx(WINDOW *); +PDCEX int getcury(WINDOW *); +PDCEX void traceoff(void); +PDCEX void traceon(void); +PDCEX char *unctrl(chtype); + +PDCEX int crmode(void); +PDCEX int nocrmode(void); +PDCEX int draino(int); +PDCEX int resetterm(void); +PDCEX int fixterm(void); +PDCEX int saveterm(void); +PDCEX void setsyx(int, int); + +PDCEX int mouse_set(unsigned long); +PDCEX int mouse_on(unsigned long); +PDCEX int mouse_off(unsigned long); +PDCEX int request_mouse_pos(void); +PDCEX int map_button(unsigned long); +PDCEX void wmouse_position(WINDOW *, int *, int *); +PDCEX unsigned long getmouse(void); +PDCEX unsigned long getbmap(void); + +/* ncurses */ + +PDCEX int assume_default_colors(int, int); +PDCEX const char *curses_version(void); +PDCEX bool has_key(int); +PDCEX int use_default_colors(void); +PDCEX int wresize(WINDOW *, int, int); + +PDCEX int mouseinterval(int); +PDCEX mmask_t mousemask(mmask_t, mmask_t *); +PDCEX bool mouse_trafo(int *, int *, bool); +PDCEX int nc_getmouse(MEVENT *); +PDCEX int ungetmouse(MEVENT *); +PDCEX bool wenclose(const WINDOW *, int, int); +PDCEX bool wmouse_trafo(const WINDOW *, int *, int *, bool); + +/* PDCurses */ + +PDCEX int addrawch(chtype); +PDCEX int insrawch(chtype); +PDCEX bool is_termresized(void); +PDCEX int mvaddrawch(int, int, chtype); +PDCEX int mvdeleteln(int, int); +PDCEX int mvinsertln(int, int); +PDCEX int mvinsrawch(int, int, chtype); +PDCEX int mvwaddrawch(WINDOW *, int, int, chtype); +PDCEX int mvwdeleteln(WINDOW *, int, int); +PDCEX int mvwinsertln(WINDOW *, int, int); +PDCEX int mvwinsrawch(WINDOW *, int, int, chtype); +PDCEX int raw_output(bool); +PDCEX int resize_term(int, int); +PDCEX WINDOW *resize_window(WINDOW *, int, int); +PDCEX int waddrawch(WINDOW *, chtype); +PDCEX int winsrawch(WINDOW *, chtype); +PDCEX char wordchar(void); + +#ifdef PDC_WIDE +PDCEX wchar_t *slk_wlabel(int); +#endif + +PDCEX void PDC_debug(const char *, ...); +PDCEX int PDC_ungetch(int); +PDCEX int PDC_set_blink(bool); +PDCEX int PDC_set_line_color(short); +PDCEX void PDC_set_title(const char *); + +PDCEX int PDC_clearclipboard(void); +PDCEX int PDC_freeclipboard(char *); +PDCEX int PDC_getclipboard(char **, long *); +PDCEX int PDC_setclipboard(const char *, long); + +PDCEX unsigned long PDC_get_input_fd(void); +PDCEX unsigned long PDC_get_key_modifiers(void); +PDCEX int PDC_return_key_modifiers(bool); +PDCEX int PDC_save_key_modifiers(bool); +PDCEX void PDC_set_resize_limits( const int new_min_lines, + const int new_max_lines, + const int new_min_cols, + const int new_max_cols); + +#define FUNCTION_KEY_SHUT_DOWN 0 +#define FUNCTION_KEY_PASTE 1 +#define FUNCTION_KEY_ENLARGE_FONT 2 +#define FUNCTION_KEY_SHRINK_FONT 3 +#define FUNCTION_KEY_CHOOSE_FONT 4 +#define FUNCTION_KEY_ABORT 5 +#define PDC_MAX_FUNCTION_KEYS 6 + +PDCEX int PDC_set_function_key( const unsigned function, + const int new_key); + +PDCEX WINDOW *Xinitscr(int, char **); +#ifdef XCURSES +PDCEX void XCursesExit(void); +PDCEX int sb_init(void); +PDCEX int sb_set_horz(int, int, int); +PDCEX int sb_set_vert(int, int, int); +PDCEX int sb_get_horz(int *, int *, int *); +PDCEX int sb_get_vert(int *, int *, int *); +PDCEX int sb_refresh(void); + #endif + +/*** Functions defined as macros ***/ + +/* getch() and ungetch() conflict with some DOS libraries */ + +#define getch() wgetch(stdscr) +#define ungetch(ch) PDC_ungetch(ch) + +#define COLOR_PAIR(n) (((chtype)(n) << PDC_COLOR_SHIFT) & A_COLOR) +#define PAIR_NUMBER(n) ((((n) & A_COLOR) >> PDC_COLOR_SHIFT) & 0xff) + +/* These will _only_ work as macros */ + +#define getbegyx(w, y, x) (y = getbegy(w), x = getbegx(w)) +#define getmaxyx(w, y, x) (y = getmaxy(w), x = getmaxx(w)) +#define getparyx(w, y, x) (y = getpary(w), x = getparx(w)) +#define getyx(w, y, x) (y = getcury(w), x = getcurx(w)) + +#define getsyx(y, x) { if (curscr->_leaveit) (y)=(x)=-1; \ + else getyx(curscr,(y),(x)); } + +#ifdef NCURSES_MOUSE_VERSION +# define getmouse(x) nc_getmouse(x) +#endif + +/* return codes from PDC_getclipboard() and PDC_setclipboard() calls */ + +#define PDC_CLIP_SUCCESS 0 +#define PDC_CLIP_ACCESS_ERROR 1 +#define PDC_CLIP_EMPTY 2 +#define PDC_CLIP_MEMORY_ERROR 3 + +/* PDCurses key modifier masks */ + +#define PDC_KEY_MODIFIER_SHIFT 1 +#define PDC_KEY_MODIFIER_CONTROL 2 +#define PDC_KEY_MODIFIER_ALT 4 +#define PDC_KEY_MODIFIER_NUMLOCK 8 +#define PDC_KEY_MODIFIER_REPEAT 16 + +#ifdef __cplusplus +# undef bool +} +#endif + +#endif /* __PDCURSES__ */ diff --git a/src/cc/rogue/x86_64-w64-msvc/deps/install/include/curspriv.h b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/curspriv.h new file mode 100644 index 000000000..b5edcc173 --- /dev/null +++ b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/curspriv.h @@ -0,0 +1,134 @@ +/* Public Domain Curses */ + +/* Private definitions and declarations for use within PDCurses. + These should generally not be referenced by applications. */ + +#ifndef __CURSES_INTERNALS__ +#define __CURSES_INTERNALS__ 1 + +#define CURSES_LIBRARY +#include + +#if defined(__TURBOC__) || defined(__EMX__) || defined(__DJGPP__) || \ + defined(__CYGWIN__) || defined(__MINGW32__) || \ + defined(__WATCOMC__) || defined(__PACIFIC__) +# ifndef HAVE_VSSCANF +# define HAVE_VSSCANF /* have vsscanf() */ +# endif +#endif + +#if defined(__CYGWIN__) || defined(__MINGW32__) || \ + defined(__LCC__) || defined(__WATCOMC__) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF /* have vsnprintf() */ +# endif +#endif + +#if defined(_MSC_VER) && defined(_WIN32) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE 1 /* kill nonsense warnings */ +#endif + +/*----------------------------------------------------------------------*/ + +typedef struct /* structure for ripped off lines */ +{ + int line; + int (*init)(WINDOW *, int); +} RIPPEDOFFLINE; + +/* Window properties */ + +#define _SUBWIN 0x01 /* window is a subwindow */ +#define _PAD 0x10 /* X/Open Pad. */ +#define _SUBPAD 0x20 /* X/Open subpad. */ + +/* Miscellaneous */ + +#define _NO_CHANGE -1 /* flags line edge unchanged */ + +#define _ECHAR 0x08 /* Erase char (^H) */ +#define _DWCHAR 0x17 /* Delete Word char (^W) */ +#define _DLCHAR 0x15 /* Delete Line char (^U) */ + +extern WINDOW *pdc_lastscr; +extern FILE *pdc_dbfp; /* tracing file pointer (NULL = off) */ +extern bool pdc_color_started; +extern unsigned long pdc_key_modifiers; +extern MOUSE_STATUS pdc_mouse_status; + +/*----------------------------------------------------------------------*/ + +/* Platform implementation functions */ + +void PDC_beep(void); +bool PDC_can_change_color(void); +int PDC_color_content(short, short *, short *, short *); +bool PDC_check_key(void); +int PDC_curs_set(int); +void PDC_flushinp(void); +int PDC_get_columns(void); +int PDC_get_cursor_mode(void); +int PDC_get_key(void); +int PDC_get_rows(void); +void PDC_gotoyx(int, int); +int PDC_init_color(short, short, short, short); +void PDC_init_pair(short, short, short); +int PDC_modifiers_set(void); +int PDC_mouse_set(void); +void PDC_napms(int); +int PDC_pair_content(short, short *, short *); +void PDC_reset_prog_mode(void); +void PDC_reset_shell_mode(void); +int PDC_resize_screen(int, int); +void PDC_restore_screen_mode(int); +void PDC_save_screen_mode(int); +void PDC_scr_close(void); +void PDC_scr_free(void); +int PDC_scr_open(int, char **); +void PDC_set_keyboard_binary(bool); +void PDC_transform_line(int, int, int, const chtype *); +const char *PDC_sysname(void); + +/* Internal cross-module functions */ + +void PDC_init_atrtab(void); +WINDOW *PDC_makelines(WINDOW *); +WINDOW *PDC_makenew(int, int, int, int); +int PDC_mouse_in_slk(int, int); +void PDC_slk_free(void); +void PDC_slk_initialize(void); +void PDC_sync(WINDOW *); + +#ifdef PDC_WIDE +int PDC_mbtowc(wchar_t *, const char *, size_t); +size_t PDC_mbstowcs(wchar_t *, const char *, size_t); +size_t PDC_wcstombs(char *, const wchar_t *, size_t); +#endif + +#ifdef PDCDEBUG +# define PDC_LOG(x) if (pdc_dbfp) PDC_debug x +#else +# define PDC_LOG(x) +#endif + +/* Internal macros for attributes */ + +#ifdef CHTYPE_LONG +# define PDC_COLOR_PAIRS 256 +#else +# define PDC_COLOR_PAIRS 32 +#endif + +#ifndef max +# define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif +#ifndef min +# define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#define DIVROUND(num, divisor) (((num) + ((divisor) >> 1)) / (divisor)) + +#define PDC_CLICK_PERIOD 150 /* time to wait for a click, if + not set by mouseinterval() */ + +#endif /* __CURSES_INTERNALS__*/ diff --git a/src/cc/rogue/x86_64-w64-msvc/deps/install/include/getopt.h b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/getopt.h new file mode 100644 index 000000000..4de6e853e --- /dev/null +++ b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/getopt.h @@ -0,0 +1,93 @@ +/* $Id: getopt.h,v 1.1 2009/10/16 19:50:28 rodney Exp rodney $ */ +/* $OpenBSD: getopt.h,v 1.1 2002/12/03 20:24:29 millert Exp $ */ +/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GETOPT_H_ +#define _GETOPT_H_ + +#if 0 +#include +#endif + +/* + * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions + */ +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + /* name of long option */ + const char *name; + /* + * one of no_argument, required_argument, and optional_argument: + * whether option takes an argument + */ + int has_arg; + /* if not NULL, set *flag to val when option found */ + int *flag; + /* if flag not NULL, value to set *flag to; else return value */ + int val; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +int getopt_long(int, char * const *, const char *, + const struct option *, int *); +int getopt_long_only(int, char * const *, const char *, + const struct option *, int *); +#ifndef _GETOPT_DEFINED +#define _GETOPT_DEFINED +int getopt(int, char * const *, const char *); +int getsubopt(char **, char * const *, char **); + +extern char *optarg; /* getopt(3) external variables */ +extern int opterr; +extern int optind; +extern int optopt; +extern int optreset; +extern char *suboptarg; /* getsubopt(3) external variable */ +#endif /* _GETOPT_DEFINED */ + +#ifdef __cplusplus +} +#endif +#endif /* !_GETOPT_H_ */ diff --git a/src/cc/rogue/x86_64-w64-msvc/deps/install/include/panel.h b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/panel.h new file mode 100644 index 000000000..7f1fb1f17 --- /dev/null +++ b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/panel.h @@ -0,0 +1,56 @@ +/* Public Domain Curses */ + +/*----------------------------------------------------------------------* + * Panels for PDCurses * + *----------------------------------------------------------------------*/ + +#ifndef __PDCURSES_PANEL_H__ +#define __PDCURSES_PANEL_H__ 1 + +#include + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +extern "C" +{ +#endif + +typedef struct panelobs +{ + struct panelobs *above; + struct panel *pan; +} PANELOBS; + +typedef struct panel +{ + WINDOW *win; + int wstarty; + int wendy; + int wstartx; + int wendx; + struct panel *below; + struct panel *above; + const void *user; + struct panelobs *obscure; +} PANEL; + +PDCEX int bottom_panel(PANEL *pan); +PDCEX int del_panel(PANEL *pan); +PDCEX int hide_panel(PANEL *pan); +PDCEX int move_panel(PANEL *pan, int starty, int startx); +PDCEX PANEL *new_panel(WINDOW *win); +PDCEX PANEL *panel_above(const PANEL *pan); +PDCEX PANEL *panel_below(const PANEL *pan); +PDCEX int panel_hidden(const PANEL *pan); +PDCEX const void *panel_userptr(const PANEL *pan); +PDCEX WINDOW *panel_window(const PANEL *pan); +PDCEX int replace_panel(PANEL *pan, WINDOW *win); +PDCEX int set_panel_userptr(PANEL *pan, const void *uptr); +PDCEX int show_panel(PANEL *pan); +PDCEX int top_panel(PANEL *pan); +PDCEX void update_panels(void); + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +} +#endif + +#endif /* __PDCURSES_PANEL_H__ */ diff --git a/src/cc/rogue/x86_64-w64-msvc/deps/install/include/term.h b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/term.h new file mode 100644 index 000000000..0ba0b7a7f --- /dev/null +++ b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/term.h @@ -0,0 +1,48 @@ +/* Public Domain Curses */ + +/* PDCurses doesn't operate with terminfo, but we need these functions for + compatibility, to allow some things (notably, interface libraries for + other languages) to be compiled. Anyone who tries to actually _use_ + them will be disappointed, since they only return ERR. */ + +#ifndef __PDCURSES_TERM_H__ +#define __PDCURSES_TERM_H__ 1 + +#include + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +extern "C" +{ +#endif + +typedef struct +{ + const char *_termname; +} TERMINAL; + +/* PDCEX is defined in curses.h */ +PDCEX TERMINAL *cur_term; + +int del_curterm(TERMINAL *); +int putp(const char *); +int restartterm(const char *, int, int *); +TERMINAL *set_curterm(TERMINAL *); +int setterm(const char *); +int setupterm(const char *, int, int *); +int tgetent(char *, const char *); +int tgetflag(const char *); +int tgetnum(const char *); +char *tgetstr(const char *, char **); +char *tgoto(const char *, int, int); +int tigetflag(const char *); +int tigetnum(const char *); +char *tigetstr(const char *); +char *tparm(const char *, long, long, long, long, long, + long, long, long, long); +int tputs(const char *, int, int (*)(int)); + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +} +#endif + +#endif /* __PDCURSES_TERM_H__ */ diff --git a/src/cc/rogue/x86_64-w64-msvc/deps/install/include/unistd.h b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/unistd.h new file mode 100644 index 000000000..5d2440309 --- /dev/null +++ b/src/cc/rogue/x86_64-w64-msvc/deps/install/include/unistd.h @@ -0,0 +1,56 @@ +#ifndef _UNISTD_H +#define _UNISTD_H 1 + +/* This is intended as a drop-in replacement for unistd.h on Windows. + * Please add functionality as neeeded. + * https://stackoverflow.com/a/826027/1202830 + */ + +#include +#include +#include /* getopt at: https://gist.github.com/ashelly/7776712 */ +#include /* for getpid() and the exec..() family */ +#include /* for _getcwd() and _chdir() */ + +#define srandom srand +#define random rand + +/* Values for the second argument to access. + These may be OR'd together. */ +#define R_OK 4 /* Test for read permission. */ +#define W_OK 2 /* Test for write permission. */ +//#define X_OK 1 /* execute permission - unsupported in windows*/ +#define F_OK 0 /* Test for existence. */ + +#define access _access +#define dup2 _dup2 +#define execve _execve +#define ftruncate _chsize +#define unlink _unlink +#define fileno _fileno +#define getcwd _getcwd +#define chdir _chdir +#define isatty _isatty +#define lseek _lseek +/* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */ + +#ifdef _WIN64 +#define ssize_t __int64 +#else +#define ssize_t long +#endif + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +/* should be in some equivalent to */ +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; + +#endif /* unistd.h */ \ No newline at end of file diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index f765a17b9..5dc970bc8 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -321,6 +321,26 @@ int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransa } else return(-1); } +void disp_playerdata(std::vector playerdata) +{ + struct rogue_player P; int32_t i; char packitemstr[512]; + if ( playerdata.size() > 0 ) + { + for (i=0; i>16,P.level,P.experience,P.dungeonlevel); + for (i=0; i playerdata,uint256 playertxid,uint256 tokenid,std::string symbol,std::string pname,uint256 gametxid) { int32_t i,vout,spentvini,numvouts,n=0; uint256 txid,spenttxid,hashBlock; struct rogue_player P; char packitemstr[512],*datastr=0; UniValue obj(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx; @@ -487,6 +507,8 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke int32_t i,numvouts,spentvini,n,matches = 0; CPubKey pk; uint256 tid,active,spenttxid,tokenid,hashBlock,txid,origplayergame; CTransaction spenttx,matchtx,batontx; std::vector checkdata; CBlockIndex *pindex; char ccaddr[64],*keystrokes=0; batonvalue = numkeys = numplayers = batonht = 0; playertxid = batontxid = zeroid; + if ( keystrokesp != 0 ) + *keystrokesp = 0; for (i=0; i 0 ) { @@ -969,6 +991,7 @@ char *rogue_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vecto fclose(fp); } } + //fprintf(stderr,"call replay2\n"); num = rogue_replay2(newplayer,seed,keystrokes,numkeys,playerdata.size()==0?0:&P,0); newdata.resize(num); for (i=0; i no playerdata\n"); @@ -1075,17 +1099,14 @@ int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C *cashoutp = 0; roguepk = GetUnspendable(cp,0); GetCCaddress1of2(cp,rogueaddr,roguepk,pk); - //fprintf(stderr,"call extractgame\n"); if ( (keystrokes= rogue_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,rogueaddr)) != 0 ) { - //fprintf(stderr,"numkeys.%d rogue_extractgame %s\n",numkeys,gametxid.GetHex().c_str()); free(keystrokes); sprintf(fname,"rogue.%llu.pack",(long long)seed); remove(fname); - //fprintf(stderr,"extracted.(%s)\n",str); - for (i=0; i>16,P.level,P.experience,P.dungeonlevel); fprintf(stderr,"newdata[%d] != playerdata[%d], numkeys.%d %s pub.%s playertxid.%s good.%d bad.%d\n",(int32_t)newdata.size(),(int32_t)playerdata.size(),numkeys,rogueaddr,pubkey33_str(str2,(uint8_t *)&pk),playertxid.GetHex().c_str(),good,bad); } @@ -1230,8 +1264,8 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param if ( P.amulet != 0 ) mult *= 5; dungeonlevel = P.dungeonlevel; - if ( P.amulet != 0 && dungeonlevel < 21 ) - dungeonlevel = 21; + if ( P.amulet != 0 && dungeonlevel < 26 ) + dungeonlevel = 26; cashout = (uint64_t)P.gold * P.gold * mult * dungeonlevel; fprintf(stderr,"\nextracted $$$gold.%d -> %.8f ROGUE hp.%d strength.%d/%d level.%d exp.%d dl.%d n.%d amulet.%d\n",P.gold,(double)cashout/COIN,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel,n,P.amulet); if ( funcid == 'H' && maxplayers > 1 ) @@ -1465,6 +1499,8 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C if ( (numvouts= tx.vout.size()) > 1 ) { txid = tx.GetHash(); + if ( txid == Parseuint256("1ae04dc0c5f2fca2053819a3a1b2efe5d355c34f58d6f16d59e5e2573e7baf7f") ) // osx rogue chain ht.50902 + enabled = 0; scriptPubKey = tx.vout[numvouts-1].scriptPubKey; GetOpReturnData(scriptPubKey,vopret); if ( vopret.size() > 2 ) @@ -1539,29 +1575,32 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C return eval->Invalid("couldnt decode H/Q opret"); } // verify pk belongs to this tx - if ( tokentx == 'c' && playerdata.size() > 0 ) + if ( tokentx == 'c' ) { - static char laststr[512]; char cashstr[512]; - if ( rogue_playerdata_validate(&cashout,ptxid,cp,playerdata,gametxid,pk) < 0 ) + if ( playerdata.size() > 0 ) { - sprintf(cashstr,"tokentx.(%c) decoded.%d ht.%d gametxid.%s player.%s invalid playerdata[%d]\n",tokentx,decoded,height,gametxid.GetHex().c_str(),ptxid.GetHex().c_str(),(int32_t)playerdata.size()); + static char laststr[512]; char cashstr[512]; + if ( rogue_playerdata_validate(&cashout,ptxid,cp,playerdata,gametxid,pk) < 0 ) + { + sprintf(cashstr,"tokentx.(%c) decoded.%d ht.%d gametxid.%s player.%s invalid playerdata[%d]\n",tokentx,decoded,height,gametxid.GetHex().c_str(),ptxid.GetHex().c_str(),(int32_t)playerdata.size()); + if ( strcmp(laststr,cashstr) != 0 ) + { + strcpy(laststr,cashstr); + fprintf(stderr,"%s\n",cashstr); + } + if ( enabled != 0 ) + return eval->Invalid("mismatched playerdata"); + } + if ( funcid == 'H' ) + cashout *= 2; + sprintf(cashstr,"tokentx.(%c) decoded.%d ht.%d txid.%s %.8f vs vout2 %.8f",tokentx,decoded,height,txid.GetHex().c_str(),(double)cashout/COIN,(double)tx.vout[2].nValue/COIN); if ( strcmp(laststr,cashstr) != 0 ) { strcpy(laststr,cashstr); fprintf(stderr,"%s\n",cashstr); } - if ( enabled != 0 ) - return eval->Invalid("mismatched playerdata"); - } - if ( funcid == 'H' ) - cashout *= 2; - sprintf(cashstr,"tokentx.(%c) decoded.%d ht.%d txid.%s %.8f vs vout2 %.8f",tokentx,decoded,height,txid.GetHex().c_str(),(double)cashout/COIN,(double)tx.vout[2].nValue/COIN); - if ( strcmp(laststr,cashstr) != 0 ) - { - strcpy(laststr,cashstr); - fprintf(stderr,"%s\n",cashstr); - } - if ( enabled != 0 && tx.vout[2].nValue != cashout ) + } else cashout = 10000; + if ( enabled != 0 && tx.vout[2].nValue > cashout ) return eval->Invalid("mismatched cashout amount"); } if ( funcid == 'Q' ) diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index 254c9b135..d6ae473fe 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -858,7 +858,7 @@ int main(int argc, char **argv) next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1); score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1); - + int32_t counter = 0; // Game loop while (running) { running = tg_tick(tg, move); @@ -866,7 +866,8 @@ int main(int argc, char **argv) display_piece(next, tg->next); display_piece(hold, tg->stored); display_score(score, tg); - doupdate(); + if ( (counter++ % 5) == 0 ) + doupdate(); sleep_milli(10); switch (getch()) { diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 5be94dc94..6dac120e4 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1655,6 +1655,87 @@ UniValue getmempoolinfo(const UniValue& params, bool fHelp) return mempoolInfoToJSON(); } +inline CBlockIndex* LookupBlockIndex(const uint256& hash) +{ + AssertLockHeld(cs_main); + BlockMap::const_iterator it = mapBlockIndex.find(hash); + return it == mapBlockIndex.end() ? nullptr : it->second; +} + +UniValue getchaintxstats(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() > 2) + throw runtime_error( + "getchaintxstats\n" + "\nCompute statistics about the total number and rate of transactions in the chain.\n" + "\nArguments:\n" + "1. nblocks (numeric, optional) Number of blocks in averaging window.\n" + "2. blockhash (string, optional) The hash of the block which ends the window.\n" + "\nResult:\n" + "{\n" + " \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n" + " \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n" + " \"window_final_block_hash\": \"...\", (string) The hash of the final block in the window.\n" + " \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n" + " \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n" + " \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n" + " \"txrate\": x.xx, (numeric) The average rate of transactions per second in the window. Only returned if \"window_interval\" is > 0.\n" + "}\n" + "\nExamples:\n" + + HelpExampleCli("getchaintxstats", "") + + HelpExampleRpc("getchaintxstats", "2016") + ); + + const CBlockIndex* pindex; + int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month + + if (params[1].isNull()) { + LOCK(cs_main); + pindex = chainActive.Tip(); + } else { + uint256 hash(ParseHashV(params[1], "blockhash")); + LOCK(cs_main); + pindex = LookupBlockIndex(hash); + if (!pindex) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); + } + if (!chainActive.Contains(pindex)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Block is not in main chain"); + } + } + + assert(pindex != nullptr); + + if (params[0].isNull()) { + blockcount = std::max(0, std::min(blockcount, pindex->GetHeight() - 1)); + } else { + blockcount = params[0].get_int(); + + if (blockcount < 0 || (blockcount > 0 && blockcount >= pindex->GetHeight())) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 0 and the block's height - 1"); + } + } + + const CBlockIndex* pindexPast = pindex->GetAncestor(pindex->GetHeight() - blockcount); + int nTimeDiff = pindex->GetMedianTimePast() - pindexPast->GetMedianTimePast(); + int nTxDiff = pindex->nChainTx - pindexPast->nChainTx; + + UniValue ret(UniValue::VOBJ); + ret.pushKV("time", (int64_t)pindex->nTime); + ret.pushKV("txcount", (int64_t)pindex->nChainTx); + ret.pushKV("window_final_block_hash", pindex->GetBlockHash().GetHex()); + ret.pushKV("window_block_count", blockcount); + if (blockcount > 0) { + ret.pushKV("window_tx_count", nTxDiff); + ret.pushKV("window_interval", nTimeDiff); + if (nTimeDiff > 0) { + ret.pushKV("txrate", ((double)nTxDiff) / nTimeDiff); + } + } + + return ret; +} + UniValue invalidateblock(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -1742,6 +1823,7 @@ static const CRPCCommand commands[] = { "blockchain", "getblockhash", &getblockhash, true }, { "blockchain", "getblockheader", &getblockheader, true }, { "blockchain", "getchaintips", &getchaintips, true }, + { "blockchain", "getchaintxstats", &getchaintxstats, true }, { "blockchain", "getdifficulty", &getdifficulty, true }, { "blockchain", "getmempoolinfo", &getmempoolinfo, true }, { "blockchain", "getrawmempool", &getrawmempool, true }, diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 3cbde9f10..19910b25c 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -89,6 +89,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "listunspent", 2 }, { "getblock", 1 }, { "getblockheader", 1 }, + { "getchaintxstats", 0 }, { "getlastsegidstakes", 0 }, { "gettransaction", 1 }, { "getrawtransaction", 1 }, diff --git a/src/txdb.cpp b/src/txdb.cpp index b798599b7..0588d52de 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -441,7 +441,7 @@ uint32_t komodo_segid32(char *coinaddr); UniValue CBlockTreeDB::Snapshot(int top) { int64_t total = 0; int64_t totalAddresses = 0; std::string address; - int64_t utxos = 0; int64_t ignoredAddresses; + int64_t utxos = 0; int64_t ignoredAddresses = 0; boost::scoped_ptr iter(NewIterator()); std::map addressAmounts; std::vector > vaddr; @@ -491,27 +491,31 @@ UniValue CBlockTreeDB::Snapshot(int top) getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); - std::map ::iterator ignored = ignoredMap.find(address); - if (ignored != ignoredMap.end()) { - fprintf(stderr,"ignoring %s\n", address.c_str()); - ignoredAddresses++; - continue; - } + if (nValue > 0) { + std::map ::iterator ignored = ignoredMap.find(address); + if (ignored != ignoredMap.end()) { + fprintf(stderr,"ignoring %s\n", address.c_str()); + ignoredAddresses++; + continue; + } - std::map ::iterator pos = addressAmounts.find(address); - if (pos == addressAmounts.end()) { - // insert new address + utxo amount - //fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); - addressAmounts[address] = nValue; - totalAddresses++; + std::map ::iterator pos = addressAmounts.find(address); + if (pos == addressAmounts.end()) { + // insert new address + utxo amount + //fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + addressAmounts[address] = nValue; + totalAddresses++; + } else { + // update unspent tally for this address + //fprintf(stderr, "updating address %s with new utxo amount %li\n", address.c_str(), nValue); + addressAmounts[address] += nValue; + } + //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); + // total += nValue; + utxos++; } else { - // update unspent tally for this address - //fprintf(stderr, "updating address %s with new utxo amount %li\n", address.c_str(), nValue); - addressAmounts[address] += nValue; + fprintf(stderr,"ignoring amount=0 UTXO for %s\n", address.c_str()); } - //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - // total += nValue; - utxos++; } catch (const std::exception& e) { fprintf(stderr, "DONE %s: LevelDB addressindex exception! - %s\n", __func__, e.what()); break; From d8d7463ea05274a28a00dc193cfc39c19296ba60 Mon Sep 17 00:00:00 2001 From: blackjok3rtt <30971146+blackjok3rtt@users.noreply.github.com> Date: Mon, 18 Mar 2019 15:22:20 +0800 Subject: [PATCH 002/111] Fix sendmany bug for Alright (#1336) * fix sendmany bug, when sending to multiple address diffrent amounts would always use the first seen value. * Possible fix for multi node musig. Needs to be tested. Was getting stuck at nonce stage, as reported by gcharang. --- src/cc/musig.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 35293088c..bc113bc5c 100644 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -538,7 +538,7 @@ UniValue musig_commit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) for (i=0; i<33; i++) sprintf(&str[i<<1],"%02x",((uint8_t *)pk.begin())[i]); str[66] = 0; - if ( n == 5 ) + if ( n == 3 ) MUSIG[myind]->numnonces = 1; result.push_back(Pair("myind",MUSIG[myind]->myind)); result.push_back(Pair("nonce",str)); @@ -629,7 +629,7 @@ UniValue musig_nonce(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) result.push_back(Pair("myind",MUSIG[myind]->myind)); result.push_back(Pair("partialsig",str)); result.push_back(Pair("result","success")); - if ( n == 5 ) + if ( n == 3 ) MUSIG[myind]->numpartials = 1; return(result); } else return(cclib_error(result,"error serializing partial sig")); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 38c21d2bd..471364b91 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1457,24 +1457,19 @@ UniValue sendmany(const UniValue& params, bool fHelp) if (params.size() > 4) subtractFeeFromAmount = params[4].get_array(); - std::set destinations; std::vector vecSend; CAmount totalAmount = 0; std::vector keys = sendTo.getKeys(); + int32_t i = 0; for (const std::string& name_ : keys) { CTxDestination dest = DecodeDestination(name_); if (!IsValidDestination(dest)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Zcash address: ") + name_); } - /*if (destinations.count(dest)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ") + name_); - }*/ - destinations.insert(dest); - CScript scriptPubKey = GetScriptForDestination(dest); - CAmount nAmount = AmountFromValue(sendTo[name_]); + CAmount nAmount = AmountFromValue(sendTo[i]); if (nAmount <= 0) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); totalAmount += nAmount; @@ -1488,6 +1483,7 @@ UniValue sendmany(const UniValue& params, bool fHelp) CRecipient recipient = {scriptPubKey, nAmount, fSubtractFeeFromAmount}; vecSend.push_back(recipient); + i++; } EnsureWalletIsUnlocked(); From 7fbcfc27e3e4ee4fe383c24d531713865aa50fe9 Mon Sep 17 00:00:00 2001 From: smk762 <35845239+smk762@users.noreply.github.com> Date: Sat, 23 Mar 2019 15:29:23 +0800 Subject: [PATCH 003/111] Update cryptoconditions.py update keys, remove failing tokens tests (no tokenid) --- qa/rpc-tests/cryptoconditions.py | 49 ++++++++++++-------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index ee119b75a..d5456e801 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -3,7 +3,6 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. - from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ @@ -25,7 +24,6 @@ def generate_random_string(length): random_string = ''.join(choice(ascii_uppercase) for i in range(length)) return random_string - class CryptoConditionsTest (BitcoinTestFramework): def setup_chain(self): @@ -105,13 +103,13 @@ class CryptoConditionsTest (BitcoinTestFramework): faucet = rpc.faucetaddress() assert_equal(faucet['result'], 'success') # verify all keys look like valid AC addrs, could be better - for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: + for x in ['myCCAddress(Faucet)', 'FaucetCCAddress', 'FaucetCCTokensAddress', 'myaddress', 'FaucetNormalAddress']: assert_equal(faucet[x][0], 'R') - + result = rpc.faucetaddress(self.pubkey) assert_success(result) # test that additional CCaddress key is returned - for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress', 'CCaddress']: + for x in ['myCCAddress(Faucet)', 'FaucetCCAddress', 'FaucetCCTokensAddress', 'myaddress', 'FaucetNormalAddress']: assert_equal(result[x][0], 'R') # no funds in the faucet yet @@ -179,12 +177,12 @@ class CryptoConditionsTest (BitcoinTestFramework): dice = rpc.diceaddress() assert_equal(dice['result'], 'success') - for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: + for x in ['myCCAddress(Dice)', 'DiceCCAddress', 'DiceCCTokensAddress', 'myaddress', 'DiceNormalAddress']: assert_equal(dice[x][0], 'R') dice = rpc.diceaddress(self.pubkey) assert_equal(dice['result'], 'success') - for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress', 'CCaddress']: + for x in ['myCCAddress(Dice)', 'DiceCCAddress', 'DiceCCTokensAddress', 'myaddress', 'DiceNormalAddress']: assert_equal(dice[x][0], 'R') # no dice created yet @@ -333,12 +331,12 @@ class CryptoConditionsTest (BitcoinTestFramework): rpc = self.nodes[0] result = rpc.tokenaddress() assert_success(result) - for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + for x in ['myCCAddress(Tokens)', 'TokensNormalAddress', 'TokensNormalAddress', 'myaddress','TokensCCAddress']: assert_equal(result[x][0], 'R') result = rpc.tokenaddress(self.pubkey) assert_success(result) - for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']: + for x in ['myCCAddress(Tokens)', 'TokensNormalAddress', 'TokensNormalAddress', 'myaddress','TokensCCAddress']: assert_equal(result[x][0], 'R') # there are no tokens created yet result = rpc.tokenlist() @@ -361,17 +359,6 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenlist() assert_equal(result[0], tokenid) - # there are no token orders yet - result = rpc.tokenorders() - assert_equal(result, []) - - # getting token balance for pubkey - result = rpc.tokenbalance(self.pubkey) - assert_success(result) - assert_equal(result['balance'], 0) - assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') - assert_equal(result['tokenid'], self.pubkey) - # get token balance for token with pubkey result = rpc.tokenbalance(tokenid, self.pubkey) assert_success(result) @@ -421,7 +408,7 @@ class CryptoConditionsTest (BitcoinTestFramework): tokenask = rpc.tokenask("100", tokenid, "7.77") tokenaskhex = tokenask['hex'] tokenaskid = self.send_and_mine(tokenask['hex'], rpc) - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) order = result[0] assert order, "found order" @@ -440,7 +427,7 @@ class CryptoConditionsTest (BitcoinTestFramework): assert txid, "found txid" # should be no token orders - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) assert_equal(result, []) # checking ask cancellation @@ -448,7 +435,7 @@ class CryptoConditionsTest (BitcoinTestFramework): testorderid = self.send_and_mine(testorder['hex'], rpc) cancel = rpc.tokencancelask(tokenid, testorderid) self.send_and_mine(cancel["hex"], rpc) - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) assert_equal(result, []) # invalid numtokens bid @@ -474,7 +461,7 @@ class CryptoConditionsTest (BitcoinTestFramework): tokenbid = rpc.tokenbid("100", tokenid, "10") tokenbidhex = tokenbid['hex'] tokenbidid = self.send_and_mine(tokenbid['hex'], rpc) - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) order = result[0] assert order, "found order" @@ -493,7 +480,7 @@ class CryptoConditionsTest (BitcoinTestFramework): assert txid, "found txid" # should be no token orders - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) assert_equal(result, []) # checking bid cancellation @@ -501,7 +488,7 @@ class CryptoConditionsTest (BitcoinTestFramework): testorderid = self.send_and_mine(testorder['hex'], rpc) cancel = rpc.tokencancelbid(tokenid, testorderid) self.send_and_mine(cancel["hex"], rpc) - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) assert_equal(result, []) # invalid token transfer amount (have to add status to CC code!) @@ -522,11 +509,11 @@ class CryptoConditionsTest (BitcoinTestFramework): def run_rewards_tests(self): rpc = self.nodes[0] result = rpc.rewardsaddress() - for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress']: + for x in ['myCCAddress(Rewards)', 'myaddress', 'RewardsCCAddress', 'RewardsCCTokensAddress', 'RewardsNormalAddress']: assert_equal(result[x][0], 'R') result = rpc.rewardsaddress(self.pubkey) - for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress', 'CCaddress']: + for x in ['myCCAddress(Rewards)', 'myaddress', 'RewardsCCAddress', 'RewardsCCTokensAddress', 'RewardsNormalAddress']: assert_equal(result[x][0], 'R') # no rewards yet @@ -637,12 +624,13 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.oraclesaddress() assert_success(result) - for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']: + + for x in ['OraclesCCAddress', 'OraclesNormalAddress', 'myCCAddress(Oracles)','OraclesCCTokensAddress', 'myaddress']: assert_equal(result[x][0], 'R') result = rpc.oraclesaddress(self.pubkey) assert_success(result) - for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']: + for x in ['OraclesCCAddress', 'OraclesNormalAddress', 'myCCAddress(Oracles)','OraclesCCTokensAddress', 'myaddress']: assert_equal(result[x][0], 'R') # there are no oracles created yet @@ -674,7 +662,6 @@ class CryptoConditionsTest (BitcoinTestFramework): # assert_success(result) # globals()["oracle_{}".format(f)] = self.send_and_mine(result['hex'], rpc) - def run_test (self): print("Mining blocks...") rpc = self.nodes[0] From c386669e654aa186854d1935561c3a9f2832341b Mon Sep 17 00:00:00 2001 From: smk762 Date: Mon, 25 Mar 2019 12:56:01 +0100 Subject: [PATCH 004/111] update rpc-cc scripts for address keys --- qa/rpc-tests/cryptoconditions.py | 690 ---------------------- qa/rpc-tests/cryptoconditions_channels.py | 11 +- qa/rpc-tests/cryptoconditions_dice.py | 13 +- qa/rpc-tests/cryptoconditions_faucet.py | 12 +- qa/rpc-tests/cryptoconditions_gateways.py | 6 +- qa/rpc-tests/cryptoconditions_heir.py | 12 +- qa/rpc-tests/cryptoconditions_oracles.py | 12 +- qa/rpc-tests/cryptoconditions_rewards.py | 12 +- qa/rpc-tests/cryptoconditions_token.py | 20 +- 9 files changed, 63 insertions(+), 725 deletions(-) delete mode 100755 qa/rpc-tests/cryptoconditions.py diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py deleted file mode 100755 index d5456e801..000000000 --- a/qa/rpc-tests/cryptoconditions.py +++ /dev/null @@ -1,690 +0,0 @@ -#!/usr/bin/env python2 -# Copyright (c) 2018 SuperNET developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. - -from test_framework.test_framework import BitcoinTestFramework -from test_framework.authproxy import JSONRPCException -from test_framework.util import assert_equal, assert_greater_than, \ - initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ - stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises - -import time -from decimal import Decimal -from random import choice -from string import ascii_uppercase - -def assert_success(result): - assert_equal(result['result'], 'success') - -def assert_error(result): - assert_equal(result['result'], 'error') - -def generate_random_string(length): - random_string = ''.join(choice(ascii_uppercase) for i in range(length)) - return random_string - -class CryptoConditionsTest (BitcoinTestFramework): - - def setup_chain(self): - print("Initializing CC test directory "+self.options.tmpdir) - self.num_nodes = 2 - initialize_chain_clean(self.options.tmpdir, self.num_nodes) - - def setup_network(self, split = False): - print("Setting up network...") - self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" - self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf" - self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" - self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp" - self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0" - self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi" - self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, - extra_args=[[ - # always give -ac_name as first extra_arg and port as third - '-ac_name=REGTEST', - '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', - '-port=64367', - '-rpcport=64368', - '-regtest', - '-addressindex=1', - '-spentindex=1', - '-ac_supply=5555555', - '-ac_reward=10000000000000', - '-pubkey=' + self.pubkey, - '-ac_cc=2', - '-whitelist=127.0.0.1', - '-debug', - '--daemon', - '-rpcuser=rt', - '-rpcpassword=rt' - ], - ['-ac_name=REGTEST', - '-conf='+self.options.tmpdir+'/node1/REGTEST.conf', - '-port=64365', - '-rpcport=64366', - '-regtest', - '-addressindex=1', - '-spentindex=1', - '-ac_supply=5555555', - '-ac_reward=10000000000000', - '-pubkey=' + self.pubkey1, - '-ac_cc=2', - '-whitelist=127.0.0.1', - '-debug', - '-addnode=127.0.0.1:64367', - '--daemon', - '-rpcuser=rt', - '-rpcpassword=rt']] - ) - self.is_network_split = split - self.rpc = self.nodes[0] - self.rpc1 = self.nodes[1] - self.sync_all() - print("Done setting up network") - - def send_and_mine(self, xtn, rpc_connection): - txid = rpc_connection.sendrawtransaction(xtn) - assert txid, 'got txid' - # we need the tx above to be confirmed in the next block - rpc_connection.generate(1) - return txid - - def run_faucet_tests(self): - rpc = self.rpc - rpc1 = self.rpc1 - - # basic sanity tests - result = rpc.getwalletinfo() - assert_greater_than(result['txcount'], 100) - assert_greater_than(result['balance'], 0.0) - balance = result['balance'] - - faucet = rpc.faucetaddress() - assert_equal(faucet['result'], 'success') - # verify all keys look like valid AC addrs, could be better - for x in ['myCCAddress(Faucet)', 'FaucetCCAddress', 'FaucetCCTokensAddress', 'myaddress', 'FaucetNormalAddress']: - assert_equal(faucet[x][0], 'R') - - result = rpc.faucetaddress(self.pubkey) - assert_success(result) - # test that additional CCaddress key is returned - for x in ['myCCAddress(Faucet)', 'FaucetCCAddress', 'FaucetCCTokensAddress', 'myaddress', 'FaucetNormalAddress']: - assert_equal(result[x][0], 'R') - - # no funds in the faucet yet - result = rpc.faucetget() - assert_error(result) - - result = rpc.faucetinfo() - assert_success(result) - - result = rpc.faucetfund("0") - assert_error(result) - - result = rpc.faucetfund("-1") - assert_error(result) - - # we need at least 1 + txfee to get - result = rpc.faucetfund("2") - assert_success(result) - assert result['hex'], "hex key found" - - # broadcast the xtn - result = rpc.sendrawtransaction(result['hex']) - txid = result[0] - assert txid, "found txid" - - # we need the tx above to be confirmed in the next block - rpc.generate(1) - self.sync_all() - - result = rpc.getwalletinfo() - # minus one block reward - balance2 = result['balance'] - 100000 - # make sure our balance is less now - assert_greater_than(balance, balance2) - - result = rpc.faucetinfo() - assert_success(result) - assert_greater_than( result['funding'], 0 ) - - # claiming faucet on second node - faucetgethex = rpc1.faucetget() - assert_success(faucetgethex) - assert faucetgethex['hex'], "hex key found" - - balance1 = rpc1.getwalletinfo()['balance'] - - # try to broadcast the faucetget transaction - result = self.send_and_mine(faucetgethex['hex'], rpc1) - assert txid, "transaction broadcasted" - - balance2 = rpc1.getwalletinfo()['balance'] - assert_greater_than(balance2, balance1) - - self.sync_all() - - def run_dice_tests(self): - rpc = self.nodes[0] - rpc1 = self.nodes[1] - self.sync_all() - - # have to generate few blocks on second node to be able to place bets - rpc1.generate(10) - result = rpc1.getbalance() - assert_greater_than(result, 100000) - - dice = rpc.diceaddress() - assert_equal(dice['result'], 'success') - for x in ['myCCAddress(Dice)', 'DiceCCAddress', 'DiceCCTokensAddress', 'myaddress', 'DiceNormalAddress']: - assert_equal(dice[x][0], 'R') - - dice = rpc.diceaddress(self.pubkey) - assert_equal(dice['result'], 'success') - for x in ['myCCAddress(Dice)', 'DiceCCAddress', 'DiceCCTokensAddress', 'myaddress', 'DiceNormalAddress']: - assert_equal(dice[x][0], 'R') - - # no dice created yet - result = rpc.dicelist() - assert_equal(result, []) - - # creating dice plan with too long name (>8 chars) - result = rpc.dicefund("THISISTOOLONG", "10000", "10", "10000", "10", "5") - assert_error(result) - - # creating dice plan with < 100 funding - result = rpc.dicefund("LUCKY","10","1","10000","10","5") - assert_error(result) - - # creating dice plan with 0 blocks timeout - result = rpc.dicefund("LUCKY","10","1","10000","10","0") - assert_error(result) - - # creating dice plan - dicefundtx = rpc.dicefund("LUCKY","1000","1","800","10","5") - diceid = self.send_and_mine(dicefundtx['hex'], rpc) - - # checking if it in plans list now - result = rpc.dicelist() - assert_equal(result[0], diceid) - - # set dice name for futher usage - dicename = "LUCKY" - - # adding zero funds to plan - result = rpc.diceaddfunds(dicename,diceid,"0") - assert_error(result) - - # adding negative funds to plan - result = rpc.diceaddfunds(dicename,diceid,"-1") - assert_error(result) - - # adding funds to plan - addfundstx = rpc.diceaddfunds(dicename,diceid,"1100") - result = self.send_and_mine(addfundstx['hex'], rpc) - - # checking if funds added to plan - result = rpc.diceinfo(diceid) - assert_equal(result["funding"], "2100.00000000") - - # not valid dice info checking - result = rpc.diceinfo("invalid") - assert_error(result) - - # placing 0 amount bet - result = rpc1.dicebet(dicename,diceid,"0","2") - assert_error(result) - - # placing negative amount bet - result = rpc1.dicebet(dicename,diceid,"-1","2") - assert_error(result) - - # placing bet more than maxbet - result = rpc1.dicebet(dicename,diceid,"900","2") - assert_error(result) - - # placing bet with amount more than funding - result = rpc1.dicebet(dicename,diceid,"3000","2") - assert_error(result) - - # placing bet with potential won more than funding - result = rpc1.dicebet(dicename,diceid,"750","9") - assert_error(result) - - # placing 0 odds bet - result = rpc1.dicebet(dicename,diceid,"1","0") - assert_error(result) - - # placing negative odds bet - result = rpc1.dicebet(dicename,diceid,"1","-1") - assert_error(result) - - # placing bet with odds more than allowed - result = rpc1.dicebet(dicename,diceid,"1","11") - assert_error(result) - - # placing bet with not correct dice name - result = rpc1.dicebet("nope",diceid,"100","2") - assert_error(result) - - # placing bet with not correct dice id - result = rpc1.dicebet(dicename,self.pubkey,"100","2") - assert_error(result) - - # have to make some entropy for the next test - entropytx = 0 - fundingsum = 1 - while entropytx < 110: - fundingsuminput = str(fundingsum) - fundinghex = rpc.diceaddfunds(dicename,diceid,fundingsuminput) - result = self.send_and_mine(fundinghex['hex'], rpc) - entropytx = entropytx + 1 - fundingsum = fundingsum + 1 - - rpc.generate(2) - self.sync_all() - - # valid bet placing - placebet = rpc1.dicebet(dicename,diceid,"100","2") - betid = self.send_and_mine(placebet["hex"], rpc1) - assert result, "bet placed" - - # check bet status - result = rpc1.dicestatus(dicename,diceid,betid) - assert_success(result) - - # note initial dice funding state at this point. - # TODO: track player balance somehow (hard to do because of mining and fees) - diceinfo = rpc.diceinfo(diceid) - funding = float(diceinfo['funding']) - - # # placing same amount bets with amount 1 and odds 1:3, checking if balance changed correct - # losscounter = 0 - # wincounter = 0 - # betcounter = 0 - # - # while (betcounter < 10): - # placebet = rpc1.dicebet(dicename,diceid,"1","2") - # betid = self.send_and_mine(placebet["hex"], rpc1) - # time.sleep(3) - # self.sync_all() - # finish = rpc.dicefinish(dicename,diceid,betid) - # self.send_and_mine(finish["hex"], rpc1) - # self.sync_all() - # time.sleep(3) - # betresult = rpc1.dicestatus(dicename,diceid,betid) - # betcounter = betcounter + 1 - # if betresult["status"] == "loss": - # losscounter = losscounter + 1 - # elif betresult["status"] == "win": - # wincounter = wincounter + 1 - # else: - # pass - # - # # funding balance should increase if player loss, decrease if player won - # fundbalanceguess = funding + losscounter - wincounter * 2 - # fundinfoactual = rpc.diceinfo(diceid) - # assert_equal(round(fundbalanceguess),round(float(fundinfoactual['funding']))) - - def run_token_tests(self): - rpc = self.nodes[0] - result = rpc.tokenaddress() - assert_success(result) - for x in ['myCCAddress(Tokens)', 'TokensNormalAddress', 'TokensNormalAddress', 'myaddress','TokensCCAddress']: - assert_equal(result[x][0], 'R') - - result = rpc.tokenaddress(self.pubkey) - assert_success(result) - for x in ['myCCAddress(Tokens)', 'TokensNormalAddress', 'TokensNormalAddress', 'myaddress','TokensCCAddress']: - assert_equal(result[x][0], 'R') - # there are no tokens created yet - result = rpc.tokenlist() - assert_equal(result, []) - - # trying to create token with negaive supply - result = rpc.tokencreate("NUKE", "-1987420", "no bueno supply") - assert_error(result) - - # creating token with name more than 32 chars - result = rpc.tokencreate("NUKE123456789012345678901234567890", "1987420", "name too long") - assert_error(result) - - # creating valid token - result = rpc.tokencreate("DUKE", "1987.420", "Duke's custom token") - assert_success(result) - - tokenid = self.send_and_mine(result['hex'], rpc) - - result = rpc.tokenlist() - assert_equal(result[0], tokenid) - - # get token balance for token with pubkey - result = rpc.tokenbalance(tokenid, self.pubkey) - assert_success(result) - assert_equal(result['balance'], 198742000000) - assert_equal(result['tokenid'], tokenid) - - # get token balance for token without pubkey - result = rpc.tokenbalance(tokenid) - assert_success(result) - assert_equal(result['balance'], 198742000000) - assert_equal(result['tokenid'], tokenid) - - # this is not a valid assetid - result = rpc.tokeninfo(self.pubkey) - assert_error(result) - - # check tokeninfo for valid token - result = rpc.tokeninfo(tokenid) - assert_success(result) - assert_equal(result['tokenid'], tokenid) - assert_equal(result['owner'], self.pubkey) - assert_equal(result['name'], "DUKE") - assert_equal(result['supply'], 198742000000) - assert_equal(result['description'], "Duke's custom token") - - # invalid numtokens ask - result = rpc.tokenask("-1", tokenid, "1") - assert_error(result) - - # invalid numtokens ask - result = rpc.tokenask("0", tokenid, "1") - assert_error(result) - - # invalid price ask - result = rpc.tokenask("1", tokenid, "-1") - assert_error(result) - - # invalid price ask - result = rpc.tokenask("1", tokenid, "0") - assert_error(result) - - # invalid tokenid ask - result = rpc.tokenask("100", "deadbeef", "1") - assert_error(result) - - # valid ask - tokenask = rpc.tokenask("100", tokenid, "7.77") - tokenaskhex = tokenask['hex'] - tokenaskid = self.send_and_mine(tokenask['hex'], rpc) - result = rpc.tokenorders(tokenid) - order = result[0] - assert order, "found order" - - # invalid ask fillunits - result = rpc.tokenfillask(tokenid, tokenaskid, "0") - assert_error(result) - - # invalid ask fillunits - result = rpc.tokenfillask(tokenid, tokenaskid, "-777") - assert_error(result) - - # valid ask fillunits - fillask = rpc.tokenfillask(tokenid, tokenaskid, "777") - result = self.send_and_mine(fillask['hex'], rpc) - txid = result[0] - assert txid, "found txid" - - # should be no token orders - result = rpc.tokenorders(tokenid) - assert_equal(result, []) - - # checking ask cancellation - testorder = rpc.tokenask("100", tokenid, "7.77") - testorderid = self.send_and_mine(testorder['hex'], rpc) - cancel = rpc.tokencancelask(tokenid, testorderid) - self.send_and_mine(cancel["hex"], rpc) - result = rpc.tokenorders(tokenid) - assert_equal(result, []) - - # invalid numtokens bid - result = rpc.tokenbid("-1", tokenid, "1") - assert_error(result) - - # invalid numtokens bid - result = rpc.tokenbid("0", tokenid, "1") - assert_error(result) - - # invalid price bid - result = rpc.tokenbid("1", tokenid, "-1") - assert_error(result) - - # invalid price bid - result = rpc.tokenbid("1", tokenid, "0") - assert_error(result) - - # invalid tokenid bid - result = rpc.tokenbid("100", "deadbeef", "1") - assert_error(result) - - tokenbid = rpc.tokenbid("100", tokenid, "10") - tokenbidhex = tokenbid['hex'] - tokenbidid = self.send_and_mine(tokenbid['hex'], rpc) - result = rpc.tokenorders(tokenid) - order = result[0] - assert order, "found order" - - # invalid bid fillunits - result = rpc.tokenfillbid(tokenid, tokenbidid, "0") - assert_error(result) - - # invalid bid fillunits - result = rpc.tokenfillbid(tokenid, tokenbidid, "-777") - assert_error(result) - - # valid bid fillunits - fillbid = rpc.tokenfillbid(tokenid, tokenbidid, "1000") - result = self.send_and_mine(fillbid['hex'], rpc) - txid = result[0] - assert txid, "found txid" - - # should be no token orders - result = rpc.tokenorders(tokenid) - assert_equal(result, []) - - # checking bid cancellation - testorder = rpc.tokenbid("100", tokenid, "7.77") - testorderid = self.send_and_mine(testorder['hex'], rpc) - cancel = rpc.tokencancelbid(tokenid, testorderid) - self.send_and_mine(cancel["hex"], rpc) - result = rpc.tokenorders(tokenid) - assert_equal(result, []) - - # invalid token transfer amount (have to add status to CC code!) - randompubkey = "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" - result = rpc.tokentransfer(tokenid,randompubkey,"0") - assert_error(result) - - # invalid token transfer amount (have to add status to CC code!) - result = rpc.tokentransfer(tokenid,randompubkey,"-1") - assert_error(result) - - # valid token transfer - sendtokens = rpc.tokentransfer(tokenid,randompubkey,"1") - self.send_and_mine(sendtokens["hex"], rpc) - result = rpc.tokenbalance(tokenid,randompubkey) - assert_equal(result["balance"], 1) - - def run_rewards_tests(self): - rpc = self.nodes[0] - result = rpc.rewardsaddress() - for x in ['myCCAddress(Rewards)', 'myaddress', 'RewardsCCAddress', 'RewardsCCTokensAddress', 'RewardsNormalAddress']: - assert_equal(result[x][0], 'R') - - result = rpc.rewardsaddress(self.pubkey) - for x in ['myCCAddress(Rewards)', 'myaddress', 'RewardsCCAddress', 'RewardsCCTokensAddress', 'RewardsNormalAddress']: - assert_equal(result[x][0], 'R') - - # no rewards yet - result = rpc.rewardslist() - assert_equal(result, []) - - # looking up non-existent reward should return error - result = rpc.rewardsinfo("none") - assert_error(result) - - # creating rewards plan with name > 8 chars, should return error - result = rpc.rewardscreatefunding("STUFFSTUFF", "7777", "25", "0", "10", "10") - assert_error(result) - - # creating rewards plan with 0 funding - result = rpc.rewardscreatefunding("STUFF", "0", "25", "0", "10", "10") - assert_error(result) - - # creating rewards plan with 0 maxdays - result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "0") - assert_error(result) - - # creating rewards plan with > 25% APR - result = rpc.rewardscreatefunding("STUFF", "7777", "30", "0", "10", "10") - assert_error(result) - - # creating valid rewards plan - result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10") - assert result['hex'], 'got raw xtn' - fundingtxid = rpc.sendrawtransaction(result['hex']) - assert fundingtxid, 'got txid' - - # confirm the above xtn - rpc.generate(1) - result = rpc.rewardsinfo(fundingtxid) - assert_success(result) - assert_equal(result['name'], 'STUFF') - assert_equal(result['APR'], "25.00000000") - assert_equal(result['minseconds'], 0) - assert_equal(result['maxseconds'], 864000) - assert_equal(result['funding'], "7777.00000000") - assert_equal(result['mindeposit'], "10.00000000") - assert_equal(result['fundingtxid'], fundingtxid) - - # checking if new plan in rewardslist - result = rpc.rewardslist() - assert_equal(result[0], fundingtxid) - - # creating reward plan with already existing name, should return error - result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10") - assert_error(result) - - # add funding amount must be positive - result = rpc.rewardsaddfunding("STUFF", fundingtxid, "-1") - assert_error(result) - - # add funding amount must be positive - result = rpc.rewardsaddfunding("STUFF", fundingtxid, "0") - assert_error(result) - - # adding valid funding - result = rpc.rewardsaddfunding("STUFF", fundingtxid, "555") - addfundingtxid = self.send_and_mine(result['hex'], rpc) - assert addfundingtxid, 'got funding txid' - - # checking if funding added to rewardsplan - result = rpc.rewardsinfo(fundingtxid) - assert_equal(result['funding'], "8332.00000000") - - # trying to lock funds, locking funds amount must be positive - result = rpc.rewardslock("STUFF", fundingtxid, "-5") - assert_error(result) - - # trying to lock funds, locking funds amount must be positive - result = rpc.rewardslock("STUFF", fundingtxid, "0") - assert_error(result) - - # trying to lock less than the min amount is an error - result = rpc.rewardslock("STUFF", fundingtxid, "7") - assert_error(result) - - # locking funds in rewards plan - result = rpc.rewardslock("STUFF", fundingtxid, "10") - assert_success(result) - locktxid = result['hex'] - assert locktxid, "got lock txid" - - # locktxid has not been broadcast yet - result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid) - assert_error(result) - - # broadcast xtn - txid = rpc.sendrawtransaction(locktxid) - assert txid, 'got txid from sendrawtransaction' - - # confirm the xtn above - rpc.generate(1) - - # will not unlock since reward amount is less than tx fee - result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid) - assert_error(result) - - def run_oracles_tests(self): - rpc = self.nodes[0] - rpc1 = self.nodes[1] - - result = rpc1.oraclesaddress() - - result = rpc.oraclesaddress() - assert_success(result) - - for x in ['OraclesCCAddress', 'OraclesNormalAddress', 'myCCAddress(Oracles)','OraclesCCTokensAddress', 'myaddress']: - assert_equal(result[x][0], 'R') - - result = rpc.oraclesaddress(self.pubkey) - assert_success(result) - for x in ['OraclesCCAddress', 'OraclesNormalAddress', 'myCCAddress(Oracles)','OraclesCCTokensAddress', 'myaddress']: - assert_equal(result[x][0], 'R') - - # there are no oracles created yet - result = rpc.oracleslist() - assert_equal(result, []) - - # looking up non-existent oracle should return error. - result = rpc.oraclesinfo("none") - assert_error(result) - - # attempt to create oracle with not valid data type should return error - result = rpc.oraclescreate("Test", "Test", "Test") - assert_error(result) - - # attempt to create oracle with description > 32 symbols should return error - too_long_name = generate_random_string(33) - result = rpc.oraclescreate(too_long_name, "Test", "s") - - - # attempt to create oracle with description > 4096 symbols should return error - too_long_description = generate_random_string(4100) - result = rpc.oraclescreate("Test", too_long_description, "s") - assert_error(result) - # # valid creating oracles of different types - # # using such naming to re-use it for data publishing / reading (e.g. oracle_s for s type) - # valid_formats = ["s", "S", "d", "D", "c", "C", "t", "T", "i", "I", "l", "L", "h", "Ihh"] - # for f in valid_formats: - # result = rpc.oraclescreate("Test", "Test", f) - # assert_success(result) - # globals()["oracle_{}".format(f)] = self.send_and_mine(result['hex'], rpc) - - def run_test (self): - print("Mining blocks...") - rpc = self.nodes[0] - rpc1 = self.nodes[1] - # utxos from block 1 become mature in block 101 - rpc.generate(101) - self.sync_all() - rpc.getinfo() - rpc1.getinfo() - # this corresponds to -pubkey above - print("Importing privkeys") - rpc.importprivkey(self.privkey) - rpc1.importprivkey(self.privkey1) - self.run_faucet_tests() - self.sync_all() - self.run_rewards_tests() - self.sync_all() - self.run_dice_tests() - self.sync_all() - self.run_token_tests() - self.sync_all() - self.run_oracles_tests() - - -if __name__ == '__main__': - CryptoConditionsTest ().main() diff --git a/qa/rpc-tests/cryptoconditions_channels.py b/qa/rpc-tests/cryptoconditions_channels.py index 71f62f49d..2248efeab 100755 --- a/qa/rpc-tests/cryptoconditions_channels.py +++ b/qa/rpc-tests/cryptoconditions_channels.py @@ -27,13 +27,14 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): rpc1 = self.nodes[1] # checking channelsaddress call - + result = rpc.channelsaddress(self.pubkey) assert_success(result) # test that additional CCaddress key is returned - for x in ['ChannelsCC1of2TokensAddress', 'myCCAddress(Channels)', 'ChannelsCC1of2Address', 'myAddress', \ - 'myCCaddress', 'ChannelsNormalAddress', 'PubkeyCCaddress(Channels)', 'ChannelsCCAddress']: - assert_equal(result[x][0], 'R') + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') # getting empty channels list result = rpc.channelslist() @@ -80,7 +81,7 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): # now in channelinfo payment information should appear result = rpc.channelsinfo(channel_txid) assert_equal(result["Transactions"][1]["Payment"], payment_tx_id) - + time.sleep(90) # number of payments should be equal 1 (one denomination used) result = rpc.channelsinfo(channel_txid)["Transactions"][1]["Number of payments"] assert_equal(result, 1) diff --git a/qa/rpc-tests/cryptoconditions_dice.py b/qa/rpc-tests/cryptoconditions_dice.py index 7b960cb67..e93260178 100755 --- a/qa/rpc-tests/cryptoconditions_dice.py +++ b/qa/rpc-tests/cryptoconditions_dice.py @@ -28,15 +28,20 @@ class CryptoconditionsDiceTest(CryptoconditionsTestFramework): for x in result.keys(): print(x+": "+str(result[x])) assert_equal(result['result'], 'success') - for x in ['myCCaddress', 'DiceCCAddress', 'myaddress']: - assert_equal(result[x][0], 'R') + + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') result = rpc.diceaddress(self.pubkey) for x in result.keys(): print(x+": "+str(result[x])) assert_equal(result['result'], 'success') - for x in ['myCCaddress', 'DiceCCAddress', 'myaddress', 'DiceCCTokensAddress', 'DiceNormalAddress']: - assert_equal(result[x][0], 'R') + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') # no dice created yet result = rpc.dicelist() diff --git a/qa/rpc-tests/cryptoconditions_faucet.py b/qa/rpc-tests/cryptoconditions_faucet.py index c02522cc5..47e81b5ed 100755 --- a/qa/rpc-tests/cryptoconditions_faucet.py +++ b/qa/rpc-tests/cryptoconditions_faucet.py @@ -29,16 +29,20 @@ class CryptoconditionsFaucetTest(CryptoconditionsTestFramework): for x in result.keys(): print(x+": "+str(result[x])) # verify all keys look like valid AC addrs, could be better - for x in ['myCCaddress', 'FaucetCCTokensAddress', 'FaucetNormalAddress', 'myaddress']: - assert_equal(result[x][0], 'R') + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') result = rpc.faucetaddress(self.pubkey) assert_success(result) for x in result.keys(): print(x+": "+str(result[x])) # test that additional CCaddress key is returned - for x in ['myCCaddress', 'FaucetCCTokensAddress', 'FaucetNormalAddress', 'myaddress']: - assert_equal(result[x][0], 'R') + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') # no funds in the faucet yet result = rpc.faucetget() diff --git a/qa/rpc-tests/cryptoconditions_gateways.py b/qa/rpc-tests/cryptoconditions_gateways.py index a7f0cad2b..b12ea9f7e 100755 --- a/qa/rpc-tests/cryptoconditions_gateways.py +++ b/qa/rpc-tests/cryptoconditions_gateways.py @@ -20,8 +20,10 @@ class CryptoconditionsGatewaysTest(CryptoconditionsTestFramework): result = rpc.gatewaysaddress() assert_success(result) - for x in ['GatewaysCCaddress', 'myCCaddress', 'Gatewaysmarker', 'myaddress']: - assert_equal(result[x][0], 'R') + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') assert_equal("03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40", result["GatewaysPubkey"]) diff --git a/qa/rpc-tests/cryptoconditions_heir.py b/qa/rpc-tests/cryptoconditions_heir.py index a2443f0b3..12ca8b3da 100755 --- a/qa/rpc-tests/cryptoconditions_heir.py +++ b/qa/rpc-tests/cryptoconditions_heir.py @@ -22,15 +22,19 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework): result = rpc.heiraddress('') assert_success(result) + # verify all keys look like valid AC addrs, could be better - for x in ['HeirNormalAddress', 'HeirCCTokensAddress', 'myaddress', 'myCCaddress', 'HeirCCAddress']: - assert_equal(result[x][0], 'R') + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') result = rpc.heiraddress(self.pubkey) assert_success(result) + # test that additional CCaddress key is returned - for x in ['HeirNormalAddress', 'myCCaddress', 'myaddress', 'HeirCC1of2Address', 'HeirCCAddress', 'HeirCC1of2TokensAddress']: - assert_equal(result[x][0], 'R') + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') # getting empty heir list result = rpc.heirlist() diff --git a/qa/rpc-tests/cryptoconditions_oracles.py b/qa/rpc-tests/cryptoconditions_oracles.py index 008ab6256..953df5ca9 100755 --- a/qa/rpc-tests/cryptoconditions_oracles.py +++ b/qa/rpc-tests/cryptoconditions_oracles.py @@ -22,13 +22,17 @@ class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): result = rpc.oraclesaddress() assert_success(result) - for x in ['myCCaddress', 'OraclesCCAddress', 'OraclesNormalAddress', 'myaddress', 'OraclesCCTokensAddress']: - assert_equal(result[x][0], 'R') + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') result = rpc.oraclesaddress(self.pubkey) assert_success(result) - for x in ['myCCaddress', 'OraclesCCAddress', 'OraclesNormalAddress', 'myaddress', 'OraclesCCTokensAddress']: - assert_equal(result[x][0], 'R') + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') # there are no oracles created yet result = rpc.oracleslist() diff --git a/qa/rpc-tests/cryptoconditions_rewards.py b/qa/rpc-tests/cryptoconditions_rewards.py index d70e40740..8fd5d4c9f 100755 --- a/qa/rpc-tests/cryptoconditions_rewards.py +++ b/qa/rpc-tests/cryptoconditions_rewards.py @@ -19,12 +19,16 @@ class CryptoconditionsRewardsTest(CryptoconditionsTestFramework): rpc = self.nodes[0] result = rpc.rewardsaddress() - for x in ['myCCaddress', 'myaddress', 'RewardsCCAddress', 'RewardsCCTokensAddress', 'RewardsNormalAddress']: - assert_equal(result[x][0], 'R') + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') result = rpc.rewardsaddress(self.pubkey) - for x in ['myCCaddress', 'myaddress', 'RewardsCCAddress', 'RewardsCCTokensAddress', 'RewardsNormalAddress']: - assert_equal(result[x][0], 'R') + + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') # no rewards yet result = rpc.rewardslist() diff --git a/qa/rpc-tests/cryptoconditions_token.py b/qa/rpc-tests/cryptoconditions_token.py index faf2cbc8d..263d85dde 100755 --- a/qa/rpc-tests/cryptoconditions_token.py +++ b/qa/rpc-tests/cryptoconditions_token.py @@ -21,23 +21,27 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): result = rpc.tokenaddress() assert_success(result) - for x in ['TokensCCAddress', 'myCCaddress', 'myCCAddress(Tokens)', 'myaddress', 'TokensNormalAddress']: - assert_equal(result[x][0], 'R') + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') result = rpc.tokenaddress(self.pubkey) assert_success(result) - for x in ['TokensCCAddress', 'myCCaddress', 'myCCAddress(Tokens)', 'myaddress', 'TokensNormalAddress']: - assert_equal(result[x][0], 'R') + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') result = rpc.assetsaddress() assert_success(result) - for x in ['AssetsCCAddress', 'myCCaddress', 'myCCAddress(Assets)', 'myaddress', 'AssetsNormalAddress']: - assert_equal(result[x][0], 'R') + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') result = rpc.assetsaddress(self.pubkey) assert_success(result) - for x in ['AssetsCCAddress', 'myCCaddress', 'myCCAddress(Assets)', 'myaddress', 'AssetsNormalAddress']: - assert_equal(result[x][0], 'R') + for x in result.keys(): + if x.find('ddress') > 0: + assert_equal(result[x][0], 'R') # there are no tokens created yet result = rpc.tokenlist() From ebcbb234a85067c3815134afd9db6424aec1fae1 Mon Sep 17 00:00:00 2001 From: smk762 <35845239+smk762@users.noreply.github.com> Date: Mon, 25 Mar 2019 20:00:54 +0800 Subject: [PATCH 005/111] Update cryptoconditions_channels.py --- qa/rpc-tests/cryptoconditions_channels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions_channels.py b/qa/rpc-tests/cryptoconditions_channels.py index 2248efeab..7f82f2f3c 100755 --- a/qa/rpc-tests/cryptoconditions_channels.py +++ b/qa/rpc-tests/cryptoconditions_channels.py @@ -81,7 +81,7 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): # now in channelinfo payment information should appear result = rpc.channelsinfo(channel_txid) assert_equal(result["Transactions"][1]["Payment"], payment_tx_id) - time.sleep(90) + # number of payments should be equal 1 (one denomination used) result = rpc.channelsinfo(channel_txid)["Transactions"][1]["Number of payments"] assert_equal(result, 1) From 5aa85d7dad0f4bac5bf9fa533898044a59d4e9e9 Mon Sep 17 00:00:00 2001 From: smk762 <35845239+smk762@users.noreply.github.com> Date: Mon, 25 Mar 2019 20:01:40 +0800 Subject: [PATCH 006/111] Update cryptoconditions_rewards.py --- qa/rpc-tests/cryptoconditions_rewards.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_rewards.py b/qa/rpc-tests/cryptoconditions_rewards.py index 8fd5d4c9f..57d3032b8 100755 --- a/qa/rpc-tests/cryptoconditions_rewards.py +++ b/qa/rpc-tests/cryptoconditions_rewards.py @@ -19,13 +19,11 @@ class CryptoconditionsRewardsTest(CryptoconditionsTestFramework): rpc = self.nodes[0] result = rpc.rewardsaddress() - for x in result.keys(): if x.find('ddress') > 0: assert_equal(result[x][0], 'R') result = rpc.rewardsaddress(self.pubkey) - for x in result.keys(): if x.find('ddress') > 0: assert_equal(result[x][0], 'R') From 1b5605f3f70bedbbab2aaf038226194e66008418 Mon Sep 17 00:00:00 2001 From: smk762 <35845239+smk762@users.noreply.github.com> Date: Mon, 25 Mar 2019 20:02:31 +0800 Subject: [PATCH 007/111] Update cryptoconditions_dice.py --- qa/rpc-tests/cryptoconditions_dice.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_dice.py b/qa/rpc-tests/cryptoconditions_dice.py index e93260178..7b9d3fbae 100755 --- a/qa/rpc-tests/cryptoconditions_dice.py +++ b/qa/rpc-tests/cryptoconditions_dice.py @@ -25,11 +25,8 @@ class CryptoconditionsDiceTest(CryptoconditionsTestFramework): assert_greater_than(result, 100000) result = rpc.diceaddress() - for x in result.keys(): - print(x+": "+str(result[x])) assert_equal(result['result'], 'success') - for x in result.keys(): if x.find('ddress') > 0: assert_equal(result[x][0], 'R') From 3a4fa333f7cec948e25fe4348fa621d2aa4913c0 Mon Sep 17 00:00:00 2001 From: smk762 <35845239+smk762@users.noreply.github.com> Date: Mon, 25 Mar 2019 20:03:07 +0800 Subject: [PATCH 008/111] Update cryptoconditions_faucet.py --- qa/rpc-tests/cryptoconditions_faucet.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_faucet.py b/qa/rpc-tests/cryptoconditions_faucet.py index 47e81b5ed..27c5fce4e 100755 --- a/qa/rpc-tests/cryptoconditions_faucet.py +++ b/qa/rpc-tests/cryptoconditions_faucet.py @@ -26,10 +26,8 @@ class CryptoconditionsFaucetTest(CryptoconditionsTestFramework): result = rpc.faucetaddress() assert_equal(result['result'], 'success') - for x in result.keys(): - print(x+": "+str(result[x])) + # verify all keys look like valid AC addrs, could be better - for x in result.keys(): if x.find('ddress') > 0: assert_equal(result[x][0], 'R') From d08fedb7a43ac4740f8d29d7e93a2df181e17b6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 22:12:33 -1100 Subject: [PATCH 009/111] if ( komodo_nextheight() > 77777 && cashout > ROGUE_MAXCASHOUT ) --- src/cc/gamescc.cpp | 5 +++-- src/cc/rogue_rpc.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 758d2fc78..38e28a416 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -3513,11 +3513,12 @@ int tetris(int argc, char **argv) doupdate(); sleep_milli(10); c = getch(); - if ( c >= 0 ) + if ( c != -1 || skipcount == 0x3fff ) { if ( skipcount > 0 ) issue_games_events(gametxid,eventid-skipcount,skipcount | 0x4000); - issue_games_events(gametxid,eventid,c); + if ( c != -1 ) + issue_games_events(gametxid,eventid,c); skipcount = 0; } else skipcount++; eventid++; diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index fbb1a3d93..ee5f3d566 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -22,6 +22,7 @@ #define ROGUE_MAXPLAYERS 64 // need to send unused fees back to globalCC address to prevent leeching #define ROGUE_MAXKEYSTROKESGAP 60 #define ROGUE_MAXITERATIONS 777 +#define ROGUE_MAXCASHOUT (777 * COIN) #include "rogue/rogue_player.h" @@ -1112,6 +1113,8 @@ int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C dungeonlevel = P.dungeonlevel; if ( P.amulet != 0 && dungeonlevel < 26 ) dungeonlevel = 26; + if ( dungeonlevel > 42 ) + dungeonlevel = 42; *cashoutp = (uint64_t)P.gold * P.gold * mult * dungeonlevel; if ( newdata == playerdata ) { @@ -1281,6 +1284,8 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param } if ( cashout > 0 ) { + if ( komodo_nextheight() > 77777 && cashout > ROGUE_MAXCASHOUT ) + cashout = ROGUE_MAXCASHOUT; if ( (inputsum= AddCClibInputs(cp,mtx,roguepk,cashout,60,cp->unspendableCCaddr)) > cashout ) CCchange = (inputsum - cashout); else fprintf(stderr,"couldnt find enough utxos\n"); @@ -1598,6 +1603,8 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C cashout *= 2; //cashout += numplayers * buyin; } + if ( height > 777777 && cashout > ROGUE_MAXCASHOUT ) + cashout = ROGUE_MAXCASHOUT; sprintf(cashstr,"tokentx.(%c) decoded.%d ht.%d txid.%s %.8f vs vout2 %.8f",tokentx,decoded,height,txid.GetHex().c_str(),(double)cashout/COIN,(double)tx.vout[2].nValue/COIN); if ( strcmp(laststr,cashstr) != 0 ) { From fa0a35aa5a2dac695e4452587f5c9b18e5943be0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:11:36 -1100 Subject: [PATCH 010/111] Split out Tetris --- src/cc/dapps/dappstd.c | 1020 +++++++++++++++++ src/cc/gamescc.cpp | 2048 +--------------------------------- src/cc/gamescc.h | 32 +- src/cc/tetris.c | 758 +++++++++++++ src/cc/tetris.cpp | 2376 +--------------------------------------- src/cc/tetris.h | 197 ++++ 6 files changed, 2046 insertions(+), 4385 deletions(-) create mode 100644 src/cc/dapps/dappstd.c create mode 100644 src/cc/tetris.c create mode 100644 src/cc/tetris.h diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c new file mode 100644 index 000000000..ec8045b2f --- /dev/null +++ b/src/cc/dapps/dappstd.c @@ -0,0 +1,1020 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +// requires CHAINNAME and GAMEMAIN() to be #defined + +#include +#include +#include +#include +#include +#include +#include + +char USERPASS[8192]; uint16_t GAMES_PORT; +char Gametxidstr[67]; +char *clonestr(char *str); + +#define MAXSTR 1024 +char whoami[MAXSTR]; + +#define SMALLVAL 0.000000000000001 +#define SATOSHIDEN ((uint64_t)100000000L) +#define dstr(x) ((double)(x) / SATOSHIDEN) +#define KOMODO_ASSETCHAIN_MAXLEN 65 +char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],IPADDRESS[100]; + +#ifndef _BITS256 +#define _BITS256 +union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; +typedef union _bits256 bits256; +#endif + +#ifdef _WIN32 +#ifdef _MSC_VER +int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + time = ((uint64_t)file_time.dwLowDateTime); + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long)((time - EPOCH) / 10000000L); + tp->tv_usec = (long)(system_time.wMilliseconds * 1000); + return 0; +} +#endif // _MSC_VER +#endif + +double OS_milliseconds() +{ + struct timeval tv; double millis; +#ifdef __MINGW32__ + mingw_gettimeofday(&tv,NULL); +#else + gettimeofday(&tv,NULL); +#endif + millis = ((double)tv.tv_sec * 1000. + (double)tv.tv_usec / 1000.); + //printf("tv_sec.%ld usec.%d %f\n",tv.tv_sec,tv.tv_usec,millis); + return(millis); +} + +int32_t _unhex(char c) +{ + if ( c >= '0' && c <= '9' ) + return(c - '0'); + else if ( c >= 'a' && c <= 'f' ) + return(c - 'a' + 10); + else if ( c >= 'A' && c <= 'F' ) + return(c - 'A' + 10); + return(-1); +} + +int32_t is_hexstr(char *str,int32_t n) +{ + int32_t i; + if ( str == 0 || str[0] == 0 ) + return(0); + for (i=0; str[i]!=0; i++) + { + if ( n > 0 && i >= n ) + break; + if ( _unhex(str[i]) < 0 ) + break; + } + if ( n == 0 ) + return(i); + return(i == n); +} + +int32_t unhex(char c) +{ + int32_t hex; + if ( (hex= _unhex(c)) < 0 ) + { + //printf("unhex: illegal hexchar.(%c)\n",c); + } + return(hex); +} + +unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); } + +int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex) +{ + int32_t adjust,i = 0; + //printf("decode.(%s)\n",hex); + if ( is_hexstr(hex,n) <= 0 ) + { + memset(bytes,0,n); + return(n); + } + if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) + hex[--n] = 0; + if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) ) + { + if ( n > 0 ) + { + bytes[0] = unhex(hex[0]); + printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex)); + } + bytes++; + hex++; + adjust = 1; + } else adjust = 0; + if ( n > 0 ) + { + for (i=0; i>4) & 0xf); + hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); + //printf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]); + } + hexbytes[len*2] = 0; + //printf("len.%ld\n",len*2+1); + return((int32_t)len*2+1); +} + +char *bits256_str(char hexstr[65],bits256 x) +{ + init_hexbytes_noT(hexstr,x.bytes,sizeof(x)); + return(hexstr); +} + +long _stripwhite(char *buf,int accept) +{ + int32_t i,j,c; + if ( buf == 0 || buf[0] == 0 ) + return(0); + for (i=j=0; buf[i]!=0; i++) + { + buf[j] = c = buf[i]; + if ( c == accept || (c != ' ' && c != '\n' && c != '\r' && c != '\t' && c != '\b') ) + j++; + } + buf[j] = 0; + return(j); +} + +char *parse_conf_line(char *line,char *field) +{ + line += strlen(field); + for (; *line!='='&&*line!=0; line++) + break; + if ( *line == 0 ) + return(0); + if ( *line == '=' ) + line++; + while ( line[strlen(line)-1] == '\r' || line[strlen(line)-1] == '\n' || line[strlen(line)-1] == ' ' ) + line[strlen(line)-1] = 0; + //printf("LINE.(%s)\n",line); + _stripwhite(line,0); + return(clonestr(line)); +} + +int32_t safecopy(char *dest,char *src,long len) +{ + int32_t i = -1; + if ( src != 0 && dest != 0 && src != dest ) + { + if ( dest != 0 ) + memset(dest,0,len); + for (i=0; i buflen ) + { + *allocsizep = filesize; + *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep+64); + } + rewind(fp); + if ( buf == 0 ) + printf("Null buf ???\n"); + else + { + if ( fread(buf,1,(long)filesize,fp) != (unsigned long)filesize ) + printf("error reading filesize.%ld\n",(long)filesize); + buf[filesize] = 0; + } + fclose(fp); + *lenp = filesize; + //printf("loaded.(%s)\n",buf); + } //else printf("OS_loadfile couldnt load.(%s)\n",fname); + return(buf); +} + +uint8_t *OS_fileptr(long *allocsizep,char *fname) +{ + long filesize = 0; uint8_t *buf = 0; void *retptr; + *allocsizep = 0; + retptr = OS_loadfile(fname,&buf,&filesize,allocsizep); + return((uint8_t *)retptr); +} + +struct MemoryStruct { char *memory; size_t size; }; +struct return_string { char *ptr; size_t len; }; + +// return data from the server +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_SSL (1<<0) +#define CURL_GLOBAL_WIN32 (1<<1) + + +/************************************************************************ + * + * Initialize the string handler so that it is thread safe + * + ************************************************************************/ + +void init_string(struct return_string *s) +{ + s->len = 0; + s->ptr = (char *)calloc(1,s->len+1); + if ( s->ptr == NULL ) + { + fprintf(stderr,"init_string malloc() failed\n"); + exit(-1); + } + s->ptr[0] = '\0'; +} + +/************************************************************************ + * + * Use the "writer" to accumulate text until done + * + ************************************************************************/ + +size_t accumulatebytes(void *ptr,size_t size,size_t nmemb,struct return_string *s) +{ + size_t new_len = s->len + size*nmemb; + s->ptr = (char *)realloc(s->ptr,new_len+1); + if ( s->ptr == NULL ) + { + fprintf(stderr, "accumulate realloc() failed\n"); + exit(-1); + } + memcpy(s->ptr+s->len,ptr,size*nmemb); + s->ptr[new_len] = '\0'; + s->len = new_len; + return(size * nmemb); +} + +/************************************************************************ + * + * return the current system time in milliseconds + * + ************************************************************************/ + +#define EXTRACT_BITCOIND_RESULT // if defined, ensures error is null and returns the "result" field +#ifdef EXTRACT_BITCOIND_RESULT + +/************************************************************************ + * + * perform post processing of the results + * + ************************************************************************/ + +char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *params) +{ + long i,j,len; char *retstr = 0; cJSON *json,*result,*error; + //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); + if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) + { + if ( strcmp(command,"signrawtransaction") != 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); + return(rpcstr); + } + json = cJSON_Parse(rpcstr); + if ( json == 0 ) + { + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s can't parse.(%s) params.(%s)\n",debugstr,command,rpcstr,params); + free(rpcstr); + return(0); + } + result = cJSON_GetObjectItem(json,"result"); + error = cJSON_GetObjectItem(json,"error"); + if ( error != 0 && result != 0 ) + { + if ( (error->type&0xff) == cJSON_NULL && (result->type&0xff) != cJSON_NULL ) + { + retstr = cJSON_Print(result); + len = strlen(retstr); + if ( retstr[0] == '"' && retstr[len-1] == '"' ) + { + for (i=1,j=0; itype&0xff) != cJSON_NULL || (result->type&0xff) != cJSON_NULL ) + { + if ( strcmp(command,"signrawtransaction") != 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC (%s) error.%s\n",debugstr,command,rpcstr); + } + free(rpcstr); + } else retstr = rpcstr; + free_json(json); + //fprintf(stderr,"<<<<<<<<<<< bitcoind_RPC: postprocess returns.(%s)\n",retstr); + return(retstr); +} +#endif + +#ifdef _WIN32 +#ifdef _MSC_VER +#define sleep(x) Sleep(1000*(x)) +#endif +#endif + +/************************************************************************ + * + * perform the query + * + ************************************************************************/ + +char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params) +{ + static int didinit,count,count2; static double elapsedsum,elapsedsum2; + struct curl_slist *headers = NULL; struct return_string s; CURLcode res; CURL *curl_handle; + char *bracket0,*bracket1,*databuf = 0; long len; int32_t specialcase,numretries; double starttime; + if ( didinit == 0 ) + { + didinit = 1; + curl_global_init(CURL_GLOBAL_ALL); //init the curl session + } + numretries = 0; + if ( debugstr != 0 && strcmp(debugstr,"BTCD") == 0 && command != 0 && strcmp(command,"SuperNET") == 0 ) + specialcase = 1; + else specialcase = 0; + if ( url[0] == 0 ) + strcpy(url,"http://127.0.0.1:7876/nxt"); + if ( specialcase != 0 && 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: debug.(%s) url.(%s) command.(%s) params.(%s)\n",debugstr,url,command,params); +try_again: + if ( retstrp != 0 ) + *retstrp = 0; + starttime = OS_milliseconds(); + curl_handle = curl_easy_init(); + init_string(&s); + headers = curl_slist_append(0,"Expect:"); + + curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); + curl_easy_setopt(curl_handle,CURLOPT_URL, url); + curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulatebytes); // send all data to this function + curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback + curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash + curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback + if ( strncmp(url,"https",5) == 0 ) + { + curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYPEER,0); + curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYHOST,0); + } + if ( userpass != 0 ) + curl_easy_setopt(curl_handle,CURLOPT_USERPWD, userpass); + databuf = 0; + if ( params != 0 ) + { + if ( command != 0 && specialcase == 0 ) + { + len = strlen(params); + if ( len > 0 && params[0] == '[' && params[len-1] == ']' ) { + bracket0 = bracket1 = (char *)""; + } + else + { + bracket0 = (char *)"["; + bracket1 = (char *)"]"; + } + + databuf = (char *)malloc(256 + strlen(command) + strlen(params)); + sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); + //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + // + } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); + curl_easy_setopt(curl_handle,CURLOPT_POST,1L); + if ( databuf != 0 ) + curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,databuf); + else curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,params); + } + //laststart = milliseconds(); + res = curl_easy_perform(curl_handle); + curl_slist_free_all(headers); + curl_easy_cleanup(curl_handle); + if ( databuf != 0 ) // clean up temporary buffer + { + free(databuf); + databuf = 0; + } + if ( res != CURLE_OK ) + { + numretries++; + if ( specialcase != 0 ) + { + printf("<<<<<<<<<<< bitcoind_RPC.(%s): BTCD.%s timeout params.(%s) s.ptr.(%s) err.%d\n",url,command,params,s.ptr,res); + free(s.ptr); + return(0); + } + else if ( numretries >= 1 ) + { + //printf("Maximum number of retries exceeded!\n"); + free(s.ptr); + return(0); + } + if ( (rand() % 1000) == 0 ) + printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries); + free(s.ptr); + sleep((1< (%s)\n",params,s.ptr); + count2++; + elapsedsum2 += (OS_milliseconds() - starttime); + if ( (count2 % 10000) == 0) + printf("%d: ave %9.6f | elapsed %.3f millis | NXT calls.(%s) cmd.(%s)\n",count2,elapsedsum2/count2,(double)(OS_milliseconds() - starttime),url,command); + return(s.ptr); + } + } + printf("bitcoind_RPC: impossible case\n"); + free(s.ptr); + return(0); +} + +static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) +{ + size_t realsize = (size * nmemb); + struct MemoryStruct *mem = (struct MemoryStruct *)data; + mem->memory = (char *)((ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1)); + if ( mem->memory != 0 ) + { + if ( ptr != 0 ) + memcpy(&(mem->memory[mem->size]),ptr,realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + } + //printf("got %d bytes\n",(int32_t)(size*nmemb)); + return(realsize); +} + +char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3) +{ + struct MemoryStruct chunk; CURL *cHandle; long code; struct curl_slist *headers = 0; + if ( (cHandle= *cHandlep) == NULL ) + *cHandlep = cHandle = curl_easy_init(); + else curl_easy_reset(cHandle); + //#ifdef DEBUG + //curl_easy_setopt(cHandle,CURLOPT_VERBOSE, 1); + //#endif + curl_easy_setopt(cHandle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + curl_easy_setopt(cHandle,CURLOPT_SSL_VERIFYPEER,0); + //curl_easy_setopt(cHandle,CURLOPT_SSLVERSION,1); + curl_easy_setopt(cHandle,CURLOPT_URL,url); + curl_easy_setopt(cHandle,CURLOPT_CONNECTTIMEOUT,10); + if ( userpass != 0 && userpass[0] != 0 ) + curl_easy_setopt(cHandle,CURLOPT_USERPWD,userpass); + if ( postfields != 0 && postfields[0] != 0 ) + { + curl_easy_setopt(cHandle,CURLOPT_POST,1); + curl_easy_setopt(cHandle,CURLOPT_POSTFIELDS,postfields); + } + if ( hdr0 != NULL && hdr0[0] != 0 ) + { + //printf("HDR0.(%s) HDR1.(%s) HDR2.(%s) HDR3.(%s)\n",hdr0!=0?hdr0:"",hdr1!=0?hdr1:"",hdr2!=0?hdr2:"",hdr3!=0?hdr3:""); + headers = curl_slist_append(headers,hdr0); + if ( hdr1 != 0 && hdr1[0] != 0 ) + headers = curl_slist_append(headers,hdr1); + if ( hdr2 != 0 && hdr2[0] != 0 ) + headers = curl_slist_append(headers,hdr2); + if ( hdr3 != 0 && hdr3[0] != 0 ) + headers = curl_slist_append(headers,hdr3); + } //headers = curl_slist_append(0,"Expect:"); + if ( headers != 0 ) + curl_easy_setopt(cHandle,CURLOPT_HTTPHEADER,headers); + //res = curl_easy_perform(cHandle); + memset(&chunk,0,sizeof(chunk)); + curl_easy_setopt(cHandle,CURLOPT_WRITEFUNCTION,WriteMemoryCallback); + curl_easy_setopt(cHandle,CURLOPT_WRITEDATA,(void *)&chunk); + curl_easy_perform(cHandle); + curl_easy_getinfo(cHandle,CURLINFO_RESPONSE_CODE,&code); + if ( headers != 0 ) + curl_slist_free_all(headers); + if ( code != 200 ) + printf("(%s) server responded with code %ld (%s)\n",url,code,chunk.memory); + return(chunk.memory); +} + +uint16_t _komodo_userpass(char *username, char *password, FILE *fp) +{ + char *rpcuser,*rpcpassword,*str,*ipaddress,line[8192]; uint16_t port = 0; + rpcuser = rpcpassword = 0; + username[0] = password[0] = 0; + while ( fgets(line,sizeof(line),fp) != 0 ) + { + if ( line[0] == '#' ) + continue; + //printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword")); + if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) + rpcuser = parse_conf_line(str,(char *)"rpcuser"); + else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) + rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); + else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) + { + port = atoi(parse_conf_line(str,(char *)"rpcport")); + //fprintf(stderr,"rpcport.%u in file\n",port); + } + else if ( (str= strstr(line,(char *)"ipaddress")) != 0 ) + { + ipaddress = parse_conf_line(str,(char *)"ipaddress"); + strcpy(IPADDRESS,ipaddress); + } + } + if ( rpcuser != 0 && rpcpassword != 0 ) + { + strcpy(username,rpcuser); + strcpy(password,rpcpassword); + } + //printf("rpcuser.(%s) rpcpassword.(%s) %u ipaddress.%s\n",rpcuser,rpcpassword,port,ipaddress); + if ( rpcuser != 0 ) + free(rpcuser); + if ( rpcpassword != 0 ) + free(rpcpassword); + return(port); +} + +uint16_t komodo_userpass(char *userpass,char *symbol) +{ + FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[KOMODO_ASSETCHAIN_MAXLEN]; + userpass[0] = 0; + if ( strcmp("KMD",symbol) == 0 ) + { +#ifdef __APPLE__ + sprintf(confname,"Komodo.conf"); +#else + sprintf(confname,"komodo.conf"); +#endif + } + else sprintf(confname,"%s.conf",symbol); + //komodo_statefname(fname,symbol,confname); + if ( (fp= fopen(confname,"rb")) != 0 ) + { + port = _komodo_userpass(username,password,fp); + sprintf(userpass,"%s:%s",username,password); + if ( strcmp(symbol,ASSETCHAINS_SYMBOL) == 0 ) + strcpy(USERPASS,userpass); + fclose(fp); + } + return(port); +} + +#define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True) + +char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) +{ + //static void *cHandle; + char url[512],*retstr=0,*retstr2=0,postdata[8192]; + if ( params == 0 || params[0] == 0 ) + params = (char *)"[]"; + if ( strlen(params) < sizeof(postdata)-128 ) + { + sprintf(url,(char *)"http://%s:%u",IPADDRESS,port); + sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); + //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,USERPASS); + retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); + //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); + } + return(retstr2); +} + +int32_t issue_games_events(bits256 gametxid,uint32_t eventid,int32_t c) +{ + static FILE *fp; + char params[512],*retstr,str[65]; cJSON *retjson,*resobj; int32_t retval = -1; + if ( fp == 0 ) + fp = fopen("events.log","wb"); + sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c,bits256_str(str,gametxid),eventid); + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) + { + retval = 0; + if ( fp != 0 ) + { + fprintf(fp,"%s\n",jprint(resobj,0)); + fflush(fp); + } + } + free_json(retjson); + } else fprintf(fp,"error parsing %s\n",retstr); + free(retstr); + } else fprintf(fp,"error issuing method %s\n",params); + return(retval); +} + +int32_t games_sendrawtransaction(char *rawtx) +{ + char *params,*retstr,*hexstr; cJSON *retjson,*resobj; int32_t retval = -1; + params = (char *)malloc(strlen(rawtx) + 16); + sprintf(params,"[\"%s\"]",rawtx); + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"sendrawtransaction",params,GAMES_PORT)) != 0 ) + { + if ( 0 ) // causes 4th level crash + { + static FILE *fp; + if ( fp == 0 ) + fp = fopen("games.sendlog","wb"); + if ( fp != 0 ) + { + fprintf(fp,"%s\n",retstr); + fflush(fp); + } + } + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) + { + if ( (hexstr= jstr(resobj,0)) != 0 && is_hexstr(hexstr,64) == 64 ) + retval = 0; + } + free_json(retjson); + } + + /* log sendrawtx result in file */ + + /* + FILE *debug_file; + debug_file = fopen("tx_debug.log", "a"); + fprintf(debug_file, "%s\n", retstr); + fflush(debug_file); + fclose(debug_file); + */ + + free(retstr); + } + free(params); + return(retval); +} + +int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num) +{ + char cmd[16384],hexstr[16384],params[32768],*retstr,*errstr,*rawtx,*pastkeys,*keys; int32_t i,len,numpastkeys,retflag = -1; cJSON *retjson,*resobj; uint8_t *pastcmp; + if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) + { + if ( rs->keystrokeshex != 0 ) + { + if ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) + { + if ( waitflag == 0 ) + return(0); + else if ( 0 ) + { + while ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) + { + //fprintf(stderr,"pre-rebroadcast\n"); + sleep(10); + } + } + } + free(rs->keystrokeshex), rs->keystrokeshex = 0; + } + if ( 0 && (pastkeys= games_keystrokesload(&numpastkeys,seed,1)) != 0 ) + { + sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr); + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (keys= jstr(resobj,(char *)"keystrokes")) != 0 ) + { + len = strlen(keys) / 2; + pastcmp = (uint8_t *)malloc(len + 1); + decode_hex(pastcmp,len,keys); + fprintf(stderr,"keystrokes.(%s) vs pastkeys\n",keys); + for (i=0; i> keystrokes.log",ASSETCHAINS_SYMBOL,Gametxidstr,hexstr); + if ( system(cmd) != 0 ) + fprintf(stderr,"error issuing (%s)\n",cmd); + } + else + { + static FILE *fp; + if ( fp == 0 ) + fp = fopen("keystrokes.log","a"); + sprintf(params,"[\"keystrokes\",\"17\",\"[%%22%s%%22,%%22%s%%22]\"]",Gametxidstr,hexstr); + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) + { + if ( fp != 0 ) + { + fprintf(fp,"%s\n",params); + fprintf(fp,"%s\n",retstr); + fflush(fp); + } + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (rawtx= jstr(resobj,(char *)"hex")) != 0 ) + { + if ( rs->keystrokeshex != 0 ) + free(rs->keystrokeshex); + if ( (errstr= jstr(resobj,(char *)"error")) == 0 ) + { + rs->keystrokeshex = (char *)malloc(strlen(rawtx)+1); + strcpy(rs->keystrokeshex,rawtx); + retflag = 1; + } else fprintf(stderr,"error sending keystrokes tx\n"), sleep(1); + //fprintf(stderr,"set keystrokestx <- %s\n",rs->keystrokeshex); + } + free_json(retjson); + } + free(retstr); + } + if ( 0 && waitflag != 0 && rs->keystrokeshex != 0 ) + { + while ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) + { + //fprintf(stderr,"post-rebroadcast\n"); + sleep(3); + } + free(rs->keystrokeshex), rs->keystrokeshex = 0; + } + } + } + return(retflag); +} + +int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) +{ + char cmd[32768]; int32_t i,n,retval=-1; char params[1024],*filestr=0,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item,*resultjson; + if ( rs->guiflag == 0 ) + return(-1); + if ( gametxidstr == 0 || *gametxidstr == 0 ) + return(retval); + if ( 0 ) + { + sprintf(fname,"%s.gameinfo",gametxidstr); + sprintf(cmd,"./komodo-cli -ac_name=%s cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",ASSETCHAINS_SYMBOL,gametxidstr,fname); + if ( system(cmd) != 0 ) + fprintf(stderr,"error issuing (%s)\n",cmd); + else filestr = (char *)OS_fileptr(&allocsize,fname); + } + else + { + sprintf(params,"[\"gameinfo\",\"17\",\"[%%22%s%%22]\"]",gametxidstr); + filestr = komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT); + } + if ( filestr != 0 ) + { + if ( (retjson= cJSON_Parse(filestr)) != 0 && (resultjson= jobj(retjson,(char *)"result")) != 0 ) + { + //fprintf(stderr,"gameinfo.(%s)\n",jprint(resultjson,0)); + if ( (array= jarray(&n,resultjson,(char *)"players")) != 0 ) + { + for (i=0; iP,(int32_t)strlen(datastr)/2,datastr); + fprintf(stderr,"set pname[%s] %s\n",pname==0?"":pname,jprint(item,0)); + rs->restoring = 1; + } + } + } + } + } + free_json(retjson); + } + free(filestr); + } + return(retval); +} + +#ifdef _WIN32 +#ifdef _MSC_VER +__inline int msver(void) { + switch (_MSC_VER) { + case 1500: return 2008; + case 1600: return 2010; + case 1700: return 2012; + case 1800: return 2013; + case 1900: return 2015; + //case 1910: return 2017; + default: return (_MSC_VER / 100); + } +} + +static inline bool is_x64(void) { +#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) + return 1; +#elif defined(__amd64__) || defined(__amd64) || defined(_M_X64) || defined(_M_IA64) + return 1; +#else + return 0; +#endif +} + +#define BUILD_DATE __DATE__ " " __TIME__ +#endif // _WIN32 +#endif // _MSC_VER + +int main(int argc, char **argv) +{ + uint64_t seed; FILE *fp = 0; int32_t i,j,c; char userpass[8192]; +#ifdef _WIN32 +#ifdef _MSC_VER + printf("*** games for Windows [ Build %s ] ***\n", BUILD_DATE); + const char* arch = is_x64() ? "64-bits" : "32-bits"; + printf(" Built with VC++ %d (%ld) %s\n\n", msver(), _MSC_FULL_VER, arch); +#endif +#endif + + for (i=j=0; argv[0][i]!=0&&j payload) -{ - uint256 gametxid; int32_t i,len; char str[67]; uint32_t eventid = 0; - if ( (len= payload.size()) > 36 ) - { - len -= 36; - for (i=0; i<32; i++) - ((uint8_t *)&gametxid)[i] = payload[len+i]; - eventid = (uint32_t)payload[len+32]; - eventid |= (uint32_t)payload[len+33] << 8; - eventid |= (uint32_t)payload[len+34] << 16; - eventid |= (uint32_t)payload[len+35] << 24; - for (i=0; i payload); +int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector 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) { @@ -1343,99 +1335,6 @@ UniValue games_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } -int64_t games_cashout(struct games_player *P) -{ - int32_t dungeonlevel; int64_t mult=10,cashout = 0; - if ( P->amulet != 0 ) - mult *= 5; - dungeonlevel = P->dungeonlevel; - if ( P->amulet != 0 && dungeonlevel < 26 ) - dungeonlevel = 26; - cashout = (uint64_t)P->gold * P->gold * mult * dungeonlevel; - return(cashout); -} - -int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) -{ - static uint32_t good,bad; static uint256 prevgame; - char str[512],*keystrokes,gamesaddr[64],str2[67],fname[64]; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed; CPubKey gamespk; struct games_player P; - *cashoutp = 0; - gamespk = GetUnspendable(cp,0); - GetCCaddress1of2(cp,gamesaddr,gamespk,pk); - if ( (keystrokes= games_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,gamesaddr)) != 0 ) - { - free(keystrokes); - sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); - remove(fname); - - for (i=0; i no playerdata, good.%d bad.%d\n",good,bad); - } - *cashoutp = 0; - return(0); - } - } - if ( gametxid != prevgame ) - { - prevgame = gametxid; - bad++; - disp_gamesplayerdata(newdata); - disp_gamesplayerdata(playerdata); - fprintf(stderr,"%s playerdata: gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d\n",gametxid.GetHex().c_str(),P.gold,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel); - fprintf(stderr,"newdata[%d] != playerdata[%d], numkeys.%d %s pub.%s playertxid.%s good.%d bad.%d\n",(int32_t)newdata.size(),(int32_t)playerdata.size(),numkeys,gamesaddr,pubkey33_str(str2,(uint8_t *)&pk),playertxid.GetHex().c_str(),good,bad); - } - } - sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); - remove(fname); - //fprintf(stderr,"no keys games_extractgame %s\n",gametxid.GetHex().c_str()); - return(-1); -} - UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { //vin0 -> highlander vout from creategame TCBOO @@ -1657,1928 +1556,11 @@ UniValue games_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } -bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) -{ - return(true); -} +#include "tetris.cpp" -int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) -{ - return(-1); -} +#else // STANDALONE -void games_packitemstr(char *packitemstr,struct games_packitem *item) -{ - sprintf(packitemstr,"not yet"); -} -#else - - -#include -#include -#include -#include -#include -#include -#include - -char USERPASS[8192]; uint16_t GAMES_PORT; -char Gametxidstr[67]; -char *clonestr(char *str); - -#define MAXSTR 1024 -char whoami[MAXSTR]; - -#define SMALLVAL 0.000000000000001 -#define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)(x) / SATOSHIDEN) -#define KOMODO_ASSETCHAIN_MAXLEN 65 -char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],IPADDRESS[100]; - -#ifndef _BITS256 -#define _BITS256 -union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; -typedef union _bits256 bits256; -#endif - -#ifdef _WIN32 -#ifdef _MSC_VER -int gettimeofday(struct timeval * tp, struct timezone * tzp) -{ - // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's - static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); - - SYSTEMTIME system_time; - FILETIME file_time; - uint64_t time; - - GetSystemTime(&system_time); - SystemTimeToFileTime(&system_time, &file_time); - time = ((uint64_t)file_time.dwLowDateTime); - time += ((uint64_t)file_time.dwHighDateTime) << 32; - - tp->tv_sec = (long)((time - EPOCH) / 10000000L); - tp->tv_usec = (long)(system_time.wMilliseconds * 1000); - return 0; -} -#endif // _MSC_VER -#endif - - - -double OS_milliseconds() -{ - struct timeval tv; double millis; -#ifdef __MINGW32__ - mingw_gettimeofday(&tv,NULL); -#else - gettimeofday(&tv,NULL); -#endif - millis = ((double)tv.tv_sec * 1000. + (double)tv.tv_usec / 1000.); - //printf("tv_sec.%ld usec.%d %f\n",tv.tv_sec,tv.tv_usec,millis); - return(millis); -} - -int32_t _unhex(char c) -{ - if ( c >= '0' && c <= '9' ) - return(c - '0'); - else if ( c >= 'a' && c <= 'f' ) - return(c - 'a' + 10); - else if ( c >= 'A' && c <= 'F' ) - return(c - 'A' + 10); - return(-1); -} - -int32_t is_hexstr(char *str,int32_t n) -{ - int32_t i; - if ( str == 0 || str[0] == 0 ) - return(0); - for (i=0; str[i]!=0; i++) - { - if ( n > 0 && i >= n ) - break; - if ( _unhex(str[i]) < 0 ) - break; - } - if ( n == 0 ) - return(i); - return(i == n); -} - -int32_t unhex(char c) -{ - int32_t hex; - if ( (hex= _unhex(c)) < 0 ) - { - //printf("unhex: illegal hexchar.(%c)\n",c); - } - return(hex); -} - -unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); } - -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex) -{ - int32_t adjust,i = 0; - //printf("decode.(%s)\n",hex); - if ( is_hexstr(hex,n) <= 0 ) - { - memset(bytes,0,n); - return(n); - } - if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) - hex[--n] = 0; - if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) ) - { - if ( n > 0 ) - { - bytes[0] = unhex(hex[0]); - printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex)); - } - bytes++; - hex++; - adjust = 1; - } else adjust = 0; - if ( n > 0 ) - { - for (i=0; i>4) & 0xf); - hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); - //printf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]); - } - hexbytes[len*2] = 0; - //printf("len.%ld\n",len*2+1); - return((int32_t)len*2+1); -} - -char *bits256_str(char hexstr[65],bits256 x) -{ - init_hexbytes_noT(hexstr,x.bytes,sizeof(x)); - return(hexstr); -} - -long _stripwhite(char *buf,int accept) -{ - int32_t i,j,c; - if ( buf == 0 || buf[0] == 0 ) - return(0); - for (i=j=0; buf[i]!=0; i++) - { - buf[j] = c = buf[i]; - if ( c == accept || (c != ' ' && c != '\n' && c != '\r' && c != '\t' && c != '\b') ) - j++; - } - buf[j] = 0; - return(j); -} - -char *parse_conf_line(char *line,char *field) -{ - line += strlen(field); - for (; *line!='='&&*line!=0; line++) - break; - if ( *line == 0 ) - return(0); - if ( *line == '=' ) - line++; - while ( line[strlen(line)-1] == '\r' || line[strlen(line)-1] == '\n' || line[strlen(line)-1] == ' ' ) - line[strlen(line)-1] = 0; - //printf("LINE.(%s)\n",line); - _stripwhite(line,0); - return(clonestr(line)); -} - -int32_t safecopy(char *dest,char *src,long len) -{ - int32_t i = -1; - if ( src != 0 && dest != 0 && src != dest ) - { - if ( dest != 0 ) - memset(dest,0,len); - for (i=0; i buflen ) - { - *allocsizep = filesize; - *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep+64); - } - rewind(fp); - if ( buf == 0 ) - printf("Null buf ???\n"); - else - { - if ( fread(buf,1,(long)filesize,fp) != (unsigned long)filesize ) - printf("error reading filesize.%ld\n",(long)filesize); - buf[filesize] = 0; - } - fclose(fp); - *lenp = filesize; - //printf("loaded.(%s)\n",buf); - } //else printf("OS_loadfile couldnt load.(%s)\n",fname); - return(buf); -} - -uint8_t *OS_fileptr(long *allocsizep,char *fname) -{ - long filesize = 0; uint8_t *buf = 0; void *retptr; - *allocsizep = 0; - retptr = OS_loadfile(fname,&buf,&filesize,allocsizep); - return((uint8_t *)retptr); -} - -struct MemoryStruct { char *memory; size_t size; }; -struct return_string { char *ptr; size_t len; }; - -// return data from the server -#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) -#define CURL_GLOBAL_SSL (1<<0) -#define CURL_GLOBAL_WIN32 (1<<1) - - -/************************************************************************ - * - * Initialize the string handler so that it is thread safe - * - ************************************************************************/ - -void init_string(struct return_string *s) -{ - s->len = 0; - s->ptr = (char *)calloc(1,s->len+1); - if ( s->ptr == NULL ) - { - fprintf(stderr,"init_string malloc() failed\n"); - exit(-1); - } - s->ptr[0] = '\0'; -} - -/************************************************************************ - * - * Use the "writer" to accumulate text until done - * - ************************************************************************/ - -size_t accumulatebytes(void *ptr,size_t size,size_t nmemb,struct return_string *s) -{ - size_t new_len = s->len + size*nmemb; - s->ptr = (char *)realloc(s->ptr,new_len+1); - if ( s->ptr == NULL ) - { - fprintf(stderr, "accumulate realloc() failed\n"); - exit(-1); - } - memcpy(s->ptr+s->len,ptr,size*nmemb); - s->ptr[new_len] = '\0'; - s->len = new_len; - return(size * nmemb); -} - -/************************************************************************ - * - * return the current system time in milliseconds - * - ************************************************************************/ - -#define EXTRACT_BITCOIND_RESULT // if defined, ensures error is null and returns the "result" field -#ifdef EXTRACT_BITCOIND_RESULT - -/************************************************************************ - * - * perform post processing of the results - * - ************************************************************************/ - -char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *params) -{ - long i,j,len; char *retstr = 0; cJSON *json,*result,*error; - //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); - if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) - { - if ( strcmp(command,"signrawtransaction") != 0 ) - printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); - return(rpcstr); - } - json = cJSON_Parse(rpcstr); - if ( json == 0 ) - { - printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s can't parse.(%s) params.(%s)\n",debugstr,command,rpcstr,params); - free(rpcstr); - return(0); - } - result = cJSON_GetObjectItem(json,"result"); - error = cJSON_GetObjectItem(json,"error"); - if ( error != 0 && result != 0 ) - { - if ( (error->type&0xff) == cJSON_NULL && (result->type&0xff) != cJSON_NULL ) - { - retstr = cJSON_Print(result); - len = strlen(retstr); - if ( retstr[0] == '"' && retstr[len-1] == '"' ) - { - for (i=1,j=0; itype&0xff) != cJSON_NULL || (result->type&0xff) != cJSON_NULL ) - { - if ( strcmp(command,"signrawtransaction") != 0 ) - printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC (%s) error.%s\n",debugstr,command,rpcstr); - } - free(rpcstr); - } else retstr = rpcstr; - free_json(json); - //fprintf(stderr,"<<<<<<<<<<< bitcoind_RPC: postprocess returns.(%s)\n",retstr); - return(retstr); -} -#endif - -#ifdef _WIN32 -#ifdef _MSC_VER -#define sleep(x) Sleep(1000*(x)) -#endif -#endif - -/************************************************************************ - * - * perform the query - * - ************************************************************************/ - -char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params) -{ - static int didinit,count,count2; static double elapsedsum,elapsedsum2; - struct curl_slist *headers = NULL; struct return_string s; CURLcode res; CURL *curl_handle; - char *bracket0,*bracket1,*databuf = 0; long len; int32_t specialcase,numretries; double starttime; - if ( didinit == 0 ) - { - didinit = 1; - curl_global_init(CURL_GLOBAL_ALL); //init the curl session - } - numretries = 0; - if ( debugstr != 0 && strcmp(debugstr,"BTCD") == 0 && command != 0 && strcmp(command,"SuperNET") == 0 ) - specialcase = 1; - else specialcase = 0; - if ( url[0] == 0 ) - strcpy(url,"http://127.0.0.1:7876/nxt"); - if ( specialcase != 0 && 0 ) - printf("<<<<<<<<<<< bitcoind_RPC: debug.(%s) url.(%s) command.(%s) params.(%s)\n",debugstr,url,command,params); -try_again: - if ( retstrp != 0 ) - *retstrp = 0; - starttime = OS_milliseconds(); - curl_handle = curl_easy_init(); - init_string(&s); - headers = curl_slist_append(0,"Expect:"); - - curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); - curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(curl_handle,CURLOPT_URL, url); - curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulatebytes); // send all data to this function - curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback - curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash - curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback - if ( strncmp(url,"https",5) == 0 ) - { - curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYPEER,0); - curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYHOST,0); - } - if ( userpass != 0 ) - curl_easy_setopt(curl_handle,CURLOPT_USERPWD, userpass); - databuf = 0; - if ( params != 0 ) - { - if ( command != 0 && specialcase == 0 ) - { - len = strlen(params); - if ( len > 0 && params[0] == '[' && params[len-1] == ']' ) { - bracket0 = bracket1 = (char *)""; - } - else - { - bracket0 = (char *)"["; - bracket1 = (char *)"]"; - } - - databuf = (char *)malloc(256 + strlen(command) + strlen(params)); - sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); - //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); - // - } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); - curl_easy_setopt(curl_handle,CURLOPT_POST,1L); - if ( databuf != 0 ) - curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,databuf); - else curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,params); - } - //laststart = milliseconds(); - res = curl_easy_perform(curl_handle); - curl_slist_free_all(headers); - curl_easy_cleanup(curl_handle); - if ( databuf != 0 ) // clean up temporary buffer - { - free(databuf); - databuf = 0; - } - if ( res != CURLE_OK ) - { - numretries++; - if ( specialcase != 0 ) - { - printf("<<<<<<<<<<< bitcoind_RPC.(%s): BTCD.%s timeout params.(%s) s.ptr.(%s) err.%d\n",url,command,params,s.ptr,res); - free(s.ptr); - return(0); - } - else if ( numretries >= 1 ) - { - //printf("Maximum number of retries exceeded!\n"); - free(s.ptr); - return(0); - } - if ( (rand() % 1000) == 0 ) - printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries); - free(s.ptr); - sleep((1< (%s)\n",params,s.ptr); - count2++; - elapsedsum2 += (OS_milliseconds() - starttime); - if ( (count2 % 10000) == 0) - printf("%d: ave %9.6f | elapsed %.3f millis | NXT calls.(%s) cmd.(%s)\n",count2,elapsedsum2/count2,(double)(OS_milliseconds() - starttime),url,command); - return(s.ptr); - } - } - printf("bitcoind_RPC: impossible case\n"); - free(s.ptr); - return(0); -} - -static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) -{ - size_t realsize = (size * nmemb); - struct MemoryStruct *mem = (struct MemoryStruct *)data; - mem->memory = (char *)((ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1)); - if ( mem->memory != 0 ) - { - if ( ptr != 0 ) - memcpy(&(mem->memory[mem->size]),ptr,realsize); - mem->size += realsize; - mem->memory[mem->size] = 0; - } - //printf("got %d bytes\n",(int32_t)(size*nmemb)); - return(realsize); -} - -char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3) -{ - struct MemoryStruct chunk; CURL *cHandle; long code; struct curl_slist *headers = 0; - if ( (cHandle= *cHandlep) == NULL ) - *cHandlep = cHandle = curl_easy_init(); - else curl_easy_reset(cHandle); - //#ifdef DEBUG - //curl_easy_setopt(cHandle,CURLOPT_VERBOSE, 1); - //#endif - curl_easy_setopt(cHandle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); - curl_easy_setopt(cHandle,CURLOPT_SSL_VERIFYPEER,0); - //curl_easy_setopt(cHandle,CURLOPT_SSLVERSION,1); - curl_easy_setopt(cHandle,CURLOPT_URL,url); - curl_easy_setopt(cHandle,CURLOPT_CONNECTTIMEOUT,10); - if ( userpass != 0 && userpass[0] != 0 ) - curl_easy_setopt(cHandle,CURLOPT_USERPWD,userpass); - if ( postfields != 0 && postfields[0] != 0 ) - { - curl_easy_setopt(cHandle,CURLOPT_POST,1); - curl_easy_setopt(cHandle,CURLOPT_POSTFIELDS,postfields); - } - if ( hdr0 != NULL && hdr0[0] != 0 ) - { - //printf("HDR0.(%s) HDR1.(%s) HDR2.(%s) HDR3.(%s)\n",hdr0!=0?hdr0:"",hdr1!=0?hdr1:"",hdr2!=0?hdr2:"",hdr3!=0?hdr3:""); - headers = curl_slist_append(headers,hdr0); - if ( hdr1 != 0 && hdr1[0] != 0 ) - headers = curl_slist_append(headers,hdr1); - if ( hdr2 != 0 && hdr2[0] != 0 ) - headers = curl_slist_append(headers,hdr2); - if ( hdr3 != 0 && hdr3[0] != 0 ) - headers = curl_slist_append(headers,hdr3); - } //headers = curl_slist_append(0,"Expect:"); - if ( headers != 0 ) - curl_easy_setopt(cHandle,CURLOPT_HTTPHEADER,headers); - //res = curl_easy_perform(cHandle); - memset(&chunk,0,sizeof(chunk)); - curl_easy_setopt(cHandle,CURLOPT_WRITEFUNCTION,WriteMemoryCallback); - curl_easy_setopt(cHandle,CURLOPT_WRITEDATA,(void *)&chunk); - curl_easy_perform(cHandle); - curl_easy_getinfo(cHandle,CURLINFO_RESPONSE_CODE,&code); - if ( headers != 0 ) - curl_slist_free_all(headers); - if ( code != 200 ) - printf("(%s) server responded with code %ld (%s)\n",url,code,chunk.memory); - return(chunk.memory); -} - -uint16_t _komodo_userpass(char *username, char *password, FILE *fp) -{ - char *rpcuser,*rpcpassword,*str,*ipaddress,line[8192]; uint16_t port = 0; - rpcuser = rpcpassword = 0; - username[0] = password[0] = 0; - while ( fgets(line,sizeof(line),fp) != 0 ) - { - if ( line[0] == '#' ) - continue; - //printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword")); - if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) - rpcuser = parse_conf_line(str,(char *)"rpcuser"); - else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) - rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); - else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) - { - port = atoi(parse_conf_line(str,(char *)"rpcport")); - //fprintf(stderr,"rpcport.%u in file\n",port); - } - else if ( (str= strstr(line,(char *)"ipaddress")) != 0 ) - { - ipaddress = parse_conf_line(str,(char *)"ipaddress"); - strcpy(IPADDRESS,ipaddress); - } - } - if ( rpcuser != 0 && rpcpassword != 0 ) - { - strcpy(username,rpcuser); - strcpy(password,rpcpassword); - } - //printf("rpcuser.(%s) rpcpassword.(%s) %u ipaddress.%s\n",rpcuser,rpcpassword,port,ipaddress); - if ( rpcuser != 0 ) - free(rpcuser); - if ( rpcpassword != 0 ) - free(rpcpassword); - return(port); -} - -uint16_t komodo_userpass(char *userpass,char *symbol) -{ - FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[KOMODO_ASSETCHAIN_MAXLEN]; - userpass[0] = 0; - if ( strcmp("KMD",symbol) == 0 ) - { -#ifdef __APPLE__ - sprintf(confname,"Komodo.conf"); -#else - sprintf(confname,"komodo.conf"); -#endif - } - else sprintf(confname,"%s.conf",symbol); - //komodo_statefname(fname,symbol,confname); - if ( (fp= fopen(confname,"rb")) != 0 ) - { - port = _komodo_userpass(username,password,fp); - sprintf(userpass,"%s:%s",username,password); - if ( strcmp(symbol,ASSETCHAINS_SYMBOL) == 0 ) - strcpy(USERPASS,userpass); - fclose(fp); - } - return(port); -} - -#define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True) - -char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) -{ - //static void *cHandle; - char url[512],*retstr=0,*retstr2=0,postdata[8192]; - if ( params == 0 || params[0] == 0 ) - params = (char *)"[]"; - if ( strlen(params) < sizeof(postdata)-128 ) - { - sprintf(url,(char *)"http://%s:%u",IPADDRESS,port); - sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,USERPASS); - retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); - //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); - } - return(retstr2); -} - -int32_t issue_games_events(bits256 gametxid,uint32_t eventid,int32_t c) -{ - static FILE *fp; - char params[512],*retstr,str[65]; cJSON *retjson,*resobj; int32_t retval = -1; - if ( fp == 0 ) - fp = fopen("events.log","wb"); - sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c,bits256_str(str,gametxid),eventid); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) - { - retval = 0; - if ( fp != 0 ) - { - fprintf(fp,"%s\n",jprint(resobj,0)); - fflush(fp); - } - } - free_json(retjson); - } else fprintf(fp,"error parsing %s\n",retstr); - free(retstr); - } else fprintf(fp,"error issuing method %s\n",params); - return(retval); -} - -int32_t games_sendrawtransaction(char *rawtx) -{ - char *params,*retstr,*hexstr; cJSON *retjson,*resobj; int32_t retval = -1; - params = (char *)malloc(strlen(rawtx) + 16); - sprintf(params,"[\"%s\"]",rawtx); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"sendrawtransaction",params,GAMES_PORT)) != 0 ) - { - if ( 0 ) // causes 4th level crash - { - static FILE *fp; - if ( fp == 0 ) - fp = fopen("games.sendlog","wb"); - if ( fp != 0 ) - { - fprintf(fp,"%s\n",retstr); - fflush(fp); - } - } - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) - { - if ( (hexstr= jstr(resobj,0)) != 0 && is_hexstr(hexstr,64) == 64 ) - retval = 0; - } - free_json(retjson); - } - - /* log sendrawtx result in file */ - - /* - FILE *debug_file; - debug_file = fopen("tx_debug.log", "a"); - fprintf(debug_file, "%s\n", retstr); - fflush(debug_file); - fclose(debug_file); - */ - - free(retstr); - } - free(params); - return(retval); -} - -int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num) -{ - char cmd[16384],hexstr[16384],params[32768],*retstr,*errstr,*rawtx,*pastkeys,*keys; int32_t i,len,numpastkeys,retflag = -1; cJSON *retjson,*resobj; uint8_t *pastcmp; - if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) - { - if ( rs->keystrokeshex != 0 ) - { - if ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) - { - if ( waitflag == 0 ) - return(0); - else if ( 0 ) - { - while ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) - { - //fprintf(stderr,"pre-rebroadcast\n"); - sleep(10); - } - } - } - free(rs->keystrokeshex), rs->keystrokeshex = 0; - } - if ( 0 && (pastkeys= games_keystrokesload(&numpastkeys,seed,1)) != 0 ) - { - sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (keys= jstr(resobj,(char *)"keystrokes")) != 0 ) - { - len = strlen(keys) / 2; - pastcmp = (uint8_t *)malloc(len + 1); - decode_hex(pastcmp,len,keys); - fprintf(stderr,"keystrokes.(%s) vs pastkeys\n",keys); - for (i=0; i> keystrokes.log",ASSETCHAINS_SYMBOL,Gametxidstr,hexstr); - if ( system(cmd) != 0 ) - fprintf(stderr,"error issuing (%s)\n",cmd); - } - else - { - static FILE *fp; - if ( fp == 0 ) - fp = fopen("keystrokes.log","a"); - sprintf(params,"[\"keystrokes\",\"17\",\"[%%22%s%%22,%%22%s%%22]\"]",Gametxidstr,hexstr); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) - { - if ( fp != 0 ) - { - fprintf(fp,"%s\n",params); - fprintf(fp,"%s\n",retstr); - fflush(fp); - } - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (rawtx= jstr(resobj,(char *)"hex")) != 0 ) - { - if ( rs->keystrokeshex != 0 ) - free(rs->keystrokeshex); - if ( (errstr= jstr(resobj,(char *)"error")) == 0 ) - { - rs->keystrokeshex = (char *)malloc(strlen(rawtx)+1); - strcpy(rs->keystrokeshex,rawtx); - retflag = 1; - } else fprintf(stderr,"error sending keystrokes tx\n"), sleep(1); - //fprintf(stderr,"set keystrokestx <- %s\n",rs->keystrokeshex); - } - free_json(retjson); - } - free(retstr); - } - if ( 0 && waitflag != 0 && rs->keystrokeshex != 0 ) - { - while ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) - { - //fprintf(stderr,"post-rebroadcast\n"); - sleep(3); - } - free(rs->keystrokeshex), rs->keystrokeshex = 0; - } - } - } - return(retflag); -} - -int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) -{ - char cmd[32768]; int32_t i,n,retval=-1; char params[1024],*filestr=0,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item,*resultjson; - if ( rs->guiflag == 0 ) - return(-1); - if ( gametxidstr == 0 || *gametxidstr == 0 ) - return(retval); - if ( 0 ) - { - sprintf(fname,"%s.gameinfo",gametxidstr); - sprintf(cmd,"./komodo-cli -ac_name=%s cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",ASSETCHAINS_SYMBOL,gametxidstr,fname); - if ( system(cmd) != 0 ) - fprintf(stderr,"error issuing (%s)\n",cmd); - else filestr = (char *)OS_fileptr(&allocsize,fname); - } - else - { - sprintf(params,"[\"gameinfo\",\"17\",\"[%%22%s%%22]\"]",gametxidstr); - filestr = komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT); - } - if ( filestr != 0 ) - { - if ( (retjson= cJSON_Parse(filestr)) != 0 && (resultjson= jobj(retjson,(char *)"result")) != 0 ) - { - //fprintf(stderr,"gameinfo.(%s)\n",jprint(resultjson,0)); - if ( (array= jarray(&n,resultjson,(char *)"players")) != 0 ) - { - for (i=0; iP,(int32_t)strlen(datastr)/2,datastr); - fprintf(stderr,"set pname[%s] %s\n",pname==0?"":pname,jprint(item,0)); - rs->restoring = 1; - } - } - } - } - } - free_json(retjson); - } - free(filestr); - } - return(retval); -} - -#ifdef _WIN32 -#ifdef _MSC_VER -__inline int msver(void) { - switch (_MSC_VER) { - case 1500: return 2008; - case 1600: return 2010; - case 1700: return 2012; - case 1800: return 2013; - case 1900: return 2015; - //case 1910: return 2017; - default: return (_MSC_VER / 100); - } -} - -static inline bool is_x64(void) { -#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) - return 1; -#elif defined(__amd64__) || defined(__amd64) || defined(_M_X64) || defined(_M_IA64) - return 1; -#else - return 0; -#endif -} - -#define BUILD_DATE __DATE__ " " __TIME__ -#endif // _WIN32 -#endif // _MSC_VER - -int main(int argc, char **argv) -{ - uint64_t seed; FILE *fp = 0; int32_t i,j,c; char userpass[8192]; -#ifdef _WIN32 -#ifdef _MSC_VER - printf("*** games for Windows [ Build %s ] ***\n", BUILD_DATE); - const char* arch = is_x64() ? "64-bits" : "32-bits"; - printf(" Built with VC++ %d (%ld) %s\n\n", msver(), _MSC_FULL_VER, arch); -#endif -#endif - - for (i=j=0; argv[0][i]!=0&&j // for FILE -#include // for bool -#include -#include -#include -#include -#include -#include - -#ifdef BUILD_GAMESCC -#include "rogue/cursesd.h" -#else -#include -#endif - -/* - Convert a tetromino type to its corresponding cell. - */ -#define TYPE_TO_CELL(x) ((x)+1) - -/* - Strings for how you would print a tetris board. - */ -#define TC_EMPTY_STR " " -#define TC_BLOCK_STR "\u2588" - -/* - Questions about a tetris cell. - */ -#define TC_IS_EMPTY(x) ((x) == TC_EMPTY) -#define TC_IS_FILLED(x) (!TC_IS_EMPTY(x)) - -/* - How many cells in a tetromino? - */ -#define TETRIS 4 -/* - How many tetrominos? - */ -#define NUM_TETROMINOS 7 -/* - How many orientations of a tetromino? - */ -#define NUM_ORIENTATIONS 4 - -/* - Level constants. - */ -#define MAX_LEVEL 19 -#define LINES_PER_LEVEL 10 - -/* - A "cell" is a 1x1 block within a tetris board. - */ -typedef enum { - TC_EMPTY, TC_CELLI, TC_CELLJ, TC_CELLL, TC_CELLO, TC_CELLS, TC_CELLT, TC_CELLZ -} tetris_cell; - -/* - A "type" is a type/shape of a tetromino. Not including orientation. - */ -typedef enum { - TET_I, TET_J, TET_L, TET_O, TET_S, TET_T, TET_Z -} tetris_type; - -/* - A row,column pair. Negative numbers allowed, because we need them for - offsets. - */ -typedef struct { - int row; - int col; -} tetris_location; - -/* - A "block" is a struct that contains information about a tetromino. - Specifically, what type it is, what orientation it has, and where it is. - */ -typedef struct { - int typ; - int ori; - tetris_location loc; -} tetris_block; - -/* - All possible moves to give as input to the game. - */ -typedef enum { - TM_LEFT, TM_RIGHT, TM_CLOCK, TM_COUNTER, TM_DROP, TM_HOLD, TM_NONE -} tetris_move; - -/* - A game object! - */ -typedef struct { - /* - Game board stuff: - */ - int rows; - int cols; - char *board; - /* - Scoring information: - */ - int points; - int level; - /* - Falling block is the one currently going down. Next block is the one that - will be falling after this one. Stored is the block that you can swap out. - */ - tetris_block falling; - tetris_block next; - tetris_block stored; - /* - Number of game ticks until the block will move down. - */ - int ticks_till_gravity; - /* - Number of lines until you advance to the next level. - */ - int lines_remaining; -} tetris_game; - -/* - This array stores all necessary information about the cells that are filled by - each tetromino. The first index is the type of the tetromino (i.e. shape, - e.g. I, J, Z, etc.). The next index is the orientation (0-3). The final - array contains 4 tetris_location objects, each mapping to an offset from a - point on the upper left that is the tetromino "origin". - */ -extern tetris_location TETROMINOS[NUM_TETROMINOS][NUM_ORIENTATIONS][TETRIS]; - -/* - This array tells you how many ticks per gravity by level. Decreases as level - increases, to add difficulty. - */ -extern int GRAVITY_LEVEL[MAX_LEVEL+1]; - -// Data structure manipulation. -void tg_init(tetris_game *obj, int rows, int cols); -tetris_game *tg_create(int rows, int cols); -void tg_destroy(tetris_game *obj); -void tg_delete(tetris_game *obj); -tetris_game *tg_load(FILE *f); -void tg_save(tetris_game *obj, FILE *f); - -// Public methods not related to memory: -char tg_get(tetris_game *obj, int row, int col); -bool tg_check(tetris_game *obj, int row, int col); -bool tg_tick(tetris_game *obj, tetris_move move); -void tg_print(tetris_game *obj, FILE *f); - -#endif // TETRIS_H - - -#define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) -#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) - -/******************************************************************************* - Array Definitions - *******************************************************************************/ - -tetris_location TETROMINOS[NUM_TETROMINOS][NUM_ORIENTATIONS][TETRIS] = { - // I - {{{1, 0}, {1, 1}, {1, 2}, {1, 3}}, - {{0, 2}, {1, 2}, {2, 2}, {3, 2}}, - {{3, 0}, {3, 1}, {3, 2}, {3, 3}}, - {{0, 1}, {1, 1}, {2, 1}, {3, 1}}}, - // J - {{{0, 0}, {1, 0}, {1, 1}, {1, 2}}, - {{0, 1}, {0, 2}, {1, 1}, {2, 1}}, - {{1, 0}, {1, 1}, {1, 2}, {2, 2}}, - {{0, 1}, {1, 1}, {2, 0}, {2, 1}}}, - // L - {{{0, 2}, {1, 0}, {1, 1}, {1, 2}}, - {{0, 1}, {1, 1}, {2, 1}, {2, 2}}, - {{1, 0}, {1, 1}, {1, 2}, {2, 0}}, - {{0, 0}, {0, 1}, {1, 1}, {2, 1}}}, - // O - {{{0, 1}, {0, 2}, {1, 1}, {1, 2}}, - {{0, 1}, {0, 2}, {1, 1}, {1, 2}}, - {{0, 1}, {0, 2}, {1, 1}, {1, 2}}, - {{0, 1}, {0, 2}, {1, 1}, {1, 2}}}, - // S - {{{0, 1}, {0, 2}, {1, 0}, {1, 1}}, - {{0, 1}, {1, 1}, {1, 2}, {2, 2}}, - {{1, 1}, {1, 2}, {2, 0}, {2, 1}}, - {{0, 0}, {1, 0}, {1, 1}, {2, 1}}}, - // T - {{{0, 1}, {1, 0}, {1, 1}, {1, 2}}, - {{0, 1}, {1, 1}, {1, 2}, {2, 1}}, - {{1, 0}, {1, 1}, {1, 2}, {2, 1}}, - {{0, 1}, {1, 0}, {1, 1}, {2, 1}}}, - // Z - {{{0, 0}, {0, 1}, {1, 1}, {1, 2}}, - {{0, 2}, {1, 1}, {1, 2}, {2, 1}}, - {{1, 0}, {1, 1}, {2, 1}, {2, 2}}, - {{0, 1}, {1, 0}, {1, 1}, {2, 0}}}, -}; - -int GRAVITY_LEVEL[MAX_LEVEL+1] = { - // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, - //10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 30, 28, 26, 24, 22, 20, 16, 12, 8, 4 -}; - -/******************************************************************************* - Helper Functions for Blocks - *******************************************************************************/ - -void sleep_milli(int milliseconds) -{ - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = milliseconds * 1000 * 1000; - nanosleep(&ts, NULL); -} - -/* - Return the block at the given row and column. - */ -char tg_get(tetris_game *obj, int row, int column) -{ - return obj->board[obj->cols * row + column]; -} - -/* - Set the block at the given row and column. - */ -static void tg_set(tetris_game *obj, int row, int column, char value) -{ - obj->board[obj->cols * row + column] = value; -} - -/* - Check whether a row and column are in bounds. - */ -bool tg_check(tetris_game *obj, int row, int col) -{ - return 0 <= row && row < obj->rows && 0 <= col && col < obj->cols; -} - -/* - Place a block onto the board. - */ -static void tg_put(tetris_game *obj, tetris_block block) -{ - int i; - for (i = 0; i < TETRIS; i++) { - tetris_location cell = TETROMINOS[block.typ][block.ori][i]; - tg_set(obj, block.loc.row + cell.row, block.loc.col + cell.col, - TYPE_TO_CELL(block.typ)); - } -} - -/* - Clear a block out of the board. - */ -static void tg_remove(tetris_game *obj, tetris_block block) -{ - int i; - for (i = 0; i < TETRIS; i++) { - tetris_location cell = TETROMINOS[block.typ][block.ori][i]; - tg_set(obj, block.loc.row + cell.row, block.loc.col + cell.col, TC_EMPTY); - } -} - -/* - Check if a block can be placed on the board. - */ -static bool tg_fits(tetris_game *obj, tetris_block block) -{ - int i, r, c; - for (i = 0; i < TETRIS; i++) { - tetris_location cell = TETROMINOS[block.typ][block.ori][i]; - r = block.loc.row + cell.row; - c = block.loc.col + cell.col; - if (!tg_check(obj, r, c) || TC_IS_FILLED(tg_get(obj, r, c))) { - return false; - } - } - return true; -} - -/* - Return a random tetromino type. - */ -static int random_tetromino(void) -{ - return rand() % NUM_TETROMINOS; -} - -/* - Create a new falling block and populate the next falling block with a random - one. - */ -static void tg_new_falling(tetris_game *obj) -{ - // Put in a new falling tetromino. - obj->falling = obj->next; - obj->next.typ = random_tetromino(); - obj->next.ori = 0; - obj->next.loc.row = 0; - obj->next.loc.col = obj->cols/2 - 2; -} - -/******************************************************************************* - Game Turn Helpers - *******************************************************************************/ - -/* - Tick gravity, and move the block down if gravity should act. - */ -static void tg_do_gravity_tick(tetris_game *obj) -{ - obj->ticks_till_gravity--; - if (obj->ticks_till_gravity <= 0) { - tg_remove(obj, obj->falling); - obj->falling.loc.row++; - if (tg_fits(obj, obj->falling)) { - obj->ticks_till_gravity = GRAVITY_LEVEL[obj->level]; - } else { - obj->falling.loc.row--; - tg_put(obj, obj->falling); - - tg_new_falling(obj); - } - tg_put(obj, obj->falling); - } -} - -/* - Move the falling tetris block left (-1) or right (+1). - */ -static void tg_move(tetris_game *obj, int direction) -{ - tg_remove(obj, obj->falling); - obj->falling.loc.col += direction; - if (!tg_fits(obj, obj->falling)) { - obj->falling.loc.col -= direction; - } - tg_put(obj, obj->falling); -} - -/* - Send the falling tetris block to the bottom. - */ -static void tg_down(tetris_game *obj) -{ - tg_remove(obj, obj->falling); - while (tg_fits(obj, obj->falling)) { - obj->falling.loc.row++; - } - obj->falling.loc.row--; - tg_put(obj, obj->falling); - tg_new_falling(obj); -} - -/* - Rotate the falling block in either direction (+/-1). - */ -static void tg_rotate(tetris_game *obj, int direction) -{ - tg_remove(obj, obj->falling); - - while (true) { - obj->falling.ori = (obj->falling.ori + direction) % NUM_ORIENTATIONS; - - // If the new orientation fits, we're done. - if (tg_fits(obj, obj->falling)) - break; - - // Otherwise, try moving left to make it fit. - obj->falling.loc.col--; - if (tg_fits(obj, obj->falling)) - break; - - // Finally, try moving right to make it fit. - obj->falling.loc.col += 2; - if (tg_fits(obj, obj->falling)) - break; - - // Put it back in its original location and try the next orientation. - obj->falling.loc.col--; - // Worst case, we come back to the original orientation and it fits, so this - // loop will terminate. - } - - tg_put(obj, obj->falling); -} - -/* - Swap the falling block with the block in the hold buffer. - */ -static void tg_hold(tetris_game *obj) -{ - tg_remove(obj, obj->falling); - if (obj->stored.typ == -1) { - obj->stored = obj->falling; - tg_new_falling(obj); - } else { - int typ = obj->falling.typ, ori = obj->falling.ori; - obj->falling.typ = obj->stored.typ; - obj->falling.ori = obj->stored.ori; - obj->stored.typ = typ; - obj->stored.ori = ori; - while (!tg_fits(obj, obj->falling)) { - obj->falling.loc.row--; - } - } - tg_put(obj, obj->falling); -} - -/* - Perform the action specified by the move. - */ -static void tg_handle_move(tetris_game *obj, tetris_move move) -{ - switch (move) { - case TM_LEFT: - tg_move(obj, -1); - break; - case TM_RIGHT: - tg_move(obj, 1); - break; - case TM_DROP: - tg_down(obj); - break; - case TM_CLOCK: - tg_rotate(obj, 1); - break; - case TM_COUNTER: - tg_rotate(obj, -1); - break; - case TM_HOLD: - tg_hold(obj); - break; - default: - // pass - break; - } -} - -/* - Return true if line i is full. - */ -static bool tg_line_full(tetris_game *obj, int i) -{ - int j; - for (j = 0; j < obj->cols; j++) { - if (TC_IS_EMPTY(tg_get(obj, i, j))) - return false; - } - return true; -} - -/* - Shift every row above r down one. - */ -static void tg_shift_lines(tetris_game *obj, int r) -{ - int i, j; - for (i = r-1; i >= 0; i--) { - for (j = 0; j < obj->cols; j++) { - tg_set(obj, i+1, j, tg_get(obj, i, j)); - tg_set(obj, i, j, TC_EMPTY); - } - } -} - -/* - Find rows that are filled, remove them, shift, and return the number of - cleared rows. - */ -static int tg_check_lines(tetris_game *obj) -{ - int i, nlines = 0; - tg_remove(obj, obj->falling); // don't want to mess up falling block - - for (i = obj->rows-1; i >= 0; i--) { - if (tg_line_full(obj, i)) { - tg_shift_lines(obj, i); - i++; // do this line over again since they're shifted - nlines++; - } - } - - tg_put(obj, obj->falling); // replace - return nlines; -} - -/* - Adjust the score for the game, given how many lines were just cleared. - */ -static void tg_adjust_score(tetris_game *obj, int lines_cleared) -{ - static int line_multiplier[] = {0, 40, 100, 300, 1200}; - obj->points += line_multiplier[lines_cleared] * (obj->level + 1); - if (lines_cleared >= obj->lines_remaining) { - obj->level = MIN(MAX_LEVEL, obj->level + 1); - lines_cleared -= obj->lines_remaining; - obj->lines_remaining = LINES_PER_LEVEL - lines_cleared; - } else { - obj->lines_remaining -= lines_cleared; - } -} - -/* - Return true if the game is over. - */ -static bool tg_game_over(tetris_game *obj) -{ - int i, j; - bool over = false; - tg_remove(obj, obj->falling); - for (i = 0; i < 2; i++) { - for (j = 0; j < obj->cols; j++) { - if (TC_IS_FILLED(tg_get(obj, i, j))) { - over = true; - } - } - } - tg_put(obj, obj->falling); - return over; -} - -/******************************************************************************* - Main Public Functions - *******************************************************************************/ - -/* - Do a single game tick: process gravity, user input, and score. Return true if - the game is still running, false if it is over. - */ -bool tg_tick(tetris_game *obj, tetris_move move) -{ - int lines_cleared; - // Handle gravity. - tg_do_gravity_tick(obj); - - // Handle input. - tg_handle_move(obj, move); - - // Check for cleared lines - lines_cleared = tg_check_lines(obj); - - tg_adjust_score(obj, lines_cleared); - - // Return whether the game will continue (NOT whether it's over) - return !tg_game_over(obj); -} - -void tg_init(tetris_game *obj, int rows, int cols) -{ - // Initialization logic - obj->rows = rows; - obj->cols = cols; - obj->board = (char *)malloc(rows * cols); - memset(obj->board, TC_EMPTY, rows * cols); - obj->points = 0; - obj->level = 0; - obj->ticks_till_gravity = GRAVITY_LEVEL[obj->level]; - obj->lines_remaining = LINES_PER_LEVEL; - srand(time(NULL)); - tg_new_falling(obj); - tg_new_falling(obj); - obj->stored.typ = -1; - obj->stored.ori = 0; - obj->stored.loc.row = 0; - obj->next.loc.col = obj->cols/2 - 2; - printf("%d", obj->falling.loc.col); -} - -tetris_game *tg_create(int rows, int cols) -{ - tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); - tg_init(obj, rows, cols); - return obj; -} - -void tg_destroy(tetris_game *obj) -{ - // Cleanup logic - free(obj->board); -} - -void tg_delete(tetris_game *obj) { - tg_destroy(obj); - free(obj); -} - -/* - Load a game from a file. - */ -tetris_game *tg_load(FILE *f) -{ - tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); - if (fread(obj, sizeof(tetris_game), 1, f) != 1 ) - { - fprintf(stderr,"read game error\n"); - free(obj); - obj = 0; - } - else - { - obj->board = (char *)malloc(obj->rows * obj->cols); - if (fread(obj->board, sizeof(char), obj->rows * obj->cols, f) != obj->rows * obj->cols ) - { - fprintf(stderr,"fread error\n"); - free(obj->board); - free(obj); - obj = 0; - } - } - return obj; -} - -/* - Save a game to a file. - */ -void tg_save(tetris_game *obj, FILE *f) -{ - if (fwrite(obj, sizeof(tetris_game), 1, f) != 1 ) - fprintf(stderr,"error writing tetrisgame\n"); - else if (fwrite(obj->board, sizeof(char), obj->rows * obj->cols, f) != obj->rows * obj->cols ) - fprintf(stderr,"error writing board\n"); -} - -/* - Print a game board to a file. Really just for early debugging. - */ -void tg_print(tetris_game *obj, FILE *f) { - int i, j; - for (i = 0; i < obj->rows; i++) { - for (j = 0; j < obj->cols; j++) { - if (TC_IS_EMPTY(tg_get(obj, i, j))) { - fputs(TC_EMPTY_STR, f); - } else { - fputs(TC_BLOCK_STR, f); - } - } - fputc('\n', f); - } -} - -/* - 2 columns per cell makes the game much nicer. - */ -#define COLS_PER_CELL 2 -/* - Macro to print a cell of a specific type to a window. - */ -#define ADD_BLOCK(w,x) waddch((w),' '|A_REVERSE|COLOR_PAIR(x)); \ -waddch((w),' '|A_REVERSE|COLOR_PAIR(x)) -#define ADD_EMPTY(w) waddch((w), ' '); waddch((w), ' ') - -/* - Print the tetris board onto the ncurses window. - */ -void display_board(WINDOW *w, tetris_game *obj) -{ - int i, j; - box(w, 0, 0); - for (i = 0; i < obj->rows; i++) { - wmove(w, 1 + i, 1); - for (j = 0; j < obj->cols; j++) { - if (TC_IS_FILLED(tg_get(obj, i, j))) { - ADD_BLOCK(w,tg_get(obj, i, j)); - } else { - ADD_EMPTY(w); - } - } - } - wnoutrefresh(w); -} - -/* - Display a tetris piece in a dedicated window. - */ -void display_piece(WINDOW *w, tetris_block block) -{ - int b; - tetris_location c; - wclear(w); - box(w, 0, 0); - if (block.typ == -1) { - wnoutrefresh(w); - return; - } - for (b = 0; b < TETRIS; b++) { - c = TETROMINOS[block.typ][block.ori][b]; - wmove(w, c.row + 1, c.col * COLS_PER_CELL + 1); - ADD_BLOCK(w, TYPE_TO_CELL(block.typ)); - } - wnoutrefresh(w); -} - -/* - Display score information in a dedicated window. - */ -void display_score(WINDOW *w, tetris_game *tg) -{ - wclear(w); - box(w, 0, 0); - wprintw(w, (char *)"Score\n%d\n", tg->points); - wprintw(w, (char *)"Level\n%d\n", tg->level); - wprintw(w, (char *)"Lines\n%d\n", tg->lines_remaining); - wnoutrefresh(w); -} - -/* - Save and exit the game. - */ -void save(tetris_game *game, WINDOW *w) -{ - FILE *f; - - wclear(w); - box(w, 0, 0); // return the border - wmove(w, 1, 1); - wprintw(w, (char *)"Save and exit? [Y/n] "); - wrefresh(w); - timeout(-1); - if (getch() == 'n') { - timeout(0); - return; - } - f = fopen("tetris.save", "w"); - tg_save(game, f); - fclose(f); - tg_delete(game); - endwin(); - fprintf(stderr,"Game saved to \"tetris.save\".\n"); - fprintf(stderr,"Resume by passing the filename as an argument to this program.\n"); - exit(EXIT_SUCCESS); -} - -/* - Do the NCURSES initialization steps for color blocks. - */ -void init_colors(void) -{ - start_color(); - //init_color(COLOR_ORANGE, 1000, 647, 0); - init_pair(TC_CELLI, COLOR_CYAN, COLOR_BLACK); - init_pair(TC_CELLJ, COLOR_BLUE, COLOR_BLACK); - init_pair(TC_CELLL, COLOR_WHITE, COLOR_BLACK); - init_pair(TC_CELLO, COLOR_YELLOW, COLOR_BLACK); - init_pair(TC_CELLS, COLOR_GREEN, COLOR_BLACK); - init_pair(TC_CELLT, COLOR_MAGENTA, COLOR_BLACK); - init_pair(TC_CELLZ, COLOR_RED, COLOR_BLACK); -} - -/* - Main tetris game! - */ -#ifdef STANDALONE -char *clonestr(char *str) -{ - char *clone; int32_t len; - if ( str == 0 || str[0] == 0 ) - { - printf("warning cloning nullstr.%p\n",str); -#ifdef __APPLE__ - while ( 1 ) sleep(1); -#endif - str = (char *)""; - } - len = strlen(str); - clone = (char *)calloc(1,len+16); - strcpy(clone,str); - return(clone); -} - -int tetris(int argc, char **argv) -{ - tetris_game *tg; - tetris_move move = TM_NONE; - bool running = true; - WINDOW *board, *next, *hold, *score; - int32_t c,skipcount=0; bits256 gametxid; uint32_t eventid = 0; - memset(&gametxid,0,sizeof(gametxid)); - // Load file if given a filename. - if (argc >= 2) { - FILE *f = fopen(argv[1], "r"); - if (f == NULL) { - perror("tetris"); - exit(EXIT_FAILURE); - } - tg = tg_load(f); - fclose(f); - } else { - // Otherwise create new game. - tg = tg_create(22, 10); - } - // NCURSES initialization: - initscr(); // initialize curses - cbreak(); // pass key presses to program, but not signals - noecho(); // don't echo key presses to screen - keypad(stdscr, TRUE); // allow arrow keys - timeout(0); // no blocking on getch() - curs_set(0); // set the cursor to invisible - init_colors(); // setup tetris colors - - // Create windows for each section of the interface. - board = newwin(tg->rows + 2, 2 * tg->cols + 2, 0, 0); - next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); - hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1); - score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1); - int32_t counter = 0; - // Game loop - while (running) { - running = tg_tick(tg, move); - display_board(board, tg); - display_piece(next, tg->next); - display_piece(hold, tg->stored); - display_score(score, tg); - if ( (counter++ % 5) == 0 ) - doupdate(); - sleep_milli(10); - c = getch(); - if ( c != -1 || skipcount == 0x3fff ) - { - if ( skipcount > 0 ) - issue_games_events(gametxid,eventid-skipcount,skipcount | 0x4000); - if ( c != -1 ) - issue_games_events(gametxid,eventid,c); - skipcount = 0; - } else skipcount++; - eventid++; - switch ( c ) - { - case KEY_LEFT: - move = TM_LEFT; - break; - case KEY_RIGHT: - move = TM_RIGHT; - break; - case KEY_UP: - move = TM_CLOCK; - break; - case KEY_DOWN: - move = TM_DROP; - break; - case 'q': - running = false; - move = TM_NONE; - break; - case 'p': - wclear(board); - box(board, 0, 0); - wmove(board, tg->rows/2, (tg->cols*COLS_PER_CELL-6)/2); - wprintw(board, "PAUSED"); - wrefresh(board); - timeout(-1); - getch(); - timeout(0); - move = TM_NONE; - break; - case 's': - save(tg, board); - move = TM_NONE; - break; - case ' ': - move = TM_HOLD; - break; - default: - move = TM_NONE; - } - } - - // Deinitialize NCurses - wclear(stdscr); - endwin(); - // Output ending message. - printf("Game over!\n"); - printf("You finished with %d points on level %d.\n", tg->points, tg->level); - - // Deinitialize Tetris - tg_delete(tg); - return 0; -} - -int32_t games_replay(uint64_t seed,int32_t sleeptime) -{ - return(-1); -} +#include "tetris.c" #endif diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 19e5f8d26..07a1f8e65 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -20,7 +20,7 @@ std::string MYCCLIBNAME = (char *)"gamescc"; #define GAMES_MAXKEYSTROKESGAP 60 #define GAMES_MAXPLAYERS 64 #define GAMES_REGISTRATIONSIZE (100 * 10000) -#define GAMES_REGISTRATION 5 +#define GAMES_REGISTRATION 1 #define GAMES_RNGMULT 11109 #define GAMES_RNGOFFSET 13849 @@ -29,7 +29,6 @@ std::string MYCCLIBNAME = (char *)"gamescc"; #define MYCCNAME "games" std::string Games_pname; -#define GAMENAME "sudoku" #define RPC_FUNCS \ { (char *)MYCCNAME, (char *)"rng", (char *)"hash,playerid", 1, 2, ' ', EVAL_GAMES }, \ @@ -104,33 +103,4 @@ if ( cp->evalcode == EVAL_GAMES ) \ } #endif -#define MAXPACK 23 -struct games_packitem -{ - int32_t type,launch,count,which,hplus,dplus,arm,flags,group; - char damage[8],hurldmg[8]; -}; - -struct games_player -{ - int32_t gold,hitpoints,strength,level,experience,packsize,dungeonlevel,amulet; - struct games_packitem gamespack[MAXPACK]; -}; - -struct games_state -{ - uint64_t seed; - char *keystrokes,*keystrokeshex; - uint32_t needflush,replaydone; - int32_t numkeys,ind,num,guiflag,counter,sleeptime,playersize,restoring,lastnum; - FILE *logfp; - struct games_player P; - char buffered[10000]; - uint8_t playerdata[10000]; -}; - -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); - - #endif diff --git a/src/cc/tetris.c b/src/cc/tetris.c new file mode 100644 index 000000000..4ffd27575 --- /dev/null +++ b/src/cc/tetris.c @@ -0,0 +1,758 @@ + +#include "tetris.h" +#include "dapps/dappstd.c" + + +/***************************************************************************/ +/** https://github.com/brenns10/tetris + @file main.c + @author Stephen Brennan + @date Created Wednesday, 10 June 2015 + @brief Main program for tetris. + @copyright Copyright (c) 2015, Stephen Brennan. Released under the Revised + BSD License. See LICENSE.txt for details. + *******************************************************************************/ + + +#include // for FILE +#include // for bool +#include +#include +#include +#include +#include +#include + +#ifdef BUILD_GAMESCC +#include "rogue/cursesd.h" +#else +#include +#endif + + +#define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) +#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) + +/******************************************************************************* + Array Definitions + *******************************************************************************/ + +const tetris_location TETROMINOS[NUM_TETROMINOS][NUM_ORIENTATIONS][TETRIS] = +{ + // I + {{{1, 0}, {1, 1}, {1, 2}, {1, 3}}, + {{0, 2}, {1, 2}, {2, 2}, {3, 2}}, + {{3, 0}, {3, 1}, {3, 2}, {3, 3}}, + {{0, 1}, {1, 1}, {2, 1}, {3, 1}}}, + // J + {{{0, 0}, {1, 0}, {1, 1}, {1, 2}}, + {{0, 1}, {0, 2}, {1, 1}, {2, 1}}, + {{1, 0}, {1, 1}, {1, 2}, {2, 2}}, + {{0, 1}, {1, 1}, {2, 0}, {2, 1}}}, + // L + {{{0, 2}, {1, 0}, {1, 1}, {1, 2}}, + {{0, 1}, {1, 1}, {2, 1}, {2, 2}}, + {{1, 0}, {1, 1}, {1, 2}, {2, 0}}, + {{0, 0}, {0, 1}, {1, 1}, {2, 1}}}, + // O + {{{0, 1}, {0, 2}, {1, 1}, {1, 2}}, + {{0, 1}, {0, 2}, {1, 1}, {1, 2}}, + {{0, 1}, {0, 2}, {1, 1}, {1, 2}}, + {{0, 1}, {0, 2}, {1, 1}, {1, 2}}}, + // S + {{{0, 1}, {0, 2}, {1, 0}, {1, 1}}, + {{0, 1}, {1, 1}, {1, 2}, {2, 2}}, + {{1, 1}, {1, 2}, {2, 0}, {2, 1}}, + {{0, 0}, {1, 0}, {1, 1}, {2, 1}}}, + // T + {{{0, 1}, {1, 0}, {1, 1}, {1, 2}}, + {{0, 1}, {1, 1}, {1, 2}, {2, 1}}, + {{1, 0}, {1, 1}, {1, 2}, {2, 1}}, + {{0, 1}, {1, 0}, {1, 1}, {2, 1}}}, + // Z + {{{0, 0}, {0, 1}, {1, 1}, {1, 2}}, + {{0, 2}, {1, 1}, {1, 2}, {2, 1}}, + {{1, 0}, {1, 1}, {2, 1}, {2, 2}}, + {{0, 1}, {1, 0}, {1, 1}, {2, 0}}}, +}; + +const int GRAVITY_LEVEL[MAX_LEVEL+1] = { + // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, + //10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 30, 28, 26, 24, 22, 20, 16, 12, 8, 4 +}; + +/******************************************************************************* + Helper Functions for Blocks + *******************************************************************************/ + +void sleep_milli(int milliseconds) +{ + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = milliseconds * 1000 * 1000; + nanosleep(&ts, NULL); +} + +/* + Return the block at the given row and column. + */ +char tg_get(tetris_game *obj, int row, int column) +{ + return obj->board[obj->cols * row + column]; +} + +/* + Set the block at the given row and column. + */ +static void tg_set(tetris_game *obj, int row, int column, char value) +{ + obj->board[obj->cols * row + column] = value; +} + +/* + Check whether a row and column are in bounds. + */ +bool tg_check(tetris_game *obj, int row, int col) +{ + return 0 <= row && row < obj->rows && 0 <= col && col < obj->cols; +} + +/* + Place a block onto the board. + */ +static void tg_put(tetris_game *obj, tetris_block block) +{ + int i; + for (i = 0; i < TETRIS; i++) { + tetris_location cell = TETROMINOS[block.typ][block.ori][i]; + tg_set(obj, block.loc.row + cell.row, block.loc.col + cell.col, + TYPE_TO_CELL(block.typ)); + } +} + +/* + Clear a block out of the board. + */ +static void tg_remove(tetris_game *obj, tetris_block block) +{ + int i; + for (i = 0; i < TETRIS; i++) { + tetris_location cell = TETROMINOS[block.typ][block.ori][i]; + tg_set(obj, block.loc.row + cell.row, block.loc.col + cell.col, TC_EMPTY); + } +} + +/* + Check if a block can be placed on the board. + */ +static bool tg_fits(tetris_game *obj, tetris_block block) +{ + int i, r, c; + for (i = 0; i < TETRIS; i++) { + tetris_location cell = TETROMINOS[block.typ][block.ori][i]; + r = block.loc.row + cell.row; + c = block.loc.col + cell.col; + if (!tg_check(obj, r, c) || TC_IS_FILLED(tg_get(obj, r, c))) { + return false; + } + } + return true; +} + +/* + Create a new falling block and populate the next falling block with a random + one. + */ +static void tg_new_falling(tetris_game *obj) +{ + // Put in a new falling tetromino. + obj->falling = obj->next; + obj->next.typ = random_tetromino(); + obj->next.ori = 0; + obj->next.loc.row = 0; + obj->next.loc.col = obj->cols/2 - 2; +} + +/******************************************************************************* + Game Turn Helpers + *******************************************************************************/ + +/* + Tick gravity, and move the block down if gravity should act. + */ +static void tg_do_gravity_tick(tetris_game *obj) +{ + obj->ticks_till_gravity--; + if (obj->ticks_till_gravity <= 0) { + tg_remove(obj, obj->falling); + obj->falling.loc.row++; + if (tg_fits(obj, obj->falling)) { + obj->ticks_till_gravity = GRAVITY_LEVEL[obj->level]; + } else { + obj->falling.loc.row--; + tg_put(obj, obj->falling); + + tg_new_falling(obj); + } + tg_put(obj, obj->falling); + } +} + +/* + Move the falling tetris block left (-1) or right (+1). + */ +static void tg_move(tetris_game *obj, int direction) +{ + tg_remove(obj, obj->falling); + obj->falling.loc.col += direction; + if (!tg_fits(obj, obj->falling)) { + obj->falling.loc.col -= direction; + } + tg_put(obj, obj->falling); +} + +/* + Send the falling tetris block to the bottom. + */ +static void tg_down(tetris_game *obj) +{ + tg_remove(obj, obj->falling); + while (tg_fits(obj, obj->falling)) { + obj->falling.loc.row++; + } + obj->falling.loc.row--; + tg_put(obj, obj->falling); + tg_new_falling(obj); +} + +/* + Rotate the falling block in either direction (+/-1). + */ +static void tg_rotate(tetris_game *obj, int direction) +{ + tg_remove(obj, obj->falling); + + while (true) { + obj->falling.ori = (obj->falling.ori + direction) % NUM_ORIENTATIONS; + + // If the new orientation fits, we're done. + if (tg_fits(obj, obj->falling)) + break; + + // Otherwise, try moving left to make it fit. + obj->falling.loc.col--; + if (tg_fits(obj, obj->falling)) + break; + + // Finally, try moving right to make it fit. + obj->falling.loc.col += 2; + if (tg_fits(obj, obj->falling)) + break; + + // Put it back in its original location and try the next orientation. + obj->falling.loc.col--; + // Worst case, we come back to the original orientation and it fits, so this + // loop will terminate. + } + + tg_put(obj, obj->falling); +} + +/* + Swap the falling block with the block in the hold buffer. + */ +static void tg_hold(tetris_game *obj) +{ + tg_remove(obj, obj->falling); + if (obj->stored.typ == -1) { + obj->stored = obj->falling; + tg_new_falling(obj); + } else { + int typ = obj->falling.typ, ori = obj->falling.ori; + obj->falling.typ = obj->stored.typ; + obj->falling.ori = obj->stored.ori; + obj->stored.typ = typ; + obj->stored.ori = ori; + while (!tg_fits(obj, obj->falling)) { + obj->falling.loc.row--; + } + } + tg_put(obj, obj->falling); +} + +/* + Perform the action specified by the move. + */ +static void tg_handle_move(tetris_game *obj, tetris_move move) +{ + switch (move) { + case TM_LEFT: + tg_move(obj, -1); + break; + case TM_RIGHT: + tg_move(obj, 1); + break; + case TM_DROP: + tg_down(obj); + break; + case TM_CLOCK: + tg_rotate(obj, 1); + break; + case TM_COUNTER: + tg_rotate(obj, -1); + break; + case TM_HOLD: + tg_hold(obj); + break; + default: + // pass + break; + } +} + +/* + Return true if line i is full. + */ +static bool tg_line_full(tetris_game *obj, int i) +{ + int j; + for (j = 0; j < obj->cols; j++) { + if (TC_IS_EMPTY(tg_get(obj, i, j))) + return false; + } + return true; +} + +/* + Shift every row above r down one. + */ +static void tg_shift_lines(tetris_game *obj, int r) +{ + int i, j; + for (i = r-1; i >= 0; i--) { + for (j = 0; j < obj->cols; j++) { + tg_set(obj, i+1, j, tg_get(obj, i, j)); + tg_set(obj, i, j, TC_EMPTY); + } + } +} + +/* + Find rows that are filled, remove them, shift, and return the number of + cleared rows. + */ +static int tg_check_lines(tetris_game *obj) +{ + int i, nlines = 0; + tg_remove(obj, obj->falling); // don't want to mess up falling block + + for (i = obj->rows-1; i >= 0; i--) { + if (tg_line_full(obj, i)) { + tg_shift_lines(obj, i); + i++; // do this line over again since they're shifted + nlines++; + } + } + + tg_put(obj, obj->falling); // replace + return nlines; +} + +/* + Adjust the score for the game, given how many lines were just cleared. + */ +static void tg_adjust_score(tetris_game *obj, int lines_cleared) +{ + static int line_multiplier[] = {0, 40, 100, 300, 1200}; + obj->points += line_multiplier[lines_cleared] * (obj->level + 1); + if (lines_cleared >= obj->lines_remaining) { + obj->level = MIN(MAX_LEVEL, obj->level + 1); + lines_cleared -= obj->lines_remaining; + obj->lines_remaining = LINES_PER_LEVEL - lines_cleared; + } else { + obj->lines_remaining -= lines_cleared; + } +} + +/* + Return true if the game is over. + */ +static bool tg_game_over(tetris_game *obj) +{ + int i, j; + bool over = false; + tg_remove(obj, obj->falling); + for (i = 0; i < 2; i++) { + for (j = 0; j < obj->cols; j++) { + if (TC_IS_FILLED(tg_get(obj, i, j))) { + over = true; + } + } + } + tg_put(obj, obj->falling); + return over; +} + +/******************************************************************************* + Main Public Functions + *******************************************************************************/ + +/* + Do a single game tick: process gravity, user input, and score. Return true if + the game is still running, false if it is over. + */ +bool tg_tick(tetris_game *obj, tetris_move move) +{ + int lines_cleared; + // Handle gravity. + tg_do_gravity_tick(obj); + + // Handle input. + tg_handle_move(obj, move); + + // Check for cleared lines + lines_cleared = tg_check_lines(obj); + + tg_adjust_score(obj, lines_cleared); + + // Return whether the game will continue (NOT whether it's over) + return !tg_game_over(obj); +} + +void tg_init(tetris_game *obj, int rows, int cols) +{ + // Initialization logic + obj->rows = rows; + obj->cols = cols; + obj->board = (char *)malloc(rows * cols); + memset(obj->board, TC_EMPTY, rows * cols); + obj->points = 0; + obj->level = 0; + obj->ticks_till_gravity = GRAVITY_LEVEL[obj->level]; + obj->lines_remaining = LINES_PER_LEVEL; + //srand(time(NULL)); + tg_new_falling(obj); + tg_new_falling(obj); + obj->stored.typ = -1; + obj->stored.ori = 0; + obj->stored.loc.row = 0; + obj->next.loc.col = obj->cols/2 - 2; + printf("%d", obj->falling.loc.col); +} + +tetris_game *tg_create(int rows, int cols) +{ + tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); + tg_init(obj, rows, cols); + return obj; +} + +void tg_destroy(tetris_game *obj) +{ + // Cleanup logic + free(obj->board); +} + +void tg_delete(tetris_game *obj) { + tg_destroy(obj); + free(obj); +} + +/* + Load a game from a file. + */ +tetris_game *tg_load(FILE *f) +{ + tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); + if (fread(obj, sizeof(tetris_game), 1, f) != 1 ) + { + fprintf(stderr,"read game error\n"); + free(obj); + obj = 0; + } + else + { + obj->board = (char *)malloc(obj->rows * obj->cols); + if (fread(obj->board, sizeof(char), obj->rows * obj->cols, f) != obj->rows * obj->cols ) + { + fprintf(stderr,"fread error\n"); + free(obj->board); + free(obj); + obj = 0; + } + } + return obj; +} + +/* + Save a game to a file. + */ +void tg_save(tetris_game *obj, FILE *f) +{ + if (fwrite(obj, sizeof(tetris_game), 1, f) != 1 ) + fprintf(stderr,"error writing tetrisgame\n"); + else if (fwrite(obj->board, sizeof(char), obj->rows * obj->cols, f) != obj->rows * obj->cols ) + fprintf(stderr,"error writing board\n"); +} + +/* + Print a game board to a file. Really just for early debugging. + */ +void tg_print(tetris_game *obj, FILE *f) { + int i, j; + for (i = 0; i < obj->rows; i++) { + for (j = 0; j < obj->cols; j++) { + if (TC_IS_EMPTY(tg_get(obj, i, j))) { + fputs(TC_EMPTY_STR, f); + } else { + fputs(TC_BLOCK_STR, f); + } + } + fputc('\n', f); + } +} + +/* + 2 columns per cell makes the game much nicer. + */ +#define COLS_PER_CELL 2 +/* + Macro to print a cell of a specific type to a window. + */ +#define ADD_BLOCK(w,x) waddch((w),' '|A_REVERSE|COLOR_PAIR(x)); \ +waddch((w),' '|A_REVERSE|COLOR_PAIR(x)) +#define ADD_EMPTY(w) waddch((w), ' '); waddch((w), ' ') + +/* + Print the tetris board onto the ncurses window. + */ +void display_board(WINDOW *w, tetris_game *obj) +{ + int i, j; + box(w, 0, 0); + for (i = 0; i < obj->rows; i++) { + wmove(w, 1 + i, 1); + for (j = 0; j < obj->cols; j++) { + if (TC_IS_FILLED(tg_get(obj, i, j))) { + ADD_BLOCK(w,tg_get(obj, i, j)); + } else { + ADD_EMPTY(w); + } + } + } + wnoutrefresh(w); +} + +/* + Display a tetris piece in a dedicated window. + */ +void display_piece(WINDOW *w, tetris_block block) +{ + int b; + tetris_location c; + wclear(w); + box(w, 0, 0); + if (block.typ == -1) { + wnoutrefresh(w); + return; + } + for (b = 0; b < TETRIS; b++) { + c = TETROMINOS[block.typ][block.ori][b]; + wmove(w, c.row + 1, c.col * COLS_PER_CELL + 1); + ADD_BLOCK(w, TYPE_TO_CELL(block.typ)); + } + wnoutrefresh(w); +} + +/* + Display score information in a dedicated window. + */ +void display_score(WINDOW *w, tetris_game *tg) +{ + wclear(w); + box(w, 0, 0); + wprintw(w, (char *)"Score\n%d\n", tg->points); + wprintw(w, (char *)"Level\n%d\n", tg->level); + wprintw(w, (char *)"Lines\n%d\n", tg->lines_remaining); + wnoutrefresh(w); +} + +/* + Save and exit the game. + */ +void save(tetris_game *game, WINDOW *w) +{ + FILE *f; + + wclear(w); + box(w, 0, 0); // return the border + wmove(w, 1, 1); + wprintw(w, (char *)"Save and exit? [Y/n] "); + wrefresh(w); + timeout(-1); + if (getch() == 'n') { + timeout(0); + return; + } + f = fopen("tetris.save", "w"); + tg_save(game, f); + fclose(f); + tg_delete(game); + endwin(); + fprintf(stderr,"Game saved to \"tetris.save\".\n"); + fprintf(stderr,"Resume by passing the filename as an argument to this program.\n"); + exit(EXIT_SUCCESS); +} + +/* + Do the NCURSES initialization steps for color blocks. + */ +void init_colors(void) +{ + start_color(); + //init_color(COLOR_ORANGE, 1000, 647, 0); + init_pair(TC_CELLI, COLOR_CYAN, COLOR_BLACK); + init_pair(TC_CELLJ, COLOR_BLUE, COLOR_BLACK); + init_pair(TC_CELLL, COLOR_WHITE, COLOR_BLACK); + init_pair(TC_CELLO, COLOR_YELLOW, COLOR_BLACK); + init_pair(TC_CELLS, COLOR_GREEN, COLOR_BLACK); + init_pair(TC_CELLT, COLOR_MAGENTA, COLOR_BLACK); + init_pair(TC_CELLZ, COLOR_RED, COLOR_BLACK); +} + +/* + Main tetris game! + */ +#ifdef STANDALONE +char *clonestr(char *str) +{ + char *clone; int32_t len; + if ( str == 0 || str[0] == 0 ) + { + printf("warning cloning nullstr.%p\n",str); +#ifdef __APPLE__ + while ( 1 ) sleep(1); +#endif + str = (char *)""; + } + len = strlen(str); + clone = (char *)calloc(1,len+16); + strcpy(clone,str); + return(clone); +} + +int tetris(int argc, char **argv) +{ + tetris_game *tg; + tetris_move move = TM_NONE; + bool running = true; + WINDOW *board, *next, *hold, *score; + int32_t c,skipcount=0; bits256 gametxid; uint32_t eventid = 0; + memset(&gametxid,0,sizeof(gametxid)); + // Load file if given a filename. + if (argc >= 2) { + FILE *f = fopen(argv[1], "r"); + if (f == NULL) { + perror("tetris"); + exit(EXIT_FAILURE); + } + tg = tg_load(f); + fclose(f); + } else { + // Otherwise create new game. + tg = tg_create(22, 10); + } + // NCURSES initialization: + initscr(); // initialize curses + cbreak(); // pass key presses to program, but not signals + noecho(); // don't echo key presses to screen + keypad(stdscr, TRUE); // allow arrow keys + timeout(0); // no blocking on getch() + curs_set(0); // set the cursor to invisible + init_colors(); // setup tetris colors + + // Create windows for each section of the interface. + board = newwin(tg->rows + 2, 2 * tg->cols + 2, 0, 0); + next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); + hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1); + score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1); + int32_t counter = 0; + // Game loop + while (running) { + running = tg_tick(tg, move); + display_board(board, tg); + display_piece(next, tg->next); + display_piece(hold, tg->stored); + display_score(score, tg); + if ( (counter++ % 5) == 0 ) + doupdate(); + sleep_milli(10); + c = getch(); + if ( c != -1 || skipcount == 0x3fff ) + { + if ( skipcount > 0 ) + issue_games_events(gametxid,eventid-skipcount,skipcount | 0x4000); + if ( c != -1 ) + issue_games_events(gametxid,eventid,c); + skipcount = 0; + } else skipcount++; + eventid++; + switch ( c ) + { + case KEY_LEFT: + move = TM_LEFT; + break; + case KEY_RIGHT: + move = TM_RIGHT; + break; + case KEY_UP: + move = TM_CLOCK; + break; + case KEY_DOWN: + move = TM_DROP; + break; + case 'q': + running = false; + move = TM_NONE; + break; + case 'p': + wclear(board); + box(board, 0, 0); + wmove(board, tg->rows/2, (tg->cols*COLS_PER_CELL-6)/2); + wprintw(board, "PAUSED"); + wrefresh(board); + timeout(-1); + getch(); + timeout(0); + move = TM_NONE; + break; + case 's': + save(tg, board); + move = TM_NONE; + break; + case ' ': + move = TM_HOLD; + break; + default: + move = TM_NONE; + } + } + + // Deinitialize NCurses + wclear(stdscr); + endwin(); + // Output ending message. + printf("Game over!\n"); + printf("You finished with %d points on level %d.\n", tg->points, tg->level); + + // Deinitialize Tetris + tg_delete(tg); + return 0; +} + +int32_t games_replay(uint64_t seed,int32_t sleeptime) +{ + return(-1); +} diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index d6ae473fe..fd833d7b7 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -1,939 +1,4 @@ -/***************************************************************************/ -/** https://github.com/brenns10/tetris - @file main.c - @author Stephen Brennan - @date Created Wednesday, 10 June 2015 - @brief Main program for tetris. - @copyright Copyright (c) 2015, Stephen Brennan. Released under the Revised - BSD License. See LICENSE.txt for details. - *******************************************************************************/ - - -#ifndef TETRIS_H -#define TETRIS_H - -#include // for FILE -#include // for bool -#include -#include -#include -#include -#include - -#include -#include - -//#include -//#include - - -/* - Convert a tetromino type to its corresponding cell. - */ -#define TYPE_TO_CELL(x) ((x)+1) - -/* - Strings for how you would print a tetris board. - */ -#define TC_EMPTY_STR " " -#define TC_BLOCK_STR "\u2588" - -/* - Questions about a tetris cell. - */ -#define TC_IS_EMPTY(x) ((x) == TC_EMPTY) -#define TC_IS_FILLED(x) (!TC_IS_EMPTY(x)) - -/* - How many cells in a tetromino? - */ -#define TETRIS 4 -/* - How many tetrominos? - */ -#define NUM_TETROMINOS 7 -/* - How many orientations of a tetromino? - */ -#define NUM_ORIENTATIONS 4 - -/* - Level constants. - */ -#define MAX_LEVEL 19 -#define LINES_PER_LEVEL 10 - -/* - A "cell" is a 1x1 block within a tetris board. - */ -typedef enum { - TC_EMPTY, TC_CELLI, TC_CELLJ, TC_CELLL, TC_CELLO, TC_CELLS, TC_CELLT, TC_CELLZ -} tetris_cell; - -/* - A "type" is a type/shape of a tetromino. Not including orientation. - */ -typedef enum { - TET_I, TET_J, TET_L, TET_O, TET_S, TET_T, TET_Z -} tetris_type; - -/* - A row,column pair. Negative numbers allowed, because we need them for - offsets. - */ -typedef struct { - int row; - int col; -} tetris_location; - -/* - A "block" is a struct that contains information about a tetromino. - Specifically, what type it is, what orientation it has, and where it is. - */ -typedef struct { - int typ; - int ori; - tetris_location loc; -} tetris_block; - -/* - All possible moves to give as input to the game. - */ -typedef enum { - TM_LEFT, TM_RIGHT, TM_CLOCK, TM_COUNTER, TM_DROP, TM_HOLD, TM_NONE -} tetris_move; - -/* - A game object! - */ -typedef struct { - /* - Game board stuff: - */ - int rows; - int cols; - char *board; - /* - Scoring information: - */ - int points; - int level; - /* - Falling block is the one currently going down. Next block is the one that - will be falling after this one. Stored is the block that you can swap out. - */ - tetris_block falling; - tetris_block next; - tetris_block stored; - /* - Number of game ticks until the block will move down. - */ - int ticks_till_gravity; - /* - Number of lines until you advance to the next level. - */ - int lines_remaining; -} tetris_game; - -/* - This array stores all necessary information about the cells that are filled by - each tetromino. The first index is the type of the tetromino (i.e. shape, - e.g. I, J, Z, etc.). The next index is the orientation (0-3). The final - array contains 4 tetris_location objects, each mapping to an offset from a - point on the upper left that is the tetromino "origin". - */ -extern tetris_location TETROMINOS[NUM_TETROMINOS][NUM_ORIENTATIONS][TETRIS]; - -/* - This array tells you how many ticks per gravity by level. Decreases as level - increases, to add difficulty. - */ -extern int GRAVITY_LEVEL[MAX_LEVEL+1]; - -// Data structure manipulation. -void tg_init(tetris_game *obj, int rows, int cols); -tetris_game *tg_create(int rows, int cols); -void tg_destroy(tetris_game *obj); -void tg_delete(tetris_game *obj); -tetris_game *tg_load(FILE *f); -void tg_save(tetris_game *obj, FILE *f); - -// Public methods not related to memory: -char tg_get(tetris_game *obj, int row, int col); -bool tg_check(tetris_game *obj, int row, int col); -bool tg_tick(tetris_game *obj, tetris_move move); -void tg_print(tetris_game *obj, FILE *f); - -#endif // TETRIS_H - - -#define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) -#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) - -/******************************************************************************* - Array Definitions - *******************************************************************************/ - -tetris_location TETROMINOS[NUM_TETROMINOS][NUM_ORIENTATIONS][TETRIS] = { - // I - {{{1, 0}, {1, 1}, {1, 2}, {1, 3}}, - {{0, 2}, {1, 2}, {2, 2}, {3, 2}}, - {{3, 0}, {3, 1}, {3, 2}, {3, 3}}, - {{0, 1}, {1, 1}, {2, 1}, {3, 1}}}, - // J - {{{0, 0}, {1, 0}, {1, 1}, {1, 2}}, - {{0, 1}, {0, 2}, {1, 1}, {2, 1}}, - {{1, 0}, {1, 1}, {1, 2}, {2, 2}}, - {{0, 1}, {1, 1}, {2, 0}, {2, 1}}}, - // L - {{{0, 2}, {1, 0}, {1, 1}, {1, 2}}, - {{0, 1}, {1, 1}, {2, 1}, {2, 2}}, - {{1, 0}, {1, 1}, {1, 2}, {2, 0}}, - {{0, 0}, {0, 1}, {1, 1}, {2, 1}}}, - // O - {{{0, 1}, {0, 2}, {1, 1}, {1, 2}}, - {{0, 1}, {0, 2}, {1, 1}, {1, 2}}, - {{0, 1}, {0, 2}, {1, 1}, {1, 2}}, - {{0, 1}, {0, 2}, {1, 1}, {1, 2}}}, - // S - {{{0, 1}, {0, 2}, {1, 0}, {1, 1}}, - {{0, 1}, {1, 1}, {1, 2}, {2, 2}}, - {{1, 1}, {1, 2}, {2, 0}, {2, 1}}, - {{0, 0}, {1, 0}, {1, 1}, {2, 1}}}, - // T - {{{0, 1}, {1, 0}, {1, 1}, {1, 2}}, - {{0, 1}, {1, 1}, {1, 2}, {2, 1}}, - {{1, 0}, {1, 1}, {1, 2}, {2, 1}}, - {{0, 1}, {1, 0}, {1, 1}, {2, 1}}}, - // Z - {{{0, 0}, {0, 1}, {1, 1}, {1, 2}}, - {{0, 2}, {1, 1}, {1, 2}, {2, 1}}, - {{1, 0}, {1, 1}, {2, 1}, {2, 2}}, - {{0, 1}, {1, 0}, {1, 1}, {2, 0}}}, -}; - -int GRAVITY_LEVEL[MAX_LEVEL+1] = { - // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, - //10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 30, 28, 26, 24, 22, 20, 16, 12, 8, 4 -}; - -/******************************************************************************* - Helper Functions for Blocks - *******************************************************************************/ - -void sleep_milli(int milliseconds) -{ - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = milliseconds * 1000 * 1000; - nanosleep(&ts, NULL); -} - -/* - Return the block at the given row and column. - */ -char tg_get(tetris_game *obj, int row, int column) -{ - return obj->board[obj->cols * row + column]; -} - -/* - Set the block at the given row and column. - */ -static void tg_set(tetris_game *obj, int row, int column, char value) -{ - obj->board[obj->cols * row + column] = value; -} - -/* - Check whether a row and column are in bounds. - */ -bool tg_check(tetris_game *obj, int row, int col) -{ - return 0 <= row && row < obj->rows && 0 <= col && col < obj->cols; -} - -/* - Place a block onto the board. - */ -static void tg_put(tetris_game *obj, tetris_block block) -{ - int i; - for (i = 0; i < TETRIS; i++) { - tetris_location cell = TETROMINOS[block.typ][block.ori][i]; - tg_set(obj, block.loc.row + cell.row, block.loc.col + cell.col, - TYPE_TO_CELL(block.typ)); - } -} - -/* - Clear a block out of the board. - */ -static void tg_remove(tetris_game *obj, tetris_block block) -{ - int i; - for (i = 0; i < TETRIS; i++) { - tetris_location cell = TETROMINOS[block.typ][block.ori][i]; - tg_set(obj, block.loc.row + cell.row, block.loc.col + cell.col, TC_EMPTY); - } -} - -/* - Check if a block can be placed on the board. - */ -static bool tg_fits(tetris_game *obj, tetris_block block) -{ - int i, r, c; - for (i = 0; i < TETRIS; i++) { - tetris_location cell = TETROMINOS[block.typ][block.ori][i]; - r = block.loc.row + cell.row; - c = block.loc.col + cell.col; - if (!tg_check(obj, r, c) || TC_IS_FILLED(tg_get(obj, r, c))) { - return false; - } - } - return true; -} - -/* - Return a random tetromino type. - */ -static int random_tetromino(void) { - return rand() % NUM_TETROMINOS; -} - -/* - Create a new falling block and populate the next falling block with a random - one. - */ -static void tg_new_falling(tetris_game *obj) -{ - // Put in a new falling tetromino. - obj->falling = obj->next; - obj->next.typ = random_tetromino(); - obj->next.ori = 0; - obj->next.loc.row = 0; - obj->next.loc.col = obj->cols/2 - 2; -} - -/******************************************************************************* - Game Turn Helpers - *******************************************************************************/ - -/* - Tick gravity, and move the block down if gravity should act. - */ -static void tg_do_gravity_tick(tetris_game *obj) -{ - obj->ticks_till_gravity--; - if (obj->ticks_till_gravity <= 0) { - tg_remove(obj, obj->falling); - obj->falling.loc.row++; - if (tg_fits(obj, obj->falling)) { - obj->ticks_till_gravity = GRAVITY_LEVEL[obj->level]; - } else { - obj->falling.loc.row--; - tg_put(obj, obj->falling); - - tg_new_falling(obj); - } - tg_put(obj, obj->falling); - } -} - -/* - Move the falling tetris block left (-1) or right (+1). - */ -static void tg_move(tetris_game *obj, int direction) -{ - tg_remove(obj, obj->falling); - obj->falling.loc.col += direction; - if (!tg_fits(obj, obj->falling)) { - obj->falling.loc.col -= direction; - } - tg_put(obj, obj->falling); -} - -/* - Send the falling tetris block to the bottom. - */ -static void tg_down(tetris_game *obj) -{ - tg_remove(obj, obj->falling); - while (tg_fits(obj, obj->falling)) { - obj->falling.loc.row++; - } - obj->falling.loc.row--; - tg_put(obj, obj->falling); - tg_new_falling(obj); -} - -/* - Rotate the falling block in either direction (+/-1). - */ -static void tg_rotate(tetris_game *obj, int direction) -{ - tg_remove(obj, obj->falling); - - while (true) { - obj->falling.ori = (obj->falling.ori + direction) % NUM_ORIENTATIONS; - - // If the new orientation fits, we're done. - if (tg_fits(obj, obj->falling)) - break; - - // Otherwise, try moving left to make it fit. - obj->falling.loc.col--; - if (tg_fits(obj, obj->falling)) - break; - - // Finally, try moving right to make it fit. - obj->falling.loc.col += 2; - if (tg_fits(obj, obj->falling)) - break; - - // Put it back in its original location and try the next orientation. - obj->falling.loc.col--; - // Worst case, we come back to the original orientation and it fits, so this - // loop will terminate. - } - - tg_put(obj, obj->falling); -} - -/* - Swap the falling block with the block in the hold buffer. - */ -static void tg_hold(tetris_game *obj) -{ - tg_remove(obj, obj->falling); - if (obj->stored.typ == -1) { - obj->stored = obj->falling; - tg_new_falling(obj); - } else { - int typ = obj->falling.typ, ori = obj->falling.ori; - obj->falling.typ = obj->stored.typ; - obj->falling.ori = obj->stored.ori; - obj->stored.typ = typ; - obj->stored.ori = ori; - while (!tg_fits(obj, obj->falling)) { - obj->falling.loc.row--; - } - } - tg_put(obj, obj->falling); -} - -/* - Perform the action specified by the move. - */ -static void tg_handle_move(tetris_game *obj, tetris_move move) -{ - switch (move) { - case TM_LEFT: - tg_move(obj, -1); - break; - case TM_RIGHT: - tg_move(obj, 1); - break; - case TM_DROP: - tg_down(obj); - break; - case TM_CLOCK: - tg_rotate(obj, 1); - break; - case TM_COUNTER: - tg_rotate(obj, -1); - break; - case TM_HOLD: - tg_hold(obj); - break; - default: - // pass - break; - } -} - -/* - Return true if line i is full. - */ -static bool tg_line_full(tetris_game *obj, int i) -{ - int j; - for (j = 0; j < obj->cols; j++) { - if (TC_IS_EMPTY(tg_get(obj, i, j))) - return false; - } - return true; -} - -/* - Shift every row above r down one. - */ -static void tg_shift_lines(tetris_game *obj, int r) -{ - int i, j; - for (i = r-1; i >= 0; i--) { - for (j = 0; j < obj->cols; j++) { - tg_set(obj, i+1, j, tg_get(obj, i, j)); - tg_set(obj, i, j, TC_EMPTY); - } - } -} - -/* - Find rows that are filled, remove them, shift, and return the number of - cleared rows. - */ -static int tg_check_lines(tetris_game *obj) -{ - int i, nlines = 0; - tg_remove(obj, obj->falling); // don't want to mess up falling block - - for (i = obj->rows-1; i >= 0; i--) { - if (tg_line_full(obj, i)) { - tg_shift_lines(obj, i); - i++; // do this line over again since they're shifted - nlines++; - } - } - - tg_put(obj, obj->falling); // replace - return nlines; -} - -/* - Adjust the score for the game, given how many lines were just cleared. - */ -static void tg_adjust_score(tetris_game *obj, int lines_cleared) -{ - static int line_multiplier[] = {0, 40, 100, 300, 1200}; - obj->points += line_multiplier[lines_cleared] * (obj->level + 1); - if (lines_cleared >= obj->lines_remaining) { - obj->level = MIN(MAX_LEVEL, obj->level + 1); - lines_cleared -= obj->lines_remaining; - obj->lines_remaining = LINES_PER_LEVEL - lines_cleared; - } else { - obj->lines_remaining -= lines_cleared; - } -} - -/* - Return true if the game is over. - */ -static bool tg_game_over(tetris_game *obj) -{ - int i, j; - bool over = false; - tg_remove(obj, obj->falling); - for (i = 0; i < 2; i++) { - for (j = 0; j < obj->cols; j++) { - if (TC_IS_FILLED(tg_get(obj, i, j))) { - over = true; - } - } - } - tg_put(obj, obj->falling); - return over; -} - -/******************************************************************************* - Main Public Functions - *******************************************************************************/ - -/* - Do a single game tick: process gravity, user input, and score. Return true if - the game is still running, false if it is over. - */ -bool tg_tick(tetris_game *obj, tetris_move move) -{ - int lines_cleared; - // Handle gravity. - tg_do_gravity_tick(obj); - - // Handle input. - tg_handle_move(obj, move); - - // Check for cleared lines - lines_cleared = tg_check_lines(obj); - - tg_adjust_score(obj, lines_cleared); - - // Return whether the game will continue (NOT whether it's over) - return !tg_game_over(obj); -} - -void tg_init(tetris_game *obj, int rows, int cols) -{ - // Initialization logic - obj->rows = rows; - obj->cols = cols; - obj->board = (char *)malloc(rows * cols); - memset(obj->board, TC_EMPTY, rows * cols); - obj->points = 0; - obj->level = 0; - obj->ticks_till_gravity = GRAVITY_LEVEL[obj->level]; - obj->lines_remaining = LINES_PER_LEVEL; - srand(time(NULL)); - tg_new_falling(obj); - tg_new_falling(obj); - obj->stored.typ = -1; - obj->stored.ori = 0; - obj->stored.loc.row = 0; - obj->next.loc.col = obj->cols/2 - 2; - printf("%d", obj->falling.loc.col); -} - -tetris_game *tg_create(int rows, int cols) -{ - tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); - tg_init(obj, rows, cols); - return obj; -} - -void tg_destroy(tetris_game *obj) -{ - // Cleanup logic - free(obj->board); -} - -void tg_delete(tetris_game *obj) { - tg_destroy(obj); - free(obj); -} - -/* - Load a game from a file. - */ -tetris_game *tg_load(FILE *f) -{ - tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); - if (fread(obj, sizeof(tetris_game), 1, f) != 1 ) - { - fprintf(stderr,"read game error\n"); - free(obj); - obj = 0; - } - else - { - obj->board = (char *)malloc(obj->rows * obj->cols); - if (fread(obj->board, sizeof(char), obj->rows * obj->cols, f) != obj->rows * obj->cols ) - { - fprintf(stderr,"fread error\n"); - free(obj->board); - free(obj); - obj = 0; - } - } - return obj; -} - -/* - Save a game to a file. - */ -void tg_save(tetris_game *obj, FILE *f) -{ - if (fwrite(obj, sizeof(tetris_game), 1, f) != 1 ) - fprintf(stderr,"error writing tetrisgame\n"); - else if (fwrite(obj->board, sizeof(char), obj->rows * obj->cols, f) != obj->rows * obj->cols ) - fprintf(stderr,"error writing board\n"); -} - -/* - Print a game board to a file. Really just for early debugging. - */ -void tg_print(tetris_game *obj, FILE *f) { - int i, j; - for (i = 0; i < obj->rows; i++) { - for (j = 0; j < obj->cols; j++) { - if (TC_IS_EMPTY(tg_get(obj, i, j))) { - fputs(TC_EMPTY_STR, f); - } else { - fputs(TC_BLOCK_STR, f); - } - } - fputc('\n', f); - } -} - -/* - 2 columns per cell makes the game much nicer. - */ -#define COLS_PER_CELL 2 -/* - Macro to print a cell of a specific type to a window. - */ -#define ADD_BLOCK(w,x) waddch((w),' '|A_REVERSE|COLOR_PAIR(x)); \ -waddch((w),' '|A_REVERSE|COLOR_PAIR(x)) -#define ADD_EMPTY(w) waddch((w), ' '); waddch((w), ' ') - -/* - Print the tetris board onto the ncurses window. - */ -void display_board(WINDOW *w, tetris_game *obj) -{ - int i, j; - box(w, 0, 0); - for (i = 0; i < obj->rows; i++) { - wmove(w, 1 + i, 1); - for (j = 0; j < obj->cols; j++) { - if (TC_IS_FILLED(tg_get(obj, i, j))) { - ADD_BLOCK(w,tg_get(obj, i, j)); - } else { - ADD_EMPTY(w); - } - } - } - wnoutrefresh(w); -} - -/* - Display a tetris piece in a dedicated window. - */ -void display_piece(WINDOW *w, tetris_block block) -{ - int b; - tetris_location c; - wclear(w); - box(w, 0, 0); - if (block.typ == -1) { - wnoutrefresh(w); - return; - } - for (b = 0; b < TETRIS; b++) { - c = TETROMINOS[block.typ][block.ori][b]; - wmove(w, c.row + 1, c.col * COLS_PER_CELL + 1); - ADD_BLOCK(w, TYPE_TO_CELL(block.typ)); - } - wnoutrefresh(w); -} - -/* - Display score information in a dedicated window. - */ -void display_score(WINDOW *w, tetris_game *tg) -{ - wclear(w); - box(w, 0, 0); - wprintw(w, "Score\n%d\n", tg->points); - wprintw(w, "Level\n%d\n", tg->level); - wprintw(w, "Lines\n%d\n", tg->lines_remaining); - wnoutrefresh(w); -} - -/* - Boss mode! Make it look like you're doing work. - */ -void boss_mode(void) -{ - clear(); - //Mix_PauseMusic(); - printw("user@workstation-312:~/Documents/presentation $ ls -l\n" - "total 528\n" - "drwxr-xr-x 2 user users 4096 Jun 9 17:05 .\n" - "drwxr-xr-x 4 user users 4096 Jun 10 09:52 ..\n" - "-rw-r--r-- 1 user users 88583 Jun 9 14:13 figure1.png\n" - "-rw-r--r-- 1 user users 65357 Jun 9 15:40 figure2.png\n" - "-rw-r--r-- 1 user users 4469 Jun 9 16:17 presentation.aux\n" - "-rw-r--r-- 1 user users 42858 Jun 9 16:17 presentation.log\n" - "-rw-r--r-- 1 user users 2516 Jun 9 16:17 presentation.nav\n" - "-rw-r--r-- 1 user users 183 Jun 9 16:17 presentation.out\n" - "-rw-r--r-- 1 user users 349607 Jun 9 16:17 presentation.pdf\n" - "-rw-r--r-- 1 user users 0 Jun 9 16:17 presentation.snm\n" - "-rw-r--r-- 1 user users 9284 Jun 9 17:05 presentation.tex\n" - "-rw-r--r-- 1 user users 229 Jun 9 16:17 presentation.toc\n" - "\n" - "user@workstation-312:~/Documents/presentation $ "); - echo(); - timeout(-1); - while (getch() != KEY_F(1)); - timeout(0); - noecho(); - clear(); - //Mix_ResumeMusic(); -} - -/* - Save and exit the game. - */ -void save(tetris_game *game, WINDOW *w) -{ - FILE *f; - - wclear(w); - box(w, 0, 0); // return the border - wmove(w, 1, 1); - wprintw(w, "Save and exit? [Y/n] "); - wrefresh(w); - timeout(-1); - if (getch() == 'n') { - timeout(0); - return; - } - f = fopen("tetris.save", "w"); - tg_save(game, f); - fclose(f); - tg_delete(game); - endwin(); - printf("Game saved to \"tetris.save\".\n"); - printf("Resume by passing the filename as an argument to this program.\n"); - exit(EXIT_SUCCESS); -} - -/* - Do the NCURSES initialization steps for color blocks. - */ -void init_colors(void) -{ - start_color(); - //init_color(COLOR_ORANGE, 1000, 647, 0); - init_pair(TC_CELLI, COLOR_CYAN, COLOR_BLACK); - init_pair(TC_CELLJ, COLOR_BLUE, COLOR_BLACK); - init_pair(TC_CELLL, COLOR_WHITE, COLOR_BLACK); - init_pair(TC_CELLO, COLOR_YELLOW, COLOR_BLACK); - init_pair(TC_CELLS, COLOR_GREEN, COLOR_BLACK); - init_pair(TC_CELLT, COLOR_MAGENTA, COLOR_BLACK); - init_pair(TC_CELLZ, COLOR_RED, COLOR_BLACK); -} - -/* - Main tetris game! - */ -#ifdef STANDALONE - -int main(int argc, char **argv) -{ - tetris_game *tg; - tetris_move move = TM_NONE; - bool running = true; - WINDOW *board, *next, *hold, *score; - //Mix_Music *music; - - // Load file if given a filename. - if (argc >= 2) { - FILE *f = fopen(argv[1], "r"); - if (f == NULL) { - perror("tetris"); - exit(EXIT_FAILURE); - } - tg = tg_load(f); - fclose(f); - } else { - // Otherwise create new game. - tg = tg_create(22, 10); - } - - /* Initialize music. - if (SDL_Init(SDL_INIT_AUDIO) < 0) { - fprintf(stderr, "unable to initialize SDL\n"); - exit(EXIT_FAILURE); - } - if (Mix_Init(MIX_INIT_MP3) != MIX_INIT_MP3) { - fprintf(stderr, "unable to initialize SDL_mixer\n"); - exit(EXIT_FAILURE); - } - if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) != 0) { - fprintf(stderr, "unable to initialize audio\n"); - exit(EXIT_FAILURE); - } - Mix_AllocateChannels(1); // only need background music - music = Mix_LoadMUS("tetris.mp3"); - if (music) { - Mix_PlayMusic(music, -1); - }*/ - - // NCURSES initialization: - initscr(); // initialize curses - cbreak(); // pass key presses to program, but not signals - noecho(); // don't echo key presses to screen - keypad(stdscr, TRUE); // allow arrow keys - timeout(0); // no blocking on getch() - curs_set(0); // set the cursor to invisible - init_colors(); // setup tetris colors - - // Create windows for each section of the interface. - board = newwin(tg->rows + 2, 2 * tg->cols + 2, 0, 0); - next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); - hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1); - score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1); - int32_t counter = 0; - // Game loop - while (running) { - running = tg_tick(tg, move); - display_board(board, tg); - display_piece(next, tg->next); - display_piece(hold, tg->stored); - display_score(score, tg); - if ( (counter++ % 5) == 0 ) - doupdate(); - sleep_milli(10); - - switch (getch()) { - case KEY_LEFT: - move = TM_LEFT; - break; - case KEY_RIGHT: - move = TM_RIGHT; - break; - case KEY_UP: - move = TM_CLOCK; - break; - case KEY_DOWN: - move = TM_DROP; - break; - case 'q': - running = false; - move = TM_NONE; - break; - case 'p': - wclear(board); - box(board, 0, 0); - wmove(board, tg->rows/2, (tg->cols*COLS_PER_CELL-6)/2); - wprintw(board, "PAUSED"); - wrefresh(board); - timeout(-1); - getch(); - timeout(0); - move = TM_NONE; - break; - case 'b': - boss_mode(); - move = TM_NONE; - break; - case 's': - save(tg, board); - move = TM_NONE; - break; - case ' ': - move = TM_HOLD; - break; - default: - move = TM_NONE; - } - } - - // Deinitialize NCurses - wclear(stdscr); - endwin(); - - /* Deinitialize Sound - Mix_HaltMusic(); - Mix_FreeMusic(music); - Mix_CloseAudio(); - Mix_Quit();*/ - - // Output ending message. - printf("Game over!\n"); - printf("You finished with %d points on level %d.\n", tg->points, tg->level); - - // Deinitialize Tetris - tg_delete(tg); - return 0; -} -#else - /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -949,973 +14,55 @@ int main(int argc, char **argv) * * ******************************************************************************/ -#include "cJSON.h" -#include "CCinclude.h" +// game specific code for daemon -#define TETRIS_REGISTRATION 5 -#define TETRIS_REGISTRATIONSIZE (100 * 10000) -#define TETRIS_MAXPLAYERS 64 // need to send unused fees back to globalCC address to prevent leeching -#define TETRIS_MAXKEYSTROKESGAP 60 -#define TETRIS_MAXITERATIONS 777 - - -std::string Tetris_pname = ""; - -CScript tetris_newgameopret(int64_t buyin,int32_t maxplayers) +int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload) { - CScript opret; uint8_t evalcode = EVAL_TETRIS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'G' << buyin << maxplayers); - return(opret); -} - -CScript tetris_registeropret(uint256 gametxid,uint256 playertxid) -{ - CScript opret; uint8_t evalcode = EVAL_TETRIS; - //fprintf(stderr,"opret.(%s %s).R\n",gametxid.GetHex().c_str(),playertxid.GetHex().c_str()); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'R' << gametxid << playertxid); - return(opret); -} - -CScript tetris_keystrokesopret(uint256 gametxid,uint256 batontxid,CPubKey pk,std::vectorkeystrokes) -{ - CScript opret; uint8_t evalcode = EVAL_TETRIS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'K' << gametxid << batontxid << pk << keystrokes); - return(opret); -} - -CScript tetris_highlanderopret(uint8_t funcid,uint256 gametxid,int32_t regslot,CPubKey pk,std::vectorplayerdata,std::string pname) -{ - CScript opret; uint8_t evalcode = EVAL_TETRIS; std::string symbol(ASSETCHAINS_SYMBOL); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << gametxid << symbol << pname << regslot << pk << playerdata ); - return(opret); -} - -uint8_t tetris_highlanderopretdecode(uint256 &gametxid, uint256 &tokenid, int32_t ®slot, CPubKey &pk, std::vector &playerdata, std::string &symbol, std::string &pname,CScript scriptPubKey) -{ - std::string name, description; std::vector vorigPubkey; - std::vector> oprets, opretsDummy; - std::vector vopretNonfungible, vopret, vopretDummy,origpubkey; - uint8_t e, f,*script; std::vector voutPubkeys; - tokenid = zeroid; - GetOpReturnData(scriptPubKey, vopret); - script = (uint8_t *)vopret.data(); - if ( script[1] == 'c' && (f= DecodeTokenCreateOpRet(scriptPubKey,origpubkey,name,description, oprets)) == 'c' ) + uint256 gametxid; int32_t i,len; char str[67]; uint32_t eventid = 0; + if ( (len= payload.size()) > 36 ) { - GetOpretBlob(oprets, OPRETID_NONFUNGIBLEDATA, vopretNonfungible); - vopret = vopretNonfungible; - } - else if ( script[1] != 'H' && script[1] != 'Q' && (f= DecodeTokenOpRet(scriptPubKey, e, tokenid, voutPubkeys, opretsDummy)) != 0 ) - { - //fprintf(stderr,"decode opret %c tokenid.%s\n",script[1],tokenid.GetHex().c_str()); - GetNonfungibleData(tokenid, vopretNonfungible); //load nonfungible data from the 'tokenbase' tx - vopret = vopretNonfungible; - } - if ( vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> gametxid; ss >> symbol; ss >> pname; ss >> regslot; ss >> pk; ss >> playerdata) != 0 && e == EVAL_TETRIS && (f == 'H' || f == 'Q') ) - { - return(f); - } - fprintf(stderr,"SKIP obsolete: e.%d f.%c game.%s regslot.%d psize.%d\n",e,f,gametxid.GetHex().c_str(),regslot,(int32_t)playerdata.size()); - return(0); -} - -uint8_t tetris_keystrokesopretdecode(uint256 &gametxid,uint256 &batontxid,CPubKey &pk,std::vector &keystrokes,CScript scriptPubKey) -{ - std::vector vopret; uint8_t e,f; - GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> gametxid; ss >> batontxid; ss >> pk; ss >> keystrokes) != 0 && e == EVAL_TETRIS && f == 'K' ) - { - return(f); - } - return(0); -} - -uint8_t tetris_registeropretdecode(uint256 &gametxid,uint256 &tokenid,uint256 &playertxid,CScript scriptPubKey) -{ - std::string name, description; std::vector vorigPubkey; - std::vector> oprets; - std::vector vopretNonfungible, vopret, vopretDummy,origpubkey; - uint8_t e, f,*script; std::vector voutPubkeys; - tokenid = zeroid; - GetOpReturnData(scriptPubKey, vopret); - script = (uint8_t *)vopret.data(); - if ( script[1] == 'c' && (f= DecodeTokenCreateOpRet(scriptPubKey,origpubkey,name,description,oprets)) == 'c' ) - { - GetOpretBlob(oprets, OPRETID_NONFUNGIBLEDATA, vopretNonfungible); - vopret = vopretNonfungible; - } - else if ( script[1] != 'R' && (f= DecodeTokenOpRet(scriptPubKey, e, tokenid, voutPubkeys, oprets)) != 0 ) - { - GetOpretBlob(oprets, OPRETID_TETRISGAMEDATA, vopretDummy); // blob from non-creation tx opret - vopret = vopretDummy; - } - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> gametxid; ss >> playertxid) != 0 && e == EVAL_TETRIS && f == 'R' ) - { - return(f); - } - //fprintf(stderr,"e.%d f.%c game.%s playertxid.%s\n",e,f,gametxid.GetHex().c_str(),playertxid.GetHex().c_str()); - return(0); -} - -uint8_t tetris_newgameopreturndecode(int64_t &buyin,int32_t &maxplayers,CScript scriptPubKey) -{ - std::vector vopret; uint8_t e,f; - GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> buyin; ss >> maxplayers) != 0 && e == EVAL_TETRIS && f == 'G' ) - { - return(f); - } - return(0); -} - -void tetris_univalue(UniValue &result,const char *method,int64_t maxplayers,int64_t buyin) -{ - if ( method != 0 ) - { - result.push_back(Pair("name","tetris")); - result.push_back(Pair("method",method)); - } - if ( maxplayers > 0 ) - result.push_back(Pair("maxplayers",maxplayers)); - if ( buyin >= 0 ) - { - result.push_back(Pair("buyin",ValueFromAmount(buyin))); - if ( buyin == 0 ) - result.push_back(Pair("type","newbie")); - else result.push_back(Pair("type","buyin")); - } -} - -int32_t tetris_iamregistered(int32_t maxplayers,uint256 gametxid,CTransaction tx,char *mytetrisaddr) -{ - int32_t i,vout; uint256 spenttxid,hashBlock; CTransaction spenttx; char destaddr[64]; - for (i=0; i= 0 ) - { - if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 ) - { - Getscriptaddress(destaddr,spenttx.vout[0].scriptPubKey); - if ( strcmp(mytetrisaddr,destaddr) == 0 ) - return(1); - //else fprintf(stderr,"myaddr.%s vs %s\n",mytetrisaddr,destaddr); - } //else fprintf(stderr,"cant find spenttxid.%s\n",spenttxid.GetHex().c_str()); - } //else fprintf(stderr,"vout %d is unspent\n",vout); - } - return(0); -} - -int32_t tetris_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransaction &tx,int64_t &buyin,int32_t &maxplayers,uint256 txid,int32_t unspentv0) -{ - uint256 hashBlock; int32_t i,numvouts; char coinaddr[64]; CPubKey tetrispk; uint64_t txfee = 10000; - buyin = maxplayers = 0; - if ( (txid == zeroid || myGetTransaction(txid,tx,hashBlock) != 0) && (numvouts= tx.vout.size()) > 1 ) - { - if ( txid != zeroid ) - gameheight = komodo_blockheight(hashBlock); - else - { - txid = tx.GetHash(); - //fprintf(stderr,"set txid %s %llu\n",txid.GetHex().c_str(),(long long)CCgettxout(txid,0,1)); - } - if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) == txfee && (unspentv0 == 0 || CCgettxout(txid,0,1,0) == txfee) ) - { - if ( tetris_newgameopreturndecode(buyin,maxplayers,tx.vout[numvouts-1].scriptPubKey) == 'G' ) - { - if ( maxplayers < 1 || maxplayers > TETRIS_MAXPLAYERS || buyin < 0 ) - return(-6); - if ( numvouts > 2*maxplayers+1 ) - { - for (i=0; i playerdata,uint256 playertxid,uint256 tokenid,std::string symbol,std::string pname,uint256 gametxid) +int64_t games_cashout(struct games_player *P) { - int32_t i,vout,spentvini,numvouts,n=0; uint256 txid,spenttxid,hashBlock; struct tetris_player P; char packitemstr[512],*datastr=0; UniValue obj(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx; - memset(&P,0,sizeof(P)); - if ( playerdata.size() > 0 ) - { - datastr = (char *)malloc(playerdata.size()*2+1); - for (i=0; i= 0 ) - txid = spenttxid; - else if ( myIsutxo_spentinmempool(spenttxid,spentvini,txid,vout) == 0 || spenttxid == zeroid ) - { - fprintf(stderr,"mempool tracking error %s/v0\n",txid.ToString().c_str()); - break; - } - txid = spenttxid; - vout = 0; - if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) - { - for (i=0; i TETRIS_MAXITERATIONS ) - break; - } - obj.push_back(Pair("gametxid",gametxid.GetHex())); - if ( txid != playertxid ) - obj.push_back(Pair("batontxid",txid.GetHex())); - obj.push_back(Pair("playertxid",playertxid.GetHex())); - if ( tokenid != zeroid ) - obj.push_back(Pair("tokenid",tokenid.GetHex())); - else obj.push_back(Pair("tokenid",playertxid.GetHex())); - if ( datastr != 0 ) - { - obj.push_back(Pair("data",datastr)); - free(datastr); - } - obj.push_back(Pair("pack",a)); - obj.push_back(Pair("packsize",(int64_t)P.packsize)); - obj.push_back(Pair("hitpoints",(int64_t)P.hitpoints)); - obj.push_back(Pair("strength",(int64_t)(P.strength&0xffff))); - obj.push_back(Pair("maxstrength",(int64_t)(P.strength>>16))); - obj.push_back(Pair("level",(int64_t)P.level)); - obj.push_back(Pair("experience",(int64_t)P.experience)); - obj.push_back(Pair("dungeonlevel",(int64_t)P.dungeonlevel)); - obj.push_back(Pair("chain",symbol)); - obj.push_back(Pair("pname",pname)); - return(obj); + int32_t dungeonlevel; int64_t mult=10,cashout = 0; + if ( P->amulet != 0 ) + mult *= 5; + dungeonlevel = P->dungeonlevel; + if ( P->amulet != 0 && dungeonlevel < 26 ) + dungeonlevel = 26; + cashout = (uint64_t)P->gold * P->gold * mult * dungeonlevel; + return(cashout); } -int32_t tetris_iterateplayer(uint256 ®istertxid,uint256 firsttxid,int32_t firstvout,uint256 lasttxid) // retrace playertxid vins to reach highlander <- this verifies player is valid and tetris_playerdataspend makes sure it can only be used once -{ - uint256 spenttxid,txid = firsttxid; int32_t spentvini,n,vout = firstvout; - registertxid = zeroid; - if ( vout < 0 ) - return(-1); - n = 0; - while ( (spentvini= myIsutxo_spent(spenttxid,txid,vout)) == 0 ) - { - txid = spenttxid; - vout = spentvini; - if ( registertxid == zeroid ) - registertxid = txid; - if ( ++n >= TETRIS_MAXITERATIONS ) - { - fprintf(stderr,"tetris_iterateplayer n.%d, seems something is wrong\n",n); - return(-2); - } - } - if ( txid == lasttxid ) - return(0); - else - { - fprintf(stderr,"firsttxid.%s/v%d -> %s != last.%s\n",firsttxid.ToString().c_str(),firstvout,txid.ToString().c_str(),lasttxid.ToString().c_str()); - return(-1); - } -} - -/* - playertxid is whoever owns the nonfungible satoshi and it might have been bought and sold many times. - highlander is the game winning tx with the player data and is the only place where the unique player data exists - origplayergame is the gametxid that ends up being won by the highlander and they are linked directly as the highlander tx spends gametxid.vout0 - */ - -int32_t tetris_playerdata(struct CCcontract_info *cp,uint256 &origplayergame,uint256 &tokenid,CPubKey &pk,std::vector &playerdata,std::string &symbol,std::string &pname,uint256 playertxid) -{ - uint256 origplayertxid,hashBlock,gametxid,registertxid; CTransaction gametx,playertx,highlandertx; std::vector vopret; uint8_t *script,e,f; int32_t i,regslot,gameheight,numvouts,maxplayers; int64_t buyin; - if ( myGetTransaction(playertxid,playertx,hashBlock) != 0 && (numvouts= playertx.vout.size()) > 0 ) - { - if ( (f= tetris_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,playertx.vout[numvouts-1].scriptPubKey)) == 'H' || f == 'Q' ) - { - origplayergame = gametxid; - if ( tokenid != zeroid ) - { - playertxid = tokenid; - if ( myGetTransaction(playertxid,playertx,hashBlock) == 0 || (numvouts= playertx.vout.size()) <= 0 ) - { - fprintf(stderr,"couldnt get tokenid.%s\n",playertxid.GetHex().c_str()); - return(-2); - } - } - if ( tetris_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0) == 0 ) - { - //fprintf(stderr,"playertxid.%s got vin.%s/v%d gametxid.%s iterate.%d\n",playertxid.ToString().c_str(),playertx.vin[1].prevout.hash.ToString().c_str(),(int32_t)playertx.vin[1].prevout.n-maxplayers,gametxid.ToString().c_str(),tetris_iterateplayer(registertxid,gametxid,playertx.vin[1].prevout.n-maxplayers,playertxid)); - if ( (tokenid != zeroid || playertx.vin[1].prevout.hash == gametxid) && tetris_iterateplayer(registertxid,gametxid,playertx.vin[1].prevout.n-maxplayers,playertxid) == 0 ) - { - // if registertxid has vin from pk, it can be used - return(0); - } else fprintf(stderr,"hash mismatch or illegal gametxid\n"); - } else fprintf(stderr,"invalid game %s\n",gametxid.GetHex().c_str()); - } //else fprintf(stderr,"invalid player funcid.%c\n",f); - } else fprintf(stderr,"couldnt get playertxid.%s\n",playertxid.GetHex().c_str()); - return(-1); -} - -int32_t tetris_playerdataspend(CMutableTransaction &mtx,uint256 playertxid,int32_t vout,uint256 origplayergame) -{ - int64_t txfee = 10000; CTransaction tx; uint256 hashBlock; - if ( CCgettxout(playertxid,vout,1,0) == 1 ) // not sure if this is enough validation - { - mtx.vin.push_back(CTxIn(playertxid,vout,CScript())); - return(0); - } - else - { - vout = 0; - if ( myGetTransaction(playertxid,tx,hashBlock) != 0 && tx.vout[vout].nValue == 1 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) - { - if ( CCgettxout(playertxid,vout,1,0) == 1 ) // not sure if this is enough validation - { - mtx.vin.push_back(CTxIn(playertxid,vout,CScript())); - return(0); - } - } - return(-1); - } -} - -int32_t tetris_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **keystrokesp,int32_t &numkeys,int32_t ®slot,std::vector &playerdata,uint256 &batontxid,int32_t &batonvout,int64_t &batonvalue,int32_t &batonht,uint256 gametxid,CTransaction gametx,int32_t maxplayers,char *destaddr,int32_t &numplayers,std::string &symbol,std::string &pname) -{ - int32_t i,numvouts,spentvini,n,matches = 0; CPubKey pk; uint256 tid,active,spenttxid,tokenid,hashBlock,txid,origplayergame; CTransaction spenttx,matchtx,batontx; std::vector checkdata; CBlockIndex *pindex; char ccaddr[64],*keystrokes=0; - batonvalue = numkeys = numplayers = batonht = 0; - playertxid = batontxid = zeroid; - for (i=0; i= 0 ) - { - if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 ) - { - numplayers++; - Getscriptaddress(ccaddr,spenttx.vout[0].scriptPubKey); - if ( strcmp(destaddr,ccaddr) == 0 ) - { - matches++; - regslot = i; - matchtx = spenttx; - } //else fprintf(stderr,"%d+1 doesnt match %s vs %s\n",i,ccaddr,destaddr); - } //else fprintf(stderr,"%d+1 couldnt find spenttx.%s\n",i,spenttxid.GetHex().c_str()); - } //else fprintf(stderr,"%d+1 unspent\n",i); - } - if ( matches == 1 ) - { - numvouts = matchtx.vout.size(); - //fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex().c_str(),matches,numvouts); - if ( tetris_registeropretdecode(txid,tokenid,playertxid,matchtx.vout[numvouts-1].scriptPubKey) == 'R' )//&& txid == gametxid ) - { - //fprintf(stderr,"tokenid.%s txid.%s vs gametxid.%s player.%s\n",tokenid.GetHex().c_str(),txid.GetHex().c_str(),gametxid.GetHex().c_str(),playertxid.GetHex().c_str()); - if ( tokenid != zeroid ) - active = tokenid; - else active = playertxid; - if ( active == zeroid || tetris_playerdata(cp,origplayergame,tid,pk,playerdata,symbol,pname,active) == 0 ) - { - txid = matchtx.GetHash(); - //fprintf(stderr,"scan forward active.%s spenttxid.%s\n",active.GetHex().c_str(),txid.GetHex().c_str()); - n = 0; - while ( CCgettxout(txid,0,1,0) < 0 ) - { - spenttxid = zeroid; - spentvini = -1; - if ( (spentvini= myIsutxo_spent(spenttxid,txid,0)) >= 0 ) - txid = spenttxid; - else - { - if ( myIsutxo_spentinmempool(spenttxid,spentvini,txid,0) == 0 || spenttxid == zeroid ) - { - fprintf(stderr,"mempool tracking error %s/v0\n",txid.ToString().c_str()); - return(-2); - } - } - txid = spenttxid; - //fprintf(stderr,"n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); - if ( spentvini != 0 ) // game is over? - { - return(0); - } - if ( keystrokesp != 0 && myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() >= 2 ) - { - uint256 g,b; CPubKey p; std::vector k; - if ( tetris_keystrokesopretdecode(g,b,p,k,spenttx.vout[spenttx.vout.size()-1].scriptPubKey) == 'K' ) - { - keystrokes = (char *)realloc(keystrokes,numkeys + (int32_t)k.size()); - for (i=0; i= TETRIS_MAXITERATIONS ) - { - fprintf(stderr,"tetris_findbaton n.%d, seems something is wrong\n",n); - return(-5); - } - } - //fprintf(stderr,"set baton %s\n",txid.GetHex().c_str()); - batontxid = txid; - batonvout = 0; // not vini - // how to detect timeout, bailedout, highlander - hashBlock = zeroid; - if ( myGetTransaction(batontxid,batontx,hashBlock) != 0 && batontx.vout.size() > 0 ) - { - if ( hashBlock == zeroid ) - batonht = komodo_nextheight(); - else if ( (pindex= komodo_blockindex(hashBlock)) == 0 ) - return(-4); - else batonht = pindex->GetHeight(); - batonvalue = batontx.vout[0].nValue; - //printf("batonht.%d keystrokes[%d]\n",batonht,numkeys); - return(0); - } else fprintf(stderr,"couldnt find baton\n"); - } else fprintf(stderr,"error with playerdata\n"); - } else fprintf(stderr,"findbaton opret error\n"); - } - return(-1); -} - -int32_t tetris_playersalive(int32_t &openslots,int32_t &numplayers,uint256 gametxid,int32_t maxplayers,int32_t gameht,CTransaction gametx) -{ - int32_t i,n,vout,spentvini,registration_open = 0,alive = 0; CTransaction tx; uint256 txid,spenttxid,hashBlock; CBlockIndex *pindex; uint64_t txfee = 10000; - numplayers = openslots = 0; - if ( komodo_nextheight() <= gameht+TETRIS_MAXKEYSTROKESGAP ) - registration_open = 1; - for (i=0; i= 0 ) - txid = spenttxid; - else if ( myIsutxo_spentinmempool(spenttxid,spentvini,txid,vout) == 0 || spenttxid == zeroid ) - { - fprintf(stderr,"mempool tracking error %s/v0\n",txid.ToString().c_str()); - break; - } - txid = spenttxid; - vout = 0; - //fprintf(stderr,"n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); - if ( spentvini != 0 ) - break; - if ( n++ > TETRIS_MAXITERATIONS ) - break; - } - if ( txid != zeroid ) - { - if ( myGetTransaction(txid,tx,hashBlock) != 0 ) - { - if ( (pindex= komodo_blockindex(hashBlock)) != 0 ) - { - if ( pindex->GetHeight() <= gameht+TETRIS_MAXKEYSTROKESGAP ) - alive++; - } - } - } - } - } - else if ( registration_open != 0 ) - openslots++; - } - //fprintf(stderr,"numalive.%d openslots.%d\n",alive,openslots); - return(alive); -} - -uint64_t tetris_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 gametxid,char *mytetrisaddr) -{ - CBlockIndex *pindex; int32_t ht,openslots,delay,numplayers; uint256 hashBlock; uint64_t seed=0; char cmd[512]; CTransaction tx; - if ( myGetTransaction(gametxid,tx,hashBlock) != 0 && (pindex= komodo_blockindex(hashBlock)) != 0 ) - { - ht = pindex->GetHeight(); - delay = TETRIS_REGISTRATION * (maxplayers > 1); - obj.push_back(Pair("height",ht)); - obj.push_back(Pair("start",ht+delay)); - if ( komodo_nextheight() > ht+delay ) - { - if ( (pindex= komodo_chainactive(ht+delay)) != 0 ) - { - hashBlock = pindex->GetBlockHash(); - obj.push_back(Pair("starthash",hashBlock.ToString())); - memcpy(&seed,&hashBlock,sizeof(seed)); - seed &= (1LL << 62) - 1; - obj.push_back(Pair("seed",(int64_t)seed)); - if ( tetris_iamregistered(maxplayers,gametxid,tx,mytetrisaddr) > 0 ) - sprintf(cmd,"cc/tetris %llu %s",(long long)seed,gametxid.ToString().c_str()); - else sprintf(cmd,"./komodo-cli -ac_name=%s cclib register %d \"[%%22%s%%22]\"",ASSETCHAINS_SYMBOL,EVAL_TETRIS,gametxid.ToString().c_str()); - obj.push_back(Pair("run",cmd)); - } - } - obj.push_back(Pair("alive",tetris_playersalive(openslots,numplayers,gametxid,maxplayers,ht,tx))); - obj.push_back(Pair("openslots",openslots)); - obj.push_back(Pair("numplayers",numplayers)); - } - obj.push_back(Pair("maxplayers",maxplayers)); - obj.push_back(Pair("buyin",ValueFromAmount(buyin))); - return(seed); -} - -void tetris_gameplayerinfo(struct CCcontract_info *cp,UniValue &obj,uint256 gametxid,CTransaction gametx,int32_t vout,int32_t maxplayers,char *mytetrisaddr) -{ - // identify if bailout or quit or timed out - uint256 batontxid,spenttxid,gtxid,ptxid,tokenid,hashBlock,playertxid; CTransaction spenttx,batontx; int32_t numplayers,regslot,numkeys,batonvout,batonht,retval; int64_t batonvalue; std::vector playerdata; char destaddr[64]; std::string symbol,pname; - destaddr[0] = 0; - if ( myIsutxo_spent(spenttxid,gametxid,vout) >= 0 ) - { - if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 ) - Getscriptaddress(destaddr,spenttx.vout[0].scriptPubKey); - } - obj.push_back(Pair("slot",(int64_t)vout-1)); - if ( (retval= tetris_findbaton(cp,playertxid,0,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,destaddr,numplayers,symbol,pname)) == 0 ) - { - if ( CCgettxout(gametxid,maxplayers+vout,1,0) == 10000 ) - { - if ( myGetTransaction(batontxid,batontx,hashBlock) != 0 && batontx.vout.size() > 1 ) - { - if ( tetris_registeropretdecode(gtxid,tokenid,ptxid,batontx.vout[batontx.vout.size()-1].scriptPubKey) == 'R' && ptxid == playertxid && gtxid == gametxid ) - obj.push_back(Pair("status","registered")); - else obj.push_back(Pair("status","alive")); - } else obj.push_back(Pair("status","error")); - } else obj.push_back(Pair("status","finished")); - obj.push_back(Pair("baton",batontxid.ToString())); - obj.push_back(Pair("tokenid",tokenid.ToString())); - obj.push_back(Pair("batonaddr",destaddr)); - obj.push_back(Pair("ismine",strcmp(mytetrisaddr,destaddr)==0)); - obj.push_back(Pair("batonvout",(int64_t)batonvout)); - obj.push_back(Pair("batonvalue",ValueFromAmount(batonvalue))); - obj.push_back(Pair("batonht",(int64_t)batonht)); - if ( playerdata.size() > 0 ) - obj.push_back(Pair("player",tetris_playerobj(playerdata,playertxid,tokenid,symbol,pname,gametxid))); - } else fprintf(stderr,"findbaton err.%d\n",retval); -} - -int64_t tetris_registrationbaton(CMutableTransaction &mtx,uint256 gametxid,CTransaction gametx,int32_t maxplayers) -{ - int32_t vout,j,r; int64_t nValue; - if ( gametx.vout.size() > maxplayers+1 ) - { - r = rand() % maxplayers; - for (j=0; j 0 ) - { - result.push_back(Pair("hex",rawtx)); - if ( DecodeHexTx(tx,rawtx) != 0 ) - { - if ( broadcastflag != 0 && myAddtomempool(tx) != 0 ) - RelayTransaction(tx); - result.push_back(Pair("txid",tx.GetHash().ToString())); - result.push_back(Pair("result","success")); - } else result.push_back(Pair("error","decode hex")); - } else result.push_back(Pair("error","couldnt finalize CCtx")); - return(result); -} - -UniValue tetris_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey tetrispk,mypk; char *jsonstr; uint64_t inputsum,change,required,buyin=0; int32_t i,n,maxplayers = 1; - if ( txfee == 0 ) - txfee = 10000; - if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) - { - if ( n > 0 ) - { - maxplayers = juint(jitem(params,0),0); - if ( n > 1 ) - buyin = jdouble(jitem(params,1),0) * COIN + 0.0000000049; - } - } - if ( maxplayers < 1 || maxplayers > TETRIS_MAXPLAYERS ) - return(cclib_error(result,"illegal maxplayers")); - mypk = pubkey2pk(Mypubkey()); - tetrispk = GetUnspendable(cp,0); - tetris_univalue(result,"newgame",maxplayers,buyin); - required = (3*txfee + maxplayers*(TETRIS_REGISTRATIONSIZE+txfee)); - if ( (inputsum= AddCClibInputs(cp,mtx,tetrispk,required,16,cp->unspendableCCaddr)) >= required ) - { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,tetrispk)); // for highlander TCBOO creation - for (i=0; ievalcode,TETRIS_REGISTRATIONSIZE,tetrispk,tetrispk)); - for (i=0; ievalcode,txfee,tetrispk,tetrispk)); - if ( (change= inputsum - required) >= txfee ) - mtx.vout.push_back(MakeCC1vout(cp->evalcode,change,tetrispk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,tetris_newgameopret(buyin,maxplayers)); - return(tetris_rawtxresult(result,rawtx,1)); - } - else return(cclib_error(result,"illegal maxplayers")); - return(result); -} - -UniValue tetris_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); std::vector playerdata; uint256 playertxid,tokenid,origplayergame;int32_t n; CPubKey pk; bits256 t; std::string symbol,pname; - result.push_back(Pair("result","success")); - tetris_univalue(result,"playerinfo",-1,-1); - if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) - { - if ( n > 0 ) - { - playertxid = juint256(jitem(params,0)); - if ( tetris_playerdata(cp,origplayergame,tokenid,pk,playerdata,symbol,pname,playertxid) < 0 ) - return(cclib_error(result,"invalid playerdata")); - result.push_back(Pair("player",tetris_playerobj(playerdata,playertxid,tokenid,symbol,pname,origplayergame))); - } else return(cclib_error(result,"no playertxid")); - return(result); - } else return(cclib_error(result,"couldnt reparse params")); -} - -UniValue tetris_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - // vin0 -> TETRIS_REGISTRATIONSIZE 1of2 registration baton from creategame - // vin1 -> optional nonfungible character vout @ - // vin2 -> original creation TCBOO playerdata used - // vin3+ -> buyin - // vout0 -> keystrokes/completion baton - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); char destaddr[64],coinaddr[64]; uint256 tokenid,gametxid,origplayergame,playertxid,hashBlock; int32_t err,maxplayers,gameheight,n,numvouts,vout=1; int64_t inputsum,buyin,CCchange=0; CPubKey pk,mypk,tetrispk,burnpk; CTransaction tx,playertx; std::vector playerdata; std::string rawtx,symbol,pname; bits256 t; - - if ( txfee == 0 ) - txfee = 10000; - mypk = pubkey2pk(Mypubkey()); - burnpk = pubkey2pk(ParseHex(CC_BURNPUBKEY)); - tetrispk = GetUnspendable(cp,0); - tetris_univalue(result,"register",-1,-1); - playertxid = tokenid = zeroid; - if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) - { - if ( n > 0 ) - { - gametxid = juint256(jitem(params,0)); - if ( (err= tetris_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid,1)) == 0 ) - { - if ( n > 1 ) - { - playertxid = juint256(jitem(params,1)); - if ( tetris_playerdata(cp,origplayergame,tokenid,pk,playerdata,symbol,pname,playertxid) < 0 ) - return(cclib_error(result,"couldnt extract valid playerdata")); - if ( tokenid != zeroid ) // if it is tokentransfer this will be 0 - vout = 1; - } - if ( komodo_nextheight() > gameheight + TETRIS_MAXKEYSTROKESGAP ) - return(cclib_error(result,"didnt register in time, TETRIS_MAXKEYSTROKESGAP")); - tetris_univalue(result,0,maxplayers,buyin); - GetCCaddress1of2(cp,coinaddr,tetrispk,mypk); - if ( tetris_iamregistered(maxplayers,gametxid,tx,coinaddr) > 0 ) - return(cclib_error(result,"already registered")); - if ( (inputsum= tetris_registrationbaton(mtx,gametxid,tx,maxplayers)) != TETRIS_REGISTRATIONSIZE ) - return(cclib_error(result,"couldnt find available registration baton")); - else if ( playertxid != zeroid && tetris_playerdataspend(mtx,playertxid,vout,origplayergame) < 0 ) - return(cclib_error(result,"couldnt find playerdata to spend")); - else if ( buyin > 0 && AddNormalinputs(mtx,mypk,buyin,64) < buyin ) - return(cclib_error(result,"couldnt find enough normal funds for buyin")); - if ( tokenid != zeroid ) - { - mtx.vin.push_back(CTxIn(tokenid,0)); // spending cc marker as token is burned - char unspendableTokenAddr[64]; uint8_t tokenpriv[32]; struct CCcontract_info *cpTokens, tokensC; - cpTokens = CCinit(&tokensC, EVAL_TOKENS); - CPubKey unspPk = GetUnspendable(cpTokens, tokenpriv); - GetCCaddress(cpTokens, unspendableTokenAddr, unspPk); - CCaddr2set(cp, EVAL_TOKENS, unspPk, tokenpriv, unspendableTokenAddr); - } - mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,buyin + inputsum - txfee,tetrispk,mypk)); - GetCCaddress1of2(cp,destaddr,tetrispk,tetrispk); - CCaddr1of2set(cp,tetrispk,tetrispk,cp->CCpriv,destaddr); - mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode, 1, burnpk)); - - uint8_t e, funcid; uint256 tid; std::vector voutPubkeys, voutPubkeysEmpty; int32_t didtx = 0; - CScript opretRegister = tetris_registeropret(gametxid, playertxid); - if ( playertxid != zeroid ) - { - voutPubkeysEmpty.push_back(burnpk); - if ( myGetTransaction(playertxid,playertx,hashBlock) != 0 ) - { - std::vector> oprets; - if ( (funcid= DecodeTokenOpRet(playertx.vout.back().scriptPubKey, e, tid, voutPubkeys, oprets)) != 0) - { // if token in the opret - didtx = 1; - if ( funcid == 'c' ) - tid = tokenid == zeroid ? playertxid : tokenid; - vscript_t vopretRegister; - GetOpReturnData(opretRegister, vopretRegister); - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, - EncodeTokenOpRet(tid, voutPubkeysEmpty /*=never spent*/, std::make_pair(OPRETID_TETRISGAMEDATA, vopretRegister))); - } - } - } - if ( didtx == 0 ) - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, opretRegister); - - return(tetris_rawtxresult(result,rawtx,1)); - } else return(cclib_error(result,"invalid gametxid")); - } else return(cclib_error(result,"no gametxid")); - } else return(cclib_error(result,"couldnt reparse params")); -} - -UniValue tetris_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - // vin0 -> baton from registration or previous keystrokes - // vout0 -> new baton - // opret -> user input chars - // being killed should auto broadcast (possible to be suppressed?) - // respawn to be prevented by including timestamps - int32_t nextheight = komodo_nextheight(); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); - UniValue result(UniValue::VOBJ); CPubKey tetrispk,mypk; uint256 gametxid,playertxid,batontxid; int64_t batonvalue,buyin; std::vector keystrokes,playerdata; int32_t numplayers,regslot,numkeys,batonht,batonvout,n,elapsed,gameheight,maxplayers; CTransaction tx; CTxOut txout; char *keystrokestr,destaddr[64]; std::string rawtx,symbol,pname; bits256 t; uint8_t mypriv[32]; - if ( txfee == 0 ) - txfee = 10000; - tetris_univalue(result,"keystrokes",-1,-1); - if ( params != 0 && (n= cJSON_GetArraySize(params)) == 2 && (keystrokestr= jstr(jitem(params,1),0)) != 0 ) - { - gametxid = juint256(jitem(params,0)); - result.push_back(Pair("gametxid",gametxid.GetHex())); - result.push_back(Pair("keystrokes",keystrokestr)); - keystrokes = ParseHex(keystrokestr); - mypk = pubkey2pk(Mypubkey()); - tetrispk = GetUnspendable(cp,0); - GetCCaddress1of2(cp,destaddr,tetrispk,mypk); - if ( tetris_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid,1) == 0 ) - { - if ( tetris_findbaton(cp,playertxid,0,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,tx,maxplayers,destaddr,numplayers,symbol,pname) == 0 ) - { - result.push_back(Pair("batontxid",batontxid.GetHex())); - result.push_back(Pair("playertxid",playertxid.GetHex())); - if ( maxplayers == 1 || nextheight <= batonht+TETRIS_MAXKEYSTROKESGAP ) - { - mtx.vin.push_back(CTxIn(batontxid,batonvout,CScript())); //this validates user if pk - mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,batonvalue-txfee,tetrispk,mypk)); - Myprivkey(mypriv); - CCaddr1of2set(cp,tetrispk,mypk,mypriv,destaddr); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,tetris_keystrokesopret(gametxid,batontxid,mypk,keystrokes)); - //fprintf(stderr,"KEYSTROKES.(%s)\n",rawtx.c_str()); - return(tetris_rawtxresult(result,rawtx,1)); - } else return(cclib_error(result,"keystrokes tx was too late")); - } else return(cclib_error(result,"couldnt find batontxid")); - } else return(cclib_error(result,"invalid gametxid")); - } else return(cclib_error(result,"couldnt reparse params")); -} - -char *tetris_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vector &newdata,uint64_t &seed,uint256 &playertxid,struct CCcontract_info *cp,uint256 gametxid,char *tetrisaddr) -{ - CPubKey tetrispk; 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 playerdata; uint256 batontxid; FILE *fp; uint8_t newplayer[10000]; struct tetris_player P,endP; - tetrispk = GetUnspendable(cp,0); - *numkeysp = 0; - seed = 0; - num = numkeys = 0; - playertxid = zeroid; - str[0] = 0; - if ( (err= tetris_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0)) == 0 ) - { - if ( (retval= tetris_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,tetrisaddr,numplayers,symbol,pname)) == 0 ) - { - UniValue obj; - seed = tetris_gamefields(obj,maxplayers,buyin,gametxid,tetrisaddr); - //fprintf(stderr,"(%s) found baton %s numkeys.%d seed.%llu playerdata.%d playertxid.%s\n",pname.size()!=0?pname.c_str():Tetris_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 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 tetris_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); CPubKey pk,tetrispk; int32_t i,n,numkeys,flag = 0; uint64_t seed; char str[512],tetrisaddr[64],*pubstr,*hexstr,*keystrokes = 0; std::vector newdata; uint256 gametxid,playertxid; FILE *fp; uint8_t pub33[33]; - pk = pubkey2pk(Mypubkey()); - tetrispk = GetUnspendable(cp,0); - result.push_back(Pair("name","tetris")); - result.push_back(Pair("method","extract")); - tetrisaddr[0] = 0; - if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) - { - if ( n > 0 ) - { - gametxid = juint256(jitem(params,0)); - result.push_back(Pair("gametxid",gametxid.GetHex())); - if ( n == 2 ) - { - if ( (pubstr= jstr(jitem(params,1),0)) != 0 ) - { - if (strlen(pubstr) == 66 ) - { - decode_hex(pub33,33,pubstr); - pk = buf2pk(pub33); - } - else if ( strlen(pubstr) < 36 ) - strcpy(tetrisaddr,pubstr); - } - //fprintf(stderr,"gametxid.%s %s\n",gametxid.GetHex().c_str(),pubstr); - } - if ( tetrisaddr[0] == 0 ) - GetCCaddress1of2(cp,tetrisaddr,tetrispk,pk); - result.push_back(Pair("tetrisaddr",tetrisaddr)); - str[0] = 0; - if ( (keystrokes= tetris_extractgame(1,str,&numkeys,newdata,seed,playertxid,cp,gametxid,tetrisaddr)) != 0 ) - { - result.push_back(Pair("status","success")); - flag = 1; - hexstr = (char *)malloc(numkeys*2 + 1); - for (i=0; i playerdata,uint256 gametxid,CPubKey pk) +int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) { static uint32_t good,bad; static uint256 prevgame; - char str[512],*keystrokes,tetrisaddr[64],str2[67],fname[64]; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed,mult = 10; CPubKey tetrispk; struct tetris_player P; + char str[512],*keystrokes,gamesaddr[64],str2[67],fname[64]; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed; CPubKey gamespk; struct games_player P; *cashoutp = 0; - tetrispk = GetUnspendable(cp,0); - GetCCaddress1of2(cp,tetrisaddr,tetrispk,pk); - //fprintf(stderr,"call extractgame\n"); - if ( (keystrokes= tetris_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,tetrisaddr)) != 0 ) + gamespk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,gamesaddr,gamespk,pk); + if ( (keystrokes= games_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,gamesaddr)) != 0 ) { - //fprintf(stderr,"numkeys.%d tetris_extractgame %s\n",numkeys,gametxid.GetHex().c_str()); free(keystrokes); - sprintf(fname,"tetris.%llu.pack",(long long)seed); + sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); remove(fname); - - //fprintf(stderr,"extracted.(%s)\n",str); - for (i=0; i>16,P.level,P.experience,P.dungeonlevel); - fprintf(stderr,"newdata[%d] != playerdata[%d], numkeys.%d %s pub.%s playertxid.%s good.%d bad.%d\n",(int32_t)newdata.size(),(int32_t)playerdata.size(),numkeys,tetrisaddr,pubkey33_str(str2,(uint8_t *)&pk),playertxid.GetHex().c_str(),good,bad); + fprintf(stderr,"newdata[%d] != playerdata[%d], numkeys.%d %s pub.%s playertxid.%s good.%d bad.%d\n",(int32_t)newdata.size(),(int32_t)playerdata.size(),numkeys,gamesaddr,pubkey33_str(str2,(uint8_t *)&pk),playertxid.GetHex().c_str(),good,bad); } } - sprintf(fname,"tetris.%llu.pack",(long long)seed); + sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); remove(fname); - //fprintf(stderr,"no keys tetris_extractgame %s\n",gametxid.GetHex().c_str()); + //fprintf(stderr,"no keys games_extractgame %s\n",gametxid.GetHex().c_str()); return(-1); } -UniValue tetris_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params,char *method) +int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) // replay in daemon { - //vin0 -> highlander vout from creategame TCBOO - //vin1 -> keystrokes baton of completed game, must be last to quit or first to win, only spent registration batons matter. If more than 60 blocks since last keystrokes, it is forfeit - //vins2+ -> rest of unspent registration utxo so all newgame vouts are spent - //vout0 -> nonfungible character with pack @ - //vout1 -> 1% ingame gold and all the buyins - - // detect if last to bailout - // vin0 -> kestrokes baton of completed game with Q - // vout0 -> playerdata marker - // vout0 -> 1% ingame gold - // get any playerdata, get all keystrokes, replay game and compare final state - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx,symbol,pname; CTransaction gametx; uint64_t seed,mult; int64_t buyin,batonvalue,inputsum,cashout,CCchange=0; int32_t i,err,gameheight,tmp,numplayers,regslot,n,num,dungeonlevel,numkeys,maxplayers,batonht,batonvout; char mytetrisaddr[64],*keystrokes = 0; std::vector playerdata,newdata,nodata; uint256 batontxid,playertxid,gametxid; CPubKey mypk,tetrispk; uint8_t player[10000],mypriv[32],funcid; - struct CCcontract_info *cpTokens, tokensC; - - if ( txfee == 0 ) - txfee = 10000; - mypk = pubkey2pk(Mypubkey()); - tetrispk = GetUnspendable(cp,0); - GetCCaddress1of2(cp,mytetrisaddr,tetrispk,mypk); - result.push_back(Pair("name","tetris")); - result.push_back(Pair("method",method)); - result.push_back(Pair("mytetrisaddr",mytetrisaddr)); - if ( strcmp(method,"bailout") == 0 ) - { - funcid = 'Q'; - mult = 10; //100000; - } - else - { - funcid = 'H'; - mult = 20; //200000; - } - if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) - { - if ( n > 0 ) - { - gametxid = juint256(jitem(params,0)); - result.push_back(Pair("gametxid",gametxid.GetHex())); - if ( (err= tetris_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,1)) == 0 ) - { - if ( tetris_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,mytetrisaddr,numplayers,symbol,pname) == 0 ) - { - UniValue obj; struct tetris_player P; - seed = tetris_gamefields(obj,maxplayers,buyin,gametxid,mytetrisaddr); - fprintf(stderr,"(%s) found baton %s numkeys.%d seed.%llu playerdata.%d\n",pname.size()!=0?pname.c_str():Tetris_pname.c_str(),batontxid.ToString().c_str(),numkeys,(long long)seed,(int32_t)playerdata.size()); - memset(&P,0,sizeof(P)); - if ( playerdata.size() > 0 ) - { - for (i=0; i 0 ) - { - newdata.resize(num); - for (i=0; i no playerdata\n"); - newdata.resize(0); - //P.gold = (P.gold * 8) / 10; - } - else - { - cpTokens = CCinit(&tokensC, EVAL_TOKENS); - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(cpTokens,NULL))); // marker to token cc addr, burnable and validated - mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,1,mypk)); - if ( P.amulet != 0 ) - mult *= 5; - dungeonlevel = P.dungeonlevel; - if ( P.amulet != 0 && dungeonlevel < 21 ) - dungeonlevel = 21; - cashout = (uint64_t)P.gold * P.gold * mult * dungeonlevel; - fprintf(stderr,"\nextracted $$$gold.%d -> %.8f TETRIS hp.%d strength.%d/%d level.%d exp.%d dl.%d n.%d amulet.%d\n",P.gold,(double)cashout/COIN,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel,n,P.amulet); - if ( funcid == 'H' && maxplayers > 1 ) - { - if ( P.amulet == 0 ) - { - if ( numplayers != maxplayers ) - return(cclib_error(result,"numplayers != maxplayers")); - else if ( tetris_playersalive(tmp,tmp,gametxid,maxplayers,gameheight,gametx) > 1 ) - return(cclib_error(result,"highlander must be a winner or last one standing")); - } - cashout += numplayers * buyin; - } - if ( cashout >= txfee ) - { - if ( (inputsum= AddCClibInputs(cp,mtx,tetrispk,cashout,16,cp->unspendableCCaddr)) > (uint64_t)P.gold*mult ) - CCchange = (inputsum - cashout); - mtx.vout.push_back(CTxOut(cashout,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - } - } - } - mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange + (batonvalue-3*txfee),tetrispk)); - Myprivkey(mypriv); - CCaddr1of2set(cp,tetrispk,mypk,mypriv,mytetrisaddr); - CScript opret; - if ( pname.size() == 0 ) - pname = Tetris_pname; - if ( newdata.size() == 0 ) - { - opret = tetris_highlanderopret(funcid, gametxid, regslot, mypk, nodata,pname); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,opret); - //fprintf(stderr,"nodata finalizetx.(%s)\n",rawtx.c_str()); - } - else - { - opret = tetris_highlanderopret(funcid, gametxid, regslot, mypk, newdata,pname); - char seedstr[32]; - sprintf(seedstr,"%llu",(long long)seed); - std::vector vopretNonfungible; - GetOpReturnData(opret, vopretNonfungible); - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeTokenCreateOpRet('c', Mypubkey(), std::string(seedstr), gametxid.GetHex(), vopretNonfungible)); - } - return(tetris_rawtxresult(result,rawtx,1)); - } - result.push_back(Pair("result","success")); - } else fprintf(stderr,"illegal game err.%d\n",err); - } else fprintf(stderr,"parameters only n.%d\n",n); - } - return(result); + return(-1); } -UniValue tetris_bailout(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +void games_packitemstr(char *packitemstr,struct games_packitem *item) { - return(tetris_finishgame(txfee,cp,params,"bailout")); + sprintf(packitemstr,"not yet"); } -UniValue tetris_highlander(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { - return(tetris_finishgame(txfee,cp,params,"highlander")); -} - -UniValue tetris_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,gameheight,maxplayers,numvouts; uint256 txid; CTransaction tx; int64_t buyin; uint64_t seed; bits256 t; char mytetrisaddr[64],str[64]; CPubKey mypk,tetrispk; - result.push_back(Pair("name","tetris")); - result.push_back(Pair("method","gameinfo")); - if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) - { - if ( n > 0 ) - { - txid = juint256(jitem(params,0)); - result.push_back(Pair("gametxid",txid.GetHex())); - if ( tetris_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid,0) == 0 ) - { - result.push_back(Pair("result","success")); - result.push_back(Pair("gameheight",(int64_t)gameheight)); - mypk = pubkey2pk(Mypubkey()); - tetrispk = GetUnspendable(cp,0); - GetCCaddress1of2(cp,mytetrisaddr,tetrispk,mypk); - //fprintf(stderr,"mytetrisaddr.%s\n",mytetrisaddr); - seed = tetris_gamefields(result,maxplayers,buyin,txid,mytetrisaddr); - result.push_back(Pair("seed",(int64_t)seed)); - for (i=0; i > unspentOutputs; - tetrispk = GetUnspendable(cp,0); - GetCCaddress(cp,coinaddr,tetrispk); - SetCCunspents(unspentOutputs,coinaddr); - nextheight = komodo_nextheight(); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - //char str[65]; fprintf(stderr,"%s check %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); - if ( it->second.satoshis != txfee || vout != 0 ) // reject any that are not highlander markers - continue; - if ( tetris_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid,1) == 0 && nextheight <= gameheight+TETRIS_MAXKEYSTROKESGAP ) - { - tetris_playersalive(openslots,numplayers,txid,maxplayers,gameheight,tx); - if ( openslots > 0 ) - a.push_back(txid.GetHex()); - } - } - result.push_back(Pair("result","success")); - tetris_univalue(result,"pending",-1,-1); - result.push_back(Pair("pending",a)); - result.push_back(Pair("numpending",(int64_t)a.size())); - return(result); -} - -UniValue tetris_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ),a(UniValue::VARR); int64_t buyin; uint256 tokenid,gametxid,txid,hashBlock; CTransaction playertx,tx; int32_t maxplayers,vout,numvouts; std::vector playerdata; CPubKey tetrispk,mypk,pk; std::string symbol,pname; char coinaddr[64]; - std::vector > unspentOutputs; - tetrispk = GetUnspendable(cp,0); - mypk = pubkey2pk(Mypubkey()); - GetTokensCCaddress(cp,coinaddr,mypk); - SetCCunspents(unspentOutputs,coinaddr); - tetris_univalue(result,"players",-1,-1); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - //char str[65]; fprintf(stderr,"%s check %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); - if ( it->second.satoshis != 1 || vout > 1 ) - continue; - if ( tetris_playerdata(cp,gametxid,tokenid,pk,playerdata,symbol,pname,txid) == 0 )//&& pk == mypk ) - { - a.push_back(txid.GetHex()); - //a.push_back(Pair("playerdata",tetris_playerobj(playerdata))); - } - } - result.push_back(Pair("playerdata",a)); - result.push_back(Pair("numplayerdata",(int64_t)a.size())); - return(result); -} - -UniValue tetris_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); uint256 txid,hashBlock,gametxid,tokenid,playertxid; int32_t vout,maxplayers,gameheight,numvouts; CPubKey tetrispk,mypk; char coinaddr[64]; CTransaction tx,gametx; int64_t buyin; - std::vector > addressIndex; - //std::vector > unspentOutputs; - tetrispk = GetUnspendable(cp,0); - mypk = pubkey2pk(Mypubkey()); - GetCCaddress1of2(cp,coinaddr,tetrispk,mypk); - //SetCCunspents(unspentOutputs,coinaddr); - SetCCtxids(addressIndex,coinaddr); - tetris_univalue(result,"games",-1,-1); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) - //for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - //char str[65]; fprintf(stderr,"%s check %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); - if ( vout == 0 ) - { - if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) - { - if ( tetris_registeropretdecode(gametxid,tokenid,playertxid,tx.vout[numvouts-1].scriptPubKey) == 'R' ) - { - if ( tetris_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0) == 0 ) - { - if ( CCgettxout(txid,vout,1,0) < 0 ) - b.push_back(gametxid.GetHex()); - else a.push_back(gametxid.GetHex()); - } - } - } - } - } - result.push_back(Pair("pastgames",b)); - result.push_back(Pair("games",a)); - result.push_back(Pair("numgames",(int64_t)(a.size()+b.size()))); - return(result); -} - -UniValue tetris_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); int32_t n; char *namestr = 0; - tetris_univalue(result,"setname",-1,-1); - if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) - { - if ( n > 0 ) - { - if ( (namestr= jstri(params,0)) != 0 ) - { - result.push_back(Pair("result","success")); - result.push_back(Pair("pname",namestr)); - tetris_pname = namestr; - return(result); - } - } - } - result.push_back(Pair("result","error")); - result.push_back(Pair("error","couldnt get name")); - return(result); -} - -bool tetris_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) -{ - CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid,tokentx=0; int32_t i,maxplayers,enabled = 0,decoded=0,regslot,ind,err,dispflag,gameheight,score,numvouts; CTransaction vintx,gametx; CPubKey pk; uint256 hashBlock,gametxid,txid,tokenid,batontxid,playertxid,ptxid; int64_t buyin,cashout; std::vector playerdata,keystrokes; std::string symbol,pname; - if ( strcmp(ASSETCHAINS_SYMBOL,"ROGUE") == 0 ) - { - if (height < 21274 ) - return(true); - else if ( height > 50000 ) - enabled = 1; - } else enabled = 1; - if ( (numvouts= tx.vout.size()) > 1 ) - { - txid = tx.GetHash(); - scriptPubKey = tx.vout[numvouts-1].scriptPubKey; - GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 ) - { - script = (uint8_t *)vopret.data(); - funcid = script[1]; - if ( (e= script[0]) == EVAL_TOKENS ) - { - tokentx = funcid; - if ( (funcid= tetris_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,scriptPubKey)) == 0 ) - { - if ( (funcid= tetris_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) == 0 ) - { - fprintf(stderr,"ht.%d couldnt decode tokens opret (%c)\n",height,script[1]); - } else e = EVAL_TETRIS, decoded = 1; - } else e = EVAL_TETRIS, decoded = 1; - } - if ( e == EVAL_TETRIS ) - { - //fprintf(stderr,"ht.%d tetris.(%c)\n",height,script[1]); - if ( decoded == 0 ) - { - switch ( funcid ) - { - case 'G': // seems just need to make sure no vout abuse is left to do - gametx = tx; - gametxid = tx.GetHash(); - gameheight = height; - if ( (err= tetris_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,zeroid,0)) != 0 ) - { - fprintf(stderr,"height.%d %s tetris_isvalidgame error.%d\n",height,gametxid.GetHex().c_str(),err); - return eval->Invalid("invalid gametxid"); - } - //fprintf(stderr,"height.%d %s tetris_isvalidgame\n",height,gametxid.GetHex().c_str()); - return(true); - break; - case 'R': - if ( (funcid= tetris_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) != 'R' ) - { - return eval->Invalid("couldnt decode register opret"); - } - // baton is created - // validation is done below - break; - case 'K': - if ( (funcid= tetris_keystrokesopretdecode(gametxid,batontxid,pk,keystrokes,scriptPubKey)) != 'K' ) - { - return eval->Invalid("couldnt decode keystrokes opret"); - } - // spending the baton proves it is the user if the pk is the signer - return(true); - break; - case 'H': case 'Q': - // done in the next switch statement as there are some H/Q tx with playerdata which would skip this section - break; - default: - return eval->Invalid("illegal tetris non-decoded funcid"); - break; - } - } - switch ( funcid ) - { - case 'R': // register - // verify vout amounts are as they should be and no vins that shouldnt be - return(true); - case 'H': // win - case 'Q': // bailout - if ( (f= tetris_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,scriptPubKey)) != funcid ) - { - //fprintf(stderr,"height.%d couldnt decode H/Q opret\n",height); - //if ( height > 20000 ) - return eval->Invalid("couldnt decode H/Q opret"); - } - // verify pk belongs to this tx - if ( tokentx == 'c' && playerdata.size() > 0 ) - { - static char laststr[512]; char cashstr[512]; - if ( tetris_playerdata_validate(&cashout,ptxid,cp,playerdata,gametxid,pk) < 0 ) - { - sprintf(cashstr,"tokentx.(%c) decoded.%d ht.%d gametxid.%s player.%s invalid playerdata[%d]\n",tokentx,decoded,height,gametxid.GetHex().c_str(),ptxid.GetHex().c_str(),(int32_t)playerdata.size()); - if ( strcmp(laststr,cashstr) != 0 ) - { - strcpy(laststr,cashstr); - fprintf(stderr,"%s\n",cashstr); - } - if ( enabled != 0 ) - return eval->Invalid("mismatched playerdata"); - } - if ( funcid == 'H' ) - cashout *= 2; - sprintf(cashstr,"tokentx.(%c) decoded.%d ht.%d txid.%s %.8f vs vout2 %.8f",tokentx,decoded,height,txid.GetHex().c_str(),(double)cashout/COIN,(double)tx.vout[2].nValue/COIN); - if ( strcmp(laststr,cashstr) != 0 ) - { - strcpy(laststr,cashstr); - fprintf(stderr,"%s\n",cashstr); - } - if ( enabled != 0 && tx.vout[2].nValue != cashout ) - return eval->Invalid("mismatched cashout amount"); - } - if ( funcid == 'Q' ) - { - // verify vin/vout - } - else // 'H' - { - // verify vin/vout and proper payouts - } - return(true); - break; - default: - return eval->Invalid("illegal tetris funcid"); - break; - } - } else return eval->Invalid("illegal evalcode"); - } else return eval->Invalid("opret too small"); - } else return eval->Invalid("not enough vouts"); return(true); } -#endif diff --git a/src/cc/tetris.h b/src/cc/tetris.h new file mode 100644 index 000000000..f032bf2da --- /dev/null +++ b/src/cc/tetris.h @@ -0,0 +1,197 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef H_TETRIS_H +#define H_TETRIS_H + +#define GAMENAME "tetris" +#define GAMEMAIN tetris +#define CHAINNAME "GTEST" + +#define MAXPACK 23 +struct games_packitem +{ + int32_t type,launch,count,which,hplus,dplus,arm,flags,group; + char damage[8],hurldmg[8]; +}; + +struct games_player +{ + int32_t gold,hitpoints,strength,level,experience,packsize,dungeonlevel,amulet; + struct games_packitem gamespack[MAXPACK]; +}; + +struct games_state +{ + uint64_t seed; + char *keystrokes,*keystrokeshex; + uint32_t needflush,replaydone; + int32_t numkeys,ind,num,guiflag,counter,sleeptime,playersize,restoring,lastnum; + FILE *logfp; + struct games_player P; + char buffered[10000]; + uint8_t playerdata[10000]; +}; + + +/***************************************************************************/ +/** https://github.com/brenns10/tetris + @file main.c + @author Stephen Brennan + @date Created Wednesday, 10 June 2015 + @brief Main program for tetris. + @copyright Copyright (c) 2015, Stephen Brennan. Released under the Revised + BSD License. See LICENSE.txt for details. + *******************************************************************************/ + +/* + Convert a tetromino type to its corresponding cell. + */ +#define TYPE_TO_CELL(x) ((x)+1) + +/* + Strings for how you would print a tetris board. + */ +#define TC_EMPTY_STR " " +#define TC_BLOCK_STR "\u2588" + +/* + Questions about a tetris cell. + */ +#define TC_IS_EMPTY(x) ((x) == TC_EMPTY) +#define TC_IS_FILLED(x) (!TC_IS_EMPTY(x)) + +/* + How many cells in a tetromino? + */ +#define TETRIS 4 +/* + How many tetrominos? + */ +#define NUM_TETROMINOS 7 +/* + How many orientations of a tetromino? + */ +#define NUM_ORIENTATIONS 4 + +/* + Level constants. + */ +#define MAX_LEVEL 19 +#define LINES_PER_LEVEL 10 + +/* + A "cell" is a 1x1 block within a tetris board. + */ +typedef enum { + TC_EMPTY, TC_CELLI, TC_CELLJ, TC_CELLL, TC_CELLO, TC_CELLS, TC_CELLT, TC_CELLZ +} tetris_cell; + +/* + A "type" is a type/shape of a tetromino. Not including orientation. + */ +typedef enum { + TET_I, TET_J, TET_L, TET_O, TET_S, TET_T, TET_Z +} tetris_type; + +/* + A row,column pair. Negative numbers allowed, because we need them for + offsets. + */ +typedef struct { + int row; + int col; +} tetris_location; + +/* + A "block" is a struct that contains information about a tetromino. + Specifically, what type it is, what orientation it has, and where it is. + */ +typedef struct { + int typ; + int ori; + tetris_location loc; +} tetris_block; + +/* + All possible moves to give as input to the game. + */ +typedef enum { + TM_LEFT, TM_RIGHT, TM_CLOCK, TM_COUNTER, TM_DROP, TM_HOLD, TM_NONE +} tetris_move; + +/* + A game object! + */ +typedef struct { + /* + Game board stuff: + */ + int rows; + int cols; + char *board; + /* + Scoring information: + */ + int points; + int level; + /* + Falling block is the one currently going down. Next block is the one that + will be falling after this one. Stored is the block that you can swap out. + */ + tetris_block falling; + tetris_block next; + tetris_block stored; + /* + Number of game ticks until the block will move down. + */ + int ticks_till_gravity; + /* + Number of lines until you advance to the next level. + */ + int lines_remaining; +} tetris_game; + +/* + This array stores all necessary information about the cells that are filled by + each tetromino. The first index is the type of the tetromino (i.e. shape, + e.g. I, J, Z, etc.). The next index is the orientation (0-3). The final + array contains 4 tetris_location objects, each mapping to an offset from a + point on the upper left that is the tetromino "origin". + */ +extern tetris_location TETROMINOS[NUM_TETROMINOS][NUM_ORIENTATIONS][TETRIS]; + +/* + This array tells you how many ticks per gravity by level. Decreases as level + increases, to add difficulty. + */ +extern int GRAVITY_LEVEL[MAX_LEVEL+1]; + +// Data structure manipulation. +void tg_init(tetris_game *obj, int rows, int cols); +tetris_game *tg_create(int rows, int cols); +void tg_destroy(tetris_game *obj); +void tg_delete(tetris_game *obj); +tetris_game *tg_load(FILE *f); +void tg_save(tetris_game *obj, FILE *f); + +// Public methods not related to memory: +char tg_get(tetris_game *obj, int row, int col); +bool tg_check(tetris_game *obj, int row, int col); +bool tg_tick(tetris_game *obj, tetris_move move); +void tg_print(tetris_game *obj, FILE *f); + +#endif + From c5b7efd7f8c25acf310619f15d9b203f7bde8a50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:26:24 -1100 Subject: [PATCH 011/111] Optimize --- src/cc/gamescc.cpp | 114 ++++----------------------------------------- src/cc/tetris.c | 11 ++++- src/cc/tetris.cpp | 85 +++++++++++++++++++++++++++++++++ src/cc/tetris.h | 88 +++++++++++++++++----------------- 4 files changed, 148 insertions(+), 150 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 11ceb3345..869205acc 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -14,15 +14,18 @@ ******************************************************************************/ #include "gamescc.h" - -#include "tetris.h" - -static int random_tetromino(void) -{ - return rand() % NUM_TETROMINOS; -} +#include "tetris.c" // replace with game code #ifndef STANDALONE +int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload); +int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector 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 &newdata,uint64_t &seed,uint256 &playertxid,struct CCcontract_info *cp,uint256 gametxid,char *gamesaddr); + +#include "tetris.cpp" // replace with game specific functions + /* ./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 payload); -int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector 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 &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 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 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 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 diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 4ffd27575..94ceda83b 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -1,7 +1,10 @@ #include "tetris.h" -#include "dapps/dappstd.c" +static int random_tetromino(void) +{ + return rand() % NUM_TETROMINOS; +} /***************************************************************************/ /** https://github.com/brenns10/tetris @@ -622,10 +625,12 @@ void init_colors(void) init_pair(TC_CELLZ, COLOR_RED, COLOR_BLACK); } +#else /* Main tetris game! */ -#ifdef STANDALONE +#include "dapps/dappstd.c" + char *clonestr(char *str) { char *clone; int32_t len; @@ -756,3 +761,5 @@ int32_t games_replay(uint64_t seed,int32_t sleeptime) { return(-1); } +#endif + diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index fd833d7b7..4d0be1e96 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -128,6 +128,91 @@ int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C return(-1); } +char *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vector &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 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 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); +} + int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) // replay in daemon { return(-1); diff --git a/src/cc/tetris.h b/src/cc/tetris.h index f032bf2da..b239a1644 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -1,51 +1,7 @@ -/****************************************************************************** - * Copyright © 2014-2019 The SuperNET Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * SuperNET software, including this file may be copied, modified, propagated * - * or distributed except according to the terms contained in the LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ #ifndef H_TETRIS_H #define H_TETRIS_H -#define GAMENAME "tetris" -#define GAMEMAIN tetris -#define CHAINNAME "GTEST" - -#define MAXPACK 23 -struct games_packitem -{ - int32_t type,launch,count,which,hplus,dplus,arm,flags,group; - char damage[8],hurldmg[8]; -}; - -struct games_player -{ - int32_t gold,hitpoints,strength,level,experience,packsize,dungeonlevel,amulet; - struct games_packitem gamespack[MAXPACK]; -}; - -struct games_state -{ - uint64_t seed; - char *keystrokes,*keystrokeshex; - uint32_t needflush,replaydone; - int32_t numkeys,ind,num,guiflag,counter,sleeptime,playersize,restoring,lastnum; - FILE *logfp; - struct games_player P; - char buffered[10000]; - uint8_t playerdata[10000]; -}; - - /***************************************************************************/ /** https://github.com/brenns10/tetris @file main.c @@ -193,5 +149,49 @@ bool tg_check(tetris_game *obj, int row, int col); bool tg_tick(tetris_game *obj, tetris_move move); void tg_print(tetris_game *obj, FILE *f); +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ +#define GAMENAME "tetris" +#define GAMEMAIN tetris +#define CHAINNAME "GTEST" + +#define MAXPACK 23 +struct games_packitem +{ + int32_t type,launch,count,which,hplus,dplus,arm,flags,group; + char damage[8],hurldmg[8]; +}; + +struct games_player +{ + int32_t gold,hitpoints,strength,level,experience,packsize,dungeonlevel,amulet; + struct games_packitem gamespack[MAXPACK]; +}; + +struct games_state +{ + uint64_t seed; + char *keystrokes,*keystrokeshex; + uint32_t needflush,replaydone; + int32_t numkeys,ind,num,guiflag,counter,sleeptime,playersize,restoring,lastnum; + FILE *logfp; + struct games_player P; + char buffered[10000]; + uint8_t playerdata[10000]; +}; + + #endif From f9c20dab7876d7f08ccd0411fcbcf7311dee27f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:27:25 -1100 Subject: [PATCH 012/111] Def standalone --- src/cc/tetris.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 94ceda83b..7c6ff768e 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -625,7 +625,7 @@ void init_colors(void) init_pair(TC_CELLZ, COLOR_RED, COLOR_BLACK); } -#else +#ifdef STANDALONE /* Main tetris game! */ From a3d531714ec633ee3f685e493c12958500aee6ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:28:28 -1100 Subject: [PATCH 013/111] Extern const --- src/cc/tetris.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/tetris.h b/src/cc/tetris.h index b239a1644..e2639cba1 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -127,13 +127,13 @@ typedef struct { array contains 4 tetris_location objects, each mapping to an offset from a point on the upper left that is the tetromino "origin". */ -extern tetris_location TETROMINOS[NUM_TETROMINOS][NUM_ORIENTATIONS][TETRIS]; +extern const tetris_location TETROMINOS[NUM_TETROMINOS][NUM_ORIENTATIONS][TETRIS]; /* This array tells you how many ticks per gravity by level. Decreases as level increases, to add difficulty. */ -extern int GRAVITY_LEVEL[MAX_LEVEL+1]; +extern const int GRAVITY_LEVEL[MAX_LEVEL+1]; // Data structure manipulation. void tg_init(tetris_game *obj, int rows, int cols); From 8c71d44ba66aabfde1cdad6055d94185d3ae14dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:31:43 -1100 Subject: [PATCH 014/111] Reorder --- src/cc/gamescc.cpp | 26 -------------------------- src/cc/tetris.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 869205acc..f62a8699c 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -17,12 +17,6 @@ #include "tetris.c" // replace with game code #ifndef STANDALONE -int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload); -int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector 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 &newdata,uint64_t &seed,uint256 &playertxid,struct CCcontract_info *cp,uint256 gametxid,char *gamesaddr); #include "tetris.cpp" // replace with game specific functions @@ -551,26 +545,6 @@ int32_t games_playersalive(int32_t &openslots,int32_t &numplayers,uint256 gametx return(alive); } -void disp_gamesplayerdata(std::vector playerdata) -{ - struct games_player P; int32_t i; char packitemstr[512]; - if ( playerdata.size() > 0 ) - { - for (i=0; i>16,P.level,P.experience,P.dungeonlevel); - for (i=0; i playerdata,uint256 playertxid,uint256 tokenid,std::string symbol,std::string pname,uint256 gametxid) { int32_t i,vout,spentvini,numvouts,n=0; uint256 txid,spenttxid,hashBlock; struct games_player P; char packitemstr[512],*datastr=0; UniValue obj(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx; diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index 4d0be1e96..cb9c47cc8 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -14,6 +14,10 @@ * * ******************************************************************************/ +int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **keystrokesp,int32_t &numkeys,int32_t ®slot,std::vector &playerdata,uint256 &batontxid,int32_t &batonvout,int64_t &batonvalue,int32_t &batonht,uint256 gametxid,CTransaction gametx,int32_t maxplayers,char *destaddr,int32_t &numplayers,std::string &symbol,std::string &pname); +int32_t games_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransaction &tx,int64_t &buyin,int32_t &maxplayers,uint256 txid,int32_t unspentv0); +uint64_t games_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 gametxid,char *mygamesaddr); + // game specific code for daemon int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload) @@ -47,6 +51,26 @@ int64_t games_cashout(struct games_player *P) return(cashout); } +void disp_gamesplayerdata(std::vector playerdata) +{ + struct games_player P; int32_t i; char packitemstr[512]; + if ( playerdata.size() > 0 ) + { + for (i=0; i>16,P.level,P.experience,P.dungeonlevel); + for (i=0; i playerdata,uint256 gametxid,CPubKey pk) { static uint32_t good,bad; static uint256 prevgame; From 43bdea08406e8d7e0b759c555c2d77085464583e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:33:49 -1100 Subject: [PATCH 015/111] Reorder --- src/cc/tetris.cpp | 174 +++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index cb9c47cc8..f9e4e167a 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -20,6 +20,16 @@ uint64_t games_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 // game specific code for daemon +void games_packitemstr(char *packitemstr,struct games_packitem *item) +{ + sprintf(packitemstr,"not yet"); +} + +int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) // replay in daemon +{ + return(-1); +} + int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload) { uint256 gametxid; int32_t i,len; char str[67]; uint32_t eventid = 0; @@ -71,87 +81,6 @@ void disp_gamesplayerdata(std::vector playerdata) } } -int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) -{ - static uint32_t good,bad; static uint256 prevgame; - char str[512],*keystrokes,gamesaddr[64],str2[67],fname[64]; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed; CPubKey gamespk; struct games_player P; - *cashoutp = 0; - gamespk = GetUnspendable(cp,0); - GetCCaddress1of2(cp,gamesaddr,gamespk,pk); - if ( (keystrokes= games_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,gamesaddr)) != 0 ) - { - free(keystrokes); - sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); - remove(fname); - - for (i=0; i no playerdata, good.%d bad.%d\n",good,bad); - } - *cashoutp = 0; - return(0); - } - } - if ( gametxid != prevgame ) - { - prevgame = gametxid; - bad++; - disp_gamesplayerdata(newdata); - disp_gamesplayerdata(playerdata); - fprintf(stderr,"%s playerdata: gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d\n",gametxid.GetHex().c_str(),P.gold,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel); - fprintf(stderr,"newdata[%d] != playerdata[%d], numkeys.%d %s pub.%s playertxid.%s good.%d bad.%d\n",(int32_t)newdata.size(),(int32_t)playerdata.size(),numkeys,gamesaddr,pubkey33_str(str2,(uint8_t *)&pk),playertxid.GetHex().c_str(),good,bad); - } - } - sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); - remove(fname); - //fprintf(stderr,"no keys games_extractgame %s\n",gametxid.GetHex().c_str()); - return(-1); -} - char *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vector &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 playerdata; uint256 batontxid; FILE *fp; uint8_t newplayer[10000]; struct games_player P,endP; @@ -237,16 +166,87 @@ char *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vecto return(0); } -int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) // replay in daemon +int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) { + static uint32_t good,bad; static uint256 prevgame; + char str[512],*keystrokes,gamesaddr[64],str2[67],fname[64]; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed; CPubKey gamespk; struct games_player P; + *cashoutp = 0; + gamespk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,gamesaddr,gamespk,pk); + if ( (keystrokes= games_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,gamesaddr)) != 0 ) + { + free(keystrokes); + sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); + remove(fname); + + for (i=0; i no playerdata, good.%d bad.%d\n",good,bad); + } + *cashoutp = 0; + return(0); + } + } + if ( gametxid != prevgame ) + { + prevgame = gametxid; + bad++; + disp_gamesplayerdata(newdata); + disp_gamesplayerdata(playerdata); + fprintf(stderr,"%s playerdata: gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d\n",gametxid.GetHex().c_str(),P.gold,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel); + fprintf(stderr,"newdata[%d] != playerdata[%d], numkeys.%d %s pub.%s playertxid.%s good.%d bad.%d\n",(int32_t)newdata.size(),(int32_t)playerdata.size(),numkeys,gamesaddr,pubkey33_str(str2,(uint8_t *)&pk),playertxid.GetHex().c_str(),good,bad); + } + } + sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); + remove(fname); + //fprintf(stderr,"no keys games_extractgame %s\n",gametxid.GetHex().c_str()); return(-1); } -void games_packitemstr(char *packitemstr,struct games_packitem *item) -{ - sprintf(packitemstr,"not yet"); -} - bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { return(true); From c166507c62a7afb2b21d69243a968a28fe51907d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:36:06 -1100 Subject: [PATCH 016/111] rand() --- src/cc/tetris.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 7c6ff768e..d3e9911a1 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -1,6 +1,12 @@ #include "tetris.h" +/* + In order to port a game into gamesCC, the RNG needs to be seeded with the gametxid seed, also events needs to be broadcast using issue_games_events + */ + +int rand(); + static int random_tetromino(void) { return rand() % NUM_TETROMINOS; From d5e26e7bc590a061aabe1ae336bd66e7fae20ab4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:44:10 -1100 Subject: [PATCH 017/111] Declare rs --- src/cc/tetris.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index d3e9911a1..874a6437d 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -2,7 +2,7 @@ #include "tetris.h" /* - In order to port a game into gamesCC, the RNG needs to be seeded with the gametxid seed, also events needs to be broadcast using issue_games_events + In order to port a game into gamesCC, the RNG needs to be seeded with the gametxid seed, also events needs to be broadcast using issue_games_events. Also the game engine needs to be daemonized, preferably by putting all globals into a single data structure. */ int rand(); @@ -654,14 +654,40 @@ char *clonestr(char *str) return(clone); } +struct games_state globalR; + int tetris(int argc, char **argv) { tetris_game *tg; tetris_move move = TM_NONE; bool running = true; WINDOW *board, *next, *hold, *score; + struct games_state *rs = &globalR; int32_t c,skipcount=0; bits256 gametxid; uint32_t eventid = 0; memset(&gametxid,0,sizeof(gametxid)); + memset(rs,0,sizeof(*rs)); + rs->guiflag = 1; + rs->sleeptime = 1; // non-zero to allow refresh() + if ( argc == 3 && strlen(argv[2]) == 64 ) + { +#ifdef _WIN32 +#ifdef _MSC_VER + rs->seed = _strtoui64(argv[1], NULL, 10); +#else + rs->seed = atol(argv[1]); // windows, but not MSVC +#endif // _MSC_VER +#else + rs->seed = atol(argv[1]); // non-windows +#endif // _WIN32 + strcpy(Gametxidstr,argv[2]); + fprintf(stderr,"setplayerdata\n"); + if ( games_setplayerdata(rs,Gametxidstr) < 0 ) + { + fprintf(stderr,"invalid gametxid, or already started\n"); + return(-1); + } + } else rs->seed = 777; + // Load file if given a filename. if (argc >= 2) { FILE *f = fopen(argv[1], "r"); From 226179dcd386417dded5910f9c28154d5f905868 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:45:17 -1100 Subject: [PATCH 018/111] Skip rand() --- src/cc/tetris.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 874a6437d..adcf098f5 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -5,11 +5,10 @@ In order to port a game into gamesCC, the RNG needs to be seeded with the gametxid seed, also events needs to be broadcast using issue_games_events. Also the game engine needs to be daemonized, preferably by putting all globals into a single data structure. */ -int rand(); - static int random_tetromino(void) { - return rand() % NUM_TETROMINOS; + return(0); + //return rand() % NUM_TETROMINOS; } /***************************************************************************/ From b4dd00266d9c2496f0e039a3e2d708e61bb3d540 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 00:55:53 -1100 Subject: [PATCH 019/111] Active rngnext --- src/cc/tetris.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index adcf098f5..db88c0659 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -3,12 +3,14 @@ /* In order to port a game into gamesCC, the RNG needs to be seeded with the gametxid seed, also events needs to be broadcast using issue_games_events. Also the game engine needs to be daemonized, preferably by putting all globals into a single data structure. + + also, the standalone game needs to support argv of seed gametxid, along with replay args */ -static int random_tetromino(void) +static int random_tetromino(struct games_state *rs) { - return(0); - //return rand() % NUM_TETROMINOS; + rs->seed = _games_rngnext(rs->seed); + return(rs->seed % NUM_TETROMINOS); } /***************************************************************************/ @@ -173,11 +175,11 @@ static bool tg_fits(tetris_game *obj, tetris_block block) Create a new falling block and populate the next falling block with a random one. */ -static void tg_new_falling(tetris_game *obj) +static void tg_new_falling(struct games_state *rs,tetris_game *obj) { // Put in a new falling tetromino. obj->falling = obj->next; - obj->next.typ = random_tetromino(); + obj->next.typ = random_tetromino(rs); obj->next.ori = 0; obj->next.loc.row = 0; obj->next.loc.col = obj->cols/2 - 2; @@ -190,7 +192,7 @@ static void tg_new_falling(tetris_game *obj) /* Tick gravity, and move the block down if gravity should act. */ -static void tg_do_gravity_tick(tetris_game *obj) +static void tg_do_gravity_tick(struct games_state *rs,tetris_game *obj) { obj->ticks_till_gravity--; if (obj->ticks_till_gravity <= 0) { @@ -202,7 +204,7 @@ static void tg_do_gravity_tick(tetris_game *obj) obj->falling.loc.row--; tg_put(obj, obj->falling); - tg_new_falling(obj); + tg_new_falling(rs,obj); } tg_put(obj, obj->falling); } @@ -411,11 +413,11 @@ static bool tg_game_over(tetris_game *obj) Do a single game tick: process gravity, user input, and score. Return true if the game is still running, false if it is over. */ -bool tg_tick(tetris_game *obj, tetris_move move) +bool tg_tick(struct games_state *rs,tetris_game *obj, tetris_move move) { int lines_cleared; // Handle gravity. - tg_do_gravity_tick(obj); + tg_do_gravity_tick(rs,obj); // Handle input. tg_handle_move(obj, move); @@ -687,7 +689,7 @@ int tetris(int argc, char **argv) } } else rs->seed = 777; - // Load file if given a filename. + /* Load file if given a filename. if (argc >= 2) { FILE *f = fopen(argv[1], "r"); if (f == NULL) { @@ -699,7 +701,9 @@ int tetris(int argc, char **argv) } else { // Otherwise create new game. tg = tg_create(22, 10); - } + }*/ + tg = tg_create(22, 10); + // NCURSES initialization: initscr(); // initialize curses cbreak(); // pass key presses to program, but not signals @@ -717,7 +721,7 @@ int tetris(int argc, char **argv) int32_t counter = 0; // Game loop while (running) { - running = tg_tick(tg, move); + running = tg_tick(rs,tg, move); display_board(board, tg); display_piece(next, tg->next); display_piece(hold, tg->stored); From 46dba9071ba32f439570e7bd8bc390b0103e677c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 01:49:11 -1100 Subject: [PATCH 020/111] Add keystrokes replay --- src/cc/dapps/dappstd.c | 318 ++++++++++++++++++++++++++++------------- src/cc/tetris.c | 65 +++++++-- 2 files changed, 274 insertions(+), 109 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index ec8045b2f..033633665 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -688,33 +688,6 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) return(retstr2); } -int32_t issue_games_events(bits256 gametxid,uint32_t eventid,int32_t c) -{ - static FILE *fp; - char params[512],*retstr,str[65]; cJSON *retjson,*resobj; int32_t retval = -1; - if ( fp == 0 ) - fp = fopen("events.log","wb"); - sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c,bits256_str(str,gametxid),eventid); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) - { - retval = 0; - if ( fp != 0 ) - { - fprintf(fp,"%s\n",jprint(resobj,0)); - fflush(fp); - } - } - free_json(retjson); - } else fprintf(fp,"error parsing %s\n",retstr); - free(retstr); - } else fprintf(fp,"error issuing method %s\n",params); - return(retval); -} - int32_t games_sendrawtransaction(char *rawtx) { char *params,*retstr,*hexstr; cJSON *retjson,*resobj; int32_t retval = -1; @@ -781,91 +754,240 @@ int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,cha } free(rs->keystrokeshex), rs->keystrokeshex = 0; } - if ( 0 && (pastkeys= games_keystrokesload(&numpastkeys,seed,1)) != 0 ) - { - sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (keys= jstr(resobj,(char *)"keystrokes")) != 0 ) - { - len = strlen(keys) / 2; - pastcmp = (uint8_t *)malloc(len + 1); - decode_hex(pastcmp,len,keys); - fprintf(stderr,"keystrokes.(%s) vs pastkeys\n",keys); - for (i=0; i> keystrokes.log",ASSETCHAINS_SYMBOL,Gametxidstr,hexstr); - if ( system(cmd) != 0 ) - fprintf(stderr,"error issuing (%s)\n",cmd); - } - else - { - static FILE *fp; - if ( fp == 0 ) - fp = fopen("keystrokes.log","a"); - sprintf(params,"[\"keystrokes\",\"17\",\"[%%22%s%%22,%%22%s%%22]\"]",Gametxidstr,hexstr); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) + if ( fp != 0 ) { - if ( fp != 0 ) + fprintf(fp,"%s\n",params); + fprintf(fp,"%s\n",retstr); + fflush(fp); + } + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (rawtx= jstr(resobj,(char *)"hex")) != 0 ) { - fprintf(fp,"%s\n",params); - fprintf(fp,"%s\n",retstr); - fflush(fp); - } - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (rawtx= jstr(resobj,(char *)"hex")) != 0 ) + if ( rs->keystrokeshex != 0 ) + free(rs->keystrokeshex); + if ( (errstr= jstr(resobj,(char *)"error")) == 0 ) { - if ( rs->keystrokeshex != 0 ) - free(rs->keystrokeshex); - if ( (errstr= jstr(resobj,(char *)"error")) == 0 ) - { - rs->keystrokeshex = (char *)malloc(strlen(rawtx)+1); - strcpy(rs->keystrokeshex,rawtx); - retflag = 1; - } else fprintf(stderr,"error sending keystrokes tx\n"), sleep(1); - //fprintf(stderr,"set keystrokestx <- %s\n",rs->keystrokeshex); - } - free_json(retjson); + rs->keystrokeshex = (char *)malloc(strlen(rawtx)+1); + strcpy(rs->keystrokeshex,rawtx); + retflag = 1; + } else fprintf(stderr,"error sending keystrokes tx\n"), sleep(1); + //fprintf(stderr,"set keystrokestx <- %s\n",rs->keystrokeshex); } - free(retstr); - } - if ( 0 && waitflag != 0 && rs->keystrokeshex != 0 ) - { - while ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) - { - //fprintf(stderr,"post-rebroadcast\n"); - sleep(3); - } - free(rs->keystrokeshex), rs->keystrokeshex = 0; + free_json(retjson); } + free(retstr); } } return(retflag); } +int32_t gamesfname(char *fname,uint64_t seed,int32_t counter) +{ + sprintf(fname,"%s.%llu.%d",GAMENAME,(long long)seed,counter); + return(0); +} + +int32_t flushkeystrokes_local(struct games_state *rs,int32_t waitflag) +{ +#ifdef STANDALONE + char fname[1024]; FILE *fp; int32_t i,retflag = -1; + rs->counter++; + gamesfname(fname,rs->seed,rs->counter); + if ( (fp= fopen(fname,"wb")) != 0 ) + { + if ( fwrite(rs->buffered,1,rs->num,fp) == rs->num ) + { + rs->num = 0; + retflag = 0; + fclose(fp); + gamesfname(fname,rs->seed,rs->counter+1); + if ( (fp= fopen(fname,"wb")) != 0 ) // truncate next file + fclose(fp); + //fprintf(stderr,"savefile <- %s retflag.%d\n",fname,retflag); + //} + } else fprintf(stderr,"error writing (%s)\n",fname); + } else fprintf(stderr,"error creating (%s)\n",fname); + return(retflag); +#else + return(0); +#endif +} + +#ifndef STANDALONE +// stubs for inside daemon + +int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num) +{ + return(0); +} + +int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) +{ + return(-1); +} +#endif + +int32_t flushkeystrokes(struct games_state *rs,int32_t waitflag) +{ + if ( rs->num > 0 ) + { + if ( games_progress(rs,waitflag,rs->seed,rs->buffered,rs->num) > 0 ) + { + flushkeystrokes_local(rs,waitflag); + memset(rs->buffered,0,sizeof(rs->buffered)); + } + } + return(0); +} + +void games_bailout(struct games_state *rs) +{ + flushkeystrokes(rs,1); +} + +#ifdef _WIN32 +#ifdef _MSC_VER +#define sleep(x) Sleep(1000*(x)) +#endif +#endif + +int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) +{ + struct games_state *rs; FILE *fp; int32_t i,n; + rs = (struct games_state *)calloc(1,sizeof(*rs)); + rs->seed = seed; + rs->keystrokes = keystrokes; + rs->numkeys = num; + rs->sleeptime = sleepmillis * 1000; + if ( player != 0 ) + { + rs->P = *player; + rs->restoring = 1; + //fprintf(stderr,"restore player packsize.%d HP.%d\n",rs->P.packsize,rs->P.hitpoints); + if ( rs->P.packsize > MAXPACK ) + rs->P.packsize = MAXPACK; + } + globalR = *rs; + uint32_t starttime = (uint32_t)time(NULL); + gamesiterate(rs); + if ( 0 ) + { + fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime); + sleep(2); + starttime = (uint32_t)time(NULL); + for (i=0; i<10000; i++) + { + memset(rs,0,sizeof(*rs)); + rs->seed = seed; + rs->keystrokes = keystrokes; + rs->numkeys = num; + rs->sleeptime = 0; + gamesiterate(rs); + } + fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL)-starttime); + sleep(3); + } + // extract playerdata + + /*if ( (fp= fopen("checkfile","wb")) != 0 ) + { + //save_file(rs,fp,0); + //fprintf(stderr,"gold.%d hp.%d strength.%d/%d level.%d exp.%d dungeon.%d data[%d]\n",rs->P.gold,rs->P.hitpoints,rs->P.strength&0xffff,rs->P.strength>>16,rs->P.level,rs->P.experience,rs->P.dungeonlevel,rs->playersize); + if ( newdata != 0 && rs->playersize > 0 ) + memcpy(newdata,rs->playerdata,rs->playersize); + }*/ + if ( newdata != 0 && rs->playersize > 0 ) + memcpy(newdata,rs->playerdata,rs->playersize); + n = rs->playersize; + free(rs); + return(n); +} + +long get_filesize(FILE *fp) +{ + long fsize,fpos = ftell(fp); + fseek(fp,0,SEEK_END); + fsize = ftell(fp); + fseek(fp,fpos,SEEK_SET); + return(fsize); +} + +char *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter) +{ + char fname[1024],*keystrokes = 0; FILE *fp; long fsize; int32_t num = 0; + *numkeysp = 0; + while ( 1 ) + { + gamesfname(fname,seed,counter); + //printf("check (%s)\n",fname); + if ( (fp= fopen(fname,"rb")) == 0 ) + break; + if ( (fsize= get_filesize(fp)) <= 0 ) + { + fclose(fp); + //printf("fsize.%ld\n",fsize); + break; + } + if ( (keystrokes= (char *)realloc(keystrokes,num+fsize)) == 0 ) + { + fprintf(stderr,"error reallocating keystrokes\n"); + fclose(fp); + return(0); + } + if ( fread(&keystrokes[num],1,fsize,fp) != fsize ) + { + fprintf(stderr,"error reading keystrokes from (%s)\n",fname); + fclose(fp); + free(keystrokes); + return(0); + } + fclose(fp); + num += fsize; + counter++; + //fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num); + } + *numkeysp = num; + return(keystrokes); +} + +int32_t games_replay(uint64_t seed,int32_t sleeptime) +{ + FILE *fp; char fname[1024]; char *keystrokes = 0; long fsize; int32_t i,num=0,counter = 0; struct games_state *rs; struct games_player P,*player = 0; + if ( seed == 0 ) + seed = 777; + keystrokes = games_keystrokesload(&num,seed,counter); + if ( num > 0 ) + { + sprintf(fname,"%s.%llu.player",GAMENAME,(long long)seed); + if ( (fp=fopen(fname,"rb")) != 0 ) + { + if ( fread(&P,1,sizeof(P),fp) > 0 ) + { + //printf("max size player\n"); + player = &P; + } + fclose(fp); + } + games_replay2(0,seed,keystrokes,num,player,sleeptime); + mvaddstr(LINES - 2, 0, (char *)"replay completed"); + endwin(); + my_exit(0); + } + if ( keystrokes != 0 ) + free(keystrokes); + return(num); +} + int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) { char cmd[32768]; int32_t i,n,retval=-1; char params[1024],*filestr=0,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item,*resultjson; diff --git a/src/cc/tetris.c b/src/cc/tetris.c index db88c0659..5e873e5c4 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -638,6 +638,34 @@ void init_colors(void) */ #include "dapps/dappstd.c" +int32_t issue_games_events(struct games_state *rs,bits256 gametxid,uint32_t eventid,char c) +{ + static FILE *fp; + char params[512],*retstr,str[65]; cJSON *retjson,*resobj; int32_t retval = -1; + if ( fp == 0 ) + fp = fopen("events.log","wb"); + sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,bits256_str(str,gametxid),eventid); + rs->buffered[rs->num++] = c; + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) + { + retval = 0; + if ( fp != 0 ) + { + fprintf(fp,"%s\n",jprint(resobj,0)); + fflush(fp); + } + } + free_json(retjson); + } else fprintf(fp,"error parsing %s\n",retstr); + free(retstr); + } else fprintf(fp,"error issuing method %s\n",params); + return(retval); +} + char *clonestr(char *str) { char *clone; int32_t len; @@ -730,34 +758,49 @@ int tetris(int argc, char **argv) doupdate(); sleep_milli(10); c = getch(); - if ( c != -1 || skipcount == 0x3fff ) + switch ( c ) + { + case KEY_LEFT: + c = 'h'; + break; + case KEY_RIGHT: + c = 'l'; + break; + case KEY_UP: + c = 'k'; + break; + case KEY_DOWN: + c = 'j'; + break; + } + if ( c < 0 || skipcount == 0x7f ) { if ( skipcount > 0 ) - issue_games_events(gametxid,eventid-skipcount,skipcount | 0x4000); + issue_games_events(rs,gametxid,eventid-skipcount,skipcount | 0x80); if ( c != -1 ) - issue_games_events(gametxid,eventid,c); + issue_games_events(rs,gametxid,eventid,c); skipcount = 0; } else skipcount++; eventid++; switch ( c ) { - case KEY_LEFT: + case 'h': move = TM_LEFT; break; - case KEY_RIGHT: + case 'l': move = TM_RIGHT; break; - case KEY_UP: + case 'k': move = TM_CLOCK; break; - case KEY_DOWN: + case 'j': move = TM_DROP; break; case 'q': running = false; move = TM_NONE; break; - case 'p': + /*case 'p': wclear(board); box(board, 0, 0); wmove(board, tg->rows/2, (tg->cols*COLS_PER_CELL-6)/2); @@ -771,7 +814,7 @@ int tetris(int argc, char **argv) case 's': save(tg, board); move = TM_NONE; - break; + break;*/ case ' ': move = TM_HOLD; break; @@ -792,9 +835,9 @@ int tetris(int argc, char **argv) return 0; } -int32_t games_replay(uint64_t seed,int32_t sleeptime) +void gamesiterate(struct games_state *rs) { - return(-1); + } #endif From c9a3844f54799b77c862c38f9faf06c3a0a08a1e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 01:52:18 -1100 Subject: [PATCH 021/111] Test --- src/cc/tetris.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/tetris.h b/src/cc/tetris.h index e2639cba1..40a9c97cb 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -137,7 +137,7 @@ extern const int GRAVITY_LEVEL[MAX_LEVEL+1]; // Data structure manipulation. void tg_init(tetris_game *obj, int rows, int cols); -tetris_game *tg_create(int rows, int cols); +tetris_game *tg_create(struct games_state *rs,int rows, int cols); void tg_destroy(tetris_game *obj); void tg_delete(tetris_game *obj); tetris_game *tg_load(FILE *f); @@ -146,7 +146,7 @@ void tg_save(tetris_game *obj, FILE *f); // Public methods not related to memory: char tg_get(tetris_game *obj, int row, int col); bool tg_check(tetris_game *obj, int row, int col); -bool tg_tick(tetris_game *obj, tetris_move move); +bool tg_tick(struct games_state *rs,tetris_game *obj, tetris_move move); void tg_print(tetris_game *obj, FILE *f); /****************************************************************************** @@ -192,6 +192,7 @@ struct games_state uint8_t playerdata[10000]; }; +uint64_t _games_rngnext(uint64_t initseed); #endif From a49081204962ba5076cdf59ec509d2182b6c4911 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 01:54:09 -1100 Subject: [PATCH 022/111] struct games_state *rs, --- src/cc/tetris.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 5e873e5c4..4dbb71f89 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -226,7 +226,7 @@ static void tg_move(tetris_game *obj, int direction) /* Send the falling tetris block to the bottom. */ -static void tg_down(tetris_game *obj) +static void tg_down(struct games_state *rs,tetris_game *obj) { tg_remove(obj, obj->falling); while (tg_fits(obj, obj->falling)) { @@ -234,7 +234,7 @@ static void tg_down(tetris_game *obj) } obj->falling.loc.row--; tg_put(obj, obj->falling); - tg_new_falling(obj); + tg_new_falling(rs,obj); } /* @@ -273,12 +273,12 @@ static void tg_rotate(tetris_game *obj, int direction) /* Swap the falling block with the block in the hold buffer. */ -static void tg_hold(tetris_game *obj) +static void tg_hold(struct games_state *rs,tetris_game *obj) { tg_remove(obj, obj->falling); if (obj->stored.typ == -1) { obj->stored = obj->falling; - tg_new_falling(obj); + tg_new_falling(rs,obj); } else { int typ = obj->falling.typ, ori = obj->falling.ori; obj->falling.typ = obj->stored.typ; @@ -431,7 +431,7 @@ bool tg_tick(struct games_state *rs,tetris_game *obj, tetris_move move) return !tg_game_over(obj); } -void tg_init(tetris_game *obj, int rows, int cols) +void tg_init(struct games_state *rs,tetris_game *obj, int rows, int cols) { // Initialization logic obj->rows = rows; @@ -443,8 +443,8 @@ void tg_init(tetris_game *obj, int rows, int cols) obj->ticks_till_gravity = GRAVITY_LEVEL[obj->level]; obj->lines_remaining = LINES_PER_LEVEL; //srand(time(NULL)); - tg_new_falling(obj); - tg_new_falling(obj); + tg_new_falling(rs,obj); + tg_new_falling(ts,obj); obj->stored.typ = -1; obj->stored.ori = 0; obj->stored.loc.row = 0; @@ -452,10 +452,10 @@ void tg_init(tetris_game *obj, int rows, int cols) printf("%d", obj->falling.loc.col); } -tetris_game *tg_create(int rows, int cols) +tetris_game *tg_create(struct games_state *rs,int rows, int cols) { tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); - tg_init(obj, rows, cols); + tg_init(rs,obj, rows, cols); return obj; } From 30df5445c762767263c3312560624476bac74c02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 01:57:07 -1100 Subject: [PATCH 023/111] struct games_state *rs, --- src/cc/tetris.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 4dbb71f89..1b039dc6f 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -295,7 +295,7 @@ static void tg_hold(struct games_state *rs,tetris_game *obj) /* Perform the action specified by the move. */ -static void tg_handle_move(tetris_game *obj, tetris_move move) +static void tg_handle_move(struct games_state *rs,tetris_game *obj, tetris_move move) { switch (move) { case TM_LEFT: @@ -305,7 +305,7 @@ static void tg_handle_move(tetris_game *obj, tetris_move move) tg_move(obj, 1); break; case TM_DROP: - tg_down(obj); + tg_down(rs,obj); break; case TM_CLOCK: tg_rotate(obj, 1); @@ -314,7 +314,7 @@ static void tg_handle_move(tetris_game *obj, tetris_move move) tg_rotate(obj, -1); break; case TM_HOLD: - tg_hold(obj); + tg_hold(rs,obj); break; default: // pass @@ -420,7 +420,7 @@ bool tg_tick(struct games_state *rs,tetris_game *obj, tetris_move move) tg_do_gravity_tick(rs,obj); // Handle input. - tg_handle_move(obj, move); + tg_handle_move(rs,obj, move); // Check for cleared lines lines_cleared = tg_check_lines(obj); @@ -444,7 +444,7 @@ void tg_init(struct games_state *rs,tetris_game *obj, int rows, int cols) obj->lines_remaining = LINES_PER_LEVEL; //srand(time(NULL)); tg_new_falling(rs,obj); - tg_new_falling(ts,obj); + tg_new_falling(rs,obj); obj->stored.typ = -1; obj->stored.ori = 0; obj->stored.loc.row = 0; @@ -728,9 +728,9 @@ int tetris(int argc, char **argv) fclose(f); } else { // Otherwise create new game. - tg = tg_create(22, 10); + tg = tg_create(rs,22, 10); }*/ - tg = tg_create(22, 10); + tg = tg_create(rs,22, 10); // NCURSES initialization: initscr(); // initialize curses From 3a6db6cc718d9550b414dca6190775755f8cf6a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 01:59:56 -1100 Subject: [PATCH 024/111] Gamesiterate --- src/cc/dapps/dappstd.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 033633665..5c8fb0204 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -23,6 +23,9 @@ #include #include +extern struct games_state globalR; +void gamesiterate(struct games_state *rs); + char USERPASS[8192]; uint16_t GAMES_PORT; char Gametxidstr[67]; char *clonestr(char *str); @@ -960,6 +963,19 @@ char *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter) return(keystrokes); } +void games_exit() +{ + uint32_t counter; + resetltchars(); + if ( globalR.guiflag != 0 || globalR.sleeptime != 0 ) + exit(st); + else if ( counter++ < 10 ) + { + fprintf(stderr,"would have exit.(%d) sleeptime.%d\n",st,globalR.sleeptime); + globalR.replaydone = 1; + } +} + int32_t games_replay(uint64_t seed,int32_t sleeptime) { FILE *fp; char fname[1024]; char *keystrokes = 0; long fsize; int32_t i,num=0,counter = 0; struct games_state *rs; struct games_player P,*player = 0; @@ -981,7 +997,7 @@ int32_t games_replay(uint64_t seed,int32_t sleeptime) games_replay2(0,seed,keystrokes,num,player,sleeptime); mvaddstr(LINES - 2, 0, (char *)"replay completed"); endwin(); - my_exit(0); + games_exit(); } if ( keystrokes != 0 ) free(keystrokes); From 7604ee369749937957eb18958542dee377691973 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 02:01:32 -1100 Subject: [PATCH 025/111] Exit --- src/cc/dapps/dappstd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 5c8fb0204..5f8821890 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -966,9 +966,9 @@ char *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter) void games_exit() { uint32_t counter; - resetltchars(); + //resetltchars(); if ( globalR.guiflag != 0 || globalR.sleeptime != 0 ) - exit(st); + exit(0); else if ( counter++ < 10 ) { fprintf(stderr,"would have exit.(%d) sleeptime.%d\n",st,globalR.sleeptime); From 62fc48877e96a4877de5d8ae12752221cdf4af30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 02:05:19 -1100 Subject: [PATCH 026/111] -print --- src/cc/dapps/dappstd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 5f8821890..b93e7b41d 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -971,7 +971,7 @@ void games_exit() exit(0); else if ( counter++ < 10 ) { - fprintf(stderr,"would have exit.(%d) sleeptime.%d\n",st,globalR.sleeptime); + fprintf(stderr,"would have exit sleeptime.%d\n",globalR.sleeptime); globalR.replaydone = 1; } } From 7b8adf33e196a8a3e3ba5d957796a980a13922cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 02:06:33 -1100 Subject: [PATCH 027/111] Gamesrngnext --- src/cc/gamescc.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index f62a8699c..367c8d96e 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -16,6 +16,21 @@ #include "gamescc.h" #include "tetris.c" // replace with game code + +uint64_t _games_rngnext(uint64_t initseed) +{ + uint16_t seeds[4]; int32_t i; + seeds[0] = initseed; + seeds[1] = (initseed >> 16); + seeds[2] = (initseed >> 32); + seeds[3] = (initseed >> 48); + seeds[0] = (seeds[0]*GAMES_RNGMULT + GAMES_RNGOFFSET); + seeds[1] = ((seeds[0] ^ seeds[1])*GAMES_RNGMULT + GAMES_RNGOFFSET); + seeds[2] = ((seeds[0] ^ seeds[1] ^ seeds[2])*GAMES_RNGMULT + GAMES_RNGOFFSET); + seeds[3] = ((seeds[0] ^ seeds[1] ^ seeds[2] ^ seeds[3])*GAMES_RNGMULT + GAMES_RNGOFFSET); + return(((uint64_t)seeds[3] << 48) | ((uint64_t)seeds[2] << 24) | ((uint64_t)seeds[1] << 16) | seeds[0]); +} + #ifndef STANDALONE #include "tetris.cpp" // replace with game specific functions @@ -195,20 +210,6 @@ UniValue games_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastf return(result); } -uint64_t _games_rngnext(uint64_t initseed) -{ - uint16_t seeds[4]; int32_t i; - seeds[0] = initseed; - seeds[1] = (initseed >> 16); - seeds[2] = (initseed >> 32); - seeds[3] = (initseed >> 48); - seeds[0] = (seeds[0]*GAMES_RNGMULT + GAMES_RNGOFFSET); - seeds[1] = ((seeds[0] ^ seeds[1])*GAMES_RNGMULT + GAMES_RNGOFFSET); - seeds[2] = ((seeds[0] ^ seeds[1] ^ seeds[2])*GAMES_RNGMULT + GAMES_RNGOFFSET); - seeds[3] = ((seeds[0] ^ seeds[1] ^ seeds[2] ^ seeds[3])*GAMES_RNGMULT + GAMES_RNGOFFSET); - 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; From fd3ded58bc46422389e95033d69f22779fa99ec9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 02:07:13 -1100 Subject: [PATCH 028/111] #define GAMES_RNGMULT 11109 #define GAMES_RNGOFFSET 13849 #define GAMES_MAXRNGS 10000 --- src/cc/gamescc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 07a1f8e65..6ec5dc9c4 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -3,6 +3,9 @@ #include #include +#define GAMES_RNGMULT 11109 +#define GAMES_RNGOFFSET 13849 +#define GAMES_MAXRNGS 10000 #ifndef STANDALONE @@ -22,9 +25,6 @@ std::string MYCCLIBNAME = (char *)"gamescc"; #define GAMES_REGISTRATIONSIZE (100 * 10000) #define GAMES_REGISTRATION 1 -#define GAMES_RNGMULT 11109 -#define GAMES_RNGOFFSET 13849 -#define GAMES_MAXRNGS 10000 #define MYCCNAME "games" From 5330c2349980178a6236e6d32308ef4b4982573c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 02:23:50 -1100 Subject: [PATCH 029/111] Gamesiterate --- src/cc/tetris.c | 186 ++++++++++++++++++++++++------------------------ 1 file changed, 93 insertions(+), 93 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 1b039dc6f..1cc7962f5 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -638,13 +638,13 @@ void init_colors(void) */ #include "dapps/dappstd.c" -int32_t issue_games_events(struct games_state *rs,bits256 gametxid,uint32_t eventid,char c) +int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,char c) { static FILE *fp; - char params[512],*retstr,str[65]; cJSON *retjson,*resobj; int32_t retval = -1; + char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; if ( fp == 0 ) fp = fopen("events.log","wb"); - sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,bits256_str(str,gametxid),eventid); + sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,gametxidstr,eventid); rs->buffered[rs->num++] = c; if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) { @@ -685,15 +685,98 @@ char *clonestr(char *str) struct games_state globalR; +void gamesiterate(struct games_state *rs,tetris_game *tg) +{ + uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE; + int32_t c,skipcount=0; uint32_t eventid = 0; + WINDOW *board, *next, *hold, *score; + // Create windows for each section of the interface. + board = newwin(tg->rows + 2, 2 * tg->cols + 2, 0, 0); + next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); + hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1); + score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1); + while (running) + { + running = tg_tick(rs,tg, move); + display_board(board, tg); + display_piece(next, tg->next); + display_piece(hold, tg->stored); + display_score(score, tg); + if ( (counter++ % 5) == 0 ) + doupdate(); + sleep_milli(10); + c = getch(); + switch ( c ) + { + case KEY_LEFT: + c = 'h'; + break; + case KEY_RIGHT: + c = 'l'; + break; + case KEY_UP: + c = 'k'; + break; + case KEY_DOWN: + c = 'j'; + break; + } + if ( c < 0 || skipcount == 0x7f ) + { + if ( skipcount > 0 ) + issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x80); + if ( c != -1 ) + issue_games_events(rs,Gametxidstr,eventid,c); + skipcount = 0; + } else skipcount++; + eventid++; + switch ( c ) + { + case 'h': + move = TM_LEFT; + break; + case 'l': + move = TM_RIGHT; + break; + case 'k': + move = TM_CLOCK; + break; + case 'j': + move = TM_DROP; + break; + case 'q': + running = false; + move = TM_NONE; + break; + /*case 'p': + wclear(board); + box(board, 0, 0); + wmove(board, tg->rows/2, (tg->cols*COLS_PER_CELL-6)/2); + wprintw(board, "PAUSED"); + wrefresh(board); + timeout(-1); + getch(); + timeout(0); + move = TM_NONE; + break; + case 's': + save(tg, board); + move = TM_NONE; + break;*/ + case ' ': + move = TM_HOLD; + break; + default: + move = TM_NONE; + } + } +} + int tetris(int argc, char **argv) { tetris_game *tg; - tetris_move move = TM_NONE; - bool running = true; - WINDOW *board, *next, *hold, *score; struct games_state *rs = &globalR; - int32_t c,skipcount=0; bits256 gametxid; uint32_t eventid = 0; - memset(&gametxid,0,sizeof(gametxid)); + int32_t c,skipcount=0; uint32_t eventid = 0; memset(rs,0,sizeof(*rs)); rs->guiflag = 1; rs->sleeptime = 1; // non-zero to allow refresh() @@ -741,88 +824,9 @@ int tetris(int argc, char **argv) curs_set(0); // set the cursor to invisible init_colors(); // setup tetris colors - // Create windows for each section of the interface. - board = newwin(tg->rows + 2, 2 * tg->cols + 2, 0, 0); - next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); - hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1); - score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1); - int32_t counter = 0; // Game loop - while (running) { - running = tg_tick(rs,tg, move); - display_board(board, tg); - display_piece(next, tg->next); - display_piece(hold, tg->stored); - display_score(score, tg); - if ( (counter++ % 5) == 0 ) - doupdate(); - sleep_milli(10); - c = getch(); - switch ( c ) - { - case KEY_LEFT: - c = 'h'; - break; - case KEY_RIGHT: - c = 'l'; - break; - case KEY_UP: - c = 'k'; - break; - case KEY_DOWN: - c = 'j'; - break; - } - if ( c < 0 || skipcount == 0x7f ) - { - if ( skipcount > 0 ) - issue_games_events(rs,gametxid,eventid-skipcount,skipcount | 0x80); - if ( c != -1 ) - issue_games_events(rs,gametxid,eventid,c); - skipcount = 0; - } else skipcount++; - eventid++; - switch ( c ) - { - case 'h': - move = TM_LEFT; - break; - case 'l': - move = TM_RIGHT; - break; - case 'k': - move = TM_CLOCK; - break; - case 'j': - move = TM_DROP; - break; - case 'q': - running = false; - move = TM_NONE; - break; - /*case 'p': - wclear(board); - box(board, 0, 0); - wmove(board, tg->rows/2, (tg->cols*COLS_PER_CELL-6)/2); - wprintw(board, "PAUSED"); - wrefresh(board); - timeout(-1); - getch(); - timeout(0); - move = TM_NONE; - break; - case 's': - save(tg, board); - move = TM_NONE; - break;*/ - case ' ': - move = TM_HOLD; - break; - default: - move = TM_NONE; - } - } - + gamesiterate(rs,tg); + games_bailout(rs); // Deinitialize NCurses wclear(stdscr); endwin(); @@ -835,9 +839,5 @@ int tetris(int argc, char **argv) return 0; } -void gamesiterate(struct games_state *rs) -{ - -} #endif From b0d0adb729531b32267a673e9a0f1a6dbd42eb04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 02:28:32 -1100 Subject: [PATCH 030/111] Gamesiterate --- src/cc/tetris.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 1cc7962f5..98e6a2fab 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -685,12 +685,13 @@ char *clonestr(char *str) struct games_state globalR; -void gamesiterate(struct games_state *rs,tetris_game *tg) +void gamesiterate(struct games_state *rs) { uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE; - int32_t c,skipcount=0; uint32_t eventid = 0; + int32_t c,skipcount=0; uint32_t eventid = 0; tetris_game *tg; WINDOW *board, *next, *hold, *score; // Create windows for each section of the interface. + tg = tg_create(rs,22, 10); board = newwin(tg->rows + 2, 2 * tg->cols + 2, 0, 0); next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1); @@ -774,7 +775,6 @@ void gamesiterate(struct games_state *rs,tetris_game *tg) int tetris(int argc, char **argv) { - tetris_game *tg; struct games_state *rs = &globalR; int32_t c,skipcount=0; uint32_t eventid = 0; memset(rs,0,sizeof(*rs)); @@ -813,7 +813,6 @@ int tetris(int argc, char **argv) // Otherwise create new game. tg = tg_create(rs,22, 10); }*/ - tg = tg_create(rs,22, 10); // NCURSES initialization: initscr(); // initialize curses @@ -825,7 +824,7 @@ int tetris(int argc, char **argv) init_colors(); // setup tetris colors // Game loop - gamesiterate(rs,tg); + gamesiterate(rs); games_bailout(rs); // Deinitialize NCurses wclear(stdscr); From a02e96bc3b1b1c62b6b1ec7006b7a2ae2f3ec0e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 02:41:16 -1100 Subject: [PATCH 031/111] Free obj --- src/cc/dapps/dappstd.c | 15 ++++++++++----- src/cc/tetris.c | 21 +++++++++++---------- src/cc/tetris.h | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index b93e7b41d..1ab3e6427 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -24,7 +24,7 @@ #include extern struct games_state globalR; -void gamesiterate(struct games_state *rs); +void *gamesiterate(struct games_state *rs); char USERPASS[8192]; uint16_t GAMES_PORT; char Gametxidstr[67]; @@ -866,7 +866,7 @@ void games_bailout(struct games_state *rs) int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) { - struct games_state *rs; FILE *fp; int32_t i,n; + struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; rs = (struct games_state *)calloc(1,sizeof(*rs)); rs->seed = seed; rs->keystrokes = keystrokes; @@ -882,7 +882,7 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu } globalR = *rs; uint32_t starttime = (uint32_t)time(NULL); - gamesiterate(rs); + ptr = gamesiterate(rs); if ( 0 ) { fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime); @@ -909,8 +909,13 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu if ( newdata != 0 && rs->playersize > 0 ) memcpy(newdata,rs->playerdata,rs->playersize); }*/ - if ( newdata != 0 && rs->playersize > 0 ) - memcpy(newdata,rs->playerdata,rs->playersize); + if ( ptr != 0 ) + { + // extract data from ptr + if ( newdata != 0 && rs->playersize > 0 ) + memcpy(newdata,rs->playerdata,rs->playersize); + free(ptr); + } n = rs->playersize; free(rs); return(n); diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 98e6a2fab..0f81971c4 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -436,7 +436,7 @@ void tg_init(struct games_state *rs,tetris_game *obj, int rows, int cols) // Initialization logic obj->rows = rows; obj->cols = cols; - obj->board = (char *)malloc(rows * cols); + //obj->board = (char *)malloc(rows * cols); memset(obj->board, TC_EMPTY, rows * cols); obj->points = 0; obj->level = 0; @@ -454,19 +454,19 @@ void tg_init(struct games_state *rs,tetris_game *obj, int rows, int cols) tetris_game *tg_create(struct games_state *rs,int rows, int cols) { - tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); + tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game) + rows*cols); tg_init(rs,obj, rows, cols); return obj; } -void tg_destroy(tetris_game *obj) +/*void tg_destroy(tetris_game *obj) { // Cleanup logic free(obj->board); -} +}*/ void tg_delete(tetris_game *obj) { - tg_destroy(obj); + //tg_destroy(obj); free(obj); } @@ -591,7 +591,7 @@ void display_score(WINDOW *w, tetris_game *tg) /* Save and exit the game. - */ + void save(tetris_game *game, WINDOW *w) { FILE *f; @@ -614,7 +614,7 @@ void save(tetris_game *game, WINDOW *w) fprintf(stderr,"Game saved to \"tetris.save\".\n"); fprintf(stderr,"Resume by passing the filename as an argument to this program.\n"); exit(EXIT_SUCCESS); -} +}*/ /* Do the NCURSES initialization steps for color blocks. @@ -685,7 +685,7 @@ char *clonestr(char *str) struct games_state globalR; -void gamesiterate(struct games_state *rs) +void *gamesiterate(struct games_state *rs) { uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE; int32_t c,skipcount=0; uint32_t eventid = 0; tetris_game *tg; @@ -771,12 +771,13 @@ void gamesiterate(struct games_state *rs) move = TM_NONE; } } + return(tg); } int tetris(int argc, char **argv) { struct games_state *rs = &globalR; - int32_t c,skipcount=0; uint32_t eventid = 0; + int32_t c,skipcount=0; uint32_t eventid = 0; tetris_game *tg = 0; memset(rs,0,sizeof(*rs)); rs->guiflag = 1; rs->sleeptime = 1; // non-zero to allow refresh() @@ -824,7 +825,7 @@ int tetris(int argc, char **argv) init_colors(); // setup tetris colors // Game loop - gamesiterate(rs); + tg = gamesiterate(rs); games_bailout(rs); // Deinitialize NCurses wclear(stdscr); diff --git a/src/cc/tetris.h b/src/cc/tetris.h index 40a9c97cb..9fce377d7 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -97,7 +97,6 @@ typedef struct { */ int rows; int cols; - char *board; /* Scoring information: */ @@ -118,6 +117,7 @@ typedef struct { Number of lines until you advance to the next level. */ int lines_remaining; + char board[]; } tetris_game; /* From 44776662d087dd12d3e2d40a4f73adb0ff126ea3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 02:45:09 -1100 Subject: [PATCH 032/111] -load --- src/cc/tetris.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 0f81971c4..23d58e45c 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -472,7 +472,7 @@ void tg_delete(tetris_game *obj) { /* Load a game from a file. - */ + tetris_game *tg_load(FILE *f) { tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); @@ -494,18 +494,18 @@ tetris_game *tg_load(FILE *f) } } return obj; -} +}*/ /* Save a game to a file. - */ + void tg_save(tetris_game *obj, FILE *f) { if (fwrite(obj, sizeof(tetris_game), 1, f) != 1 ) fprintf(stderr,"error writing tetrisgame\n"); else if (fwrite(obj->board, sizeof(char), obj->rows * obj->cols, f) != obj->rows * obj->cols ) fprintf(stderr,"error writing board\n"); -} +}*/ /* Print a game board to a file. Really just for early debugging. From 6712caf91e3ae2cf1f013e689e419dc72cacdfa8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 02:46:10 -1100 Subject: [PATCH 033/111] Ptr --- src/cc/tetris.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 23d58e45c..305bf0c3b 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -825,7 +825,7 @@ int tetris(int argc, char **argv) init_colors(); // setup tetris colors // Game loop - tg = gamesiterate(rs); + tg = (tetris_game *)gamesiterate(rs); games_bailout(rs); // Deinitialize NCurses wclear(stdscr); From b7c8205870d3ada608abbf1d29acb67c43c0eb39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:14:26 -1100 Subject: [PATCH 034/111] Origseed --- src/cc/dapps/dappstd.c | 65 ++++++++++++++++++++++++++++++--- src/cc/tetris.c | 82 +++++++++++++++++++++++++----------------- src/cc/tetris.h | 2 +- 3 files changed, 111 insertions(+), 38 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 1ab3e6427..f98a3af63 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -805,7 +805,7 @@ int32_t flushkeystrokes_local(struct games_state *rs,int32_t waitflag) #ifdef STANDALONE char fname[1024]; FILE *fp; int32_t i,retflag = -1; rs->counter++; - gamesfname(fname,rs->seed,rs->counter); + gamesfname(fname,rs->origseed,rs->counter); if ( (fp= fopen(fname,"wb")) != 0 ) { if ( fwrite(rs->buffered,1,rs->num,fp) == rs->num ) @@ -813,7 +813,7 @@ int32_t flushkeystrokes_local(struct games_state *rs,int32_t waitflag) rs->num = 0; retflag = 0; fclose(fp); - gamesfname(fname,rs->seed,rs->counter+1); + gamesfname(fname,rs->origseed,rs->counter+1); if ( (fp= fopen(fname,"wb")) != 0 ) // truncate next file fclose(fp); //fprintf(stderr,"savefile <- %s retflag.%d\n",fname,retflag); @@ -844,7 +844,7 @@ int32_t flushkeystrokes(struct games_state *rs,int32_t waitflag) { if ( rs->num > 0 ) { - if ( games_progress(rs,waitflag,rs->seed,rs->buffered,rs->num) > 0 ) + if ( games_progress(rs,waitflag,rs->origseed,rs->buffered,rs->num) > 0 ) { flushkeystrokes_local(rs,waitflag); memset(rs->buffered,0,sizeof(rs->buffered)); @@ -868,7 +868,7 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu { struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; rs = (struct games_state *)calloc(1,sizeof(*rs)); - rs->seed = seed; + rs->seed = rs->origseed = seed; rs->keystrokes = keystrokes; rs->numkeys = num; rs->sleeptime = sleepmillis * 1000; @@ -891,7 +891,7 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu for (i=0; i<10000; i++) { memset(rs,0,sizeof(*rs)); - rs->seed = seed; + rs->seed = rs->origseed = seed; rs->keystrokes = keystrokes; rs->numkeys = num; rs->sleeptime = 0; @@ -1009,6 +1009,61 @@ int32_t games_replay(uint64_t seed,int32_t sleeptime) return(num); } +char games_readchar(struct rogue_state *rs) +{ + char c,ch = -1; + if ( rs != 0 && rs->guiflag == 0 ) + { + static uint32_t counter; + if ( rs->ind < rs->numkeys ) + { + c = rs->keystrokes[rs->ind++]; + if ( 0 ) + { + static FILE *fp; static int32_t counter; + if ( fp == 0 ) + fp = fopen("log","wb"); + if ( fp != 0 ) + { + fprintf(fp,"%d: (%c) seed.%llu\n",counter,c,(long long)rs->origseed); + fflush(fp); + counter++; + } + } + return(c); + } + if ( rs->replaydone != 0 && counter++ < 3 ) + fprintf(stderr,"replay finished but readchar called\n"); + rs->replaydone = (uint32_t)time(NULL); + if ( counter < 3 || (counter & 1) == 0 ) + return('y'); + else return(ESCAPE); + } + if ( rs == 0 || rs->guiflag != 0 ) + { + ch = (char) getch(); + if (ch == 3) + { + _quit(); + return(27); + } + if ( rs != 0 && rs->guiflag != 0 ) + { + if ( rs->num < sizeof(rs->buffered) ) + { + rs->buffered[rs->num++] = ch; + if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) + { + rs->needflush = (uint32_t)time(NULL); + //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); + //sleep(3); + } + } else fprintf(stderr,"buffer filled without flushed\n"); + } + } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); + return(ch); +} + int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) { char cmd[32768]; int32_t i,n,retval=-1; char params[1024],*filestr=0,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item,*resultjson; diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 305bf0c3b..3047e0e55 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -696,40 +696,57 @@ void *gamesiterate(struct games_state *rs) next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1); score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1); - while (running) + while ( running != 0 ) { - running = tg_tick(rs,tg, move); - display_board(board, tg); - display_piece(next, tg->next); - display_piece(hold, tg->stored); - display_score(score, tg); - if ( (counter++ % 5) == 0 ) - doupdate(); - sleep_milli(10); - c = getch(); - switch ( c ) + running = tg_tick(rs,tg,move); + if ( rs->guiflag != 0 ) { - case KEY_LEFT: - c = 'h'; - break; - case KEY_RIGHT: - c = 'l'; - break; - case KEY_UP: - c = 'k'; - break; - case KEY_DOWN: - c = 'j'; - break; + display_board(board,tg); + display_piece(next,tg->next); + display_piece(hold,tg->stored); + display_score(score,tg); + if ( (counter++ % 5) == 0 ) + doupdate(); + sleep_milli(10); + c = games_readchar(rs); + switch ( c ) + { + case KEY_LEFT: + c = 'h'; + break; + case KEY_RIGHT: + c = 'l'; + break; + case KEY_UP: + c = 'k'; + break; + case KEY_DOWN: + c = 'j'; + break; + } + if ( c < 0 || skipcount == 0x7f ) + { + if ( skipcount > 0 ) + issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x80); + if ( c != -1 ) + issue_games_events(rs,Gametxidstr,eventid,c); + skipcount = 0; + } else skipcount++; } - if ( c < 0 || skipcount == 0x7f ) + else { + if ( skipcount == 0 ) + { + c = games_readchar(rs); + if ( (c & 0x80) != 0 ) + { + skipcount = (c & 0x7f); + c = 'S'; + } + } if ( skipcount > 0 ) - issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x80); - if ( c != -1 ) - issue_games_events(rs,Gametxidstr,eventid,c); - skipcount = 0; - } else skipcount++; + skipcount--; + } eventid++; switch ( c ) { @@ -785,13 +802,14 @@ int tetris(int argc, char **argv) { #ifdef _WIN32 #ifdef _MSC_VER - rs->seed = _strtoui64(argv[1], NULL, 10); + rs->origseed = _strtoui64(argv[1], NULL, 10); #else - rs->seed = atol(argv[1]); // windows, but not MSVC + rs->origseed = atol(argv[1]); // windows, but not MSVC #endif // _MSC_VER #else - rs->seed = atol(argv[1]); // non-windows + rs->origseed = atol(argv[1]); // non-windows #endif // _WIN32 + rs->seed = rs->origseed; strcpy(Gametxidstr,argv[2]); fprintf(stderr,"setplayerdata\n"); if ( games_setplayerdata(rs,Gametxidstr) < 0 ) diff --git a/src/cc/tetris.h b/src/cc/tetris.h index 9fce377d7..317dad62b 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -182,7 +182,7 @@ struct games_player struct games_state { - uint64_t seed; + uint64_t seed,origseed; char *keystrokes,*keystrokeshex; uint32_t needflush,replaydone; int32_t numkeys,ind,num,guiflag,counter,sleeptime,playersize,restoring,lastnum; From 81263613bb334f39325a4c46bcae4b3cd8eceded Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:15:11 -1100 Subject: [PATCH 035/111] Games --- src/cc/dapps/dappstd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index f98a3af63..714bcaf82 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -1009,7 +1009,7 @@ int32_t games_replay(uint64_t seed,int32_t sleeptime) return(num); } -char games_readchar(struct rogue_state *rs) +char games_readchar(struct games_state *rs) { char c,ch = -1; if ( rs != 0 && rs->guiflag == 0 ) From d223563eff2e4595e0fa11102d4b7c429b76ffa6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:16:36 -1100 Subject: [PATCH 036/111] Test --- src/cc/dapps/dappstd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 714bcaf82..0f3d8cc24 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -1035,16 +1035,14 @@ char games_readchar(struct games_state *rs) if ( rs->replaydone != 0 && counter++ < 3 ) fprintf(stderr,"replay finished but readchar called\n"); rs->replaydone = (uint32_t)time(NULL); - if ( counter < 3 || (counter & 1) == 0 ) - return('y'); - else return(ESCAPE); + return(0); } if ( rs == 0 || rs->guiflag != 0 ) { ch = (char) getch(); if (ch == 3) { - _quit(); + //_quit(); return(27); } if ( rs != 0 && rs->guiflag != 0 ) From a4103580310f3648eecf57747a5b6ed1b371066d Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 26 Mar 2019 15:36:10 +0100 Subject: [PATCH 037/111] Correct GatewaysCC validation to check spending from global address. (#19) - Add additional vin/vout check - Check that marker spending from global CC address is only for a marker value - Set fixed marker values instead of depending on txfee --- src/cc/gateways.cpp | 163 +++++++++++++++++++++++--------------------- 1 file changed, 85 insertions(+), 78 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index f0c8735e2..4993e1078 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -152,6 +152,7 @@ #define KMD_P2SHTYPE 85 #define KMD_WIFTYPE 188 #define KMD_TADDR 0 +#define CC_MARKER_VALUE 10000 CScript EncodeGatewaysBindOpRet(uint8_t funcid,uint256 tokenid,std::string coin,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector gatewaypubkeys,uint8_t taddr,uint8_t prefix,uint8_t prefix2,uint8_t wiftype) { @@ -185,7 +186,7 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,ui if ( N > 1 ) { strcpy(depositaddr,CBitcoinAddress(CScriptID(GetScriptForMultisig(M,gatewaypubkeys))).ToString().c_str()); - LOGSTREAM("gatewayscc", CCLOG_DEBUG1, stream << "f." << f << " M." << M << " of N." << N << " size." << (int32_t)gatewaypubkeys.size() << " -> " << depositaddr << std::endl); + LOGSTREAM("gatewayscc", CCLOG_DEBUG1, stream << "f." << f << " M." << (int)M << " of N." << (int)N << " size." << (int32_t)gatewaypubkeys.size() << " -> " << depositaddr << std::endl); } else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(gatewaypubkeys[0])) << OP_CHECKSIG); } else @@ -600,7 +601,7 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],K,M,N,taddr,prefix,prefix2,wiftype; - char str[65],destaddr[64],depositaddr[65],validationError[512]; + char str[65],destaddr[65],depositaddr[65],gatewaystokensaddr[65],validationError[512]; std::vector txids; std::vector pubkeys,publishers,tmppublishers; std::vector proof; int64_t fullsupply,totalsupply,amount,tmpamount; uint256 hashblock,txid,bindtxid,deposittxid,withdrawtxid,completetxid,tokenid,tmptokenid,oracletxid,bindtokenid,cointxid,tmptxid,merkleroot,mhash; CTransaction bindtx,tmptx; std::string refcoin,tmprefcoin,hex,name,description,format; CPubKey pubkey,tmppubkey,gatewayspk; @@ -619,7 +620,8 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // } // else // { - gatewayspk = GetUnspendable(cp,0); + gatewayspk = GetUnspendable(cp,0); + GetTokensCCaddress(cp, gatewaystokensaddr, gatewayspk); if ( (funcid = DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)) != 0) { switch ( funcid ) @@ -628,14 +630,14 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & //vin.0: normal input //vin.1: CC input of tokens //vout.0: CC vout of gateways tokens to gateways tokens CC address - //vout.1: CC vout txfee marker + //vout.1: CC vout marker //vout.n-1: opreturn - 'B' tokenid coin totalsupply oracletxid M N pubkeys taddr prefix prefix2 wiftype return eval->Invalid("unexpected GatewaysValidate for gatewaysbind!"); break; case 'D': //vin.0: normal input - //vout.0: CC vout txfee marker to destination pubkey - //vout.1: normal output txfee marker to txidaddr + //vout.0: CC vout marker to destination pubkey + //vout.1: normal output marker to txidaddr //vout.n-1: opreturn - 'D' bindtxid coin publishers txids height cointxid claimvout deposithex proof destpub amount return eval->Invalid("unexpected GatewaysValidate for gatewaysdeposit!"); break; @@ -647,19 +649,19 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & //vout.1: CC vout change of gateways tokens to gateways tokens CC address (if any) //vout.n-1: opreturn - 'C' tokenid bindtxid coin deposittxid destpub amount if ((numvouts=tx.vout.size()) < 1 || DecodeGatewaysClaimOpRet(tx.vout[numvouts-1].scriptPubKey,tmptokenid,bindtxid,refcoin,deposittxid,pubkey,amount)!='C') - return eval->Invalid("invalid gatewaysClaim OP_RETURN data!"); - else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) - return eval->Invalid("vin.0 is normal for gatewaysClaim!"); - else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) - return eval->Invalid("vin.1 is CC for gatewaysClaim!"); - else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) - return eval->Invalid("vin.2 is CC for gatewaysClaim!"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.0 is CC for gatewaysClaim!"); + return eval->Invalid("invalid gatewaysclaim OP_RETURN data!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); + else if ( IsCCInput(tmptx.vin[0].scriptSig) != 0 ) + return eval->Invalid("vin.0 is normal for gatewaysbind!"); + else if ( IsCCInput(tmptx.vin[1].scriptSig) == 0 ) + return eval->Invalid("vin.1 is CC for gatewaysbind!"); + else if ( ConstrainVout(tmptx.vout[0],1,gatewaystokensaddr,totalsupply)==0) + return eval->Invalid("invalid tokens to gateways vout for gatewaysbind!"); + else if ( ConstrainVout(tmptx.vout[1],1,cp->unspendableCCaddr,CC_MARKER_VALUE)==0) + return eval->Invalid("invalid marker vout for gatewaysbind!"); else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (tmptokenid!=tokenid) @@ -697,6 +699,12 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & return eval->Invalid("invalid gatewaysdeposittxid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysDepositOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptxid,tmprefcoin,tmppublishers,txids,height,cointxid,claimvout,hex,proof,tmppubkey,tmpamount) != 'D') return eval->Invalid("invalid gatewaysdeposit OP_RETURN data!"); + else if ( IsCCInput(tmptx.vin[0].scriptSig) != 0 ) + return eval->Invalid("vin.0 is normal for gatewaysdeposit!"); + else if ( GetCCaddress(cp,destaddr,tmppubkey)==0 || ConstrainVout(tmptx.vout[0],1,destaddr,CC_MARKER_VALUE)==0) + return eval->Invalid("invalid CC marker vout for gatewaysdeposit!"); + else if ( CCtxidaddr(destaddr,cointxid)==CPubKey() || ConstrainVout(tmptx.vout[1],0,destaddr,CC_MARKER_VALUE)==0) + return eval->Invalid("invalid normal marker vout for gatewaysdeposit!"); else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in deposit tx"); else if (bindtxid!=tmptxid) @@ -705,6 +713,18 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & return eval->Invalid("deposit amount greater then bind total supply"); else if (komodo_txnotarizedconfirmed(deposittxid) == false) return eval->Invalid("gatewaysdeposit tx is not yet confirmed(notarised)!"); + else if (myGetTransaction(tx.vin[2].prevout.hash,tmptx,hashblock) == 0) + return eval->Invalid("invalid gatewaysdeposittxid!"); + else if (IsCCInput(tx.vin[0].scriptSig) != 0) + return eval->Invalid("vin.0 is normal for gatewaysclaim!"); + else if (IsCCInput(tx.vin[1].scriptSig) == 0) + return eval->Invalid("vin.1 is CC for gatewaysclaim!"); + else if ((*cp->ismyvin)(tx.vin[2].scriptSig) == 0 || myGetTransaction(tx.vin[2].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[2].prevout.n].nValue!=CC_MARKER_VALUE) + return eval->Invalid("vin.2 is CC marker for gatewaysclaim or invalid marker amount!"); + else if (_GetCCaddress(destaddr,EVAL_TOKENS,pubkey)==0 || ConstrainVout(tx.vout[0],1,destaddr,amount)==0) + return eval->Invalid("invalid vout tokens to destpub for gatewaysclaim!"); + else if (numvouts>2 && (myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || ConstrainVout(tx.vout[1],1,gatewaystokensaddr,tmptx.vout[tx.vin[1].prevout.n].nValue-amount)==0)) + return eval->Invalid("invalid CC change vout for gatewaysclaim!"); else if (amount!=tmpamount) return eval->Invalid("claimed amount different then deposit amount"); else if (tx.vout[0].nValue!=amount) @@ -739,7 +759,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & case 'W': //vin.0: normal input //vin.1: CC input of tokens - //vout.0: CC vout txfee marker to gateways CC address + //vout.0: CC vout marker to gateways CC address //vout.1: CC vout of gateways tokens back to gateways tokens CC address //vout.2: CC vout change of tokens back to owners pubkey (if any) //vout.n-1: opreturn - 'W' tokenid bindtxid refcoin withdrawpub amount @@ -748,16 +768,10 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & case 'P': //vin.0: normal input //vin.1: CC input of marker from previous tx (withdraw or partialsing) - //vout.0: CC vout txfee marker to gateways CC address + //vout.0: CC vout marker to gateways CC address //vout.n-1: opreturn - 'P' withdrawtxid refcoin number_of_signs mypk hex if ((numvouts=tx.vout.size()) > 0 && DecodeGatewaysPartialOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,refcoin,K,pubkey,hex)!='P') - return eval->Invalid("invalid gatewaysPartialSign OP_RETURN data!"); - else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) - return eval->Invalid("vin.0 is normal for gatewaysPartialSign!"); - else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) - return eval->Invalid("vin.1 is CC for gatewaysPartialSign!"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.0 is CC for gatewaysPartialSign!"); + return eval->Invalid("invalid gatewaysPartialSign OP_RETURN data!"); else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid withdraw txid!"); else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptokenid,bindtxid,tmprefcoin,pubkey,amount)!='W') @@ -768,10 +782,10 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & return eval->Invalid("vin.0 is normal for gatewaysWithdraw!"); else if ( IsCCInput(tmptx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for gatewaysWithdraw!"); - else if ( tmptx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.0 is CC for gatewaysWithdraw!"); - else if ( tmptx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.1 is CC for gatewaysWithdraw!"); + else if ( ConstrainVout(tmptx.vout[0],1,cp->unspendableCCaddr,CC_MARKER_VALUE)==0) + return eval->Invalid("invalid marker vout for gatewaysWithdraw!"); + else if ( ConstrainVout(tmptx.vout[1],1,gatewaystokensaddr,amount)==0) + return eval->Invalid("invalid tokens to gateways vout for gatewaysWithdraw!"); else if (tmptx.vout[1].nValue!=amount) return eval->Invalid("amount in opret not matching tx tokens amount!"); else if (komodo_txnotarizedconfirmed(withdrawtxid) == false) @@ -785,23 +799,23 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptokenid!=tokenid) return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (komodo_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + else if (IsCCInput(tx.vin[0].scriptSig) != 0) + return eval->Invalid("vin.0 is normal for gatewayspartialsign!"); + else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) + return eval->Invalid("vin.1 is CC marker for gatewayspartialsign or invalid marker amount!"); + else if (ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,CC_MARKER_VALUE) == 0 ) + return eval->Invalid("vout.0 invalid marker for gatewayspartialsign!"); else if (K>M) return eval->Invalid("invalid number of signs!"); break; case 'S': //vin.0: normal input //vin.1: CC input of marker from previous tx (withdraw or partialsing) - //vout.0: CC vout txfee marker to gateways CC address + //vout.0: CC vout marker to gateways CC address //vout.n-1: opreturn - 'S' withdrawtxid refcoin hex if ((numvouts=tx.vout.size()) > 0 && DecodeGatewaysCompleteSigningOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,refcoin,K,hex)!='S') return eval->Invalid("invalid gatewayscompletesigning OP_RETURN data!"); - else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) - return eval->Invalid("vin.0 is normal for gatewayscompletesigning!"); - else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) - return eval->Invalid("vin.1 is CC for gatewayscompletesigning!"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.0 is CC for gatewayscompletesigning!"); else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid withdraw txid!"); else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptokenid,bindtxid,tmprefcoin,pubkey,amount)!='W') @@ -812,10 +826,10 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & return eval->Invalid("vin.0 is normal for gatewaysWithdraw!"); else if ( IsCCInput(tmptx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for gatewaysWithdraw!"); - else if ( tmptx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.0 is CC for gatewaysWithdraw!"); - else if ( tmptx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.1 is CC for gatewaysWithdraw!"); + else if ( ConstrainVout(tmptx.vout[0],1,cp->unspendableCCaddr,CC_MARKER_VALUE)==0) + return eval->Invalid("invalid marker vout for gatewaysWithdraw!"); + else if ( ConstrainVout(tmptx.vout[1],1,gatewaystokensaddr,amount)==0) + return eval->Invalid("invalid tokens to gateways vout for gatewaysWithdraw!"); else if (tmptx.vout[1].nValue!=amount) return eval->Invalid("amount in opret not matching tx tokens amount!"); else if (komodo_txnotarizedconfirmed(withdrawtxid) == false) @@ -829,21 +843,22 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptokenid!=tokenid) return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (komodo_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + else if (IsCCInput(tx.vin[0].scriptSig) != 0) + return eval->Invalid("vin.0 is normal for gatewayscompletesigning!"); + else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) + return eval->Invalid("vin.1 is CC marker for gatewayscompletesigning or invalid marker amount!"); + else if (ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,CC_MARKER_VALUE) == 0 ) + return eval->Invalid("vout.0 invalid marker for gatewayscompletesigning!"); else if (KInvalid("invalid number of signs!"); break; case 'M': - //vin.0: CC input of gatewayscompletesigning tx marker to gateways CC address + //vin.0: normal input + //vin.1: CC input of gatewayscompletesigning tx marker to gateways CC address //vout.0: opreturn - 'M' withdrawtxid refcoin completetxid if ((numvouts=tx.vout.size()) > 0 && DecodeGatewaysMarkDoneOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,refcoin,completetxid)!='M') - return eval->Invalid("invalid gatewaysmarkdone OP_RETURN data!"); - else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) - return eval->Invalid("vin.0 is normal for gatewaysmarkdone!"); - else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) - return eval->Invalid("vin.1 is CC for gatewaysmarkdone!"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 ) - return eval->Invalid("vout.0 is normal for gatewaysmarkdone!"); + return eval->Invalid("invalid gatewaysmarkdone OP_RETURN data!"); else if (myGetTransaction(completetxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewayscompletesigning txid!"); else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysCompleteSigningOpRet(tmptx.vout[numvouts-1].scriptPubKey,withdrawtxid,tmprefcoin,K,hex)!='S') @@ -867,7 +882,11 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptokenid!=tokenid) return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (komodo_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) + return eval->Invalid("vin.0 is normal for gatewaysmarkdone!"); + else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) + return eval->Invalid("vin.1 is CC marker for gatewaysmarkdone or invalid marker amount!"); else if (KInvalid("invalid number of signs!"); break; @@ -907,29 +926,17 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { funcid=DecodeGatewaysOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey); - if (vout==0 && funcid=='B' && bindtxid==txid && total != 0 && maxinputs != 0) + if ((vout==0 && funcid=='B' && bindtxid==txid && total != 0 && maxinputs != 0) || + (vout==1 && funcid=='W' && DecodeGatewaysWithdrawOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,tmptokenid,tmpbindtxid,tmprefcoin,withdrawpub,amount) == 'W' && + tmpbindtxid==bindtxid && tmprefcoin==refcoin && tmptokenid==tokenid && total != 0 && maxinputs != 0) || + (vout==1 && funcid=='C' && DecodeGatewaysClaimOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,tmptokenid,tmpbindtxid,tmprefcoin,deposittxid,destpub,amount) == 'C' && + tmpbindtxid==bindtxid && tmprefcoin==refcoin && tmptokenid==tokenid && total != 0 && maxinputs != 0)) { mtx.vin.push_back(CTxIn(txid,vout,CScript())); totalinputs += it->second.satoshis; n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) break; - } - else if (vout==1 && funcid=='W' && DecodeGatewaysWithdrawOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,tmptokenid,tmpbindtxid,tmprefcoin,withdrawpub,amount) == 'W' && - tmpbindtxid==bindtxid && tmprefcoin==refcoin && tmptokenid==tokenid && total != 0 && maxinputs != 0) - { - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - totalinputs += it->second.satoshis; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) break; - } - else if (vout==1 && funcid=='C' && DecodeGatewaysClaimOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,tmptokenid,tmpbindtxid,tmprefcoin,deposittxid,destpub,amount) == 'C' && - tmpbindtxid==bindtxid && tmprefcoin==refcoin && tmptokenid==tokenid && total != 0 && maxinputs != 0) - { - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - totalinputs += it->second.satoshis; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) break; - } + } } } return(totalinputs); @@ -1033,12 +1040,12 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) + if ( AddNormalinputs(mtx,mypk,txfee+CC_MARKER_VALUE,3) > 0 ) { if (AddTokenCCInputs(cpTokens, mtx, mypk, tokenid, totalsupply, 64)>0) { mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,totalsupply,gatewayspk)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,gatewayspk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CC_MARKER_VALUE,gatewayspk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysBindOpRet('B',tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype))); } } @@ -1112,10 +1119,10 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - if ( AddNormalinputs(mtx,mypk,3*txfee,4) > 0 ) + if ( AddNormalinputs(mtx,mypk,txfee+2*CC_MARKER_VALUE,4) > 0 ) { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,destpub)); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,cointxid))) << OP_CHECKSIG)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CC_MARKER_VALUE,destpub)); + mtx.vout.push_back(CTxOut(CC_MARKER_VALUE,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,cointxid))) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysDepositOpRet('D',bindtxid,coin,publishers,txids,height,cointxid,claimvout,deposithex,proof,destpub,amount))); } CCerror = strprintf("cant find enough inputs"); @@ -1262,12 +1269,12 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin } } } - if( AddNormalinputs(mtx, mypk, 3*txfee, 4) > 0 ) + if( AddNormalinputs(mtx, mypk, txfee+CC_MARKER_VALUE, 4) > 0 ) { if ((inputs = AddTokenCCInputs(cpTokens, mtx, mypk, tokenid, amount, 60)) > 0) { if ( inputs > amount ) CCchange = (inputs - amount); - mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,txfee,gatewayspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CC_MARKER_VALUE,gatewayspk)); mtx.vout.push_back(MakeTokensCC1vout(EVAL_GATEWAYS,amount,gatewayspk)); if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); return(FinalizeCCTx(0, cpTokens, mtx, mypk, txfee,EncodeGatewaysWithdrawOpRet('W',tokenid,bindtxid,refcoin,withdrawpub,amount))); @@ -1377,7 +1384,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc if (AddNormalinputs(mtx,mypk,txfee,3)!=0) { mtx.vin.push_back(CTxIn(tx.GetHash(),0,CScript())); - mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,txfee,gatewayspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CC_MARKER_VALUE,gatewayspk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysPartialOpRet('P',withdrawtxid,refcoin,K+1,mypk,hex))); } CCerror = strprintf("error adding funds for partialsign"); @@ -1476,7 +1483,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string if (AddNormalinputs(mtx,mypk,txfee,3)!=0) { mtx.vin.push_back(CTxIn(lasttxid,0,CScript())); - mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,txfee,gatewayspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CC_MARKER_VALUE,gatewayspk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysCompleteSigningOpRet('S',withdrawtxid,refcoin,K+1,hex))); } CCerror = strprintf("error adding funds for completesigning"); @@ -1541,7 +1548,7 @@ std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string ref if (AddNormalinputs(mtx,mypk,txfee,3)!=0) { mtx.vin.push_back(CTxIn(completetxid,0,CScript())); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(CC_MARKER_VALUE,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysMarkDoneOpRet('M',withdrawtxid,refcoin,completetxid))); } CCerror = strprintf("error adding funds for markdone"); From 80085d9d390de918412418dff05e64121b55b8aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:38:25 -1100 Subject: [PATCH 038/111] Fund --- src/cc/gamescc.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/cc/gamescc.h | 2 ++ src/cc/tetris.c | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 367c8d96e..a361b43ba 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1443,5 +1443,42 @@ UniValue games_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } +UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); std::string rawtx; int64_t amount,inputsum; CPubKey gamespk,mypk; std::vector opret; + if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 ) + { + amount = jdouble(jitem(params,1),0) * COIN + 0.0000000049; + gamespk = GetUnspendable(cp,0); + mypk = pubkey2pk(Mypubkey()); + if ( amount > GAMES_TXFEE ) + { + if ( (inputsum= AddNormalinputs(mtx,mypk,amount+GAMES_TXFEE,64)) >= amount+GAMES_TXFEE ) + { + mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,amount,gamespk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,GAMES_TXFEE,opret); + return(games_rawtxresult(result,rawtx,1)); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough funds")); + } + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","amount too small")); + } + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt parse")); + } + return(result); +} + #endif diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 6ec5dc9c4..a61b07564 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -33,6 +33,7 @@ std::string Games_pname; #define RPC_FUNCS \ { (char *)MYCCNAME, (char *)"rng", (char *)"hash,playerid", 1, 2, ' ', EVAL_GAMES }, \ { (char *)MYCCNAME, (char *)"rngnext", (char *)"seed", 1, 1, ' ', EVAL_GAMES }, \ + { (char *)MYCCNAME, (char *)"fund", (char *)"amount", 1, 1, ' ', EVAL_GAMES }, \ { (char *)MYCCNAME, (char *)"players", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \ { (char *)MYCCNAME, (char *)"games", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \ { (char *)MYCCNAME, (char *)"pending", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \ @@ -49,6 +50,7 @@ std::string Games_pname; 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_rngnext(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue games_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue games_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue games_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 3047e0e55..fe042d28c 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -811,7 +811,7 @@ int tetris(int argc, char **argv) #endif // _WIN32 rs->seed = rs->origseed; strcpy(Gametxidstr,argv[2]); - fprintf(stderr,"setplayerdata\n"); + fprintf(stderr,"setplayerdata %s\n",Gametxidstr); if ( games_setplayerdata(rs,Gametxidstr) < 0 ) { fprintf(stderr,"invalid gametxid, or already started\n"); From 84023b1540678bd5bb3be354295ff6b2e58177b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:40:55 -1100 Subject: [PATCH 039/111] Script --- src/cc/gamescc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index a361b43ba..41e571c15 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1446,8 +1446,8 @@ UniValue games_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx; int64_t amount,inputsum; CPubKey gamespk,mypk; std::vector opret; - if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 ) + UniValue result(UniValue::VOBJ); std::string rawtx; int64_t amount,inputsum; CPubKey gamespk,mypk; CScript opret; + if ( params != 0 && cJSON_GetArraySize(params) == 1 ) { amount = jdouble(jitem(params,1),0) * COIN + 0.0000000049; gamespk = GetUnspendable(cp,0); From e954ca48c7df58953263d5affaf1bd805686a795 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:42:56 -1100 Subject: [PATCH 040/111] Enable fund --- src/cc/gamescc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index a61b07564..e3bd15ea7 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -95,6 +95,8 @@ if ( cp->evalcode == EVAL_GAMES ) \ return(games_extract(txfee,cp,params)); \ else if ( strcmp(method,"finish") == 0 ) \ return(games_finish(txfee,cp,params)); \ + else if ( strcmp(method,"fund") == 0 ) \ + return(games_fund(txfee,cp,params)); \ else \ { \ result.push_back(Pair("result","error")); \ From 62731f9972a0a88c9b7702bbb7d4ca6bb833c6ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:44:39 -1100 Subject: [PATCH 041/111] params0 --- src/cc/gamescc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 41e571c15..9be6426ea 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1449,7 +1449,7 @@ UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue result(UniValue::VOBJ); std::string rawtx; int64_t amount,inputsum; CPubKey gamespk,mypk; CScript opret; if ( params != 0 && cJSON_GetArraySize(params) == 1 ) { - amount = jdouble(jitem(params,1),0) * COIN + 0.0000000049; + amount = jdouble(jitem(params,0),0) * COIN + 0.0000000049; gamespk = GetUnspendable(cp,0); mypk = pubkey2pk(Mypubkey()); if ( amount > GAMES_TXFEE ) From fc3753d23b96782459aab4663a8543f6713b6a66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:50:45 -1100 Subject: [PATCH 042/111] +print --- src/cc/gamescc.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 9be6426ea..5ac8fc5c7 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1457,6 +1457,11 @@ UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( (inputsum= AddNormalinputs(mtx,mypk,amount+GAMES_TXFEE,64)) >= amount+GAMES_TXFEE ) { mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,amount,gamespk)); + { + char destaddr[64]; + GetScriptaddress(destaddr,mtx.vout[0].scriptPubKey); + fprintf(stderr,"destaddr.(%s) %d\n",destaddr,cp->evalcode); + } rawtx = FinalizeCCTx(0,cp,mtx,mypk,GAMES_TXFEE,opret); return(games_rawtxresult(result,rawtx,1)); } From 00e6b83927e172ca8204778e800c4059d0bc9e8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:51:19 -1100 Subject: [PATCH 043/111] Fix --- src/cc/gamescc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 5ac8fc5c7..2f48a2c3c 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1456,7 +1456,8 @@ UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { if ( (inputsum= AddNormalinputs(mtx,mypk,amount+GAMES_TXFEE,64)) >= amount+GAMES_TXFEE ) { - mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,amount,gamespk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,gamespk)); + if ( 0 ) { char destaddr[64]; GetScriptaddress(destaddr,mtx.vout[0].scriptPubKey); From f3c31104f7b62483bd1bfbe76e107a870128df34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 03:51:35 -1100 Subject: [PATCH 044/111] Test --- src/cc/gamescc.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 2f48a2c3c..2f5c031c5 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1457,12 +1457,6 @@ UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( (inputsum= AddNormalinputs(mtx,mypk,amount+GAMES_TXFEE,64)) >= amount+GAMES_TXFEE ) { mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,gamespk)); - if ( 0 ) - { - char destaddr[64]; - GetScriptaddress(destaddr,mtx.vout[0].scriptPubKey); - fprintf(stderr,"destaddr.(%s) %d\n",destaddr,cp->evalcode); - } rawtx = FinalizeCCTx(0,cp,mtx,mypk,GAMES_TXFEE,opret); return(games_rawtxresult(result,rawtx,1)); } From 4b5da75d7da26636917cc757d3f01932505e96f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 04:10:41 -1100 Subject: [PATCH 045/111] Fix gameloop --- src/cc/tetris.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index fe042d28c..d09116881 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -724,11 +724,11 @@ void *gamesiterate(struct games_state *rs) c = 'j'; break; } - if ( c < 0 || skipcount == 0x7f ) + if ( c >= 0 || skipcount == 0x7f ) { if ( skipcount > 0 ) issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x80); - if ( c != -1 ) + if ( c >= 0 ) issue_games_events(rs,Gametxidstr,eventid,c); skipcount = 0; } else skipcount++; From b4043bc6bb0c58cb6ee7d0cc33cdc1f2d5ac6bed Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 04:17:43 -1100 Subject: [PATCH 046/111] Scrub vals --- src/cc/dapps/dappstd.c | 15 +++++++++++++++ src/cc/tetris.c | 20 +++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 0f3d8cc24..267335b05 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -1040,6 +1040,21 @@ char games_readchar(struct games_state *rs) if ( rs == 0 || rs->guiflag != 0 ) { ch = (char) getch(); + switch ( ch ) + { + case KEY_LEFT: + c = 'h'; + break; + case KEY_RIGHT: + c = 'l'; + break; + case KEY_UP: + c = 'k'; + break; + case KEY_DOWN: + c = 'j'; + break; + } if (ch == 3) { //_quit(); diff --git a/src/cc/tetris.c b/src/cc/tetris.c index d09116881..5ddb10ca4 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -299,9 +299,11 @@ static void tg_handle_move(struct games_state *rs,tetris_game *obj, tetris_move { switch (move) { case TM_LEFT: + fprintf(stderr,"LEFT "); tg_move(obj, -1); break; case TM_RIGHT: + fprintf(stderr,"RIGHT "); tg_move(obj, 1); break; case TM_DROP: @@ -644,8 +646,7 @@ int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eve char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; if ( fp == 0 ) fp = fopen("events.log","wb"); - sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,gametxidstr,eventid); - rs->buffered[rs->num++] = c; + sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c&0xff,gametxidstr,eventid); if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) @@ -709,21 +710,6 @@ void *gamesiterate(struct games_state *rs) doupdate(); sleep_milli(10); c = games_readchar(rs); - switch ( c ) - { - case KEY_LEFT: - c = 'h'; - break; - case KEY_RIGHT: - c = 'l'; - break; - case KEY_UP: - c = 'k'; - break; - case KEY_DOWN: - c = 'j'; - break; - } if ( c >= 0 || skipcount == 0x7f ) { if ( skipcount > 0 ) From 510689b9541daa870f0b136502ef663af755ab31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 04:18:59 -1100 Subject: [PATCH 047/111] Necroses --- src/cc/dapps/dappstd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 267335b05..80b651b45 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -22,6 +22,7 @@ #include #include #include +#include extern struct games_state globalR; void *gamesiterate(struct games_state *rs); From aeba5e4b071ce0a470bd007f084a417d1572a607 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 04:20:20 -1100 Subject: [PATCH 048/111] Fetch --- src/cc/dapps/dappstd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 80b651b45..a5ef379db 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -22,7 +22,6 @@ #include #include #include -#include extern struct games_state globalR; void *gamesiterate(struct games_state *rs); @@ -1012,7 +1011,7 @@ int32_t games_replay(uint64_t seed,int32_t sleeptime) char games_readchar(struct games_state *rs) { - char c,ch = -1; + char ch = -1; int32_t c; if ( rs != 0 && rs->guiflag == 0 ) { static uint32_t counter; @@ -1040,8 +1039,8 @@ char games_readchar(struct games_state *rs) } if ( rs == 0 || rs->guiflag != 0 ) { - ch = (char) getch(); - switch ( ch ) + c = getch(); + switch ( c ) { case KEY_LEFT: c = 'h'; @@ -1056,6 +1055,7 @@ char games_readchar(struct games_state *rs) c = 'j'; break; } + ch = c; if (ch == 3) { //_quit(); @@ -1065,7 +1065,7 @@ char games_readchar(struct games_state *rs) { if ( rs->num < sizeof(rs->buffered) ) { - rs->buffered[rs->num++] = ch; + rs->buffered[rs->num++] = c; if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) { rs->needflush = (uint32_t)time(NULL); @@ -1075,7 +1075,7 @@ char games_readchar(struct games_state *rs) } else fprintf(stderr,"buffer filled without flushed\n"); } } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); - return(ch); + return(c); } int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) From e96b3bf96ae29acd188baa7f336313c8e48c9d9e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 04:34:08 -1100 Subject: [PATCH 049/111] Gamesevent --- src/cc/dapps/dappstd.c | 43 +++++++++++++++++++++++++----------------- src/cc/tetris.c | 18 +++++++++--------- src/cc/tetris.cpp | 6 +++--- src/cc/tetris.h | 8 +++++--- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index a5ef379db..05f4fe332 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -249,7 +249,7 @@ int32_t safecopy(char *dest,char *src,long len) //#endif int32_t games_replay(uint64_t seed,int32_t sleeptime); -char *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter); +gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter); int GAMEMAIN(int argc, char **argv); @@ -735,9 +735,9 @@ int32_t games_sendrawtransaction(char *rawtx) return(retval); } -int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num) +int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,gamesevent *keystrokes,int32_t num) { - char cmd[16384],hexstr[16384],params[32768],*retstr,*errstr,*rawtx,*pastkeys,*keys; int32_t i,len,numpastkeys,retflag = -1; cJSON *retjson,*resobj; uint8_t *pastcmp; + char cmd[16384],hexstr[16384],params[32768],*retstr,*errstr,*rawtx; int32_t i,len,retflag = -1; cJSON *retjson,*resobj; if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) { if ( rs->keystrokeshex != 0 ) @@ -757,9 +757,18 @@ int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,cha } free(rs->keystrokeshex), rs->keystrokeshex = 0; } + memset(hexstr,0,sizeof(hexstr)); for (i=0; iorigseed,rs->counter); if ( (fp= fopen(fname,"wb")) != 0 ) { - if ( fwrite(rs->buffered,1,rs->num,fp) == rs->num ) + if ( fwrite(rs->buffered,sizeof(*rs->buffered),rs->num,fp) == rs->num ) { rs->num = 0; retflag = 0; @@ -864,7 +873,7 @@ void games_bailout(struct games_state *rs) #endif #endif -int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) +int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) { struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; rs = (struct games_state *)calloc(1,sizeof(*rs)); @@ -930,9 +939,9 @@ long get_filesize(FILE *fp) return(fsize); } -char *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter) +gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter) { - char fname[1024],*keystrokes = 0; FILE *fp; long fsize; int32_t num = 0; + char fname[1024]; gamesevent *keystrokes = 0; FILE *fp; long fsize; int32_t num = 0; *numkeysp = 0; while ( 1 ) { @@ -946,7 +955,7 @@ char *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter) //printf("fsize.%ld\n",fsize); break; } - if ( (keystrokes= (char *)realloc(keystrokes,num+fsize)) == 0 ) + if ( (keystrokes= (char *)realloc(keystrokes,sizeof(*keystrokes)*(num+fsize))) == 0 ) { fprintf(stderr,"error reallocating keystrokes\n"); fclose(fp); @@ -983,7 +992,7 @@ void games_exit() int32_t games_replay(uint64_t seed,int32_t sleeptime) { - FILE *fp; char fname[1024]; char *keystrokes = 0; long fsize; int32_t i,num=0,counter = 0; struct games_state *rs; struct games_player P,*player = 0; + FILE *fp; char fname[1024]; gamesevent *keystrokes = 0; long fsize; int32_t i,num=0,counter = 0; struct games_state *rs; struct games_player P,*player = 0; if ( seed == 0 ) seed = 777; keystrokes = games_keystrokesload(&num,seed,counter); @@ -1009,15 +1018,15 @@ int32_t games_replay(uint64_t seed,int32_t sleeptime) return(num); } -char games_readchar(struct games_state *rs) +gamesevent games_readevent(struct games_state *rs) { - char ch = -1; int32_t c; + gamesevent ch = -1; int32_t c; if ( rs != 0 && rs->guiflag == 0 ) { static uint32_t counter; if ( rs->ind < rs->numkeys ) { - c = rs->keystrokes[rs->ind++]; + ch = rs->keystrokes[rs->ind++]; if ( 0 ) { static FILE *fp; static int32_t counter; @@ -1030,7 +1039,7 @@ char games_readchar(struct games_state *rs) counter++; } } - return(c); + return(ch); } if ( rs->replaydone != 0 && counter++ < 3 ) fprintf(stderr,"replay finished but readchar called\n"); @@ -1065,7 +1074,7 @@ char games_readchar(struct games_state *rs) { if ( rs->num < sizeof(rs->buffered) ) { - rs->buffered[rs->num++] = c; + rs->buffered[rs->num++] = ch; if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) { rs->needflush = (uint32_t)time(NULL); @@ -1075,7 +1084,7 @@ char games_readchar(struct games_state *rs) } else fprintf(stderr,"buffer filled without flushed\n"); } } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); - return(c); + return(ch); } int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 5ddb10ca4..048a701f5 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -640,13 +640,13 @@ void init_colors(void) */ #include "dapps/dappstd.c" -int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,char c) +int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,int16_t c) { static FILE *fp; char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; if ( fp == 0 ) fp = fopen("events.log","wb"); - sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c&0xff,gametxidstr,eventid); + sprintf(params,"[\"events\",\"17\",\"[%%22%04x%%22,%%22%s%%22,%u]\"]",c&0xffff,gametxidstr,eventid); if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) @@ -689,7 +689,7 @@ struct games_state globalR; void *gamesiterate(struct games_state *rs) { uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE; - int32_t c,skipcount=0; uint32_t eventid = 0; tetris_game *tg; + gamesevent c; uint16_t skipcount=0; uint32_t eventid = 0; tetris_game *tg; WINDOW *board, *next, *hold, *score; // Create windows for each section of the interface. tg = tg_create(rs,22, 10); @@ -709,11 +709,11 @@ void *gamesiterate(struct games_state *rs) if ( (counter++ % 5) == 0 ) doupdate(); sleep_milli(10); - c = games_readchar(rs); - if ( c >= 0 || skipcount == 0x7f ) + c = games_readevent(rs); + if ( c >= 0 || skipcount == 0x3fff ) { if ( skipcount > 0 ) - issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x80); + issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x4000); if ( c >= 0 ) issue_games_events(rs,Gametxidstr,eventid,c); skipcount = 0; @@ -723,10 +723,10 @@ void *gamesiterate(struct games_state *rs) { if ( skipcount == 0 ) { - c = games_readchar(rs); - if ( (c & 0x80) != 0 ) + c = games_readevent(rs); + if ( (c & 0x4000) == 0x4000 ) { - skipcount = (c & 0x7f); + skipcount = (c & 0x3fff); c = 'S'; } } diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index f9e4e167a..a20652012 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -42,9 +42,9 @@ int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector pay eventid |= (uint32_t)payload[len+33] << 8; eventid |= (uint32_t)payload[len+34] << 16; eventid |= (uint32_t)payload[len+35] << 24; - for (i=0; i Date: Tue, 26 Mar 2019 04:35:25 -1100 Subject: [PATCH 050/111] Gamesevent --- src/cc/dapps/dappstd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 05f4fe332..55ffb33be 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -767,7 +767,7 @@ int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,gam else if ( sizeof(gamesevent) == 4 ) sprintf(&hexstr[i<<3],"%08x",keystrokes[i]&0xffffffff); else if ( sizeof(gamesevent) == 8 ) - sprintf(&hexstr[i<<4],"%016x",keystrokes[i]&0xffffffffffffffff); + sprintf(&hexstr[i<<4],"%016x",(long long)(keystrokes[i]&0xffffffffffffffffLL)); } static FILE *fp; if ( fp == 0 ) @@ -955,7 +955,7 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter //printf("fsize.%ld\n",fsize); break; } - if ( (keystrokes= (char *)realloc(keystrokes,sizeof(*keystrokes)*(num+fsize))) == 0 ) + if ( (keystrokes= (gamesevent *)realloc(keystrokes,sizeof(*keystrokes)*(num+fsize))) == 0 ) { fprintf(stderr,"error reallocating keystrokes\n"); fclose(fp); From 297794b25367e2140aa5700edc8c0bd2ded736d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 04:36:01 -1100 Subject: [PATCH 051/111] Llx --- src/cc/dapps/dappstd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 55ffb33be..e120787bf 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -767,7 +767,7 @@ int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,gam else if ( sizeof(gamesevent) == 4 ) sprintf(&hexstr[i<<3],"%08x",keystrokes[i]&0xffffffff); else if ( sizeof(gamesevent) == 8 ) - sprintf(&hexstr[i<<4],"%016x",(long long)(keystrokes[i]&0xffffffffffffffffLL)); + sprintf(&hexstr[i<<4],"%016llx",(long long)(keystrokes[i]&0xffffffffffffffffLL)); } static FILE *fp; if ( fp == 0 ) From 4aed5b5b98c3a28924b7568d84cb803ee7c5a629 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 04:46:22 -1100 Subject: [PATCH 052/111] Uint check --- src/cc/tetris.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 048a701f5..6541d61e5 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -710,7 +710,7 @@ void *gamesiterate(struct games_state *rs) doupdate(); sleep_milli(10); c = games_readevent(rs); - if ( c >= 0 || skipcount == 0x3fff ) + if ( c <= 0x7f || skipcount == 0x3fff ) { if ( skipcount > 0 ) issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x4000); From 0642013b11d5083ad953a88bfbecba447021fccc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:02:16 -1100 Subject: [PATCH 053/111] Skip -1 --- src/cc/dapps/dappstd.c | 4 ++-- src/cc/tetris.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index e120787bf..4bd116235 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -1070,7 +1070,7 @@ gamesevent games_readevent(struct games_state *rs) //_quit(); return(27); } - if ( rs != 0 && rs->guiflag != 0 ) + /*if ( rs != 0 && rs->guiflag != 0 ) { if ( rs->num < sizeof(rs->buffered) ) { @@ -1082,7 +1082,7 @@ gamesevent games_readevent(struct games_state *rs) //sleep(3); } } else fprintf(stderr,"buffer filled without flushed\n"); - } + }*/ } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); return(ch); } diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 6541d61e5..19aa0467b 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -640,13 +640,21 @@ void init_colors(void) */ #include "dapps/dappstd.c" -int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,int16_t c) +int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,gamesevent c) { static FILE *fp; char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; if ( fp == 0 ) fp = fopen("events.log","wb"); - sprintf(params,"[\"events\",\"17\",\"[%%22%04x%%22,%%22%s%%22,%u]\"]",c&0xffff,gametxidstr,eventid); + rs->buffered[rs->num++] = c; + if ( sizeof(c) == 1 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c&0xff,gametxidstr,eventid); + else if ( sizeof(c) == 2 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%04x%%22,%%22%s%%22,%u]\"]",c&0xffff,gametxidstr,eventid); + else if ( sizeof(c) == 4 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c&0xffffffff,gametxidstr,eventid); + else if ( sizeof(c) == 8 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%016llx%%22,%%22%s%%22,%u]\"]",(long long)c,gametxidstr,eventid); if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) From bb97066b46ce6958b59a5df84eeced24070ded82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:15:09 -1100 Subject: [PATCH 054/111] replay2 --- src/cc/dapps/dappstd.c | 57 ------------------------------------------ src/cc/gamescc.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++ src/cc/tetris.cpp | 6 ++--- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 4bd116235..bac8cd50c 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -873,63 +873,6 @@ void games_bailout(struct games_state *rs) #endif #endif -int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) -{ - struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; - rs = (struct games_state *)calloc(1,sizeof(*rs)); - rs->seed = rs->origseed = seed; - rs->keystrokes = keystrokes; - rs->numkeys = num; - rs->sleeptime = sleepmillis * 1000; - if ( player != 0 ) - { - rs->P = *player; - rs->restoring = 1; - //fprintf(stderr,"restore player packsize.%d HP.%d\n",rs->P.packsize,rs->P.hitpoints); - if ( rs->P.packsize > MAXPACK ) - rs->P.packsize = MAXPACK; - } - globalR = *rs; - uint32_t starttime = (uint32_t)time(NULL); - ptr = gamesiterate(rs); - if ( 0 ) - { - fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime); - sleep(2); - starttime = (uint32_t)time(NULL); - for (i=0; i<10000; i++) - { - memset(rs,0,sizeof(*rs)); - rs->seed = rs->origseed = seed; - rs->keystrokes = keystrokes; - rs->numkeys = num; - rs->sleeptime = 0; - gamesiterate(rs); - } - fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL)-starttime); - sleep(3); - } - // extract playerdata - - /*if ( (fp= fopen("checkfile","wb")) != 0 ) - { - //save_file(rs,fp,0); - //fprintf(stderr,"gold.%d hp.%d strength.%d/%d level.%d exp.%d dungeon.%d data[%d]\n",rs->P.gold,rs->P.hitpoints,rs->P.strength&0xffff,rs->P.strength>>16,rs->P.level,rs->P.experience,rs->P.dungeonlevel,rs->playersize); - if ( newdata != 0 && rs->playersize > 0 ) - memcpy(newdata,rs->playerdata,rs->playersize); - }*/ - if ( ptr != 0 ) - { - // extract data from ptr - if ( newdata != 0 && rs->playersize > 0 ) - memcpy(newdata,rs->playerdata,rs->playersize); - free(ptr); - } - n = rs->playersize; - free(rs); - return(n); -} - long get_filesize(FILE *fp) { long fsize,fpos = ftell(fp); diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 2f5c031c5..31b33e2b5 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -31,6 +31,63 @@ 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]); } +int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) +{ + struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; + rs = (struct games_state *)calloc(1,sizeof(*rs)); + rs->seed = rs->origseed = seed; + rs->keystrokes = keystrokes; + rs->numkeys = num; + rs->sleeptime = sleepmillis * 1000; + if ( player != 0 ) + { + rs->P = *player; + rs->restoring = 1; + //fprintf(stderr,"restore player packsize.%d HP.%d\n",rs->P.packsize,rs->P.hitpoints); + if ( rs->P.packsize > MAXPACK ) + rs->P.packsize = MAXPACK; + } + globalR = *rs; + uint32_t starttime = (uint32_t)time(NULL); + ptr = gamesiterate(rs); + if ( 0 ) + { + fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime); + sleep(2); + starttime = (uint32_t)time(NULL); + for (i=0; i<10000; i++) + { + memset(rs,0,sizeof(*rs)); + rs->seed = rs->origseed = seed; + rs->keystrokes = keystrokes; + rs->numkeys = num; + rs->sleeptime = 0; + gamesiterate(rs); + } + fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL)-starttime); + sleep(3); + } + // extract playerdata + + /*if ( (fp= fopen("checkfile","wb")) != 0 ) + { + //save_file(rs,fp,0); + //fprintf(stderr,"gold.%d hp.%d strength.%d/%d level.%d exp.%d dungeon.%d data[%d]\n",rs->P.gold,rs->P.hitpoints,rs->P.strength&0xffff,rs->P.strength>>16,rs->P.level,rs->P.experience,rs->P.dungeonlevel,rs->playersize); + if ( newdata != 0 && rs->playersize > 0 ) + memcpy(newdata,rs->playerdata,rs->playersize); + }*/ + if ( ptr != 0 ) + { + // extract data from ptr + if ( newdata != 0 && rs->playersize > 0 ) + memcpy(newdata,rs->playerdata,rs->playersize); + free(ptr); + } + n = rs->playersize; + free(rs); + return(n); +} + #ifndef STANDALONE #include "tetris.cpp" // replace with game specific functions diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index a20652012..6a1269099 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -20,15 +20,15 @@ uint64_t games_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 // game specific code for daemon -void games_packitemstr(char *packitemstr,struct games_packitem *item) +/*void games_packitemstr(char *packitemstr,struct games_packitem *item) { sprintf(packitemstr,"not yet"); } int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) // replay in daemon { - return(-1); -} + return(0); +}*/ int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload) { From 2ed6eccec62b8c459c88f0d3f3bedbf25dcfb9b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:16:46 -1100 Subject: [PATCH 055/111] Test --- src/cc/gamescc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 31b33e2b5..d5ec503c9 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -14,8 +14,6 @@ ******************************************************************************/ #include "gamescc.h" -#include "tetris.c" // replace with game code - uint64_t _games_rngnext(uint64_t initseed) { @@ -88,6 +86,9 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 return(n); } +#include "tetris.c" // replace with game code + + #ifndef STANDALONE #include "tetris.cpp" // replace with game specific functions From d61a4c44cf1f00a739dd5da7e74c4ee5ff571d86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:17:56 -1100 Subject: [PATCH 056/111] Test --- src/cc/gamescc.cpp | 4 +--- src/cc/tetris.h | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index d5ec503c9..80f89332f 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -14,6 +14,7 @@ ******************************************************************************/ #include "gamescc.h" +#include "tetris.c" // replace with game code uint64_t _games_rngnext(uint64_t initseed) { @@ -86,9 +87,6 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 return(n); } -#include "tetris.c" // replace with game code - - #ifndef STANDALONE #include "tetris.cpp" // replace with game specific functions diff --git a/src/cc/tetris.h b/src/cc/tetris.h index 3c246a3bd..b2f2fbe04 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -193,8 +193,10 @@ struct games_state gamesevent buffered[5000],*keystrokes; uint8_t playerdata[1024]; }; +extern struct games_state globalR; uint64_t _games_rngnext(uint64_t initseed); +int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis); #endif From 32851ac12aa85f2a599ac6b13791f75304051720 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:24:33 -1100 Subject: [PATCH 057/111] Baton support for games event --- src/cc/gamescc.cpp | 17 +++++++++++------ src/cc/tetris.h | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 80f89332f..227b3c5ae 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -848,9 +848,9 @@ int64_t games_registrationbaton(CMutableTransaction &mtx,uint256 gametxid,CTrans return(0); } -int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **keystrokesp,int32_t &numkeys,int32_t ®slot,std::vector &playerdata,uint256 &batontxid,int32_t &batonvout,int64_t &batonvalue,int32_t &batonht,uint256 gametxid,CTransaction gametx,int32_t maxplayers,char *destaddr,int32_t &numplayers,std::string &symbol,std::string &pname) +int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gamesevent **keystrokesp,int32_t &numkeys,int32_t ®slot,std::vector &playerdata,uint256 &batontxid,int32_t &batonvout,int64_t &batonvalue,int32_t &batonht,uint256 gametxid,CTransaction gametx,int32_t maxplayers,char *destaddr,int32_t &numplayers,std::string &symbol,std::string &pname) { - int32_t i,numvouts,spentvini,n,matches = 0; CPubKey pk; uint256 tid,active,spenttxid,tokenid,hashBlock,txid,origplayergame; CTransaction spenttx,matchtx,batontx; std::vector checkdata; CBlockIndex *pindex; char ccaddr[64],*keystrokes=0; + int32_t i,numvouts,spentvini,n,matches = 0; CPubKey pk; uint256 tid,active,spenttxid,tokenid,hashBlock,txid,origplayergame; CTransaction spenttx,matchtx,batontx; std::vector checkdata; CBlockIndex *pindex; char ccaddr[64]; gamesevent *keystrokes=0; batonvalue = numkeys = numplayers = batonht = 0; playertxid = batontxid = zeroid; if ( keystrokesp != 0 ) @@ -913,10 +913,15 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke uint256 g,b; CPubKey p; std::vector k; if ( games_keystrokesopretdecode(g,b,p,k,spenttx.vout[spenttx.vout.size()-1].scriptPubKey) == 'K' ) { - keystrokes = (char *)realloc(keystrokes,numkeys + (int32_t)k.size()); + keystrokes = (char *)realloc(keystrokes,sizeof(*keystrokes)*(numkeys + (int32_t)k.size())); for (i=0; i 1% ingame gold // get any playerdata, get all keystrokes, replay game and compare final state CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); char *method = (char *)"bailout"; - UniValue result(UniValue::VOBJ); std::string rawtx,symbol,pname; CTransaction gametx; uint64_t seed; int64_t buyin,batonvalue,inputsum,cashout=0,CCchange=0; int32_t i,err,gameheight,tmp,numplayers,regslot,n,num,dungeonlevel,numkeys,maxplayers,batonht,batonvout; char mygamesaddr[64],*keystrokes = 0; std::vector playerdata,newdata,nodata; uint256 batontxid,playertxid,gametxid; CPubKey mypk,gamespk; uint8_t player[10000],mypriv[32],funcid; + UniValue result(UniValue::VOBJ); std::string rawtx,symbol,pname; CTransaction gametx; uint64_t seed; int64_t buyin,batonvalue,inputsum,cashout=0,CCchange=0; int32_t i,err,gameheight,tmp,numplayers,regslot,n,num,dungeonlevel,numkeys,maxplayers,batonht,batonvout; char mygamesaddr[64]; gamesevent *keystrokes = 0; std::vector playerdata,newdata,nodata; uint256 batontxid,playertxid,gametxid; CPubKey mypk,gamespk; uint8_t player[10000],mypriv[32],funcid; struct CCcontract_info *cpTokens, tokensC; if ( txfee == 0 ) diff --git a/src/cc/tetris.h b/src/cc/tetris.h index b2f2fbe04..94d56dbfc 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -194,7 +194,9 @@ struct games_state uint8_t playerdata[1024]; }; extern struct games_state globalR; +void *gamesiterate(struct games_state *rs); +void games_packitemstr(char *packitemstr,struct games_packitem *item); uint64_t _games_rngnext(uint64_t initseed); int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis); From 985e8a71273f48f85a7f9246b11ef74f0c1263d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:26:45 -1100 Subject: [PATCH 058/111] Test --- src/cc/gamescc.cpp | 1 + src/cc/tetris.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 227b3c5ae..7dc368d72 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -916,6 +916,7 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven keystrokes = (char *)realloc(keystrokes,sizeof(*keystrokes)*(numkeys + (int32_t)k.size())); for (i=0; i playerdata) } } -char *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vector &newdata,uint64_t &seed,uint256 &playertxid,struct CCcontract_info *cp,uint256 gametxid,char *gamesaddr) +gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vector &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 playerdata; uint256 batontxid; FILE *fp; uint8_t newplayer[10000]; struct games_player P,endP; + 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]; gamesevent *keystrokes = 0; std::vector playerdata; uint256 batontxid; FILE *fp; uint8_t newplayer[10000]; struct games_player P,endP; gamespk = GetUnspendable(cp,0); *numkeysp = 0; seed = 0; @@ -110,7 +110,7 @@ char *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vecto sprintf(fname,"%s.%llu.0",GAMENAME,(long long)seed); if ( (fp= fopen(fname,"wb")) != 0 ) { - if ( fwrite(keystrokes,1,numkeys,fp) != numkeys ) + if ( fwrite(keystrokes,sizeof(*keystrokes),numkeys,fp) != numkeys ) fprintf(stderr,"error writing %s\n",fname); fclose(fp); } From ce1a3197b2d933c7104dcfbf1abe7e617f82ebdf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:28:25 -1100 Subject: [PATCH 059/111] Test --- src/cc/tetris.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index 2ef048364..216d4c4d0 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -14,7 +14,7 @@ * * ******************************************************************************/ -int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **keystrokesp,int32_t &numkeys,int32_t ®slot,std::vector &playerdata,uint256 &batontxid,int32_t &batonvout,int64_t &batonvalue,int32_t &batonht,uint256 gametxid,CTransaction gametx,int32_t maxplayers,char *destaddr,int32_t &numplayers,std::string &symbol,std::string &pname); +int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gamesevent **keystrokesp,int32_t &numkeys,int32_t ®slot,std::vector &playerdata,uint256 &batontxid,int32_t &batonvout,int64_t &batonvalue,int32_t &batonht,uint256 gametxid,CTransaction gametx,int32_t maxplayers,char *destaddr,int32_t &numplayers,std::string &symbol,std::string &pname); int32_t games_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransaction &tx,int64_t &buyin,int32_t &maxplayers,uint256 txid,int32_t unspentv0); uint64_t games_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 gametxid,char *mygamesaddr); @@ -169,7 +169,7 @@ gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std: int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) { static uint32_t good,bad; static uint256 prevgame; - char str[512],*keystrokes,gamesaddr[64],str2[67],fname[64]; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed; CPubKey gamespk; struct games_player P; + char str[512],gamesaddr[64],str2[67],fname[64]; gamesevent *keystrokes; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed; CPubKey gamespk; struct games_player P; *cashoutp = 0; gamespk = GetUnspendable(cp,0); GetCCaddress1of2(cp,gamesaddr,gamespk,pk); From 6ce5d7f762bf9cc2115151b281695c42eb7ce9d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:31:50 -1100 Subject: [PATCH 060/111] Hexer --- src/cc/gamescc.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 7dc368d72..0f261a184 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -913,7 +913,7 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven uint256 g,b; CPubKey p; std::vector k; if ( games_keystrokesopretdecode(g,b,p,k,spenttx.vout[spenttx.vout.size()-1].scriptPubKey) == 'K' ) { - keystrokes = (char *)realloc(keystrokes,sizeof(*keystrokes)*(numkeys + (int32_t)k.size())); + keystrokes = (gamesevent *)realloc(keystrokes,sizeof(*keystrokes)*(numkeys + (int32_t)k.size())); for (i=0; i newdata; uint256 gametxid,playertxid; FILE *fp; uint8_t pub33[33]; + UniValue result(UniValue::VOBJ); CPubKey pk,gamespk; int32_t i,n,numkeys,flag = 0; uint64_t seed; char str[512],gamesaddr[64],*pubstr,*hexstr; gamesevent *keystrokes = 0; std::vector newdata; uint256 gametxid,playertxid; FILE *fp; uint8_t pub33[33]; pk = pubkey2pk(Mypubkey()); gamespk = GetUnspendable(cp,0); result.push_back(Pair("name","games")); @@ -1263,10 +1263,25 @@ UniValue games_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { result.push_back(Pair("status","success")); flag = 1; - hexstr = (char *)malloc(numkeys*2 + 1); + hexstr = (char *)calloc(1,sizeof(gamesevent)*numkeys*2 + 1); for (i=0; i Date: Tue, 26 Mar 2019 05:33:56 -1100 Subject: [PATCH 061/111] Link errors --- src/cc/tetris.c | 116 +++++++++++++++++++++++----------------------- src/cc/tetris.cpp | 4 +- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 19aa0467b..803d163fa 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -634,64 +634,6 @@ void init_colors(void) init_pair(TC_CELLZ, COLOR_RED, COLOR_BLACK); } -#ifdef STANDALONE -/* - Main tetris game! - */ -#include "dapps/dappstd.c" - -int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,gamesevent c) -{ - static FILE *fp; - char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; - if ( fp == 0 ) - fp = fopen("events.log","wb"); - rs->buffered[rs->num++] = c; - if ( sizeof(c) == 1 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c&0xff,gametxidstr,eventid); - else if ( sizeof(c) == 2 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%04x%%22,%%22%s%%22,%u]\"]",c&0xffff,gametxidstr,eventid); - else if ( sizeof(c) == 4 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c&0xffffffff,gametxidstr,eventid); - else if ( sizeof(c) == 8 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%016llx%%22,%%22%s%%22,%u]\"]",(long long)c,gametxidstr,eventid); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) - { - retval = 0; - if ( fp != 0 ) - { - fprintf(fp,"%s\n",jprint(resobj,0)); - fflush(fp); - } - } - free_json(retjson); - } else fprintf(fp,"error parsing %s\n",retstr); - free(retstr); - } else fprintf(fp,"error issuing method %s\n",params); - return(retval); -} - -char *clonestr(char *str) -{ - char *clone; int32_t len; - if ( str == 0 || str[0] == 0 ) - { - printf("warning cloning nullstr.%p\n",str); -#ifdef __APPLE__ - while ( 1 ) sleep(1); -#endif - str = (char *)""; - } - len = strlen(str); - clone = (char *)calloc(1,len+16); - strcpy(clone,str); - return(clone); -} - struct games_state globalR; void *gamesiterate(struct games_state *rs) @@ -785,6 +727,64 @@ void *gamesiterate(struct games_state *rs) return(tg); } +#ifdef STANDALONE +/* + Main tetris game! + */ +#include "dapps/dappstd.c" + +int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,gamesevent c) +{ + static FILE *fp; + char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; + if ( fp == 0 ) + fp = fopen("events.log","wb"); + rs->buffered[rs->num++] = c; + if ( sizeof(c) == 1 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c&0xff,gametxidstr,eventid); + else if ( sizeof(c) == 2 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%04x%%22,%%22%s%%22,%u]\"]",c&0xffff,gametxidstr,eventid); + else if ( sizeof(c) == 4 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c&0xffffffff,gametxidstr,eventid); + else if ( sizeof(c) == 8 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%016llx%%22,%%22%s%%22,%u]\"]",(long long)c,gametxidstr,eventid); + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) + { + retval = 0; + if ( fp != 0 ) + { + fprintf(fp,"%s\n",jprint(resobj,0)); + fflush(fp); + } + } + free_json(retjson); + } else fprintf(fp,"error parsing %s\n",retstr); + free(retstr); + } else fprintf(fp,"error issuing method %s\n",params); + return(retval); +} + +char *clonestr(char *str) +{ + char *clone; int32_t len; + if ( str == 0 || str[0] == 0 ) + { + printf("warning cloning nullstr.%p\n",str); +#ifdef __APPLE__ + while ( 1 ) sleep(1); +#endif + str = (char *)""; + } + len = strlen(str); + clone = (char *)calloc(1,len+16); + strcpy(clone,str); + return(clone); +} + int tetris(int argc, char **argv) { struct games_state *rs = &globalR; diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index 216d4c4d0..c2caaa8a9 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -19,12 +19,12 @@ int32_t games_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransa uint64_t games_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 gametxid,char *mygamesaddr); // game specific code for daemon - -/*void games_packitemstr(char *packitemstr,struct games_packitem *item) +void games_packitemstr(char *packitemstr,struct games_packitem *item) { sprintf(packitemstr,"not yet"); } +/* int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) // replay in daemon { return(0); From a10f3988eeb975f9d7319e22e0fe812478bf89ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:35:58 -1100 Subject: [PATCH 062/111] Test --- src/cc/tetris.c | 71 ++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 803d163fa..f6a4974c4 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -635,6 +635,43 @@ void init_colors(void) } struct games_state globalR; +gamesevent games_readevent(struct games_state *rs); +extern char Gametxidstr[]; + +int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,gamesevent c) +{ + static FILE *fp; + char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; + if ( fp == 0 ) + fp = fopen("events.log","wb"); + rs->buffered[rs->num++] = c; + if ( sizeof(c) == 1 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c&0xff,gametxidstr,eventid); + else if ( sizeof(c) == 2 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%04x%%22,%%22%s%%22,%u]\"]",c&0xffff,gametxidstr,eventid); + else if ( sizeof(c) == 4 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c&0xffffffff,gametxidstr,eventid); + else if ( sizeof(c) == 8 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%016llx%%22,%%22%s%%22,%u]\"]",(long long)c,gametxidstr,eventid); + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) + { + retval = 0; + if ( fp != 0 ) + { + fprintf(fp,"%s\n",jprint(resobj,0)); + fflush(fp); + } + } + free_json(retjson); + } else fprintf(fp,"error parsing %s\n",retstr); + free(retstr); + } else fprintf(fp,"error issuing method %s\n",params); + return(retval); +} void *gamesiterate(struct games_state *rs) { @@ -733,40 +770,6 @@ void *gamesiterate(struct games_state *rs) */ #include "dapps/dappstd.c" -int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,gamesevent c) -{ - static FILE *fp; - char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; - if ( fp == 0 ) - fp = fopen("events.log","wb"); - rs->buffered[rs->num++] = c; - if ( sizeof(c) == 1 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c&0xff,gametxidstr,eventid); - else if ( sizeof(c) == 2 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%04x%%22,%%22%s%%22,%u]\"]",c&0xffff,gametxidstr,eventid); - else if ( sizeof(c) == 4 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c&0xffffffff,gametxidstr,eventid); - else if ( sizeof(c) == 8 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%016llx%%22,%%22%s%%22,%u]\"]",(long long)c,gametxidstr,eventid); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) - { - retval = 0; - if ( fp != 0 ) - { - fprintf(fp,"%s\n",jprint(resobj,0)); - fflush(fp); - } - } - free_json(retjson); - } else fprintf(fp,"error parsing %s\n",retstr); - free(retstr); - } else fprintf(fp,"error issuing method %s\n",params); - return(retval); -} char *clonestr(char *str) { From 38bf6a68951aaf878ad881eae0812c704a5cfd3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:38:17 -1100 Subject: [PATCH 063/111] Fix --- src/cc/tetris.c | 74 +++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index f6a4974c4..3b330f5ca 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -635,43 +635,8 @@ void init_colors(void) } struct games_state globalR; -gamesevent games_readevent(struct games_state *rs); extern char Gametxidstr[]; - -int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,gamesevent c) -{ - static FILE *fp; - char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; - if ( fp == 0 ) - fp = fopen("events.log","wb"); - rs->buffered[rs->num++] = c; - if ( sizeof(c) == 1 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c&0xff,gametxidstr,eventid); - else if ( sizeof(c) == 2 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%04x%%22,%%22%s%%22,%u]\"]",c&0xffff,gametxidstr,eventid); - else if ( sizeof(c) == 4 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c&0xffffffff,gametxidstr,eventid); - else if ( sizeof(c) == 8 ) - sprintf(params,"[\"events\",\"17\",\"[%%22%016llx%%22,%%22%s%%22,%u]\"]",(long long)c,gametxidstr,eventid); - if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) - { - retval = 0; - if ( fp != 0 ) - { - fprintf(fp,"%s\n",jprint(resobj,0)); - fflush(fp); - } - } - free_json(retjson); - } else fprintf(fp,"error parsing %s\n",retstr); - free(retstr); - } else fprintf(fp,"error issuing method %s\n",params); - return(retval); -} +int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,gamesevent c); void *gamesiterate(struct games_state *rs) { @@ -689,6 +654,7 @@ void *gamesiterate(struct games_state *rs) running = tg_tick(rs,tg,move); if ( rs->guiflag != 0 ) { +#ifdef STANDALONE display_board(board,tg); display_piece(next,tg->next); display_piece(hold,tg->stored); @@ -705,6 +671,7 @@ void *gamesiterate(struct games_state *rs) issue_games_events(rs,Gametxidstr,eventid,c); skipcount = 0; } else skipcount++; +#endif } else { @@ -788,6 +755,41 @@ char *clonestr(char *str) return(clone); } +int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,gamesevent c) +{ + static FILE *fp; + char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; + if ( fp == 0 ) + fp = fopen("events.log","wb"); + rs->buffered[rs->num++] = c; + if ( sizeof(c) == 1 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c&0xff,gametxidstr,eventid); + else if ( sizeof(c) == 2 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%04x%%22,%%22%s%%22,%u]\"]",c&0xffff,gametxidstr,eventid); + else if ( sizeof(c) == 4 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%08x%%22,%%22%s%%22,%u]\"]",c&0xffffffff,gametxidstr,eventid); + else if ( sizeof(c) == 8 ) + sprintf(params,"[\"events\",\"17\",\"[%%22%016llx%%22,%%22%s%%22,%u]\"]",(long long)c,gametxidstr,eventid); + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) + { + retval = 0; + if ( fp != 0 ) + { + fprintf(fp,"%s\n",jprint(resobj,0)); + fflush(fp); + } + } + free_json(retjson); + } else fprintf(fp,"error parsing %s\n",retstr); + free(retstr); + } else fprintf(fp,"error issuing method %s\n",params); + return(retval); +} + int tetris(int argc, char **argv) { struct games_state *rs = &globalR; From 82c132b6fbc6ea6f97f737626e7ea226ac362c24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:38:58 -1100 Subject: [PATCH 064/111] gamesevent games_readevent(struct games_state *rs) --- src/cc/tetris.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 3b330f5ca..487566ed4 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -637,6 +637,7 @@ void init_colors(void) struct games_state globalR; extern char Gametxidstr[]; int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,gamesevent c); +gamesevent games_readevent(struct games_state *rs); void *gamesiterate(struct games_state *rs) { From 8ba50f49c8d7981d7530a8d725305f6f8636c28c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:41:31 -1100 Subject: [PATCH 065/111] Test --- src/cc/dapps/dappstd.c | 69 ------------------------------------------ src/cc/gamescc.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index bac8cd50c..3992cb80e 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -961,75 +961,6 @@ int32_t games_replay(uint64_t seed,int32_t sleeptime) return(num); } -gamesevent games_readevent(struct games_state *rs) -{ - gamesevent ch = -1; int32_t c; - if ( rs != 0 && rs->guiflag == 0 ) - { - static uint32_t counter; - if ( rs->ind < rs->numkeys ) - { - ch = rs->keystrokes[rs->ind++]; - if ( 0 ) - { - static FILE *fp; static int32_t counter; - if ( fp == 0 ) - fp = fopen("log","wb"); - if ( fp != 0 ) - { - fprintf(fp,"%d: (%c) seed.%llu\n",counter,c,(long long)rs->origseed); - fflush(fp); - counter++; - } - } - return(ch); - } - if ( rs->replaydone != 0 && counter++ < 3 ) - fprintf(stderr,"replay finished but readchar called\n"); - rs->replaydone = (uint32_t)time(NULL); - return(0); - } - if ( rs == 0 || rs->guiflag != 0 ) - { - c = getch(); - switch ( c ) - { - case KEY_LEFT: - c = 'h'; - break; - case KEY_RIGHT: - c = 'l'; - break; - case KEY_UP: - c = 'k'; - break; - case KEY_DOWN: - c = 'j'; - break; - } - ch = c; - if (ch == 3) - { - //_quit(); - return(27); - } - /*if ( rs != 0 && rs->guiflag != 0 ) - { - if ( rs->num < sizeof(rs->buffered) ) - { - rs->buffered[rs->num++] = ch; - if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) - { - rs->needflush = (uint32_t)time(NULL); - //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); - //sleep(3); - } - } else fprintf(stderr,"buffer filled without flushed\n"); - }*/ - } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); - return(ch); -} - int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) { char cmd[32768]; int32_t i,n,retval=-1; char params[1024],*filestr=0,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item,*resultjson; diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 0f261a184..b99c052ac 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -30,6 +30,75 @@ 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]); } +gamesevent games_readevent(struct games_state *rs) +{ + gamesevent ch = -1; int32_t c; + if ( rs != 0 && rs->guiflag == 0 ) + { + static uint32_t counter; + if ( rs->ind < rs->numkeys ) + { + ch = rs->keystrokes[rs->ind++]; + if ( 0 ) + { + static FILE *fp; static int32_t counter; + if ( fp == 0 ) + fp = fopen("log","wb"); + if ( fp != 0 ) + { + fprintf(fp,"%d: (%c) seed.%llu\n",counter,c,(long long)rs->origseed); + fflush(fp); + counter++; + } + } + return(ch); + } + if ( rs->replaydone != 0 && counter++ < 3 ) + fprintf(stderr,"replay finished but readchar called\n"); + rs->replaydone = (uint32_t)time(NULL); + return(0); + } + if ( rs == 0 || rs->guiflag != 0 ) + { + c = getch(); + switch ( c ) + { + case KEY_LEFT: + c = 'h'; + break; + case KEY_RIGHT: + c = 'l'; + break; + case KEY_UP: + c = 'k'; + break; + case KEY_DOWN: + c = 'j'; + break; + } + ch = c; + if (ch == 3) + { + //_quit(); + return(27); + } + /*if ( rs != 0 && rs->guiflag != 0 ) + { + if ( rs->num < sizeof(rs->buffered) ) + { + rs->buffered[rs->num++] = ch; + if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) + { + rs->needflush = (uint32_t)time(NULL); + //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); + //sleep(3); + } + } else fprintf(stderr,"buffer filled without flushed\n"); + }*/ + } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); + return(ch); +} + int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) { struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; From e34fc6b5108521078b0c4d934044aafa91937129 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:43:30 -1100 Subject: [PATCH 066/111] Linker fix --- src/cc/gamescc.cpp | 138 ++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index b99c052ac..2746e8097 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -30,75 +30,6 @@ 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]); } -gamesevent games_readevent(struct games_state *rs) -{ - gamesevent ch = -1; int32_t c; - if ( rs != 0 && rs->guiflag == 0 ) - { - static uint32_t counter; - if ( rs->ind < rs->numkeys ) - { - ch = rs->keystrokes[rs->ind++]; - if ( 0 ) - { - static FILE *fp; static int32_t counter; - if ( fp == 0 ) - fp = fopen("log","wb"); - if ( fp != 0 ) - { - fprintf(fp,"%d: (%c) seed.%llu\n",counter,c,(long long)rs->origseed); - fflush(fp); - counter++; - } - } - return(ch); - } - if ( rs->replaydone != 0 && counter++ < 3 ) - fprintf(stderr,"replay finished but readchar called\n"); - rs->replaydone = (uint32_t)time(NULL); - return(0); - } - if ( rs == 0 || rs->guiflag != 0 ) - { - c = getch(); - switch ( c ) - { - case KEY_LEFT: - c = 'h'; - break; - case KEY_RIGHT: - c = 'l'; - break; - case KEY_UP: - c = 'k'; - break; - case KEY_DOWN: - c = 'j'; - break; - } - ch = c; - if (ch == 3) - { - //_quit(); - return(27); - } - /*if ( rs != 0 && rs->guiflag != 0 ) - { - if ( rs->num < sizeof(rs->buffered) ) - { - rs->buffered[rs->num++] = ch; - if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) - { - rs->needflush = (uint32_t)time(NULL); - //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); - //sleep(3); - } - } else fprintf(stderr,"buffer filled without flushed\n"); - }*/ - } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); - return(ch); -} - int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) { struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; @@ -1628,3 +1559,72 @@ UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) #endif +gamesevent games_readevent(struct games_state *rs) +{ + gamesevent ch = -1; int32_t c; + if ( rs != 0 && rs->guiflag == 0 ) + { + static uint32_t counter; + if ( rs->ind < rs->numkeys ) + { + ch = rs->keystrokes[rs->ind++]; + if ( 0 ) + { + static FILE *fp; static int32_t counter; + if ( fp == 0 ) + fp = fopen("log","wb"); + if ( fp != 0 ) + { + fprintf(fp,"%d: (%c) seed.%llu\n",counter,c,(long long)rs->origseed); + fflush(fp); + counter++; + } + } + return(ch); + } + if ( rs->replaydone != 0 && counter++ < 3 ) + fprintf(stderr,"replay finished but readchar called\n"); + rs->replaydone = (uint32_t)time(NULL); + return(0); + } + if ( rs == 0 || rs->guiflag != 0 ) + { + c = getch(); + switch ( c ) + { + case KEY_LEFT: + c = 'h'; + break; + case KEY_RIGHT: + c = 'l'; + break; + case KEY_UP: + c = 'k'; + break; + case KEY_DOWN: + c = 'j'; + break; + } + ch = c; + if (ch == 3) + { + //_quit(); + return(27); + } + /*if ( rs != 0 && rs->guiflag != 0 ) + { + if ( rs->num < sizeof(rs->buffered) ) + { + rs->buffered[rs->num++] = ch; + if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) + { + rs->needflush = (uint32_t)time(NULL); + //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); + //sleep(3); + } + } else fprintf(stderr,"buffer filled without flushed\n"); + }*/ + } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); + return(ch); +} + From e495123a5d5611b32d5cf7ed594e7a05f3ca9e81 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:44:39 -1100 Subject: [PATCH 067/111] link --- src/cc/gamescc.cpp | 68 --------------------------------------------- src/cc/tetris.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 68 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 2746e8097..ad578400d 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1559,72 +1559,4 @@ UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) #endif -gamesevent games_readevent(struct games_state *rs) -{ - gamesevent ch = -1; int32_t c; - if ( rs != 0 && rs->guiflag == 0 ) - { - static uint32_t counter; - if ( rs->ind < rs->numkeys ) - { - ch = rs->keystrokes[rs->ind++]; - if ( 0 ) - { - static FILE *fp; static int32_t counter; - if ( fp == 0 ) - fp = fopen("log","wb"); - if ( fp != 0 ) - { - fprintf(fp,"%d: (%c) seed.%llu\n",counter,c,(long long)rs->origseed); - fflush(fp); - counter++; - } - } - return(ch); - } - if ( rs->replaydone != 0 && counter++ < 3 ) - fprintf(stderr,"replay finished but readchar called\n"); - rs->replaydone = (uint32_t)time(NULL); - return(0); - } - if ( rs == 0 || rs->guiflag != 0 ) - { - c = getch(); - switch ( c ) - { - case KEY_LEFT: - c = 'h'; - break; - case KEY_RIGHT: - c = 'l'; - break; - case KEY_UP: - c = 'k'; - break; - case KEY_DOWN: - c = 'j'; - break; - } - ch = c; - if (ch == 3) - { - //_quit(); - return(27); - } - /*if ( rs != 0 && rs->guiflag != 0 ) - { - if ( rs->num < sizeof(rs->buffered) ) - { - rs->buffered[rs->num++] = ch; - if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) - { - rs->needflush = (uint32_t)time(NULL); - //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); - //sleep(3); - } - } else fprintf(stderr,"buffer filled without flushed\n"); - }*/ - } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); - return(ch); -} diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 487566ed4..9808622f4 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -732,6 +732,75 @@ void *gamesiterate(struct games_state *rs) return(tg); } +gamesevent games_readevent(struct games_state *rs) +{ + gamesevent ch = -1; int32_t c; + if ( rs != 0 && rs->guiflag == 0 ) + { + static uint32_t counter; + if ( rs->ind < rs->numkeys ) + { + ch = rs->keystrokes[rs->ind++]; + if ( 0 ) + { + static FILE *fp; static int32_t counter; + if ( fp == 0 ) + fp = fopen("log","wb"); + if ( fp != 0 ) + { + fprintf(fp,"%d: (%c) seed.%llu\n",counter,c,(long long)rs->origseed); + fflush(fp); + counter++; + } + } + return(ch); + } + if ( rs->replaydone != 0 && counter++ < 3 ) + fprintf(stderr,"replay finished but readchar called\n"); + rs->replaydone = (uint32_t)time(NULL); + return(0); + } + if ( rs == 0 || rs->guiflag != 0 ) + { + c = getch(); + switch ( c ) + { + case KEY_LEFT: + c = 'h'; + break; + case KEY_RIGHT: + c = 'l'; + break; + case KEY_UP: + c = 'k'; + break; + case KEY_DOWN: + c = 'j'; + break; + } + ch = c; + if (ch == 3) + { + //_quit(); + return(27); + } + /*if ( rs != 0 && rs->guiflag != 0 ) + { + if ( rs->num < sizeof(rs->buffered) ) + { + rs->buffered[rs->num++] = ch; + if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) + { + rs->needflush = (uint32_t)time(NULL); + //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); + //sleep(3); + } + } else fprintf(stderr,"buffer filled without flushed\n"); + }*/ + } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); + return(ch); +} + #ifdef STANDALONE /* Main tetris game! From fd1ff16d471d38297bec4f0f23f217b20768a0f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:46:18 -1100 Subject: [PATCH 068/111] Test --- src/cc/rogue/cursesd.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cc/rogue/cursesd.h b/src/cc/rogue/cursesd.h index e3eec5d41..0b68bc307 100644 --- a/src/cc/rogue/cursesd.h +++ b/src/cc/rogue/cursesd.h @@ -16,6 +16,13 @@ #ifndef H_CURSESD_H #define H_CURSESD_H +#define KEY_OFFSET 0x100 +#define KEY_DOWN (KEY_OFFSET + 0x02) /* Down arrow key */ +#define KEY_UP (KEY_OFFSET + 0x03) /* Up arrow key */ +#define KEY_LEFT (KEY_OFFSET + 0x04) /* Left arrow key */ +#define KEY_RIGHT (KEY_OFFSET + 0x05) /* Right arrow key */ + + #define COLOR_BLACK 0 #ifdef PDC_RGB /* RGB */ From db01efa0221cd74add1802356ba7bdf514828d12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:47:13 -1100 Subject: [PATCH 069/111] Readevent --- src/cc/gamescc.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++ src/cc/tetris.c | 69 ---------------------------------------------- 2 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index ad578400d..255866c86 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -30,6 +30,75 @@ 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]); } +gamesevent games_readevent(struct games_state *rs) +{ + gamesevent ch = -1; int32_t c; + if ( rs != 0 && rs->guiflag == 0 ) + { + static uint32_t counter; + if ( rs->ind < rs->numkeys ) + { + ch = rs->keystrokes[rs->ind++]; + if ( 0 ) + { + static FILE *fp; static int32_t counter; + if ( fp == 0 ) + fp = fopen("log","wb"); + if ( fp != 0 ) + { + fprintf(fp,"%d: (%c) seed.%llu\n",counter,c,(long long)rs->origseed); + fflush(fp); + counter++; + } + } + return(ch); + } + if ( rs->replaydone != 0 && counter++ < 3 ) + fprintf(stderr,"replay finished but readchar called\n"); + rs->replaydone = (uint32_t)time(NULL); + return(0); + } + if ( rs == 0 || rs->guiflag != 0 ) + { + c = getch(); + switch ( c ) + { + case KEY_LEFT: + c = 'h'; + break; + case KEY_RIGHT: + c = 'l'; + break; + case KEY_UP: + c = 'k'; + break; + case KEY_DOWN: + c = 'j'; + break; + } + ch = c; + if (ch == 3) + { + //_quit(); + return(27); + } + /*if ( rs != 0 && rs->guiflag != 0 ) + { + if ( rs->num < sizeof(rs->buffered) ) + { + rs->buffered[rs->num++] = ch; + if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) + { + rs->needflush = (uint32_t)time(NULL); + //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); + //sleep(3); + } + } else fprintf(stderr,"buffer filled without flushed\n"); + }*/ + } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); + return(ch); +} + int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) { struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 9808622f4..487566ed4 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -732,75 +732,6 @@ void *gamesiterate(struct games_state *rs) return(tg); } -gamesevent games_readevent(struct games_state *rs) -{ - gamesevent ch = -1; int32_t c; - if ( rs != 0 && rs->guiflag == 0 ) - { - static uint32_t counter; - if ( rs->ind < rs->numkeys ) - { - ch = rs->keystrokes[rs->ind++]; - if ( 0 ) - { - static FILE *fp; static int32_t counter; - if ( fp == 0 ) - fp = fopen("log","wb"); - if ( fp != 0 ) - { - fprintf(fp,"%d: (%c) seed.%llu\n",counter,c,(long long)rs->origseed); - fflush(fp); - counter++; - } - } - return(ch); - } - if ( rs->replaydone != 0 && counter++ < 3 ) - fprintf(stderr,"replay finished but readchar called\n"); - rs->replaydone = (uint32_t)time(NULL); - return(0); - } - if ( rs == 0 || rs->guiflag != 0 ) - { - c = getch(); - switch ( c ) - { - case KEY_LEFT: - c = 'h'; - break; - case KEY_RIGHT: - c = 'l'; - break; - case KEY_UP: - c = 'k'; - break; - case KEY_DOWN: - c = 'j'; - break; - } - ch = c; - if (ch == 3) - { - //_quit(); - return(27); - } - /*if ( rs != 0 && rs->guiflag != 0 ) - { - if ( rs->num < sizeof(rs->buffered) ) - { - rs->buffered[rs->num++] = ch; - if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) - { - rs->needflush = (uint32_t)time(NULL); - //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); - //sleep(3); - } - } else fprintf(stderr,"buffer filled without flushed\n"); - }*/ - } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); - return(ch); -} - #ifdef STANDALONE /* Main tetris game! From 2fda05a5310a37b222e4f0c7731ddebbf5e511ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 05:57:58 -1100 Subject: [PATCH 070/111] Disable return0 --- src/cc/gamescc.cpp | 1 + src/cc/tetris.cpp | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 255866c86..442632c4e 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -102,6 +102,7 @@ gamesevent games_readevent(struct games_state *rs) int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) { struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; +return(0); rs = (struct games_state *)calloc(1,sizeof(*rs)); rs->seed = rs->origseed = seed; rs->keystrokes = keystrokes; diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index c2caaa8a9..1e0cb95d1 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -24,12 +24,6 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) sprintf(packitemstr,"not yet"); } -/* -int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) // replay in daemon -{ - return(0); -}*/ - int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload) { uint256 gametxid; int32_t i,len; char str[67]; uint32_t eventid = 0; From 21b50727bfe56f6e4ac43625046ccd6d965746f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:01:08 -1100 Subject: [PATCH 071/111] +print --- src/cc/gamescc.cpp | 18 +++++++++--------- src/cc/tetris.cpp | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 442632c4e..650c051b9 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -927,7 +927,7 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven *keystrokesp = 0; for (i=0; i= 0 ) { if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 ) @@ -946,17 +946,17 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven if ( matches == 1 ) { numvouts = matchtx.vout.size(); - //fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex().c_str(),matches,numvouts); +fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex().c_str(),matches,numvouts); if ( games_registeropretdecode(txid,tokenid,playertxid,matchtx.vout[numvouts-1].scriptPubKey) == 'R' )//&& txid == gametxid ) { - //fprintf(stderr,"tokenid.%s txid.%s vs gametxid.%s player.%s\n",tokenid.GetHex().c_str(),txid.GetHex().c_str(),gametxid.GetHex().c_str(),playertxid.GetHex().c_str()); + fprintf(stderr,"tokenid.%s txid.%s vs gametxid.%s player.%s\n",tokenid.GetHex().c_str(),txid.GetHex().c_str(),gametxid.GetHex().c_str(),playertxid.GetHex().c_str()); if ( tokenid != zeroid ) active = tokenid; else active = playertxid; if ( active == zeroid || games_playerdata(cp,origplayergame,tid,pk,playerdata,symbol,pname,active) == 0 ) { txid = matchtx.GetHash(); - //fprintf(stderr,"scan forward active.%s spenttxid.%s\n",active.GetHex().c_str(),txid.GetHex().c_str()); + fprintf(stderr,"scan forward active.%s spenttxid.%s\n",active.GetHex().c_str(),txid.GetHex().c_str()); n = 0; while ( CCgettxout(txid,0,1,0) < 0 ) { @@ -973,7 +973,7 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven } } txid = spenttxid; - //fprintf(stderr,"n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); + fprintf(stderr,"n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); if ( spentvini != 0 ) // game is over? { return(0); @@ -994,17 +994,17 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven } numkeys += (int32_t)k.size() / sizeof(gamesevent); (*keystrokesp) = keystrokes; - //fprintf(stderr,"updated keystrokes.%p[%d]\n",keystrokes,numkeys); + fprintf(stderr,"updated keystrokes.%p[%d]\n",keystrokes,numkeys); } } - //fprintf(stderr,"n.%d txid.%s\n",n,txid.GetHex().c_str()); + fprintf(stderr,"n.%d txid.%s\n",n,txid.GetHex().c_str()); if ( ++n >= GAMES_MAXITERATIONS ) { fprintf(stderr,"games_findbaton n.%d, seems something is wrong\n",n); return(-5); } } - //fprintf(stderr,"set baton %s\n",txid.GetHex().c_str()); + fprintf(stderr,"set baton %s\n",txid.GetHex().c_str()); batontxid = txid; batonvout = 0; // not vini // how to detect timeout, bailedout, highlander @@ -1017,7 +1017,7 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven return(-4); else batonht = pindex->GetHeight(); batonvalue = batontx.vout[0].nValue; - //printf("batonht.%d keystrokes[%d]\n",batonht,numkeys); + printf("batonht.%d keystrokes[%d]\n",batonht,numkeys); return(0); } else fprintf(stderr,"couldnt find baton\n"); } else fprintf(stderr,"error with playerdata\n"); diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index 1e0cb95d1..a91157dde 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -90,7 +90,7 @@ gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std: { 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()); + 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 ) { @@ -116,7 +116,7 @@ gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std: fclose(fp); } } - //fprintf(stderr,"call replay2\n"); + 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 no playerdata\n"); From 1c12ebcf34fe1d1046481122e944dd4e1ca2379f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:05:22 -1100 Subject: [PATCH 072/111] +print --- src/cc/gamescc.cpp | 19 ++++++++++--------- src/cc/tetris.cpp | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 650c051b9..8fa629b7f 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -927,7 +927,7 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven *keystrokesp = 0; for (i=0; i= 0 ) { if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 ) @@ -946,17 +946,17 @@ fprintf(stderr,"findbaton.%d of %d\n",i,maxplayers); if ( matches == 1 ) { numvouts = matchtx.vout.size(); -fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex().c_str(),matches,numvouts); +//fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex().c_str(),matches,numvouts); if ( games_registeropretdecode(txid,tokenid,playertxid,matchtx.vout[numvouts-1].scriptPubKey) == 'R' )//&& txid == gametxid ) { - fprintf(stderr,"tokenid.%s txid.%s vs gametxid.%s player.%s\n",tokenid.GetHex().c_str(),txid.GetHex().c_str(),gametxid.GetHex().c_str(),playertxid.GetHex().c_str()); + //fprintf(stderr,"tokenid.%s txid.%s vs gametxid.%s player.%s\n",tokenid.GetHex().c_str(),txid.GetHex().c_str(),gametxid.GetHex().c_str(),playertxid.GetHex().c_str()); if ( tokenid != zeroid ) active = tokenid; else active = playertxid; if ( active == zeroid || games_playerdata(cp,origplayergame,tid,pk,playerdata,symbol,pname,active) == 0 ) { txid = matchtx.GetHash(); - fprintf(stderr,"scan forward active.%s spenttxid.%s\n",active.GetHex().c_str(),txid.GetHex().c_str()); + //fprintf(stderr,"scan forward active.%s spenttxid.%s\n",active.GetHex().c_str(),txid.GetHex().c_str()); n = 0; while ( CCgettxout(txid,0,1,0) < 0 ) { @@ -973,9 +973,10 @@ fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex( } } txid = spenttxid; - fprintf(stderr,"n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); + //fprintf(stderr,"n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); if ( spentvini != 0 ) // game is over? { + fprintf(stderr,"gameisover n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); return(0); } if ( keystrokesp != 0 && myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() >= 2 ) @@ -994,17 +995,17 @@ fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex( } numkeys += (int32_t)k.size() / sizeof(gamesevent); (*keystrokesp) = keystrokes; - fprintf(stderr,"updated keystrokes.%p[%d]\n",keystrokes,numkeys); + //fprintf(stderr,"updated keystrokes.%p[%d]\n",keystrokes,numkeys); } } - fprintf(stderr,"n.%d txid.%s\n",n,txid.GetHex().c_str()); + //fprintf(stderr,"n.%d txid.%s\n",n,txid.GetHex().c_str()); if ( ++n >= GAMES_MAXITERATIONS ) { fprintf(stderr,"games_findbaton n.%d, seems something is wrong\n",n); return(-5); } } - fprintf(stderr,"set baton %s\n",txid.GetHex().c_str()); + //fprintf(stderr,"set baton %s\n",txid.GetHex().c_str()); batontxid = txid; batonvout = 0; // not vini // how to detect timeout, bailedout, highlander @@ -1017,7 +1018,7 @@ fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex( return(-4); else batonht = pindex->GetHeight(); batonvalue = batontx.vout[0].nValue; - printf("batonht.%d keystrokes[%d]\n",batonht,numkeys); + //printf("batonht.%d keystrokes[%d]\n",batonht,numkeys); return(0); } else fprintf(stderr,"couldnt find baton\n"); } else fprintf(stderr,"error with playerdata\n"); diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index a91157dde..1a55de005 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -89,6 +89,7 @@ gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std: if ( (retval= games_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,gamesaddr,numplayers,symbol,pname)) == 0 ) { UniValue obj; + fprintf(stderr,"got baton\n"); 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)); From 33ba39090d1f82f9d11ffd2a999f6eded3732860 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:07:43 -1100 Subject: [PATCH 073/111] Test --- src/cc/gamescc.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 8fa629b7f..503eb17e3 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -984,18 +984,19 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven uint256 g,b; CPubKey p; std::vector k; if ( games_keystrokesopretdecode(g,b,p,k,spenttx.vout[spenttx.vout.size()-1].scriptPubKey) == 'K' ) { - keystrokes = (gamesevent *)realloc(keystrokes,sizeof(*keystrokes)*(numkeys + (int32_t)k.size())); - for (i=0; i Date: Tue, 26 Mar 2019 06:14:00 -1100 Subject: [PATCH 074/111] Test --- src/cc/gamescc.cpp | 8 ++++---- src/cc/tetris.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 503eb17e3..1684e6a18 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -976,7 +976,7 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven //fprintf(stderr,"n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); if ( spentvini != 0 ) // game is over? { - fprintf(stderr,"gameisover n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); + //fprintf(stderr,"gameisover n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); return(0); } if ( keystrokesp != 0 && myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() >= 2 ) @@ -984,7 +984,7 @@ int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gameseven uint256 g,b; CPubKey p; std::vector k; if ( games_keystrokesopretdecode(g,b,p,k,spenttx.vout[spenttx.vout.size()-1].scriptPubKey) == 'K' ) { - fprintf(stderr,"update keystrokes.%p[%d]\n",keystrokes,numkeys); + //fprintf(stderr,"update keystrokes.%p[%d]\n",keystrokes,numkeys); keystrokes = (gamesevent *)realloc(keystrokes,(int32_t)(sizeof(*keystrokes)*numkeys + k.size())); for (i=0; i 0 ) { @@ -117,7 +117,7 @@ gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std: fclose(fp); } } - fprintf(stderr,"call replay2\n"); + //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 no playerdata\n"); From 63cc12029754c0deac3f433a0af52404ad3cbf27 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:25:03 -1100 Subject: [PATCH 075/111] Replay --- src/cc/tetris.c | 25 ++++++++++++++----------- src/cc/tetris.cpp | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 487566ed4..6b63bb008 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -644,8 +644,19 @@ void *gamesiterate(struct games_state *rs) uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE; gamesevent c; uint16_t skipcount=0; uint32_t eventid = 0; tetris_game *tg; WINDOW *board, *next, *hold, *score; - // Create windows for each section of the interface. + if ( rs->guiflag != 0 ) + { + // NCURSES initialization: + initscr(); // initialize curses + cbreak(); // pass key presses to program, but not signals + noecho(); // don't echo key presses to screen + keypad(stdscr, TRUE); // allow arrow keys + timeout(0); // no blocking on getch() + curs_set(0); // set the cursor to invisible + init_colors(); // setup tetris colors + } tg = tg_create(rs,22, 10); + // Create windows for each section of the interface. board = newwin(tg->rows + 2, 2 * tg->cols + 2, 0, 0); next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1); @@ -668,7 +679,7 @@ void *gamesiterate(struct games_state *rs) { if ( skipcount > 0 ) issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x4000); - if ( c >= 0 ) + if ( c <= 0x7f ) issue_games_events(rs,Gametxidstr,eventid,c); skipcount = 0; } else skipcount++; @@ -679,6 +690,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); + fprintf(stderr,"%04x\n",c); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); @@ -833,15 +845,6 @@ int tetris(int argc, char **argv) tg = tg_create(rs,22, 10); }*/ - // NCURSES initialization: - initscr(); // initialize curses - cbreak(); // pass key presses to program, but not signals - noecho(); // don't echo key presses to screen - keypad(stdscr, TRUE); // allow arrow keys - timeout(0); // no blocking on getch() - curs_set(0); // set the cursor to invisible - init_colors(); // setup tetris colors - // Game loop tg = (tetris_game *)gamesiterate(rs); games_bailout(rs); diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index 605c969ab..7f601bb56 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -91,7 +91,7 @@ gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std: UniValue obj; //fprintf(stderr,"got baton\n"); 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()); + //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 ) { From 73f31d4a2edf3b780088f2acff03ac356028b929 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:33:51 -1100 Subject: [PATCH 076/111] Keystrokes --- src/cc/dapps/dappstd.c | 10 +++++----- src/cc/tetris.c | 15 +++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 3992cb80e..4f67f20e5 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -889,7 +889,7 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter while ( 1 ) { gamesfname(fname,seed,counter); - //printf("check (%s)\n",fname); + printf("check (%s)\n",fname); if ( (fp= fopen(fname,"rb")) == 0 ) break; if ( (fsize= get_filesize(fp)) <= 0 ) @@ -898,7 +898,7 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter //printf("fsize.%ld\n",fsize); break; } - if ( (keystrokes= (gamesevent *)realloc(keystrokes,sizeof(*keystrokes)*(num+fsize))) == 0 ) + if ( (keystrokes= (gamesevent *)realloc(keystrokes,sizeof(*keystrokes)*num+fsize))) == 0 ) { fprintf(stderr,"error reallocating keystrokes\n"); fclose(fp); @@ -912,9 +912,9 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter return(0); } fclose(fp); - num += fsize; + num += (int32_t)(fsize / sizeof(gamesevent)); counter++; - //fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num); + fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num); } *numkeysp = num; return(keystrokes); @@ -1097,7 +1097,7 @@ int main(int argc, char **argv) seed = atol(argv[1]); // non-windows #endif // _WIN32 - //fprintf(stderr,"replay %llu\n",(long long)seed); + fprintf(stderr,"replay %llu\n",(long long)seed); return(games_replay(seed,10)); } else diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 6b63bb008..5c3f742bb 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -810,7 +810,7 @@ int tetris(int argc, char **argv) memset(rs,0,sizeof(*rs)); rs->guiflag = 1; rs->sleeptime = 1; // non-zero to allow refresh() - if ( argc == 3 && strlen(argv[2]) == 64 ) + if ( argc >= 2 && strlen(argv[2]) == 64 ) { #ifdef _WIN32 #ifdef _MSC_VER @@ -822,12 +822,15 @@ int tetris(int argc, char **argv) rs->origseed = atol(argv[1]); // non-windows #endif // _WIN32 rs->seed = rs->origseed; - strcpy(Gametxidstr,argv[2]); - fprintf(stderr,"setplayerdata %s\n",Gametxidstr); - if ( games_setplayerdata(rs,Gametxidstr) < 0 ) + if ( argc >= 3 ) { - fprintf(stderr,"invalid gametxid, or already started\n"); - return(-1); + strcpy(Gametxidstr,argv[2]); + fprintf(stderr,"setplayerdata %s\n",Gametxidstr); + if ( games_setplayerdata(rs,Gametxidstr) < 0 ) + { + fprintf(stderr,"invalid gametxid, or already started\n"); + return(-1); + } } } else rs->seed = 777; From 42b2c36f726b6f1941dc1a7fb320cf33cf04dd79 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:34:30 -1100 Subject: [PATCH 077/111] Test --- src/cc/dapps/dappstd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 4f67f20e5..18f66ca58 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -898,7 +898,7 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter //printf("fsize.%ld\n",fsize); break; } - if ( (keystrokes= (gamesevent *)realloc(keystrokes,sizeof(*keystrokes)*num+fsize))) == 0 ) + if ( (keystrokes= (gamesevent *)realloc(keystrokes,sizeof(*keystrokes)*num+fsize)) == 0 ) { fprintf(stderr,"error reallocating keystrokes\n"); fclose(fp); From bd855221dfa67a79ac3b6c6c2545c355d5815684 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:36:47 -1100 Subject: [PATCH 078/111] Activate replay --- src/cc/dapps/dappstd.c | 5 +++-- src/cc/gamescc.cpp | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 18f66ca58..d8ed48b9b 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -886,10 +886,10 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter { char fname[1024]; gamesevent *keystrokes = 0; FILE *fp; long fsize; int32_t num = 0; *numkeysp = 0; - while ( 1 ) + if ( 1 ) { gamesfname(fname,seed,counter); - printf("check (%s)\n",fname); + //printf("check (%s)\n",fname); if ( (fp= fopen(fname,"rb")) == 0 ) break; if ( (fsize= get_filesize(fp)) <= 0 ) @@ -939,6 +939,7 @@ int32_t games_replay(uint64_t seed,int32_t sleeptime) if ( seed == 0 ) seed = 777; keystrokes = games_keystrokesload(&num,seed,counter); + fprintf(stderr,"keystrokes.%p num.%d\n",keystrokes,num); if ( num > 0 ) { sprintf(fname,"%s.%llu.player",GAMENAME,(long long)seed); diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 1684e6a18..282b0051b 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -102,7 +102,6 @@ gamesevent games_readevent(struct games_state *rs) int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis) { struct games_state *rs; FILE *fp; int32_t i,n; void *ptr; -return(0); rs = (struct games_state *)calloc(1,sizeof(*rs)); rs->seed = rs->origseed = seed; rs->keystrokes = keystrokes; From 81170c2e29f845c254173ab83e7d9609665999ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:37:28 -1100 Subject: [PATCH 079/111] Break --- src/cc/dapps/dappstd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index d8ed48b9b..2b5900408 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -886,7 +886,7 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter { char fname[1024]; gamesevent *keystrokes = 0; FILE *fp; long fsize; int32_t num = 0; *numkeysp = 0; - if ( 1 ) + while ( 1 ) { gamesfname(fname,seed,counter); //printf("check (%s)\n",fname); @@ -915,6 +915,7 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter num += (int32_t)(fsize / sizeof(gamesevent)); counter++; fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num); + break; } *numkeysp = num; return(keystrokes); From b4a06f0cbc27d47eb441af5ac8791cfa0d4f2d0b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:39:26 -1100 Subject: [PATCH 080/111] Test --- src/cc/dapps/dappstd.c | 2 +- src/cc/rogue/cursesd.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 2b5900408..697e9f948 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -914,7 +914,7 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter fclose(fp); num += (int32_t)(fsize / sizeof(gamesevent)); counter++; - fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num); + //fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num); break; } *numkeysp = num; diff --git a/src/cc/rogue/cursesd.h b/src/cc/rogue/cursesd.h index 0b68bc307..7dd83d435 100644 --- a/src/cc/rogue/cursesd.h +++ b/src/cc/rogue/cursesd.h @@ -175,6 +175,8 @@ char *unctrl(char c); #define leaveok(win,bf) 0 #define halfdelay(x) 0 #define nocbreak() 0 +#define cbreak() 0 +#define curs_set(x) 0 // for tetris #define init_pair(a,b,c) 0 From 5295446c978338d3eee62de4fabd001985b6d6cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 06:44:16 -1100 Subject: [PATCH 081/111] Revendian --- src/cc/dapps/dappstd.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 697e9f948..3653166cb 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -882,9 +882,21 @@ long get_filesize(FILE *fp) return(fsize); } +gamesevent revendian(gamesevent revx) +{ + gamesevent x = 0; + for (i=0; i>= 8; + } + return(x); +} + gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter) { - char fname[1024]; gamesevent *keystrokes = 0; FILE *fp; long fsize; int32_t num = 0; + char fname[1024]; gamesevent *keystrokes = 0; FILE *fp; long fsize; int32_t i,num = 0; *numkeysp = 0; while ( 1 ) { @@ -911,6 +923,8 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter free(keystrokes); return(0); } + for (i=0; i Date: Tue, 26 Mar 2019 06:44:59 -1100 Subject: [PATCH 082/111] Switch --- src/cc/dapps/dappstd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 3653166cb..9240c6404 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -884,11 +884,11 @@ long get_filesize(FILE *fp) gamesevent revendian(gamesevent revx) { - gamesevent x = 0; + int32_t i; gamesevent x = 0; for (i=0; i>= 8; } return(x); From 9df89f97fcccf72444b83e06bd6ea102572b9fd3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 07:01:15 -1100 Subject: [PATCH 083/111] +print --- src/cc/dapps/dappstd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 9240c6404..5961b5e7a 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -885,12 +885,10 @@ long get_filesize(FILE *fp) gamesevent revendian(gamesevent revx) { int32_t i; gamesevent x = 0; + fprintf(stderr,"%04x -> ",revx); for (i=0; i>= 8; - } + ((uint8_t *)&x)[i] = ((uint8_t *)&revx)[sizeof(gamesevent)-1-i]; + fprintf(stderr,"%04x\n",x); return(x); } From 15143c0129bb15824ab1c06f9b4d97319bf3617b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 07:02:35 -1100 Subject: [PATCH 084/111] Fix --- src/cc/dapps/dappstd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 5961b5e7a..6ef4381e5 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -921,10 +921,10 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter free(keystrokes); return(0); } - for (i=0; i Date: Tue, 26 Mar 2019 07:09:02 -1100 Subject: [PATCH 085/111] display_board(board,tg); display_piece(next,tg->next); display_piece(hold,tg->stored); display_score(score,tg); if ( (counter++ % 5) == 0 ) doupdate(); --- src/cc/dapps/dappstd.c | 6 +++--- src/cc/tetris.c | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 6ef4381e5..eee51739b 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -885,10 +885,10 @@ long get_filesize(FILE *fp) gamesevent revendian(gamesevent revx) { int32_t i; gamesevent x = 0; - fprintf(stderr,"%04x -> ",revx); + //fprintf(stderr,"%04x -> ",revx); for (i=0; i 0 ) { sprintf(fname,"%s.%llu.player",GAMENAME,(long long)seed); diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 5c3f742bb..cb54ee261 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -299,11 +299,11 @@ static void tg_handle_move(struct games_state *rs,tetris_game *obj, tetris_move { switch (move) { case TM_LEFT: - fprintf(stderr,"LEFT "); + //fprintf(stderr,"LEFT "); tg_move(obj, -1); break; case TM_RIGHT: - fprintf(stderr,"RIGHT "); + //fprintf(stderr,"RIGHT "); tg_move(obj, 1); break; case TM_DROP: @@ -644,7 +644,7 @@ void *gamesiterate(struct games_state *rs) uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE; gamesevent c; uint16_t skipcount=0; uint32_t eventid = 0; tetris_game *tg; WINDOW *board, *next, *hold, *score; - if ( rs->guiflag != 0 ) + if ( rs->guiflag != 0 || rs->sleeptime != 0 ) { // NCURSES initialization: initscr(); // initialize curses @@ -664,15 +664,18 @@ void *gamesiterate(struct games_state *rs) while ( running != 0 ) { running = tg_tick(rs,tg,move); - if ( rs->guiflag != 0 ) + if ( rs->guiflag != 0 || rs->sleeptime != 0 ) { -#ifdef STANDALONE display_board(board,tg); display_piece(next,tg->next); display_piece(hold,tg->stored); display_score(score,tg); if ( (counter++ % 5) == 0 ) doupdate(); + } + if ( rs->guiflag != 0 ) + { +#ifdef STANDALONE sleep_milli(10); c = games_readevent(rs); if ( c <= 0x7f || skipcount == 0x3fff ) @@ -687,6 +690,8 @@ void *gamesiterate(struct games_state *rs) } else { + if ( rs->sleeptime >= 1000 ) + sleep_milli(rs->sleeptime/1000); if ( skipcount == 0 ) { c = games_readevent(rs); From 140468d27dcba162144a60412f7015671ad2d7a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 07:10:36 -1100 Subject: [PATCH 086/111] -print --- src/cc/dapps/dappstd.c | 2 +- src/cc/tetris.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index eee51739b..9b44bc6a9 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -1112,7 +1112,7 @@ int main(int argc, char **argv) #endif // _WIN32 fprintf(stderr,"replay %llu\n",(long long)seed); - return(games_replay(seed,10)); + return(games_replay(seed,3)); } else { diff --git a/src/cc/tetris.c b/src/cc/tetris.c index cb54ee261..bd9a5526d 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -695,7 +695,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); - fprintf(stderr,"%04x\n",c); + //fprintf(stderr,"%04x\n",c); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); From 2bcc183fb073c89dff6b9ca5e145ed0ba089a1ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 07:16:24 -1100 Subject: [PATCH 087/111] +print --- src/cc/tetris.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index bd9a5526d..cb54ee261 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -695,7 +695,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); - //fprintf(stderr,"%04x\n",c); + fprintf(stderr,"%04x\n",c); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); From bd4bab770c09f227000b5641b03dcf07fd315dea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 07:23:50 -1100 Subject: [PATCH 088/111] Dont flip --- src/cc/dapps/dappstd.c | 12 +----------- src/cc/gamescc.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 9b44bc6a9..764a569ac 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -882,16 +882,6 @@ long get_filesize(FILE *fp) return(fsize); } -gamesevent revendian(gamesevent revx) -{ - int32_t i; gamesevent x = 0; - //fprintf(stderr,"%04x -> ",revx); - for (i=0; i ",revx); + for (i=0; i Date: Tue, 26 Mar 2019 07:24:48 -1100 Subject: [PATCH 089/111] gamesevent games_revendian(gamesevent revx) --- src/cc/tetris.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/tetris.h b/src/cc/tetris.h index 94d56dbfc..338eee3cb 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -199,6 +199,7 @@ void *gamesiterate(struct games_state *rs); void games_packitemstr(char *packitemstr,struct games_packitem *item); uint64_t _games_rngnext(uint64_t initseed); int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis); +gamesevent games_revendian(gamesevent revx); #endif From 4799abb82dd0bcf86353a8eee3246599a458ce92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 07:27:08 -1100 Subject: [PATCH 090/111] -print --- src/cc/tetris.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index cb54ee261..bd9a5526d 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -695,7 +695,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); - fprintf(stderr,"%04x\n",c); + //fprintf(stderr,"%04x\n",c); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); From 317b1a249829b6f4e400c295280c0af00731096e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:02:29 -1100 Subject: [PATCH 091/111] Tweaks --- src/cc/gamescc.cpp | 222 +++++++++++++++++++++++++++++++++++------ src/cc/gamescc.h | 12 ++- src/cc/rogue_rpc.cpp | 71 +++++++------ src/cc/tetris.c | 12 ++- src/cc/tetris.cpp | 232 ++++++------------------------------------- src/cc/tetris.h | 14 +-- 6 files changed, 288 insertions(+), 275 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index c01a89b69..063da9355 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -16,6 +16,9 @@ #include "gamescc.h" #include "tetris.c" // replace with game code +int32_t GAMEDATA(struct games_player *P,void *ptr); +void GAMEJSON(UniValue &obj,struct games_player *P); + uint64_t _games_rngnext(uint64_t initseed) { uint16_t seeds[4]; int32_t i; @@ -92,19 +95,6 @@ gamesevent games_readevent(struct games_state *rs) //_quit(); return(27); } - /*if ( rs != 0 && rs->guiflag != 0 ) - { - if ( rs->num < sizeof(rs->buffered) ) - { - rs->buffered[rs->num++] = ch; - if ( rs->num > (sizeof(rs->buffered)*9)/10 && rs->needflush == 0 ) - { - rs->needflush = (uint32_t)time(NULL); - //fprintf(stderr,"needflush.%u %d of %d\n",rs->needflush,rs->num,(int32_t)sizeof(rs->buffered)); - //sleep(3); - } - } else fprintf(stderr,"buffer filled without flushed\n"); - }*/ } else fprintf(stderr,"readchar rs.%p non-gui error?\n",rs); return(ch); } @@ -121,7 +111,6 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 { rs->P = *player; rs->restoring = 1; - //fprintf(stderr,"restore player packsize.%d HP.%d\n",rs->P.packsize,rs->P.hitpoints); if ( rs->P.packsize > MAXPACK ) rs->P.packsize = MAXPACK; } @@ -150,14 +139,15 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 /*if ( (fp= fopen("checkfile","wb")) != 0 ) { //save_file(rs,fp,0); - //fprintf(stderr,"gold.%d hp.%d strength.%d/%d level.%d exp.%d dungeon.%d data[%d]\n",rs->P.gold,rs->P.hitpoints,rs->P.strength&0xffff,rs->P.strength>>16,rs->P.level,rs->P.experience,rs->P.dungeonlevel,rs->playersize); if ( newdata != 0 && rs->playersize > 0 ) memcpy(newdata,rs->playerdata,rs->playersize); }*/ if ( ptr != 0 ) { // extract data from ptr - if ( newdata != 0 && rs->playersize > 0 ) + if ( GAMEDATA(&rs->P,ptr) < 0 ) + memset(&rs->P,0,sizeof(rs->P)); + else if ( newdata != 0 && rs->playersize > 0 ) memcpy(newdata,rs->playerdata,rs->playersize); free(ptr); } @@ -695,7 +685,6 @@ UniValue games_playerobj(std::vector playerdata,uint256 playertxid,uint } datastr[i<<1] = 0; } - int32_t gold,hitpoints,strength,level,experience,packsize,dungeonlevel,pad; for (i=0; i playerdata,uint256 playertxid,uint free(datastr); } obj.push_back(Pair("pack",a)); - obj.push_back(Pair("packsize",(int64_t)P.packsize)); - obj.push_back(Pair("hitpoints",(int64_t)P.hitpoints)); - obj.push_back(Pair("strength",(int64_t)(P.strength&0xffff))); - obj.push_back(Pair("maxstrength",(int64_t)(P.strength>>16))); - obj.push_back(Pair("level",(int64_t)P.level)); - obj.push_back(Pair("experience",(int64_t)P.experience)); - obj.push_back(Pair("dungeonlevel",(int64_t)P.dungeonlevel)); + GAMEPLAYERJSON(obj,&P); obj.push_back(Pair("chain",symbol)); obj.push_back(Pair("pname",pname)); return(obj); @@ -834,6 +817,24 @@ int32_t games_iamregistered(int32_t maxplayers,uint256 gametxid,CTransaction tx, return(0); } +int64_t games_buyins(uint256 gametxid) +{ + int32_t i,vout; uint256 spenttxid,hashBlock; CTransaction spenttx; int64_t buyins = 0; + for (i=0; i= 0 ) + { + if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 ) + { + if ( spenttx.vout[0].nValue > GAMES_REGISTRATIONSIZE ) + buyins += (spenttx.vout[0].nValue - GAMES_REGISTRATIONSIZE); + } //else fprintf(stderr,"cant find spenttxid.%s\n",spenttxid.GetHex().c_str()); + } //else fprintf(stderr,"vout %d is unspent\n",vout); + } + return(buyins); +} + uint64_t games_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 gametxid,char *mygamesaddr) { CBlockIndex *pindex; int32_t ht,openslots,delay,numplayers; uint256 hashBlock; uint64_t seed=0; char cmd[512]; CTransaction tx; @@ -861,6 +862,7 @@ uint64_t games_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 obj.push_back(Pair("alive",games_playersalive(openslots,numplayers,gametxid,maxplayers,ht,tx))); obj.push_back(Pair("openslots",openslots)); obj.push_back(Pair("numplayers",numplayers)); + obj.push_back(Pair("buyins",ValueFromAmount(game_buyins(gametxid)))); } obj.push_back(Pair("maxplayers",maxplayers)); obj.push_back(Pair("buyin",ValueFromAmount(buyin))); @@ -885,6 +887,27 @@ UniValue games_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *param } else return(cclib_error(result,"couldnt reparse params")); } +void disp_gamesplayerdata(std::vector playerdata) +{ + struct games_player P; int32_t i; char packitemstr[512],line[512]; + if ( playerdata.size() > 0 ) + { + for (i=0; i &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]; gamesevent *keystrokes = 0; std::vector 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; + //fprintf(stderr,"got baton\n"); + 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 no playerdata\n"); + newdata.resize(0); + *numkeysp = numkeys; + return(keystrokes); + } + else + { + *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; gamesevent *keystrokes = 0; std::vector newdata; uint256 gametxid,playertxid; FILE *fp; uint8_t pub33[33]; @@ -1380,7 +1478,7 @@ UniValue games_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } -UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params,char *method) { //vin0 -> highlander vout from creategame TCBOO //vin1 -> keystrokes baton of completed game, must be last to quit or first to win, only spent registration batons matter. If more than 60 blocks since last keystrokes, it is forfeit @@ -1393,8 +1491,8 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) // vout0 -> playerdata marker // vout0 -> 1% ingame gold // get any playerdata, get all keystrokes, replay game and compare final state - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); char *method = (char *)"bailout"; - UniValue result(UniValue::VOBJ); std::string rawtx,symbol,pname; CTransaction gametx; uint64_t seed; int64_t buyin,batonvalue,inputsum,cashout=0,CCchange=0; int32_t i,err,gameheight,tmp,numplayers,regslot,n,num,dungeonlevel,numkeys,maxplayers,batonht,batonvout; char mygamesaddr[64]; gamesevent *keystrokes = 0; std::vector playerdata,newdata,nodata; uint256 batontxid,playertxid,gametxid; CPubKey mypk,gamespk; uint8_t player[10000],mypriv[32],funcid; + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); std::string rawtx,symbol,pname; CTransaction gametx; uint64_t seed; int64_t buyin,batonvalue,inputsum,cashout=0,CCchange=0; int32_t i,err,gameheight,tmp,numplayers,regslot,n,num,numkeys,maxplayers,batonht,batonvout; char mygamesaddr[64]; gamesevent *keystrokes = 0; std::vector playerdata,newdata,nodata; uint256 batontxid,playertxid,gametxid; CPubKey mypk,gamespk; uint8_t player[10000],mypriv[32],funcid; struct CCcontract_info *cpTokens, tokensC; if ( txfee == 0 ) @@ -1452,11 +1550,10 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) newdata[i] = player[i]; ((uint8_t *)&P)[i] = player[i]; } - if ( (P.gold <= 0 || P.hitpoints <= 0 || (P.strength&0xffff) <= 0 || P.level <= 0 || P.experience <= 0 || P.dungeonlevel <= 0) ) + if ( disp_gamesplayer(str,&P) < 0 ) { //fprintf(stderr,"zero value character was killed -> no playerdata\n"); newdata.resize(0); - //P.gold = (P.gold * 8) / 10; } else { @@ -1464,7 +1561,7 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(cpTokens,NULL))); // marker to token cc addr, burnable and validated mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,1,mypk)); cashout = games_cashout(&P); - fprintf(stderr,"\nextracted $$$gold.%d -> %.8f GAME hp.%d strength.%d/%d level.%d exp.%d dl.%d n.%d amulet.%d\n",P.gold,(double)cashout/COIN,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel,n,P.amulet); + fprintf(stderr,"\ncashout %.8f extracted %s\n",(double)cashout/COIN,str); if ( funcid == 'H' && maxplayers > 1 ) { if ( P.amulet == 0 ) @@ -1474,7 +1571,7 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) else if ( games_playersalive(tmp,tmp,gametxid,maxplayers,gameheight,gametx) > 1 ) return(cclib_error(result,"highlander must be a winner or last one standing")); } - cashout += numplayers * buyin; + cashout += games_buyins(gametxid);//numplayers * buyin; } if ( cashout > 0 ) { @@ -1516,6 +1613,16 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } +UniValue games_bailout(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + return(games_finish(txfee,cp,params,"bailout")); +} + +UniValue games_highlander(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + return(games_finish(txfee,cp,params,"highlander")); +} + UniValue games_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int64_t buyin; uint256 tokenid,gametxid,txid,hashBlock; CTransaction playertx,tx; int32_t maxplayers,vout,numvouts; std::vector playerdata; CPubKey gamespk,mypk,pk; std::string symbol,pname; char coinaddr[64]; @@ -1638,6 +1745,59 @@ UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } +int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) +{ + static uint32_t good,bad; static uint256 prevgame; + char str[512],gamesaddr[64],str2[67],fname[64]; gamesevent *keystrokes; int32_t i,numkeys; std::vector newdata; uint64_t seed; CPubKey gamespk; struct games_player P; + *cashoutp = 0; + gamespk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,gamesaddr,gamespk,pk); + if ( (keystrokes= games_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,gamesaddr)) != 0 ) + { + free(keystrokes); + sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); + remove(fname); + for (i=0; ievalcode == EVAL_GAMES ) \ return(games_keystrokes(txfee,cp,params)); \ else if ( strcmp(method,"extract") == 0 ) \ return(games_extract(txfee,cp,params)); \ - else if ( strcmp(method,"finish") == 0 ) \ - return(games_finish(txfee,cp,params)); \ + else if ( strcmp(method,"bailout") == 0 ) \ + return(games_bailout(txfee,cp,params)); \ + else if ( strcmp(method,"highlander") == 0 ) \ + return(games_highlander(txfee,cp,params)); \ else if ( strcmp(method,"fund") == 0 ) \ return(games_fund(txfee,cp,params)); \ else \ diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index ee5f3d566..4b74e21b7 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -283,6 +283,24 @@ int32_t rogue_iamregistered(int32_t maxplayers,uint256 gametxid,CTransaction tx, return(0); } +int64_t rogue_buyins(uint256 gametxid) +{ + int32_t i,vout; uint256 spenttxid,hashBlock; CTransaction spenttx; int64_t buyins = 0; + for (i=0; i= 0 ) + { + if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 ) + { + if ( spenttx.vout[0].nValue > ROGUE_REGISTRATIONSIZE ) + buyins += (spenttx.vout[0].nValue - ROGUE_REGISTRATIONSIZE); + } //else fprintf(stderr,"cant find spenttxid.%s\n",spenttxid.GetHex().c_str()); + } //else fprintf(stderr,"vout %d is unspent\n",vout); + } + return(buyins); +} + int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransaction &tx,int64_t &buyin,int32_t &maxplayers,uint256 txid,int32_t unspentv0) { uint256 hashBlock; int32_t i,numvouts; char coinaddr[64]; CPubKey roguepk; uint64_t txfee = 10000; @@ -690,6 +708,7 @@ uint64_t rogue_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 obj.push_back(Pair("alive",rogue_playersalive(openslots,numplayers,gametxid,maxplayers,ht,tx))); obj.push_back(Pair("openslots",openslots)); obj.push_back(Pair("numplayers",numplayers)); + obj.push_back(Pair("buyins",ValueFromAmount(rogue_buyins(gametxid)))); } obj.push_back(Pair("maxplayers",maxplayers)); obj.push_back(Pair("buyin",ValueFromAmount(buyin))); @@ -1093,6 +1112,20 @@ UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } +int64_t rogue_cashout(struct rogue_player *P) +{ + int32_t dungeonlevel; int64_t mult = 10; + if ( P->amulet != 0 ) + mult *= 5; + dungeonlevel = P->dungeonlevel; + if ( P->amulet != 0 && dungeonlevel < 26 ) + dungeonlevel = 26; + if ( dungeonlevel > 42 ) + dungeonlevel = 42; + cashout = (uint64_t)P->gold * P->gold * mult * dungeonlevel; + return(cashout); +} + int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) { static uint32_t good,bad; static uint256 prevgame; @@ -1105,17 +1138,9 @@ int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C free(keystrokes); sprintf(fname,"rogue.%llu.pack",(long long)seed); remove(fname); - for (i=0; i 42 ) - dungeonlevel = 42; - *cashoutp = (uint64_t)P.gold * P.gold * mult * dungeonlevel; + *cashoutp = rogue_cashout(&P); if ( newdata == playerdata ) { if ( gametxid != prevgame ) @@ -1206,16 +1231,10 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param result.push_back(Pair("name","rogue")); result.push_back(Pair("method",method)); result.push_back(Pair("myrogueaddr",myrogueaddr)); + mult = 10; //100000; if ( strcmp(method,"bailout") == 0 ) - { funcid = 'Q'; - mult = 10; //100000; - } - else - { - funcid = 'H'; - mult = 20; //200000; - } + else funcid = 'H'; if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n > 0 ) @@ -1264,13 +1283,10 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param cpTokens = CCinit(&tokensC, EVAL_TOKENS); mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(cpTokens,NULL))); // marker to token cc addr, burnable and validated mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,1,mypk)); - if ( P.amulet != 0 ) - mult *= 5; - dungeonlevel = P.dungeonlevel; - if ( P.amulet != 0 && dungeonlevel < 26 ) - dungeonlevel = 26; - cashout = (uint64_t)P.gold * P.gold * mult * dungeonlevel; + cashout = rogue_cashout(&P); fprintf(stderr,"\nextracted $$$gold.%d -> %.8f ROGUE hp.%d strength.%d/%d level.%d exp.%d dl.%d n.%d amulet.%d\n",P.gold,(double)cashout/COIN,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel,n,P.amulet); + if ( komodo_nextheight() > 77777 && cashout > ROGUE_MAXCASHOUT ) + cashout = ROGUE_MAXCASHOUT; if ( funcid == 'H' && maxplayers > 1 ) { if ( P.amulet == 0 ) @@ -1280,12 +1296,11 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param else if ( rogue_playersalive(tmp,tmp,gametxid,maxplayers,gameheight,gametx) > 1 ) return(cclib_error(result,"highlander must be a winner or last one standing")); } + cashout *= 2; cashout += numplayers * buyin; } if ( cashout > 0 ) { - if ( komodo_nextheight() > 77777 && cashout > ROGUE_MAXCASHOUT ) - cashout = ROGUE_MAXCASHOUT; if ( (inputsum= AddCClibInputs(cp,mtx,roguepk,cashout,60,cp->unspendableCCaddr)) > cashout ) CCchange = (inputsum - cashout); else fprintf(stderr,"couldnt find enough utxos\n"); @@ -1598,13 +1613,13 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C if ( enabled != 0 ) return eval->Invalid("mismatched playerdata"); } + if ( height > 777777 && cashout > ROGUE_MAXCASHOUT ) + cashout = ROGUE_MAXCASHOUT; if ( funcid == 'H' ) { cashout *= 2; - //cashout += numplayers * buyin; + cashout += rogue_buyins(gametxid); } - if ( height > 777777 && cashout > ROGUE_MAXCASHOUT ) - cashout = ROGUE_MAXCASHOUT; sprintf(cashstr,"tokentx.(%c) decoded.%d ht.%d txid.%s %.8f vs vout2 %.8f",tokentx,decoded,height,txid.GetHex().c_str(),(double)cashout/COIN,(double)tx.vout[2].nValue/COIN); if ( strcmp(laststr,cashstr) != 0 ) { diff --git a/src/cc/tetris.c b/src/cc/tetris.c index bd9a5526d..54ca3b953 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -7,12 +7,20 @@ also, the standalone game needs to support argv of seed gametxid, along with replay args */ -static int random_tetromino(struct games_state *rs) +int random_tetromino(struct games_state *rs) { rs->seed = _games_rngnext(rs->seed); return(rs->seed % NUM_TETROMINOS); } +int32_t tetrisdata(struct games_player *P,void *ptr) +{ + tetris_game *tg = ptr; + P->gold = tg->points; + P->dungeonlevel = tg->level; + return(0); +} + /***************************************************************************/ /** https://github.com/brenns10/tetris @file main.c @@ -676,7 +684,7 @@ void *gamesiterate(struct games_state *rs) if ( rs->guiflag != 0 ) { #ifdef STANDALONE - sleep_milli(10); + sleep_milli(25); c = games_readevent(rs); if ( c <= 0x7f || skipcount == 0x3fff ) { diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index 7f601bb56..e44b50925 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -14,14 +14,37 @@ * * ******************************************************************************/ -int32_t games_findbaton(struct CCcontract_info *cp,uint256 &playertxid,gamesevent **keystrokesp,int32_t &numkeys,int32_t ®slot,std::vector &playerdata,uint256 &batontxid,int32_t &batonvout,int64_t &batonvalue,int32_t &batonht,uint256 gametxid,CTransaction gametx,int32_t maxplayers,char *destaddr,int32_t &numplayers,std::string &symbol,std::string &pname); -int32_t games_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransaction &tx,int64_t &buyin,int32_t &maxplayers,uint256 txid,int32_t unspentv0); -uint64_t games_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 gametxid,char *mygamesaddr); - // game specific code for daemon void games_packitemstr(char *packitemstr,struct games_packitem *item) { - sprintf(packitemstr,"not yet"); + sprintf(packitemstr,""); +} + +int64_t games_cashout(struct games_player *P) +{ + int32_t dungeonlevel = P->dungeonlevel; int64_t mult=1000,cashout = 0; + cashout = (uint64_t)P->gold * mult * dungeonlevel * dungeonlevel; + return(cashout); +} + +void tetrisjson(UniValue &obj,struct games_player *P) +{ + obj.push_back(Pair("packsize",(int64_t)P->packsize)); + obj.push_back(Pair("hitpoints",(int64_t)P->hitpoints)); + obj.push_back(Pair("strength",(int64_t)(P->strength&0xffff))); + obj.push_back(Pair("maxstrength",(int64_t)(P->strength>>16))); + obj.push_back(Pair("level",(int64_t)P->level)); + obj.push_back(Pair("experience",(int64_t)P->experience)); + obj.push_back(Pair("dungeonlevel",(int64_t)P->dungeonlevel)); +} + +int32_t disp_gamesplayer(char *str,struct games_player *P) +{ + str[0] = 0; + if ( P->gold <= 0 || P->hitpoints <= 0 || (P->strength&0xffff) <= 0 || P->level <= 0 || P->experience <= 0 || P->dungeonlevel <= 0 ) + return(-1); + sprintf(str," <- playerdata: gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d",P->gold,P->hitpoints,P->strength&0xffff,P->strength>>16,P->level,P->experience,P->dungeonlevel); + return(0); } int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload) @@ -43,205 +66,6 @@ int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector pay } else return(-1); } -int64_t games_cashout(struct games_player *P) -{ - int32_t dungeonlevel; int64_t mult=10,cashout = 0; - if ( P->amulet != 0 ) - mult *= 5; - dungeonlevel = P->dungeonlevel; - if ( P->amulet != 0 && dungeonlevel < 26 ) - dungeonlevel = 26; - cashout = (uint64_t)P->gold * P->gold * mult * dungeonlevel; - return(cashout); -} - -void disp_gamesplayerdata(std::vector playerdata) -{ - struct games_player P; int32_t i; char packitemstr[512]; - if ( playerdata.size() > 0 ) - { - for (i=0; i>16,P.level,P.experience,P.dungeonlevel); - for (i=0; i &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]; gamesevent *keystrokes = 0; std::vector 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; - //fprintf(stderr,"got baton\n"); - 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 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); -} - -int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) -{ - static uint32_t good,bad; static uint256 prevgame; - char str[512],gamesaddr[64],str2[67],fname[64]; gamesevent *keystrokes; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed; CPubKey gamespk; struct games_player P; - *cashoutp = 0; - gamespk = GetUnspendable(cp,0); - GetCCaddress1of2(cp,gamesaddr,gamespk,pk); - if ( (keystrokes= games_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,gamesaddr)) != 0 ) - { - free(keystrokes); - sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); - remove(fname); - - for (i=0; i no playerdata, good.%d bad.%d\n",good,bad); - } - *cashoutp = 0; - return(0); - } - } - if ( gametxid != prevgame ) - { - prevgame = gametxid; - bad++; - disp_gamesplayerdata(newdata); - disp_gamesplayerdata(playerdata); - fprintf(stderr,"%s playerdata: gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d\n",gametxid.GetHex().c_str(),P.gold,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel); - fprintf(stderr,"newdata[%d] != playerdata[%d], numkeys.%d %s pub.%s playertxid.%s good.%d bad.%d\n",(int32_t)newdata.size(),(int32_t)playerdata.size(),numkeys,gamesaddr,pubkey33_str(str2,(uint8_t *)&pk),playertxid.GetHex().c_str(),good,bad); - } - } - sprintf(fname,"%s.%llu.pack",GAMENAME,(long long)seed); - remove(fname); - //fprintf(stderr,"no keys games_extractgame %s\n",gametxid.GetHex().c_str()); - return(-1); -} - bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { return(true); diff --git a/src/cc/tetris.h b/src/cc/tetris.h index 338eee3cb..79a1c2c3e 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -163,9 +163,12 @@ void tg_print(tetris_game *obj, FILE *f); * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ -#define GAMENAME "tetris" -#define GAMEMAIN tetris -#define CHAINNAME "GTEST" +#define GAMENAME "tetris" // name of executable +#define GAMEMAIN tetris // main program of game +#define GAMEJSON tetrisjson // displays game specific json +#define GAMEDATA tetrisdata // extracts data from game specific variables into games_state +#define CHAINNAME "GTEST" // -ac_name= +typedef uint16_t gamesevent; // can be 8, 16, 32, or 64 bits #define MAXPACK 23 struct games_packitem @@ -180,8 +183,6 @@ struct games_player struct games_packitem gamespack[MAXPACK]; }; -typedef uint16_t gamesevent; - struct games_state { uint64_t seed,origseed; @@ -191,7 +192,7 @@ struct games_state FILE *logfp; struct games_player P; gamesevent buffered[5000],*keystrokes; - uint8_t playerdata[1024]; + uint8_t playerdata[8192]; }; extern struct games_state globalR; void *gamesiterate(struct games_state *rs); @@ -200,6 +201,7 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item); uint64_t _games_rngnext(uint64_t initseed); int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis); gamesevent games_revendian(gamesevent revx); +int32_t disp_gamesplayer(char *str,struct games_player *P); #endif From ef1c722d2de8985d423c2ff17ca41ccd0c125490 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:04:11 -1100 Subject: [PATCH 092/111] Test --- src/cc/gamescc.cpp | 3 ++- src/cc/tetris.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 063da9355..6763b9033 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -17,7 +17,6 @@ #include "tetris.c" // replace with game code int32_t GAMEDATA(struct games_player *P,void *ptr); -void GAMEJSON(UniValue &obj,struct games_player *P); uint64_t _games_rngnext(uint64_t initseed) { @@ -160,6 +159,8 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 #include "tetris.cpp" // replace with game specific functions +void GAMEJSON(UniValue &obj,struct games_player *P); + /* ./c cclib rng 17 \"[%229433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775%22,250]\" { diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 54ca3b953..dd142e036 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -15,7 +15,7 @@ int random_tetromino(struct games_state *rs) int32_t tetrisdata(struct games_player *P,void *ptr) { - tetris_game *tg = ptr; + tetris_game *tg = (tetris_game *)ptr; P->gold = tg->points; P->dungeonlevel = tg->level; return(0); From 1254c3ed5cbb7e3ad6e26c3d859956be2b723198 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:10:39 -1100 Subject: [PATCH 093/111] Test --- src/cc/gamescc.cpp | 14 +++++++------- src/cc/tetris.cpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 6763b9033..62d49c3dd 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -818,7 +818,7 @@ int32_t games_iamregistered(int32_t maxplayers,uint256 gametxid,CTransaction tx, return(0); } -int64_t games_buyins(uint256 gametxid) +int64_t games_buyins(uint256 gametxid,int32_t maxplayers) { int32_t i,vout; uint256 spenttxid,hashBlock; CTransaction spenttx; int64_t buyins = 0; for (i=0; i playerdata) { - struct games_player P; int32_t i; char packitemstr[512],line[512]; + struct games_player P; int32_t i; char packitemstr[512],str[512]; if ( playerdata.size() > 0 ) { for (i=0; i 1% ingame gold // get any playerdata, get all keystrokes, replay game and compare final state CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx,symbol,pname; CTransaction gametx; uint64_t seed; int64_t buyin,batonvalue,inputsum,cashout=0,CCchange=0; int32_t i,err,gameheight,tmp,numplayers,regslot,n,num,numkeys,maxplayers,batonht,batonvout; char mygamesaddr[64]; gamesevent *keystrokes = 0; std::vector playerdata,newdata,nodata; uint256 batontxid,playertxid,gametxid; CPubKey mypk,gamespk; uint8_t player[10000],mypriv[32],funcid; + UniValue result(UniValue::VOBJ); std::string rawtx,symbol,pname; CTransaction gametx; uint64_t seed; int64_t buyin,batonvalue,inputsum,cashout=0,CCchange=0; int32_t i,err,gameheight,tmp,numplayers,regslot,n,num,numkeys,maxplayers,batonht,batonvout; char mygamesaddr[64],str[512]; gamesevent *keystrokes = 0; std::vector playerdata,newdata,nodata; uint256 batontxid,playertxid,gametxid; CPubKey mypk,gamespk; uint8_t player[10000],mypriv[32],funcid; struct CCcontract_info *cpTokens, tokensC; if ( txfee == 0 ) @@ -1572,7 +1572,7 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params,ch else if ( games_playersalive(tmp,tmp,gametxid,maxplayers,gameheight,gametx) > 1 ) return(cclib_error(result,"highlander must be a winner or last one standing")); } - cashout += games_buyins(gametxid);//numplayers * buyin; + cashout += games_buyins(gametxid,maxplayers);//numplayers * buyin; } if ( cashout > 0 ) { @@ -1616,12 +1616,12 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params,ch UniValue games_bailout(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - return(games_finish(txfee,cp,params,"bailout")); + return(games_finish(txfee,cp,params,(char *)"bailout")); } UniValue games_highlander(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - return(games_finish(txfee,cp,params,"highlander")); + return(games_finish(txfee,cp,params,(char *)"highlander")); } UniValue games_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index e44b50925..a862e2a3f 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -17,7 +17,7 @@ // game specific code for daemon void games_packitemstr(char *packitemstr,struct games_packitem *item) { - sprintf(packitemstr,""); + strcpy(packitemstr,""); } int64_t games_cashout(struct games_player *P) From f1737210077500e3ebec693f8ab674fec799251c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:11:29 -1100 Subject: [PATCH 094/111] Test --- src/cc/tetris.cpp | 2 +- src/cc/tetris.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index a862e2a3f..a461d139e 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -27,7 +27,7 @@ int64_t games_cashout(struct games_player *P) return(cashout); } -void tetrisjson(UniValue &obj,struct games_player *P) +void tetrisplayerjson(UniValue &obj,struct games_player *P) { obj.push_back(Pair("packsize",(int64_t)P->packsize)); obj.push_back(Pair("hitpoints",(int64_t)P->hitpoints)); diff --git a/src/cc/tetris.h b/src/cc/tetris.h index 79a1c2c3e..9d16a8e8b 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -165,7 +165,7 @@ void tg_print(tetris_game *obj, FILE *f); ******************************************************************************/ #define GAMENAME "tetris" // name of executable #define GAMEMAIN tetris // main program of game -#define GAMEJSON tetrisjson // displays game specific json +#define GAMEPLAYERJSON tetrisplayerjson // displays game specific json #define GAMEDATA tetrisdata // extracts data from game specific variables into games_state #define CHAINNAME "GTEST" // -ac_name= typedef uint16_t gamesevent; // can be 8, 16, 32, or 64 bits From 5abd8a92071773f5e85e7a33dfb2c587e0be71ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:19:43 -1100 Subject: [PATCH 095/111] test --- src/cc/tetris.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index dd142e036..3e2d4a24c 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -307,11 +307,11 @@ static void tg_handle_move(struct games_state *rs,tetris_game *obj, tetris_move { switch (move) { case TM_LEFT: - //fprintf(stderr,"LEFT "); + fprintf(stderr,"LEFT "); tg_move(obj, -1); break; case TM_RIGHT: - //fprintf(stderr,"RIGHT "); + fprintf(stderr,"RIGHT "); tg_move(obj, 1); break; case TM_DROP: @@ -459,7 +459,7 @@ void tg_init(struct games_state *rs,tetris_game *obj, int rows, int cols) obj->stored.ori = 0; obj->stored.loc.row = 0; obj->next.loc.col = obj->cols/2 - 2; - printf("%d", obj->falling.loc.col); + //printf("%d", obj->falling.loc.col); } tetris_game *tg_create(struct games_state *rs,int rows, int cols) @@ -672,7 +672,7 @@ void *gamesiterate(struct games_state *rs) while ( running != 0 ) { running = tg_tick(rs,tg,move); - if ( rs->guiflag != 0 || rs->sleeptime != 0 ) + if ( 0 && (rs->guiflag != 0 || rs->sleeptime != 0) ) { display_board(board,tg); display_piece(next,tg->next); @@ -703,7 +703,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); - //fprintf(stderr,"%04x\n",c); + fprintf(stderr,"%04x\n",c); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); From 701f7027f5c9252482850d68f25bfcd952c05cf6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:21:06 -1100 Subject: [PATCH 096/111] -flip --- src/cc/dapps/dappstd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 764a569ac..925b8749a 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -913,8 +913,8 @@ gamesevent *games_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter } fclose(fp); num += (int32_t)(fsize / sizeof(gamesevent)); - for (i=0; i Date: Tue, 26 Mar 2019 09:22:13 -1100 Subject: [PATCH 097/111] -print --- src/cc/tetris.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 3e2d4a24c..7db0e7fa0 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -307,11 +307,11 @@ static void tg_handle_move(struct games_state *rs,tetris_game *obj, tetris_move { switch (move) { case TM_LEFT: - fprintf(stderr,"LEFT "); + //fprintf(stderr,"LEFT "); tg_move(obj, -1); break; case TM_RIGHT: - fprintf(stderr,"RIGHT "); + //fprintf(stderr,"RIGHT "); tg_move(obj, 1); break; case TM_DROP: @@ -703,7 +703,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); - fprintf(stderr,"%04x\n",c); + //fprintf(stderr,"%04x\n",c); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); From 250fe82e9c18dd63e433efad944c9e8ce81db9eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:23:50 -1100 Subject: [PATCH 098/111] Display --- src/cc/tetris.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 7db0e7fa0..e5a9be712 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -672,7 +672,7 @@ void *gamesiterate(struct games_state *rs) while ( running != 0 ) { running = tg_tick(rs,tg,move); - if ( 0 && (rs->guiflag != 0 || rs->sleeptime != 0) ) + if ( 1 && (rs->guiflag != 0 || rs->sleeptime != 0) ) { display_board(board,tg); display_piece(next,tg->next); @@ -698,8 +698,8 @@ void *gamesiterate(struct games_state *rs) } else { - if ( rs->sleeptime >= 1000 ) - sleep_milli(rs->sleeptime/1000); + if ( rs->sleeptime != 0 ) + sleep_milli(1); if ( skipcount == 0 ) { c = games_readevent(rs); From 7c63b83176b25a0e14cdfae2ad5ebd6821fa69df Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:26:40 -1100 Subject: [PATCH 099/111] Test --- src/cc/tetris.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index e5a9be712..6308740e7 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -678,13 +678,13 @@ void *gamesiterate(struct games_state *rs) display_piece(next,tg->next); display_piece(hold,tg->stored); display_score(score,tg); - if ( (counter++ % 5) == 0 ) - doupdate(); } if ( rs->guiflag != 0 ) { #ifdef STANDALONE - sleep_milli(25); + sleep_milli(15); + if ( (counter++ % 10) == 0 ) + doupdate(); c = games_readevent(rs); if ( c <= 0x7f || skipcount == 0x3fff ) { @@ -699,7 +699,11 @@ void *gamesiterate(struct games_state *rs) else { if ( rs->sleeptime != 0 ) + { sleep_milli(1); + if ( (counter++ % 20) == 0 ) + doupdate(); + } if ( skipcount == 0 ) { c = games_readevent(rs); From a29ad0f9bbbd478c15a296e8ef62ed2362061991 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:28:19 -1100 Subject: [PATCH 100/111] +print --- src/cc/tetris.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 6308740e7..852aecbc9 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -707,7 +707,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); - //fprintf(stderr,"%04x\n",c); + fprintf(stderr,"%04x\n",c); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); From 0d7dbc3929e4462882aa1848dfea6860c96aed29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:31:44 -1100 Subject: [PATCH 101/111] rs->replaydone --- src/cc/tetris.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 852aecbc9..3bf5b098a 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -698,6 +698,8 @@ void *gamesiterate(struct games_state *rs) } else { + if ( rs->replaydone != 0 ) + break; if ( rs->sleeptime != 0 ) { sleep_milli(1); @@ -707,7 +709,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); - fprintf(stderr,"%04x\n",c); + fprintf(stderr,"%04x score.%d level.%d\n",c,tg->score,tg->level); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); From b8f944dfe9fa3dfdf03bde72e61f6a830b221682 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:32:24 -1100 Subject: [PATCH 102/111] Points --- src/cc/tetris.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 3bf5b098a..97c35ecd9 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -709,7 +709,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); - fprintf(stderr,"%04x score.%d level.%d\n",c,tg->score,tg->level); + fprintf(stderr,"%04x score.%d level.%d\n",c,tg->points,tg->level); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); From d35bad65b5bc02bc60995acba09f88eb68ab079e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:35:18 -1100 Subject: [PATCH 103/111] Print --- src/cc/gamescc.cpp | 1 + src/cc/tetris.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 62d49c3dd..ce0b3e479 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -152,6 +152,7 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 } n = rs->playersize; free(rs); + fprintf(stderr,"score.%d level.%d\n",tg->points,tg->level); return(n); } diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 97c35ecd9..214145659 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -709,7 +709,7 @@ void *gamesiterate(struct games_state *rs) if ( skipcount == 0 ) { c = games_readevent(rs); - fprintf(stderr,"%04x score.%d level.%d\n",c,tg->points,tg->level); + //fprintf(stderr,"%04x score.%d level.%d\n",c,tg->points,tg->level); if ( (c & 0x4000) == 0x4000 ) { skipcount = (c & 0x3fff); From 4b555126d5c5ca1163a15d2203cd10e2c54ca134 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:36:15 -1100 Subject: [PATCH 104/111] Test --- src/cc/gamescc.cpp | 1 - src/cc/tetris.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index ce0b3e479..62d49c3dd 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -152,7 +152,6 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 } n = rs->playersize; free(rs); - fprintf(stderr,"score.%d level.%d\n",tg->points,tg->level); return(n); } diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 214145659..0a613c0c9 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -18,6 +18,7 @@ int32_t tetrisdata(struct games_player *P,void *ptr) tetris_game *tg = (tetris_game *)ptr; P->gold = tg->points; P->dungeonlevel = tg->level; + fprintf(stderr,"score.%d level.%d\n",tg->points,tg->level); return(0); } From 91fcfefd16831bebce19239153294ed092222655 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:38:35 -1100 Subject: [PATCH 105/111] Test --- src/cc/tetris.c | 2 +- src/cc/tetris.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/tetris.c b/src/cc/tetris.c index 0a613c0c9..c507ec019 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -18,7 +18,7 @@ int32_t tetrisdata(struct games_player *P,void *ptr) tetris_game *tg = (tetris_game *)ptr; P->gold = tg->points; P->dungeonlevel = tg->level; - fprintf(stderr,"score.%d level.%d\n",tg->points,tg->level); + //fprintf(stderr,"score.%d level.%d\n",tg->points,tg->level); return(0); } diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index a461d139e..39e8f1a65 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -41,7 +41,7 @@ void tetrisplayerjson(UniValue &obj,struct games_player *P) int32_t disp_gamesplayer(char *str,struct games_player *P) { str[0] = 0; - if ( P->gold <= 0 || P->hitpoints <= 0 || (P->strength&0xffff) <= 0 || P->level <= 0 || P->experience <= 0 || P->dungeonlevel <= 0 ) + if ( P->gold <= 0 )//|| P->hitpoints <= 0 || (P->strength&0xffff) <= 0 || P->level <= 0 || P->experience <= 0 || P->dungeonlevel <= 0 ) return(-1); sprintf(str," <- playerdata: gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d",P->gold,P->hitpoints,P->strength&0xffff,P->strength>>16,P->level,P->experience,P->dungeonlevel); return(0); From c2f90d6173669d602c7644c481508699b8695d5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:41:47 -1100 Subject: [PATCH 106/111] Test --- src/cc/gamescc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 62d49c3dd..867c0a79b 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -151,6 +151,7 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 free(ptr); } n = rs->playersize; + fprintf(stderr,"gold.%d\n",rs->P.gold); sleep(3); free(rs); return(n); } @@ -1374,7 +1375,7 @@ gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std: fclose(fp); } } - //fprintf(stderr,"call replay2\n"); + 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 Date: Tue, 26 Mar 2019 09:44:32 -1100 Subject: [PATCH 107/111] Test --- src/cc/gamescc.cpp | 2 +- src/cc/tetris.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 867c0a79b..698890c57 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1375,7 +1375,6 @@ gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std: 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 no playerdata\n"); diff --git a/src/cc/tetris.cpp b/src/cc/tetris.cpp index 39e8f1a65..8a52dcb37 100644 --- a/src/cc/tetris.cpp +++ b/src/cc/tetris.cpp @@ -41,8 +41,8 @@ void tetrisplayerjson(UniValue &obj,struct games_player *P) int32_t disp_gamesplayer(char *str,struct games_player *P) { str[0] = 0; - if ( P->gold <= 0 )//|| P->hitpoints <= 0 || (P->strength&0xffff) <= 0 || P->level <= 0 || P->experience <= 0 || P->dungeonlevel <= 0 ) - return(-1); + //if ( P->gold <= 0 )//|| P->hitpoints <= 0 || (P->strength&0xffff) <= 0 || P->level <= 0 || P->experience <= 0 || P->dungeonlevel <= 0 ) + // return(-1); sprintf(str," <- playerdata: gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d",P->gold,P->hitpoints,P->strength&0xffff,P->strength>>16,P->level,P->experience,P->dungeonlevel); return(0); } From 67ba7536bdbed814b00041266fadaea2f3b7fb32 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:47:04 -1100 Subject: [PATCH 108/111] Test --- src/cc/gamescc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 698890c57..2c5668253 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -146,12 +146,13 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 // extract data from ptr if ( GAMEDATA(&rs->P,ptr) < 0 ) memset(&rs->P,0,sizeof(rs->P)); - else if ( newdata != 0 && rs->playersize > 0 ) + else rs->playersize = sizeof(rs->P); + if ( newdata != 0 && rs->playersize > 0 ) memcpy(newdata,rs->playerdata,rs->playersize); free(ptr); } n = rs->playersize; - fprintf(stderr,"gold.%d\n",rs->P.gold); sleep(3); + //fprintf(stderr,"gold.%d\n",rs->P.gold); sleep(3); free(rs); return(n); } From a43f0b65d4535cfd24f1db97547b7d954789d45b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:50:16 -1100 Subject: [PATCH 109/111] Test --- src/cc/dapps/dappstd.c | 2 +- src/cc/tetris.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 925b8749a..917045ed5 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -862,7 +862,7 @@ int32_t flushkeystrokes(struct games_state *rs,int32_t waitflag) return(0); } -void games_bailout(struct games_state *rs) +void gamesbailout(struct games_state *rs) { flushkeystrokes(rs,1); } diff --git a/src/cc/tetris.c b/src/cc/tetris.c index c507ec019..cb89c0da0 100644 --- a/src/cc/tetris.c +++ b/src/cc/tetris.c @@ -651,7 +651,7 @@ gamesevent games_readevent(struct games_state *rs); void *gamesiterate(struct games_state *rs) { uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE; - gamesevent c; uint16_t skipcount=0; uint32_t eventid = 0; tetris_game *tg; + gamesevent c; uint16_t skipcount=0; int32_t prevlevel; uint32_t eventid = 0; tetris_game *tg; WINDOW *board, *next, *hold, *score; if ( rs->guiflag != 0 || rs->sleeptime != 0 ) { @@ -665,6 +665,7 @@ void *gamesiterate(struct games_state *rs) init_colors(); // setup tetris colors } tg = tg_create(rs,22, 10); + prevlevel = tg->level; // Create windows for each section of the interface. board = newwin(tg->rows + 2, 2 * tg->cols + 2, 0, 0); next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1); @@ -693,6 +694,11 @@ void *gamesiterate(struct games_state *rs) issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x4000); if ( c <= 0x7f ) issue_games_events(rs,Gametxidstr,eventid,c); + if ( tg->level != prevlevel ) + { + flushkeystrokes(rs,0); + prevlevel = tg->level; + } skipcount = 0; } else skipcount++; #endif @@ -870,7 +876,7 @@ int tetris(int argc, char **argv) // Game loop tg = (tetris_game *)gamesiterate(rs); - games_bailout(rs); + gamesbailout(rs); // Deinitialize NCurses wclear(stdscr); endwin(); From 8660a2eedc523474c9d47fe342c4389892b593b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:51:32 -1100 Subject: [PATCH 110/111] -print --- src/cc/gamescc.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 2c5668253..3e12a7010 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -146,9 +146,12 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,gamesevent *keystrokes,int3 // extract data from ptr if ( GAMEDATA(&rs->P,ptr) < 0 ) memset(&rs->P,0,sizeof(rs->P)); - else rs->playersize = sizeof(rs->P); - if ( newdata != 0 && rs->playersize > 0 ) - memcpy(newdata,rs->playerdata,rs->playersize); + else + { + rs->playersize = sizeof(rs->P); + if ( newdata != 0 ) + memcpy(newdata,&rs->P,rs->playersize); + } free(ptr); } n = rs->playersize; @@ -1383,7 +1386,7 @@ gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std: newdata[i] = newplayer[i]; ((uint8_t *)&endP)[i] = newplayer[i]; } - fprintf(stderr,"newgold.%d\n",endP.gold); sleep(3); + //fprintf(stderr,"newgold.%d\n",endP.gold); sleep(3); if ( disp_gamesplayer(str,&endP) < 0 ) { sprintf(str,"zero value character -> no playerdata\n"); From 8a7a1da70f3773317c9e370d90e8957c0fc1e04b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Mar 2019 09:52:15 -1100 Subject: [PATCH 111/111] int32_t flushkeystrokes(struct games_state *rs,int32_t waitflag) --- src/cc/tetris.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/tetris.h b/src/cc/tetris.h index 9d16a8e8b..c4cfb3b31 100644 --- a/src/cc/tetris.h +++ b/src/cc/tetris.h @@ -196,6 +196,7 @@ struct games_state }; extern struct games_state globalR; void *gamesiterate(struct games_state *rs); +int32_t flushkeystrokes(struct games_state *rs,int32_t waitflag); void games_packitemstr(char *packitemstr,struct games_packitem *item); uint64_t _games_rngnext(uint64_t initseed);