Merge pull request #1354 from jl777/jl777

Jl777
This commit is contained in:
jl777
2019-03-25 22:13:35 -11:00
committed by GitHub
6 changed files with 1181 additions and 61 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,11 @@
#ifndef H_GAMESCC_H
#define H_GAMESCC_H
#include <stdint.h>
#include <stdio.h>
#ifndef STANDALONE
#define ENABLE_WALLET
extern CWallet* pwalletMain;
@@ -30,29 +35,28 @@ std::string Games_pname;
{ (char *)MYCCNAME, (char *)"rng", (char *)"hash,playerid", 1, 2, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"rngnext", (char *)"seed", 1, 1, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"players", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"list", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"games", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"pending", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"setname", (char *)"pname", 1, 1, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"create", (char *)"maxplayers,buyin", 2, 2, 'C', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"newgame", (char *)"maxplayers,buyin", 2, 2, 'C', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"playerinfo", (char *)"playertxid", 1, 1, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"info", (char *)"gametxid", 1, 1, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"gameinfo", (char *)"gametxid", 1, 1, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"keystrokes", (char *)"txid,hexstr", 2, 2, 'K', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"finish", (char *)"gametxid", 1, 1, 'Q', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"events", (char *)"eventshex [gametxid [eventid]]", 1, 3, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"extract", (char *)"gametxid [pubkey]", 1, 2, ' ', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"register", (char *)"gametxid [playertxid]", 1, 2, 'R', EVAL_GAMES },
bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx);
UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_rngnext(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_list(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_create(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_info(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
@@ -66,14 +70,30 @@ if ( cp->evalcode == EVAL_GAMES ) \
return(games_rng(txfee,cp,params)); \
else if ( strcmp(method,"rngnext") == 0 ) \
return(games_rngnext(txfee,cp,params)); \
else if ( strcmp(method,"create") == 0 ) \
return(games_create(txfee,cp,params)); \
else if ( strcmp(method,"info") == 0 ) \
return(games_info(txfee,cp,params)); \
else if ( strcmp(method,"newgame") == 0 ) \
return(games_newgame(txfee,cp,params)); \
else if ( strcmp(method,"gameinfo") == 0 ) \
return(games_gameinfo(txfee,cp,params)); \
else if ( strcmp(method,"register") == 0 ) \
return(games_register(txfee,cp,params)); \
else if ( strcmp(method,"events") == 0 ) \
return(games_events(txfee,cp,params)); \
else if ( strcmp(method,"players") == 0 ) \
return(games_players(txfee,cp,params)); \
else if ( strcmp(method,"games") == 0 ) \
return(games_games(txfee,cp,params)); \
else if ( strcmp(method,"pending") == 0 ) \
return(games_pending(txfee,cp,params)); \
else if ( strcmp(method,"setname") == 0 ) \
return(games_setname(txfee,cp,params)); \
else if ( strcmp(method,"playerinfo") == 0 ) \
return(games_playerinfo(txfee,cp,params)); \
else if ( strcmp(method,"keystrokes") == 0 ) \
return(games_keystrokes(txfee,cp,params)); \
else if ( strcmp(method,"extract") == 0 ) \
return(games_extract(txfee,cp,params)); \
else if ( strcmp(method,"finish") == 0 ) \
return(games_finish(txfee,cp,params)); \
else \
{ \
result.push_back(Pair("result","error")); \
@@ -82,6 +102,7 @@ if ( cp->evalcode == EVAL_GAMES ) \
return(result); \
} \
}
#endif
#define MAXPACK 23
struct games_packitem
@@ -96,6 +117,18 @@ struct games_player
struct games_packitem gamespack[MAXPACK];
};
struct games_state
{
uint64_t seed;
char *keystrokes,*keystrokeshex;
uint32_t needflush,replaydone;
int32_t numkeys,ind,num,guiflag,counter,sleeptime,playersize,restoring,lastnum;
FILE *logfp;
struct games_player P;
char buffered[10000];
uint8_t playerdata[10000];
};
int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis);
void games_packitemstr(char *packitemstr,struct games_packitem *item);

View File

@@ -1,2 +1,2 @@
gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -DSTANDALONE tetris.cpp -lncurses -o tetris
gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -DSTANDALONE gamescc.cpp -lncurses -lcurl -o tetris

View File

@@ -197,6 +197,9 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t
uint256 txid,fundingtxid,hashBlock,vinfundingtxid; uint64_t vinsbits,sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx;
numvins = tx.vin.size();
numvouts = tx.vout.size();
int64_t interest; uint64_t valuein;
CCoinsViewCache &view = *pcoinsTip;
valuein = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime);
preventCCvins = preventCCvouts = -1;
if ( numvouts < 1 )
return eval->Invalid("no vouts");
@@ -255,6 +258,11 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t
if ( (*cp->ismyvin)(tx.vin[i].scriptSig) == 0 )
return eval->Invalid("unexpected normal vin for unlock");
}
if ( valuein-tx.GetValueOut() > txfee )
{
fprintf(stderr, "valueout.%li vs valuein.%li txfee.%li\n", tx.GetValueOut(), valuein, txfee);
return eval->Invalid("alright is stealing your money");
}
if ( numvouts == 2 && numvins == 1 )
{
if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 )
@@ -707,4 +715,3 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2
fprintf(stderr,"amount %.8f -> reward %.8f\n",(double)amount/COIN,(double)reward/COIN);
return("");
}

