void quest_join(struct char_data *ch, struct char_data *qm, char argument[MAX_INPUT_LENGTH]) { qst_vnum vnum; qst_rnum rnum; char buf[MAX_INPUT_LENGTH]; if (!*argument) snprintf(buf, sizeof(buf), "%s What quest did you wish to join?", GET_NAME(ch)); else if (GET_QUEST(ch) != NOTHING) snprintf(buf, sizeof(buf), "%s But you are already part of a quest!", GET_NAME(ch)); else if((vnum = find_quest_by_qmnum(ch, GET_MOB_VNUM(qm), atoi(argument))) == NOTHING) snprintf(buf, sizeof(buf), "%s I don't know of such a quest!", GET_NAME(ch)); else if ((rnum = real_quest(vnum)) == NOTHING) snprintf(buf, sizeof(buf), "%s I don't know of such a quest!", GET_NAME(ch)); else if (GET_LEVEL(ch) < QST_MINLEVEL(rnum)) snprintf(buf, sizeof(buf), "%s You are not experienced enough for that quest!", GET_NAME(ch)); else if (GET_LEVEL(ch) > QST_MAXLEVEL(rnum)) snprintf(buf, sizeof(buf), "%s You are too experienced for that quest!", GET_NAME(ch)); else if (is_complete(ch, vnum)) snprintf(buf, sizeof(buf), "%s You have already completed that quest!", GET_NAME(ch)); else if ((QST_PREV(rnum) != NOTHING) && !is_complete(ch, QST_PREV(rnum))) snprintf(buf, sizeof(buf), "%s That quest is not available to you yet!", GET_NAME(ch)); else if ((QST_PREREQ(rnum) != NOTHING) && (real_object(QST_PREREQ(rnum)) != NOTHING) && (get_obj_in_list_num(real_object(QST_PREREQ(rnum)), ch->carrying) == NULL)) snprintf(buf, sizeof(buf), "%s You need to have %s first!", GET_NAME(ch), obj_proto[real_object(QST_PREREQ(rnum))].short_description); else { act("You join the quest.", TRUE, ch, NULL, NULL, TO_CHAR); act("$n has joined a quest.", TRUE, ch, NULL, NULL, TO_ROOM); snprintf(buf, sizeof(buf), "%s Listen carefully to the instructions.", GET_NAME(ch)); do_tell(qm, buf, cmd_tell, 0); set_quest(ch, rnum); send_to_char(ch, "%s", QST_INFO(rnum)); if (QST_TIME(rnum) != -1) snprintf(buf, sizeof(buf), "%s You have a time limit of %d turn%s to complete the quest.", GET_NAME(ch), QST_TIME(rnum), QST_TIME(rnum) == 1 ? "" : "s"); else snprintf(buf, sizeof(buf), "%s You can take however long you want to complete the quest.", GET_NAME(ch)); } do_tell(qm, buf, cmd_tell, 0); save_char(ch); }
file_view file_view_pool::open_file(storage_index_t st, std::string const& p , file_index_t const file_index, file_storage const& fs , open_mode_t const m) { // potentially used to hold a reference to a file object that's // about to be destructed. If we have such object we assign it to // this member to be destructed after we release the std::mutex. On some // operating systems (such as OSX) closing a file may take a long // time. We don't want to hold the std::mutex for that. std::shared_ptr<file_mapping> defer_destruction; std::unique_lock<std::mutex> l(m_mutex); TORRENT_ASSERT(is_complete(p)); auto& key_view = m_files.get<0>(); auto const i = key_view.find(file_id{st, file_index}); if (i != key_view.end()) { key_view.modify(i, [&](file_entry& e) { e.last_use = aux::time_now(); // make sure the write bit is set if we asked for it // it's OK to use a read-write file if we just asked for read. But if // we asked for write, the file we serve back must be opened in write // mode if (!(e.mode & open_mode::write) && (m & open_mode::write)) { defer_destruction = std::move(e.mapping); e.mapping = std::make_shared<file_mapping>( file_handle(fs.file_path(file_index, p) , fs.file_size(file_index), m), m , fs.file_size(file_index)); e.mode = m; } }); auto& lru_view = m_files.get<1>(); lru_view.relocate(m_files.project<1>(i), lru_view.begin()); return i->mapping->view(); } if (int(m_files.size()) >= m_size - 1) { // the file cache is at its maximum size, close // the least recently used file remove_oldest(l); } l.unlock(); file_entry e({st, file_index}, fs.file_path(file_index, p), m , fs.file_size(file_index)); auto ret = e.mapping->view(); l.lock(); auto& key_view2 = m_files.get<0>(); key_view2.insert(std::move(e)); return ret; }
int phr_parse_response(const char* buf_start, size_t len, int* minor_version, int* status, const char** msg, size_t* msg_len, struct phr_header* headers, size_t* num_headers, size_t last_len) { const char * buf = buf_start, * buf_end = buf + len; size_t max_headers = *num_headers; int r; *minor_version = -1; *status = 0; *msg = NULL; *msg_len = 0; *num_headers = 0; /* if last_len != 0, check if the response is complete (a fast countermeasure against slowloris */ if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) { return r; } if ((buf = parse_response(buf, buf_end, minor_version, status, msg, msg_len, headers, num_headers, max_headers, &r)) == NULL) { return r; } return buf - buf_start; }
void user_auction_claim_operation::evaluate( transaction_evaluation_state& eval_state ) { try { FC_ASSERT( !"This operation is not enabled yet!" ); auto chain = eval_state._current_state; auto obj = chain->get_object_record( this->auction_id ); FC_ASSERT( obj.valid(), "No such auction." ); auto auction = obj->as<user_auction_record>(); FC_ASSERT( auction.is_complete( *chain ), "Auction is not over yet." ); if( this->claim_balance ) { FC_ASSERT( NOT auction.balance_claimed, "Those auction winnings have already been claimed." ); eval_state.check_update_permission( auction.beneficiary ); eval_state.add_balance( auction.previous_bid ); auction.balance_claimed = true; } if( this->claim_object ) // set the item's owner to the winner { FC_ASSERT( NOT auction.object_claimed, "That object has already been claimed." ); eval_state.check_update_permission( auction.previous_bidder ); auto item = chain->get_object_record( auction.item ); FC_ASSERT( item->owner_object == auction._id, "An auction was being held for an item owned by someone else?"); item->owner_object = auction.previous_bidder; chain->store_object_record( *item ); auction.object_claimed = true; } chain->store_object_record( object_record( auction ) ); } FC_CAPTURE_AND_RETHROW( (eval_state)(*this) ) }
//First call : chance_solver(dummy_grid,0,0,chance_grid); chance_grid=dummy_grid //Recursive call : chance_solver(dummy_grid,x,y,new_chance_grid); int chance_solver(int dummy_grid[MAX][MAX],int x, int y, int chance_grid[MAX][MAX]) { int i, contradiction; int new_chance_grid[MAX][MAX], chance_array[MAX]; if(dummy_grid[x][y] != 0){ if(y == MAX - 1) chance_solver(dummy_grid,x+1,0,chance_grid); // if(is_complete(chance_grid)) // print(chance_grid); else chance_solver(dummy_grid,x,y+1,chance_grid); return(0); } copier(chance_grid,new_chance_grid); contradiction = chance_updater(chance_grid,x,y,chance_array); if(contradiction) return FALSE; for(i = 0; i < MAX; ++i){ if(chance_array[i] == TRUE){ new_chance_grid[x][y] = i + 1; if(is_complete(new_chance_grid)) print(new_chance_grid); if(y == MAX - 1) chance_solver(dummy_grid,x+1,0,new_chance_grid); else chance_solver(dummy_grid,x,y+1,new_chance_grid); } } return(0); }
int phr_parse_request(const char* buf_start, size_t len, const char** method, size_t* method_len, const char** path, size_t* path_len, int* minor_version, struct phr_header* headers, size_t* num_headers, size_t last_len) { const char * buf = buf_start, * buf_end = buf_start + len; size_t max_headers = *num_headers; int r; *method = NULL; *method_len = 0; *path = NULL; *path_len = 0; *minor_version = -1; *num_headers = 0; /* if last_len != 0, check if the request is complete (a fast countermeasure againt slowloris */ if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) { return r; } if ((buf = parse_request(buf, buf_end, method, method_len, path, path_len, minor_version, headers, num_headers, max_headers, &r)) == NULL) { return r; } return buf - buf_start; }
int uniq_updater(int orig_grid[MAX][MAX]) { int x, y , num, unique, chance_uniq, nsol, possible, complete; unique = TRUE; while(unique == TRUE){ for(x = 0; x < MAX; ++x){ for(y = 0; y < MAX; ++y){ if(orig_grid[x][y] == 0){ nsol = 0; for(num = 1; num <= MAX; ++num){ possible = checker(orig_grid,x,y,num); if(possible){ ++nsol; chance_uniq = num; } } if(nsol == 1){ orig_grid[x][y] = chance_uniq; unique = TRUE; complete = is_complete(orig_grid); if(complete) return TRUE; } else //! unique = FALSE; //multiple sols. } } } } return unique; //return to main and print final orig_grid }
void solve_board(board_t* board) { stats.solve++; if (is_complete(board)) { printf("SOLVED!\n"); print_board(board); print_stats(stats); assert(0); } else if (is_dead_end(board)) { debugf("dead end, skip\n"); } else { size_t i_row, i_col; digits_t digits; find_next_continuation(board, &i_row, &i_col, &digits); debugf("best continuation [%lu,%lu]\n", i_row, i_col); size_t i; for (i = 1; i < NDIGITS; i++) { if (0 == digits.digits[i]) { debugf("extending [%lu,%lu] <- %lu\n", i_row, i_col, i); board_t* new_board = copy_board(board); set_digit(new_board, i_row, i_col, i); solve_board(new_board); free(new_board); } } } }
void IncrementalMerkleTree<Depth, Hash>::append(Hash obj) { if (is_complete(Depth)) { throw std::runtime_error("tree is full"); } if (!left) { // Set the left leaf left = obj; } else if (!right) { // Set the right leaf right = obj; } else { // Combine the leaves and propagate it up the tree boost::optional<Hash> combined = Hash::combine(*left, *right); // Set the "left" leaf to the object and make the "right" leaf none left = obj; right = boost::none; for (size_t i = 0; i < Depth; i++) { if (i < parents.size()) { if (parents[i]) { combined = Hash::combine(*parents[i], *combined); parents[i] = boost::none; } else { parents[i] = *combined; break; } } else { parents.push_back(combined); break; } } } }
static int wait_for_complete(struct loopback_test *t) { int number_of_events = 0; char dummy; int ret; int i; struct timespec *ts = NULL; struct sigaction sa; sigset_t mask_old, mask; sigemptyset(&mask); sigemptyset(&mask_old); sigaddset(&mask, SIGINT); sigprocmask(SIG_BLOCK, &mask, &mask_old); sa.sa_handler = handler; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); if (sigaction(SIGINT, &sa, NULL) == -1) { fprintf(stderr, "sigaction error\n"); return -1; } if (t->poll_timeout.tv_sec != 0) ts = &t->poll_timeout; while (1) { ret = ppoll(t->fds, t->poll_count, ts, &mask_old); if (ret <= 0) { stop_tests(t); fprintf(stderr, "Poll exit with errno %d\n", errno); return -1; } for (i = 0; i < t->poll_count; i++) { if (t->fds[i].revents & POLLPRI) { /* Dummy read to clear the event */ read(t->fds[i].fd, &dummy, 1); number_of_events++; } } if (number_of_events == t->poll_count) break; } if (!is_complete(t)) { fprintf(stderr, "Iteration count did not finish!\n"); return -1; } return 0; }
void mission::process() { if( !in_progress() ) { return; } if( deadline > 0 && calendar::turn > deadline ) { fail(); } else if( npc_id < 0 && is_complete( npc_id ) ) { // No quest giver. wrap_up(); } }
static void natpmp_resp_handler(int err, const struct natpmp_resp *resp, void *arg) { struct comp *comp = arg; struct mnat_media *m = comp->media; struct sa map_addr; if (err) { warning("natpmp: response error: %m\n", err); complete(m->sess, err); return; } if (resp->op != NATPMP_OP_MAPPING_UDP) return; if (resp->result != NATPMP_SUCCESS) { warning("natpmp: request failed with result code: %d\n", resp->result); complete(m->sess, EPROTO); return; } if (resp->u.map.int_port != comp->int_port) { info("natpmp: ignoring response for internal_port=%u\n", resp->u.map.int_port); return; } info("natpmp: mapping granted for comp %u:" " internal_port=%u, external_port=%u, lifetime=%u\n", comp->id, resp->u.map.int_port, resp->u.map.ext_port, resp->u.map.lifetime); map_addr = natpmp_extaddr; sa_set_port(&map_addr, resp->u.map.ext_port); comp->lifetime = resp->u.map.lifetime; /* Update SDP media with external IP-address mapping */ if (comp->id == 1) sdp_media_set_laddr(m->sdpm, &map_addr); else sdp_media_set_laddr_rtcp(m->sdpm, &map_addr); comp->granted = true; tmr_start(&comp->tmr, comp->lifetime * 1000 * 3/4, refresh_timeout, comp); is_complete(m->sess); }
TEST(TestReedSolomonCodes, test_encode_decode) { { kodo::rs_encoder<fifi::binary8>::factory encoder_factory(255, 1600); kodo::rs_decoder<fifi::binary8>::factory decoder_factory(255, 1600); uint32_t symbols = rand_symbols(255); uint32_t symbol_size = rand_symbol_size(); encoder_factory.set_symbols(symbols); encoder_factory.set_symbol_size(symbol_size); decoder_factory.set_symbols(symbols); decoder_factory.set_symbol_size(symbol_size); auto encoder = encoder_factory.build(); auto decoder = decoder_factory.build(); // Encode/decode operations EXPECT_TRUE(encoder->payload_size() == decoder->payload_size()); std::vector<uint8_t> payload(encoder->payload_size()); std::vector<uint8_t> data_in = random_vector(encoder->block_size()); encoder->set_symbols(sak::storage(data_in)); uint32_t symbol_count = 0; while( !decoder->is_complete() ) { encoder->encode( &payload[0] ); decoder->decode( &payload[0] ); ++symbol_count; } // A reed solomon code should be able to decode // with exactly k symbols EXPECT_EQ(symbol_count, symbols); std::vector<uint8_t> data_out(decoder->block_size(), '\0'); decoder->copy_symbols(sak::storage(data_out)); EXPECT_TRUE(std::equal(data_out.begin(), data_out.end(), data_in.begin())); } }
void posix_storage::rename_file(file_index_t const index, std::string const& new_filename, storage_error& ec) { if (index < file_index_t(0) || index >= files().end_file()) return; std::string const old_name = files().file_path(index, m_save_path); if (exists(old_name, ec.ec)) { std::string new_path; if (is_complete(new_filename)) new_path = new_filename; else new_path = combine_path(m_save_path, new_filename); std::string new_dir = parent_path(new_path); // create any missing directories that the new filename // lands in create_directories(new_dir, ec.ec); if (ec.ec) { ec.file(index); ec.operation = operation_t::file_rename; return; } rename(old_name, new_path, ec.ec); if (ec.ec == boost::system::errc::no_such_file_or_directory) ec.ec.clear(); if (ec) { ec.file(index); ec.operation = operation_t::file_rename; return; } } else if (ec.ec) { // if exists fails, report that error ec.file(index); ec.operation = operation_t::file_rename; return; } if (!m_mapped_files) { m_mapped_files.reset(new file_storage(files())); } m_mapped_files->rename_file(index, new_filename); }
void quest_show(struct char_data *ch, mob_vnum qm) { qst_rnum rnum; int counter = 0; send_to_char(ch, "The following quests are available:\r\n" "Index Description ( Vnum) Done?\r\n" "----- ---------------------------------------------------- ------- -----\r\n"); for (rnum = 0; rnum < total_quests; rnum++) if (qm == QST_MASTER(rnum)) send_to_char(ch, "\tg%4d\tn) \tc%-52.52s\tn \ty(%5d)\tn \ty(%s)\tn\r\n", ++counter, QST_DESC(rnum), QST_NUM(rnum), (is_complete(ch, QST_NUM(rnum)) ? "Yes" : "No ")); if (!counter) send_to_char(ch, "There are no quests available here at the moment.\r\n"); }
R * yield() { BOOST_ASSERT( is_running() ); BOOST_ASSERT( ! is_complete() ); flags_ &= ~flag_running; param_type to; param_type * from( reinterpret_cast< param_type * >( callee_.jump( caller_, reinterpret_cast< intptr_t >( & to), preserve_fpu() ) ) ); flags_ |= flag_running; if ( from->do_unwind) throw forced_unwind(); BOOST_ASSERT( from->data); return from->data; }
//------------------------------------------------------------------------------------------------------------- void process::get_status( bool wait ) { // must be in parent if ( is_running() && ( getpid() == parent_pid ) ) { int status = -1; int pid; if ( wait ) { pid = waitpid( child_pid, &status, 0 ); _child_state = complete; DEBUG_INFO("TH", "child process complete" ); child_pid = -1; } else { pid = waitpid( child_pid, &status, WNOHANG ); if ( pid == child_pid ) { DEBUG_INFO("TH", "child process complete" ); // we got status on something, so the process is done _child_state = complete; // close pipes child_pid = -1; close( to_pipe[ 1 ] ); close( from_pipe[ 0 ] ); } } if ( is_complete() ) { if ( WIFEXITED( status ) ) { DEBUG_INFO("TH", "child process exited exit code=: " << WEXITSTATUS( status ) << ", error= " << strerror( WEXITSTATUS( status ) ) ); _child_error = false; } else if ( WIFSIGNALED( status ) ) { DEBUG_INFO("TH", "child process killed by signal, signal=" << WTERMSIG( status ) ); _child_error = true; } } } }
/* todo: detect multiple responses */ static void pcp_resp_handler(int err, struct pcp_msg *msg, void *arg) { struct comp *comp = arg; struct mnat_media *m = comp->media; const struct pcp_map *map; if (err) { warning("pcp: mapping error: %m\n", err); complete(m->sess, err, NULL); return; } else if (msg->hdr.result != PCP_SUCCESS) { warning("pcp: mapping error: %s\n", pcp_result_name(msg->hdr.result)); re_printf("%H\n", pcp_msg_print, msg); complete(m->sess, EPROTO, "pcp error"); return; } map = pcp_msg_payload(msg); info("pcp: %s: mapping granted for %s:" " internal_port=%u, external_addr=%J (lifetime %u seconds)\n", sdp_media_name(m->sdpm), comp->id==1 ? "RTP" : "RTCP", map->int_port, &map->ext_addr, msg->hdr.lifetime); /* Update SDP media with external IP-address mapping */ if (comp->id == 1) sdp_media_set_laddr(m->sdpm, &map->ext_addr); else sdp_media_set_laddr_rtcp(m->sdpm, &map->ext_addr); comp->granted = true; m->srv_epoch = msg->hdr.epoch; is_complete(m->sess); }
R * yield_to_( Other * other, typename Other::param_type * to) { BOOST_ASSERT( ! is_complete() ); BOOST_ASSERT( is_running() ); BOOST_ASSERT( ! other->is_complete() ); BOOST_ASSERT( ! other->is_running() ); other->caller_ = caller_; flags_ &= ~flag_running; param_type * from( reinterpret_cast< param_type * >( callee_.jump( other->callee_, reinterpret_cast< intptr_t >( to), preserve_fpu() ) ) ); flags_ |= flag_running; if ( from->do_unwind) throw forced_unwind(); BOOST_ASSERT( from->data); return from->data; }
std::string combine_path(std::string const& lhs, std::string const& rhs) { TORRENT_ASSERT(!is_complete(rhs)); if (lhs.empty() || lhs == ".") return rhs; if (rhs.empty() || rhs == ".") return lhs; #ifdef TORRENT_WINDOWS #define TORRENT_SEPARATOR "\\" bool need_sep = lhs[lhs.size()-1] != '\\' && lhs[lhs.size()-1] != '/'; #else #define TORRENT_SEPARATOR "/" bool need_sep = lhs[lhs.size()-1] != '/'; #endif std::string ret; int target_size = lhs.size() + rhs.size() + 2; ret.resize(target_size); target_size = snprintf(&ret[0], target_size, "%s%s%s", lhs.c_str() , (need_sep?TORRENT_SEPARATOR:""), rhs.c_str()); ret.resize(target_size); return ret; }
static int wait_for_complete(struct loopback_test *t) { int remaining_timeouts = MAX_TIMEOUT_COUNT; char buf[MAX_SYSFS_PATH]; struct timeval timeout; fd_set read_fds; int ret; while (1) { /* Wait for change */ timeout.tv_sec = TIMEOUT_SEC; timeout.tv_usec = 0; FD_ZERO(&read_fds); FD_SET(t->inotify_fd, &read_fds); ret = select(FD_SETSIZE, &read_fds, NULL, NULL, &timeout); if (ret < 0) { fprintf(stderr, "Select error.\n"); return -1; } /* timeout - test may be finished.*/ if (!FD_ISSET(t->inotify_fd, &read_fds)) { remaining_timeouts--; if (is_complete(t)) return 0; if (!remaining_timeouts) { fprintf(stderr, "Too many timeouts\n"); return -1; } } else { /* read to clear the event */ ret = read(t->inotify_fd, buf, sizeof(buf)); } } return 0; }
int main() { // Set the number of symbols (i.e. the generation size in RLNC // terminology) and the size of a symbol in bytes uint32_t symbols = 42; uint32_t symbol_size = 100; typedef kodo::full_rlnc_encoder<fifi::binary8> rlnc_encoder; typedef kodo::full_rlnc_decoder<fifi::binary8> rlnc_decoder; // In the following we will make an encoder/decoder factory. // The factories are used to build actual encoders/decoders rlnc_encoder::factory encoder_factory(symbols, symbol_size); auto encoder = encoder_factory.build(); rlnc_decoder::factory decoder_factory(symbols, symbol_size); auto decoder = decoder_factory.build(); std::vector<uint8_t> payload(encoder->payload_size()); std::vector<uint8_t> data_in(encoder->block_size()); // Just for fun - fill the data with random data for(auto &e: data_in) e = rand() % 256; // Assign the data buffer to the encoder so that we may start // to produce encoded symbols from it encoder->set_symbols(sak::storage(data_in)); while( !decoder->is_complete() ) { // Encode a packet into the payload buffer encoder->encode( &payload[0] ); // Pass that packet to the decoder decoder->decode( &payload[0] ); } }
bool read_pkt(buf_ptr &buf_out) { buf_ptr buf_in = super::buffer(); if (!is_done() && is_partial_complete()) { get_pkt(buf_out); return true; } else if (is_done()) { increment(); return false; } while (true) { super::rlnc_hdr_reserve(buf_in); if (!super::read_pkt(buf_in)) break; if (!validate_type(buf_in)) continue; put_pkt(buf_in); process_rank(); buf_in->reset(); if (is_complete()) { send_ack(super::rlnc_hdr_block(), base::m_coder->rank()); break; } } if (!is_partial_complete()) return false; get_pkt(buf_out); return true; }
void player_activity::do_turn( player *p ) { switch( type ) { case ACT_WAIT: case ACT_WAIT_NPC: case ACT_WAIT_WEATHER: // Based on time, not speed moves_left -= 100; p->rooted(); p->pause(); break; case ACT_PICKAXE: // Based on speed, not time if( p->moves <= moves_left ) { moves_left -= p->moves; p->moves = 0; } else { p->moves -= moves_left; moves_left = 0; } activity_handlers::pickaxe_do_turn( this, p ); break; case ACT_BURROW: // Based on speed, not time if( p->moves <= moves_left ) { moves_left -= p->moves; p->moves = 0; } else { p->moves -= moves_left; moves_left = 0; } activity_handlers::burrow_do_turn( this, p ); break; case ACT_AIM: if( index == 0 ) { if( !p->weapon.is_gun() ) { // We lost our gun somehow, bail out. type = ACT_NULL; break; } g->m.build_map_cache( g->get_levz() ); g->plfire(); } break; case ACT_GAME: // Takes care of u.activity.moves_left activity_handlers::game_do_turn( this, p ); break; case ACT_VIBE: // Takes care of u.activity.moves_left activity_handlers::vibe_do_turn( this, p ); break; case ACT_REFILL_VEHICLE: type = ACT_NULL; // activity is not used anymore. break; case ACT_PULP: // does not really use u.activity.moves_left, stops itself when finished activity_handlers::pulp_do_turn( this, p ); break; case ACT_FISH: // Based on time, not speed--or it should be // (Being faster doesn't make the fish bite quicker) moves_left -= 100; p->rooted(); p->pause(); break; case ACT_DROP: activity_on_turn_drop(); break; case ACT_STASH: activity_on_turn_stash(); break; case ACT_PICKUP: activity_on_turn_pickup(); break; case ACT_MOVE_ITEMS: activity_on_turn_move_items(); break; case ACT_ADV_INVENTORY: p->cancel_activity(); advanced_inv(); break; case ACT_ARMOR_LAYERS: p->cancel_activity(); p->sort_armor(); break; case ACT_START_FIRE: moves_left -= 100; // based on time if( p->i_at( position ).has_flag( "LENS" ) ) { // if using a lens, handle potential changes in weather activity_handlers::start_fire_lens_do_turn( this, p ); } p->rooted(); p->pause(); break; case ACT_OPEN_GATE: // Based on speed, not time if( p->moves <= moves_left ) { moves_left -= p->moves; p->moves = 0; } else { p->moves -= moves_left; moves_left = 0; } break; case ACT_FILL_LIQUID: activity_handlers::fill_liquid_do_turn( this, p ); break; case ACT_ATM: iexamine::atm( *p, p->pos() ); break; case ACT_START_ENGINES: moves_left -= 100; p->rooted(); p->pause(); break; case ACT_OXYTORCH: if( p->moves <= moves_left ) { moves_left -= p->moves; p->moves = 0; } else { p->moves -= moves_left; moves_left = 0; } if( values[0] > 0 ) { activity_handlers::oxytorch_do_turn( this, p ); } break; case ACT_CRACKING: if( !( p->has_amount( "stethoscope", 1 ) || p->has_bionic( "bio_ears" ) ) ) { // We lost our cracking tool somehow, bail out. type = ACT_NULL; break; } // Based on speed, not time if( p->moves <= moves_left ) { moves_left -= p->moves; p->moves = 0; } else { p->moves -= moves_left; moves_left = 0; } p->practice( skill_id( "mechanics" ), 1 ); break; case ACT_REPAIR_ITEM: { // Based on speed * detail vision const int effective_moves = p->moves / p->fine_detail_vision_mod(); if( effective_moves <= moves_left ) { moves_left -= effective_moves; p->moves = 0; } else { p->moves -= moves_left * p->fine_detail_vision_mod(); moves_left = 0; } } break; case ACT_BUTCHER: // Drain some stamina p->mod_stat( "stamina", -20.0f * p->stamina / p->get_stamina_max() ); // Based on speed, not time if( p->moves <= moves_left ) { moves_left -= p->moves; p->moves = 0; } else { p->moves -= moves_left; moves_left = 0; } break; default: // Based on speed, not time if( p->moves <= moves_left ) { moves_left -= p->moves; p->moves = 0; } else { p->moves -= moves_left; moves_left = 0; } } if( is_complete() ) { finish( p ); } }
int ProtocolParser::process_in() { if (!is_complete()) { return Error_packet_not_complete; } switch (get_packet_type()) { case Packet_type_external_rsa_key : { c_Debug() << "process packet, type == 'Packet_type_external_rsa_key'" << "\r\n"; if (!got_rsa_key()) { // process external RSA public key if (parse_external_rsa_key_packet() == ProtocolParser::Error_no) { // send internal RSA public key std::vector<char> packet; int parse_result = prepare_rsa_internal_pub_key_packet(packet); if (parse_result == ProtocolParser::Error_no) { Net::send_data(own_node_->get_socket(), &packet[0], packet.size()); c_Debug() << "process packet, type == 'Packet_type_external_rsa_key', OK" << "\r\n"; return Error_no; } } c_Debug() << "process packet, type == 'Packet_type_external_rsa_key', Error_rsa_key_packet" << "\r\n"; return Error_rsa_key_packet; } break; } case Packet_type_login_data : { c_Debug() << "process packet, type == 'Packet_type_login_data'" << "\r\n"; if (!got_login_data_) { if (parse_login_packet() == ProtocolParser::Error_no) { // check login and passwd bool user_exist = db_.check_user_exist(login_, passwd_hash_); if (user_exist) { // get user ID by login int user_id; db_.get_user_id_by_login(&login_[0], &user_id); own_node_->set_user_id(user_id); // get node ID by name if (!node_name_.empty()) { int node_id = 0; if (db_.get_node_id_by_name(node_name_, &node_id)) { own_node_->set_node_id(node_id); } } // send login accept packet std::vector<char> accept_login_packet; prepare_packet(Packet_type_login_accept, TunnelCommon::Protocol::c_packet_login_accept, accept_login_packet); Net::send_data(own_node_->get_socket(), &accept_login_packet[0], accept_login_packet.size()); c_Debug() << "process packet, send login_accept_packet\r\n"; c_Debug() << "process packet, type == 'Packet_type_login_data', OK" << "\r\n"; return Error_no; } c_Debug() << "process packet, type == 'Packet_type_login_data', Error_parse_login_node_not_exist" << "\r\n"; return Error_parse_login_node_not_exist; } c_Debug() << "process packet, type == 'Packet_type_login_data', Error_parse_login_packet" << "\r\n"; return Error_parse_login_packet; } break; } default: { c_Debug() << "process packet, Error_unknown_packet" << "\r\n"; flush(); return Error_unknown_packet; } } flush(); return Error_no; }
int main() { //! [2] // Set the number of symbols (i.e. the generation size in RLNC // terminology) and the size of a symbol in bytes uint32_t max_symbols = 40; uint32_t max_symbol_size = 64; uint32_t object_size = 6400; //! [3] //! [4] using storage_encoder = kodo::object::storage_encoder< kodo::shallow_full_rlnc_encoder<fifi::binary>, kodo::fixed_partitioning_scheme>; using storage_decoder = kodo::object::storage_decoder< kodo::shallow_full_rlnc_decoder<fifi::binary>, kodo::fixed_partitioning_scheme>; //! [5] storage_encoder::factory encoder_factory(max_symbols, max_symbol_size); storage_decoder::factory decoder_factory(max_symbols, max_symbol_size); std::vector<uint8_t> data_out(object_size, '\0'); std::vector<uint8_t> data_in(object_size, 'x'); encoder_factory.set_storage(sak::storage(data_in)); decoder_factory.set_storage(sak::storage(data_out)); auto object_encoder = encoder_factory.build(); auto object_decoder = decoder_factory.build(); std::cout << "Object size = " << object_size << std::endl; std::cout << "Encoder blocks = " << object_encoder->blocks() << std::endl; std::cout << "Decoder blocks = " << object_decoder->blocks() << std::endl; //! [6] for (uint32_t i = 0; i < object_encoder->blocks(); ++i) { std::cout << "Block = " << i << " symbols = " << object_encoder->symbols(i) << " symbol size = " << object_encoder->symbol_size(i) << std::endl; } //! [7] for (uint32_t i = 0; i < object_encoder->blocks(); ++i) { auto e = object_encoder->build(i); auto d = object_decoder->build(i); std::vector<uint8_t> payload(e->payload_size()); while (!d->is_complete()) { e->encode( payload.data() ); // Here we would send and receive the payload over a // network. Lets throw away some packet to simulate. if (rand() % 2) { continue; } d->decode( payload.data() ); } } // Check we properly decoded the data if (data_in == data_out) { std::cout << "Data decoded correctly" << std::endl; } else { std::cout << "Unexpected failure to decode " << "please file a bug report :)" << std::endl; } }
file_handle file_pool::open_file(void* st, std::string const& p , int file_index, file_storage const& fs, int m, error_code& ec) { // potentially used to hold a reference to a file object that's // about to be destructed. If we have such object we assign it to // this member to be destructed after we release the mutex. On some // operating systems (such as OSX) closing a file may take a long // time. We don't want to hold the mutex for that. file_handle defer_destruction; mutex::scoped_lock l(m_mutex); #if TORRENT_USE_ASSERTS // we're not allowed to open a file // from a deleted storage! TORRENT_ASSERT(std::find(m_deleted_storages.begin(), m_deleted_storages.end(), std::make_pair(fs.name(), (void const*)&fs)) == m_deleted_storages.end()); #endif TORRENT_ASSERT(st != 0); TORRENT_ASSERT(is_complete(p)); TORRENT_ASSERT((m & file::rw_mask) == file::read_only || (m & file::rw_mask) == file::read_write); file_set::iterator i = m_files.find(std::make_pair(st, file_index)); if (i != m_files.end()) { lru_file_entry& e = i->second; e.last_use = aux::time_now(); if (e.key != st && ((e.mode & file::rw_mask) != file::read_only || (m & file::rw_mask) != file::read_only)) { // this means that another instance of the storage // is using the exact same file. ec = errors::file_collision; return file_handle(); } e.key = st; // if we asked for a file in write mode, // and the cached file is is not opened in // write mode, re-open it if ((((e.mode & file::rw_mask) != file::read_write) && ((m & file::rw_mask) == file::read_write)) || (e.mode & file::random_access) != (m & file::random_access)) { // close the file before we open it with // the new read/write privilages, since windows may // file opening a file twice. However, since there may // be outstanding operations on it, we can't close the // file, we can only delete our reference to it. // if this is the only reference to the file, it will be closed defer_destruction = e.file_ptr; e.file_ptr = boost::make_shared<file>(); std::string full_path = fs.file_path(file_index, p); if (!e.file_ptr->open(full_path, m, ec)) { m_files.erase(i); return file_handle(); } #ifdef TORRENT_WINDOWS if (m_low_prio_io) set_low_priority(e.file_ptr); #endif TORRENT_ASSERT(e.file_ptr->is_open()); e.mode = m; } return e.file_ptr; } lru_file_entry e; e.file_ptr = boost::make_shared<file>(); if (!e.file_ptr) { ec = error_code(ENOMEM, get_posix_category()); return e.file_ptr; } std::string full_path = fs.file_path(file_index, p); if (!e.file_ptr->open(full_path, m, ec)) return file_handle(); #ifdef TORRENT_WINDOWS if (m_low_prio_io) set_low_priority(e.file_ptr); #endif e.mode = m; e.key = st; m_files.insert(std::make_pair(std::make_pair(st, file_index), e)); TORRENT_ASSERT(e.file_ptr->is_open()); file_handle file_ptr = e.file_ptr; // the file is not in our cache if ((int)m_files.size() >= m_size) { // the file cache is at its maximum size, close // the least recently used (lru) file from it remove_oldest(l); } return file_ptr; }
int main() { char c; int max_num = MAX; init_hanoi(max_num); printf("\n\n\n\n\n\n"); printf("\t\t\t\tHanoi Game\n\t\t\t\t"); printf("Enter '<' to quit!\n\t\t\t\tEnter '>' to show cheats!\n\n"); show_hanoi(); while(!is_complete(c_top)){ while(catch_status == FALSE) { c = getch(); if(c == 'd'){ switch(now_status) { case ON_A: now_status = ON_B; break; case ON_B: now_status = ON_C; break; case ON_C: now_status = ON_A; break; } show_hanoi(); } else if(c == 'a'){ switch(now_status) { case ON_A: now_status = ON_C; break; case ON_B: now_status = ON_A; break; case ON_C: now_status = ON_B; break; } show_hanoi(); } else if(c == 's') { catch_status = TRUE; show_hanoi(); break; } else if(c == '>') { dohanoi(max_num,65,66,67); printf("\n"); show_hanoi(); break; } else if(c == '<') { printf("Game Over! Bye!\n"); exit(0); } } while(catch_status == TRUE) { c = getch(); if(c == 'd'){ switch(now_status) { case ON_A: a_to_b(); now_status = ON_B; break; case ON_B: b_to_c(); now_status = ON_C; break; case ON_C: c_to_a(); now_status = ON_A; break; } show_hanoi(); } else if(c == 'a'){ switch(now_status) { case ON_A: a_to_c(); now_status = ON_C; break; case ON_B: b_to_a(); now_status = ON_A; break; case ON_C: c_to_b(); now_status = ON_B; break; } show_hanoi(); } else if(c == 's') { catch_status = FALSE; show_hanoi(); break; } else if(c == '>') { dohanoi(max_num,65,66,67); printf("\n"); show_hanoi(); break; } else if(c == '<') { printf("Game Over! Bye!\n"); exit(0); } } } printf("Good Game! Bye!\n"); return 0; }
int main() { // Set the number of symbols (i.e. the generation size in RLNC // terminology) and the size of a symbol in bytes uint32_t max_symbols = 42; uint32_t max_symbol_size = 64; std::string encode_filename = "encode-file.bin"; // Create a test file for encoding. std::ofstream encode_file; encode_file.open (encode_filename, std::ios::binary); uint32_t file_size = 50000; std::vector<char> encode_data(file_size); std::vector<char> decode_data; // Just write some bytes to the file for(uint32_t i = 0; i < file_size; ++i) { encode_data[i] = rand() % 255; } encode_file.write(&encode_data[0], file_size); encode_file.close(); // Select the encoding and decoding algorithms typedef kodo::full_rlnc_encoder<fifi::binary> encoder_t; typedef kodo::full_rlnc_decoder<fifi::binary> decoder_t; // Now for the encoder we use a file_encoder with the chosen // encoding algorithm typedef kodo::file_encoder<encoder_t> file_encoder_t; // For decoding we use an object_decoder with the chosen // decoding algorithm typedef kodo::object_decoder<decoder_t> object_decoder_t; // Create the encoder factory - builds the individual encoders used file_encoder_t::factory encoder_factory(max_symbols, max_symbol_size); // Create the actual file encoder using the encoder factory and // the filename of the file to be encoded file_encoder_t file_encoder(encoder_factory, encode_filename); // Create the decoder factory - build the individual decoders used object_decoder_t::factory decoder_factory(max_symbols, max_symbol_size); // Create the object decoder using the decoder factory and the // size of the file to be decoded object_decoder_t object_decoder(decoder_factory, file_size); // Now in the following loop we go through all the encoders // needed to encode the entire file. We the build the corresponding // decoder and decode the chunk immediately. In practice where // encoders and decoders are on different devices e.g. connected // over a network, we would have to pass also the encoder and decoder // index between the source and sink to allow the correct data would // passed from encoder to corresponding decoder. for(uint32_t i = 0; i < file_encoder.encoders(); ++i) { auto encoder = file_encoder.build(i); auto decoder = object_decoder.build(i); // Set the encoder non-systematic if(kodo::has_systematic_encoder<encoder_t>::value) kodo::set_systematic_off(encoder); std::vector<uint8_t> payload(encoder->payload_size()); while( !decoder->is_complete() ) { // Encode a packet into the payload buffer encoder->encode( &payload[0] ); // In practice send the payload over a network, save it to // a file etc. Then when needed build and pass it to the decoder // Pass that packet to the decoder decoder->decode( &payload[0] ); } std::vector<uint8_t> data_out(decoder->block_size()); decoder->copy_symbols(sak::storage(data_out)); data_out.resize(decoder->bytes_used()); decode_data.insert(decode_data.end(), data_out.begin(), data_out.end()); } // Check we properly decoded the data if (std::equal(decode_data.begin(), decode_data.end(), encode_data.begin())) { std::cout << "Data decoded correctly" << std::endl; } else { std::cout << "Unexpected failure to decode " << "please file a bug report :)" << std::endl; } }
void generic_complete_quest(struct char_data *ch) { qst_rnum rnum; qst_vnum vnum = GET_QUEST(ch); struct obj_data *new_obj; int happy_qp, happy_gold, happy_exp; if (--GET_QUEST_COUNTER(ch) <= 0) { rnum = real_quest(vnum); if (IS_HAPPYHOUR && IS_HAPPYQP) { happy_qp = (int)(QST_POINTS(rnum) * (((float)(100+HAPPY_QP))/(float)100)); happy_qp = MAX(happy_qp, 0); GET_QUESTPOINTS(ch) += happy_qp; send_to_char(ch, "%s\r\nYou have been awarded %d quest points for your service.\r\n", QST_DONE(rnum), happy_qp); } else { GET_QUESTPOINTS(ch) += QST_POINTS(rnum); send_to_char(ch, "%s\r\nYou have been awarded %d quest points for your service.\r\n", QST_DONE(rnum), QST_POINTS(rnum)); } if (QST_GOLD(rnum)) { if ((IS_HAPPYHOUR) && (IS_HAPPYGOLD)) { happy_gold = (int)(QST_GOLD(rnum) * (((float)(100+HAPPY_GOLD))/(float)100)); happy_gold = MAX(happy_gold, 0); increase_gold(ch, happy_gold); send_to_char(ch, "You have been awarded %d gold coins for your service.\r\n", happy_gold); } else { increase_gold(ch, QST_GOLD(rnum)); send_to_char(ch, "You have been awarded %d gold coins for your service.\r\n", QST_GOLD(rnum)); } } if (QST_EXP(rnum)) { gain_exp(ch, QST_EXP(rnum)); if ((IS_HAPPYHOUR) && (IS_HAPPYEXP)) { happy_exp = (int)(QST_EXP(rnum) * (((float)(100+HAPPY_EXP))/(float)100)); happy_exp = MAX(happy_exp, 0); send_to_char(ch, "You have been awarded %d experience for your service.\r\n", happy_exp); } else { send_to_char(ch, "You have been awarded %d experience points for your service.\r\n", QST_EXP(rnum)); } } if (QST_OBJ(rnum) && QST_OBJ(rnum) != NOTHING) { if (real_object(QST_OBJ(rnum)) != NOTHING) { if ((new_obj = read_object((QST_OBJ(rnum)),VIRTUAL)) != NULL) { obj_to_char(new_obj, ch); send_to_char(ch, "You have been presented with %s%s for your service.\r\n", GET_OBJ_SHORT(new_obj), CCNRM(ch, C_NRM)); } } } if (!IS_SET(QST_FLAGS(rnum), AQ_REPEATABLE)) add_completed_quest(ch, vnum); clear_quest(ch); if ((real_quest(QST_NEXT(rnum)) != NOTHING) && (QST_NEXT(rnum) != vnum) && !is_complete(ch, QST_NEXT(rnum))) { rnum = real_quest(QST_NEXT(rnum)); set_quest(ch, rnum); send_to_char(ch, "The next stage of your quest awaits:\r\n%s", QST_INFO(rnum)); } } save_char(ch); }