|
@@ -5,93 +5,85 @@
|
|
|
|
|
|
NetworkMessage::NetworkMessage()
|
|
|
{
|
|
|
- adress = 0;
|
|
|
- adressLength = 0;
|
|
|
+ address = 0;
|
|
|
+ addressLength = 0;
|
|
|
broadcast = 0;
|
|
|
message = 0;
|
|
|
msgDelete = 0;
|
|
|
msgLength = 0;
|
|
|
useBackground = 0;
|
|
|
- minPosition.x = std::numeric_limits<float>::min();
|
|
|
- minPosition.y = std::numeric_limits<float>::min();
|
|
|
- minPosition.z = std::numeric_limits<float>::min();
|
|
|
- maxPosition.x = std::numeric_limits<float>::max();
|
|
|
- maxPosition.y = std::numeric_limits<float>::max();
|
|
|
- maxPosition.z = std::numeric_limits<float>::max();
|
|
|
- affectedDimension = -1;
|
|
|
}
|
|
|
|
|
|
NetworkMessage::~NetworkMessage()
|
|
|
{
|
|
|
if (msgDelete)
|
|
|
delete[] message;
|
|
|
- delete[] adress;
|
|
|
+ delete[] address;
|
|
|
}
|
|
|
|
|
|
-void NetworkMessage::adressChunck(Chunk* zChunk)
|
|
|
+void NetworkMessage::addressChunck(Chunk* zChunk)
|
|
|
{
|
|
|
- delete[] adress;
|
|
|
- adressLength = 10;
|
|
|
- adress = new char[adressLength];
|
|
|
- adress[0] = 1; // dimension response
|
|
|
- adress[1] = 1; // chunck
|
|
|
+ delete[] address;
|
|
|
+ addressLength = 10;
|
|
|
+ address = new char[addressLength];
|
|
|
+ address[0] = 1; // dimension response
|
|
|
+ address[1] = 1; // chunck
|
|
|
Framework::Punkt center = zChunk->getCenter();
|
|
|
- *(int*)(adress + 2) = center.x;
|
|
|
- *(int*)(adress + 6) = center.y;
|
|
|
- minPosition = zChunk->getMin();
|
|
|
- maxPosition = zChunk->getMax();
|
|
|
- affectedDimension = zChunk->getDimensionId();
|
|
|
+ *(int*)(address + 2) = center.x;
|
|
|
+ *(int*)(address + 6) = center.y;
|
|
|
}
|
|
|
|
|
|
-void NetworkMessage::adressEntity(Entity* zEntity)
|
|
|
+void NetworkMessage::addressEntity(Entity* zEntity)
|
|
|
{
|
|
|
- delete[] adress;
|
|
|
- adressLength = 6;
|
|
|
- adress = new char[adressLength];
|
|
|
- adress[0] = 1; // dimension response
|
|
|
- adress[1] = 2; // entity
|
|
|
- *(int*)(adress + 2) = zEntity->getId();
|
|
|
- minPosition = zEntity->getPosition();
|
|
|
- maxPosition = zEntity->getPosition();
|
|
|
- affectedDimension = zEntity->getCurrentDimensionId();
|
|
|
+ delete[] address;
|
|
|
+ addressLength = 6;
|
|
|
+ address = new char[addressLength];
|
|
|
+ address[0] = 1; // dimension response
|
|
|
+ address[1] = 2; // entity
|
|
|
+ *(int*)(address + 2) = zEntity->getId();
|
|
|
}
|
|
|
|
|
|
-void NetworkMessage::adressBlock(Block* zBlock)
|
|
|
+void NetworkMessage::addressDimension()
|
|
|
{
|
|
|
- delete[] adress;
|
|
|
- adressLength = 14;
|
|
|
- adress = new char[adressLength];
|
|
|
- adress[0] = 1; // dimension response
|
|
|
- adress[1] = 3; // block
|
|
|
+ delete[] address;
|
|
|
+ addressLength = 1;
|
|
|
+ address = new char[1];
|
|
|
+ address[0] = 1; // dimension response
|
|
|
+}
|
|
|
+
|
|
|
+void NetworkMessage::addressBlock(Block* zBlock)
|
|
|
+{
|
|
|
+ delete[] address;
|
|
|
+ addressLength = 14;
|
|
|
+ address = new char[addressLength];
|
|
|
+ address[0] = 1; // dimension response
|
|
|
+ address[1] = 3; // block
|
|
|
Framework::Vec3<int> pos = zBlock->getPos();
|
|
|
- *(int*)(adress + 2) = pos.x;
|
|
|
- *(int*)(adress + 6) = pos.y;
|
|
|
- *(int*)(adress + 10) = pos.z;
|
|
|
- minPosition = pos;
|
|
|
- maxPosition = pos;
|
|
|
- affectedDimension = zBlock->getDimensionId();
|
|
|
+ *(int*)(address + 2) = pos.x;
|
|
|
+ *(int*)(address + 6) = pos.y;
|
|
|
+ *(int*)(address + 10) = pos.z;
|
|
|
}
|
|
|
|
|
|
void NetworkMessage::openDialog(Framework::Text dialogName)
|
|
|
{
|
|
|
- delete[] adress;
|
|
|
- adressLength = (char)(4 + dialogName.getLength());
|
|
|
- adress = new char[adressLength];
|
|
|
- adress[0] = 2; // gui message
|
|
|
- adress[1] = 0; // open dialog
|
|
|
- *(short*)(adress + 2) = (short)dialogName.getLength(); // block
|
|
|
- memcpy(adress + 4, dialogName.getText(), dialogName.getLength());
|
|
|
+ delete[] address;
|
|
|
+ addressLength = (char)(4 + dialogName.getLength());
|
|
|
+ address = new char[addressLength];
|
|
|
+ address[0] = 2; // gui message
|
|
|
+ address[1] = 0; // open dialog
|
|
|
+ *(short*)(address + 2) = (short)dialogName.getLength(); // block
|
|
|
+ memcpy(address + 4, dialogName.getText(), dialogName.getLength());
|
|
|
}
|
|
|
|
|
|
-void NetworkMessage::adressGui(Framework::Text elementId)
|
|
|
+void NetworkMessage::addressGui(Framework::Text elementId)
|
|
|
{
|
|
|
- delete[] adress;
|
|
|
- adressLength = (char)(4 + elementId.getLength());
|
|
|
- adress = new char[adressLength];
|
|
|
- adress[0] = 2; // gui message
|
|
|
- adress[1] = 1; // element message
|
|
|
- *(short*)(adress + 2) = (short)elementId.getLength(); // block
|
|
|
- memcpy(adress + 4, elementId.getText(), elementId.getLength());
|
|
|
+ delete[] address;
|
|
|
+ addressLength = (char)(4 + elementId.getLength());
|
|
|
+ address = new char[addressLength];
|
|
|
+ address[0] = 2; // gui message
|
|
|
+ address[1] = 1; // element message
|
|
|
+ *(short*)(address + 2) = (short)elementId.getLength(); // block
|
|
|
+ memcpy(address + 4, elementId.getText(), elementId.getLength());
|
|
|
}
|
|
|
|
|
|
void NetworkMessage::setMessage(char* msg, int length, bool deleteMsg)
|
|
@@ -113,21 +105,14 @@ void NetworkMessage::sendToAll()
|
|
|
broadcast = true;
|
|
|
}
|
|
|
|
|
|
-bool NetworkMessage::isAreaAffected(Framework::Vec3<float> min, Framework::Vec3<float> max, int affectedDimension) const
|
|
|
-{
|
|
|
- return minPosition.x <= max.x && maxPosition.x >= min.x &&
|
|
|
- minPosition.y <= max.y && maxPosition.y >= min.y &&
|
|
|
- minPosition.z <= max.z && maxPosition.z >= min.z && (this->affectedDimension < 0 || this->affectedDimension == affectedDimension);
|
|
|
-}
|
|
|
-
|
|
|
void NetworkMessage::writeTo(Framework::StreamWriter* zWriter) const
|
|
|
{
|
|
|
- int total = msgLength + adressLength;
|
|
|
+ int total = msgLength + addressLength;
|
|
|
if (total)
|
|
|
{
|
|
|
zWriter->schreibe((char*)&GameClient::Message::API_MESSAGE, 1);
|
|
|
zWriter->schreibe((char*)&total, 4);
|
|
|
- zWriter->schreibe(adress, adressLength);
|
|
|
+ zWriter->schreibe(address, addressLength);
|
|
|
zWriter->schreibe(message, msgLength);
|
|
|
}
|
|
|
}
|
|
@@ -139,7 +124,7 @@ bool NetworkMessage::isBroadcast() const
|
|
|
|
|
|
bool NetworkMessage::isEmpty() const
|
|
|
{
|
|
|
- return msgLength + adressLength <= 0;
|
|
|
+ return msgLength + addressLength <= 0;
|
|
|
}
|
|
|
|
|
|
bool NetworkMessage::isUseBackground() const
|