void Handle_One_Event() { static const long twentyTicks = time_in_ticks(20).asMilliseconds(); static const long fortyTicks = time_in_ticks(40).asMilliseconds(); through_sending(); Handle_Update(); //(cur_time - last_anim_time > 42) if((animTimer.getElapsedTime().asMilliseconds() >= fortyTicks) && (overall_mode != MODE_STARTUP) && (anim_onscreen) && get_bool_pref("DrawTerrainAnimation", true) && (!gInBackground)) { animTimer.restart(); draw_terrain(); } if((animTimer.getElapsedTime().asMilliseconds() > twentyTicks) && (overall_mode == MODE_STARTUP)) { animTimer.restart(); draw_startup_anim(true); } clear_sound_memory(); if(map_visible && mini_map.pollEvent(event)){ if(event.type == sf::Event::Closed) { mini_map.setVisible(false); map_visible = false; } else if(event.type == sf::Event::GainedFocus) makeFrontWindow(mainPtr); } if(!mainPtr.pollEvent(event)) { if(changed_display_mode) { changed_display_mode = false; adjust_window_mode(); } flushingInput = false; redraw_screen(REFRESH_NONE); return; } switch(event.type) { case sf::Event::KeyPressed: if(flushingInput) return; if(!(event.key.*systemKey)) handle_keystroke(event); break; case sf::Event::MouseButtonPressed: if(flushingInput) return; Mouse_Pressed(); break; case sf::Event::MouseLeft: // Make sure we don't have an arrow cursor when it's outside the window make_cursor_sword(); break; case sf::Event::GainedFocus: Handle_Update(); makeFrontWindow(mainPtr); case sf::Event::MouseMoved: if(!gInBackground) { location where(event.mouseMove.x, event.mouseMove.y); change_cursor(where); } break; case sf::Event::MouseWheelMoved: if(flushingInput) return; handle_scroll(event); break; case sf::Event::Closed: if(overall_mode == MODE_STARTUP) { if(party_in_memory) { std::string choice = cChoiceDlog("quit-confirm-save", {"save","quit","cancel"}).show(); if(choice == "cancel") break; if(choice == "save") { fs::path file = nav_put_party(); if(!file.empty()) break; save_party(file, univ); } } All_Done = true; break; } if(overall_mode > MODE_TOWN){ std::string choice = cChoiceDlog("quit-confirm-nosave", {"quit", "cancel"}).show(); if(choice == "cancel") break; } else { std::string choice = cChoiceDlog("quit-confirm-save", {"save", "quit", "cancel"}).show(); if(choice == "cancel") break; if(choice == "save") save_party(univ.file, univ); } All_Done = true; default: break; // There's several events we don't need to handle at all } flushingInput = false; // TODO: Could there be a case when the key and mouse input that needs to be flushed has other events interspersed? }
int bbgp() { unsigned char buf[BGP_SIZE]; struct bgp *bgp_hdr; int n; // handle the open negotiations if (handle_bgp_open()) { // return if they fail return(0); } // send our update with our one route if (Send_Update()) { return(0); } // established loop while ((n = read(STDIN_FILENO, buf, BGP_SIZE)) == BGP_SIZE) { // handle update/notification/keepalive messages bgp_hdr = (struct bgp *)buf; switch(bgp_hdr->bgp_type) { case BGP_NOTIFICATION: // if (debug) fprintf(stderr,"Received BGP Notification\n"); // pass this off to the notification message handler if (Handle_Notify(bgp_hdr->bgp_len)) { return (-1); } break; case BGP_KEEPALIVE: // if (debug) fprintf(stderr,"Received BGP Keepalive\n"); // make sure the keepalive is of valid length if (bgp_hdr->bgp_len != htons(BGP_SIZE)) { bgp_send_notification(BGP_NOTIFY_MAJOR_MSG, BGP_NOTIFY_MINOR_MSG_LEN); return(-1); } // store the time when we received this peer.last_ack = time(NULL); // if (debug) print_rib(); break; case BGP_UPDATE: // pass this off to the update message handler // if (debug) fprintf(stderr,"Received BGP Update length %d\n", ntohs(bgp_hdr->bgp_len)); if (Handle_Update(ntohs(bgp_hdr->bgp_len))) { return(-1); } break; default: // invalid type // if (debug) fprintf(stderr,"Received invalid message type (%d)\n", bgp_hdr->bgp_type); bgp_send_notification(BGP_NOTIFY_MAJOR_MSG, BGP_NOTIFY_MINOR_MSG_TYPE); return(-1); } } // if we got here, the while loop received an invalid length bgp packet // if (debug) fprintf(stderr,"Received invalid length (%d) packet, errno: %s\n", n, sys_errlist[errno]); fflush(stderr); bgp_send_notification(BGP_NOTIFY_MAJOR_MSG, BGP_NOTIFY_MINOR_MSG_LEN); return(-1); }