예제 #1
0
void ReqGetNewMsgs::OnSuccess()
{
  PXml p = m_xml.getChildNode(0);
  Assert(SafeStrCmp(p.getName(), "now"));
  timestamp = p.getText();

  p = m_xml.getChildNode(1);
  if (SafeStrCmp(p.getName(), "msgs"))
  {
    int numMsgs = p.nChildNode();
    for (int i = 0; i < numMsgs; i++)
    {
      PXml msg = p.getChildNode(i);

      int id = atoi(msg.getChildNode(0).getText());
      int senderId = atoi(msg.getChildNode(1).getText());
      timestamp = msg.getChildNode(2).getText();
      Timestamp whenSent = atoi(timestamp.c_str());
      std::string text = msg.getChildNode(3).getText();
      text = DecodeMsg(text); ////Replace(text, "_", " "); // replace underscores with spaces -- TODO punctuation 
      int recipId = atoi(msg.getChildNode(4).getText());

std::cout << "GOT NEW MSG!! ID: " << id << " sender: " << senderId << " sent: " << whenSent.ToString() << " text: " << text << "\n";

      TheMsgManager::Instance()->QueueMsg(MsgManager::Msg(id, text, senderId, recipId, whenSent));
    }
  }
  else
  {
    ShowError("Unexpected format for msgs response");
  }
}
예제 #2
0
void FileUpdater::OnSuccess()
{
  // Do nothing if GSFileUpdateCheck is no longer the current state - this means we chose
  //  to skip this check.
  // TODO
  if (TheGame::Instance()->GetState() != TheGSFileUpdateCheck::Instance())
  {
std::cout << "SKIPPED FILE UPDATE CHECK, SO IGNORING SERVER RESPONSE!!\n";
    return;
  }

  PXml p = m_xml.getChildNode(1);
  if (SafeStrCmp(p.getName(), "files"))
  {
#ifdef XML_DEBUG
std::cout << "Found files element\n";
#endif

    // Get children - each child is of form <file>$filename</file>. Delete each file(!)
    int num = p.nChildNode();
std::cout << num << "children\n";
    for (int i = 0; i < num; i++)
    {
      PXml child = p.getChildNode(i);
      if (!SafeStrCmp(child.getName(), "file"))
      {
std::cout << "Got 'files' but no 'file' child\n";
        OnFailure();
      }
      std::string f = child.getText();
      std::string full = File::GetRoot() + f;

std::cout << "DELETE THIS FILE: \"" << full << "\"\n";
      if (AmjuDeleteFile(full))
      {
std::cout << " -- succeeded!\n";
      }
      else
      {
std::cout << " -- failed!\n"; 
      }
      // TODO and tell ObjectManager/ObjectUpdater to remove info about this file from their caches!

    } 
    // Done - now prod ObjectManager to get new files
std::cout << "Have finished deleting updated files, now need to download new versions!\n";

    TheGSFileUpdateCheck::Instance()->OnFinishedChecking(m_timestamp);
  }
  else
  {
    OnFailure();
  }

}
hsBool  plDynSurfaceWriter::plWinSurface::FontMatches( const char *face, uint16_t size, uint8_t flags, hsBool aaRGB )
{
    if( SafeStrCmp( face, fFontFace ) == 0 && fFontSize == size && 
        fFontFlags == flags && fFontAntiAliasRGB == aaRGB )
        return true;
    
    return false;
}
예제 #4
0
void PosUpdateReq::OnSuccess()
{
  // Child 0 is timestamp
//  PXml p = m_xml.getChildNode(0);
//  Assert(SafeStrCmp(p.getName(), "now"));
//  std::string timestamp = p.getText();
//std::cout << "Got new pos update timestamp: " << timestamp << "\n";

  TheObjectUpdater::Instance()->SetTimestampPos(m_timestamp);

  PXml p = m_xml.getChildNode(1);
  if (SafeStrCmp(p.getName(), "objs"))
  {
#ifdef XML_DEBUG
std::cout << "found objs element\n";
#endif

    int numObjs = p.nChildNode();

#ifdef XML_DEBUG
if (numObjs > 0)
{
  std::cout << "PosUpdateReq: got " << numObjs << " positions.\n";
}
#endif

    for (int i = 0; i < numObjs; i++)
    {
      PXml obj = p.getChildNode(i);

#ifdef XML_DEBUG
std::cout << "Obj " << i << ": ";
#endif

      int id = ToInt(obj.getChildNode(0).getText());
      float x = ToFloat(obj.getChildNode(1).getText());
      float y = ToFloat(obj.getChildNode(2).getText());
      float z = ToFloat(obj.getChildNode(3).getText());
      int location = atoi(obj.getChildNode(4).getText());

//std::cout << "##@@## Got msg from server, Queueing pos for object " << id << " location: " << location << " x: " << x << " y: " << y << " z: " << z << "\n";

      TheObjectUpdater::Instance()->QueueUpdatePos(id, Vec3f(x, y, z), location);
    }
  }
  else
  {
    // Unexpected response from server. Is server reachable ?
    // TODO LOG this error
    ShowError("Pos update: Didn't find \"objs\" tag in response");
  }
}
예제 #5
0
  virtual void OnSuccess()
  {
    // Add each new object to ObjectManager, as it now needs to download all associated assets, 
    //  then create the new object locally.

#ifdef OBJECT_CHECK_DEBUG
std::cout << "Got successful response to object check request!\n";
#endif

    // Format of XML:
    // <now/>           <- Child(0)
    // <objs>            <- Child(1)
    //  <obj>            <- Child(1)->Child(n)
    //   <id/>           <- Child(1)->Child(n)->Child(0) etc
    //   <type/>
    //   <assetfile/>
    //   <owner/>
    //   <createtime/>
    //  </obj>
    // <objs>

    PXml p = m_xml.getChildNode(0);
    Assert(SafeStrCmp(p.getName(), "now"));
    std::string timestamp = p.getText();

    TheObjectManager::Instance()->SetTimestamp(timestamp);

    p = m_xml.getChildNode(1);
    if (SafeStrCmp(p.getName(), "objs"))
    {
#ifdef XML_DEBUG
std::cout << "found objs element\n";
#endif

      int numObjs = p.nChildNode();

      for (int i = 0; i < numObjs; i++)
      {
        PXml obj = p.getChildNode(i);

#ifdef XML_DEBUG
std::cout << "Obj " << i << ": ";
#endif

        int id = atoi(obj.getChildNode(0).getText());
        std::string type = obj.getChildNode(1).getText();
        std::string assetfile = obj.getChildNode(2).getText();
        std::string datafile = obj.getChildNode(3).getText();
        int owner = atoi(obj.getChildNode(4).getText());

#ifdef XML_DEBUG
std::cout << " ID: " << id << ": ";
std::cout << " Type: " << type << "\n";
#endif

//std::cout << "NEW OBJECT! ID: " << id << " Type: " << type << " Asset file: " << assetfile << " Data file: " << datafile << " Owner: " << owner << "\n";

        TheObjectManager::Instance()->AddObject(new Object(id, owner, type, assetfile, datafile));
      }
    }
    else
    {
      // Unexpected response from server. Is server reachable ?
      // TODO LOG this error
      ShowError("Didn't find \"objs\" tag in response");
    }
  } 
