Merge pull request #1253 from jl777/jl777

stable rogue
This commit is contained in:
jl777
2019-02-16 02:11:27 -11:00
committed by GitHub
49 changed files with 775 additions and 315 deletions

View File

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

View File

@@ -47,7 +47,7 @@ bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t
//int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); // --> GetTokenBalance()
int64_t AddAssetInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs);
UniValue AssetOrders(uint256 tokenid);
UniValue AssetOrders(uint256 tokenid, CPubKey pubkey, uint8_t additionalEvalCode);
//UniValue AssetInfo(uint256 tokenid);
//UniValue AssetList();
//std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description);

View File

@@ -458,7 +458,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *origCCadd
else if( GetAssetorigaddrs(cp, origCCaddr, origaddr, vinTx) == 0 )
return eval->Invalid("couldnt get origaddr for buyvin");
fprintf(stderr,"AssetValidateCCvin() got %.8f to origaddr.(%s)\n", (double)vinTx.vout[tx.vin[vini].prevout.n].nValue/COIN,origaddr);
//fprintf(stderr,"AssetValidateCCvin() got %.8f to origaddr.(%s)\n", (double)vinTx.vout[tx.vin[vini].prevout.n].nValue/COIN,origaddr);
if ( vinTx.vout[0].nValue == 0 )
return eval->Invalid("null value CCvin");
@@ -622,7 +622,7 @@ bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t
assetoshis = IsTokensvout(false, false, cpTokens, NULL, vinTx, tx.vin[i].prevout.n, assetid);
if (assetoshis != 0)
{
std::cerr << "AssetCalcAmounts() vin i=" << i << " assetoshis=" << assetoshis << std::endl;
//std::cerr << "AssetCalcAmounts() vin i=" << i << " assetoshis=" << assetoshis << std::endl;
inputs += assetoshis;
}
}
@@ -634,7 +634,7 @@ bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t
assetoshis = IsAssetvout(cpAssets, tmpprice, tmporigpubkey, tx, i, assetid);
if (assetoshis != 0)
{
std::cerr << "AssetCalcAmounts() vout i=" << i << " assetoshis=" << assetoshis << std::endl;
//std::cerr << "AssetCalcAmounts() vout i=" << i << " assetoshis=" << assetoshis << std::endl;
outputs += assetoshis;
}
}

View File

@@ -66,100 +66,102 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK
}
*/
UniValue AssetOrders(uint256 refassetid)
UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode)
{
static uint256 zero;
UniValue result(UniValue::VARR);
struct CCcontract_info *cpAssets, assetsC;
struct CCcontract_info *cpTokens, tokensC;
cpAssets = CCinit(&assetsC, EVAL_ASSETS);
cpTokens = CCinit(&tokensC, EVAL_TOKENS);
auto addOrders = [&](struct CCcontract_info *cp, std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it)
{
uint256 txid, hashBlock, assetid, assetid2;
int64_t price;
std::vector<uint8_t> origpubkey;
CTransaction vintx;
CTransaction ordertx;
uint8_t funcid, evalCode;
char numstr[32], funcidstr[16], origaddr[64], assetidstr[65];
char numstr[32], funcidstr[16], origaddr[64], origtokenaddr[64], assetidstr[65];
txid = it->first.txhash;
//std::cerr << "addOrders() txid=" << txid.GetHex() << std::endl;
if ( GetTransaction(txid, vintx, hashBlock, false) != 0 )
LOGSTREAM("ccassets", CCLOG_DEBUG2, stream << "addOrders() checking txid=" << txid.GetHex() << std::endl);
if ( GetTransaction(txid, ordertx, hashBlock, false) != 0 )
{
// for logging: funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey);
//std::cerr << "addOrders() vintx.vout.size()=" << vintx.vout.size() << " funcid=" << (char)(funcid ? funcid : ' ') << " assetid=" << assetid.GetHex() << std::endl;
if (vintx.vout.size() > 0 && (funcid = DecodeAssetTokenOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) != 0)
if (ordertx.vout.size() > 0 && (funcid = DecodeAssetTokenOpRet(ordertx.vout[ordertx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) != 0)
{
if (refassetid != zero && assetid != refassetid)
{
//int32_t z;
//for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&txid)[z]);
//fprintf(stderr," txid\n");
//for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&assetid)[z]);
//fprintf(stderr," assetid\n");
//for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&refassetid)[z]);
//fprintf(stderr," refassetid\n");
return;
}
LOGSTREAM("ccassets", CCLOG_DEBUG2, stream << "addOrders() checking ordertx.vout.size()=" << ordertx.vout.size() << " funcid=" << (char)(funcid ? funcid : ' ') << " assetid=" << assetid.GetHex() << std::endl);
//std::cerr << "addOrders() it->first.index=" << it->first.index << " vintx.vout[it->first.index].nValue=" << vintx.vout[it->first.index].nValue << std::endl;
if (vintx.vout[it->first.index].nValue == 0)
return;
if (refassetid != zero && assetid == refassetid ||
pk != CPubKey() && pk == pubkey2pk(origpubkey) && (funcid == 'S' || funcid == 's'))
{
UniValue item(UniValue::VOBJ);
LOGSTREAM("ccassets", CCLOG_DEBUG2, stream << "addOrders() it->first.index=" << it->first.index << " ordertx.vout[it->first.index].nValue=" << ordertx.vout[it->first.index].nValue << std::endl);
if (ordertx.vout[it->first.index].nValue == 0) {
LOGSTREAM("ccassets", CCLOG_DEBUG2, stream << "addOrders() order with value=0 skipped" << std::endl);
return;
}
funcidstr[0] = funcid;
funcidstr[1] = 0;
item.push_back(Pair("funcid", funcidstr));
item.push_back(Pair("txid", uint256_str(assetidstr,txid)));
item.push_back(Pair("vout", (int64_t)it->first.index));
if ( funcid == 'b' || funcid == 'B' )
{
sprintf(numstr,"%.8f",(double)vintx.vout[it->first.index].nValue/COIN);
item.push_back(Pair("amount",numstr));
sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue/COIN);
item.push_back(Pair("bidamount",numstr));
}
else
{
sprintf(numstr,"%llu",(long long)vintx.vout[it->first.index].nValue);
item.push_back(Pair("amount",numstr));
sprintf(numstr,"%llu",(long long)vintx.vout[0].nValue);
item.push_back(Pair("askamount",numstr));
}
if ( origpubkey.size() == 33 )
{
GetCCaddress(cp, origaddr, pubkey2pk(origpubkey)); // TODO: what is this? is it asset or token??
item.push_back(Pair("origaddress", origaddr));
}
if ( assetid != zeroid )
item.push_back(Pair("tokenid",uint256_str(assetidstr,assetid)));
if ( assetid2 != zeroid )
item.push_back(Pair("otherid",uint256_str(assetidstr,assetid2)));
if ( price > 0 )
{
if ( funcid == 's' || funcid == 'S' || funcid == 'e' || funcid == 'e' )
UniValue item(UniValue::VOBJ);
funcidstr[0] = funcid;
funcidstr[1] = 0;
item.push_back(Pair("funcid", funcidstr));
item.push_back(Pair("txid", uint256_str(assetidstr, txid)));
item.push_back(Pair("vout", (int64_t)it->first.index));
if (funcid == 'b' || funcid == 'B')
{
sprintf(numstr,"%.8f",(double)price / COIN);
item.push_back(Pair("totalrequired", numstr));
sprintf(numstr,"%.8f",(double)price / (COIN * vintx.vout[0].nValue));
item.push_back(Pair("price", numstr));
sprintf(numstr, "%.8f", (double)ordertx.vout[it->first.index].nValue / COIN);
item.push_back(Pair("amount", numstr));
sprintf(numstr, "%.8f", (double)ordertx.vout[0].nValue / COIN);
item.push_back(Pair("bidamount", numstr));
}
else
{
item.push_back(Pair("totalrequired", (int64_t)price));
sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue / (price * COIN));
item.push_back(Pair("price",numstr));
sprintf(numstr, "%llu", (long long)ordertx.vout[it->first.index].nValue);
item.push_back(Pair("amount", numstr));
sprintf(numstr, "%llu", (long long)ordertx.vout[0].nValue);
item.push_back(Pair("askamount", numstr));
}
if (origpubkey.size() == 33)
{
GetCCaddress(cp, origaddr, pubkey2pk(origpubkey));
item.push_back(Pair("origaddress", origaddr));
GetTokensCCaddress(cpTokens, origtokenaddr, pubkey2pk(origpubkey));
item.push_back(Pair("origtokenaddress", origtokenaddr));
}
if (assetid != zeroid)
item.push_back(Pair("tokenid", uint256_str(assetidstr, assetid)));
if (assetid2 != zeroid)
item.push_back(Pair("otherid", uint256_str(assetidstr, assetid2)));
if (price > 0)
{
if (funcid == 's' || funcid == 'S' || funcid == 'e' || funcid == 'e')
{
sprintf(numstr, "%.8f", (double)price / COIN);
item.push_back(Pair("totalrequired", numstr));
sprintf(numstr, "%.8f", (double)price / (COIN * ordertx.vout[0].nValue));
item.push_back(Pair("price", numstr));
}
else
{
item.push_back(Pair("totalrequired", (int64_t)price));
sprintf(numstr, "%.8f", (double)ordertx.vout[0].nValue / (price * COIN));
item.push_back(Pair("price", numstr));
}
}
result.push_back(item);
LOGSTREAM("ccassets", CCLOG_DEBUG1, stream << "addOrders() added order funcId=" << (char)(funcid ? funcid : ' ') << " it->first.index=" << it->first.index << " ordertx.vout[it->first.index].nValue=" << ordertx.vout[it->first.index].nValue << " tokenid=" << assetid.GetHex() << std::endl);
}
result.push_back(item);
//fprintf(stderr,"addOrders() func.(%c) %s/v%d %.8f\n",funcid,uint256_str(assetidstr,txid),(int32_t)it->first.index,(double)vintx.vout[it->first.index].nValue/COIN);
}
}
};
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputsTokens, unspentOutputsCoins;
struct CCcontract_info *cpAssets, assetsC;
cpAssets = CCinit(&assetsC, EVAL_ASSETS);
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputsTokens, unspentOutputsDualEvalTokens, unspentOutputsCoins;
char assetsUnspendableAddr[64];
GetCCaddress(cpAssets, assetsUnspendableAddr, GetUnspendable(cpAssets, NULL));
@@ -167,24 +169,39 @@ UniValue AssetOrders(uint256 refassetid)
char assetsTokensUnspendableAddr[64];
std::vector<uint8_t> vopretNonfungible;
GetNonfungibleData(refassetid, vopretNonfungible);
if (vopretNonfungible.size() > 0)
cpAssets->additionalTokensEvalcode2 = vopretNonfungible.begin()[0];
if (refassetid != zeroid) {
GetNonfungibleData(refassetid, vopretNonfungible);
if (vopretNonfungible.size() > 0)
cpAssets->additionalTokensEvalcode2 = vopretNonfungible.begin()[0];
}
GetTokensCCaddress(cpAssets, assetsTokensUnspendableAddr, GetUnspendable(cpAssets, NULL));
SetCCunspents(unspentOutputsTokens, assetsTokensUnspendableAddr);
// tokenasks:
// tokenbids:
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator itCoins = unspentOutputsCoins.begin();
itCoins != unspentOutputsCoins.end();
itCoins++)
addOrders(cpAssets, itCoins);
// tokenbids:
// tokenasks:
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator itTokens = unspentOutputsTokens.begin();
itTokens != unspentOutputsTokens.end();
itTokens++)
addOrders(cpAssets, itTokens);
if (additionalEvalCode != 0) { //this would be mytokenorders
char assetsDualEvalTokensUnspendableAddr[64];
// try also dual eval tokenasks (and we do not need bids):
cpAssets->additionalTokensEvalcode2 = additionalEvalCode;
GetTokensCCaddress(cpAssets, assetsDualEvalTokensUnspendableAddr, GetUnspendable(cpAssets, NULL));
SetCCunspents(unspentOutputsDualEvalTokens, assetsDualEvalTokensUnspendableAddr);
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator itDualEvalTokens = unspentOutputsDualEvalTokens.begin();
itDualEvalTokens != unspentOutputsDualEvalTokens.end();
itDualEvalTokens++)
addOrders(cpAssets, itDualEvalTokens);
}
return(result);
}

