예제 #1
0
파일: time.cpp 프로젝트: Arnaud474/Warmux
void GameTime::Reset()
{
  current_time = 0;
  waiting_for_user = false;
  waiting_for_network = false;
  if (IsLOGGING("extra_slow")) {
    stopwatch.Reset(0.1);
  } else if (IsLOGGING("slow")) {
    stopwatch.Reset(0.25);
  } else {
    stopwatch.Reset();
  }
}
예제 #2
0
bool Downloader::TwitterLogin(const std::string& user, const std::string& pwd)
{
  if (twitter_logged)
    return true;
  std::string html, fields;

  twitter_logged = false;
  if (!GetUrl("http://mobile.twitter.com/session/new", &html)) {
    goto end;
  }
  MSG_DEBUG("downloader", "Login connect success!");

  // Find authenticity_token value
  if (!FindNameValue(auth, "authenticity_token", html)) {
    error = _("Can't find authenticity_token");
    goto end;
  }
  MSG_DEBUG("downloader", "authenticity_token=%s", auth.c_str());

  html.clear();

  fields = "authenticity_token=" + auth + "&username="******"&password="******"downloader", "Fields: %s\n", fields.c_str());
  if (!Post("http://mobile.twitter.com/session", &html, fields)) {
    goto end;
  }
#if 0
  if (html.find("class=\"warning\"") != std::string::npos) {
    printf("Login failed, probably incorrect credentials\n");
    goto end;
  }
#endif
  MSG_DEBUG("downloader", "Login success!\n");
  
  html.clear();

  twitter_logged = true;