예제 #6
0
void Ve1Req::HandleResult()
{
  m_errorStr.clear();

  bool success = false;

  const HttpResult& res = GetResult();
  if (res.GetSuccess())
  {
    const std::string& str = res.GetString();
    m_xml = ParseXml(str.c_str());

    // For all responses, Child 0 is current server time

    PXml p = m_xml.getChildNode(0);
    if (SafeStrCmp(p.getName(), "now"))
    {
      m_timestamp = p.getText();

      // TODO More checking
      success = true;
    }
    else
    {
      // TODO Get HTTP code
      m_errorStr = m_name + ": Didn't get time stamp in result: " + str;
    }

    if (m_xml.nChildNode() > 1) 
    {
      p = m_xml.getChildNode(1);
      if (SafeStrCmp(p.getName(), "error"))
      {
        m_errorStr = p.getText();
        success = false;
      }
      m_errorCode = "";
      // Check for <errorcode>
      if (m_xml.nChildNode() > 2)
      {
        p = m_xml.getChildNode(1);
        if (SafeStrCmp(p.getName(), "errorcode"))
        {
          m_errorCode = p.getText();
        }
      }
    }
  }
  else
  {
    //m_errorStr = res.GetErrorString();
    m_errorStr = "I don't seem to be able to go online. Is your internet connection working?";
  }

  if (success)
  {
    OnSuccess();
  }
  else
  {
    OnFailure();
  }
}
예제 #7
0
void ReqLogin::OnSuccess()
{
  // Check for session ID or login failure
  TheVe1ReqManager::Instance()->SetLoggedIn(false);

  // Format of XML:
  // <session/>           <- Child(1)

  PXml p = m_xml.getChildNode(1);
  if (SafeStrCmp(p.getName(), "session"))
  {
#ifdef XML_DEBUG
std::cout << "found session element\n";
#endif

    std::string sessionId = p.getText();
    std::string playername;
    int objId = -1; // object ID for local player

    // Get player name and object ID for local player
    p = m_xml.getChildNode(2);
    if (SafeStrCmp(p.getName(), "playername"))
    {
      playername = p.getText();
std::cout << "**Got player name! \"" << playername << "\"\n";
    }
    else
    {
      // Got session ID but no player name, WTF ?
std::cout << "Got session ID but no player name, WTF??\n";
    }

    p = m_xml.getChildNode(3);
    if (SafeStrCmp(p.getName(), "objid"))
    {
      objId = ToInt(p.getText());
std::cout << "**Got local player object ID: " << objId << "\n";
    }
    else
    {
        // Got session ID but we don't know the object ID for the local player. WTF ?
std::cout << "Got session ID but we don't know the object ID for the local player. WTF?\n";
    }

    p = m_xml.getChildNode(4);
    if (SafeStrCmp(p.getName(), "loc"))
    {
      int loc = ToInt(p.getText());
      // TODO Use ResetLocalPlayer() to set start pos/loc ?????
      TheGSStartGame::Instance()->SetStartLoc(loc); 
std::cout << "Got start location: " << loc << "\n";
    }
    else
    {
      // Reset here to well known start location.
      ResetLocalPlayer();
std::cout << "No start location.\n";
    }

    std::cout << "Got session ID! " << sessionId << "\n"; 

    TheVe1ReqManager::Instance()->SetSessionId(sessionId);
    TheVe1ReqManager::Instance()->SetLoggedIn(true);

    // Check if we are set up
    std::string playerInfoFilename = playername + ".txt";
    // TODO Sanitise the filename

    ThePlayerInfoManager::Instance()->SetCurrentPlayer(playerInfoFilename);
    ThePlayerInfoManager::Instance()->Save();

    PlayerInfo* pi = ThePlayerInfoManager::Instance()->GetPI(); 

    pi->PISetInt(PI_KEY("player obj id"), objId);
    pi->PISetString(PI_KEY("playername"), playername);
    pi->PISetString(PI_KEY("email"), m_email);
    pi->Save();

    // Set options for this player
    TheGSOptions::Instance()->LoadSettingsFromPI(pi);

    // TODO Do we need to set this via ObjectUpdater too, so it gets sent to all clients ?

    // Set ID of this player object as the local player ID
    SetLocalPlayerId(objId);

    Assert(pi);

    // Play happy logged in sound
    TheSoundManager::Instance()->PlayWav("Sound/button112.wav");

    if (GetGameMode() == AMJU_MODE_EDIT)
    {
      TheGame::Instance()->SetCurrentState(TheGSStartGame::Instance());
    }
    else
    {
      // Handle research info: session, mode, etc.
      ChooseMode();
    }
  }
  else
  {
std::cout << "Didn't get sesssion ID from server :-(\n";
    TheGSLoginWaiting::Instance()->SetErrorString("Didn't get session ID from server");
  }
}
예제 #8
0
void ReqLogin::ChooseMode()
{
  TheResearchCalendar::Instance()->Clear();

  GameMode gm = AMJU_MODE_NO_GAME;
  bool doCogTests = false;

  PXml research = m_xml.getChildNode(5);
  if (SafeStrCmp(research.getName(), "research"))
  {
    // Schedule - for calendar
    PXml p = research.getChildNode(4);
    if (SafeStrCmp(p.getName(), "dates"))
    {
      Time today(Time::Now());
      today.RoundDown(TimePeriod(ONE_DAY_IN_SECONDS));

      // Bunch of dates - add to TheResearchCal
      int numDates = p.nChildNode();
      for (int i = 0; i < numDates; i++)
      {
        PXml date = p.getChildNode(i);
        if (SafeStrCmp(date.getName(), "date"))
        {
          if (SafeStrCmp(date.getChildNode(0).getName(), "timestamp") &&
              SafeStrCmp(date.getChildNode(1).getName(), "cogtest") &&
              SafeStrCmp(date.getChildNode(2).getName(), "play"))
          {
            std::string dateStr = date.getChildNode(0).getText();
            bool cogtest = SafeStrCmp(date.getChildNode(1).getText(), "1"); 
            bool play = SafeStrCmp(date.getChildNode(2).getText(), "1"); 

            Time t(dateStr);
            t.RoundDown(TimePeriod(ONE_DAY_IN_SECONDS));
            if (t == today)
            {
              // Cog tests already done today ?
              Results results = TheCogTestResults::Instance()->GetResultsForDate(Time::Now());
              if (results.empty())
              {
                doCogTests = cogtest;
              }
              else
              {
                doCogTests = false;
                std::cout << "Test results for today are here already.\n";
              }

              if (play)
              { 
                gm = AMJU_MODE_MULTI;
              }
              if (doCogTests && !play)
              {
                // Create dummy target for heart count, etc
                CreateDummyLocalPlayer();
              }
            }
            TheResearchCalendar::Instance()->AddResearchDate(ResearchDate(Time(dateStr), cogtest, play));   
          }
          else
          {
            std::cout << "Login: unexpected format for session dates.\n";
            Assert(0);
          }
        }
      }
    }
    else
    {
      std::cout << "Login: found research element but no schedule.\n";
    }
  }
  else
  {
    std::cout << "No research element in login.pl response?!?\n";
    Assert(0);
  }

  // Now we can look up today on the calendar to get game mode flags.

  ResetLocalPlayerFuelCount();

  SetGameMode(gm); // TODO handle edit mode - send extra flag to login.pl ??

  SetDoCogTests(doCogTests); // mode, in GameMode

  TheGSCalendar::Instance()->SetPrevState(TheGSToday::Instance());
  TheGSThanks::Instance()->SetPrevState(TheGSToday::Instance());
  TheGame::Instance()->SetCurrentState(TheGSThanks::Instance());
  TheGSMain::Instance()->ResetHud();
}