View File

@@ -392,7 +392,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti
return eval->Invalid("mismatched vout0 assets dual unspendable CCaddr for fill sell");
}
}
fprintf(stderr,"fill validated\n");
//fprintf(stderr,"fill validated\n");
break;
case 'E': // fillexchange
////////// not implemented yet ////////////
@@ -451,7 +451,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti
}
}
////////// not implemented yet ////////////
fprintf(stderr,"fill validated\n");
//fprintf(stderr,"fill validated\n");
break;
default:
@@ -462,7 +462,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti
// what does this do?
bool bPrevent = PreventCC(eval, tx, preventCCvins, numvins, preventCCvouts, numvouts);
std::cerr << "AssetsValidate() PreventCC returned=" << bPrevent << std::endl;
//std::cerr << "AssetsValidate() PreventCC returned=" << bPrevent << std::endl;
return (bPrevent);
}

View File

@@ -62,6 +62,8 @@ CClib_methods[] =
{ (char *)"rogue", (char *)"highlander", (char *)"gametxid", 1, 1, 'H', EVAL_ROGUE },
{ (char *)"rogue", (char *)"playerinfo", (char *)"playertxid", 1, 1, 'I', EVAL_ROGUE },
{ (char *)"rogue", (char *)"players", (char *)"<no args>", 0, 0, 'D', EVAL_ROGUE },
{ (char *)"rogue", (char *)"games", (char *)"<no args>", 0, 0, 'F', EVAL_ROGUE },
{ (char *)"rogue", (char *)"setname", (char *)"pname", 1, 1, 'N', EVAL_ROGUE },
#else
{ (char *)"sudoku", (char *)"gen", (char *)"<no args>", 0, 0, 'G', EVAL_SUDOKU },
{ (char *)"sudoku", (char *)"txidinfo", (char *)"txid", 1, 1, 'T', EVAL_SUDOKU },
@@ -85,6 +87,8 @@ UniValue rogue_bailout(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue rogue_highlander(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
UniValue rogue_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
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);
#else
bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx);
@@ -118,6 +122,10 @@ UniValue CClib_method(struct CCcontract_info *cp,char *method,cJSON *params)
return(rogue_playerinfo(txfee,cp,params));
else if ( strcmp(method,"players") == 0 )
return(rogue_players(txfee,cp,params));
else if ( strcmp(method,"games") == 0 )
return(rogue_games(txfee,cp,params));
else if ( strcmp(method,"setname") == 0 )
return(rogue_setname(txfee,cp,params));
else
{
result.push_back(Pair("result","error"));

View File

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

View File

@@ -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 -lncurses
#gcc -std=c++11 -fPIC -shared -o librogue.so cclib.o rogue/rogue.so
cp librogue.so ../libcc.so

View File

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

View File

@@ -9,7 +9,7 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
//#include <curses.h>
#include "rogue.h"
/*

View File

@@ -10,8 +10,8 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
//#include <stdlib.h>
//#include <curses.h>
#include "rogue.h"
#define DRAGONSHOT 5 /* one chance in DRAGONSHOT that a dragon will flame */

View File

@@ -10,10 +10,7 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <string.h>
#include <curses.h>
#include <ctype.h>
//#include <curses.h>
#include "rogue.h"
/*
@@ -312,8 +309,12 @@ over:
after = FALSE;
msg(rs,"version %s. (mctesq was here)", release);
when 'S':
after = FALSE;
save_game(rs);
after = FALSE;
#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 '^':

108
src/cc/rogue/cursesd.c Normal file
View File

@@ -0,0 +1,108 @@
/******************************************************************************
* 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 *initscr()
{
if ( stdscr == 0 )
stdscr = (WINDOW *)calloc(1,sizeof(*stdscr));
return(stdscr);
}
void endwin()
{
if ( stdscr != 0 )
free(stdscr), stdscr = 0;
endwinflag = 1;
}
int isendwin(void)
{
return(endwinflag);
}
int wrefresh(WINDOW *win)
{
return(0);
}
int refresh(void)
{
endwinflag = 0;
return(wrefresh(stdscr));
}
int wnoutrefresh(WINDOW *win)
{
return(0);
}
int doupdate(void)
{
return(0);
}
int redrawwin(WINDOW *win)
{
return(wrefresh(win));
}
int wredrawln(WINDOW *win, int beg_line, int num_lines)
{
return(wrefresh(win));
}
int werase(WINDOW *win)
{
}
int erase(void)
{
return(werase(stdscr));
}
int wclear(WINDOW *win)
{
}
int clear(void)
{
return(wclear(stdscr));
}
int wclrtobot(WINDOW *win)
{
}
int clrtobot(void)
{
return(wclrtobot(stdscr));
}
int wclrtoeol(WINDOW *win)
{
}
int clrtoeol(void)
{
return(wclrtoeol(stdscr));
}

133
src/cc/rogue/cursesd.h Normal file
View File

@@ -0,0 +1,133 @@
/******************************************************************************
* 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 <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h> /* we need va_list */
#include <stddef.h> /* we want wchar_t */
#include <stdbool.h>
#include <ctype.h>
#include <time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#ifdef notyet
struct cursesd_info
{
uint8_t screen[LINES][COLS];
} *stdscr;
typedef struct cursesd_info WINDOW;
WINDOW *initscr(void);
int endwin(void);
int 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);
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);
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#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

