TEG_STATUS xmlscores_load( void ) { char filename[512]; xmlDocPtr doc; xmlNodePtr cur; PSCORES curscore; /* * build an XML tree from the file; */ snprintf( filename, sizeof(filename)-1,"%s/%s/server_scores.xml",g_get_home_dir(),TEG_DIRRC); filename[ sizeof(filename)-1 ] = 0; doc = xmlParseFile( filename ); if (doc == NULL) return TEG_STATUS_ERROR; /* * Check if the document is of the right kind */ cur = xmlDocGetRootElement(doc); if (cur == NULL) { fprintf(stderr,("Empty document\n")); goto error; } if (xmlStrcmp(cur->name, (const xmlChar *) "teg_scores")) { fprintf(stderr,("Wrong type. root node != teg_scores\n")); goto error; } /* * Allocate the structure to be returned. */ cur = xml_get_element_children( cur ); while( cur != NULL ) { if ( !xmlStrcmp(cur->name, (const xmlChar *) "score") ) { curscore = parseScore( doc, cur ); if (curscore != NULL) scores_insert_score(curscore); } else { fprintf(stderr,("Wrong type (%s). score was expected\n"), cur->name); goto error; } cur = xml_get_element_next( cur ); } xmlFreeDoc(doc); return TEG_STATUS_SUCCESS; error: xmlFreeDoc(doc); return TEG_STATUS_ERROR; }
Atree* atreeinit(char *arg) { Atree *a; uchar score[VtScoreSize]; fmtinstall('V', scoreFmt); z = vtdial(nil); if(z == nil) fprint(2, "warning: cannot dial venti: %r\n"); else if(vtconnect(z) < 0) { fprint(2, "warning: cannot connect to venti: %r\n"); z = nil; } a = mallocz(sizeof(Atree), 1); if(strncmp(arg, "vac:", 4) == 0) { if(!parseScore(score, arg+4, strlen(arg+4))) { fprint(2, "cannot parse score\n"); return nil; } a->root = initxvacroot(score); } else a->root = initxcache(arg); a->resizefd = -1; return a; }
GameStatus getStatus() { string name; int year; time_t timer, nextRound; wchar_t nameyearstr[MAX_CHAR_LEN]; wchar_t timestr[MAX_CHAR_LEN]; GetWindowText(nameyearH,nameyearstr,sizeof(nameyearstr)); GetWindowText(timeH,timestr,sizeof(timestr)); parseNameYear(nameyearstr, name, year); parseTimer(timestr, timer, nextRound); GameStatus gs = GameStatus(name, year, nextRound, nPlayer); for (int i = 0; i<nPlayer; ++i) { string pname; bool finishedTurn; Status status; int score; wchar_t * playerstr = new wchar_t[MAX_CHAR_LEN]; wchar_t * pingstr = new wchar_t[MAX_CHAR_LEN]; wchar_t * scorestr = new wchar_t[MAX_CHAR_LEN]; GetWindowText(PlayerH[i].nameH, playerstr, MAX_CHAR_LEN); GetWindowText(PlayerH[i].pingH, pingstr, MAX_CHAR_LEN); GetWindowText(PlayerH[i].scoreH, scorestr, MAX_CHAR_LEN); parsePlayer(playerstr, pname, finishedTurn); parsePing(pingstr, status); parseScore(scorestr, score, status); delete[] playerstr; delete[] pingstr; delete[] scorestr; //Player p = new Player(pname, finishedTurn, status, score); gs.setPlayer(i, pname, finishedTurn, status, score); } return gs; }
static u32int ventiRoot(char *host, char *s) { int i, n; uchar score[VtScoreSize]; u32int addr, tag; DirEntry de; MetaBlock mb; MetaEntry me; Entry e; VtRoot root; if(!parseScore(score, s)) vtFatal("bad score '%s'", s); if((z = vtDial(host, 0)) == nil || !vtConnect(z, nil)) vtFatal("connect to venti: %R"); tag = tagGen(); addr = blockAlloc(BtDir, tag); ventiRead(score, VtRootType); if(!vtRootUnpack(&root, buf)) vtFatal("corrupted root: vtRootUnpack"); n = ventiRead(root.score, VtDirType); /* * Fossil's vac archives start with an extra layer of source, * but vac's don't. */ if(n <= 2*VtEntrySize){ if(!entryUnpack(&e, buf, 0)) vtFatal("bad root: top entry"); n = ventiRead(e.score, VtDirType); } /* * There should be three root sources (and nothing else) here. */ for(i=0; i<3; i++){ if(!entryUnpack(&e, buf, i) || !(e.flags&VtEntryActive) || e.psize < 256 || e.dsize < 256) vtFatal("bad root: entry %d", i); fprint(2, "%V\n", e.score); } if(n > 3*VtEntrySize) vtFatal("bad root: entry count"); blockWrite(PartData, addr); /* * Maximum qid is recorded in root's msource, entry #2 (conveniently in e). */ ventiRead(e.score, VtDataType); if(!mbUnpack(&mb, buf, bsize)) vtFatal("bad root: mbUnpack"); meUnpack(&me, &mb, 0); if(!deUnpack(&de, &me)) vtFatal("bad root: dirUnpack"); if(!de.qidSpace) vtFatal("bad root: no qidSpace"); qid = de.qidMax; /* * Recreate the top layer of source. */ entryInit(&e); e.flags |= VtEntryLocal|VtEntryDir; e.size = VtEntrySize*3; e.tag = tag; localToGlobal(addr, e.score); addr = blockAlloc(BtDir, RootTag); memset(buf, 0, bsize); entryPack(&e, buf, 0); blockWrite(PartData, addr); return addr; }