Merge pull request #452 from TES3MP/0.6.3 while resolving conflicts

Conflicts:
	apps/openmw-mp/Script/Functions/Worldstate.cpp
	apps/openmw/mwmp/Worldstate.cpp
	components/openmw-mp/Base/BaseWorldstate.hpp
This commit is contained in:
David Cernat 2018-06-25 04:44:30 +03:00
commit d5b3d08ec9
7 changed files with 94 additions and 31 deletions

View file

@ -172,10 +172,19 @@ void MapTiles::processUpdate()
} }
void MapTiles::addMapTile(const MapTile &mapTile) void MapTiles::addMapTile(const MapTile &mapTile)
{
if (mapTile.mapTile.imageData.size() > mwmp::maxImageDataSize)
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Error loading image file for map tile: "
"%i, %i has a size of %i, which is over the maximum allowed of %i!",
mapTile.mapTile.x, mapTile.mapTile.y, mapTile.mapTile.imageData.size(), mwmp::maxImageDataSize);
}
else
{ {
mwmp::Networking::get().get().getServerWorldstate()->mapChanges.mapTiles.push_back(mapTile.mapTile); mwmp::Networking::get().get().getServerWorldstate()->mapChanges.mapTiles.push_back(mapTile.mapTile);
setChanged(); setChanged();
} }
}
MapTile MapTiles::getMapTile(int id) const MapTile MapTiles::getMapTile(int id) const
{ {

View file

@ -31,21 +31,43 @@ Networking *Worldstate::getNetworking()
return mwmp::Main::get().getNetworking(); return mwmp::Main::get().getNetworking();
} }
void Worldstate::sendMapExplored(int x, int y, const std::vector<char>& imageData) bool Worldstate::containsExploredMapTile(int cellX, int cellY)
{
for (const auto &mapTile : exploredMapTiles)
{
if (mapTile.x == cellX && mapTile.y == cellY)
return true;
}
return false;
}
void Worldstate::markExploredMapTile(int cellX, int cellY)
{
mwmp::BaseMapTile exploredTile;
exploredTile.x = cellX;
exploredTile.y = cellY;
exploredMapTiles.push_back(exploredTile);
}
void Worldstate::sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData)
{ {
mapChanges.mapTiles.clear(); mapChanges.mapTiles.clear();
mwmp::BaseMapTile mapTile; mwmp::BaseMapTile mapTile;
mapTile.x = x; mapTile.x = cellX;
mapTile.y = y; mapTile.y = cellY;
mapTile.imageData = imageData; mapTile.imageData = imageData;
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_MAP with x: %i, y: %i", x, y); LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Sending ID_PLAYER_MAP with x: %i, y: %i", cellX, cellY);
mapChanges.mapTiles.push_back(mapTile); mapChanges.mapTiles.push_back(mapTile);
getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->setWorldstate(this); getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->setWorldstate(this);
getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->Send(); getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->Send();
// Keep this tile marked as explored so we don't send any more packets for it
markExploredMapTile(mapTile.x, mapTile.y);
} }
void Worldstate::setMapExplored() void Worldstate::setMapExplored()
@ -58,5 +80,8 @@ void Worldstate::setMapExplored()
MWBase::Environment::get().getWindowManager()->addVisitedLocation(cellStore->getCell()->mName, mapTile.x, mapTile.y); MWBase::Environment::get().getWindowManager()->addVisitedLocation(cellStore->getCell()->mName, mapTile.x, mapTile.y);
MWBase::Environment::get().getWindowManager()->setGlobalMapImage(mapTile.x, mapTile.y, mapTile.imageData); MWBase::Environment::get().getWindowManager()->setGlobalMapImage(mapTile.x, mapTile.y, mapTile.imageData);
// Keep this tile marked as explored so we don't send any more packets for it
markExploredMapTile(mapTile.x, mapTile.y);
} }
} }

View file

