Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
83d7574648
  1. 14
      iguana/main.c
  2. 4
      iguana/pangea777.h
  3. 61
      iguana/pangea_api.c
  4. 8
      iguana/pangea_bets.c
  5. 50
      iguana/pangea_hand.c
  6. 54
      iguana/pangea_json.c
  7. 2
      iguana/pangea_summary.c

14
iguana/main.c

@ -278,7 +278,7 @@ void sigcontinue_func() { printf("\nSIGCONT\n"); signal(SIGCONT,sigcontinue_func
void iguana_main(void *arg) void iguana_main(void *arg)
{ {
FILE *fp; cJSON *json; uint8_t *space,secretbuf[512]; uint32_t r; long allocsize; bits256 pangeahash; FILE *fp; cJSON *json; uint8_t *space,secretbuf[512],x; uint32_t r; long allocsize; bits256 pangeahash;
char helperstr[64],fname[512],*wallet2,*wallet2str,*tmpstr,*confstr,*helperargs,*ipaddr,*coinargs=0,*secret,*jsonstr = arg; char helperstr[64],fname[512],*wallet2,*wallet2str,*tmpstr,*confstr,*helperargs,*ipaddr,*coinargs=0,*secret,*jsonstr = arg;
struct supernet_info *myinfo; struct supernet_info *myinfo;
int32_t i,len,flag,c; bits256 acct,seed,checkhash,wallethash,walletpub,wallet2shared,wallet2priv,wallet2pub; int32_t i,len,flag,c; bits256 acct,seed,checkhash,wallethash,walletpub,wallet2shared,wallet2priv,wallet2pub;
@ -404,8 +404,16 @@ void iguana_main(void *arg)
strcpy(myinfo->ipaddr,"127.0.0.1"); strcpy(myinfo->ipaddr,"127.0.0.1");
myinfo->myaddr.selfipbits = (uint32_t)calc_ipbits(myinfo->ipaddr); myinfo->myaddr.selfipbits = (uint32_t)calc_ipbits(myinfo->ipaddr);
} }
OS_randombytes(myinfo->privkey.bytes,sizeof(myinfo->privkey)); #ifdef __APPLE__
myinfo->myaddr.pubkey = curve25519(myinfo->privkey,curve25519_basepoint9()); x = 1;
#else
x = 0;
#endif
while ( myinfo->myaddr.pubkey.bytes[0] != x )
{
OS_randombytes(myinfo->privkey.bytes,sizeof(myinfo->privkey));
myinfo->myaddr.pubkey = curve25519(myinfo->privkey,curve25519_basepoint9());
}
vcalc_sha256(0,acct.bytes,(void *)myinfo->myaddr.persistent.bytes,sizeof(bits256)); vcalc_sha256(0,acct.bytes,(void *)myinfo->myaddr.persistent.bytes,sizeof(bits256));
myinfo->myaddr.nxt64bits = acct.txid; myinfo->myaddr.nxt64bits = acct.txid;
RS_encode(myinfo->myaddr.NXTADDR,myinfo->myaddr.nxt64bits); RS_encode(myinfo->myaddr.NXTADDR,myinfo->myaddr.nxt64bits);

4
iguana/pangea777.h

@ -92,7 +92,7 @@ struct table_info
{ {
struct table_info *next,*prev; struct game_info G; // must be at top of table_info struct table_info *next,*prev; struct game_info G; // must be at top of table_info
struct player_info *active[CARDS777_MAXPLAYERS]; struct player_info *active[CARDS777_MAXPLAYERS];
uint32_t numhands,summarysize,timestamp,numactive; int64_t hostrake,pangearake; uint32_t numhands,summarysize,timestamp; int64_t hostrake,pangearake;
struct hand_info hand; int64_t snapshot[CARDS777_MAXPLAYERS]; struct hand_info hand; int64_t snapshot[CARDS777_MAXPLAYERS];
uint8_t myind,summary[65536],space[65536*2]; char spacestr[65536*4+1]; uint8_t myind,summary[65536],space[65536*2]; char spacestr[65536*4+1];
struct cards777_privdata priv; struct cards777_privdata priv;
@ -148,7 +148,7 @@ uint8_t *cards777_encode(bits256 *encoded,bits256 *xoverz,uint8_t *allshares,uin
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); 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);
void pangea_summaryadd(struct supernet_info *myinfo,struct table_info *tp,uint8_t type,void *arg0,int32_t size0,void *arg1,int32_t size1); void pangea_summaryadd(struct supernet_info *myinfo,struct table_info *tp,uint8_t type,void *arg0,int32_t size0,void *arg1,int32_t size1);
cJSON *pangea_tablejson(struct game_info *gp); cJSON *pangea_tablejson(struct supernet_info *myinfo,struct table_info *tp);
cJSON *pangea_lobbyjson(struct supernet_info *myinfo); cJSON *pangea_lobbyjson(struct supernet_info *myinfo);
cJSON *pangea_tablestatus(struct supernet_info *myinfo,struct table_info *tp); cJSON *pangea_tablestatus(struct supernet_info *myinfo,struct table_info *tp);

61
iguana/pangea_api.c

@ -132,6 +132,15 @@ struct pangea_msghdr *pangea_msgcreate(struct supernet_info *myinfo,bits256 tabl
return(0); return(0);
} }
void pangea_playeradd(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p,cJSON *json)
{
p->playerpub = jbits256(json,"playerpub");
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);
}
char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct pangea_msghdr *pm,cJSON *json,char *cmdstr,char *ipaddr) 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]; int32_t datalen; bits256 pangeahash;
@ -142,7 +151,7 @@ char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct p
jaddstr(argjson,"cmd",cmdstr); jaddstr(argjson,"cmd",cmdstr);
if ( myinfo->ipaddr[0] == 0 || strncmp(myinfo->ipaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 ) 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\"}")); return(clonestr("{\"error\":\"need to send your ipaddr for now\"}"));
jaddstr(argjson,"myipaddr",myinfo->ipaddr); jaddstr(argjson,"playeripaddr",myinfo->ipaddr);
jaddbits256(argjson,"categoryhash",pangeahash); jaddbits256(argjson,"categoryhash",pangeahash);
jaddbits256(argjson,"subhash",tablehash); jaddbits256(argjson,"subhash",tablehash);
jaddbits256(argjson,"playerpub",myinfo->myaddr.persistent); jaddbits256(argjson,"playerpub",myinfo->myaddr.persistent);
@ -263,19 +272,20 @@ void pangea_tablejoin(PANGEA_HANDARGS)
} }
else if ( (json= cJSON_Parse((char *)pm->serialized)) != 0 ) else if ( (json= cJSON_Parse((char *)pm->serialized)) != 0 )
{ {
if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits ) for (i=0; i<tp->G.numactive; i++)
if ( tp->G.P[i].nxt64bits == pm->sig.signer64bits )
break;
if ( i == tp->G.numactive )
{ {
for (i=0; i<tp->G.numactive; i++) pangea_playeradd(myinfo,tp,&tp->G.P[tp->G.numactive++],json);
if ( tp->G.P[i].nxt64bits == pm->sig.signer64bits ) printf("add player.%d %p\n",i,tp);
break; printf("NEW LOBBY.(%s)\n",jprint(pangea_lobbyjson(myinfo),1));
if ( i == tp->G.numactive ) if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits )
{ {
pangea_playeradd(myinfo,tp,&tp->G.P[tp->G.numactive++],json);
printf("add player.%d\n",i);
pangea_jsondatacmd(myinfo,pm->tablehash,(struct pangea_msghdr *)space,json,"accept",myinfo->ipaddr); pangea_jsondatacmd(myinfo,pm->tablehash,(struct pangea_msghdr *)space,json,"accept",myinfo->ipaddr);
} else printf("duplicate player.%llu\n",(long long)pm->sig.signer64bits); printf("my table! ");
printf("my table! "); }
} } else printf("duplicate player.%llu\n",(long long)pm->sig.signer64bits);
printf("pending join of %llu table.(%s)\n",(long long)pm->sig.signer64bits,bits256_str(str,pm->tablehash)); printf("pending join of %llu table.(%s)\n",(long long)pm->sig.signer64bits,bits256_str(str,pm->tablehash));
free_json(json); free_json(json);
} else printf("tablejoin cant parse json\n"); } else printf("tablejoin cant parse json\n");
@ -290,21 +300,16 @@ void pangea_tableaccept(PANGEA_HANDARGS)
{ {
if ( (json= cJSON_Parse((char *)pm->serialized)) != 0 ) if ( (json= cJSON_Parse((char *)pm->serialized)) != 0 )
{ {
if ( pangea_playerparse(&p,json) == 0 ) if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits )
{ {
p.nxt64bits = pm->sig.signer64bits; expand_ipbits(ipaddr,p.ipbits);
tp->G.P[tp->G.numactive++] = p; printf("connect to new player.(%s)\n",ipaddr);
if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits ) }
{ else if ( pm->sig.signer64bits == myinfo->myaddr.nxt64bits )
expand_ipbits(ipaddr,p.ipbits); {
printf("connect to new player.(%s)\n",ipaddr); expand_ipbits(ipaddr,tp->G.hostipbits);
} printf("connect to host.(%s)\n",ipaddr);
else if ( pm->sig.signer64bits == myinfo->myaddr.nxt64bits ) }
{
expand_ipbits(ipaddr,tp->G.hostipbits);
printf("connect to host.(%s)\n",ipaddr);
}
} else printf("error playerparse.(%s)\n",jprint(json,0));
free_json(json); free_json(json);
if ( ipbits != 0 ) if ( ipbits != 0 )
{ {
@ -360,7 +365,7 @@ void pangea_tablecreate(PANGEA_HANDARGS)
} }
} }
void pangea_parse(struct supernet_info *myinfo,struct pangea_msghdr *pm,cJSON *argjson) void pangea_parse(struct supernet_info *myinfo,struct pangea_msghdr *pm,cJSON *argjson,char *remoteaddr)
{ {
bits256 tablehash; char *method; struct table_info *tp; bits256 tablehash; char *method; struct table_info *tp;
tablehash = jbits256(argjson,"subhash"); tablehash = jbits256(argjson,"subhash");
@ -404,7 +409,7 @@ int32_t pangea_hexmsg(struct supernet_info *myinfo,void *data,int32_t len,char *
if ( remoteaddr != 0 && remoteaddr[0] == 0 && strcmp("127.0.0.1",remoteaddr) == 0 && ((uint8_t *)pm)[len-1] == 0 && (argjson= cJSON_Parse((char *)pm)) != 0 ) if ( remoteaddr != 0 && remoteaddr[0] == 0 && strcmp("127.0.0.1",remoteaddr) == 0 && ((uint8_t *)pm)[len-1] == 0 && (argjson= cJSON_Parse((char *)pm)) != 0 )
{ {
printf("pangea_hexmsg RESULT.(%s)\n",jprint(argjson,0)); printf("pangea_hexmsg RESULT.(%s)\n",jprint(argjson,0));
pangea_parse(myinfo,pm,argjson); pangea_parse(myinfo,pm,argjson,remoteaddr);
free_json(argjson); free_json(argjson);
return(1); return(1);
} }
@ -418,7 +423,7 @@ int32_t pangea_hexmsg(struct supernet_info *myinfo,void *data,int32_t len,char *
//printf("<<<<<<<<<<<<< sigsize.%ld VALIDATED [%ld] len.%d t%u allocsize.%d (%s) [%d]\n",sizeof(pm->sig),(long)serialized-(long)pm,datalen,pm->sig.timestamp,pm->sig.allocsize,(char *)pm->serialized,serialized[datalen-1]); //printf("<<<<<<<<<<<<< sigsize.%ld VALIDATED [%ld] len.%d t%u allocsize.%d (%s) [%d]\n",sizeof(pm->sig),(long)serialized-(long)pm,datalen,pm->sig.timestamp,pm->sig.allocsize,(char *)pm->serialized,serialized[datalen-1]);
if ( serialized[datalen-1] == 0 && (argjson= cJSON_Parse((char *)pm->serialized)) != 0 ) if ( serialized[datalen-1] == 0 && (argjson= cJSON_Parse((char *)pm->serialized)) != 0 )
{ {
pangea_parse(myinfo,pm,argjson); pangea_parse(myinfo,pm,argjson,remoteaddr);
free_json(argjson); free_json(argjson);
} else printf("ERROR >>>>>>> (%s) cant parse\n",(char *)pm->serialized); } else printf("ERROR >>>>>>> (%s) cant parse\n",(char *)pm->serialized);
} }

8
iguana/pangea_bets.c

@ -92,7 +92,7 @@ int32_t pangea_bet(struct supernet_info *myinfo,struct table_info *tp,struct pla
void pangea_antes(struct supernet_info *myinfo,struct table_info *tp) void pangea_antes(struct supernet_info *myinfo,struct table_info *tp)
{ {
int32_t i,n,N; struct player_info *p; uint64_t threshold; int32_t handid; int32_t i,n,N; struct player_info *p; uint64_t threshold; int32_t handid;
N = tp->numactive; N = tp->G.numactive;
for (i=0; i<tp->G.N; i++) for (i=0; i<tp->G.N; i++)
{ {
tp->G.P[i].ind = i; tp->G.P[i].ind = i;
@ -136,7 +136,7 @@ void pangea_antes(struct supernet_info *myinfo,struct table_info *tp)
void pangea_checkantes(struct supernet_info *myinfo,struct table_info *tp) void pangea_checkantes(struct supernet_info *myinfo,struct table_info *tp)
{ {
int64_t bets[CARDS777_MAXPLAYERS+1]; int32_t i,N = tp->numactive; struct hand_info *hand = &tp->hand; int64_t bets[CARDS777_MAXPLAYERS+1]; int32_t i,N = tp->G.numactive; struct hand_info *hand = &tp->hand;
pangea_snapshot(tp,bets); pangea_snapshot(tp,bets);
for (i=0; i<N; i++) for (i=0; i<N; i++)
{ {
@ -192,7 +192,7 @@ int32_t pangea_sidepots(struct supernet_info *myinfo,struct table_info *tp,int32
{ {
int32_t i,j,nonz,N,n = 0; uint64_t bet,minbet = 0; int32_t i,j,nonz,N,n = 0; uint64_t bet,minbet = 0;
memset(sidepots,0,sizeof(uint64_t)*CARDS777_MAXPLAYERS*CARDS777_MAXPLAYERS); memset(sidepots,0,sizeof(uint64_t)*CARDS777_MAXPLAYERS*CARDS777_MAXPLAYERS);
N = tp->numactive; N = tp->G.numactive;
for (j=0; j<N; j++) for (j=0; j<N; j++)
sidepots[0][j] = bets[j]; sidepots[0][j] = bets[j];
nonz = 1; nonz = 1;
@ -245,7 +245,7 @@ int64_t pangea_splitpot(struct supernet_info *myinfo,struct table_info *tp,uint6
struct player_info *winners[CARDS777_MAXPLAYERS]; struct player_info *winners[CARDS777_MAXPLAYERS];
int32_t j,n,N,numwinners = 0; uint32_t bestrank,rank; uint8_t tmp; struct player_info *p; int32_t j,n,N,numwinners = 0; uint32_t bestrank,rank; uint8_t tmp; struct player_info *p;
uint64_t total = 0,bet,split,maxrake,rake=0,pangearake=0; char handstr[128],besthandstr[128]; uint64_t total = 0,bet,split,maxrake,rake=0,pangearake=0; char handstr[128],besthandstr[128];
N = tp->numactive; N = tp->G.numactive;
bestrank = 0; bestrank = 0;
besthandstr[0] = 0; besthandstr[0] = 0;
for (j=n=0; j<N; j++) for (j=n=0; j<N; j++)

50
iguana/pangea_hand.c

@ -17,7 +17,7 @@
int32_t pangea_slotA(struct table_info *tp) { return(0); } int32_t pangea_slotA(struct table_info *tp) { return(0); }
int32_t pangea_slotB(struct table_info *tp) { return(1); } int32_t pangea_slotB(struct table_info *tp) { return(1); }
int32_t pangea_lastnode(struct table_info *tp) { return(tp->numactive-1); } int32_t pangea_lastnode(struct table_info *tp) { return(tp->G.numactive-1); }
int32_t pangea_nextnode(struct table_info *tp) { return(tp->priv.myind+1); } int32_t pangea_nextnode(struct table_info *tp) { return(tp->priv.myind+1); }
int32_t pangea_prevnode(struct table_info *tp) { return(tp->priv.myind-1); } int32_t pangea_prevnode(struct table_info *tp) { return(tp->priv.myind-1); }
@ -72,7 +72,7 @@ int32_t pangea_actives(int32_t *activej,struct table_info *tp)
{ {
int32_t i,n; struct player_info *p; int32_t i,n; struct player_info *p;
*activej = -1; *activej = -1;
for (i=n=0; i<tp->numactive; i++) for (i=n=0; i<tp->G.numactive; i++)
{ {
if ( (p= tp->active[i]) != 0 && p->betstatus != CARDS777_FOLD ) if ( (p= tp->active[i]) != 0 && p->betstatus != CARDS777_FOLD )
{ {
@ -87,7 +87,7 @@ int32_t pangea_actives(int32_t *activej,struct table_info *tp)
int32_t pangea_myrank(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p) int32_t pangea_myrank(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p)
{ {
int32_t i; uint32_t myrank = p->handrank; int32_t i; uint32_t myrank = p->handrank;
for (i=0; i<tp->numactive; i++) for (i=0; i<tp->G.numactive; i++)
if ( tp->active[i] != 0 && tp->active[i] != p && tp->active[i]->handrank > myrank ) if ( tp->active[i] != 0 && tp->active[i] != p && tp->active[i]->handrank > myrank )
return(-1); return(-1);
return(myrank != 0); return(myrank != 0);
@ -187,7 +187,7 @@ void pangea_newhand(PANGEA_HANDARGS)
tp->priv.myind = i; tp->priv.myind = i;
} }
tp->priv.mypriv = myinfo->privkey, tp->priv.mypub = myinfo->myaddr.pubkey; tp->priv.mypriv = myinfo->privkey, tp->priv.mypub = myinfo->myaddr.pubkey;
tp->G.M = (tp->numactive >> 1) + 1; tp->G.M = (tp->G.numactive >> 1) + 1;
hand->startdecktime = pm->sig.timestamp; hand->startdecktime = pm->sig.timestamp;
memcpy(hand->cardpubs,pubkeys,numcards * sizeof(bits256)); memcpy(hand->cardpubs,pubkeys,numcards * sizeof(bits256));
PNACL_message("player.%d NEWHAND.%llx received numhands.%d button.%d cardi.%d | N %d numactive.%d\n",tp->myind,(long long)hand->cardpubs[numcards].txid,tp->numhands,hand->button,hand->cardi,tp->G.N,n); PNACL_message("player.%d NEWHAND.%llx received numhands.%d button.%d cardi.%d | N %d numactive.%d\n",tp->myind,(long long)hand->cardpubs[numcards].txid,tp->numhands,hand->button,hand->cardi,tp->G.N,n);
@ -197,7 +197,7 @@ void pangea_newhand(PANGEA_HANDARGS)
printf("checkprod mismatch myind.%d\n",tp->myind); printf("checkprod mismatch myind.%d\n",tp->myind);
return; return;
} }
tp->numactive = n; tp->G.numactive = n;
memset(tp->summary,0,sizeof(tp->summary)); memset(tp->summary,0,sizeof(tp->summary));
hand->summaries = hand->mismatches = tp->summarysize = 0; hand->summaries = hand->mismatches = tp->summarysize = 0;
handid = tp->numhands++; handid = tp->numhands++;
@ -211,12 +211,12 @@ void pangea_checkstart(struct supernet_info *myinfo,struct table_info *tp)
int32_t i; struct hand_info *hand = &tp->hand; int32_t i; struct hand_info *hand = &tp->hand;
if ( bits256_nonz(hand->checkprod) > 0 && hand->encodestarted == 0 ) if ( bits256_nonz(hand->checkprod) > 0 && hand->encodestarted == 0 )
{ {
for (i=0; i<tp->numactive; i++) for (i=0; i<tp->G.numactive; i++)
{ {
if ( bits256_cmp(hand->othercardpubs[i],hand->checkprod) != 0 ) if ( bits256_cmp(hand->othercardpubs[i],hand->checkprod) != 0 )
break; break;
} }
if ( i == tp->numactive ) if ( i == tp->G.numactive )
{ {
if ( PANGEA_PAUSE > 0 ) if ( PANGEA_PAUSE > 0 )
sleep(PANGEA_PAUSE); sleep(PANGEA_PAUSE);
@ -224,7 +224,7 @@ void pangea_checkstart(struct supernet_info *myinfo,struct table_info *tp)
{ {
hand->encodestarted = (uint32_t)time(NULL); hand->encodestarted = (uint32_t)time(NULL);
PNACL_message("SERVERSTATE issues encoded %llx\n",(long long)hand->checkprod.txid); PNACL_message("SERVERSTATE issues encoded %llx\n",(long long)hand->checkprod.txid);
pangea_sendcmd(myinfo,tp,"encoded",pangea_slotB(tp),tp->priv.outcards[0].bytes,sizeof(bits256) * tp->numactive * tp->G.numcards,tp->numactive*tp->G.numcards,-1); pangea_sendcmd(myinfo,tp,"encoded",pangea_slotB(tp),tp->priv.outcards[0].bytes,sizeof(bits256) * tp->G.numactive * tp->G.numcards,tp->G.numactive*tp->G.numcards,-1);
} }
} }
} }
@ -250,7 +250,7 @@ void pangea_gotdeck(PANGEA_HANDARGS)
void pangea_encoded(PANGEA_HANDARGS) void pangea_encoded(PANGEA_HANDARGS)
{ {
bits256 audit[CARDS777_MAXPLAYERS]; int32_t i,iter,cardi,destplayer,N = tp->numactive; bits256 audit[CARDS777_MAXPLAYERS]; int32_t i,iter,cardi,destplayer,N = tp->G.numactive;
struct hand_info *hand = &tp->hand; struct hand_info *hand = &tp->hand;
if ( N <= 1 || data == 0 || datalen != (tp->G.numcards * N) * sizeof(bits256) ) if ( N <= 1 || data == 0 || datalen != (tp->G.numcards * N) * sizeof(bits256) )
{ {
@ -262,7 +262,7 @@ void pangea_encoded(PANGEA_HANDARGS)
PNACL_message("player.%d ind.%d encodes into %p %llx -> %llx next.%d N %d\n",tp->myind,tp->myind,tp->priv.outcards,(long long)*(uint64_t *)data,(long long)tp->priv.outcards[0].txid,pangea_nextnode(tp),N); PNACL_message("player.%d ind.%d encodes into %p %llx -> %llx next.%d N %d\n",tp->myind,tp->myind,tp->priv.outcards,(long long)*(uint64_t *)data,(long long)tp->priv.outcards[0].txid,pangea_nextnode(tp),N);
if ( tp->myind > 0 ) if ( tp->myind > 0 )
{ {
if ( tp->myind < tp->numactive-1 ) if ( tp->myind < tp->G.numactive-1 )
{ {
//PNACL_message("send encoded\n"); //PNACL_message("send encoded\n");
pangea_sendcmd(myinfo,tp,"encoded",pangea_nextnode(tp),tp->priv.outcards[0].bytes,datalen,N*tp->G.numcards,-1); pangea_sendcmd(myinfo,tp,"encoded",pangea_nextnode(tp),tp->priv.outcards[0].bytes,datalen,N*tp->G.numcards,-1);
@ -287,20 +287,20 @@ void pangea_encoded(PANGEA_HANDARGS)
void pangea_final(PANGEA_HANDARGS) void pangea_final(PANGEA_HANDARGS)
{ {
if ( data == 0 || datalen != (tp->G.numcards * tp->numactive) * sizeof(bits256) ) if ( data == 0 || datalen != (tp->G.numcards * tp->G.numactive) * sizeof(bits256) )
{ {
PNACL_message("pangea_final invalid datalen.%d vs %ld\n",datalen,(long)((tp->G.numcards * tp->numactive) * sizeof(bits256))); PNACL_message("pangea_final invalid datalen.%d vs %ld\n",datalen,(long)((tp->G.numcards * tp->G.numactive) * sizeof(bits256)));
return; return;
} }
if ( Debuglevel > 2 ) if ( Debuglevel > 2 )
PNACL_message("player.%d final into %p\n",tp->myind,tp->priv.outcards); PNACL_message("player.%d final into %p\n",tp->myind,tp->priv.outcards);
memcpy(tp->hand.final,data,sizeof(bits256) * tp->numactive * tp->G.numcards); memcpy(tp->hand.final,data,sizeof(bits256) * tp->G.numactive * tp->G.numcards);
} }
void pangea_preflop(PANGEA_HANDARGS) void pangea_preflop(PANGEA_HANDARGS)
{ {
int32_t i,iter,cardi,destplayer,maxlen,N; bits256 audit[CARDS777_MAXPLAYERS]; int32_t i,iter,cardi,destplayer,maxlen,N; bits256 audit[CARDS777_MAXPLAYERS];
N = tp->numactive; N = tp->G.numactive;
maxlen = (int32_t)(2 * N * N * CARDS777_MAXCARDS * sizeof(bits256)); maxlen = (int32_t)(2 * N * N * CARDS777_MAXCARDS * sizeof(bits256));
if ( N <= 1 || data == 0 || datalen != (2 * N) * (N * N * sizeof(bits256)) ) if ( N <= 1 || data == 0 || datalen != (2 * N) * (N * N * sizeof(bits256)) )
{ {
@ -349,7 +349,7 @@ void pangea_card(PANGEA_HANDARGS)
{ {
struct hand_info *hand; int32_t destplayer,card,selector,N,cardi,validcard = -1; struct hand_info *hand; int32_t destplayer,card,selector,N,cardi,validcard = -1;
bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; char cardAstr[8],cardBstr[8]; struct player_info *destp; bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; char cardAstr[8],cardBstr[8]; struct player_info *destp;
N = tp->numactive, cardi = pm->cardi, destplayer = pm->destplayer; hand = &tp->hand; N = tp->G.numactive, cardi = pm->cardi, destplayer = pm->destplayer; hand = &tp->hand;
destp = tp->active[destplayer]; destp = tp->active[destplayer];
if ( N <= 1 || data == 0 || datalen != sizeof(bits256)*N || destp == 0 ) if ( N <= 1 || data == 0 || datalen != sizeof(bits256)*N || destp == 0 )
{ {
@ -385,7 +385,7 @@ void pangea_card(PANGEA_HANDARGS)
int64_t pangea_snapshot(struct table_info *tp,int64_t *snapshot) int64_t pangea_snapshot(struct table_info *tp,int64_t *snapshot)
{ {
struct player_info *p; int64_t betsize; int32_t i,N = tp->numactive; struct player_info *p; int64_t betsize; int32_t i,N = tp->G.numactive;
memset(snapshot,0,N * sizeof(int64_t)); memset(snapshot,0,N * sizeof(int64_t));
for (betsize=i=0; i<N; i++) for (betsize=i=0; i<N; i++)
{ {
@ -402,7 +402,7 @@ int64_t pangea_snapshot(struct table_info *tp,int64_t *snapshot)
void pangea_startbets(struct supernet_info *myinfo,struct table_info *tp,int32_t cardi) void pangea_startbets(struct supernet_info *myinfo,struct table_info *tp,int32_t cardi)
{ {
uint32_t now,i,N = tp->numactive; struct player_info *p; int64_t snapshot[CARDS777_MAXPLAYERS+1]; uint32_t now,i,N = tp->G.numactive; struct player_info *p; int64_t snapshot[CARDS777_MAXPLAYERS+1];
struct hand_info *hand = &tp->hand; struct hand_info *hand = &tp->hand;
if ( PANGEA_PAUSE > 0 ) if ( PANGEA_PAUSE > 0 )
sleep(PANGEA_PAUSE); sleep(PANGEA_PAUSE);
@ -431,7 +431,7 @@ void pangea_startbets(struct supernet_info *myinfo,struct table_info *tp,int32_t
void pangea_facedown(PANGEA_HANDARGS) void pangea_facedown(PANGEA_HANDARGS)
{ {
int32_t i,validcard,cardi,senderind,N,n = 0; uint64_t havemask; struct player_info *p; int32_t i,validcard,cardi,senderind,N,n = 0; uint64_t havemask; struct player_info *p;
N = tp->numactive, senderind = pm->myind, cardi = pm->cardi; N = tp->G.numactive, senderind = pm->myind, cardi = pm->cardi;
p = tp->active[senderind]; p = tp->active[senderind];
if ( p == 0 || N <= 1 || data == 0 || datalen != sizeof(int32_t) ) if ( p == 0 || N <= 1 || data == 0 || datalen != sizeof(int32_t) )
{ {
@ -461,7 +461,7 @@ void pangea_facedown(PANGEA_HANDARGS)
void pangea_faceup(PANGEA_HANDARGS) void pangea_faceup(PANGEA_HANDARGS)
{ {
int32_t cardi,validcard,i,senderind,N; struct hand_info *hand; uint16_t tmp; struct player_info *p,*destp; int32_t cardi,validcard,i,senderind,N; struct hand_info *hand; uint16_t tmp; struct player_info *p,*destp;
N = tp->numactive, senderind = pm->myind, cardi = pm->cardi, hand = &tp->hand; N = tp->G.numactive, senderind = pm->myind, cardi = pm->cardi, hand = &tp->hand;
destp = tp->active[senderind]; destp = tp->active[senderind];
if ( destp == 0 || N <= 1 || data == 0 || datalen != sizeof(bits256) ) if ( destp == 0 || N <= 1 || data == 0 || datalen != sizeof(bits256) )
{ {
@ -512,7 +512,7 @@ void pangea_turn(PANGEA_HANDARGS)
{ {
int32_t turni,cardi,senderind,N; struct player_info *destp; int32_t turni,cardi,senderind,N; struct player_info *destp;
int64_t snapshot[CARDS777_MAXPLAYERS+1]; struct hand_info *hand = &tp->hand; int64_t snapshot[CARDS777_MAXPLAYERS+1]; struct hand_info *hand = &tp->hand;
N = tp->numactive, senderind = pm->myind, turni = pm->turni, cardi = pm->cardi; N = tp->G.numactive, senderind = pm->myind, turni = pm->turni, cardi = pm->cardi;
destp = tp->active[senderind]; destp = tp->active[senderind];
if ( destp == 0 || N <= 1 ) if ( destp == 0 || N <= 1 )
{ {
@ -541,7 +541,7 @@ void pangea_confirm(PANGEA_HANDARGS)
{ {
uint32_t starttime; int32_t i,N,senderind,turni,cardi; uint64_t betsize=0,amount=0; uint32_t starttime; int32_t i,N,senderind,turni,cardi; uint64_t betsize=0,amount=0;
int64_t snapshot[CARDS777_MAXPLAYERS+1]; struct player_info *p; struct hand_info *hand; int64_t snapshot[CARDS777_MAXPLAYERS+1]; struct player_info *p; struct hand_info *hand;
N = tp->numactive, senderind = pm->myind, turni = pm->turni, cardi = pm->cardi; N = tp->G.numactive, senderind = pm->myind, turni = pm->turni, cardi = pm->cardi;
hand = &tp->hand; p = tp->active[senderind]; hand = &tp->hand; p = tp->active[senderind];
if ( p == 0 || N <= 1 || data == 0 ) if ( p == 0 || N <= 1 || data == 0 )
{ {
@ -610,7 +610,7 @@ void pangea_finish(struct supernet_info *myinfo,struct table_info *tp)
int64_t tsnap,sidepots[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS];//,list[CARDS777_MAXPLAYERS]; int64_t tsnap,sidepots[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS];//,list[CARDS777_MAXPLAYERS];
uint64_t pangearake,rake; int64_t balances[CARDS777_MAXPLAYERS],bets[CARDS777_MAXPLAYERS+1]; uint64_t pangearake,rake; int64_t balances[CARDS777_MAXPLAYERS],bets[CARDS777_MAXPLAYERS+1];
uint32_t changes; uint16_t busted,rebuy; int32_t j,n,r,N,norake = 0; struct hand_info *hand; uint32_t changes; uint16_t busted,rebuy; int32_t j,n,r,N,norake = 0; struct hand_info *hand;
N = tp->numactive, hand = &tp->hand; N = tp->G.numactive, hand = &tp->hand;
if ( hand->finished == 0 ) if ( hand->finished == 0 )
{ {
memset(sidepots,0,sizeof(sidepots)); memset(sidepots,0,sizeof(sidepots));
@ -694,7 +694,7 @@ void pangea_action(PANGEA_HANDARGS)
uint32_t now; struct player_info *p; int64_t x,snapshot[CARDS777_MAXPLAYERS + 1]; uint32_t now; struct player_info *p; int64_t x,snapshot[CARDS777_MAXPLAYERS + 1];
int32_t action,cardi,i,j,senderind,N,destplayer = 0; int32_t action,cardi,i,j,senderind,N,destplayer = 0;
bits256 audit[CARDS777_MAXPLAYERS]; struct hand_info *hand; uint8_t tmp; uint64_t amount = 0; bits256 audit[CARDS777_MAXPLAYERS]; struct hand_info *hand; uint8_t tmp; uint64_t amount = 0;
action = pm->turni, senderind = pm->myind, cardi = pm->cardi, N = tp->numactive, hand = &tp->hand; action = pm->turni, senderind = pm->myind, cardi = pm->cardi, N = tp->G.numactive, hand = &tp->hand;
p = tp->active[senderind]; p = tp->active[senderind];
memcpy(&amount,data,sizeof(amount)); memcpy(&amount,data,sizeof(amount));
if ( N <= 1 || p == 0 || cardi < 2*N ) if ( N <= 1 || p == 0 || cardi < 2*N )
@ -820,7 +820,7 @@ void pangea_action(PANGEA_HANDARGS)
void pangea_decoded(PANGEA_HANDARGS) void pangea_decoded(PANGEA_HANDARGS)
{ {
int32_t cardi,destplayer,card,turni,N; bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; struct hand_info *hand; int32_t cardi,destplayer,card,turni,N; bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; struct hand_info *hand;
cardi = pm->cardi, turni = pm->turni, N = tp->numactive, hand = &tp->hand; cardi = pm->cardi, turni = pm->turni, N = tp->G.numactive, hand = &tp->hand;
if ( N <= 1 || data == 0 || datalen != sizeof(bits256)*N ) if ( N <= 1 || data == 0 || datalen != sizeof(bits256)*N )
{ {
PNACL_message("pangea_decoded invalid datalen.%d vs %ld\n",datalen,(long)sizeof(bits256)); PNACL_message("pangea_decoded invalid datalen.%d vs %ld\n",datalen,(long)sizeof(bits256));
@ -858,7 +858,7 @@ void pangea_decoded(PANGEA_HANDARGS)
void pangea_showdown(PANGEA_HANDARGS) void pangea_showdown(PANGEA_HANDARGS)
{ {
struct player_info *p; int32_t i,turni,N,cardi,myind; struct hand_info *hand; uint64_t amount=0; struct player_info *p; int32_t i,turni,N,cardi,myind; struct hand_info *hand; uint64_t amount=0;
cardi = pm->cardi, turni = pm->turni, N = tp->numactive, hand = &tp->hand; cardi = pm->cardi, turni = pm->turni, N = tp->G.numactive, hand = &tp->hand;
myind = tp->priv.myind; myind = tp->priv.myind;
if ( (p= tp->active[myind]) == 0 ) if ( (p= tp->active[myind]) == 0 )
{ {

54
iguana/pangea_json.c

@ -15,18 +15,21 @@
#include "pangea777.h" #include "pangea777.h"
void pangea_playeradd(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p,cJSON *json) cJSON *pangea_playerjson(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p)
{ {
p->playerpub = jbits256(json,"playerpub"); char ipaddr[64]; cJSON *json = cJSON_CreateObject();
p->ipbits = calc_ipbits(jstr(json,"myipaddr")); jaddstr(json,"handle",p->handle);
safecopy(p->handle,jstr(json,"handle"),sizeof(p->handle)); expand_ipbits(ipaddr,p->ipbits);
p->balance = 100 * SATOSHIDEN; jaddstr(json,"playeripaddr",ipaddr);
p->nxt64bits = acct777_nxt64bits(p->playerpub); jaddbits256(json,"playerpub",p->playerpub);
return(json);
} }
cJSON *pangea_tablejson(struct game_info *gp) cJSON *pangea_tablejson(struct supernet_info *myinfo,struct table_info *tp)
{ {
char ipaddr[64],str[64]; struct tai t; int32_t seconds; cJSON *json = cJSON_CreateObject(); char ipaddr[64],str[64]; struct tai t; int32_t i,seconds; cJSON *array,*json; struct game_info *gp;
gp = &tp->G;
json = cJSON_CreateObject();
jaddbits256(json,"tablehash",gp->tablehash); jaddbits256(json,"tablehash",gp->tablehash);
expand_ipbits(ipaddr,gp->hostipbits); expand_ipbits(ipaddr,gp->hostipbits);
jaddstr(json,"host",ipaddr); jaddstr(json,"host",ipaddr);
@ -58,6 +61,15 @@ cJSON *pangea_tablejson(struct game_info *gp)
} }
} }
} }
if ( tp->G.numactive > 0 )
{
array = cJSON_CreateArray();
for (i=0; i<tp->G.numactive; i++)
jaddi(array,pangea_playerjson(myinfo,tp,&tp->G.P[i]));
jadd(json,"players",array);
}
jaddnum(json,"numactive",tp->G.numactive);
printf("tp.%p\n",tp);
return(json); return(json);
} }
@ -109,7 +121,7 @@ cJSON *pangea_lobbyjson(struct supernet_info *myinfo)
HASH_ITER(hh,cat->sub,sub,tmp) HASH_ITER(hh,cat->sub,sub,tmp)
{ {
if ( (tp= sub->info) != 0 && pangea_opentable(&tp->G) > 0 ) if ( (tp= sub->info) != 0 && pangea_opentable(&tp->G) > 0 )
jaddi(array,pangea_tablejson(&tp->G)); jaddi(array,pangea_tablejson(myinfo,tp));
} }
} }
jadd(retjson,"tables",array); jadd(retjson,"tables",array);
@ -118,20 +130,6 @@ cJSON *pangea_lobbyjson(struct supernet_info *myinfo)
return(retjson); return(retjson);
} }
int32_t pangea_playerparse(struct player_info *p,cJSON *json)
{
char *handle,*ipaddr;
if ( (handle= jstr(json,"handle")) != 0 && strlen(handle) < sizeof(p->handle)-1 )
strcpy(p->handle,handle);
p->playerpub = jbits256(json,"playerpub");
if ( (ipaddr= jstr(json,"myipaddr")) != 0 && is_ipaddr(ipaddr) > 0 )
{
p->ipbits = calc_ipbits(ipaddr);
return(0);
}
return(-1);
}
cJSON *pangea_handjson(struct hand_info *hand,uint8_t *holecards,int32_t isbot) cJSON *pangea_handjson(struct hand_info *hand,uint8_t *holecards,int32_t isbot)
{ {
int32_t i,card; char cardAstr[8],cardBstr[8],pairstr[18],cstr[128]; cJSON *array,*json = cJSON_CreateObject(); int32_t i,card; char cardAstr[8],cardBstr[8],pairstr[18],cstr[128]; cJSON *array,*json = cJSON_CreateObject();
@ -193,7 +191,7 @@ cJSON *pangea_tablestatus(struct supernet_info *myinfo,struct table_info *tp)
struct player_info *p; int32_t i,n,N,j,countdown,iter; cJSON *item,*array,*json; struct player_info *p; int32_t i,n,N,j,countdown,iter; cJSON *item,*array,*json;
int64_t won[CARDS777_MAXPLAYERS],snapshot[CARDS777_MAXPLAYERS],bets[CARDS777_MAXPLAYERS]; int64_t won[CARDS777_MAXPLAYERS],snapshot[CARDS777_MAXPLAYERS],bets[CARDS777_MAXPLAYERS];
int64_t total,val; char *handhist,*str; struct game_info *gp; struct hand_info *hand; int64_t total,val; char *handhist,*str; struct game_info *gp; struct hand_info *hand;
hand = &tp->hand, gp = &tp->G, N = tp->numactive; hand = &tp->hand, gp = &tp->G, N = tp->G.numactive;
json = cJSON_CreateObject(); json = cJSON_CreateObject();
jaddbits256(json,"tablehash",gp->tablehash); jaddbits256(json,"tablehash",gp->tablehash);
jadd64bits(json,"myind",tp->priv.myind); jadd64bits(json,"myind",tp->priv.myind);
@ -201,7 +199,7 @@ cJSON *pangea_tablestatus(struct supernet_info *myinfo,struct table_info *tp)
jaddnum(json,"maxbuyin",gp->maxbuyin); jaddnum(json,"maxbuyin",gp->maxbuyin);
jaddnum(json,"button",tp->hand.button); jaddnum(json,"button",tp->hand.button);
jaddnum(json,"M",gp->M); jaddnum(json,"M",gp->M);
jaddnum(json,"N",tp->numactive); jaddnum(json,"N",tp->G.numactive);
jaddnum(json,"numcards",gp->numcards); jaddnum(json,"numcards",gp->numcards);
jaddnum(json,"numhands",tp->numhands); jaddnum(json,"numhands",tp->numhands);
jaddnum(json,"rake",(double)gp->rakemillis/10.); jaddnum(json,"rake",(double)gp->rakemillis/10.);
@ -211,14 +209,14 @@ cJSON *pangea_tablestatus(struct supernet_info *myinfo,struct table_info *tp)
jaddnum(json,"bigblind",dstr(gp->bigblind)); jaddnum(json,"bigblind",dstr(gp->bigblind));
jaddnum(json,"ante",dstr(gp->ante)); jaddnum(json,"ante",dstr(gp->ante));
array = cJSON_CreateArray(); array = cJSON_CreateArray();
for (i=0; i<tp->numactive; i++) for (i=0; i<tp->G.numactive; i++)
jaddi64bits(array,tp->active[i]!=0?tp->active[i]->nxt64bits:0); jaddi64bits(array,tp->active[i]!=0?tp->active[i]->nxt64bits:0);
jadd(json,"addrs",array); jadd(json,"addrs",array);
total = 0; total = 0;
for (iter=0; iter<6; iter++) for (iter=0; iter<6; iter++)
{ {
array = cJSON_CreateArray(); array = cJSON_CreateArray();
for (i=0; i<tp->numactive; i++) for (i=0; i<tp->G.numactive; i++)
{ {
val = 0; val = 0;
if ( (p= tp->active[i]) != 0 ) if ( (p= tp->active[i]) != 0 )
@ -311,7 +309,7 @@ void pangea_playerprint(struct supernet_info *myinfo,struct table_info *tp,int32
void pangea_statusprint(struct supernet_info *myinfo,struct table_info *tp,int32_t myind) void pangea_statusprint(struct supernet_info *myinfo,struct table_info *tp,int32_t myind)
{ {
int32_t i,N; char handstr[64]; uint8_t handvals[7]; struct hand_info *hand = &tp->hand; int32_t i,N; char handstr[64]; uint8_t handvals[7]; struct hand_info *hand = &tp->hand;
N = tp->numactive; N = tp->G.numactive;
for (i=0; i<N; i++) for (i=0; i<N; i++)
pangea_playerprint(myinfo,tp,i,myind); pangea_playerprint(myinfo,tp,i,myind);
handstr[0] = 0; handstr[0] = 0;

2
iguana/pangea_summary.c

@ -259,7 +259,7 @@ void pangea_summaryadd(struct supernet_info *myinfo,struct table_info *tp,uint8_
void pangea_summary(PANGEA_HANDARGS) void pangea_summary(PANGEA_HANDARGS)
{ {
char *otherhist,*handhist = 0; int32_t senderind,N,matched = 0; struct hand_info *hand = &tp->hand; char *otherhist,*handhist = 0; int32_t senderind,N,matched = 0; struct hand_info *hand = &tp->hand;
senderind = pm->myind, N = tp->numactive; senderind = pm->myind, N = tp->G.numactive;
if ( Debuglevel > 2 ) // ordering changes crc if ( Debuglevel > 2 ) // ordering changes crc
printf("player.%d [%d]: got summary.%d from %d memcmp.%d\n",tp->priv.myind,tp->summarysize,datalen,senderind,memcmp(data,tp->summary,datalen)); printf("player.%d [%d]: got summary.%d from %d memcmp.%d\n",tp->priv.myind,tp->summarysize,datalen,senderind,memcmp(data,tp->summary,datalen));
if ( datalen == tp->summarysize ) if ( datalen == tp->summarysize )

Loading…
Cancel
Save