Merge pull request #82 from jl777/FSM

Merge latest FSM down
This commit is contained in:
blackjok3rtt
2019-02-18 19:20:07 +08:00
committed by GitHub
25 changed files with 845 additions and 327 deletions

View File

@@ -14,10 +14,10 @@ define $(package)_set_vars
endef
else
package=zeromq
$(package)_version=4.2.1
$(package)_download_path=https://github.com/zeromq/libzmq/releases/download/v$($(package)_version)
$(package)_version=4.3.1
$(package)_download_path=https://github.com/zeromq/libzmq/releases/download/v$($(package)_version)/
$(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=27d1e82a099228ee85a7ddb2260f40830212402c605a4a10b5e5498a7e0e9d03
$(package)_sha256_hash=bcbabe1e2c7d0eec4ed612e10b94b112dd5f06fcefa994a0c79a45d835cd21eb
define $(package)_set_vars
$(package)_config_opts=--without-documentation --disable-shared --disable-curve

View File

@@ -578,9 +578,9 @@ komodod_LDADD += \
$(LIBZCASH_LIBS)
if TARGET_DARWIN
komodod_LDADD += libcc.dylib -lncurses
komodod_LDADD += libcc.dylib # -lncurses
else
komodod_LDADD += libcc.so -lncurses
komodod_LDADD += libcc.so # -lncurses
endif

View File

@@ -907,10 +907,12 @@ std::string CreateToken(int64_t txfee, int64_t tokensupply, std::string name, st
if( nonfungibleData.size() > 0 )
destEvalCode = nonfungibleData.begin()[0];
// NOTE: we should prevent spending fake-tokens from this marker in IsTokenvout():
mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(cp, NULL))); // new marker to token cc addr, burnable and validated, vout pos now changed to 0 (from 1)
mtx.vout.push_back(MakeTokensCC1vout(destEvalCode, tokensupply, mypk));
//mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(cp->CChexstr) << OP_CHECKSIG)); // old marker (non-burnable because spending could not be validated)
// NOTE: we should prevent spending fake-tokens from this marker in IsTokenvout():
mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(cp, NULL))); // new marker to token cc addr, burnable and validated, this vout must be=1
//mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(cp, NULL))); // ...moved to vout=0 for matching with rogue-game token
return(FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeTokenCreateOpRet('c', Mypubkey(), name, description, nonfungibleData)));
}
@@ -1007,8 +1009,11 @@ UniValue TokenInfo(uint256 tokenid)
std::vector<uint8_t> origpubkey;
std::vector<uint8_t> vopretNonfungible;
std::string name, description;
struct CCcontract_info *cpTokens, tokensCCinfo;
if (GetTransaction(tokenid, vintx, hashBlock, false) == 0)
cpTokens = CCinit(&tokensCCinfo, EVAL_TOKENS);
if( !GetTransaction(tokenid, vintx, hashBlock, false) )
{
fprintf(stderr, "TokenInfo() cant find tokenid\n");
result.push_back(Pair("result", "error"));
@@ -1020,17 +1025,23 @@ UniValue TokenInfo(uint256 tokenid)
LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "TokenInfo() passed tokenid isnt token creation txid" << std::endl);
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "tokenid isnt token creation txid"));
return result;
}
result.push_back(Pair("result", "success"));
result.push_back(Pair("tokenid", tokenid.GetHex()));
result.push_back(Pair("owner", HexStr(origpubkey)));
result.push_back(Pair("name", name));
result.push_back(Pair("supply", vintx.vout[0].nValue));
int64_t supply = 0, output;
for (int v = 0; v < vintx.vout.size() - 1; v++)
if ((output = IsTokensvout(false, true, cpTokens, NULL, vintx, v, tokenid)) > 0)
supply += output;
result.push_back(Pair("supply", supply));
result.push_back(Pair("description", description));
if( !vopretNonfungible.empty() )
result.push_back(Pair("data", HexStr(vopretNonfungible)));
return(result);
return result;
}
UniValue TokenList()

View File

@@ -177,7 +177,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti
// find single-eval token user cc addr:
//GetCCaddress(cpTokens, signleEvalTokensCCaddr, pubkey2pk(origpubkey));
fprintf(stderr,"AssetValidate (%c)\n",funcid);
//fprintf(stderr,"AssetValidate (%c)\n",funcid);
if( funcid != 'o' && funcid != 'x' && eval->GetTxUnconfirmed(assetid, createTx, hashBlock) == 0 )
return eval->Invalid("cant find asset create txid");

View File

