mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-09 15:16:42 +02:00
identify client by id instead of MAC
This commit is contained in:
parent
433a2ff252
commit
9ec135e1b8
7 changed files with 61 additions and 50 deletions
|
@ -79,8 +79,8 @@ void StreamServer::onDisconnect(StreamSession* streamSession)
|
|||
if (session == nullptr)
|
||||
return;
|
||||
|
||||
logO << "onDisconnect: " << session->macAddress << "\n";
|
||||
ClientInfoPtr clientInfo = Config::instance().getClientInfo(streamSession->macAddress);
|
||||
logO << "onDisconnect: " << session->clientId << "\n";
|
||||
ClientInfoPtr clientInfo = Config::instance().getClientInfo(streamSession->clientId);
|
||||
logD << "sessions: " << sessions_.size() << "\n";
|
||||
// don't block: remove StreamSession in a thread
|
||||
auto func = [](shared_ptr<StreamSession> s)->void{s->stop();};
|
||||
|
@ -246,7 +246,7 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
connection->sendAsync(timeMsg, true);
|
||||
|
||||
// refresh connection state
|
||||
ClientInfoPtr client = Config::instance().getClientInfo(connection->macAddress);
|
||||
ClientInfoPtr client = Config::instance().getClientInfo(connection->clientId);
|
||||
if (client != nullptr)
|
||||
{
|
||||
gettimeofday(&client->lastSeen, NULL);
|
||||
|
@ -257,17 +257,17 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
{
|
||||
msg::Hello helloMsg;
|
||||
helloMsg.deserialize(baseMessage, buffer);
|
||||
connection->macAddress = helloMsg.getMacAddress();
|
||||
logO << "Hello from " << connection->macAddress << ", host: " << helloMsg.getHostName() << ", v" << helloMsg.getVersion()
|
||||
connection->clientId = helloMsg.getClientId();
|
||||
logO << "Hello from " << connection->clientId << ", host: " << helloMsg.getHostName() << ", v" << helloMsg.getVersion()
|
||||
<< ", ClientName: " << helloMsg.getClientName() << ", OS: " << helloMsg.getOS() << ", Arch: " << helloMsg.getArch()
|
||||
<< ", Protocol version: " << helloMsg.getProtocolVersion() << "\n";
|
||||
|
||||
logD << "request kServerSettings: " << connection->macAddress << "\n";
|
||||
logD << "request kServerSettings: " << connection->clientId << "\n";
|
||||
// std::lock_guard<std::mutex> mlock(mutex_);
|
||||
ClientInfoPtr clientInfo = Config::instance().getClientInfo(connection->macAddress, true);
|
||||
ClientInfoPtr clientInfo = Config::instance().getClientInfo(connection->clientId, true);
|
||||
if (clientInfo == nullptr)
|
||||
{
|
||||
logE << "could not get client info for MAC: " << connection->macAddress << "\n";
|
||||
logE << "could not get client info for client: " << connection->clientId << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -281,7 +281,8 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
connection->sendAsync(serverSettings);
|
||||
}
|
||||
|
||||
ClientInfoPtr client = Config::instance().getClientInfo(connection->macAddress);
|
||||
ClientInfoPtr client = Config::instance().getClientInfo(connection->clientId);
|
||||
client->host.mac = helloMsg.getMacAddress();
|
||||
client->host.ip = connection->getIP();
|
||||
client->host.name = helloMsg.getHostName();
|
||||
client->host.os = helloMsg.getOS();
|
||||
|
@ -289,6 +290,7 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
client->snapclient.version = helloMsg.getVersion();
|
||||
client->snapclient.name = helloMsg.getClientName();
|
||||
client->snapclient.protocolVersion = helloMsg.getProtocolVersion();
|
||||
client->config.instance = helloMsg.getInstance();
|
||||
client->connected = true;
|
||||
gettimeofday(&client->lastSeen, NULL);
|
||||
|
||||
|
@ -324,14 +326,13 @@ session_ptr StreamServer::getStreamSession(StreamSession* streamSession) const
|
|||
}
|
||||
|
||||
|
||||
session_ptr StreamServer::getStreamSession(const std::string& mac) const
|
||||
session_ptr StreamServer::getStreamSession(const std::string& clientId) const
|
||||
{
|
||||
// logO << "getStreamSession: " << mac << "\n";
|
||||
std::lock_guard<std::recursive_mutex> mlock(sessionsMutex_);
|
||||
for (auto session: sessions_)
|
||||
{
|
||||
// logO << "getStreamSession, checking: " << session->macAddress << "\n";
|
||||
if (session->macAddress == mac)
|
||||
if (session->clientId == clientId)
|
||||
return session;
|
||||
}
|
||||
return nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue