Ejemplo n.º 1
0
void RemoteNetworkView::RemoveHTTPSocket(IEventDataPtr pEventData) {
	printf("Remove HTTP Socket %d\n", pEventData->VGetSocketId());
	NetSocket* netSocket = g_pSocketManager->FindSocket(pEventData->VGetSocketId());
	// say to delete socket AFTER packet treatment
	if (netSocket) {
	    netSocket->SetSocketDelete(4);
	}	
}
Ejemplo n.º 2
0
void RemoteNetworkView::ForwardEvent(IEventDataPtr pEventData) {
	std::string httpinmsg;
	if (!pEventData) {
		GCC_ERROR("Event Invalid");
		return;
	}
	int socketId = pEventData->VGetSocketId();

	std::ostrstream out;

	pEventData->VSerialize(out);
	out << std::ends;

	IPacket *packetBack = NULL;
	if (!strncmp("HTTP", &out.rdbuf()->str()[0], 4)) {
		packetBack = GCC_NEW HTTPPacket(out.rdbuf()->str());
	}
	else {
		//TODO create binary packet
	}
	std::shared_ptr<IPacket> ipBack(packetBack);
	printf("RemoteNetworkView Forward Event socket:%d %s\n", socketId, pEventData->GetName());
	g_pSocketManager->Send(socketId, ipBack);

	if (!strncmp("HTTP", &out.rdbuf()->str()[0], 4)) {
		IEventDataPtr pCloseSocketHttpEvent(CREATE_EVENT(EventData_CloseSocketHTTP::sk_EventType));
		char* id = new char[100];
		sprintf_s(id, 100, "%d", socketId);
		httpinmsg.append(id);
		std::istrstream in(httpinmsg.c_str(), httpinmsg.size());
		pCloseSocketHttpEvent->VDeserialize(in);
		IEventManager::Get()->VQueueEvent(pCloseSocketHttpEvent);
	}
}
Ejemplo n.º 3
0
void RemoteNetworkView::GetActor(IEventDataPtr pEventData) {
	char response[4];
	std::string httpinmsg;
	IEventDataPtr pResponseHttpEvent(CREATE_EVENT(EventData_ResponseHTTP::sk_EventType));

	std::shared_ptr<EventData_GetActor> pCastEventData = std::static_pointer_cast<EventData_GetActor>(pEventData);
	std::string name = pCastEventData->VGetActorName();
	unsigned int ip = pCastEventData->VGetIp();
	pResponseHttpEvent->VSetSocketId(pEventData->VGetSocketId());
	pResponseHttpEvent->VSetIp(ip);
	//look for actor data in actor manager by ip / actor name
	StrongActorPtr pActor = m_ActorManager->GetActorByName(ip, name);

	if (pActor == NULL) {
		_itoa_s(http_response_code_t::NOTFOUND, response,10);
		httpinmsg.append(response);
		std::istrstream in(httpinmsg.c_str(),httpinmsg.size());
		pResponseHttpEvent->VDeserialize(in);
		IEventManager::Get()->VTriggerEvent(pResponseHttpEvent);
	}
	else {
		// Better (de-)serialize Actor with streams
		std::string buffer;
		_itoa_s(http_response_code_t::OK, response, 10);
		buffer.append(response);
		buffer.append(" ");

		char* id = new char[10];
		sprintf_s(id, 10, "%d", pActor->GetId());
		buffer.append(id);
		buffer.append("#");
		buffer.append(pActor->GetName());
		buffer.append("#");
		Vec3 position = pActor->GetPosition();
		char *xpos = new char[10];
		sprintf_s(xpos, 10, "%.3f", position.x);
		buffer.append(xpos);
		buffer.append("#");
		char *ypos = new char[10];
		sprintf_s(ypos, 10, "%.3f", position.y);
		buffer.append(ypos);
		buffer.append("#");
		char *zpos = new char[10];
		sprintf_s(zpos, 10, "%.3f", position.z);
		buffer.append(zpos);	
		buffer.push_back('\0');
		// when found, send answer	
		std::istrstream in(buffer.c_str(), buffer.size());
		pResponseHttpEvent->VDeserialize(in);
		IEventManager::Get()->VTriggerEvent(pResponseHttpEvent);
	}
}