void
ObjectAccessor::WorldObjectChangeAccumulator::Visit(PlayerMapType &m)
{
    for(PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
    {
        BuildPacket(iter->getSource());
        if (!iter->getSource()->GetSharedVisionList().empty())
        {
            SharedVisionList::const_iterator it = iter->getSource()->GetSharedVisionList().begin();
            for ( ; it != iter->getSource()->GetSharedVisionList().end(); ++it)
                BuildPacket(*it);
        }
    }
}
Exemple #2
0
void GossipMenu::SendTo(Player* Plr)
{
    WorldPacket data(SMSG_GOSSIP_MESSAGE, Menu.size() * 50 + 24);
    BuildPacket(data);
    data << uint32(0);  // 0 quests obviously
    Plr->GetSession()->SendPacket(&data);
}
Exemple #3
0
/// Sends this packet's data to target QTcpSocket, using necessary packet-headers.
bool SIPPacket::Send(Socket * sock){
	assert(sock);
	// Check if header is set.
	EnsureHeader();
	/// Construct message
	String fullPacket = BuildPacket();
	int bytesWritten = sock->Write(fullPacket.c_str(), fullPacket.Length());
	return true;
}
RTPPacket::RTPPacket(uint8_t payloadtype,const void *payloaddata,size_t payloadlen,uint16_t seqnr,
		  uint32_t timestamp,uint32_t ssrc,bool gotmarker,uint8_t numcsrcs,const uint32_t *csrcs,
		  bool gotextension,uint16_t extensionid,uint16_t extensionlen_numwords,const void *extensiondata,
		  size_t maxpacksize, RTPMemoryManager *mgr) : RTPMemoryObject(mgr),receivetime(0,0)
{
	Clear();
	error = BuildPacket(payloadtype,payloaddata,payloadlen,seqnr,timestamp,ssrc,gotmarker,numcsrcs,
	       	            csrcs,gotextension,extensionid,extensionlen_numwords,extensiondata,0,maxpacksize);
}
Exemple #5
0
void Session::Worker()
{
    sLog->StaticOut("Network worker thread running");
    sApp->ThreadStatus.sessionworker = true;

    char* buf = new char[BUFFER_LEN];
    int result, error;
    Player* pClient = NULL;
    std::list<Player*>::iterator itr;

    while(1)
    {
        if (clientList.empty())
        {
            // Wait for longer period, no need to check for socket traffic so often if nobody's connected
            boost::this_thread::sleep(boost::posix_time::milliseconds(100));
            continue;
        }

        for (itr = clientList.begin(); itr != clientList.end();)
        {
            pClient = (*itr); // Who wants ugly star in brackets?!
            if (pClient)
            {
                memset(buf,0,BUFFER_LEN);
                result = recv(pClient->m_socket, buf, BUFFER_LEN, 0);
                error = LASTERROR();

                if (result > 0)
                {
                    sLog->NetworkOut(pClient,"Received data, size: %u",result);
                    ProcessPacket(BuildPacket(buf,result), pClient);
                }
                else if (result == 0 || error == SOCKETCONNRESET)
                {
                    sLog->NetworkOut(pClient,"Client disconnected");
                    sInstanceManager->RemovePlayerFromInstances(pClient);
                    itr = clientList.erase(itr);
                    continue;
                }
                else
                {
                    if (error != SOCKETWOULDBLOCK && error != 0)
                    {
                        //error
                        sLog->NetworkOut(pClient,"Unhandled socket error: %u",error);
                    }
                }
            }
            ++itr;
        }

        // Some waiting time, could be changed if needed, but thread have to wait since select() is not present
        boost::this_thread::sleep(boost::posix_time::milliseconds(10));
    }
}
RTPPacket::RTPPacket(uint8_t payloadtype,const void *payloaddata,size_t payloadlen,uint16_t seqnr,
		  uint32_t timestamp,uint32_t ssrc,bool gotmarker,uint8_t numcsrcs,const uint32_t *csrcs,
		  bool gotextension,uint16_t extensionid,uint16_t extensionlen_numwords,const void *extensiondata,
		  void *buffer,size_t buffersize, RTPMemoryManager *mgr) : RTPMemoryObject(mgr),receivetime(0,0)
{
	Clear();
	if (buffer == 0)
		error = ERR_RTP_PACKET_EXTERNALBUFFERNULL;
	else if (buffersize <= 0)
		error = ERR_RTP_PACKET_ILLEGALBUFFERSIZE;
	else
		error = BuildPacket(payloadtype,payloaddata,payloadlen,seqnr,timestamp,ssrc,gotmarker,numcsrcs,
		                    csrcs,gotextension,extensionid,extensionlen_numwords,extensiondata,buffer,buffersize);
}
void
ObjectAccessor::WorldObjectChangeAccumulator::Visit(DynamicObjectMapType &m)
{
    for(DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
    {
        uint64 guid = iter->getSource()->GetCasterGUID();
        if(IS_PLAYER_GUID(guid))
        {
            //Caster may be NULL if DynObj is in removelist
            if(Player *caster = FindPlayer(guid))
                if (caster->GetUInt64Value(PLAYER_FARSIGHT) == iter->getSource()->GetGUID())
                    BuildPacket(caster);
        }
    }
}
BOOL CALLBACK DlgProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uiMsg)
	{
	case WM_INITDIALOG:
		::g_hDlg = hDlg;
		SetDlgItemText(hDlg, IDC_CHAT, "Chat message to send goes here");
		SendDlgItemMessage(hDlg, IDC_CHAT, EM_LIMITTEXT, 1600, 0);
		break;
	case WM_QUIT:
	case WM_CLOSE:
		EndDialog(hDlg, 0);
		break;
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDCANCEL:
			EndDialog(hDlg, 0);
			break;
		case IDOK:
			{
				int index = SendDlgItemMessage(hDlg, IDC_CBUSERS, CB_GETCURSEL, 0, 0);
				int textLength = SendDlgItemMessage(hDlg, IDC_CHAT, WM_GETTEXTLENGTH, 0, 0);
				if(textLength == 0)
					break;
				char* emailSelected = new char[128];
				char* packet = new char[textLength+1];
				GetDlgItemText(hDlg, IDC_CHAT, packet, textLength+1);
				SendDlgItemMessage(hDlg, IDC_CBUSERS, CB_GETLBTEXT, index, (LPARAM)emailSelected);
				SOCKET sessionToSendTo = GetSessionFromEmail(emailSelected);
				BuildPacket(sessionToSendTo, packet);
				delete [] emailSelected;
				delete [] packet;
			}
			break;	
		}
		break;
	default: break;
	}