@@ -76,7 +76,7 @@ CClib_methods[] =
std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params);
#ifdef BUILD_ROGUE
int32_t rogue_replay(uint64_t seed,int32_t sleeptime);
int32_t rogue_replay(uint64_t seed,int32_t sleepmillis);
bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx);
UniValue rogue_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
@@ -496,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"

View File

@@ -2,7 +2,7 @@
cd rogue;
./configure # only need this first time
make; cd ..
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 -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

View File

@@ -259,18 +259,22 @@ over:
again = TRUE;
goto over;
}
when 'q': quaff(rs);
case 'q': quaff(rs);
break;
when 'Q':
after = FALSE;
q_comm = TRUE;
quit(0);
if ( rs->guiflag != 0 && rs->needflush == 0 )
rs->needflush = (uint32_t)time(NULL);
q_comm = FALSE;
if ( rs->guiflag != 0 )
rogue_bailout(rs);
else rs->replaydone = (uint32_t)time(NULL);
return;
after = FALSE;
q_comm = TRUE;
if ( _quit() > 0 )
{
if ( rs->guiflag != 0 )
{
if (rs->needflush == 0 )
rs->needflush = (uint32_t)time(NULL);
rogue_bailout(rs);
} else rs->replaydone = (uint32_t)time(NULL);
}
q_comm = FALSE;
return;
when 'i': after = FALSE; inventory(rs,pack, 0);
when 'I': after = FALSE; picky_inven(rs);
when 'd': drop(rs);

View File

@@ -16,93 +16,409 @@
#include "cursesd.h"
static int32_t endwinflag;
WINDOW *stdscr,*curscr;
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 = (WINDOW *)calloc(1,sizeof(*stdscr));
stdscr = newwin(LINES,COLS,0,0);
return(stdscr);
}
void endwin()
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;
//fprintf(stderr,"%s\n",str);
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 && i<n; i++)
waddch(win,str[i]);
return(0);
}
int32_t mvwaddstr(WINDOW *win, int32_t y, int32_t x, const char *str)
{
win->y = 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);
}
int isendwin(void)
int32_t isendwin(void)
{
return(endwinflag);
}
int wrefresh(WINDOW *win)
{
return(0);
}
int refresh(void)
int32_t refresh(void)
{
endwinflag = 0;
return(wrefresh(stdscr));
}
int wnoutrefresh(WINDOW *win)
{
return(0);
}
int doupdate(void)
{
return(0);
}
int redrawwin(WINDOW *win)
int32_t redrawwin(WINDOW *win)
{
return(wrefresh(win));
}
int wredrawln(WINDOW *win, int beg_line, int num_lines)
int32_t wredrawln(WINDOW *win, int32_t beg_line, int32_t num_lines)
{
return(wrefresh(win));
}
int werase(WINDOW *win)
// functions with no data side effect
#ifdef they_are_macros
int32_t wrefresh(WINDOW *win)
{
return(0);
}
int erase(void)
int32_t wnoutrefresh(WINDOW *win)
{
return(werase(stdscr));
return(0);
}
int wclear(WINDOW *win)
int32_t doupdate(void)
{
return(0);
}
int clear(void)
int32_t touchwin(WINDOW *win)
{
return(wclear(stdscr));
return(0);
}
int wclrtobot(WINDOW *win)
int32_t standout(void)
{
return(0);
}
int clrtobot(void)
int32_t standend(void)
{
return(wclrtobot(stdscr));
return(0);
}
int wclrtoeol(WINDOW *win)
int32_t raw(void)
{
return(0);
}
int clrtoeol(void)
int32_t keypad(WINDOW *win, bool bf)
{
return(wclrtoeol(stdscr));
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);
}

View File

