bool Hi::Load(File* f) { if (!f->GetInteger(&m_score)) { return false; } if (!f->GetInteger(&m_level)) { return false; } if (!f->GetInteger(&m_depth)) { return false; } if (!f->GetDataLine(&m_nick)) { return false; } m_nick = DecodeStr(m_nick); if (!LoadVec3(f, &m_pos)) { return false; } return true; }
void GlobalHiScoreDb::HandleResponseFromServer(const std::string& response) { HiScoreVec vec; PXml xml = ParseXml(response.c_str()); /* Example response: <hiscores> <hi> <score>200</score> <nick>Jay</nick> <level>2</level> <depth>3</depth> <pos> <x>12</x> <y>34</y> <z>56</z> </pos> </hi> </hiscores> */ xml = xml.getChildNode("hiscores"); if (!xml.isEmpty()) { int n = xml.nChildNode(); for (int i = 0; i < n; i++) { PXml xhi = xml.getChildNode(i); if (!xhi.isEmpty()) { PXml xscore = xhi.getChildNode("score"); if (!xscore.isEmpty()) { int score = ToInt(xscore.getText()); PXml xnick = xhi.getChildNode("nick"); if (!xnick.isEmpty()) { std::string nick = xnick.getText(); PXml xlevel = xhi.getChildNode("level"); if (!xlevel.isEmpty()) { int level = ToInt(xlevel.getText()); PXml xdepth = xhi.getChildNode("depth"); if (!xdepth.isEmpty()) { int depth = ToInt(xdepth.getText()); PXml xpos = xhi.getChildNode("pos"); if (!xpos.isEmpty()) { PXml xx = xpos.getChildNode("x"); PXml xy = xpos.getChildNode("y"); PXml xz = xpos.getChildNode("z"); if (!xx.isEmpty() && !xy.isEmpty() && !xz.isEmpty()) { Vec3f pos(ToFloat(xx.getText()), ToFloat(xy.getText()), ToFloat(xz.getText())); // Nickname is stored encoded in server DB Hi hi(score, level, depth, DecodeStr(nick), pos); vec.push_back(hi); continue; } } } } } } } #ifdef _DEBUG std::cout << "ERROR (1) parsing hi scores XML from server!\n"; #endif return; } } else { #ifdef _DEBUG std::cout << "ERROR (2) parsing hi scores XML from server!\n"; #endif return; } m_global.SetVec(vec); // Save locally so we can show something if we lose connectivity later m_global.Save(FILENAME_GLOBAL); // Remove local hi scores which are in the response for (const Hi& hi : vec) { m_local.RemoveHiScore(hi); } m_local.Save(FILENAME_LOCAL); }
// Function processes command line parameters int ProcessCommandLine (int argc, char* argv[], Config& settings, char*& pInFile, char*& pOutFile, char*& pConfig) { int cmdCount = 0; char* cmdRead; while (cmdCount < argc-1) { // command line error if (cmdCount < 0) return cmdCount; // next command to process! cmdCount++; cmdRead = argv[cmdCount]; // this is a command directive if (cmdRead[0] == '-') { // upcase the command parameter StrUpr (cmdRead); cmdRead++; // miscellaneous flags, "sort +1" DecodeFlg ("BCL", settings.braceLoc, False); DecodeFlg ("BNL", settings.braceLoc, True); DecodeInt ("CC", settings.posOfCommentsWC); DecodeInt ("F", settings.numOfLineFunc); DecodeStr ("FI", pInFile); DecodeStr ("FNC", pConfig); DecodeStr ("FO", pOutFile); DecodeInt ("I", settings.tabSpaceSize); DecodeFlg ("LG", settings.deleteHighChars, 3); DecodeInt ("NC", settings.posOfCommentsNC); DecodeInt ("QB", settings.queueBuffer); DecodeFlg ("S", settings.useTabs, False); DecodeFlg ("T", settings.useTabs, True); DecodeFlg ("TBCL", settings.topBraceLoc, False); DecodeFlg ("TBNL", settings.topBraceLoc, True); // "No" flags DecodeFlg ("NA", settings.deleteHighChars, 0); DecodeFlg ("NB", settings.backUp, False); DecodeFlg ("NBBI", settings.braceIndent2, False); DecodeFlg ("NBI", settings.braceIndent, False); DecodeFlg ("NLCNC", settings.leaveCommentsNC, False); DecodeFlg ("NO", settings.output, False); DecodeFlg ("NQ", settings.quoteChars, False); // "Yes" flags DecodeFlg ("YA", settings.deleteHighChars, 1); DecodeFlg ("YB", settings.backUp, True); DecodeFlg ("YBBI", settings.braceIndent2, True); DecodeFlg ("YBI", settings.braceIndent, True); DecodeFlg ("YLCNC", settings.leaveCommentsNC, True); DecodeFlg ("YO", settings.output, True); DecodeFlg ("YQ", settings.quoteChars, True); // ### display help ### if( (strcmp ("?", cmdRead) == 0) || (strcmp ("H", cmdRead) == 0) ) { verbose ("*** Displaying Brief Help ***\n"); PrintProgramHelp (); return -1; } warning ("Unknown Command Directive %s \n", cmdRead); PrintProgramHelp (); return -1; } else if (pInFile == NULL) pInFile = argv [cmdCount]; else if (pOutFile == NULL) pOutFile = argv [cmdCount]; else { warning ("Command Line Error : Expected Command Directive, Not %s\n", argv[cmdCount]); PrintProgramHelp (); return -1; } } if (settings.queueBuffer < 2) settings.queueBuffer = 2; return 0; }