static void read_stdin( int fd, void *data ) { UNUSED( data ); char buf[ 1024 ]; memset( buf, '\0', sizeof( buf ) ); ssize_t ret = read( fd, buf, sizeof( buf ) ); if ( ret < 0 ) { if ( errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK ) { return; } set_readable( fd, false ); error( "Read error ( errno = %s [%d] ).", strerror( errno ), errno ); return; } else if ( ret == 0 ) { return; } if ( stdin_read_buffer == NULL ) { set_readable( fd, false ); error( "Read buffer is not allocated yet" ); return; } char *p = append_back_buffer( stdin_read_buffer, ( size_t ) ret ); memcpy( p, buf, ( size_t ) ret ); char *lf = find_character( stdin_read_buffer->data, stdin_read_buffer->length, '\n' ); while ( lf != NULL ) { size_t length = ( size_t ) ( lf - ( char * ) stdin_read_buffer->data ); if ( length > 0 ) { buffer *string = alloc_buffer_with_length( length ); p = append_back_buffer( string, length ); memcpy( p, stdin_read_buffer->data, length ); relay_string( string ); free_buffer( string ); remove_front_buffer( stdin_read_buffer, length + 1 ); } else { if ( stdin_read_buffer->length > 0 ) { remove_front_buffer( stdin_read_buffer, 1 ); } } if ( stdin_read_buffer->length == 0 ) { break; } lf = find_character( stdin_read_buffer->data, stdin_read_buffer->length, '\n' ); } // truncate head room manually buffer *truncated = duplicate_buffer( stdin_read_buffer ); free_buffer( stdin_read_buffer ); stdin_read_buffer = truncated; }
void srequest( Network::Client* client, PKTIN_34* msg ) { u32 serial = cfBEu32( msg->serial2 ); if ( msg->stattype == STATTYPE_STATWINDOW ) { if ( client->chr->serial == serial ) statrequest( client, serial ); else { Mobile::Character* bob = find_character( serial ); if ( bob == NULL ) return; if ( !client->chr->is_concealed_from_me( bob ) && client->chr->is_visible_to_me( bob ) ) { if ( pol_distance( client->chr->x, client->chr->y, bob->x, bob->y ) < 20 ) statrequest( client, serial ); } if ( client->chr->has_party() ) client->chr->party()->send_stat_to( client->chr, bob ); } } else if ( msg->stattype == STATTYPE_SKILLWINDOW ) skillrequest( client, serial ); }
void singleclick(Network::Client* client, u32 serial) { passert_always(client != nullptr && client->chr != nullptr); if (IsCharacter(serial)) { Mobile::Character* chr = nullptr; if (serial == client->chr->serial) chr = client->chr; else chr = find_character(serial); if (chr != nullptr && inrange(client->chr, chr) && !client->chr->is_concealed_from_me(chr)) { if (chr->has_title_guild() && (settingsManager.ssopt.core_handled_tags & 0x1)) send_nametext(client, chr, "[" + chr->title_guild() + "]"); send_nametext(client, chr, chr->name()); std::string tags = create_nametags(chr); if (!tags.empty()) send_nametext(client, chr, tags); } } else // single clicked on an item { Items::Item* item = find_legal_singleclick_item(client->chr, serial); if (item) { send_objdesc(client, item); } } }
void handle_allnames( Client *client, PKTBI_98_IN *msg ) { u32 serial = cfBEu32( msg->serial ); Character *the_mob = find_character( serial ); if (the_mob != NULL) { if (!client->chr->is_visible_to_me(the_mob)) { return; } if (pol_distance(client->chr->x, client->chr->y, the_mob->x, the_mob->y) > 20) { return; } PKTBI_98_OUT allnames; allnames.msgtype = PKTBI_98_OUT_ID; allnames.msglen = ctBEu16(0x25); // 0x25 = 37. Static Length. allnames.serial = the_mob->serial_ext; strzcpy( allnames.name, the_mob->name().c_str(), sizeof allnames.name ); transmit( client, &allnames, sizeof allnames ); } else { return; } }
void TargetCursor::handle_target_cursor( Mobile::Character* chr, PKTBI_6C* msg ) { if ( msg->selected_serial != 0 ) // targetted something { if ( chr->dead() ) // but is dead { if ( chr->client != NULL ) send_sysmessage( chr->client, "I am dead and cannot do that." ); cancel( chr ); return; } if ( ( chr->frozen() || chr->paralyzed() ) && !chr->setting_enabled( "freemove" ) ) { if ( chr->client != NULL ) { if ( chr->frozen() ) private_say_above( chr, chr, "I am frozen and cannot do that." ); else if ( chr->paralyzed() ) private_say_above( chr, chr, "I am paralyzed and cannot do that." ); } cancel( chr ); return; } u32 selected_serial = cfBEu32( msg->selected_serial ); UObject* obj = system_find_object( selected_serial ); if ( obj != NULL && obj->script_isa( POLCLASS_MOBILE ) && !obj->script_isa( POLCLASS_NPC ) ) { Mobile::Character* targeted = find_character( selected_serial ); // check for when char is not logged on if ( targeted != NULL ) { if ( !chr->is_visible_to_me( targeted ) ) { cancel( chr ); return; } if ( msg->cursor_type == 1 ) { if ( ( JusticeRegion::RunNoCombatCheck( chr->client ) == true ) || ( JusticeRegion::RunNoCombatCheck( targeted->client ) == true ) ) { send_sysmessage( chr->client, "Combat is not allowed in this area." ); cancel( chr ); return; } } } } } if ( msg->x != 0xffff || msg->selected_serial != 0 ) on_target_cursor( chr, msg ); else cancel( chr ); }
int main() { char ch='x'; char p[128]; gets(p); find_character(p,ch); return 0; }
void NoLosCharacterCursor::on_target_cursor( Mobile::Character* targetter, PKTBI_6C* msgin ) { if ( msgin == NULL ) return; u32 selected_serial = cfBEu32( msgin->selected_serial ); Mobile::Character* chr = find_character( selected_serial ); if ( chr != NULL ) ( *func )( targetter, chr ); }
UObject *find_toplevel_object( u32 serial ) { if ( IsItem( serial ) ) { return find_toplevel_item( serial ); } else { return find_character( serial ); } }
void GameMap::move_character(Character * c, Area * direction_ptr) { Area * cur_area = find_character(c); Area * new_area = direction_ptr; if (new_area != NULL){ new_area->spawn_character(c); cur_area->remove_character(c); } else { cout << "\nYou can't move any further in that direction!" << endl; } }
void handle_rename_char( Client* client, PKTIN_75* msg ) { Character* chr = find_character( cfBEu32( msg->serial )); if (chr != NULL) { if (client->chr->can_rename( chr )) { msg->name[ sizeof msg->name-1 ] = '\0'; // check for legal characters for( char* p = msg->name; *p; p++ ) { // only allow: a-z, A-Z & spaces if ( *p != ' ' && !isalpha(*p) ) { char buffer[512]; sprintf(buffer, "Client #%lu (account %s) attempted an invalid rename (packet 0x%2.02x):", client->instance_, (client->acct != NULL) ? client->acct->name() : "unknown", msg->msgtype); cout << buffer << endl; fdump( stdout, msg->name, static_cast<int>(strlen(msg->name)) ); if (logfile) { Log("%s\n", buffer); fdump( logfile, msg->name, static_cast<int>(strlen(msg->name)) ); } *p = '\0'; send_sysmessage( client, "Invalid name!" ); return; //dave 12/26 if invalid name, do not apply to chr! } } chr->setname( msg->name ); } else { send_sysmessage( client, "I can't rename that." ); } } else { send_sysmessage( client, "I can't find that." ); } }
void statrequest( Network::Client* client, u32 serial ) { if ( serial == client->chr->serial ) { send_full_statmsg( client, client->chr ); } else { Mobile::Character* chr = find_character( serial ); if ( chr != NULL ) { if ( client->chr->is_visible_to_me( chr ) ) { if ( inrange( client->chr, chr ) ) send_short_statmsg( client, chr ); } } } }
void get_character(IplImage * img) { img = cvLoadImage("img_plate_after_preprocess.bmp", -1); if (img == NULL) { fprintf(stderr, "Can not open file img_plate_after_preprocess.bmp"); exit(-1); } /*也是两个链表用来存放矩形的*/ List rects = create_list(); List rects_final = create_list(); if (img == NULL) { fprintf(stderr, "error in openning file.\n"); exit(-1); } CvMemStorage * storage = cvCreateMemStorage(0); CvSeq * contours = NULL; remove_border_ul(img); /*消除上下边界*/ IplImage * img_after_removed = cvLoadImage("img_after_border_removed.bmp", -1); if (img_after_removed == NULL) { fprintf(stderr, "Can not open file img_after_border_removed.bmp"); exit(-1); } make_border_black(img_after_removed); get_contour_rect(img_after_removed, rects, storage, contours); /*找到所有矩形*/ filter_rect_by_area(rects->next, rects_final, img_after_removed->width * img_after_removed->height); /*现在还要继续去除左右边界: 左右边界的特点是: 1.几乎全为白色点,注意1也是这样 2.面积不在1的范围之内,1的最大最小值定义在头文件中了 3.比例比1的大或小,比例也定义在头文件中了 */ rects_final = sort(rects_final); filter_rect_lr(rects_final, img_after_removed); draw_contour_rect(img_after_removed, rects_final->next); find_character(img_after_removed, rects_final); /*也没有什么好改进的地方了*/ }
void doubleclick( Network::Client* client, PKTIN_06* msg ) { u32 serial = cfBEu32( msg->serial ); u32 paperdoll_macro_flag = serial & 0x80000000Lu; serial &= ~0x80000000Lu; // keypress versus doubleclick switch? // the find_character would find this, but most of the time it's your own paperdoll. // this is special-cased for two reasons: // 1) it's commonly done // 2) ghosts can doubleclick ONLY their paperdoll. if ( serial == client->chr->serial ) { if ( !paperdoll_macro_flag ) { ScriptDef sd; sd.quickconfig( "scripts/misc/dblclickself.ecl" ); if ( sd.exists() ) { ref_ptr<Bscript::EScriptProgram> prog; prog = find_script2( sd, false, Plib::systemstate.config.cache_interactive_scripts ); if ( prog.get() != nullptr && client->chr->start_script( prog.get(), false ) ) { return; } } } send_paperdoll( client, client->chr ); return; } if ( client->chr->dblclick_wait() > read_gameclock() ) { private_say_above( client->chr, client->chr, "You must wait to use something again." ); return; } else client->chr->dblclick_wait( read_gameclock() + settingsManager.ssopt.dblclick_wait ); if ( IsCharacter( serial ) ) { if ( client->chr->dead() ) return; Mobile::Character* chr = find_character( serial ); if ( !chr ) return; if ( chr->isa( UOBJ_CLASS::CLASS_NPC ) ) { Mobile::NPC* npc = static_cast<Mobile::NPC*>( chr ); if ( npc->can_accept_event( EVID_DOUBLECLICKED ) ) { npc->send_event( new Module::SourcedEvent( EVID_DOUBLECLICKED, client->chr ) ); return; } } bool script_ran = false; ScriptDef sd; sd.quickconfig( "scripts/misc/dblclickother.ecl" ); if ( sd.exists() ) { ref_ptr<Bscript::EScriptProgram> prog; prog = find_script2( sd, false, Plib::systemstate.config.cache_interactive_scripts ); if ( prog.get() != nullptr ) script_ran = client->chr->start_script( prog.get(), false, new Module::ECharacterRefObjImp( chr ) ); } if ( !script_ran && inrange( client->chr, chr ) ) { // MuadDib Changed from a large if || || || to switch case. 1/4/2007 switch ( chr->graphic ) { case UOBJ_HUMAN_MALE: case UOBJ_HUMAN_FEMALE: case UOBJ_HUMAN_MALE_GHOST: case UOBJ_HUMAN_FEMALE_GHOST: case UOBJ_ELF_MALE: case UOBJ_ELF_FEMALE: case UOBJ_ELF_MALE_GHOST: case UOBJ_ELF_FEMALE_GHOST: case UOBJ_GARGOYLE_MALE: case UOBJ_GARGOYLE_FEMALE: case UOBJ_GARGOYLE_MALE_GHOST: case UOBJ_GARGOYLE_FEMALE_GHOST: case UOBJ_GAMEMASTER: case 0x3de: case 0x3df: case 0x3e2: send_paperdoll( client, chr ); break; } } return; } else // doubleclicked an item { // next, search worn items, items in the backpack, and items in the world. Items::Item* item = find_legal_item( client->chr, serial ); // next, check people's backpacks. (don't recurse down) // (not done yet) if ( item != nullptr ) { const Items::ItemDesc& id = item->itemdesc(); if ( !id.ghosts_can_use && client->chr->dead() ) { private_say_above( client->chr, client->chr, "I am dead and cannot do that." ); return; } if ( !id.can_use_while_frozen && client->chr->frozen() ) { private_say_above( client->chr, client->chr, "I am frozen and cannot do that." ); return; } if ( !id.can_use_while_paralyzed && client->chr->paralyzed() ) { private_say_above( client->chr, client->chr, "I am paralyzed and cannot do that." ); return; } unsigned short dst = pol_distance( client->chr, item ); if ( dst > id.doubleclick_range && !client->chr->can_dblclickany() ) { private_say_above( client->chr, item, "That is too far away." ); return; } UObject* obj = item->toplevel_owner(); obj = obj->self_as_owner(); if ( id.use_requires_los && !client->chr->realm->has_los( *client->chr, *obj ) ) // DAVE // 11/24 { private_say_above( client->chr, item, "I can't see that." ); return; } ScriptDef sd; sd.quickconfig( "scripts/misc/dblclickitem.ecl" ); if ( sd.exists() ) { ref_ptr<Bscript::EScriptProgram> prog; prog = find_script2( sd, false, Plib::systemstate.config.cache_interactive_scripts ); if ( prog.get() != nullptr ) client->chr->start_script( prog.get(), false, new Module::EItemRefObjImp( item ) ); } item->double_click( client ); return; } // allow looking into containers being traded if ( client->chr->is_trading() ) { UContainer* cont = client->chr->trade_container()->find_container( serial ); if ( cont != nullptr ) { cont->builtin_on_use( client ); if ( !cont->locked() ) { if ( client->chr->trading_with->client != nullptr ) cont->builtin_on_use( client->chr->trading_with->client ); } return; } } } }
void equip_item( Client *client, PKTIN_13 *msg ) { u32 serial = cfBEu32( msg->serial ); u8 layer = msg->layer; u32 equip_on_serial = cfBEu32( msg->equipped_on ); if ((layer > HIGHEST_LAYER) || (layer == 0) || client->chr->dead()) { send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP ); return; } Item *item = client->chr->gotten_item; if (item == NULL) { Log( "Character %08lX tried to equip item %08lx, which did not exist in gotten_items.\n", client->chr->serial, serial ); send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP ); // 5 return; } if (item->serial != serial) { Log( "Character %08lX tried to equip item %08lx, but had gotten item %08lX\n", client->chr->serial, serial, item->serial); send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP ); // 5 item->gotten_by = NULL; return; } ItemRef itemref(item); item->layer = item->tile_layer; client->chr->gotten_item->inuse(false); item->is_gotten(false); item->gotten_by = NULL; client->chr->gotten_item = NULL; Character* equip_on = NULL; if (equip_on_serial == client->chr->serial) { equip_on = client->chr; } else { equip_on = find_character( equip_on_serial ); if (equip_on == NULL || !client->chr->can_clothe( equip_on )) { send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP ); undo_get_item( client->chr, item ); return; } } if (equip_on->layer_is_equipped( item->tile_layer )) { // it appears the client already checks for this, so this code hasn't been exercised. // we'll assume client mouse holds on to object // 3D Client doesn't check for this! send_item_move_failure( client, MOVE_ITEM_FAILURE_ALREADY_WORN ); undo_get_item( client->chr, item ); //added 11/01/03 for 3d client return; } if (!equip_on->strong_enough_to_equip( item )) { send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP ); // the client now puts the item back where it was before. // return the item to wherever it was. (?) undo_get_item( client->chr, item ); if (client->chr == equip_on) { send_sysmessage( client, "You are not strong enough to use that." ); } else { send_sysmessage( client, "Insufficient strength to equip that." ); } return; } if (!equip_on->equippable( item ) || !item->check_equiptest_scripts( equip_on ) || !item->check_equip_script( equip_on, false )) { send_item_move_failure( client, MOVE_ITEM_FAILURE_ILLEGAL_EQUIP ); if(item->orphan()) { return; } undo_get_item( client->chr, item ); return; } if(item->orphan()) { return; } equip_on->equip( item ); send_wornitem_to_inrange( equip_on, item ); }