/** * \brief Check if the collision is with a player. * \param that The other item of the collision. * \param info Some informations about the collision. */ void ptb::honeypot::collision_check_and_apply ( bear::engine::base_item& that, bear::universe::collision_info& info ) { player_proxy p(&that); if ( p != NULL ) { if ( !m_given ) { create_decoration(); m_given = true; level_variables::set_honeypots_found ( get_level(), level_variables::get_honeypots_found(get_level()) + 1 ); level_variables::set_honeypot_found( get_level(), m_id, true); if ( level_variables::get_honeypots_found(get_level()) % 5 == 0 ) { give_life(1); give_life(2); } on_found(p.get_index()); send_notification(p.get_index()); kill(); } else default_collision(info); } else default_collision(info); } // honeypot::collision_check_and_apply()
static void do_test(int s, struct sockaddr_in *addr) { fcntl(s, F_SETFL, fcntl(s, F_GETFL) | O_NONBLOCK); // set non-blocking while(1) { if(connect(s, (const struct sockaddr*)addr, sizeof(*addr)) == -1) { if(errno == EISCONN) break; if(errno != EINPROGRESS && errno != EALREADY) { /* filter out errors we don't care about */ if(errno != ECONNREFUSED) fprintf(stderr, "connect() failed: %s (%d)\n", strerror(errno), errno); return; } } fd_set wfds; FD_ZERO(&wfds); FD_SET(s, &wfds); struct timeval timeout = { 0, ms_timeout * 1000 }; int result = select(s+1, NULL, &wfds, NULL, &timeout); if(result == -1) { fprintf(stderr, "Error selecting on connect(): %s (%d)\n", strerror(errno), errno); return; } if(result == 0) { /* connect timed out */ return; } } /* wait for data on read */ fd_set rfds; FD_ZERO(&rfds); FD_SET(s, &rfds); struct timeval timeout = { 0, ms_timeout * 1000 }; int result = select(s+1, &rfds, NULL, NULL, &timeout); if(result == -1) { fprintf(stderr, "Error selecting on read(): %s (%d)\n", strerror(errno), errno); return; } if(result == 0) { /* read timed out */ return; } char buf[1024]; int len = read(s, buf, sizeof(buf)); if(len == 0) { /* connection returned nothing */ return; } if(len == -1) { fprintf(stderr, "Error on read(): %s (%d)\n", strerror(errno), errno); return; } buf[len] = '\0'; if(strstr(buf, "SSH-") == buf) { /* SSH found... */ uint32_t ip = (uint32_t)addr->sin_addr.s_addr; int len = snprintf(buf, sizeof(buf), "%d.%d.%d.%d\n", (ip>> 0)&0xFF, (ip>> 8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF); /* do this as syscall, to be atomic */ write(1, buf, len); buf[len-1] = '\0'; on_found(buf); }