end:
  if (!twitter_logged && IsLOGGING("download")) {
    FILE *f = fopen("out.htm", "wt");
    fwrite(html.c_str(), html.size(), 1, f);
    fclose(f);
    MSG_DEBUG("downloader", "Login failed: %s\n", error.c_str());
  }

  return twitter_logged;
}
예제 #3
0
void Construct::Draw()
{
  Weapon::Draw();

  if (EnoughAmmo()
      && EnoughAmmoUnit()
      && !Interface::GetInstance()->weapons_menu.IsDisplayed()
      && Interface::GetInstance()->IsDisplayed()
      && Network::GetInstance()->IsTurnMaster()) {

    dst = Mouse::GetInstance()->GetWorldPosition();
    construct_spr->SetRotation_rad(angle);
    construct_spr->Draw(dst - construct_spr->GetSize() / 2);

#ifdef DEBUG
    if (IsLOGGING("test_rectangle")) {
      Rectanglei test_rect(dst - construct_spr->GetSizeMax() / 2, construct_spr->GetSizeMax());
      test_rect.SetPosition(test_rect.GetPosition() - Camera::GetInstance()->GetPosition());
      GetMainWindow().RectangleColor(test_rect, primary_red_color, 1);
    }
#endif
  }
}
예제 #4
0
bool Downloader::FacebookLogin(const std::string& email, const std::string& pwd)
{
  if (fb_logged)
    return true;
  std::string html, fields;

  fb_logged = false;
  if (!GetUrl("http://m.facebook.com/login.php?http&refsrc=http%3A%2F%2Fm.facebook.com%2F&no_next_msg&refid=8", &html)) {
    goto end;
  }
  MSG_DEBUG("downloader", "Login connect success!");
  
  // Find m_ts value
  if (!FindNameValue(m_ts, "m_ts", html)) {
    error = "Can't find m_ts";
    goto end;
  }
  MSG_DEBUG("downloader", "m_ts=%s", m_ts.c_str());

  // Find post_form_id value
  if (!FindNameValue(post_form_id, "post_form_id", html)) {
    error = "Can't find post_form_id";
    goto end;
  } 
   MSG_DEBUG("downloader", "post_form_id=%s", post_form_id.c_str());
  
  // Find form
  if (!FindPair(form, "action", "id=\"login_form\"", html)) {
    error = "Can't find form";
    goto end;
  } 
  MSG_DEBUG("downloader", "form=%s", form.c_str());

  html.clear();

  form = "http://m.facebook.com" + form;
  fields = "lsd=&post_form_id=" + post_form_id +
           "&version=1&ajax=0&pxr=0&gps=0&email=" + UrlEncode(email) +
           "&pass="******"&m_ts=" + m_ts + "&login=Login";
  MSG_DEBUG("downloader", "Fields: %s\n", fields.c_str());
  if (!Post(form.c_str(), &html, fields.c_str())) {
    goto end;
  }
  if (html.find("abb acr aps") != std::string::npos) {
    error = _("Login error, probably invalid email or password");
    goto end;
  }
  MSG_DEBUG("downloader", "Login success!\n");

  // Find form
  if (!FindPair(form, "action", "id=\"composer_form\"", html)) {
    error = "Can't find form";
    goto end;
  } 
  MSG_DEBUG("downloader", "form=%s", form.c_str());
  
  // Find fb_dtsg
  if (!FindNameValue(fb_dtsg, "fb_dtsg", html)) {
    error = "Can't find fb_dtsg";
    goto end;
  } 
  MSG_DEBUG("downloader", "fb_dtsg=%s", fb_dtsg.c_str());

  // Find post_form_id value
  if (!FindNameValue(post_form_id, "post_form_id", html)) {
    error = "Can't find post_form_id";
    goto end;
  } 
  MSG_DEBUG("downloader", "post_form_id=%s", post_form_id.c_str());
  
  form = "http://m.facebook.com" + form;
  html.clear();

  fb_logged = true;

end:
  if (!fb_logged && IsLOGGING("download")) {
    FILE *f = fopen("out.htm", "wt");
    fwrite(html.c_str(), html.size(), 1, f);
    fclose(f);
    MSG_DEBUG("downloader", "Login failed: %s\n", error.c_str());
  }

  return fb_logged;
}
예제 #5
0
파일: keyboard.cpp 프로젝트: fluxer/warmux
bool Keyboard::HandleKeyEvent(const SDL_Event& evnt)
{
  // Not a registred event
  if (!IsRegistredEvent(evnt.type))
    return false;

  Key_Event_t event_type;
  switch(evnt.type) {
  case SDL_KEYDOWN:
    event_type = KEY_PRESSED;
    break;
  case SDL_KEYUP:
    event_type = KEY_RELEASED;
    break;
  default:
    return false;
  }

  //Handle input text for Chat session in Network game
  if (Game::GetInstance()->chatsession.CheckInput()) {
    if (event_type == KEY_PRESSED)
      Game::GetInstance()->chatsession.HandleKeyPressed(evnt);
    else if (event_type == KEY_RELEASED)
      Game::GetInstance()->chatsession.HandleKeyReleased(evnt);
    return false;
  }

  SDLKey basic_key_code = evnt.key.keysym.sym;

#ifdef DEBUG
  if (IsLOGGING("killsynchro")
      && basic_key_code == SDLK_k
      && event_type == KEY_RELEASED) {
    fprintf(stderr, "\n\nKILLING NETWORK SYNCHRONISATION!\n\n");
    RandomSync().SetSeed(0);
  }
#endif

  // Also ignore real key code of a modifier, fix bug #15238
  if (IsModifier(basic_key_code)) {
    int modifier_changed = modifier_only_bits ^ GetModifierBits();
    if (event_type == KEY_RELEASED) {
      for (std::set<SDLKey>::const_iterator it = pressed_keys.begin(); it != pressed_keys.end(); it++ ) {
        int key_code = *it + MODIFIER_OFFSET * modifier_changed;
        HandleKeyComboEvent(key_code, KEY_RELEASED);
      }
    } else if (modifier_only_bits && event_type == KEY_PRESSED) {
      for (std::set<SDLKey>::const_iterator it = pressed_keys.begin(); it != pressed_keys.end(); it++ ) {
        int key_code = *it + MODIFIER_OFFSET * modifier_only_bits;
        HandleKeyComboEvent(key_code, KEY_RELEASED);
      }
    }
    modifier_only_bits = GetModifierBits();
    return false;
  }
#ifdef MAEMO
  if (SDL_GetModState() & KMOD_MODE) {
    if (basic_key_code == SDLK_LEFT) basic_key_code = SDLK_UP;
    if (basic_key_code == SDLK_RIGHT) basic_key_code = SDLK_DOWN;
  }
#endif

  int key_code;
  int previous_modifier_bits = modifier_bits;
  modifier_bits = GetModifierBits();

  if (modifier_bits != previous_modifier_bits) {
    std::set<SDLKey>::const_iterator it = pressed_keys.find(basic_key_code);
    if (it !=  pressed_keys.end()) {
      key_code = basic_key_code + MODIFIER_OFFSET * previous_modifier_bits;
      HandleKeyComboEvent(key_code, KEY_RELEASED);
      if (key_code != basic_key_code)
        HandleKeyComboEvent(basic_key_code, KEY_RELEASED);
      pressed_keys.erase(basic_key_code);
      if (event_type == KEY_PRESSED) {
        key_code = basic_key_code + MODIFIER_OFFSET * modifier_bits;
        HandleKeyComboEvent(key_code, KEY_PRESSED);
        pressed_keys.insert(basic_key_code);
      }
      return true;
    }
  }

  if (event_type == KEY_PRESSED) {
    key_code = basic_key_code + (MODIFIER_OFFSET * modifier_bits);
    HandleKeyComboEvent(key_code, KEY_PRESSED);
    if (previous_modifier_bits ^ modifier_bits) {
      key_code = basic_key_code + (MODIFIER_OFFSET * previous_modifier_bits);
      HandleKeyComboEvent(key_code, KEY_RELEASED);
    }
    pressed_keys.insert(basic_key_code);
  } else {
    ASSERT(event_type == KEY_RELEASED);
    key_code = basic_key_code + (MODIFIER_OFFSET * previous_modifier_bits);
    HandleKeyComboEvent(key_code, KEY_RELEASED);
    if (key_code != basic_key_code)
      HandleKeyComboEvent(basic_key_code, KEY_RELEASED);
    pressed_keys.erase(basic_key_code);
  }
  return true;
}
예제 #6
0
파일: weapon.cpp 프로젝트: yeKcim/warmux
void Weapon::Draw(){
  if (Game::GetInstance()->ReadState() != Game::PLAYING &&
      m_last_fire_time + 100 < Time::GetInstance()->Read())
    return;

#ifndef DEBUG_HOLE
  if (m_last_fire_time + m_fire_remanence_time > Time::GetInstance()->Read())
#endif
    DrawWeaponFire();

  DrawAmmoUnits();

  ASSERT(drawable || !ShouldBeDrawn());
  if (!(drawable && ShouldBeDrawn()))
    return;

  if (ActiveCharacter().IsGhost()
      || ActiveCharacter().IsDrowned()
      || ActiveCharacter().IsDead())
    return;

  // rotate weapon if needed
  if (!EqualsZero(min_angle - max_angle)) {
    if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT)
      m_image->SetRotation_rad(ActiveCharacter().GetFiringAngle());
    else
      m_image->SetRotation_rad(ActiveCharacter().GetFiringAngle()-PI);
  } else {
    m_image->SetRotation_rad(ZERO);
  }

  // flip image if needed
  if (use_flipping) {
    m_image->SetFlipped(DIRECTION_LEFT == ActiveCharacter().GetDirection());
  }

  // Calculate position of the image
  int x,y;
  PosXY (x, y);

  // Animate the display of the weapon:
  if (m_time_anim_begin + ANIM_DISPLAY_TIME > Time::GetInstance()->Read()) {
    if (!EqualsZero(min_angle - max_angle)) {
      Double angle = m_image->GetRotation_rad();
      angle += sin(HALF_PI * Double(Time::GetInstance()->Read() - m_time_anim_begin) / ANIM_DISPLAY_TIME)
             * TWO_PI;
      m_image->SetRotation_rad(angle);
      m_image->Scale(ONE, ONE);
    }
    else {
      Double scale = sin((Double)1.5 * HALF_PI * Double(Time::GetInstance()->Read() - m_time_anim_begin) / ANIM_DISPLAY_TIME)
                   / sin((Double)1.5 * HALF_PI);
      if (scale.IsNotZero()) {
        m_image->Scale(scale, scale);
        m_image->SetFlipped(DIRECTION_LEFT == ActiveCharacter().GetDirection());
      }

      // Recompute position to get the icon centered over the skin
      if (origin == weapon_origin_OVER)
        PosXY(x,y);
    }
  } else
    m_image->Scale(ONE, ONE);

  if (m_image)
    m_image->Blit(GetMainWindow(), Point2i(x, y) - Camera::GetInstance()->GetPosition());

#ifdef DEBUG
  if (IsLOGGING("weapon")) {
    Point2i hand;
    ActiveCharacter().GetHandPosition(hand);
    Rectanglei rect(hand - 1 - Camera::GetInstance()->GetPosition(),
                    Point2i(3, 3));

    GetWorld().ToRedrawOnMap(rect);

    GetMainWindow().RectangleColor(rect, c_red);

    MSG_DEBUG("weapon.handposition", "Position: %d, %d - hand: %d, %d",
              ActiveCharacter().GetX(), ActiveCharacter().GetY(),
              hand.GetX(), hand.GetY());
  }
  if (IsLOGGING("weapon.hole")) {
    Rectanglei rect(GetGunHolePosition() - Camera::GetInstance()->GetPosition() - 1,
                    Point2i(3, 3));
  
    GetWorld().ToRedrawOnMap(rect);
    GetMainWindow().RectangleColor(rect, c_red);
  }
#endif
}