Exemplo n.º 1
0
/**
 * progress one frame, handle all network traffic
 */
void NG_NetworkScene::proceed(double curtime)
{
	if (!m_networkdevice) return;
	if (!m_networkdevice->IsOnline()) return;

	ClearAllMessageMaps();

	// read all NetworkMessages from the device
	vector<NG_NetworkMessage*> messages =
		m_networkdevice->RetrieveNetworkMessages();

	vector<NG_NetworkMessage*>::iterator mesit = messages.begin();
	for (; !(mesit == messages.end()); mesit++) {
		NG_NetworkMessage* message = (*mesit);
		vector<NG_NetworkMessage*>* tmplist=NULL;

		vector<NG_NetworkMessage*>** tmplistptr =
			m_messagesByDestinationName[message->GetDestinationName()];
		// if there is already a vector of messages, append, else create
		// a new vector and insert into map
		if (!tmplistptr) {
			tmplist = new vector<NG_NetworkMessage*>;
			m_messagesByDestinationName.insert(message->GetDestinationName(),
											   tmplist);
		} else {
			tmplist = *tmplistptr;
		}
		message->AddRef();
		tmplist->push_back(message);
		tmplist = NULL;

		tmplistptr = m_messagesBySenderName[message->GetSenderName()];
		// if there is already a vector of messages, append, else create
		// a new vector and insert into map
		if (!tmplistptr) {
			tmplist = new vector<NG_NetworkMessage*>;
			m_messagesBySenderName.insert(message->GetSenderName(), tmplist);
		}  else {
			tmplist = *tmplistptr;
		}
		message->AddRef();
		tmplist->push_back(message);
		tmplist = NULL;
		
		tmplistptr = m_messagesBySubject[message->GetSubject()];
		// if there is already a vector of messages, append, else create
		// a new vector and insert into map
		if (!tmplistptr) {
			tmplist = new vector<NG_NetworkMessage*>;
			m_messagesBySubject.insert(message->GetSubject(), tmplist);
		}  else {
			tmplist = *tmplistptr;
		}
		message->AddRef();
		tmplist->push_back(message);
		tmplist = NULL;
	}
}
Exemplo n.º 2
0
vector<NG_NetworkMessage*> NG_NetworkScene::FindMessages(
	const STR_String& to,
	const STR_String& from,
	const STR_String& subject,
	bool spamallowed)
{
	vector<NG_NetworkMessage*> foundmessages;
	bool notfound = false;

	// broad phase
	notfound = ((to.IsEmpty() || spamallowed) ? notfound : m_messagesByDestinationName[to] == NULL);
	if (!notfound)
		notfound = (from.IsEmpty() ? notfound : m_messagesBySenderName[from] == NULL);
	if (!notfound)
		notfound = (subject.IsEmpty() ? notfound : m_messagesBySubject[subject] == NULL);
	if (notfound) {
		// it's definitely NOT in the scene, so stop looking
	} else { // narrow phase
		// possibly it's there, but maybe not (false hit)
		if (to.IsEmpty()) {
			// take all messages, and check other fields
			MT_assert(!"objectnames that are empty are not valid, so make it a hobby project :)\n");
		} else {
			//todo: find intersection of messages (that are in other 2 maps)
			vector<NG_NetworkMessage*>** tolistptr = m_messagesByDestinationName[to];
			if (tolistptr) {
				vector<NG_NetworkMessage*>* tolist = *tolistptr;
				vector<NG_NetworkMessage*>::iterator listit;
				for (listit=tolist->begin();!(listit==tolist->end());listit++) {
					NG_NetworkMessage* message = *listit;
					if (ConstraintsAreValid(from, subject, message)) {
						message->AddRef();
						foundmessages.push_back(message);
					}
				} 
			}
			// TODO find intersection of messages (that are in other 2 maps)
			if (spamallowed) {
				tolistptr = m_messagesByDestinationName[""];
				if (tolistptr) {
					vector<NG_NetworkMessage*>* tolist = *tolistptr;
					vector<NG_NetworkMessage*>::iterator listit;
					for (listit=tolist->begin();!(listit==tolist->end());listit++) {
						NG_NetworkMessage* message = *listit;
						if (ConstraintsAreValid(from, subject, message)) {
							message->AddRef();
							foundmessages.push_back(message);
						}
					} 
				}
			}
		}
	} 
	return foundmessages;
}