From 6076346df49b7221664db19e7afe74db0b775778 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sun, 5 Mar 2017 16:55:05 +0800 Subject: [PATCH] [Client] Add Networking::preInit() method --- apps/openmw/mwmp/Networking.cpp | 48 +++++++++++++++++++++++++++++++-- apps/openmw/mwmp/Networking.hpp | 2 ++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 8d52b03f5..dfd9390a1 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "DedicatedPlayer.hpp" #include "LocalPlayer.hpp" #include "GUIController.hpp" @@ -163,7 +164,19 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector } } + 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); +} +void Networking::preInit(std::vector &content, Files::Collections &collections) +{ + std::string errmsg = ""; + PacketPreInit::PluginContainer checksums; vector::const_iterator it(content.begin()); for (int idx = 0; it != content.end(); ++it, ++idx) { @@ -172,14 +185,45 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector if (col.doesExist(*it)) { unsigned int crc32 = Utils::crc32checksum(col.getPath(*it).string()); - printf("idx: %d\tchecksum: %x\tfile:%s\n", idx, crc32, col.getPath(*it).c_str()); + checksums.push_back(make_pair(*it, crc32)); + + printf("idx: %d\tchecksum: %x\tfile: %s\n", idx, crc32, col.getPath(*it).c_str()); } else - { throw std::runtime_error("Plugin doesn't exists."); + } + + PacketPreInit packetPreInit(peer); + RakNet::BitStream bs; + RakNet::RakNetGUID guid; + packetPreInit.Packet(&bs, guid, true, checksums); + + 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"; } } + if (!errmsg.empty()) { LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, errmsg.c_str()); diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index c522f1b8d..694114407 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -56,6 +56,8 @@ namespace mwmp void processWorldPacket(RakNet::Packet *packet); void receiveMessage(RakNet::Packet *packet); LocalPlayer *getLocalPlayer(); + + void preInit(std::vector &content, Files::Collections &collections); }; }