int main(int argc, char **argv) { int sock; struct sockaddr_in cs; struct imsi *im; extern char *optarg; extern int optind, optopt; int option; char *proxy; attack_t a; a.dest = NULL; a.text = NULL; a.type = -1; while ((option = getopt(argc, argv, "hp:d:t:a:s:b")) != -1) { if (option == EOF) break; switch(option){ case 'p': proxy = optarg; break; case 'd': a.dest = optarg; break; case 't': if(strlen(optarg) >= SMS_TEXT_SIZE){ usage(argv[0], "SMS text exceeds maximum length"); } a.text = optarg; break; case 'a': if(optarg[0] == 'i'){ a.type = ATTACK_INJECT; } else if(optarg[0] == 'm'){ a.type = ATTACK_MODIFY; } else { usage(argv[0], "unknown attack"); } break; case 'h': usage(argv[0], NULL); break; case ':': fprintf(stderr, "Option -%c requires an operand\n", optopt); return -1; break; case '?': fprintf(stderr, "Unrecognized option: -%c\n", optopt); return -2; break; default: usage(argv[0], NULL); break; } } if(!proxy){ usage(argv[0], "Specify a proxy IP first...."); } if(-1 == a.type){ usage(argv[0], "Please specify attack type..."); } cs.sin_family = AF_INET; cs.sin_port = htons(UMA_PORT); cs.sin_addr.s_addr = inet_addr(proxy); if(-1 == cs.sin_addr.s_addr){ fprintf(stderr, "address conversion failed\n"); return -2; } if(-1 == (a.sock = socket(cs.sin_family, SOCK_STREAM, 0))){ perror("socket()"); return -3; } if(connect(a.sock, (struct sockaddr*) &cs, sizeof(struct sockaddr_in)) < 0){ perror("connect()"); return -4; } if(-1 == start_attack(&a)){ fprintf(stderr, "Error performing attack\n"); close(sock); return -1; } close(sock); return 0; }
void Soldier::take_hit(int attack_strength, Person* attacker_ptr) { Person::take_hit(attack_strength, attacker_ptr); start_attack(attacker_ptr); }
// Main loop the game int game_loop() { SDL_Rect dest; int x, y, aux; SDL_Event event; unsigned long t1, t2; int no_unselect = 0; // Main loop t1 = SDL_GetTicks(); while (1) { // Restart the game if (game_state.state == NEW_GAME){ if (gm == GM_MULTIPLAYER) { aux = BOARD_RESTARTED; write_socket(&aux, sizeof(int)); new_game(false, GM_MULTIPLAYER, false); } else { new_game(false, GM_SINGLE, false); } } else if (game_state.state == GAME_LOSE || game_state.state == GAME_WIN || game_state.state == GAME_EXIT) { if (gm == GM_MULTIPLAYER) { if (game_state.state == GAME_EXIT) { aux = END_GAME; write_socket(&aux, sizeof(int)); } finish_attack(game_state.state == GAME_WIN); } dest.x = 386; dest.y = 151; dest.w = dest.h = 0; if (game_state.state != GAME_EXIT) { SDL_BlitSurface(game_state.state == GAME_WIN ? win : lose, NULL, screen, &dest); SDL_Update(386, 151, 365, 178); SDL_Delay(4000); } return (game_state.state == GAME_LOSE); } if (SDL_PollEvent(&event)) { switch (event.type) { // Key pressed case SDL_KEYDOWN: if (event.key.state == SDL_PRESSED) { // Quit if (event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_BACKSPACE || event.key.keysym.sym == SDLK_F4 || event.key.keysym.sym == SDLK_F5 || event.key.keysym.sym == SDLK_F6) { game_state.state = GAME_EXIT; } } // Quit the game case SDL_QUIT: game_state.state = GAME_EXIT; break; // Window focus change #if 0 case SDL_ACTIVEEVENT: if (event.active.gain == 0 && gm != GM_MULTIPLAYER) { game_state.state = GAME_EXIT; } break; #endif // Button pressed case SDL_MOUSEBUTTONUP: case SDL_FINGERUP: no_unselect = 1; if (game_state.state == UNSELECTED_FIRST) { game_state.state = IDLE; break; } case SDL_MOUSEBUTTONDOWN: case SDL_FINGERDOWN: if (event.type == SDL_FINGERDOWN) { event.button.x = event.tfinger.x; event.button.y = event.tfinger.y; } // Diamond area if (event.button.x >= BOARD_OFFSETX && event.button.x < BOARD_WIDTH * DIAMOND_WIDTH + BOARD_OFFSETX && event.button.y >= BOARD_OFFSETY && event.button.y < BOARD_HEIGHT * DIAMOND_HEIGHT + BOARD_OFFSETY) { x = (event.button.x - BOARD_OFFSETX) / DIAMOND_WIDTH; y = (event.button.y - BOARD_OFFSETY) / DIAMOND_HEIGHT; if (game_state.state == IDLE) { game_state.state = SELECTED_FIRST; game_state.x_first = x; game_state.y_first = y; draw = true; } else if (game_state.state == SELECTED_FIRST) { if(game_state.x_first == x && game_state.y_first == y && !no_unselect) { game_state.state = UNSELECTED_FIRST; draw = true; } else if ((abs(game_state.x_first - x) == 1 && (game_state.y_first == y)) || ((game_state.x_first == x) && (abs(game_state.y_first - y) == 1))){ game_state.state = SELECTED_SECOND; game_state.x_second = x; game_state.y_second = y; draw = true; } else { game_state.x_first = x; game_state.y_first = y; draw = true; } } } else if (event.button.x >= BACK2_OFFSETX && event.button.y >= BACK2_OFFSETY && event.button.x < BACK2_OFFSETX2 && event.button.y < BACK2_OFFSETY2) { game_state.state = GAME_EXIT; break; } no_unselect = 0; break; } } // Update screen and reset timer time_tick(); if (draw_screen()) { t1 = SDL_GetTicks(); } // Calculate time and send attack for multiplayer if (gm == GM_MULTIPLAYER) { update_player(); if (ss == SS_CLOSE) { return 0; } else { t2 = SDL_GetTicks(); if (t2 - t1 >= 3500 || combo_score > 310) { t1 = t2; total_score += combo_score; // Update life if (combo_score) { if (total_score >= 1400) { total_score = 1400; game_state.state = GAME_WIN; } else start_attack(1); dest.x = LIFE_ENEMYX - total_score / 10; dest.y = LIFEY; dest.w = total_score / 10; dest.h = LIFE_HEIGHT; SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 0, 0)); SDL_Update(LIFE_ENEMYX - LIFE_WIDTH, LIFEY, LIFE_WIDTH, LIFE_HEIGHT); write_socket(&combo_score, sizeof(int)); combo_score = 0; // Erase progress bar dest.x = 21; dest.y = 335; dest.w = 311; dest.h = 36; SDL_BlitSurface(bg, &dest, screen, &dest); SDL_Update(dest.x, dest.y, dest.w, dest.h); } } } // Timer for single player } else { t2 = SDL_GetTicks(); if (t2 - t1 >= timer_delay) { t1 = t2; single_timer -= 2; if (single_timer <= 0) game_state.state = GAME_LOSE; draw_timer_bar(true); } } } }