1
0
mirror of https://github.com/ShaYmez/xlxd.git synced 2026-07-25 11:34:11 -04:00

xlxd 1.2.4 / db 2.1.0

implement XLX interlink feature
This commit is contained in:
LX3JL
2016-02-11 18:51:12 +01:00
parent 4831ba8829
commit 2f9e8a8781
259 changed files with 2603 additions and 647 deletions
+51 -39
View File
@@ -45,6 +45,10 @@ bool CDextraProtocol::Init(void)
// create our socket
ok &= m_Socket.Open(DEXTRA_PORT);
if ( !ok )
{
std::cout << "Error opening socket on port UDP" << DEXTRA_PORT << " on ip " << g_Reflector.GetListenIp() << std::endl;
}
// update time
m_LastKeepaliveTime.Now();
@@ -139,7 +143,7 @@ void CDextraProtocol::Task(void)
}
else if ( IsValidKeepAlivePacket(Buffer, &Callsign) )
{
//std::cout << "DExtra keepalive packet from " << Callsign << " at " << Ip << std::endl;
//std::cout << "DExtra keepalive packet from " << Callsign << " at " << Ip << std::endl;
// find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients();
@@ -166,42 +170,8 @@ void CDextraProtocol::Task(void)
// keep client alive
if ( m_LastKeepaliveTime.DurationSinceNow() > DEXTRA_KEEPALIVE_PERIOD )
{
// DExtra protocol sends and monitors keepalives packets
// event if the client is currently streaming
// so, send keepalives to all
CBuffer keepalive;
EncodeKeepAlivePacket(&keepalive);
// iterate on clients
CClients *clients = g_Reflector.GetClients();
int index = -1;
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, &index)) != NULL )
{
// send keepalive
m_Socket.Send(keepalive, client->GetIp());
// client busy ?
if ( client->IsAMaster() )
{
// yes, just tickle it
client->Alive();
}
// otherwise check if still with us
else if ( !client->IsAlive() )
{
// no, disconnect
CBuffer disconnect;
EncodeDisconnectPacket(&disconnect);
m_Socket.Send(disconnect, client->GetIp());
// remove it
std::cout << "DExtra client " << client->GetCallsign() << " keepalive timeout" << std::endl;
clients->RemoveClient(client);
}
}
g_Reflector.ReleaseClients();
//
HandleKeepalives();
// update time
m_LastKeepaliveTime.Now();
@@ -248,6 +218,49 @@ void CDextraProtocol::HandleQueue(void)
m_Queue.Unlock();
}
////////////////////////////////////////////////////////////////////////////////////////
// keepalive helpers
void CDextraProtocol::HandleKeepalives(void)
{
// DExtra protocol sends and monitors keepalives packets
// event if the client is currently streaming
// so, send keepalives to all
CBuffer keepalive;
EncodeKeepAlivePacket(&keepalive);
// iterate on clients
CClients *clients = g_Reflector.GetClients();
int index = -1;
CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, &index)) != NULL )
{
// send keepalive
m_Socket.Send(keepalive, client->GetIp());
// client busy ?
if ( client->IsAMaster() )
{
// yes, just tickle it
client->Alive();
}
// otherwise check if still with us
else if ( !client->IsAlive() )
{
// no, disconnect
CBuffer disconnect;
EncodeDisconnectPacket(&disconnect);
m_Socket.Send(disconnect, client->GetIp());
// remove it
std::cout << "DExtra client " << client->GetCallsign() << " keepalive timeout" << std::endl;
clients->RemoveClient(client);
}
}
g_Reflector.ReleaseClients();
}
////////////////////////////////////////////////////////////////////////////////////////
// streams helpers
@@ -301,7 +314,7 @@ bool CDextraProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *cal
callsign->SetCallsign(Buffer.data(), 8);
callsign->SetModule(Buffer.data()[8]);
*reflectormodule = Buffer.data()[9];
valid = (callsign->IsValid() && std::isupper(*reflectormodule));
valid = (callsign->IsValid() && IsLetter(*reflectormodule));
}
return valid;
}
@@ -437,7 +450,6 @@ void CDextraProtocol::EncodeDisconnectPacket(CBuffer *Buffer)
Buffer->Set(tag, sizeof(tag));
}
bool CDextraProtocol::EncodeDvHeaderPacket(const CDvHeaderPacket &Packet, CBuffer *Buffer) const
{
uint8 tag[] = { 'D','S','V','T',0x10,0x00,0x00,0x00,0x20,0x00,0x01,0x02 };