@ -13,11 +13,18 @@ namespace mwmp
Worldstate(); Worldstate();
virtual ~Worldstate(); virtual ~Worldstate();
bool containsExploredMapTile(int cellX, int cellY);
void markExploredMapTile(int cellX, int cellY);
void setMapExplored(); void setMapExplored();
void sendMapExplored(int x, int y, const std::vector<char>& imageData); void sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData);
private: private:
std::vector<BaseMapTile> exploredMapTiles;
Networking *getNetworking(); Networking *getNetworking();
}; };

View file

@ -636,11 +636,20 @@ namespace MWRender
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_PLAYER_MAP packet with this map tile to the server Send an ID_PLAYER_MAP packet with this map tile to the server, but only if:
1) We have recorded the exterior cell corresponding to this tile's coordinates
2) The tile has not previously been marked as explored in this client's mwmp::Worldstate
*/ */
if (originToCellX.count(imageDest.mX) > 0 && originToCellY.count(imageDest.mY) > 0) if (originToCellX.count(imageDest.mX) > 0 && originToCellY.count(imageDest.mY) > 0)
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "New global map tile corresponds to cell %i, %i", originToCellX.at(imageDest.mX), originToCellY.at(imageDest.mY)); int cellX = originToCellX.at(imageDest.mX);
int cellY = originToCellY.at(imageDest.mY);
mwmp::Worldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate();
if (!worldstate->containsExploredMapTile(cellX, cellY))
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "New global map tile corresponds to cell %i, %i", originToCellX.at(imageDest.mX), originToCellY.at(imageDest.mY));
osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png"); osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png");
if (!readerwriter) if (!readerwriter)
@ -661,7 +670,8 @@ namespace MWRender
std::string stringData = ostream.str(); std::string stringData = ostream.str();
std::vector<char> vectorData = std::vector<char>(stringData.begin(), stringData.end()); std::vector<char> vectorData = std::vector<char>(stringData.begin(), stringData.end());
mwmp::Main::get().getNetworking()->getWorldstate()->sendMapExplored(originToCellX.at(imageDest.mX), originToCellY.at(imageDest.mY), vectorData); worldstate->sendMapExplored(cellX, cellY, vectorData);
}
} }
/* /*
End of tes3mp addition End of tes3mp addition

View file

@ -9,6 +9,8 @@
namespace mwmp namespace mwmp
{ {
static const int maxImageDataSize = 1800;
struct BaseMapTile struct BaseMapTile
{ {
int x; int x;

View file

@ -1,4 +1,5 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Log.hpp>
#include "PacketWorldMap.hpp" #include "PacketWorldMap.hpp"
using namespace std; using namespace std;
@ -31,17 +32,25 @@ void PacketWorldMap::Packet(RakNet::BitStream *bs, bool send)
RW(mapTile.x, send); RW(mapTile.x, send);
RW(mapTile.y, send); RW(mapTile.y, send);
uint32_t imageDataCount; uint32_t imageDataSize;
if (send) if (send)
imageDataCount = static_cast<uint32_t>(mapTile.imageData.size()); imageDataSize = static_cast<uint32_t>(mapTile.imageData.size());
RW(imageDataCount, send); RW(imageDataSize, send);
if (imageDataSize > mwmp::maxImageDataSize)
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Processed invalid ID_WORLD_MAP packet where tile %i, %i had an imageDataSize of %i",
mapTile.x, mapTile.y, imageDataSize);
LOG_APPEND(Log::LOG_ERROR, "- The packet was ignored after that point");
return;
}
if (!send) if (!send)
{ {
mapTile.imageData.clear(); mapTile.imageData.clear();
mapTile.imageData.resize(imageDataCount); mapTile.imageData.resize(imageDataSize);
} }
for (auto &&imageChar : mapTile.imageData) for (auto &&imageChar : mapTile.imageData)

View file

@ -49,6 +49,7 @@ Special thanks (in alphabetical order)
Camul Camul
David Wery David Wery
DestinedToDie DestinedToDie
Donovan Ando
Gluka Gluka
Goodevil Goodevil
greetasdf greetasdf