mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:00:04 +00:00 
			
		
		
		
	Consistent usage of ValidateMessage() in level 3 packets
This commit is contained in:
		
							parent
							
								
									7a9582a689
								
							
						
					
					
						commit
						03fdd99585
					
				
					 5 changed files with 146 additions and 102 deletions
				
			
		|  | @ -82,6 +82,8 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) | |||
| { | ||||
|    bool blockValid = true; | ||||
| 
 | ||||
|    std::streampos isBegin = is.tellg(); | ||||
| 
 | ||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||
|    is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 2); | ||||
| 
 | ||||
|  | @ -102,34 +104,6 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) | |||
| 
 | ||||
|       vectorSize -= 2; | ||||
|    } | ||||
| 
 | ||||
|    // The number of vectors is equal to the size divided by the number of bytes
 | ||||
|    // in a vector
 | ||||
|    int vectorCount = vectorSize / 8; | ||||
| 
 | ||||
|    p->beginI_.resize(vectorCount); | ||||
|    p->beginJ_.resize(vectorCount); | ||||
|    p->endI_.resize(vectorCount); | ||||
|    p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|    for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|    { | ||||
|       is.read(reinterpret_cast<char*>(&p->beginI_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->beginJ_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|       p->beginI_[v] = ntohs(p->beginI_[v]); | ||||
|       p->beginJ_[v] = ntohs(p->beginJ_[v]); | ||||
|       p->endI_[v]   = ntohs(p->endI_[v]); | ||||
|       p->endJ_[v]   = ntohs(p->endJ_[v]); | ||||
|    } | ||||
| 
 | ||||
|    if (is.eof()) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||
|       blockValid = false; | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       if (p->packetCode_ != 7 && p->packetCode_ != 10) | ||||
|  | @ -140,6 +114,39 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) | |||
|       } | ||||
|    } | ||||
| 
 | ||||
|    if (blockValid) | ||||
|    { | ||||
|       // The number of vectors is equal to the size divided by the number of
 | ||||
|       // bytes in a vector
 | ||||
|       int vectorCount = vectorSize / 8; | ||||
| 
 | ||||
|       p->beginI_.resize(vectorCount); | ||||
|       p->beginJ_.resize(vectorCount); | ||||
|       p->endI_.resize(vectorCount); | ||||
|       p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|       for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|       { | ||||
|          is.read(reinterpret_cast<char*>(&p->beginI_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->beginJ_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|          p->beginI_[v] = ntohs(p->beginI_[v]); | ||||
|          p->beginJ_[v] = ntohs(p->beginJ_[v]); | ||||
|          p->endI_[v]   = ntohs(p->endI_[v]); | ||||
|          p->endJ_[v]   = ntohs(p->endJ_[v]); | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    std::streampos isEnd     = is.tellg(); | ||||
|    std::streamoff bytesRead = isEnd - isBegin; | ||||
| 
 | ||||
|    if (!ValidateMessage(is, bytesRead)) | ||||
|    { | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    return blockValid; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat