Merge pull request #131 from jl777/jl777

sync jl777
This commit is contained in:
ca333
2019-02-18 09:46:06 +01:00
committed by GitHub
14 changed files with 230 additions and 124 deletions

View File

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

View File

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

View File

@@ -907,10 +907,12 @@ std::string CreateToken(int64_t txfee, int64_t tokensupply, std::string name, st
if( nonfungibleData.size() > 0 ) if( nonfungibleData.size() > 0 )
destEvalCode = nonfungibleData.begin()[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(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) //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))); // ...moved to vout=0 for matching with rogue-game token
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
return(FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeTokenCreateOpRet('c', Mypubkey(), name, description, nonfungibleData))); 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> origpubkey;
std::vector<uint8_t> vopretNonfungible; std::vector<uint8_t> vopretNonfungible;
std::string name, description; 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"); fprintf(stderr, "TokenInfo() cant find tokenid\n");
result.push_back(Pair("result", "error")); 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); 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("result", "error"));
result.push_back(Pair("error", "tokenid isnt token creation txid")); result.push_back(Pair("error", "tokenid isnt token creation txid"));
return result;
} }
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
result.push_back(Pair("tokenid", tokenid.GetHex())); result.push_back(Pair("tokenid", tokenid.GetHex()));
result.push_back(Pair("owner", HexStr(origpubkey))); result.push_back(Pair("owner", HexStr(origpubkey)));
result.push_back(Pair("name", name)); 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)); result.push_back(Pair("description", description));
if( !vopretNonfungible.empty() ) if( !vopretNonfungible.empty() )
result.push_back(Pair("data", HexStr(vopretNonfungible))); result.push_back(Pair("data", HexStr(vopretNonfungible)));
return(result); return result;
} }
UniValue TokenList() UniValue TokenList()

View File

@@ -76,7 +76,7 @@ CClib_methods[] =
std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params); std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params);
#ifdef BUILD_ROGUE #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); 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); UniValue rogue_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);

View File