return FALSE;
}
Exemple #9
0
// Sends this packet to target client. If header has not been set by a subclass it will be generated using the given client data and known sender data.
bool SIPPacket::Send(Peer * receiver)
{
	assert(receiver);
	// With a few exceptions, demand a valid receiver before proceeding.
	switch(sipType)
	{
		case SIP_REGISTER:
		case SIP_BAD_REQUEST:
			break;
		default:
			if (!receiver->isValid)
			{
				std::cout<<"SIPPacket::Send:\nPacket: ";
				Print();
				receiver->Print();
				std::cout<<"WARNING: Sending packet to undefined receiver. May not be desired for too long.";
			//	assert(false);
			//	return false;
//				assert(receiver->isValid);
			}
	}
	// Set recipient if not already done so.
	EnsureRecipient(receiver);

	// Check if header is set.
	EnsureHeader();
	/// Construct message
	String fullPacket = BuildPacket();
	List<String> lines = GetLines(fullPacket);
	std::cout << "\nWriting packet...\n" <<fullPacket<<"\nWith lines: "<<lines.Size();
	// Send it.
	int bytesWritten = receiver->primaryCommunicationSocket->Write(fullPacket.c_str(), fullPacket.Length());
	assert(bytesWritten);
//	int bytesWritten = sock->Write(fullPacket.c_str(), fullPacket.Length());
	return true;
}	
Exemple #10
0
void Session::Worker()
{
    sLog->StaticOut("Network worker thread running");
    sApp->ThreadStatus.sessionworker = true;

    char* buf = new char[BUFFER_LEN];
    int result, error;
    SOCK res;
    Player* pClient = NULL;
    Player* pNew = new Player;
    pNew->m_addrLen = sizeof(pNew->m_sockInfo);
    std::list<Player*>::iterator itr;

    while(1)
    {
        res = accept(m_socket, (sockaddr*)&pNew->m_sockInfo, &pNew->m_addrLen);
        error = LASTERROR();

        if (res == INVALID_SOCKET && error == SOCKETWOULDBLOCK)
        {
            // zadne prichozi spojeni
        }
        else if (res == INVALID_SOCKET && error != SOCKETWOULDBLOCK)
        {
            sLog->ErrorOut("Socket error: %i", error);
        }
        else
        {
            pNew->m_socket = res;
            pNew->m_addrLen = sizeof(pNew->m_sockInfo);

            sLog->DebugOut("Accepting connection from %s",inet_ntoa((in_addr)pNew->m_sockInfo.sin_addr));

            clientList.push_back(pNew);
            sLog->NetworkDebugOut(pNew,"Inserted into client list");

            pNew = new Player;
            pNew->m_addrLen = sizeof(pNew->m_sockInfo);
        }

        if (clientList.empty())
        {
            // Wait for longer period, no need to check for socket traffic so often if nobody's connected
            boost::this_thread::sleep(boost::posix_time::milliseconds(100));
            continue;
        }

        for (itr = clientList.begin(); itr != clientList.end();)
        {
            pClient = (*itr); // Who wants ugly star in brackets?!
            if (pClient)
            {
                memset(buf,0,BUFFER_LEN);
                result = recv(pClient->m_socket, buf, BUFFER_LEN, 0);
                error = LASTERROR();

                if (result > 0)
                {
                    sLog->NetworkDebugOut(pClient,"Received data, size: %u",result);
                    SmartPacket* parsed = BuildPacket(buf,result);
                    if (parsed)
                    {
                        sLog->NetworkDebugOut(pClient,"Opcode 0x%.2X, size %u", parsed->GetOpcode(), parsed->GetSize());
                        ProcessPacket(parsed, pClient);

                        int32 totalparsed = parsed->GetSize()+8;
                        while (totalparsed < result)
                        {
                            parsed = BuildPacket(buf+totalparsed, result-totalparsed);
                            if (parsed)
                            {
                                sLog->NetworkDebugOut(pClient,"Parsed additional %u bytes",parsed->GetSize());
                                sLog->NetworkDebugOut(pClient,"Opcode 0x%.2X, size %u", parsed->GetOpcode(), parsed->GetSize());
                                ProcessPacket(parsed, pClient);
                                totalparsed += parsed->GetSize()+8;
                            }
                            else
                                break;
                        }
                    }
                }
                else if (result == 0 || error == SOCKETCONNRESET)
                {
                    sLog->NetworkDebugOut(pClient,"Client disconnected");
                    sInstanceManager->RemovePlayerFromInstances(pClient);
                    itr = clientList.erase(itr);
                    continue;
                }
                else
                {
                    if (error != SOCKETWOULDBLOCK && error != 0)
                    {
                        //error
                        sLog->NetworkOut(pClient,"Unhandled socket error: %u",error);
                    }
                }
            }
            ++itr;
        }

        // Some waiting time, could be changed if needed, but thread have to wait since select() is not present
        // technically, this counts as "yield" on Windows
        boost::this_thread::sleep(boost::posix_time::milliseconds(1));
    }
}
bool AuxPlayerIndex::BuildPacket()
{
    return BuildPacket(PacketBuffer, PacketSize);
}