void WorldSocket::AsyncWrite(WorldPacket const& packet) { if (sPacketLog->CanLogPacket()) sPacketLog->LogPacket(packet, SERVER_TO_CLIENT); TC_LOG_TRACE("network.opcode", "S->C: %s %s", (_worldSession ? _worldSession->GetPlayerInfo() : GetRemoteIpAddress()).c_str(), GetOpcodeNameForLogging(packet.GetOpcode()).c_str()); ServerPktHeader header(packet.size() + 2, packet.GetOpcode()); std::vector<uint8> data(header.getHeaderLength() + packet.size()); std::memcpy(data.data(), header.header, header.getHeaderLength()); if (!packet.empty()) std::memcpy(&data[header.getHeaderLength()], packet.contents(), packet.size()); std::lock_guard<std::mutex> guard(_writeLock); bool needsWriteStart = _writeQueue.empty(); _authCrypt.EncryptSend(data.data(), header.getHeaderLength()); _writeQueue.push(std::move(data)); if (needsWriteStart) AsyncWrite(_writeQueue.front()); }
void WorldSession::HandleClearTradeItem(WorldPacket & recv_data) { CHECK_PACKET_SIZE(recv_data, 1); if(_player->mTradeTarget == 0) return; uint8 TradeSlot = recv_data.contents()[0]; if(TradeSlot > 6) return; // clean status Player * plr = _player->GetTradeTarget(); if ( !plr ) return; uint32 TradeStatus = TRADE_STATUS_STATE_CHANGED; #ifdef USING_BIG_ENDIAN swap32(&TradeStatus); OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus); plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus); swap32(&TradeStatus); #else OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus); plr->m_session->OutPacket(SMSG_TRADE_STATUS, 4, &TradeStatus); #endif plr->mTradeStatus = TradeStatus; _player->mTradeStatus = TradeStatus; _player->mTradeItems[TradeSlot] = 0; _player->SendTradeUpdate(); }
void WorldSocket::SendPacket(const WorldPacket& pct, bool immediate) { if (IsClosed()) return; // Dump outgoing packet. //sLog.outWorldPacketDump(uint32(get_handle()), pct.GetOpcode(), pct.GetOpcodeName(), &pct, false); ServerPktHeader header; header.cmd = pct.GetOpcode(); EndianConvert(header.cmd); header.size = static_cast<uint16>(pct.size() + 2); EndianConvertReverse(header.size); m_crypt.EncryptSend(reinterpret_cast<uint8 *>(&header), sizeof(header)); Write(reinterpret_cast<const char *>(&header), sizeof(header)); if (!!pct.size()) Write(reinterpret_cast<const char *>(pct.contents()), pct.size()); if (immediate) ForceFlushOut(); }
int WorldSocket::iSendPacket (const WorldPacket& pct) { if (m_OutBuffer->space () < pct.size () + sizeof (ServerPktHeader)) { errno = ENOBUFS; return -1; } ServerPktHeader header; header.cmd = pct.GetOpcode (); EndianConvert(header.cmd); header.size = (uint16) pct.size () + 2; EndianConvertReverse(header.size); m_Crypt.EncryptSend ((uint8*) & header, sizeof (header)); if (m_OutBuffer->copy ((char*) & header, sizeof (header)) == -1) ACE_ASSERT (false); if (!pct.empty ()) if (m_OutBuffer->copy ((char*) pct.contents (), pct.size ()) == -1) ACE_ASSERT (false); return 0; }
void VoiceChatClientSocket::OnRead() { WorldPacket *data; // uint16 op // uint16 size // <data> for(;;) { // no more data if( GetReadBufferSize() < 4 ) break; Read(2, (uint8*)&op); Read(2, (uint8*)&remaining); if( GetReadBufferSize() < remaining ) break; data = new WorldPacket(op, remaining); data->resize(remaining); Read(remaining, (uint8*)data->contents()); // handle the packet sVoiceChatHandler.OnRead(data); delete data; remaining = op = 0; } }
uint32 WorldSocket::CompressPacket(uint8* buffer, WorldPacket const& packet) { uint32 opcode = packet.GetOpcode(); uint32 bufferSize = deflateBound(_compressionStream, packet.size() + sizeof(opcode)); _compressionStream->next_out = buffer; _compressionStream->avail_out = bufferSize; _compressionStream->next_in = (Bytef*)&opcode; _compressionStream->avail_in = sizeof(uint32); int32 z_res = deflate(_compressionStream, Z_BLOCK); if (z_res != Z_OK) { TC_LOG_ERROR("network", "Can't compress packet opcode (zlib: deflate) Error code: %i (%s, msg: %s)", z_res, zError(z_res), _compressionStream->msg); return 0; } _compressionStream->next_in = (Bytef*)packet.contents(); _compressionStream->avail_in = packet.size(); z_res = deflate(_compressionStream, Z_SYNC_FLUSH); if (z_res != Z_OK) { TC_LOG_ERROR("network", "Can't compress packet data (zlib: deflate) Error code: %i (%s, msg: %s)", z_res, zError(z_res), _compressionStream->msg); return 0; } return bufferSize - _compressionStream->avail_out; }
bool WorldSocket::SendPacket(const WorldPacket& pct) { if (IsClosed()) return false; // Dump outgoing packet. sLog.outWorldPacketDump(native_handle(), pct.GetOpcode(), pct.GetOpcodeName(), &pct, false); ServerPktHeader header(pct.size() + 2, pct.GetOpcode()); crypt_.EncryptSend((uint8*) header.header, header.getHeaderLength()); GuardType Guard(out_buffer_lock_); if (out_buffer_->space() >= pct.size() + header.getHeaderLength()) { // Put the packet on the buffer. if (!out_buffer_->Write(header.header, header.getHeaderLength())) MANGOS_ASSERT(false); if (!pct.empty() && !out_buffer_->Write(pct.contents(), pct.size())) MANGOS_ASSERT(false); } else { // Enqueue the packet. throw std::exception("network write buffer is too small to accommodate packet"); } StartAsyncSend(); return true; }
void PacketLog::LogPacket(WorldPacket const& packet, Direction direction, boost::asio::ip::address const& addr, uint16 port) { std::lock_guard<std::mutex> lock(_logPacketLock); PacketHeader header; *reinterpret_cast<uint32*>(header.Direction) = direction == CLIENT_TO_SERVER ? 0x47534d43 : 0x47534d53; header.ConnectionId = 0; header.ArrivalTicks = getMSTime(); header.OptionalDataSize = sizeof(header.OptionalData); memset(header.OptionalData.SocketIPBytes, 0, sizeof(header.OptionalData.SocketIPBytes)); if (addr.is_v4()) { auto bytes = addr.to_v4().to_bytes(); memcpy(header.OptionalData.SocketIPBytes, bytes.data(), bytes.size()); } else if (addr.is_v6()) { auto bytes = addr.to_v6().to_bytes(); memcpy(header.OptionalData.SocketIPBytes, bytes.data(), bytes.size()); } header.OptionalData.SocketPort = port; header.Length = packet.size() + sizeof(header.Opcode); header.Opcode = packet.GetOpcode(); fwrite(&header, sizeof(header), 1, _file); if (!packet.empty()) fwrite(packet.contents(), 1, packet.size(), _file); fflush(_file); }
void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData) { // Don't accept tickets if the ticket queue is disabled. (Ticket UI is greyed out but not fully dependable) if (sTicketMgr->GetStatus() == GMTICKET_QUEUE_STATUS_DISABLED) return; if (GetPlayer()->getLevel() < sWorld->getIntConfig(CONFIG_TICKET_LEVEL_REQ)) { SendNotification(GetTrinityString(LANG_TICKET_REQ), sWorld->getIntConfig(CONFIG_TICKET_LEVEL_REQ)); return; } GMTicketResponse response = GMTICKET_RESPONSE_CREATE_ERROR; GmTicket* ticket = sTicketMgr->GetTicketByPlayer(GetPlayer()->GetGUID()); if (ticket && ticket->IsCompleted()) sTicketMgr->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID()); // Player must not have ticket if (!ticket || ticket->IsClosed()) { uint32 mapId; float x, y, z; std::string message; uint32 needResponse; bool needMoreHelp; uint32 count; std::list<uint32> times; uint32 decompressedSize; std::string chatLog; recvData >> mapId; recvData >> x >> y >> z; recvData >> message; recvData >> needResponse; recvData >> needMoreHelp; recvData >> count; for (uint32 i = 0; i < count; i++) { uint32 time; recvData >> time; times.push_back(time); } recvData >> decompressedSize; if (count && decompressedSize && decompressedSize < 0xFFFF) { uint32 pos = recvData.rpos(); ByteBuffer dest; dest.resize(decompressedSize); uLongf realSize = decompressedSize; if (uncompress(dest.contents(), &realSize, recvData.contents() + pos, recvData.size() - pos) == Z_OK) { dest >> chatLog; }
void WorldSocket::HandleAuthSession(WorldPacket& recvPacket) { std::shared_ptr<AuthSession> authSession = std::make_shared<AuthSession>(); // Read the content of the packet recvPacket >> authSession->Build; recvPacket >> authSession->LoginServerID; recvPacket >> authSession->Account; recvPacket >> authSession->LoginServerType; recvPacket >> authSession->LocalChallenge; recvPacket >> authSession->RegionID; recvPacket >> authSession->BattlegroupID; recvPacket >> authSession->RealmID; // realmId from auth_database.realmlist table recvPacket >> authSession->DosResponse; recvPacket.read(authSession->Digest, 20); authSession->AddonInfo.append(recvPacket.contents() + recvPacket.rpos(), recvPacket.size() - recvPacket.rpos()); // Get the account information from the auth database PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME); stmt->setInt32(0, int32(realm.Id.Realm)); stmt->setString(1, authSession->Account); _queryCallback = std::bind(&WorldSocket::HandleAuthSessionCallback, this, authSession, std::placeholders::_1); _queryFuture = LoginDatabase.AsyncQuery(stmt); }
void WorldSession::HandleWardenDataOpcode(WorldPacket& recv_data) { m_Warden->DecryptData(const_cast<uint8*>(recv_data.contents()), recv_data.size()); uint8 Opcode; recv_data >> Opcode; sLog.outDebug("WARDEN: Got packet, opcode %02X, size %u", Opcode, recv_data.size()); recv_data.hexlike(); switch (Opcode) { case WARDEN_CMSG_MODULE_MISSING: m_Warden->SendModuleToClient(); break; case WARDEN_CMSG_MODULE_OK: m_Warden->RequestHash(); break; case WARDEN_CMSG_CHEAT_CHECKS_RESULT: m_Warden->HandleData(recv_data); break; case WARDEN_CMSG_MEM_CHECKS_RESULT: sLog.outDebug("WARDEN: NYI WARDEN_CMSG_MEM_CHECKS_RESULT received!"); break; case WARDEN_CMSG_HASH_RESULT: m_Warden->HandleHashResult(recv_data); m_Warden->InitializeModule(); break; case WARDEN_CMSG_MODULE_FAILED: sLog.outDebug("WARDEN: NYI WARDEN_CMSG_MODULE_FAILED received!"); break; default: sLog.outError("Got unknown warden opcode %02X of size %u.", Opcode, recv_data.size() - 1); break; } }
WorldPacket * Mailbox::BuildMailboxListingPacket() { WorldPacket * data = new WorldPacket(SMSG_MAIL_LIST_RESULT, 500); MessageMap::iterator itr; uint32 count = 0; uint32 t = (uint32)UNIXTIME; *data << uint8(0); // size placeholder for(itr = Messages.begin(); itr != Messages.end(); ++itr) { if(itr->second.expire_time && t > itr->second.expire_time) continue; // expired mail -> skip it if((uint32)UNIXTIME < itr->second.delivery_time) continue; // undelivered if(itr->second.AddMessageDataToPacket(*data)) ++count; if(count == 50) break; } const_cast<uint8*>(data->contents())[0] = count; // do cleanup on request mail CleanupExpiredMessages(); return data; }
void WorldSession::HandleWardenDataOpcode(WorldPacket& recvData) { _warden->DecryptData(const_cast<uint8*>(recvData.contents()), recvData.size()); uint8 opcode; recvData >> opcode; sLog->outDebug(LOG_FILTER_WARDEN, "Got packet, opcode %02X, size %u", opcode, uint32(recvData.size())); recvData.hexlike(); switch (opcode) { case WARDEN_CMSG_MODULE_MISSING: _warden->SendModuleToClient(); break; case WARDEN_CMSG_MODULE_OK: _warden->RequestHash(); break; case WARDEN_CMSG_CHEAT_CHECKS_RESULT: _warden->HandleData(recvData); break; case WARDEN_CMSG_MEM_CHECKS_RESULT: sLog->outDebug(LOG_FILTER_WARDEN, "NYI WARDEN_CMSG_MEM_CHECKS_RESULT received!"); break; case WARDEN_CMSG_HASH_RESULT: _warden->HandleHashResult(recvData); _warden->InitializeModule(); break; case WARDEN_CMSG_MODULE_FAILED: sLog->outDebug(LOG_FILTER_WARDEN, "NYI WARDEN_CMSG_MODULE_FAILED received!"); break; default: sLog->outDebug(LOG_FILTER_WARDEN, "Got unknown warden opcode %02X of size %u.", opcode, uint32(recvData.size() - 1)); break; } }
void WorldSession::HandleClearTradeItem(WorldPacket & recv_data) { CHECK_PACKET_SIZE(recv_data, 1); if(_player->mTradeTarget == 0) { return; } uint8 TradeSlot = recv_data.contents()[0]; if( TradeSlot >= TRADE_TOTAL_TRADE_SLOTS ) { return; } // clean status Player * plr = _player->GetTradeTarget(); if ( !plr ) { return; } // packetSMSG_TRADE_STATUS data; // memset( &data, 0, sizeof( data ) ); // data.trade_status = TRADE_STATUS_STATE_CHANGED; // OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data); // plr->m_session->OutPacket(SMSG_TRADE_STATUS,sizeof( packetSMSG_TRADE_STATUS ), &data); plr->mTradeStatus = TRADE_STATUS_STATE_CHANGED; _player->mTradeStatus = TRADE_STATUS_STATE_CHANGED; _player->mTradeItems[TradeSlot] = 0; _player->SendTradeUpdate(); }
void ClusterInterface::HandlePackedPlayerInfo(WorldPacket & pck) { uint32 real_size; pck >> real_size; uLongf rsize = real_size; ByteBuffer buf(real_size); buf.resize(real_size); if(uncompress((uint8*)buf.contents(), &rsize, pck.contents() + 4, (u_long)pck.size() - 4) != Z_OK) { printf("Uncompress of player info failed.\n"); return; } RPlayerInfo * pi; uint32 count; buf >> count; for(uint32 i = 0; i < count; ++i) { pi = new RPlayerInfo; pi->Unpack(buf); _onlinePlayers[pi->Guid] = pi; } }
void WorldSession::HandleSetTradeItem(WorldPacket & recv_data) { if(!_player->IsInWorld() || _player->mTradeTarget == 0) return; CHECK_PACKET_SIZE(recv_data, 3); uint8 TradeSlot = recv_data.contents()[0]; int8 SourceBag = recv_data.contents()[1]; uint8 SourceSlot = recv_data.contents()[2]; Player* pTarget = _player->GetTradeTarget(); if(pTarget == NULL || !pTarget->IsInWorld() || TradeSlot > 6) return; Item* pItem = _player->GetItemInterface()->GetInventoryItem(SourceBag, SourceSlot); if( pItem == NULL ) return; if(pItem->IsContainer()) { if( pItem->IsContainer() && TO_CONTAINER(pItem)->HasItems() ) { _player->GetItemInterface()->BuildInventoryChangeError( pItem, NULLITEM, INV_ERR_CANT_TRADE_EQUIP_BAGS); return; } } for(uint32 i = 0; i < 7; i++) { // duping little shits if(_player->mTradeItems[i] == pItem || pTarget->mTradeItems[i] == pItem) { sWorld.LogCheater(this, "tried to dupe an item through trade"); Disconnect(); uint8 TradeStatus = TRADE_STATUS_CANCELLED; if( pTarget->m_session && pTarget->m_session->GetSocket()) pTarget->m_session->SendTradeStatus(TradeStatus); return; } } _player->mTradeItems[TradeSlot] = pItem; _player->SendTradeUpdate(); }
int PoolSocket::SendPacket (const WorldPacket& pct) { ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1); if (closing_) return -1; // Dump outgoing packet. if (sPacketLog->CanLogPacket()) sPacketLog->LogPacket(pct, SERVER_TO_CLIENT); Flexi::ServerPktHeader header(pct.size()+2, pct.GetOpcode()); m_Crypt.EncryptSend ((uint8*)header.header, header.getHeaderLength()); if (m_OutBuffer->space() >= pct.size()+ header.getHeaderLength() && msg_queue()->is_empty()) { // Put the packet on the buffer. if (m_OutBuffer->copy((char*) header.header, header.getHeaderLength()) == -1) ACE_ASSERT (false); if (!pct.empty()) if (m_OutBuffer->copy((char*) pct.contents(), pct.size()) == -1) ACE_ASSERT (false); } else { // Enqueue the packet. ACE_Message_Block* mb; ACE_NEW_RETURN(mb, ACE_Message_Block(pct.size() + header.getHeaderLength()), -1); mb->copy((char*) header.header, header.getHeaderLength()); if (!pct.empty()) mb->copy((const char*)pct.contents(), pct.size()); if (msg_queue()->enqueue_tail(mb,(ACE_Time_Value*)&ACE_Time_Value::zero) == -1) { sLog->outError("NodeSocket::SendPacket enqueue_tail failed"); mb->release(); return -1; } } return 0; }
void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData) { // Don't accept tickets if the ticket queue is disabled. (Ticket UI is greyed out but not fully dependable) if (sTicketMgr->GetStatus() == GMTICKET_QUEUE_STATUS_DISABLED) return; if(!GetPlayer()->CanSpeak()) { std::string timeStr = secsToTimeString(m_muteTime - time(NULL)); SendNotification(GetTrinityString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str()); return; } if (GetPlayer()->getLevel() < sWorld->getIntConfig(CONFIG_TICKET_LEVEL_REQ)) { SendNotification(GetTrinityString(LANG_TICKET_REQ), sWorld->getIntConfig(CONFIG_TICKET_LEVEL_REQ)); return; } GMTicketResponse response = GMTICKET_RESPONSE_CREATE_ERROR; GmTicket* ticket = sTicketMgr->GetTicketByPlayer(GetPlayer()->GetGUID()); if (ticket && ticket->IsCompleted()) sTicketMgr->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID());; // Player must not have ticket if (!ticket || ticket->IsClosed()) { ticket = new GmTicket(GetPlayer(), recvData); uint32 count; std::list<uint32> times; uint32 decompressedSize; std::string chatLog; recvData >> count; for (uint32 i = 0; i < count; i++) { uint32 time; recvData >> time; times.push_back(time); } recvData >> decompressedSize; if (count && decompressedSize && decompressedSize < 0xFFFF) { uint32 pos = recvData.rpos(); ByteBuffer dest; dest.resize(decompressedSize); uLongf realSize = decompressedSize; if (uncompress(dest.contents(), &realSize, recvData.contents() + pos, recvData.size() - pos) == Z_OK) { dest >> chatLog; ticket->SetChatLog(times, chatLog); }
void WorldSession::HandleSetTradeItem(WorldPacket & recv_data) { if(_player->mTradeTarget == 0) return; CHECK_PACKET_SIZE(recv_data, 3); uint8 TradeSlot = recv_data.contents()[0]; uint8 SourceBag = recv_data.contents()[1]; uint8 SourceSlot = recv_data.contents()[2]; Item * pItem = _player->GetItemInterface()->GetInventoryItem(SourceBag, SourceSlot); if(pItem == 0 || TradeSlot > 6) return; _player->mTradeItems[TradeSlot] = pItem; _player->SendTradeUpdate(); }
void ClusterInterface::HandleWoWPacket(WorldPacket & pck) { uint32 size, sid; uint16 opcode; pck >> sid >> opcode >> size; if(!_sessions[sid]) { Log.Error("HandleWoWPacket", "Invalid session: %u", sid); return; } DEBUG_LOG("HandleWoWPacket", "Forwarding %s to client", LookupName(opcode, g_worldOpcodeNames)); WorldPacket * npck = new WorldPacket(opcode, size); npck->resize(size); memcpy((void*)npck->contents(), pck.contents()+10, size); _sessions[sid]->QueuePacket(npck); }
void WorldSession::HandleGMTicketCreateOpcode( WorldPacket & recv_data ) { WorldPacket data; uint32 guid; guid = GetPlayer()->GetGUIDLow(); std::string ticketText = ""; Field *fields; uint8 buf[516]; uint32 cat[] = { 0,5,1,2,0,6,4,7,0,8,3 }; memcpy( buf, recv_data.contents(), sizeof buf < recv_data.size() ? sizeof buf : recv_data.size() ); buf[272] = 0; ticketText = (char *)buf + 17; sDatabase.escape_string(ticketText); QueryResult *result = sDatabase.PQuery("SELECT COUNT(*) FROM `character_ticket` WHERE `guid` = '%u'",guid); if (result) { int cnt; fields = result->Fetch(); cnt = fields[0].GetUInt32(); delete result; if ( cnt > 0 ) { data.Initialize( SMSG_GMTICKET_CREATE, 4 ); data << uint32(1); SendPacket( &data ); } else { sDatabase.PExecute("INSERT INTO `character_ticket` (`guid`,`ticket_text`,`ticket_category`) VALUES ('%u', '%s', '%u')", guid, ticketText.c_str(), cat[buf[0]]); data.Initialize( SMSG_QUERY_TIME_RESPONSE, 4 ); //data << (uint32)20; data << (uint32)getMSTime(); SendPacket( &data ); data.Initialize( SMSG_GMTICKET_CREATE, 4 ); data << uint32(2); SendPacket( &data ); DEBUG_LOG("update the ticket\n"); ObjectAccessor::PlayersMapType &m = ObjectAccessor::Instance().GetPlayers(); for(ObjectAccessor::PlayersMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if(itr->second->GetSession()->GetSecurity() >= 2 && itr->second->isAcceptTickets()) ChatHandler::PSendSysMessage(itr->second->GetSession(),"New ticket from %s",GetPlayer()->GetName()); } } } }
void WorldSession::HandleGMTicketUpdateTextOpcode( WorldPacket & recv_data ) { WorldPacket data; uint32 guid = GetPlayer()->GetGUIDLow(); std::string ticketText = ""; uint8 buf[516]; memcpy( buf, recv_data.contents(), sizeof buf <recv_data.size() ? sizeof buf : recv_data.size() ); ticketText = (char *)buf + 1; sDatabase.escape_string(ticketText); sDatabase.PExecute("UPDATE `character_ticket` SET `ticket_text` = '%s' WHERE `guid` = '%u'", ticketText.c_str(), guid); }
void WorldSession::HandleClearTradeItem(WorldPacket & recv_data) { CHECK_PACKET_SIZE(recv_data, 1); if(!_player->IsInWorld() || _player->mTradeTarget == 0) return; uint8 TradeSlot = recv_data.contents()[0]; if(TradeSlot > 6) return; _player->mTradeItems[TradeSlot] = NULLITEM; _player->SendTradeUpdate(); }
void WorldSession::HandleSetTradeGold(WorldPacket & recv_data) { if(_player->mTradeTarget == 0) return; uint32 Gold = *(uint32*)recv_data.contents(); if(_player->mTradeGold != Gold) { _player->mTradeGold = (Gold > _player->GetUInt32Value(PLAYER_FIELD_COINAGE) ? _player->GetUInt32Value(PLAYER_FIELD_COINAGE) : Gold); _player->SendTradeUpdate(); } }
void Mailbox::FillTimePacket(WorldPacket& data) { uint32 c = 0; MessageMap::iterator iter = Messages.begin(); data << uint32(0) << uint32(0); for(; iter != Messages.end(); ++iter) { if(iter->second.deleted_flag == 0 && iter->second.read_flag == 0 && (uint32)UNIXTIME >= iter->second.delivery_time) { // unread message, w00t. ++c; data << uint64(iter->second.sender_guid); data << uint32(0); data << uint32(0);// money or smth? data << uint32(iter->second.stationary); //data << float(UNIXTIME-iter->second.delivery_time); data << float(-9.0f); // maybe the above? } } if(c==0) { #ifdef USING_BIG_ENDIAN *(uint32*)(&data.contents()[0])=swap32(0xc7a8c000); #else *(uint32*)(&data.contents()[0])=0xc7a8c000; #endif } else { #ifdef USING_BIG_ENDIAN *(uint32*)(&data.contents()[4])=swap32(c); #else *(uint32*)(&data.contents()[4])=c; #endif } }
void WServer::HandleWoWPacket(WorldPacket & pck) { uint32 sessionid, size; uint16 opcode; /* get session */ pck >> sessionid >> opcode >> size; Session * session = sClientMgr.GetSession(sessionid); if(!session) return; /* write it to that session's output buffer */ WorldSocket * s = session->GetSocket(); if(s) s->OutPacket(opcode, size, size ? ((const void*)(pck.contents() + 10)) : 0); }
void WorldSocket::SendPacket(WorldPacket& packet) { if (!IsOpen()) return; if (sPacketLog->CanLogPacket()) sPacketLog->LogPacket(packet, SERVER_TO_CLIENT, GetRemoteIpAddress(), GetRemotePort()); if (_worldSession && packet.size() > 0x400 && !packet.IsCompressed()) packet.Compress(_worldSession->GetCompressionStream()); TC_LOG_TRACE("network.opcode", "S->C: %s %s", (_worldSession ? _worldSession->GetPlayerInfo() : GetRemoteIpAddress().to_string()).c_str(), GetOpcodeNameForLogging(packet.GetOpcode()).c_str()); ServerPktHeader header(packet.size() + 2, packet.GetOpcode()); std::unique_lock<std::mutex> guard(_writeLock); _authCrypt.EncryptSend(header.header, header.getHeaderLength()); #ifndef TC_SOCKET_USE_IOCP if (_writeQueue.empty() && _writeBuffer.GetRemainingSpace() >= header.getHeaderLength() + packet.size()) { _writeBuffer.Write(header.header, header.getHeaderLength()); if (!packet.empty()) _writeBuffer.Write(packet.contents(), packet.size()); } else #endif { MessageBuffer buffer(header.getHeaderLength() + packet.size()); buffer.Write(header.header, header.getHeaderLength()); if (!packet.empty()) buffer.Write(packet.contents(), packet.size()); QueuePacket(std::move(buffer), guard); } }
void WorldSession::HandleGMTicketUpdateTextOpcode( WorldPacket & recv_data ) { WorldPacket data; uint64 guid = GetPlayer()->GetGUID(); std::string ticketText = ""; char * p, p1[512]; uint8 buf[516]; memcpy( buf, recv_data.contents(), sizeof buf <recv_data.size() ? sizeof buf : recv_data.size() ); p = (char *)buf + 1; my_esc( p1, (const char *)buf + 1 ); std::stringstream ss; ticketText = p1; ss << "UPDATE `gmtickets` set ticket_text = '" << ticketText << "' WHERE guid = '" << guid << "'"; sDatabase.Execute( ss.str( ).c_str( ) ); }
void ClusterInterface::HandleCreatePlayer(WorldPacket & pck) { uint32 accountid, size; uint16 opcode; pck >> accountid >> opcode >> size; if (_sessions[accountid] != NULL) return; WorldSession* s=new WorldSession(accountid, "", NULL); //construct the cmsg_char_create WorldPacket data(opcode, size); data.resize(size); memcpy((void*)data.contents(), pck.contents() + 10, size); Player * pNewChar = objmgr.CreatePlayer(); pNewChar->SetSession(s); if(!pNewChar->Create( data )) { // failed. pNewChar->ok_to_remove = true; delete pNewChar; return; } pNewChar->UnSetBanned(); pNewChar->addSpell(22027); // Remove Insignia if(pNewChar->getClass() == WARLOCK) { pNewChar->AddSummonSpell(416, 3110); // imp fireball pNewChar->AddSummonSpell(417, 19505); pNewChar->AddSummonSpell(1860, 3716); pNewChar->AddSummonSpell(1863, 7814); } pNewChar->SaveToDB(true); pNewChar->ok_to_remove = true; delete pNewChar; delete s; //now lets send the info back, send accountid, we have no sessionid WorldPacket result(ICMSG_CREATE_PLAYER, 5); data << accountid << uint8(0x2F); //CHAR_CREATE_SUCCESS SendPacket(&result); }
bool UpdateData::buildPacket(WorldPacket& packet, bool hasTransport) { ByteBuffer buf(m_data.size() + 10 + m_guidList.size() * 8); buf << (u_int)(!m_guidList.empty() ? m_blockCount + 1 : m_blockCount); buf << (u_char)(hasTransport ? 1 : 0); if (!m_guidList.empty()) { buf << (u_char)UPDATETYPE_OUT_OF_RANGE_OBJECTS; buf << (u_int)m_guidList.size(); for (IDList::const_iterator itr = m_guidList.begin(); itr != m_guidList.end(); ++itr) { buf << (u_char)0xFF; buf << (u_int64)*itr; } } buf.append(m_data); packet.clear(); // 大小超过50字节的数据包要压缩 if (m_data.size() > 50) { u_int destSize = (u_int)buf.size() + buf.size() / 10 + 16; packet.resize(destSize); packet.put(0, (u_int)buf.size()); compress(const_cast<u_char*>(packet.contents()) + sizeof(u_int), &destSize, (void*)buf.contents(), (u_int)buf.size()); if (destSize == 0) return false; packet.resize(destSize + sizeof(u_int)); packet.setOpcode(SMSG_COMPRESSED_UPDATE_OBJECT); } else { packet.append(buf); packet.setOpcode(SMSG_UPDATE_OBJECT); } return true; }