2016-01-04 12:17:30 +00:00
|
|
|
//
|
2016-01-12 03:41:44 +00:00
|
|
|
// Created by koncord on 04.01.16.
|
2016-01-04 12:17:30 +00:00
|
|
|
//
|
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <components/esm/cellid.hpp>
|
2016-10-24 14:52:19 +00:00
|
|
|
|
2016-11-17 15:16:25 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
#include "../mwworld/inventorystore.hpp"
|
|
|
|
|
|
|
|
#include "../mwclass/npc.hpp"
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
#include "../mwmechanics/combat.hpp"
|
2016-10-24 14:52:19 +00:00
|
|
|
|
2016-08-04 16:31:15 +00:00
|
|
|
#include <SDL_messagebox.h>
|
2016-01-04 12:17:30 +00:00
|
|
|
#include "Networking.hpp"
|
|
|
|
#include "../mwstate/statemanagerimp.hpp"
|
2016-08-18 17:20:17 +00:00
|
|
|
#include <components/openmw-mp/Log.hpp>
|
2016-08-27 07:36:22 +00:00
|
|
|
#include <components/openmw-mp/Version.hpp>
|
2017-03-04 05:23:26 +00:00
|
|
|
#include <components/files/configurationmanager.hpp>
|
|
|
|
#include <components/openmw-mp/Utils.hpp>
|
2017-03-05 08:55:05 +00:00
|
|
|
#include <components/openmw-mp/Packets/PacketPreInit.hpp>
|
2016-01-12 03:41:44 +00:00
|
|
|
#include "DedicatedPlayer.hpp"
|
2016-12-16 08:59:15 +00:00
|
|
|
#include "LocalPlayer.hpp"
|
|
|
|
#include "GUIController.hpp"
|
|
|
|
#include "WorldController.hpp"
|
2016-01-12 03:41:44 +00:00
|
|
|
#include "Main.hpp"
|
2016-01-04 12:17:30 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2016-01-12 03:41:44 +00:00
|
|
|
using namespace mwmp;
|
2016-01-04 12:17:30 +00:00
|
|
|
|
2016-10-19 19:49:35 +00:00
|
|
|
Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerController(peer), worldController(peer)
|
2016-01-04 12:17:30 +00:00
|
|
|
{
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
RakNet::SocketDescriptor sd;
|
|
|
|
sd.port=0;
|
|
|
|
RakNet::StartupResult b = peer->Startup(1,&sd, 1);
|
|
|
|
RakAssert(b==RAKNET_STARTED);
|
|
|
|
|
2016-10-19 19:49:35 +00:00
|
|
|
playerController.SetStream(0, &bsOut);
|
|
|
|
worldController.SetStream(0, &bsOut);
|
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
connected = 0;
|
2016-01-04 12:17:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
Networking::~Networking()
|
2016-01-04 12:17:30 +00:00
|
|
|
{
|
2016-01-12 03:41:44 +00:00
|
|
|
peer->Shutdown(100);
|
|
|
|
peer->CloseConnection(peer->GetSystemAddressFromIndex(0), true, 0);
|
|
|
|
RakNet::RakPeerInterface::DestroyInstance(peer);
|
2016-01-04 12:17:30 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 19:54:06 +00:00
|
|
|
void Networking::update()
|
2016-01-04 12:17:30 +00:00
|
|
|
{
|
2016-01-12 03:41:44 +00:00
|
|
|
RakNet::Packet *packet;
|
2016-08-24 23:58:03 +00:00
|
|
|
std::string errmsg = "";
|
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
for (packet=peer->Receive(); packet; peer->DeallocatePacket(packet), packet=peer->Receive())
|
|
|
|
{
|
|
|
|
switch (packet->data[0])
|
|
|
|
{
|
|
|
|
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Another client has disconnected.");
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
case ID_REMOTE_CONNECTION_LOST:
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Another client has lost connection.");
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
case ID_REMOTE_NEW_INCOMING_CONNECTION:
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Another client has connected.");
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
case ID_CONNECTION_REQUEST_ACCEPTED:
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Our connection request has been accepted.");
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
case ID_NEW_INCOMING_CONNECTION:
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "A connection is incoming.");
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
case ID_NO_FREE_INCOMING_CONNECTIONS:
|
2016-11-21 21:40:50 +00:00
|
|
|
errmsg = "The server is full.";
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
case ID_DISCONNECTION_NOTIFICATION:
|
2016-08-24 23:58:03 +00:00
|
|
|
errmsg = "We have been disconnected.";
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
case ID_CONNECTION_LOST:
|
2016-08-24 23:58:03 +00:00
|
|
|
errmsg = "Connection lost.";
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
2016-11-15 19:54:06 +00:00
|
|
|
receiveMessage(packet);
|
2016-08-19 04:54:10 +00:00
|
|
|
//LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Message with identifier %i has arrived.", packet->data[0]);
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-08-24 23:58:03 +00:00
|
|
|
|
2016-09-28 11:27:35 +00:00
|
|
|
if (!errmsg.empty())
|
|
|
|
{
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, errmsg.c_str());
|
2016-08-24 23:58:03 +00:00
|
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "tes3mp", errmsg.c_str(), 0);
|
|
|
|
MWBase::Environment::get().getStateManager()->requestQuit();
|
|
|
|
}
|
2016-01-04 12:17:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 05:23:26 +00:00
|
|
|
void Networking::connect(const std::string &ip, unsigned short port, std::vector<string> &content, Files::Collections &collections)
|
2016-01-04 12:17:30 +00:00
|
|
|
{
|
2016-01-12 03:41:44 +00:00
|
|
|
RakNet::SystemAddress master;
|
|
|
|
master.SetBinaryAddress(ip.c_str());
|
|
|
|
master.SetPortHostOrder(port);
|
2016-08-09 10:25:52 +00:00
|
|
|
std::string errmsg = "";
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-09-18 03:49:30 +00:00
|
|
|
stringstream sstr(TES3MP_VERSION);
|
|
|
|
sstr << TES3MP_PROTO_VERSION;
|
|
|
|
|
|
|
|
if (peer->Connect(master.ToString(false), master.GetPort(), sstr.str().c_str(), (int) sstr.str().size(), 0, 0, 3, 500, 0) != RakNet::CONNECTION_ATTEMPT_STARTED)
|
2016-08-09 10:25:52 +00:00
|
|
|
errmsg = "Connection attempt failed.\n";
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
bool queue = true;
|
2016-08-17 15:20:36 +00:00
|
|
|
while (queue)
|
2016-01-04 12:17:30 +00:00
|
|
|
{
|
2016-01-12 03:41:44 +00:00
|
|
|
for (RakNet::Packet *packet = peer->Receive(); packet; peer->DeallocatePacket(
|
|
|
|
packet), packet = peer->Receive())
|
|
|
|
{
|
|
|
|
switch (packet->data[0])
|
|
|
|
{
|
|
|
|
case ID_CONNECTION_ATTEMPT_FAILED:
|
|
|
|
{
|
2016-08-04 16:31:15 +00:00
|
|
|
errmsg = "Connection failed.\n"
|
2016-08-24 23:58:03 +00:00
|
|
|
"Either the IP address is wrong or a firewall on either system is blocking\n"
|
2016-08-04 16:31:15 +00:00
|
|
|
"UDP packets on the port you have chosen.";
|
2016-01-12 03:41:44 +00:00
|
|
|
queue = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_INVALID_PASSWORD:
|
|
|
|
{
|
2016-08-04 16:31:15 +00:00
|
|
|
errmsg = "Connection failed.\n"
|
2016-09-28 05:26:18 +00:00
|
|
|
"The client or server is outdated.";
|
2016-01-12 03:41:44 +00:00
|
|
|
queue = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_CONNECTION_REQUEST_ACCEPTED:
|
|
|
|
{
|
|
|
|
serverAddr = packet->systemAddress;
|
|
|
|
connected = true;
|
|
|
|
queue = false;
|
2016-01-04 12:17:30 +00:00
|
|
|
|
2016-08-19 04:54:10 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_CONNECTION_REQUESTED_ACCEPTED from %s",
|
2017-03-04 06:55:35 +00:00
|
|
|
serverAddr.ToString());
|
2016-08-18 19:29:54 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_DISCONNECTION_NOTIFICATION:
|
|
|
|
throw runtime_error("ID_DISCONNECTION_NOTIFICATION.\n");
|
|
|
|
case ID_CONNECTION_BANNED:
|
|
|
|
throw runtime_error("ID_CONNECTION_BANNED.\n");
|
|
|
|
case ID_CONNECTION_LOST:
|
|
|
|
throw runtime_error("ID_CONNECTION_LOST.\n");
|
|
|
|
default:
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Connection message with identifier %i has arrived in initialization.",
|
|
|
|
packet->data[0]);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-04 12:17:30 +00:00
|
|
|
}
|
2016-08-09 10:25:52 +00:00
|
|
|
|
2017-03-05 08:55:05 +00:00
|
|
|
if (!errmsg.empty())
|
|
|
|
{
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, errmsg.c_str());
|
|
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "tes3mp", errmsg.c_str(), 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
preInit(content, collections);
|
|
|
|
}
|
2017-03-04 05:23:26 +00:00
|
|
|
|
2017-03-05 08:55:05 +00:00
|
|
|
void Networking::preInit(std::vector<std::string> &content, Files::Collections &collections)
|
|
|
|
{
|
|
|
|
std::string errmsg = "";
|
|
|
|
PacketPreInit::PluginContainer checksums;
|
2017-03-04 05:23:26 +00:00
|
|
|
vector<string>::const_iterator it(content.begin());
|
|
|
|
for (int idx = 0; it != content.end(); ++it, ++idx)
|
|
|
|
{
|
|
|
|
boost::filesystem::path filename(*it);
|
|
|
|
const Files::MultiDirCollection& col = collections.getCollection(filename.extension().string());
|
|
|
|
if (col.doesExist(*it))
|
|
|
|
{
|
|
|
|
unsigned int crc32 = Utils::crc32checksum(col.getPath(*it).string());
|
2017-03-05 08:55:05 +00:00
|
|
|
checksums.push_back(make_pair(*it, crc32));
|
|
|
|
|
2017-04-01 02:57:27 +00:00
|
|
|
printf("idx: %d\tchecksum: %X\tfile: %s\n", idx, crc32, col.getPath(*it).string().c_str());
|
2017-03-04 05:23:26 +00:00
|
|
|
}
|
|
|
|
else
|
2017-04-01 02:57:27 +00:00
|
|
|
throw std::runtime_error("Plugin doesn't exist.");
|
2017-03-05 08:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PacketPreInit packetPreInit(peer);
|
|
|
|
RakNet::BitStream bs;
|
|
|
|
RakNet::RakNetGUID guid;
|
2017-03-06 14:52:18 +00:00
|
|
|
packetPreInit.setChecksums(&checksums);
|
2017-03-06 09:44:08 +00:00
|
|
|
packetPreInit.setGUID(guid);
|
2017-03-06 14:52:18 +00:00
|
|
|
packetPreInit.SetSendStream(&bs);
|
|
|
|
packetPreInit.Send(serverAddr);
|
2017-03-06 09:44:08 +00:00
|
|
|
|
2017-03-05 08:55:05 +00:00
|
|
|
|
|
|
|
bool done = false;
|
|
|
|
PacketPreInit::PluginContainer checksumsResponse;
|
|
|
|
/*while (!done)
|
|
|
|
{
|
|
|
|
for (RakNet::Packet *packet = peer->Receive(); packet; peer->DeallocatePacket(packet), packet = peer->Receive())
|
|
|
|
{
|
|
|
|
if(packet->data[0] == ID_GAME_PREINIT)
|
|
|
|
{
|
|
|
|
RakNet::BitStream bsIn(&packet->data[0], packet->length, false);
|
|
|
|
packetPreInit.Packet(&bsIn, guid, false, checksumsResponse);
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if(!checksumsResponse.empty()) // something wrong
|
|
|
|
{
|
|
|
|
errmsg = "Your plugins\tShould be\n";
|
|
|
|
for(int i = 0; i < checksumsResponse.size(); i++)
|
|
|
|
{
|
|
|
|
errmsg += checksums[i].first + " " + MyGUI::utility::toString(checksums[i].second) + "\t";
|
|
|
|
errmsg += checksumsResponse[i].first + " " + MyGUI::utility::toString(checksumsResponse[i].second) + "\n";
|
2017-03-04 05:23:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 08:55:05 +00:00
|
|
|
|
2016-08-17 15:04:35 +00:00
|
|
|
if (!errmsg.empty())
|
2016-08-09 10:25:52 +00:00
|
|
|
{
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, errmsg.c_str());
|
2016-08-24 23:58:03 +00:00
|
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "tes3mp", errmsg.c_str(), 0);
|
2016-08-09 10:25:52 +00:00
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 19:54:06 +00:00
|
|
|
void Networking::processPlayerPacket(RakNet::Packet *packet)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
RakNet::RakNetGUID guid;
|
2016-08-05 06:21:09 +00:00
|
|
|
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
|
2016-10-26 12:55:34 +00:00
|
|
|
bsIn.Read(guid);
|
2016-01-04 12:17:30 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
DedicatedPlayer *pl = 0;
|
2016-10-26 12:55:34 +00:00
|
|
|
static RakNet::RakNetGUID myGuid = getLocalPlayer()->guid;
|
|
|
|
if (guid != myGuid)
|
2016-11-15 19:54:06 +00:00
|
|
|
pl = Players::getPlayer(guid);
|
2016-01-04 12:17:30 +00:00
|
|
|
|
2016-10-19 19:49:35 +00:00
|
|
|
PlayerPacket *myPacket = playerController.GetPacket(packet->data[0]);
|
2016-01-04 12:17:30 +00:00
|
|
|
|
2016-08-17 15:20:36 +00:00
|
|
|
switch (packet->data[0])
|
2016-01-04 12:17:30 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
case ID_HANDSHAKE:
|
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Send(serverAddr);
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_BASEINFO:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2017-02-05 07:01:33 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_BASEINFO from server");
|
2016-10-21 16:23:56 +00:00
|
|
|
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Packet was about my id");
|
2016-08-17 18:18:04 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
if (packet->length == myPacket->headerSize())
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Requesting info");
|
2017-03-06 09:44:08 +00:00
|
|
|
|
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Send(serverAddr);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Updating LocalPlayer");
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->updateChar();
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-01-25 15:06:15 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl == 0 ? "new player" : pl->npc.mName.c_str());
|
2016-10-21 16:23:56 +00:00
|
|
|
|
|
|
|
if (pl == 0)
|
2016-07-17 09:53:55 +00:00
|
|
|
{
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Exchanging data with new player");
|
2016-11-15 19:54:06 +00:00
|
|
|
pl = Players::newPlayer(guid);
|
2016-07-17 09:53:55 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-11-15 19:54:06 +00:00
|
|
|
Players::createPlayer(guid);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_POS:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
if (packet->length != myPacket->headerSize())
|
|
|
|
{
|
2017-02-05 07:01:33 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_PLAYER_POS changed by server");
|
2017-03-06 09:44:08 +00:00
|
|
|
|
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->setPosition();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
getLocalPlayer()->updatePosition(true);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else if (pl != 0)
|
2016-10-27 16:09:05 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-27 16:09:05 +00:00
|
|
|
pl->updateMarker();
|
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_USER_MYID:
|
|
|
|
{
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_USER_MYID from server");
|
2016-10-26 12:55:34 +00:00
|
|
|
myGuid = guid;
|
|
|
|
getLocalPlayer()->guid = guid;
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_USER_DISCONNECTED:
|
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-10-21 16:23:56 +00:00
|
|
|
MWBase::Environment::get().getStateManager()->requestQuit();
|
|
|
|
else if (pl != 0)
|
2016-11-15 19:54:06 +00:00
|
|
|
Players::disconnectPlayer(guid);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_EQUIPMENT:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
if (packet->length == myPacket->headerSize())
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-11-17 20:33:30 +00:00
|
|
|
getLocalPlayer()->updateEquipment(true);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-11-17 20:33:30 +00:00
|
|
|
getLocalPlayer()->setEquipment();
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else if (pl != 0)
|
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-11-17 20:33:30 +00:00
|
|
|
pl->updateEquipment();
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_INVENTORY:
|
2016-10-31 15:16:41 +00:00
|
|
|
{
|
|
|
|
if (guid == myGuid)
|
|
|
|
{
|
|
|
|
if (packet->length == myPacket->headerSize())
|
|
|
|
{
|
|
|
|
getLocalPlayer()->updateInventory(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2017-01-20 10:43:05 +00:00
|
|
|
int inventoryAction = getLocalPlayer()->inventoryChanges.action;
|
2016-11-20 02:06:33 +00:00
|
|
|
|
2017-01-20 10:43:05 +00:00
|
|
|
if (inventoryAction == InventoryChanges::ADD)
|
2016-10-31 15:16:41 +00:00
|
|
|
{
|
2017-01-19 13:18:37 +00:00
|
|
|
getLocalPlayer()->addItems();
|
2016-10-31 15:16:41 +00:00
|
|
|
}
|
2017-01-20 10:43:05 +00:00
|
|
|
else if (inventoryAction == InventoryChanges::REMOVE)
|
2016-10-31 15:16:41 +00:00
|
|
|
{
|
2017-01-19 13:18:37 +00:00
|
|
|
getLocalPlayer()->removeItems();
|
2016-10-31 15:16:41 +00:00
|
|
|
}
|
2017-01-20 10:43:05 +00:00
|
|
|
else // InventoryChanges::SET
|
2016-10-31 15:16:41 +00:00
|
|
|
{
|
2017-01-19 13:18:37 +00:00
|
|
|
getLocalPlayer()->setInventory();
|
2016-10-31 15:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_SPELLBOOK:
|
2016-11-21 00:28:05 +00:00
|
|
|
{
|
2016-12-29 13:19:26 +00:00
|
|
|
if (guid == myGuid)
|
|
|
|
{
|
|
|
|
if (packet->length == myPacket->headerSize())
|
|
|
|
{
|
2017-01-20 10:05:45 +00:00
|
|
|
getLocalPlayer()->sendSpellbook();
|
2016-12-29 13:19:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2017-01-20 10:43:05 +00:00
|
|
|
int spellbookAction = getLocalPlayer()->spellbookChanges.action;
|
2017-01-19 13:18:37 +00:00
|
|
|
|
2017-01-20 10:43:05 +00:00
|
|
|
if (spellbookAction == SpellbookChanges::ADD)
|
2017-01-19 13:18:37 +00:00
|
|
|
{
|
|
|
|
getLocalPlayer()->addSpells();
|
|
|
|
}
|
2017-01-20 10:43:05 +00:00
|
|
|
else if (spellbookAction == SpellbookChanges::REMOVE)
|
2017-01-19 13:18:37 +00:00
|
|
|
{
|
|
|
|
getLocalPlayer()->removeSpells();
|
|
|
|
}
|
2017-01-20 10:43:05 +00:00
|
|
|
else // SpellbookChanges::SET
|
2016-12-29 13:19:26 +00:00
|
|
|
{
|
2017-01-19 13:18:37 +00:00
|
|
|
getLocalPlayer()->setSpellbook();
|
2016-12-29 13:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-21 00:28:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_JOURNAL:
|
2017-01-20 09:15:10 +00:00
|
|
|
{
|
2017-01-24 17:32:25 +00:00
|
|
|
if (guid == myGuid)
|
|
|
|
{
|
|
|
|
if (packet->length == myPacket->headerSize())
|
|
|
|
{
|
|
|
|
// Entire journal cannot currently be requested from players
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2017-01-24 17:32:25 +00:00
|
|
|
getLocalPlayer()->addJournalItems();
|
|
|
|
}
|
|
|
|
}
|
2017-01-20 09:15:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_ATTACK:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
|
|
|
if (pl != 0)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
|
2016-11-15 19:54:06 +00:00
|
|
|
//cout << "Player: " << pl->Npc()->mName << " pressed: " << (pl->getAttack()->pressed == 1) << endl;
|
2017-01-25 15:06:15 +00:00
|
|
|
if (pl->attack.pressed == 0)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", pl->attack.success ? "true" : "false");
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2017-01-25 15:06:15 +00:00
|
|
|
if (pl->attack.success == 1)
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f", pl->attack.damage);
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWMechanics::CreatureStats &stats = pl->getPtr().getClass().getNpcStats(pl->getPtr());
|
2017-01-25 15:06:15 +00:00
|
|
|
stats.getSpells().setSelectedSpell(pl->attack.refid);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWWorld::Ptr victim;
|
2017-01-25 15:06:15 +00:00
|
|
|
if (pl->attack.target == getLocalPlayer()->guid)
|
2016-10-21 16:23:56 +00:00
|
|
|
victim = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
2017-01-25 15:06:15 +00:00
|
|
|
else if (Players::getPlayer(pl->attack.target) != 0)
|
|
|
|
victim = Players::getPlayer(pl->attack.target)->getPtr();
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWWorld::Ptr attacker;
|
|
|
|
attacker = pl->getPtr();
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
// Get the weapon used (if hand-to-hand, weapon = inv.end())
|
2017-01-25 15:06:15 +00:00
|
|
|
if (pl->drawState == 1)
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
|
|
|
MWWorld::InventoryStore &inv = attacker.getClass().getInventoryStore(attacker);
|
|
|
|
MWWorld::ContainerStoreIterator weaponslot = inv.getSlot(
|
|
|
|
MWWorld::InventoryStore::Slot_CarriedRight);
|
|
|
|
MWWorld::Ptr weapon = ((weaponslot != inv.end()) ? *weaponslot : MWWorld::Ptr());
|
|
|
|
if (!weapon.isEmpty() && weapon.getTypeName() != typeid(ESM::Weapon).name())
|
|
|
|
weapon = MWWorld::Ptr();
|
|
|
|
|
|
|
|
if (victim.mRef != 0)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
bool healthdmg;
|
|
|
|
if (!weapon.isEmpty())
|
|
|
|
healthdmg = true;
|
|
|
|
else
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim);
|
|
|
|
healthdmg = otherstats.isParalyzed() || otherstats.getKnockedDown();
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
|
|
|
|
if (!weapon.isEmpty())
|
2017-01-25 15:06:15 +00:00
|
|
|
MWMechanics::blockMeleeAttack(attacker, victim, weapon, pl->attack.damage, 1);
|
|
|
|
pl->getPtr().getClass().onHit(victim, pl->attack.damage, healthdmg, weapon, attacker, osg::Vec3f(),
|
|
|
|
pl->attack.success);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else
|
|
|
|
{
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", pl->attack.refid.c_str());
|
2017-01-25 15:06:15 +00:00
|
|
|
LOG_APPEND(Log::LOG_VERBOSE, " - success: %d", pl->attack.success);
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_DYNAMICSTATS:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
if (packet->length == myPacket->headerSize())
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->updateDynamicStats(true);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->setDynamicStats();
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else if (pl != 0)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
|
|
|
|
MWWorld::Ptr ptrPlayer = pl->getPtr();
|
|
|
|
MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer);
|
|
|
|
MWMechanics::DynamicStat<float> value;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-01-25 15:06:15 +00:00
|
|
|
value.readState(pl->creatureStats.mDynamic[i]);
|
2016-10-21 16:23:56 +00:00
|
|
|
ptrCreatureStats->setDynamic(i, value);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-27 23:38:25 +00:00
|
|
|
case ID_PLAYER_DEATH:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2017-02-27 23:38:25 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_DEATH from server");
|
2017-03-03 22:29:01 +00:00
|
|
|
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-03-03 22:29:01 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Packet was about me");
|
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
|
|
|
MWMechanics::DynamicStat<float> health = player.getClass().getCreatureStats(player).getHealth();
|
|
|
|
health.setCurrent(0);
|
|
|
|
player.getClass().getCreatureStats(player).setHealth(health);
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Send(serverAddr);
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
|
|
|
else if (pl != 0)
|
|
|
|
{
|
2017-01-25 15:06:15 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl->npc.mName.c_str());
|
2017-03-03 22:29:01 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWMechanics::DynamicStat<float> health;
|
2017-01-25 15:06:15 +00:00
|
|
|
pl->creatureStats.mDead = true;
|
|
|
|
health.readState(pl->creatureStats.mDynamic[0]);
|
2016-10-21 16:23:56 +00:00
|
|
|
health.setCurrent(0);
|
2017-01-25 15:06:15 +00:00
|
|
|
health.writeState(pl->creatureStats.mDynamic[0]);
|
2016-10-21 16:23:56 +00:00
|
|
|
pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-02-27 23:38:25 +00:00
|
|
|
case ID_PLAYER_RESURRECT:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2017-03-03 22:29:01 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_RESURRECT from server");
|
|
|
|
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2017-03-03 22:29:01 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Packet was about me");
|
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
|
|
|
player.getClass().getCreatureStats(player).resurrect();
|
2017-02-24 09:50:43 +00:00
|
|
|
|
|
|
|
// If this player had a weapon or spell readied when dying, they will
|
|
|
|
// still have it readied but be unable to use it unless we clear it here
|
|
|
|
player.getClass().getNpcStats(player).setDrawState(MWMechanics::DrawState_Nothing);
|
|
|
|
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Send(serverAddr);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->updateDynamicStats(true);
|
2017-03-06 09:44:08 +00:00
|
|
|
playerController.GetPacket(ID_PLAYER_DYNAMICSTATS)->setPlayer(getLocalPlayer());
|
|
|
|
playerController.GetPacket(ID_PLAYER_DYNAMICSTATS)->Send(serverAddr);
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
|
|
|
else if (pl != 0)
|
|
|
|
{
|
2017-03-03 22:29:01 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl->npc.mName.c_str());
|
|
|
|
|
2017-01-25 15:06:15 +00:00
|
|
|
pl->creatureStats.mDead = false;
|
|
|
|
if (pl->creatureStats.mDynamic[0].mMod < 1)
|
|
|
|
pl->creatureStats.mDynamic[0].mMod = 1;
|
|
|
|
pl->creatureStats.mDynamic[0].mCurrent = pl->creatureStats.mDynamic[0].mMod;
|
2016-01-04 12:17:30 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
pl->getPtr().getClass().getCreatureStats(pl->getPtr()).resurrect();
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWMechanics::DynamicStat<float> health;
|
2017-01-25 15:06:15 +00:00
|
|
|
health.readState(pl->creatureStats.mDynamic[0]);
|
2016-10-21 16:23:56 +00:00
|
|
|
pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-20 08:30:50 +00:00
|
|
|
case ID_PLAYER_CELL_CHANGE:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
if (packet->length == myPacket->headerSize())
|
|
|
|
getLocalPlayer()->updateCell(true);
|
|
|
|
else
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->setCell();
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-09-29 10:17:46 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else if (pl != 0)
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
pl->updateCell();
|
2016-09-29 10:17:46 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-26 11:49:20 +00:00
|
|
|
case ID_PLAYER_CELL_STATE:
|
2017-01-25 12:51:43 +00:00
|
|
|
{
|
2017-02-04 07:13:15 +00:00
|
|
|
if (guid == myGuid)
|
|
|
|
{
|
|
|
|
if (packet->length == myPacket->headerSize())
|
|
|
|
getLocalPlayer()->sendCellStates();
|
|
|
|
}
|
|
|
|
|
2017-01-25 12:51:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_DRAWSTATE:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->updateDrawStateAndFlags(true);
|
|
|
|
else if (pl != 0)
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-11-15 19:54:06 +00:00
|
|
|
pl->updateDrawState();
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_CHAT_MESSAGE:
|
|
|
|
{
|
|
|
|
std::string message;
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2017-01-25 15:06:15 +00:00
|
|
|
message = getLocalPlayer()->chatMessage;
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
|
|
|
else if (pl != 0)
|
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2017-01-25 15:06:15 +00:00
|
|
|
message = pl->chatMessage;
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
2016-11-15 19:54:06 +00:00
|
|
|
Main::get().getGUIController()->printChatMessage(message);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_CHARGEN:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-09-29 10:17:46 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-04 12:25:43 +00:00
|
|
|
case ID_PLAYER_ATTRIBUTE:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
if (packet->length == myPacket->headerSize())
|
|
|
|
{
|
|
|
|
getLocalPlayer()->updateAttributes(true);
|
|
|
|
}
|
|
|
|
else
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->setAttributes();
|
2016-09-29 10:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else if (pl != 0)
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWWorld::Ptr ptrPlayer = pl->getPtr();
|
|
|
|
MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer);
|
|
|
|
MWMechanics::AttributeValue attributeValue;
|
2016-09-25 11:28:25 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
for (int i = 0; i < 8; ++i)
|
|
|
|
{
|
2017-01-25 15:06:15 +00:00
|
|
|
attributeValue.readState(pl->creatureStats.mAttributes[i]);
|
2016-10-21 16:23:56 +00:00
|
|
|
ptrCreatureStats->setAttribute(i, attributeValue);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-09-29 10:17:46 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-04 12:25:43 +00:00
|
|
|
case ID_PLAYER_SKILL:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
if (packet->length == myPacket->headerSize())
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->updateSkills(true);
|
2016-09-29 10:17:46 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->setSkills();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pl != 0)
|
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWWorld::Ptr ptrPlayer = pl->getPtr();
|
|
|
|
MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer);
|
|
|
|
MWMechanics::SkillValue skillValue;
|
2016-09-25 11:28:25 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
for (int i = 0; i < 27; ++i)
|
|
|
|
{
|
2017-01-25 15:06:15 +00:00
|
|
|
skillValue.readState(pl->npcStats.mSkills[i]);
|
2016-10-21 16:23:56 +00:00
|
|
|
ptrNpcStats->setSkill(i, skillValue);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-09-29 10:17:46 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_LEVEL:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
if (packet->length == myPacket->headerSize())
|
2016-09-25 11:28:25 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->updateLevel(true);
|
2016-09-25 11:28:25 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->setLevel();
|
2016-09-29 10:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
else if (pl != 0)
|
2016-09-29 10:17:46 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(pl);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-07-23 14:02:06 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
MWWorld::Ptr ptrPlayer = pl->getPtr();
|
|
|
|
MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer);
|
2016-07-23 14:02:06 +00:00
|
|
|
|
2017-01-25 15:06:15 +00:00
|
|
|
ptrCreatureStats->setLevel(pl->creatureStats.mLevel);
|
2016-09-29 10:17:46 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_GUI_MESSAGEBOX:
|
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-08-30 03:17:06 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_GUI_MESSAGEBOX, Type %d, MSG %s", getLocalPlayer()->guiMessageBox.type,
|
|
|
|
getLocalPlayer()->guiMessageBox.label.c_str());
|
2016-10-21 16:23:56 +00:00
|
|
|
|
2017-01-27 08:41:10 +00:00
|
|
|
int messageBoxType = getLocalPlayer()->guiMessageBox.type;
|
|
|
|
|
|
|
|
if (messageBoxType == BasePlayer::GUIMessageBox::MessageBox)
|
2016-11-15 19:54:06 +00:00
|
|
|
Main::get().getGUIController()->showMessageBox(getLocalPlayer()->guiMessageBox);
|
2017-01-27 08:41:10 +00:00
|
|
|
else if (messageBoxType == BasePlayer::GUIMessageBox::CustomMessageBox)
|
2016-11-15 19:54:06 +00:00
|
|
|
Main::get().getGUIController()->showCustomMessageBox(getLocalPlayer()->guiMessageBox);
|
2017-01-27 08:41:10 +00:00
|
|
|
else if (messageBoxType == BasePlayer::GUIMessageBox::InputDialog)
|
2016-11-15 19:54:06 +00:00
|
|
|
Main::get().getGUIController()->showInputBox(getLocalPlayer()->guiMessageBox);
|
2017-01-27 08:41:10 +00:00
|
|
|
else if (messageBoxType == BasePlayer::GUIMessageBox::ListBox)
|
2016-11-15 19:54:06 +00:00
|
|
|
Main::get().getGUIController()->showDialogList(getLocalPlayer()->guiMessageBox);
|
2016-08-30 03:17:06 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 07:01:33 +00:00
|
|
|
case ID_PLAYER_CHARCLASS:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-08-30 05:24:31 +00:00
|
|
|
{
|
2016-10-21 16:23:56 +00:00
|
|
|
if (packet->length == myPacket->headerSize())
|
|
|
|
getLocalPlayer()->sendClass();
|
|
|
|
else
|
2016-08-30 05:24:31 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
getLocalPlayer()->setClass();
|
2016-08-30 05:24:31 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-31 20:53:32 +00:00
|
|
|
break;
|
2016-10-23 15:32:03 +00:00
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
case ID_GAME_TIME:
|
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
if (guid == myGuid)
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
if (getLocalPlayer()->hour != -1)
|
|
|
|
world->setHour(getLocalPlayer()->hour);
|
|
|
|
else if (getLocalPlayer()->day != -1)
|
|
|
|
world->setDay(getLocalPlayer()->day);
|
|
|
|
else if (getLocalPlayer()->month != -1)
|
|
|
|
world->setMonth(getLocalPlayer()->month);
|
|
|
|
}
|
2016-10-21 17:44:15 +00:00
|
|
|
break;
|
2016-11-03 18:59:39 +00:00
|
|
|
}
|
|
|
|
case ID_GAME_CONSOLE:
|
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setPlayer(getLocalPlayer());
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-11-03 18:59:39 +00:00
|
|
|
break;
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
|
|
|
default:
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled PlayerPacket with identifier %i has arrived", packet->data[0]);
|
2016-01-04 12:17:30 +00:00
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-01-04 12:17:30 +00:00
|
|
|
|
2016-11-15 19:54:06 +00:00
|
|
|
void Networking::processWorldPacket(RakNet::Packet *packet)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-26 12:55:34 +00:00
|
|
|
RakNet::RakNetGUID guid;
|
2016-10-21 17:44:15 +00:00
|
|
|
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
|
2016-10-26 12:55:34 +00:00
|
|
|
bsIn.Read(guid);
|
2016-10-21 17:44:15 +00:00
|
|
|
|
|
|
|
DedicatedPlayer *pl = 0;
|
2016-10-26 12:55:34 +00:00
|
|
|
static RakNet::RakNetGUID myGuid = getLocalPlayer()->guid;
|
|
|
|
if (guid != myGuid)
|
2016-11-15 19:54:06 +00:00
|
|
|
pl = Players::getPlayer(guid);
|
2016-10-21 17:44:15 +00:00
|
|
|
|
2016-10-21 16:23:56 +00:00
|
|
|
WorldPacket *myPacket = worldController.GetPacket(packet->data[0]);
|
2017-02-14 17:31:56 +00:00
|
|
|
|
2017-03-06 09:44:08 +00:00
|
|
|
myPacket->setEvent(&worldEvent);
|
|
|
|
myPacket->Packet(&bsIn, false);
|
2016-10-21 16:23:56 +00:00
|
|
|
|
|
|
|
switch (packet->data[0])
|
|
|
|
{
|
2017-02-05 16:45:23 +00:00
|
|
|
case ID_CONTAINER:
|
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2017-02-05 16:45:23 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_CONTAINER about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
LOG_APPEND(Log::LOG_VERBOSE, "- action: %i", worldEvent.action);
|
2017-02-14 17:31:56 +00:00
|
|
|
|
|
|
|
// If we've received a request for information, comply with it
|
2017-02-23 07:18:48 +00:00
|
|
|
if (worldEvent.action == mwmp::BaseEvent::REQUEST)
|
|
|
|
worldEvent.sendContainers(ptrCellStore);
|
2017-02-14 17:31:56 +00:00
|
|
|
// Otherwise, edit containers based on the information received
|
|
|
|
else
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.editContainers(ptrCellStore);
|
2017-02-05 16:45:23 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-25 09:15:27 +00:00
|
|
|
case ID_OBJECT_PLACE:
|
2016-10-21 18:57:05 +00:00
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_PLACE about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.placeObjects(ptrCellStore);
|
2016-10-22 09:45:19 +00:00
|
|
|
|
2016-10-21 18:57:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-10-25 09:15:27 +00:00
|
|
|
case ID_OBJECT_DELETE:
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_DELETE about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.deleteObjects(ptrCellStore);
|
2016-10-22 09:45:19 +00:00
|
|
|
|
2016-10-21 17:44:15 +00:00
|
|
|
break;
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
2016-10-25 09:15:27 +00:00
|
|
|
case ID_OBJECT_LOCK:
|
2016-10-24 10:20:04 +00:00
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_LOCK about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.lockObjects(ptrCellStore);
|
2016-10-24 10:20:04 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-25 09:15:27 +00:00
|
|
|
case ID_OBJECT_UNLOCK:
|
2016-10-24 08:26:31 +00:00
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_UNLOCK about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.unlockObjects(ptrCellStore);
|
2016-10-24 08:26:31 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-25 09:15:27 +00:00
|
|
|
case ID_OBJECT_SCALE:
|
2016-10-24 21:52:42 +00:00
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_SCALE about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.scaleObjects(ptrCellStore);
|
2016-10-24 21:52:42 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-25 11:07:00 +00:00
|
|
|
case ID_OBJECT_MOVE:
|
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_MOVE about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.moveObjects(ptrCellStore);
|
2016-10-25 11:07:00 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-25 11:28:39 +00:00
|
|
|
case ID_OBJECT_ROTATE:
|
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ROTATE about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.rotateObjects(ptrCellStore);
|
2016-10-27 13:09:02 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_OBJECT_ANIM_PLAY:
|
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ANIM_PLAY about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.animateObjects(ptrCellStore);
|
2016-10-25 11:28:39 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-02-01 09:54:40 +00:00
|
|
|
case ID_DOOR_STATE:
|
2016-10-25 07:40:55 +00:00
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_DOOR_STATE about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.activateDoors(ptrCellStore);
|
2016-10-24 14:52:19 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-26 09:25:50 +00:00
|
|
|
case ID_SCRIPT_LOCAL_SHORT:
|
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_SHORT about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.setLocalShorts(ptrCellStore);
|
2016-10-26 09:25:50 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_SCRIPT_LOCAL_FLOAT:
|
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
|
2016-11-04 13:47:55 +00:00
|
|
|
|
|
|
|
if (!ptrCellStore) return;
|
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_FLOAT about %s", worldEvent.cell.getDescription().c_str());
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.setLocalFloats(ptrCellStore);
|
2016-10-26 09:25:50 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-26 21:41:14 +00:00
|
|
|
case ID_SCRIPT_MEMBER_SHORT:
|
|
|
|
{
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_MEMBER_SHORT");
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.setMemberShorts();
|
2016-10-26 21:41:14 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-26 09:25:50 +00:00
|
|
|
case ID_SCRIPT_GLOBAL_SHORT:
|
|
|
|
{
|
2016-11-17 04:39:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_GLOBAL_SHORT");
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.setGlobalShorts();
|
2016-10-26 09:25:50 +00:00
|
|
|
|
2017-01-28 10:34:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_MUSIC_PLAY:
|
|
|
|
{
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY");
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.playMusic();
|
2017-01-28 10:34:45 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_VIDEO_PLAY:
|
|
|
|
{
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY");
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.playVideo();
|
2016-10-26 09:25:50 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-21 16:23:56 +00:00
|
|
|
default:
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled WorldPacket with identifier %i has arrived", packet->data[0]);
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-15 19:54:06 +00:00
|
|
|
void Networking::receiveMessage(RakNet::Packet *packet)
|
2016-10-21 16:23:56 +00:00
|
|
|
{
|
|
|
|
if (packet->length < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (playerController.ContainsPacket(packet->data[0]))
|
|
|
|
{
|
2016-11-15 19:54:06 +00:00
|
|
|
processPlayerPacket(packet);
|
2016-10-21 16:23:56 +00:00
|
|
|
}
|
|
|
|
else if (worldController.ContainsPacket(packet->data[0]))
|
|
|
|
{
|
2016-11-15 19:54:06 +00:00
|
|
|
processWorldPacket(packet);
|
2016-01-04 12:17:30 +00:00
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-01-04 12:17:30 +00:00
|
|
|
|
2016-11-15 19:54:06 +00:00
|
|
|
PlayerPacket *Networking::getPlayerPacket(RakNet::MessageID id)
|
2016-10-19 19:49:35 +00:00
|
|
|
{
|
|
|
|
return playerController.GetPacket(id);
|
|
|
|
}
|
|
|
|
|
2016-11-15 19:54:06 +00:00
|
|
|
WorldPacket *Networking::getWorldPacket(RakNet::MessageID id)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-10-19 19:49:35 +00:00
|
|
|
return worldController.GetPacket(id);
|
2016-01-04 12:17:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
LocalPlayer *Networking::getLocalPlayer()
|
2016-01-04 12:17:30 +00:00
|
|
|
{
|
2016-01-12 03:41:44 +00:00
|
|
|
return mwmp::Main::get().getLocalPlayer();
|
|
|
|
}
|
|
|
|
|
2017-02-23 07:18:48 +00:00
|
|
|
WorldEvent *Networking::resetWorldEvent()
|
2016-10-20 11:28:19 +00:00
|
|
|
{
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent.cell.blank();
|
|
|
|
worldEvent.objectChanges.objects.clear();
|
|
|
|
worldEvent.guid = getLocalPlayer()->guid;
|
|
|
|
return &worldEvent;
|
2016-10-20 11:28:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
bool Networking::isDedicatedPlayer(const MWWorld::Ptr &ptr)
|
|
|
|
{
|
2016-08-17 15:20:36 +00:00
|
|
|
if (ptr.mRef == 0)
|
2016-01-12 03:41:44 +00:00
|
|
|
return 0;
|
2016-11-15 19:54:06 +00:00
|
|
|
DedicatedPlayer *pl = Players::getPlayer(ptr);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
return pl != 0;
|
|
|
|
}
|
2016-01-04 12:17:30 +00:00
|
|
|
|
2016-11-15 19:54:06 +00:00
|
|
|
bool Networking::attack(const MWWorld::Ptr &ptr)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-11-15 19:54:06 +00:00
|
|
|
DedicatedPlayer *pl = Players::getPlayer(ptr);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-08-17 15:20:36 +00:00
|
|
|
if (pl == 0)
|
2016-01-12 03:41:44 +00:00
|
|
|
return false;
|
|
|
|
|
2017-01-25 15:06:15 +00:00
|
|
|
return pl->attack.pressed;
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Networking::isConnected()
|
|
|
|
{
|
|
|
|
return connected;
|
2016-01-04 12:17:30 +00:00
|
|
|
}
|