@@ -11,7 +11,7 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
//#include <curses.h>
#include "rogue.h"
#define EMPTY 0

View File

@@ -10,7 +10,7 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
//#include <curses.h>
#include "rogue.h"
/*

View File

@@ -10,7 +10,7 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
//#include <curses.h>
#include "rogue.h"
@@ -452,7 +452,7 @@ void externs_clear()
memset(p_colors,0,sizeof(p_colors));
memset(prbuf,0,sizeof(prbuf));
memset(r_stones,0,sizeof(r_stones));
memset(whoami,0,sizeof(whoami));
//memset(whoami,0,sizeof(whoami));
memset(ws_made,0,sizeof(ws_made));
memset(ws_type,0,sizeof(ws_type));
runch = 0; /* Direction player is running */

View File

@@ -13,6 +13,9 @@
#ifndef H_EXTERN_ROGUE_H
#define H_EXTERN_ROGUE_H
#include <stdio.h>
#include <stdbool.h>
#ifdef HAVE_CONFIG_H
#ifdef PDCURSES
#undef HAVE_UNISTD_H

View File

@@ -10,10 +10,10 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
#include <string.h>
#include <ctype.h>
//#include <stdlib.h>
//#include <curses.h>
//#include <string.h>
//#include <ctype.h>
#include "rogue.h"
//#define EQSTR(a, b) (strcmp(a, b) == 0)

View File

@@ -10,10 +10,10 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
#include <ctype.h>
#include <string.h>
//#include <stdlib.h>
//#include <curses.h>
//#include <ctype.h>
//#include <string.h>
#include "rogue.h"
/*

View File

@@ -4,10 +4,10 @@
* @(#)io.c 4.32 (Berkeley) 02/05/99
*/
#include <stdarg.h>
#include <curses.h>
#include <ctype.h>
#include <string.h>
//#include <stdarg.h>
//#include <curses.h>
//#include <ctype.h>
//#include <string.h>
#include "rogue.h"
/*
@@ -162,7 +162,8 @@ 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 )
fprintf(stderr,"replay finished but readchar called\n");
rs->replaydone = (uint32_t)time(NULL);
//if ( (rand() & 1) == 0 )
// return(ESCAPE);

View File

@@ -10,9 +10,9 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
#include <memory.h>
//#include <stdlib.h>
//#include <curses.h>
//#include <memory.h>
#include "rogue.h"
#ifdef MASTER

View File

@@ -46,7 +46,8 @@
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <curses.h>
//#include <curses.h>
#include "rogue.h"
#include "extern.h"
#define NOOP(x) (x += 0)

View File

@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <unistd.h>
#define SMALLVAL 0.000000000000001
#define SATOSHIDEN ((uint64_t)100000000L)
@@ -190,7 +191,11 @@ int32_t safecopy(char *dest,char *src,long len)
#define true 1
#define false 0
#ifdef STANDALONE
#include "../komodo/src/komodo_cJSON.c"
#else
#include "../../komodo_cJSON.c"
#endif
int32_t rogue_replay(uint64_t seed,int32_t sleeptime);
int rogue(int argc, char **argv, char **envp);

View File

@@ -44,7 +44,7 @@
#undef MOUSE_MOVED
#endif
#include <curses.h>
//#include <curses.h>
#include "extern.h"
#if defined(HAVE_SYS_TYPES)

View File

@@ -10,10 +10,10 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
#include <string.h>
#include <ctype.h>
//#include <stdlib.h>
//#include <curses.h>
//#include <string.h>
//#include <ctype.h>
#include "rogue.h"
/*

View File

@@ -10,10 +10,10 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <string.h>
//#include <curses.h>
//#include <string.h>
#include "rogue.h"
#include <ctype.h>
//#include <ctype.h>
/*
* List of monsters in rough order of vorpalness

View File

@@ -10,8 +10,8 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <ctype.h>
//#include <curses.h>
//#include <ctype.h>
#include "rogue.h"
/*

View File

@@ -11,8 +11,8 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <string.h>
//#include <curses.h>
//#include <string.h>
#include "rogue.h"
#define TREAS_ROOM 20 /* one chance in TREAS_ROOM for a treasure room */

View File

@@ -12,10 +12,10 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
#include <ctype.h>
#include <string.h>
//#include <stdlib.h>
//#include <curses.h>
//#include <ctype.h>
//#include <string.h>
#include "rogue.h"
#define EQSTR(a, b, c) (strncmp(a, b, c) == 0)

View File

@@ -10,9 +10,9 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <string.h>
#include <curses.h>
#include <ctype.h>
//#include <string.h>
//#include <curses.h>
//#include <ctype.h>
#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)

View File

