You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1067 lines
44 KiB

9 years ago
/******************************************************************************
* 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"
9 years ago
#define PANGEA_GOTDECKS 1
#define PANGEA_GOTFINAL 2
struct pangea_queueitem { struct queueitem DL; struct tai start,last; int32_t waitevent; };
struct pangea_queueitem *pangea_queuefind(struct table_info *tp,int32_t waitevent)
{
int32_t iter; struct pangea_queueitem *ptr;
for (iter=0; iter<2; iter++)
{
while ( (ptr= queue_dequeue(&tp->stateQ[iter],0)) != 0 )
{
if ( ptr->waitevent == waitevent )
return(ptr);
queue_enqueue("stateQ",&tp->stateQ[iter ^ 1],&ptr->DL,0);
}
}
return(0);
}
void pangea_queuestate(struct table_info *tp,int32_t currentstate,int32_t waitevent)
{
struct pangea_queueitem *ptr;
if ( (ptr= pangea_queuefind(tp,currentstate)) == 0 )
ptr = calloc(1,sizeof(*ptr));
ptr->last = ptr->start = tai_now();
ptr->waitevent = waitevent;
char str[65]; printf("table.%s current.%d -> wait.%d\n",bits256_str(str,tp->G.tablehash),currentstate,waitevent);
queue_enqueue("stateQ",&tp->stateQ[0],&ptr->DL,0);
}
9 years ago
int32_t pangea_slotA(struct table_info *tp) { return(0); }
int32_t pangea_slotB(struct table_info *tp) { return(1); }
9 years ago
int32_t pangea_lastnode(struct table_info *tp) { return(tp->G.numactive-1); }
9 years ago
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;
9 years ago
for (i=n=0; i<tp->G.numactive; i++)
9 years ago
{
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;
9 years ago
for (i=0; i<tp->G.numactive; i++)
9 years ago
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)
{
9 years ago
int32_t i; struct hand_info *hand = &tp->hand;
9 years ago
memset(hand,0,sizeof(*hand));
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;
9 years ago
if ( tp->G.N < tp->G.numactive )
tp->G.N = tp->G.numactive;
9 years ago
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;
9 years ago
//if ( tp->G.P[i].balance > 0 )
9 years ago
playerpubs[n++] = tp->G.P[i].playerpub;
9 years ago
if ( bits256_cmp(tp->G.P[i].playerpub,myinfo->myaddr.persistent))
{
tp->priv.myind = i;
char str[65],str2[65]; printf("player.%d (%s) vs persistent.(%s) myind.%d\n",i,bits256_str(str,tp->G.P[i].playerpub),bits256_str(str2,myinfo->myaddr.persistent),tp->priv.myind );
}
9 years ago
}
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);
9 years ago
hand->othercardpubs[tp->priv.myind] = hand->checkprod;
9 years ago
datalen = (tp->G.numcards + 1 + n) * sizeof(bits256);
pangea_sendcmd(myinfo,tp,"newhand",-1,hand->cardpubs[0].bytes,datalen,n,n);
9 years ago
printf("host sends NEWDECK checkprod.%llx numhands.%d\n",(long long)hand->checkprod.txid,tp->numhands);
9 years ago
{
bits256 checkprod; char str[65],str2[65];
checkprod = cards777_pubkeys(hand->cardpubs,tp->G.numcards,hand->cardpubs[tp->G.numcards]);
if ( bits256_cmp(checkprod,hand->checkprod) != 0 )
printf("checkprod err.(%s) != (%s)\n",bits256_str(str,checkprod),bits256_str(str2,hand->checkprod));
for (i=0; i<tp->G.numcards; i++)
printf("%d: %s\n",i,bits256_str(str,hand->cardpubs[i]));
printf("cardpubs.(%s)\n",bits256_str(str,hand->cardpubs[tp->G.numcards]));
}
9 years ago
pangea_queuestate(tp,PANGEA_GOTDECKS,PANGEA_GOTDECKS);
9 years ago
return(0);
}
void pangea_newhand(PANGEA_HANDARGS)
{
9 years ago
int32_t i,handid,numcards,n,ind; struct hand_info *hand; bits256 *pubkeys; char str[65],str2[65];
9 years ago
hand = &tp->hand;
numcards = tp->G.numcards;
9 years ago
if ( data == 0 || datalen != (numcards + 1 + tp->G.numactive) * sizeof(bits256) )
9 years ago
{
PNACL_message("pangea_newhand invalid datalen.%d vs %ld\n",datalen,(long)((numcards + 1) * sizeof(bits256)));
return;
}
pubkeys = (bits256 *)data;
9 years ago
n = turni;
9 years ago
tp->priv.myind = -1;
9 years ago
tp->priv.mypriv = myinfo->persistent_priv, tp->priv.mypub = myinfo->myaddr.persistent;
tp->G.M = (tp->G.numactive >> 1) + 1;
9 years ago
for (i=0; i<n; i++)
{
9 years ago
if ( (ind= pangea_Pind(tp,pubkeys[numcards + 1 + i])) >= 0 && ind > i )
9 years ago
{
9 years ago
tp->G.P[i] = tp->G.P[ind];
printf("init player[%d] with.%d\n",i,ind);
}
9 years ago
ind = i;
tp->G.P[ind].playerpub = pubkeys[numcards + 1 + i];
tp->G.P[ind].nxt64bits = acct777_nxt64bits(pubkeys[numcards + 1 + i]);
9 years ago
tp->active[i] = &tp->G.P[ind];
if ( i == 0 )
hand->button = ind;
9 years ago
if ( bits256_cmp(tp->G.P[ind].playerpub,myinfo->myaddr.persistent))
9 years ago
{
9 years ago
tp->priv.myind = i;
9 years ago
printf("player.%d (%s) vs persistent.(%s) myind.%d\n",i,bits256_str(str,tp->G.P[ind].playerpub),bits256_str(str2,myinfo->myaddr.persistent),tp->priv.myind );
}
9 years ago
}
9 years ago
hand->startdecktime = (uint32_t)time(NULL);//pm->sig.timestamp;
9 years ago
memcpy(hand->cardpubs,pubkeys,(numcards +1 + tp->G.numactive) * sizeof(bits256));
9 years ago
PNACL_message("player.%d NEWHAND.%llx received numhands.%d button.%d cardi.%d | N %d numactive.%d\n",tp->priv.myind,(long long)hand->cardpubs[numcards].txid,tp->numhands,hand->button,hand->cardi,tp->G.N,n);
9 years ago
//printf("check.%s\n",bits256_str(str,hand->cardpubs[numcards]));
9 years ago
hand->checkprod = cards777_pubkeys(hand->cardpubs,numcards,hand->cardpubs[numcards]);
9 years ago
//printf("B check.%s\n",bits256_str(str,hand->checkprod));
//printf("P0.%s\n",bits256_str(str,hand->cardpubs[numcards+1]));
//printf("P1.%s\n",bits256_str(str,hand->cardpubs[numcards+2]));
9 years ago
if ( bits256_cmp(hand->checkprod,hand->cardpubs[numcards]) != 0 )
{
9 years ago
for (i=0; i<tp->G.numcards; i++)
printf("%d: %s\n",i,bits256_str(str,hand->cardpubs[i]));
9 years ago
printf("checkprod mismatch myind.%d %s\n",tp->priv.myind,bits256_str(str,hand->cardpubs[i]));
9 years ago
return;
}
9 years ago
if ( tp->priv.myind >= 0 )
{
hand->othercardpubs[tp->priv.myind] = hand->checkprod;
tp->G.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));
9 years ago
pangea_sendcmd(myinfo,tp,"gothand",-1,hand->checkprod.bytes,sizeof(bits256),hand->cardi,hand->button);
printf("sent gotdeck\n");
9 years ago
}
9 years ago
}
9 years ago
int32_t pangea_checkstart(struct supernet_info *myinfo,struct table_info *tp)
9 years ago
{
9 years ago
int32_t i,matches = 0; struct hand_info *hand = &tp->hand;
9 years ago
if ( bits256_nonz(hand->checkprod) > 0 && hand->encodestarted == 0 )
{
9 years ago
for (i=0; i<tp->G.numactive; i++)
9 years ago
{
9 years ago
if ( bits256_cmp(hand->othercardpubs[i],hand->checkprod) == 0 )
matches++;
char str[65],str2[65]; printf("matches.%d (%s vs %s)\n",matches,bits256_str(str,hand->othercardpubs[i]),bits256_str(str2,hand->checkprod));
9 years ago
}
9 years ago
if ( matches == tp->G.numactive )
9 years ago
{
9 years ago
if ( tp->priv.myind == pangea_slotA(tp) )
9 years ago
{
9 years ago
//if ( PANGEA_PAUSE > 0 )
// sleep(PANGEA_PAUSE);
9 years ago
hand->encodestarted = (uint32_t)time(NULL);
9 years ago
tp->hand.sentencoded |= (1 << tp->priv.myind);
9 years ago
pangea_queuestate(tp,PANGEA_GOTDECKS,PANGEA_GOTFINAL);
9 years ago
PNACL_message("start encoded %llx destplayer.%d vs myind.%d\n",(long long)hand->checkprod.txid,pangea_slotB(tp),tp->priv.myind);
pangea_sendcmd(myinfo,tp,"encoded",pangea_slotB(tp),tp->priv.outcards[0].bytes,sizeof(bits256) * tp->G.numactive * tp->G.numcards,tp->G.numactive*tp->G.numcards,-1);
9 years ago
return(matches);
9 years ago
}
9 years ago
} else printf("i.%d != numactive.%d\n",matches,tp->G.numactive);
9 years ago
} else printf("zero checkprod or encodestarted.%u\n",hand->encodestarted);
return(-1);
9 years ago
}
9 years ago
void pangea_gothand(PANGEA_HANDARGS)
9 years ago
{
9 years ago
int32_t i; uint64_t total = 0;
9 years ago
printf("P%d: gothand from p%d\n",tp->priv.myind,senderind);
9 years ago
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));
9 years ago
PNACL_message("player.%d pangea_gotdeck from P.%d otherpubs.%llx\n",tp->priv.myind,senderind,(long long)tp->hand.othercardpubs[senderind].txid);
9 years ago
}
9 years ago
pangea_checkstart(myinfo,tp);
9 years ago
}
9 years ago
void pangea_sentencoded(PANGEA_HANDARGS)
{
9 years ago
tp->hand.sentencoded |= (1 << senderind);
printf("P%d: got sentencoded from %d\n",tp->priv.myind,senderind);
9 years ago
}
void pangea_gotfinal(PANGEA_HANDARGS)
{
9 years ago
tp->hand.gotfinal |= (1 << senderind);
printf("P%d: gotfinal from %d\n",tp->priv.myind,senderind);
9 years ago
}
9 years ago
void pangea_encoded(PANGEA_HANDARGS)
{
9 years ago
bits256 audit[CARDS777_MAXPLAYERS]; int32_t i,iter;
9 years ago
struct hand_info *hand = &tp->hand;
9 years ago
printf("pangea_encoded\n");
9 years ago
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;
}
9 years ago
hand->encodestarted = (uint32_t)time(NULL);//pm->sig.timestamp;
9 years ago
cards777_encode(myinfo,tp->priv.outcards,tp->priv.xoverz,tp->priv.allshares,tp->priv.myshares,hand->sharenrs[tp->priv.myind],tp->G.M,(void *)data,tp->G.numcards,N);
9 years ago
PNACL_message("player.%d ind.%d encodes into %p %llx -> %llx next.%d N %d\n",tp->priv.myind,tp->priv.myind,tp->priv.outcards,(long long)*(uint64_t *)data,(long long)tp->priv.outcards[0].txid,pangea_nextnode(tp),N);
if ( tp->priv.myind > 0 )
9 years ago
{
9 years ago
if ( tp->priv.myind < tp->G.numactive-1 )
9 years ago
{
//PNACL_message("send encoded\n");
pangea_sendcmd(myinfo,tp,"encoded",pangea_nextnode(tp),tp->priv.outcards[0].bytes,datalen,N*tp->G.numcards,-1);
9 years ago
pangea_sendcmd(myinfo,tp,"sentencoded",-1,0,0,tp->priv.myind,pangea_nextnode(tp));
9 years ago
}
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);
}
9 years ago
PNACL_message("send preflop %ld\n",(long)((2 * N) * (N * N * sizeof(bits256))));
9 years ago
pangea_preflop(myinfo,N,turni,cardi,destplayer,senderind,tp,tp->priv.audits[0].bytes,(2 * N) * (N * N * sizeof(bits256)));
9 years ago
}
}
}
void pangea_final(PANGEA_HANDARGS)
{
9 years ago
if ( data == 0 || datalen != (tp->G.numcards * tp->G.numactive) * sizeof(bits256) )
9 years ago
{
9 years ago
PNACL_message("pangea_final invalid datalen.%d vs %ld\n",datalen,(long)((tp->G.numcards * tp->G.numactive) * sizeof(bits256)));
9 years ago
return;
}
if ( Debuglevel > 2 )
9 years ago
PNACL_message("player.%d final into %p\n",tp->priv.myind,tp->priv.outcards);
9 years ago
memcpy(tp->hand.final,data,sizeof(bits256) * tp->G.numactive * tp->G.numcards);
9 years ago
pangea_sendcmd(myinfo,tp,"gotfinal",-1,0,0,tp->priv.myind,tp->priv.myind);
}
9 years ago
int32_t pangea_queueprocess(struct supernet_info *myinfo,struct table_info *tp)
9 years ago
{
int32_t iter,retval,flag = 0; double diff; struct pangea_queueitem *ptr;
9 years ago
//char str[65]; printf("queueprocess.(%s)\n",bits256_str(str,tp->G.tablehash));
9 years ago
for (iter=0; iter<2; iter++)
{
while ( (ptr= queue_dequeue(&tp->stateQ[iter],0)) != 0 )
{
retval = 0;
diff = tai_diff(ptr->last,tai_now());
if ( diff > 10000 )
{
printf("its been over 10 seconds %.3f no state.%d yet\n",diff,ptr->waitevent);
}
switch ( ptr->waitevent )
{
case PANGEA_GOTDECKS:
9 years ago
if ( pangea_checkstart(myinfo,tp) > 0 )
9 years ago
return(1);
break;
case PANGEA_GOTFINAL:
9 years ago
//printf("sentencoded.%x, waiting for gotfinal\n",tp->hand.sentencoded);
9 years ago
break;
}
if ( retval != 0 )
{
flag++;
free(ptr);
}
else
{
ptr->last = tai_now();
queue_enqueue("stateQ",&tp->stateQ[iter ^ 1],&ptr->DL,0);
}
}
}
return(flag);
9 years ago
}
9 years ago
void pangea_queues(struct supernet_info *myinfo)
{
struct gecko_chain *cat,*subchain,*tmp; //struct table_info *tp;
9 years ago
pangea_update(myinfo);
if ( (cat= category_find(calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY)) != 0 )
{
9 years ago
HASH_ITER(hh,cat->subchains,subchain,tmp)
9 years ago
{
9 years ago
printf("undeprecate\n");
//if ( (tp= sub->info) != 0 )
// pangea_queueprocess(myinfo,tp);
9 years ago
}
}
}
9 years ago
void pangea_preflop(PANGEA_HANDARGS)
{
9 years ago
int32_t i,iter,maxlen; bits256 audit[CARDS777_MAXPLAYERS];
9 years ago
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;
}
9 years ago
PNACL_message("preflop player.%d\n",tp->priv.myind);
9 years ago
memcpy(tp->priv.audits,data,datalen);
9 years ago
if ( tp->priv.myind != pangea_slotA(tp) && tp->priv.myind != pangea_slotB(tp) )
9 years ago
{
//for (i=0; i<tp->G.numcards*N; i++)
// PNACL_message("%llx ",(long long)tp->priv.outcards[i].txid);
9 years ago
PNACL_message("player.%d outcards\n",tp->priv.myind);
9 years ago
for (cardi=0; cardi<N*2; cardi++)
for (destplayer=0; destplayer<N; destplayer++)
{
pangea_rwaudit(0,audit,tp->priv.audits,cardi,destplayer,N);
9 years ago
//if ( 1 && (card= cards777_checkcard(&cardpriv,cardi,tp->priv.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->priv.myind,card);
audit[0] = cards777_decode(&audit[tp->priv.myind],tp->priv.xoverz,destplayer,audit[0],tp->priv.outcards,tp->G.numcards,N);
9 years ago
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
{
9 years ago
PNACL_message("P%d sendout cards\n",tp->priv.myind);
9 years ago
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);
9 years ago
audit[0] = cards777_decode(&audit[tp->priv.myind],tp->priv.xoverz,destplayer,audit[0],tp->priv.outcards,tp->G.numcards,N);
9 years ago
pangea_rwaudit(1,audit,tp->priv.audits,cardi,destplayer,N);
9 years ago
//PNACL_message("[%llx + %llx] ",*(long long *)&audit[0],(long long)&audit[tp->priv.myind]);
if ( destplayer == tp->priv.myind )
9 years ago
{
printf("send card to myself\n");
9 years ago
// pangea_card(myinfo,N,turni,cardi,destplayer,tp->priv.myind,tp,audit[0].bytes,sizeof(bits256)*N);
9 years ago
}
9 years ago
// else
pangea_sendcmd(myinfo,tp,"card",destplayer,audit[0].bytes,sizeof(bits256)*N,cardi,-1);
9 years ago
}
}
}
void pangea_card(PANGEA_HANDARGS)
{
9 years ago
struct hand_info *hand; int32_t card,selector,validcard = -1;
9 years ago
bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; char cardAstr[8],cardBstr[8]; struct player_info *destp;
9 years ago
hand = &tp->hand;
9 years ago
destp = tp->active[destplayer];
9 years ago
if ( N <= 1 || data == 0 || datalen != sizeof(bits256)*N || destp == 0 || destplayer < 0 )
9 years ago
{
9 years ago
PNACL_message("pangea_card invalid datalen.%d vs %ld destplayer.%d destp.%p\n",datalen,(long)sizeof(bits256)*N,destplayer,destp);
9 years ago
return;
}
pangea_rwaudit(1,(void *)data,tp->priv.audits,cardi,destplayer,N);
pangea_rwaudit(0,audit,tp->priv.audits,cardi,destplayer,N);
9 years ago
PNACL_message("pangea_card.%d destplayer.%d [%llx]\n",cardi,destplayer,(long long)audit[0].txid);
if ( (card= cards777_checkcard(&cardpriv,cardi,tp->priv.myind,destplayer,myinfo->persistent_priv,hand->cardpubs,tp->G.numcards,audit[0])) >= 0 )
9 years ago
{
9 years ago
destplayer = tp->priv.myind;
//if ( Debuglevel > 2 )
PNACL_message("player.%d got card.[%d]\n",tp->priv.myind,card);
9 years ago
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 )
9 years ago
PNACL_message("player.%d decoded cardi.%d card.[%02d] but it doesnt validate\n",tp->priv.myind,cardi,card);
} else PNACL_message("ERROR player.%d got no card %llx\n",tp->priv.myind,*(long long *)data);
9 years ago
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)
{
9 years ago
struct player_info *p; int64_t betsize; int32_t i,N = tp->G.numactive;
9 years ago
memset(snapshot,0,N * sizeof(int64_t));
9 years ago
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)
{
9 years ago
uint32_t now,i,N = tp->G.numactive; struct player_info *p; int64_t snapshot[CARDS777_MAXPLAYERS+1];
9 years ago
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)
{
9 years ago
int32_t i,validcard,n = 0; uint64_t havemask; struct player_info *p;
9 years ago
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;
}
9 years ago
validcard = turni;
9 years ago
if ( validcard > 0 )
p->havemask |= (1LL << cardi);
9 years ago
//if ( Debuglevel > 2 )
PNACL_message(" | player.%d sees that destplayer.%d got cardi.%d valid.%d | %llx | n.%d\n",tp->priv.myind,senderind,cardi,validcard,(long long)p->havemask,n);
9 years ago
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++;
}
}
9 years ago
if ( tp->priv.myind == pangea_slotA(tp) && n == N )
9 years ago
pangea_startbets(myinfo,tp,N*2);
}
void pangea_faceup(PANGEA_HANDARGS)
{
9 years ago
int32_t validcard,i; struct hand_info *hand; uint16_t tmp; struct player_info *p,*destp;
hand = &tp->hand;
9 years ago
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;
}
9 years ago
validcard = (turni >= 0);
9 years ago
if ( Debuglevel > 2 || tp->priv.myind == pangea_slotA(tp) )
9 years ago
{
9 years ago
PNACL_message("from.%d -> player.%d COMMUNITY.[%d] cardi.%d valid.%d\n",senderind,tp->priv.myind,data[1],cardi,validcard);
9 years ago
}
9 years ago
PNACL_message("got FACEUP cardi.%d validcard.%d [%d]\n",cardi,validcard,data[1]);
9 years ago
if ( validcard > 0 )
{
tmp = (cardi << 8);
9 years ago
tmp |= (turni & 0xff);
9 years ago
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]);
9 years ago
if ( senderind == tp->priv.myind )
9 years ago
pangea_rank(myinfo,tp,senderind);
9 years ago
if ( tp->priv.myind == pangea_slotA(tp) && cardi >= N*2+2 && cardi < N*2+5 )
9 years ago
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)
{
9 years ago
struct player_info *destp; int64_t snapshot[CARDS777_MAXPLAYERS+1]; struct hand_info *hand = &tp->hand;
9 years ago
destp = tp->active[senderind];
if ( destp == 0 || N <= 1 )
{
PNACL_message("pangea_turn illegal arg\n");
return;
}
9 years ago
//if ( Debuglevel > 2 )
printf("P%d: got turn.%d from %d | cardi.%d summary[%d] crc.%u\n",tp->priv.myind,turni,senderind,cardi,tp->summarysize,calc_crc32(0,tp->summary,tp->summarysize));
9 years ago
destp->turni = turni;
if ( senderind == 0 )
{
hand->cardi = cardi;
hand->betstarted = 1;
hand->undergun = turni;
9 years ago
if ( tp->priv.myind != pangea_slotA(tp) )
9 years ago
{
pangea_checkantes(myinfo,tp);
hand->betsizesnapshot = pangea_snapshot(tp,snapshot);
9 years ago
//printf("player.%d sends confirmturn.%d\n",tp->priv.myind,turni);
9 years ago
pangea_sendcmd(myinfo,tp,"confirm",-1,(void *)snapshot,sizeof(uint64_t)*(N+1),cardi,turni);
}
}
}
void pangea_confirm(PANGEA_HANDARGS)
{
9 years ago
uint32_t starttime; int32_t i; uint64_t betsize=0,amount=0;
9 years ago
int64_t snapshot[CARDS777_MAXPLAYERS+1]; struct player_info *p; struct hand_info *hand;
hand = &tp->hand; p = tp->active[senderind];
if ( p == 0 || N <= 1 || data == 0 )
{
printf("pangea_turn: null data\n");
return;
}
9 years ago
printf("P%d: got confirmturn.%d cardi.%d sender.%d\n",tp->priv.myind,turni,cardi,senderind);
9 years ago
//if ( datalen == sizeof(betsize) )
// memcpy(&betsize,data,sizeof(betsize));
starttime = hand->starttime;
9 years ago
if ( senderind == 0 && tp->priv.myind != pangea_slotA(tp) )
9 years ago
{
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);
9 years ago
if ( tp->priv.myind == pangea_slotA(tp) && i == N )
9 years ago
{
betsize = pangea_snapshot(tp,snapshot);
hand->betsize = hand->betsizesnapshot = betsize;
//if ( Debuglevel > 2 )
9 years ago
printf("player.%d sends confirmturn.%d cardi.%d betsize %.0f\n",tp->priv.myind,hand->undergun,hand->cardi,dstr(betsize));
9 years ago
if ( senderind != 0 )
pangea_sendcmd(myinfo,tp,"confirm",-1,(void *)snapshot,sizeof(*snapshot)*(N+1),hand->cardi,hand->undergun);
}
9 years ago
if ( senderind == 0 && (turni= hand->undergun) == tp->priv.myind && (p= tp->active[senderind]) != 0 )
9 years ago
{
if ( hand->betsize != betsize )
9 years ago
printf("P%d: pangea_turn warning hand.betsize %.8f != betsize %.8f\n",tp->priv.myind,dstr(hand->betsize),dstr(betsize));
9 years ago
//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);
}
9 years ago
if ( tp->priv.myind == pangea_slotA(tp) )
9 years ago
{
char *str = jprint(pangea_tablestatus(myinfo,tp),1);
printf("%s\n",str);
free(str);
}
9 years ago
//pangea_statusprint(dp,priv,tp->priv.myind);
9 years ago
}
}
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;
9 years ago
N = tp->G.numactive, hand = &tp->hand;
9 years ago
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);
}
9 years ago
if ( 0 && tp->priv.myind == activej && tp->priv.automuck == 0 )
9 years ago
{
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)
{
9 years ago
uint32_t now; struct player_info *p; int64_t x,snapshot[CARDS777_MAXPLAYERS + 1]; int32_t action,i,j;
many changes blockexplorer tab: needs to allow to input height, blockhash or txid. also please display images/BTC_blocks.jpg below the text as a w800 x h400 bitmap, which is active using the mouse api for coin management, below the active coins have a form that arbitrary json can be input with an add button to the right that will call &#34;addcoin&#34; API. this way I can test adding new coins dynamically. dont worry if it doesnt work, just as long as it submits the json to the C code. I am pretty sure I need to do some debugging of this peers management is not working for me at all. maybe it is due to bad internet. On initialization you need to read in the confs/BTCD_peers.txt from the native filesystem and save it into the chrome app filesystem. same thing for confs/BTCD_hdrs.txt. But this is only to be done if there isnt already such a file inside chrome. if there is, only do it upon a button invoked by the user. the reason is that the pexe is updating this file with the latest. Maybe it is nice to have an &#34;extract&#34; button that will copy out from the chrome storage into the native filesystem. There is also the manifest issue about localstorage vs chrome.localstorage. not sure what is needed to be done, but certainly a priority to get it so everything works as a chrome app. I know before it was making ramchain files inside the chrome filesystem, so it is probably things the GUI is doing. maybe in the settings tab, which has obsolete stuff that can be removed. anyway, the issue about files existing in the native filesystem -&gt; chrome and optionally extracting them is an issue for the confs files and .html template files used to autogenerate the port7778, maybe other files are affected. i think we need a way to have a list of hardcoded files that are just copied into chrome on startup if they dont exist already (or if possible copy over if the native version is bigger?) and buttons to extract them for debug tab: THREE_STRINGS(SuperNET,encryptjson,passphrase,permanentfile,anything); TWO_STRINGS(SuperNET,decryptjson,passphrase,permanentfile); at the top of page a way to put in passphrase and optional permanentfile along with arbitrary json. The standard form template has no easy way to describe to pass in everything as it is oriented to specific fields. but the encryptjson API saves all the fields, so the arbitrary json from the form needs to be combined at the same level as the &#34;agent&#34;, &#34;method&#34;, etc. I know, not the best, but internally it makes it easier. so {&#34;agent&#34;:&#34;SuperNET&#34;,&#34;method&#34;:&#34;encryptjson&#34;,&#34;passphrase&#34;:&#34;&lt;passphrase&gt;&#34;,&#34; permanentfile&#34;:&#34;&lt;filename&gt;&#34;,&#34;fromform&#34;:&#34;valuefromform&#34;,&#34;fromform2&#34;:&#34;valu efromform2&#34;,...rest of form at top level} then this will save it into a file with crazy number (it is a hash like txid) but given the same passphrase and filename, it will regenerate this hash so you dont actually have to store it, but it helps during debugging. for the filename, we must warn quite strongly to the user that if the file is ever lost or even changed in any way that the data will not be recoverable. also best to not allow the user to specify a file that does not exist. I think at this point chrome app version gets a bit tricky. we could simply push the native file into the chrome storage, but then an attacker who gets access to the computer could just get a list of these files and it really wont be much protection. So that means if a filename is specified, it needs to be copied into the chrome space, then immediately deleted... ok, this seems like not a good approach. let us make it so that the permanentfile option is not available from the chrome app, but only if the native version is running. that way we sidestep the issue of the pexe not having access to the specified file. Speaking of native vs pexe, on the startup page we should have a radio button that allows the user to select which the GUI will talk to. It should default based on a self test to the more likely value, but it is possible that the user wants to use the native version, even if the pexe is running. another thing to have on the startup page is a simple login: THREE_STRINGS(SuperNET,login,passphrase,permanentfile,handle); ZERO_ARGS(SuperNET,logout); ZERO_ARGS(SuperNET,activehandle); the handle is a human readable name that is associated with the passphrase/permanentfile. There can only be one active account (though it will be possible to associate different accounts with tradebots). use the activehandle API to find out who is logged in and the associated addresses and pubkeys The above is not yet tested so if it doesnt work, dont fret, just let me know. Once set the handle can be displayed in various places to let the user know which account is logged in. The standard 12 dictionary word passphrases should be used, but any string can be sent in as the password for Pangea: INT_AND_ARRAY(pangea,host,minplayers,params); ZERO_ARGS(pangea,lobby); HASH_AND_STRING(pangea,join,tablehash,handle); HASH_AND_INT(pangea,buyin,tablehash,numchips); HASH_ARG(pangea,start,tablehash); // by host only HASH_ARG(pangea,status,tablehash); HASH_ARG(pangea,call,tablehash); HASH_ARG(pangea,check,tablehash); HASH_AND_INT(pangea,raise,tablehash,numchips); HASH_AND_INT(pangea,bet,tablehash,numchips); HASH_ARG(pangea,fold,tablehash); HASH_AND_STRING(pangea,mode,tablehash,modestr); HASH_ARG(pangea,history,tablehash); HASH_AND_INT(pangea,handhistory,tablehash,hand); The first thing that is done is a &#34;host&#34; by any node. the &#34;params&#34; should be an arbitrary json (like encryptjson) as it needs to be at the top level and it has quite a few different parameters still subject to change. The lobby API will just display all the hosted tables. once a table exists, players can join and then buyin. the buyin is denominated in chips, each chip&#39;s value is determined by the host&#39;s initial parameters. once there are enough players joined with adequate buyin&#39;s verified, the host will be able to do a start. if done before it will (eventually) give an error. for now it will just proceed. The host and players that have joined a tablehash, need to do regular status calls to see if the game has started. Probably just once per 5 or even 10 seconds is fine before the start. Once the game starts (the status will have this info) then once per second polling is needed. Then when it is your turn (as indicated by status) you need to do one of the 5 actions (fold, call, check, raise, bet). do not worry if you dont understand what all these do, just allow the user to do any of these. I guess it is possible to submit it ahead of time. I will support internally remembering the most recent action done prior to it being your turn. once it is your turn and an action is sent to the table, it is too late to change. The last API calls are for getting handhistory where hand is 0 to N-1, being the numbering of the hands played at that table. if just history, all the history for all hands at the table is coming back, so it could be quite big. probably I will make it a summary, but for the GUI just display the returned values. the mode is to change some poker specific modes, so just allow there to be a string entered. do not worry about understanding the pokerness of the API, just the overall flow: host -&gt; creates, join/buyin -&gt; fills up player slots, start -&gt; starts the game status -&gt; to determine when the game starts (or if it is cancelled) and once started actions -&gt; game specific but basically just (button + arg) that is the user input results are via status for current game and history for past ones please try to do the above logic in a generic way so it can be reused for other games. The basic flow should be the same for almost all multiplayer turn based games and even for multiplayer realtime games For InstantDEX: on the apikeypair/userid there needs to be two modes. one for when there is no stored apikey and the current form is fine, just need to make it wider as most apikeys are quite long. Now once there is an apikey saved all that is needed is the passphrase to unlock it. So here is where the encrptjson/decryptjson is used. When saving the apikey for the first time, it can be: a) not saved -&gt; nothing extra to do b) saved without password -&gt; you can just save to a file and use it to load it back in. use confs dir confs/instantdex.exchange.api or something like that c) saved with password (optional filename for native) -&gt; probably best to save in the confs dir to indicate that there is an encrypted file for this, so just that and not the actual passphrase in the file with the above, when the exchange is selected, you can see if the confs file exists and if it has the plaintext, just populate the field, if not, then indicate that a passphrase is needed. if the user provides the passphrase, then decryptjson and populate the fields and autosubmit. A special case is to encrypt the apikeys with the passphrase used when logging in. This is only available if the checkbox to &#34;remember passphrase during session&#34; is set on the main iguana login screen. (i forgot to mention that checkbox!) So the login passphrase is stored in memory, then the GUI simply uses that + encryptjson for storing/decrypting. I would imagine that storing in the confs file that it is encrypted using &#34;handle&#34;&#39;s account login might be a good way to differentiate between this mode of password usage. OK, so we now have the insecure plaintext, the decent using handle&#39;s passphrase and paranoid different passphrase for each exchange (with additional permanentfile for native versions) &#34;SUPPORT&#34; -&gt; &#34;SUPPORTS&#34; just a typo and &#34;allpairs&#34; API is missing from the selection Might as well add a &#34;tradebots&#34; tab: THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission); STRING_AND_DOUBLE(tradebot,monitorall,exchange,commission); THREE_STRINGS(tradebot,unmonitor,exchange,base,rel); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,accumulate,exchange,base,rel,pr ice,volume,duration); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,divest,exchange,base,rel,price, volume,duration); STRING_ARG(tradebot,activebots,exchange); TWO_STRINGS(tradebot,status,exchange,botid); TWO_STRINGS(tradebot,pause,exchange,botid); TWO_STRINGS(tradebot,stop,exchange,botid); TWO_STRINGS(tradebot,resume,exchange,botid); the above are API for exchange specific bots, most should be self-explanatory. bots are created via &#34;accumulate&#34; or &#34;divest&#34; API call. it returns botid. once created, you can do status, pause, stop, resume to a botid. and an activebots API call lists all the active bots for an exchange. duration is in seconds the &#34;monitor&#34; API starts background monitoring of a specific base/rel, &#34;unmonitor&#34; stops this. &#34;monitorall&#34; just does a monitor to the entire list of &#34;allpairs&#34; for that exchange. Keep in mind that doing a monitorall will not add load to an exchange as the request to each exchange is governed by pollgap, but if you have 3 things monitored, it will take 3*pollgap + time each one takes to execute. and if N are monitored it is N*pollgap + time of each, with the &#34;time of each&#34; possibly taking a very long time. And one final request for today: Bitmap tab. It should be an active bitmap using mouse api. either a dropdown to select the bitmap or a form entry. then the rest of the page (resize the bitmap to the page size) being the active bitmap. So on a small screen the bitmap is smaller x/y dimensions and larger on larger screens. plz make sure the proper dimensions are communicated to the pexe via API if it ever is changed. @vineet.bhargav86: I changed the &#34;passphrase&#34; fieldname to &#34;password&#34; for the encryptjson/decryptjson related API. The reason is that the password is like a wallet password and is only local, so it doesnt need to be as high entropy as passphrase. I also added a field to the login API as I realized that the 12 word &#34;passphrase&#34; is the payload and usually wont be sent in: FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase); using &#34;abiglongpassword&#34; for the passphrase -&gt; {&#34;pubkey&#34;:&#34;6c469ba10b40b3eb9d1dba569d7f929d55a29d8f97cd5425907ef2f38f906 209&#34;,&#34;RS&#34;:&#34;NXT-KGV9-DXX8-TM86-DXR96&#34;,&#34;NXT&#34;:&#34;12834974574569896807&#34;,&#34;btcpu bkey&#34;:&#34;024e7641dc947b211bc30fe3339765258902794687b227121fc217284f9d8503c 8&#34;,&#34;rmd160&#34;:&#34;33453c24914db7b77069b7ea24df44f6be145938&#34;,&#34;BTC&#34;:&#34;15g6QK2dSd iW9ZTQEnnJxKrSph6uP7uU23&#34;,&#34;BTCD&#34;:&#34;RDxHUpuv3TX5DZpbhxmS3rBeaxZW1fvYvC&#34;,&#34;r esult&#34;:&#34;success&#34;,&#34;handle&#34;:&#34;test&#34;,&#34;tag&#34;:&#34;14805226009240621255&#34;} and if you use that to log into NXT, it gives the same address. The BTC and BTCD addresses are all derived from the same privkey so they are all interchangeable with the NXT address. The user can therefore select which coin&#39;s addressing they are most comfortable with I also added an &#34;allin&#34; action API for pangea. all the action API will autocalculate the number of chips if passed in 0 for numchips ***************** security issue ******** please dont use the GET URL method when dealing with passphrase!!! Those URL&#39;s tend to get logged and available in browser histories. so anything dealing with the actual passphrase needs to use the postCall form or POST
9 years ago
bits256 audit[CARDS777_MAXPLAYERS]; struct hand_info *hand; uint8_t tmp; int64_t amount = 0;
9 years ago
hand = &tp->hand;
9 years ago
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;
}
9 years ago
action = cardi;
9 years ago
if ( senderind != hand->undergun )
{
9 years ago
printf("T%d: out of turn action.%d by player.%d (undergun.%d) cardi.%d amount %.8f\n",tp->priv.myind,action,senderind,hand->undergun,cardi,dstr(amount));
9 years ago
return;
}
tmp = senderind;
p->action = action;
many changes blockexplorer tab: needs to allow to input height, blockhash or txid. also please display images/BTC_blocks.jpg below the text as a w800 x h400 bitmap, which is active using the mouse api for coin management, below the active coins have a form that arbitrary json can be input with an add button to the right that will call &#34;addcoin&#34; API. this way I can test adding new coins dynamically. dont worry if it doesnt work, just as long as it submits the json to the C code. I am pretty sure I need to do some debugging of this peers management is not working for me at all. maybe it is due to bad internet. On initialization you need to read in the confs/BTCD_peers.txt from the native filesystem and save it into the chrome app filesystem. same thing for confs/BTCD_hdrs.txt. But this is only to be done if there isnt already such a file inside chrome. if there is, only do it upon a button invoked by the user. the reason is that the pexe is updating this file with the latest. Maybe it is nice to have an &#34;extract&#34; button that will copy out from the chrome storage into the native filesystem. There is also the manifest issue about localstorage vs chrome.localstorage. not sure what is needed to be done, but certainly a priority to get it so everything works as a chrome app. I know before it was making ramchain files inside the chrome filesystem, so it is probably things the GUI is doing. maybe in the settings tab, which has obsolete stuff that can be removed. anyway, the issue about files existing in the native filesystem -&gt; chrome and optionally extracting them is an issue for the confs files and .html template files used to autogenerate the port7778, maybe other files are affected. i think we need a way to have a list of hardcoded files that are just copied into chrome on startup if they dont exist already (or if possible copy over if the native version is bigger?) and buttons to extract them for debug tab: THREE_STRINGS(SuperNET,encryptjson,passphrase,permanentfile,anything); TWO_STRINGS(SuperNET,decryptjson,passphrase,permanentfile); at the top of page a way to put in passphrase and optional permanentfile along with arbitrary json. The standard form template has no easy way to describe to pass in everything as it is oriented to specific fields. but the encryptjson API saves all the fields, so the arbitrary json from the form needs to be combined at the same level as the &#34;agent&#34;, &#34;method&#34;, etc. I know, not the best, but internally it makes it easier. so {&#34;agent&#34;:&#34;SuperNET&#34;,&#34;method&#34;:&#34;encryptjson&#34;,&#34;passphrase&#34;:&#34;&lt;passphrase&gt;&#34;,&#34; permanentfile&#34;:&#34;&lt;filename&gt;&#34;,&#34;fromform&#34;:&#34;valuefromform&#34;,&#34;fromform2&#34;:&#34;valu efromform2&#34;,...rest of form at top level} then this will save it into a file with crazy number (it is a hash like txid) but given the same passphrase and filename, it will regenerate this hash so you dont actually have to store it, but it helps during debugging. for the filename, we must warn quite strongly to the user that if the file is ever lost or even changed in any way that the data will not be recoverable. also best to not allow the user to specify a file that does not exist. I think at this point chrome app version gets a bit tricky. we could simply push the native file into the chrome storage, but then an attacker who gets access to the computer could just get a list of these files and it really wont be much protection. So that means if a filename is specified, it needs to be copied into the chrome space, then immediately deleted... ok, this seems like not a good approach. let us make it so that the permanentfile option is not available from the chrome app, but only if the native version is running. that way we sidestep the issue of the pexe not having access to the specified file. Speaking of native vs pexe, on the startup page we should have a radio button that allows the user to select which the GUI will talk to. It should default based on a self test to the more likely value, but it is possible that the user wants to use the native version, even if the pexe is running. another thing to have on the startup page is a simple login: THREE_STRINGS(SuperNET,login,passphrase,permanentfile,handle); ZERO_ARGS(SuperNET,logout); ZERO_ARGS(SuperNET,activehandle); the handle is a human readable name that is associated with the passphrase/permanentfile. There can only be one active account (though it will be possible to associate different accounts with tradebots). use the activehandle API to find out who is logged in and the associated addresses and pubkeys The above is not yet tested so if it doesnt work, dont fret, just let me know. Once set the handle can be displayed in various places to let the user know which account is logged in. The standard 12 dictionary word passphrases should be used, but any string can be sent in as the password for Pangea: INT_AND_ARRAY(pangea,host,minplayers,params); ZERO_ARGS(pangea,lobby); HASH_AND_STRING(pangea,join,tablehash,handle); HASH_AND_INT(pangea,buyin,tablehash,numchips); HASH_ARG(pangea,start,tablehash); // by host only HASH_ARG(pangea,status,tablehash); HASH_ARG(pangea,call,tablehash); HASH_ARG(pangea,check,tablehash); HASH_AND_INT(pangea,raise,tablehash,numchips); HASH_AND_INT(pangea,bet,tablehash,numchips); HASH_ARG(pangea,fold,tablehash); HASH_AND_STRING(pangea,mode,tablehash,modestr); HASH_ARG(pangea,history,tablehash); HASH_AND_INT(pangea,handhistory,tablehash,hand); The first thing that is done is a &#34;host&#34; by any node. the &#34;params&#34; should be an arbitrary json (like encryptjson) as it needs to be at the top level and it has quite a few different parameters still subject to change. The lobby API will just display all the hosted tables. once a table exists, players can join and then buyin. the buyin is denominated in chips, each chip&#39;s value is determined by the host&#39;s initial parameters. once there are enough players joined with adequate buyin&#39;s verified, the host will be able to do a start. if done before it will (eventually) give an error. for now it will just proceed. The host and players that have joined a tablehash, need to do regular status calls to see if the game has started. Probably just once per 5 or even 10 seconds is fine before the start. Once the game starts (the status will have this info) then once per second polling is needed. Then when it is your turn (as indicated by status) you need to do one of the 5 actions (fold, call, check, raise, bet). do not worry if you dont understand what all these do, just allow the user to do any of these. I guess it is possible to submit it ahead of time. I will support internally remembering the most recent action done prior to it being your turn. once it is your turn and an action is sent to the table, it is too late to change. The last API calls are for getting handhistory where hand is 0 to N-1, being the numbering of the hands played at that table. if just history, all the history for all hands at the table is coming back, so it could be quite big. probably I will make it a summary, but for the GUI just display the returned values. the mode is to change some poker specific modes, so just allow there to be a string entered. do not worry about understanding the pokerness of the API, just the overall flow: host -&gt; creates, join/buyin -&gt; fills up player slots, start -&gt; starts the game status -&gt; to determine when the game starts (or if it is cancelled) and once started actions -&gt; game specific but basically just (button + arg) that is the user input results are via status for current game and history for past ones please try to do the above logic in a generic way so it can be reused for other games. The basic flow should be the same for almost all multiplayer turn based games and even for multiplayer realtime games For InstantDEX: on the apikeypair/userid there needs to be two modes. one for when there is no stored apikey and the current form is fine, just need to make it wider as most apikeys are quite long. Now once there is an apikey saved all that is needed is the passphrase to unlock it. So here is where the encrptjson/decryptjson is used. When saving the apikey for the first time, it can be: a) not saved -&gt; nothing extra to do b) saved without password -&gt; you can just save to a file and use it to load it back in. use confs dir confs/instantdex.exchange.api or something like that c) saved with password (optional filename for native) -&gt; probably best to save in the confs dir to indicate that there is an encrypted file for this, so just that and not the actual passphrase in the file with the above, when the exchange is selected, you can see if the confs file exists and if it has the plaintext, just populate the field, if not, then indicate that a passphrase is needed. if the user provides the passphrase, then decryptjson and populate the fields and autosubmit. A special case is to encrypt the apikeys with the passphrase used when logging in. This is only available if the checkbox to &#34;remember passphrase during session&#34; is set on the main iguana login screen. (i forgot to mention that checkbox!) So the login passphrase is stored in memory, then the GUI simply uses that + encryptjson for storing/decrypting. I would imagine that storing in the confs file that it is encrypted using &#34;handle&#34;&#39;s account login might be a good way to differentiate between this mode of password usage. OK, so we now have the insecure plaintext, the decent using handle&#39;s passphrase and paranoid different passphrase for each exchange (with additional permanentfile for native versions) &#34;SUPPORT&#34; -&gt; &#34;SUPPORTS&#34; just a typo and &#34;allpairs&#34; API is missing from the selection Might as well add a &#34;tradebots&#34; tab: THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission); STRING_AND_DOUBLE(tradebot,monitorall,exchange,commission); THREE_STRINGS(tradebot,unmonitor,exchange,base,rel); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,accumulate,exchange,base,rel,pr ice,volume,duration); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,divest,exchange,base,rel,price, volume,duration); STRING_ARG(tradebot,activebots,exchange); TWO_STRINGS(tradebot,status,exchange,botid); TWO_STRINGS(tradebot,pause,exchange,botid); TWO_STRINGS(tradebot,stop,exchange,botid); TWO_STRINGS(tradebot,resume,exchange,botid); the above are API for exchange specific bots, most should be self-explanatory. bots are created via &#34;accumulate&#34; or &#34;divest&#34; API call. it returns botid. once created, you can do status, pause, stop, resume to a botid. and an activebots API call lists all the active bots for an exchange. duration is in seconds the &#34;monitor&#34; API starts background monitoring of a specific base/rel, &#34;unmonitor&#34; stops this. &#34;monitorall&#34; just does a monitor to the entire list of &#34;allpairs&#34; for that exchange. Keep in mind that doing a monitorall will not add load to an exchange as the request to each exchange is governed by pollgap, but if you have 3 things monitored, it will take 3*pollgap + time each one takes to execute. and if N are monitored it is N*pollgap + time of each, with the &#34;time of each&#34; possibly taking a very long time. And one final request for today: Bitmap tab. It should be an active bitmap using mouse api. either a dropdown to select the bitmap or a form entry. then the rest of the page (resize the bitmap to the page size) being the active bitmap. So on a small screen the bitmap is smaller x/y dimensions and larger on larger screens. plz make sure the proper dimensions are communicated to the pexe via API if it ever is changed. @vineet.bhargav86: I changed the &#34;passphrase&#34; fieldname to &#34;password&#34; for the encryptjson/decryptjson related API. The reason is that the password is like a wallet password and is only local, so it doesnt need to be as high entropy as passphrase. I also added a field to the login API as I realized that the 12 word &#34;passphrase&#34; is the payload and usually wont be sent in: FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase); using &#34;abiglongpassword&#34; for the passphrase -&gt; {&#34;pubkey&#34;:&#34;6c469ba10b40b3eb9d1dba569d7f929d55a29d8f97cd5425907ef2f38f906 209&#34;,&#34;RS&#34;:&#34;NXT-KGV9-DXX8-TM86-DXR96&#34;,&#34;NXT&#34;:&#34;12834974574569896807&#34;,&#34;btcpu bkey&#34;:&#34;024e7641dc947b211bc30fe3339765258902794687b227121fc217284f9d8503c 8&#34;,&#34;rmd160&#34;:&#34;33453c24914db7b77069b7ea24df44f6be145938&#34;,&#34;BTC&#34;:&#34;15g6QK2dSd iW9ZTQEnnJxKrSph6uP7uU23&#34;,&#34;BTCD&#34;:&#34;RDxHUpuv3TX5DZpbhxmS3rBeaxZW1fvYvC&#34;,&#34;r esult&#34;:&#34;success&#34;,&#34;handle&#34;:&#34;test&#34;,&#34;tag&#34;:&#34;14805226009240621255&#34;} and if you use that to log into NXT, it gives the same address. The BTC and BTCD addresses are all derived from the same privkey so they are all interchangeable with the NXT address. The user can therefore select which coin&#39;s addressing they are most comfortable with I also added an &#34;allin&#34; action API for pangea. all the action API will autocalculate the number of chips if passed in 0 for numchips ***************** security issue ******** please dont use the GET URL method when dealing with passphrase!!! Those URL&#39;s tend to get logged and available in browser histories. so anything dealing with the actual passphrase needs to use the postCall form or POST
9 years ago
p->actualaction = pangea_playerbet(myinfo,&p->actualbet,tp,tp->active[senderind],amount,CARDS777_CHECK);
9 years ago
hand->undergun = (hand->undergun + 1) % N;
hand->numactions++;
9 years ago
//if ( Debuglevel > 2 )//|| tp->priv.myind == 0 )
printf("player.%d: got action.%d cardi.%d senderind.%d -> undergun.%d numactions.%d\n",tp->priv.myind,action,cardi,senderind,hand->undergun,hand->numactions);
9 years ago
if ( pangea_lastman(myinfo,tp) > 0 )
return;
9 years ago
if ( tp->priv.myind == pangea_slotA(tp) )
9 years ago
{
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 )
{
9 years ago
//printf("T%d: senderind.%d i.%d j.%d -> undergun.%d numactions.%d\n",tp->priv.myind,senderind,i,j,hand->undergun,hand->numactions);
9 years ago
//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);
}
}
}
9 years ago
if ( Debuglevel > 2 )// || tp->priv.myind == 0 )
9 years ago
{
char *str = jprint(pangea_tablestatus(myinfo,tp),1);
9 years ago
printf("player.%d got pangea_action.%d for player.%d action.%d amount %.8f | numactions.%d\n%s\n",tp->priv.myind,cardi,senderind,action,dstr(amount),hand->numactions,str);
9 years ago
free(str);
}
}
void pangea_decoded(PANGEA_HANDARGS)
{
9 years ago
int32_t card; bits256 cardpriv,audit[CARDS777_MAXPLAYERS]; struct hand_info *hand;
hand = &tp->hand;
9 years ago
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);
9 years ago
if ( turni == tp->priv.myind )
9 years ago
{
9 years ago
if ( tp->priv.myind != pangea_slotA(tp) )
9 years ago
{
9 years ago
audit[0] = cards777_decode(&audit[tp->priv.myind],tp->priv.xoverz,destplayer,audit[0],tp->priv.outcards,tp->G.numcards,N);
9 years ago
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
{
9 years ago
if ( (card= cards777_checkcard(&cardpriv,cardi,tp->priv.myind,tp->priv.myind,tp->priv.mypriv,hand->cardpubs,tp->G.numcards,audit[0])) >= 0 )
9 years ago
{
if ( cards777_validate(cardpriv,hand->final[cardi*N + destplayer],hand->cardpubs,tp->G.numcards,audit,N,tp->priv.mypub) < 0 )
9 years ago
PNACL_message("player.%d decoded cardi.%d card.[%d] but it doesnt validate\n",tp->priv.myind,cardi,card);
9 years ago
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)
{
9 years ago
struct player_info *p; int32_t i,myind; struct hand_info *hand; uint64_t amount=0;
hand = &tp->hand;
9 years ago
myind = tp->priv.myind;
if ( (p= tp->active[myind]) == 0 )
{
printf("error nullp myind.%d\n",myind);
return;
}
9 years ago
//if ( Debuglevel > 2 )
9 years ago
printf("P%d: showdown from sender.%d\n",myind,senderind);
9 years ago
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;
9 years ago
if ( myind == pangea_slotA(tp) && senderind != 0 )
9 years ago
{
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;
}
9 years ago
printf("senderind.%d host sends showdown for undergun.%d\n",senderind,hand->undergun);
9 years ago
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);
}