示例#1
0
// check *any* packet for account auth information, then
account_entry_t * check_auth_packet(packet_head_t *p) {
    assert(p->pkt_type == AUTH);

    return get_account(p->card_id, p->auth_code);


}
示例#2
0
// come back with a fin response
pack_and_data_t *process_client_fin(pack_and_data_t *pin) {
    packet_head_t *fin_pkt = pin->ph;
    uint32_t cid = fin_pkt->card_id;
    uint32_t acd =  fin_pkt->auth_code;
    uint32_t txn_id = fin_pkt->transaction_id;
    account_entry_t * ae = get_account(cid, acd);

    if(ae == NULL) {
        ERRNO = ERRNO_MP_NOT_FOUND;
        return NULL;
    }

    txn_entry_t * te = get_transaction(ae, txn_id);
    if(te == NULL) {
        // err no set by get_txn
        return NULL;
    }


    if(finalize_transaction(te) != OK) {
        // finalize transaction sets huge errno for double fin
        return NULL;
    }



    return create_basic_response(cid, acd, txn_id, FIN, fin_pkt->op_code, OK, 0);

}
示例#3
0
acct_txn_entry_t * get_acct_txn_reg(uint32_t cid, uint32_t acd, uint32_t txn_id) {

    account_entry_t * ae = get_account(cid, acd);



    if(ae == NULL) {
        ERRNO = ERRNO_MP_NOT_FOUND;
        return NULL;
    }

    txn_entry_t * te = get_transaction(ae, txn_id);
    if(te == NULL) {
        ERRNO = ERRNO_MP_NOT_FOUND;
        return NULL;
    }

    acct_txn_entry_t *aet = (acct_txn_entry_t *) malloc(sizeof(acct_txn_entry_t));
    if(aet == NULL) {
        ERRNO = ERRNO_MP_ALLOC;
        return NULL;
    }
    aet->ae = ae;
    aet->txn = te;

    return aet;


};
示例#4
0
pack_and_data_t * generate_new_init_and_init_resp(pack_and_data_t *pin) {
    packet_head_t *ip = pin->ph;
    packet_data_balance_t *b = pin->data;

    if(b == NULL) {

        return NULL;
    }


    uint32_t cid = register_card_id();
    uint32_t acd = register_auth_code();





    int acct_ok = create_account(cid, acd, b);

    if(acct_ok != OK) {
        return NULL;
    }



    account_entry_t *ae = get_account(cid, acd);
    if(ae == NULL) {
        return NULL;
    }


    open_txn(ae, ip);

    // needed for log entry
    pin->ph->card_id = cid;
    pin->ph->auth_code = acd;
    txn_entry_t * t = add_transaction_log_entry(ae, pin);

    if(t == NULL) {
        return NULL;
    }

    return create_basic_response(cid, acd, ip->transaction_id, INIT, ISSUE, OK, 0);

}
示例#5
0
文件: pyaccount.c 项目: KaSt/nereamud
int PyAccount_init(PyAccount *self, PyObject *args, PyObject *kwds) {
  char *kwlist[] = {"name", NULL};
  char     *name = NULL;

  // get the uid
  if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &name)) {
    PyErr_Format(PyExc_TypeError, "Accounts may only be created using a name");
    return -1;
  }

  // make sure an account with this name exists
  if(!account_exists(name)) {
    PyErr_Format(PyExc_TypeError, "Account with name %s does not exist.", name);
    return -1;
  }

  self->account = get_account(name);
  return 0;
}
示例#6
0
文件: dice.cpp 项目: dwj1979/eos
void apply_offer( const offer_bet& offer ) {
   eos_assert( offer.amount > 0, "insufficient bet" );
   eos_assert( !hasOffer( offer.commitment ), "offer with this commitment already exist" );
   require_auth( offer.player );

   auto acnt = get_account( offer.player );
   acnt.balance -= offer.amount;
   acnt.open_offers++;
   save( acnt );

   /**
    *  1. Lookup lowerbound on offer's by offer_primary_key
    *     if lowerbound.primary.bet == offer.bet
    *          global_dice.nextgameid++  (load and save to DB)
    *          create new game and set game.bet == offer.bet
    *          set player1 == lowerbound player
    *          set player2 == offer.player
    *          update lowerbound.primary.bet = 0 and lwoerbound.gameid = global_dice.nextgameid
    *          Create offer entry in offers table with bet = 0 and gameid == --^
    *     else      
    *          Create offer entry in offers table with bet = offer.bet and gameid = 0
    */
}
示例#7
0
pack_and_data_t * process_client_history(pack_and_data_t *padi, size_t *ds) {
    packet_head_t *cb_hist = padi->ph;
    packet_data_history_t *hist = (packet_data_history_t *) padi->data;
    uint32_t cid = cb_hist->card_id;
    uint32_t acd = cb_hist->auth_code;
    uint32_t txn_id = cb_hist->transaction_id;


    account_entry_t * ae = get_account(cid, acd);
    txn_entry_t * te = add_transaction_log_entry(ae, padi);
    acct_txn_entry_t * aet = get_acct_txn_reg(cid, acd, txn_id);

    if(aet == NULL) {
        return NULL;
    }




    size_t n_transactions = aet->ae->txn_log->n_nodes;
    size_t data_sz =0;
    int i =0;
    if(cb_hist->transaction_id == 0x0002ee11)
        i = 0;

    for(txn_entry_t *txn = transaction_iterator(aet->ae); txn != NULL;
            txn = transaction_iterator(NULL)) {
        if(txn == NULL)
            break;


        if(txn->p->card_id != cid)
            continue;

        data_sz += txn->data_sz;
        if(i >= hist->count) {
            break;
        }
        i += 1;

    }
    if(padi->ph->transaction_id == 223352)
        i = i;

    // complex size calculation takes into account void * space for each txn t

    size_t resp_size =  sizeof(packet_data_history_t) + data_sz + sizeof(transaction_t)*i - sizeof(void *)*i;
    pack_and_data_t *resp = create_basic_response(cid, acd, txn_id, OPS, HISTORY, OK, resp_size);
    if(resp == NULL) {

        return NULL;
    }
    packet_head_t *resp_ph = resp->ph;
    packet_data_history_t *phptr = (packet_data_history_t *) (resp->data);
    resp_ph->op_code = HISTORY;
    transaction_t * txn_ptr = (transaction_t *) (phptr+1);

    size_t hist_ct = 0;
    te->state = OPS;
    size_t final_data_sz =  0;
    for(txn_entry_t *txn = transaction_iterator(aet->ae); txn != NULL;
            txn = transaction_iterator(NULL)) {

        if(txn == NULL)
            break;

        if(txn->p->card_id != cid)
            continue;
        if(hist_ct >= hist->count)
            break;


        txn_ptr->op_code = txn->p->op_code;
        txn_ptr->state = txn->state;

        txn_ptr->status = txn->p->status;
        txn_ptr->card_id = txn->p->card_id;
        txn_ptr->transaction_id = txn->p->transaction_id;


        size_t dss = txn->data_sz;

#if PATCHED
        if(txn->data == NULL)
            _terminate(26);
#endif
        cgc_memcpy(&(txn_ptr->details), txn->data, dss);
        hist_ct += 1;


        // sizeof txn_t already has void ptr which is where we're copying data...
        size_t cp_sz = sizeof(transaction_t) + dss - sizeof(void *);
        final_data_sz += cp_sz;

        txn_ptr =  ((void *) txn_ptr) +cp_sz;




    }


    *ds =  final_data_sz+4;
    resp->pay_data_l = final_data_sz+4;

    phptr->count = i;
    finalize_transaction(te);



    return resp;

}
示例#8
0
文件: socket.c 项目: KaSt/nereamud
/* Recover from a copyover - load players */
void copyover_recover() {     
  CHAR_DATA    *dMob;
  ACCOUNT_DATA *account;
  SOCKET_DATA  *dsock;
  FILE *fp;
  char acct[100];
  char name[100];
  char host[MAX_BUFFER];
  int desc;
      
  log_string("Copyover recovery initiated");

  if ((fp = fopen(COPYOVER_FILE, "r")) == NULL) {  
    log_string("Copyover file not found. Exitting.");
    exit (1);
  }
      
  /* In case something crashes - doesn't prevent reading */
  unlink(COPYOVER_FILE);

  for (;;) {  
    fscanf(fp, "%d %s %s %s\n", &desc, acct, name, host);
    if (desc == -1)
      break;

    // Many thanks to Rhaelar for the help in finding this bug; clear_socket
    // does not like receiving freshly malloc'd data. We have to make sure
    // everything is zeroed before we pass it to clear_socket
    //    dsock = malloc(sizeof(*dsock));
    dsock = calloc(1, sizeof(*dsock));
    clear_socket(dsock, desc);

    dsock->hostname = strdup(host);
    listPut(socket_list, dsock);
    propertyTablePut(sock_table, dsock);

    // load account data
    if((account = get_account(acct)) != NULL)
      socketSetAccount(dsock, account);
    // no luck!
    else {
      close_socket(dsock, FALSE);
      continue;
    }

    // load player data
    if ((dMob = get_player(name)) != NULL) {
      // attach to socket
      charSetSocket(dMob, dsock);
      socketSetChar(dsock, dMob);

      // try putting the character into the game
      // close the socket if we fail.
      if(!try_enter_game(dMob)) {
	// do not bother extracting, since we haven't entered the game yet
	unreference_player(socketGetChar(dsock));
	socketSetChar(dsock, NULL);
	close_socket(dsock, FALSE);
	continue;
      }
    }
    // no luck
    else {
      close_socket(dsock, FALSE);
      continue;
    }
   
    // Write something, and check if it goes error-free
    if (!text_to_socket(dsock, "\n\r <*>  And before you know it, everything has changed  <*>\n\r")) { 
      close_socket(dsock, FALSE);
      continue;
    }
  
    // make sure the socket can be used
    dsock->bust_prompt    =  TRUE;
    dsock->lookup_status  =  TSTATE_DONE;

    // let our modules know we've finished copying over a socket
    hookRun("copyover_complete", hookBuildInfo("sk", dsock));

    // negotiate compression
    text_to_buffer(dsock, (char *) compress_will2);
    text_to_buffer(dsock, (char *) compress_will);
  }
  fclose(fp);

  // now, set all of the sockets' control to the new fSet
  reconnect_copyover_sockets();
}