diff --git a/src/Makefile.am b/src/Makefile.am index 8503ebb56..1881f0a90 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -571,8 +571,14 @@ komodod_LDADD += \ $(LIBBITCOIN_CRYPTO) \ $(LIBVERUS_CRYPTO) \ $(LIBVERUS_PORTABLE_CRYPTO) \ - $(LIBZCASH_LIBS) \ - libcc.so -lncurses + $(LIBZCASH_LIBS) + +if TARGET_DARWIN +komodod_LDADD += libcc.dylib -lncurses +else +komodod_LDADD += libcc.so -lncurses +endif + if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index c13f55ce4..77f6a21ac 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -64,6 +64,7 @@ CClib_methods[] = { (char *)"rogue", (char *)"players", (char *)"", 0, 0, 'D', EVAL_ROGUE }, { (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 }, #else { (char *)"sudoku", (char *)"gen", (char *)"", 0, 0, 'G', EVAL_SUDOKU }, { (char *)"sudoku", (char *)"txidinfo", (char *)"txid", 1, 1, 'T', EVAL_SUDOKU }, @@ -89,6 +90,7 @@ UniValue rogue_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *param UniValue rogue_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue rogue_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue rogue_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); #else bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx); @@ -118,6 +120,8 @@ UniValue CClib_method(struct CCcontract_info *cp,char *method,cJSON *params) return(rogue_bailout(txfee,cp,params)); else if ( strcmp(method,"highlander") == 0 ) return(rogue_highlander(txfee,cp,params)); + else if ( strcmp(method,"extract") == 0 ) + return(rogue_extract(txfee,cp,params)); else if ( strcmp(method,"playerinfo") == 0 ) return(rogue_playerinfo(txfee,cp,params)); else if ( strcmp(method,"players") == 0 ) @@ -492,6 +496,7 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will #ifdef BUILD_ROGUE #include "rogue_rpc.cpp" +#include "rogue/cursesd.c" #include "rogue/vers.c" #include "rogue/extern.c" #include "rogue/armor.c" diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index ca069ee57..fd20314bb 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -106,12 +106,12 @@ CScript EncodeChannelsOpRet(uint8_t funcid,uint256 tokenid,uint256 opentxid,CPub uint8_t DecodeChannelsOpRet(const CScript &scriptPubKey, uint256 &tokenid, uint256 &opentxid, CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain) { - std::vector vopret; uint8_t *script,e,f,tokenevalcode; - std::vector pubkeys; std::vector vOpretExtra; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; + std::vector pubkeys; if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys,vOpretExtra)!=0 && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) { - if (!E_UNMARSHAL(vOpretExtra, { ss >> vopret; })) return (0); + vopret=vOpretExtra; } else GetOpReturnData(scriptPubKey, vopret); if ( vopret.size() > 2 ) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 41cd37e3a..5d803a80e 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -167,12 +167,11 @@ CScript EncodeGatewaysBindOpRet(uint8_t funcid,uint256 tokenid,std::string coin, uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,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) { - std::vector vopret; uint8_t *script,e,f,tokenevalcode; - std::vector vOpretExtra; std::vector pubkeys; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; std::vector pubkeys; if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys,vOpretExtra)!=0 && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) { - if (!E_UNMARSHAL(vOpretExtra, { ss >> vopret; })) return (0); + vopret=vOpretExtra; } else GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); @@ -230,12 +229,11 @@ CScript EncodeGatewaysClaimOpRet(uint8_t funcid,uint256 tokenid,uint256 bindtxid uint8_t DecodeGatewaysClaimOpRet(const CScript &scriptPubKey,uint256 &tokenid,uint256 &bindtxid,std::string &refcoin,uint256 &deposittxid,CPubKey &destpub,int64_t &amount) { - std::vector vopret; uint8_t *script,e,f,tokenevalcode; - std::vector pubkeys; std::vector vOpretExtra; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; std::vector pubkeys; if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys,vOpretExtra)!=0 && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) { - if (!E_UNMARSHAL(vOpretExtra, { ss >> vopret; })) return (0); + vopret=vOpretExtra; } else GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); @@ -260,12 +258,11 @@ CScript EncodeGatewaysWithdrawOpRet(uint8_t funcid,uint256 tokenid,uint256 bindt uint8_t DecodeGatewaysWithdrawOpRet(const CScript &scriptPubKey, uint256& tokenid, uint256 &bindtxid, std::string &refcoin, CPubKey &withdrawpub, int64_t &amount) { - std::vector vopret; uint8_t *script,e,f,tokenevalcode; - std::vector pubkeys; std::vector vOpretExtra; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; std::vector pubkeys; if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys,vOpretExtra)!=0 && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) { - if (!E_UNMARSHAL(vOpretExtra, { ss >> vopret; })) return (0); + vopret=vOpretExtra; } else GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); @@ -339,12 +336,11 @@ uint8_t DecodeGatewaysMarkDoneOpRet(const CScript &scriptPubKey, uint256 &withdr uint8_t DecodeGatewaysOpRet(const CScript &scriptPubKey) { - std::vector vopret; uint8_t *script,e,f,tokenevalcode; - std::vector pubkeys; std::vector vOpretExtra; uint256 tokenid; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; std::vector pubkeys; uint256 tokenid; if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys,vOpretExtra)!=0 && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) { - if (!E_UNMARSHAL(vOpretExtra, { ss >> vopret; })) return (0); + vopret=vOpretExtra; } else GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 4fea0be1e..aca30208b 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -327,27 +327,28 @@ uint8_t _DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& { uint8_t evalCodeTokens = 0; std::vector voutPubkeysDummy; - std::vector vopretExtra, vopretStripped; + std::vector vopretExtra /*, vopretStripped*/; if (DecodeTokenOpRet(scriptPubKey, evalCodeTokens, tokenid, voutPubkeysDummy, vopretExtra) != 0) { - if (vopretExtra.size() > 1) { - // restore the second opret: + /* if (vopretExtra.size() > 1) { + // restore the second opret: - if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size - if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl; - return (uint8_t)0; - } - } - else { + /* unmarshalled in DecodeTokenOpRet: + if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size + if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl; + return (uint8_t)0; + } + } */ + if (vopretExtra.size() < 1) { if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() empty vopretExtra" << std::endl; return (uint8_t)0; } } else { - GetOpReturnData(scriptPubKey, vopretStripped); + GetOpReturnData(scriptPubKey, vopretExtra); } - return _DecodeHeirOpRet(vopretStripped, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); + return _DecodeHeirOpRet(vopretExtra, ownerPubkey, heirPubkey, inactivityTime, heirName, memo, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); } // overload to decode opret in fundingtxid: diff --git a/src/cc/makecclib b/src/cc/makecclib index 0aecab072..ea44acdae 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -1 +1,2 @@ +#!/bin/sh gcc -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o ../libcc.so cclib.cpp diff --git a/src/cc/makerogue b/src/cc/makerogue index 08c86dee8..249e646f5 100755 --- a/src/cc/makerogue +++ b/src/cc/makerogue @@ -1,7 +1,8 @@ +#!/bin/sh cd rogue; ./configure # only need this first time make; cd .. -gcc -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -o librogue.so -c cclib.cpp -lncurses +gcc -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -o librogue.so -c cclib.cpp #gcc -std=c++11 -fPIC -shared -o librogue.so cclib.o rogue/rogue.so cp librogue.so ../libcc.so diff --git a/src/cc/rogue/Makefile.in b/src/cc/rogue/Makefile.in index c2f4e551a..a6d410b23 100644 --- a/src/cc/rogue/Makefile.in +++ b/src/cc/rogue/Makefile.in @@ -101,7 +101,7 @@ HDRS = rogue.h extern.h score.h OBJS1 = vers.$(O) extern.$(O) armor.$(O) chase.$(O) command.$(O) \ daemon.$(O) daemons.$(O) fight.$(O) init.$(O) io.$(O) list.$(O) \ mach_dep.$(O) rogue.$(O) mdport.$(O) misc.$(O) monsters.$(O) \ - move.$(O) new_level.$(O) + move.$(O) new_level.$(O) OBJS2 = options.$(O) pack.$(O) passages.$(O) potions.$(O) rings.$(O) \ rip.$(O) rooms.$(O) save.$(O) scrolls.$(O) state.$(O) sticks.$(O) \ things.$(O) weapons.$(O) wizard.$(O) xcrypt.$(O) diff --git a/src/cc/rogue/armor.c b/src/cc/rogue/armor.c index 5244628b1..20c5704a8 100644 --- a/src/cc/rogue/armor.c +++ b/src/cc/rogue/armor.c @@ -9,7 +9,7 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include +//#include #include "rogue.h" /* diff --git a/src/cc/rogue/chase.c b/src/cc/rogue/chase.c index 73d53e1fd..059df470d 100644 --- a/src/cc/rogue/chase.c +++ b/src/cc/rogue/chase.c @@ -10,8 +10,8 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include +//#include +//#include #include "rogue.h" #define DRAGONSHOT 5 /* one chance in DRAGONSHOT that a dragon will flame */ diff --git a/src/cc/rogue/command.c b/src/cc/rogue/command.c index 9446d704f..6cc6b0763 100644 --- a/src/cc/rogue/command.c +++ b/src/cc/rogue/command.c @@ -10,10 +10,7 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include -#include +//#include #include "rogue.h" /* @@ -272,6 +269,7 @@ over: q_comm = FALSE; if ( rs->guiflag != 0 ) rogue_bailout(rs); + else rs->replaydone = (uint32_t)time(NULL); return; when 'i': after = FALSE; inventory(rs,pack, 0); when 'I': after = FALSE; picky_inven(rs); @@ -312,9 +310,12 @@ over: after = FALSE; msg(rs,"version %s. (mctesq was here)", release); when 'S': - msg(rs,"Saving is disabled, use bailout rpc"); after = FALSE; - //save_game(rs); +#ifdef STANDALONE + save_game(rs); +#else + msg(rs,"Saving is disabled, use bailout rpc"); +#endif when '.': ; /* Rest command */ when ' ': after = FALSE; /* "Legal" illegal command */ when '^': diff --git a/src/cc/rogue/cursesd.c b/src/cc/rogue/cursesd.c new file mode 100644 index 000000000..99274b86f --- /dev/null +++ b/src/cc/rogue/cursesd.c @@ -0,0 +1,423 @@ +/****************************************************************************** + * 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. * + * * + ******************************************************************************/ + +#include "cursesd.h" + +static int32_t endwinflag; +WINDOW *stdscr; +int32_t ESCDELAY; + +WINDOW *newwin(int32_t nlines,int32_t ncols,int32_t begin_y,int32_t begin_x) +{ + WINDOW *scr = 0; + if ( nlines == LINES && ncols == COLS && begin_y == 0 && begin_x == 0 ) + scr = (WINDOW *)calloc(1,sizeof(*stdscr)); + curscr = scr; + return(scr); +} + +WINDOW *initscr() +{ + if ( stdscr == 0 ) + stdscr = newwin(LINES,COLS,0,0); + return(stdscr); +} + +int32_t delwin(WINDOW *win) +{ + free(win); + return(0); +} + +int32_t wmove(WINDOW *win, int32_t y, int32_t x) +{ + win->y = y; + win->x = x; + return(0); +} + +int32_t move(int32_t y, int32_t x) +{ + return(wmove(stdscr,y,x)); +} + +int32_t werase(WINDOW *win) +{ + memset(win->screen,' ',sizeof(win->screen)); + return(0); +} + +int32_t wclear(WINDOW *win) +{ + werase(win); + clearok(win,TRUE); + return(0); +} + +int32_t wclrtoeol(WINDOW *win) +{ + if ( win->x < COLS-1 ) + memset(&win->screen[win->y][win->x],' ',COLS - win->x); + return(0); +} + +int32_t wclrtobot(WINDOW *win) +{ + wclrtoeol(win); + if ( win->y < LINES-1 ) + memset(&win->screen[win->y+1][0],' ',COLS); + return(0); +} + +int32_t erase(void) +{ + return(werase(stdscr)); +} + +int32_t clear(void) +{ + return(wclear(stdscr)); +} + +int32_t clrtobot(void) +{ + return(wclrtobot(stdscr)); +} + +int32_t clrtoeol(void) +{ + return(wclrtoeol(stdscr)); +} + +int32_t waddch(WINDOW *win, chtype ch) +{ + int32_t i; + if ( ch == '\t' ) + { + for (i=0; i<8; i++) + { + if ( win->x >= COLS-1 ) + break; + win->x++; + if ( (win->x & 7) == 0 ) + break; + } + } + else if ( ch == '\n' ) + { + wclrtoeol(win); + win->x = 0; + win->y++; + if ( win->y >= LINES ) + win->y = 0; + } + else if ( ch == '\b' ) + { + if ( win->x > 0 ) + win->x--; + } + else + { + win->screen[win->y][win->x++] = ch; + if ( win->x >= COLS ) + { + win->x = 0; + win->y++; + if ( win->y >= LINES ) + win->y = 0; + } + } + return(0); +} + +int32_t mvwaddch(WINDOW *win, int32_t y, int32_t x, chtype ch) +{ + win->y = y; + win->x = x; + return(waddch(win,ch)); +} + +int32_t addch(chtype ch) +{ + return(waddch(stdscr,ch)); +} + +int32_t mvaddch(int32_t y, int32_t x, chtype ch) +{ + return(mvwaddch(stdscr,y,x,ch)); +} + +int32_t waddstr(WINDOW *win, const char *str) +{ + int32_t i; + for (i=0; str[i]!=0; i++) + waddch(win,str[i]); + return(0); +} + +int32_t waddnstr(WINDOW *win, const char *str, int32_t n) +{ + int32_t i; + for (i=0; str[i]!=0 && iy = y; + win->x = x; + return(waddstr(win,str)); +} + +int32_t mvwaddnstr(WINDOW *win, int32_t y, int32_t x, const char *str, int32_t n) +{ + win->y = y; + win->x = x; + return(waddnstr(win,str,n)); +} + +int32_t addstr(const char *str) +{ + return(waddstr(stdscr,str)); +} + +int32_t addnstr(const char *str, int32_t n) +{ + return(waddnstr(stdscr,str,n)); +} + +int32_t mvaddstr(int32_t y, int32_t x, const char *str) +{ + stdscr->y = y; + stdscr->x = x; + return(waddstr(stdscr,str)); +} + +int32_t mvaddnstr(int32_t y, int32_t x, const char *str, int32_t n) +{ + stdscr->y = y; + stdscr->x = x; + return(waddnstr(stdscr,str,n)); +} + +int32_t printw(char *fmt,...) +{ + char str[512]; int32_t ret; va_list myargs; // Declare a va_list type variable + va_start(myargs,fmt); // Initialise the va_list variable with the ... after fmt + ret = vsprintf(str,fmt,myargs); // Forward the '...' to vsprintf + va_end(myargs); // Clean up the va_list + return(addstr(str)); +} + +int32_t wprintw(WINDOW *win,char *fmt,...) +{ + char str[512]; int32_t ret; va_list myargs; // Declare a va_list type variable + va_start(myargs,fmt); // Initialise the va_list variable with the ... after fmt + ret = vsprintf(str,fmt,myargs); // Forward the '...' to vsprintf + va_end(myargs); // Clean up the va_list + return(waddstr(win,str)); +} + +int32_t mvprintw(int32_t y,int32_t x,char *fmt,...) +{ + char str[512]; int32_t ret; va_list myargs; // Declare a va_list type variable + va_start(myargs,fmt); // Initialise the va_list variable with the ... after fmt + ret = vsprintf(str,fmt,myargs); // Forward the '...' to vsprintf + va_end(myargs); // Clean up the va_list + stdscr->y = y; + stdscr->x = x; + return(addstr(str)); +} + +int32_t mvwprintw(WINDOW *win,int32_t y,int32_t x,char *fmt,...) +{ + char str[512]; int32_t ret; va_list myargs; // Declare a va_list type variable + va_start(myargs,fmt); // Initialise the va_list variable with the ... after fmt + ret = vsprintf(str,fmt,myargs); // Forward the '...' to vsprintf + va_end(myargs); // Clean up the va_list + win->y = y; + win->x = x; + return(waddstr(win,str)); +} + +chtype winch(WINDOW *win) +{ + return(win->screen[win->y][win->x]); +} + +chtype inch(void) +{ + return(winch(stdscr)); +} + +chtype mvwinch(WINDOW *win, int32_t y, int32_t x) +{ + win->y = y; + win->x = x; + return(win->screen[win->y][win->x]); +} + +chtype mvinch(int32_t y, int32_t x) +{ + return(mvwinch(stdscr,y,x)); +} + +int32_t mvcur(int32_t oldrow, int32_t oldcol, int32_t newrow, int32_t newcol) +{ + stdscr->y = newrow; + stdscr->x = newcol; + return(0); +} + +int32_t endwin(void) +{ + if ( stdscr != 0 ) + free(stdscr), stdscr = 0; + endwinflag = 1; + return(0); +} + +int32_t isendwin(void) +{ + return(endwinflag); +} + +int32_t refresh(void) +{ + endwinflag = 0; + return(wrefresh(stdscr)); +} + +int32_t redrawwin(WINDOW *win) +{ + return(wrefresh(win)); +} + +int32_t wredrawln(WINDOW *win, int32_t beg_line, int32_t num_lines) +{ + return(wrefresh(win)); +} + +// functions with no data side effect +#ifdef they_are_macros +int32_t wrefresh(WINDOW *win) +{ + return(0); +} + +int32_t wnoutrefresh(WINDOW *win) +{ + return(0); +} + +int32_t doupdate(void) +{ + return(0); +} + +int32_t touchwin(WINDOW *win) +{ + return(0); +} + +int32_t standout(void) +{ + return(0); +} + +int32_t standend(void) +{ + return(0); +} + +int32_t raw(void) +{ + return(0); +} + +int32_t keypad(WINDOW *win, bool bf) +{ + return(0); +} + +int32_t noecho(void) +{ + return(0); +} + +int32_t flushinp(void) +{ + return(0); +} + +int32_t clearok(WINDOW *win, bool bf) +{ + return(0); +} + +int32_t idlok(WINDOW *win, bool bf) +{ + return(0); +} + +int32_t leaveok(WINDOW *win, bool bf) +{ + return(0); +} +#endif + +int32_t mvwin(WINDOW *win, int32_t y, int32_t x) // stub +{ + fprintf(stderr,"unexpected call to mvwin\n"); + return(0); +} + +WINDOW *subwin(WINDOW *orig, int32_t nlines, int32_t ncols, int32_t begin_y, int32_t begin_x) +{ + fprintf(stderr,"unexpected and unsupported call to subwin\n"); + return(0); +} + +char erasechar(void) +{ + fprintf(stderr,"unexpected and unsupported call to erasechar\n"); + return(8); +} + +char killchar(void) +{ + fprintf(stderr,"unexpected and unsupported call to erasechar\n"); + return(3); +} + +int32_t wgetnstr(WINDOW *win, char *str, int32_t n) // stub +{ + fprintf(stderr,"unexpected and unsupported call to mvgetnstr\n"); + return(0); +} + +int32_t getch(void) +{ + fprintf(stderr,"unexpected and unsupported call to getch\n"); + return(0); +} + +int32_t md_readchar(void) +{ + fprintf(stderr,"unexpected and unsupported call to md_readchar\n"); + return(0); +} + diff --git a/src/cc/rogue/cursesd.h b/src/cc/rogue/cursesd.h new file mode 100644 index 000000000..4fa09e9d9 --- /dev/null +++ b/src/cc/rogue/cursesd.h @@ -0,0 +1,158 @@ +/****************************************************************************** + * 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_CURSESD_H +#define H_CURSESD_H + +#define LINES 24 +#define COLS 80 + +#include +#include +#include +#include +#include +#include +#include /* we need va_list */ +#include /* we want wchar_t */ +#include +#include + +#include +#include +#include +#include +#include + +#define ERR (-1) + +struct cursesd_info +{ + uint8_t screen[LINES][COLS]; + int32_t x,y; +}; +typedef struct cursesd_info WINDOW; +extern WINDOW *stdscr,*curscr; +extern int32_t ESCDELAY; +typedef char chtype; + +int32_t getch(void); // stub +int32_t md_readchar(void); // stub + +WINDOW *initscr(void); +int32_t endwin(void); +int32_t isendwin(void); +//SCREEN *newterm(const char *type, FILE *outfd, FILE *infd); +//SCREEN *set_term(SCREEN *new); +//void delscreen(SCREEN* sp); + +int32_t refresh(void); +int32_t wrefresh(WINDOW *win); +//int32_t wnoutrefresh(WINDOW *win); +//int32_t doupdate(void); +int32_t redrawwin(WINDOW *win); +int32_t wredrawln(WINDOW *win, int32_t beg_line, int32_t num_lines); + +int32_t erase(void); +int32_t werase(WINDOW *win); +int32_t clear(void); +int32_t wclear(WINDOW *win); +int32_t clrtobot(void); +int32_t wclrtobot(WINDOW *win); +int32_t clrtoeol(void); +int32_t wclrtoeol(WINDOW *win); + +int32_t standout(void); +int32_t standend(void); +int32_t raw(void); +int32_t noecho(void); +int32_t flushinp(void); +int32_t keypad(WINDOW *win, bool bf); + +int32_t clearok(WINDOW *win, bool bf); +int32_t idlok(WINDOW *win, bool bf); +int32_t leaveok(WINDOW *win, bool bf); + +WINDOW *newwin(int32_t nlines,int32_t ncols,int32_t begin_y,int32_t begin_x); // only LINES,COLS,0,0 +int32_t delwin(WINDOW *win); +int32_t touchwin(WINDOW *win); // stub +WINDOW *subwin(WINDOW *orig, int32_t nlines, int32_t ncols, int32_t begin_y, int32_t begin_x); // stub +int32_t mvwin(WINDOW *win, int32_t y, int32_t x); // stub +int32_t mvcur(int32_t oldrow, int32_t oldcol, int32_t newrow, int32_t newcol); + +char erasechar(void); // stub +char killchar(void); // stub + +int32_t move(int32_t y, int32_t x); +int32_t wmove(WINDOW *win, int32_t y, int32_t x); + +chtype inch(void); +chtype winch(WINDOW *win); +chtype mvinch(int32_t y, int32_t x); +chtype mvwinch(WINDOW *win, int32_t y, int32_t x); + +int32_t addch(chtype ch); +int32_t waddch(WINDOW *win, chtype ch); +int32_t mvaddch(int32_t y, int32_t x, chtype ch); +int32_t mvwaddch(WINDOW *win, int32_t y, int32_t x, chtype ch); + +int32_t addstr(const char *str); +int32_t addnstr(const char *str, int32_t n); +int32_t waddstr(WINDOW *win, const char *str); +int32_t waddnstr(WINDOW *win, const char *str, int32_t n); +int32_t mvaddstr(int32_t y, int32_t x, const char *str); +int32_t mvaddnstr(int32_t y, int32_t x, const char *str, int32_t n); +int32_t mvwaddstr(WINDOW *win, int32_t y, int32_t x, const char *str); +int32_t mvwaddnstr(WINDOW *win, int32_t y, int32_t x, const char *str, int32_t n); + +int32_t wgetnstr(WINDOW *win, char *str, int32_t n); // stub +int32_t printw(char *fmt,...); +int32_t wprintw(WINDOW *win,char *fmt,...); +int32_t mvprintw(int32_t y,int32_t x,char *fmt,...); +int32_t mvwprintw(WINDOW *win,int32_t y,int32_t x,char *fmt,...); + +#define A_CHARTEXT 0xff +#define baudrate() 9600 +#define unctrl(a) "^x" +#define getmaxx(a) COLS +#define getmaxy(a) LINES +#define getyx(win,_argfory,_argforx) _argfory = win->y, _argforx = win->x + +// functions with only visible effects +#define wrefresh(win) 0 +#define wnoutrefresh(win) 0 +#define doupdate() 0 +#define touchwin(win) 0 +#define standout() 0 +#define standend() 0 +#define raw() 0 +#define keypad(win,bf) 0 +#define noecho() 0 +#define flushinp() 0 +#define clearok(win,bf) 0 +#define idlok(win,bf) 0 +#define leaveok(win,bf) 0 +#define halfdelay(x) 0 +#define nocbreak() 0 + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#endif + diff --git a/src/cc/rogue/daemon.c b/src/cc/rogue/daemon.c index 8309dc642..1da06d499 100644 --- a/src/cc/rogue/daemon.c +++ b/src/cc/rogue/daemon.c @@ -11,7 +11,7 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include +//#include #include "rogue.h" #define EMPTY 0 diff --git a/src/cc/rogue/daemons.c b/src/cc/rogue/daemons.c index 436aa004d..42e685320 100644 --- a/src/cc/rogue/daemons.c +++ b/src/cc/rogue/daemons.c @@ -10,7 +10,7 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include +//#include #include "rogue.h" /* diff --git a/src/cc/rogue/extern.c b/src/cc/rogue/extern.c index 39a48b23f..fdb77307c 100644 --- a/src/cc/rogue/extern.c +++ b/src/cc/rogue/extern.c @@ -10,7 +10,7 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include +//#include #include "rogue.h" diff --git a/src/cc/rogue/extern.h b/src/cc/rogue/extern.h index 486d85ff1..fc3454830 100644 --- a/src/cc/rogue/extern.h +++ b/src/cc/rogue/extern.h @@ -13,6 +13,9 @@ #ifndef H_EXTERN_ROGUE_H #define H_EXTERN_ROGUE_H +#include +#include + #ifdef HAVE_CONFIG_H #ifdef PDCURSES #undef HAVE_UNISTD_H diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index 7f4aad587..43474616e 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -10,10 +10,10 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include "rogue.h" //#define EQSTR(a, b) (strcmp(a, b) == 0) diff --git a/src/cc/rogue/init.c b/src/cc/rogue/init.c index 1f63e1d51..f296d6182 100644 --- a/src/cc/rogue/init.c +++ b/src/cc/rogue/init.c @@ -10,10 +10,10 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include "rogue.h" /* @@ -27,7 +27,7 @@ void restore_player(struct rogue_state *rs) int32_t i; THING *obj; //rs->P.gold = purse; max_hp = rs->P.hitpoints; - max_stats.s_str = rs->P.strength; + pstats.s_str = max_stats.s_str = rs->P.strength; pstats.s_lvl = rs->P.level; pstats.s_exp = rs->P.experience; for (i=0; iP.packsize; i++) @@ -49,7 +49,11 @@ void init_player(struct rogue_state *rs) // duplicate rng usage of normal case obj = new_item(); init_weapon(obj, MACE); + free(obj); + obj = new_item(); init_weapon(obj, BOW); + free(obj); + obj = new_item(); init_weapon(obj, ARROW); obj->o_count = rnd(15) + 25; free(obj); diff --git a/src/cc/rogue/io.c b/src/cc/rogue/io.c index 30795f2ad..c920ee411 100644 --- a/src/cc/rogue/io.c +++ b/src/cc/rogue/io.c @@ -4,10 +4,11 @@ * @(#)io.c 4.32 (Berkeley) 02/05/99 */ -#include -#include -#include -#include +//#include +//#include +//#include +//#include + #include "rogue.h" /* @@ -155,6 +156,7 @@ readchar(struct rogue_state *rs) char ch = -1; if ( rs != 0 && rs->guiflag == 0 ) { + static uint32_t counter; if ( rs->ind < rs->numkeys ) { //if ( rs->ind == rs->numkeys-1 ) @@ -162,12 +164,15 @@ readchar(struct rogue_state *rs) //fprintf(stderr,"(%c) ",rs->keystrokes[rs->ind]); return(rs->keystrokes[rs->ind++]); } - fprintf(stderr,"replay finished but readchar called\n"); + if ( rs->replaydone != 0 && counter++ < 3 ) + fprintf(stderr,"replay finished but readchar called\n"); rs->replaydone = (uint32_t)time(NULL); //if ( (rand() & 1) == 0 ) // return(ESCAPE); //else - return('y'); + if ( counter < 3 || (counter & 1) == 0 ) + return('y'); + else return(ESCAPE); } if ( rs == 0 || rs->guiflag != 0 ) { diff --git a/src/cc/rogue/list.c b/src/cc/rogue/list.c index 6affc662c..622af60cd 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -10,9 +10,9 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include +//#include +//#include +//#include #include "rogue.h" #ifdef MASTER diff --git a/src/cc/rogue/mach_dep.c b/src/cc/rogue/mach_dep.c index 34e502816..6d0e1c66f 100644 --- a/src/cc/rogue/mach_dep.c +++ b/src/cc/rogue/mach_dep.c @@ -46,7 +46,8 @@ #include #include #include -#include +//#include +#include "rogue.h" #include "extern.h" #define NOOP(x) (x += 0) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 21c52deab..12e6af368 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -19,6 +19,7 @@ #include #include #include +#include #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) @@ -251,7 +252,7 @@ int main(int argc, char **argv, char **envp) if ( argc == 2 && (fp=fopen(argv[1],"rb")) == 0 ) { seed = atol(argv[1]); - fprintf(stderr,"replay %llu\n",(long long)seed); + //fprintf(stderr,"replay %llu\n",(long long)seed); return(rogue_replay(seed,50000)); } else diff --git a/src/cc/rogue/mdport.c b/src/cc/rogue/mdport.c index acd257617..841dffbb8 100644 --- a/src/cc/rogue/mdport.c +++ b/src/cc/rogue/mdport.c @@ -44,7 +44,7 @@ #undef MOUSE_MOVED #endif -#include +//#include #include "extern.h" #if defined(HAVE_SYS_TYPES) @@ -81,7 +81,12 @@ #endif #endif +#ifndef BUILD_ROGUE #include /* AIX requires curses.h be included before term.h */ +#else +#include "cursesd.h" +#endif + #if defined(HAVE_TERM_H) #include @@ -1076,6 +1081,7 @@ md_setsuspchar(int c) #define M_KEYPAD 2 #define M_TRAIL 3 +#ifndef BUILD_ROGUE int md_readchar() { @@ -1315,7 +1321,8 @@ md_readchar() return(ch & 0x7F); } - +#endif + #if defined(LOADAV) && defined(HAVE_NLIST_H) && defined(HAVE_NLIST) /* * loadav: diff --git a/src/cc/rogue/misc.c b/src/cc/rogue/misc.c index 168886b6b..7db9d073a 100644 --- a/src/cc/rogue/misc.c +++ b/src/cc/rogue/misc.c @@ -10,10 +10,10 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include "rogue.h" /* diff --git a/src/cc/rogue/monsters.c b/src/cc/rogue/monsters.c index 4649de9a2..2f6d68362 100644 --- a/src/cc/rogue/monsters.c +++ b/src/cc/rogue/monsters.c @@ -10,10 +10,10 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include +//#include +//#include #include "rogue.h" -#include +//#include /* * List of monsters in rough order of vorpalness diff --git a/src/cc/rogue/move.c b/src/cc/rogue/move.c index 3bdf90d37..c70d668ca 100644 --- a/src/cc/rogue/move.c +++ b/src/cc/rogue/move.c @@ -10,8 +10,8 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include +//#include +//#include #include "rogue.h" /* diff --git a/src/cc/rogue/new_level.c b/src/cc/rogue/new_level.c index 9dc0d761f..b55d3e42c 100644 --- a/src/cc/rogue/new_level.c +++ b/src/cc/rogue/new_level.c @@ -11,8 +11,8 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include +//#include +//#include #include "rogue.h" #define TREAS_ROOM 20 /* one chance in TREAS_ROOM for a treasure room */ diff --git a/src/cc/rogue/options.c b/src/cc/rogue/options.c index 6907da598..258bd184f 100644 --- a/src/cc/rogue/options.c +++ b/src/cc/rogue/options.c @@ -12,10 +12,10 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include "rogue.h" #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) @@ -266,7 +266,7 @@ get_str(struct rogue_state *rs,void *vopt, WINDOW *win) { if (c == -1) continue; - else if (c == erasechar()) /* process erase character */ + /*else if (c == erasechar()) // process erase character { if (sp > buf) { @@ -276,12 +276,12 @@ get_str(struct rogue_state *rs,void *vopt, WINDOW *win) } continue; } - else if (c == killchar()) /* process kill character */ + else if (c == killchar()) // process kill character { sp = buf; wmove(win, oy, ox); continue; - } + }*/ else if (sp == buf) { if (c == '-' && win != stdscr) diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index ee628b4f0..2f683441b 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -10,9 +10,9 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include +//#include +//#include +//#include #include "rogue.h" /* @@ -165,6 +165,7 @@ out: bool pack_room(struct rogue_state *rs,bool from_floor, THING *obj) { + inpack = num_packitems(); if (++inpack > MAXPACK) { if (!terse) @@ -178,7 +179,8 @@ pack_room(struct rogue_state *rs,bool from_floor, THING *obj) inpack = MAXPACK; return FALSE; } - + //fprintf(stderr,"inpack.%d vs MAX.%d\n",inpack,MAXPACK), sleep(2); + if (from_floor) { detach(lvl_obj, obj); @@ -244,6 +246,16 @@ pack_char() * List what is in the pack. Return TRUE if there is something of * the given type. */ + +int32_t num_packitems() +{ + THING *list = pack; + int32_t type = 0,n = 0; + for (; list != NULL; list = next(list)) + n++; + return(n); +} + bool inventory(struct rogue_state *rs,THING *list, int type) { @@ -272,6 +284,8 @@ inventory(struct rogue_state *rs,THING *list, int type) } msg_esc = FALSE; } + //if ( n_objs != inpack ) + // fprintf(stderr,"n_objs.%d vs inpack.%d\n",n_objs,inpack), sleep(2); if (n_objs == 0) { if (terse) diff --git a/src/cc/rogue/passages.c b/src/cc/rogue/passages.c index 79b3706aa..5437f4972 100644 --- a/src/cc/rogue/passages.c +++ b/src/cc/rogue/passages.c @@ -10,8 +10,8 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include +//#include +//#include #include "rogue.h" /* diff --git a/src/cc/rogue/potions.c b/src/cc/rogue/potions.c index de09efb9b..00865b5dd 100644 --- a/src/cc/rogue/potions.c +++ b/src/cc/rogue/potions.c @@ -10,8 +10,8 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include +//#include +//#include #include "rogue.h" typedef struct diff --git a/src/cc/rogue/rings.c b/src/cc/rogue/rings.c index 56f7a0294..747da302a 100644 --- a/src/cc/rogue/rings.c +++ b/src/cc/rogue/rings.c @@ -10,7 +10,7 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include +//#include #include "rogue.h" /* diff --git a/src/cc/rogue/rip.c b/src/cc/rogue/rip.c index a5b3e7208..65be2e8fa 100644 --- a/src/cc/rogue/rip.c +++ b/src/cc/rogue/rip.c @@ -11,14 +11,14 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include +//#include +//#include +//#include #include -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include "rogue.h" #include "score.h" @@ -87,6 +87,7 @@ score(struct rogue_state *rs,int amount, int flags, char monst) delwin(curscr); if (hw != NULL) delwin(hw); + hw = NULL; } top_ten = (SCORE *) malloc(numscores * sizeof (SCORE)); diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 00cda9426..b709e8d3a 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -8,12 +8,11 @@ * @(#)main.c 4.22 (Berkeley) 02/05/99 */ -#include -#include +//#include +//#include #include -#include -#include -#include +//#include +//#include #include "rogue.h" #ifdef STANDALONE #include "../komodo/src/komodo_cJSON.h" @@ -88,9 +87,13 @@ void rogueiterate(struct rogue_state *rs) endwin(); my_exit(1); } + //fprintf(stderr,"LINES %d, COLS %d\n",LINES,COLS); + // Set up windows if ( hw == NULL ) + { hw = newwin(LINES, COLS, 0, 0); + } idlok(stdscr, TRUE); idlok(hw, TRUE); #ifdef MASTER @@ -103,7 +106,9 @@ void rogueiterate(struct rogue_state *rs) fuse(swander, 0, WANDERTIME, AFTER); start_daemon(stomach, 0, AFTER); if ( rs->restoring != 0 ) + { restore_player(rs); + } playit(rs); } @@ -231,37 +236,40 @@ void rogue_bailout(struct rogue_state *rs) fprintf(stderr,"error issuing (%s)\n",cmd); } -int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player) +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; rs = (struct rogue_state *)calloc(1,sizeof(*rs)); rs->seed = seed; rs->keystrokes = keystrokes; rs->numkeys = num; - rs->sleeptime = 0*50000; + rs->sleeptime = sleepmillis * 1000; if ( player != 0 ) { rs->P = *player; rs->restoring = 1; - fprintf(stderr,"restore player packsize.%d\n",rs->P.packsize); + //fprintf(stderr,"restore player packsize.%d HP.%d\n",rs->P.packsize,rs->P.hitpoints); } uint32_t starttime = (uint32_t)time(NULL); rogueiterate(rs); - /*fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime); - sleep(2); - - starttime = (uint32_t)time(NULL); - for (i=0; i<100; i++) + if ( 0 ) { - memset(rs,0,sizeof(*rs)); - rs->seed = seed; - rs->keystrokes = keystrokes; - rs->numkeys = num; - rs->sleeptime = 0; - rogueiterate(rs); + 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; + rogueiterate(rs); + } + fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL)-starttime); + sleep(3); } - fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL)-starttime); - sleep(1);*/ if ( (fp= fopen("checkfile","wb")) != 0 ) { save_file(rs,fp,0); @@ -284,17 +292,19 @@ long get_filesize(FILE *fp) int32_t rogue_replay(uint64_t seed,int32_t sleeptime) { - FILE *fp; char fname[1024]; char *keystrokes = 0; long num=0,fsize; int32_t i,counter = 0; struct rogue_state *rs; + FILE *fp; char fname[1024]; char *keystrokes = 0; long num=0,fsize; int32_t i,counter = 0; struct rogue_state *rs; struct rogue_player P,*player = 0; if ( seed == 0 ) seed = 777; while ( 1 ) { roguefname(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 ) @@ -316,8 +326,19 @@ int32_t rogue_replay(uint64_t seed,int32_t sleeptime) } if ( num > 0 ) { - rogue_replay2(0,seed,keystrokes,num,0); - mvaddstr(LINES - 2, 0, (char *)"replay completed"); + sprintf(fname,"rogue.%llu.player",(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); + } + rogue_replay2(0,seed,keystrokes,num,player,150); + + //mvaddstr(LINES - 2, 0, (char *)"replay completed"); endwin(); } if ( keystrokes != 0 ) @@ -523,9 +544,11 @@ tstp(int ignored) fflush(stdout); //wmove(curscr,oy,ox); #ifndef __APPLE__ +#ifndef BUILD_ROGUE curscr->_cury = oy; curscr->_curx = ox; #endif +#endif } /* @@ -569,7 +592,8 @@ playit(struct rogue_state *rs) { if ( rs->replaydone != 0 ) { - //fprintf(stderr,"replaydone\n"); sleep(3); + if ( rs->sleeptime != 0 ) + sleep(3); return; } if ( rs->sleeptime != 0 ) @@ -626,8 +650,8 @@ quit(int sig) } else { - score(rs,purse, 1, 0); - fprintf(stderr,"done!\n"); + //score(rs,purse, 1, 0); + //fprintf(stderr,"done!\n"); } } else diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index 5eccb2e8c..a5ddf943f 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -12,9 +12,42 @@ #ifndef H_ROGUE_H #define H_ROGUE_H +#include +#include +#include +#include +#include +#include +#include /* we need va_list */ +#include /* we want wchar_t */ +#include +#include + +#include +#include +#include +#include +#include + +#ifndef BUILD_ROGUE +#include +#else +#include "cursesd.h" +#endif + +#ifdef LINES +#undef LINES +#endif +#ifdef COLS +#undef COLS +#endif + +#define LINES 24 +#define COLS 80 #include "extern.h" + #undef lines #define NOOP(x) (x += 0) @@ -358,7 +391,7 @@ int32_t roguefname(char *fname,uint64_t seed,int32_t counter); int32_t flushkeystrokes(struct rogue_state *rs); int32_t rogue_restorepack(struct rogue_state *rs); void restore_player(struct rogue_state *rs); -int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player); +int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player,int32_t sleepmillis); void rogue_bailout(struct rogue_state *rs); /* @@ -782,6 +815,7 @@ THING *leave_pack(struct rogue_state *rs,THING *obj, bool newobj, bool all); THING *new_item(void); THING *new_thing(struct rogue_state *rs); void end_line(struct rogue_state *rs); +int32_t num_packitems(); void runners(struct rogue_state *rs,int); void land(struct rogue_state *rs,int); @@ -826,5 +860,8 @@ extern const char *wood[]; extern int cNWOOD; extern const char *metal[]; extern int cNMETAL; + +//extern WINDOW *stdscr,*curscr; + #endif diff --git a/src/cc/rogue/rooms.c b/src/cc/rogue/rooms.c index 31991b08f..41041d627 100644 --- a/src/cc/rogue/rooms.c +++ b/src/cc/rogue/rooms.c @@ -10,8 +10,8 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include +//#include +//#include #include "rogue.h" typedef struct spot { /* position matrix for maze positions */ diff --git a/src/cc/rogue/save.c b/src/cc/rogue/save.c index adec30e2e..15dda401e 100644 --- a/src/cc/rogue/save.c +++ b/src/cc/rogue/save.c @@ -10,13 +10,13 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include #include "rogue.h" #include "score.h" @@ -165,21 +165,24 @@ save_file(struct rogue_state *rs,FILE *savef,int32_t guiflag) memset(histo,0,sizeof(histo)); for (i=0; iP)[i]); + //fprintf(stderr,"%02x",((uint8_t *)&rs->P)[i]); histo[((uint8_t *)&rs->P)[i]]++; rs->playerdata[i] = ((uint8_t *)&rs->P)[i]; } rs->playersize = n; - fprintf(stderr," packsize.%d n.%d\n",rs->P.packsize,n); + //fprintf(stderr," packsize.%d n.%d\n",rs->P.packsize,n); if ( (fp= fopen(rogue_packfname(rs,fname),"wb")) != 0 ) { fwrite(&rs->P,1,n,fp); fclose(fp); } - for (i=nonz=0; i<0x100; i++) - if ( histo[i] != 0 ) - fprintf(stderr,"(%d %d) ",i,histo[i]), nonz++; - fprintf(stderr,"nonz.%d\n",nonz); + if ( 0 ) + { + for (i=nonz=0; i<0x100; i++) + if ( histo[i] != 0 ) + fprintf(stderr,"(%d %d) ",i,histo[i]), nonz++; + fprintf(stderr,"nonz.%d\n",nonz); + } fflush(savef); fclose(savef); if ( guiflag != 0 ) @@ -224,7 +227,9 @@ restore(struct rogue_state *rs,char *file, char **envp) char buf[MAXSTR]; //auto STAT sbuf2; - + if ( rs->guiflag == 0 ) + return(0); + if (strcmp(file, "-r") == 0) file = file_name; diff --git a/src/cc/rogue/scrolls.c b/src/cc/rogue/scrolls.c index b6854ab07..5554a5701 100644 --- a/src/cc/rogue/scrolls.c +++ b/src/cc/rogue/scrolls.c @@ -10,8 +10,8 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include +//#include +//#include #include "rogue.h" /* diff --git a/src/cc/rogue/state.c b/src/cc/rogue/state.c index 3db54a319..e738a9d16 100644 --- a/src/cc/rogue/state.c +++ b/src/cc/rogue/state.c @@ -29,9 +29,9 @@ SUCH DAMAGE. */ -#include -#include -#include +//#include +//#include +//#include #include "rogue.h" /************************************************************************/ @@ -1434,7 +1434,7 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) item = &rs->P.roguepack[rs->P.packsize]; if ( pstats.s_hpt <= 0 ) { - fprintf(stderr,"KILLED\n"); + //fprintf(stderr,"KILLED\n"); rs->P.gold = -1; rs->P.hitpoints = -1; rs->P.strength = -1; @@ -1448,13 +1448,13 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) { rs->P.gold = purse; rs->P.hitpoints = max_hp; - rs->P.strength = max_stats.s_str; + rs->P.strength = pstats.s_str; //max_stats.s_str; rs->P.level = pstats.s_lvl; rs->P.experience = pstats.s_exp; rs->P.dungeonlevel = level; - fprintf(stderr,"%ld gold.%d hp.%d strength.%d level.%d exp.%d %d\n",ftell(savef),purse,max_hp,max_stats.s_str,pstats.s_lvl,pstats.s_exp,level); + //fprintf(stderr,"%ld gold.%d hp.%d strength.%d level.%d exp.%d %d\n",ftell(savef),purse,max_hp,max_stats.s_str,pstats.s_lvl,pstats.s_exp,level); } - fprintf(stderr,"object (%s) x.%d y.%d type.%d pack.(%c:%d)\n",inv_name(o,FALSE),o->_o._o_pos.x,o->_o._o_pos.y,o->_o._o_type,o->_o._o_packch,o->_o._o_packch); + //fprintf(stderr,"object (%s) x.%d y.%d type.%d pack.(%c:%d)\n",inv_name(o,FALSE),o->_o._o_pos.x,o->_o._o_pos.y,o->_o._o_type,o->_o._o_packch,o->_o._o_packch); if ( rs->P.packsize < MAXPACK && o->o_type != AMULET ) { packsave(item,o->_o._o_type,o->_o._o_launch,o->_o._o_damage,sizeof(o->_o._o_damage),o->_o._o_hurldmg,sizeof(o->_o._o_hurldmg),o->_o._o_count,o->_o._o_which,o->_o._o_hplus,o->_o._o_dplus,o->_o._o_arm,o->_o._o_flags,o->_o._o_group); diff --git a/src/cc/rogue/sticks.c b/src/cc/rogue/sticks.c index 39e098339..f048f9423 100644 --- a/src/cc/rogue/sticks.c +++ b/src/cc/rogue/sticks.c @@ -11,9 +11,9 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include +//#include +//#include +//#include #include "rogue.h" /* diff --git a/src/cc/rogue/things.c b/src/cc/rogue/things.c index 4e572c60b..39c7b94b7 100644 --- a/src/cc/rogue/things.c +++ b/src/cc/rogue/things.c @@ -11,9 +11,9 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include +//#include +//#include +//#include #include "rogue.h" /* @@ -498,55 +498,62 @@ add_line(struct rogue_state *rs,char *fmt, char *arg) if (line_cnt >= LINES - 1 || fmt == NULL) { if (inv_type == INV_OVER && fmt == NULL && !newpage) - { - msg(rs,""); + { + msg(rs,""); if ( rs->sleeptime != 0 ) refresh(); - tw = newwin(line_cnt + 1, maxlen + 2, 0, COLS - maxlen - 3); - sw = subwin(tw, line_cnt + 1, maxlen + 1, 0, COLS - maxlen - 2); - for (y = 0; y <= line_cnt; y++) - { - wmove(sw, y, 0); - for (x = 0; x <= maxlen; x++) - waddch(sw, mvwinch(hw, y, x)); - } - wmove(tw, line_cnt, 1); - waddstr(tw, prompt); - /* - * if there are lines below, use 'em - */ - if (LINES > NUMLINES) - { - if (NUMLINES + line_cnt > LINES) - mvwin(tw, LINES - (line_cnt + 1), COLS - maxlen - 3); - else - mvwin(tw, NUMLINES, 0); - } - touchwin(tw); - wrefresh(tw); - wait_for(rs,' '); + if ( rs->guiflag != 0 ) + { + tw = newwin(line_cnt + 1, maxlen + 2, 0, COLS - maxlen - 3); + sw = subwin(tw, line_cnt + 1, maxlen + 1, 0, COLS - maxlen - 2); + for (y = 0; y <= line_cnt; y++) + { + wmove(sw, y, 0); + for (x = 0; x <= maxlen; x++) + waddch(sw, mvwinch(hw, y, x)); + } + wmove(tw, line_cnt, 1); + waddstr(tw, prompt); + /* + * if there are lines below, use 'em + */ + if (LINES > NUMLINES) + { + if (NUMLINES + line_cnt > LINES) + mvwin(tw, LINES - (line_cnt + 1), COLS - maxlen - 3); + else + mvwin(tw, NUMLINES, 0); + } + touchwin(tw); + wrefresh(tw); + wait_for(rs,' '); if (md_hasclreol()) - { - werase(tw); - leaveok(tw, TRUE); - wrefresh(tw); - } - delwin(tw); - touchwin(stdscr); + { + werase(tw); + leaveok(tw, TRUE); + wrefresh(tw); + } + delwin(tw); + touchwin(stdscr); + } + else + { + wait_for(rs,' '); + } } else { - wmove(hw, LINES - 1, 0); - waddstr(hw, prompt); - wrefresh(hw); - wait_for(rs,' '); - clearok(curscr, TRUE); - wclear(hw); - touchwin(stdscr); - } - newpage = TRUE; - line_cnt = 0; - maxlen = (int) strlen(prompt); + wmove(hw, LINES - 1, 0); + waddstr(hw, prompt); + wrefresh(hw); + wait_for(rs,' '); + clearok(curscr, TRUE); + wclear(hw); + touchwin(stdscr); + } + newpage = TRUE; + line_cnt = 0; + maxlen = (int) strlen(prompt); } if (fmt != NULL && !(line_cnt == 0 && *fmt == '\0')) { diff --git a/src/cc/rogue/weapons.c b/src/cc/rogue/weapons.c index 6693f0814..e5a5eacf6 100644 --- a/src/cc/rogue/weapons.c +++ b/src/cc/rogue/weapons.c @@ -10,9 +10,9 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include +//#include +//#include +//#include #include "rogue.h" #define NO_WEAPON -1 diff --git a/src/cc/rogue/wizard.c b/src/cc/rogue/wizard.c index e56928d33..ee16b2d9b 100644 --- a/src/cc/rogue/wizard.c +++ b/src/cc/rogue/wizard.c @@ -11,10 +11,10 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include "rogue.h" /* diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index f37d587ea..4d6167b3f 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -22,7 +22,24 @@ #define ROGUE_MAXPLAYERS 64 // need to send unused fees back to globalCC address to prevent leeching #define ROGUE_MAXKEYSTROKESGAP 60 #define ROGUE_MAXITERATIONS 777 -std::string Rogue_pname = "fred"; + +#define MAXPACK 23 +struct rogue_packitem +{ + int32_t type,launch,count,which,hplus,dplus,arm,flags,group; + char damage[8],hurldmg[8]; +}; +struct rogue_player +{ + int32_t gold,hitpoints,strength,level,experience,packsize,dungeonlevel,pad; + struct rogue_packitem roguepack[MAXPACK]; +}; +int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player,int32_t sleepmillis); +#define ROGUE_DECLARED_PACK +void rogue_packitemstr(char *packitemstr,struct rogue_packitem *item); + + +std::string Rogue_pname = ""; /* Roguelander - using highlander competition between rogue players @@ -133,20 +150,6 @@ std::string Rogue_pname = "fred"; // ./c cclib bailout 17 \"[%226d3243c6e5ab383898b28a87e01f6c00b5bdd9687020f17f5caacc8a61febd19%22]\" // ./komodo-cli -ac_name=ROGUE cclib register 17 \"[%22a898f4ceef7647ba113b9f3c24ef045f5d134935a3b09bdd1a997b9d474f4c1b%22,%22f11d0cb4e2e4c21f029a1146f8e5926f11456885b7ab7d665096f5efedec8ea0%22]\" -#define MAXPACK 23 -struct rogue_packitem -{ - int32_t type,launch,count,which,hplus,dplus,arm,flags,group; - char damage[8],hurldmg[8]; -}; -struct rogue_player -{ - int32_t gold,hitpoints,strength,level,experience,packsize,dungeonlevel,pad; - struct rogue_packitem roguepack[MAXPACK]; -}; -int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player); -#define ROGUE_DECLARED_PACK -void rogue_packitemstr(char *packitemstr,struct rogue_packitem *item); CScript rogue_newgameopret(int64_t buyin,int32_t maxplayers) { @@ -400,7 +403,7 @@ UniValue rogue_playerobj(std::vector playerdata,uint256 playertxid,uint 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("name",pname)); + obj.push_back(Pair("pname",pname)); return(obj); } @@ -823,6 +826,83 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param } else return(cclib_error(result,"couldnt reparse params")); } +UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result; CPubKey pk,roguepk; int32_t i,n,num,maxplayers,gameheight,batonht,batonvout,numplayers,regslot,numkeys,err; std::string symbol,pname; CTransaction gametx; uint64_t seed,mult; int64_t buyin,batonvalue; char rogueaddr[64],fname[64],*pubstr,*keystrokes = 0; std::vector playerdata,newdata; uint256 batontxid,playertxid,gametxid; FILE *fp; uint8_t player[10000],pub33[33]; + pk = pubkey2pk(Mypubkey()); + roguepk = GetUnspendable(cp,0); + result.push_back(Pair("status","success")); + result.push_back(Pair("name","rogue")); + result.push_back(Pair("method","extract")); + if ( (params= cclib_reparse(&n,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 && strlen(pubstr) == 66 ) + { + decode_hex(pub33,33,pubstr); + pk = buf2pk(pub33); + } + fprintf(stderr,"gametxid.%s %s\n",gametxid.GetHex().c_str(),pubstr); + } + GetCCaddress1of2(cp,rogueaddr,roguepk,pk); + result.push_back(Pair("rogueaddr",rogueaddr)); + if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid)) == 0 ) + { + if ( rogue_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,rogueaddr,numplayers,symbol,pname) == 0 ) + { + UniValue obj; struct rogue_player P; + seed = rogue_gamefields(obj,maxplayers,buyin,gametxid,rogueaddr); + fprintf(stderr,"(%s) found baton %s numkeys.%d seed.%llu playerdata.%d\n",pname.size()!=0?pname.c_str():Rogue_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 no playerdata\n"); + newdata.resize(0); + } + fprintf(stderr,"\nextracted $$$gold.%d hp.%d strength.%d level.%d exp.%d dl.%d n.%d size.%d\n",P.gold,P.hitpoints,P.strength,P.level,P.experience,P.dungeonlevel,n,(int32_t)sizeof(P)); + if ( keystrokes != 0 ) + free(keystrokes); + } else num = 0; + } + } + } + } + return(result); +} + UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params,char *method) { //vin0 -> highlander vout from creategame TCBOO @@ -866,15 +946,11 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param result.push_back(Pair("gametxid",gametxid.GetHex())); if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid)) == 0 ) { - if ( maxplayers == 1 ) - mult /= 2; if ( rogue_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,myrogueaddr,numplayers,symbol,pname) == 0 ) { UniValue obj; struct rogue_player P; - if ( pname.size() == 0 ) - pname = Rogue_pname; seed = rogue_gamefields(obj,maxplayers,buyin,gametxid,myrogueaddr); - fprintf(stderr,"(%s) found baton %s numkeys.%d seed.%llu playerdata.%d\n",pname.c_str(),batontxid.ToString().c_str(),numkeys,(long long)seed,(int32_t)playerdata.size()); + fprintf(stderr,"(%s) found baton %s numkeys.%d seed.%llu playerdata.%d\n",pname.size()!=0?pname.c_str():Rogue_pname.c_str(),batontxid.ToString().c_str(),numkeys,(long long)seed,(int32_t)playerdata.size()); memset(&P,0,sizeof(P)); if ( playerdata.size() > 0 ) { @@ -883,7 +959,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param } if ( keystrokes != 0 ) { - num = rogue_replay2(player,seed,keystrokes,numkeys,playerdata.size()==0?0:&P); + num = rogue_replay2(player,seed,keystrokes,numkeys,playerdata.size()==0?0:&P,0); if ( keystrokes != 0 ) free(keystrokes); } else num = 0; @@ -906,6 +982,8 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param } else { + if ( maxplayers == 1 ) + mult /= 2; 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)); @@ -930,6 +1008,8 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param Myprivkey(mypriv); CCaddr1of2set(cp,roguepk,mypk,mypriv,myrogueaddr); CScript opret; + if ( pname.size() == 0 ) + pname = Rogue_pname; if ( newdata.size() == 0 ) { opret = rogue_highlanderopret(funcid, gametxid, regslot, mypk, nodata,pname); @@ -1025,7 +1105,7 @@ UniValue rogue_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) result.push_back(Pair("result","success")); rogue_univalue(result,"pending",-1,-1); result.push_back(Pair("pending",a)); - result.push_back(Pair("numpending",a.size())); + result.push_back(Pair("numpending",(int64_t)a.size())); return(result); } @@ -1052,7 +1132,7 @@ UniValue rogue_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) } } result.push_back(Pair("playerdata",a)); - result.push_back(Pair("numplayerdata",a.size())); + result.push_back(Pair("numplayerdata",(int64_t)a.size())); return(result); } @@ -1091,7 +1171,7 @@ UniValue rogue_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) } result.push_back(Pair("pastgames",b)); result.push_back(Pair("games",a)); - result.push_back(Pair("numgames",a.size()+b.size())); + result.push_back(Pair("numgames",(int64_t)(a.size()+b.size()))); return(result); } @@ -1106,7 +1186,7 @@ UniValue rogue_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( (namestr= jstri(params,0)) != 0 ) { result.push_back(Pair("result","success")); - result.push_back(Pair("name",namestr)); + result.push_back(Pair("pname",namestr)); Rogue_pname = namestr; return(result); }