@@ -10,8 +10,8 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
//#include <stdlib.h>
//#include <curses.h>
#include "rogue.h"
/*

View File

@@ -10,8 +10,8 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <ctype.h>
//#include <curses.h>
//#include <ctype.h>
#include "rogue.h"
typedef struct

View File

@@ -10,7 +10,7 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
//#include <curses.h>
#include "rogue.h"
/*

View File

@@ -11,14 +11,14 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <string.h>
#include <time.h>
//#include <stdlib.h>
//#include <string.h>
//#include <time.h>
#include <signal.h>
#include <sys/types.h>
#include <ctype.h>
#include <fcntl.h>
#include <curses.h>
//#include <sys/types.h>
//#include <ctype.h>
//#include <fcntl.h>
//#include <curses.h>
#include "rogue.h"
#include "score.h"

View File

@@ -8,14 +8,17 @@
* @(#)main.c 4.22 (Berkeley) 02/05/99
*/
#include <stdlib.h>
#include <string.h>
//#include <stdlib.h>
//#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
#include <curses.h>
//#include <unistd.h>
//#include <curses.h>
#include "rogue.h"
#ifdef STANDALONE
#include "../komodo/src/komodo_cJSON.h"
#else
#include "../../komodo_cJSON.h"
#endif
/*
* main:
@@ -84,6 +87,8 @@ 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);
@@ -148,7 +153,9 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname);
int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr)
{
char cmd[32768]; int32_t i,n,retval=-1; char *filestr,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item;
char cmd[32768]; int32_t i,n,retval=-1; char *filestr,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item;
if ( gametxidstr == 0 || *gametxidstr == 0 )
return(retval);
sprintf(fname,"%s.gameinfo",gametxidstr);
sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",gametxidstr,fname);
if ( system(cmd) != 0 )
@@ -170,8 +177,10 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr)
retval = 0;
if ( (item= jobj(item,"player")) != 0 && (datastr= jstr(item,"data")) != 0 )
{
if ( (pname= jstr(item,"pname")) != 0 && strlen(pname) < MAXSTR-1 )
strcpy(whoami,pname);
decode_hex((uint8_t *)&rs->P,(int32_t)strlen(datastr)/2,datastr);
//fprintf(stderr,"set datastr[%d]\n",(int32_t)strlen(datastr));
fprintf(stderr,"set pname[%s] %s\n",pname==0?"":pname,jprint(item,0));
rs->restoring = 1;
}
}
@@ -188,12 +197,15 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr)
void rogue_progress(uint64_t seed,char *keystrokes,int32_t num)
{
char cmd[16384],hexstr[16384]; int32_t i;
for (i=0; i<num; i++)
sprintf(&hexstr[i<<1],"%02x",keystrokes[i]);
hexstr[i<<1] = 0;
sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib keystrokes 17 \\\"[%%22%s%%22,%%22%s%%22]\\\" >> keystrokes.log",Gametxidstr,hexstr);
if ( system(cmd) != 0 )
fprintf(stderr,"error issuing (%s)\n",cmd);
if ( Gametxidstr[0] != 0 )
{
for (i=0; i<num; i++)
sprintf(&hexstr[i<<1],"%02x",keystrokes[i]);
hexstr[i<<1] = 0;
sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib keystrokes 17 \\\"[%%22%s%%22,%%22%s%%22]\\\" >> keystrokes.log",Gametxidstr,hexstr);
if ( system(cmd) != 0 )
fprintf(stderr,"error issuing (%s)\n",cmd);
}
}
int32_t flushkeystrokes(struct rogue_state *rs)
@@ -236,21 +248,24 @@ int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu
}
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);
@@ -358,8 +373,8 @@ int rogue(int argc, char **argv, char **envp)
if ((env = getenv("ROGUEOPTS")) != NULL)
parse_opts(env);
if (env == NULL || whoami[0] == '\0')
strucpy(whoami, md_getusername(), (int) strlen(md_getusername()));
//if (env == NULL || whoami[0] == '\0')
// strucpy(whoami, md_getusername(), (int) strlen(md_getusername()));
lowtime = (int) time(NULL);
#ifdef MASTER
if (wizard && getenv("SEED") != NULL)

View File

@@ -12,9 +12,43 @@
#ifndef H_ROGUE_H
#define H_ROGUE_H
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h> /* we need va_list */
#include <stddef.h> /* we want wchar_t */
#include <stdbool.h>
#include <ctype.h>
#include <time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#ifndef DONTUSEGUI
#include <curses.h>
#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)
@@ -782,6 +816,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);

View File

@@ -10,8 +10,8 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <ctype.h>
#include <curses.h>
//#include <ctype.h>
//#include <curses.h>
#include "rogue.h"
typedef struct spot { /* position matrix for maze positions */

View File

@@ -10,13 +10,13 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <curses.h>
//#include <stdlib.h>
//#include <sys/types.h>
//#include <sys/stat.h>
//#include <errno.h>
//#include <signal.h>
//#include <string.h>
//#include <curses.h>
#include "rogue.h"
#include "score.h"

View File

@@ -10,8 +10,8 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <ctype.h>
//#include <curses.h>
//#include <ctype.h>
#include "rogue.h"
/*

View File

@@ -29,9 +29,9 @@
SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
#include <curses.h>
//#include <stdlib.h>
//#include <string.h>
//#include <curses.h>
#include "rogue.h"
/************************************************************************/
@@ -1374,9 +1374,9 @@ void rogue_restoreobject(THING *o,struct rogue_packitem *item)
break;
// cur_armor and cur_weapon should be set
}
char packitemstr[256];
strcpy(packitemstr,inv_name(o,FALSE));
fprintf(stderr,"packitem.(%s)\n",packitemstr);
//char packitemstr[256];
//strcpy(packitemstr,inv_name(o,FALSE));
//fprintf(stderr,"packitem.(%s)\n",packitemstr);
}
}

View File