View File

@@ -16,6 +16,24 @@
#ifndef H_CURSESD_H
#define H_CURSESD_H
#define COLOR_BLACK 0
#ifdef PDC_RGB /* RGB */
# define COLOR_RED 1
# define COLOR_GREEN 2
# define COLOR_BLUE 4
#else /* BGR */
# define COLOR_BLUE 1
# define COLOR_GREEN 2
# define COLOR_RED 4
#endif
#define COLOR_CYAN (COLOR_BLUE | COLOR_GREEN)
#define COLOR_MAGENTA (COLOR_RED | COLOR_BLUE)
#define COLOR_YELLOW (COLOR_RED | COLOR_GREEN)
#define COLOR_WHITE 7
#define LINES 24
#define COLS 80
@@ -151,6 +169,15 @@ char *unctrl(char c);
#define halfdelay(x) 0
#define nocbreak() 0
// for tetris
#define init_pair(a,b,c) 0
#define start_color() 0
#define box(a,b,c) 0
#define A_REVERSE 0
#define COLOR_PAIR(a) 0
#define timeout(x) 0
// end for tetris
#ifndef TRUE
#define TRUE 1
#endif

View File

@@ -22,6 +22,7 @@
#define ROGUE_MAXPLAYERS 64 // need to send unused fees back to globalCC address to prevent leeching
#define ROGUE_MAXKEYSTROKESGAP 60
#define ROGUE_MAXITERATIONS 777
#define ROGUE_MAXCASHOUT (777 * COIN)
#include "rogue/rogue_player.h"
@@ -1112,6 +1113,8 @@ int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C
dungeonlevel = P.dungeonlevel;
if ( P.amulet != 0 && dungeonlevel < 26 )
dungeonlevel = 26;
if ( dungeonlevel > 42 )
dungeonlevel = 42;
*cashoutp = (uint64_t)P.gold * P.gold * mult * dungeonlevel;
if ( newdata == playerdata )
{
@@ -1281,6 +1284,8 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
}
if ( cashout > 0 )
{
if ( komodo_nextheight() > 77777 && cashout > ROGUE_MAXCASHOUT )
cashout = ROGUE_MAXCASHOUT;
if ( (inputsum= AddCClibInputs(cp,mtx,roguepk,cashout,60,cp->unspendableCCaddr)) > cashout )
CCchange = (inputsum - cashout);
else fprintf(stderr,"couldnt find enough utxos\n");
@@ -1598,6 +1603,8 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C
cashout *= 2;
//cashout += numplayers * buyin;
}
if ( height > 777777 && cashout > ROGUE_MAXCASHOUT )
cashout = ROGUE_MAXCASHOUT;
sprintf(cashstr,"tokentx.(%c) decoded.%d ht.%d txid.%s %.8f vs vout2 %.8f",tokentx,decoded,height,txid.GetHex().c_str(),(double)cashout/COIN,(double)tx.vout[2].nValue/COIN);
if ( strcmp(laststr,cashstr) != 0 )
{