static void CcpDecodeConfig(Fsm fp, FsmOption list, int num, int mode) { Bund b = (Bund)fp->arg; CcpState const ccp = &b->ccp; u_int ackSizeSave, rejSizeSave; int k, rej; /* Forget our previous choice on new request */ if (mode == MODE_REQ) ccp->recv = NULL; /* Decode each config option */ for (k = 0; k < num; k++) { FsmOption const opt = &list[k]; int index; CompType ct; char buf[32]; Log(LG_CCP, ("[%s] %s", b->name, CcpTypeName(opt->type, buf, sizeof(buf)))); if ((ct = CcpFindComp(opt->type, &index)) == NULL) { if (mode == MODE_REQ) { Log(LG_CCP, ("[%s] Not supported", b->name)); FsmRej(fp, opt); } continue; } switch (mode) { case MODE_REQ: ackSizeSave = gAckSize; rejSizeSave = gRejSize; rej = (!Acceptable(&ccp->options, index) || CCP_SELF_REJECTED(ccp, index) || (ccp->recv && ccp->recv != ct)); if (rej) { (*ct->DecodeConfig)(fp, opt, MODE_NOP); FsmRej(fp, opt); break; } (*ct->DecodeConfig)(fp, opt, mode); if (gRejSize != rejSizeSave) { /* we rejected it */ CCP_SELF_REJ(ccp, index); break; } if (gAckSize != ackSizeSave) /* we accepted it */ ccp->recv = ct; break; case MODE_REJ: (*ct->DecodeConfig)(fp, opt, mode); CCP_PEER_REJ(ccp, index); break; case MODE_NAK: case MODE_NOP: (*ct->DecodeConfig)(fp, opt, mode); break; } } }
//@{ bool Acceptable(Number val1, Number val2) const { std::vector<Number> vals(2); vals[0] = val1; vals[1] = val2; return Acceptable(vals); }
void FileBrowser::UpdateStrings() { Clear(); for (int i = 0; i < dir->Count(); i++) { const char* name = dir->File(i); if (Acceptable(Concat(lastpath, name))) { if (dir->IsADirectory(Concat(lastpath, name))) { char buf[MAXPATHLEN+1]; strcpy(buf, name); strcat(buf, "/"); Append(buf); } else { Append(name); } } } }
void OptStat(Context ctx, Options opt, ConfInfo list) { int k, peered = 0; for (k = 0; list[k].name; k++) { if (list[k].peered) { peered = 1; break; } } if (peered) Printf("\t\t\tSelf\t\tPeer\r\n"); for (k = 0; list[k].name; k++) { ConfInfo const c = &list[k]; Printf("\t%-10s\t%s", c->name, Enabled(opt, c->option) ? "enable" : "disable"); if (c->peered) Printf("\t\t%s", Acceptable(opt, c->option) ? "accept" : "deny"); Printf("\r\n"); } }
// // Check // // Check if allowed to build at the given location // Placement::Result Placement::Check(const Matrix &location, U32 flags) { ASSERT(IsSetup()); S32 xZip, zZip, xFoot, zFoot; S32 xMax, zMax; S32 x, z; // Reset the array Reset(); // Set default result result = PR_OK; // Get direction dir = WorldCtrl::GetCompassDirection(location.front); // Get cell in bottom left corner of footprint FindOrigin(location, dir, min); // Setup extents using current direction SetupMaximums(xMax, zMax, size.x, size.z, dir); // Save max point max.Set(min.x + xMax - 3, min.z + zMax - 3); // Step over footprint in terrain space // This loop must occur before the thump simulation, as cell.map has to be set up for (z = 0; z < zMax; z++) { for (x = 0; x < xMax; x++) { // Convert the terrain offset to footprint offsets CalculateOffsets(dir, size.x, size.z, x, z, xZip, zZip, xFoot, zFoot); // Get the placement cell at this position Cell &cell = GetCell(xFoot, zFoot); // Is this a zipping location (not on a lower fringe) if (x > 0 && z > 0) { // Save zipping value, adjusting for fringe cell.zip.Set(xZip - 1, zZip - 1); ASSERT(cell.zip.x >= 0); ASSERT(cell.zip.z >= 0); } // Get actual terrain cell position cell.map.Set(min.x + x - 1, min.z + z - 1); } } // If we are doing a thumping simulation, then thumped.valid is TRUE and the // real TerrainData::Cell will be substituted for the thumped version when // performing the placement check. // Otherwise, the real terrain cell will be used if (flags & CHECK_NOTHUMPTEST) { // Thumped is no longer valid thumped.Invalidate(); } else { // Copy terrain into thumped buffer if (thumped.CopyTerrain()) { // Calculate the best height to build at thumpHeight = thumped.CalcBestHeight(); // Thump terrain into the thumped buffer ThumpTerrain(thumpHeight, 0.0F, THUMP_TOBUFFER); // Update slopes thumped.UpdateCells(); } } // UnitObjType is used inside the loop UnitObjType *unitObjType = Promote::Type<UnitObjType>(&type->GetMapType()); // Step over footprint in terrain space for (z = 0; z < zMax; z++) { for (x = 0; x < xMax; x++) { // Default cell result to ok Result r = PR_OK; // Convert the terrain offset to footprint offsets CalculateOffsets(dir, size.x, size.z, x, z, xZip, zZip, xFoot, zFoot); // Get the placement cell at this position Cell &cell = GetCell(xFoot, zFoot); // Is this position on the map if (WorldCtrl::CellOnMapNoEdge(cell.map.x, cell.map.z)) { // Get the map cell at this location TerrainData::Cell &origCell = TerrainData::GetCell(cell.map.x, cell.map.z); // Get the thumped cell at this location TerrainData::Cell *thumpCell = thumped.IsValid() ? thumped.GetCell(x, z) : NULL; // Is there another footprint at this location if (!AvailableInstanceIndex(origCell.footIndex)) { r = (cell.onFoot) ? PR_FOOTON : PR_FOOTOFF; } else if (!TestThumpArea(cell.map, cell.map)) { r = PR_THUMPING; } else // Is this position on the footprint if (cell.onFoot) { Point<S32> g; // Convert cell to grain WorldCtrl::CellToFirstGrain(cell.map.x, cell.map.z, g.x, g.z); // Get the type cell Type::Cell &typeCell = GetType().GetCell(cell.type.x, cell.type.z); // Probe lower grains if (typeCell.GetFlag(Type::CLAIMLO) && ClaimBlock(g, Claim::LAYER_LOWER, flags)) { r = PR_CLAIM; } else // Probe upper grains if (typeCell.GetFlag(Type::CLAIMHI) && ClaimBlock(g, Claim::LAYER_UPPER, flags)) { r = PR_CLAIM; } else // Can this object build on this location if (!PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), origCell)) { r = PR_CANMOVETO; } else if (thumpCell && !PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), *thumpCell)) { r = PR_CANMOVETO; } else // Is this cell shrouded if (!(flags & CHECK_IGNORESHROUD) && team && !Sight::Seen(cell.map.x, cell.map.z, team)) { r = PR_SHROUDED; } } else { if (unitObjType) { if (unitObjType->CanBoard()) { // The pathability check is extended to the fringe cells for objects that can have a board manager if (!PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), origCell)) { r = PR_CANMOVETO; } else if (thumpCell && !PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), *thumpCell)) { r = PR_CANMOVETO; } } else { // Not allowed to change the pathability state from passabable to impassable if (PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), origCell)) { if (thumpCell && !PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), *thumpCell)) { r = PR_CANMOVETO; } } } } } } else { r = PR_OFFMAP; } // Save result in cell cell.result = r; // Save significant results if (!Acceptable(r) || result == PR_OK) { result = r; } } } return (result); }
static void IpcpDecodeConfig(Fsm fp, FsmOption list, int num, int mode) { Bund b = (Bund)fp->arg; IpcpState const ipcp = &b->ipcp; struct in_addr *wantip, *peerip; int k; /* Decode each config option */ for (k = 0; k < num; k++) { FsmOption const opt = &list[k]; FsmOptInfo const oi = FsmFindOptInfo(gIpcpConfOpts, opt->type); if (!oi) { Log(LG_IPCP, ("[%s] UNKNOWN[%d] len=%d", b->name, opt->type, opt->len)); if (mode == MODE_REQ) FsmRej(fp, opt); continue; } if (!oi->supported) { Log(LG_IPCP, ("[%s] %s", b->name, oi->name)); if (mode == MODE_REQ) { Log(LG_IPCP, ("[%s] Not supported", b->name)); FsmRej(fp, opt); } continue; } if (opt->len < oi->minLen + 2 || opt->len > oi->maxLen + 2) { Log(LG_IPCP, ("[%s] %s", b->name, oi->name)); if (mode == MODE_REQ) { Log(LG_IPCP, ("[%s] bogus len=%d", b->name, opt->len)); FsmRej(fp, opt); } continue; } switch (opt->type) { case TY_IPADDR: { struct in_addr ip; struct u_addr tmp; memcpy(&ip, opt->data, 4); in_addrtou_addr(&ip, &tmp); Log(LG_IPCP, ("[%s] %s %s", b->name, oi->name, inet_ntoa(ip))); switch (mode) { case MODE_REQ: if (!IpAddrInRange(&ipcp->peer_allow, &tmp) || !ip.s_addr) { if (ipcp->peer_addr.s_addr == 0) Log(LG_IPCP, ("[%s] no IP address available for peer!", b->name)); if (Enabled(&ipcp->conf.options, IPCP_CONF_PRETENDIP)) { Log(LG_IPCP, ("[%s] pretending that %s is OK, will ignore", b->name, inet_ntoa(ip))); ipcp->peer_addr = ip; FsmAck(fp, opt); break; } memcpy(opt->data, &ipcp->peer_addr, 4); Log(LG_IPCP, ("[%s] NAKing with %s", b->name, inet_ntoa(ipcp->peer_addr))); FsmNak(fp, opt); break; } Log(LG_IPCP, ("[%s] %s is OK", b->name, inet_ntoa(ip))); ipcp->peer_addr = ip; FsmAck(fp, opt); break; case MODE_NAK: { if (IpAddrInRange(&ipcp->self_allow, &tmp)) { Log(LG_IPCP, ("[%s] %s is OK", b->name, inet_ntoa(ip))); ipcp->want_addr = ip; } else if (Enabled(&ipcp->conf.options, IPCP_CONF_PRETENDIP)) { Log(LG_IPCP, ("[%s] pretending that %s is OK, will ignore", b->name, inet_ntoa(ip))); ipcp->want_addr = ip; } else Log(LG_IPCP, ("[%s] %s is unacceptable", b->name, inet_ntoa(ip))); } break; case MODE_REJ: IPCP_PEER_REJ(ipcp, opt->type); if (ipcp->want_addr.s_addr == 0) Log(LG_IPCP, ("[%s] Problem: I need an IP address!", b->name)); break; } } break; #ifdef USE_NG_VJC case TY_COMPPROTO: { struct ipcpvjcomp vj; memcpy(&vj, opt->data, sizeof(vj)); Log(LG_IPCP, ("[%s] %s %s, %d comp. channels, %s comp-cid", b->name, oi->name, ProtoName(ntohs(vj.proto)), vj.maxchan + 1, vj.compcid ? "allow" : "no")); switch (mode) { case MODE_REQ: if (!Acceptable(&ipcp->conf.options, IPCP_CONF_VJCOMP) && !b->params.vjc_enable) { FsmRej(fp, opt); break; } if (ntohs(vj.proto) == PROTO_VJCOMP && vj.maxchan <= IPCP_VJCOMP_MAX_MAXCHAN && vj.maxchan >= IPCP_VJCOMP_MIN_MAXCHAN) { ipcp->peer_comp = vj; FsmAck(fp, opt); break; } vj.proto = htons(PROTO_VJCOMP); vj.maxchan = IPCP_VJCOMP_MAX_MAXCHAN; vj.compcid = 0; memcpy(opt->data, &vj, sizeof(vj)); FsmNak(fp, opt); break; case MODE_NAK: if (ntohs(vj.proto) != PROTO_VJCOMP) { Log(LG_IPCP, ("[%s] Can't accept proto 0x%04x", b->name, (u_short) ntohs(vj.proto))); break; } if (vj.maxchan != ipcp->want_comp.maxchan) { if (vj.maxchan <= IPCP_VJCOMP_MAX_MAXCHAN && vj.maxchan >= IPCP_VJCOMP_MIN_MAXCHAN) { Log(LG_IPCP, ("[%s] Adjusting # compression channels", b->name)); ipcp->want_comp.maxchan = vj.maxchan; } else { Log(LG_IPCP, ("[%s] Can't handle %d maxchan", b->name, vj.maxchan)); } } if (vj.compcid) { Log(LG_IPCP, ("[%s] Can't accept comp-cid", b->name)); break; } break; case MODE_REJ: IPCP_PEER_REJ(ipcp, opt->type); ipcp->want_comp.proto = 0; break; } } break; #endif /* USE_NG_VJC */ case TY_PRIMARYDNS: if (b->params.peer_dns[0].s_addr != 0) peerip = &b->params.peer_dns[0]; else peerip = &ipcp->conf.peer_dns[0]; wantip = &ipcp->want_dns[0]; goto doDnsNbns; case TY_PRIMARYNBNS: if (b->params.peer_nbns[0].s_addr != 0) peerip = &b->params.peer_nbns[0]; else peerip = &ipcp->conf.peer_nbns[0]; wantip = &ipcp->want_nbns[0]; goto doDnsNbns; case TY_SECONDARYDNS: if (b->params.peer_dns[1].s_addr != 0) peerip = &b->params.peer_dns[1]; else peerip = &ipcp->conf.peer_dns[1]; wantip = &ipcp->want_dns[1]; goto doDnsNbns; case TY_SECONDARYNBNS: if (b->params.peer_nbns[1].s_addr != 0) peerip = &b->params.peer_nbns[1]; else peerip = &ipcp->conf.peer_nbns[1]; wantip = &ipcp->want_nbns[1]; doDnsNbns: { struct in_addr hisip; memcpy(&hisip, opt->data, 4); Log(LG_IPCP, ("[%s] %s %s", b->name, oi->name, inet_ntoa(hisip))); switch (mode) { case MODE_REQ: if (hisip.s_addr == 0) { /* he's asking for one */ if (peerip->s_addr == 0) { /* we don't got one */ FsmRej(fp, opt); break; } Log(LG_IPCP, ("[%s] NAKing with %s", b->name, inet_ntoa(*peerip))); memcpy(opt->data, peerip, sizeof(*peerip)); FsmNak(fp, opt); /* we got one for him */ break; } FsmAck(fp, opt); /* he knows what he wants */ break; case MODE_NAK: /* we asked for his server, he's telling us */ *wantip = hisip; break; case MODE_REJ: /* we asked for his server, he's ignorant */ IPCP_PEER_REJ(ipcp, opt->type); break; } } break; default: assert(0); } } }