@@ -11,9 +11,9 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <string.h>
#include <ctype.h>
//#include <curses.h>
//#include <string.h>
//#include <ctype.h>
#include "rogue.h"
/*

View File

@@ -11,9 +11,9 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <string.h>
#include <ctype.h>
//#include <curses.h>
//#include <string.h>
//#include <ctype.h>
#include "rogue.h"
/*
@@ -498,55 +498,55 @@ 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 (md_hasclreol())
{
werase(tw);
leaveok(tw, TRUE);
wrefresh(tw);
}
delwin(tw);
touchwin(stdscr);
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
{
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'))
{

View File

@@ -10,9 +10,9 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <string.h>
#include <ctype.h>
//#include <curses.h>
//#include <string.h>
//#include <ctype.h>
#include "rogue.h"
#define NO_WEAPON -1

View File

@@ -11,10 +11,10 @@
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
#include <string.h>
#include <ctype.h>
//#include <stdlib.h>
//#include <curses.h>
//#include <string.h>
//#include <ctype.h>
#include "rogue.h"
/*

View File

@@ -21,6 +21,25 @@
#define ROGUE_REGISTRATIONSIZE (100 * 10000)
#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 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);
std::string Rogue_pname = "";
/*
Roguelander - using highlander competition between rogue players
@@ -116,7 +135,8 @@
// todo:
// verify keystrokes tx is in mempool and confirmed
// chaining when mempool tx sometimes infinite loops
// chaining when mempool tx sometimes infinite loops?
// bailout stealing, is it possible?
//////////////////////// 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 &
@@ -130,20 +150,6 @@
// ./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)
{
@@ -167,14 +173,14 @@ CScript rogue_keystrokesopret(uint256 gametxid,uint256 batontxid,CPubKey pk,std:
return(opret);
}
CScript rogue_highlanderopret(uint8_t funcid,uint256 gametxid,int32_t regslot,CPubKey pk,std::vector<uint8_t>playerdata)
CScript rogue_highlanderopret(uint8_t funcid,uint256 gametxid,int32_t regslot,CPubKey pk,std::vector<uint8_t>playerdata,std::string pname)
{
CScript opret; uint8_t evalcode = EVAL_ROGUE;
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << gametxid << regslot << pk << playerdata);
CScript opret; uint8_t evalcode = EVAL_ROGUE; std::string symbol(ASSETCHAINS_SYMBOL);
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << gametxid << symbol << pname << regslot << pk << playerdata );
return(opret);
}
uint8_t rogue_highlanderopretdecode(uint256 &gametxid, uint256 &tokenid, int32_t &regslot, CPubKey &pk, std::vector<uint8_t> &playerdata, CScript scriptPubKey)
uint8_t rogue_highlanderopretdecode(uint256 &gametxid, uint256 &tokenid, int32_t &regslot, CPubKey &pk, std::vector<uint8_t> &playerdata, std::string &symbol, std::string &pname,CScript scriptPubKey)
{
std::string name, description; std::vector<uint8_t> vorigPubkey;
std::vector<uint8_t> vopretNonfungible, vopret, vopretDummy,origpubkey;
@@ -192,7 +198,7 @@ uint8_t rogue_highlanderopretdecode(uint256 &gametxid, uint256 &tokenid, int32_t
GetNonfungibleData(tokenid, vopretNonfungible); //load nonfungible data from the 'tokenbase' tx
vopret = vopretNonfungible;
}
if ( vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> gametxid; ss >> regslot; ss >> pk; ss >> playerdata) != 0 && e == EVAL_ROGUE && (f == 'H' || f == 'Q') )
if ( vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> gametxid; ss >> symbol; ss >> pname; ss >> regslot; ss >> pk; ss >> playerdata) != 0 && e == EVAL_ROGUE && (f == 'H' || f == 'Q') )
{
return(f);
}
@@ -231,7 +237,7 @@ uint8_t rogue_registeropretdecode(uint256 &gametxid,uint256 &tokenid,uint256 &pl
{
return(f);
}
fprintf(stderr,"e.%d f.%c game.%s playertxid.%s\n",e,f,gametxid.GetHex().c_str(),playertxid.GetHex().c_str());
//fprintf(stderr,"e.%d f.%c game.%s playertxid.%s\n",e,f,gametxid.GetHex().c_str(),playertxid.GetHex().c_str());
return(0);
}
@@ -363,7 +369,7 @@ int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransa
} else return(-1);
}
UniValue rogue_playerobj(std::vector<uint8_t> playerdata,uint256 playertxid,uint256 tokenid)
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);
memset(&P,0,sizeof(P));
@@ -396,21 +402,29 @@ UniValue rogue_playerobj(std::vector<uint8_t> playerdata,uint256 playertxid,uint
obj.push_back(Pair("level",(int64_t)P.level));
obj.push_back(Pair("experience",(int64_t)P.experience));
obj.push_back(Pair("dungeonlevel",(int64_t)P.dungeonlevel));
obj.push_back(Pair("chain",symbol));
obj.push_back(Pair("pname",pname));
return(obj);
}
int32_t rogue_iterateplayer(uint256 &registertxid,uint256 firsttxid,int32_t firstvout,uint256 lasttxid) // retrace playertxid vins to reach highlander <- this verifies player is valid and rogue_playerdataspend makes sure it can only be used once
{
uint256 spenttxid,txid = firsttxid; int32_t spentvini,vout = firstvout;
uint256 spenttxid,txid = firsttxid; int32_t spentvini,n,vout = firstvout;
registertxid = zeroid;
if ( vout < 0 )
return(-1);
n = 0;
while ( (spentvini= myIsutxo_spent(spenttxid,txid,vout)) == 0 )
{
txid = spenttxid;
vout = spentvini;
if ( registertxid == zeroid )
registertxid = txid;
if ( ++n >= ROGUE_MAXITERATIONS )
{
fprintf(stderr,"rogue_iterateplayer n.%d, seems something is wrong\n",n);
return(-2);
}
}
if ( txid == lasttxid )
return(0);
@@ -427,12 +441,12 @@ int32_t rogue_iterateplayer(uint256 &registertxid,uint256 firsttxid,int32_t firs
origplayergame is the gametxid that ends up being won by the highlander and they are linked directly as the highlander tx spends gametxid.vout0
*/
int32_t rogue_playerdata(struct CCcontract_info *cp,uint256 &origplayergame,uint256 &tokenid,CPubKey &pk,std::vector<uint8_t> &playerdata,uint256 playertxid)
int32_t rogue_playerdata(struct CCcontract_info *cp,uint256 &origplayergame,uint256 &tokenid,CPubKey &pk,std::vector<uint8_t> &playerdata,std::string &symbol,std::string &pname,uint256 playertxid)
{
uint256 origplayertxid,hashBlock,gametxid,registertxid; CTransaction gametx,playertx,highlandertx; std::vector<uint8_t> vopret; uint8_t *script,e,f; int32_t i,regslot,gameheight,numvouts,maxplayers; int64_t buyin;
if ( GetTransaction(playertxid,playertx,hashBlock,false) != 0 && (numvouts= playertx.vout.size()) > 0 )
{
if ( (f= rogue_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,playertx.vout[numvouts-1].scriptPubKey)) == 'H' || f == 'Q' )
if ( (f= rogue_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,playertx.vout[numvouts-1].scriptPubKey)) == 'H' || f == 'Q' )
{
if ( tokenid != zeroid )
{
@@ -452,7 +466,7 @@ int32_t rogue_playerdata(struct CCcontract_info *cp,uint256 &origplayergame,uint
return(0);
} else fprintf(stderr,"hash mismatch or illegal gametxid\n");
} else fprintf(stderr,"invalid game %s\n",gametxid.GetHex().c_str());
}
} //else fprintf(stderr,"invalid player funcid.%c\n",f);
} else fprintf(stderr,"couldnt get playertxid.%s\n",playertxid.GetHex().c_str());
return(-1);
}
@@ -467,9 +481,9 @@ int32_t rogue_playerdataspend(CMutableTransaction &mtx,uint256 playertxid,int32_
} else return(-1);
}
int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **keystrokesp,int32_t &numkeys,int32_t &regslot,std::vector<uint8_t> &playerdata,uint256 &batontxid,int32_t &batonvout,int64_t &batonvalue,int32_t &batonht,uint256 gametxid,CTransaction gametx,int32_t maxplayers,char *destaddr,int32_t &numplayers)
int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **keystrokesp,int32_t &numkeys,int32_t &regslot,std::vector<uint8_t> &playerdata,uint256 &batontxid,int32_t &batonvout,int64_t &batonvalue,int32_t &batonht,uint256 gametxid,CTransaction gametx,int32_t maxplayers,char *destaddr,int32_t &numplayers,std::string &symbol,std::string &pname)
{
int32_t i,numvouts,spentvini,matches = 0; CPubKey pk; uint256 tid,spenttxid,tokenid,hashBlock,txid,origplayergame; CTransaction spenttx,matchtx,batontx; std::vector<uint8_t> checkdata; CBlockIndex *pindex; char ccaddr[64],*keystrokes=0;
int32_t i,numvouts,spentvini,n,matches = 0; CPubKey pk; uint256 tid,active,spenttxid,tokenid,hashBlock,txid,origplayergame; CTransaction spenttx,matchtx,batontx; std::vector<uint8_t> checkdata; CBlockIndex *pindex; char ccaddr[64],*keystrokes=0;
numkeys = numplayers = 0;
playertxid = zeroid;
for (i=0; i<maxplayers; i++)
@@ -497,13 +511,15 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke
//fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex().c_str(),matches,numvouts);
if ( rogue_registeropretdecode(txid,tokenid,playertxid,matchtx.vout[numvouts-1].scriptPubKey) == 'R' )//&& txid == gametxid )
{
fprintf(stderr,"tokenid.%s txid.%s vs gametxid.%s\n",tokenid.GetHex().c_str(),txid.GetHex().c_str(),gametxid.GetHex().c_str());
//fprintf(stderr,"tokenid.%s txid.%s vs gametxid.%s player.%s\n",tokenid.GetHex().c_str(),txid.GetHex().c_str(),gametxid.GetHex().c_str(),playertxid.GetHex().c_str());
if ( tokenid != zeroid )
playertxid = tokenid;
if ( playertxid == zeroid || rogue_playerdata(cp,origplayergame,tid,pk,playerdata,playertxid) == 0 )
active = tokenid;
else active = playertxid;
if ( active == zeroid || rogue_playerdata(cp,origplayergame,tid,pk,playerdata,symbol,pname,active) == 0 )
{
txid = matchtx.GetHash();
//fprintf(stderr,"scan forward playertxid.%s spenttxid.%s\n",playertxid.GetHex().c_str(),txid.GetHex().c_str());
//fprintf(stderr,"scan forward active.%s spenttxid.%s\n",active.GetHex().c_str(),txid.GetHex().c_str());
n = 0;
while ( CCgettxout(txid,0,1) < 0 )
{
spenttxid = zeroid;
@@ -515,12 +531,13 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke
fprintf(stderr,"mempool tracking error %s/v0\n",txid.ToString().c_str());
return(-2);
}
txid = spenttxid;
if ( spentvini != 0 )
return(-3);
if ( keystrokesp != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() == 2 )
if ( keystrokesp != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 )
{
uint256 g,b; CPubKey p; std::vector<uint8_t> k;
if ( rogue_keystrokesopretdecode(g,b,p,k,spenttx.vout[1].scriptPubKey) == 'K' )
if ( rogue_keystrokesopretdecode(g,b,p,k,spenttx.vout[spenttx.vout.size()-1].scriptPubKey) == 'K' )
{
keystrokes = (char *)realloc(keystrokes,numkeys + (int32_t)k.size());
for (i=0; i<k.size(); i++)
@@ -529,6 +546,11 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke
(*keystrokesp) = keystrokes;
}
}
if ( ++n >= ROGUE_MAXITERATIONS )
{
fprintf(stderr,"rogue_findbaton n.%d, seems something is wrong\n",n);
return(-5);
}
}
//fprintf(stderr,"set baton %s\n",txid.GetHex().c_str());
batontxid = txid;
@@ -561,7 +583,7 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke
void rogue_gameplayerinfo(struct CCcontract_info *cp,UniValue &obj,uint256 gametxid,CTransaction gametx,int32_t vout,int32_t maxplayers,char *myrogueaddr)
{
// identify if bailout or quit or timed out
uint256 batontxid,spenttxid,gtxid,ptxid,tokenid,hashBlock,playertxid; CTransaction spenttx,batontx; int32_t numplayers,regslot,numkeys,batonvout,batonht,retval; int64_t batonvalue; std::vector<uint8_t> playerdata; char destaddr[64];
uint256 batontxid,spenttxid,gtxid,ptxid,tokenid,hashBlock,playertxid; CTransaction spenttx,batontx; int32_t numplayers,regslot,numkeys,batonvout,batonht,retval; int64_t batonvalue; std::vector<uint8_t> playerdata; char destaddr[64]; std::string symbol,pname;
destaddr[0] = 0;
if ( myIsutxo_spent(spenttxid,gametxid,vout) >= 0 )
{
@@ -569,7 +591,7 @@ void rogue_gameplayerinfo(struct CCcontract_info *cp,UniValue &obj,uint256 gamet
Getscriptaddress(destaddr,spenttx.vout[0].scriptPubKey);
}
obj.push_back(Pair("slot",(int64_t)vout-1));
if ( (retval= rogue_findbaton(cp,playertxid,0,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,destaddr,numplayers)) == 0 )
if ( (retval= rogue_findbaton(cp,playertxid,0,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,destaddr,numplayers,symbol,pname)) == 0 )
{
if ( CCgettxout(gametxid,maxplayers+vout,1) == 10000 )
{
@@ -588,7 +610,7 @@ void rogue_gameplayerinfo(struct CCcontract_info *cp,UniValue &obj,uint256 gamet
obj.push_back(Pair("batonvalue",ValueFromAmount(batonvalue)));
obj.push_back(Pair("batonht",(int64_t)batonht));
if ( playerdata.size() > 0 )
obj.push_back(Pair("player",rogue_playerobj(playerdata,playertxid,tokenid)));
obj.push_back(Pair("player",rogue_playerobj(playerdata,playertxid,tokenid,symbol,pname)));
} else fprintf(stderr,"findbaton err.%d\n",retval);
}
@@ -667,7 +689,7 @@ UniValue rogue_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
UniValue rogue_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
{
UniValue result(UniValue::VOBJ); std::vector<uint8_t> playerdata; uint256 playertxid,tokenid,origplayergame;int32_t n; CPubKey pk; bits256 t;
UniValue result(UniValue::VOBJ); std::vector<uint8_t> playerdata; uint256 playertxid,tokenid,origplayergame;int32_t n; CPubKey pk; bits256 t; std::string symbol,pname;
result.push_back(Pair("result","success"));
rogue_univalue(result,"playerinfo",-1,-1);
if ( (params= cclib_reparse(&n,params)) != 0 )
@@ -675,9 +697,9 @@ UniValue rogue_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
if ( n > 0 )
{
playertxid = juint256(jitem(params,0));
if ( rogue_playerdata(cp,origplayergame,tokenid,pk,playerdata,playertxid) < 0 )
if ( rogue_playerdata(cp,origplayergame,tokenid,pk,playerdata,symbol,pname,playertxid) < 0 )
return(cclib_error(result,"invalid playerdata"));
result.push_back(Pair("player",rogue_playerobj(playerdata,playertxid,tokenid)));
result.push_back(Pair("player",rogue_playerobj(playerdata,playertxid,tokenid,symbol,pname)));
} else return(cclib_error(result,"no playertxid"));
return(result);
} else return(cclib_error(result,"couldnt reparse params"));
@@ -691,7 +713,7 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
// vin3+ -> buyin
// vout0 -> keystrokes/completion baton
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
UniValue result(UniValue::VOBJ); char destaddr[64],coinaddr[64]; uint256 tokenid,gametxid,origplayergame,playertxid,hashBlock; int32_t err,maxplayers,gameheight,n,numvouts,vout=1; int64_t inputsum,buyin,CCchange=0; CPubKey pk,mypk,roguepk,burnpk; CTransaction tx,playertx; std::vector<uint8_t> playerdata; std::string rawtx; bits256 t;
UniValue result(UniValue::VOBJ); char destaddr[64],coinaddr[64]; uint256 tokenid,gametxid,origplayergame,playertxid,hashBlock; int32_t err,maxplayers,gameheight,n,numvouts,vout=1; int64_t inputsum,buyin,CCchange=0; CPubKey pk,mypk,roguepk,burnpk; CTransaction tx,playertx; std::vector<uint8_t> playerdata; std::string rawtx,symbol,pname; bits256 t;
if ( txfee == 0 )
txfee = 10000;
@@ -710,7 +732,7 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
if ( n > 1 )
{
playertxid = juint256(jitem(params,1));
if ( rogue_playerdata(cp,origplayergame,tokenid,pk,playerdata,playertxid) < 0 )
if ( rogue_playerdata(cp,origplayergame,tokenid,pk,playerdata,symbol,pname,playertxid) < 0 )
return(cclib_error(result,"couldnt extract valid playerdata"));
if ( tokenid != zeroid )
vout = 1;
@@ -725,9 +747,9 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
return(cclib_error(result,"couldnt find playerdata to spend"));
else if ( buyin > 0 && AddNormalinputs(mtx,mypk,buyin,64) < buyin )
return(cclib_error(result,"couldnt find enough normal funds for buyin"));
if ( playertxid != zeroid )
if ( tokenid != zeroid )
{
mtx.vin.push_back(CTxIn(playertxid,0)); // spending cc marker as token is burned
mtx.vin.push_back(CTxIn(tokenid,0)); // spending cc marker as token is burned
char unspendableTokenAddr[64]; uint8_t tokenpriv[32]; struct CCcontract_info *cpTokens, tokensC;
cpTokens = CCinit(&tokensC, EVAL_TOKENS);
CPubKey unspPk = GetUnspendable(cpTokens, tokenpriv);
@@ -743,7 +765,6 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
CScript opretRegister = rogue_registeropret(gametxid, playertxid);
if ( playertxid != zeroid )
{
//fprintf(stderr,"gametxid.%s playertxid.%s opR.%d\n",gametxid.GetHex().c_str(),playertxid.GetHex().c_str(),(int32_t)opretRegister.size());
voutPubkeysEmpty.push_back(burnpk);
if ( GetTransaction(playertxid,playertx,hashBlock,false) != 0 )
{
@@ -775,7 +796,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
// respawn to be prevented by including timestamps
int32_t nextheight = komodo_nextheight();
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight);
UniValue result(UniValue::VOBJ); CPubKey roguepk,mypk; uint256 gametxid,playertxid,batontxid; int64_t batonvalue,buyin; std::vector<uint8_t> keystrokes,playerdata; int32_t numplayers,regslot,numkeys,batonht,batonvout,n,elapsed,gameheight,maxplayers; CTransaction tx; CTxOut txout; char *keystrokestr,destaddr[64]; std::string rawtx; bits256 t; uint8_t mypriv[32];
UniValue result(UniValue::VOBJ); CPubKey roguepk,mypk; uint256 gametxid,playertxid,batontxid; int64_t batonvalue,buyin; std::vector<uint8_t> keystrokes,playerdata; int32_t numplayers,regslot,numkeys,batonht,batonvout,n,elapsed,gameheight,maxplayers; CTransaction tx; CTxOut txout; char *keystrokestr,destaddr[64]; std::string rawtx,symbol,pname; bits256 t; uint8_t mypriv[32];
if ( txfee == 0 )
txfee = 10000;
rogue_univalue(result,"keystrokes",-1,-1);
@@ -788,7 +809,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
GetCCaddress1of2(cp,destaddr,roguepk,mypk);
if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid) == 0 )
{
if ( rogue_findbaton(cp,playertxid,0,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,tx,maxplayers,destaddr,numplayers) == 0 )
if ( rogue_findbaton(cp,playertxid,0,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,tx,maxplayers,destaddr,numplayers,symbol,pname) == 0 )
{
if ( maxplayers == 1 || nextheight <= batonht+ROGUE_MAXKEYSTROKESGAP )
{
@@ -819,7 +840,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
// vout0 -> 1% ingame gold
// get any playerdata, get all keystrokes, replay game and compare final state
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
UniValue result(UniValue::VOBJ); std::string rawtx; CTransaction gametx; uint64_t seed,mult; int64_t buyin,batonvalue,inputsum,cashout,CCchange=0; int32_t i,err,gameheight,tmp,numplayers,regslot,n,num,numkeys,maxplayers,batonht,batonvout; char myrogueaddr[64],*keystrokes = 0; std::vector<uint8_t> playerdata,newdata; uint256 batontxid,playertxid,gametxid; CPubKey mypk,roguepk; uint8_t player[10000],mypriv[32],funcid;
UniValue result(UniValue::VOBJ); std::string rawtx,symbol,pname; CTransaction gametx; uint64_t seed,mult; int64_t buyin,batonvalue,inputsum,cashout,CCchange=0; int32_t i,err,gameheight,tmp,numplayers,regslot,n,num,numkeys,maxplayers,batonht,batonvout; char myrogueaddr[64],*keystrokes = 0; std::vector<uint8_t> playerdata,newdata,nodata; uint256 batontxid,playertxid,gametxid; CPubKey mypk,roguepk; uint8_t player[10000],mypriv[32],funcid;
struct CCcontract_info *cpTokens, tokensC;
if ( txfee == 0 )
@@ -850,11 +871,13 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
{
if ( maxplayers == 1 )
mult /= 2;
if ( rogue_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,myrogueaddr,numplayers) == 0 )
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,"found baton %s numkeys.%d seed.%llu playerdata.%d\n",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.c_str(),batontxid.ToString().c_str(),numkeys,(long long)seed,(int32_t)playerdata.size());
memset(&P,0,sizeof(P));
if ( playerdata.size() > 0 )
{
@@ -909,11 +932,16 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
Myprivkey(mypriv);
CCaddr1of2set(cp,roguepk,mypk,mypriv,myrogueaddr);
CScript opret = rogue_highlanderopret(funcid, gametxid, regslot, mypk, newdata);
CScript opret;
if ( newdata.size() == 0 )
{
opret = rogue_highlanderopret(funcid, gametxid, regslot, mypk, nodata,pname);
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,opret);
//fprintf(stderr,"nodata finalizetx.(%s)\n",rawtx.c_str());
}
else
{
opret = rogue_highlanderopret(funcid, gametxid, regslot, mypk, newdata,pname);
char seedstr[32];
sprintf(seedstr,"%llu",(long long)seed);
std::vector<uint8_t> vopretNonfungible;
@@ -1000,13 +1028,13 @@ 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);
}
UniValue rogue_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
{
UniValue result(UniValue::VOBJ),a(UniValue::VARR); int64_t buyin; uint256 tokenid,gametxid,txid,hashBlock; CTransaction playertx,tx; int32_t maxplayers,vout,numvouts; std::vector<uint8_t> playerdata; CPubKey roguepk,mypk,pk; char coinaddr[64];
UniValue result(UniValue::VOBJ),a(UniValue::VARR); int64_t buyin; uint256 tokenid,gametxid,txid,hashBlock; CTransaction playertx,tx; int32_t maxplayers,vout,numvouts; std::vector<uint8_t> playerdata; CPubKey roguepk,mypk,pk; std::string symbol,pname; char coinaddr[64];
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
roguepk = GetUnspendable(cp,0);
mypk = pubkey2pk(Mypubkey());
@@ -1020,14 +1048,75 @@ UniValue rogue_players(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 != 1 || vout > 1 )
continue;
if ( rogue_playerdata(cp,gametxid,tokenid,pk,playerdata,txid) == 0 )//&& pk == mypk )
if ( rogue_playerdata(cp,gametxid,tokenid,pk,playerdata,symbol,pname,txid) == 0 )//&& pk == mypk )
{
a.push_back(rogue_playerobj(playerdata,txid,tokenid));
//result.push_back(Pair("playerdata",rogue_playerobj(playerdata)));
a.push_back(txid.GetHex());
//a.push_back(Pair("playerdata",rogue_playerobj(playerdata)));
}
}
result.push_back(Pair("playerdata",a));
result.push_back(Pair("numplayerdata",a.size()));
result.push_back(Pair("numplayerdata",(int64_t)a.size()));
return(result);
}
UniValue rogue_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
{
UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); uint256 txid,hashBlock,gametxid,tokenid,playertxid; int32_t vout,maxplayers,gameheight,numvouts; CPubKey roguepk,mypk; char coinaddr[64]; CTransaction tx,gametx; int64_t buyin;
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
//std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
roguepk = GetUnspendable(cp,0);
mypk = pubkey2pk(Mypubkey());
GetCCaddress1of2(cp,coinaddr,roguepk,mypk);
//SetCCunspents(unspentOutputs,coinaddr);
SetCCtxids(addressIndex,coinaddr);
rogue_univalue(result,"games",-1,-1);
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
//for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
{
txid = it->first.txhash;
vout = (int32_t)it->first.index;
//char str[65]; fprintf(stderr,"%s check %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN);
if ( vout == 0 )
{
if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 )
{
if ( rogue_registeropretdecode(gametxid,tokenid,playertxid,tx.vout[numvouts-1].scriptPubKey) == 'R' )
{
if ( rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid) == 0 )
{
if ( CCgettxout(txid,vout,1) < 0 )
b.push_back(gametxid.GetHex());
else a.push_back(gametxid.GetHex());
}
}
}
}
}
result.push_back(Pair("pastgames",b));
result.push_back(Pair("games",a));
result.push_back(Pair("numgames",(int64_t)(a.size()+b.size())));
return(result);
}
UniValue rogue_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
{
UniValue result(UniValue::VOBJ); int32_t n; char *namestr = 0;
rogue_univalue(result,"setname",-1,-1);
if ( (params= cclib_reparse(&n,params)) != 0 )
{
if ( n > 0 )
{
if ( (namestr= jstri(params,0)) != 0 )
{
result.push_back(Pair("result","success"));
result.push_back(Pair("pname",namestr));
Rogue_pname = namestr;
return(result);
}
}
}
result.push_back(Pair("result","error"));
result.push_back(Pair("error","couldnt get name"));
return(result);
}

View File

@@ -499,6 +499,7 @@ static const CRPCCommand vRPCCommands[] =
{ "tokens", "tokeninfo", &tokeninfo, true },
{ "tokens", "tokenlist", &tokenlist, true },
{ "tokens", "tokenorders", &tokenorders, true },
{ "tokens", "mytokenorders", &mytokenorders, true },
{ "tokens", "tokenaddress", &tokenaddress, true },
{ "tokens", "tokenbalance", &tokenbalance, true },
{ "tokens", "tokencreate", &tokencreate, true },

View File

@@ -241,6 +241,7 @@ extern UniValue coinsupply(const UniValue& params, bool fHelp);
extern UniValue tokeninfo(const UniValue& params, bool fHelp);
extern UniValue tokenlist(const UniValue& params, bool fHelp);
extern UniValue tokenorders(const UniValue& params, bool fHelp);
extern UniValue mytokenorders(const UniValue& params, bool fHelp);
extern UniValue tokenbalance(const UniValue& params, bool fHelp);
extern UniValue assetsaddress(const UniValue& params, bool fHelp);
extern UniValue tokenaddress(const UniValue& params, bool fHelp);

View File

@@ -7038,8 +7038,8 @@ UniValue tokenorders(const UniValue& params, bool fHelp)
{
uint256 tokenid;
if ( fHelp || params.size() > 1 )
throw runtime_error("tokenorders [tokenid]\n");
if ( ensure_CCrequirements(EVAL_ASSETS) < 0 )
throw runtime_error("tokenorders tokenid\n");
if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0)
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -7048,9 +7048,29 @@ UniValue tokenorders(const UniValue& params, bool fHelp)
if (tokenid == zeroid)
throw runtime_error("incorrect tokenid\n");
}
else
memset(&tokenid,0,sizeof(tokenid));
return(AssetOrders(tokenid));
else {
// memset(&tokenid, 0, sizeof(tokenid));
throw runtime_error("no tokenid\n");
}
return AssetOrders(tokenid, CPubKey(), 0);
}
UniValue mytokenorders(const UniValue& params, bool fHelp)
{
uint256 tokenid;
if (fHelp || params.size() > 2)
throw runtime_error("mytokenorders [evalcode]\n");
if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0)
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
uint8_t additionalEvalCode = 0;
if (params.size() == 1)
additionalEvalCode = strtol(params[0].get_str().c_str(), NULL, 0); // supports also 0xEE-like values
return AssetOrders(zeroid, Mypubkey(), additionalEvalCode);
}
UniValue tokenbalance(const UniValue& params, bool fHelp)
@@ -7235,7 +7255,7 @@ UniValue tokenbid(const UniValue& params, bool fHelp)
UniValue result(UniValue::VOBJ); int64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid;
if ( fHelp || params.size() != 3 )
throw runtime_error("tokenbid numtokens tokenid price\n");
if ( ensure_CCrequirements(EVAL_ASSETS) < 0 )
if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0)
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -7277,7 +7297,7 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp)
UniValue result(UniValue::VOBJ); std::string hex; int32_t i; uint256 tokenid,bidtxid;
if ( fHelp || params.size() != 2 )
throw runtime_error("tokencancelbid tokenid bidtxid\n");
if ( ensure_CCrequirements(EVAL_ASSETS) < 0 )
if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0)
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -7302,7 +7322,7 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp)
UniValue result(UniValue::VOBJ); int64_t fillamount; std::string hex; uint256 tokenid,bidtxid;
if ( fHelp || params.size() != 3 )
throw runtime_error("tokenfillbid tokenid bidtxid fillamount\n");
if ( ensure_CCrequirements(EVAL_ASSETS) < 0 )
if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0)
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -7334,7 +7354,7 @@ UniValue tokenask(const UniValue& params, bool fHelp)
UniValue result(UniValue::VOBJ); int64_t askamount,numtokens; std::string hex; double price; uint256 tokenid;
if ( fHelp || params.size() != 3 )
throw runtime_error("tokenask numtokens tokenid price\n");
if ( ensure_CCrequirements(EVAL_ASSETS) < 0 )
if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0)
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -7396,7 +7416,7 @@ UniValue tokencancelask(const UniValue& params, bool fHelp)
UniValue result(UniValue::VOBJ); std::string hex; int32_t i; uint256 tokenid,asktxid;
if ( fHelp || params.size() != 2 )
throw runtime_error("tokencancelask tokenid asktxid\n");
if ( ensure_CCrequirements(EVAL_ASSETS) < 0 )
if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0)
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -7421,7 +7441,7 @@ UniValue tokenfillask(const UniValue& params, bool fHelp)
UniValue result(UniValue::VOBJ); int64_t fillunits; std::string hex; uint256 tokenid,asktxid;
if ( fHelp || params.size() != 3 )
throw runtime_error("tokenfillask tokenid asktxid fillunits\n");
if ( ensure_CCrequirements(EVAL_ASSETS) < 0 )
if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0)
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);