New auth protocol

coverity_scan^2
Koncord 8 years ago
parent 61c5456373
commit 96e2d749c7

@ -52,10 +52,9 @@ void Networking::Update(RakNet::Packet *packet)
if (player == 0) if (player == 0)
{ {
controller->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid); controller->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
Players::NewPlayer(packet->guid);
NewPlayer(packet->guid);
player = Players::GetPlayer(packet->guid); player = Players::GetPlayer(packet->guid);
controller->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(packet->guid), false);
return; return;
} }
@ -97,6 +96,20 @@ void Networking::Update(RakNet::Packet *packet)
return; return;
} }
player->Handshake(); player->Handshake();
return;
}
if (!player->isHandshaked())
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Have not completed handshake with player %d",
player->GetID());
//KickPlayer(player->guid);
return;
}
if (packet->data[0] == ID_LOADED)
{
player->Loaded();
static constexpr unsigned int ident = Script::CallbackIdentity("OnPlayerConnect"); static constexpr unsigned int ident = Script::CallbackIdentity("OnPlayerConnect");
Script::CallBackReturn<ident> result = true; Script::CallBackReturn<ident> result = true;
@ -108,22 +121,27 @@ void Networking::Update(RakNet::Packet *packet)
Players::DeletePlayer(packet->guid); Players::DeletePlayer(packet->guid);
return; return;
} }
}
else if(packet->data[0] == ID_GAME_BASE_INFO)
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_BASE_INFO about %s",
player->Npc()->mName.c_str());
return; myPacket->Read(player);
myPacket->Send(player, true);
} }
if (!player->isHandshaked()) if(!player->isLoaded())
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Have not completed handshake with player %d",
player->GetID());
//KickPlayer(player->guid);
return; return;
else if(player->BirthSign()->empty())
{
(*player->BirthSign()) = "a";
NewPlayer(packet->guid);
} }
switch (packet->data[0]) switch (packet->data[0])
{ {
case ID_GAME_BASE_INFO: /*case ID_GAME_BASE_INFO:
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_BASE_INFO about %s", LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_BASE_INFO about %s",
player->Npc()->mName.c_str()); player->Npc()->mName.c_str());
@ -132,7 +150,7 @@ void Networking::Update(RakNet::Packet *packet)
myPacket->Send(player, true); myPacket->Send(player, true);
break; break;
} }*/
case ID_GAME_UPDATE_POS: case ID_GAME_UPDATE_POS:
{ {
//DEBUG_PRINTF("ID_GAME_UPDATE_POS \n"); //DEBUG_PRINTF("ID_GAME_UPDATE_POS \n");
@ -331,10 +349,6 @@ void Networking::Update(RakNet::Packet *packet)
void Networking::NewPlayer(RakNet::RakNetGUID guid) void Networking::NewPlayer(RakNet::RakNetGUID guid)
{ {
Players::NewPlayer(guid);
controller->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(guid), false);
controller->GetPacket(ID_GAME_BASE_INFO)->RequestData(guid); controller->GetPacket(ID_GAME_BASE_INFO)->RequestData(guid);
controller->GetPacket(ID_GAME_UPDATE_BASESTATS)->RequestData(guid); controller->GetPacket(ID_GAME_UPDATE_BASESTATS)->RequestData(guid);
controller->GetPacket(ID_GAME_ATTRIBUTE)->RequestData(guid); controller->GetPacket(ID_GAME_ATTRIBUTE)->RequestData(guid);
@ -343,7 +357,7 @@ void Networking::NewPlayer(RakNet::RakNetGUID guid)
controller->GetPacket(ID_GAME_CELL)->RequestData(guid); controller->GetPacket(ID_GAME_CELL)->RequestData(guid);
controller->GetPacket(ID_GAME_UPDATE_EQUIPED)->RequestData(guid); controller->GetPacket(ID_GAME_UPDATE_EQUIPED)->RequestData(guid);
for (TPlayers::iterator pl = players->begin(); pl != players->end(); pl++) for (TPlayers::iterator pl = players->begin(); pl != players->end(); pl++) //sending other players to new player
{ {
if (pl->first == guid) continue; if (pl->first == guid) continue;

@ -644,9 +644,9 @@ void OMW::Engine::go()
ToUTF8::Utf8Encoder encoder (mEncoding); ToUTF8::Utf8Encoder encoder (mEncoding);
mEncoder = &encoder; mEncoder = &encoder;
mwmp::Main::Init(mContentFiles);
prepareEngine (settings); prepareEngine (settings);
mwmp::Main::Create(); mwmp::Main::PostInit();
mSkipMenu = true; mSkipMenu = true;
if (!mSaveGameFile.empty()) if (!mSaveGameFile.empty())

@ -91,19 +91,35 @@ void Main::Configure(const boost::program_options::variables_map &variables)
Main::addr = variables["connect"].as<string>(); Main::addr = variables["connect"].as<string>();
} }
void Main::Create() Settings::CategorySettingValueMap saveUserSettings;
{ Settings::CategorySettingValueMap saveDefaultSettings;
assert(!pMain); Settings::CategorySettingVector saveChangedSettings;
pMain = new Main();
Settings::Manager mgr; Settings::Manager InitMgr(Settings::Manager &mgr)
Settings::CategorySettingValueMap saveUserSettings = mgr.mUserSettings; {
Settings::CategorySettingValueMap saveDefaultSettings = mgr.mDefaultSettings; saveUserSettings = mgr.mUserSettings;
Settings::CategorySettingVector saveChangedSettings = mgr.mChangedSettings; saveDefaultSettings = mgr.mDefaultSettings;
saveChangedSettings = mgr.mChangedSettings;
mgr.mUserSettings.clear(); mgr.mUserSettings.clear();
mgr.mDefaultSettings.clear(); mgr.mDefaultSettings.clear();
mgr.mChangedSettings.clear(); mgr.mChangedSettings.clear();
loadSettings(mgr); loadSettings(mgr);
}
void RestoreMgr(Settings::Manager &mgr)
{
mgr.mUserSettings = saveUserSettings;
mgr.mDefaultSettings = saveDefaultSettings;
mgr.mChangedSettings = saveChangedSettings;
}
void Main::Init(std::vector<std::string> &content)
{
assert(!pMain);
pMain = new Main();
Settings::Manager mgr;
InitMgr(mgr);
int logLevel = mgr.getInt("loglevel", "General"); int logLevel = mgr.getInt("loglevel", "General");
Log::SetLevel(logLevel); Log::SetLevel(logLevel);
@ -120,15 +136,21 @@ void Main::Create()
} }
pMain->mGUIController->setupChat(mgr); pMain->mNetworking->Connect(pMain->server, pMain->port);
RestoreMgr(mgr);
}
mgr.mUserSettings = saveUserSettings; void Main::PostInit()
mgr.mDefaultSettings = saveDefaultSettings; {
mgr.mChangedSettings = saveChangedSettings; Settings::Manager mgr;
InitMgr(mgr);
pMain->mGUIController->setupChat(mgr);
RestoreMgr(mgr);
//pMain->mGUILogin = new GUILogin();
const MWBase::Environment &environment = MWBase::Environment::get(); const MWBase::Environment &environment = MWBase::Environment::get();
environment.getStateManager()->newGame(true); environment.getStateManager()->newGame(true);
MWBase::Environment::get().getMechanicsManager()->toggleAI();
} }
void Main::Destroy() void Main::Destroy()
@ -164,17 +186,14 @@ void Main::UpdateWorld(float dt) const
if (!mLocalPlayer->CharGenThread()) if (!mLocalPlayer->CharGenThread())
return; return;
if (!mNetworking->isConnected()) static bool init = true;
if (init)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); init = false;
MWBase::Environment::get().getMechanicsManager()->toggleAI(); LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server");
(*mLocalPlayer->Npc()) = *player.get<ESM::NPC>()->mBase;
mLocalPlayer->updateAttributesAndSkills();
mNetworking->Connect(server, port); mNetworking->GetPacket(ID_GAME_BASE_INFO)->Send(getLocalPlayer());
player.getClass().getCreatureStats(player).getSpells().add("fireball"); mNetworking->GetPacket(ID_LOADED)->Send(getLocalPlayer());
mLocalPlayer->updateBaseStats(true); mLocalPlayer->updateBaseStats(true);
get().getGUIController()->setChatVisible(true); get().getGUIController()->setChatVisible(true);
} }

@ -14,7 +14,8 @@ namespace mwmp
static void OptionsDesc(boost::program_options::options_description *desc); static void OptionsDesc(boost::program_options::options_description *desc);
static void Configure(const boost::program_options::variables_map &variables); static void Configure(const boost::program_options::variables_map &variables);
static void Create(); static void Init(std::vector<std::string> &content);
static void PostInit();
static void Destroy(); static void Destroy();
static const Main &get(); static const Main &get();
static void Frame(float dt); static void Frame(float dt);

@ -6,6 +6,6 @@
#define OPENMW_VERSION_HPP #define OPENMW_VERSION_HPP
#define TES3MP_VERSION "0.0.1c" #define TES3MP_VERSION "0.0.1c"
#define TES3MP_PROTO_VERSION 1 #define TES3MP_PROTO_VERSION 2
#endif //OPENMW_VERSION_HPP #endif //OPENMW_VERSION_HPP

Loading…
Cancel
Save