void HexarcTest (CUniverse &Universe, CXMLElement *pCmdLine) { int i, j; CString sHostspec = pCmdLine->GetAttribute(OPTION_HOST); if (sHostspec.IsBlank()) sHostspec = HOSTSPEC_DEFAULT; CHTTPClientSession Session; if (!Connect(sHostspec, Session)) return; // Read the list of high scores for (j = 0; j < 5; j++) { CJSONValue Payload = CJSONValue(CJSONValue::typeObject); Payload.InsertHandoff(FIELD_MAX_GAMES, CJSONValue(100)); CJSONValue Result; if (!ServerCommand(Session, METHOD_OPTIONS, FUNC_HIGH_SCORE_GAMES, Payload, &Result)) { printf("%s\n", Result.AsString().GetASCIIZPointer()); return; } // For each adventure, print high score if (Result.GetCount() == 0) printf("No game records.\n"); else { for (i = 0; i < Result.GetCount(); i++) { const CJSONValue &Record = Result.GetElement(i); DWORD dwAdventure = (DWORD)Record.GetElement(FIELD_ADVENTURE).AsInt32(); if (dwAdventure == 0) continue; CGameRecord GameRecord; if (GameRecord.InitFromJSON(Record) != NOERROR) { printf("Unable to parse JSON record.\n"); continue; } DWORD dwAdventureUNID = GameRecord.GetAdventureUNID(); CString sUsername = GameRecord.GetUsername(); int iScore = GameRecord.GetScore(); printf("%x %s %d\n", dwAdventureUNID, sUsername.GetASCIIZPointer(), iScore); } } } }
ALERROR CMultiverseModel::SetCollection (const CJSONValue &Data, CString *retsResult) // SetCollection // // Sets the collection from a JSON value. Caller should have called // OnCollectionLoading. { CSmartLock Lock(m_cs); int i; // Try to load the collection into a temporary array. If we get any errors // then we abort without damage. bool bErrors = false; TArray<CMultiverseCatalogEntry *> NewCollection; for (i = 0; i < Data.GetCount(); i++) { const CJSONValue &Entry = Data.GetElement(i); // If this is a game engine entry then see if it tells us to upgrade // our engine. if (strEquals(TYPE_GAME_ENGINE, Entry.GetElement(FIELD_TYPE).AsString())) { SetUpgradeVersion(Entry); continue; } // Create a catalog entry and add to our collection CMultiverseCatalogEntry *pNewEntry; if (CMultiverseCatalogEntry::CreateFromJSON(Entry, &pNewEntry, retsResult) != NOERROR) { bErrors = true; continue; } // If this entry is not valid (perhaps because it is still in // development) then ignore it. if (!pNewEntry->IsValid()) { delete pNewEntry; continue; } // Add to the new collection NewCollection.Insert(pNewEntry); } // If we had errors while loading, and we didn't load anything then abort. // Otherwise we assume that only a couple of entries were bad (possibly // because they are under development). if (bErrors && NewCollection.GetCount() == 0) { m_fLoadingCollection = false; return ERR_FAIL; } // Otherwise, replace our collection. return SetCollection(NewCollection); }