network stuff

This commit is contained in:
Vladislav Khorev 2013-02-27 14:03:45 +00:00
parent 5d13869324
commit 3c974a33de
3 changed files with 49 additions and 3 deletions

View File

@ -82,6 +82,8 @@ public:
void SendPropertyTree(boost::property_tree::ptree pTree);
void DisconnectSlots();
};
@ -111,10 +113,11 @@ public:
void StartAccept();
void HandleAccept(boost::shared_ptr<TConnectedUser> user, const boost::system::error_code& error);
void DeleteUser(boost::shared_ptr<TConnectedUser> user);
//Need to generalize this
boost::signal<void(boost::shared_ptr<TConnectedUser>)> OnUserAuthorizedSignal;
//boost::signal<void(std::string)> OnUserDisconnectedSignal;
boost::signal<void(boost::shared_ptr<TConnectedUser>)> OnUserDisconnectedSignal;
};

View File

@ -254,7 +254,20 @@ void TClientSocket::Close()
ClientDataReader->DataReadSignalMap.Clear();
std::shared_ptr<TSimpleAuthorization> authorization = boost::get<std::shared_ptr<TSimpleAuthorization>>(Authorization);
authorization->AuthorizedSignal.disconnect_all_slots();
authorization->SaveLoginPasswordSignal.disconnect_all_slots();
authorization->ErrorSignal.disconnect_all_slots();
OnDisconnectedSignal();
OnAddressNotResolvedSignal.disconnect_all_slots();
OnConnectedSignal.disconnect_all_slots();
OnAutorizedSignal.disconnect_all_slots();
OnDisconnectedSignal.disconnect_all_slots();
}
}

View File

@ -60,12 +60,15 @@ namespace SE
TConnectedUser::~TConnectedUser()
{
}
void TConnectedUser::HandleAllowed(std::string login)
{
UserDataReader = boost::shared_ptr<TDataReader>(new TDataReader(Socket));
UserDataReader->ErrorSignal.connect(boost::bind(&TServerSocket::DeleteUser, &Server, shared_from_this()));
Login = login;
Server.OnUserAuthorizedSignal(shared_from_this());
@ -78,6 +81,19 @@ namespace SE
SE::SendPropertyTree(Server.IoService, Socket, pTree);
}
void TConnectedUser::DisconnectSlots()
{
UserDataReader->DataReadSignalMap.Clear();
UserDataReader->ErrorSignal.disconnect_all_slots();
std::shared_ptr<TSimpleAutorizator> authorizator = boost::get<std::shared_ptr<TSimpleAutorizator>>(Autorizator);
authorizator->ErrorSignal.disconnect_all_slots();
authorizator->AllowedSignal.disconnect_all_slots();
authorizator->DeniedSignal.disconnect_all_slots();
}
@ -131,7 +147,10 @@ namespace SE
UserArr.push_back(user);
boost::get<std::shared_ptr<TSimpleAutorizator>>(user->Autorizator)->AllowedSignal.connect(boost::bind(&TConnectedUser::HandleAllowed, user, _1));
std::shared_ptr<TSimpleAutorizator> authorizator = boost::get<std::shared_ptr<TSimpleAutorizator>>(user->Autorizator);
authorizator->AllowedSignal.connect(boost::bind(&TConnectedUser::HandleAllowed, user, _1));
authorizator->ErrorSignal.connect(boost::bind(&TServerSocket::DeleteUser, this, user));
boost::get<std::shared_ptr<TSimpleAutorizator>>(user->Autorizator)->StartListen();
@ -140,5 +159,16 @@ namespace SE
StartAccept();
}
void TServerSocket::DeleteUser(boost::shared_ptr<TConnectedUser> user)
{
std::vector<boost::shared_ptr<TConnectedUser>>::iterator i = std::find(UserArr.begin(), UserArr.end(), user);
user->DisconnectSlots();
OnUserDisconnectedSignal(user);
UserArr.erase(i);
}
} //namspace SE