mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 22:39:45 +02:00
name the current domain server
This commit is contained in:
parent
934e2e3cc5
commit
a362fdc2ed
4 changed files with 87 additions and 29 deletions
|
@ -147,6 +147,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
|
||||
NodeList::getInstance()->addHook(&_voxels);
|
||||
NodeList::getInstance()->addHook(this);
|
||||
NodeList::getInstance()->addDomainListener(this);
|
||||
|
||||
|
||||
// network receive thread and voxel parsing thread are both controlled by the --nonblocking command line
|
||||
|
@ -236,6 +237,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
Application::~Application() {
|
||||
NodeList::getInstance()->removeHook(&_voxels);
|
||||
NodeList::getInstance()->removeHook(this);
|
||||
NodeList::getInstance()->removeDomainListener(this);
|
||||
|
||||
_sharedVoxelSystem.changeTree(new VoxelTree);
|
||||
|
||||
|
@ -314,8 +316,6 @@ void Application::initializeGL() {
|
|||
char title[50];
|
||||
sprintf(title, "Interface: %4.2f seconds\n", startupTime);
|
||||
qDebug("%s", title);
|
||||
_window->setWindowTitle(title);
|
||||
|
||||
const char LOGSTASH_INTERFACE_START_TIME_KEY[] = "interface-start-time";
|
||||
|
||||
// ask the Logstash class to record the startup time
|
||||
|
@ -3235,6 +3235,10 @@ void Application::attachNewHeadToNode(Node* newNode) {
|
|||
}
|
||||
}
|
||||
|
||||
void Application::domainChanged(QString domain) {
|
||||
_window->setWindowTitle(domain);
|
||||
}
|
||||
|
||||
void Application::nodeAdded(Node* node) {
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ static const float NODE_KILLED_RED = 1.0f;
|
|||
static const float NODE_KILLED_GREEN = 0.0f;
|
||||
static const float NODE_KILLED_BLUE = 0.0f;
|
||||
|
||||
class Application : public QApplication, public NodeListHook, public PacketSenderNotify {
|
||||
class Application : public QApplication, public NodeListHook, public PacketSenderNotify, public DomainChangeListener {
|
||||
Q_OBJECT
|
||||
|
||||
friend class VoxelPacketProcessor;
|
||||
|
@ -142,6 +142,8 @@ public:
|
|||
virtual void nodeAdded(Node* node);
|
||||
virtual void nodeKilled(Node* node);
|
||||
virtual void packetSentNotification(ssize_t length);
|
||||
|
||||
virtual void domainChanged(QString domain);
|
||||
|
||||
public slots:
|
||||
void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data);
|
||||
|
|
|
@ -82,22 +82,20 @@ NodeList::~NodeList() {
|
|||
stopSilentNodeRemovalThread();
|
||||
}
|
||||
|
||||
void NodeList::setDomainHostname(const char* domainHostname) {
|
||||
memset(_domainHostname, 0, sizeof(_domainHostname));
|
||||
memcpy(_domainHostname, domainHostname, strlen(domainHostname));
|
||||
|
||||
void NodeList::setDomainHostname(const char* domainHostname) {
|
||||
// reset the domain IP so the hostname is checked again
|
||||
setDomainIP("");
|
||||
resetDomainData(_domainHostname, domainHostname);
|
||||
}
|
||||
|
||||
void NodeList::setDomainIP(const char* domainIP) {
|
||||
memset(_domainIP, 0, sizeof(_domainIP));
|
||||
memcpy(_domainIP, domainIP, strlen(domainIP));
|
||||
resetDomainData(_domainIP, domainIP);
|
||||
}
|
||||
|
||||
void NodeList::setDomainIPToLocalhost() {
|
||||
int ip = getLocalAddress();
|
||||
sprintf(_domainIP, "%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||
char _localIP[INET_ADDRSTRLEN];
|
||||
sprintf(_localIP, "%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||
setDomainIP(_localIP);
|
||||
}
|
||||
|
||||
void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) {
|
||||
|
@ -269,25 +267,8 @@ void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNo
|
|||
}
|
||||
|
||||
void NodeList::sendDomainServerCheckIn() {
|
||||
static bool printedDomainServerIP = false;
|
||||
|
||||
// Lookup the IP address of the domain server if we need to
|
||||
if (atoi(_domainIP) == 0) {
|
||||
printf("Looking up %s\n", _domainHostname);
|
||||
struct hostent* pHostInfo;
|
||||
if ((pHostInfo = gethostbyname(_domainHostname)) != NULL) {
|
||||
sockaddr_in tempAddress;
|
||||
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
|
||||
strcpy(_domainIP, inet_ntoa(tempAddress.sin_addr));
|
||||
qDebug("Domain Server: %s\n", _domainHostname);
|
||||
} else {
|
||||
qDebug("Failed domain server lookup\n");
|
||||
}
|
||||
} else if (!printedDomainServerIP) {
|
||||
qDebug("Domain Server IP: %s\n", _domainIP);
|
||||
printedDomainServerIP = true;
|
||||
}
|
||||
|
||||
domainLookup();
|
||||
static unsigned char* checkInPacket = NULL;
|
||||
static int checkInPacketSize = 0;
|
||||
|
||||
|
@ -650,6 +631,21 @@ void NodeListIterator::skipDeadAndStopIncrement() {
|
|||
}
|
||||
}
|
||||
|
||||
void NodeList::addDomainListener(DomainChangeListener* listener) {
|
||||
_domainListeners.push_back(listener);
|
||||
QString domain = (strlen(_domainHostname) > 0) ? _domainHostname : _domainIP;
|
||||
listener->domainChanged(domain);
|
||||
}
|
||||
|
||||
void NodeList::removeDomainListener(DomainChangeListener* listener) {
|
||||
for (int i = 0; i < _domainListeners.size(); i++) {
|
||||
if (_domainListeners[i] == listener) {
|
||||
_domainListeners.erase(_domainListeners.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NodeList::addHook(NodeListHook* hook) {
|
||||
_hooks.push_back(hook);
|
||||
}
|
||||
|
@ -676,3 +672,47 @@ void NodeList::notifyHooksOfKilledNode(Node* node) {
|
|||
_hooks[i]->nodeKilled(node);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeList::notifyDomainChanged() {
|
||||
QString domain = (strlen(_domainHostname) > 0) ? _domainHostname : _domainIP;
|
||||
for (int i = 0; i < _domainListeners.size(); i++) {
|
||||
_domainListeners[i]->domainChanged(domain);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeList::resetDomainData(char domainField[], const char* domainValue) {
|
||||
memset(_domainHostname, 0, sizeof(_domainHostname));
|
||||
memcpy(_domainHostname, "", strlen(""));
|
||||
|
||||
memset(_domainIP, 0, sizeof(_domainIP));
|
||||
memcpy(_domainIP, "", strlen(""));
|
||||
|
||||
memset(domainField, 0, sizeof(&domainField));
|
||||
memcpy(domainField, domainValue, strlen(domainValue));
|
||||
|
||||
domainLookup();
|
||||
notifyDomainChanged();
|
||||
}
|
||||
|
||||
void NodeList::domainLookup() {
|
||||
static bool printedDomainServerIP = false;
|
||||
|
||||
// Lookup the IP address of the domain server if we need to
|
||||
if (atoi(_domainIP) == 0) {
|
||||
printf("Looking up %s\n", _domainHostname);
|
||||
struct hostent* pHostInfo;
|
||||
if ((pHostInfo = gethostbyname(_domainHostname)) != NULL) {
|
||||
sockaddr_in tempAddress;
|
||||
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
|
||||
strcpy(_domainIP, inet_ntoa(tempAddress.sin_addr));
|
||||
|
||||
qDebug("Domain Server: %s\n", _domainHostname);
|
||||
} else {
|
||||
qDebug("Failed domain server lookup\n");
|
||||
}
|
||||
} else if (!printedDomainServerIP) {
|
||||
notifyDomainChanged();
|
||||
qDebug("Domain Server IP: %s\n", _domainIP);
|
||||
printedDomainServerIP = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,10 @@ public:
|
|||
virtual void nodeKilled(Node* node) = 0;
|
||||
};
|
||||
|
||||
class DomainChangeListener {
|
||||
public:
|
||||
virtual void domainChanged(QString domain) = 0;
|
||||
};
|
||||
|
||||
class NodeList {
|
||||
public:
|
||||
|
@ -130,6 +134,9 @@ public:
|
|||
void notifyHooksOfAddedNode(Node* node);
|
||||
void notifyHooksOfKilledNode(Node* node);
|
||||
|
||||
void addDomainListener(DomainChangeListener* listener);
|
||||
void removeDomainListener(DomainChangeListener* listener);
|
||||
|
||||
private:
|
||||
static NodeList* _sharedInstance;
|
||||
|
||||
|
@ -158,6 +165,11 @@ private:
|
|||
void timePingReply(sockaddr *nodeAddress, unsigned char *packetData);
|
||||
|
||||
std::vector<NodeListHook*> _hooks;
|
||||
std::vector<DomainChangeListener*> _domainListeners;
|
||||
|
||||
void resetDomainData(char domainField[], const char* domainData);
|
||||
void notifyDomainChanged();
|
||||
void domainLookup();
|
||||
};
|
||||
|
||||
class NodeListIterator : public std::iterator<std::input_iterator_tag, Node> {
|
||||
|
|
Loading…
Reference in a new issue