From 9c555e6168c8442e5994fdc69551e4865bf5cb46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 07:59:17 -1100 Subject: [PATCH 01/34] Colors --- src/cc/gamescc.cpp | 3 --- src/cc/rogue/cursesd.h | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index c6206b2ee..694846350 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1659,8 +1659,6 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) sprintf(packitemstr,"not yet"); } -#ifdef includgame - /***************************************************************************/ /** https://github.com/brenns10/tetris @file main.c @@ -2534,5 +2532,4 @@ int main(int argc, char **argv) return 0; } #endif -#endif diff --git a/src/cc/rogue/cursesd.h b/src/cc/rogue/cursesd.h index cb74941e5..fbac07855 100644 --- a/src/cc/rogue/cursesd.h +++ b/src/cc/rogue/cursesd.h @@ -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 From 02facf2da73eda9e77633fead9c7e0c4228f1177 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 08:04:50 -1100 Subject: [PATCH 02/34] Test --- src/cc/gamescc.cpp | 12 ++++++------ src/cc/rogue/cursesd.h | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 694846350..175cc3dc2 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -2379,9 +2379,9 @@ void display_score(WINDOW *w, tetris_game *tg) { wclear(w); box(w, 0, 0); - wprintw(w, "Score\n%d\n", tg->points); - wprintw(w, "Level\n%d\n", tg->level); - wprintw(w, "Lines\n%d\n", tg->lines_remaining); + wprintw(w, (char *)"Score\n%d\n", tg->points); + wprintw(w, (char *)"Level\n%d\n", tg->level); + wprintw(w, (char *)"Lines\n%d\n", tg->lines_remaining); wnoutrefresh(w); } @@ -2395,7 +2395,7 @@ void save(tetris_game *game, WINDOW *w) wclear(w); box(w, 0, 0); // return the border wmove(w, 1, 1); - wprintw(w, "Save and exit? [Y/n] "); + wprintw(w, (char *)"Save and exit? [Y/n] "); wrefresh(w); timeout(-1); if (getch() == 'n') { @@ -2407,8 +2407,8 @@ void save(tetris_game *game, WINDOW *w) fclose(f); tg_delete(game); endwin(); - printf("Game saved to \"tetris.save\".\n"); - printf("Resume by passing the filename as an argument to this program.\n"); + fprintf(stderr,"Game saved to \"tetris.save\".\n"); + fprintf(stderr,"Resume by passing the filename as an argument to this program.\n"); exit(EXIT_SUCCESS); } diff --git a/src/cc/rogue/cursesd.h b/src/cc/rogue/cursesd.h index fbac07855..0ae992427 100644 --- a/src/cc/rogue/cursesd.h +++ b/src/cc/rogue/cursesd.h @@ -168,6 +168,12 @@ char *unctrl(char c); #define leaveok(win,bf) 0 #define halfdelay(x) 0 #define nocbreak() 0 +#define init_color(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 #ifndef TRUE #define TRUE 1 From a06129b526ff501c30bfed43625a325938e2107c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 08:07:18 -1100 Subject: [PATCH 03/34] init_pair --- src/cc/rogue/cursesd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/cursesd.h b/src/cc/rogue/cursesd.h index 0ae992427..cdad704ed 100644 --- a/src/cc/rogue/cursesd.h +++ b/src/cc/rogue/cursesd.h @@ -168,7 +168,7 @@ char *unctrl(char c); #define leaveok(win,bf) 0 #define halfdelay(x) 0 #define nocbreak() 0 -#define init_color(a,b,c) 0 +#define init_pair(a,b,c) 0 #define start_color() 0 #define box(a,b,c) 0 #define A_REVERSE 0 From b91cd4346bca52fcd668c3748f535785b8a3ba25 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 08:50:49 -1100 Subject: [PATCH 04/34] Standalone --- src/cc/gamescc.cpp | 995 ++++++++++++++++++++++++++++++++++++++++- src/cc/rogue/cursesd.h | 3 + 2 files changed, 996 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 175cc3dc2..59adfae1d 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1659,6 +1659,997 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) sprintf(packitemstr,"not yet"); } +#ifdef STANDALONE + +#include +#include +#include +#include +#include +#include +#include +#include + +char USERPASS[8192]; uint16_t GAMES_PORT; +extern char Gametxidstr[67]; + +#define SMALLVAL 0.000000000000001 +#define SATOSHIDEN ((uint64_t)100000000L) +#define dstr(x) ((double)(x) / SATOSHIDEN) +#define KOMODO_ASSETCHAIN_MAXLEN 65 +char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],IPADDRESS[100]; + +#ifndef _BITS256 +#define _BITS256 +union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; +typedef union _bits256 bits256; +#endif + +#ifdef _WIN32 +#ifdef _MSC_VER +int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + time = ((uint64_t)file_time.dwLowDateTime); + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long)((time - EPOCH) / 10000000L); + tp->tv_usec = (long)(system_time.wMilliseconds * 1000); + return 0; +} +#endif // _MSC_VER +#endif + + + +double OS_milliseconds() +{ + struct timeval tv; double millis; +#ifdef __MINGW32__ + mingw_gettimeofday(&tv,NULL); +#else + gettimeofday(&tv,NULL); +#endif + millis = ((double)tv.tv_sec * 1000. + (double)tv.tv_usec / 1000.); + //printf("tv_sec.%ld usec.%d %f\n",tv.tv_sec,tv.tv_usec,millis); + return(millis); +} + +int32_t _unhex(char c) +{ + if ( c >= '0' && c <= '9' ) + return(c - '0'); + else if ( c >= 'a' && c <= 'f' ) + return(c - 'a' + 10); + else if ( c >= 'A' && c <= 'F' ) + return(c - 'A' + 10); + return(-1); +} + +int32_t is_hexstr(char *str,int32_t n) +{ + int32_t i; + if ( str == 0 || str[0] == 0 ) + return(0); + for (i=0; str[i]!=0; i++) + { + if ( n > 0 && i >= n ) + break; + if ( _unhex(str[i]) < 0 ) + break; + } + if ( n == 0 ) + return(i); + return(i == n); +} + +int32_t unhex(char c) +{ + int32_t hex; + if ( (hex= _unhex(c)) < 0 ) + { + //printf("unhex: illegal hexchar.(%c)\n",c); + } + return(hex); +} + +unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); } + +int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex) +{ + int32_t adjust,i = 0; + //printf("decode.(%s)\n",hex); + if ( is_hexstr(hex,n) <= 0 ) + { + memset(bytes,0,n); + return(n); + } + if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) + hex[--n] = 0; + if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) ) + { + if ( n > 0 ) + { + bytes[0] = unhex(hex[0]); + printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex)); + } + bytes++; + hex++; + adjust = 1; + } else adjust = 0; + if ( n > 0 ) + { + for (i=0; i>4) & 0xf); + hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); + //printf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]); + } + hexbytes[len*2] = 0; + //printf("len.%ld\n",len*2+1); + return((int32_t)len*2+1); +} + +char *bits256_str(char hexstr[65],bits256 x) +{ + init_hexbytes_noT(hexstr,x.bytes,sizeof(x)); + return(hexstr); +} + +long _stripwhite(char *buf,int accept) +{ + int32_t i,j,c; + if ( buf == 0 || buf[0] == 0 ) + return(0); + for (i=j=0; buf[i]!=0; i++) + { + buf[j] = c = buf[i]; + if ( c == accept || (c != ' ' && c != '\n' && c != '\r' && c != '\t' && c != '\b') ) + j++; + } + buf[j] = 0; + return(j); +} + +char *clonestr(char *str) +{ + char *clone; + if ( str == 0 || str[0] == 0 ) + { + printf("warning cloning nullstr.%p\n",str); +#ifdef __APPLE__ + while ( 1 ) sleep(1); +#endif + str = (char *)""; + } + clone = (char *)malloc(strlen(str)+16); + strcpy(clone,str); + return(clone); +} + +char *parse_conf_line(char *line,char *field) +{ + line += strlen(field); + for (; *line!='='&&*line!=0; line++) + break; + if ( *line == 0 ) + return(0); + if ( *line == '=' ) + line++; + while ( line[strlen(line)-1] == '\r' || line[strlen(line)-1] == '\n' || line[strlen(line)-1] == ' ' ) + line[strlen(line)-1] = 0; + //printf("LINE.(%s)\n",line); + _stripwhite(line,0); + return(clonestr(line)); +} + +int32_t safecopy(char *dest,char *src,long len) +{ + int32_t i = -1; + if ( src != 0 && dest != 0 && src != dest ) + { + if ( dest != 0 ) + memset(dest,0,len); + for (i=0; i buflen ) + { + *allocsizep = filesize; + *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep+64); + } + rewind(fp); + if ( buf == 0 ) + printf("Null buf ???\n"); + else + { + if ( fread(buf,1,(long)filesize,fp) != (unsigned long)filesize ) + printf("error reading filesize.%ld\n",(long)filesize); + buf[filesize] = 0; + } + fclose(fp); + *lenp = filesize; + //printf("loaded.(%s)\n",buf); + } //else printf("OS_loadfile couldnt load.(%s)\n",fname); + return(buf); +} + +uint8_t *OS_fileptr(long *allocsizep,char *fname) +{ + long filesize = 0; uint8_t *buf = 0; void *retptr; + *allocsizep = 0; + retptr = OS_loadfile(fname,&buf,&filesize,allocsizep); + return((uint8_t *)retptr); +} + +struct MemoryStruct { char *memory; size_t size; }; +struct return_string { char *ptr; size_t len; }; + +// return data from the server +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_SSL (1<<0) +#define CURL_GLOBAL_WIN32 (1<<1) + + +/************************************************************************ + * + * Initialize the string handler so that it is thread safe + * + ************************************************************************/ + +void init_string(struct return_string *s) +{ + s->len = 0; + s->ptr = (char *)calloc(1,s->len+1); + if ( s->ptr == NULL ) + { + fprintf(stderr,"init_string malloc() failed\n"); + exit(-1); + } + s->ptr[0] = '\0'; +} + +/************************************************************************ + * + * Use the "writer" to accumulate text until done + * + ************************************************************************/ + +size_t accumulatebytes(void *ptr,size_t size,size_t nmemb,struct return_string *s) +{ + size_t new_len = s->len + size*nmemb; + s->ptr = (char *)realloc(s->ptr,new_len+1); + if ( s->ptr == NULL ) + { + fprintf(stderr, "accumulate realloc() failed\n"); + exit(-1); + } + memcpy(s->ptr+s->len,ptr,size*nmemb); + s->ptr[new_len] = '\0'; + s->len = new_len; + return(size * nmemb); +} + +/************************************************************************ + * + * return the current system time in milliseconds + * + ************************************************************************/ + +#define EXTRACT_BITCOIND_RESULT // if defined, ensures error is null and returns the "result" field +#ifdef EXTRACT_BITCOIND_RESULT + +/************************************************************************ + * + * perform post processing of the results + * + ************************************************************************/ + +char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *params) +{ + long i,j,len; char *retstr = 0; cJSON *json,*result,*error; + //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); + if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) + { + if ( strcmp(command,"signrawtransaction") != 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); + return(rpcstr); + } + json = cJSON_Parse(rpcstr); + if ( json == 0 ) + { + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s can't parse.(%s) params.(%s)\n",debugstr,command,rpcstr,params); + free(rpcstr); + return(0); + } + result = cJSON_GetObjectItem(json,"result"); + error = cJSON_GetObjectItem(json,"error"); + if ( error != 0 && result != 0 ) + { + if ( (error->type&0xff) == cJSON_NULL && (result->type&0xff) != cJSON_NULL ) + { + retstr = cJSON_Print(result); + len = strlen(retstr); + if ( retstr[0] == '"' && retstr[len-1] == '"' ) + { + for (i=1,j=0; itype&0xff) != cJSON_NULL || (result->type&0xff) != cJSON_NULL ) + { + if ( strcmp(command,"signrawtransaction") != 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC (%s) error.%s\n",debugstr,command,rpcstr); + } + free(rpcstr); + } else retstr = rpcstr; + free_json(json); + //fprintf(stderr,"<<<<<<<<<<< bitcoind_RPC: postprocess returns.(%s)\n",retstr); + return(retstr); +} +#endif + +#ifdef _WIN32 +#ifdef _MSC_VER +#define sleep(x) Sleep(1000*(x)) +#endif +#endif + +/************************************************************************ + * + * perform the query + * + ************************************************************************/ + +char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params) +{ + static int didinit,count,count2; static double elapsedsum,elapsedsum2; + struct curl_slist *headers = NULL; struct return_string s; CURLcode res; CURL *curl_handle; + char *bracket0,*bracket1,*databuf = 0; long len; int32_t specialcase,numretries; double starttime; + if ( didinit == 0 ) + { + didinit = 1; + curl_global_init(CURL_GLOBAL_ALL); //init the curl session + } + numretries = 0; + if ( debugstr != 0 && strcmp(debugstr,"BTCD") == 0 && command != 0 && strcmp(command,"SuperNET") == 0 ) + specialcase = 1; + else specialcase = 0; + if ( url[0] == 0 ) + strcpy(url,"http://127.0.0.1:7876/nxt"); + if ( specialcase != 0 && 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: debug.(%s) url.(%s) command.(%s) params.(%s)\n",debugstr,url,command,params); +try_again: + if ( retstrp != 0 ) + *retstrp = 0; + starttime = OS_milliseconds(); + curl_handle = curl_easy_init(); + init_string(&s); + headers = curl_slist_append(0,"Expect:"); + + curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); + curl_easy_setopt(curl_handle,CURLOPT_URL, url); + curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulatebytes); // send all data to this function + curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback + curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash + curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback + if ( strncmp(url,"https",5) == 0 ) + { + curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYPEER,0); + curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYHOST,0); + } + if ( userpass != 0 ) + curl_easy_setopt(curl_handle,CURLOPT_USERPWD, userpass); + databuf = 0; + if ( params != 0 ) + { + if ( command != 0 && specialcase == 0 ) + { + len = strlen(params); + if ( len > 0 && params[0] == '[' && params[len-1] == ']' ) { + bracket0 = bracket1 = (char *)""; + } + else + { + bracket0 = (char *)"["; + bracket1 = (char *)"]"; + } + + databuf = (char *)malloc(256 + strlen(command) + strlen(params)); + sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); + //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + // + } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); + curl_easy_setopt(curl_handle,CURLOPT_POST,1L); + if ( databuf != 0 ) + curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,databuf); + else curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,params); + } + //laststart = milliseconds(); + res = curl_easy_perform(curl_handle); + curl_slist_free_all(headers); + curl_easy_cleanup(curl_handle); + if ( databuf != 0 ) // clean up temporary buffer + { + free(databuf); + databuf = 0; + } + if ( res != CURLE_OK ) + { + numretries++; + if ( specialcase != 0 ) + { + printf("<<<<<<<<<<< bitcoind_RPC.(%s): BTCD.%s timeout params.(%s) s.ptr.(%s) err.%d\n",url,command,params,s.ptr,res); + free(s.ptr); + return(0); + } + else if ( numretries >= 1 ) + { + //printf("Maximum number of retries exceeded!\n"); + free(s.ptr); + return(0); + } + if ( (rand() % 1000) == 0 ) + printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries); + free(s.ptr); + sleep((1< (%s)\n",params,s.ptr); + count2++; + elapsedsum2 += (OS_milliseconds() - starttime); + if ( (count2 % 10000) == 0) + printf("%d: ave %9.6f | elapsed %.3f millis | NXT calls.(%s) cmd.(%s)\n",count2,elapsedsum2/count2,(double)(OS_milliseconds() - starttime),url,command); + return(s.ptr); + } + } + printf("bitcoind_RPC: impossible case\n"); + free(s.ptr); + return(0); +} + +static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) +{ + size_t realsize = (size * nmemb); + struct MemoryStruct *mem = (struct MemoryStruct *)data; + mem->memory = (char *)((ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1)); + if ( mem->memory != 0 ) + { + if ( ptr != 0 ) + memcpy(&(mem->memory[mem->size]),ptr,realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + } + //printf("got %d bytes\n",(int32_t)(size*nmemb)); + return(realsize); +} + +char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3) +{ + struct MemoryStruct chunk; CURL *cHandle; long code; struct curl_slist *headers = 0; + if ( (cHandle= *cHandlep) == NULL ) + *cHandlep = cHandle = curl_easy_init(); + else curl_easy_reset(cHandle); + //#ifdef DEBUG + //curl_easy_setopt(cHandle,CURLOPT_VERBOSE, 1); + //#endif + curl_easy_setopt(cHandle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + curl_easy_setopt(cHandle,CURLOPT_SSL_VERIFYPEER,0); + //curl_easy_setopt(cHandle,CURLOPT_SSLVERSION,1); + curl_easy_setopt(cHandle,CURLOPT_URL,url); + curl_easy_setopt(cHandle,CURLOPT_CONNECTTIMEOUT,10); + if ( userpass != 0 && userpass[0] != 0 ) + curl_easy_setopt(cHandle,CURLOPT_USERPWD,userpass); + if ( postfields != 0 && postfields[0] != 0 ) + { + curl_easy_setopt(cHandle,CURLOPT_POST,1); + curl_easy_setopt(cHandle,CURLOPT_POSTFIELDS,postfields); + } + if ( hdr0 != NULL && hdr0[0] != 0 ) + { + //printf("HDR0.(%s) HDR1.(%s) HDR2.(%s) HDR3.(%s)\n",hdr0!=0?hdr0:"",hdr1!=0?hdr1:"",hdr2!=0?hdr2:"",hdr3!=0?hdr3:""); + headers = curl_slist_append(headers,hdr0); + if ( hdr1 != 0 && hdr1[0] != 0 ) + headers = curl_slist_append(headers,hdr1); + if ( hdr2 != 0 && hdr2[0] != 0 ) + headers = curl_slist_append(headers,hdr2); + if ( hdr3 != 0 && hdr3[0] != 0 ) + headers = curl_slist_append(headers,hdr3); + } //headers = curl_slist_append(0,"Expect:"); + if ( headers != 0 ) + curl_easy_setopt(cHandle,CURLOPT_HTTPHEADER,headers); + //res = curl_easy_perform(cHandle); + memset(&chunk,0,sizeof(chunk)); + curl_easy_setopt(cHandle,CURLOPT_WRITEFUNCTION,WriteMemoryCallback); + curl_easy_setopt(cHandle,CURLOPT_WRITEDATA,(void *)&chunk); + curl_easy_perform(cHandle); + curl_easy_getinfo(cHandle,CURLINFO_RESPONSE_CODE,&code); + if ( headers != 0 ) + curl_slist_free_all(headers); + if ( code != 200 ) + printf("(%s) server responded with code %ld (%s)\n",url,code,chunk.memory); + return(chunk.memory); +} + +uint16_t _komodo_userpass(char *username, char *password, FILE *fp) +{ + char *rpcuser,*rpcpassword,*str,*ipaddress,line[8192]; uint16_t port = 0; + rpcuser = rpcpassword = 0; + username[0] = password[0] = 0; + while ( fgets(line,sizeof(line),fp) != 0 ) + { + if ( line[0] == '#' ) + continue; + //printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword")); + if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) + rpcuser = parse_conf_line(str,(char *)"rpcuser"); + else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) + rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); + else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) + { + port = atoi(parse_conf_line(str,(char *)"rpcport")); + //fprintf(stderr,"rpcport.%u in file\n",port); + } + else if ( (str= strstr(line,(char *)"ipaddress")) != 0 ) + { + ipaddress = parse_conf_line(str,(char *)"ipaddress"); + strcpy(IPADDRESS,ipaddress); + } + } + if ( rpcuser != 0 && rpcpassword != 0 ) + { + strcpy(username,rpcuser); + strcpy(password,rpcpassword); + } + //printf("rpcuser.(%s) rpcpassword.(%s) %u ipaddress.%s\n",rpcuser,rpcpassword,port,ipaddress); + if ( rpcuser != 0 ) + free(rpcuser); + if ( rpcpassword != 0 ) + free(rpcpassword); + return(port); +} + +uint16_t komodo_userpass(char *userpass,char *symbol) +{ + FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[KOMODO_ASSETCHAIN_MAXLEN]; + userpass[0] = 0; + if ( strcmp("KMD",symbol) == 0 ) + { +#ifdef __APPLE__ + sprintf(confname,"Komodo.conf"); +#else + sprintf(confname,"komodo.conf"); +#endif + } + else sprintf(confname,"%s.conf",symbol); + //komodo_statefname(fname,symbol,confname); + if ( (fp= fopen(confname,"rb")) != 0 ) + { + port = _komodo_userpass(username,password,fp); + sprintf(userpass,"%s:%s",username,password); + if ( strcmp(symbol,ASSETCHAINS_SYMBOL) == 0 ) + strcpy(USERPASS,userpass); + fclose(fp); + } + return(port); +} + +#define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True) + +char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) +{ + //static void *cHandle; + char url[512],*retstr=0,*retstr2=0,postdata[8192]; + if ( params == 0 || params[0] == 0 ) + params = (char *)"[]"; + if ( strlen(params) < sizeof(postdata)-128 ) + { + sprintf(url,(char *)"http://%s:%u",IPADDRESS,port); + sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); + //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,USERPASS); + retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); + //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); + } + return(retstr2); +} + +int32_t games_sendrawtransaction(char *rawtx) +{ + char *params,*retstr,*hexstr; cJSON *retjson,*resobj; int32_t retval = -1; + params = (char *)malloc(strlen(rawtx) + 16); + sprintf(params,"[\"%s\"]",rawtx); + if ( (retstr= komodo_issuemethod(USERPASS,"sendrawtransaction",params,GAMES_PORT)) != 0 ) + { + if ( 0 ) // causes 4th level crash + { + static FILE *fp; + if ( fp == 0 ) + fp = fopen("games.sendlog","wb"); + if ( fp != 0 ) + { + fprintf(fp,"%s\n",retstr); + fflush(fp); + } + } + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,"result")) != 0 ) + { + if ( (hexstr= jstr(resobj,0)) != 0 && is_hexstr(hexstr,64) == 64 ) + retval = 0; + } + free_json(retjson); + } + + /* log sendrawtx result in file */ + + /* + FILE *debug_file; + debug_file = fopen("tx_debug.log", "a"); + fprintf(debug_file, "%s\n", retstr); + fflush(debug_file); + fclose(debug_file); + */ + + free(retstr); + } + free(params); + return(retval); +} + +int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num) +{ + char cmd[16384],hexstr[16384],params[32768],*retstr,*errstr,*rawtx,*pastkeys,*pastcmp,*keys; int32_t i,len,numpastkeys,retflag = -1; cJSON *retjson,*resobj; + if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) + { + if ( rs->keystrokeshex != 0 ) + { + if ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) + { + if ( waitflag == 0 ) + return(0); + else if ( 0 ) + { + while ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) + { + //fprintf(stderr,"pre-rebroadcast\n"); + sleep(10); + } + } + } + free(rs->keystrokeshex), rs->keystrokeshex = 0; + } + if ( 0 && (pastkeys= games_keystrokesload(&numpastkeys,seed,1)) != 0 ) + { + sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr); + if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,GAMES_PORT)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,"result")) != 0 && (keys= jstr(resobj,"keystrokes")) != 0 ) + { + len = strlen(keys) / 2; + pastcmp = (char *)malloc(len + 1); + decode_hex(pastcmp,len,keys); + fprintf(stderr,"keystrokes.(%s) vs pastkeys\n",keys); + for (i=0; i> keystrokes.log",ASSETCHAINS_SYMBOL,Gametxidstr,hexstr); + if ( system(cmd) != 0 ) + fprintf(stderr,"error issuing (%s)\n",cmd); + } + else + { + static FILE *fp; + if ( fp == 0 ) + fp = fopen("keystrokes.log","a"); + sprintf(params,"[\"keystrokes\",\"17\",\"[%%22%s%%22,%%22%s%%22]\"]",Gametxidstr,hexstr); + if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,GAMES_PORT)) != 0 ) + { + if ( fp != 0 ) + { + fprintf(fp,"%s\n",params); + fprintf(fp,"%s\n",retstr); + fflush(fp); + } + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,"result")) != 0 && (rawtx= jstr(resobj,"hex")) != 0 ) + { + if ( rs->keystrokeshex != 0 ) + free(rs->keystrokeshex); + if ( (errstr= jstr(resobj,"error")) == 0 ) + { + rs->keystrokeshex = (char *)malloc(strlen(rawtx)+1); + strcpy(rs->keystrokeshex,rawtx); + retflag = 1; + } else fprintf(stderr,"error sending keystrokes tx\n"), sleep(1); + //fprintf(stderr,"set keystrokestx <- %s\n",rs->keystrokeshex); + } + free_json(retjson); + } + free(retstr); + } + if ( 0 && waitflag != 0 && rs->keystrokeshex != 0 ) + { + while ( games_sendrawtransaction(rs->keystrokeshex) == 0 ) + { + //fprintf(stderr,"post-rebroadcast\n"); + sleep(3); + } + free(rs->keystrokeshex), rs->keystrokeshex = 0; + } + } + } + return(retflag); +} + +int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) +{ + char cmd[32768]; int32_t i,n,retval=-1; char params[1024],*filestr=0,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item,*resultjson; + if ( rs->guiflag == 0 ) + return(-1); + if ( gametxidstr == 0 || *gametxidstr == 0 ) + return(retval); + if ( 0 ) + { + sprintf(fname,"%s.gameinfo",gametxidstr); + sprintf(cmd,"./komodo-cli -ac_name=%s cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",ASSETCHAINS_SYMBOL,gametxidstr,fname); + if ( system(cmd) != 0 ) + fprintf(stderr,"error issuing (%s)\n",cmd); + else filestr = (char *)OS_fileptr(&allocsize,fname); + } + else + { + sprintf(params,"[\"gameinfo\",\"17\",\"[%%22%s%%22]\"]",gametxidstr); + filestr = komodo_issuemethod(USERPASS,"cclib",params,GAMES_PORT); + } + if ( filestr != 0 ) + { + if ( (retjson= cJSON_Parse(filestr)) != 0 && (resultjson= jobj(retjson,"result")) != 0 ) + { + //fprintf(stderr,"gameinfo.(%s)\n",jprint(resultjson,0)); + if ( (array= jarray(&n,resultjson,"players")) != 0 ) + { + for (i=0; iP,(int32_t)strlen(datastr)/2,datastr); + fprintf(stderr,"set pname[%s] %s\n",pname==0?"":pname,jprint(item,0)); + rs->restoring = 1; + } + } + } + } + } + free_json(retjson); + } + free(filestr); + } + return(retval); +} + +#ifdef _WIN32 +#ifdef _MSC_VER +__inline int msver(void) { + switch (_MSC_VER) { + case 1500: return 2008; + case 1600: return 2010; + case 1700: return 2012; + case 1800: return 2013; + case 1900: return 2015; + //case 1910: return 2017; + default: return (_MSC_VER / 100); + } +} + +static inline bool is_x64(void) { +#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) + return 1; +#elif defined(__amd64__) || defined(__amd64) || defined(_M_X64) || defined(_M_IA64) + return 1; +#else + return 0; +#endif +} + +#define BUILD_DATE __DATE__ " " __TIME__ +#endif // _WIN32 +#endif // _MSC_VER + +int main(int argc, char **argv) +{ + uint64_t seed; FILE *fp = 0; int32_t i,j,c; char userpass[8192]; + +#ifdef _WIN32 +#ifdef _MSC_VER + printf("*** games for Windows [ Build %s ] ***\n", BUILD_DATE); + const char* arch = is_x64() ? "64-bits" : "32-bits"; + printf(" Built with VC++ %d (%ld) %s\n\n", msver(), _MSC_FULL_VER, arch); +#endif +#endif + + for (i=j=0; argv[0][i]!=0&&j= 2) { @@ -2531,5 +3521,6 @@ int main(int argc, char **argv) tg_delete(tg); return 0; } + #endif diff --git a/src/cc/rogue/cursesd.h b/src/cc/rogue/cursesd.h index cdad704ed..e3eec5d41 100644 --- a/src/cc/rogue/cursesd.h +++ b/src/cc/rogue/cursesd.h @@ -168,12 +168,15 @@ char *unctrl(char c); #define leaveok(win,bf) 0 #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 From 1d57bee66d4697a550e1df72d80e03e20478201b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 08:54:27 -1100 Subject: [PATCH 05/34] Maketetris --- src/cc/gamescc.cpp | 4 +++- src/cc/maketetris | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 59adfae1d..454af601d 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -15,6 +15,8 @@ #include "gamescc.h" +#ifndef STANDALONE + /* ./c cclib rng 17 \"[%229433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775%22,250]\" { @@ -1658,8 +1660,8 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) { sprintf(packitemstr,"not yet"); } +#else -#ifdef STANDALONE #include #include diff --git a/src/cc/maketetris b/src/cc/maketetris index 9c2a005a0..b83bef611 100755 --- a/src/cc/maketetris +++ b/src/cc/maketetris @@ -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 -o tetris From 3a7ca41dab30e01631befa8ca0ff02482ca5de4f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:13:13 -1100 Subject: [PATCH 06/34] Realtime events --- src/cc/gamescc.cpp | 56 +++++++++++++++++++++++++++++----------------- src/cc/gamescc.h | 12 ++++++++++ 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 454af601d..33d6722cd 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -336,12 +336,34 @@ int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector pay } else return(-1); } +int32_t games_event(uint32_t timestamp,uint256 gametxid,int32_t eventid,std::vector payload) +{ + std::vector sig,vopret; CPubKey mypk; uint32_t x; int32_t i,len = payload.size(); + payload.resize(len + 4 + 32); + for (i=0; i<32; i++) + payload[len++] = ((uint8_t *)&gametxid)[i]; + x = eventid; + payload[len++] = x, x >>= 8; + payload[len++] = x, x >>= 8; + payload[len++] = x, x >>= 8; + payload[len++] = x; + mypk = pubkey2pk(Mypubkey()); + if ( games_eventsign(timestamp,sig,payload,mypk) == 0 ) + { + GetOpReturnData(games_eventopret(timestamp,mypk,sig,payload),vopret); + games_payloadrecv(mypk,timestamp,payload); + komodo_sendmessage(4,8,"events",vopret); + return(0); + } else return(-1); +} + UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { static uint256 lastgametxid; static uint32_t numevents; - UniValue result(UniValue::VOBJ); std::vector sig,payload,vopret; int32_t len,i,n; uint32_t x; CPubKey mypk; char str[67]; uint32_t eventid,timestamp = 0; uint256 gametxid; + UniValue result(UniValue::VOBJ); std::vector payload; int32_t len,i,n; uint32_t x; CPubKey mypk; char str[67]; uint32_t eventid,timestamp = 0; uint256 gametxid; if ( params != 0 && (n= cJSON_GetArraySize(params)) >= 1 && n <= 3 ) { + mypk = pubkey2pk(Mypubkey()); if ( payments_parsehexdata(payload,jitem(params,0),0) == 0 ) { if ( n >= 2 ) @@ -359,21 +381,8 @@ UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( numevents <= eventid ) numevents = eventid+1; } else eventid = numevents++; - len = payload.size(); - payload.resize(len + 4 + 32); - for (i=0; i<32; i++) - payload[len++] = ((uint8_t *)&gametxid)[i]; - x = eventid; - payload[len++] = x, x >>= 8; - payload[len++] = x, x >>= 8; - payload[len++] = x, x >>= 8; - payload[len++] = x; - mypk = pubkey2pk(Mypubkey()); - if ( games_eventsign(timestamp,sig,payload,mypk) == 0 ) + if ( games_event(timestamp,gametxid,eventid,payload) == 0 ) { - GetOpReturnData(games_eventopret(timestamp,mypk,sig,payload),vopret); - games_payloadrecv(mypk,timestamp,payload); - komodo_sendmessage(4,8,"events",vopret); result.push_back(Pair("gametxid",gametxid.GetHex())); result.push_back(Pair("eventid",(int64_t)eventid)); result.push_back(Pair("timestamp",(int64_t)timestamp)); @@ -2587,7 +2596,7 @@ static inline bool is_x64(void) { int main(int argc, char **argv) { uint64_t seed; FILE *fp = 0; int32_t i,j,c; char userpass[8192]; - + strcpy(ASSETCHAINS_SYMBOL,"GTEST"); #ifdef _WIN32 #ifdef _MSC_VER printf("*** games for Windows [ Build %s ] ***\n", BUILD_DATE); @@ -2610,8 +2619,8 @@ int main(int argc, char **argv) #ifdef _WIN32 #ifdef _MSC_VER - if (strncmp(ASSETCHAINS_SYMBOL, "TETRIS.EXE", sizeof(ASSETCHAINS_SYMBOL)) == 0 || strncmp(ASSETCHAINS_SYMBOL, "TETRIS54.EXE", sizeof(ASSETCHAINS_SYMBOL)) == 0) { - strcpy(ASSETCHAINS_SYMBOL, "TETRIS"); // accept TETRIS.conf, instead of TETRIS.EXE.conf or TETRIS54.EXE.conf if build with MSVC + if (strncmp(ASSETCHAINS_SYMBOL, "GTEST.EXE", sizeof(ASSETCHAINS_SYMBOL)) == 0 || strncmp(ASSETCHAINS_SYMBOL, "GTEST54.EXE", sizeof(ASSETCHAINS_SYMBOL)) == 0) { + strcpy(ASSETCHAINS_SYMBOL, "GTEST"); // accept TETRIS.conf, instead of TETRIS.EXE.conf or TETRIS54.EXE.conf if build with MSVC } #endif #endif @@ -3432,7 +3441,7 @@ int tetris(int argc, char **argv) tetris_move move = TM_NONE; bool running = true; WINDOW *board, *next, *hold, *score; - + int32_t c; uint256 gametxid; std::vector payload; uint32_t eventid = 0; // Load file if given a filename. if (argc >= 2) { FILE *f = fopen(argv[1], "r"); @@ -3462,6 +3471,7 @@ int tetris(int argc, char **argv) score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1); int32_t counter = 0; // Game loop + payload.resize(1); while (running) { running = tg_tick(tg, move); display_board(board, tg); @@ -3471,8 +3481,12 @@ int tetris(int argc, char **argv) if ( (counter++ % 5) == 0 ) doupdate(); sleep_milli(10); - - switch (getch()) { + c = getch(); + payload[0] = c; + games_event(0,gametxid,eventid,payload); + eventid++; + switch ( c ) + { case KEY_LEFT: move = TM_LEFT; break; diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 8a6a3b656..9a48a14a4 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -96,6 +96,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); From dfd756b938f96f3153d39099010bfd674fcd9a4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:23:42 -1100 Subject: [PATCH 07/34] issue_games_events --- src/cc/gamescc.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 33d6722cd..c73b0e46f 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -2360,6 +2360,32 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) return(retstr2); } +int32_t issue_games_events(uint256 gametxid,uint32_t eventid,char c) +{ + char params[512],*retstr; cJSON *retjson,*retobj; int32_t retval = -1; + sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,gametxid.GetHex().c_str(),eventid); + if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,GAMES_PORT)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (resobj= jobj(retjson,"result")) != 0 ) + { + retval = 0; + if ( fp == 0 ) + fp = fopen("events.log","wb"); + if ( fp != 0 ) + { + fprintf(fp,"%s\n",jprint(resobj,0)); + fflush(fp); + } + } + free_json(retjson); + } + free(retstr); + } + return(retval); +} + int32_t games_sendrawtransaction(char *rawtx) { char *params,*retstr,*hexstr; cJSON *retjson,*resobj; int32_t retval = -1; @@ -3483,7 +3509,7 @@ int tetris(int argc, char **argv) sleep_milli(10); c = getch(); payload[0] = c; - games_event(0,gametxid,eventid,payload); + issue_games_events(0,gametxid,eventid,payload); eventid++; switch ( c ) { From 3ee77bc360950fe63170783c3d59403b108692f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:26:42 -1100 Subject: [PATCH 08/34] Test --- src/cc/gamescc.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index c73b0e46f..6ea6981c1 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -2362,7 +2362,10 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) int32_t issue_games_events(uint256 gametxid,uint32_t eventid,char c) { + static FILE *fp; char params[512],*retstr; cJSON *retjson,*retobj; int32_t retval = -1; + if ( fp == 0 ) + fp = fopen("events.log","wb"); sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,gametxid.GetHex().c_str(),eventid); if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,GAMES_PORT)) != 0 ) { @@ -2371,8 +2374,6 @@ int32_t issue_games_events(uint256 gametxid,uint32_t eventid,char c) if ( (resobj= jobj(retjson,"result")) != 0 ) { retval = 0; - if ( fp == 0 ) - fp = fopen("events.log","wb"); if ( fp != 0 ) { fprintf(fp,"%s\n",jprint(resobj,0)); @@ -2380,9 +2381,9 @@ int32_t issue_games_events(uint256 gametxid,uint32_t eventid,char c) } } free_json(retjson); - } + } else fprintf(fp,"error parsing %s\n",jprint(retstr)); free(retstr); - } + } else fprintf(fp,"error issuing method %s\n",params); return(retval); } From 11b4733cb7e2c06e86764022cc730d76da1c4192 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:38:26 -1100 Subject: [PATCH 09/34] (char *) --- src/cc/gamescc.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 6ea6981c1..826012f43 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -2363,15 +2363,15 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) int32_t issue_games_events(uint256 gametxid,uint32_t eventid,char c) { static FILE *fp; - char params[512],*retstr; cJSON *retjson,*retobj; int32_t retval = -1; + char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; if ( fp == 0 ) fp = fopen("events.log","wb"); sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,gametxid.GetHex().c_str(),eventid); - if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,GAMES_PORT)) != 0 ) + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( (resobj= jobj(retjson,"result")) != 0 ) + if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) { retval = 0; if ( fp != 0 ) @@ -2381,7 +2381,7 @@ int32_t issue_games_events(uint256 gametxid,uint32_t eventid,char c) } } free_json(retjson); - } else fprintf(fp,"error parsing %s\n",jprint(retstr)); + } else fprintf(fp,"error parsing %s\n",retstr); free(retstr); } else fprintf(fp,"error issuing method %s\n",params); return(retval); @@ -2392,7 +2392,7 @@ int32_t games_sendrawtransaction(char *rawtx) char *params,*retstr,*hexstr; cJSON *retjson,*resobj; int32_t retval = -1; params = (char *)malloc(strlen(rawtx) + 16); sprintf(params,"[\"%s\"]",rawtx); - if ( (retstr= komodo_issuemethod(USERPASS,"sendrawtransaction",params,GAMES_PORT)) != 0 ) + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"sendrawtransaction",params,GAMES_PORT)) != 0 ) { if ( 0 ) // causes 4th level crash { @@ -2407,7 +2407,7 @@ int32_t games_sendrawtransaction(char *rawtx) } if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( (resobj= jobj(retjson,"result")) != 0 ) + if ( (resobj= jobj(retjson,(char *)"result")) != 0 ) { if ( (hexstr= jstr(resobj,0)) != 0 && is_hexstr(hexstr,64) == 64 ) retval = 0; @@ -2460,7 +2460,7 @@ int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,cha { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( (resobj= jobj(retjson,"result")) != 0 && (keys= jstr(resobj,"keystrokes")) != 0 ) + if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (keys= jstr(resobj,(char *)"keystrokes")) != 0 ) { len = strlen(keys) / 2; pastcmp = (char *)malloc(len + 1); @@ -2508,11 +2508,11 @@ int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,cha } if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( (resobj= jobj(retjson,"result")) != 0 && (rawtx= jstr(resobj,"hex")) != 0 ) + if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (rawtx= jstr(resobj,(char *)"hex")) != 0 ) { if ( rs->keystrokeshex != 0 ) free(rs->keystrokeshex); - if ( (errstr= jstr(resobj,"error")) == 0 ) + if ( (errstr= jstr(resobj,(char *)"error")) == 0 ) { rs->keystrokeshex = (char *)malloc(strlen(rawtx)+1); strcpy(rs->keystrokeshex,rawtx); @@ -2556,26 +2556,26 @@ int32_t games_setplayerdata(struct games_state *rs,char *gametxidstr) else { sprintf(params,"[\"gameinfo\",\"17\",\"[%%22%s%%22]\"]",gametxidstr); - filestr = komodo_issuemethod(USERPASS,"cclib",params,GAMES_PORT); + filestr = komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT); } if ( filestr != 0 ) { - if ( (retjson= cJSON_Parse(filestr)) != 0 && (resultjson= jobj(retjson,"result")) != 0 ) + if ( (retjson= cJSON_Parse(filestr)) != 0 && (resultjson= jobj(retjson,(char *)"result")) != 0 ) { //fprintf(stderr,"gameinfo.(%s)\n",jprint(resultjson,0)); - if ( (array= jarray(&n,resultjson,"players")) != 0 ) + if ( (array= jarray(&n,resultjson,(char *)"players")) != 0 ) { for (i=0; iP,(int32_t)strlen(datastr)/2,datastr); fprintf(stderr,"set pname[%s] %s\n",pname==0?"":pname,jprint(item,0)); From 5f2317bd8e368933c94665ebff2dac682a6ff8eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:42:42 -1100 Subject: [PATCH 10/34] fixes --- src/cc/gamescc.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 826012f43..5217d5fa1 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1684,6 +1684,9 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) char USERPASS[8192]; uint16_t GAMES_PORT; extern char Gametxidstr[67]; +#define MAX_STR 1024 +char whoami[MAXSTR]; + #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) @@ -2433,7 +2436,7 @@ int32_t games_sendrawtransaction(char *rawtx) int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num) { - char cmd[16384],hexstr[16384],params[32768],*retstr,*errstr,*rawtx,*pastkeys,*pastcmp,*keys; int32_t i,len,numpastkeys,retflag = -1; cJSON *retjson,*resobj; + char cmd[16384],hexstr[16384],params[32768],*retstr,*errstr,*rawtx,*pastkeys,*keys; int32_t i,len,numpastkeys,retflag = -1; cJSON *retjson,*resobj; uint8_t *pastcmp; if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) { if ( rs->keystrokeshex != 0 ) @@ -2456,7 +2459,7 @@ int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,cha if ( 0 && (pastkeys= games_keystrokesload(&numpastkeys,seed,1)) != 0 ) { sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr); - if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,GAMES_PORT)) != 0 ) + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { @@ -2498,7 +2501,7 @@ int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,cha if ( fp == 0 ) fp = fopen("keystrokes.log","a"); sprintf(params,"[\"keystrokes\",\"17\",\"[%%22%s%%22,%%22%s%%22]\"]",Gametxidstr,hexstr); - if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,GAMES_PORT)) != 0 ) + if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) { if ( fp != 0 ) { @@ -3510,7 +3513,7 @@ int tetris(int argc, char **argv) sleep_milli(10); c = getch(); payload[0] = c; - issue_games_events(0,gametxid,eventid,payload); + issue_games_events(gametxid,eventid,payload); eventid++; switch ( c ) { From 89f6370c5e66aea81ec14fb7e55c64e0e02c9af0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:44:58 -1100 Subject: [PATCH 11/34] Test --- src/cc/gamescc.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 5217d5fa1..2f68fdfd8 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -13,10 +13,11 @@ * * ******************************************************************************/ -#include "gamescc.h" #ifndef STANDALONE +#include "gamescc.h" + /* ./c cclib rng 17 \"[%229433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775%22,250]\" { @@ -1684,7 +1685,7 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) char USERPASS[8192]; uint16_t GAMES_PORT; extern char Gametxidstr[67]; -#define MAX_STR 1024 +#define MAXSTR 1024 char whoami[MAXSTR]; #define SMALLVAL 0.000000000000001 @@ -2466,7 +2467,7 @@ int32_t games_progress(struct games_state *rs,int32_t waitflag,uint64_t seed,cha if ( (resobj= jobj(retjson,(char *)"result")) != 0 && (keys= jstr(resobj,(char *)"keystrokes")) != 0 ) { len = strlen(keys) / 2; - pastcmp = (char *)malloc(len + 1); + pastcmp = (uint8_t *)malloc(len + 1); decode_hex(pastcmp,len,keys); fprintf(stderr,"keystrokes.(%s) vs pastkeys\n",keys); for (i=0; i Date: Mon, 25 Mar 2019 09:47:58 -1100 Subject: [PATCH 12/34] #include "../core_io.h" #include "../script/sign.h" #include "../wallet/wallet.h" #include --- src/cc/gamescc.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 2f68fdfd8..de08b8992 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1681,6 +1681,9 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) #include #include #include +#include "../core_io.h" +#include "../wallet/wallet.h" +#include char USERPASS[8192]; uint16_t GAMES_PORT; extern char Gametxidstr[67]; From 43b96f15b9ed811c94433b246dde54e0f2526d66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:52:12 -1100 Subject: [PATCH 13/34] Ifdef --- src/cc/gamescc.cpp | 3 ++- src/cc/gamescc.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index de08b8992..0721e88fe 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -13,10 +13,11 @@ * * ******************************************************************************/ +#include "gamescc.h" + #ifndef STANDALONE -#include "gamescc.h" /* ./c cclib rng 17 \"[%229433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775%22,250]\" diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 9a48a14a4..b6b53e82e 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -1,6 +1,8 @@ #ifndef H_GAMESCC_H #define H_GAMESCC_H +#ifndef STANDALONE + #define ENABLE_WALLET extern CWallet* pwalletMain; @@ -82,6 +84,7 @@ if ( cp->evalcode == EVAL_GAMES ) \ return(result); \ } \ } +#endif #define MAXPACK 23 struct games_packitem From d4d7d1adfdb6ab8cfab9f2e6a8129ff6fd9893f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:53:19 -1100 Subject: [PATCH 14/34] Stdio --- src/cc/gamescc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index b6b53e82e..034fee044 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -1,6 +1,9 @@ #ifndef H_GAMESCC_H #define H_GAMESCC_H +#include +#include + #ifndef STANDALONE #define ENABLE_WALLET From e774c89ab5c37ec3329dcc359cb6d1bc2a8cfd6f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:55:11 -1100 Subject: [PATCH 15/34] -stdlib --- src/cc/gamescc.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 0721e88fe..57ff21131 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1676,7 +1676,6 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) #include #include -#include #include #include #include From e7031c29640864a0e8d109bb3a3c1593c09b25d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:58:21 -1100 Subject: [PATCH 16/34] Test --- src/cc/gamescc.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 57ff21131..ffb92bc0d 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1679,12 +1679,15 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) #include #include #include -#include -#include #include "../core_io.h" #include "../wallet/wallet.h" #include +#define inline +#include +#include +#undef inline + char USERPASS[8192]; uint16_t GAMES_PORT; extern char Gametxidstr[67]; @@ -3475,7 +3478,7 @@ int tetris(int argc, char **argv) tetris_move move = TM_NONE; bool running = true; WINDOW *board, *next, *hold, *score; - int32_t c; uint256 gametxid; std::vector payload; uint32_t eventid = 0; + int32_t c; uint256 gametxid; uint32_t eventid = 0; // Load file if given a filename. if (argc >= 2) { FILE *f = fopen(argv[1], "r"); @@ -3516,8 +3519,7 @@ int tetris(int argc, char **argv) doupdate(); sleep_milli(10); c = getch(); - payload[0] = c; - issue_games_events(gametxid,eventid,payload); + issue_games_events(gametxid,eventid,c); eventid++; switch ( c ) { From 23cd6f2cbef1aab8af7b2606358085dddfbecb4f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 09:58:56 -1100 Subject: [PATCH 17/34] Mv --- src/cc/gamescc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index ffb92bc0d..cc78ee5fe 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1679,13 +1679,13 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) #include #include #include -#include "../core_io.h" -#include "../wallet/wallet.h" -#include #define inline #include #include +#include "../core_io.h" +#include "../wallet/wallet.h" +#include #undef inline char USERPASS[8192]; uint16_t GAMES_PORT; From 901bc3fc952d0a3311a275fcabda8413372c5814 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:00:52 -1100 Subject: [PATCH 18/34] Test --- src/cc/gamescc.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index cc78ee5fe..9ec9f3cb0 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1679,14 +1679,8 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) #include #include #include - -#define inline #include #include -#include "../core_io.h" -#include "../wallet/wallet.h" -#include -#undef inline char USERPASS[8192]; uint16_t GAMES_PORT; extern char Gametxidstr[67]; From 6bce1c76135f585f3b9bf8e9b6443d411a960e61 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:03:02 -1100 Subject: [PATCH 19/34] Test --- src/cc/gamescc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 9ec9f3cb0..229e7d066 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -2364,7 +2364,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) return(retstr2); } -int32_t issue_games_events(uint256 gametxid,uint32_t eventid,char c) +int32_t issue_games_events(bits256 gametxid,uint32_t eventid,char c) { static FILE *fp; char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; @@ -3472,7 +3472,7 @@ int tetris(int argc, char **argv) tetris_move move = TM_NONE; bool running = true; WINDOW *board, *next, *hold, *score; - int32_t c; uint256 gametxid; uint32_t eventid = 0; + int32_t c; bits256 gametxid; uint32_t eventid = 0; // Load file if given a filename. if (argc >= 2) { FILE *f = fopen(argv[1], "r"); From 28f2d009b96e387c49f90e81c5ba98213e655c21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:06:05 -1100 Subject: [PATCH 20/34] Void *malloc --- src/cc/gamescc.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 229e7d066..1c5818568 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1682,6 +1682,8 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) #include #include +void *malloc(size_t size); + char USERPASS[8192]; uint16_t GAMES_PORT; extern char Gametxidstr[67]; @@ -2367,10 +2369,10 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) int32_t issue_games_events(bits256 gametxid,uint32_t eventid,char c) { static FILE *fp; - char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1; + char params[512],*retstr,str[65]; cJSON *retjson,*resobj; int32_t retval = -1; if ( fp == 0 ) fp = fopen("events.log","wb"); - sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,gametxid.GetHex().c_str(),eventid); + sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,bits256_str(str,gametxid),eventid); if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) @@ -3502,7 +3504,6 @@ int tetris(int argc, char **argv) score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1); int32_t counter = 0; // Game loop - payload.resize(1); while (running) { running = tg_tick(tg, move); display_board(board, tg); From a19b854238731b7373f73ad728b7c620031774e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:09:35 -1100 Subject: [PATCH 21/34] -def --- src/cc/gamescc.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 1c5818568..81bd3f48b 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1682,8 +1682,6 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) #include #include -void *malloc(size_t size); - char USERPASS[8192]; uint16_t GAMES_PORT; extern char Gametxidstr[67]; From 09589bd0e04aa334290418317447a73715531829 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:11:31 -1100 Subject: [PATCH 22/34] Test --- src/cc/gamescc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 81bd3f48b..34d0740c4 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1861,7 +1861,7 @@ long _stripwhite(char *buf,int accept) char *clonestr(char *str) { - char *clone; + char *clone; int32_t len; if ( str == 0 || str[0] == 0 ) { printf("warning cloning nullstr.%p\n",str); @@ -1870,7 +1870,8 @@ char *clonestr(char *str) #endif str = (char *)""; } - clone = (char *)malloc(strlen(str)+16); + len = strlen(str); + clone = (char *)malloc(len+16); strcpy(clone,str); return(clone); } From ce31112c570f45661be5a1586baf434844aad59b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:12:09 -1100 Subject: [PATCH 23/34] Calloc --- src/cc/gamescc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 34d0740c4..4d461ee08 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1871,7 +1871,7 @@ char *clonestr(char *str) str = (char *)""; } len = strlen(str); - clone = (char *)malloc(len+16); + clone = (char *)calloc(1,len+16); strcpy(clone,str); return(clone); } From f83da7830241f3c22878b8a279be2fa1971f6ea9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:14:14 -1100 Subject: [PATCH 24/34] char *clonestr(char *str) --- src/cc/gamescc.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 4d461ee08..cd87e9995 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1684,6 +1684,7 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) char USERPASS[8192]; uint16_t GAMES_PORT; extern char Gametxidstr[67]; +char *clonestr(char *str); #define MAXSTR 1024 char whoami[MAXSTR]; @@ -1859,23 +1860,6 @@ long _stripwhite(char *buf,int accept) return(j); } -char *clonestr(char *str) -{ - char *clone; int32_t len; - if ( str == 0 || str[0] == 0 ) - { - printf("warning cloning nullstr.%p\n",str); -#ifdef __APPLE__ - while ( 1 ) sleep(1); -#endif - str = (char *)""; - } - len = strlen(str); - clone = (char *)calloc(1,len+16); - strcpy(clone,str); - return(clone); -} - char *parse_conf_line(char *line,char *field) { line += strlen(field); @@ -2722,6 +2706,22 @@ int main(int argc, char **argv) #include #endif +char *clonestr(char *str) +{ + char *clone; int32_t len; + if ( str == 0 || str[0] == 0 ) + { + printf("warning cloning nullstr.%p\n",str); +#ifdef __APPLE__ + while ( 1 ) sleep(1); +#endif + str = (char *)""; + } + len = strlen(str); + clone = (char *)calloc(1,len+16); + strcpy(clone,str); + return(clone); +} /* Convert a tetromino type to its corresponding cell. From 8665d036e6abc1718c145ee02a7508b06193d0ab Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:15:27 -1100 Subject: [PATCH 25/34] char *clonestr(char *str) --- src/cc/gamescc.cpp | 2 +- src/cc/maketetris | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index cd87e9995..fa36e8537 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1683,7 +1683,7 @@ void games_packitemstr(char *packitemstr,struct games_packitem *item) #include char USERPASS[8192]; uint16_t GAMES_PORT; -extern char Gametxidstr[67]; +char Gametxidstr[67]; char *clonestr(char *str); #define MAXSTR 1024 diff --git a/src/cc/maketetris b/src/cc/maketetris index b83bef611..9f0af354e 100755 --- a/src/cc/maketetris +++ b/src/cc/maketetris @@ -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 gamescc.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 From be9c3500ac7c7d8170c908580f8bf97c12f2faff Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:17:38 -1100 Subject: [PATCH 26/34] Games replay --- src/cc/gamescc.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index fa36e8537..9fb135dfe 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -3568,5 +3568,10 @@ int tetris(int argc, char **argv) return 0; } +int32_t games_replay(uint64_t seed,int32_t sleeptime) +{ + return(-1); +} + #endif From 361c928fc835fa1bfca5124ca28f946f40092fc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:20:53 -1100 Subject: [PATCH 27/34] Move clonestr --- src/cc/gamescc.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 9fb135dfe..ca9419d83 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -2706,23 +2706,6 @@ int main(int argc, char **argv) #include #endif -char *clonestr(char *str) -{ - char *clone; int32_t len; - if ( str == 0 || str[0] == 0 ) - { - printf("warning cloning nullstr.%p\n",str); -#ifdef __APPLE__ - while ( 1 ) sleep(1); -#endif - str = (char *)""; - } - len = strlen(str); - clone = (char *)calloc(1,len+16); - strcpy(clone,str); - return(clone); -} - /* Convert a tetromino type to its corresponding cell. */ @@ -3466,6 +3449,22 @@ void init_colors(void) Main tetris game! */ #ifdef STANDALONE +char *clonestr(char *str) +{ + char *clone; int32_t len; + if ( str == 0 || str[0] == 0 ) + { + printf("warning cloning nullstr.%p\n",str); +#ifdef __APPLE__ + while ( 1 ) sleep(1); +#endif + str = (char *)""; + } + len = strlen(str); + clone = (char *)calloc(1,len+16); + strcpy(clone,str); + return(clone); +} int tetris(int argc, char **argv) { From 63ebb9d604ed36af16de650e183a14ba03e35ad0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:25:44 -1100 Subject: [PATCH 28/34] strcpy(ASSETCHAINS_SYMBOL,"GTEST"); --- src/cc/gamescc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index ca9419d83..85f01ba43 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -2612,7 +2612,6 @@ static inline bool is_x64(void) { int main(int argc, char **argv) { uint64_t seed; FILE *fp = 0; int32_t i,j,c; char userpass[8192]; - strcpy(ASSETCHAINS_SYMBOL,"GTEST"); #ifdef _WIN32 #ifdef _MSC_VER printf("*** games for Windows [ Build %s ] ***\n", BUILD_DATE); @@ -2640,7 +2639,8 @@ int main(int argc, char **argv) } #endif #endif - + strcpy(ASSETCHAINS_SYMBOL,"GTEST"); + GAMES_PORT = komodo_userpass(userpass,ASSETCHAINS_SYMBOL); if ( IPADDRESS[0] == 0 ) strcpy(IPADDRESS,"127.0.0.1"); From ab954658167edf41a0233fd0ac0cc3cadde87ddd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:45:04 -1100 Subject: [PATCH 29/34] Test --- src/cc/gamescc.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 85f01ba43..c80c4e161 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -387,6 +387,7 @@ UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { result.push_back(Pair("gametxid",gametxid.GetHex())); result.push_back(Pair("eventid",(int64_t)eventid)); + result.push_back(Pair("payload",jstr(jitem(params,0),0))); result.push_back(Pair("timestamp",(int64_t)timestamp)); result.push_back(Pair("result","success")); result.push_back(Pair("pubkey33",pubkey33_str(str,(uint8_t *)&mypk))); @@ -436,9 +437,9 @@ void komodo_netevent(std::vector message) } } } - for (i=0; i= 2) { FILE *f = fopen(argv[1], "r"); From 2a4a05055748694b8b49d1d44d72610bc6233ed2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 10:49:02 -1100 Subject: [PATCH 30/34] Test --- src/cc/gamescc.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index c80c4e161..7f7b15c89 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -51,6 +51,24 @@ ./c cclib events 17 \"[%226d%22,%229433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775%22,1]\" */ +int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload) +{ + uint256 gametxid; int32_t i,len; char str[67]; uint32_t eventid = 0; + if ( (len= payload.size()) > 36 ) + { + len -= 36; + for (i=0; i<32; i++) + ((uint8_t *)&gametxid)[i] = payload[len+i]; + eventid = (uint32_t)payload[len+32]; + eventid |= (uint32_t)payload[len+33] << 8; + eventid |= (uint32_t)payload[len+34] << 16; + eventid |= (uint32_t)payload[len+35] << 24; + for (i=0; i &sig,std::vecto } else return(-1); } -int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector payload) -{ - uint256 gametxid; int32_t i,len; char str[67]; uint32_t eventid = 0; - if ( (len= payload.size()) > 36 ) - { - len -= 36; - for (i=0; i<32; i++) - ((uint8_t *)&gametxid)[i] = payload[len+i]; - eventid = (uint32_t)payload[len+32]; - eventid |= (uint32_t)payload[len+33] << 8; - eventid |= (uint32_t)payload[len+34] << 16; - eventid |= (uint32_t)payload[len+35] << 24; - for (i=0; i payload) { std::vector sig,vopret; CPubKey mypk; uint32_t x; int32_t i,len = payload.size(); @@ -3514,7 +3513,8 @@ int tetris(int argc, char **argv) doupdate(); sleep_milli(10); c = getch(); - issue_games_events(gametxid,eventid,c); + if ( c >= 0 ) + issue_games_events(gametxid,eventid,c); eventid++; switch ( c ) { From 9277db7e1e0beef080feb6f753e79724c36899d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 11:11:24 -1100 Subject: [PATCH 31/34] Skip count --- src/cc/gamescc.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 7f7b15c89..b355584db 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -3472,7 +3472,7 @@ int tetris(int argc, char **argv) tetris_move move = TM_NONE; bool running = true; WINDOW *board, *next, *hold, *score; - int32_t c; bits256 gametxid; uint32_t eventid = 0; + int32_t c,skipcount=0; bits256 gametxid; uint32_t eventid = 0; memset(&gametxid,0,sizeof(gametxid)); // Load file if given a filename. if (argc >= 2) { @@ -3514,7 +3514,12 @@ int tetris(int argc, char **argv) sleep_milli(10); c = getch(); if ( c >= 0 ) + { + if ( skipcount > 0 ) + issue_games_events(gametxid,eventid-skipcount,skipcount | 0x4000); issue_games_events(gametxid,eventid,c); + skipcount = 0; + } else skipcount++; eventid++; switch ( c ) { From 81006ce271fc91f09abe725c580ea8d1acc030f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 11:50:08 -1100 Subject: [PATCH 32/34] Match rogue roc --- src/cc/gamescc.cpp | 6 +++--- src/cc/gamescc.h | 37 ++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index b355584db..758d2fc78 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -964,7 +964,7 @@ void games_gameplayerinfo(struct CCcontract_info *cp,UniValue &obj,uint256 gamet } else fprintf(stderr,"findbaton err.%d\n",retval); } -UniValue games_create(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +UniValue games_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey gamespk,mypk; char *jsonstr; uint64_t inputsum,change,required,buyin=0; int32_t i,n,maxplayers = 1; @@ -1030,7 +1030,7 @@ UniValue games_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } -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 result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,gameheight,maxplayers,numvouts; uint256 txid; CTransaction tx; int64_t buyin; uint64_t seed; bits256 t; char myaddr[64],str[64]; CPubKey mypk,gamespk; result.push_back(Pair("name","games")); @@ -1599,7 +1599,7 @@ UniValue games_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } -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 result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); uint256 txid,hashBlock,gametxid,tokenid,playertxid; int32_t vout,maxplayers,gameheight,numvouts; CPubKey gamespk,mypk; char coinaddr[64]; CTransaction tx,gametx; int64_t buyin; std::vector > addressIndex; diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 034fee044..19e5f8d26 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -35,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); @@ -71,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")); \ From c7ac37f03a713fbbbf61cff73eda72be8127174a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 26 Mar 2019 14:23:35 +0800 Subject: [PATCH 33/34] add check for transaction fee --- src/cc/rewards.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 1351bbaeb..65e32ee27 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -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(""); } - From d08fedb7a43ac4740f8d29d7e93a2df181e17b6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 22:12:33 -1100 Subject: [PATCH 34/34] if ( komodo_nextheight() > 77777 && cashout > ROGUE_MAXCASHOUT ) --- src/cc/gamescc.cpp | 5 +++-- src/cc/rogue_rpc.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 758d2fc78..38e28a416 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -3513,11 +3513,12 @@ int tetris(int argc, char **argv) doupdate(); sleep_milli(10); c = getch(); - if ( c >= 0 ) + if ( c != -1 || skipcount == 0x3fff ) { if ( skipcount > 0 ) issue_games_events(gametxid,eventid-skipcount,skipcount | 0x4000); - issue_games_events(gametxid,eventid,c); + if ( c != -1 ) + issue_games_events(gametxid,eventid,c); skipcount = 0; } else skipcount++; eventid++; diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index fbb1a3d93..ee5f3d566 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -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 ) {