bool BossAI::CheckBoundary(Unit* who) { if (!GetBoundary() || !who) return true; for (BossBoundaryMap::const_iterator itr = GetBoundary()->begin(); itr != GetBoundary()->end(); ++itr) { switch (itr->first) { case BOUNDARY_N: if (me->GetPositionX() > itr->second) return false; break; case BOUNDARY_S: if (me->GetPositionX() < itr->second) return false; break; case BOUNDARY_E: if (me->GetPositionY() < itr->second) return false; break; case BOUNDARY_W: if (me->GetPositionY() > itr->second) return false; break; case BOUNDARY_NW: if (me->GetPositionX() + me->GetPositionY() > itr->second) return false; break; case BOUNDARY_SE: if (me->GetPositionX() + me->GetPositionY() < itr->second) return false; break; case BOUNDARY_NE: if (me->GetPositionX() - me->GetPositionY() > itr->second) return false; break; case BOUNDARY_SW: if (me->GetPositionX() - me->GetPositionY() < itr->second) return false; break; default: break; } } return true; }
CStringA CHttpUploadFileProc::GetContentHead(LPCSTR lpszFileName) { CStringA straContentHead; CStringA straTemp; straContentHead.Empty(); straTemp.Format("--%s\r\n", GetBoundary()); //First Boundary straContentHead += straTemp; straTemp = ValueStr("Email", CStringA(m_threadParam.szEmail)); //Email straContentHead += straTemp; straTemp = ValueStr("FileName", lpszFileName); //FileName straContentHead += straTemp; straTemp = ValueStr("Description", CStringA(m_threadParam.szDesc)); //FileName straContentHead += straTemp; straTemp.Format("Content-Disposition: form-data; name=\"filedata\"; filename=\"%s\"\r\n" //File "Content-Type: application/octet-stream\r\n" //File Type "\r\n", lpszFileName); straContentHead += straTemp; return straContentHead; }
void Pop3::Parser::PlainTextPart () { Assert (_context.size () > 0); std::string boundary; GetBoundary (_context.top (), boundary); unsigned int const boundaryLen = boundary.size (); bool isBoundaryFound = false; std::string text; while (!_lineSeq->AtEnd ()) { std::string const line = _lineSeq->Get (); if (line.compare (0, boundaryLen, boundary) == 0) { isBoundaryFound = true; break; } text += line; text += '\n'; _lineSeq->Advance (); }; if (!isBoundaryFound) throw Pop3::MsgCorruptException ("POP3: Invalid plain text section. No boundary found."); if (!text.empty ()) text.resize (text.size () - 1); // remove '\n' at the end _sink->OnText (text); }
void Graphic_Rectangle::drawBoundary(CDC* cdc) { CRect rect = GetBoundary(); CPen pen(PS_SOLID, 1, RGB(0,0,0)); cdc->SelectObject(&pen); cdc->SelectStockObject(NULL_BRUSH); cdc->SelectStockObject(WHITE_BRUSH); CRect box(rect.BottomRight().x-5, rect.BottomRight().y-5, rect.BottomRight().x+5, rect.BottomRight().y+5); cdc->Rectangle(box); box.SetRect(rect.TopLeft().x-5, rect.TopLeft().y-5, rect.TopLeft().x+5, rect.TopLeft().y+5); cdc->Rectangle(box); box.SetRect(rect.left-5, rect.bottom-5, rect.left+5, rect.bottom+5); cdc->Rectangle(box); box.SetRect(rect.right-5, rect.top-5, rect.right+5, rect.top+5); cdc->Rectangle(box); box.SetRect(rect.CenterPoint().x-5, rect.bottom-5, rect.CenterPoint().x+5, rect.bottom+5); cdc->Rectangle(box); box.SetRect(rect.CenterPoint().x-5, rect.top-5, rect.CenterPoint().x+5, rect.top+5); cdc->Rectangle(box); box.SetRect(rect.right-5, rect.CenterPoint().y-5, rect.right+5, rect.CenterPoint().y+5); cdc->Rectangle(box); box.SetRect(rect.left-5, rect.CenterPoint().y-5, rect.left+5, rect.CenterPoint().y+5); cdc->Rectangle(box); }
// store the body part to string buffer int CMimeBody::Store(char* pszData, int nMaxSize) const { // store header fields int nSize = CMimeHeader::Store(pszData, nMaxSize); if (nSize <= 0) return nSize; // store content char* pszDataBegin = pszData; // preserve start position pszData += nSize; nMaxSize -= nSize; CMimeCodeBase* pCoder = CMimeEnvironment::CreateCoder(GetTransferEncoding()); ASSERT(pCoder != NULL); pCoder->SetInput((const char*)m_pbText, m_nTextSize, true); int nOutput = pCoder->GetOutput((unsigned char*)pszData, nMaxSize); delete pCoder; if (nOutput < 0) return nOutput; pszData += nOutput; nMaxSize -= nOutput; if (m_listBodies.empty()) return (int)(pszData - pszDataBegin); // store child body parts string strBoundary = GetBoundary(); if (strBoundary.empty()) return -1; // boundary not be set int nBoundSize = (int)strBoundary.size() + 6; for (CBodyList::const_iterator it=m_listBodies.begin(); it!=m_listBodies.end(); it++) { if (nMaxSize < nBoundSize) break; if (m_listBodies.begin() == it && *(pszData-2) == '\r' && *(pszData-1) == '\n') { pszData -= 2; nMaxSize += 2; } ::sprintf(pszData, "\r\n--%s\r\n", strBoundary.c_str()); pszData += nBoundSize; nMaxSize -= nBoundSize; CMimeBody* pBP = *it; ASSERT(pBP != NULL); nOutput = pBP->Store(pszData, nMaxSize); if (nOutput < 0) return nOutput; pszData += nOutput; nMaxSize -= nOutput; } if (nMaxSize >= nBoundSize+2) // add closing boundary delimiter { ::sprintf(pszData, "\r\n--%s--\r\n", strBoundary.c_str()); pszData += nBoundSize + 2; } return (int)(pszData - pszDataBegin); }
void Pop3::Parser::SimplePart () { if (_currentContext.IsApplication () && // type : application _currentContext.IsOctetStream () && // subtype : octet-stream _currentContext.IsBase64 ()) // encoding : base64 { AppOctetStreamBase64Part (); } else if (_currentContext.IsPlainText ()) { if (_context.size () > 0) // multipart message PlainTextPart (); else PlainTextMessage (); } else { // Revisit: handle other simple parts if (_context.size () > 0) // multipart message { std::string boundary; GetBoundary (_context.top (), boundary); if (!EatToLine (boundary)) throw Pop3::MsgCorruptException ("POP3: Corrupted message syntax. " "Boundary not found in multipart message."); } else { EatToEnd (); } } }
// return the length needed to store this body part to string buffer int CMimeBody::GetLength() const { int nLength = CMimeHeader::GetLength(); CMimeCodeBase* pCoder = CMimeEnvironment::CreateCoder(GetTransferEncoding()); ASSERT(pCoder != NULL); pCoder->SetInput((const char*)m_pbText, m_nTextSize, true); nLength += pCoder->GetOutputLength(); delete pCoder; if (m_listBodies.empty()) return nLength; string strBoundary = GetBoundary(); int nBoundSize = (int) strBoundary.size(); list<CMimeBody*>::const_iterator it; for (it=m_listBodies.begin(); it!=m_listBodies.end(); it++) { nLength += nBoundSize + 6; // include 2 leading hyphens and 2 pair of CRLFs CMimeBody* pBP = *it; ASSERT(pBP != NULL); nLength += pBP->GetLength(); } nLength += nBoundSize + 8; // include 2 leading hyphens, 2 trailng hyphens and 2 pair of CRLFs return nLength; }
void StartPoint::find_best_start(const AircraftState &state, const OrderedTaskPoint &next, const FlatProjection &projection) { /* check which boundary point results in the smallest distance to fly */ const OZBoundary boundary = GetBoundary(); assert(!boundary.empty()); const auto end = boundary.end(); auto i = boundary.begin(); assert(i != end); const GeoPoint &next_location = next.GetLocationRemaining(); GeoPoint best_location = *i; fixed best_distance = ::DoubleDistance(state.location, *i, next_location); for (++i; i != end; ++i) { fixed distance = ::DoubleDistance(state.location, *i, next_location); if (distance < best_distance) { best_location = *i; best_distance = distance; } } SetSearchMin(SearchPoint(best_location, projection)); }
void ReSizeGameWnd(HWND hwnd) { POINT ptLeftTop; // 左上角 POINT ptRightBottom; // 右下角 RECT rectWindow; PGAME_COORD pCoordBoundary = GetBoundary(); // 设置游戏边界 rectBoundary.left = 10; rectBoundary.top = 10; rectBoundary.right = 10 + CELL_PIXEL*(pCoordBoundary->x + 1); rectBoundary.bottom = 10 + CELL_PIXEL*(pCoordBoundary->y + 1); // 计算上下左右角的位置 ptLeftTop.x = rectBoundary.left; ptLeftTop.y = rectBoundary.top; ptRightBottom.x = rectBoundary.right; ptRightBottom.y = rectBoundary.bottom; ClientToScreen(hwnd, &ptLeftTop); ClientToScreen(hwnd, &ptRightBottom); GetWindowRect(hwnd, &rectWindow); // 计算好了,设置窗口大小。 MoveWindow(hwnd, rectWindow.left, rectWindow.top, ptLeftTop.x - rectWindow.left + ptRightBottom.x - rectWindow.left, // 保存边界和左右两边边框相等。 rectBoundary.bottom + 120, //给积分信息留出显示空间。 TRUE); }
void OrderedTaskPoint::UpdateOZ(const TaskProjection &projection) { UpdateGeometry(); SampledTaskPoint::UpdateOZ(projection, GetBoundary()); }
void OrderedTaskPoint::ScanProjection(TaskProjection &task_projection) const { task_projection.Scan(GetLocation()); for (const auto &i : GetBoundary()) task_projection.Scan(i); }
bool Graphic_Rectangle::PointInObj(CPoint pt){ CRect rect= GetBoundary(); pointStart = rect.TopLeft(); pointEnd = rect.BottomRight(); if(rect.left-pt.x < 5 && rect.left-pt.x > -5){ if(rect.top - pt.y <5 && rect.top-pt.y> -5) Move_Direction=1; else if(rect.bottom - pt.y <5 && rect.bottom-pt.y>-5) Move_Direction=7; else Move_Direction=8; return true; } else if(rect.right-pt.x < 5 && rect.right-pt.x >-5){ if(rect.top - pt.y <5 && rect.top-pt.y> -5) Move_Direction=3; else if(rect.bottom - pt.y <5 && rect.bottom-pt.y>-5) Move_Direction=5; else Move_Direction=4; return true; } else{ if(rect.top - pt.y <5 && rect.top-pt.y> -5) { Move_Direction=2; return true; } else if(rect.bottom - pt.y <5 && rect.bottom-pt.y>-5) { Move_Direction=6; return true; } else if (CRect(GetBoundary()).PtInRect(pt)) { Move_Direction=0; return true; } else return false; } }
void GetBoundary(const SegmentationDesc::Region2D& region, int frame_width, bool inner_boundary, vector<uchar>* buffer, RegionBoundary* boundary) { vector<const SegmentationDesc::Region2D*> regions; regions.push_back(®ion); GetBoundary(regions, frame_width, inner_boundary, buffer, boundary); }
void OrderedTaskPoint::scan_projection(TaskProjection &task_projection) const { task_projection.scan_location(GetLocation()); #define fixed_steps fixed(0.05) const ObservationZone::Boundary boundary = GetBoundary(); for (auto i = boundary.begin(), end = boundary.end(); i != end; ++i) task_projection.scan_location(*i); }
CStringA CHttpUploadFileProc::ValueStr(LPCSTR lpszName, LPCSTR lpszValue) { CStringA stra; stra.Format("Content-Disposition: form-data; name=\"%s\"\r\n" //Name "\r\n" "%s" //Value "\r\n--%s\r\n", //Boundary lpszName, lpszValue, GetBoundary()); return stra; }
void OrderedTaskPoint::UpdateBoundingBox(const TaskProjection &task_projection) { flat_bb = FlatBoundingBox(task_projection.ProjectInteger(GetLocation())); for (const auto &i : GetBoundary()) flat_bb.Expand(task_projection.ProjectInteger(i)); flat_bb.ExpandByOne(); // add 1 to fix rounding }
void OrderedTaskPoint::update_boundingbox(const TaskProjection &task_projection) { flat_bb = FlatBoundingBox(task_projection.project(GetLocation())); const ObservationZone::Boundary boundary = GetBoundary(); for (auto i = boundary.begin(), end = boundary.end(); i != end; ++i) flat_bb.Expand(task_projection.project(*i)); flat_bb.ExpandByOne(); // add 1 to fix rounding }
void SampledTaskPoint::UpdateOZ(const TaskProjection &projection) { search_max = search_reference; search_min = search_reference; boundary_points.clear(); for (const SearchPoint sp : GetBoundary()) boundary_points.push_back(sp); UpdateProjection(projection); }
// store the body part to un-encoded string buffer void MimeBody::Store(AnsiString &output, bool bIncludeHeader) const { // store header fields int nSize = 0; if (bIncludeHeader) MimeHeader::Store(output); // Copy the data to the output buffer. output.append(m_pbText); if (m_listBodies.empty()) return; // store child body parts string strBoundary = GetBoundary(); if (strBoundary.empty()) return; // boundary not be set int nBoundSize = (int)strBoundary.size() + 6; // Bill48105 - These iOutputSize are temp fix for [ ambiguous error int iOutputSizeLess2 = output.size() - 2; int iOutputSizeLess1 = output.size() - 1; for (BodyList::const_iterator it=m_listBodies.begin(); it!=m_listBodies.end(); it++) { // If the initial body ends with \r\n, remove them. We add new ones below. if (m_listBodies.begin() == it && output.size() >= 2 && output[iOutputSizeLess2] == '\r' && output[iOutputSizeLess1] == '\n') { output = output.Mid(0, output.GetLength() - 2); } AnsiString boundaryLine = Formatter::Format(_T("\r\n--{0}\r\n"), String(strBoundary)); output.append(boundaryLine); shared_ptr<MimeBody> pBP = *it; ASSERT(pBP != NULL); pBP->Store(output); } AnsiString endBoundaryLine = Formatter::Format(_T("\r\n--{0}--\r\n"), String(strBoundary)); output.append(endBoundaryLine); }
void SampledTaskPoint::UpdateOZ(const TaskProjection &projection) { search_max = search_reference; search_min = search_reference; boundary_points.clear(); if (boundary_scored) { const OZBoundary boundary = GetBoundary(); for (auto i = boundary.begin(), end = boundary.end(); i != end; ++i) { SearchPoint sp(*i); boundary_points.push_back(sp); } boundary_points.PruneInterior(); } else { boundary_points.push_back(search_reference); } UpdateProjection(projection); }
// return the length needed to store this body part // in an de-coded buffer int MimeBody::GetLength(bool bIncludeHeader) const { int nLength = 0; if (bIncludeHeader) nLength += MimeHeader::GetLength(); if (m_listBodies.empty()) return nLength; string strBoundary = GetBoundary(); int nBoundSize = (int) strBoundary.size(); list<shared_ptr<MimeBody> >::const_iterator it; for (it=m_listBodies.begin(); it!=m_listBodies.end(); it++) { nLength += nBoundSize + 6; // include 2 leading hyphens and 2 pair of CRLFs shared_ptr<MimeBody> pBP = *it; ASSERT(pBP != NULL); nLength += pBP->GetLength(); } nLength += nBoundSize + 8; // include 2 leading hyphens, 2 trailng hyphens and 2 pair of CRLFs return nLength; }
// Recursive void Pop3::Parser::MultiPart () { std::string boundary; GetBoundary (_currentContext, boundary); unsigned int boundaryLen = boundary.size (); while (!_lineSeq->AtEnd ()) { // Not a MIME boundary // RFC #2046: implementers must ignore "preamble". // Still we cannot just skip this line if we want to // be able to serialize the whole original message if (!EatToLine (boundary)) throw Pop3::MsgCorruptException ("POP3: Corrupted message syntax. " "Boundary not found in multipart message."); Assert (!_lineSeq->AtEnd ()); std::string const line = _lineSeq->Get (); unsigned lineLen = line.size (); Assert (line.compare (0, boundaryLen, boundary) == 0); if (lineLen >= boundaryLen + 2 && line [boundaryLen] == '-' && line [boundaryLen + 1] == '-') { // Closing boundary _lineSeq->Advance (); break; } else { _lineSeq->Advance (); _context.push (_currentContext); _currentContext.Clear (); // Recurse Message (); _currentContext = _context.top (); _context.pop (); } } }
CStringA CHttpUploadFileProc::GetContentTail() { CStringA straContentTail; straContentTail.Format("\r\n--%s--\r\n", GetBoundary()); return straContentTail; }
// load a body part from string buffer int CMimeBody::Load(const char* pszData, int nDataSize) { // load header fields int nSize = CMimeHeader::Load(pszData, nDataSize); if (nSize <= 0) return nSize; const char* pszDataBegin = pszData; // preserve start position pszData += nSize; nDataSize -= nSize; FreeBuffer(); // determine the length of the content const char* pszEnd = pszData + nDataSize; int nMediaType = GetMediaType(); if (MEDIA_MULTIPART == nMediaType) { // find the begin boundary string strBoundary = GetBoundary(); if (!strBoundary.empty()) { strBoundary = "\r\n--" + strBoundary; pszEnd = ::FindString(pszData-2, strBoundary.c_str(), pszEnd); if (!pszEnd) pszEnd = pszData + nDataSize; else pszEnd += 2; } } // load content nSize = (int)(pszEnd - pszData); if (nSize > 0) { CMimeCodeBase* pCoder = CMimeEnvironment::CreateCoder(GetTransferEncoding()); ASSERT(pCoder != NULL); pCoder->SetInput(pszData, nSize, false); int nOutput = pCoder->GetOutputLength(); if (AllocateBuffer(nOutput+4)) nOutput = pCoder->GetOutput(m_pbText, nOutput); else nOutput = -1; delete pCoder; if (nOutput < 0) return nOutput; ASSERT(nOutput < m_nTextSize); m_pbText[nOutput] = 0; m_nTextSize = nOutput; pszData += nSize; nDataSize -= nSize; } if (nDataSize <= 0) return (int)(pszData - pszDataBegin); // load child body parts string strBoundary = GetBoundary(); ASSERT(strBoundary.size() > 0); strBoundary = "\r\n--" + strBoundary; // look for the first boundary (case sensitive) pszData -= 2; // go back to CRLF nDataSize += 2; pszEnd = pszData + nDataSize; const char* pszBound1 = ::FindString(pszData, strBoundary.c_str(), pszEnd); while (pszBound1 != NULL && pszBound1 < pszEnd) { const char* pszStart = ::FindString(pszBound1+2, "\r\n", pszEnd); if (!pszStart) break; pszStart += 2; if (pszBound1[strBoundary.size()] == '-' && pszBound1[strBoundary.size()+1] == '-') return (int)(pszStart - pszDataBegin); // reach the closing boundary // look for the next boundary const char* pszBound2 = ::FindString(pszStart, strBoundary.c_str(), pszEnd); if (!pszBound2) // overflow, boundary may be truncated pszBound2 = pszEnd; int nEntitySize = (int) (pszBound2 - pszStart); // find the media type of this body part: CMimeHeader header; header.Load(pszStart, nEntitySize); string strMediaType = header.GetMainType(); CMimeBody* pBP = CreatePart(strMediaType.c_str()); int nInputSize = pBP->Load(pszStart, nEntitySize); if (nInputSize < 0) { ErasePart(pBP); return nInputSize; } pszBound1 = pszBound2; } return (int)(pszEnd - pszDataBegin); }
CStringA CHttpUploadFileProc::GetHttpAppendHeader() { CStringA straHeader; straHeader.Format("Content-Type: multipart/form-data; boundary=%s\r\n", GetBoundary()); return straHeader; }
// load a body part from string buffer int MimeBody::Load(const char* pszData, int nDataSize, int &index) { index++; m_iPartIndex = index; // load header fields int nSize = MimeHeader::Load(pszData, nDataSize, true); if (nSize <= 0) return nSize; const char* pszDataBegin = pszData; // preserve start position pszData += nSize; nDataSize -= nSize; FreeBuffer(); // determine the length of the content const char* pszEnd = pszData + nDataSize; int nMediaType = GetMediaType(); if (MEDIA_MULTIPART == nMediaType) { // find the begin boundary string strBoundary = GetBoundary(); if (!strBoundary.empty()) { strBoundary = "\r\n--" + strBoundary + "\r\n"; pszEnd = FindString(pszData-2, strBoundary.c_str(), pszEnd); if (!pszEnd) pszEnd = pszData + nDataSize; else pszEnd += 2; } } // load content nSize = (int)(pszEnd - pszData); if (nSize > 0) { if (AllocateBuffer(nSize+4)) { m_pbText.append(pszData, nSize); pszData += nSize; nDataSize -= nSize; } else return -1; } if (nDataSize <= 0) return (int)(pszData - pszDataBegin); // load child body parts string strBoundary = GetBoundary(); ASSERT(strBoundary.size() > 0); strBoundary = "\r\n--" + strBoundary; // look for the first boundary (case sensitive) pszData -= 2; // go back to CRLF nDataSize += 2; pszEnd = pszData + nDataSize; const char* pszBound1 = GetBoundaryEnd(pszData, pszEnd, strBoundary.c_str()); int counter = 10000; while (pszBound1 != NULL && pszBound1 < pszEnd && counter > 0) { counter--; const char* pszStart = FindString(pszBound1+2, "\r\n", pszEnd); if (!pszStart) break; pszStart += 2; if (pszBound1[strBoundary.size()] == '-' && pszBound1[strBoundary.size()+1] == '-') return (int)(pszStart - pszDataBegin); // reach the closing boundary // look for the next boundary string strBoundaryLine = strBoundary + "\r\n"; const char* pszBound2 = GetBoundaryEnd(pszStart, pszEnd, strBoundary.c_str()); if (!pszBound2) // overflow, boundary may be truncated pszBound2 = pszEnd; int nEntitySize = (int) (pszBound2 - pszStart); shared_ptr<MimeBody> pBP = shared_ptr<MimeBody>(new MimeBody()); m_listBodies.push_back(pBP); int nInputSize = pBP->Load(pszStart, nEntitySize, m_iPartIndex); if (nInputSize < 0) { ErasePart(pBP); return nInputSize; } pszBound1 = pszBound2; } return (int)(pszEnd - pszDataBegin); }