std::unique_ptr<proto::Bip44Address> Blockchain::LoadAddress( const Identifier& nymID, const Identifier& accountID, const std::uint32_t index, const BIP44Chain chain) const { LOCK_ACCOUNT() std::unique_ptr<proto::Bip44Address> output{}; const std::string sNymID = nymID.str(); const std::string sAccountID = accountID.str(); auto account = load_account(accountLock, sNymID, sAccountID); if (false == bool(account)) { otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist." << std::endl; return output; } const auto allocatedIndex = chain ? account->internalindex() : account->externalindex(); if (index > allocatedIndex) { otErr << OT_METHOD << __FUNCTION__ << ": Address has not been allocated." << std::endl; return output; } auto& address = find_address(index, chain, *account); output.reset(new proto::Bip44Address(address)); return output; }
struct account * account_by_name(char *name) { PGresult *res; int acct_id; // First check to see if we already have it in memory struct account *acct = g_hash_table_find(account_cache, account_name_matches, name); if (acct) return acct; // Apprently, we don't, so look it up on the db res = sql_query("select idnum from accounts where lower(name)='%s'", tmp_sqlescape(tmp_tolower(name))); if (PQntuples(res) != 1) return NULL; acct_id = atoi(PQgetvalue(res, 0, 0)); // Now try to load it CREATE(acct, struct account, 1); if (load_account(acct, acct_id)) return acct; free(acct); return NULL; }
static void populate_user_list(login_dlg *ldlg) { GSList *l; GList *strings = NULL; JamHost *host = ldlg->curhost; JamAccount *acc; gtk_widget_set_sensitive(ldlg->bupdate, JAM_HOST_IS_LJ(ldlg->curhost)); for (l = host->accounts; l != NULL; l = l->next) { strings = g_list_append(strings, (char*)jam_account_get_username(l->data)); } if (strings) gtk_combo_set_popdown_strings(GTK_COMBO(ldlg->cusername), strings); else gtk_list_clear_items(GTK_LIST(GTK_COMBO(ldlg->cusername)->list), 0, -1); if (host->lastaccount) { acc = host->lastaccount; } else if (host->accounts) { acc = host->accounts->data; } else { acc = NULL; } gtk_entry_set_text(GTK_ENTRY(ldlg->eusername), acc ? jam_account_get_username(acc) : ""); load_account(ldlg, acc); }
static void username_changed(GtkWidget *w, login_dlg *ldlg) { JamAccount *acc; acc = jam_host_get_account_by_username(ldlg->curhost, gtk_entry_get_text(GTK_ENTRY(ldlg->eusername)), FALSE); load_account(ldlg, acc); }
std::unique_ptr<proto::Bip44Address> Blockchain::AllocateAddress( const Identifier& nymID, const Identifier& accountID, const std::string& label, const BIP44Chain chain) const { LOCK_ACCOUNT() const std::string sNymID = nymID.str(); const std::string sAccountID = accountID.str(); std::unique_ptr<proto::Bip44Address> output{nullptr}; auto account = load_account(accountLock, sNymID, sAccountID); if (false == bool(account)) { otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist." << std::endl; return output; } const auto& type = account->type(); const auto index = chain ? account->internalindex() : account->externalindex(); if (MAX_INDEX == index) { otErr << OT_METHOD << __FUNCTION__ << ": Account is full." << std::endl; return output; } auto& newAddress = add_address(index, *account, chain); newAddress.set_version(BLOCKCHAIN_VERSION); newAddress.set_index(index); newAddress.set_address(calculate_address(*account, chain, index)); OT_ASSERT(false == newAddress.address().empty()); otErr << OT_METHOD << __FUNCTION__ << ": Address " << newAddress.address() << " allocated." << std::endl; newAddress.set_label(label); const auto saved = api_.Storage().Store(sNymID, type, *account); if (false == saved) { otErr << OT_METHOD << __FUNCTION__ << ": Failed to save account." << std::endl; return output; } output.reset(new proto::Bip44Address(newAddress)); return output; }
bool account_reload(struct account * account) { free(account->name); free(account->password); free(account->email); free(account->creation_addr); free(account->login_addr); g_list_free(account->trusted); account->trusted = NULL; g_list_free(account->chars); account->chars = NULL; g_hash_table_remove(account_cache, GINT_TO_POINTER(account->id)); return load_account(account, account->id); }
struct account * account_by_idnum(int id) { // First check to see if we already have it in memory struct account *acct = g_hash_table_lookup(account_cache, GINT_TO_POINTER(id)); if (acct) return acct; // Apparently, we don't, so look it up on the db CREATE(acct, struct account, 1); if (load_account(acct, id)) return acct; free_account(acct); return NULL; }
bool Blockchain::StoreOutgoing( const Identifier& senderNymID, const Identifier& accountID, const Identifier& recipientContactID, const proto::BlockchainTransaction& transaction) const { LOCK_ACCOUNT() const std::string sNymID = senderNymID.str(); const std::string sAccountID = accountID.str(); auto account = load_account(accountLock, sNymID, sAccountID); if (false == bool(account)) { otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist." << std::endl; return false; } const auto& txid = transaction.txid(); account->add_outgoing(txid); auto saved = api_.Storage().Store(sNymID, account->type(), *account); if (false == saved) { otErr << OT_METHOD << __FUNCTION__ << ": Failed to save account." << std::endl; return false; } saved = api_.Storage().Store(transaction); if (false == saved) { otErr << OT_METHOD << __FUNCTION__ << ": Failed to save transaction." << std::endl; return false; } if (recipientContactID.empty()) { return true; } return activity_.AddBlockchainTransaction( senderNymID, recipientContactID, StorageBox::OUTGOINGBLOCKCHAIN, transaction); }
void do_fingeracct(CHAR_DATA *ch, char *arguments) { ACCOUNT_DATA *acc; char buf[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; char buf3[MAX_STRING_LENGTH]; char buf4[128]; int i, j, len = 0; if (arguments[0] == 0) { send_to_char(ch, "Whom would you like to finger?\n"); return; } acc = new_account(); load_account(arguments, acc); if (acc->name[0] == 0) { free_account(acc); send_to_char(ch, "Unable to finger that account.\n"); return; } send_to_char(ch, "\n#R+#r--------------------------#1[#2Finger Account#1]#r--------------------------#R+\n"); snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Account: #R%s#1]", acc->name); snprintf(buf3, MAX_STRING_LENGTH, "#1[#2Logins: #R%d#1]", acc->logins); snprintf(buf, MAX_STRING_LENGTH, "#r| %-40s %-40s #r|\n", buf2, buf3); send_to_char(ch, buf); serial_time(acc->time, buf4); if (acc->lasttime == 0) snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Lastsave: #RNever!#1]"); else snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Lastsave: #R%s#1]", acc->lasttime); snprintf(buf3, MAX_STRING_LENGTH, "#1[#2Time: #R%s#1]", buf4); snprintf(buf, MAX_STRING_LENGTH, "#r| %-40s %-40s #r|\n", buf2, buf3); send_to_char(ch, buf); for (i = 0; i < acc->charcount; ++i) if (strlen(acc->character[i]) > len) len = strlen(acc->character[i]); for (i = 0; i < acc->charcount; ++i) { for (j = 0; j < len - strlen(acc->character[i]); ++j) buf[j] = ' '; buf[j] = '\0'; switch (acc->status[i]) { default: case CHSTATUS_NORMAL: strlcat(buf, "#1#R#1", MAX_STRING_LENGTH); /* gets around colors not displaying */ break; case CHSTATUS_HARDCORE: strlcat(buf, "#1[#RH#1]", MAX_STRING_LENGTH); break; case CHSTATUS_DELETED: strlcat(buf, "#1[#1D#1]", MAX_STRING_LENGTH); break; case CHSTATUS_IMMORTAL: strlcat(buf, "#1[#YI#1]", MAX_STRING_LENGTH); break; } snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Char %d: #R%s#1] %s", i+1, acc->character[i], buf); serial_time(acc->chtime[i], buf4); snprintf(buf3, MAX_STRING_LENGTH, "#1[#2Time: #R%s#1]", buf4); snprintf(buf, MAX_STRING_LENGTH, "#r| %-46s %-40s #r|\n", buf2, buf3); send_to_char(ch, buf); } snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Email: #R%s#1]", acc->email); snprintf(buf, MAX_STRING_LENGTH, "#r| %-74s #r|\n", buf2); send_to_char(ch, buf); if (acc->lasthost[0] == 0) snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Host: #RN/A#1]"); else snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Host: #R%s#1]", acc->lasthost); snprintf(buf, MAX_STRING_LENGTH, "#r| %-74s #r|\n", buf2); send_to_char(ch, buf); send_to_char(ch, "#R+#r--------------------------------------------------------------------#R+#n\n"); free_account(acc); }
void do_finger(CHAR_DATA *ch, char *arguments) { ACCOUNT_DATA *acc; CHAR_DATA *xch; char buf[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; char buf3[MAX_STRING_LENGTH]; int email = 0; if (arguments[0] == 0) { send_to_char(ch, "Whom would you like to finger?\n"); return; } xch = load_character(NULL, arguments); if (xch->name[0] == 0) send_to_char(ch, "Unable to finger that player.\n"); else { acc = new_account(); load_account(xch->accname, acc); send_to_char(ch, "\n#R+#r------------------------------#1[#2Finger#1]#r------------------------------#R+\n"); snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Character: #R%s#1]", xch->name); snprintf(buf3, MAX_STRING_LENGTH, "#1[#2Class: #RNone#1]"); snprintf(buf, MAX_STRING_LENGTH, "#r| %-40s %-40s #r|\n", buf2, buf3); send_to_char(ch, buf); time_words(xch->time, buf3); snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Time: #R%s#1]", buf3); snprintf(buf, MAX_STRING_LENGTH, "#r| %-74s #r|\n", buf2); send_to_char(ch, buf); if (IS_SET(acc->aflags, AFLAG_PUBLIC_EMAIL)) { email = 1; snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Email: #R%s#1]", acc->email); snprintf(buf, MAX_STRING_LENGTH, "#r| %-74s #r|\n", buf2); send_to_char(ch, buf); } if (ch->level == LEVEL_SUPREME) { send_to_char(ch, "#R+#r-----------------------------#1[#2Imm Info#1]#r-----------------------------#R+\n"); if (email == 0) { snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Email: #R%s#1]", acc->email); snprintf(buf, MAX_STRING_LENGTH, "#r| %-74s #r|\n", buf2); send_to_char(ch, buf); } snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Account: #R%s#1]", xch->accname); snprintf(buf, MAX_STRING_LENGTH, "#r| %-74s #r|\n", buf2); send_to_char(ch, buf); if (acc->lasttime == 0) snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Lastsave: #RNever!#1]"); else snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Lastsave: #R%s#1]", acc->lasttime); snprintf(buf, MAX_STRING_LENGTH, "#r| %-74s #r|\n", buf2); send_to_char(ch, buf); if (acc->lasthost[0] == 0) snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Host: #RN/A#1]"); else snprintf(buf2, MAX_STRING_LENGTH, "#1[#2Host: #R%s#1]", acc->lasthost); snprintf(buf, MAX_STRING_LENGTH, "#r| %-74s #r|\n", buf2); send_to_char(ch, buf); } send_to_char(ch, "#R+#r--------------------------------------------------------------------#R+#n\n"); unlink_character(xch); free_account(acc); } free_character(xch); }
bool Blockchain::StoreIncoming( const Identifier& nymID, const Identifier& accountID, const std::uint32_t index, const BIP44Chain chain, const proto::BlockchainTransaction& transaction) const { LOCK_ACCOUNT() const std::string sNymID = nymID.str(); const std::string sAccountID = accountID.str(); auto account = load_account(accountLock, sNymID, sAccountID); if (false == bool(account)) { otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist." << std::endl; return false; } const auto allocatedIndex = chain ? account->internalindex() : account->externalindex(); if (index > allocatedIndex) { otErr << OT_METHOD << __FUNCTION__ << ": Address has not been allocated." << std::endl; return false; } auto& address = find_address(index, chain, *account); bool exists = false; for (const auto& txid : address.incoming()) { if (txid == transaction.txid()) { exists = true; break; } } if (false == exists) { address.add_incoming(transaction.txid()); } auto saved = api_.Storage().Store(sNymID, account->type(), *account); if (false == saved) { otErr << OT_METHOD << __FUNCTION__ << ": Failed to save account." << std::endl; return false; } saved = api_.Storage().Store(transaction); if (false == saved) { otErr << OT_METHOD << __FUNCTION__ << ": Failed to save transaction." << std::endl; return false; } if (address.contact().empty()) { return true; } const auto contactID = Identifier::Factory(address.contact()); return activity_.AddBlockchainTransaction( nymID, contactID, StorageBox::INCOMINGBLOCKCHAIN, transaction); }
bool Blockchain::AssignAddress( const Identifier& nymID, const Identifier& accountID, const std::uint32_t index, const Identifier& contactID, const BIP44Chain chain) const { LOCK_ACCOUNT() const std::string sNymID = nymID.str(); const std::string sAccountID = accountID.str(); const std::string sContactID = contactID.str(); auto account = load_account(accountLock, sNymID, sAccountID); if (false == bool(account)) { otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist." << std::endl; return false; } const auto& type = account->type(); const auto allocatedIndex = chain ? account->internalindex() : account->externalindex(); if (index > allocatedIndex) { otErr << OT_METHOD << __FUNCTION__ << ": Address has not been allocated." << std::endl; return false; } auto& address = find_address(index, chain, *account); const auto& existing = address.contact(); if (false == existing.empty()) { move_transactions(nymID, address, existing, sContactID); } address.set_contact(sContactID); account->set_revision(account->revision() + 1); // check: does the activity thread exist between nym and contact? bool threadExists = false; const auto threadList = api_.Storage().ThreadList(sNymID, false); for (const auto it : threadList) { const auto& id = it.first; if (id == sContactID) { threadExists = true; } } if (threadExists) { // check: does every incoming transaction exist as an activity std::shared_ptr<proto::StorageThread> thread = activity_.Thread(nymID, contactID); OT_ASSERT(thread); for (const std::string& txID : address.incoming()) { bool exists = false; for (const auto activity : thread->item()) if (txID.compare(activity.id()) == 0) exists = true; // add: transaction to the thread if (!exists) { activity_.AddBlockchainTransaction( nymID, contactID, StorageBox::INCOMINGBLOCKCHAIN, *Transaction(txID)); } } } else { // create the thread and add the transactions for (const auto txID : address.incoming()) { activity_.AddBlockchainTransaction( nymID, contactID, StorageBox::INCOMINGBLOCKCHAIN, *Transaction(txID)); } } return api_.Storage().Store(sNymID, type, *account); }
void file_init (Conf *config) { char *buffer; char *key, *val; FILE *fd; char *old_version = NULL; buffer = CONFIG_FILE; if ((fd = fopen (buffer, "r")) == NULL) { first_run (buffer); if ((fd = fopen (buffer, "r")) == NULL) { exit(1); } } c2_free (buffer); /* Start reading the file */ for (;;) { if ((key = fd_get_word (fd)) == NULL) break; if ((val = fd_get_word (fd)) == NULL) break; if (fd_move_to (fd, '\n', 1, TRUE, TRUE) == EOF) fseek (fd, -1, SEEK_CUR); if (streq (key, "empty_garbage")) { config->empty_garbage = atoi (val); c2_free (val); } else if (streq (key, "account")) { load_account (&config->account_head, val); } else if (streq (key, "mailbox")) { c2_mailbox_load (&config->mailbox_head, val); } else if (streq (key, "check_timeout")) { config->check_timeout = atoi (val); c2_free (val); } else if (streq (key, "check_at_start")) { config->check_at_start = atoi (val); c2_free (val); } else if (streq (key, "use_outbox")) { config->use_outbox = atoi (val); c2_free (val); } else if (streq (key, "use_persistent_smtp_connection")) { config->use_persistent_smtp_connection = atoi (val); c2_free (val); } else if (streq (key, "persistent_smtp_address")) { config->persistent_smtp_address = val; } else if (streq (key, "persistent_smtp_port")) { config->persistent_smtp_port = atoi (val); c2_free (val); } else if (streq (key, "prepend_char_on_re")) { c2_free (config->prepend_char_on_re); config->prepend_char_on_re = val; } else if (streq (key, "message_bigger")) { config->message_bigger = atoi (val); c2_free (val); } else if (streq (key, "timeout")) { config->timeout = atoi (val); c2_free (val); } else if (streq (key, "mark_as_read")) { config->mark_as_read = atoi (val); c2_free (val); } #ifdef BUILD_ADDRESS_BOOK else if (streq (key, "addrbook_init")) { config->addrbook_init = atoi (val); c2_free (val); } #endif else if (streq (key, "color_reply_original_message")) { sscanf (val, "%dx%dx%d", (int *) &config->color_reply_original_message.red, (int *) &config->color_reply_original_message.green, (int *) &config->color_reply_original_message.blue); c2_free (val); } else if (streq (key, "color_misc_body")) { sscanf (val, "%dx%dx%d", (int *) &config->color_misc_body.red, (int *) &config->color_misc_body.green, (int *) &config->color_misc_body.blue); c2_free (val); } else if (streq (key, "cronosII")) { if (strne (val+2, VERSION)) { old_version = g_strdup (val+2); } } else { buffer = g_strdup_printf (_("Unknown command in config file: %s"), key); cronos_error (ERROR_INTERNAL, buffer, ERROR_WARNING); c2_free (val); } c2_free (key); } fclose (fd); if (old_version) { pthread_t thread; pthread_create (&thread, NULL, PTHREAD_FUNC (c2_version_difference), old_version); } }
void nanny(DESCRIPTOR_DATA *d, char *input) { int i; char buf[MAX_STRING_LENGTH]; DESCRIPTOR_DATA *dt; switch(d->state) { case STATE_GET_NAME: if (input[0] == 0) { sckoutput(d->socket, "Fine, then.\n"); wipe_descriptor(d); return; } i = check_string(input, 4, 12, 0); if (i == 1) send_to_descriptor(d, "Your name must have at least 4 letters.\n"); else if (i == 2) send_to_descriptor(d, "Your name can contain at most 12 letters.\n"); else if (i == 4 || i == 3) send_to_descriptor(d, "Your name can contain only letters.\n"); else { input[0] = UPPER(input[0]); load_account(input, d->acc); d->acc->d = d; if (d->acc->name[0] == 0) { check_address(d->ip, d->acc->name); if (d->acc->name[0] != 0 && stricmp(input, d->acc->name)) send_to_descriptor(d, "#RWARNING:#n Your IP is linked to an existing account. It is against the rules to have multiple accounts.\n\n"); strlcpy(d->acc->name, input, 32); snprintf(buf, MAX_STRING_LENGTH, "Are you sure you want the name %s? ", input); send_to_descriptor(d, buf); d->state = STATE_CONFIRM_NAME; return; } send_to_descriptor(d, "Password? "); send_to_descriptor(d, password_on); d->state = STATE_GET_PASS; return; } send_to_descriptor(d, "What do you want your account name to be? "); break; case STATE_GET_PASS: send_to_descriptor(d, password_off); if (!strcmp(d->acc->password, input)) { /* check to see if someone else is logged in under this account */ for (dt = dhead; dt; dt = dt->next) { if (dt == d || dt->acc == NULL) continue; if (!stricmp(d->acc->name, dt->acc->name)) { /* d = new connection, dt = old */ if (dt->socket > 0 && dt->state != STATE_LINKDEAD) { sckoutput(dt->socket, "\n\nYou have been kicked off.\n"); close(dt->socket); } dt->socket = d->socket; d->socket = -1; /* this is mandatory because wipe_descriptor closes d->socket */ wipe_descriptor(d); d = dt; if (d->state != STATE_PLAYING && d->state != STATE_LINKDEAD) send_to_descriptor(d, "\nYou have kicked someone off while they were logging in. Sending you to the account menu.\n"); else { destroy_all_events(d->acc->ch, EVENT_LINKDEAD); setup_char_events(d->acc->ch); d->acc->ch->idle = 0; syslog("RECONNECT", "%s (on %s@%s) has reconnected.", d->acc->ch->name, d->acc->name, d->ip); d->state = STATE_PLAYING; send_to_descriptor(d, "\n#RReconnected.#n\n"); return; } } } syslog("LOGIN", "%s@%s has logged in.", d->acc->name, d->ip); d->state = STATE_ACCT_MENU; d->acc->logins++; save_account(d->acc); show_account_menu(d, 0); snprintf(buf, MAX_STRING_LENGTH, "#1[#2Last connection from #R%s#2 at #R%s#2.#1]\n", d->acc->lasthost, d->acc->lasttime); save_address(d); send_to_descriptor(d, buf); if (d->acc->failed == 1) snprintf(buf, MAX_STRING_LENGTH, "#1[#RWARNING:#2 1 failed login attempt since your last connection.#1]\n"); else if (d->acc->failed > 1) snprintf(buf, MAX_STRING_LENGTH, "#1[#RWARNING:#2 %d failed login attempts since your last connection.#1]\n", d->acc->failed); if (d->acc->failed > 0) { send_to_descriptor(d, buf); d->acc->failed = 0; save_account(d->acc); } send_to_descriptor(d, "#nWhat is your choice? "); return; } sckoutput(d->socket, "Incorrect password. Logging you off...\n"); syslog("PASSWORD", "%s@%s -- incorrect password! Logged off.", d->acc->name, d->ip); d->acc->failed++; save_account(d->acc); wipe_descriptor(d); break; case STATE_CONFIRM_NAME: if (input[0] == 'y' || input[0] == 'Y') { send_to_descriptor(d, "What do you want your password to be? "); syslog("NEW", "New account %s is being created.", d->acc->name); d->state = STATE_NEW_PASS; send_to_descriptor(d, password_on); return; } send_to_descriptor(d, "Okay. What do you want your name to be? "); d->state = STATE_GET_NAME; break; case STATE_NEW_PASS: send_to_descriptor(d, password_off); if (input[0] == 0) { send_to_descriptor(d, "\nWhat do you want your password to be? "); send_to_descriptor(d, password_on); return; } i = check_string(input, 4, 12, 1); if (i == 1) send_to_descriptor(d, "\nYour password must have at least 4 characters.\n"); else if (i == 2) send_to_descriptor(d, "\nYour password can contain at most 12 characters.\n"); else if (i == 4) send_to_descriptor(d, "\nYour password can contain only letters and numbers.\n"); else { strlcpy(d->acc->password, input, 32); send_to_descriptor(d, "\nPlease retype your password for confirmation. "); send_to_descriptor(d, password_on); d->state = STATE_CONFIRM_PASS; return; } send_to_descriptor(d, "\nWhat do you want your password to be? "); send_to_descriptor(d, password_on); break; case STATE_CONFIRM_PASS: send_to_descriptor(d, password_off); if (strcmp(d->acc->password, input)) { send_to_descriptor(d, "\nYour passwords must match exactly.\nWhat do you want your password to be? "); d->state = STATE_NEW_PASS; d->acc->password[0] = 0; send_to_descriptor(d, password_on); return; } send_to_descriptor(d, "\nDo you want ANSI color? "); d->state = STATE_GET_ANSI; break; case STATE_GET_ANSI: d->acc->aflags = 0; if (input[0] == 'y' || input[0] == 'Y') SET_BIT(d->acc->aflags, AFLAG_ANSI); else if (input[0] == 'n' || input[0] == 'N') ; else { send_to_descriptor(d, "Please type yes or no.\nDo you want ANSI color? "); return; } for (dt = dhead; dt; dt = dt->next) { if (dt == d) continue; if (!stricmp(d->acc->name, dt->acc->name) && (dt->state > STATE_GET_PASS || dt->state < STATE_CONFIRM_NAME)) { sckoutput(d->socket, "You have been kicked off.\n"); wipe_descriptor(d); return; } } d->acc->logins = 1; d->acc->changes = time(NULL); strlcpy(d->acc->email, "Unset", 128); d->state = STATE_ACCT_MENU; log_time(d->acc->firsttime); save_address(d); show_account_menu(d, 1); save_account(d->acc); break; case STATE_ACCT_MENU: switch (input[0]) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': i = atoi(input); if (i > d->acc->charcount) { send_to_descriptor(d, "Unknown option.\nWhat is your choice? "); return; } if (d->acc->status[i - 1] == CHSTATUS_DELETED) { send_to_descriptor(d, "You are unable to log onto that player.\nWhat is your choice? "); return; } { d->acc->ch = load_character(d->acc, d->acc->character[i - 1]); d->acc->ch->acc = d->acc; d->acc->ch->d = d; setup_char_events(d->acc->ch); d->state = STATE_PLAYING; d->acc->cur_char = i - 1; ++d->acc->chlogins[i - 1]; destroy_d_events(d, EVENT_LOGINIDLE); if (d->acc->ch->level >= LEVEL_IMMORTAL) d->acc->status[i - 1] = CHSTATUS_IMMORTAL; if (!IS_SET(d->acc->ch->cflags, CFLAG_OLDPLAYER)) { syslog("LOGIN", "%s (on %s@%s) is now playing for the first time!", d->acc->ch->name, d->acc->name, d->ip); login_msg_new(d->acc->ch); SET_BIT(d->acc->ch->cflags, CFLAG_OLDPLAYER); if (IS_SET(d->acc->ch->cflags, CFLAG_HARDCORE)) d->acc->ch->plane = PLANE_HNEWBIE; else d->acc->ch->plane = PLANE_NEWBIE; d->acc->ch->maxhp = 1000; d->acc->ch->maxmove = 1000; d->acc->ch->maxmana = 1000; d->acc->ch->hp = d->acc->ch->maxhp; d->acc->ch->move = d->acc->ch->maxmove; d->acc->ch->mana = d->acc->ch->maxmana; d->acc->ch->level = LEVEL_MORTAL; d->acc->ch->sightradius = 5; /* pwipe: increase this to 50 */ strlcpy(d->acc->ch->prompt, "#1[#2%pP#1] #1[#2%h#1/#2%HH %m#1/#2%MM %v#1/#2%VV#1]#n> ", 256); send_to_char(d->acc->ch, "\nWelcome to Undertow. This is a completely custom MUD. We recommend that you read #RHELP NEWBIE#n.\n"); } else { syslog("LOGIN", "%s (on %s@%s) is now playing.", d->acc->ch->name, d->acc->name, d->ip); login_msg(d->acc->ch); do_look(d->acc->ch, ""); } save_account(d->acc); } break; case 'r': case 'R': if (new_changes(d->acc) == 0) { send_to_descriptor(d, "There are no new changes.\nWhat is your choice? "); return; } show_changes(d->acc, -1); send_to_descriptor(d, "\n#nWhat is your choice? "); break; case 'c': case 'C': d->state = STATE_CONFIG_MENU; show_account_settings(d); break; case 's': case 'S': send_who(d); send_to_descriptor(d, "#nWhat is your choice? "); break; case 'n': case 'N': if (d->acc->charcount >= MAX_CHARS_PER_ACCOUNT) { send_to_descriptor(d, "You have met your maximum amount of characters for this account.\nWhat is your choice?"); return; } d->state = STATE_NEW_CHAR; send_to_descriptor(d, "What do you want your name to be? "); break; case 'd': case 'D': if (d->acc->charcount == 0) { send_to_descriptor(d, "You have no characters to delete.\nWhat is your choice? "); return; } show_delete_menu(d); d->state = STATE_DELETE_CHAR; break; case 'q': case 'Q': save_account(d->acc); syslog("QUIT", "%s@%s quit at the login screen.", d->acc->name, d->ip); sckoutput(d->socket, "Goodbye.\n"); wipe_descriptor(d); break; case '\0': show_account_menu(d, 1); break; default: send_to_descriptor(d, "Unknown option.\nWhat is your choice? "); break; } break; case STATE_CONFIG_MENU: switch (input[0]) { case 'r': case 'R': d->state = STATE_ACCT_MENU; show_account_menu(d, 1); break; case 'a': case 'A': TOGGLE_BIT(d->acc->aflags, AFLAG_ANSI); if (IS_SET(d->acc->aflags, AFLAG_ANSI)) { if (IS_SET(d->acc->aflags, AFLAG_ANSI_SPARSE)) send_to_descriptor(d, "Your prompts will now be colored. If you want full color, turn Full ANSI Color on.\nWhat is your choice? "); else send_to_descriptor(d, "Welcome to the wonderful world of #Rc#Yo#Gl#Co#Mr#n!\nWhat is your choice? "); } else send_to_descriptor(d, "ANSI color turned off.\nWhat is your choice? "); break; case 'f': case 'F': TOGGLE_BIT(d->acc->aflags, AFLAG_ANSI_SPARSE); if (!IS_SET(d->acc->aflags, AFLAG_ANSI)) send_to_descriptor(d, "You would probably notice a subsequent color level change if you had color on.\nWhat is your choice? "); else if (IS_SET(d->acc->aflags, AFLAG_ANSI_SPARSE)) send_to_descriptor(d, "You will now only see colored prompts.\nWhat is your choice? "); else send_to_descriptor(d, "You will now see full color.\nWhat is your choice? "); break; case 'l': case 'L': TOGGLE_BIT(d->acc->aflags, AFLAG_REPLYLOCK); if (IS_SET(d->acc->aflags, AFLAG_REPLYLOCK)) send_to_descriptor(d, "You will now reply only to the last person to whom you sent a tell.\nWhat is your choice? "); else send_to_descriptor(d, "You will now reply to the person who most recently sent you a tell.\nWhat is your choice? "); break; case 'p': case 'P': TOGGLE_BIT(d->acc->aflags, AFLAG_PUBLIC_EMAIL); if (IS_SET(d->acc->aflags, AFLAG_PUBLIC_EMAIL)) send_to_descriptor(d, "Your email address is now public.\nWhat is your choice? "); else send_to_descriptor(d, "Your email address is now private.\nWhat is your choice? "); break; case 'c': case 'C': d->state = STATE_CHANGE_PASS1; send_to_descriptor(d, "What is your current password? "); send_to_descriptor(d, password_on); break; case 'e': case 'E': d->state = STATE_SET_EMAIL; send_to_descriptor(d, "What is your email address? "); break; case '\0': show_account_settings(d); break; case 'd': case 'D': SET_BIT(d->acc->aflags, AFLAG_ANSI); REMOVE_BIT(d->acc->aflags, AFLAG_ANSI_SPARSE); REMOVE_BIT(d->acc->aflags, AFLAG_PUBLIC_EMAIL); strlcpy(d->acc->email, "Unset", 128); send_to_descriptor(d, "Reverted to default settings.\nWhat is your choice?"); break; default: send_to_descriptor(d, "Unknown option.\nWhat is your choice? "); break; } break; case STATE_CHANGE_PASS1: send_to_descriptor(d, password_off); if (input[0] == 0) { d->state = STATE_CONFIG_MENU; send_to_descriptor(d, "\nWhat is your choice? "); return; } if (strcmp(d->acc->password, input)) { send_to_descriptor(d, "\nIncorrect password.\nWhat is your choice? "); d->state = STATE_CONFIG_MENU; return; } d->state = STATE_CHANGE_PASS2; d->acc->temp[0] = 0; send_to_descriptor(d, "\nWhat do you want your new password to be? "); send_to_descriptor(d, password_on); break; case STATE_CHANGE_PASS2: send_to_descriptor(d, password_off); if (input[0] == 0) { d->state = STATE_CONFIG_MENU; send_to_descriptor(d, "\nWhat is your choice? "); return; } i = check_string(input, 4, 12, 1); if (i == 1) send_to_descriptor(d, "\nYour password must have at least 4 characters.\n"); else if (i == 2) send_to_descriptor(d, "\nYour password can contain at most 12 characters.\n"); else if (i == 4) send_to_descriptor(d, "\nYour password can contain only letters and numbers.\n"); else { strlcpy(d->acc->temp, input, 128); send_to_descriptor(d, "\nPlease retype your password for confirmation. "); d->state = STATE_CHANGE_PASS3; send_to_descriptor(d, password_on); return; } send_to_descriptor(d, "\nWhat do you want your password to be? "); send_to_descriptor(d, password_on); break; case STATE_CHANGE_PASS3: send_to_descriptor(d, password_off); if (input[0] == 0) { d->state = STATE_CONFIG_MENU; send_to_descriptor(d, "\nWhat is your choice? "); return; } if (strcmp(d->acc->temp, input)) { send_to_descriptor(d, "\nPasswords must match exactly.\nWhat is your choice? "); d->state = STATE_CONFIG_MENU; return; } strlcpy(d->acc->password, input, 32); send_to_descriptor(d, "\nYour password is now changed.\nWhat is your choice? "); d->state = STATE_CONFIG_MENU; save_account(d->acc); break; case STATE_SET_EMAIL: i = check_string(input, -1, 47, 0); if (i == 2) send_to_descriptor(d, "Your email can contain at most 47 characters.\n"); else if (strlen(input) == 0) { strlcpy(d->acc->email, "Unset", 128); d->state = STATE_CONFIG_MENU; send_to_descriptor(d, "Your email address is now unset.\nWhat is your choice? "); } else { replace(input, buf, "%", "", MAX_STRING_LENGTH); replace(buf, input, "~", "-", MAX_STRING_LENGTH); strlcpy(d->acc->email, input, 128); d->state = STATE_CONFIG_MENU; snprintf(buf, MAX_STRING_LENGTH, "Your email address is now %s.\nWhat is your choice? ", input); send_to_descriptor(d, buf); return; } send_to_descriptor(d, "What is your email address? "); break; case STATE_DELETE_CHAR: if (input[0] == 'r' || input[0] == 'R') { d->state = STATE_ACCT_MENU; show_account_menu(d, 1); return; } if (input[0] == 0) { show_delete_menu(d); return; } i = atoi(input); if (i < 1 || i > d->acc->charcount) send_to_descriptor(d, "Out of bounds.\nWhich character do you want to delete? "); else { d->acc->name[15] = --i; snprintf(buf, MAX_STRING_LENGTH, "Are you sure you want to delete %s?", d->acc->character[i]); send_to_descriptor(d, buf); d->state = STATE_CONFIRM_DEL; } break; case STATE_CONFIRM_DEL: if (input[0] == 'y' || input[0] == 'Y') { i = d->acc->name[15]; d->acc->name[15] = 0; snprintf(buf, MAX_STRING_LENGTH, "%s has been deleted.\nWhat is your choice? ", d->acc->character[i]); send_to_descriptor(d, buf); syslog("DELETION", "%s (on %s@%s) has selfdeleted.", d->acc->character[i], d->acc->name, d->ip); d->state = STATE_ACCT_MENU; d->acc->chtime[i] = 0; snprintf(buf, MAX_STRING_LENGTH, "rm -f account/%s.chr", d->acc->character[i]); to_lower(buf); system(buf); d->acc->charcount--; while (i < d->acc->charcount) { strlcpy(d->acc->character[i], d->acc->character[i + 1], 32); i++; } save_account(d->acc); return; } d->state = STATE_ACCT_MENU; show_account_menu(d, 1); break; case STATE_NEW_CHAR: i = 0; if (input[0] == 0) { d->state = STATE_ACCT_MENU; show_account_menu(d, 1); return; } i = check_string(input, 4, 12, 0); if (i == 1) send_to_descriptor(d, "Your name must have atleast 4 letters.\n"); else if (i == 2) send_to_descriptor(d, "Your name can contain at most 12 letters.\n"); else if (i == 4 || i == 3) send_to_descriptor(d, "Your name can contain only letters.\n"); else { input[0] = UPPER(input[0]); for (dt = dhead; dt; dt = dt->next) if ((d != dt) && !stricmp(input, dt->acc->character[dt->acc->charcount])) i = 1; if (i == 0 && char_exists(input)) i = 1; if (i) { snprintf(buf, MAX_STRING_LENGTH, "The name %s is already taken.\nWhat do you want your name to be? ", input); send_to_descriptor(d, buf); return; } strlcpy(d->acc->character[d->acc->charcount], input, 32); snprintf(buf, MAX_STRING_LENGTH, "Are you sure you want the name %s? ", input); send_to_descriptor(d, buf); d->state = STATE_CONFIRM_CHAR; return; } send_to_descriptor(d, "What do you want your name to be? "); break; case STATE_CONFIRM_CHAR: if (input[0] == 'y' || input[0] == 'Y') { if (d->acc->logins == 1) { d->state = STATE_ACCT_MENU; finish_creation(d, 0); return; } d->state = STATE_GET_HARDCORE; send_to_descriptor(d, "Do you want this character to be hardcore (death = deletion)? "); } else { d->state = STATE_ACCT_MENU; show_account_menu(d, 1); } break; case STATE_GET_HARDCORE: finish_creation(d, input[0] == 'y' || input[0] == 'Y'); break; } }
void check_psionic_talents (CHAR_DATA *ch) { ACCOUNT_DATA *account; int chance = 0, roll = 0; int cur_talents = 0, i = 0, j = 1; int talents [8] = { SKILL_CLAIRVOYANCE, SKILL_DANGER_SENSE, SKILL_EMPATHIC_HEAL, SKILL_HEX, SKILL_MENTAL_BOLT, SKILL_PRESCIENCE, SKILL_SENSITIVITY, SKILL_TELEPATHY }; bool check = TRUE, again = TRUE, awarded = FALSE, block = FALSE; char buf [MAX_STRING_LENGTH] = {'\0'}; char *date = NULL; if ( is_newbie (ch) || ch->aur <= 15 ) return; if ( ch->pc && ch->pc->account ) { if ( !(account = load_account (ch->pc->account)) ) return; if ( IS_SET (account->flags, ACCOUNT_NOPSI) ) block = TRUE; if ( account->roleplay_points < 2 ) block = TRUE; free_account (account); } else return; if ( block ) return; if ( ch->aur < 16 ) return; else if ( ch->aur == 16 ) chance = 5; else if ( ch->aur == 17 ) chance = 10; else if ( ch->aur == 18 ) chance = 20; else if ( ch->aur == 19 ) chance = 30; else if ( ch->aur == 20 ) chance = 45; else if ( ch->aur == 21 ) chance = 50; else if ( ch->aur == 22 ) chance = 60; else if ( ch->aur == 23 ) chance = 70; else if ( ch->aur == 24 ) chance = 80; else chance = 95; chance += number(1,10); chance = MIN(chance, 95); for ( i = 0; i <= 7; i++ ) if ( ch->skills[talents[i]] ) cur_talents++; while ( check && cur_talents <= 4 ) { if ( number(1,100) <= chance ) { again = TRUE; while ( again ) { roll = talents[number(0,7)]; if ( !ch->skills [roll] ) { ch->skills [roll] = 1; cur_talents++; again = FALSE; awarded = TRUE; } chance /= 2; } if ( cur_talents >= 4 ) check = FALSE; } else check = FALSE; } if ( !awarded ) return; snprintf (buf, MAX_STRING_LENGTH, "This character rolled positive for the following talents:\n\n"); for ( i = 0; i <= 7; i++ ) if ( ch->skills [talents[i]] ) snprintf (buf + strlen(buf), MAX_STRING_LENGTH, " %d. %s\n", j++, skill_data[talents[i]].skill_name); date = timestr(date); add_message ("Psi_talents", 2, "Server", date, ch->tname, "", buf, 0); add_message (ch->tname, 3, "Server", date, "Psionic Talents.", "", buf, 0); mem_free (date); }