Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
d3e6842315
  1. 4
      agents/field.html
  2. 12
      agents/footer.html
  3. 19
      agents/formfooter.html
  4. 16
      agents/formheader.html
  5. 49
      agents/header.html
  6. 26
      crypto777/curve25519.c
  7. 326
      deprecated/obsolete.h
  8. 4
      field.html
  9. 12
      footer.html
  10. 19
      formfooter.html
  11. 16
      formheader.html
  12. 49
      header.html
  13. 30
      iguana/SuperNET.c
  14. 9
      iguana/SuperNET.h
  15. 39
      iguana/SuperNET_category.c
  16. 2
      iguana/cards777.c
  17. 2
      iguana/iguana.sources
  18. 3
      iguana/iguana777.h
  19. 4
      iguana/iguana_accept.c
  20. 21
      iguana/iguana_peers.c
  21. 204
      iguana/pangea777.h
  22. 805
      iguana/pangea_api.c
  23. 387
      iguana/pangea_bets.c
  24. 400
      iguana/pangea_fsm.c
  25. 270
      iguana/pangea_funds.c
  26. 933
      iguana/pangea_hand.c
  27. 10
      iguana/pangea_init.c
  28. 316
      iguana/pangea_json.c
  29. 11
      iguana/pangea_network.c
  30. 311
      iguana/pangea_summary.c
  31. 3
      includes/curve25519.h
  32. 37
      includes/iguana_apideclares.h
  33. 2
      pangea/pangea777.c
  34. 4
      pangea/pangeafunds.c

4
agents/field.html

@ -0,0 +1,4 @@
<div class="form-group">
<label for="%s">%s</label>
<textarea class="form-control" name="%s" rows="1" cols="%s" %s></textarea>
</div>

12
agents/footer.html

@ -0,0 +1,12 @@
</div>
</div>
<!-- API fileds -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body></html>

19
agents/formfooter.html

@ -0,0 +1,19 @@
</div>
<div class="col-md-6">
<div class="form-group">
<label for="broadcast">Response</label>
<figure class="highlight" for="%s" disabled="">
<pre>
<code id="%s" class="language-html" data-lang="javascript"></code>
</pre>
</figure>
</div>
</div>
</div>
<input type="submit" value="%s" class="btn btn-default">
</form>
</div>
</div>
</div>

16
agents/formheader.html

@ -0,0 +1,16 @@
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading-%s">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-%s" aria-expanded="false" aria-controls="collapse-%s">
%s %s
</a>
</h4>
</div>
<div id="collapse-%s" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-%s">
<div class="panel-body">
<form action="http://127.0.0.1:7778/api/%s/%s" oninput="%s">
<div class="row">
<div class="col-md-6">

49
agents/header.html

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>SuperNET API></title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
</head>
<body>
<!-- Navigation Bar -->
<div class="navbar navbar-default" role="navigation">
<div class="container" style="min-width: 90%;">
<div class="navbar-header">
<a class="navbar-brand" href="#">SuperNET API</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="https://phabricator.supernet.org/w/" target="_blank" style="margin-left:20px;">Developer Wiki</a></li>
</ul>
</div>
</div>
</div>
<!-- Navigation Bar -->
<!-- API fileds -->
<div class="container" style="min-width: 90%">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

26
crypto777/curve25519.c

@ -1759,9 +1759,20 @@ bits256 acct777_invoicehash(bits256 *invoicehash,uint16_t lockdays,uint8_t chain
//char *bits256_str(); //char *bits256_str();
//struct acct777_sig { bits256 sigbits,pubkey; uint64_t signer64bits; uint32_t timestamp,allocsize; }; //struct acct777_sig { bits256 sigbits,pubkey; uint64_t signer64bits; uint32_t timestamp,allocsize; };
void acct777_rwsig(int32_t rwflag,uint8_t *serialized,struct acct777_sig *sig)
{
int32_t len = 0;
iguana_rwbignum(rwflag,&serialized[len],sizeof(bits256),sig->sigbits.bytes), len += sizeof(bits256);
iguana_rwbignum(rwflag,&serialized[len],sizeof(bits256),sig->pubkey.bytes),len += sizeof(bits256);
iguana_rwnum(rwflag,&serialized[len],sizeof(sig->signer64bits),&sig->signer64bits),len += sizeof(sig->signer64bits);
iguana_rwnum(rwflag,&serialized[len],sizeof(sig->timestamp),&sig->timestamp),len += sizeof(sig->timestamp);
iguana_rwnum(rwflag,&serialized[len],sizeof(sig->allocsize),&sig->allocsize),len += sizeof(sig->allocsize);
}
uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubkey,uint32_t timestamp,uint8_t *serialized,int32_t datalen) uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubkey,uint32_t timestamp,uint8_t *serialized,int32_t datalen)
{ {
int32_t len = 0; bits256 pubkey; bits256 shared; uint8_t buf[sizeof(*sig)]; bits256 pubkey; bits256 shared; uint8_t buf[sizeof(*sig)];
pubkey = acct777_pubkey(privkey); pubkey = acct777_pubkey(privkey);
if ( memcmp(sig->pubkey.bytes,otherpubkey.bytes,sizeof(bits256)) != 0 ) if ( memcmp(sig->pubkey.bytes,otherpubkey.bytes,sizeof(bits256)) != 0 )
{ {
@ -1772,13 +1783,9 @@ uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubke
sig->allocsize = (int32_t)(datalen + sizeof(*sig)); sig->allocsize = (int32_t)(datalen + sizeof(*sig));
sig->signer64bits = acct777_nxt64bits(sig->pubkey); sig->signer64bits = acct777_nxt64bits(sig->pubkey);
} }
shared = curve25519(privkey,otherpubkey); sig->sigbits = shared = curve25519(privkey,otherpubkey);
memset(buf,0,sizeof(buf)); memset(buf,0,sizeof(buf));
iguana_rwbignum(1,&buf[len],sizeof(bits256),shared.bytes), len += sizeof(bits256); acct777_rwsig(1,buf,sig);
iguana_rwbignum(1,&buf[len],sizeof(bits256),sig->pubkey.bytes),len += sizeof(bits256);
iguana_rwnum(1,&buf[len],sizeof(sig->signer64bits),&sig->signer64bits),len += sizeof(sig->signer64bits);
iguana_rwnum(1,&buf[len],sizeof(sig->timestamp),&sig->timestamp),len += sizeof(sig->timestamp);
iguana_rwnum(1,&buf[len],sizeof(sig->allocsize),&sig->allocsize),len += sizeof(sig->allocsize);
//int32_t i; for (i=0; i<sizeof(*sig); i++) //int32_t i; for (i=0; i<sizeof(*sig); i++)
// printf("%02x ",buf[i]); // printf("%02x ",buf[i]);
//char str[65]; printf("shared.(%s) crc.%u datalen.%d\n",bits256_str(str,shared),calc_crc32(0,buf,sizeof(buf)),datalen); //char str[65]; printf("shared.(%s) crc.%u datalen.%d\n",bits256_str(str,shared),calc_crc32(0,buf,sizeof(buf)),datalen);
@ -1789,10 +1796,11 @@ uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubke
uint64_t acct777_validate(struct acct777_sig *sig,bits256 privkey,bits256 pubkey) uint64_t acct777_validate(struct acct777_sig *sig,bits256 privkey,bits256 pubkey)
{ {
struct acct777_sig checksig; uint64_t signerbits; int32_t datalen; struct acct777_sig checksig; uint64_t signerbits; int32_t datalen; uint8_t *serialized;
datalen = (int32_t)(sig->allocsize - sizeof(*sig)); datalen = (int32_t)(sig->allocsize - sizeof(*sig));
checksig = *sig; checksig = *sig;
acct777_sign(&checksig,privkey,pubkey,sig->timestamp,sig->serialized,datalen); serialized = (uint8_t *)((long)sig + sizeof(*sig));
acct777_sign(&checksig,privkey,pubkey,sig->timestamp,serialized,datalen);
if ( memcmp(checksig.sigbits.bytes,sig->sigbits.bytes,sizeof(checksig.sigbits)) != 0 ) if ( memcmp(checksig.sigbits.bytes,sig->sigbits.bytes,sizeof(checksig.sigbits)) != 0 )
{ {
printf("sig compare error using sig->pub from %llu\n",(long long)acct777_nxt64bits(sig->pubkey)); printf("sig compare error using sig->pub from %llu\n",(long long)acct777_nxt64bits(sig->pubkey));

326
deprecated/obsolete.h

@ -12380,5 +12380,331 @@ len = 0;
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
*/ */
/*INT_AND_ARRAY(pangea,newhand,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,ping,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,gotdeck,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,ready,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,encoded,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,final,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,addedfunds,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,preflop,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,decoded,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,card,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,facedown,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,faceup,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,turn,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,confirmturn,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,chat,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,action,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,showdown,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,handsummary,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}*/
/*INT_AND_ARRAY(pangea,newhand,senderind,params);
INT_AND_ARRAY(pangea,ping,senderind,params);
INT_AND_ARRAY(pangea,gotdeck,senderind,params);
INT_AND_ARRAY(pangea,ready,senderind,params);
INT_AND_ARRAY(pangea,encoded,senderind,params);
INT_AND_ARRAY(pangea,final,senderind,params);
INT_AND_ARRAY(pangea,addedfunds,senderind,params);
INT_AND_ARRAY(pangea,preflop,senderind,params);
INT_AND_ARRAY(pangea,decoded,senderind,params);
INT_AND_ARRAY(pangea,card,senderind,params);
INT_AND_ARRAY(pangea,facedown,senderind,params);
INT_AND_ARRAY(pangea,faceup,senderind,params);
INT_AND_ARRAY(pangea,turn,senderind,params);
INT_AND_ARRAY(pangea,confirmturn,senderind,params);
INT_AND_ARRAY(pangea,chat,senderind,params);
INT_AND_ARRAY(pangea,action,senderind,params);
INT_AND_ARRAY(pangea,showdown,senderind,params);
INT_AND_ARRAY(pangea,handsummary,senderind,params);*/
else if ( (sp= pangea_find64(tableid,my64bits)) != 0 && (chatstr= jstr(json,"chat")) != 0 && strlen(chatstr) < 256 )
{
if ( 0 && (pm= j64bits(json,"pm")) != 0 )
{
for (i=0; i<sp->numaddrs; i++)
if ( sp->addrs[i] == pm )
break;
if ( i == sp->numaddrs )
return(clonestr("{\"error\":\"specified pm destination not at table\"}"));
} else i = -1;
pangea_sendcmd(hex,&sp->tp->hn,"chat",i,(void *)chatstr,(int32_t)strlen(chatstr)+1,pangea_ind(sp,sp->myslot),-1);
return(clonestr("{\"result\":\"chat message sent\"}"));
}
/*void _pangea_chat(uint64_t senderbits,void *buf,int32_t len,int32_t senderind)
{
PNACL_message(">>>>>>>>>>> CHAT FROM.%d %llu: (%s)\n",senderind,(long long)senderbits,(char *)buf);
}
else if ( strcmp(methodstr,"newtable") == 0 )
retstr = pangea_newtable(juint(json,"threadid"),json,plugin->nxt64bits,*(bits256 *)plugin->mypriv,*(bits256 *)plugin->mypub,plugin->transport,plugin->ipaddr,plugin->pangeaport,juint(json,"minbuyin"),juint(json,"maxbuyin"),juint(json,"rakemillis"));
else if ( sender == 0 || sender[0] == 0 )
{
if ( strcmp(methodstr,"start") == 0 )
{
strcpy(retbuf,"{\"result\":\"start issued\"}");
if ( (base= jstr(json,"base")) != 0 )
{
if ( (maxplayers= juint(json,"maxplayers")) < 2 )
maxplayers = 2;
else if ( maxplayers > CARDS777_MAXPLAYERS )
maxplayers = CARDS777_MAXPLAYERS;
if ( jstr(json,"resubmit") == 0 )
sprintf(retbuf,"{\"resubmit\":[{\"method\":\"start\"}, {\"bigblind\":\"%llu\"}, {\"ante\":\"%llu\"}, {\"rakemillis\":\"%u\"}, {\"maxplayers\":%d}, {\"minbuyin\":%d}, {\"maxbuyin\":%d}],\"pluginrequest\":\"SuperNET\",\"plugin\":\"InstantDEX\",\"method\":\"orderbook\",\"base\":\"%s\",\"exchange\":\"pangea\",\"allfields\":1}",(long long)j64bits(json,"bigblind"),(long long)j64bits(json,"ante"),juint(json,"rakemillis"),maxplayers,juint(json,"minbuyin"),juint(json,"maxbuyin"),jstr(json,"base")!=0?jstr(json,"base"):"BTCD");
else if ( pangea_start(plugin,retbuf,base,0,j64bits(json,"bigblind"),j64bits(json,"ante"),juint(json,"rakemillis"),maxplayers,juint(json,"minbuyin"),juint(json,"maxbuyin"),json) < 0 )
;
} else strcpy(retbuf,"{\"error\":\"no base specified\"}");
}
else if ( strcmp(methodstr,"status") == 0 )
retstr = pangea_status(plugin->nxt64bits,j64bits(json,"tableid"),json);
}
int32_t pangea_unzbuf(uint8_t *buf,char *hexstr,int32_t len)
{
int32_t i,j,len2;
for (len2=i=0; i<len; i+=2)
{
if ( hexstr[i] == 'Z' )
{
for (j=0; j<hexstr[i+1]-'A'; j++)
buf[len2++] = 0;
}
else buf[len2++] = _decode_hex(&hexstr[i]);
}
//char *tmp = calloc(1,len*2+1);
//init_hexbytes_noT(tmp,buf,len2);
//PostMessage("zlen %d to len2 %d\n",len,len2);
//free(tmp);
return(len2);
}
int32_t pangea_poll(uint64_t *senderbitsp,uint32_t *timestampp,union hostnet777 *hn)
{
char *jsonstr,*hexstr,*cmdstr; cJSON *json; struct cards777_privdata *priv; struct cards777_pubdata *dp; struct pangea_info *sp;
int32_t len,senderind,maxlen; uint8_t *buf;
*senderbitsp = 0;
dp = hn->client->H.pubdata, sp = dp->table;
priv = hn->client->H.privdata;
if ( hn == 0 || hn->client == 0 || dp == 0 || priv == 0 )
{
if ( Debuglevel > 2 )
PNACL_message("pangea_poll: null hn.%p %p dp.%p priv.%p\n",hn,hn!=0?hn->client:0,dp,priv);
return(-1);
}
maxlen = (int32_t)(sizeof(bits256) * dp->N*dp->N*dp->numcards);
if ( (buf= malloc(maxlen)) == 0 )
{
PNACL_message("pangea_poll: null buf\n");
return(-1);
}
if ( dp != 0 && priv != 0 && (jsonstr= queue_dequeue(&hn->client->H.Q,1)) != 0 )
{
//pangea_neworder(dp,dp->table,0,0);
//PNACL_message("player.%d GOT.(%s)\n",hn->client->H.slot,jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
*senderbitsp = j64bits(json,"sender");
if ( (senderind= juint(json,"myind")) < 0 || senderind >= dp->N )
{
PNACL_message("pangea_poll: illegal senderind.%d cardi.%d turni.%d (%s)\n",senderind,juint(json,"cardi"),juint(json,"turni"),jsonstr);
goto cleanup;
}
*timestampp = juint(json,"timestamp");
hn->client->H.state = juint(json,"state");
len = juint(json,"n");
cmdstr = jstr(json,"cmd");
if ( sp->myind < 0 )
{
// check for reactivation command
goto cleanup;
}
if ( cmdstr != 0 && strcmp(cmdstr,"preflop") == 0 )
{
if ( (hexstr= jstr(json,"data")) != 0 )
len = pangea_unzbuf(buf,hexstr,len);
}
else if ( (hexstr= jstr(json,"data")) != 0 && strlen(hexstr) == (len<<1) )
{
if ( len > maxlen )
{
PNACL_message("len too big for pangea_poll\n");
goto cleanup;
}
decode_hex(buf,len,hexstr);
} else if ( hexstr != 0 )
PNACL_message("len.%d vs hexlen.%ld (%s)\n",len,(long)(strlen(hexstr)>>1),hexstr);
if ( cmdstr != 0 )
{
if ( strcmp(cmdstr,"newhand") == 0 )
pangea_newhand(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"ping") == 0 )
pangea_ping(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"gotdeck") == 0 )
pangea_gotdeck(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"ready") == 0 )
pangea_ready(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"encoded") == 0 )
pangea_encoded(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"final") == 0 )
pangea_final(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"addfunds") == 0 )
pangea_addfunds(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"preflop") == 0 )
pangea_preflop(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"decoded") == 0 )
pangea_decoded(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"card") == 0 )
pangea_card(hn,json,dp,priv,buf,len,juint(json,"cardi"),senderind);
else if ( strcmp(cmdstr,"facedown") == 0 )
pangea_facedown(hn,json,dp,priv,buf,len,juint(json,"cardi"),senderind);
else if ( strcmp(cmdstr,"faceup") == 0 )
pangea_faceup(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"turn") == 0 )
pangea_turn(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"confirmturn") == 0 )
pangea_confirmturn(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"chat") == 0 )
pangea_chat(*senderbitsp,buf,len,senderind);
else if ( strcmp(cmdstr,"action") == 0 )
pangea_action(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"showdown") == 0 )
pangea_showdown(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"summary") == 0 )
pangea_gotsummary(hn,json,dp,priv,buf,len,senderind);
}
cleanup:
free_json(json);
}
free_queueitem(jsonstr);
}
free(buf);
return(hn->client->H.state);
}
char *Pangea_bypass(uint64_t my64bits,uint8_t myprivkey[32],cJSON *json)
{
char *methodstr,*retstr = 0;
if ( (methodstr= jstr(json,"method")) != 0 )
{
if ( strcmp(methodstr,"turn") == 0 )
retstr = _pangea_input(my64bits,j64bits(json,"tableid"),json);
else if ( strcmp(methodstr,"status") == 0 )
retstr = _pangea_status(my64bits,j64bits(json,"tableid"),json);
else if ( strcmp(methodstr,"mode") == 0 )
retstr = _pangea_mode(my64bits,j64bits(json,"tableid"),json);
else if ( strcmp(methodstr,"buyin") == 0 )
retstr = _pangea_buyin(my64bits,j64bits(json,"tableid"),json);
else if ( strcmp(methodstr,"history") == 0 )
retstr = _pangea_history(my64bits,j64bits(json,"tableid"),json);
}
return(retstr);
}*/
/*sprintf(hex,"{\"cmd\":\"%s\",\"turni\":%d,\"myslot\":%d,\"myind\":%d,\"cardi\":%d,\"dest\":%d,\"sender\":\"%llu\",\"n\":%u,%s\"data\":\"",cmdstr,turni,priv->myslot,pangea_ind(dp->table,priv->myslot),cardi,destplayer,(long long)myinfo->myaddr.nxt64bits,(long)time(NULL),datalen,hoststr);
n = (int32_t)strlen(hex);
if ( strcmp(cmdstr,"preflop") == 0 )
{
memcpy(&hex[n],data,datalen+1);
hexlen = (int32_t)strlen(hex)+1;
}
else
if ( data != 0 && datalen != 0 )
init_hexbytes_noT(&hex[n],data,datalen);
strcat(hex,"\"}");
if ( (json= cJSON_Parse(hex)) == 0 )
{
PNACL_message("error creating json\n");
return;
}
free_json(json);
hexlen = (int32_t)strlen(hex)+1;*/
#endif #endif

4
field.html

@ -0,0 +1,4 @@
<div class="form-group">
<label for="%s">%s</label>
<textarea class="form-control" name="%s" rows="1" cols="%s" %s></textarea>
</div>

12
footer.html

@ -0,0 +1,12 @@
</div>
</div>
<!-- API fileds -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body></html>

19
formfooter.html

@ -0,0 +1,19 @@
</div>
<div class="col-md-6">
<div class="form-group">
<label for="broadcast">Response</label>
<figure class="highlight" for="%s" disabled="">
<pre>
<code id="%s" class="language-html" data-lang="javascript"></code>
</pre>
</figure>
</div>
</div>
</div>
<input type="submit" value="%s" class="btn btn-default">
</form>
</div>
</div>
</div>

16
formheader.html

@ -0,0 +1,16 @@
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading-%s">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-%s" aria-expanded="false" aria-controls="collapse-%s">
%s %s
</a>
</h4>
</div>
<div id="collapse-%s" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-%s">
<div class="panel-body">
<form action="http://127.0.0.1:7778/api/%s/%s" oninput="%s">
<div class="row">
<div class="col-md-6">

49
header.html

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>SuperNET API></title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
</head>
<body>
<!-- Navigation Bar -->
<div class="navbar navbar-default" role="navigation">
<div class="container" style="min-width: 90%;">
<div class="navbar-header">
<a class="navbar-brand" href="#">SuperNET API</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="https://phabricator.supernet.org/w/" target="_blank" style="margin-left:20px;">Developer Wiki</a></li>
</ul>
</div>
</div>
</div>
<!-- Navigation Bar -->
<!-- API fileds -->
<div class="container" style="min-width: 90%">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

30
iguana/SuperNET.c

@ -16,6 +16,24 @@
#include "iguana777.h" #include "iguana777.h"
#include "../includes/tweetnacl.h" #include "../includes/tweetnacl.h"
cJSON *SuperNET_argjson(cJSON *json)
{
cJSON *argjson = jduplicate(json);
jdelete(argjson,"agent");
jdelete(argjson,"method");
jdelete(argjson,"categoryhash");
jdelete(argjson,"subhash");
jdelete(argjson,"mypub");
jdelete(argjson,"hexmsg");
jdelete(argjson,"plaintext");
jdelete(argjson,"broadcast");
jdelete(argjson,"ov");
jdelete(argjson,"check");
jdelete(argjson,"yourip");
jdelete(argjson,"myip");
return(argjson);
}
bits256 SuperNET_sharedseed(bits256 privkey,bits256 otherpub) bits256 SuperNET_sharedseed(bits256 privkey,bits256 otherpub)
{ {
bits256 seed2,seed; bits256 seed2,seed;
@ -41,7 +59,7 @@ void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,c
printf("got %s remotepeer.(%s) supernet.%d\n",symbol,ipaddr,supernetflag); printf("got %s remotepeer.(%s) supernet.%d\n",symbol,ipaddr,supernetflag);
if ( supernetflag != 0 && (uint32_t)myinfo->myaddr.selfipbits != (uint32_t)ipbits ) if ( supernetflag != 0 && (uint32_t)myinfo->myaddr.selfipbits != (uint32_t)ipbits )
{ {
if ( (addr= iguana_peerslot(coin,ipbits)) != 0 ) if ( (addr= iguana_peerslot(coin,ipbits,0)) != 0 )
{ {
printf("launch startconnection to supernet peer.(%s)\n",ipaddr); printf("launch startconnection to supernet peer.(%s)\n",ipaddr);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
@ -488,10 +506,11 @@ int32_t DHT_dist(bits256 desthash,bits256 hash)
return(dist*0); return(dist*0);
} }
struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_info **coinp,uint32_t destipbits,bits256 category,bits256 subhash) struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_info **coinp,uint64_t destipbits,bits256 category,bits256 subhash)
{ {
int32_t i,j; struct iguana_peer *addr; int32_t i,j; struct iguana_peer *addr; uint16_t port;
*coinp = 0; *coinp = 0;
port = (uint16_t)(destipbits >> 32);
for (i=0; i<IGUANA_MAXCOINS; i++) for (i=0; i<IGUANA_MAXCOINS; i++)
{ {
if ( Coins[i] != 0 ) if ( Coins[i] != 0 )
@ -502,6 +521,8 @@ struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_i
if ( addr->usock >= 0 ) if ( addr->usock >= 0 )
{ {
if ( destipbits == addr->ipbits || category_peer(myinfo,addr,category,subhash) >= 0 ) if ( destipbits == addr->ipbits || category_peer(myinfo,addr,category,subhash) >= 0 )
{
if ( port == 0 || addr->A.port == port )
{ {
*coinp = Coins[i]; *coinp = Coins[i];
return(addr); return(addr);
@ -510,10 +531,11 @@ struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_i
} }
} }
} }
}
return(0); return(0);
} }
char *SuperNET_DHTsend(struct supernet_info *myinfo,uint32_t destipbits,bits256 categoryhash,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) char *SuperNET_DHTsend(struct supernet_info *myinfo,uint64_t destipbits,bits256 categoryhash,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext)
{ {
int32_t i,j; char *convstr,*jsonstr=0; struct iguana_peer *addr; cJSON *json; struct iguana_info *coin; int32_t i,j; char *convstr,*jsonstr=0; struct iguana_peer *addr; cJSON *json; struct iguana_info *coin;
if ( myinfo == 0 ) if ( myinfo == 0 )

9
iguana/SuperNET.h

@ -118,16 +118,21 @@ char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remotead
char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 category,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext); char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 category,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext);
char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSON *json,char *remoteaddr); char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSON *json,char *remoteaddr);
char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr); char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr);
char *SuperNET_DHTsend(struct supernet_info *myinfo,uint32_t destipbits,bits256 category,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext); char *SuperNET_DHTsend(struct supernet_info *myinfo,uint64_t destipbits,bits256 category,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext);
uint16_t SuperNET_API2num(char *agent,char *method); uint16_t SuperNET_API2num(char *agent,char *method);
int32_t SuperNET_num2API(char *agent,char *method,uint16_t num); int32_t SuperNET_num2API(char *agent,char *method,uint16_t num);
bits256 SuperNET_sharedseed(bits256 privkey,bits256 otherpub); bits256 SuperNET_sharedseed(bits256 privkey,bits256 otherpub);
int32_t SuperNET_decrypt(bits256 *senderpubp,uint64_t *senderbitsp,uint32_t *timestampp,bits256 mypriv,bits256 mypub,uint8_t *dest,int32_t maxlen,uint8_t *src,int32_t len); int32_t SuperNET_decrypt(bits256 *senderpubp,uint64_t *senderbitsp,uint32_t *timestampp,bits256 mypriv,bits256 mypub,uint8_t *dest,int32_t maxlen,uint8_t *src,int32_t len);
cJSON *SuperNET_argjson(cJSON *json);
struct category_info { UT_hash_handle hh; queue_t Q; bits256 hash; struct category_info *sub; } *Categories; struct category_info { UT_hash_handle hh; queue_t Q; bits256 hash; void *info; struct category_info *sub; } *Categories;
struct category_msg { struct queueitem DL; struct tai t; int32_t len; uint8_t msg[]; }; struct category_msg { struct queueitem DL; struct tai t; int32_t len; uint8_t msg[]; };
void *category_info(bits256 categoryhash,bits256 subhash);
void *category_infoset(bits256 categoryhash,bits256 subhash,void *info);
struct category_info *category_find(bits256 categoryhash,bits256 subhash);
int32_t SuperNET_str2hex(uint8_t *hex,char *str); int32_t SuperNET_str2hex(uint8_t *hex,char *str);
void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len); void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len);
void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,struct tai now); void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,struct tai now);

39
iguana/SuperNET_category.c

@ -30,20 +30,47 @@ bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory)
return(categoryhash); return(categoryhash);
} }
queue_t *category_Q(bits256 categoryhash,bits256 subhash) struct category_info *category_find(bits256 categoryhash,bits256 subhash)
{ {
struct category_info *cat,*sub; queue_t *Q = 0; struct category_info *cat,*sub = 0;
HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat); HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat);
if ( cat != 0 ) if ( cat != 0 )
{ {
if ( bits256_nonz(subhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 ) if ( bits256_nonz(subhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 )
{ {
HASH_FIND(hh,cat->sub,subhash.bytes,sizeof(subhash),sub); HASH_FIND(hh,cat->sub,subhash.bytes,sizeof(subhash),sub);
if ( sub != 0 ) return(sub);
Q = &sub->Q; }
} else Q = &cat->Q; return(cat);
}
return(0);
}
queue_t *category_Q(bits256 categoryhash,bits256 subhash)
{
struct category_info *cat;
if ( (cat= category_find(categoryhash,subhash)) != 0 )
return(&cat->Q);
else return(0);
}
void *category_info(bits256 categoryhash,bits256 subhash)
{
struct category_info *cat;
if ( (cat= category_find(categoryhash,subhash)) != 0 )
return(cat->info);
else return(0);
}
void *category_infoset(bits256 categoryhash,bits256 subhash,void *info)
{
struct category_info *cat;
if ( (cat= category_find(categoryhash,subhash)) != 0 )
{
cat->info = info;
return(info);
} }
return(Q); return(0);
} }
struct category_msg *category_gethexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash) struct category_msg *category_gethexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash)

2
iguana/cards777.c

@ -299,6 +299,7 @@ bits256 cards777_decode(bits256 *seedp,bits256 *xoverz,int32_t destplayer,bits25
return(cipher); return(cipher);
} }
#ifdef notyet
struct cards777_privdata *cards777_allocpriv(int32_t numcards,int32_t N) struct cards777_privdata *cards777_allocpriv(int32_t numcards,int32_t N)
{ {
struct cards777_privdata *priv; struct cards777_privdata *priv;
@ -328,7 +329,6 @@ struct cards777_pubdata *cards777_allocpub(int32_t M,int32_t numcards,int32_t N)
return(dp); return(dp);
} }
#ifdef notyet
int32_t cards777_testinit(struct hostnet777_server *srv,int32_t M,struct hostnet777_client **clients,int32_t N,int32_t numcards) int32_t cards777_testinit(struct hostnet777_server *srv,int32_t M,struct hostnet777_client **clients,int32_t N,int32_t numcards)
{ {
//static int64_t balances[9]; //static int64_t balances[9];

2
iguana/iguana.sources

@ -1,3 +1,3 @@
#iguana_html.c #iguana_html.c
SOURCES := SuperNET.c SuperNET_hexmsg.c pangea_api.c pangea_funds.c cards777.c pangea_fsm.c pangea_network.c pangea_init.c poker.c ramchain_api.c iguana_tx.c iguana_wallet.c iguana_pubkeys.c iguana_recv.c iguana_bundles.c iguana_msg.c iguana_rpc.c iguana777.c iguana_chains.c iguana_peers.c iguana_accept.c iguana_bitmap.c iguana_init.c iguana_ramchain.c iguana_blocks.c iguana_json.c main.c SOURCES := SuperNET.c SuperNET_hexmsg.c pangea_api.c pangea_bets.c cards777.c pangea_summary.c pangea_json.c pangea_hand.c poker.c ramchain_api.c iguana_tx.c iguana_wallet.c iguana_pubkeys.c iguana_recv.c iguana_bundles.c iguana_msg.c iguana_rpc.c iguana777.c iguana_chains.c iguana_peers.c iguana_accept.c iguana_bitmap.c iguana_init.c iguana_ramchain.c iguana_blocks.c iguana_json.c main.c

3
iguana/iguana777.h

@ -659,10 +659,11 @@ int32_t iguana_scriptgen(struct iguana_info *coin,uint8_t *script,char *asmstr,s
int32_t iguana_ramchain_spendtxid(struct iguana_info *coin,bits256 *txidp,struct iguana_txid *T,int32_t numtxids,bits256 *X,int32_t numexternaltxids,struct iguana_spend *s); int32_t iguana_ramchain_spendtxid(struct iguana_info *coin,bits256 *txidp,struct iguana_txid *T,int32_t numtxids,bits256 *X,int32_t numexternaltxids,struct iguana_spend *s);
struct iguana_info *iguana_coinselect(); struct iguana_info *iguana_coinselect();
void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr); void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr);
struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits); struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int32_t forceflag);
void iguana_dedicatedglue(void *arg); void iguana_dedicatedglue(void *arg);
void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag); void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag);
void SuperNET_yourip(struct supernet_info *myinfo,char *yourip); void SuperNET_yourip(struct supernet_info *myinfo,char *yourip);
void iguana_peerkill(struct iguana_info *coin);
char *busdata_sync(uint32_t *noncep,char *jsonstr,char *broadcastmode,char *destNXTaddr); char *busdata_sync(uint32_t *noncep,char *jsonstr,char *broadcastmode,char *destNXTaddr);
void peggy(); void peggy();

4
iguana/iguana_accept.c

