Merge branch '0.7.0' of https://github.com/TES3MP/openmw-tes3mp into 0.7.0

remotes/1728160796594174844/tmp_0.7.0-alpha
David Cernat 7 years ago
commit 6c50d4199b

@ -1,6 +1,9 @@
TES3MP
======
Copyright (c) 2008-2015, OpenMW Team
Copyright (c) 2016-2018, TES3MP Team
[![Build Status](https://travis-ci.org/TES3MP/openmw-tes3mp.svg?branch=master)](https://travis-ci.org/TES3MP/openmw-tes3mp)
TES3MP is a project aiming to add multiplayer functionality to [OpenMW](https://github.com/OpenMW/openmw), an open-source game engine that supports playing "The Elder Scrolls III: Morrowind" by Bethesda Softworks.

@ -212,18 +212,15 @@ void Networking::processWorldstatePacket(RakNet::Packet *packet)
}
void Networking::update(RakNet::Packet *packet)
bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn)
{
Player *player = Players::getPlayer(packet->guid);
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
bsIn.IgnoreBytes((unsigned int) RakNet::RakNetGUID::size()); // Ignore GUID from received packet
if (player == nullptr)
{
if (packet->data[0] == ID_GAME_PREINIT)
if (packet->data[0] != ID_GAME_PREINIT)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s sent wrong first packet (ID_GAME_PREINIT was expected)",
packet->systemAddress.ToString());
peer->CloseConnection(packet->systemAddress, true);
}
DEBUG_PRINTF("ID_GAME_PREINIT");
PacketPreInit::PluginContainer plugins;
@ -232,11 +229,11 @@ void Networking::update(RakNet::Packet *packet)
packetPreInit.setChecksums(&plugins);
packetPreInit.Read();
if (!packetPreInit.isPacketValid())
if (!packetPreInit.isPacketValid() || plugins.empty())
{
LOG_APPEND(Log::LOG_ERROR, "Invalid packetPreInit");
peer->CloseConnection(packet->systemAddress, false); // close connection without notification
return;
return false;
}
auto plugin = plugins.begin();
@ -257,7 +254,6 @@ void Networking::update(RakNet::Packet *packet)
// the server
if (it == hashList.end())
break;
}
else // name is incorrect
break;
@ -280,20 +276,20 @@ void Networking::update(RakNet::Packet *packet)
PacketPreInit::PluginContainer tmp;
packetPreInit.setChecksums(&tmp);
packetPreInit.Send(packet->systemAddress);
Players::newPlayer(packet->guid); // create player if connection allowed
playerPacketController->SetStream(&bsIn, nullptr); // and request handshake
playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
return true;
}
return;
}
playerPacketController->SetStream(&bsIn, 0);
playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
Players::newPlayer(packet->guid);
player = Players::getPlayer(packet->guid);
return;
return false;
}
else if (playerPacketController->ContainsPacket(packet->data[0]))
void Networking::update(RakNet::Packet *packet, RakNet::BitStream &bsIn)
{
if (playerPacketController->ContainsPacket(packet->data[0]))
{
playerPacketController->SetStream(&bsIn, 0);
playerPacketController->SetStream(&bsIn, nullptr);
processPlayerPacket(packet);
}
else if (actorPacketController->ContainsPacket(packet->data[0]))
@ -531,10 +527,19 @@ int Networking::mainLoop()
case ID_UNCONNECTED_PING:
break;
default:
update(packet);
{
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
bsIn.IgnoreBytes((unsigned int) RakNet::RakNetGUID::size()); // Ignore GUID from received packet
if (Players::isPlayerExists(packet->guid))
update(packet, bsIn);
else
preInit(packet, bsIn);
break;
}
}
}
TimerAPI::Tick();
this_thread::sleep_for(chrono::milliseconds(1));
}

@ -29,7 +29,7 @@ namespace mwmp
void processActorPacket(RakNet::Packet *packet);
void processObjectPacket(RakNet::Packet *packet);
void processWorldstatePacket(RakNet::Packet *packet);
void update(RakNet::Packet *packet);
void update(RakNet::Packet *packet, RakNet::BitStream &bsIn);
unsigned short numberOfConnections() const;
unsigned int maxConnections() const;
@ -65,6 +65,7 @@ namespace mwmp
void postInit();
private:
bool preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn);
PacketPreInit::PluginContainer getPluginListSample();
std::string serverPassword;
static Networking *sThis;

@ -54,9 +54,10 @@ void Players::newPlayer(RakNet::RakNetGUID guid)
Player *Players::getPlayer(RakNet::RakNetGUID guid)
{
if (players.count(guid) == 0)
auto it = players.find(guid);
if (it == players.end())
return nullptr;
return players[guid];
return it->second;
}
TPlayers *Players::getPlayers()
@ -123,9 +124,10 @@ int Player::getLoadState()
Player *Players::getPlayer(unsigned short id)
{
if (slots.find(id) == slots.end())
auto it = slots.find(id);
if (it == slots.end())
return nullptr;
return slots[id];
return it->second;
}
CellController::TContainer *Player::getCells()
@ -174,3 +176,8 @@ void Player::forEachLoaded(std::function<void(Player *pl, Player *other)> func)
func(this, pl);
}
}
bool Players::isPlayerExists(RakNet::RakNetGUID guid)
{
return players.find(guid) != players.end();
}

@ -34,6 +34,7 @@ public:
static Player *getPlayer(unsigned short id);
static TPlayers *getPlayers();
static unsigned short getLastPlayerId();
static bool isPlayerExists(RakNet::RakNetGUID guid);
private:
static TPlayers players;

Loading…
Cancel
Save