From 040d48fe1e0b83a7ad7af44b6bf4b73b62b73c66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 24 Jan 2016 22:29:50 -0300 Subject: [PATCH] test --- crypto777/curve25519.c | 2 +- iguana/pangea777.h | 4 +- iguana/pangea_api.c | 122 ++++++++++++++++++++++------------ includes/iguana_apideclares.h | 1 + 4 files changed, 85 insertions(+), 44 deletions(-) diff --git a/crypto777/curve25519.c b/crypto777/curve25519.c index dd1bdf258..e4dc45375 100755 --- a/crypto777/curve25519.c +++ b/crypto777/curve25519.c @@ -1777,7 +1777,7 @@ int32_t acct777_sigcheck(struct acct777_sig *sig) #define TEN_YEARS (10 * 365 * 24 * 3600) if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE ) { - printf("acct777_sign: invalid datalen.%d hex.%08x\n",sig->allocsize,sig->allocsize); + //printf("acct777_sign: invalid datalen.%d hex.%08x\n",sig->allocsize,sig->allocsize); return(-1); } if ( sig->timestamp < IGUANA_GENESIS || sig->timestamp > (long)IGUANA_GENESIS+TEN_YEARS ) diff --git a/iguana/pangea777.h b/iguana/pangea777.h index 74c381efa..9ad49b294 100755 --- a/iguana/pangea777.h +++ b/iguana/pangea777.h @@ -82,8 +82,8 @@ struct player_info struct game_info { bits256 tablehash,gamehash; - uint8_t M,N,numcards,ismine,numactive; - uint32_t allocsize,rakemillis,minbuyin,maxbuyin,minplayers,maxplayers,opentime,started,finished; + uint8_t M,N,numcards,ismine; + uint32_t numactive,allocsize,rakemillis,minbuyin,maxbuyin,minplayers,maxplayers,opentime,started,finished; uint64_t maxrake,hostrake,bigblind,ante,pangearake,hostipbits,creatorbits; struct player_info P[CARDS777_MAXPLAYERS]; }; diff --git a/iguana/pangea_api.c b/iguana/pangea_api.c index 083e412a6..8eb435be2 100755 --- a/iguana/pangea_api.c +++ b/iguana/pangea_api.c @@ -134,28 +134,69 @@ struct pangea_msghdr *pangea_msgcreate(struct supernet_info *myinfo,bits256 tabl void pangea_playeradd(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p,cJSON *json) { - p->playerpub = jbits256(json,"playerpub"); + if ( jobj(json,"playerpub") != 0 ) + p->playerpub = jbits256(json,"playerpub"); + else p->playerpub = GENESIS_PUBKEY; p->ipbits = calc_ipbits(jstr(json,"playeripaddr")); safecopy(p->handle,jstr(json,"handle"), sizeof(p->handle)); p->balance = 100 * SATOSHIDEN; p->nxt64bits = acct777_nxt64bits(p->playerpub); } +struct table_info *pangea_table(bits256 tablehash) +{ + struct table_info *tp; int32_t allocsize; bits256 pangeahash; char str[65]; + pangeahash = calc_categoryhashes(0,"pangea",0); + if ( (tp= category_info(pangeahash,tablehash)) == 0 ) + { + allocsize = (int32_t)(sizeof(tp->G) + sizeof(void *)*2); + if ( (tp= calloc(1,allocsize)) == 0 ) + printf("error: couldnt create table.(%s)\n",bits256_str(str,tablehash)); + } + if ( tp != 0 ) + { + category_subscribe(SuperNET_MYINFO(0),pangeahash,tablehash); + if ( category_infoset(pangeahash,tablehash,tp) == 0 ) + printf("error: couldnt set table.(%s)\n",bits256_str(str,tablehash)), tp = 0; + else tp->G.allocsize = allocsize; + } + return(tp); +} + char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct pangea_msghdr *pm,cJSON *json,char *cmdstr,char *ipaddr) { - cJSON *argjson; char *reqstr,hexstr[8192]; int32_t datalen; bits256 pangeahash; + cJSON *argjson; char *reqstr,hexstr[8192]; uint64_t nxt64bits; + struct table_info *tp; int32_t i,datalen; bits256 pangeahash; pangeahash = calc_categoryhashes(0,"pangea",0); category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY); category_subscribe(myinfo,pangeahash,tablehash); - argjson = SuperNET_argjson(json); + argjson = cJSON_CreateObject();//SuperNET_argjson(json); jaddstr(argjson,"cmd",cmdstr); if ( myinfo->ipaddr[0] == 0 || strncmp(myinfo->ipaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 ) return(clonestr("{\"error\":\"need to send your ipaddr for now\"}")); - jaddstr(argjson,"playeripaddr",myinfo->ipaddr); + jaddstr(argjson,"playeripaddr",ipaddr); jaddbits256(argjson,"categoryhash",pangeahash); jaddbits256(argjson,"subhash",tablehash); jaddbits256(argjson,"playerpub",myinfo->myaddr.persistent); jaddstr(argjson,"handle",jstr(json,"handle")); + nxt64bits = acct777_nxt64bits(myinfo->myaddr.persistent); + if ( (tp= pangea_table(tablehash)) != 0 && tp->G.numactive < tp->G.maxplayers ) + { + for (i=0; iG.numactive; i++) + if ( tp->G.P[i].nxt64bits == nxt64bits ) + break; + if ( i == tp->G.numactive ) + { + printf("self join\n"); + struct player_info *p = &tp->G.P[tp->G.numactive++]; + p->playerpub = myinfo->myaddr.persistent; + p->ipbits = calc_ipbits(myinfo->ipaddr); + safecopy(p->handle,jstr(json,"handle"),sizeof(p->handle)); + p->balance = 100 * SATOSHIDEN; + p->nxt64bits = nxt64bits; + //pangea_playeradd(myinfo,tp,&tp->G.P[tp->G.numactive++],argjson); + } + } reqstr = jprint(argjson,1); datalen = (int32_t)(strlen(reqstr) + 1); memcpy(pm->serialized,reqstr,datalen); @@ -165,7 +206,12 @@ char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct p printf("pangea send.(%s)\n",cmdstr); init_hexbytes_noT(hexstr,(uint8_t *)pm,pm->sig.allocsize); return(SuperNET_categorymulticast(myinfo,0,pangeahash,tablehash,hexstr,0,2,1)); - } else return(clonestr("{\"error\":\"couldnt create pangea message\"}")); + } + else + { + printf("cant msgcreate\n"); + return(clonestr("{\"error\":\"couldnt create pangea message\"}")); + } } void pangea_sendcmd(struct supernet_info *myinfo,struct table_info *tp,char *cmdstr,int32_t destplayer,uint8_t *data,int32_t datalen,int32_t cardi,int32_t turni) @@ -194,26 +240,6 @@ void pangea_sendcmd(struct supernet_info *myinfo,struct table_info *tp,char *cmd } } -struct table_info *pangea_table(bits256 tablehash) -{ - struct table_info *tp; int32_t allocsize; bits256 pangeahash; char str[65]; - pangeahash = calc_categoryhashes(0,"pangea",0); - if ( (tp= category_info(pangeahash,tablehash)) == 0 ) - { - allocsize = (int32_t)(sizeof(tp->G) + sizeof(void *)*2); - if ( (tp= calloc(1,allocsize)) == 0 ) - printf("error: couldnt create table.(%s)\n",bits256_str(str,tablehash)); - } - if ( tp != 0 ) - { - category_subscribe(SuperNET_MYINFO(0),pangeahash,tablehash); - if ( category_infoset(pangeahash,tablehash,tp) == 0 ) - printf("error: couldnt set table.(%s)\n",bits256_str(str,tablehash)), tp = 0; - else tp->G.allocsize = allocsize; - } - return(tp); -} - int32_t pangea_allocsize(struct table_info *tp,int32_t setptrs) { long allocsize = sizeof(*tp); int32_t N,numcards = tp->G.numcards; @@ -279,7 +305,6 @@ void pangea_tablejoin(PANGEA_HANDARGS) { pangea_playeradd(myinfo,tp,&tp->G.P[tp->G.numactive++],json); printf("add player.%d %p\n",i,tp); - printf("NEW LOBBY.(%s)\n",jprint(pangea_lobbyjson(myinfo),1)); if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits ) { pangea_jsondatacmd(myinfo,pm->tablehash,(struct pangea_msghdr *)space,json,"accept",myinfo->ipaddr); @@ -294,7 +319,7 @@ void pangea_tablejoin(PANGEA_HANDARGS) void pangea_tableaccept(PANGEA_HANDARGS) { cJSON *json; char ipaddr[64]; struct iguana_peer *addr; uint64_t ipbits = 0; - struct iguana_info *coin; struct player_info p; int32_t allocsize; + struct iguana_info *coin; struct player_info p; ipaddr[0] = 0; if ( pm->sig.signer64bits == tp->G.creatorbits && tp->G.numactive < tp->G.maxplayers ) { @@ -333,17 +358,6 @@ void pangea_tableaccept(PANGEA_HANDARGS) addr->persistent_peer = 1; } } else printf("no open iguana peer slots, cant connect\n"); - if ( tp->G.numactive >= tp->G.minplayers && pangea_tableismine(myinfo,tp) >= 0 ) - { - allocsize = pangea_allocsize(tp,0); - if ( tp->G.allocsize < allocsize ) - { - tp = pangea_tablealloc(tp); - category_infoset(tp->G.gamehash,tp->G.tablehash,tp); - } - if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits ) - pangea_newdeck(myinfo,tp); - } } } } @@ -427,7 +441,7 @@ int32_t pangea_hexmsg(struct supernet_info *myinfo,void *data,int32_t len,char * free_json(argjson); } else printf("ERROR >>>>>>> (%s) cant parse\n",(char *)pm->serialized); } - else + else if ( 0 ) { for (i=0; isig)]; + struct pangea_msghdr *pm; int32_t i,allocsize; uint64_t cmdbits; struct table_info *tp; if ( tablecmds[0].cmdbits == 0 ) { for (i=0; iG.allocsize < allocsize ) + { + tp = pangea_tablealloc(tp); + category_infoset(tp->G.gamehash,tp->G.tablehash,tp); + } (*tablecmds[i].func)(myinfo,pm,tp,pm->serialized,(int32_t)(pm->sig.allocsize - sizeof(*pm))); break; } @@ -651,6 +671,26 @@ HASH_AND_ARRAY(pangea,join,tablehash,params) return(pangea_jsondatacmd(myinfo,tablehash,(struct pangea_msghdr *)space,json,"join",myinfo->ipaddr)); } +HASH_AND_ARRAY(pangea,start,tablehash,params) +{ + struct table_info *tp; int32_t allocsize; + if ( (tp= pangea_table(tablehash)) != 0 ) + { + if ( tp->G.numactive >= tp->G.minplayers && pangea_tableismine(myinfo,tp) >= 0 ) + { + allocsize = pangea_allocsize(tp,0); + if ( tp->G.allocsize < allocsize ) + { + tp = pangea_tablealloc(tp); + category_infoset(tp->G.gamehash,tp->G.tablehash,tp); + } + if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits ) + pangea_newdeck(myinfo,tp); + } + return(clonestr("{\"result\":\"started tablehash\"}")); + } + return(clonestr("{\"error\":\"cant find tablehash\"}")); +} #undef IGUANA_ARGS #include "../includes/iguana_apiundefs.h" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 0b448e181..6f53a9b75 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -21,6 +21,7 @@ INT_AND_ARRAY(pangea,host,minplayers,params); ZERO_ARGS(pangea,lobby); HASH_AND_ARRAY(pangea,join,tablehash,params); +HASH_AND_ARRAY(pangea,start,tablehash,params); ZERO_ARGS(SuperNET,help); STRING_ARG(SuperNET,bitcoinrpc,setcoin);