@ -100,7 +100,7 @@ void iguana_acceptloop(void *args)
{ {
}*/ }*/
if ( (addr= iguana_peerslot(coin,ipbits)) == 0 ) if ( (addr= iguana_peerslot(coin,ipbits,0)) == 0 )
{ {
ptr = mycalloc('a',1,sizeof(*ptr)); ptr = mycalloc('a',1,sizeof(*ptr));
strcpy(ptr->ipaddr,ipaddr); strcpy(ptr->ipaddr,ipaddr);
@ -126,7 +126,7 @@ int32_t iguana_pendingaccept(struct iguana_info *coin)
struct iguana_accept *ptr; char ipaddr[64]; struct iguana_peer *addr; struct iguana_accept *ptr; char ipaddr[64]; struct iguana_peer *addr;
if ( (ptr= queue_dequeue(&coin->acceptQ,0)) != 0 ) if ( (ptr= queue_dequeue(&coin->acceptQ,0)) != 0 )
{ {
if ( (addr= iguana_peerslot(coin,ptr->ipbits)) != 0 ) if ( (addr= iguana_peerslot(coin,ptr->ipbits,0)) != 0 )
{ {
expand_ipbits(ipaddr,ptr->ipbits); expand_ipbits(ipaddr,ptr->ipbits);
printf("iguana_pendingaccept LAUNCH DEDICATED THREAD for %s\n",ipaddr); printf("iguana_pendingaccept LAUNCH DEDICATED THREAD for %s\n",ipaddr);

21
iguana/iguana_peers.c

@ -614,19 +614,31 @@ void iguana_startconnection(void *arg)
} }
} }
struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits) void iguana_peerkill(struct iguana_info *coin)
{
struct iguana_peer *addr;
if ( coin->peers.numranked > 0 && (addr= coin->peers.ranked[coin->peers.numranked-1]) != 0 )
{
printf("mark rank.%d as dead.(%s)\n",coin->peers.numranked,addr->ipaddr);
addr->dead = (uint32_t)time(NULL);
}
}
struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int32_t forceflag)
{ {
int32_t i; struct iguana_peer *addr; char ipaddr[64]; int32_t i; struct iguana_peer *addr; char ipaddr[64];
for (i=0; i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
if ( ipbits == coin->peers.active[i].ipbits ) if ( ipbits == coin->peers.active[i].ipbits )
return(0); return(forceflag!=0 ? &coin->peers.active[i] : 0);
expand_ipbits(ipaddr,ipbits); expand_ipbits(ipaddr,ipbits);
#ifdef IGUANA_DISABLEPEERS #ifdef IGUANA_DISABLEPEERS
if ( strcmp("127.0.0.1",ipaddr) != 0 ) if ( strcmp("127.0.0.1",ipaddr) != 0 )
return(0); return(0);
#endif #endif
//portable_mutex_lock(&coin->peers_mutex); //portable_mutex_lock(&coin->peers_mutex);
for (i=0; i<coin->MAXPEERS && i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
{
if ( i < coin->MAXPEERS || forceflag != 0 )
{ {
addr = &coin->peers.active[i]; addr = &coin->peers.active[i];
addr->addrind = i; addr->addrind = i;
@ -645,6 +657,7 @@ struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits)
} }
portable_mutex_unlock(&coin->peers_mutex); portable_mutex_unlock(&coin->peers_mutex);
} }
}
return(0); return(0);
} }
@ -655,7 +668,7 @@ void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA)
{ {
//printf("%x\n",iA->ipbits); //printf("%x\n",iA->ipbits);
//portable_mutex_unlock(&coin->peers_mutex); //portable_mutex_unlock(&coin->peers_mutex);
if ( (addr= iguana_peerslot(coin,iA->ipbits)) != 0 )//i < coin->MAXPEERS && i < IGUANA_MAXPEERS && addr != 0 ) if ( (addr= iguana_peerslot(coin,iA->ipbits,0)) != 0 )//i < coin->MAXPEERS && i < IGUANA_MAXPEERS && addr != 0 )
{ {
//printf("pend.%d status.%d possible peer.(%s).%x threads %d %d %d %d\n",addr->pending,iA->status,addr->ipaddr,addr->ipbits,iguana_numthreads(coin,0),iguana_numthreads(coin,1),iguana_numthreads(coin,2),iguana_numthreads(coin,3)); //printf("pend.%d status.%d possible peer.(%s).%x threads %d %d %d %d\n",addr->pending,iA->status,addr->ipaddr,addr->ipbits,iguana_numthreads(coin,0),iguana_numthreads(coin,1),iguana_numthreads(coin,2),iguana_numthreads(coin,3));
if ( addr->pending == 0 && iA->status != IGUANA_PEER_CONNECTING ) if ( addr->pending == 0 && iA->status != IGUANA_PEER_CONNECTING )

204
iguana/pangea777.h

@ -48,85 +48,88 @@
#define CARDS777_CHANGES 15 #define CARDS777_CHANGES 15
#define CARDS777_SNAPSHOT 16 #define CARDS777_SNAPSHOT 16
struct cards777_handinfo struct cards777_privdata
{
bits256 holecards[2],mypriv,mypub,*audits,*outcards,*xoverz;
//,*reconstructed[CARDS777_MAXPLAYERS],*mofn[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS];
uint8_t *myshares[CARDS777_MAXPLAYERS],*allshares;
uint8_t hole[2],cardis[2],automuck,autofold,myind;
bits256 data[];
};
struct hand_info
{ {
bits256 checkprod,*cardpubs,*final,community256[5],cards[CARDS777_MAXPLAYERS][2]; bits256 checkprod,*cardpubs,*final,community256[5],cards[CARDS777_MAXPLAYERS][2];
uint64_t othercardpubs[CARDS777_MAXPLAYERS]; bits256 othercardpubs[CARDS777_MAXPLAYERS];
int64_t havemasks[CARDS777_MAXPLAYERS],betsize,hostrake,pangearake,lastraise,bets[CARDS777_MAXPLAYERS],snapshot[CARDS777_MAXPLAYERS+1],won[CARDS777_MAXPLAYERS]; int64_t betsize,lastraise,betsizesnapshot;
uint32_t starttime,handmask,lastbettor,startdecktime,betstarted,finished,encodestarted; uint32_t starttime,handmask,lastbettor,startdecktime,betstarted,finished,encodestarted;
uint32_t cardi,userinput_starttime,handranks[CARDS777_MAXPLAYERS]; uint32_t readymask,summaries,mismatches,cardi,userinput_starttime,handranks;
int8_t betstatus[CARDS777_MAXPLAYERS],actions[CARDS777_MAXPLAYERS],turnis[CARDS777_MAXPLAYERS]; uint8_t button,numactions,undergun,community[5],sharenrs[CARDS777_MAXPLAYERS][255];
uint8_t numactions,undergun,community[5],sharenrs[CARDS777_MAXPLAYERS][255],hands[CARDS777_MAXPLAYERS][7];
}; };
struct cards777_pubdata struct player_info
{ {
int64_t snapshot[CARDS777_MAXPLAYERS]; bits256 playerpub;
uint64_t maxrake,hostrake,bigblind,ante,pangearake,summaries,mismatches; struct iguana_peer *addr;
uint32_t button,readymask,numhands,rakemillis,minbuyin,maxbuyin,summarysize; uint64_t ipbits,nxt64bits,havemask;
void *table; struct cards777_handinfo hand; int64_t balance,buyinamount,bets,won,snapshot;
char newhand[65536],coinstr[16]; uint8_t M,N,numcards,summary[65536]; bits256 data[]; uint32_t handrank;
uint8_t hand[7];
int8_t ind,action,betstatus,turni;
char handle[32];
}; };
struct cards777_privdata struct game_info
{ {
bits256 holecards[2],*audits,*outcards,*xoverz; bits256 tablehash,gamehash;
//,*reconstructed[CARDS777_MAXPLAYERS],*mofn[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS]; uint8_t M,N,numcards,ismine,numactive;
uint8_t *myshares[CARDS777_MAXPLAYERS],*allshares,hole[2],cardis[2],automuck,autofold; uint32_t allocsize,rakemillis,minbuyin,maxbuyin,minplayers,maxplayers,opentime,started,finished;
bits256 data[]; uint64_t maxrake,hostrake,bigblind,ante,pangearake,hostipbits,creatorbits;
struct player_info P[CARDS777_MAXPLAYERS];
}; };
extern int32_t Debuglevel; struct table_info
bits256 xoverz_donna(bits256 a);
bits256 crecip_donna(bits256 a);
bits256 fmul_donna(bits256 a,bits256 b);
void calc_shares(unsigned char *shares,unsigned char *secret,int32_t size,int32_t width,int32_t M,int32_t N,unsigned char *sharenrs);
int32_t init_sharenrs(unsigned char sharenrs[255],unsigned char *orig,int32_t m,int32_t n);
struct pangea_info
{ {
uint32_t timestamp,numaddrs,minbuyin,maxbuyin; struct table_info *next,*prev; struct game_info G; // must be at top of table_info
int64_t balances[CARDS777_MAXPLAYERS]; uint8_t isbot[CARDS777_MAXPLAYERS]; bits256 playerpubs[CARDS777_MAXPLAYERS]; struct player_info *active[CARDS777_MAXPLAYERS];
uint64_t basebits,bigblind,ante,addrs[CARDS777_MAXPLAYERS],active[CARDS777_MAXPLAYERS],tableid; uint32_t numhands,summarysize,timestamp,numactive; int64_t hostrake,pangearake;
char btcpubkeystr[67],wipstr[64],coinstr[16],multisigaddr[64],scriptPubKey[128],redeemScript[4096]; struct hand_info hand; int64_t snapshot[CARDS777_MAXPLAYERS];
uint8_t addrtype,p2shtype,wiftype,btcpub[33]; uint8_t myind,summary[65536],space[65536*2]; char spacestr[65536*4+1];
int32_t myslot,myind,numactive,buyinvouts[CARDS777_MAXPLAYERS]; uint64_t buyinamounts[CARDS777_MAXPLAYERS]; struct cards777_privdata priv;
char buyintxids[CARDS777_MAXPLAYERS][128],coinaddrs[CARDS777_MAXPLAYERS][67],btcpubkeys[CARDS777_MAXPLAYERS][67];
struct pangea_thread *tp; struct cards777_privdata *priv; struct cards777_pubdata *dp;
}; };
extern struct pangea_info *TABLES[100];
//./BitcoinDarkd SuperNET '{"agent":"InstantDEX","method":"orderbook","exchange":"active","base":"NXT","rel":"BTC"}'
// ./SNapi "{\"agent\":\"InstantDEX\",\"method\":\"orderbook\",\"exchange\":\"pangea\",\"base\":\"NXT\"}"
// ./SNapi "{\"agent\":\"InstantDEX\",\"method\":\"placebid\",\"exchange\":\"pangea\",\"base\":\"NXT\"}"
struct pangeanet777_endpoint { char endpoint[128],transport[16],ipaddr[64]; uint16_t port; }; struct tournament_info
struct pangeanet777_id { bits256 pubkey; uint64_t nxt64bits; void *privdata,*pubdata; int32_t pmsock; uint32_t lastcontact; };
union pangeanet777 { struct pangeanet777_server *server; struct pangeanet777_client *client; };
struct pangeanet777_hdr
{ {
queue_t Q; bits256 privkey,pubkey; struct tournament_info *next,*prev;
void *privdata,*pubdata; uint64_t nxt64bits;//,recvhashes[64]; struct table_info *tables;
void (*pollfunc)(union pangeanet777 *hn);
uint32_t lastping; int32_t slot,done,state,ind;
}; };
struct pangeanet777_client { struct pangeanet777_hdr H; int32_t subsock; struct pangeanet777_id my; uint64_t balance,tableid; }; struct pangea_info
struct pangeanet777_server
{ {
struct pangeanet777_hdr H; struct table_info *tables,*mytable;
int32_t num,max,pubsock; struct pangeanet777_endpoint ep; //queue_t mailboxQ[CARDS777_MAXPLAYERS]; struct tournament_info *tournaments;
struct pangeanet777_id clients[];
}; };
struct pangea_thread extern int32_t Debuglevel;
bits256 xoverz_donna(bits256 a);
bits256 crecip_donna(bits256 a);
bits256 fmul_donna(bits256 a,bits256 b);
void calc_shares(unsigned char *shares,unsigned char *secret,int32_t size,int32_t width,int32_t M,int32_t N,unsigned char *sharenrs);
int32_t init_sharenrs(unsigned char sharenrs[255],unsigned char *orig,int32_t m,int32_t n);
struct pangea_msghdr
{ {
union pangeanet777 hn; uint64_t nxt64bits; int32_t threadid,ishost,M,N,numcards; // sig { bits256 sigbits,pubkey; uint64_t signer64bits; uint32_t timestamp,allocsize; };
}; struct acct777_sig sig __attribute__((packed));
extern struct pangea_thread *THREADS[_PANGEA_MAXTHREADS]; bits256 tablehash;
char cmd[8];
int8_t turni,cardi,destplayer,myind; // ALL DATA MUST BE SERIALIZED!!!
uint8_t serialized[];
} __attribute__((packed));
#define PANGEA_ARGS struct supernet_info *myinfo,struct table_info *tp,cJSON *json
#define PANGEA_CALLARGS myinfo,tp,json
int32_t SuperNET_copybits(int32_t reverse,uint8_t *dest,uint8_t *src,int32_t len); int32_t SuperNET_copybits(int32_t reverse,uint8_t *dest,uint8_t *src,int32_t len);
@ -142,50 +145,49 @@ int32_t cards777_validate(bits256 cardpriv,bits256 final,bits256 *cardpubs,int32
bits256 cards777_decode(bits256 *seedp,bits256 *xoverz,int32_t destplayer,bits256 cipher,bits256 *outcards,int32_t numcards,int32_t N); bits256 cards777_decode(bits256 *seedp,bits256 *xoverz,int32_t destplayer,bits256 cipher,bits256 *outcards,int32_t numcards,int32_t N);
uint8_t *cards777_encode(bits256 *encoded,bits256 *xoverz,uint8_t *allshares,uint8_t *myshares[],uint8_t sharenrs[255],int32_t M,bits256 *ciphers,int32_t numcards,int32_t N); uint8_t *cards777_encode(bits256 *encoded,bits256 *xoverz,uint8_t *allshares,uint8_t *myshares[],uint8_t sharenrs[255],int32_t M,bits256 *ciphers,int32_t numcards,int32_t N);
int32_t pangea_search(struct pangea_info *sp,uint64_t nxt64bits); 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);
int32_t pangea_tableaddr(struct cards777_pubdata *dp,uint64_t destbits); void pangea_summaryadd(struct supernet_info *myinfo,struct table_info *tp,uint8_t type,void *arg0,int32_t size0,void *arg1,int32_t size1);
struct pangea_info *pangea_find64(uint64_t tableid,uint64_t nxt64bits);
struct pangea_info *pangea_find(uint64_t tableid,int32_t threadid); cJSON *pangea_tablejson(struct game_info *gp);
int32_t pangea_neworder(struct cards777_pubdata *dp,struct pangea_info *sp,uint64_t *active,int32_t numactive); cJSON *pangea_lobbyjson(struct supernet_info *myinfo);
cJSON *pangea_tablestatus(struct supernet_info *myinfo,struct table_info *tp);
cJSON *pangea_tablestatus(struct pangea_info *sp);
void pangea_summary(union pangeanet777 *hn,struct cards777_pubdata *dp,uint8_t type,void *arg0,int32_t size0,void *arg1,int32_t size1); int64_t pangea_snapshot(struct table_info *tp,int64_t *snapshot);
void pangea_startbets(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t cardi); int32_t pangea_slotA(struct table_info *tp);
void pangea_checkantes(union pangeanet777 *hn,struct cards777_pubdata *dp);
uint64_t pangea_bot(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t turni,int32_t cardi,uint64_t betsize); char *pangea_dispsummary(struct supernet_info *myinfo,struct table_info *tp,int32_t verbose,uint8_t *summary,int32_t summarysize,bits256 tablehash,int32_t handid,int32_t numplayers);
char *pangea_dispsummary(struct pangea_info *sp,int32_t verbose,uint8_t *summary,int32_t summarysize,uint64_t tableid,int32_t handid,int32_t numplayers); int32_t pangea_parsesummary(uint8_t *typep,uint64_t *valAp,uint64_t *bits64p,bits256 *cardp,uint8_t *summary,int32_t len);
char *_pangea_input(uint64_t my64bits,uint64_t tableid,cJSON *json); int32_t pangea_anotherhand(struct supernet_info *myinfo,struct table_info *tp,int32_t sleepflag);
void pangea_finish(union pangeanet777 *hn,struct cards777_pubdata *dp);
void pangea_serverstate(union pangeanet777 *hn,struct cards777_pubdata *dp,struct cards777_privdata *priv); void pangea_gamecreate(struct game_info *gp,uint32_t timestamp,bits256 tablehash,cJSON *json);
int32_t pangea_playerparse(struct player_info *p,cJSON *json);
int32_t pangea_anotherhand(void *hn,struct cards777_pubdata *dp,int32_t sleepflag); int32_t pangea_newdeck(struct supernet_info *myinfo,struct table_info *tp);
void pangea_clearhand(struct cards777_pubdata *dp,struct cards777_handinfo *hand,struct cards777_privdata *priv); int32_t pangea_tableismine(struct supernet_info *myinfo,struct table_info *tp);
void pangea_create_newtable(char *retbuf,struct pangea_info *sp,struct cards777_pubdata *dp,uint64_t *isbot);
void pangea_buyins(uint32_t *minbuyinp,uint32_t *maxbuyinp); void pangea_checkantes(struct supernet_info *myinfo,struct table_info *tp);
int32_t pangea_sidepots(int32_t dispflag,uint64_t sidepots[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS],struct cards777_pubdata *dp,int64_t *bets); int32_t pangea_bet(struct supernet_info *myinfo,struct table_info *tp,struct player_info *player,int64_t bet,int32_t action);
int64_t pangea_splitpot(int64_t *won,uint64_t *pangearakep,uint64_t sidepot[CARDS777_MAXPLAYERS],union pangeanet777 *hn,int32_t rakemillis); int32_t pangea_sidepots(struct supernet_info *myinfo,struct table_info *tp,int32_t dispflag,int64_t sidepots[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS],int64_t *bets);
int32_t pangea_actives(int32_t *activej,struct cards777_pubdata *dp); int64_t pangea_splitpot(struct supernet_info *myinfo,struct table_info *tp,uint64_t *pangearakep,int64_t sidepot[CARDS777_MAXPLAYERS],int32_t rakemillis);
int32_t pangea_bet(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t player,int64_t bet,int32_t action);
uint64_t pangea_winnings(int32_t player,uint64_t *pangearakep,uint64_t *hostrakep,uint64_t total,int32_t numwinners,int32_t rakemillis,uint64_t maxrake); #define PANGEA_HANDARGS struct supernet_info *myinfo,struct pangea_msghdr *pm,struct table_info *tp,uint8_t *data,int32_t datalen
int32_t _pangea_addfunds(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind); #define PANGEA_HANDCALLARGS myinfo,pm,tp,data,datalen
void _pangea_chat(uint64_t senderbits,void *buf,int32_t len,int32_t senderind);
void pangea_tablecreate(PANGEA_HANDARGS);
void pangea_sendcmd(char *hex,union pangeanet777 *hn,char *cmdstr,int32_t destplayer,uint8_t *data,int32_t datalen,int32_t cardi,int32_t turni); void pangea_newhand(PANGEA_HANDARGS);
int32_t pangea_slotA(struct pangea_info *sp); void pangea_gotdeck(PANGEA_HANDARGS);
int32_t pangea_slotB(struct pangea_info *sp); void pangea_encoded(PANGEA_HANDARGS);
int32_t pangea_slot(struct pangea_info *sp,int32_t ind); void pangea_decoded(PANGEA_HANDARGS);
int32_t pangea_ind(struct pangea_info *sp,int32_t slot); void pangea_final(PANGEA_HANDARGS);
int32_t pangea_slot(struct pangea_info *sp,int32_t ind); void pangea_preflop(PANGEA_HANDARGS);
int32_t pangea_poll(uint64_t *senderbitsp,uint32_t *timestampp,union pangeanet777 *hn); void pangea_card(PANGEA_HANDARGS);
void pangea_facedown(PANGEA_HANDARGS);
int32_t pangeanet777_register(struct pangeanet777_server *srv,bits256 clientpub,int32_t slot); void pangea_faceup(PANGEA_HANDARGS);
struct pangeanet777_client *pangeanet777_client(bits256 privkey,bits256 pubkey,char *srvendpoint,int32_t slot); void pangea_turn(PANGEA_HANDARGS);
struct pangeanet777_server *pangeanet777_server(bits256 srvprivkey,bits256 srvpubkey,char *transport,char *ipaddr,uint16_t port,int32_t maxclients); void pangea_confirm(PANGEA_HANDARGS);
int32_t pangeanet777_idle(union pangeanet777 *hn); void pangea_action(PANGEA_HANDARGS);
void pangeanet777_msg(uint64_t destbits,bits256 destpub,union pangeanet777 *src,int32_t blindflag,char *jsonstr,int32_t len); void pangea_showdown(PANGEA_HANDARGS);
struct pangea_info *pangea_threadtables(int32_t *nump,int32_t threadid,uint64_t tableid); void pangea_summary(PANGEA_HANDARGS);
extern int32_t Debuglevel,PANGEA_MAXTHREADS,Showmode,Autofold; extern int32_t Debuglevel,PANGEA_MAXTHREADS,Showmode,Autofold;
bits256 issue_getpubkey(int32_t *haspubkeyp,char *acct);
#endif #endif

805
iguana/pangea_api.c

@ -13,36 +13,39 @@
* * * *
******************************************************************************/ ******************************************************************************/
#include "pangea777.h"
//struct acct777_sig { bits256 sigbits,pubkey; uint64_t signer64bits; uint32_t timestamp; };
struct pangea_msghdr /*
if ( pangeanet777_idle(hn) != 0 )
m++;
pangea_poll(&senderbits,&timestamp,hn);
dp = hn->client->H.pubdata;
if ( dp != 0 && hn->client->H.slot == pangea_slotA(dp->table) )
pinggap = 1;
if ( hn->client != 0 && dp != 0 )
{ {
struct acct777_sig sig __attribute__((packed)); if ( time(NULL) > hn->client->H.lastping + pinggap )
} __attribute__((packed)); {
if ( 0 && (dp= hn->client->H.pubdata) != 0 )
cJSON *pangea_lobbyjson(struct supernet_info *myinfo)
{ {
cJSON *retjson = cJSON_CreateObject(); pangea_sendcmd(hex,hn,"ping",-1,dp->hand.checkprod.bytes,sizeof(uint64_t),dp->hand.cardi,dp->hand.undergun);
return(retjson); hn->client->H.lastping = (uint32_t)time(NULL);
} }
}
int32_t pangea_updatemsg(struct supernet_info *myinfo,struct pangea_msghdr *pm,int32_t len) if ( dp->hand.handmask == ((1 << dp->N) - 1) && dp->hand.finished == 0 )//&& dp->hand.pangearake == 0 )
{ {
char str[65]; printf("PANGEA.(%s) sends %s\n",bits256_str(str,pm->sig.pubkey),pm->sig.serialized); PNACL_message("P%d: all players folded or showed cards at %ld | rakemillis %d\n",hn->client->H.slot,(long)time(NULL),dp->rakemillis);
return(0); pangea_finish(hn,dp);
} }
if ( hn->client->H.slot == pangea_slotA(dp->table) )
pangea_serverstate(hn,dp,hn->server->H.privdata);
}
*/
void pangea_update(struct supernet_info *myinfo) #include "pangea777.h"
{
struct category_msg *m; bits256 pangeahash; int32_t pangea_datalen(struct pangea_msghdr *pm)
pangeahash = calc_categoryhashes(0,"pangea",0);
while ( (m= category_gethexmsg(myinfo,pangeahash,GENESIS_PUBKEY)) != 0 )
{ {
pangea_updatemsg(myinfo,(struct pangea_msghdr *)m->msg,m->len); return((int32_t)(pm->sig.allocsize - sizeof(pm->sig) - sizeof(*pm)));
free(m);
}
} }
int32_t pangea_validate(struct pangea_msghdr *pm,bits256 privkey,bits256 pubkey) int32_t pangea_validate(struct pangea_msghdr *pm,bits256 privkey,bits256 pubkey)
@ -55,67 +58,310 @@ int32_t pangea_validate(struct pangea_msghdr *pm,bits256 privkey,bits256 pubkey)
return(-1); return(-1);
} }
struct pangea_msghdr *pangea_msgcreate(struct supernet_info *myinfo,uint8_t *space,bits256 tablehash,uint8_t *serialized,int32_t datalen) int32_t pangea_rwdata(int32_t rwflag,uint8_t *serialized,int32_t datalen,void *endianedp)
{ {
bits256 otherpubkey; uint32_t timestamp; struct pangea_msghdr *pm = (struct pangea_msghdr *)space; int32_t i,n,len = 0; uint64_t x; bits256 X;
memset(pm,0,sizeof(*pm)); if ( datalen <= sizeof(uint64_t) )
{
if ( rwflag != 0 )
memcpy(&x,endianedp,datalen);
iguana_rwnum(rwflag,&serialized[0],datalen,&x);
if ( rwflag == 0 )
memcpy(endianedp,&x,datalen);
}
else if ( datalen >= sizeof(bits256) && (datalen % sizeof(bits256)) == 0 )
{
n = (int32_t)(datalen / sizeof(bits256));
for (i=0; i<n; i++)
{
if ( rwflag != 0 )
memcpy(&X,&endianedp[len],sizeof(bits256));
len += iguana_rwbignum(1,&serialized[len],sizeof(bits256),&endianedp[len]);
if ( rwflag == 0 )
memcpy(&endianedp[len],&X,sizeof(bits256));
}
}
else
{
printf("pangea_sendcmd: unexpected datalen.%d mod.%ld\n",datalen,(datalen % sizeof(bits256)));
return(-1);
}
return(datalen);
}
struct pangea_msghdr *pangea_msgcreate(struct supernet_info *myinfo,bits256 tablehash,struct pangea_msghdr *pm,int32_t datalen)
{
bits256 otherpubkey; uint32_t timestamp; uint8_t buf[sizeof(pm->sig)],*serialized;
memset(&pm->sig,0,sizeof(pm->sig));
iguana_rwbignum(1,pm->tablehash.bytes,sizeof(bits256),tablehash.bytes);
datalen += (int32_t)(sizeof(*pm) - sizeof(pm->sig));
serialized = (void *)((long)pm + sizeof(pm->sig));
otherpubkey = acct777_msgpubkey(serialized,datalen); otherpubkey = acct777_msgpubkey(serialized,datalen);
if ( datalen > 0 )
memcpy(pm->sig.serialized,serialized,datalen);
timestamp = (uint32_t)time(NULL); timestamp = (uint32_t)time(NULL);
acct777_sign(&pm->sig,myinfo->privkey,otherpubkey,timestamp,serialized,datalen); acct777_sign(&pm->sig,myinfo->privkey,otherpubkey,timestamp,serialized,datalen);
if ( pangea_validate(pm,acct777_msgprivkey(serialized,datalen),pm->sig.pubkey) == 0 ) if ( pangea_validate(pm,acct777_msgprivkey(serialized,datalen),pm->sig.pubkey) == 0 )
{
memset(buf,0,sizeof(buf));
acct777_rwsig(1,buf,&pm->sig);
memcpy(&pm->sig,buf,sizeof(buf));
return(pm); return(pm);
else printf("error validating pangea msg\n"); } else printf("error validating pangea msg\n");
return(0); return(0);
} }
void pangea_sendcmd(char *hex,union pangeanet777 *hn,char *cmdstr,int32_t destplayer,uint8_t *data,int32_t datalen,int32_t cardi,int32_t turni) 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;
pangeahash = calc_categoryhashes(0,"pangea",0);
category_sub(myinfo,pangeahash,GENESIS_PUBKEY);
category_sub(myinfo,pangeahash,tablehash);
argjson = SuperNET_argjson(json);
jaddstr(argjson,"cmd","newtable");
jaddstr(argjson,"myipaddr",myinfo->ipaddr);
reqstr = jprint(argjson,1);
datalen = (int32_t)(strlen(reqstr) + 1);
memcpy(pm->serialized,reqstr,datalen);
free(reqstr);
if ( pangea_msgcreate(myinfo,tablehash,pm,datalen) != 0 )
{
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\"}"));
}
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)
{
struct player_info *p; struct pangea_msghdr *pm; char *str;
pm = (void *)tp->space;
memset(pm,0,sizeof(*pm));
strncpy(pm->cmd,cmdstr,8);
pm->turni = turni, pm->myind = tp->priv.myind, pm->cardi = cardi, pm->destplayer = destplayer;
pangea_rwdata(1,pm->serialized,datalen,data);
if ( pangea_msgcreate(myinfo,tp->G.tablehash,pm,datalen) != 0 )
{
if ( destplayer < 0 )
{
init_hexbytes_noT(tp->spacestr,(uint8_t *)pm,pm->sig.allocsize);
if ( (str= SuperNET_categorymulticast(myinfo,0,tp->G.gamehash,tp->G.tablehash,tp->spacestr,0,2,1)) != 0 )
free(str);
}
else if ( (p= tp->active[destplayer]) != 0 )
{
// encrypt here!
int32_t plaintext = 1; // for now
if ( (str= SuperNET_DHTsend(myinfo,p->ipbits,tp->G.gamehash,tp->G.tablehash,tp->spacestr,0,0,plaintext)) != 0 )
free(str);
}
}
}
void pangea_ping(PANGEA_HANDARGS)
{
}
void pangea_ready(PANGEA_HANDARGS)
{
}
void pangea_addfunds(PANGEA_HANDARGS)
{
}
void pangea_tablejoin(PANGEA_HANDARGS)
{ {
int32_t n,hexlen,blindflag = 0; uint64_t destbits; bits256 destpub; cJSON *json; char hoststr[1024]; struct pangea_info *sp; char str[65],str2[65],space[4096]; struct tai t; int32_t i,seconds; cJSON *json;
struct cards777_pubdata *dp = hn->client->H.pubdata; if ( tp->G.started != 0 )
hoststr[0] = 0;
sp = dp->table;
sprintf(hex,"{\"cmd\":\"%s\",\"turni\":%d,\"myslot\":%d,\"myind\":%d,\"cardi\":%d,\"dest\":%d,\"sender\":\"%llu\",\"timestamp\":\"%lu\",\"n\":%u,%s\"data\":\"",cmdstr,turni,hn->client->H.slot,pangea_ind(dp->table,hn->client->H.slot),cardi,destplayer,(long long)hn->client->H.nxt64bits,(long)time(NULL),datalen,hoststr);
n = (int32_t)strlen(hex);
if ( strcmp(cmdstr,"preflop") == 0 )
{ {
memcpy(&hex[n],data,datalen+1); OS_conv_unixtime(&t,&seconds,tp->G.finished == 0 ? tp->G.started : tp->G.finished);
hexlen = (int32_t)strlen(hex)+1; printf("table.(%s) already %s %s\n",bits256_str(str,pm->tablehash),tp->G.finished == 0 ? "started" : "finished",utc_str(str2,t));
PNACL_message("P%d HEX.[] hexlen.%d n.%d\n",hn->server->H.slot,hexlen,datalen);
} }
else if ( data != 0 && datalen != 0 ) else if ( tp->G.numactive >= tp->G.maxplayers )
init_hexbytes_noT(&hex[n],data,datalen);
strcat(hex,"\"}");
if ( (json= cJSON_Parse(hex)) == 0 )
{ {
PNACL_message("error creating json\n"); printf("table.(%s) numactive.%d >= max.%d\n",bits256_str(str,pm->tablehash),tp->G.numactive,tp->G.maxplayers);
return;
} }
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 )
{
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("pending join of %llu table.(%s)\n",(long long)pm->sig.signer64bits,bits256_str(str,pm->tablehash));
free_json(json); free_json(json);
hexlen = (int32_t)strlen(hex)+1; } else printf("tablejoin cant parse json\n");
//PNACL_message("HEX.[%s] hexlen.%d n.%d\n",hex,hexlen,datalen); }
if ( destplayer < 0 )//|| ((1LL << destplayer) & dp->pmworks) == 0 )
int32_t pangea_allocsize(struct table_info *tp,int32_t setptrs)
{
long allocsize = sizeof(*tp); int32_t N,numcards = tp->G.numcards;
N = tp->G.numactive;
allocsize += sizeof(bits256) * (2 * ((N * numcards * N) + (N * numcards)));
allocsize += sizeof(bits256) * ((numcards + 1) + (N * numcards));
if ( setptrs != 0 )
{ {
destbits = 0; tp->hand.cardpubs = tp->priv.data;
memset(destpub.bytes,0,sizeof(destpub)); tp->hand.final = &tp->hand.cardpubs[numcards + 1 + N];
//PNACL_message("T%d broadcasts %d\n",hn->client->H.slot,hexlen); tp->priv.audits = &tp->hand.final[N * numcards];
tp->priv.outcards = &tp->priv.audits[N * numcards * N];
tp->priv.xoverz = &tp->priv.outcards[N * numcards];
tp->priv.allshares = (void *)&tp->priv.xoverz[N * numcards]; // N*numcards*N
} }
else return((int32_t)allocsize);
}
struct table_info *pangea_tablealloc(struct table_info *tp)
{ {
destpub = sp->playerpubs[pangea_slot(sp,destplayer)]; int32_t allocsize = pangea_allocsize(tp,0);
destbits = acct777_nxt64bits(destpub); if ( tp->G.allocsize != allocsize )
//PNACL_message("T%d sends %d to dest.%d\n",hn->client->H.slot,hexlen,destplayer); {
tp = realloc(tp,allocsize);
pangea_allocsize(tp,1);
} }
pangeanet777_msg(destbits,destpub,hn,blindflag,hex,hexlen); return(tp);
} }
char *_pangea_status(uint64_t my64bits,uint64_t tableid,cJSON *json) 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;
ipaddr[0] = 0;
if ( pm->sig.signer64bits == tp->G.creatorbits && tp->G.numactive < tp->G.maxplayers )
{
if ( (json= cJSON_Parse((char *)pm->serialized)) != 0 )
{
if ( pangea_playerparse(&p,json) == 0 )
{
p.nxt64bits = pm->sig.signer64bits;
tp->G.P[tp->G.numactive++] = p;
if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits )
{ {
int32_t i,j,threadid = juint(json,"threadid"); struct pangea_info *sp; cJSON *item,*array=0,*retjson = 0; expand_ipbits(ipaddr,p.ipbits);
if ( tableid != 0 ) printf("connect to new player.(%s)\n",ipaddr);
}
else if ( pm->sig.signer64bits == myinfo->myaddr.nxt64bits )
{ {
if ( (sp= pangea_find(tableid,threadid)) != 0 ) 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);
if ( ipbits != 0 )
{
coin = iguana_coinfind("BTCD");
if ( (addr= iguana_peerslot(coin,ipbits,1)) == 0 )
{
iguana_peerkill(coin);
sleep(3);
addr = iguana_peerslot(coin,ipbits,1);
}
if ( addr != 0 )
{
if ( addr->usock < 0 )
{
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
printf("launch start connection to (%s)\n",ipaddr);
} else printf("already connected\n");
} 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);
}
}
}
}
}
void pangea_tablecreate(PANGEA_HANDARGS)
{
cJSON *json;
if ( tp->G.gamehash.txid != 0 )
{
char str[65]; printf("table.(%s) already exists\n",bits256_str(str,pm->tablehash));
}
else if ( (json= cJSON_Parse((char *)pm->serialized)) != 0 )
{
pangea_gamecreate(&tp->G,pm->sig.timestamp,pm->tablehash,json);
tp->G.creatorbits = pm->sig.signer64bits;
free_json(json);
}
}
void pangea_update(struct supernet_info *myinfo)
{
static struct { char *cmdstr; void (*func)(PANGEA_HANDARGS); uint64_t cmdbits; } tablecmds[] =
{
{ "newtable", pangea_tablecreate }, { "join", pangea_tablejoin },
{ "accept", pangea_tableaccept }, { "addfunds", pangea_addfunds },
{ "newhand", pangea_newhand }, { "ping", pangea_ping },
{ "gotdeck", pangea_gotdeck }, { "ready", pangea_ready },
{ "encoded", pangea_encoded }, { "decoded", pangea_decoded },
{ "final", pangea_final }, { "preflop", pangea_preflop },
{ "card", pangea_card }, { "facedown", pangea_facedown }, { "faceup", pangea_faceup },
{ "turn", pangea_turn }, { "confirm", pangea_confirm }, { "action", pangea_action },
{ "showdown", pangea_showdown }, { "summary", pangea_summary },
};
struct category_msg *m; bits256 pangeahash,tablehash; struct pangea_msghdr *pm; int32_t i,allocsize;
uint64_t cmdbits; char str[65]; struct table_info *tp; uint8_t buf[sizeof(pm->sig)];
if ( tablecmds[0].cmdbits == 0 )
{
for (i=0; i<sizeof(tablecmds)/sizeof(*tablecmds); i++)
tablecmds[i].cmdbits = stringbits(tablecmds[i].cmdstr);
}
pangeahash = calc_categoryhashes(0,"pangea",0);
while ( (m= category_gethexmsg(myinfo,pangeahash,GENESIS_PUBKEY)) != 0 )
{
pm = (struct pangea_msghdr *)m->msg;
acct777_rwsig(0,(void *)&pm->sig,(void *)buf), memcpy(&pm->sig,buf,sizeof(pm->sig));
iguana_rwbignum(0,pm->tablehash.bytes,sizeof(bits256),tablehash.bytes);
pm->tablehash = tablehash;
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));
else 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;
}
if ( tp != 0 && pangea_rwdata(0,pm->serialized,pangea_datalen(pm),pm->serialized) > 0 )
{
cmdbits = stringbits(pm->cmd);
for (i=0; i<sizeof(tablecmds)/sizeof(*tablecmds); i++)
{
if ( tablecmds[i].cmdbits == cmdbits )
{
(*tablecmds[i].func)(myinfo,pm,tp,pm->serialized,(int32_t)(pm->sig.allocsize - sizeof(*pm)));
break;
}
}
}
free(m);
}
}
/*
char *_pangea_status(struct supernet_info *myinfo,bits256 tablehash,cJSON *json)
{
int32_t i,j,threadid = juint(json,"threadid"); struct pangea_info *sp;
cJSON *item,*array=0,*retjson = 0; uint64_t my64bits = myinfo->myaddr.nxt64bits;
if ( tablehash.txid != 0 )
{
if ( (sp= pangea_find(tablehash.txid,threadid)) != 0 )
{ {
if ( (item= pangea_tablestatus(sp)) != 0 ) if ( (item= pangea_tablestatus(sp)) != 0 )
{ {
@ -158,75 +404,22 @@ char *_pangea_status(uint64_t my64bits,uint64_t tableid,cJSON *json)
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
/*int32_t pangea_idle(struct supernet_info *plugin) char *_pangea_history(struct supernet_info *myinfo,bits256 tablehash,cJSON *json)
{
int32_t i,n,m,pinggap = 1; uint64_t senderbits; uint32_t timestamp; struct pangea_thread *tp; union pangeanet777 *hn;
struct cards777_pubdata *dp; char hex[1024];
while ( 1 )
{
for (i=n=m=0; i<_PANGEA_MAXTHREADS; i++)
{
if ( (tp= THREADS[i]) != 0 )
{
hn = &tp->hn;
//PNACL_message("pangea idle player.%d\n",hn->client->H.slot);
if ( hn->client->H.done == 0 )
{
n++;
if ( pangeanet777_idle(hn) != 0 )
m++;
pangea_poll(&senderbits,&timestamp,hn);
dp = hn->client->H.pubdata;
if ( dp != 0 && hn->client->H.slot == pangea_slotA(dp->table) )
pinggap = 1;
if ( hn->client != 0 && dp != 0 )
{
if ( time(NULL) > hn->client->H.lastping + pinggap )
{
if ( 0 && (dp= hn->client->H.pubdata) != 0 )
{
pangea_sendcmd(hex,hn,"ping",-1,dp->hand.checkprod.bytes,sizeof(uint64_t),dp->hand.cardi,dp->hand.undergun);
hn->client->H.lastping = (uint32_t)time(NULL);
}
}
if ( dp->hand.handmask == ((1 << dp->N) - 1) && dp->hand.finished == 0 )//&& dp->hand.pangearake == 0 )
{
PNACL_message("P%d: all players folded or showed cards at %ld | rakemillis %d\n",hn->client->H.slot,(long)time(NULL),dp->rakemillis);
pangea_finish(hn,dp);
}
if ( hn->client->H.slot == pangea_slotA(dp->table) )
pangea_serverstate(hn,dp,hn->server->H.privdata);
}
}
}
}
if ( n == 0 )
break;
if ( m == 0 )
usleep(3000);
}
//for (i=0; i<_PANGEA_MAXTHREADS; i++)
// if ( THREADS[i] != 0 && Pangea_waiting != 0 )
// pangea_userpoll(&THREADS[i]->hn);
return(0);
}*/
char *_pangea_history(uint64_t my64bits,uint64_t tableid,cJSON *json)
{ {
struct pangea_info *sp; struct pangea_info *sp;
if ( (sp= pangea_find64(tableid,my64bits)) != 0 && sp->dp != 0 ) if ( (sp= pangea_find64(tablehash.txid,myinfo->myaddr.nxt64bits)) != 0 && sp->dp != 0 )
{ {
if ( jobj(json,"handid") == 0 ) if ( jobj(json,"handid") == 0 )
return(pangea_dispsummary(sp,juint(json,"verbose"),sp->dp->summary,sp->dp->summarysize,tableid,sp->dp->numhands-1,sp->dp->N)); return(pangea_dispsummary(sp,juint(json,"verbose"),sp->dp->summary,sp->dp->summarysize,tablehash.txid,sp->dp->numhands-1,sp->dp->N));
else return(pangea_dispsummary(sp,juint(json,"verbose"),sp->dp->summary,sp->dp->summarysize,tableid,juint(json,"handid"),sp->dp->N)); else return(pangea_dispsummary(sp,juint(json,"verbose"),sp->dp->summary,sp->dp->summarysize,tablehash.txid,juint(json,"handid"),sp->dp->N));
} }
return(clonestr("{\"error\":\"cant find tableid\"}")); return(clonestr("{\"error\":\"cant find tableid\"}"));
} }
char *_pangea_buyin(uint64_t my64bits,uint64_t tableid,cJSON *json) char *_pangea_buyin(struct supernet_info *myinfo,bits256 tablehash,cJSON *json)
{ {
struct pangea_info *sp; uint32_t buyin,vout; uint64_t amount = 0; char hex[1024],jsonstr[1024],*txidstr,*destaddr; struct pangea_info *sp; uint32_t buyin,vout; uint64_t amount = 0; char hex[1024],jsonstr[1024],*txidstr,*destaddr;
if ( (sp= pangea_find64(tableid,my64bits)) != 0 && sp->dp != 0 && sp->tp != 0 && (amount= j64bits(json,"amount")) != 0 ) if ( (sp= pangea_find64(tablehash.txid,myinfo->myaddr.nxt64bits)) != 0 && sp->dp != 0 && sp->tp != 0 && (amount= j64bits(json,"amount")) != 0 )
{ {
buyin = (uint32_t)(amount / sp->dp->bigblind); buyin = (uint32_t)(amount / sp->dp->bigblind);
PNACL_message("buyin.%u amount %.8f -> %.8f\n",buyin,dstr(amount),dstr(buyin * sp->bigblind)); PNACL_message("buyin.%u amount %.8f -> %.8f\n",buyin,dstr(amount),dstr(buyin * sp->bigblind));
@ -237,9 +430,8 @@ char *_pangea_buyin(uint64_t my64bits,uint64_t tableid,cJSON *json)
{ {
vout = juint(json,"vout"); vout = juint(json,"vout");
sprintf(jsonstr,"{\"txid\":\"%s\",\"vout\":%u,\"msig\":\"%s\",\"amount\":%.8f}",txidstr,vout,sp->multisigaddr,dstr(amount)); sprintf(jsonstr,"{\"txid\":\"%s\",\"vout\":%u,\"msig\":\"%s\",\"amount\":%.8f}",txidstr,vout,sp->multisigaddr,dstr(amount));
pangea_sendcmd(hex,&sp->tp->hn,"addfunds",-1,(void *)jsonstr,(int32_t)strlen(jsonstr)+1,pangea_ind(sp,sp->myslot),-1); pangea_sendcmd(PANGEA_ARGS,"addfunds",-1,(void *)jsonstr,(int32_t)strlen(jsonstr)+1,pangea_ind(sp,sp->myslot),-1);
} else pangea_sendcmd(hex,&sp->tp->hn,"addfunds",-1,(void *)&amount,sizeof(amount),pangea_ind(sp,sp->myslot),-1); } else pangea_sendcmd(PANGEA_ARGS,"addfunds",-1,(void *)&amount,sizeof(amount),pangea_ind(sp,sp->myslot),-1);
//pangea_sendcmd(hex,&sp->tp->hn,"addfunds",0,(void *)&amount,sizeof(amount),pangea_ind(sp,sp->myslot),-1);
return(clonestr("{\"result\":\"buyin sent\"}")); return(clonestr("{\"result\":\"buyin sent\"}"));
} }
else else
@ -251,348 +443,57 @@ char *_pangea_buyin(uint64_t my64bits,uint64_t tableid,cJSON *json)
return(clonestr("{\"error\":\"cant buyin unless you are part of the table\"}")); return(clonestr("{\"error\":\"cant buyin unless you are part of the table\"}"));
} }
char *_pangea_mode(uint64_t my64bits,uint64_t tableid,cJSON *json)
char *_pangea_mode(struct supernet_info *myinfo,bits256 tablehash,cJSON *json)
{ {
struct pangea_info *sp; char *chatstr,hex[8192]; int32_t i; uint64_t pm; struct pangea_info *sp;
if ( jobj(json,"automuck") != 0 ) if ( jobj(json,"automuck") != 0 )
{ {
if ( tableid == 0 ) if ( tablehash.txid == 0 )
Showmode = juint(json,"automuck"); Showmode = juint(json,"automuck");
else if ( (sp= pangea_find64(tableid,my64bits)) != 0 && sp->priv != 0 ) else if ( (sp= pangea_find64(tablehash.txid,myinfo->myaddr.nxt64bits)) != 0 && sp->priv != 0 )
sp->priv->automuck = juint(json,"automuck"); sp->priv->automuck = juint(json,"automuck");
else return(clonestr("{\"error\":\"automuck not tableid or sp->priv\"}")); else return(clonestr("{\"error\":\"automuck not tableid or sp->priv\"}"));
return(clonestr("{\"result\":\"set automuck mode\"}")); return(clonestr("{\"result\":\"set automuck mode\"}"));
} }
else if ( jobj(json,"autofold") != 0 ) else if ( jobj(json,"autofold") != 0 )
{ {
if ( tableid == 0 ) if ( tablehash.txid == 0 )
Autofold = juint(json,"autofold"); Autofold = juint(json,"autofold");
else if ( (sp= pangea_find64(tableid,my64bits)) != 0 && sp->priv != 0 ) else if ( (sp= pangea_find64(tablehash.txid,myinfo->myaddr.nxt64bits)) != 0 && sp->priv != 0 )
sp->priv->autofold = juint(json,"autofold"); sp->priv->autofold = juint(json,"autofold");
else return(clonestr("{\"error\":\"autofold not tableid or sp->priv\"}")); else return(clonestr("{\"error\":\"autofold not tableid or sp->priv\"}"));
return(clonestr("{\"result\":\"set autofold mode\"}")); return(clonestr("{\"result\":\"set autofold mode\"}"));
} }
else if ( (sp= pangea_find64(tableid,my64bits)) != 0 && (chatstr= jstr(json,"chat")) != 0 && strlen(chatstr) < 256 )
{
if ( 0 && (pm= j64bits(json,"pm")) != 0 )
{
for (i=0; i<sp->numaddrs; i++)
if ( sp->addrs[i] == pm )
break;
if ( i == sp->numaddrs )
return(clonestr("{\"error\":\"specified pm destination not at table\"}"));
} else i = -1;
pangea_sendcmd(hex,&sp->tp->hn,"chat",i,(void *)chatstr,(int32_t)strlen(chatstr)+1,pangea_ind(sp,sp->myslot),-1);
return(clonestr("{\"result\":\"chat message sent\"}"));
}
return(clonestr("{\"error\":\"unknown pangea mode\"}")); return(clonestr("{\"error\":\"unknown pangea mode\"}"));
}
void _pangea_chat(uint64_t senderbits,void *buf,int32_t len,int32_t senderind)
{
PNACL_message(">>>>>>>>>>> CHAT FROM.%d %llu: (%s)\n",senderind,(long long)senderbits,(char *)buf);
}
/*
else if ( strcmp(methodstr,"newtable") == 0 )
retstr = pangea_newtable(juint(json,"threadid"),json,plugin->nxt64bits,*(bits256 *)plugin->mypriv,*(bits256 *)plugin->mypub,plugin->transport,plugin->ipaddr,plugin->pangeaport,juint(json,"minbuyin"),juint(json,"maxbuyin"),juint(json,"rakemillis"));
else if ( sender == 0 || sender[0] == 0 )
{
if ( strcmp(methodstr,"start") == 0 )
{
strcpy(retbuf,"{\"result\":\"start issued\"}");
if ( (base= jstr(json,"base")) != 0 )
{
if ( (maxplayers= juint(json,"maxplayers")) < 2 )
maxplayers = 2;
else if ( maxplayers > CARDS777_MAXPLAYERS )
maxplayers = CARDS777_MAXPLAYERS;
if ( jstr(json,"resubmit") == 0 )
sprintf(retbuf,"{\"resubmit\":[{\"method\":\"start\"}, {\"bigblind\":\"%llu\"}, {\"ante\":\"%llu\"}, {\"rakemillis\":\"%u\"}, {\"maxplayers\":%d}, {\"minbuyin\":%d}, {\"maxbuyin\":%d}],\"pluginrequest\":\"SuperNET\",\"plugin\":\"InstantDEX\",\"method\":\"orderbook\",\"base\":\"%s\",\"exchange\":\"pangea\",\"allfields\":1}",(long long)j64bits(json,"bigblind"),(long long)j64bits(json,"ante"),juint(json,"rakemillis"),maxplayers,juint(json,"minbuyin"),juint(json,"maxbuyin"),jstr(json,"base")!=0?jstr(json,"base"):"BTCD");
else if ( pangea_start(plugin,retbuf,base,0,j64bits(json,"bigblind"),j64bits(json,"ante"),juint(json,"rakemillis"),maxplayers,juint(json,"minbuyin"),juint(json,"maxbuyin"),json) < 0 )
;
} else strcpy(retbuf,"{\"error\":\"no base specified\"}");
}
else if ( strcmp(methodstr,"status") == 0 )
retstr = pangea_status(plugin->nxt64bits,j64bits(json,"tableid"),json);
}
int32_t pangea_unzbuf(uint8_t *buf,char *hexstr,int32_t len)
{
int32_t i,j,len2;
for (len2=i=0; i<len; i+=2)
{
if ( hexstr[i] == 'Z' )
{
for (j=0; j<hexstr[i+1]-'A'; j++)
buf[len2++] = 0;
}
else buf[len2++] = _decode_hex(&hexstr[i]);
}
//char *tmp = calloc(1,len*2+1);
//init_hexbytes_noT(tmp,buf,len2);
//PostMessage("zlen %d to len2 %d\n",len,len2);
//free(tmp);
return(len2);
}
int32_t pangea_poll(uint64_t *senderbitsp,uint32_t *timestampp,union hostnet777 *hn)
{
char *jsonstr,*hexstr,*cmdstr; cJSON *json; struct cards777_privdata *priv; struct cards777_pubdata *dp; struct pangea_info *sp;
int32_t len,senderind,maxlen; uint8_t *buf;
*senderbitsp = 0;
dp = hn->client->H.pubdata, sp = dp->table;
priv = hn->client->H.privdata;
if ( hn == 0 || hn->client == 0 || dp == 0 || priv == 0 )
{
if ( Debuglevel > 2 )
PNACL_message("pangea_poll: null hn.%p %p dp.%p priv.%p\n",hn,hn!=0?hn->client:0,dp,priv);
return(-1);
}
maxlen = (int32_t)(sizeof(bits256) * dp->N*dp->N*dp->numcards);
if ( (buf= malloc(maxlen)) == 0 )
{
PNACL_message("pangea_poll: null buf\n");
return(-1);
}
if ( dp != 0 && priv != 0 && (jsonstr= queue_dequeue(&hn->client->H.Q,1)) != 0 )
{
//pangea_neworder(dp,dp->table,0,0);
//PNACL_message("player.%d GOT.(%s)\n",hn->client->H.slot,jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
*senderbitsp = j64bits(json,"sender");
if ( (senderind= juint(json,"myind")) < 0 || senderind >= dp->N )
{
PNACL_message("pangea_poll: illegal senderind.%d cardi.%d turni.%d (%s)\n",senderind,juint(json,"cardi"),juint(json,"turni"),jsonstr);
goto cleanup;
}
*timestampp = juint(json,"timestamp");
hn->client->H.state = juint(json,"state");
len = juint(json,"n");
cmdstr = jstr(json,"cmd");
if ( sp->myind < 0 )
{
// check for reactivation command
goto cleanup;
}
if ( cmdstr != 0 && strcmp(cmdstr,"preflop") == 0 )
{
if ( (hexstr= jstr(json,"data")) != 0 )
len = pangea_unzbuf(buf,hexstr,len);
}
else if ( (hexstr= jstr(json,"data")) != 0 && strlen(hexstr) == (len<<1) )
{
if ( len > maxlen )
{
PNACL_message("len too big for pangea_poll\n");
goto cleanup;
}
decode_hex(buf,len,hexstr);
} else if ( hexstr != 0 )
PNACL_message("len.%d vs hexlen.%ld (%s)\n",len,(long)(strlen(hexstr)>>1),hexstr);
if ( cmdstr != 0 )
{
if ( strcmp(cmdstr,"newhand") == 0 )
pangea_newhand(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"ping") == 0 )
pangea_ping(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"gotdeck") == 0 )
pangea_gotdeck(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"ready") == 0 )
pangea_ready(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"encoded") == 0 )
pangea_encoded(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"final") == 0 )
pangea_final(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"addfunds") == 0 )
pangea_addfunds(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"preflop") == 0 )
pangea_preflop(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"decoded") == 0 )
pangea_decoded(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"card") == 0 )
pangea_card(hn,json,dp,priv,buf,len,juint(json,"cardi"),senderind);
else if ( strcmp(cmdstr,"facedown") == 0 )
pangea_facedown(hn,json,dp,priv,buf,len,juint(json,"cardi"),senderind);
else if ( strcmp(cmdstr,"faceup") == 0 )
pangea_faceup(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"turn") == 0 )
pangea_turn(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"confirmturn") == 0 )
pangea_confirmturn(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"chat") == 0 )
pangea_chat(*senderbitsp,buf,len,senderind);
else if ( strcmp(cmdstr,"action") == 0 )
pangea_action(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"showdown") == 0 )
pangea_showdown(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"summary") == 0 )
pangea_gotsummary(hn,json,dp,priv,buf,len,senderind);
}
cleanup:
free_json(json);
}
free_queueitem(jsonstr);
}
free(buf);
return(hn->client->H.state);
}*/ }*/
char *Pangea_bypass(uint64_t my64bits,uint8_t myprivkey[32],cJSON *json)
{
char *methodstr,*retstr = 0;
if ( (methodstr= jstr(json,"method")) != 0 )
{
if ( strcmp(methodstr,"turn") == 0 )
retstr = _pangea_input(my64bits,j64bits(json,"tableid"),json);
else if ( strcmp(methodstr,"status") == 0 )
retstr = _pangea_status(my64bits,j64bits(json,"tableid"),json);
else if ( strcmp(methodstr,"mode") == 0 )
retstr = _pangea_mode(my64bits,j64bits(json,"tableid"),json);
//else if ( strcmp(methodstr,"rosetta") == 0 )
// retstr = pangea_univ(myprivkey,json);
else if ( strcmp(methodstr,"buyin") == 0 )
retstr = _pangea_buyin(my64bits,j64bits(json,"tableid"),json);
else if ( strcmp(methodstr,"history") == 0 )
retstr = _pangea_history(my64bits,j64bits(json,"tableid"),json);
}
return(retstr);
}
#include "../includes/iguana_apidefs.h" #include "../includes/iguana_apidefs.h"
INT_AND_ARRAY(pangea,newhand,senderind,params) /*HASH_AND_ARRAY(pangea,turn,tablehash,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,ping,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,gotdeck,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,ready,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,encoded,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,final,senderind,params)
{ {
cJSON *retjson = cJSON_CreateObject(); return(_pangea_turn(myinfo,tablehash,json));
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,addedfunds,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,preflop,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,decoded,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,card,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,facedown,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,faceup,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,turn,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,confirmturn,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,chat,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,action,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,showdown,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
INT_AND_ARRAY(pangea,handsummary,senderind,params)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
} }
HASH_AND_ARRAY(pangea,status,tablehash,params) HASH_AND_ARRAY(pangea,status,tablehash,params)
{ {
cJSON *retjson = cJSON_CreateObject(); return(_pangea_status(myinfo,tablehash,json));
return(jprint(retjson,1));
} }
HASH_AND_ARRAY(pangea,mode,tablehash,params) HASH_AND_ARRAY(pangea,mode,tablehash,params)
{ {
cJSON *retjson = cJSON_CreateObject(); return(_pangea_mode(myinfo,tablehash,json));
return(jprint(retjson,1));
} }
HASH_AND_ARRAY(pangea,buyin,tablehash,params) HASH_AND_ARRAY(pangea,buyin,tablehash,params)
{ {
cJSON *retjson = cJSON_CreateObject(); return(_pangea_buyin(myinfo,tablehash,json));
return(jprint(retjson,1));
} }
HASH_AND_ARRAY(pangea,history,tablehash,params) HASH_AND_ARRAY(pangea,history,tablehash,params)
{ {
cJSON *retjson = cJSON_CreateObject(); return(_pangea_history(myinfo,tablehash,json));
return(jprint(retjson,1)); }*/
}
ZERO_ARGS(pangea,lobby) ZERO_ARGS(pangea,lobby)
{ {
@ -604,57 +505,15 @@ ZERO_ARGS(pangea,lobby)
INT_AND_ARRAY(pangea,host,minplayers,params) INT_AND_ARRAY(pangea,host,minplayers,params)
{ {
cJSON *retjson,*argjson; char *str,hexstr[1024],*reqstr; bits256 tablehash; uint8_t space[sizeof(struct pangea_msghdr) + 4096];
bits256 pangeahash,tablehash; struct pangea_msghdr *pm; uint8_t space[sizeof(*pm) + 512];
pangeahash = calc_categoryhashes(0,"pangea",0);
OS_randombytes(tablehash.bytes,sizeof(tablehash)); OS_randombytes(tablehash.bytes,sizeof(tablehash));
category_sub(myinfo,pangeahash,GENESIS_PUBKEY); return(pangea_jsondatacmd(myinfo,tablehash,(struct pangea_msghdr *)space,json,"host",myinfo->ipaddr));
category_sub(myinfo,pangeahash,tablehash);
argjson = cJSON_CreateObject();
jaddbits256(argjson,"newtable",tablehash);
jaddnum(argjson,"minplayers",minplayers);
jaddstr(argjson,"myipaddr",myinfo->ipaddr);
reqstr = jprint(argjson,1);
if ( (pm= pangea_msgcreate(myinfo,space,tablehash,(void *)reqstr,(int32_t)strlen(reqstr)+1)) != 0 )
{
free(reqstr);
init_hexbytes_noT(hexstr,(uint8_t *)pm,pm->sig.allocsize);
str = SuperNET_categorymulticast(myinfo,0,pangeahash,GENESIS_PUBKEY,hexstr,0,1,1);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","table created");
jaddstr(retjson,"multicast",str);
jaddbits256(retjson,"tablehash",tablehash);
return(jprint(retjson,1));
}
else
{
free(reqstr);
return(clonestr("{\"error\":\"couldnt create pangea message\"}"));
}
} }
HASH_AND_ARRAY(pangea,join,tablehash,params) HASH_AND_ARRAY(pangea,join,tablehash,params)
{ {
cJSON *argjson; char hexstr[512],*reqstr; uint8_t space[sizeof(struct pangea_msghdr) + 4096];
bits256 pangeahash; struct pangea_msghdr *pm; uint8_t space[sizeof(*pm) + 512]; return(pangea_jsondatacmd(myinfo,tablehash,(struct pangea_msghdr *)space,json,"join",myinfo->ipaddr));
pangeahash = calc_categoryhashes(0,"pangea",0);
category_sub(myinfo,pangeahash,GENESIS_PUBKEY);
category_sub(myinfo,pangeahash,tablehash);
argjson = cJSON_CreateObject();
jaddbits256(argjson,"join",tablehash);
jaddstr(argjson,"myipaddr",myinfo->ipaddr);
reqstr = jprint(argjson,1);
if ( (pm= pangea_msgcreate(myinfo,space,tablehash,(void *)reqstr,(int32_t)strlen(reqstr))) != 0 )
{
free(reqstr);
init_hexbytes_noT(hexstr,(uint8_t *)pm,pm->sig.allocsize);
return(SuperNET_categorymulticast(myinfo,0,pangeahash,tablehash,hexstr,0,1,1));
}
else
{
free(reqstr);
return(clonestr("{\"error\":\"couldnt create pangea message\"}"));
}
} }
#undef IGUANA_ARGS #undef IGUANA_ARGS

387
iguana/pangea_bets.c

@ -0,0 +1,387 @@
/******************************************************************************
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "pangea777.h"
void pangea_fold(struct supernet_info *myinfo,struct table_info *tp,struct player_info *player)
{
uint8_t tmp;
//printf("player.%d folded\n",player); //getchar();
tp->hand.handmask |= (1 << player->ind);
player->betstatus = CARDS777_FOLD;
player->action = CARDS777_FOLD;
tmp = player->ind;
pangea_summaryadd(myinfo,tp,CARDS777_FOLD,&tmp,sizeof(tmp),(void *)&player->bets,sizeof(player->bets));
}
int32_t pangea_bet(struct supernet_info *myinfo,struct table_info *tp,struct player_info *player,int64_t bet,int32_t action)
{
uint64_t sum; uint8_t tmp; struct hand_info *hand = &tp->hand;
if ( Debuglevel > 2 )
printf("PANGEA_BET[%d] <- %.8f\n",player->ind,dstr(bet));
if ( player->betstatus == CARDS777_ALLIN )
return(CARDS777_ALLIN);
else if ( player->betstatus == CARDS777_FOLD )
return(CARDS777_FOLD);
if ( bet > 0 && bet >= player->balance )
{
bet = player->balance;
player->betstatus = action = CARDS777_ALLIN;
}
else
{
if ( bet > hand->betsize && bet > hand->lastraise && bet < (hand->lastraise<<1) )
{
printf("pangea_bet %.8f not double %.8f, clip to lastraise\n",dstr(bet),dstr(hand->lastraise));
bet = hand->lastraise;
action = CARDS777_RAISE;
}
}
sum = player->bets;
if ( sum+bet < hand->betsize && action != CARDS777_ALLIN )
{
pangea_fold(myinfo,tp,player);
action = CARDS777_FOLD;
if ( Debuglevel > 2 )
printf("player.%d betsize %.8f < hand.betsize %.8f FOLD\n",player->ind,dstr(bet),dstr(hand->betsize));
return(action);
}
else if ( bet >= 2*hand->lastraise )
{
hand->lastraise = bet;
hand->numactions = 0;
if ( action == CARDS777_CHECK )
{
action = CARDS777_FULLRAISE; // allows all players to check/bet again
if ( Debuglevel > 2 )
printf("FULLRAISE by player.%d\n",player->ind);
}
}
sum += bet;
if ( sum > hand->betsize )
{
hand->numactions = 0;
hand->betsize = sum, hand->lastbettor = player->ind;
if ( sum > hand->lastraise && action == CARDS777_ALLIN )
hand->lastraise = sum;
else if ( action == CARDS777_CHECK )
action = CARDS777_BET;
}
if ( bet > 0 && action == CARDS777_CHECK )
action = CARDS777_CALL;
tmp = player->ind;
pangea_summaryadd(myinfo,tp,action,&tmp,sizeof(tmp),(void *)&bet,sizeof(bet));
player->balance -= bet, player->bets += bet;
if ( Debuglevel > 2 )
printf("player.%d: player.%d BET %f -> balances %f bets %f\n",tp->myind,player->ind,dstr(bet),dstr(player->balance),dstr(player->bets));
return(action);
}
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;
N = tp->numactive;
for (i=0; i<tp->G.N; i++)
{
tp->G.P[i].ind = i;
if ( (tp->snapshot[i]= tp->G.P[i].balance) <= 0 )
pangea_fold(myinfo,tp,&tp->G.P[i]);
}
handid = tp->numhands - 1;
pangea_summaryadd(myinfo,tp,CARDS777_SNAPSHOT,(void *)&handid,sizeof(handid),(void *)tp->snapshot,sizeof(uint64_t)*CARDS777_MAXPLAYERS);
if ( tp->G.ante != 0 )
{
for (i=0; i<N; i++)
{
if ( (p= tp->active[i]) != 0 )
{
if ( p->balance < tp->G.ante )
pangea_fold(myinfo,tp,p);
else pangea_bet(myinfo,tp,p,tp->G.ante,CARDS777_ANTE);
} else printf("unexpected null player ptr\n");
}
}
for (i=n=0; i<N; i++)
{
if ( i == 0 )
threshold = (tp->G.bigblind >> 1) - 1;
else if ( i == 1 )
threshold = tp->G.bigblind - 1;
else threshold = 0;
if ( (p= tp->active[i]) != 0 && p->balance < threshold )
pangea_fold(myinfo,tp,p);
else n++;
}
if ( n < 2 )
printf("pangea_antes not enough players n.%d\n",n);
else
{
pangea_bet(myinfo,tp,tp->active[0],(tp->G.bigblind>>1),CARDS777_SMALLBLIND);
pangea_bet(myinfo,tp,tp->active[1],tp->G.bigblind,CARDS777_BIGBLIND);
}
}
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;
pangea_snapshot(tp,bets);
for (i=0; i<N; i++)
{
//printf("%.8f ",dstr(dp->balances[i]));
if ( bets[i] != 0 )
break;
}
if ( i == N && hand->checkprod.txid != 0 )
{
for (i=0; i<N; i++)
if ( bets[i] != 0 )
break;
if ( i == N )
{
//printf("i.%d vs N.%d call antes\n",i,N);
pangea_antes(myinfo,tp);
} else printf("bets i.%d\n",i);
}
}
uint64_t pangea_winnings(int32_t player,uint64_t *pangearakep,uint64_t *hostrakep,uint64_t total,int32_t numwinners,int32_t rakemillis,uint64_t maxrake)
{
uint64_t split,pangearake,rake;
if ( numwinners > 0 )
{
split = (total * (1000 - rakemillis)) / (1000 * numwinners);
pangearake = (total - split*numwinners);
if ( pangearake > maxrake )
{
pangearake = maxrake;
split = (total - pangearake) / numwinners;
pangearake = (total - split*numwinners);
}
}
else
{
split = 0;
pangearake = total;
}
if ( rakemillis > PANGEA_MINRAKE_MILLIS )
{
rake = (pangearake * (rakemillis - PANGEA_MINRAKE_MILLIS)) / rakemillis;
pangearake -= rake;
}
else rake = 0;
*hostrakep = rake;
*pangearakep = pangearake;
printf("\nP%d: rakemillis.%d total %.8f split %.8f rake %.8f pangearake %.8f\n",player,rakemillis,dstr(total),dstr(split),dstr(rake),dstr(pangearake));
return(split);
}
int32_t pangea_sidepots(struct supernet_info *myinfo,struct table_info *tp,int32_t dispflag,int64_t sidepots[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS],int64_t *bets)
{
int32_t i,j,nonz,N,n = 0; uint64_t bet,minbet = 0;
memset(sidepots,0,sizeof(uint64_t)*CARDS777_MAXPLAYERS*CARDS777_MAXPLAYERS);
N = tp->numactive;
for (j=0; j<N; j++)
sidepots[0][j] = bets[j];
nonz = 1;
while ( nonz > 0 )
{
for (minbet=j=0; j<N; j++)
{
if ( (bet= sidepots[n][j]) != 0 )
{
if ( tp->active[j] != 0 && tp->active[j]->betstatus != CARDS777_FOLD )
{
if ( minbet == 0 || bet < minbet )
minbet = bet;
}
}
}
for (j=nonz=0; j<N; j++)
{
if ( sidepots[n][j] > minbet && tp->active[j] != 0 && tp->active[j]->betstatus != CARDS777_FOLD )
nonz++;
}
if ( nonz > 0 )
{
for (j=0; j<N; j++)
{
if ( sidepots[n][j] > minbet )
{
sidepots[n+1][j] = (sidepots[n][j] - minbet);
sidepots[n][j] = minbet;
}
}
}
if ( ++n >= N )
break;
}
if ( dispflag != 0 )
{
for (i=0; i<n; i++)
{
for (j=0; j<N; j++)
printf("%.8f ",dstr(sidepots[i][j]));
printf("sidepot.%d of %d\n",i,n);
}
}
return(n);
}
int64_t pangea_splitpot(struct supernet_info *myinfo,struct table_info *tp,uint64_t *pangearakep,int64_t sidepot[CARDS777_MAXPLAYERS],int32_t rakemillis)
{
struct player_info *winners[CARDS777_MAXPLAYERS];
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];
N = tp->numactive;
bestrank = 0;
besthandstr[0] = 0;
for (j=n=0; j<N; j++)
{
if ( (bet= sidepot[j]) != 0 )
{
total += bet;
if ( (p= tp->active[j]) != 0 && p->betstatus != CARDS777_FOLD )
{
if ( p->handrank > bestrank )
{
bestrank = p->handrank;
set_handstr(besthandstr,p->hand,0);
//printf("set besthandstr.(%s)\n",besthandstr);
}
}
}
}
for (j=0; j<N; j++)
{
if ( (p= tp->active[j]) != 0 && p->betstatus != CARDS777_FOLD && sidepot[j] > 0 )
{
if ( p->handrank == bestrank )
winners[numwinners++] = p;
rank = set_handstr(handstr,p->hand,0);
if ( handstr[strlen(handstr)-1] == ' ' )
handstr[strlen(handstr)-1] = 0;
//if ( hn->server->H.slot == 0 )
printf("(p%d %14s)",j,handstr[0]!=' '?handstr:handstr+1);
//printf("(%2d %2d).%d ",dp->hands[j][5],dp->hands[j][6],(int32_t)dp->balances[j]);
}
}
if ( numwinners == 0 )
printf("pangea_splitpot error: numwinners.0\n");
else
{
uint64_t maxrakes[CARDS777_MAXPLAYERS+1] = { 0, 0, 1, 2, 2, 3, 3, 3, 3, 3 }; // 2players 1BB, 3-4players, 2BB, 5+players 3BB
for (j=n=0; j<N; j++)
if ( (p= tp->active[j]) != 0 && p->bets > 0 )
n++;
if ( (maxrake= maxrakes[n] * tp->G.bigblind) > tp->G.maxrake )
{
maxrake = tp->G.maxrake;
//if ( strcmp(dp->coinstr,"BTC") == 0 && maxrake < PANGEA_BTCMAXRAKE )
// maxrake = PANGEA_BTCMAXRAKE;
//else if ( maxrake < PANGEA_MAXRAKE )
maxrake = PANGEA_MAXRAKE;
}
split = pangea_winnings(tp->priv.myind,&pangearake,&rake,total,numwinners,rakemillis,maxrake);
(*pangearakep) += pangearake;
for (j=0; j<numwinners; j++)
{
tmp = winners[j]->ind;
pangea_summaryadd(myinfo,tp,CARDS777_WINNINGS,&tmp,sizeof(tmp),(void *)&split,sizeof(split));
winners[j]->balance += split;
winners[j]->won += split;
}
if ( split*numwinners + rake + pangearake != total )
printf("pangea_split total error %.8f != split %.8f numwinners %d rake %.8f pangearake %.8f\n",dstr(total),dstr(split),numwinners,dstr(rake),dstr(pangearake));
//if ( hn->server->H.slot == 0 )
{
printf(" total %.8f split %.8f rake %.8f Prake %.8f hand.(%s) N%d winners ",dstr(total),dstr(split),dstr(rake),dstr(pangearake),besthandstr,tp->numhands);
for (j=0; j<numwinners; j++)
printf("%d ",winners[j]->ind);
printf("\n");
}
}
return(rake);
}
/*char *pangea_input(uint64_t my64bits,uint64_t tableid,cJSON *json)
{
char *actionstr; uint64_t sum,amount=0; int32_t action=0,num,threadid; struct table_info *sp; struct cards777_pubdata *dp; char hex[4096];
threadid = juint(json,"threadid");
if ( (sp= pangea_threadtables(&num,threadid,tableid)) == 0 )
return(clonestr("{\"error\":\"you are not playing on any tables\"}"));
if ( 0 && num != 1 )
return(clonestr("{\"error\":\"more than one active table\"}"));
else if ( (dp= sp->dp) == 0 )
return(clonestr("{\"error\":\"no pubdata ptr for table\"}"));
else if ( dp->hand.undergun != pangea_ind(sp,sp->myslot) || dp->hand.betsize == 0 )
{
printf("undergun.%d threadid.%d myind.%d\n",dp->hand.undergun,sp->tp->threadid,pangea_ind(sp,sp->myslot));
return(clonestr("{\"error\":\"not your turn\"}"));
}
else if ( (actionstr= jstr(json,"action")) == 0 )
return(clonestr("{\"error\":\"on action specified\"}"));
else
{
if ( strcmp(actionstr,"check") == 0 || strcmp(actionstr,"call") == 0 || strcmp(actionstr,"bet") == 0 || strcmp(actionstr,"raise") == 0 || strcmp(actionstr,"allin") == 0 || strcmp(actionstr,"fold") == 0 )
{
sum = dp->hand.bets[pangea_ind(sp,sp->myslot)];
if ( strcmp(actionstr,"allin") == 0 )
amount = sp->balances[sp->myslot], action = CARDS777_ALLIN;
else if ( strcmp(actionstr,"bet") == 0 )
amount = j64bits(json,"amount"), action = 1;
else
{
if ( dp->hand.betsize == sum )
{
if ( strcmp(actionstr,"check") == 0 || strcmp(actionstr,"call") == 0 )
action = 0;
else if ( strcmp(actionstr,"raise") == 0 )
{
action = 1;
if ( (amount= dp->hand.lastraise) < j64bits(json,"amount") )
amount = j64bits(json,"amount");
}
else printf("unsupported userinput command.(%s)\n",actionstr);
}
else
{
if ( strcmp(actionstr,"check") == 0 || strcmp(actionstr,"call") == 0 )
action = 1, amount = (dp->hand.betsize - sum);
else if ( strcmp(actionstr,"raise") == 0 )
{
action = 2;
amount = (dp->hand.betsize - sum);
if ( amount < dp->hand.lastraise )
amount = dp->hand.lastraise;
if ( j64bits(json,"amount") > amount )
amount = j64bits(json,"amount");
}
else if ( strcmp(actionstr,"fold") == 0 )
action = 0;
else printf("unsupported userinput command.(%s)\n",actionstr);
}
}
if ( amount > sp->balances[sp->myslot] )
amount = sp->balances[sp->myslot], action = CARDS777_ALLIN;
pangea_sendcmd(hex,&sp->tp->hn,"action",-1,(void *)&amount,sizeof(amount),dp->hand.cardi,action);
printf("ACTION.(%s)\n",hex);
return(clonestr("{\"result\":\"action submitted\"}"));
}
else return(clonestr("{\"error\":\"illegal action specified, must be: check, call, bet, raise, fold or allin\"}"));
}
}*/

400
iguana/pangea_fsm.c

@ -15,35 +15,34 @@
#include "pangea777.h" #include "pangea777.h"
int32_t pangea_slotA(struct table_info *sp)
int32_t pangea_slotA(struct pangea_info *sp)
{ {
return(0); return(0);
} }
int32_t pangea_slotB(struct pangea_info *sp) int32_t pangea_slotB(struct table_info *sp)
{ {
uint64_t nxt64bits; uint64_t nxt64bits;
nxt64bits = sp->active[1]; nxt64bits = sp->active[1];
return(pangea_search(sp,nxt64bits)); return(pangea_search(sp,nxt64bits));
} }
int32_t pangea_slot(struct pangea_info *sp,int32_t ind) int32_t pangea_slot(struct table_info *sp,int32_t ind)
{ {
return(pangea_tableaddr(sp->dp,sp->active[ind])); return(pangea_tableaddr(sp->dp,sp->active[ind]));
} }
int32_t pangea_ind(struct pangea_info *sp,int32_t slot) int32_t pangea_ind(struct table_info *sp,int32_t slot)
{ {
return(pangea_search(sp,sp->addrs[slot])); return(pangea_search(sp,sp->addrs[slot]));
} }
int32_t pangea_lastnode(struct pangea_info *sp) int32_t pangea_lastnode(struct table_info *sp)
{ {
return(pangea_search(sp,sp->active[sp->numactive-1])); return(pangea_search(sp,sp->active[sp->numactive-1]));
} }
int32_t pangea_nextnode(struct pangea_info *sp) int32_t pangea_nextnode(struct table_info *sp)
{ {
if ( sp->myind < sp->numactive-1 ) if ( sp->myind < sp->numactive-1 )
return(sp->myind + 1); return(sp->myind + 1);
@ -54,7 +53,7 @@ int32_t pangea_nextnode(struct pangea_info *sp)
} }
} }
int32_t pangea_prevnode(struct pangea_info *sp) int32_t pangea_prevnode(struct table_info *sp)
{ {
if ( sp->myind > 0 ) if ( sp->myind > 0 )
return(sp->myind - 1); return(sp->myind - 1);
@ -65,7 +64,7 @@ int32_t pangea_prevnode(struct pangea_info *sp)
} }
} }
int32_t pangea_neworder(struct cards777_pubdata *dp,struct pangea_info *sp,uint64_t *active,int32_t numactive) int32_t pangea_neworder(struct cards777_pubdata *dp,struct table_info *sp,uint64_t *active,int32_t numactive)
{ {
int32_t slots[CARDS777_MAXPLAYERS],i; int32_t slots[CARDS777_MAXPLAYERS],i;
if ( active == 0 ) if ( active == 0 )
@ -97,7 +96,7 @@ int32_t pangea_neworder(struct cards777_pubdata *dp,struct pangea_info *sp,uint6
return(numactive); return(numactive);
} }
int32_t pangea_inactivate(struct cards777_pubdata *dp,struct pangea_info *sp,uint64_t nxt64bits) int32_t pangea_inactivate(struct cards777_pubdata *dp,struct table_info *sp,uint64_t nxt64bits)
{ {
int32_t i,n; uint64_t active[CARDS777_MAXPLAYERS]; int32_t i,n; uint64_t active[CARDS777_MAXPLAYERS];
for (i=n=0; i<sp->numactive; i++) for (i=n=0; i<sp->numactive; i++)
@ -141,7 +140,7 @@ void pangea_sendnewdeck(union pangeanet777 *hn,struct cards777_pubdata *dp)
int32_t pangea_newdeck(union pangeanet777 *src) int32_t pangea_newdeck(union pangeanet777 *src)
{ {
uint8_t data[(CARDS777_MAXCARDS + 1) * sizeof(bits256)]; struct cards777_pubdata *dp; struct cards777_privdata *priv; int32_t i,n,m,len; uint8_t data[(CARDS777_MAXCARDS + 1) * sizeof(bits256)]; struct cards777_pubdata *dp; struct cards777_privdata *priv; int32_t i,n,m,len;
bits256 playerpubs[CARDS777_MAXPLAYERS]; struct pangea_info *sp; uint64_t removelist[CARDS777_MAXPLAYERS]; cJSON *array; char *str; bits256 playerpubs[CARDS777_MAXPLAYERS]; struct table_info *sp; uint64_t removelist[CARDS777_MAXPLAYERS]; cJSON *array; char *str;
dp = src->client->H.pubdata, sp = dp->table; dp = src->client->H.pubdata, sp = dp->table;
priv = src->client->H.privdata; priv = src->client->H.privdata;
pangea_clearhand(dp,&dp->hand,priv); pangea_clearhand(dp,&dp->hand,priv);
@ -178,7 +177,7 @@ int32_t pangea_newdeck(union pangeanet777 *src)
int32_t pangea_anotherhand(void *hn,struct cards777_pubdata *dp,int32_t sleepflag) int32_t pangea_anotherhand(void *hn,struct cards777_pubdata *dp,int32_t sleepflag)
{ {
int32_t i,n,activej = -1; uint64_t total = 0; struct pangea_info *sp = dp->table; int32_t i,n,activej = -1; uint64_t total = 0; struct table_info *sp = dp->table;
for (i=n=0; i<sp->numaddrs; i++) for (i=n=0; i<sp->numaddrs; i++)
{ {
total += sp->balances[i]; total += sp->balances[i];
@ -209,9 +208,9 @@ int32_t pangea_anotherhand(void *hn,struct cards777_pubdata *dp,int32_t sleepfla
return(n); return(n);
} }
int32_t _pangea_newhand(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_newhand(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
char hex[1024]; int32_t handid,m,i; uint64_t active[CARDS777_MAXPLAYERS]; cJSON *array; struct pangea_info *sp = dp->table; char hex[1024]; int32_t handid,m,i; uint64_t active[CARDS777_MAXPLAYERS]; cJSON *array; struct table_info *sp = dp->table;
if ( data == 0 || datalen != (dp->numcards + 1) * sizeof(bits256) ) if ( data == 0 || datalen != (dp->numcards + 1) * sizeof(bits256) )
{ {
PNACL_message("pangea_newhand invalid datalen.%d vs %ld\n",datalen,(long)((dp->numcards + 1) * sizeof(bits256))); PNACL_message("pangea_newhand invalid datalen.%d vs %ld\n",datalen,(long)((dp->numcards + 1) * sizeof(bits256)));
@ -230,7 +229,7 @@ int32_t _pangea_newhand(union pangeanet777 *hn,cJSON *json,struct cards777_pubda
} }
dp->button = (dp->numhands++ % dp->N); dp->button = (dp->numhands++ % dp->N);
memcpy(dp->hand.cardpubs,data,(dp->numcards + 1) * sizeof(bits256)); memcpy(dp->hand.cardpubs,data,(dp->numcards + 1) * sizeof(bits256));
PNACL_message("player.%d NEWHAND.%llx received numhands.%d button.%d cardi.%d | dp->N %d\n",hn->client->H.slot,(long long)dp->hand.cardpubs[dp->numcards].txid,dp->numhands,dp->button,dp->hand.cardi,dp->N); PNACL_message("player.%d NEWHAND.%llx received numhands.%d button.%d cardi.%d | dp->N %d\n",priv->myslot,(long long)dp->hand.cardpubs[dp->numcards].txid,dp->numhands,dp->button,dp->hand.cardi,dp->N);
dp->hand.checkprod = cards777_pubkeys(dp->hand.cardpubs,dp->numcards,dp->hand.cardpubs[dp->numcards]); dp->hand.checkprod = cards777_pubkeys(dp->hand.cardpubs,dp->numcards,dp->hand.cardpubs[dp->numcards]);
memset(dp->summary,0,sizeof(dp->summary)); memset(dp->summary,0,sizeof(dp->summary));
dp->summaries = dp->mismatches = dp->summarysize = 0; dp->summaries = dp->mismatches = dp->summarysize = 0;
@ -238,12 +237,12 @@ int32_t _pangea_newhand(union pangeanet777 *hn,cJSON *json,struct cards777_pubda
if ( sp->myind >= 0 ) if ( sp->myind >= 0 )
{ {
pangea_summary(hn,dp,CARDS777_START,&handid,sizeof(handid),dp->hand.cardpubs[0].bytes,sizeof(bits256)*(dp->numcards+1)); pangea_summary(hn,dp,CARDS777_START,&handid,sizeof(handid),dp->hand.cardpubs[0].bytes,sizeof(bits256)*(dp->numcards+1));
pangea_sendcmd(hex,hn,"gotdeck",-1,dp->hand.checkprod.bytes,sizeof(uint64_t),dp->hand.cardi,dp->hand.userinput_starttime); pangea_sendcmd(PANGEA_CALLARGS,"gotdeck",-1,dp->hand.checkprod.bytes,sizeof(uint64_t),dp->hand.cardi,dp->hand.userinput_starttime);
} }
return(0); return(0);
} }
void pangea_checkstart(union pangeanet777 *hn,struct cards777_pubdata *dp,struct cards777_privdata *priv) void pangea_checkstart(struct table_info *tp)
{ {
int32_t i; int32_t i;
if ( dp->hand.checkprod.txid != 0 && dp->newhand[0] != 0 && dp->hand.encodestarted == 0 ) if ( dp->hand.checkprod.txid != 0 && dp->newhand[0] != 0 && dp->hand.encodestarted == 0 )
@ -264,9 +263,9 @@ void pangea_checkstart(union pangeanet777 *hn,struct cards777_pubdata *dp,struct
} }
} }
int32_t _pangea_gotdeck(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_gotdeck(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
int32_t i,slot; uint64_t total = 0; struct pangea_info *sp = dp->table; int32_t i,slot; uint64_t total = 0; struct table_info *sp = dp->table;
dp->hand.othercardpubs[senderind] = *(uint64_t *)data; dp->hand.othercardpubs[senderind] = *(uint64_t *)data;
if ( Debuglevel > 2 ) if ( Debuglevel > 2 )
{ {
@ -277,16 +276,16 @@ int32_t _pangea_gotdeck(union pangeanet777 *hn,cJSON *json,struct cards777_pubda
PNACL_message("(p%d %.8f) ",i,dstr(sp->balances[slot])); PNACL_message("(p%d %.8f) ",i,dstr(sp->balances[slot]));
} }
PNACL_message("balances %.8f [%.8f] | ",dstr(total),dstr(total + dp->hostrake + dp->pangearake)); PNACL_message("balances %.8f [%.8f] | ",dstr(total),dstr(total + dp->hostrake + dp->pangearake));
PNACL_message("player.%d pangea_gotdeck from P.%d otherpubs.%llx\n",hn->client->H.slot,senderind,(long long)dp->hand.othercardpubs[senderind]); PNACL_message("player.%d pangea_gotdeck from P.%d otherpubs.%llx\n",priv->myslot,senderind,(long long)dp->hand.othercardpubs[senderind]);
} }
pangea_checkstart(hn,dp,priv); pangea_checkstart(hn,dp,priv);
return(0); return(0);
} }
int32_t _pangea_ready(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_ready(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
int32_t create_MofN(uint8_t addrtype,char *redeemScript,char *scriptPubKey,char *p2shaddr,char *pubkeys[],int32_t M,int32_t N); int32_t create_MofN(uint8_t addrtype,char *redeemScript,char *scriptPubKey,char *p2shaddr,char *pubkeys[],int32_t M,int32_t N);
char hex[4096],hexstr[67],*pubkeys[CARDS777_MAXPLAYERS]; struct pangea_info *sp = dp->table; char hex[4096],hexstr[67],*pubkeys[CARDS777_MAXPLAYERS]; struct table_info *sp = dp->table;
uint8_t addrtype; int32_t i,slot,retval = -1; struct iguana_info *coin = 0; uint8_t addrtype; int32_t i,slot,retval = -1; struct iguana_info *coin = 0;
slot = pangea_slot(sp,senderind); slot = pangea_slot(sp,senderind);
dp->readymask |= (1 << slot); dp->readymask |= (1 << slot);
@ -306,13 +305,13 @@ int32_t _pangea_ready(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata
if ( i == dp->N )//dp->readymask == ((1 << dp->N) - 1) ) if ( i == dp->N )//dp->readymask == ((1 << dp->N) - 1) )
{ {
if ( hn->server->H.slot == pangea_slotA(sp) && senderind != 0 ) if ( hn->server->H.slot == pangea_slotA(sp) && senderind != 0 )
pangea_sendcmd(hex,hn,"ready",-1,sp->btcpub,sizeof(sp->btcpub),0,0); pangea_sendcmd(PANGEA_CALLARGS,"ready",-1,sp->btcpub,sizeof(sp->btcpub),0,0);
for (i=0; i<dp->N; i++) for (i=0; i<dp->N; i++)
pubkeys[i] = sp->btcpubkeys[pangea_slot(sp,i)]; pubkeys[i] = sp->btcpubkeys[pangea_slot(sp,i)];
retval = create_MofN(coin->chain->p2shval,sp->redeemScript,sp->scriptPubKey,sp->multisigaddr,pubkeys,dp->M,dp->N); retval = create_MofN(coin->chain->p2shval,sp->redeemScript,sp->scriptPubKey,sp->multisigaddr,pubkeys,dp->M,dp->N);
PNACL_message("retval.%d scriptPubKey.(%s) multisigaddr.(%s) redeemScript.(%s)\n",retval,sp->scriptPubKey,sp->multisigaddr,sp->redeemScript); PNACL_message("retval.%d scriptPubKey.(%s) multisigaddr.(%s) redeemScript.(%s)\n",retval,sp->scriptPubKey,sp->multisigaddr,sp->redeemScript);
} }
PNACL_message("player.%d got ready from senderind.%d slot.%d readymask.%x btcpubkey.(%s) (%s) wip.(%s)\n",hn->client->H.slot,senderind,slot,dp->readymask,hexstr,sp->coinaddrs[slot],sp->wipstr); PNACL_message("player.%d got ready from senderind.%d slot.%d readymask.%x btcpubkey.(%s) (%s) wip.(%s)\n",priv->myslot,senderind,slot,dp->readymask,hexstr,sp->coinaddrs[slot],sp->wipstr);
return(0); return(0);
} }
@ -332,9 +331,9 @@ void pangea_rwaudit(int32_t saveflag,bits256 *audit,bits256 *audits,int32_t card
} }
} }
int32_t _pangea_card(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t cardi,int32_t senderind) int32_t pangea_card(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind,int32_t cardi)
{ {
int32_t destplayer,card,selector,validcard = -1; bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; char hex[1024],cardAstr[8],cardBstr[8]; struct pangea_info *sp = dp->table; int32_t destplayer,card,selector,validcard = -1; bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; char hex[1024],cardAstr[8],cardBstr[8]; struct table_info *sp = dp->table;
if ( data == 0 || datalen != sizeof(bits256)*dp->N ) if ( data == 0 || datalen != sizeof(bits256)*dp->N )
{ {
PNACL_message("pangea_card invalid datalen.%d vs %ld\n",datalen,(long)sizeof(bits256)*dp->N); PNACL_message("pangea_card invalid datalen.%d vs %ld\n",datalen,(long)sizeof(bits256)*dp->N);
@ -345,11 +344,11 @@ int32_t _pangea_card(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata
pangea_rwaudit(1,(void *)data,priv->audits,cardi,destplayer,dp->N); pangea_rwaudit(1,(void *)data,priv->audits,cardi,destplayer,dp->N);
pangea_rwaudit(0,audit,priv->audits,cardi,destplayer,dp->N); pangea_rwaudit(0,audit,priv->audits,cardi,destplayer,dp->N);
//PNACL_message("card.%d destplayer.%d [%llx]\n",cardi,destplayer,(long long)audit[0].txid); //PNACL_message("card.%d destplayer.%d [%llx]\n",cardi,destplayer,(long long)audit[0].txid);
if ( (card= cards777_checkcard(&cardpriv,cardi,pangea_ind(dp->table,hn->client->H.slot),destplayer,hn->client->H.privkey,dp->hand.cardpubs,dp->numcards,audit[0])) >= 0 ) if ( (card= cards777_checkcard(&cardpriv,cardi,pangea_ind(dp->table,priv->myslot),destplayer,hn->client->H.privkey,dp->hand.cardpubs,dp->numcards,audit[0])) >= 0 )
{ {
destplayer = pangea_ind(dp->table,hn->client->H.slot); destplayer = pangea_ind(dp->table,priv->myslot);
if ( Debuglevel > 2 ) if ( Debuglevel > 2 )
PNACL_message("player.%d got card.[%d]\n",hn->client->H.slot,card); PNACL_message("player.%d got card.[%d]\n",priv->myslot,card);
//memcpy(&priv->incards[cardi*dp->N + destplayer],cardpriv.bytes,sizeof(bits256)); //memcpy(&priv->incards[cardi*dp->N + destplayer],cardpriv.bytes,sizeof(bits256));
selector = (cardi / dp->N); selector = (cardi / dp->N);
priv->holecards[selector] = cardpriv; priv->holecards[selector] = cardpriv;
@ -362,18 +361,18 @@ int32_t _pangea_card(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata
if ( priv->hole[1] != 0xff ) if ( priv->hole[1] != 0xff )
cardstr(cardBstr,priv->hole[1]); cardstr(cardBstr,priv->hole[1]);
PNACL_message(">>>>>>>>>> dest.%d priv.%p holecards[%02d] cardi.%d / dp->N %d (%02d %02d) -> (%s %s)\n",destplayer,priv,priv->hole[cardi / dp->N],cardi,dp->N,priv->hole[0],priv->hole[1],cardAstr,cardBstr); PNACL_message(">>>>>>>>>> dest.%d priv.%p holecards[%02d] cardi.%d / dp->N %d (%02d %02d) -> (%s %s)\n",destplayer,priv,priv->hole[cardi / dp->N],cardi,dp->N,priv->hole[0],priv->hole[1],cardAstr,cardBstr);
if ( cards777_validate(cardpriv,dp->hand.final[cardi*dp->N + destplayer],dp->hand.cardpubs,dp->numcards,audit,dp->N,sp->playerpubs[hn->client->H.slot]) < 0 ) if ( cards777_validate(cardpriv,dp->hand.final[cardi*dp->N + destplayer],dp->hand.cardpubs,dp->numcards,audit,dp->N,sp->playerpubs[priv->myslot]) < 0 )
PNACL_message("player.%d decoded cardi.%d card.[%02d] but it doesnt validate\n",hn->client->H.slot,cardi,card); PNACL_message("player.%d decoded cardi.%d card.[%02d] but it doesnt validate\n",priv->myslot,cardi,card);
} else PNACL_message("ERROR player.%d got no card %llx\n",hn->client->H.slot,*(long long *)data); } else PNACL_message("ERROR player.%d got no card %llx\n",priv->myslot,*(long long *)data);
if ( cardi < dp->N*2 ) if ( cardi < dp->N*2 )
pangea_sendcmd(hex,hn,"facedown",-1,(void *)&cardi,sizeof(cardi),cardi,validcard); pangea_sendcmd(PANGEA_CALLARGS,"facedown",-1,(void *)&cardi,sizeof(cardi),cardi,validcard);
else pangea_sendcmd(hex,hn,"faceup",-1,cardpriv.bytes,sizeof(cardpriv),cardi,0xff); else pangea_sendcmd(PANGEA_CALLARGS,"faceup",-1,cardpriv.bytes,sizeof(cardpriv),cardi,0xff);
return(0); return(0);
} }
int32_t _pangea_decoded(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_decoded(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
int32_t cardi,destplayer,card,turni; bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; char hex[1024]; struct pangea_info *sp = dp->table; int32_t cardi,destplayer,card,turni; bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; char hex[1024]; struct table_info *sp = dp->table;
if ( data == 0 || datalen != sizeof(bits256)*dp->N ) if ( data == 0 || datalen != sizeof(bits256)*dp->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));
@ -390,22 +389,22 @@ int32_t _pangea_decoded(union pangeanet777 *hn,cJSON *json,struct cards777_pubda
pangea_rwaudit(1,(void *)data,priv->audits,cardi,destplayer,dp->N); pangea_rwaudit(1,(void *)data,priv->audits,cardi,destplayer,dp->N);
pangea_rwaudit(0,audit,priv->audits,cardi,destplayer,dp->N); pangea_rwaudit(0,audit,priv->audits,cardi,destplayer,dp->N);
//memcpy(&priv->incards[cardi*dp->N + destplayer],data,sizeof(bits256)); //memcpy(&priv->incards[cardi*dp->N + destplayer],data,sizeof(bits256));
if ( turni == pangea_ind(dp->table,hn->client->H.slot) ) if ( turni == pangea_ind(dp->table,priv->myslot) )
{ {
if ( hn->client->H.slot != pangea_slotA(dp->table) ) if ( priv->myslot != pangea_slotA(dp->table) )
{ {
audit[0] = cards777_decode(&audit[sp->myind],priv->xoverz,destplayer,audit[0],priv->outcards,dp->numcards,dp->N); audit[0] = cards777_decode(&audit[sp->myind],priv->xoverz,destplayer,audit[0],priv->outcards,dp->numcards,dp->N);
pangea_rwaudit(1,audit,priv->audits,cardi,destplayer,dp->N); pangea_rwaudit(1,audit,priv->audits,cardi,destplayer,dp->N);
pangea_sendcmd(hex,hn,"decoded",-1,audit[0].bytes,sizeof(bits256)*dp->N,cardi,pangea_prevnode(dp->table)); pangea_sendcmd(PANGEA_CALLARGS,"decoded",-1,audit[0].bytes,sizeof(bits256)*dp->N,cardi,pangea_prevnode(dp->table));
//PNACL_message("player.%d decoded cardi.%d %llx -> %llx\n",hn->client->H.slot,cardi,(long long)priv->incards[cardi*dp->N + destplayer].txid,(long long)decoded.txid); //PNACL_message("player.%d decoded cardi.%d %llx -> %llx\n",priv->myslot,cardi,(long long)priv->incards[cardi*dp->N + destplayer].txid,(long long)decoded.txid);
} }
else else
{ {
if ( (card= cards777_checkcard(&cardpriv,cardi,pangea_ind(dp->table,hn->client->H.slot),pangea_ind(dp->table,hn->client->H.slot),hn->client->H.privkey,dp->hand.cardpubs,dp->numcards,audit[0])) >= 0 ) if ( (card= cards777_checkcard(&cardpriv,cardi,pangea_ind(dp->table,priv->myslot),pangea_ind(dp->table,priv->myslot),hn->client->H.privkey,dp->hand.cardpubs,dp->numcards,audit[0])) >= 0 )
{ {
if ( cards777_validate(cardpriv,dp->hand.final[cardi*dp->N + destplayer],dp->hand.cardpubs,dp->numcards,audit,dp->N,sp->playerpubs[hn->client->H.slot]) < 0 ) if ( cards777_validate(cardpriv,dp->hand.final[cardi*dp->N + destplayer],dp->hand.cardpubs,dp->numcards,audit,dp->N,sp->playerpubs[priv->myslot]) < 0 )
PNACL_message("player.%d decoded cardi.%d card.[%d] but it doesnt validate\n",hn->client->H.slot,cardi,card); PNACL_message("player.%d decoded cardi.%d card.[%d] but it doesnt validate\n",priv->myslot,cardi,card);
pangea_sendcmd(hex,hn,"faceup",-1,cardpriv.bytes,sizeof(cardpriv),cardi,cardpriv.txid!=0?0xff:-1); pangea_sendcmd(PANGEA_CALLARGS,"faceup",-1,cardpriv.bytes,sizeof(cardpriv),cardi,cardpriv.txid!=0?0xff:-1);
//PNACL_message("-> FACEUP.(%s)\n",hex); //PNACL_message("-> FACEUP.(%s)\n",hex);
} }
} }
@ -456,34 +455,34 @@ int32_t pangea_unzbuf(uint8_t *buf,char *hexstr,int32_t len)
return(len2); return(len2);
} }
int32_t _pangea_preflop(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_preflop(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
char *hex,*zbuf; int32_t i,card,len,iter,cardi,destplayer,maxlen = (int32_t)(2 * CARDS777_MAXPLAYERS * CARDS777_MAXPLAYERS * CARDS777_MAXCARDS * sizeof(bits256)); char *hex,*zbuf; int32_t i,card,len,iter,cardi,destplayer,maxlen = (int32_t)(2 * CARDS777_MAXPLAYERS * CARDS777_MAXPLAYERS * CARDS777_MAXCARDS * sizeof(bits256));
bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; struct pangea_info *sp = dp->table; bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; struct table_info *sp = dp->table;
if ( data == 0 || datalen != (2 * dp->N) * (dp->N * dp->N * sizeof(bits256)) || (hex= malloc(maxlen)) == 0 ) if ( data == 0 || datalen != (2 * dp->N) * (dp->N * dp->N * sizeof(bits256)) || (hex= malloc(maxlen)) == 0 )
{ {
PNACL_message("pangea_preflop invalid datalen.%d vs %ld\n",datalen,(long)(2 * dp->N) * (dp->N * dp->N * sizeof(bits256))); PNACL_message("pangea_preflop invalid datalen.%d vs %ld\n",datalen,(long)(2 * dp->N) * (dp->N * dp->N * sizeof(bits256)));
return(-1); return(-1);
} }
//PNACL_message("preflop player.%d\n",hn->client->H.slot); //PNACL_message("preflop player.%d\n",priv->myslot);
//memcpy(priv->incards,data,datalen); //memcpy(priv->incards,data,datalen);
memcpy(priv->audits,data,datalen); memcpy(priv->audits,data,datalen);
if ( hn->client->H.slot != pangea_slotA(dp->table) && hn->client->H.slot != pangea_slotB(dp->table) ) if ( priv->myslot != pangea_slotA(dp->table) && priv->myslot != pangea_slotB(dp->table) )
{ {
//for (i=0; i<dp->numcards*dp->N; i++) //for (i=0; i<dp->numcards*dp->N; i++)
// PNACL_message("%llx ",(long long)priv->outcards[i].txid); // PNACL_message("%llx ",(long long)priv->outcards[i].txid);
//PNACL_message("player.%d outcards\n",hn->client->H.slot); //PNACL_message("player.%d outcards\n",priv->myslot);
for (cardi=0; cardi<dp->N*2; cardi++) for (cardi=0; cardi<dp->N*2; cardi++)
for (destplayer=0; destplayer<dp->N; destplayer++) for (destplayer=0; destplayer<dp->N; destplayer++)
{ {
pangea_rwaudit(0,audit,priv->audits,cardi,destplayer,dp->N); pangea_rwaudit(0,audit,priv->audits,cardi,destplayer,dp->N);
if ( 0 && (card= cards777_checkcard(&cardpriv,cardi,pangea_ind(dp->table,hn->client->H.slot),destplayer,hn->client->H.privkey,dp->hand.cardpubs,dp->numcards,audit[0])) >= 0 ) if ( 0 && (card= cards777_checkcard(&cardpriv,cardi,pangea_ind(dp->table,priv->myslot),destplayer,hn->client->H.privkey,dp->hand.cardpubs,dp->numcards,audit[0])) >= 0 )
PNACL_message("ERROR: unexpected decode player.%d got card.[%d]\n",hn->client->H.slot,card); PNACL_message("ERROR: unexpected decode player.%d got card.[%d]\n",priv->myslot,card);
audit[0] = cards777_decode(&audit[sp->myind],priv->xoverz,destplayer,audit[0],priv->outcards,dp->numcards,dp->N); audit[0] = cards777_decode(&audit[sp->myind],priv->xoverz,destplayer,audit[0],priv->outcards,dp->numcards,dp->N);
pangea_rwaudit(1,audit,priv->audits,cardi,destplayer,dp->N); pangea_rwaudit(1,audit,priv->audits,cardi,destplayer,dp->N);
} }
//PNACL_message("issue preflop\n"); //PNACL_message("issue preflop\n");
if ( (zbuf= calloc(1,datalen*2+1)) != 0 ) if ( 0 && (zbuf= calloc(1,datalen*2+1)) != 0 )
{ {
//init_hexbytes_noT(zbuf,priv->audits[0].bytes,datalen); //init_hexbytes_noT(zbuf,priv->audits[0].bytes,datalen);
//PNACL_message("STARTZBUF.(%s)\n",zbuf); //PNACL_message("STARTZBUF.(%s)\n",zbuf);
@ -501,9 +500,10 @@ int32_t _pangea_preflop(union pangeanet777 *hn,cJSON *json,struct cards777_pubda
} }
} }
//PNACL_message("datalen.%d -> len.%d zbuf %ld\n",datalen,len,(long)strlen(zbuf)); //PNACL_message("datalen.%d -> len.%d zbuf %ld\n",datalen,len,(long)strlen(zbuf));
pangea_sendcmd(hex,hn,"preflop",pangea_prevnode(dp->table),(void *)zbuf,len,dp->N * 2 * dp->N,-1); pangea_sendcmd(PANGEA_CALLARGS,"preflop",pangea_prevnode(dp->table),(void *)zbuf,len,dp->N * 2 * dp->N,-1);
free(zbuf); free(zbuf);
} }
else pangea_sendcmd(PANGEA_CALLARGS,"preflop",pangea_prevnode(dp->table),priv->audits[0].bytes,datalen,dp->N * 2 * dp->N,-1);
} }
else else
{ {
@ -516,39 +516,39 @@ int32_t _pangea_preflop(union pangeanet777 *hn,cJSON *json,struct cards777_pubda
//PNACL_message("audit[0] %llx -> ",(long long)audit[0].txid); //PNACL_message("audit[0] %llx -> ",(long long)audit[0].txid);
audit[0] = cards777_decode(&audit[sp->myind],priv->xoverz,destplayer,audit[0],priv->outcards,dp->numcards,dp->N); audit[0] = cards777_decode(&audit[sp->myind],priv->xoverz,destplayer,audit[0],priv->outcards,dp->numcards,dp->N);
pangea_rwaudit(1,audit,priv->audits,cardi,destplayer,dp->N); pangea_rwaudit(1,audit,priv->audits,cardi,destplayer,dp->N);
//PNACL_message("[%llx + %llx] ",*(long long *)&audit[0],(long long)&audit[pangea_ind(dp->table,hn->client->H.slot)]); //PNACL_message("[%llx + %llx] ",*(long long *)&audit[0],(long long)&audit[pangea_ind(dp->table,priv->myslot)]);
if ( destplayer == pangea_ind(dp->table,hn->client->H.slot) ) if ( destplayer == pangea_ind(dp->table,priv->myslot) )
_pangea_card(hn,json,dp,priv,audit[0].bytes,sizeof(bits256)*dp->N,cardi,destplayer); pangea_card(PANGEA_CALLARGS,audit[0].bytes,sizeof(bits256)*dp->N,destplayer,cardi);
else pangea_sendcmd(hex,hn,"card",destplayer,audit[0].bytes,sizeof(bits256)*dp->N,cardi,-1); else pangea_sendcmd(PANGEA_CALLARGS,"card",destplayer,audit[0].bytes,sizeof(bits256)*dp->N,cardi,-1);
} }
} }
free(hex); free(hex);
return(0); return(0);
} }
int32_t _pangea_encoded(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_encoded(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
char *hex; bits256 audit[CARDS777_MAXPLAYERS]; int32_t i,iter,cardi,destplayer; struct pangea_info *sp = dp->table; char *hex; bits256 audit[CARDS777_MAXPLAYERS]; int32_t i,iter,cardi,destplayer; struct table_info *sp = dp->table;
if ( data == 0 || datalen != (dp->numcards * dp->N) * sizeof(bits256) ) if ( data == 0 || datalen != (dp->numcards * dp->N) * sizeof(bits256) )
{ {
PNACL_message("pangea_encode invalid datalen.%d vs %ld\n",datalen,(long)((dp->numcards * dp->N) * sizeof(bits256))); PNACL_message("pangea_encode invalid datalen.%d vs %ld\n",datalen,(long)((dp->numcards * dp->N) * sizeof(bits256)));
return(-1); return(-1);
} }
cards777_encode(priv->outcards,priv->xoverz,priv->allshares,priv->myshares,dp->hand.sharenrs[pangea_ind(dp->table,hn->client->H.slot)],dp->M,(void *)data,dp->numcards,dp->N); cards777_encode(priv->outcards,priv->xoverz,priv->allshares,priv->myshares,dp->hand.sharenrs[pangea_ind(dp->table,priv->myslot)],dp->M,(void *)data,dp->numcards,dp->N);
//int32_t i; for (i=0; i<dp->numcards*dp->N; i++) //int32_t i; for (i=0; i<dp->numcards*dp->N; i++)
// PNACL_message("%llx ",(long long)priv->outcards[i].txid); // PNACL_message("%llx ",(long long)priv->outcards[i].txid);
PNACL_message("player.%d ind.%d encodes into %p %llx -> %llx next.%d dp->N %d\n",hn->client->H.slot,pangea_ind(sp,hn->client->H.slot),priv->outcards,(long long)*(uint64_t *)data,(long long)priv->outcards[0].txid,pangea_nextnode(sp),dp->N); PNACL_message("player.%d ind.%d encodes into %p %llx -> %llx next.%d dp->N %d\n",priv->myslot,pangea_ind(sp,priv->myslot),priv->outcards,(long long)*(uint64_t *)data,(long long)priv->outcards[0].txid,pangea_nextnode(sp),dp->N);
if ( pangea_ind(sp,hn->client->H.slot) > 0 && (hex= malloc(65536)) != 0 ) if ( pangea_ind(sp,priv->myslot) > 0 && (hex= malloc(65536)) != 0 )
{ {
if ( pangea_ind(sp,hn->client->H.slot) < sp->numactive-1 ) if ( pangea_ind(sp,priv->myslot) < sp->numactive-1 )
{ {
//PNACL_message("send encoded\n"); //PNACL_message("send encoded\n");
pangea_sendcmd(hex,hn,"encoded",pangea_nextnode(sp),priv->outcards[0].bytes,datalen,dp->N*dp->numcards,-1); pangea_sendcmd(PANGEA_CALLARGS,"encoded",pangea_nextnode(sp),priv->outcards[0].bytes,datalen,dp->N*dp->numcards,-1);
} }
else else
{ {
memcpy(dp->hand.final,priv->outcards,sizeof(bits256)*dp->N*dp->numcards); memcpy(dp->hand.final,priv->outcards,sizeof(bits256)*dp->N*dp->numcards);
pangea_sendcmd(hex,hn,"final",-1,priv->outcards[0].bytes,datalen,dp->N*dp->numcards,-1); pangea_sendcmd(PANGEA_CALLARGS,"final",-1,priv->outcards[0].bytes,datalen,dp->N*dp->numcards,-1);
for (iter=cardi=0; iter<2; iter++) for (iter=cardi=0; iter<2; iter++)
for (i=0; i<dp->N; i++,cardi++) for (i=0; i<dp->N; i++,cardi++)
for (destplayer=0; destplayer<dp->N; destplayer++) for (destplayer=0; destplayer<dp->N; destplayer++)
@ -558,14 +558,14 @@ int32_t _pangea_encoded(union pangeanet777 *hn,cJSON *json,struct cards777_pubda
pangea_rwaudit(1,audit,priv->audits,cardi,destplayer,dp->N); pangea_rwaudit(1,audit,priv->audits,cardi,destplayer,dp->N);
} }
PNACL_message("call preflop %ld\n",(long)((2 * dp->N) * (dp->N * dp->N * sizeof(bits256)))); PNACL_message("call preflop %ld\n",(long)((2 * dp->N) * (dp->N * dp->N * sizeof(bits256))));
_pangea_preflop(hn,json,dp,priv,priv->audits[0].bytes,(2 * dp->N) * (dp->N * dp->N * sizeof(bits256)),pangea_ind(sp,hn->client->H.slot)); pangea_preflop(PANGEA_CALLARGS,priv->audits[0].bytes,(2 * dp->N) * (dp->N * dp->N * sizeof(bits256)),pangea_ind(sp,priv->myslot));
} }
free(hex); free(hex);
} }
return(0); return(0);
} }
int32_t _pangea_final(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_final(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
if ( data == 0 || datalen != (dp->numcards * dp->N) * sizeof(bits256) ) if ( data == 0 || datalen != (dp->numcards * dp->N) * sizeof(bits256) )
{ {
@ -573,12 +573,12 @@ int32_t _pangea_final(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata
return(-1); return(-1);
} }
if ( Debuglevel > 2 ) if ( Debuglevel > 2 )
PNACL_message("player.%d final into %p\n",hn->client->H.slot,priv->outcards); PNACL_message("player.%d final into %p\n",priv->myslot,priv->outcards);
memcpy(dp->hand.final,data,sizeof(bits256) * dp->N * dp->numcards); memcpy(dp->hand.final,data,sizeof(bits256) * dp->N * dp->numcards);
return(0); return(0);
} }
int32_t _pangea_facedown(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t cardi,int32_t senderind) int32_t pangea_facedown(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind,int32_t cardi)
{ {
int32_t i,validcard,n = 0; int32_t i,validcard,n = 0;
if ( data == 0 || datalen != sizeof(int32_t) ) if ( data == 0 || datalen != sizeof(int32_t) )
@ -597,8 +597,8 @@ int32_t _pangea_facedown(union pangeanet777 *hn,cJSON *json,struct cards777_pubd
n++; n++;
} }
if ( Debuglevel > 2 ) if ( Debuglevel > 2 )
PNACL_message(" | player.%d sees that destplayer.%d got cardi.%d valid.%d | %llx | n.%d\n",hn->client->H.slot,senderind,cardi,validcard,(long long)dp->hand.havemasks[senderind],n); PNACL_message(" | player.%d sees that destplayer.%d got cardi.%d valid.%d | %llx | n.%d\n",priv->myslot,senderind,cardi,validcard,(long long)dp->hand.havemasks[senderind],n);
if ( hn->client->H.slot == pangea_slotA(dp->table) && n == dp->N ) if ( priv->myslot == pangea_slotA(dp->table) && n == dp->N )
pangea_startbets(hn,dp,dp->N*2); pangea_startbets(hn,dp,dp->N*2);
return(0); return(0);
} }
@ -624,7 +624,7 @@ uint32_t pangea_rank(struct cards777_pubdata *dp,int32_t senderind)
return(dp->hand.handranks[senderind]); return(dp->hand.handranks[senderind]);
} }
int32_t _pangea_faceup(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_faceup(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
int32_t cardi,validcard,i; char hexstr[65]; uint16_t tmp; int32_t cardi,validcard,i; char hexstr[65]; uint16_t tmp;
if ( data == 0 || datalen != sizeof(bits256) ) if ( data == 0 || datalen != sizeof(bits256) )
@ -635,10 +635,10 @@ int32_t _pangea_faceup(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
init_hexbytes_noT(hexstr,data,sizeof(bits256)); init_hexbytes_noT(hexstr,data,sizeof(bits256));
cardi = juint(json,"cardi"); cardi = juint(json,"cardi");
validcard = ((int32_t)juint(json,"turni")) >= 0; validcard = ((int32_t)juint(json,"turni")) >= 0;
if ( Debuglevel > 2 || hn->client->H.slot == pangea_slotA(dp->table) ) if ( Debuglevel > 2 || priv->myslot == pangea_slotA(dp->table) )
{ {
char *str = jprint(json,0); char *str = jprint(json,0);
PNACL_message("from.%d -> player.%d COMMUNITY.[%d] (%s) cardi.%d valid.%d (%s)\n",senderind,hn->client->H.slot,data[1],hexstr,cardi,validcard,str); PNACL_message("from.%d -> player.%d COMMUNITY.[%d] (%s) cardi.%d valid.%d (%s)\n",senderind,priv->myslot,data[1],hexstr,cardi,validcard,str);
free(str); free(str);
} }
//PNACL_message("got FACEUP.(%s)\n",jprint(json,0)); //PNACL_message("got FACEUP.(%s)\n",jprint(json,0));
@ -655,10 +655,10 @@ int32_t _pangea_faceup(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
memcpy(dp->hand.community256[cardi - dp->N*2].bytes,data,sizeof(bits256)); memcpy(dp->hand.community256[cardi - dp->N*2].bytes,data,sizeof(bits256));
//PNACL_message("set community[%d] <- %d\n",cardi - dp->N*2,data[1]); //PNACL_message("set community[%d] <- %d\n",cardi - dp->N*2,data[1]);
if ( senderind == pangea_ind(dp->table,hn->client->H.slot) ) if ( senderind == pangea_ind(dp->table,priv->myslot) )
pangea_rank(dp,senderind); pangea_rank(dp,senderind);
//PNACL_message("calc rank\n"); //PNACL_message("calc rank\n");
if ( hn->client->H.slot == pangea_slotA(dp->table) && cardi >= dp->N*2+2 && cardi < dp->N*2+5 ) if ( priv->myslot == pangea_slotA(dp->table) && cardi >= dp->N*2+2 && cardi < dp->N*2+5 )
pangea_startbets(hn,dp,cardi+1); pangea_startbets(hn,dp,cardi+1);
//else PNACL_message("dont start bets %d\n",cardi+1); //else PNACL_message("dont start bets %d\n",cardi+1);
} }
@ -676,9 +676,9 @@ int32_t _pangea_faceup(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
return(0); return(0);
} }
int32_t _pangea_turn(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_turn(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
int32_t turni,cardi,i; char hex[2048]; uint64_t betsize = 0; struct pangea_info *sp = dp->table; int32_t turni,cardi,i; char hex[2048]; uint64_t betsize = 0; struct table_info *sp = dp->table;
turni = juint(json,"turni"); turni = juint(json,"turni");
cardi = juint(json,"cardi"); cardi = juint(json,"cardi");
if ( Debuglevel > 2 ) if ( Debuglevel > 2 )
@ -689,7 +689,7 @@ int32_t _pangea_turn(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata
dp->hand.cardi = cardi; dp->hand.cardi = cardi;
dp->hand.betstarted = 1; dp->hand.betstarted = 1;
dp->hand.undergun = turni; dp->hand.undergun = turni;
if ( hn->client->H.slot != pangea_slotA(dp->table) ) if ( priv->myslot != pangea_slotA(dp->table) )
{ {
pangea_checkantes(hn,dp); pangea_checkantes(hn,dp);
memcpy(dp->hand.snapshot,dp->hand.bets,dp->N*sizeof(uint64_t)); memcpy(dp->hand.snapshot,dp->hand.bets,dp->N*sizeof(uint64_t));
@ -697,16 +697,16 @@ int32_t _pangea_turn(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata
if ( dp->hand.bets[i] > betsize ) if ( dp->hand.bets[i] > betsize )
betsize = dp->hand.bets[i]; betsize = dp->hand.bets[i];
dp->hand.snapshot[dp->N] = betsize; dp->hand.snapshot[dp->N] = betsize;
//printf("player.%d sends confirmturn.%d\n",hn->client->H.slot,turni); //printf("player.%d sends confirmturn.%d\n",priv->myslot,turni);
pangea_sendcmd(hex,hn,"confirmturn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),cardi,turni); pangea_sendcmd(PANGEA_CALLARGS,"confirm",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),cardi,turni);
} }
} }
return(0); return(0);
} }
int32_t _pangea_confirmturn(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_confirmturn(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
uint32_t starttime; int32_t i,turni,cardi; uint64_t betsize=0,amount=0; struct pangea_info *sp=0; char hex[1024]; uint32_t starttime; int32_t i,turni,cardi; uint64_t betsize=0,amount=0; struct table_info *sp=0; char hex[1024];
if ( data == 0 ) if ( data == 0 )
{ {
printf("pangea_turn: null data\n"); printf("pangea_turn: null data\n");
@ -720,7 +720,7 @@ int32_t _pangea_confirmturn(union pangeanet777 *hn,cJSON *json,struct cards777_p
starttime = dp->hand.starttime; starttime = dp->hand.starttime;
if ( (sp= dp->table) != 0 ) if ( (sp= dp->table) != 0 )
{ {
if ( senderind == 0 && hn->client->H.slot != pangea_slotA(dp->table) ) if ( senderind == 0 && priv->myslot != pangea_slotA(dp->table) )
{ {
dp->hand.undergun = turni; dp->hand.undergun = turni;
dp->hand.cardi = cardi; dp->hand.cardi = cardi;
@ -740,27 +740,27 @@ int32_t _pangea_confirmturn(union pangeanet777 *hn,cJSON *json,struct cards777_p
break; break;
} }
//printf("sp.%p vs turni.%d cardi.%d hand.cardi %d\n",sp,turni,cardi,dp->hand.cardi); //printf("sp.%p vs turni.%d cardi.%d hand.cardi %d\n",sp,turni,cardi,dp->hand.cardi);
if ( hn->client->H.slot == pangea_slotA(dp->table) && i == dp->N ) if ( priv->myslot == pangea_slotA(dp->table) && i == dp->N )
{ {
for (betsize=i=0; i<dp->N; i++) for (betsize=i=0; i<dp->N; i++)
if ( dp->hand.bets[i] > betsize ) if ( dp->hand.bets[i] > betsize )
betsize = dp->hand.bets[i]; betsize = dp->hand.bets[i];
dp->hand.betsize = dp->hand.snapshot[dp->N] = betsize; dp->hand.betsize = dp->hand.snapshot[dp->N] = betsize;
//if ( Debuglevel > 2 ) //if ( Debuglevel > 2 )
printf("player.%d sends confirmturn.%d cardi.%d betsize %.0f\n",hn->client->H.slot,dp->hand.undergun,dp->hand.cardi,dstr(betsize)); printf("player.%d sends confirmturn.%d cardi.%d betsize %.0f\n",priv->myslot,dp->hand.undergun,dp->hand.cardi,dstr(betsize));
if ( senderind != 0 ) if ( senderind != 0 )
pangea_sendcmd(hex,hn,"confirmturn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),dp->hand.cardi,dp->hand.undergun); pangea_sendcmd(PANGEA_CALLARGS,"confirm",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),dp->hand.cardi,dp->hand.undergun);
} }
if ( senderind == 0 && (turni= dp->hand.undergun) == pangea_ind(dp->table,hn->client->H.slot) ) if ( senderind == 0 && (turni= dp->hand.undergun) == pangea_ind(dp->table,priv->myslot) )
{ {
if ( dp->hand.betsize != betsize ) if ( dp->hand.betsize != betsize )
printf("P%d: pangea_turn warning hand.betsize %.8f != betsize %.8f\n",hn->client->H.slot,dstr(dp->hand.betsize),dstr(betsize)); printf("P%d: pangea_turn warning hand.betsize %.8f != betsize %.8f\n",priv->myslot,dstr(dp->hand.betsize),dstr(betsize));
if ( sp->isbot[hn->client->H.slot] != 0 ) if ( sp->isbot[priv->myslot] != 0 )
pangea_bot(hn,dp,turni,cardi,betsize); pangea_bot(hn,dp,turni,cardi,betsize);
else if ( dp->hand.betstatus[pangea_ind(dp->table,hn->client->H.slot)] == CARDS777_FOLD || dp->hand.betstatus[pangea_ind(dp->table,hn->client->H.slot)] == CARDS777_ALLIN ) else if ( dp->hand.betstatus[pangea_ind(dp->table,priv->myslot)] == CARDS777_FOLD || dp->hand.betstatus[pangea_ind(dp->table,priv->myslot)] == CARDS777_ALLIN )
pangea_sendcmd(hex,hn,"action",-1,(void *)&amount,sizeof(amount),cardi,0); pangea_sendcmd(PANGEA_CALLARGS,"action",-1,(void *)&amount,sizeof(amount),cardi,0);
else if ( priv->autofold != 0 ) else if ( priv->autofold != 0 )
pangea_sendcmd(hex,hn,"action",-1,(void *)&amount,sizeof(amount),cardi,0); pangea_sendcmd(PANGEA_CALLARGS,"action",-1,(void *)&amount,sizeof(amount),cardi,0);
else else
{ {
dp->hand.userinput_starttime = (uint32_t)time(NULL); dp->hand.userinput_starttime = (uint32_t)time(NULL);
@ -768,38 +768,38 @@ int32_t _pangea_confirmturn(union pangeanet777 *hn,cJSON *json,struct cards777_p
dp->hand.betsize = betsize; dp->hand.betsize = betsize;
fprintf(stderr,"Waiting for user input cardi.%d: ",cardi); fprintf(stderr,"Waiting for user input cardi.%d: ",cardi);
} }
if ( hn->client->H.slot == pangea_slotA(dp->table) ) if ( priv->myslot == pangea_slotA(dp->table) )
{ {
char *str = jprint(pangea_tablestatus(sp),1); char *str = jprint(pangea_tablestatus(sp),1);
printf("%s\n",str); printf("%s\n",str);
free(str); free(str);
} }
//pangea_statusprint(dp,priv,pangea_ind(dp->table,hn->client->H.slot)); //pangea_statusprint(dp,priv,pangea_ind(dp->table,priv->myslot));
} }
} }
return(0); return(0);
} }
void pangea_sendsummary(union pangeanet777 *hn,struct cards777_pubdata *dp,struct cards777_privdata *priv) void pangea_sendsummary(struct table_info *tp)
{ {
char *hex; char *hex;
if ( (hex= malloc(dp->summarysize*2 + 4096)) != 0 ) if ( (hex= malloc(dp->summarysize*2 + 4096)) != 0 )
{ {
pangea_sendcmd(hex,hn,"summary",-1,dp->summary,dp->summarysize,0,0); pangea_sendcmd(PANGEA_CALLARGS,"summary",-1,dp->summary,dp->summarysize,0,0);
free(hex); free(hex);
} }
} }
int32_t _pangea_gotsummary(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_gotsummary(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
char *otherhist,*handhist = 0; int32_t matched = 0; struct pangea_info *sp = dp->table; char *otherhist,*handhist = 0; int32_t matched = 0; struct table_info *sp = dp->table;
if ( Debuglevel > 2 ) // ordering changes crc if ( Debuglevel > 2 ) // ordering changes crc
printf("player.%d [%d]: got summary.%d from %d memcmp.%d\n",hn->client->H.slot,dp->summarysize,datalen,senderind,memcmp(data,dp->summary,datalen)); printf("player.%d [%d]: got summary.%d from %d memcmp.%d\n",priv->myslot,dp->summarysize,datalen,senderind,memcmp(data,dp->summary,datalen));
if ( datalen == dp->summarysize ) if ( datalen == dp->summarysize )
{ {
if ( memcmp(dp->summary,data,datalen) == 0 ) if ( memcmp(dp->summary,data,datalen) == 0 )
{ {
//printf("P%d: matched senderind.%d\n",hn->client->H.slot,senderind); //printf("P%d: matched senderind.%d\n",priv->myslot,senderind);
matched = 1; matched = 1;
} }
else else
@ -810,7 +810,7 @@ int32_t _pangea_gotsummary(union pangeanet777 *hn,cJSON *json,struct cards777_pu
{ {
if ( strcmp(handhist,otherhist) == 0 ) if ( strcmp(handhist,otherhist) == 0 )
{ {
//printf("P%d: matched B senderind.%d\n",hn->client->H.slot,senderind); //printf("P%d: matched B senderind.%d\n",priv->myslot,senderind);
matched = 1; matched = 1;
} }
else printf("\n[%s] MISMATCHED vs \n[%s]\n",handhist,otherhist); else printf("\n[%s] MISMATCHED vs \n[%s]\n",handhist,otherhist);
@ -824,15 +824,15 @@ int32_t _pangea_gotsummary(union pangeanet777 *hn,cJSON *json,struct cards777_pu
dp->summaries |= (1LL << senderind); dp->summaries |= (1LL << senderind);
else else
{ {
//printf("P%d: MISMATCHED senderind.%d\n",hn->client->H.slot,senderind); //printf("P%d: MISMATCHED senderind.%d\n",priv->myslot,senderind);
dp->mismatches |= (1LL << senderind); dp->mismatches |= (1LL << senderind);
} }
if ( senderind == 0 && hn->client->H.slot != pangea_slotA(dp->table) ) if ( senderind == 0 && priv->myslot != pangea_slotA(dp->table) )
pangea_sendsummary(hn,dp,priv); pangea_sendsummary(hn,dp,priv);
if ( (dp->mismatches | dp->summaries) == (1LL << dp->N)-1 ) if ( (dp->mismatches | dp->summaries) == (1LL << dp->N)-1 )
{ {
if ( Debuglevel > 2 ) if ( Debuglevel > 2 )
printf("P%d: hand summary matches.%llx errors.%llx | size.%d\n",hn->client->H.slot,(long long)dp->summaries,(long long)dp->mismatches,dp->summarysize); printf("P%d: hand summary matches.%llx errors.%llx | size.%d\n",priv->myslot,(long long)dp->summaries,(long long)dp->mismatches,dp->summarysize);
//if ( handhist == 0 && (handhist= pangea_dispsummary(sp,1,dp->summary,dp->summarysize,sp->tableid,dp->numhands-1,dp->N)) != 0 ) //if ( handhist == 0 && (handhist= pangea_dispsummary(sp,1,dp->summary,dp->summarysize,sp->tableid,dp->numhands-1,dp->N)) != 0 )
// printf("HAND.(%s)\n",handhist), free(handhist); // printf("HAND.(%s)\n",handhist), free(handhist);
if ( hn->server->H.slot == 0 ) if ( hn->server->H.slot == 0 )
@ -847,7 +847,7 @@ int32_t _pangea_gotsummary(union pangeanet777 *hn,cJSON *json,struct cards777_pu
void pangea_finish(union pangeanet777 *hn,struct cards777_pubdata *dp) void pangea_finish(union pangeanet777 *hn,struct cards777_pubdata *dp)
{ {
int32_t j,n,r,norake = 0; uint64_t sidepots[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS],list[CARDS777_MAXPLAYERS],pangearake,rake; int64_t balances[CARDS777_MAXPLAYERS]; int32_t j,n,r,norake = 0; uint64_t sidepots[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS],list[CARDS777_MAXPLAYERS],pangearake,rake; int64_t balances[CARDS777_MAXPLAYERS];
uint32_t changes; uint16_t busted,rebuy; struct pangea_info *sp = dp->table; uint32_t changes; uint16_t busted,rebuy; struct table_info *sp = dp->table;
if ( dp->hand.finished == 0 ) if ( dp->hand.finished == 0 )
{ {
memset(sidepots,0,sizeof(sidepots)); memset(sidepots,0,sizeof(sidepots));
@ -877,7 +877,7 @@ void pangea_finish(union pangeanet777 *hn,struct cards777_pubdata *dp)
changes = (((uint32_t)rebuy<<20) | ((uint32_t)busted<<4) | (dp->N&0xf)); changes = (((uint32_t)rebuy<<20) | ((uint32_t)busted<<4) | (dp->N&0xf));
pangea_summary(hn,dp,CARDS777_CHANGES,(void *)&changes,sizeof(changes),(void *)balances,sizeof(uint64_t)*dp->N); pangea_summary(hn,dp,CARDS777_CHANGES,(void *)&changes,sizeof(changes),(void *)balances,sizeof(uint64_t)*dp->N);
pangea_summary(hn,dp,CARDS777_RAKES,(void *)&rake,sizeof(rake),(void *)&pangearake,sizeof(pangearake)); pangea_summary(hn,dp,CARDS777_RAKES,(void *)&rake,sizeof(rake),(void *)&pangearake,sizeof(pangearake));
if ( hn->client->H.slot == pangea_slotA(dp->table) ) if ( priv->myslot == pangea_slotA(dp->table) )
{ {
char *sumstr,*statstr; char *sumstr,*statstr;
statstr = jprint(pangea_tablestatus(dp->table),1); statstr = jprint(pangea_tablestatus(dp->table),1);
@ -900,7 +900,7 @@ void pangea_finish(union pangeanet777 *hn,struct cards777_pubdata *dp)
} }
} }
int32_t pangea_lastman(union pangeanet777 *hn,struct cards777_pubdata *dp,struct cards777_privdata *priv) int32_t pangea_lastman(struct table_info *tp)
{ {
int32_t activej = -1; char hex[1024]; int32_t activej = -1; char hex[1024];
if ( dp->hand.betstarted != 0 && pangea_actives(&activej,dp) <= 1 ) if ( dp->hand.betstarted != 0 && pangea_actives(&activej,dp) <= 1 )
@ -912,8 +912,8 @@ int32_t pangea_lastman(union pangeanet777 *hn,struct cards777_pubdata *dp,struct
} }
if ( 0 && hn->server->H.slot == activej && priv->automuck == 0 ) if ( 0 && hn->server->H.slot == activej && priv->automuck == 0 )
{ {
pangea_sendcmd(hex,hn,"faceup",-1,priv->holecards[0].bytes,sizeof(priv->holecards[0]),priv->cardis[0],priv->cardis[0] != 0xff); pangea_sendcmd(PANGEA_CALLARGS,"faceup",-1,priv->holecards[0].bytes,sizeof(priv->holecards[0]),priv->cardis[0],priv->cardis[0] != 0xff);
pangea_sendcmd(hex,hn,"faceup",-1,priv->holecards[1].bytes,sizeof(priv->holecards[1]),priv->cardis[1],priv->cardis[1] != 0xff); pangea_sendcmd(PANGEA_CALLARGS,"faceup",-1,priv->holecards[1].bytes,sizeof(priv->holecards[1]),priv->cardis[1],priv->cardis[1] != 0xff);
} }
pangea_finish(hn,dp); pangea_finish(hn,dp);
return(1); return(1);
@ -943,7 +943,7 @@ void pangea_startbets(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t
else pangea_checkantes(hn,dp); else pangea_checkantes(hn,dp);
dp->hand.snapshot[dp->N] = dp->hand.betsize; dp->hand.snapshot[dp->N] = dp->hand.betsize;
printf("STARTBETS.%d cardi.%d numactions.%d undergun.%d betsize %.8f dp->N %d\n",dp->hand.betstarted,cardi,dp->hand.numactions,dp->hand.undergun,dstr(dp->hand.betsize),dp->N); printf("STARTBETS.%d cardi.%d numactions.%d undergun.%d betsize %.8f dp->N %d\n",dp->hand.betstarted,cardi,dp->hand.numactions,dp->hand.undergun,dstr(dp->hand.betsize),dp->N);
pangea_sendcmd(hex,hn,"turn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),cardi,dp->hand.undergun); pangea_sendcmd(PANGEA_CALLARGS,"turn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),cardi,dp->hand.undergun);
/*for (i=0; i<dp->N; i++) /*for (i=0; i<dp->N; i++)
{ {
j = (dp->hand.undergun + i) % dp->N; j = (dp->hand.undergun + i) % dp->N;
@ -954,7 +954,7 @@ void pangea_startbets(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t
if ( i != dp->N ) if ( i != dp->N )
{ {
dp->hand.undergun = j; dp->hand.undergun = j;
pangea_sendcmd(hex,hn,"turn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),cardi,dp->hand.undergun); pangea_sendcmd(PANGEA_CALLARGS,"turn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),cardi,dp->hand.undergun);
} }
else if ( pangea_lastman(hn,dp,hn->client->H.privdata) > 0 ) else if ( pangea_lastman(hn,dp,hn->client->H.privdata) > 0 )
{ {
@ -963,7 +963,7 @@ void pangea_startbets(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t
} else printf("UNEXPECTED condition missing lastman\n");*/ } else printf("UNEXPECTED condition missing lastman\n");*/
} }
int32_t _pangea_action(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_action(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
uint32_t now; int32_t action,cardi,i,j,destplayer = 0; bits256 audit[CARDS777_MAXPLAYERS]; char hex[1024]; uint8_t tmp; uint64_t amount = 0; uint32_t now; int32_t action,cardi,i,j,destplayer = 0; bits256 audit[CARDS777_MAXPLAYERS]; char hex[1024]; uint8_t tmp; uint64_t amount = 0;
action = juint(json,"turni"); action = juint(json,"turni");
@ -977,7 +977,7 @@ int32_t _pangea_action(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
} }
if ( senderind != dp->hand.undergun ) if ( senderind != dp->hand.undergun )
{ {
printf("T%d: out of turn action.%d by player.%d (undergun.%d) cardi.%d amount %.8f\n",hn->client->H.slot,action,senderind,dp->hand.undergun,cardi,dstr(amount)); printf("T%d: out of turn action.%d by player.%d (undergun.%d) cardi.%d amount %.8f\n",priv->myslot,action,senderind,dp->hand.undergun,cardi,dstr(amount));
return(-1); return(-1);
} }
tmp = senderind; tmp = senderind;
@ -985,11 +985,11 @@ int32_t _pangea_action(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
dp->hand.actions[senderind] = action; dp->hand.actions[senderind] = action;
dp->hand.undergun = (dp->hand.undergun + 1) % dp->N; dp->hand.undergun = (dp->hand.undergun + 1) % dp->N;
dp->hand.numactions++; dp->hand.numactions++;
if ( Debuglevel > 2 )//|| hn->client->H.slot == 0 ) if ( Debuglevel > 2 )//|| priv->myslot == 0 )
printf("player.%d: got action.%d cardi.%d senderind.%d -> undergun.%d numactions.%d\n",hn->client->H.slot,action,cardi,senderind,dp->hand.undergun,dp->hand.numactions); printf("player.%d: got action.%d cardi.%d senderind.%d -> undergun.%d numactions.%d\n",priv->myslot,action,cardi,senderind,dp->hand.undergun,dp->hand.numactions);
if ( pangea_lastman(hn,dp,priv) > 0 ) if ( pangea_lastman(hn,dp,priv) > 0 )
return(0); return(0);
if ( hn->client->H.slot == pangea_slotA(dp->table) ) if ( priv->myslot == pangea_slotA(dp->table) )
{ {
now = (uint32_t)time(NULL); now = (uint32_t)time(NULL);
for (i=j=0; i<dp->N; i++) for (i=j=0; i<dp->N; i++)
@ -1005,9 +1005,9 @@ int32_t _pangea_action(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
dp->hand.undergun = j; dp->hand.undergun = j;
if ( dp->hand.numactions < dp->N ) if ( dp->hand.numactions < dp->N )
{ {
//printf("T%d: senderind.%d i.%d j.%d -> undergun.%d numactions.%d\n",hn->client->H.slot,senderind,i,j,dp->hand.undergun,dp->hand.numactions); //printf("T%d: senderind.%d i.%d j.%d -> undergun.%d numactions.%d\n",priv->myslot,senderind,i,j,dp->hand.undergun,dp->hand.numactions);
//if ( senderind != 0 ) //if ( senderind != 0 )
pangea_sendcmd(hex,hn,"turn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),dp->hand.cardi,dp->hand.undergun); pangea_sendcmd(PANGEA_CALLARGS,"turn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),dp->hand.cardi,dp->hand.undergun);
} }
else else
{ {
@ -1028,7 +1028,7 @@ int32_t _pangea_action(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
{ {
memset(audit,0,sizeof(audit)); memset(audit,0,sizeof(audit));
audit[0] = dp->hand.final[cardi*dp->N + destplayer]; audit[0] = dp->hand.final[cardi*dp->N + destplayer];
pangea_sendcmd(hex,hn,"decoded",-1,audit[0].bytes,sizeof(bits256)*dp->N,cardi,dp->N-1); pangea_sendcmd(PANGEA_CALLARGS,"decoded",-1,audit[0].bytes,sizeof(bits256)*dp->N,cardi,dp->N-1);
} }
} }
else if ( i == 3 ) else if ( i == 3 )
@ -1039,8 +1039,8 @@ int32_t _pangea_action(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
printf("decode turn\n"); printf("decode turn\n");
memset(audit,0,sizeof(audit)); memset(audit,0,sizeof(audit));
audit[0] = dp->hand.final[cardi*dp->N + destplayer]; audit[0] = dp->hand.final[cardi*dp->N + destplayer];
pangea_sendcmd(hex,hn,"decoded",-1,audit[0].bytes,sizeof(bits256)*dp->N,cardi,dp->N-1); pangea_sendcmd(PANGEA_CALLARGS,"decoded",-1,audit[0].bytes,sizeof(bits256)*dp->N,cardi,dp->N-1);
//pangea_sendcmd(hex,hn,"decoded",-1,dp->hand.final[cardi*dp->N + destplayer].bytes,sizeof(dp->hand.final[cardi*dp->N + destplayer]),cardi,dp->N-1); //pangea_sendcmd(PANGEA_CALLARGS,"decoded",-1,dp->hand.final[cardi*dp->N + destplayer].bytes,sizeof(dp->hand.final[cardi*dp->N + destplayer]),cardi,dp->N-1);
} }
else if ( i == 4 ) else if ( i == 4 )
{ {
@ -1050,8 +1050,8 @@ int32_t _pangea_action(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
cardi = dp->hand.cardi; cardi = dp->hand.cardi;
memset(audit,0,sizeof(audit)); memset(audit,0,sizeof(audit));
audit[0] = dp->hand.final[cardi*dp->N + destplayer]; audit[0] = dp->hand.final[cardi*dp->N + destplayer];
pangea_sendcmd(hex,hn,"decoded",-1,audit[0].bytes,sizeof(bits256)*dp->N,cardi,dp->N-1); pangea_sendcmd(PANGEA_CALLARGS,"decoded",-1,audit[0].bytes,sizeof(bits256)*dp->N,cardi,dp->N-1);
//pangea_sendcmd(hex,hn,"decoded",-1,dp->hand.final[cardi*dp->N + destplayer].bytes,sizeof(dp->hand.final[cardi*dp->N + destplayer]),cardi,dp->N-1); //pangea_sendcmd(PANGEA_CALLARGS,"decoded",-1,dp->hand.final[cardi*dp->N + destplayer].bytes,sizeof(dp->hand.final[cardi*dp->N + destplayer]),cardi,dp->N-1);
} }
else else
{ {
@ -1066,14 +1066,14 @@ int32_t _pangea_action(union pangeanet777 *hn,cJSON *json,struct cards777_pubdat
} }
dp->hand.undergun = j; dp->hand.undergun = j;
printf("sent showdown request for undergun.%d\n",j); printf("sent showdown request for undergun.%d\n",j);
pangea_sendcmd(hex,hn,"showdown",-1,(void *)&dp->hand.betsize,sizeof(dp->hand.betsize),cardi,dp->hand.undergun); pangea_sendcmd(PANGEA_CALLARGS,"showdown",-1,(void *)&dp->hand.betsize,sizeof(dp->hand.betsize),cardi,dp->hand.undergun);
} }
} }
} }
if ( Debuglevel > 2 )// || hn->client->H.slot == 0 ) if ( Debuglevel > 2 )// || priv->myslot == 0 )
{ {
char *str = jprint(pangea_tablestatus(dp->table),1); char *str = jprint(pangea_tablestatus(dp->table),1);
printf("player.%d got pangea_action.%d for player.%d action.%d amount %.8f | numactions.%d\n%s\n",hn->client->H.slot,cardi,senderind,action,dstr(amount),dp->hand.numactions,str); printf("player.%d got pangea_action.%d for player.%d action.%d amount %.8f | numactions.%d\n%s\n",priv->myslot,cardi,senderind,action,dstr(amount),dp->hand.numactions,str);
free(str); free(str);
} }
return(0); return(0);
@ -1088,27 +1088,27 @@ int32_t pangea_myrank(struct cards777_pubdata *dp,int32_t senderind)
return(myrank != 0); return(myrank != 0);
} }
int32_t _pangea_showdown(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_showdown(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
char hex[1024]; int32_t i,turni,cardi; uint64_t amount = 0; char hex[1024]; int32_t i,turni,cardi; uint64_t amount = 0;
turni = juint(json,"turni"); turni = juint(json,"turni");
cardi = juint(json,"cardi"); cardi = juint(json,"cardi");
if ( Debuglevel > 2 ) if ( Debuglevel > 2 )
printf("P%d: showdown from sender.%d\n",hn->client->H.slot,senderind); printf("P%d: showdown from sender.%d\n",priv->myslot,senderind);
if ( dp->hand.betstatus[pangea_ind(dp->table,hn->client->H.slot)] != CARDS777_FOLD && ((priv->automuck == 0 && dp->hand.actions[pangea_ind(dp->table,hn->client->H.slot)] != CARDS777_SENTCARDS) || (turni == pangea_ind(dp->table,hn->client->H.slot) && dp->hand.lastbettor == pangea_ind(dp->table,hn->client->H.slot))) ) if ( dp->hand.betstatus[pangea_ind(dp->table,priv->myslot)] != CARDS777_FOLD && ((priv->automuck == 0 && dp->hand.actions[pangea_ind(dp->table,priv->myslot)] != CARDS777_SENTCARDS) || (turni == pangea_ind(dp->table,priv->myslot) && dp->hand.lastbettor == pangea_ind(dp->table,priv->myslot))) )
{ {
if ( priv->automuck != 0 && pangea_myrank(dp,pangea_ind(dp->table,hn->client->H.slot)) < 0 ) if ( priv->automuck != 0 && pangea_myrank(dp,pangea_ind(dp->table,priv->myslot)) < 0 )
pangea_sendcmd(hex,hn,"action",-1,(void *)&amount,sizeof(amount),cardi,CARDS777_FOLD); pangea_sendcmd(PANGEA_CALLARGS,"action",-1,(void *)&amount,sizeof(amount),cardi,CARDS777_FOLD);
else else
{ {
pangea_sendcmd(hex,hn,"faceup",-1,priv->holecards[0].bytes,sizeof(priv->holecards[0]),priv->cardis[0],pangea_ind(dp->table,hn->client->H.slot)); pangea_sendcmd(PANGEA_CALLARGS,"faceup",-1,priv->holecards[0].bytes,sizeof(priv->holecards[0]),priv->cardis[0],pangea_ind(dp->table,priv->myslot));
pangea_sendcmd(hex,hn,"faceup",-1,priv->holecards[1].bytes,sizeof(priv->holecards[1]),priv->cardis[1],pangea_ind(dp->table,hn->client->H.slot)); pangea_sendcmd(PANGEA_CALLARGS,"faceup",-1,priv->holecards[1].bytes,sizeof(priv->holecards[1]),priv->cardis[1],pangea_ind(dp->table,priv->myslot));
dp->hand.actions[pangea_ind(dp->table,hn->client->H.slot)] = CARDS777_SENTCARDS; dp->hand.actions[pangea_ind(dp->table,priv->myslot)] = CARDS777_SENTCARDS;
} }
} }
if ( pangea_lastman(hn,dp,priv) > 0 ) if ( pangea_lastman(hn,dp,priv) > 0 )
return(0); return(0);
if ( hn->client->H.slot == pangea_slotA(dp->table) && senderind != 0 ) if ( priv->myslot == pangea_slotA(dp->table) && senderind != 0 )
{ {
for (i=0; i<dp->N; i++) for (i=0; i<dp->N; i++)
{ {
@ -1122,14 +1122,14 @@ int32_t _pangea_showdown(union pangeanet777 *hn,cJSON *json,struct cards777_pubd
break; break;
} }
printf("senderind.%d host sends showdown for undergun.%d\n",senderind,dp->hand.undergun); printf("senderind.%d host sends showdown for undergun.%d\n",senderind,dp->hand.undergun);
pangea_sendcmd(hex,hn,"showdown",-1,(void *)&dp->hand.betsize,sizeof(dp->hand.betsize),cardi,dp->hand.undergun); pangea_sendcmd(PANGEA_CALLARGS,"showdown",-1,(void *)&dp->hand.betsize,sizeof(dp->hand.betsize),cardi,dp->hand.undergun);
} }
return(0); return(0);
} }
char *_pangea_input(uint64_t my64bits,uint64_t tableid,cJSON *json) char *pangea_input(uint64_t my64bits,uint64_t tableid,cJSON *json)
{ {
char *actionstr; uint64_t sum,amount=0; int32_t action=0,num,threadid; struct pangea_info *sp; struct cards777_pubdata *dp; char hex[4096]; char *actionstr; uint64_t sum,amount=0; int32_t action=0,num,threadid; struct table_info *sp; struct cards777_pubdata *dp; char hex[4096];
threadid = juint(json,"threadid"); threadid = juint(json,"threadid");
if ( (sp= pangea_threadtables(&num,threadid,tableid)) == 0 ) if ( (sp= pangea_threadtables(&num,threadid,tableid)) == 0 )
return(clonestr("{\"error\":\"you are not playing on any tables\"}")); return(clonestr("{\"error\":\"you are not playing on any tables\"}"));
@ -1195,7 +1195,7 @@ char *_pangea_input(uint64_t my64bits,uint64_t tableid,cJSON *json)
} }
} }
int32_t _pangea_ping(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata *dp,struct cards777_privdata *priv,uint8_t *data,int32_t datalen,int32_t senderind) int32_t pangea_ping(PANGEA_ARGS,uint8_t *data,int32_t datalen,int32_t senderind)
{ {
dp->hand.othercardpubs[senderind] = *(uint64_t *)data; dp->hand.othercardpubs[senderind] = *(uint64_t *)data;
if ( senderind == 0 ) if ( senderind == 0 )
@ -1208,7 +1208,7 @@ int32_t _pangea_ping(union pangeanet777 *hn,cJSON *json,struct cards777_pubdata
dp->hand.community[i] = juint(jitem(array,i),0); dp->hand.community[i] = juint(jitem(array,i),0);
}*/ }*/
} }
//PNACL_message("player.%d GOTPING.(%s) %llx\n",hn->client->H.slot,jprint(json,0),(long long)dp->othercardpubs[senderind]); //PNACL_message("player.%d GOTPING.(%s) %llx\n",priv->myslot,jprint(json,0),(long long)dp->othercardpubs[senderind]);
return(0); return(0);
} }
@ -1216,10 +1216,10 @@ void p_angea_chat(uint64_t senderbits,void *buf,int32_t len,int32_t senderind)
{ {
PNACL_message(">>>>>>>>>>> CHAT FROM.%d %llu: (%s)\n",senderind,(long long)senderbits,(char *)buf); PNACL_message(">>>>>>>>>>> CHAT FROM.%d %llu: (%s)\n",senderind,(long long)senderbits,(char *)buf);
} }
/*
int32_t pangea_poll(uint64_t *senderbitsp,uint32_t *timestampp,union pangeanet777 *hn) int32_t pangea_poll(uint64_t *senderbitsp,uint32_t *timestampp,union pangeanet777 *hn)
{ {
char *jsonstr,*hexstr,*cmdstr; cJSON *json; struct cards777_privdata *priv; struct cards777_pubdata *dp; struct pangea_info *sp; char *jsonstr,*hexstr,*cmdstr; cJSON *json; struct cards777_privdata *priv; struct cards777_pubdata *dp; struct table_info *sp;
int32_t len,senderind,maxlen; uint8_t *buf; int32_t len,senderind,maxlen; uint8_t *buf;
*senderbitsp = 0; *senderbitsp = 0;
dp = hn->client->H.pubdata, sp = dp->table; dp = hn->client->H.pubdata, sp = dp->table;
@ -1239,7 +1239,7 @@ int32_t pangea_poll(uint64_t *senderbitsp,uint32_t *timestampp,union pangeanet77
if ( dp != 0 && priv != 0 && (jsonstr= queue_dequeue(&hn->client->H.Q,1)) != 0 ) if ( dp != 0 && priv != 0 && (jsonstr= queue_dequeue(&hn->client->H.Q,1)) != 0 )
{ {
//pangea_neworder(dp,dp->table,0,0); //pangea_neworder(dp,dp->table,0,0);
//PNACL_message("player.%d GOT.(%s)\n",hn->client->H.slot,jsonstr); //PNACL_message("player.%d GOT.(%s)\n",priv->myslot,jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 ) if ( (json= cJSON_Parse(jsonstr)) != 0 )
{ {
*senderbitsp = j64bits(json,"sender"); *senderbitsp = j64bits(json,"sender");
@ -1275,41 +1275,41 @@ int32_t pangea_poll(uint64_t *senderbitsp,uint32_t *timestampp,union pangeanet77
if ( cmdstr != 0 ) if ( cmdstr != 0 )
{ {
if ( strcmp(cmdstr,"newhand") == 0 ) if ( strcmp(cmdstr,"newhand") == 0 )
_pangea_newhand(hn,json,dp,priv,buf,len,senderind); pangea_newhand(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"ping") == 0 ) else if ( strcmp(cmdstr,"ping") == 0 )
_pangea_ping(hn,json,dp,priv,buf,len,senderind); pangea_ping(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"gotdeck") == 0 ) else if ( strcmp(cmdstr,"gotdeck") == 0 )
_pangea_gotdeck(hn,json,dp,priv,buf,len,senderind); pangea_gotdeck(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"ready") == 0 ) else if ( strcmp(cmdstr,"ready") == 0 )
_pangea_ready(hn,json,dp,priv,buf,len,senderind); pangea_ready(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"encoded") == 0 ) else if ( strcmp(cmdstr,"encoded") == 0 )
_pangea_encoded(hn,json,dp,priv,buf,len,senderind); pangea_encoded(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"final") == 0 ) else if ( strcmp(cmdstr,"final") == 0 )
_pangea_final(hn,json,dp,priv,buf,len,senderind); pangea_final(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"addfunds") == 0 ) else if ( strcmp(cmdstr,"addfunds") == 0 )
_pangea_addfunds(hn,json,dp,priv,buf,len,senderind); pangea_addfunds(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"preflop") == 0 ) else if ( strcmp(cmdstr,"preflop") == 0 )
_pangea_preflop(hn,json,dp,priv,buf,len,senderind); pangea_preflop(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"decoded") == 0 ) else if ( strcmp(cmdstr,"decoded") == 0 )
_pangea_decoded(hn,json,dp,priv,buf,len,senderind); pangea_decoded(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"card") == 0 ) else if ( strcmp(cmdstr,"card") == 0 )
_pangea_card(hn,json,dp,priv,buf,len,juint(json,"cardi"),senderind); pangea_card(PANGEA_CALLARGS,buf,len,juint(json,"cardi"),senderind);
else if ( strcmp(cmdstr,"facedown") == 0 ) else if ( strcmp(cmdstr,"facedown") == 0 )
_pangea_facedown(hn,json,dp,priv,buf,len,juint(json,"cardi"),senderind); pangea_facedown(PANGEA_CALLARGS,buf,len,juint(json,"cardi"),senderind);
else if ( strcmp(cmdstr,"faceup") == 0 ) else if ( strcmp(cmdstr,"faceup") == 0 )
_pangea_faceup(hn,json,dp,priv,buf,len,senderind); pangea_faceup(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"turn") == 0 ) else if ( strcmp(cmdstr,"turn") == 0 )
_pangea_turn(hn,json,dp,priv,buf,len,senderind); pangea_turn(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"confirmturn") == 0 ) else if ( strcmp(cmdstr,"confirm") == 0 )
_pangea_confirmturn(hn,json,dp,priv,buf,len,senderind); pangea_confirmturn(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"chat") == 0 ) else if ( strcmp(cmdstr,"chat") == 0 )
_pangea_chat(*senderbitsp,buf,len,senderind); pangea_chat(*senderbitsp,buf,len,senderind);
else if ( strcmp(cmdstr,"action") == 0 ) else if ( strcmp(cmdstr,"action") == 0 )
_pangea_action(hn,json,dp,priv,buf,len,senderind); pangea_action(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"showdown") == 0 ) else if ( strcmp(cmdstr,"showdown") == 0 )
_pangea_showdown(hn,json,dp,priv,buf,len,senderind); pangea_showdown(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"summary") == 0 ) else if ( strcmp(cmdstr,"summary") == 0 )
_pangea_gotsummary(hn,json,dp,priv,buf,len,senderind); pangea_gotsummary(PANGEA_CALLARGS,buf,len,senderind);
} }
cleanup: cleanup:
free_json(json); free_json(json);
@ -1318,11 +1318,11 @@ int32_t pangea_poll(uint64_t *senderbitsp,uint32_t *timestampp,union pangeanet77
} }
free(buf); free(buf);
return(hn->client->H.state); return(hn->client->H.state);
} }*/
void pangea_serverstate(union pangeanet777 *hn,struct cards777_pubdata *dp,struct cards777_privdata *priv) void pangea_serverstate(struct table_info *tp)
{ {
int32_t i,j,n; struct pangea_info *sp = dp->table; int32_t i,j,n; struct table_info *sp = dp->table;
if ( dp->hand.finished != 0 && time(NULL) > dp->hand.finished+PANGEA_HANDGAP ) if ( dp->hand.finished != 0 && time(NULL) > dp->hand.finished+PANGEA_HANDGAP )
{ {
PNACL_message("HANDGAP\n"); PNACL_message("HANDGAP\n");
@ -1377,7 +1377,7 @@ int32_t pangea_idle(struct supernet_info *plugin)
if ( (tp= THREADS[i]) != 0 ) if ( (tp= THREADS[i]) != 0 )
{ {
hn = &tp->hn; hn = &tp->hn;
//PNACL_message("pangea idle player.%d\n",hn->client->H.slot); //PNACL_message("pangea idle player.%d\n",priv->myslot);
if ( hn->client->H.done == 0 ) if ( hn->client->H.done == 0 )
{ {
n++; n++;
@ -1385,7 +1385,7 @@ int32_t pangea_idle(struct supernet_info *plugin)
m++; m++;
pangea_poll(&senderbits,&timestamp,hn); pangea_poll(&senderbits,&timestamp,hn);
dp = hn->client->H.pubdata; dp = hn->client->H.pubdata;
if ( dp != 0 && hn->client->H.slot == pangea_slotA(dp->table) ) if ( dp != 0 && priv->myslot == pangea_slotA(dp->table) )
pinggap = 1; pinggap = 1;
if ( hn->client != 0 && dp != 0 ) if ( hn->client != 0 && dp != 0 )
{ {
@ -1393,16 +1393,16 @@ int32_t pangea_idle(struct supernet_info *plugin)
{ {
if ( 0 && (dp= hn->client->H.pubdata) != 0 ) if ( 0 && (dp= hn->client->H.pubdata) != 0 )
{ {
pangea_sendcmd(hex,hn,"ping",-1,dp->hand.checkprod.bytes,sizeof(uint64_t),dp->hand.cardi,dp->hand.undergun); pangea_sendcmd(PANGEA_CALLARGS,"ping",-1,dp->hand.checkprod.bytes,sizeof(uint64_t),dp->hand.cardi,dp->hand.undergun);
hn->client->H.lastping = (uint32_t)time(NULL); hn->client->H.lastping = (uint32_t)time(NULL);
} }
} }
if ( dp->hand.handmask == ((1 << dp->N) - 1) && dp->hand.finished == 0 )//&& dp->hand.pangearake == 0 ) if ( dp->hand.handmask == ((1 << dp->N) - 1) && dp->hand.finished == 0 )//&& dp->hand.pangearake == 0 )
{ {
PNACL_message("P%d: all players folded or showed cards at %ld | rakemillis %d\n",hn->client->H.slot,(long)time(NULL),dp->rakemillis); PNACL_message("P%d: all players folded or showed cards at %ld | rakemillis %d\n",priv->myslot,(long)time(NULL),dp->rakemillis);
pangea_finish(hn,dp); pangea_finish(hn,dp);
} }
if ( hn->client->H.slot == pangea_slotA(dp->table) ) if ( priv->myslot == pangea_slotA(dp->table) )
pangea_serverstate(hn,dp,hn->server->H.privdata); pangea_serverstate(hn,dp,hn->server->H.privdata);
} }
} }
@ -1418,3 +1418,61 @@ int32_t pangea_idle(struct supernet_info *plugin)
// pangea_userpoll(&THREADS[i]->hn); // pangea_userpoll(&THREADS[i]->hn);
return(0); return(0);
} }
int32_t pangea_updatemsgs(struct supernet_info *myinfo,struct pangea_msghdr *pm,struct table_info *tp)
{
char *cmdstr; bits256 tablehash; int32_t n,senderind,len; uint8_t *buf;
uint64_t senderbits; uint32_t timestamp;
char str[65]; printf("PANGEA.(%s) sends %s\n",bits256_str(str,pm->sig.pubkey),pm->sig.serialized);
tablehash = pm->tablehash;
senderbits = pm->sig.senderbits;
if ( (senderind= pm->myind) < 0 || senderind >= dp->N )
return(-1);
timestamp = pm->sig.timestamp;
buf = pm->serialized;
len = (int32_t)(pm->allocsize - sizeof(*pm));
//hn->client->H.state = juint(json,"state");
if ( (cmdstr= jstr(json,"cmd")) != 0 )
{
if ( strcmp(cmdstr,"newtable") == 0 )
pangea_addtable(PANGEA_CALLARGS,tablehash);
else
{
if ( strcmp(cmdstr,"newhand") == 0 )
pangea_newhand(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"ping") == 0 )
pangea_ping(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"gotdeck") == 0 )
pangea_gotdeck(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"ready") == 0 )
pangea_ready(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"encoded") == 0 )
pangea_encoded(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"final") == 0 )
pangea_final(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"addfunds") == 0 )
_pangea_addfunds(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"preflop") == 0 )
pangea_preflop(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"decoded") == 0 )
pangea_decoded(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"card") == 0 )
pangea_card(PANGEA_CALLARGS,buf,len,senderind,pm->cardi);
else if ( strcmp(cmdstr,"facedown") == 0 )
pangea_facedown(PANGEA_CALLARGS,buf,len,senderind,pm->cardi);
else if ( strcmp(cmdstr,"faceup") == 0 )
pangea_faceup(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"turn") == 0 )
_pangea_turn(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"confirm") == 0 )
pangea_confirmturn(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"action") == 0 )
pangea_action(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"showdown") == 0 )
pangea_showdown(PANGEA_CALLARGS,buf,len,senderind);
else if ( strcmp(cmdstr,"summary") == 0 )
pangea_gotsummary(PANGEA_CALLARGS,buf,len,senderind);
}
}
return(0);
}

270
iguana/pangea_funds.c

@ -15,258 +15,6 @@
#include "pangea777.h" #include "pangea777.h"
char *pangea_typestr(uint8_t type)
{
static char err[64];
switch ( type )
{
case 0xff: return("fold");
case CARDS777_START: return("start");
case CARDS777_ANTE: return("ante");
case CARDS777_SMALLBLIND: return("smallblind");
case CARDS777_BIGBLIND: return("bigblind");
case CARDS777_CHECK: return("check");
case CARDS777_CALL: return("call");
case CARDS777_BET: return("bet");
case CARDS777_RAISE: return("raise");
case CARDS777_FULLRAISE: return("fullraise");
case CARDS777_SENTCARDS: return("sentcards");
case CARDS777_ALLIN: return("allin");
case CARDS777_FACEUP: return("faceup");
case CARDS777_WINNINGS: return("won");
case CARDS777_RAKES: return("rakes");
case CARDS777_CHANGES: return("changes");
case CARDS777_SNAPSHOT: return("snapshot");
}
sprintf(err,"unknown type.%d",type);
return(err);
}
cJSON *pangea_handitem(int32_t *cardip,cJSON **pitemp,uint8_t type,uint64_t valA,uint64_t *bits64p,bits256 card,int32_t numplayers)
{
int32_t cardi,n,i,rebuy,busted; char str[128],hexstr[65],cardpubs[(CARDS777_MAXCARDS+1)*64+1]; cJSON *item,*array,*pitem = 0;
item = cJSON_CreateObject();
*cardip = -1;
switch ( type )
{
case CARDS777_START:
jaddnum(item,"handid",valA);
init_hexbytes_noT(cardpubs,(void *)bits64p,(int32_t)((CARDS777_MAXCARDS+1) * sizeof(bits256)));
jaddstr(item,"cardpubs",cardpubs);
break;
case CARDS777_RAKES:
jaddnum(item,"hostrake",dstr(valA));
jaddnum(item,"pangearake",dstr(*bits64p));
break;
case CARDS777_SNAPSHOT:
jaddnum(item,"handid",valA);
array = cJSON_CreateArray();
for (i=0; i<CARDS777_MAXPLAYERS; i++)
{
if ( i < numplayers )
jaddinum(array,dstr(bits64p[i]));
else jaddinum(array,dstr(0));
}
jadd(item,"snapshot",array);
//printf("add snapshot for numplayers.%d\n",numplayers);
break;
case CARDS777_CHANGES:
n = (int32_t)(valA & 0xf);
busted = (int32_t)((valA>>4) & 0xffff);
rebuy = (int32_t)((valA>>20) & 0xffff);
if ( busted != 0 )
jaddnum(item,"busted",busted);
if ( rebuy != 0 )
jaddnum(item,"rebuy",rebuy);
array = cJSON_CreateArray();
for (i=0; i<n; i++)
jaddinum(array,dstr(bits64p[i]));
jadd(item,"balances",array);
break;
case CARDS777_WINNINGS:
if ( (int32_t)valA >= 0 && valA < numplayers )
jaddnum(item,"player",valA);
jaddnum(item,"won",dstr(*bits64p));
if ( pitem == 0 )
pitem = cJSON_CreateObject();
jaddnum(pitem,"won",dstr(*bits64p));
break;
case CARDS777_FACEUP:
*cardip = cardi = (int32_t)(valA >> 8);
if ( cardi >= 0 && cardi < 52 )
jaddnum(item,"cardi",cardi);
else printf("illegal cardi.%d valA.%llu\n",cardi,(long long)valA);
valA &= 0xff;
if ( (int32_t)valA >= 0 && valA < numplayers )
jaddnum(item,"player",valA);
else if ( valA == 0xff )
jaddnum(item,"community",cardi - numplayers*2);
cardstr(str,card.bytes[1]);
jaddnum(item,str,card.bytes[1]);
init_hexbytes_noT(hexstr,card.bytes,sizeof(card));
jaddstr(item,"privkey",hexstr);
break;
default:
if ( (int32_t)valA >= 0 && valA < numplayers )
jaddnum(item,"player",valA);
jaddstr(item,"action",pangea_typestr(type));
if ( pitem == 0 )
pitem = cJSON_CreateObject();
if ( *bits64p != 0 )
{
jaddnum(item,"bet",dstr(*bits64p));
jaddnum(pitem,pangea_typestr(type),dstr(*bits64p));
}
else jaddstr(pitem,"action",pangea_typestr(type));
break;
}
*pitemp = pitem;
return(item);
}
int32_t pangea_parsesummary(uint8_t *typep,uint64_t *valAp,uint64_t *bits64p,bits256 *cardp,uint8_t *summary,int32_t len)
{
int32_t handid; uint16_t cardi_player; uint32_t changes=0; uint8_t player;
*bits64p = 0;
memset(cardp,0,sizeof(*cardp));
len += SuperNET_copybits(1,&summary[len],(void *)typep,sizeof(*typep));
if ( *typep == 0 )
{
printf("len.%d type.%d [%d]\n",len,*typep,summary[len-1]);
return(-1);
}
if ( *typep == CARDS777_START || *typep == CARDS777_SNAPSHOT )
len += SuperNET_copybits(1,&summary[len],(void *)&handid,sizeof(handid)), *valAp = handid;
else if ( *typep == CARDS777_CHANGES )
len += SuperNET_copybits(1,&summary[len],(void *)&changes,sizeof(changes)), *valAp = changes;
else if ( *typep == CARDS777_RAKES )
len += SuperNET_copybits(1,&summary[len],(void *)valAp,sizeof(*valAp));
else if ( *typep == CARDS777_FACEUP )
len += SuperNET_copybits(1,&summary[len],(void *)&cardi_player,sizeof(cardi_player)), *valAp = cardi_player;
else len += SuperNET_copybits(1,&summary[len],(void *)&player,sizeof(player)), *valAp = player;
if ( *typep == CARDS777_FACEUP )
len += SuperNET_copybits(1,&summary[len],cardp->bytes,sizeof(*cardp));
else if ( *typep == CARDS777_START )
len += SuperNET_copybits(1,&summary[len],(void *)bits64p,sizeof(bits256)*(CARDS777_MAXCARDS+1));
else if ( *typep == CARDS777_SNAPSHOT )
len += SuperNET_copybits(1,&summary[len],(void *)bits64p,sizeof(*bits64p) * CARDS777_MAXPLAYERS);
else if ( *typep == CARDS777_CHANGES )
len += SuperNET_copybits(1,&summary[len],(void *)bits64p,sizeof(*bits64p) * (changes & 0xf));
else len += SuperNET_copybits(1,&summary[len],(void *)bits64p,sizeof(*bits64p));
return(len);
}
void pangea_summary(union pangeanet777 *hn,struct cards777_pubdata *dp,uint8_t type,void *arg0,int32_t size0,void *arg1,int32_t size1)
{
uint64_t valA,bits64[CARDS777_MAXPLAYERS + (CARDS777_MAXCARDS+1)*4]; bits256 card; uint8_t checktype; char *str;
cJSON *item,*pitem; int32_t len,cardi,startlen = dp->summarysize;
if ( type == 0 )
{
printf("type.0\n"); getchar();
}
//printf("summarysize.%d type.%d [%02x %02x]\n",dp->summarysize,type,*(uint8_t *)arg0,*(uint8_t *)arg1);
dp->summarysize += SuperNET_copybits(0,&dp->summary[dp->summarysize],(void *)&type,sizeof(type));
//printf("-> %d\n",dp->summary[dp->summarysize-1]);
dp->summarysize += SuperNET_copybits(0,&dp->summary[dp->summarysize],arg0,size0);
dp->summarysize += SuperNET_copybits(0,&dp->summary[dp->summarysize],arg1,size1);
//printf("startlen.%d summarysize.%d\n",startlen,dp->summarysize);
len = pangea_parsesummary(&checktype,&valA,bits64,&card,dp->summary,startlen);
if ( len != dp->summarysize || checktype != type || memcmp(&valA,arg0,size0) != 0 )
printf("pangea_summary parse error [%d] (%d vs %d) || (%d vs %d).%d || cmp.%d size0.%d size1.%d\n",startlen,len,dp->summarysize,checktype,type,dp->summary[startlen],memcmp(&valA,arg0,size0),size0,size1);
if ( card.txid != 0 && memcmp(card.bytes,arg1,sizeof(card)) != 0 )
printf("pangea_summary: parse error card mismatch %llx != %llx\n",(long long)card.txid,*(long long *)arg1);
else if ( card.txid == 0 && memcmp(arg1,bits64,size1) != 0 )
printf("pangea_summary: parse error bits64 %llx != %llx\n",(long long)bits64[0],*(long long *)arg0);
if ( 1 && hn->client->H.slot == pangea_slotA(dp->table) )
{
if ( (item= pangea_handitem(&cardi,&pitem,type,valA,bits64,card,dp->N)) != 0 )
{
str = jprint(item,1);
printf("ITEM.(%s)\n",str);
free(str);
}
if ( pitem != 0 )
{
str = jprint(pitem,1);
printf("PITEM.(%s)\n",str);
free(str);
}
}
if ( Debuglevel > 2 )//|| hn->client->H.slot == pangea_slotA(dp->table) )
printf("pangea_summary.%d %d | summarysize.%d crc.%u\n",type,*(uint8_t *)arg0,dp->summarysize,calc_crc32(0,dp->summary,dp->summarysize));
}
char *pangea_dispsummary(struct pangea_info *sp,int32_t verbose,uint8_t *summary,int32_t summarysize,uint64_t tableid,int32_t handid,int32_t numplayers)
{
int32_t i,cardi,n = 0,len = 0; uint8_t type; uint64_t valA,bits64[CARDS777_MAXPLAYERS + (CARDS777_MAXCARDS+1)*4]; bits256 card;
cJSON *item,*json,*all,*cardis[52],*players[CARDS777_MAXPLAYERS],*pitem,*array = cJSON_CreateArray();
all = cJSON_CreateArray();
memset(cardis,0,sizeof(cardis));
memset(players,0,sizeof(players));
for (i=0; i<numplayers; i++)
players[i] = cJSON_CreateArray();
while ( len < summarysize )
{
memset(bits64,0,sizeof(bits64));
len = pangea_parsesummary(&type,&valA,bits64,&card,summary,len);
if ( (item= pangea_handitem(&cardi,&pitem,type,valA,bits64,card,numplayers)) != 0 )
{
if ( cardi >= 0 && cardi < 52 )
{
//printf("cardis[%d] <- %p\n",cardi,item);
cardis[cardi] = item;
}
else jaddi(array,item);
item = 0;
}
if ( pitem != 0 )
{
jaddnum(pitem,"n",n), n++;
if ( (int32_t)valA >= 0 && valA < numplayers )
jaddi(players[valA],pitem);
else free_json(pitem), printf("illegal player.%llu\n",(long long)valA);
pitem = 0;
}
}
for (i=0; i<numplayers; i++)
jaddi(all,players[i]);
if ( verbose == 0 )
{
for (i=0; i<52; i++)
if ( cardis[i] != 0 )
free_json(cardis[i]);
free_json(array);
return(jprint(all,1));
}
else
{
json = cJSON_CreateObject();
if ( tableid != 0 )
jadd64bits(json,"tableid",tableid);
if ( 0 && sp != 0 )
{
//array = cJSON_CreateArray();
//for (i=0; i<sp->numactive; i++)
// jaddi64bits(array,sp->active[i]);
//jadd(json,"active",array);
for (i=0; i<sp->numactive; i++)
printf("%llu ",(long long)sp->active[i]);
printf("sp->numactive[%d]\n",sp->numactive);
}
jaddnum(json,"size",summarysize);
jaddnum(json,"handid",handid);
//jaddnum(json,"crc",_crc32(0,summary,summarysize));
jadd(json,"hand",array);
array = cJSON_CreateArray();
for (i=0; i<52; i++)
if ( cardis[i] != 0 )
jaddi(array,cardis[i]);
jadd(json,"cards",array);
//jadd(json,"players",all);
return(jprint(json,1));
}
}
void pangea_fold(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t player) void pangea_fold(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t player)
{ {
uint8_t tmp; uint8_t tmp;
@ -708,14 +456,14 @@ int64_t pangea_splitpot(int64_t *won,uint64_t *pangearakep,uint64_t sidepot[CARD
return(rake); return(rake);
} }
uint64_t pangea_bot(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t turni,int32_t cardi,uint64_t betsize) uint64_t pangea_bot(PANGEA_ARGS,int32_t turni,int32_t cardi,uint64_t betsize)
{ {
int32_t r,action=CARDS777_CHECK,n,activej; char hex[1024]; uint64_t threshold,total,sum,amount = 0; struct pangea_info *sp = dp->table; int32_t r,action=CARDS777_CHECK,n,activej; uint64_t threshold,total,sum,amount = 0; struct pangea_info *sp = dp->table;
sum = dp->hand.bets[pangea_ind(dp->table,hn->client->H.slot)]; sum = dp->hand.bets[pangea_ind(dp->table,priv->myslot)];
action = 0; action = 0;
n = pangea_actives(&activej,dp); n = pangea_actives(&activej,dp);
if ( (r = (rand() % 100)) < 1 ) if ( (r = (rand() % 100)) < 1 )
amount = sp->balances[hn->client->H.slot], action = CARDS777_ALLIN; amount = sp->balances[priv->myslot], action = CARDS777_ALLIN;
else else
{ {
if ( betsize == sum ) if ( betsize == sum )
@ -750,12 +498,12 @@ uint64_t pangea_bot(union pangeanet777 *hn,struct cards777_pubdata *dp,int32_t t
action = CARDS777_FOLD, amount = 0; action = CARDS777_FOLD, amount = 0;
} }
} }
else printf("pangea_turn error betsize %.8f vs sum %.8f | slot.%d ind.%d\n",dstr(betsize),dstr(sum),hn->client->H.slot,pangea_ind(dp->table,hn->client->H.slot)); else printf("pangea_turn error betsize %.8f vs sum %.8f | slot.%d ind.%d\n",dstr(betsize),dstr(sum),priv->myslot,pangea_ind(dp->table,priv->myslot));
if ( amount > sp->balances[hn->client->H.slot] ) if ( amount > sp->balances[priv->myslot] )
amount = sp->balances[hn->client->H.slot], action = CARDS777_ALLIN; amount = sp->balances[priv->myslot], action = CARDS777_ALLIN;
} }
pangea_sendcmd(hex,hn,"action",-1,(void *)&amount,sizeof(amount),cardi,action); pangea_sendcmd(PANGEA_CALLARGS,"action",-1,(void *)&amount,sizeof(amount),cardi,action);
printf("playerbot.%d got pangea_turn.%d for player.%d action.%d bet %.8f\n",hn->client->H.slot,cardi,turni,action,dstr(amount)); printf("playerbot.%d got pangea_turn.%d for player.%d action.%d bet %.8f\n",priv->myslot,cardi,turni,action,dstr(amount));
return(amount); return(amount);
} }

933
iguana/pangea_hand.c

@ -0,0 +1,933 @@
/******************************************************************************
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "pangea777.h"
int32_t pangea_slotA(struct table_info *tp) { return(0); }
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_nextnode(struct table_info *tp) { return(tp->priv.myind+1); }
int32_t pangea_prevnode(struct table_info *tp) { return(tp->priv.myind-1); }
void pangea_rwaudit(int32_t saveflag,bits256 *audit,bits256 *audits,int32_t cardi,int32_t destplayer,int32_t N)
{
int32_t i;
audits = &audits[(cardi * N + destplayer) * N];
if ( saveflag != 0 )
{
for (i=0; i<N; i++)
audits[i] = audit[i];
}
else
{
for (i=0; i<N; i++)
audit[i] = audits[i];
}
}
int32_t pangea_tableismine(struct supernet_info *myinfo,struct table_info *tp)
{
int32_t i;
if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits )
{
tp->G.ismine = tp->G.numactive;
return(tp->G.numactive);
}
else
{
for (i=0; i<tp->G.numactive; i++)
if ( tp->G.P[i].nxt64bits == myinfo->myaddr.nxt64bits )
{
tp->G.ismine = 1;
return(i);
}
}
return(-1);
}
int32_t pangea_Pind(struct table_info *tp,bits256 playerpub)
{
int32_t i;
for (i=0; i<tp->G.N; i++)
{
if ( memcmp(tp->G.P[i].playerpub.bytes,playerpub.bytes,sizeof(playerpub)) == 0 )
return(i);
}
return(-1);
}
int32_t pangea_actives(int32_t *activej,struct table_info *tp)
{
int32_t i,n; struct player_info *p;
*activej = -1;
for (i=n=0; i<tp->numactive; i++)
{
if ( (p= tp->active[i]) != 0 && p->betstatus != CARDS777_FOLD )
{
if ( *activej < 0 )
*activej = i;
n++;
}
}
return(n);
}
int32_t pangea_myrank(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p)
{
int32_t i; uint32_t myrank = p->handrank;
for (i=0; i<tp->numactive; i++)
if ( tp->active[i] != 0 && tp->active[i] != p && tp->active[i]->handrank > myrank )
return(-1);
return(myrank != 0);
}
void pangea_clearhand(struct table_info *tp)
{
bits256 *final,*cardpubs; int32_t i; struct hand_info *hand = &tp->hand;
final = hand->final, cardpubs = hand->cardpubs;
memset(hand,0,sizeof(*hand));
hand->final = final, hand->cardpubs = cardpubs;
memset(final,0,sizeof(*final) * tp->G.N * tp->G.numcards);
memset(cardpubs,0,sizeof(*cardpubs) * (1 + tp->G.numcards));
for (i=0; i<5; i++)
hand->community[i] = 0xff;
for (i=0; i<tp->G.N; i++)
memset(tp->G.P[i].hand,0xff,sizeof(tp->G.P[i].hand));
tp->priv.hole[0] = tp->priv.hole[1] = tp->priv.cardis[0] = tp->priv.cardis[1] = 0xff;
memset(tp->priv.holecards,0,sizeof(tp->priv.holecards));
}
uint32_t pangea_rank(struct supernet_info *myinfo,struct table_info *tp,int32_t senderind)
{
int32_t i; char handstr[128]; struct player_info *p; struct hand_info *hand = &tp->hand;
if ( senderind < tp->G.N && (p= tp->active[senderind]) != 0 )
{
if ( p->handrank != 0 )
return(p->handrank);
for (i=0; i<7; i++)
{
if ( i < 5 )
p->hand[i] = hand->community[i];
if ( p->hand[i] == 0xff )
break;
}
if ( i == 7 )
{
p->handrank = set_handstr(handstr,p->hand,0);
hand->handmask |= (1 << senderind);
PNACL_message("sender.%d (%s) rank.%x handmask.%x\n",senderind,handstr,p->handrank,hand->handmask);
}
return(p->handrank);
}
printf("pangea_rank.%d illegal senderind\n",senderind);
return(0);
}
// "state machine" funcs
int32_t pangea_newdeck(struct supernet_info *myinfo,struct table_info *tp)
{
bits256 *playerpubs; int32_t i,j,n,datalen,button; struct hand_info *hand = &tp->hand;
button = (tp->numhands % tp->G.N);
pangea_clearhand(tp);
playerpubs = &hand->cardpubs[tp->G.numcards + 1];
for (j=n=0; j<tp->G.N; j++)
{
i = (j + button) % tp->G.N;
if ( tp->G.P[i].balance > 0 )
playerpubs[n++] = tp->G.P[i].playerpub;
}
if ( n < tp->G.minplayers )
{
printf("pangea_newdeck %d < %d minplayers\n",n,tp->G.minplayers);
return(-1);
}
hand->checkprod = hand->cardpubs[tp->G.numcards] = cards777_initdeck(tp->priv.outcards,hand->cardpubs,tp->G.numcards,n,playerpubs,0);
datalen = (tp->G.numcards + 1 + n) * sizeof(bits256);
pangea_sendcmd(myinfo,tp,"newhand",-1,hand->cardpubs[0].bytes,datalen,n,n);
PNACL_message("host sends NEWDECK checkprod.%llx numhands.%d\n",(long long)hand->checkprod.txid,tp->numhands);
return(0);
}
void pangea_newhand(PANGEA_HANDARGS)
{
int32_t i,handid,numcards,n,ind; struct hand_info *hand; bits256 *pubkeys;
hand = &tp->hand;
numcards = tp->G.numcards;
if ( data == 0 || datalen != (numcards + 1) * sizeof(bits256) )
{
PNACL_message("pangea_newhand invalid datalen.%d vs %ld\n",datalen,(long)((numcards + 1) * sizeof(bits256)));
return;
}
pubkeys = (bits256 *)data;
n = pm->turni;
tp->myind = -1;
for (i=0; i<n; i++)
{
if ( (ind= pangea_Pind(tp,pubkeys[numcards + 1 + i])) < 0 )
{
printf("illegal pubkey, cant find player[%d]\n",i);
return;
}
tp->active[i] = &tp->G.P[ind];
if ( i == 0 )
hand->button = ind;
if ( tp->G.P[ind].nxt64bits == myinfo->myaddr.nxt64bits )
tp->priv.myind = i;
}
tp->priv.mypriv = myinfo->privkey, tp->priv.mypub = myinfo->myaddr.pubkey;
tp->G.M = (tp->numactive >> 1) + 1;
hand->startdecktime = pm->sig.timestamp;
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);
hand->checkprod = cards777_pubkeys(hand->cardpubs,numcards,hand->cardpubs[numcards]);
if ( bits256_cmp(hand->checkprod,hand->cardpubs[numcards]) != 0 )
{
printf("checkprod mismatch myind.%d\n",tp->myind);
return;
}
tp->numactive = n;
memset(tp->summary,0,sizeof(tp->summary));
hand->summaries = hand->mismatches = tp->summarysize = 0;
handid = tp->numhands++;
pangea_summaryadd(myinfo,tp,CARDS777_START,&handid,sizeof(handid),hand->cardpubs[0].bytes,sizeof(bits256) * (numcards + 1));
if ( tp->myind >= 0 )
pangea_sendcmd(myinfo,tp,"gotdeck",-1,hand->checkprod.bytes,sizeof(bits256),hand->cardi,hand->button);
}
void pangea_checkstart(struct supernet_info *myinfo,struct table_info *tp)
{
int32_t i; struct hand_info *hand = &tp->hand;
if ( bits256_nonz(hand->checkprod) > 0 && hand->encodestarted == 0 )
{
for (i=0; i<tp->numactive; i++)
{
if ( bits256_cmp(hand->othercardpubs[i],hand->checkprod) != 0 )
break;
}
if ( i == tp->numactive )
{
if ( PANGEA_PAUSE > 0 )
sleep(PANGEA_PAUSE);
if ( time(NULL) > (tp->myind*3 + hand->startdecktime) )
{
hand->encodestarted = (uint32_t)time(NULL);
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);
}
}
}
}
void pangea_gotdeck(PANGEA_HANDARGS)
{
int32_t i,senderind; uint64_t total = 0;
senderind = pm->myind;
tp->hand.othercardpubs[senderind] = *(bits256 *)data;
if ( Debuglevel > 2 )
{
for (i=0; i<tp->G.N; i++)
{
total += tp->G.P[i].balance;
PNACL_message("(p%d %.8f) ",i,dstr(tp->G.P[i].balance));
}
PNACL_message("balances %.8f [%.8f] | ",dstr(total),dstr(total + tp->G.hostrake + tp->G.pangearake));
PNACL_message("player.%d pangea_gotdeck from P.%d otherpubs.%llx\n",tp->myind,senderind,(long long)tp->hand.othercardpubs[senderind].txid);
}
pangea_checkstart(myinfo,tp);
}
void pangea_encoded(PANGEA_HANDARGS)
{
bits256 audit[CARDS777_MAXPLAYERS]; int32_t i,iter,cardi,destplayer,N = tp->numactive;
struct hand_info *hand = &tp->hand;
if ( N <= 1 || data == 0 || datalen != (tp->G.numcards * N) * sizeof(bits256) )
{
PNACL_message("pangea_encode invalid datalen.%d vs %ld\n",datalen,(long)((tp->G.numcards * N) * sizeof(bits256)));
return;
}
hand->encodestarted = pm->sig.timestamp;
cards777_encode(tp->priv.outcards,tp->priv.xoverz,tp->priv.allshares,tp->priv.myshares,hand->sharenrs[tp->myind],tp->G.M,(void *)data,tp->G.numcards,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 < tp->numactive-1 )
{
//PNACL_message("send encoded\n");
pangea_sendcmd(myinfo,tp,"encoded",pangea_nextnode(tp),tp->priv.outcards[0].bytes,datalen,N*tp->G.numcards,-1);
}
else
{
memcpy(hand->final,tp->priv.outcards,sizeof(bits256)*N*tp->G.numcards);
pangea_sendcmd(myinfo,tp,"final",-1,tp->priv.outcards[0].bytes,datalen,N*tp->G.numcards,-1);
for (iter=cardi=0; iter<2; iter++)
for (i=0; i<N; i++,cardi++)
for (destplayer=0; destplayer<N; destplayer++)
{
pangea_rwaudit(0,audit,tp->priv.audits,cardi,destplayer,N);
audit[0] = hand->final[cardi*N + destplayer];
pangea_rwaudit(1,audit,tp->priv.audits,cardi,destplayer,N);
}
PNACL_message("call preflop %ld\n",(long)((2 * N) * (N * N * sizeof(bits256))));
pangea_preflop(myinfo,pm,tp,tp->priv.audits[0].bytes,(2 * N) * (N * N * sizeof(bits256)));
}
}
}
void pangea_final(PANGEA_HANDARGS)
{
if ( data == 0 || datalen != (tp->G.numcards * tp->numactive) * sizeof(bits256) )
{
PNACL_message("pangea_final invalid datalen.%d vs %ld\n",datalen,(long)((tp->G.numcards * tp->numactive) * sizeof(bits256)));
return;
}
if ( Debuglevel > 2 )
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);
}
void pangea_preflop(PANGEA_HANDARGS)
{
int32_t i,iter,cardi,destplayer,maxlen,N; bits256 audit[CARDS777_MAXPLAYERS];
N = tp->numactive;
maxlen = (int32_t)(2 * N * N * CARDS777_MAXCARDS * sizeof(bits256));
if ( N <= 1 || data == 0 || datalen != (2 * N) * (N * N * sizeof(bits256)) )
{
PNACL_message("pangea_preflop invalid datalen.%d vs %ld\n",datalen,(long)(2 * N) * (N * N * sizeof(bits256)));
return;
}
//PNACL_message("preflop player.%d\n",tp->myind);
memcpy(tp->priv.audits,data,datalen);
if ( tp->myind != pangea_slotA(tp) && tp->myind != pangea_slotB(tp) )
{
//for (i=0; i<tp->G.numcards*N; i++)
// PNACL_message("%llx ",(long long)tp->priv.outcards[i].txid);
//PNACL_message("player.%d outcards\n",tp->myind);
for (cardi=0; cardi<N*2; cardi++)
for (destplayer=0; destplayer<N; destplayer++)
{
pangea_rwaudit(0,audit,tp->priv.audits,cardi,destplayer,N);
//if ( 1 && (card= cards777_checkcard(&cardpriv,cardi,tp->myind,destplayer,hn->client->H.privkey,hand->cardpubs,tp->G.numcards,audit[0])) >= 0 )
//PNACL_message("ERROR: unexpected decode player.%d got card.[%d]\n",tp->myind,card);
audit[0] = cards777_decode(&audit[tp->myind],tp->priv.xoverz,destplayer,audit[0],tp->priv.outcards,tp->G.numcards,N);
pangea_rwaudit(1,audit,tp->priv.audits,cardi,destplayer,N);
}
//PNACL_message("issue preflop\n");
pangea_sendcmd(myinfo,tp,"preflop",pangea_prevnode(tp),tp->priv.audits[0].bytes,datalen,N * 2 * N,-1);
}
else
{
//PNACL_message("sendout cards\n");
for (iter=cardi=0; iter<2; iter++)
for (i=0; i<N; i++,cardi++)
{
destplayer = (tp->hand.button + i) % N;
pangea_rwaudit(0,audit,tp->priv.audits,cardi,destplayer,N);
//PNACL_message("audit[0] %llx -> ",(long long)audit[0].txid);
audit[0] = cards777_decode(&audit[tp->myind],tp->priv.xoverz,destplayer,audit[0],tp->priv.outcards,tp->G.numcards,N);
pangea_rwaudit(1,audit,tp->priv.audits,cardi,destplayer,N);
//PNACL_message("[%llx + %llx] ",*(long long *)&audit[0],(long long)&audit[tp->myind]);
if ( destplayer == tp->myind )
pangea_card(myinfo,pm,tp,audit[0].bytes,sizeof(bits256)*N);
else pangea_sendcmd(myinfo,tp,"card",destplayer,audit[0].bytes,sizeof(bits256)*N,cardi,-1);
}
}
}
void pangea_card(PANGEA_HANDARGS)
{
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;
N = tp->numactive, cardi = pm->cardi, destplayer = pm->destplayer; hand = &tp->hand;
destp = tp->active[destplayer];
if ( N <= 1 || data == 0 || datalen != sizeof(bits256)*N || destp == 0 )
{
PNACL_message("pangea_card invalid datalen.%d vs %ld\n",datalen,(long)sizeof(bits256)*N);
return;
}
pangea_rwaudit(1,(void *)data,tp->priv.audits,cardi,destplayer,N);
pangea_rwaudit(0,audit,tp->priv.audits,cardi,destplayer,N);
//PNACL_message("card.%d destplayer.%d [%llx]\n",cardi,destplayer,(long long)audit[0].txid);
if ( (card= cards777_checkcard(&cardpriv,cardi,tp->myind,destplayer,myinfo->privkey,hand->cardpubs,tp->G.numcards,audit[0])) >= 0 )
{
destplayer = tp->myind;
if ( Debuglevel > 2 )
PNACL_message("player.%d got card.[%d]\n",tp->myind,card);
selector = (cardi / N);
tp->priv.holecards[selector] = cardpriv;
tp->priv.cardis[selector] = cardi;
destp->hand[5 + selector] = tp->priv.hole[selector] = cardpriv.bytes[1];
validcard = 1;
cardAstr[0] = cardBstr[0] = 0;
if ( tp->priv.hole[0] != 0xff )
cardstr(cardAstr,tp->priv.hole[0]);
if ( tp->priv.hole[1] != 0xff )
cardstr(cardBstr,tp->priv.hole[1]);
PNACL_message(">>>>>>>>>> dest.%d holecards[%02d] cardi.%d / N %d (%02d %02d) -> (%s %s)\n",destplayer,tp->priv.hole[cardi / N],cardi,N,tp->priv.hole[0],tp->priv.hole[1],cardAstr,cardBstr);
if ( cards777_validate(cardpriv,hand->final[cardi*N + destplayer],hand->cardpubs,tp->G.numcards,audit,N,tp->priv.mypub) < 0 )
PNACL_message("player.%d decoded cardi.%d card.[%02d] but it doesnt validate\n",tp->myind,cardi,card);
} else PNACL_message("ERROR player.%d got no card %llx\n",tp->myind,*(long long *)data);
if ( cardi < N*2 )
pangea_sendcmd(myinfo,tp,"facedown",-1,(void *)&cardi,sizeof(cardi),cardi,validcard);
else pangea_sendcmd(myinfo,tp,"faceup",-1,cardpriv.bytes,sizeof(cardpriv),cardi,0xff);
}
int64_t pangea_snapshot(struct table_info *tp,int64_t *snapshot)
{
struct player_info *p; int64_t betsize; int32_t i,N = tp->numactive;
memcpy(snapshot,0,N * sizeof(int64_t));
for (betsize=i=0; i<N; i++)
{
if ( (p= tp->active[i]) != 0 )
{
if ( p->bets > betsize )
betsize = p->bets;
snapshot[i] = p->bets;
} else snapshot[i] = 0;
}
snapshot[N] = betsize;
return(betsize);
}
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];
struct hand_info *hand = &tp->hand;
if ( PANGEA_PAUSE > 0 )
sleep(PANGEA_PAUSE);
if ( hand->betstarted == 0 )
hand->betstarted = 1;
else hand->betstarted++;
hand->numactions = 0;
hand->cardi = cardi;
now = (uint32_t)time(NULL);
for (i=0; i<CARDS777_MAXPLAYERS; i++)
{
p = &tp->G.P[i];
p->action = 0;
p->turni = 0xff;
if ( cardi > N*2 )
p->snapshot = p->bets;
}
hand->undergun = ((hand->button + 3) % N);
if ( cardi < N*2 )
pangea_checkantes(myinfo,tp);
hand->betsizesnapshot = hand->betsize = pangea_snapshot(tp,snapshot);
printf("STARTBETS.%d cardi.%d numactions.%d undergun.%d betsize %.8f N %d\n",hand->betstarted,cardi,hand->numactions,hand->undergun,dstr(hand->betsize),N);
pangea_sendcmd(myinfo,tp,"turn",-1,(void *)snapshot,sizeof(*snapshot)*(N+1),cardi,hand->undergun);
}
void pangea_facedown(PANGEA_HANDARGS)
{
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;
p = tp->active[senderind];
if ( p == 0 || N <= 1 || data == 0 || datalen != sizeof(int32_t) )
{
PNACL_message("pangea_facedown invalid datalen.%d vs %ld\n",datalen,(long)sizeof(bits256));
return;
}
validcard = pm->turni;
if ( validcard > 0 )
p->havemask |= (1LL << cardi);
if ( Debuglevel > 2 )
PNACL_message(" | player.%d sees that destplayer.%d got cardi.%d valid.%d | %llx | n.%d\n",tp->myind,senderind,cardi,validcard,(long long)p->havemask,n);
for (i=0; i<N; i++)
{
if ( (p= tp->active[i]) != 0 )
{
havemask = p->havemask;
if ( Debuglevel > 2 )
PNACL_message("%llx ",(long long)havemask);
if ( bitweight(havemask) == 2 )
n++;
}
}
if ( tp->myind == pangea_slotA(tp) && n == N )
pangea_startbets(myinfo,tp,N*2);
}
void pangea_faceup(PANGEA_HANDARGS)
{
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;
destp = tp->active[senderind];
if ( destp == 0 || N <= 1 || data == 0 || datalen != sizeof(bits256) )
{
PNACL_message("pangea_faceup invalid datalen.%d vs %ld\n",datalen,(long)((tp->G.numcards + 1) * sizeof(bits256)));
return;
}
validcard = (pm->turni >= 0);
if ( Debuglevel > 2 || tp->myind == pangea_slotA(tp) )
{
PNACL_message("from.%d -> player.%d COMMUNITY.[%d] cardi.%d valid.%d\n",senderind,tp->myind,data[1],cardi,validcard);
}
//PNACL_message("got FACEUP.(%s)\n",jprint(json,0));
if ( validcard > 0 )
{
tmp = (cardi << 8);
tmp |= (pm->turni & 0xff);
pangea_summaryadd(myinfo,tp,CARDS777_FACEUP,&tmp,sizeof(tmp),data,sizeof(bits256));
if ( cardi >= N*2 && cardi < N*2+5 )
{
hand->community[cardi - N*2] = data[1];
for (i=0; i<N; i++)
{
if ( (p= tp->active[i]) != 0 )
p->hand[cardi - N*2] = data[1];
}
memcpy(hand->community256[cardi - N*2].bytes,data,sizeof(bits256));
PNACL_message("set community[%d] <- %d\n",cardi - N*2,data[1]);
if ( senderind == tp->myind )
pangea_rank(myinfo,tp,senderind);
if ( tp->myind == pangea_slotA(tp) && cardi >= N*2+2 && cardi < N*2+5 )
pangea_startbets(myinfo,tp,cardi+1);
//else PNACL_message("dont start bets %d\n",cardi+1);
}
else
{
PNACL_message("valid.%d cardi.%d vs N.%d\n",validcard,cardi,N);
if ( cardi < N*2 )
{
memcpy(hand->cards[senderind][cardi/N].bytes,data,sizeof(bits256));
destp->hand[5 + cardi/N] = data[1];
pangea_rank(myinfo,tp,senderind);
}
}
}
}
void pangea_turn(PANGEA_HANDARGS)
{
int32_t turni,cardi,senderind,N; struct player_info *destp;
int64_t snapshot[CARDS777_MAXPLAYERS+1]; struct hand_info *hand = &tp->hand;
N = tp->numactive, senderind = pm->myind, turni = pm->turni, cardi = pm->cardi;
destp = tp->active[senderind];
if ( destp == 0 || N <= 1 )
{
PNACL_message("pangea_turn illegal arg\n");
return;
}
if ( Debuglevel > 2 )
printf("P%d: got turn.%d from %d | cardi.%d summary[%d] crc.%u\n",tp->myind,turni,senderind,cardi,tp->summarysize,calc_crc32(0,tp->summary,tp->summarysize));
destp->turni = turni;
if ( senderind == 0 )
{
hand->cardi = cardi;
hand->betstarted = 1;
hand->undergun = turni;
if ( tp->myind != pangea_slotA(tp) )
{
pangea_checkantes(myinfo,tp);
hand->betsizesnapshot = pangea_snapshot(tp,snapshot);
//printf("player.%d sends confirmturn.%d\n",tp->myind,turni);
pangea_sendcmd(myinfo,tp,"confirm",-1,(void *)snapshot,sizeof(uint64_t)*(N+1),cardi,turni);
}
}
}
void pangea_confirm(PANGEA_HANDARGS)
{
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;
N = tp->numactive, senderind = pm->myind, turni = pm->turni, cardi = pm->cardi;
hand = &tp->hand; p = tp->active[senderind];
if ( p == 0 || N <= 1 || data == 0 )
{
printf("pangea_turn: null data\n");
return;
}
printf("got confirmturn.%d cardi.%d sender.%d\n",turni,cardi,senderind);
//if ( datalen == sizeof(betsize) )
// memcpy(&betsize,data,sizeof(betsize));
starttime = hand->starttime;
if ( senderind == 0 && tp->myind != pangea_slotA(tp) )
{
hand->undergun = turni;
hand->cardi = cardi;
betsize = pangea_snapshot(tp,snapshot);
if ( betsize != hand->betsizesnapshot )
printf("T%d ERROR BETSIZE MISMATCH: %.8f vs %.8f\n",tp->priv.myind,dstr(betsize),dstr(hand->betsizesnapshot));
hand->betsize = betsize;
}
p->turni = turni;
for (i=0; i<N; i++)
{
if ( (p= tp->active[i]) != 0 && p->turni != turni )
break;
}
//printf("sp.%p vs turni.%d cardi.%d hand.cardi %d\n",sp,turni,cardi,hand->cardi);
if ( tp->myind == pangea_slotA(tp) && i == N )
{
betsize = pangea_snapshot(tp,snapshot);
hand->betsize = hand->betsizesnapshot = betsize;
//if ( Debuglevel > 2 )
printf("player.%d sends confirmturn.%d cardi.%d betsize %.0f\n",tp->myind,hand->undergun,hand->cardi,dstr(betsize));
if ( senderind != 0 )
pangea_sendcmd(myinfo,tp,"confirm",-1,(void *)snapshot,sizeof(*snapshot)*(N+1),hand->cardi,hand->undergun);
}
if ( senderind == 0 && (turni= hand->undergun) == tp->myind && (p= tp->active[senderind]) != 0 )
{
if ( hand->betsize != betsize )
printf("P%d: pangea_turn warning hand.betsize %.8f != betsize %.8f\n",tp->myind,dstr(hand->betsize),dstr(betsize));
//if ( sp->isbot[tp->priv.myind] != 0 )
// pangea_bot(myinfo,tp,turni,cardi,betsize);
//else
if ( p->betstatus == CARDS777_FOLD || p->betstatus == CARDS777_ALLIN )
pangea_sendcmd(myinfo,tp,"action",-1,(void *)&amount,sizeof(amount),cardi,0);
else if ( tp->priv.autofold != 0 )
pangea_sendcmd(myinfo,tp,"action",-1,(void *)&amount,sizeof(amount),cardi,0);
else
{
hand->userinput_starttime = (uint32_t)time(NULL);
hand->cardi = cardi;
hand->betsize = betsize;
fprintf(stderr,"Waiting for user input cardi.%d: ",cardi);
}
if ( tp->myind == pangea_slotA(tp) )
{
char *str = jprint(pangea_tablestatus(myinfo,tp),1);
printf("%s\n",str);
free(str);
}
//pangea_statusprint(dp,priv,tp->myind);
}
}
void pangea_finish(struct supernet_info *myinfo,struct table_info *tp)
{
int64_t tsnap,sidepots[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS];//,list[CARDS777_MAXPLAYERS];
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;
N = tp->numactive, hand = &tp->hand;
if ( hand->finished == 0 )
{
memset(sidepots,0,sizeof(sidepots));
pangea_snapshot(tp,bets);
n = pangea_sidepots(myinfo,tp,1,sidepots,bets);
if ( hand->community[0] == 0xff )
norake = 1;
for (pangearake=rake=j=0; j<n; j++)
rake += pangea_splitpot(myinfo,tp,&pangearake,sidepots[j],norake == 0 ? tp->G.rakemillis : 0);
hand->finished = (uint32_t)time(NULL);
tp->hostrake += rake;
tp->pangearake += pangearake;
tp->G.hostrake = rake;
tp->G.pangearake = pangearake;
for (j=busted=rebuy=r=0; j<N; j++)
{
if ( tp->active[j] != 0 )
{
balances[j] = tp->active[j]->balance;
tsnap = tp->snapshot[tp->active[j]->ind];
//balances[j] += hand->won[j];
//sp->balances[pangea_slot(sp,j)] = balances[j];
if ( tsnap > 0 && balances[j] <= 0 )
{
busted |= (1 << j);
//list[r++] = sp->active[j];
}
else if ( tsnap <= 0 && balances[j] > 0 )
rebuy |= (1 << j);
}
}
changes = (((uint32_t)rebuy<<20) | ((uint32_t)busted<<4) | (tp->G.N&0xf));
pangea_summaryadd(myinfo,tp,CARDS777_CHANGES,(void *)&changes,sizeof(changes),(void *)balances,sizeof(uint64_t)*tp->G.N);
pangea_summaryadd(myinfo,tp,CARDS777_RAKES,(void *)&rake,sizeof(rake),(void *)&pangearake,sizeof(pangearake));
if ( tp->priv.myind == pangea_slotA(tp) )
{
char *sumstr,*statstr;
statstr = jprint(pangea_tablestatus(myinfo,tp),1);
sumstr = pangea_dispsummary(myinfo,tp,1,tp->summary,tp->summarysize,tp->G.tablehash,tp->numhands-1,tp->G.N);
printf("%s\n\n%s",statstr,sumstr);
free(statstr), free(sumstr);
pangea_sendcmd(myinfo,tp,"summary",-1,tp->summary,tp->summarysize,0,0);
}
/*if ( 0 && busted != 0 )
{
for (j=0; j<r; j++)
{
if ( list[j] != sp->active[0] )
{
pangea_inactivate(dp,sp,list[j]);
printf("T%d: INACTIVATE.[%d] %llu\n",sp->myslot,j,(long long)list[j]);
}
}
}*/
}
}
int32_t pangea_lastman(struct supernet_info *myinfo,struct table_info *tp)
{
int32_t activej = -1; struct hand_info *hand = &tp->hand;
if ( hand->betstarted != 0 && pangea_actives(&activej,tp) <= 1 )
{
if ( hand->finished != 0 )
{
printf("DUPLICATE LASTMAN!\n");
return(1);
}
if ( 0 && tp->myind == activej && tp->priv.automuck == 0 )
{
pangea_sendcmd(myinfo,tp,"faceup",-1,tp->priv.holecards[0].bytes,sizeof(tp->priv.holecards[0]),tp->priv.cardis[0],tp->priv.cardis[0] != 0xff);
pangea_sendcmd(myinfo,tp,"faceup",-1,tp->priv.holecards[1].bytes,sizeof(tp->priv.holecards[1]),tp->priv.cardis[1],tp->priv.cardis[1] != 0xff);
}
pangea_finish(myinfo,tp);
return(1);
}
return(0);
}
void pangea_action(PANGEA_HANDARGS)
{
uint32_t now; struct player_info *p; int64_t x,snapshot[CARDS777_MAXPLAYERS + 1];
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;
action = pm->turni, senderind = pm->myind, cardi = pm->cardi, N = tp->numactive, hand = &tp->hand;
p = tp->active[senderind];
memcpy(&amount,data,sizeof(amount));
if ( N <= 1 || p == 0 || cardi < 2*N )
{
printf("pangea_action: illegal cardi.%d\n",cardi);
return;
}
if ( senderind != hand->undergun )
{
printf("T%d: out of turn action.%d by player.%d (undergun.%d) cardi.%d amount %.8f\n",tp->myind,action,senderind,hand->undergun,cardi,dstr(amount));
return;
}
tmp = senderind;
pangea_bet(myinfo,tp,tp->active[pm->myind],amount,CARDS777_CHECK);
p->action = action;
hand->undergun = (hand->undergun + 1) % N;
hand->numactions++;
if ( Debuglevel > 2 )//|| tp->myind == 0 )
printf("player.%d: got action.%d cardi.%d senderind.%d -> undergun.%d numactions.%d\n",tp->myind,action,cardi,senderind,hand->undergun,hand->numactions);
if ( pangea_lastman(myinfo,tp) > 0 )
return;
if ( tp->myind == pangea_slotA(tp) )
{
now = (uint32_t)time(NULL);
for (i=j=0; i<N; i++)
{
j = (hand->undergun + i) % N;
if ( (p= tp->active[j]) != 0 )
{
if ( p->betstatus == CARDS777_FOLD || p->betstatus == CARDS777_ALLIN )
{
p->action = p->betstatus;
//printf("skip player.%d\n",j);
hand->numactions++;
} else break;
}
}
hand->undergun = j;
if ( hand->numactions < N )
{
//printf("T%d: senderind.%d i.%d j.%d -> undergun.%d numactions.%d\n",tp->myind,senderind,i,j,hand->undergun,hand->numactions);
//if ( senderind != 0 )
memset(snapshot,0,sizeof(*snapshot)*(N+1));
for (x=i=0; i<N; i++)
if ( (p= tp->active[i]) != 0 )
{
if ( p->snapshot > x )
x = p->snapshot;
snapshot[i] = p->snapshot;
}
snapshot[N] = x;
pangea_sendcmd(myinfo,tp,"turn",-1,(void *)snapshot,sizeof(*snapshot)*(N+1),hand->cardi,hand->undergun);
}
else
{
for (i=0; i<5; i++)
{
if ( hand->community[i] == 0xff )
break;
printf("%02x ",hand->community[i]);
}
printf("COMMUNITY\n");
if ( i == 0 )
{
if ( hand->cardi != N * 2 )
printf("cardi mismatch %d != %d\n",hand->cardi,N * 2);
cardi = hand->cardi;
printf("decode flop\n");
for (i=0; i<3; i++,cardi++)
{
memset(audit,0,sizeof(audit));
audit[0] = hand->final[cardi*N + destplayer];
pangea_sendcmd(myinfo,tp,"decoded",-1,audit[0].bytes,sizeof(bits256)*N,cardi,N-1);
}
}
else if ( i == 3 )
{
if ( hand->cardi != N * 2+3 )
printf("cardi mismatch %d != %d\n",hand->cardi,N * 2 + 3);
cardi = hand->cardi;
printf("decode turn\n");
memset(audit,0,sizeof(audit));
audit[0] = hand->final[cardi*N + destplayer];
pangea_sendcmd(myinfo,tp,"decoded",-1,audit[0].bytes,sizeof(bits256)*N,cardi,N-1);
//pangea_sendcmd(myinfo,tp,"decoded",-1,hand->final[cardi*N + destplayer].bytes,sizeof(hand->final[cardi*N + destplayer]),cardi,N-1);
}
else if ( i == 4 )
{
printf("decode river\n");
if ( hand->cardi != N * 2+4 )
printf("cardi mismatch %d != %d\n",hand->cardi,N * 2+4);
cardi = hand->cardi;
memset(audit,0,sizeof(audit));
audit[0] = hand->final[cardi*N + destplayer];
pangea_sendcmd(myinfo,tp,"decoded",-1,audit[0].bytes,sizeof(bits256)*N,cardi,N-1);
//pangea_sendcmd(myinfo,tp,"decoded",-1,hand->final[cardi*N + destplayer].bytes,sizeof(hand->final[cardi*N + destplayer]),cardi,N-1);
}
else
{
cardi = N * 2 + 5;
if ( hand->cardi != N * 2+5 )
printf("cardi mismatch %d != %d\n",hand->cardi,N * 2+5);
for (i=0; i<N; i++)
{
j = (hand->lastbettor + i) % N;
if ( tp->active[j] != 0 && tp->active[j]->betstatus != CARDS777_FOLD )
break;
}
hand->undergun = j;
printf("sent showdown request for undergun.%d\n",j);
pangea_sendcmd(myinfo,tp,"showdown",-1,(void *)&hand->betsize,sizeof(hand->betsize),cardi,hand->undergun);
}
}
}
if ( Debuglevel > 2 )// || tp->myind == 0 )
{
char *str = jprint(pangea_tablestatus(myinfo,tp),1);
printf("player.%d got pangea_action.%d for player.%d action.%d amount %.8f | numactions.%d\n%s\n",tp->myind,cardi,senderind,action,dstr(amount),hand->numactions,str);
free(str);
}
}
void pangea_decoded(PANGEA_HANDARGS)
{
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;
if ( N <= 1 || data == 0 || datalen != sizeof(bits256)*N )
{
PNACL_message("pangea_decoded invalid datalen.%d vs %ld\n",datalen,(long)sizeof(bits256));
return;
}
if ( cardi < N*2 || cardi >= N*2 + 5 )
{
PNACL_message("pangea_decoded invalid cardi.%d\n",cardi);
return;
}
destplayer = 0;
pangea_rwaudit(1,(void *)data,tp->priv.audits,cardi,destplayer,N);
pangea_rwaudit(0,audit,tp->priv.audits,cardi,destplayer,N);
if ( turni == tp->myind )
{
if ( tp->myind != pangea_slotA(tp) )
{
audit[0] = cards777_decode(&audit[tp->myind],tp->priv.xoverz,destplayer,audit[0],tp->priv.outcards,tp->G.numcards,N);
pangea_rwaudit(1,audit,tp->priv.audits,cardi,destplayer,N);
pangea_sendcmd(myinfo,tp,"decoded",-1,audit[0].bytes,sizeof(bits256)*N,cardi,pangea_prevnode(tp));
}
else
{
if ( (card= cards777_checkcard(&cardpriv,cardi,tp->myind,tp->myind,tp->priv.mypriv,hand->cardpubs,tp->G.numcards,audit[0])) >= 0 )
{
if ( cards777_validate(cardpriv,hand->final[cardi*N + destplayer],hand->cardpubs,tp->G.numcards,audit,N,tp->priv.mypub) < 0 )
PNACL_message("player.%d decoded cardi.%d card.[%d] but it doesnt validate\n",tp->myind,cardi,card);
pangea_sendcmd(myinfo,tp,"faceup",-1,cardpriv.bytes,sizeof(cardpriv),cardi,cardpriv.txid!=0?0xff:-1);
//PNACL_message("-> FACEUP.(%s)\n",hex);
}
}
}
}
void pangea_showdown(PANGEA_HANDARGS)
{
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;
myind = tp->priv.myind;
if ( (p= tp->active[myind]) == 0 )
{
printf("error nullp myind.%d\n",myind);
return;
}
if ( Debuglevel > 2 )
printf("P%d: showdown from sender.%d\n",myind,pm->myind);
if ( p->betstatus != CARDS777_FOLD && ((tp->priv.automuck == 0 && p->action != CARDS777_SENTCARDS) || (turni == myind && hand->lastbettor == myind)) )
{
if ( tp->priv.automuck != 0 && pangea_myrank(myinfo,tp,p) < 0 )
pangea_sendcmd(myinfo,tp,"action",-1,(void *)&amount,sizeof(amount),cardi,CARDS777_FOLD);
else
{
pangea_sendcmd(myinfo,tp,"faceup",-1,tp->priv.holecards[0].bytes,sizeof(tp->priv.holecards[0]),tp->priv.cardis[0],myind);
pangea_sendcmd(myinfo,tp,"faceup",-1,tp->priv.holecards[1].bytes,sizeof(tp->priv.holecards[1]),tp->priv.cardis[1],myind);
p->action = CARDS777_SENTCARDS;
}
}
if ( pangea_lastman(myinfo,tp) > 0 )
return;
if ( myind == pangea_slotA(tp) && pm->myind != 0 )
{
for (i=0; i<N; i++)
{
hand->undergun = (hand->undergun + 1) % N;
if ( hand->undergun == hand->lastbettor )
{
printf("all players queried with showdown handmask.%x finished.%u\n",hand->handmask,hand->finished);
return;
}
if ( (p= tp->active[hand->undergun]) != 0 && p->betstatus != CARDS777_FOLD )
break;
}
printf("senderind.%d host sends showdown for undergun.%d\n",pm->myind,hand->undergun);
pangea_sendcmd(myinfo,tp,"showdown",-1,(void *)&hand->betsize,sizeof(hand->betsize),cardi,hand->undergun);
}
}
int32_t pangea_anotherhand(struct supernet_info *myinfo,struct table_info *tp,int32_t sleepflag)
{
int32_t i,n,activej = -1; int64_t balance,onlybalance = 0,total = 0;
for (i=n=0; i<tp->G.N; i++)
{
PNACL_message("(p%d %.8f) ",i,dstr(tp->G.P[i].balance));
if ( (balance= tp->G.P[i].balance) != 0 )
{
total += balance;
onlybalance = balance;
if ( activej < 0 )
activej = i;
n++;
}
}
PNACL_message("balance %.8f [%.8f]\n",dstr(total),dstr(total + tp->G.hostrake + tp->G.pangearake));
if ( n == 1 )
{
PNACL_message("Only player.%d left with %.8f | get sigs and cashout after numhands.%d\n",activej,dstr(onlybalance),tp->numhands);
sleep(60);
return(1);
}
else
{
if ( sleepflag != 0 )
sleep(sleepflag);
//hand->betstarted = 0;
pangea_newdeck(myinfo,tp);
if ( sleepflag != 0 )
sleep(sleepflag);
}
return(n);
}

10
iguana/pangea_init.c

@ -184,6 +184,7 @@ cJSON *pangea_sharenrs(uint8_t *sharenrs,int32_t n)
return(array); return(array);
} }
/*
char *pangea_newtable(int32_t threadid,cJSON *json,uint64_t my64bits,bits256 privkey,bits256 pubkey,char *transport,char *ipaddr,uint16_t port,uint32_t minbuyin,uint32_t maxbuyin,int32_t hostrake) char *pangea_newtable(int32_t threadid,cJSON *json,uint64_t my64bits,bits256 privkey,bits256 pubkey,char *transport,char *ipaddr,uint16_t port,uint32_t minbuyin,uint32_t maxbuyin,int32_t hostrake)
{ {
int32_t createdflag,num,i,myind= -1; uint64_t tableid,addrs[CARDS777_MAXPLAYERS],isbot[CARDS777_MAXPLAYERS]; int32_t createdflag,num,i,myind= -1; uint64_t tableid,addrs[CARDS777_MAXPLAYERS],isbot[CARDS777_MAXPLAYERS];
@ -242,13 +243,6 @@ char *pangea_newtable(int32_t threadid,cJSON *json,uint64_t my64bits,bits256 pri
} }
if ( myind < 0 ) if ( myind < 0 )
return(clonestr("{\"error\":\"this table is not for me\"}")); return(clonestr("{\"error\":\"this table is not for me\"}"));
/*if ( (array= jarray(&num,json,"balances")) == 0 )
{
PNACL_message("no balances or illegal num.%d\n",num);
return(clonestr("{\"error\":\"no balances or illegal numplayers\"}"));
}
for (i=0; i<num; i++)
balances[i] = j64bits(jitem(array,i),0);*/
if ( (array= jarray(&num,json,"isbot")) != 0 ) if ( (array= jarray(&num,json,"isbot")) != 0 )
{ {
for (i=0; i<num; i++) for (i=0; i<num; i++)
@ -315,7 +309,7 @@ char *pangea_newtable(int32_t threadid,cJSON *json,uint64_t my64bits,bits256 pri
} }
} }
return(clonestr("{\"error\":\"no tableid\"}")); return(clonestr("{\"error\":\"no tableid\"}"));
} }*/
struct pangea_thread *pangea_threadinit(struct supernet_info *plugin,int32_t maxplayers) struct pangea_thread *pangea_threadinit(struct supernet_info *plugin,int32_t maxplayers)
{ {

316
iguana/pangea_json.c

@ -0,0 +1,316 @@
/******************************************************************************
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "pangea777.h"
cJSON *pangea_tablejson(struct game_info *gp)
{
char ipaddr[64],str[64]; struct tai t; int32_t seconds; cJSON *json = cJSON_CreateObject();
jaddbits256(json,"tablehash",gp->tablehash);
expand_ipbits(ipaddr,gp->hostipbits);
jaddstr(json,"host",ipaddr);
jaddnum(json,"minbuyin",dstr(gp->minbuyin));
jaddnum(json,"maxbuyin",dstr(gp->maxbuyin));
jaddnum(json,"minplayers",gp->minplayers);
jaddnum(json,"maxplayers",gp->maxplayers);
jaddnum(json,"M",gp->M);
jaddnum(json,"N",gp->N);
jaddnum(json,"numcards",gp->numcards);
jaddnum(json,"rake",(double)gp->rakemillis/10.);
jaddnum(json,"maxrake",dstr(gp->maxrake));
jaddnum(json,"hostrake",dstr(gp->hostrake));
jaddnum(json,"pangearake",dstr(gp->pangearake));
jaddnum(json,"bigblind",dstr(gp->bigblind));
jaddnum(json,"ante",dstr(gp->ante));
if ( gp->opentime != 0 )
{
OS_conv_unixtime(&t,&seconds,gp->opentime);
jaddstr(json,"opentime",utc_str(str,t));
if ( gp->started != 0 )
{
OS_conv_unixtime(&t,&seconds,gp->started);
jaddstr(json,"started",utc_str(str,t));
if ( gp->finished != 0 )
{
OS_conv_unixtime(&t,&seconds,gp->finished);
jaddstr(json,"finished",utc_str(str,t));
}
}
}
return(json);
}
void pangea_gamecreate(struct game_info *gp,uint32_t timestamp,bits256 tablehash,cJSON *json)
{
gp->gamehash = calc_categoryhashes(0,"pangea",0);
gp->tablehash = tablehash;
gp->hostipbits = calc_ipbits(jstr(json,"myipaddr"));
gp->minbuyin = jdouble(json,"minbuyin") * SATOSHIDEN;
gp->maxbuyin = jdouble(json,"maxbuyin") * SATOSHIDEN;
gp->minplayers = juint(json,"minplayers");
gp->maxplayers = juint(json,"maxplayers");
if ( (gp->N= juint(json,"N")) < gp->minplayers )
gp->N = gp->minplayers;
if ( (gp->M= juint(json,"M")) > gp->N )
gp->M = gp->N;
if ( (gp->numcards= juint(json,"numcards")) != 52 )
gp->numcards = 52;
gp->rakemillis = jdouble(json,"rake") * 10.;
gp->maxrake = jdouble(json,"maxrake") * SATOSHIDEN;
gp->hostrake = jdouble(json,"hostrake") * SATOSHIDEN;
gp->pangearake = jdouble(json,"pangearake") * SATOSHIDEN;
gp->bigblind = jdouble(json,"bigblind") * SATOSHIDEN;
gp->ante = jdouble(json,"ante") * SATOSHIDEN;
gp->opentime = timestamp;
}
int32_t pangea_opentable(struct game_info *gp)
{
if ( gp->opentime != 0 && gp->started == 0 )
return(1);
else if ( gp->finished != 0 )
return(0);
else return(-1);
}
cJSON *pangea_lobbyjson(struct supernet_info *myinfo)
{
struct category_info *cat,*sub,*tmp; struct table_info *tp; cJSON *array,*retjson;
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
if ( (cat= category_find(calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY)) != 0 )
{
HASH_ITER(hh,cat->sub,sub,tmp)
{
if ( (tp= sub->info) != 0 && pangea_opentable(&tp->G) > 0 )
jaddi(array,pangea_tablejson(&tp->G));
}
}
jadd(retjson,"tables",array);
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)
{
int32_t i,card; char cardAstr[8],cardBstr[8],pairstr[18],cstr[128]; cJSON *array,*json = cJSON_CreateObject();
array = cJSON_CreateArray();
cstr[0] = 0;
for (i=0; i<5; i++)
{
if ( (card= hand->community[i]) != 0xff )
{
jaddinum(array,card);
cardstr(&cstr[strlen(cstr)],card);
strcat(cstr," ");
}
}
jaddstr(json,"community",cstr);
jadd(json,"cards",array);
if ( (card= holecards[0]) != 0xff )
{
jaddnum(json,"cardA",card);
cardstr(cardAstr,holecards[0]);
} else cardAstr[0] = 0;
if ( (card= holecards[1]) != 0xff )
{
jaddnum(json,"cardB",card);
cardstr(cardBstr,holecards[1]);
} else cardBstr[0] = 0;
sprintf(pairstr,"%s %s",cardAstr,cardBstr);
jaddstr(json,"holecards",pairstr);
jaddnum(json,"betsize",dstr(hand->betsize));
jaddnum(json,"lastraise",dstr(hand->lastraise));
jaddnum(json,"lastbettor",hand->lastbettor);
jaddnum(json,"numactions",hand->numactions);
jaddnum(json,"undergun",hand->undergun);
jaddnum(json,"isbot",isbot);
jaddnum(json,"cardi",hand->cardi);
return(json);
}
char *pangea_statusstr(int32_t status)
{
if ( status == CARDS777_FOLD )
return("folded");
else if ( status == CARDS777_ALLIN )
return("ALLin");
else return("active");
}
int32_t pangea_countdown(struct table_info *tp,struct player_info *p)
{
struct hand_info *hand = &tp->hand;
if ( p != 0 && hand->undergun == p->ind && hand->userinput_starttime != 0 )
return((int32_t)(hand->userinput_starttime + PANGEA_USERTIMEOUT - time(NULL)));
else return(-1);
}
cJSON *pangea_tablestatus(struct supernet_info *myinfo,struct table_info *tp)
{
int64_t sidepots[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS],totals[CARDS777_MAXPLAYERS],sum;
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 total,val; char *handhist,*str; struct game_info *gp; struct hand_info *hand;
hand = &tp->hand, gp = &tp->G, N = tp->numactive;
json = cJSON_CreateObject();
jaddbits256(json,"tablehash",gp->tablehash);
jadd64bits(json,"myind",tp->priv.myind);
jaddnum(json,"minbuyin",gp->minbuyin);
jaddnum(json,"maxbuyin",gp->maxbuyin);
jaddnum(json,"button",tp->hand.button);
jaddnum(json,"M",gp->M);
jaddnum(json,"N",tp->numactive);
jaddnum(json,"numcards",gp->numcards);
jaddnum(json,"numhands",tp->numhands);
jaddnum(json,"rake",(double)gp->rakemillis/10.);
jaddnum(json,"maxrake",dstr(gp->maxrake));
jaddnum(json,"hostrake",dstr(gp->hostrake));
jaddnum(json,"pangearake",dstr(gp->pangearake));
jaddnum(json,"bigblind",dstr(gp->bigblind));
jaddnum(json,"ante",dstr(gp->ante));
array = cJSON_CreateArray();
for (i=0; i<tp->numactive; i++)
jaddi64bits(array,tp->active[i]!=0?tp->active[i]->nxt64bits:0);
jadd(json,"addrs",array);
total = 0;
for (iter=0; iter<6; iter++)
{
array = cJSON_CreateArray();
for (i=0; i<tp->numactive; i++)
{
val = 0;
if ( (p= tp->active[i]) != 0 )
{
switch ( iter )
{
case 0: val = p->turni; str = "turns"; break;
case 1: val = p->balance; str = "balances"; break;
case 2: val = p->snapshot; str = "snapshot"; break;
case 3: val = p->betstatus; str = "status"; break;
case 4: val = p->bets; str = "bets"; break;
case 5: val = p->won; str = "won"; break;
}
}
if ( iter == 5 )
won[i] = val;
else
{
if ( iter == 3 )
jaddistr(array,pangea_statusstr((int32_t)val));
else
{
if ( iter == 4 )
total += val, bets[i] = val;
else if ( iter == 2 )
snapshot[i] = val;
jaddinum(array,val);
}
}
}
jadd(json,str,array);
}
jaddnum(json,"totalbets",dstr(total));
for (iter=0; iter<2; iter++)
if ( (n= pangea_sidepots(myinfo,tp,0,sidepots,iter == 0 ? snapshot : bets)) > 0 && n < N )
{
array = cJSON_CreateArray();
for (i=0; i<n; i++)
{
item = cJSON_CreateArray();
for (sum=j=0; j<N; j++)
jaddinum(item,dstr(sidepots[i][j])), sum += sidepots[i][j];
totals[i] = sum;
jaddi(array,item);
}
jadd(json,iter == 0 ? "pots" : "RTpots",array);
item = cJSON_CreateArray();
for (sum=i=0; i<n; i++)
jaddinum(item,dstr(totals[i])), sum += totals[i];
jadd(json,iter == 0 ? "potTotals" : "RTpotTotals",item);
jaddnum(json,iter == 0 ? "sum" : "RTsum",dstr(sum));
}
jadd64bits(json,"automuck",tp->priv.automuck);
jadd64bits(json,"autofold",tp->priv.autofold);
jadd(json,"hand",pangea_handjson(hand,tp->priv.hole,0));
if ( (handhist= pangea_dispsummary(myinfo,tp,0,tp->summary,tp->summarysize,tp->G.tablehash,tp->numhands-1,N)) != 0 )
{
if ( (item= cJSON_Parse(handhist)) != 0 )
jadd(json,"actions",item);
free(handhist);
}
if ( (countdown= pangea_countdown(tp,tp->active[tp->priv.myind])) >= 0 )
jaddnum(json,"timeleft",countdown);
if ( hand->finished != 0 )
{
item = cJSON_CreateObject();
jaddnum(item,"hostrake",dstr(tp->G.hostrake));
jaddnum(item,"pangearake",dstr(tp->G.pangearake));
array = cJSON_CreateArray();
for (i=0; i<N; i++)
jaddinum(array,dstr(won[i]));
jadd(item,"won",array);
jadd(json,"summary",item);
}
return(json);
}
void pangea_playerprint(struct supernet_info *myinfo,struct table_info *tp,int32_t i,int32_t myind)
{
int32_t countdown; char str[8]; struct player_info *p;
if ( (p= tp->active[i]) != 0 )
{
if ( (countdown= pangea_countdown(tp,tp->active[tp->priv.myind])) >= 0 )
sprintf(str,"%2d",countdown);
else str[0] = 0;
printf("%d: %6s %12.8f %2s | %12.8f %s\n",i,pangea_statusstr(p->betstatus),dstr(p->bets),str,dstr(p->balance),i == 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;
N = tp->numactive;
for (i=0; i<N; i++)
pangea_playerprint(myinfo,tp,i,myind);
handstr[0] = 0;
if ( hand->community[0] != hand->community[1] )
{
for (i=0; i<5; i++)
if ( (handvals[i]= hand->community[i]) == 0xff )
break;
if ( i == 5 )
{
if ( (handvals[5]= tp->priv.hole[0]) != 0xff && (handvals[6]= tp->priv.hole[1]) != 0xff )
set_handstr(handstr,handvals,1);
}
}
printf("%s\n",handstr);
}

11
iguana/pangea_network.c

@ -74,12 +74,12 @@ void pangeanet777_processmsg(uint64_t *destbitsp,bits256 *senderpubp,queue_t *Q,
int32_t pangeanet777_idle(union pangeanet777 *hn) int32_t pangeanet777_idle(union pangeanet777 *hn)
{ {
int32_t len=0,slot,n = 0; bits256 senderpub,mypriv,mypub; uint64_t destbits; uint8_t *msg=0; /*int32_t slot,n = 0; bits256 senderpub,mypriv,mypub; uint64_t destbits;// uint8_t *msg=0;
//long extra = sizeof(bits256)+sizeof(uint64_t); //long extra = sizeof(bits256)+sizeof(uint64_t);
if ( (slot= hn->client->H.slot) != 0 ) if ( (slot= hn->client->H.slot) != 0 )
{ {
mypriv = hn->client->H.privkey, mypub = hn->client->H.pubkey; mypriv = hn->client->H.privkey, mypub = hn->client->H.pubkey;
/*if ( (sock= hn->client->subsock) >= 0 && (len= nn_recv(sock,&msg,NN_MSG,0)) > extra ) if ( (sock= hn->client->subsock) >= 0 && (len= nn_recv(sock,&msg,NN_MSG,0)) > extra )
{ {
SuperNET_copybits(1,msg,(void *)&destbits,sizeof(uint64_t)); SuperNET_copybits(1,msg,(void *)&destbits,sizeof(uint64_t));
//printf("client got pub len.%d\n",len); //printf("client got pub len.%d\n",len);
@ -87,7 +87,7 @@ int32_t pangeanet777_idle(union pangeanet777 *hn)
pangeanet777_processmsg(&destbits,&senderpub,&hn->client->H.Q,mypriv,mypub,msg,len,0), n++; pangeanet777_processmsg(&destbits,&senderpub,&hn->client->H.Q,mypriv,mypub,msg,len,0), n++;
nn_freemsg(msg); nn_freemsg(msg);
} else if ( hn->client->H.pollfunc != 0 ) } else if ( hn->client->H.pollfunc != 0 )
(*hn->client->H.pollfunc)(hn);*/ (*hn->client->H.pollfunc)(hn);
} }
else else
{ {
@ -96,7 +96,7 @@ int32_t pangeanet777_idle(union pangeanet777 *hn)
for (slot=1; slot<hn->server->num; slot++) for (slot=1; slot<hn->server->num; slot++)
{ {
//printf("check ind.%d %.0f\n",ind,milliseconds()); //printf("check ind.%d %.0f\n",ind,milliseconds());
//f ( (sock= hn->server->clients[slot].pmsock) >= 0 && (len= nn_recv(sock,&msg,NN_MSG,0)) > extra ) if ( (sock= hn->server->clients[slot].pmsock) >= 0 && (len= nn_recv(sock,&msg,NN_MSG,0)) > extra )
{ {
//printf("server got pm[%d] %d\n",slot,len); //printf("server got pm[%d] %d\n",slot,len);
SuperNET_copybits(1,msg,(void *)&destbits,sizeof(uint64_t)); SuperNET_copybits(1,msg,(void *)&destbits,sizeof(uint64_t));
@ -113,7 +113,8 @@ int32_t pangeanet777_idle(union pangeanet777 *hn)
if ( hn->server->H.pollfunc != 0 ) if ( hn->server->H.pollfunc != 0 )
(*hn->server->H.pollfunc)(hn); (*hn->server->H.pollfunc)(hn);
} }
return(n); return(n);*/
return(0);
} }
int32_t pangeanet777_replace(struct pangeanet777_server *srv,bits256 clientpub,int32_t slot) int32_t pangeanet777_replace(struct pangeanet777_server *srv,bits256 clientpub,int32_t slot)

311
iguana/pangea_summary.c

@ -0,0 +1,311 @@
/******************************************************************************
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "pangea777.h"
char *pangea_typestr(uint8_t type)
{
static char err[64];
switch ( type )
{
case 0xff: return("fold");
case CARDS777_START: return("start");
case CARDS777_ANTE: return("ante");
case CARDS777_SMALLBLIND: return("smallblind");
case CARDS777_BIGBLIND: return("bigblind");
case CARDS777_CHECK: return("check");
case CARDS777_CALL: return("call");
case CARDS777_BET: return("bet");
case CARDS777_RAISE: return("raise");
case CARDS777_FULLRAISE: return("fullraise");
case CARDS777_SENTCARDS: return("sentcards");
case CARDS777_ALLIN: return("allin");
case CARDS777_FACEUP: return("faceup");
case CARDS777_WINNINGS: return("won");
case CARDS777_RAKES: return("rakes");
case CARDS777_CHANGES: return("changes");
case CARDS777_SNAPSHOT: return("snapshot");
}
sprintf(err,"unknown type.%d",type);
return(err);
}
cJSON *pangea_handitem(int32_t *cardip,cJSON **pitemp,uint8_t type,uint64_t valA,uint64_t *bits64p,bits256 card,int32_t numplayers)
{
int32_t cardi,n,i,rebuy,busted; char str[128],hexstr[65],cardpubs[(CARDS777_MAXCARDS+1)*64+1]; cJSON *item,*array,*pitem = 0;
item = cJSON_CreateObject();
*cardip = -1;
switch ( type )
{
case CARDS777_START:
jaddnum(item,"handid",valA);
init_hexbytes_noT(cardpubs,(void *)bits64p,(int32_t)((CARDS777_MAXCARDS+1) * sizeof(bits256)));
jaddstr(item,"cardpubs",cardpubs);
break;
case CARDS777_RAKES:
jaddnum(item,"hostrake",dstr(valA));
jaddnum(item,"pangearake",dstr(*bits64p));
break;
case CARDS777_SNAPSHOT:
jaddnum(item,"handid",valA);
array = cJSON_CreateArray();
for (i=0; i<CARDS777_MAXPLAYERS; i++)
{
if ( i < numplayers )
jaddinum(array,dstr(bits64p[i]));
else jaddinum(array,dstr(0));
}
jadd(item,"snapshot",array);
//printf("add snapshot for numplayers.%d\n",numplayers);
break;
case CARDS777_CHANGES:
n = (int32_t)(valA & 0xf);
busted = (int32_t)((valA>>4) & 0xffff);
rebuy = (int32_t)((valA>>20) & 0xffff);
if ( busted != 0 )
jaddnum(item,"busted",busted);
if ( rebuy != 0 )
jaddnum(item,"rebuy",rebuy);
array = cJSON_CreateArray();
for (i=0; i<n; i++)
jaddinum(array,dstr(bits64p[i]));
jadd(item,"balances",array);
break;
case CARDS777_WINNINGS:
if ( (int32_t)valA >= 0 && valA < numplayers )
jaddnum(item,"player",valA);
jaddnum(item,"won",dstr(*bits64p));
if ( pitem == 0 )
pitem = cJSON_CreateObject();
jaddnum(pitem,"won",dstr(*bits64p));
break;
case CARDS777_FACEUP:
*cardip = cardi = (int32_t)(valA >> 8);
if ( cardi >= 0 && cardi < 52 )
jaddnum(item,"cardi",cardi);
else printf("illegal cardi.%d valA.%llu\n",cardi,(long long)valA);
valA &= 0xff;
if ( (int32_t)valA >= 0 && valA < numplayers )
jaddnum(item,"player",valA);
else if ( valA == 0xff )
jaddnum(item,"community",cardi - numplayers*2);
cardstr(str,card.bytes[1]);
jaddnum(item,str,card.bytes[1]);
init_hexbytes_noT(hexstr,card.bytes,sizeof(card));
jaddstr(item,"privkey",hexstr);
break;
default:
if ( (int32_t)valA >= 0 && valA < numplayers )
jaddnum(item,"player",valA);
jaddstr(item,"action",pangea_typestr(type));
if ( pitem == 0 )
pitem = cJSON_CreateObject();
if ( *bits64p != 0 )
{
jaddnum(item,"bet",dstr(*bits64p));
jaddnum(pitem,pangea_typestr(type),dstr(*bits64p));
}
else jaddstr(pitem,"action",pangea_typestr(type));
break;
}
*pitemp = pitem;
return(item);
}
int32_t pangea_parsesummary(uint8_t *typep,uint64_t *valAp,uint64_t *bits64p,bits256 *cardp,uint8_t *summary,int32_t len)
{
int32_t handid; uint16_t cardi_player; uint32_t changes=0; uint8_t player;
*bits64p = 0;
memset(cardp,0,sizeof(*cardp));
len += SuperNET_copybits(1,&summary[len],(void *)typep,sizeof(*typep));
if ( *typep == 0 )
{
printf("len.%d type.%d [%d]\n",len,*typep,summary[len-1]);
return(-1);
}
if ( *typep == CARDS777_START || *typep == CARDS777_SNAPSHOT )
len += SuperNET_copybits(1,&summary[len],(void *)&handid,sizeof(handid)), *valAp = handid;
else if ( *typep == CARDS777_CHANGES )
len += SuperNET_copybits(1,&summary[len],(void *)&changes,sizeof(changes)), *valAp = changes;
else if ( *typep == CARDS777_RAKES )
len += SuperNET_copybits(1,&summary[len],(void *)valAp,sizeof(*valAp));
else if ( *typep == CARDS777_FACEUP )
len += SuperNET_copybits(1,&summary[len],(void *)&cardi_player,sizeof(cardi_player)), *valAp = cardi_player;
else len += SuperNET_copybits(1,&summary[len],(void *)&player,sizeof(player)), *valAp = player;
if ( *typep == CARDS777_FACEUP )
len += SuperNET_copybits(1,&summary[len],cardp->bytes,sizeof(*cardp));
else if ( *typep == CARDS777_START )
len += SuperNET_copybits(1,&summary[len],(void *)bits64p,sizeof(bits256)*(CARDS777_MAXCARDS+1));
else if ( *typep == CARDS777_SNAPSHOT )
len += SuperNET_copybits(1,&summary[len],(void *)bits64p,sizeof(*bits64p) * CARDS777_MAXPLAYERS);
else if ( *typep == CARDS777_CHANGES )
len += SuperNET_copybits(1,&summary[len],(void *)bits64p,sizeof(*bits64p) * (changes & 0xf));
else len += SuperNET_copybits(1,&summary[len],(void *)bits64p,sizeof(*bits64p));
return(len);
}
char *pangea_dispsummary(struct supernet_info *myinfo,struct table_info *tp,int32_t verbose,uint8_t *summary,int32_t summarysize,bits256 tablehash,int32_t handid,int32_t numplayers)
{
int32_t i,cardi,n = 0,len = 0; uint8_t type; uint64_t valA,bits64[CARDS777_MAXPLAYERS + (CARDS777_MAXCARDS+1)*4]; bits256 card;
cJSON *item,*json,*all,*cardis[52],*players[CARDS777_MAXPLAYERS],*pitem,*array = cJSON_CreateArray();
all = cJSON_CreateArray();
memset(cardis,0,sizeof(cardis));
memset(players,0,sizeof(players));
for (i=0; i<numplayers; i++)
players[i] = cJSON_CreateArray();
while ( len < summarysize )
{
memset(bits64,0,sizeof(bits64));
len = pangea_parsesummary(&type,&valA,bits64,&card,summary,len);
if ( (item= pangea_handitem(&cardi,&pitem,type,valA,bits64,card,numplayers)) != 0 )
{
if ( cardi >= 0 && cardi < 52 )
{
//printf("cardis[%d] <- %p\n",cardi,item);
cardis[cardi] = item;
}
else jaddi(array,item);
item = 0;
}
if ( pitem != 0 )
{
jaddnum(pitem,"n",n), n++;
if ( (int32_t)valA >= 0 && valA < numplayers )
jaddi(players[valA],pitem);
else free_json(pitem), printf("illegal player.%llu\n",(long long)valA);
pitem = 0;
}
}
for (i=0; i<numplayers; i++)
jaddi(all,players[i]);
if ( verbose == 0 )
{
for (i=0; i<52; i++)
if ( cardis[i] != 0 )
free_json(cardis[i]);
free_json(array);
return(jprint(all,1));
}
else
{
json = cJSON_CreateObject();
jaddbits256(json,"tablehash",tablehash);
jaddnum(json,"size",summarysize);
jaddnum(json,"handid",handid);
//jaddnum(json,"crc",_crc32(0,summary,summarysize));
jadd(json,"hand",array);
array = cJSON_CreateArray();
for (i=0; i<52; i++)
if ( cardis[i] != 0 )
jaddi(array,cardis[i]);
jadd(json,"cards",array);
//jadd(json,"players",all);
return(jprint(json,1));
}
}
void pangea_summaryadd(struct supernet_info *myinfo,struct table_info *tp,uint8_t type,void *arg0,int32_t size0,void *arg1,int32_t size1)
{
uint64_t valA,bits64[CARDS777_MAXPLAYERS + (CARDS777_MAXCARDS+1)*4];
bits256 card; uint8_t checktype; int32_t len,startlen = tp->summarysize;
if ( type == 0 )
{
printf("type.0\n"); getchar();
}
//printf("summarysize.%d type.%d [%02x %02x]\n",dp->summarysize,type,*(uint8_t *)arg0,*(uint8_t *)arg1);
tp->summarysize += SuperNET_copybits(0,&tp->summary[tp->summarysize],(void *)&type,sizeof(type));
//printf("-> %d\n",tp->summary[tp->summarysize-1]);
tp->summarysize += SuperNET_copybits(0,&tp->summary[tp->summarysize],arg0,size0);
tp->summarysize += SuperNET_copybits(0,&tp->summary[tp->summarysize],arg1,size1);
//printf("startlen.%d summarysize.%d\n",startlen,tp->summarysize);
len = pangea_parsesummary(&checktype,&valA,bits64,&card,tp->summary,startlen);
if ( len != tp->summarysize || checktype != type || memcmp(&valA,arg0,size0) != 0 )
printf("pangea_summary parse error [%d] (%d vs %d) || (%d vs %d).%d || cmp.%d size0.%d size1.%d\n",startlen,len,tp->summarysize,checktype,type,tp->summary[startlen],memcmp(&valA,arg0,size0),size0,size1);
if ( card.txid != 0 && memcmp(card.bytes,arg1,sizeof(card)) != 0 )
printf("pangea_summary: parse error card mismatch %llx != %llx\n",(long long)card.txid,*(long long *)arg1);
else if ( card.txid == 0 && memcmp(arg1,bits64,size1) != 0 )
printf("pangea_summary: parse error bits64 %llx != %llx\n",(long long)bits64[0],*(long long *)arg0);
/*if ( 1 && hn->client->H.slot == pangea_slotA(tp->table) )
{
if ( (item= pangea_handitem(&cardi,&pitem,type,valA,bits64,card,tp->G.N)) != 0 )
{
str = jprint(item,1);
printf("ITEM.(%s)\n",str);
free(str);
}
if ( pitem != 0 )
{
str = jprint(pitem,1);
printf("PITEM.(%s)\n",str);
free(str);
}
}*/
if ( Debuglevel > 2 )//|| hn->client->H.slot == pangea_slotA(tp->table) )
printf("pangea_summary.%d %d | summarysize.%d crc.%u\n",type,*(uint8_t *)arg0,tp->summarysize,calc_crc32(0,tp->summary,tp->summarysize));
}
void pangea_summary(PANGEA_HANDARGS)
{
char *otherhist,*handhist = 0; int32_t senderind,N,matched = 0; struct hand_info *hand = &tp->hand;
senderind = pm->myind, N = tp->numactive;
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));
if ( datalen == tp->summarysize )
{
if ( memcmp(tp->summary,data,datalen) == 0 )
{
//printf("P%d: matched senderind.%d\n",priv->myslot,senderind);
matched = 1;
}
else
{
if ( (handhist= pangea_dispsummary(myinfo,tp,1,tp->summary,tp->summarysize,tp->G.tablehash,tp->numhands-1,N)) != 0 )
{
if ( (otherhist= pangea_dispsummary(myinfo,tp,1,data,datalen,tp->G.tablehash,tp->numhands-1,N)) != 0 )
{
if ( strcmp(handhist,otherhist) == 0 )
{
//printf("P%d: matched B senderind.%d\n",priv->myslot,senderind);
matched = 1;
}
else printf("\n[%s] MISMATCHED vs \n[%s]\n",handhist,otherhist);
free(otherhist);
} else printf("error getting otherhist\n");
free(handhist);
} else printf("error getting handhist\n");
}
}
if ( matched != 0 )
hand->summaries |= (1LL << senderind);
else
{
//printf("P%d: MISMATCHED senderind.%d\n",priv->myslot,senderind);
hand->mismatches |= (1LL << senderind);
}
if ( senderind == 0 && tp->priv.myind != pangea_slotA(tp) )
pangea_sendcmd(myinfo,tp,"summary",-1,tp->summary,tp->summarysize,0,0);
if ( (hand->mismatches | hand->summaries) == (1LL << N)-1 )
{
if ( Debuglevel > 2 )
printf("P%d: hand summary matches.%llx errors.%llx | size.%d\n",tp->priv.myind,(long long)hand->summaries,(long long)hand->mismatches,tp->summarysize);
//if ( handhist == 0 && (handhist= pangea_dispsummary(sp,1,dp->summary,dp->summarysize,sp->tableid,dp->numhands-1,dp->N)) != 0 )
// printf("HAND.(%s)\n",handhist), free(handhist);
if ( tp->priv.myind == 0 )
{
hand->mismatches = hand->summaries = 0;
pangea_anotherhand(myinfo,tp,PANGEA_PAUSE);
}
}
}

