2016-01-12 03:41:44 +00:00
# include <stdexcept>
# include <iostream>
# include <string>
2017-04-17 13:09:07 +00:00
2019-08-19 18:39:33 +00:00
# include <components/openmw-mp/TimedLog.hpp>
2017-04-17 13:09:07 +00:00
# include <components/openmw-mp/Utils.hpp>
# include <components/openmw-mp/Version.hpp>
# include <components/openmw-mp/Packets/PacketPreInit.hpp>
2016-01-12 03:41:44 +00:00
# include <components/esm/cellid.hpp>
2017-04-17 13:09:07 +00:00
# include <components/files/configurationmanager.hpp>
2016-10-24 14:52:19 +00:00
2016-11-17 15:16:25 +00:00
# include "../mwbase/environment.hpp"
2017-04-17 13:09:07 +00:00
# include "../mwbase/world.hpp"
# include "../mwclass/npc.hpp"
# include "../mwmechanics/combat.hpp"
# include "../mwmechanics/npcstats.hpp"
# include "../mwstate/statemanagerimp.hpp"
2016-11-17 15:16:25 +00:00
# include "../mwworld/cellstore.hpp"
# include "../mwworld/esmstore.hpp"
# include "../mwworld/inventorystore.hpp"
2016-08-04 16:31:15 +00:00
# include <SDL_messagebox.h>
2017-05-02 15:37:18 +00:00
# include <RakSleep.h>
# include <iomanip>
2017-05-28 10:26:48 +00:00
# include <components/version/version.hpp>
2017-04-17 13:09:07 +00:00
2016-01-04 12:17:30 +00:00
# include "Networking.hpp"
2017-04-17 13:09:07 +00:00
# include "Main.hpp"
2017-06-06 16:06:10 +00:00
# include "processors/ProcessorInitializer.hpp"
2019-11-09 03:12:00 +00:00
# include "processors/SystemProcessor.hpp"
2017-06-06 16:06:10 +00:00
# include "processors/PlayerProcessor.hpp"
2018-05-15 19:56:47 +00:00
# include "processors/ObjectProcessor.hpp"
2017-06-06 16:06:10 +00:00
# include "processors/ActorProcessor.hpp"
2018-05-18 03:40:28 +00:00
# include "processors/WorldstateProcessor.hpp"
2017-04-18 06:32:40 +00:00
# include "GUIController.hpp"
# include "CellController.hpp"
2016-01-04 12:17:30 +00:00
2016-01-12 03:41:44 +00:00
using namespace mwmp ;
2016-01-04 12:17:30 +00:00
2021-03-20 21:21:40 +00:00
std : : string listDiscrepancies ( PacketPreInit : : PluginContainer checksums , PacketPreInit : : PluginContainer checksumsResponse )
2017-05-02 22:51:47 +00:00
{
std : : ostringstream sstr ;
2018-10-13 11:40:49 +00:00
sstr < < " Your plugins or their load order don't match the server's. A full comparison is included in your debug window and latest log file. In short, the following discrepancies have been found: \n \n " ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
int discrepancyCount = 0 ;
for ( size_t fileIndex = 0 ; fileIndex < checksums . size ( ) | | fileIndex < checksumsResponse . size ( ) ; fileIndex + + )
2017-05-02 22:51:47 +00:00
{
2018-01-06 03:39:25 +00:00
if ( fileIndex > = checksumsResponse . size ( ) )
{
discrepancyCount + + ;
if ( discrepancyCount > 1 )
sstr < < " \n " ;
2021-03-20 21:21:40 +00:00
std : : string clientFilename = checksums . at ( fileIndex ) . first ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
sstr < < fileIndex < < " : " ;
sstr < < clientFilename < < " is past the number of plugins used by the server " ;
}
else if ( fileIndex > = checksums . size ( ) )
2017-05-02 22:51:47 +00:00
{
2018-01-06 03:39:25 +00:00
discrepancyCount + + ;
if ( discrepancyCount > 1 )
sstr < < " \n " ;
2021-03-20 21:21:40 +00:00
std : : string serverFilename = checksumsResponse . at ( fileIndex ) . first ;
2018-01-06 03:39:25 +00:00
sstr < < fileIndex < < " : " ;
sstr < < serverFilename < < " is completely missing from the client but required by the server " ;
2017-05-02 22:51:47 +00:00
}
2018-01-06 03:39:25 +00:00
else
{
2021-03-20 21:21:40 +00:00
std : : string clientFilename = checksums . at ( fileIndex ) . first ;
std : : string serverFilename = checksumsResponse . at ( fileIndex ) . first ;
2017-05-02 22:51:47 +00:00
2021-03-20 21:21:40 +00:00
std : : string clientChecksum = Utils : : intToHexStr ( checksums . at ( fileIndex ) . second . at ( 0 ) ) ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
bool filenameMatches = false ;
bool checksumMatches = false ;
2021-03-20 21:21:40 +00:00
std : : string eligibleChecksums = " " ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
if ( Misc : : StringUtils : : ciEqual ( clientFilename , serverFilename ) )
filenameMatches = true ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
if ( checksumsResponse . at ( fileIndex ) . second . size ( ) > 0 )
{
for ( size_t checksumIndex = 0 ; checksumIndex < checksumsResponse . at ( fileIndex ) . second . size ( ) ; checksumIndex + + )
{
2021-03-20 21:21:40 +00:00
std : : string serverChecksum = Utils : : intToHexStr ( checksumsResponse . at ( fileIndex ) . second . at ( checksumIndex ) ) ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
if ( checksumIndex ! = 0 )
eligibleChecksums = eligibleChecksums + " or " ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
eligibleChecksums = eligibleChecksums + serverChecksum ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
if ( Misc : : StringUtils : : ciEqual ( clientChecksum , serverChecksum ) )
{
checksumMatches = true ;
break ;
}
}
}
else
checksumMatches = true ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
if ( ! filenameMatches | | ! checksumMatches )
{
discrepancyCount + + ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
if ( discrepancyCount > 1 )
sstr < < " \n " ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
sstr < < fileIndex < < " : " ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
if ( ! filenameMatches )
sstr < < clientFilename < < " doesn't match " < < serverFilename ;
2017-05-02 22:51:47 +00:00
2018-01-06 03:39:25 +00:00
if ( ! filenameMatches & & ! checksumMatches )
sstr < < " , " ;
if ( ! checksumMatches )
sstr < < " checksum " < < clientChecksum < < " doesn't match " < < eligibleChecksums ;
}
}
2017-05-02 22:51:47 +00:00
}
return sstr . str ( ) ;
}
2021-03-20 21:21:40 +00:00
std : : string listComparison ( PacketPreInit : : PluginContainer checksums , PacketPreInit : : PluginContainer checksumsResponse ,
2017-05-02 15:37:18 +00:00
bool full = false )
{
std : : ostringstream sstr ;
size_t pluginNameLen1 = 0 ;
size_t pluginNameLen2 = 0 ;
2017-06-27 08:32:16 +00:00
for ( const auto & checksum : checksums )
if ( pluginNameLen1 < checksum . first . size ( ) )
pluginNameLen1 = checksum . first . size ( ) ;
2017-05-02 15:37:18 +00:00
2017-06-27 08:32:16 +00:00
for ( const auto & checksum : checksums )
if ( pluginNameLen2 < checksum . first . size ( ) )
pluginNameLen2 = checksum . first . size ( ) ;
2017-05-02 15:37:18 +00:00
2017-05-03 06:37:52 +00:00
Utils : : printWithWidth ( sstr , " Your current plugins are: " , pluginNameLen1 + 16 ) ;
2017-05-02 15:37:18 +00:00
sstr < < " To join this server, use: \n " ;
2017-05-03 06:37:52 +00:00
Utils : : printWithWidth ( sstr , " name " , pluginNameLen1 + 2 ) ;
Utils : : printWithWidth ( sstr , " hash " , 14 ) ;
Utils : : printWithWidth ( sstr , " name " , pluginNameLen2 + 2 ) ;
2017-05-02 15:37:18 +00:00
sstr < < " hash \n " ;
2017-05-02 22:51:47 +00:00
2017-05-03 00:14:11 +00:00
for ( size_t i = 0 ; i < checksums . size ( ) | | i < checksumsResponse . size ( ) ; i + + )
2017-05-02 15:37:18 +00:00
{
2021-03-20 21:21:40 +00:00
std : : string plugin ;
2017-05-02 18:43:58 +00:00
unsigned val ;
2017-05-02 21:15:43 +00:00
if ( i < checksums . size ( ) )
2017-05-02 18:43:58 +00:00
{
plugin = checksums . at ( i ) . first ;
val = checksums . at ( i ) . second [ 0 ] ;
2017-05-02 20:22:37 +00:00
2017-05-03 06:37:52 +00:00
Utils : : printWithWidth ( sstr , plugin , pluginNameLen1 + 2 ) ;
Utils : : printWithWidth ( sstr , Utils : : intToHexStr ( val ) , 14 ) ;
2017-05-02 20:22:37 +00:00
}
else
2017-05-03 06:37:52 +00:00
Utils : : printWithWidth ( sstr , " " , pluginNameLen1 + 16 ) ;
2017-05-02 21:15:43 +00:00
2017-05-03 00:14:11 +00:00
if ( i < checksumsResponse . size ( ) )
2017-05-02 15:37:18 +00:00
{
2017-05-03 06:37:52 +00:00
Utils : : printWithWidth ( sstr , checksumsResponse [ i ] . first , pluginNameLen2 + 2 ) ;
2017-05-03 00:14:11 +00:00
if ( checksumsResponse [ i ] . second . size ( ) > 0 )
{
if ( full )
for ( size_t j = 0 ; j < checksumsResponse [ i ] . second . size ( ) ; j + + )
2017-05-03 06:37:52 +00:00
Utils : : printWithWidth ( sstr , Utils : : intToHexStr ( checksumsResponse [ i ] . second [ j ] ) , 14 ) ;
2017-05-03 00:14:11 +00:00
else
2017-05-03 06:37:52 +00:00
sstr < < Utils : : intToHexStr ( checksumsResponse [ i ] . second [ 0 ] ) ;
2017-05-03 00:14:11 +00:00
}
2017-05-02 15:37:18 +00:00
else
2017-05-03 00:14:11 +00:00
sstr < < " any " ;
2017-05-02 15:37:18 +00:00
}
2017-05-03 00:14:11 +00:00
2017-05-02 15:37:18 +00:00
sstr < < " \n " ;
}
2017-05-02 22:51:47 +00:00
2017-05-02 15:37:18 +00:00
return sstr . str ( ) ;
}
2019-11-09 03:12:00 +00:00
Networking : : Networking ( ) : peer ( RakNet : : RakPeerInterface : : GetInstance ( ) ) , systemPacketController ( peer ) ,
playerPacketController ( peer ) , actorPacketController ( peer ) , objectPacketController ( peer ) ,
worldstatePacketController ( peer )
2016-01-04 12:17:30 +00:00
{
2016-01-12 03:41:44 +00:00
RakNet : : SocketDescriptor sd ;
sd . port = 0 ;
2017-07-03 15:25:58 +00:00
auto b = peer - > Startup ( 1 , & sd , 1 ) ;
2018-06-18 21:37:52 +00:00
RakAssert ( b = = RakNet : : CRABNET_STARTED ) ;
2016-01-12 03:41:44 +00:00
2019-11-09 03:12:00 +00:00
systemPacketController . SetStream ( 0 , & bsOut ) ;
2017-04-09 05:51:28 +00:00
playerPacketController . SetStream ( 0 , & bsOut ) ;
actorPacketController . SetStream ( 0 , & bsOut ) ;
2018-05-12 16:40:00 +00:00
objectPacketController . SetStream ( 0 , & bsOut ) ;
2018-05-18 03:40:28 +00:00
worldstatePacketController . SetStream ( 0 , & bsOut ) ;
2016-10-19 19:49:35 +00:00
2016-01-12 03:41:44 +00:00
connected = 0 ;
2017-04-16 07:02:37 +00:00
ProcessorInitializer ( ) ;
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 :
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_INFO , " Another client has disconnected. " ) ;
2016-01-12 03:41:44 +00:00
break ;
case ID_REMOTE_CONNECTION_LOST :
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_INFO , " Another client has lost connection. " ) ;
2016-01-12 03:41:44 +00:00
break ;
case ID_REMOTE_NEW_INCOMING_CONNECTION :
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_INFO , " Another client has connected. " ) ;
2016-01-12 03:41:44 +00:00
break ;
case ID_CONNECTION_REQUEST_ACCEPTED :
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_WARN , " Our connection request has been accepted. " ) ;
2016-01-12 03:41:44 +00:00
break ;
case ID_NEW_INCOMING_CONNECTION :
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : 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 ) ;
2019-08-19 18:39:33 +00:00
//LOG_MESSAGE_SIMPLE(TimedLog::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 ( ) )
{
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : 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
}
2021-03-20 21:21:40 +00:00
void Networking : : connect ( const std : : string & ip , unsigned short port , std : : vector < std : : 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
2021-03-20 21:21:40 +00:00
std : : stringstream sstr ;
2017-07-02 03:11:33 +00:00
sstr < < TES3MP_VERSION ;
2016-09-18 03:49:30 +00:00
sstr < < TES3MP_PROTO_VERSION ;
2019-12-03 11:21:10 +00:00
std : : string commitHashString = Version : : getOpenmwVersion ( Main : : getResDir ( ) ) . mCommitHash ;
// Remove carriage returns added to version file on Windows
commitHashString . erase ( std : : remove ( commitHashString . begin ( ) , commitHashString . end ( ) , ' \r ' ) , commitHashString . end ( ) ) ;
sstr < < commitHashString ;
2016-09-18 03:49:30 +00:00
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
{
2017-06-27 08:32:16 +00:00
for ( RakNet : : Packet * packet = peer - > Receive ( ) ; packet ; peer - > DeallocatePacket ( packet ) , packet = peer - > Receive ( ) )
2016-01-12 03:41:44 +00:00
{
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 :
{
2018-01-15 03:55:12 +00:00
errmsg = " Version mismatch! \n Your client is on version " TES3MP_VERSION " \n "
" Please make sure the server is on the same version. " ;
2016-01-12 03:41:44 +00:00
queue = false ;
break ;
}
2018-06-19 02:24:26 +00:00
case ID_INCOMPATIBLE_PROTOCOL_VERSION :
{
errmsg = " Network protocol mismatch! \n Make sure your client is really on the same version \n "
" as the server you are trying to connect to. " ;
queue = false ;
break ;
}
2016-01-12 03:41:44 +00:00
case ID_CONNECTION_REQUEST_ACCEPTED :
{
serverAddr = packet - > systemAddress ;
2017-04-18 07:05:32 +00:00
BaseClientPacketProcessor : : SetServerAddr ( packet - > systemAddress ) ;
2017-04-18 06:37:21 +00:00
2016-01-12 03:41:44 +00:00
connected = true ;
queue = false ;
2016-01-04 12:17:30 +00:00
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : 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 :
2021-03-20 21:21:40 +00:00
throw std : : runtime_error ( " ID_DISCONNECTION_NOTIFICATION. \n " ) ;
2016-01-12 03:41:44 +00:00
case ID_CONNECTION_BANNED :
2021-03-20 21:21:40 +00:00
throw std : : runtime_error ( " You have been banned from this server. \n " ) ;
2016-01-12 03:41:44 +00:00
case ID_CONNECTION_LOST :
2021-03-20 21:21:40 +00:00
throw std : : runtime_error ( " ID_CONNECTION_LOST. \n " ) ;
2016-01-12 03:41:44 +00:00
default :
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_INFO , " Connection message with identifier %i has arrived in initialization. " ,
2017-03-04 06:55:35 +00:00
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 ( ) )
{
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_ERROR , errmsg . c_str ( ) ) ;
2017-03-05 08:55:05 +00:00
SDL_ShowSimpleMessageBox ( SDL_MESSAGEBOX_ERROR , " tes3mp " , errmsg . c_str ( ) , 0 ) ;
}
else
preInit ( content , collections ) ;
2017-05-25 18:40:49 +00:00
2019-11-09 03:12:00 +00:00
getLocalPlayer ( ) - > guid = getLocalSystem ( ) - > guid = peer - > GetMyGUID ( ) ;
2017-03-05 08:55:05 +00:00
}
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 )
{
PacketPreInit : : PluginContainer checksums ;
2021-03-20 21:21:40 +00:00
std : : vector < std : : string > : : const_iterator it ( content . begin ( ) ) ;
2017-03-04 05:23:26 +00:00
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 ) )
{
2017-05-02 15:37:18 +00:00
PacketPreInit : : HashList hashList ;
2017-08-31 07:12:22 +00:00
unsigned crc32 = Utils : : crc32Checksum ( col . getPath ( * it ) . string ( ) ) ;
2017-05-02 15:37:18 +00:00
hashList . push_back ( crc32 ) ;
checksums . push_back ( make_pair ( * it , hashList ) ) ;
2017-03-05 08:55:05 +00:00
2019-08-19 18:39:33 +00:00
LOG_APPEND ( TimedLog : : LOG_WARN , " idx: %d \t checksum: %X \t file: %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
PacketPreInit : : PluginContainer checksumsResponse ;
2017-05-02 15:37:18 +00:00
bool done = false ;
while ( ! done )
2017-03-05 08:55:05 +00:00
{
2017-05-02 15:37:18 +00:00
RakNet : : Packet * packet = peer - > Receive ( ) ;
2017-05-02 19:47:58 +00:00
if ( ! packet )
2017-03-05 08:55:05 +00:00
{
2017-05-02 15:37:18 +00:00
RakSleep ( 500 ) ;
continue ;
2017-03-05 08:55:05 +00:00
}
2017-05-02 15:37:18 +00:00
RakNet : : BitStream bsIn ( & packet - > data [ 0 ] , packet - > length , false ) ;
unsigned char packetId ;
bsIn . Read ( packetId ) ;
switch ( packetId )
2017-03-05 08:55:05 +00:00
{
2017-05-02 15:37:18 +00:00
case ID_DISCONNECTION_NOTIFICATION :
case ID_CONNECTION_LOST :
done = true ;
break ;
case ID_GAME_PREINIT :
bsIn . IgnoreBytes ( ( unsigned ) RakNet : : RakNetGUID : : size ( ) ) ;
packetPreInit . setChecksums ( & checksumsResponse ) ;
packetPreInit . Packet ( & bsIn , false ) ;
done = true ;
break ;
2017-03-04 05:23:26 +00:00
}
2017-05-02 15:37:18 +00:00
peer - > DeallocatePacket ( packet ) ;
2017-03-04 05:23:26 +00:00
}
2017-05-02 19:47:58 +00:00
if ( ! checksumsResponse . empty ( ) ) // something wrong
2017-05-02 22:51:47 +00:00
{
2018-01-06 03:39:25 +00:00
std : : string errmsg = listDiscrepancies ( checksums , checksumsResponse ) ;
2017-03-05 08:55:05 +00:00
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_ERROR , listDiscrepancies ( checksums , checksumsResponse ) . c_str ( ) ) ;
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_ERROR , listComparison ( checksums , checksumsResponse , true ) . c_str ( ) ) ;
2016-08-24 23:58:03 +00:00
SDL_ShowSimpleMessageBox ( SDL_MESSAGEBOX_ERROR , " tes3mp " , errmsg . c_str ( ) , 0 ) ;
2017-05-03 06:52:32 +00:00
connected = false ;
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 : : receiveMessage ( RakNet : : Packet * packet )
2016-10-21 16:23:56 +00:00
{
if ( packet - > length < 2 )
return ;
2019-11-09 03:12:00 +00:00
if ( systemPacketController . ContainsPacket ( packet - > data [ 0 ] ) )
{
if ( ! SystemProcessor : : Process ( * packet ) )
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_WARN , " Unhandled SystemPacket with identifier %i has arrived " , packet - > data [ 0 ] ) ;
}
else if ( playerPacketController . ContainsPacket ( packet - > data [ 0 ] ) )
2016-10-21 16:23:56 +00:00
{
2017-05-02 19:47:58 +00:00
if ( ! PlayerProcessor : : Process ( * packet ) )
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_WARN , " Unhandled PlayerPacket with identifier %i has arrived " , packet - > data [ 0 ] ) ;
2016-10-21 16:23:56 +00:00
}
2017-04-09 05:51:28 +00:00
else if ( actorPacketController . ContainsPacket ( packet - > data [ 0 ] ) )
{
2017-04-18 06:42:43 +00:00
if ( ! ActorProcessor : : Process ( * packet , actorList ) )
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_WARN , " Unhandled ActorPacket with identifier %i has arrived " , packet - > data [ 0 ] ) ;
2017-04-09 05:51:28 +00:00
}
2018-05-12 16:40:00 +00:00
else if ( objectPacketController . ContainsPacket ( packet - > data [ 0 ] ) )
2016-10-21 16:23:56 +00:00
{
2018-05-15 19:56:47 +00:00
if ( ! ObjectProcessor : : Process ( * packet , objectList ) )
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_WARN , " Unhandled ObjectPacket with identifier %i has arrived " , packet - > data [ 0 ] ) ;
2016-01-04 12:17:30 +00:00
}
2018-05-18 03:40:28 +00:00
else if ( worldstatePacketController . ContainsPacket ( packet - > data [ 0 ] ) )
{
if ( ! WorldstateProcessor : : Process ( * packet , worldstate ) )
2019-08-19 18:39:33 +00:00
LOG_MESSAGE_SIMPLE ( TimedLog : : LOG_WARN , " Unhandled WorldstatePacket with identifier %i has arrived " , packet - > data [ 0 ] ) ;
2018-05-18 03:40:28 +00:00
}
2016-01-12 03:41:44 +00:00
}
2016-01-04 12:17:30 +00:00
2019-11-09 03:12:00 +00:00
SystemPacket * Networking : : getSystemPacket ( RakNet : : MessageID id )
{
return systemPacketController . GetPacket ( id ) ;
}
2016-11-15 19:54:06 +00:00
PlayerPacket * Networking : : getPlayerPacket ( RakNet : : MessageID id )
2016-10-19 19:49:35 +00:00
{
2017-04-09 05:51:28 +00:00
return playerPacketController . GetPacket ( id ) ;
}
ActorPacket * Networking : : getActorPacket ( RakNet : : MessageID id )
{
return actorPacketController . GetPacket ( id ) ;
2016-10-19 19:49:35 +00:00
}
2018-05-12 16:40:00 +00:00
ObjectPacket * Networking : : getObjectPacket ( RakNet : : MessageID id )
2016-01-12 03:41:44 +00:00
{
2018-05-12 16:40:00 +00:00
return objectPacketController . GetPacket ( id ) ;
2016-01-04 12:17:30 +00:00
}
2018-05-18 03:40:28 +00:00
WorldstatePacket * Networking : : getWorldstatePacket ( RakNet : : MessageID id )
{
return worldstatePacketController . GetPacket ( id ) ;
}
2019-11-09 03:12:00 +00:00
LocalSystem * Networking : : getLocalSystem ( )
{
return mwmp : : Main : : get ( ) . getLocalSystem ( ) ;
}
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-04-09 13:32:44 +00:00
ActorList * Networking : : getActorList ( )
{
return & actorList ;
}
2018-05-12 21:42:24 +00:00
ObjectList * Networking : : getObjectList ( )
2016-10-20 11:28:19 +00:00
{
2018-05-12 21:42:24 +00:00
return & objectList ;
2016-10-20 11:28:19 +00:00
}
2018-05-27 12:57:47 +00:00
Worldstate * Networking : : getWorldstate ( )
2018-05-18 03:40:28 +00:00
{
return & worldstate ;
}
2016-01-12 03:41:44 +00:00
bool Networking : : isConnected ( )
{
return connected ;
2016-01-04 12:17:30 +00:00
}