@@ -16,7 +16,7 @@
#include "cursesd.h" #include "cursesd.h"
static int32_t endwinflag; static int32_t endwinflag;
WINDOW *stdscr; WINDOW *stdscr,*curscr;
int32_t ESCDELAY; int32_t ESCDELAY;
WINDOW *newwin(int32_t nlines,int32_t ncols,int32_t begin_y,int32_t begin_x) WINDOW *newwin(int32_t nlines,int32_t ncols,int32_t begin_y,int32_t begin_x)
@@ -162,6 +162,7 @@ int32_t mvaddch(int32_t y, int32_t x, chtype ch)
int32_t waddstr(WINDOW *win, const char *str) int32_t waddstr(WINDOW *win, const char *str)
{ {
int32_t i; int32_t i;
//fprintf(stderr,"%s\n",str);
for (i=0; str[i]!=0; i++) for (i=0; str[i]!=0; i++)
waddch(win,str[i]); waddch(win,str[i]);
return(0); return(0);

View File

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

View File

@@ -253,7 +253,7 @@ int main(int argc, char **argv, char **envp)
{ {
seed = atol(argv[1]); 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)); return(rogue_replay(seed,10));
} }
else else
{ {

View File

@@ -262,7 +262,7 @@ md_onsignal_autosave()
int int
md_hasclreol() md_hasclreol()
{ {
#if defined(clr_eol) /*#if defined(clr_eol)
#ifdef NCURSES_VERSION #ifdef NCURSES_VERSION
if (cur_term == NULL) if (cur_term == NULL)
return(0); return(0);
@@ -274,7 +274,8 @@ md_hasclreol()
return(TRUE); return(TRUE);
#else #else
return((CE != NULL) && (*CE != 0)); return((CE != NULL) && (*CE != 0));
#endif #endif*/
return(0);
} }
void void

View File

@@ -273,6 +273,7 @@ int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu
if ( (fp= fopen("checkfile","wb")) != 0 ) if ( (fp= fopen("checkfile","wb")) != 0 )
{ {
save_file(rs,fp,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 ) if ( newdata != 0 && rs->playersize > 0 )
memcpy(newdata,rs->playerdata,rs->playersize); memcpy(newdata,rs->playerdata,rs->playersize);
} }
@@ -336,10 +337,11 @@ int32_t rogue_replay(uint64_t seed,int32_t sleeptime)
} }
fclose(fp); 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(); endwin();
my_exit(0);
} }
if ( keystrokes != 0 ) if ( keystrokes != 0 )
free(keystrokes); free(keystrokes);
@@ -601,7 +603,7 @@ playit(struct rogue_state *rs)
} }
else else
{ {
if ( rs->needflush != 0 && rs->num > 4096 ) if ( rs->needflush != 0 && rs->num > 1024 )
{ {
if ( flushkeystrokes(rs) == 0 ) if ( flushkeystrokes(rs) == 0 )
rs->needflush = 0; rs->needflush = 0;
@@ -741,7 +743,7 @@ my_exit(int st)
{ {
uint32_t counter; uint32_t counter;
resetltchars(); resetltchars();
if ( globalR.guiflag != 0 ) if ( globalR.guiflag != 0 || globalR.sleeptime != 0 )
exit(st); exit(st);
else if ( counter++ < 10 ) else if ( counter++ < 10 )
{ {

View File

@@ -357,20 +357,7 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uin
typedef union _bits256 bits256; typedef union _bits256 bits256;
#endif #endif
#include "rogue_player.h" // interface to rpc
#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
struct rogue_state struct rogue_state
{ {

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) 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; char buf[80],fname[512]; int32_t i,n,nonz,histo[0x100]; FILE *fp;
memset(&rs->P,0,sizeof(rs->P)); if ( rs->guiflag != 0 )
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); mvcur(0, COLS - 1, LINES - 1, 0);
sprintf(buf,"%d x %d\n", LINES, COLS); putchar('\n');
encwrite(buf,80,savef); 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; n = sizeof(rs->P) - sizeof(rs->P.roguepack) + sizeof(rs->P.roguepack[0])*rs->P.packsize;
memset(histo,0,sizeof(histo)); memset(histo,0,sizeof(histo));
for (i=0; i<n; i++) 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->playerdata[i] = ((uint8_t *)&rs->P)[i];
} }
rs->playersize = n; 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 ) if ( (fp= fopen(rogue_packfname(rs,fname),"wb")) != 0 )
{ {
fwrite(&rs->P,1,n,fp); fwrite(&rs->P,1,n,fp);

View File

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

View File

@@ -23,21 +23,7 @@
#define ROGUE_MAXKEYSTROKESGAP 60 #define ROGUE_MAXKEYSTROKESGAP 60
#define ROGUE_MAXITERATIONS 777 #define ROGUE_MAXITERATIONS 777
#define MAXPACK 23 #include "rogue/rogue_player.h"
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 = ""; std::string Rogue_pname = "";
@@ -134,9 +120,9 @@ std::string Rogue_pname = "";
*/ */
// todo: // todo:
// verify keystrokes tx is in mempool and confirmed // add some more conditions to multiplayer
// chaining when mempool tx sometimes infinite loops? // how does it work with playertxid instead of pubkey
// bailout stealing, is it possible? // keystrokes retry
//////////////////////// start of CClib interface //////////////////////// 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 & //./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) 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)); memset(&P,0,sizeof(P));
if ( playerdata.size() > 0 ) if ( playerdata.size() > 0 )
{ {
@@ -393,12 +379,16 @@ UniValue rogue_playerobj(std::vector<uint8_t> playerdata,uint256 playertxid,uint
if ( tokenid != zeroid ) if ( tokenid != zeroid )
obj.push_back(Pair("tokenid",tokenid.GetHex())); obj.push_back(Pair("tokenid",tokenid.GetHex()));
else obj.push_back(Pair("tokenid",playertxid.GetHex())); else obj.push_back(Pair("tokenid",playertxid.GetHex()));
obj.push_back(Pair("data",datastr)); if ( datastr != 0 )
free(datastr); {
obj.push_back(Pair("data",datastr));
free(datastr);
}
obj.push_back(Pair("pack",a)); obj.push_back(Pair("pack",a));
obj.push_back(Pair("packsize",(int64_t)P.packsize)); obj.push_back(Pair("packsize",(int64_t)P.packsize));
obj.push_back(Pair("hitpoints",(int64_t)P.hitpoints)); 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("level",(int64_t)P.level));
obj.push_back(Pair("experience",(int64_t)P.experience)); obj.push_back(Pair("experience",(int64_t)P.experience));
obj.push_back(Pair("dungeonlevel",(int64_t)P.dungeonlevel)); 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)); playertxid = juint256(jitem(params,1));
if ( rogue_playerdata(cp,origplayergame,tokenid,pk,playerdata,symbol,pname,playertxid) < 0 ) if ( rogue_playerdata(cp,origplayergame,tokenid,pk,playerdata,symbol,pname,playertxid) < 0 )
return(cclib_error(result,"couldnt extract valid playerdata")); return(cclib_error(result,"couldnt extract valid playerdata"));
if ( tokenid != zeroid ) if ( tokenid != zeroid ) // if it is tokentransfer this will be 0
vout = 1; vout = 1;
} }
if ( komodo_nextheight() > gameheight + ROGUE_MAXKEYSTROKESGAP )
return(cclib_error(result,"didnt register in time, ROGUE_MAXKEYSTROKESGAP"));
rogue_univalue(result,0,maxplayers,buyin); rogue_univalue(result,0,maxplayers,buyin);
GetCCaddress1of2(cp,coinaddr,roguepk,mypk); GetCCaddress1of2(cp,coinaddr,roguepk,mypk);
if ( rogue_iamregistered(maxplayers,gametxid,tx,coinaddr) > 0 ) 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 ) if ( (params= cclib_reparse(&n,params)) != 0 && n == 2 && (keystrokestr= jstr(jitem(params,1),0)) != 0 )
{ {
gametxid = juint256(jitem(params,0)); gametxid = juint256(jitem(params,0));
result.push_back(Pair("gametxid",gametxid.GetHex()));
result.push_back(Pair("keystrokes",keystrokestr));
keystrokes = ParseHex(keystrokestr); keystrokes = ParseHex(keystrokestr);
mypk = pubkey2pk(Mypubkey()); mypk = pubkey2pk(Mypubkey());
roguepk = GetUnspendable(cp,0); 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 ) 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 ) if ( maxplayers == 1 || nextheight <= batonht+ROGUE_MAXKEYSTROKESGAP )
{ {
mtx.vin.push_back(CTxIn(batontxid,batonvout,CScript())); 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")); } 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 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()); pk = pubkey2pk(Mypubkey());
roguepk = GetUnspendable(cp,0); roguepk = GetUnspendable(cp,0);
result.push_back(Pair("status","success"));
result.push_back(Pair("name","rogue")); result.push_back(Pair("name","rogue"));
result.push_back(Pair("method","extract")); result.push_back(Pair("method","extract"));
if ( (params= cclib_reparse(&n,params)) != 0 ) 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); decode_hex(pub33,33,pubstr);
pk = buf2pk(pub33); 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); GetCCaddress1of2(cp,rogueaddr,roguepk,pk);
result.push_back(Pair("rogueaddr",rogueaddr)); 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 ) result.push_back(Pair("status","success"));
{ flag = 1;
UniValue obj; struct rogue_player P; result.push_back(Pair("playertxid",playertxid.GetHex()));
seed = rogue_gamefields(obj,maxplayers,buyin,gametxid,rogueaddr); result.push_back(Pair("extracted",str));
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()); result.push_back(Pair("numkeys",(int64_t)numkeys));
memset(&P,0,sizeof(P)); result.push_back(Pair("seed",(int64_t)seed));
if ( playerdata.size() > 0 ) sprintf(str,"cc/rogue/rogue %llu",(long long)seed);
{ result.push_back(Pair("replay",str));
for (i=0; i<playerdata.size(); i++) free(keystrokes);
((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;
}
} }
} }
} }
if ( flag == 0 )
result.push_back(Pair("status","error"));
return(result); return(result);
} }
@@ -975,7 +994,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
newdata[i] = player[i]; newdata[i] = player[i];
((uint8_t *)&P)[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"); fprintf(stderr,"zero value character was killed -> no playerdata\n");
newdata.resize(0); newdata.resize(0);
@@ -987,7 +1006,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
cpTokens = CCinit(&tokensC, EVAL_TOKENS); 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(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(cpTokens,NULL))); // marker to token cc addr, burnable and validated
mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,1,mypk)); 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; cashout = (uint64_t)P.gold * mult;
if ( funcid == 'H' && maxplayers > 1 ) 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")); result.push_back(Pair("result","success"));
} else fprintf(stderr,"illegal game err.%d\n",err); } 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); 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); //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 if ( it->second.satoshis != txfee || vout != 0 ) // reject any that are not highlander markers
continue; 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); rogue_playersalive(numplayers,txid,maxplayers);
if ( numplayers < maxplayers ) if ( numplayers < maxplayers )
@@ -1199,6 +1218,43 @@ 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) 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();
if ( script[0] == EVAL_ROGUE )
{
switch ( script[1] )
{
case 'G': // newgame
case 'R': // register
case 'K': // keystrokes
case 'H': // win
case 'Q': // bailout
return(true);
break;
default:
return eval->Invalid("illegal rogue funcid");
break;
}
}
else if ( script[0] == EVAL_TOKENS )
{
if ( script[1] == 'c' )
{
return(true);
}
else
{
return(true);
}
} else return eval->Invalid("illegal evalcode");
} else return eval->Invalid("opret too small");
} else return eval->Invalid("not enough vouts");
return(true); return(true);
} }