3
includes/curve25519.h

@ -34,7 +34,7 @@ typedef union _bits384 bits384;
struct sha256_vstate { uint64_t length; uint32_t state[8],curlen; uint8_t buf[64]; }; struct sha256_vstate { uint64_t length; uint32_t state[8],curlen; uint8_t buf[64]; };
struct rmd160_vstate { uint64_t length; uint8_t buf[64]; uint32_t curlen, state[5]; }; struct rmd160_vstate { uint64_t length; uint8_t buf[64]; uint32_t curlen, state[5]; };
struct acct777_sig { bits256 sigbits,pubkey; uint64_t signer64bits; uint32_t timestamp,allocsize; uint8_t serialized[]; }; struct acct777_sig { bits256 sigbits,pubkey; uint64_t signer64bits; uint32_t timestamp,allocsize; };
#undef force_inline #undef force_inline
#define force_inline __attribute__((always_inline)) #define force_inline __attribute__((always_inline))
@ -64,6 +64,7 @@ bits128 calc_md5(char digeststr[33],void *buf,int32_t len);
bits256 acct777_msgprivkey(uint8_t *data,int32_t datalen); bits256 acct777_msgprivkey(uint8_t *data,int32_t datalen);
bits256 acct777_msgpubkey(uint8_t *data,int32_t datalen); bits256 acct777_msgpubkey(uint8_t *data,int32_t datalen);
void acct777_rwsig(int32_t rwflag,uint8_t *serialized,struct acct777_sig *sig);
bits256 acct777_pubkey(bits256 privkey); bits256 acct777_pubkey(bits256 privkey);
uint64_t acct777_nxt64bits(bits256 pubkey); uint64_t acct777_nxt64bits(bits256 pubkey);

