int Get_Menu(int showwait) { int rv=-1, loop=1, mlevel=0, clevel=0, pos=0; char *pt1,*pt2; FSTRUCT fstr; if(showwait && menu.headerwait[menu.act_header] && menu.headertxt[menu.act_header]) { ShowMessage(menu.headertxt[menu.act_header],"Bitte warten ...",0); } Clear_List(&menu,1); if((fstr.fh[0]=fopen(CFG_FILE,"r"))!=NULL) { loop=1; menu.num_active=0; fstr.fnum=0; while((loop==1) && GetLine(line_buffer, BUFSIZE, &fstr)) { if(IsMenu(line_buffer)) { if(pos==menu.act_header) { clevel=menu.headerlevels[pos]; loop=0; } mlevel++; pos++; } else { pt1=strstr(line_buffer,TYPESTR[TYP_ENDMENU]); if(pt1 && (pt1==line_buffer)) { mlevel--; } } //printf("Get_Menu: loop: %d, mlevel: %d, pos: %d -> %s\n",loop,mlevel,pos,line_buffer); } if(loop) { return rv; } --pos; --mlevel; loop=1; while((loop==1) && GetLine(line_buffer, BUFSIZE, &fstr)) { if(IsMenu(line_buffer)) { pos++; if(mlevel==clevel) { AddListEntry(&menu, line_buffer, pos); rv=0; } mlevel++; } pt1=strstr(line_buffer,TYPESTR[TYP_ENDMENU]); if(pt1 && (pt1==line_buffer)) { if(mlevel==clevel) { if((pt1=strchr(line_buffer,'='))!=NULL) { pt1++; if((pt2=strxchr(pt1,','))!=NULL) { *(pt2++)=0; menu.menactdep=strdup(pt2); } menu.menact=strdup(pt1); } } mlevel--; } else { if(mlevel==clevel) { AddListEntry(&menu, line_buffer, pos); rv=0; } } if(mlevel<clevel) { loop=0; } } fclose(fstr.fh[fstr.fnum]); } return rv; }
void GhostManager::readPacket(BitStream *bstream, DWORD) { bool ghostAlwaysMode = bstream->readFlag(); int idSize; idSize = bstream->readInt( 3); idSize += 3; if(!ghostAlwaysMode && scopeAlwaysList.size()) flushScopeAlwaysObjects(); // while there's an object waiting... while(bstream->readFlag()) { if(!allowGhosts) { // houston, we have a problem - a client is trying to make // ghosts on us - NOone tries to make ghosts on us. setLastError("Invalid packet."); return; } DWORD index; int startPos = bstream->getCurPos(); index = (DWORD) bstream->readInt(idSize); if(bstream->readFlag()) // is this ghost being deleted? freeGhost(index); else { if(!ghostRefs[index].localGhost) // it's a new ghost... cool { DWORD tag; int oNumber; if(ghostAlwaysMode) oNumber = bstream->readInt(32); tag = (DWORD) bstream->readInt( 10); SimNetObject *obj = (SimNetObject *) Persistent::create(tag); if(!obj) { setLastError("Invalid packet."); return; } obj->netFlags.set(SimNetObject::IsGhost); // object gets initial update before adding to the manager obj->netIndex = index; ghostRefs[index].localGhost = obj; ghostRefs[index].localGhost->unpackUpdate(this, bstream); if(!cleanupGroup) { cleanupGroup = new SimGroup(); manager->addObject(cleanupGroup, "GhostGroup"); deleteNotify(cleanupGroup); } if(ghostAlwaysMode) { scopeAlwaysList.push_back(AddListEntry(oNumber, obj)); } else { if(!manager->registerObject(obj)) { if(!getLastError()[0]) setLastError("Invalid packet."); return; } cleanupGroup->addObject(obj); if(obj->netFlags.test(SimNetObject::PolledGhost)) owner->getEventManager()->addPolledObject(obj); } } else ghostRefs[index].localGhost->unpackUpdate(this, bstream); PacketStream::getStats()->addBits(PacketStats::Receive, bstream->getCurPos() - startPos, ghostRefs[index].localGhost->getPersistTag()); #ifdef DEBUG_NET int checksum = bstream->readInt(32); AssertFatal( (checksum ^ DebugChecksum) == index, avar("unpackUpdate did not match packUpdate for object of class %s.", ghostRefs[index].localGhost->getClassName()) ); #endif if(getLastError()[0]) return; } } if(ghostAlwaysMode) { if(bstream->readFlag()) flushScopeAlwaysObjects(); } }