示例#1
0
void Socket::WritePacketToBuffer(Packet const& packet, MessageBuffer& buffer)
{
    ServerHeader header;
    uint32 sizeOfHeader = SizeOfServerHeader;
    uint32 opcode = packet.GetOpcode();
    uint32 packetSize = packet.size();

    // Reserve space for buffer
    uint8* headerPos = buffer.GetWritePointer();
    buffer.WriteCompleted(sizeOfHeader);

    if (!packet.empty())
        buffer.Write(packet.contents(), packet.size());

    header.Size = packetSize;
    header.Command = opcode;
    memcpy(headerPos, &header, sizeOfHeader);
}
示例#2
0
DWORD WINAPI ReadQueueThread(LPVOID lp)
{
	CAujardDlg* pMain = (CAujardDlg*)lp;
	CString string;

	while (TRUE)
	{
		if (pMain->m_LoggerRecvQueue.GetFrontMode() != R)
		{
			Packet pkt;
			int recvlen = pMain->m_LoggerRecvQueue.GetData(pkt);
			if (recvlen > MAX_PKTSIZE || recvlen == 0)
			{
				Sleep(1);
				continue;
			}

			switch (pkt.GetOpcode())
			{
			case WIZ_LOGIN:
				pMain->AccountLogIn(pkt);
				break;
			case WIZ_SEL_NATION:
				pMain->SelectNation(pkt);
				break;
			case WIZ_ALLCHAR_INFO_REQ:
				pMain->AllCharInfoReq(pkt);
				break;
			case WIZ_NEW_CHAR:
				pMain->CreateNewChar(pkt);
				break;
			case WIZ_DEL_CHAR:
				pMain->DeleteChar(pkt);
				break;
			case WIZ_SEL_CHAR:
				pMain->SelectCharacter(pkt);
				break;
			case WIZ_DATASAVE:
				pMain->UserDataSave(pkt);
				break;
			case WIZ_KNIGHTS_PROCESS:
				pMain->KnightsPacket(pkt);
				break;
			case WIZ_LOGIN_INFO:
				pMain->SetLogInInfo(pkt);
				break;
			case WIZ_KICKOUT:
				pMain->UserKickOut(pkt);
				break;
			case WIZ_BATTLE_EVENT:
				pMain->BattleEventResult(pkt);
				break;
			case WIZ_SHOPPING_MALL:
				pMain->ShoppingMall(pkt);
				break;
			case WIZ_SKILLDATA:
				pMain->SkillDataProcess(pkt);
				break;
			case WIZ_FRIEND_PROCESS:
				pMain->FriendProcess(pkt);
				break;
			case WIZ_LOGOUT:
				pMain->UserLogOut(pkt);				
				break;
			}
		}
	}
}
示例#3
0
bool CGameSocket::HandlePacket(Packet & pkt)
{
	switch (pkt.GetOpcode())
	{
	case AI_SERVER_CONNECT:
		RecvServerConnect(pkt);
		break;
	case AG_USER_INFO:
		RecvUserInfo(pkt);
		break;
	case AG_USER_INOUT:
		RecvUserInOut(pkt);
		break;
	case AG_USER_MOVE:
		RecvUserMove(pkt);
		break;
	case AG_USER_MOVEEDGE:
		RecvUserMoveEdge(pkt);
		break;
	case AG_ATTACK_REQ:
		RecvAttackReq(pkt);
		break;
	case AG_USER_LOG_OUT:
		RecvUserLogOut(pkt);
		break;
	case AG_USER_REGENE:
		RecvUserRegene(pkt);
		break;
	case AG_USER_SET_HP:
		RecvUserSetHP(pkt);
		break;
	case AG_NPC_HP_CHANGE:
		RecvNpcHpChange(pkt);
		break;
	case AG_USER_UPDATE:
		RecvUserUpdate(pkt);
		break;
	case AG_ZONE_CHANGE:
		RecvZoneChange(pkt);
		break;
	case AG_USER_PARTY:
		m_Party.PartyProcess(pkt);
		break;
	case AG_USER_INFO_ALL:
		RecvUserInfoAllData(pkt);
		break;
	case AG_PARTY_INFO_ALL:
		RecvPartyInfoAllData(pkt);
		break;
	case AG_CHECK_ALIVE_REQ:
		RecvCheckAlive(pkt);
		break;
	case AG_HEAL_MAGIC:
		RecvHealMagic(pkt);
		break;
	case AG_TIME_WEATHER:
		RecvTimeAndWeather(pkt);
		break;
	case AG_USER_FAIL:
		RecvUserFail(pkt);
		break;
	case AG_BATTLE_EVENT:
		RecvBattleEvent(pkt);
		break;
	case AG_NPC_GATE_OPEN:
		RecvGateOpen(pkt);
		break;
	case AG_USER_VISIBILITY:
		RecvUserVisibility(pkt);
		break;
	}
	return true;
}
示例#4
0
bool CAISocket::HandlePacket(Packet & pkt)
{
	switch (pkt.GetOpcode())
	{
	case AG_CHECK_ALIVE_REQ:
		RecvCheckAlive(pkt);
		break;
	case AI_SERVER_CONNECT:
		LoginProcess(pkt);
		break;
	case AG_SERVER_INFO:
		RecvServerInfo(pkt);
		break;
	case NPC_INFO_ALL:
		RecvNpcInfoAll(pkt);
		break;
	case MOVE_RESULT:
		RecvNpcMoveResult(pkt);
		break;
	case MOVE_END_RESULT:
		break;
	case AG_ATTACK_REQ:
		RecvNpcAttack(pkt);
		break;
		// The AI server should send magic system requests to us.
		// It shouldn't have to duplicate all the processing code.
	case AG_MAGIC_ATTACK_REQ:
		CMagicProcess::MagicPacket(pkt);
		break;
	case AG_NPC_INFO:
		RecvNpcInfo(pkt);
		break;
	case AG_NPC_REGION_UPDATE:
		RecvNpcRegionUpdate(pkt);
		break;
	case AG_USER_EXP:
		RecvUserExp(pkt);
		break;
	case AG_SYSTEM_MSG:
		RecvSystemMsg(pkt);
		break;
	case AG_NPC_GIVE_ITEM:
		RecvNpcGiveItem(pkt);
		break;
	case AG_NPC_GATE_DESTORY:
		RecvGateDestory(pkt);
		break;
	case AG_DEAD:
		RecvNpcDead(pkt);
		break;
	case AG_NPC_INOUT:
		RecvNpcInOut(pkt);
		break;
	case AG_BATTLE_EVENT:
		RecvBattleEvent(pkt);
		break;
	case AG_NPC_EVENT_ITEM:
		RecvNpcEventItem(pkt);
		break;
	case AG_NPC_GATE_OPEN:
		RecvGateOpen(pkt);
		break;
	case AG_COMPRESSED:
		RecvCompressed(pkt);
		break;
	case AG_NPC_HP_CHANGE:
		RecvNpcHpChange(pkt);
		break;
	}

	return true;
}
示例#5
0
bool CAISocket::HandlePacket(Packet & pkt)
{
	TRACE("CAISocket::Parsing() - %X (%d), len=%d\n", pkt.GetOpcode(), pkt.GetOpcode(), pkt.size()); 
	switch (pkt.GetOpcode())
	{
		case AG_CHECK_ALIVE_REQ:
			RecvCheckAlive(pkt);
			break;
		case AI_SERVER_CONNECT:
			LoginProcess(pkt);
			break;
		case AG_SERVER_INFO:
			RecvServerInfo(pkt);
			break;
		case NPC_INFO_ALL:
			RecvNpcInfoAll(pkt);
			break;
		case MOVE_RESULT:
			RecvNpcMoveResult(pkt);
			break;
		case MOVE_END_RESULT:
			break;
		case AG_ATTACK_RESULT:
			RecvNpcAttack(pkt);
			break;
		case AG_MAGIC_ATTACK_RESULT:
			RecvMagicAttackResult(pkt);
			break;
		case AG_NPC_INFO:
			RecvNpcInfo(pkt);
			break;
		case AG_USER_SET_HP:
			RecvUserHP(pkt);
			break;
		case AG_USER_EXP:
			RecvUserExp(pkt);
			break;
		case AG_SYSTEM_MSG:
			RecvSystemMsg(pkt);
			break;
		case AG_NPC_GIVE_ITEM:
			RecvNpcGiveItem(pkt);
			break;
		case AG_USER_FAIL:
			RecvUserFail(pkt);
			break;
		case AG_NPC_GATE_DESTORY:
			RecvGateDestory(pkt);
			break;
		case AG_DEAD:
			RecvNpcDead(pkt);
			break;
		case AG_NPC_INOUT:
			RecvNpcInOut(pkt);
			break;
		case AG_BATTLE_EVENT:
			RecvBattleEvent(pkt);
			break;
		case AG_NPC_EVENT_ITEM:
			RecvNpcEventItem(pkt);
			break;
		case AG_NPC_GATE_OPEN:
			RecvGateOpen(pkt);
			break;
		case AG_COMPRESSED:
			RecvCompressed(pkt);
			break;
	}

	return true;
}
示例#6
0
void KOSocket::OnRead()
{
    Packet pkt;

    for (;;)
    {
        if (m_remaining == 0)
        {
            if (GetReadBuffer().GetSize() < 5)
                return; //check for opcode as well

            uint16 header = 0;
            GetReadBuffer().Read(&header, 2);
            if (header != 0x55aa)
            {
                TRACE("%s: Got packet without header 0x55AA, got 0x%X\n", GetRemoteIP().c_str(), header);
                goto error_handler;
            }

            GetReadBuffer().Read(&m_remaining, 2);
            if (m_remaining == 0)
            {
                TRACE("%s: Got packet without an opcode, this should never happen.\n", GetRemoteIP().c_str());
                goto error_handler;
            }
        }

        if (m_remaining > GetReadBuffer().GetAllocatedSize())
        {
            TRACE("%s: Packet received which was %u bytes in size, maximum of %u.\n", GetRemoteIP().c_str(), m_remaining, GetReadBuffer().GetAllocatedSize());
            goto error_handler;
        }

        if (m_remaining > GetReadBuffer().GetSize())
        {
            if (m_readTries > 4)
            {
                TRACE("%s: packet fragmentation count is over 4, disconnecting as they're probably up to something bad\n", GetRemoteIP().c_str());
                goto error_handler;
            }
            m_readTries++;
            return;
        }

        uint8 *in_stream = new uint8[m_remaining];

        m_readTries = 0;
        GetReadBuffer().Read(in_stream, m_remaining);

        uint16 footer = 0;
        GetReadBuffer().Read(&footer, 2);

        if (footer != 0xaa55
                || !DecryptPacket(in_stream, pkt))
        {
            TRACE("%s: Footer invalid (%X) or failed to decrypt.\n", GetRemoteIP().c_str(), footer);
            delete [] in_stream;
            goto error_handler;
        }

        delete [] in_stream;

        if (!HandlePacket(pkt))
        {

            TRACE("%s: Handler for packet %X returned false\n", GetRemoteIP().c_str(), pkt.GetOpcode());
#ifndef _DEBUG
            goto error_handler;
#endif
        }

        m_remaining = 0;
    }

    return;

error_handler:
    GetReadBuffer().Remove(GetReadBuffer().GetSize());
    Disconnect();
}
示例#7
0
void CUser::MagicSystem( Packet & pkt )
{
    uint8 command, subcommand;
    uint32 magicid;
    time_t skill_received_time;
    uint16 sid, tid, data1, data2, data3, data4, data5, data6, data7;
    CUser *pUser, *pTargetUser = NULL;
    CNpc *pMon = NULL;

    skill_received_time = GetTickCount(); //Retrieve the time at which the Magic packet is going for internal processing.

    command = pkt.GetOpcode();
    pkt >> subcommand >> magicid >> sid >> tid;

    if( sid < 0 || tid < 0 || tid > INVALID_BAND || sid != (uint16)GetSocketID()) //Return if there's an invalid source or target received.
        return;

    if( sid < MAX_USER )
    {
        if (isDead())
            return;
    }

    if(tid >= NPC_BAND)
    {
        pMon = m_pMain->m_arNpcArray.GetData(tid);
        if( !pMon || pMon->m_NpcState == NPC_DEAD )
            return;
    }
    else if( tid < MAX_USER )
    {
        pTargetUser = m_pMain->GetUserPtr(tid);
        if ( !pTargetUser )
            return;
    }

    /*
    Do ALL required pre-liminary checks here, will wrap that into another function, until then leaving this disabled.
    */
    //if(!CheckSkillCooldown(magicid, skill_received_time)) //Check if the skill is off-cooldown.
    //	return;

    //LogSkillCooldown(magicid, skill_received_time); Use this <if> the skill is successfully casted!

    pkt >> data1 >> data2 >> data3 >> data4 >> data5 >> data6 >> data7;

    switch(command)
    {
    case MAGIC_CASTING:
        break;
    case MAGIC_FLYING:
        break;
    case MAGIC_EFFECTING:
        break;
    case MAGIC_FAIL:
        goto echo;
        break;
    case MAGIC_TYPE3_END: //This is also MAGIC_TYPE4_END
        break;
    case MAGIC_CANCEL:
        break;
    case MAGIC_CANCEL2:
        break;
    }

echo :
    Packet result(WIZ_MAGIC_PROCESS);
    result << subcommand << magicid << sid << tid << data1 << data2 << data3 << data4 << data5 << data6 << data7;

    if (sid < MAX_USER)
    {
        m_pMain->Send_Region( &result, pUser->GetMap(), pUser->m_RegionX, pUser->m_RegionZ );
    }
    else if ( sid >= NPC_BAND)
    {
        m_pMain->Send_Region( &result, pMon->GetMap(), pMon->m_sRegion_X, pMon->m_sRegion_Z );
    }
}