37
includes/iguana_apideclares.h

@ -13,6 +13,15 @@
* * * *
******************************************************************************/ ******************************************************************************/
/*HASH_AND_ARRAY(pangea,userturn,tablehash,params);
HASH_AND_ARRAY(pangea,status,tableid,params);
HASH_AND_ARRAY(pangea,mode,tableid,params);
HASH_AND_ARRAY(pangea,buyin,tableid,params);
HASH_AND_ARRAY(pangea,history,tableid,params);*/
INT_AND_ARRAY(pangea,host,minplayers,params);
ZERO_ARGS(pangea,lobby);
HASH_AND_ARRAY(pangea,join,tablehash,params);
ZERO_ARGS(SuperNET,help); ZERO_ARGS(SuperNET,help);
STRING_ARG(SuperNET,bitcoinrpc,setcoin); STRING_ARG(SuperNET,bitcoinrpc,setcoin);
@ -52,34 +61,6 @@ ZERO_ARGS(SuperNET,stop);
HASH_AND_STRING(SuperNET,saveconf,wallethash,confjsonstr); HASH_AND_STRING(SuperNET,saveconf,wallethash,confjsonstr);
HASH_ARRAY_STRING(SuperNET,layer,mypriv,otherpubs,str); HASH_ARRAY_STRING(SuperNET,layer,mypriv,otherpubs,str);
INT_AND_ARRAY(pangea,newhand,senderind,params);
INT_AND_ARRAY(pangea,ping,senderind,params);
INT_AND_ARRAY(pangea,gotdeck,senderind,params);
INT_AND_ARRAY(pangea,ready,senderind,params);
INT_AND_ARRAY(pangea,encoded,senderind,params);
INT_AND_ARRAY(pangea,final,senderind,params);
INT_AND_ARRAY(pangea,addedfunds,senderind,params);
INT_AND_ARRAY(pangea,preflop,senderind,params);
INT_AND_ARRAY(pangea,decoded,senderind,params);
INT_AND_ARRAY(pangea,card,senderind,params);
INT_AND_ARRAY(pangea,facedown,senderind,params);
INT_AND_ARRAY(pangea,faceup,senderind,params);
INT_AND_ARRAY(pangea,turn,senderind,params);
INT_AND_ARRAY(pangea,confirmturn,senderind,params);
INT_AND_ARRAY(pangea,chat,senderind,params);
INT_AND_ARRAY(pangea,action,senderind,params);
INT_AND_ARRAY(pangea,showdown,senderind,params);
INT_AND_ARRAY(pangea,handsummary,senderind,params);
HASH_AND_ARRAY(pangea,status,tableid,params);
HASH_AND_ARRAY(pangea,mode,tableid,params);
HASH_AND_ARRAY(pangea,buyin,tableid,params);
HASH_AND_ARRAY(pangea,history,tableid,params);
ZERO_ARGS(pangea,lobby);
INT_AND_ARRAY(pangea,host,minplayers,params);
HASH_AND_ARRAY(pangea,join,tablehash,params);
STRING_ARG(iguana,peers,activecoin); STRING_ARG(iguana,peers,activecoin);
STRING_AND_INT(iguana,maxpeers,activecoin,max); STRING_AND_INT(iguana,maxpeers,activecoin,max);
STRING_ARG(iguana,getconnectioncount,activecoin); STRING_ARG(iguana,getconnectioncount,activecoin);

