its compiling now

This commit is contained in:
ErikasKontenis
2019-09-29 22:59:23 +03:00
parent ad4cf36193
commit 45c787b241
12 changed files with 127 additions and 62 deletions

View File

@@ -182,45 +182,66 @@ void Connection::parsePacket(const boost::system::error_code& error)
if (error) {
close(FORCE_CLOSE);
return;
} else if (connectionState != CONNECTION_STATE_OPEN) {
}
else if (connectionState != CONNECTION_STATE_OPEN) {
return;
}
//Check packet checksum
uint32_t checksum;
int32_t len = msg.getLength() - msg.getBufferPosition() - NetworkMessage::CHECKSUM_LENGTH;
if (len > 0) {
checksum = adlerChecksum(msg.getBuffer() + msg.getBufferPosition() + NetworkMessage::CHECKSUM_LENGTH, len);
}
else {
checksum = 0;
}
uint32_t recvChecksum = msg.get<uint32_t>();
if (recvChecksum != checksum) {
// it might not have been the checksum, step back
msg.skipBytes(-NetworkMessage::CHECKSUM_LENGTH);
}
if (!receivedFirst) {
// First message received
receivedFirst = true;
if (!protocol) {
// Game protocol has already been created at this point
protocol = service_port->make_protocol(msg, shared_from_this());
protocol = service_port->make_protocol(recvChecksum == checksum, msg, shared_from_this());
if (!protocol) {
close(FORCE_CLOSE);
return;
}
} else {
}
else {
msg.skipBytes(1); // Skip protocol ID
}
protocol->onRecvFirstMessage(msg);
} else {
}
else {
protocol->onRecvMessage(msg); // Send the packet to the current protocol
}
try {
readTimer.expires_from_now(boost::posix_time::seconds(CONNECTION_READ_TIMEOUT));
readTimer.async_wait(std::bind(&Connection::handleTimeout, std::weak_ptr<Connection>(shared_from_this()),
std::placeholders::_1));
std::placeholders::_1));
// Wait to the next packet
boost::asio::async_read(socket,
boost::asio::buffer(msg.getBuffer(), NetworkMessage::HEADER_LENGTH),
std::bind(&Connection::parseHeader, shared_from_this(), std::placeholders::_1));
} catch (boost::system::system_error& e) {
boost::asio::buffer(msg.getBuffer(), NetworkMessage::HEADER_LENGTH),
std::bind(&Connection::parseHeader, shared_from_this(), std::placeholders::_1));
}
catch (boost::system::system_error& e) {
std::cout << "[Network error - Connection::parsePacket] " << e.what() << std::endl;
close(FORCE_CLOSE);
}
}
void Connection::send(const OutputMessage_ptr& msg)
{
std::lock_guard<std::recursive_mutex> lockClass(connectionLock);