@@ -36,38 +36,116 @@
#include <sys/stat.h>
#include <errno.h>
#ifdef notyet
#define ERR (-1)
struct cursesd_info
{
uint8_t screen[LINES][COLS];
} *stdscr;
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);
int endwin(void);
int isendwin(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);
int refresh(void);
int wrefresh(WINDOW *win);
//int wnoutrefresh(WINDOW *win);
//int doupdate(void);
int redrawwin(WINDOW *win);
int wredrawln(WINDOW *win, int beg_line, int num_lines);
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);
int erase(void);
int werase(WINDOW *win);
int clear(void);
int wclear(WINDOW *win);
int clrtobot(void);
int wclrtobot(WINDOW *win);
int clrtoeol(void);
int wclrtoeol(WINDOW *win);
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);
#endif
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
@@ -76,58 +154,5 @@ int wclrtoeol(WINDOW *win);
#define FALSE 0
#endif
#define standout()
#define standend()
#define refresh()
#define raw()
#define noecho()
#define flushinp()
#define clear()
#define clrtoeol()
#define addch(a)
#define werase(a)
#define wclear(a)
#define delwin(a)
#define addstr(a)
#define touchwin(a)
#define idlok(a,b)
#define clearok(a,b)
#define keypad(a,b)
#define leaveok(a,b)
#define waddch(a,b)
#define waddstr(a,b)
#define move(a,b)
#define mvwin(a,b,c)
#define wmove(a,b,c)
#define mvaddch(a,b,c)
#define mvaddstr(a,b,c)
#define wgetnstr(a,b,c)
#define getyx(a,b,c)
#define mvcur(a,b,c,d)
#define mvwaddch(a,b,c,d)
#define mvprintw(...)
#define printw(...)
#define wprintw(...)
#define mvwprintw(...)
#define A_CHARTEXT 0xff
#define inch() 0
#define endwin() 1
#define isendwin() 0
#define baudrate() 9600
#define killchar() 3
#define erasechar() 8
#define wclrtoeol(a) 0
#define wrefresh(a) 0
#define unctrl(a) "^x"
#define getmaxx(a) COLS
#define getmaxy(a) LINES
#define mvinch(a,b) '.'
#define mvwinch(a,b,c) 0
#define newwin(a,b,c,d) 0
#define subwin(a,b,c,d,e) 0
#endif

View File

@@ -142,6 +142,7 @@ void leave(int);
void my_exit(int st);
void playltchars(void);
void quit(int);
int32_t _quit();
void resetltchars(void);
void set_order(int *order, int numthings);
void tstp(int ignored);

View File

@@ -27,7 +27,11 @@ void restore_player(struct rogue_state *rs)
int32_t i; THING *obj;
//rs->P.gold = purse;
max_hp = rs->P.hitpoints;
pstats.s_str = max_stats.s_str = rs->P.strength;
pstats.s_str = rs->P.strength & 0xffff;
if ( (max_stats.s_str= (rs->P.strength >> 16) & 0xffff) == 0 )
max_stats.s_str = 16;
if ( pstats.s_str > max_stats.s_str )
pstats.s_str = max_stats.s_str;
pstats.s_lvl = rs->P.level;
pstats.s_exp = rs->P.experience;
for (i=0; i<rs->P.packsize; i++)

View File

@@ -8,6 +8,7 @@
//#include <curses.h>
//#include <ctype.h>
//#include <string.h>
#include "rogue.h"
/*
@@ -152,23 +153,26 @@ step_ok(int ch)
char
readchar(struct rogue_state *rs)
{
char ch = -1;
char c,ch = -1;
if ( rs != 0 && rs->guiflag == 0 )
{
static uint32_t counter;
if ( rs->ind < rs->numkeys )
{
//if ( rs->ind == rs->numkeys-1 )
// rs->replaydone = (uint32_t)time(NULL);
//fprintf(stderr,"(%c) ",rs->keystrokes[rs->ind]);
return(rs->keystrokes[rs->ind++]);
c = rs->keystrokes[rs->ind++];
while ( c == 'Q' && rs->ind < rs->numkeys )
{
//fprintf(stderr,"Got 'Q' next (%c)\n",rs->keystrokes[rs->ind]); sleep(2);
if ( rs->keystrokes[rs->ind] == 'y' )
return(c);
rs->ind++;
c = rs->keystrokes[rs->ind++];
}
return(c);
}
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
if ( counter < 3 || (counter & 1) == 0 )
return('y');
else return(ESCAPE);
@@ -179,7 +183,7 @@ readchar(struct rogue_state *rs)
if (ch == 3)
{
quit(0);
_quit();
return(27);
}
if ( rs != 0 && rs->guiflag != 0 )

View File

@@ -253,7 +253,7 @@ int main(int argc, char **argv, char **envp)
{
seed = atol(argv[1]);
//fprintf(stderr,"replay %llu\n",(long long)seed);
return(rogue_replay(seed,50000));
return(rogue_replay(seed,10));
}
else
{

View File

@@ -81,7 +81,12 @@
#endif
#endif
#ifndef BUILD_ROGUE
#include <curses.h> /* AIX requires curses.h be included before term.h */
#else
#include "cursesd.h"
#endif
#if defined(HAVE_TERM_H)
#include <term.h>
@@ -257,7 +262,7 @@ md_onsignal_autosave()
int
md_hasclreol()
{
#if defined(clr_eol)
/*#if defined(clr_eol)
#ifdef NCURSES_VERSION
if (cur_term == NULL)
return(0);
@@ -269,7 +274,8 @@ md_hasclreol()
return(TRUE);
#else
return((CE != NULL) && (*CE != 0));
#endif
#endif*/
return(0);
}
void
@@ -1076,6 +1082,7 @@ md_setsuspchar(int c)
#define M_KEYPAD 2
#define M_TRAIL 3
#ifndef BUILD_ROGUE
int
md_readchar()
{
@@ -1315,7 +1322,8 @@ md_readchar()
return(ch & 0x7F);
}
#endif
#if defined(LOADAV) && defined(HAVE_NLIST_H) && defined(HAVE_NLIST)
/*
* loadav:

View File

@@ -349,17 +349,36 @@ void
chg_str(int amt)
{
//auto jl777: strange compiler error
str_t comp;
uint32_t comp;
if (amt == 0)
return;
add_str(&pstats.s_str, amt);
//add_str(&pstats.s_str, amt);
pstats.s_str += amt;
if ( pstats.s_str < 3 )
pstats.s_str = 3;
else if ( pstats.s_str > 31 )
pstats.s_str = 31;
comp = pstats.s_str;
if (ISRING(LEFT, R_ADDSTR))
add_str(&comp, -cur_ring[LEFT]->o_arm);
{
// add_str(&comp, -cur_ring[LEFT]->o_arm);
comp += -cur_ring[LEFT]->o_arm;
if ( comp < 3 )
comp = 3;
else if ( comp > 31 )
comp = 31;
}
if (ISRING(RIGHT, R_ADDSTR))
add_str(&comp, -cur_ring[RIGHT]->o_arm);
if (comp > max_stats.s_str)
{
//add_str(&comp, -cur_ring[RIGHT]->o_arm);
comp += -cur_ring[RIGHT]->o_arm;
if ( comp < 3 )
comp = 3;
else if ( comp > 31 )
comp = 31;
}
if ( comp > max_stats.s_str )
max_stats.s_str = comp;
}

View File

@@ -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)

View File

@@ -52,9 +52,9 @@ add_pack(struct rogue_state *rs,THING *obj, bool silent)
if (pack == NULL)
{
pack = obj;
obj->o_packch = pack_char();
inpack++;
pack = obj;
obj->o_packch = pack_char();
inpack++;
}
else
{
@@ -252,7 +252,10 @@ int32_t num_packitems()
THING *list = pack;
int32_t type = 0,n = 0;
for (; list != NULL; list = next(list))
n++;
{
if (!list->o_packch)
n++;
}
return(n);
}
@@ -288,11 +291,11 @@ inventory(struct rogue_state *rs,THING *list, int type)
// fprintf(stderr,"n_objs.%d vs inpack.%d\n",n_objs,inpack), sleep(2);
if (n_objs == 0)
{
if (terse)
msg(rs,type == 0 ? (char *)"empty handed" : (char *)"nothing appropriate");
else
msg(rs,type == 0 ? (char *)"you are empty handed" : (char *)"you don't have anything appropriate");
return FALSE;
if (terse)
msg(rs,type == 0 ? (char *)"empty handed" : (char *)"nothing appropriate");
else
msg(rs,type == 0 ? (char *)"you are empty handed" : (char *)"you don't have anything appropriate");
return FALSE;
}
end_line(rs);
return TRUE;

View File

@@ -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));

View File

@@ -91,7 +91,9 @@ void rogueiterate(struct rogue_state *rs)
// Set up windows
if ( hw == NULL )
{
hw = newwin(LINES, COLS, 0, 0);
}
idlok(stdscr, TRUE);
idlok(hw, TRUE);
#ifdef MASTER
@@ -248,6 +250,7 @@ int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu
rs->restoring = 1;
//fprintf(stderr,"restore player packsize.%d HP.%d\n",rs->P.packsize,rs->P.hitpoints);
}
globalR = *rs;
uint32_t starttime = (uint32_t)time(NULL);
rogueiterate(rs);
if ( 0 )
@@ -271,6 +274,7 @@ int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu
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);
}
@@ -334,10 +338,11 @@ int32_t rogue_replay(uint64_t seed,int32_t sleeptime)
}
fclose(fp);
}
rogue_replay2(0,seed,keystrokes,num,player,150);
rogue_replay2(0,seed,keystrokes,num,player,sleeptime);
//mvaddstr(LINES - 2, 0, (char *)"replay completed");
mvaddstr(LINES - 2, 0, (char *)"replay completed");
endwin();
my_exit(0);
}
if ( keystrokes != 0 )
free(keystrokes);
@@ -542,9 +547,11 @@ tstp(int ignored)
fflush(stdout);
//wmove(curscr,oy,ox);
#ifndef __APPLE__
#ifndef BUILD_ROGUE
curscr->_cury = oy;
curscr->_curx = ox;
#endif
#endif
}
/*
@@ -588,7 +595,7 @@ playit(struct rogue_state *rs)
{
if ( rs->replaydone != 0 )
{
if ( rs->sleeptime != 0 )
if ( 0 && rs->sleeptime != 0 )
sleep(3);
return;
}
@@ -597,7 +604,7 @@ playit(struct rogue_state *rs)
}
else
{
if ( rs->needflush != 0 && rs->num > 4096 )
if ( rs->needflush != 0 && rs->num > 1024 )
{
if ( flushkeystrokes(rs) == 0 )
rs->needflush = 0;
@@ -607,30 +614,17 @@ playit(struct rogue_state *rs)
endit(0);
}
/*
* quit:
* Have player make certain, then exit.
*/
void
quit(int sig)
int32_t _quit()
{
struct rogue_state *rs = &globalR;
int oy, ox;
int oy, ox, c;
//fprintf(stderr,"inside quit(%d)\n",sig);
if ( rs->guiflag != 0 )
{
NOOP(sig);
/*
* Reset the signal in case we got here via an interrupt
*/
if (!q_comm)
mpos = 0;
getyx(curscr, oy, ox);
msg(rs,"really quit?");
}
if (readchar(rs) == 'y')
getyx(curscr, oy, ox);
msg(rs,"really quit?");
//sleep(1);
if ( (c= readchar(rs)) == 'y')
{
if ( rs->guiflag != 0 )
{
@@ -647,11 +641,13 @@ quit(int sig)
else
{
//score(rs,purse, 1, 0);
//fprintf(stderr,"done!\n");
fprintf(stderr,"done! (%c)\n",c);
}
return(1);
}
else
{
fprintf(stderr,"'Q' answer (%c)\n",c);
move(0, 0);
clrtoeol();
status(rs);
@@ -661,9 +657,33 @@ quit(int sig)
mpos = 0;
count = 0;
to_death = FALSE;
return(0);
}
}
/*
* quit:
* Have player make certain, then exit.
*/
void quit(int sig)
{
struct rogue_state *rs = &globalR;
int oy, ox, c;
//fprintf(stderr,"inside quit(%d)\n",sig);
if ( rs->guiflag != 0 )
{
NOOP(sig);
/*
* Reset the signal in case we got here via an interrupt
*/
if (!q_comm)
mpos = 0;
}
_quit();
}
/*
* leave:
* Leave quickly, but curteously
@@ -737,11 +757,11 @@ my_exit(int st)
{
uint32_t counter;
resetltchars();
if ( globalR.guiflag != 0 )
if ( globalR.guiflag != 0 || globalR.sleeptime != 0 )
exit(st);
else if ( counter++ < 10 )
{
fprintf(stderr,"would have exit.(%d)\n",st);
fprintf(stderr,"would have exit.(%d) sleeptime.%d\n",st,globalR.sleeptime);
globalR.replaydone = 1;
}
}

View File

@@ -29,10 +29,9 @@
#include <sys/stat.h>
#include <errno.h>
#ifndef DONTUSEGUI
#ifndef BUILD_ROGUE
#include <curses.h>
#else
#include "cursesd.h"
#endif
@@ -358,20 +357,7 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uin
typedef union _bits256 bits256;
#endif
#ifndef ROGUE_DECLARED_PACK
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];
};
#define ROGUE_DECLARED_PACK
#endif
#include "rogue_player.h" // interface to rpc
struct rogue_state
{
@@ -861,5 +847,8 @@ extern const char *wood[];
extern int cNWOOD;
extern const char *metal[];
extern int cNMETAL;
//extern WINDOW *stdscr,*curscr;
#endif

View File

@@ -0,0 +1,35 @@
/******************************************************************************
* 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 ROGUE_DECLARED_PACK
#define ROGUE_DECLARED_PACK
#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);
void rogue_packitemstr(char *packitemstr,struct rogue_packitem *item);
#endif

View File

@@ -148,19 +148,24 @@ void
save_file(struct rogue_state *rs,FILE *savef,int32_t guiflag)
{
char buf[80],fname[512]; int32_t i,n,nonz,histo[0x100]; FILE *fp;
memset(&rs->P,0,sizeof(rs->P));
mvcur(0, COLS - 1, LINES - 1, 0);
putchar('\n');
endwin();
resetltchars();
md_chmod(file_name, 0400);
if ( guiflag != 0 )
if ( rs->guiflag != 0 )
{
encwrite(version, strlen(version)+1, savef);
sprintf(buf,"%d x %d\n", LINES, COLS);
encwrite(buf,80,savef);
mvcur(0, COLS - 1, LINES - 1, 0);
putchar('\n');
endwin();
resetltchars();
md_chmod(file_name, 0400);
if ( guiflag != 0 )
{
encwrite(version, strlen(version)+1, savef);
sprintf(buf,"%d x %d\n", LINES, COLS);
encwrite(buf,80,savef);
}
}
rs_save_file(rs,savef);
memset(&rs->P,0,sizeof(rs->P));
rs_save_file(rs,savef); // sets rs->P
//fprintf(stderr,"gold.%d hp.%d strength.%d level.%d exp.%d %d\n",rs->P.gold,rs->P.hitpoints,rs->P.strength,rs->P.level,rs->P.experience,rs->P.dungeonlevel);
n = sizeof(rs->P) - sizeof(rs->P.roguepack) + sizeof(rs->P.roguepack[0])*rs->P.packsize;
memset(histo,0,sizeof(histo));
for (i=0; i<n; i++)
@@ -170,7 +175,7 @@ save_file(struct rogue_state *rs,FILE *savef,int32_t guiflag)
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 playersize.%d\n",rs->P.packsize,n);
if ( (fp= fopen(rogue_packfname(rs,fname),"wb")) != 0 )
{
fwrite(&rs->P,1,n,fp);
@@ -227,7 +232,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;

View File

@@ -1437,7 +1437,7 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o)
//fprintf(stderr,"KILLED\n");
rs->P.gold = -1;
rs->P.hitpoints = -1;
rs->P.strength = -1;
rs->P.strength = 0;
rs->P.level = -1;
rs->P.experience = -1;
rs->P.dungeonlevel = -1;
@@ -1448,11 +1448,11 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o)
{
rs->P.gold = purse;
rs->P.hitpoints = max_hp;
rs->P.strength = pstats.s_str; //max_stats.s_str;
rs->P.strength = (pstats.s_str & 0xffff) | (max_stats.s_str << 16);
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/%d level.%d exp.%d %d\n",ftell(savef),purse,max_hp,pstats.s_str,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);
if ( rs->P.packsize < MAXPACK && o->o_type != AMULET )
@@ -2009,7 +2009,10 @@ int
rs_save_file(struct rogue_state *rs,FILE *savef)
{
if (write_error)
{
fprintf(stderr,"write error\n");
return(WRITESTAT);
}
rs_write_boolean(savef, after); /* 1 */ /* extern.c */
rs_write_boolean(savef, again); /* 2 */

View File

@@ -502,37 +502,44 @@ add_line(struct rogue_state *rs,char *fmt, char *arg)
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++)
if ( rs->guiflag != 0 )
{
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);
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);
}
else
{
wait_for(rs,' ');
}
delwin(tw);
touchwin(stdscr);
}
else
{

View File

@@ -23,21 +23,7 @@
#define ROGUE_MAXKEYSTROKESGAP 60
#define ROGUE_MAXITERATIONS 777
#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);
#include "rogue/rogue_player.h"
std::string Rogue_pname = "";
@@ -134,9 +120,9 @@ std::string Rogue_pname = "";
*/
// todo:
// verify keystrokes tx is in mempool and confirmed
// chaining when mempool tx sometimes infinite loops?
// bailout stealing, is it possible?
// add some more conditions to multiplayer
// how does it work with playertxid instead of pubkey
// keystrokes retry
//////////////////////// start of CClib interface
//./komodod -ac_name=ROGUE -ac_supply=1000000 -pubkey=03951a6f7967ad784453116bc55cd30c54f91ea8a5b1e9b04d6b29cfd6b395ba6c -addnode=5.9.102.210 -ac_cclib=rogue -ac_perc=10000000 -ac_reward=100000000 -ac_cc=60001 -ac_script=2ea22c80203d1579313abe7d8ea85f48c65ea66fc512c878c0d0e6f6d54036669de940febf8103120c008203000401cc > /dev/null &
@@ -371,7 +357,7 @@ int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransa
UniValue rogue_playerobj(std::vector<uint8_t> playerdata,uint256 playertxid,uint256 tokenid,std::string symbol,std::string pname)
{
int32_t i; struct rogue_player P; char packitemstr[512],*datastr; UniValue obj(UniValue::VOBJ),a(UniValue::VARR);
int32_t i; struct rogue_player P; char packitemstr[512],*datastr=0; UniValue obj(UniValue::VOBJ),a(UniValue::VARR);
memset(&P,0,sizeof(P));
if ( playerdata.size() > 0 )
{
@@ -393,12 +379,16 @@ UniValue rogue_playerobj(std::vector<uint8_t> playerdata,uint256 playertxid,uint
if ( tokenid != zeroid )
obj.push_back(Pair("tokenid",tokenid.GetHex()));
else obj.push_back(Pair("tokenid",playertxid.GetHex()));
obj.push_back(Pair("data",datastr));
free(datastr);
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));
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));
@@ -734,9 +724,11 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
playertxid = juint256(jitem(params,1));
if ( rogue_playerdata(cp,origplayergame,tokenid,pk,playerdata,symbol,pname,playertxid) < 0 )
return(cclib_error(result,"couldnt extract valid playerdata"));
if ( tokenid != zeroid )
if ( tokenid != zeroid ) // if it is tokentransfer this will be 0
vout = 1;
}
if ( komodo_nextheight() > gameheight + ROGUE_MAXKEYSTROKESGAP )
return(cclib_error(result,"didnt register in time, ROGUE_MAXKEYSTROKESGAP"));
rogue_univalue(result,0,maxplayers,buyin);
GetCCaddress1of2(cp,coinaddr,roguepk,mypk);
if ( rogue_iamregistered(maxplayers,gametxid,tx,coinaddr) > 0 )
@@ -803,6 +795,8 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
if ( (params= cclib_reparse(&n,params)) != 0 && n == 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());
roguepk = GetUnspendable(cp,0);
@@ -811,6 +805,8 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
{
if ( rogue_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+ROGUE_MAXKEYSTROKESGAP )
{
mtx.vin.push_back(CTxIn(batontxid,batonvout,CScript()));
@@ -826,12 +822,67 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
} else return(cclib_error(result,"couldnt reparse params"));
}
char *rogue_extractgame(char *str,int32_t *numkeysp,std::vector<uint8_t> &newdata,uint64_t &seed,uint256 &playertxid,struct CCcontract_info *cp,uint256 gametxid,char *rogueaddr)
{
CPubKey roguepk; int32_t i,num,maxplayers,gameheight,batonht,batonvout,numplayers,regslot,numkeys,err; std::string symbol,pname; CTransaction gametx; int64_t buyin,batonvalue; char fname[64],*keystrokes = 0; std::vector<uint8_t> playerdata; uint256 batontxid; FILE *fp; uint8_t newplayer[10000]; struct rogue_player P,endP;
roguepk = GetUnspendable(cp,0);
*numkeysp = 0;
seed = 0;
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;
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<playerdata.size(); i++)
((uint8_t *)&P)[i] = playerdata[i];
}
if ( keystrokes != 0 )
{
sprintf(fname,"rogue.%llu.0",(long long)seed);
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(keystrokes,1,numkeys,fp) != numkeys )
fprintf(stderr,"error writing %s\n",fname);
fclose(fp);
}
sprintf(fname,"rogue.%llu.player",(long long)seed);
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(&playerdata[0],1,(int32_t)playerdata.size(),fp) != playerdata.size() )
fprintf(stderr,"error writing %s\n",fname);
fclose(fp);
}
num = rogue_replay2(newplayer,seed,keystrokes,numkeys,playerdata.size()==0?0:&P,0);
newdata.resize(num);
for (i=0; i<num; i++)
{
newdata[i] = newplayer[i];
((uint8_t *)&endP)[i] = newplayer[i];
}
if ( endP.gold <= 0 || endP.hitpoints <= 0 || (endP.strength&0xffff) <= 0 || endP.level <= 0 || endP.experience <= 0 || endP.dungeonlevel <= 0 )
{
fprintf(stderr,"zero value character was killed -> no playerdata\n");
newdata.resize(0);
}
sprintf(str,"extracted $$$gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d\n",endP.gold,endP.hitpoints,endP.strength&0xffff,endP.strength>>16,endP.level,endP.experience,endP.dungeonlevel);
fprintf(stderr,"%s\n",str);
} else num = 0;
}
}
*numkeysp = numkeys;
return(keystrokes);
}
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<uint8_t> playerdata,newdata; uint256 batontxid,playertxid,gametxid; FILE *fp; uint8_t player[10000],pub33[33];
UniValue result(UniValue::VOBJ); CPubKey pk,roguepk; int32_t i,n,numkeys,flag = 0; uint64_t seed; char str[512],rogueaddr[64],*pubstr,*keystrokes = 0; std::vector<uint8_t> newdata; uint256 gametxid,playertxid; FILE *fp; uint8_t 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 )
@@ -847,59 +898,27 @@ UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
decode_hex(pub33,33,pubstr);
pk = buf2pk(pub33);
}
fprintf(stderr,"gametxid.%s %s\n",gametxid.GetHex().c_str(),pubstr);
//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 )
str[0] = 0;
if ( (keystrokes= rogue_extractgame(str,&numkeys,newdata,seed,playertxid,cp,gametxid,rogueaddr)) != 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<playerdata.size(); i++)
((uint8_t *)&P)[i] = playerdata[i];
}
if ( keystrokes != 0 )
{
sprintf(fname,"rogue.%llu.0",(long long)seed);
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(keystrokes,1,numkeys,fp) != numkeys )
fprintf(stderr,"error writing %s\n",fname);
fclose(fp);
}
sprintf(fname,"rogue.%llu.player",(long long)seed);
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(&playerdata[0],1,(int32_t)playerdata.size(),fp) != playerdata.size() )
fprintf(stderr,"error writing %s\n",fname);
fclose(fp);
}
num = rogue_replay2(player,seed,keystrokes,numkeys,playerdata.size()==0?0:&P,50);
newdata.resize(num);
for (i=0; i<num; i++)
{
newdata[i] = player[i];
((uint8_t *)&P)[i] = player[i];
}
if ( P.gold <= 0 || P.hitpoints <= 0 || P.strength <= 0 || P.level <= 0 || P.experience <= 0 || P.dungeonlevel <= 0 )
{
fprintf(stderr,"zero value character was killed -> 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;
}
result.push_back(Pair("status","success"));
flag = 1;
result.push_back(Pair("playertxid",playertxid.GetHex()));
result.push_back(Pair("extracted",str));
result.push_back(Pair("numkeys",(int64_t)numkeys));
result.push_back(Pair("seed",(int64_t)seed));
sprintf(str,"cc/rogue/rogue %llu",(long long)seed);
result.push_back(Pair("replay",str));
free(keystrokes);
}
}
}
if ( flag == 0 )
result.push_back(Pair("status","error"));
return(result);
}
@@ -975,7 +994,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
newdata[i] = player[i];
((uint8_t *)&P)[i] = player[i];
}
if ( P.gold <= 0 || P.hitpoints <= 0 || P.strength <= 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 )
{
fprintf(stderr,"zero value character was killed -> no playerdata\n");
newdata.resize(0);
@@ -987,7 +1006,7 @@ 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));
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));
fprintf(stderr,"\nextracted $$$gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d n.%d size.%d\n",P.gold,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel,n,(int32_t)sizeof(P));
cashout = (uint64_t)P.gold * mult;
if ( funcid == 'H' && maxplayers > 1 )
{
@@ -1029,7 +1048,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
}
result.push_back(Pair("result","success"));
} else fprintf(stderr,"illegal game err.%d\n",err);
} else fprintf(stderr,"n.%d\n",n);
} else fprintf(stderr,"parameters only n.%d\n",n);
}
return(result);
}
@@ -1095,7 +1114,7 @@ UniValue rogue_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
//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 ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid) == 0 && gameheight > nextheight-777 )
if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid) == 0 && nextheight <= gameheight+ROGUE_MAXKEYSTROKESGAP )
{
rogue_playersalive(numplayers,txid,maxplayers);
if ( numplayers < maxplayers )
@@ -1199,6 +1218,47 @@ UniValue rogue_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx)
{
CScript scriptPubKey; std::vector<uint8_t> vopret; uint8_t *script,e,f,funcid; int32_t i,ind,errflag,dispflag,score,numvouts; CTransaction vintx; uint256 hashBlock;
if ( (numvouts= tx.vout.size()) > 1 )
{
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 )
{
if ( script[1] == 'c' )
{
e = EVAL_ROGUE;
funcid = 'Q';
}
else if ( script[1] == 't' )
{
e = EVAL_ROGUE;
funcid = 'Q';
} else return eval->Invalid("illegal tokens funcid");
}
if ( e == EVAL_ROGUE )
{
switch ( funcid )
{
case 'G': // newgame
case 'R': // register
case 'K': // keystrokes
case 'H': // win
case 'Q': // bailout
fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]);
return(true);
break;
default:
return eval->Invalid("illegal rogue funcid");
break;
}
} else return eval->Invalid("illegal evalcode");
} else return eval->Invalid("opret too small");
} else return eval->Invalid("not enough vouts");
return(true);
}