2
pangea/pangea777.c

@ -1130,7 +1130,7 @@ int32_t pangea_poll(uint64_t *senderbitsp,uint32_t *timestampp,union hostnet777
pangea_faceup(hn,json,dp,priv,buf,len,senderind); pangea_faceup(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"turn") == 0 ) else if ( strcmp(cmdstr,"turn") == 0 )
pangea_turn(hn,json,dp,priv,buf,len,senderind); pangea_turn(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"confirmturn") == 0 ) else if ( strcmp(cmdstr,"confirm") == 0 )
pangea_confirmturn(hn,json,dp,priv,buf,len,senderind); pangea_confirmturn(hn,json,dp,priv,buf,len,senderind);
else if ( strcmp(cmdstr,"chat") == 0 ) else if ( strcmp(cmdstr,"chat") == 0 )
pangea_chat(*senderbitsp,buf,len,senderind); pangea_chat(*senderbitsp,buf,len,senderind);

4
pangea/pangeafunds.c

@ -959,7 +959,7 @@ int32_t pangea_turn(union hostnet777 *hn,cJSON *json,struct cards777_pubdata *dp
betsize = dp->hand.bets[i]; betsize = dp->hand.bets[i];
dp->hand.snapshot[dp->N] = betsize; dp->hand.snapshot[dp->N] = betsize;
//printf("player.%d sends confirmturn.%d\n",hn->client->H.slot,turni); //printf("player.%d sends confirmturn.%d\n",hn->client->H.slot,turni);
pangea_sendcmd(hex,hn,"confirmturn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),cardi,turni); pangea_sendcmd(hex,hn,"confirm",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),cardi,turni);
} }
} }
return(0); return(0);
@ -1010,7 +1010,7 @@ int32_t pangea_confirmturn(union hostnet777 *hn,cJSON *json,struct cards777_pubd
//if ( Debuglevel > 2 ) //if ( Debuglevel > 2 )
printf("player.%d sends confirmturn.%d cardi.%d betsize %.0f\n",hn->client->H.slot,dp->hand.undergun,dp->hand.cardi,dstr(betsize)); printf("player.%d sends confirmturn.%d cardi.%d betsize %.0f\n",hn->client->H.slot,dp->hand.undergun,dp->hand.cardi,dstr(betsize));
if ( senderind != 0 ) if ( senderind != 0 )
pangea_sendcmd(hex,hn,"confirmturn",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),dp->hand.cardi,dp->hand.undergun); pangea_sendcmd(hex,hn,"confirm",-1,(void *)dp->hand.snapshot,sizeof(uint64_t)*(dp->N+1),dp->hand.cardi,dp->hand.undergun);
} }
if ( senderind == 0 && (turni= dp->hand.undergun) == pangea_ind(dp->table,hn->client->H.slot) ) if ( senderind == 0 && (turni= dp->hand.undergun) == pangea_ind(dp->table,hn->client->H.slot) )
{ {

Loading…
Cancel
Save