void SystemStationEntity::EncodeDestiny( Buffer& into ) const { BallHeader head; head.entityID = data.itemID; head.mode = Destiny::DSTBALL_RIGID; head.radius = data.radius; head.x = data.position.x; head.y = data.position.y; head.z = data.position.z; head.sub_type = HasMiniBalls | IsGlobal; into.Append( head ); DSTBALL_RIGID_Struct main; main.formationID = 0xFF; into.Append( main ); const uint16 miniballsCount = 1; into.Append( miniballsCount ); MiniBall miniball; miniball.x = -7701.181; miniball.y = 8060.06; miniball.z = 27878.900; miniball.radius = 1639.241; into.Append( miniball ); const uint8 nameLen = utf8::distance( data.itemName.begin(), data.itemName.end() ); into.Append( nameLen ); const Buffer::iterator<uint16> name = into.end<uint16>(); into.ResizeAt( name, nameLen ); utf8::utf8to16( data.itemName.begin(), data.itemName.end(), name ); }
void SystemStationEntity::EncodeDestiny( Buffer& into ) const { BallHeader head; head.entityID = data.itemID; head.mode = Destiny::DSTBALL_RIGID; head.radius = static_cast<float>(data.radius); head.x = data.position.x; head.y = data.position.y; head.z = data.position.z; head.sub_type = HasMiniBalls | IsGlobal; into.Append( head ); DSTBALL_RIGID_Struct main; main.formationID = 0xFF; into.Append( main ); const uint16 miniballsCount = 1; into.Append( miniballsCount ); MiniBall miniball; miniball.x = -7701.181; miniball.y = 8060.06; miniball.z = 27878.900; miniball.radius = 1639.241; into.Append( miniball ); }
char* NormalizeFile(const char *file) { Assert(g_working_directory && g_base_directory); static Buffer normal_buf; normal_buf.Reset(); if (file[0] == '/') { // the supplied filename is already an absolute path, use that. normal_buf.Append(file, strlen(file) + 1); } else if (file[0] == '<') { // special compiler name, use it (we won't have the original source). normal_buf.Append(file, strlen(file) + 1); } else { // relative path from the working directory. normal_buf.Append(g_working_directory, strlen(g_working_directory)); normal_buf.Append("/", 1); normal_buf.Append(file, strlen(file) + 1); } CleanupPathDot((char*) normal_buf.base); CleanupPathDotDot((char*) normal_buf.base); // remove the base directory prefix, if possible. size_t base_len = strlen(g_base_directory); if (strncmp((char*)normal_buf.base, g_base_directory, base_len) == 0) { Assert(normal_buf.base[base_len] == '/'); return (char*) normal_buf.base + base_len + 1; } return (char*) normal_buf.base; }
bool FFInterface::SendMessage (const String& _rMessage) { size_t iLength = _rMessage.length () + sizeof (size_t) + 1; Buffer bufMsg; bufMsg.Append (&iLength, sizeof (size_t)); bufMsg.Append ((const char*)_rMessage, _rMessage.length () + 1); assert (iLength == bufMsg.Length ()); return ClientSocket::SendBlocking (bufMsg.GetData (), bufMsg.Length ()); }
bool FFInterface::SendMessage (const Buffer& _rMessage) { size_t iLength = _rMessage.Length () + sizeof (size_t); Buffer bufMsg; bufMsg.Append (&iLength, sizeof (size_t)); bufMsg.Append (_rMessage); assert (iLength == bufMsg.Length ()); return ClientSocket::SendNonBlocking (bufMsg.GetData (), bufMsg.Length ()); }
//TODO: ask the destiny manager to do this for us! void CelestialDynamicSystemEntity::EncodeDestiny( Buffer& into ) const { const GPoint& position = GetPosition(); const std::string itemName( GetName() ); // From SimpleSystemEntity::EncodeDestiny() in SystemEntities.cpp: /* BallHeader head; head.entityID = data.itemID; head.mode = Destiny::DSTBALL_RIGID; head.radius = data.radius; head.x = data.position.x; head.y = data.position.y; head.z = data.position.z; head.sub_type = IsMassive | IsGlobal; into.Append( head ); DSTBALL_RIGID_Struct main; main.formationID = 0xFF; into.Append( main ); */ BallHeader head; head.entityID = GetID(); head.mode = Destiny::DSTBALL_RIGID; head.radius = GetRadius(); head.x = position.x; head.y = position.y; head.z = position.z; head.sub_type = IsMassive | IsGlobal; into.Append( head ); /* MassSector mass; mass.mass = GetMass(); mass.cloak = 0; mass.unknown52 = 0xFFFFFFFFFFFFFFFFLL; mass.corpID = GetCorporationID(); mass.allianceID = GetAllianceID(); into.Append( mass ); */ DSTBALL_RIGID_Struct main; main.formationID = 0xFF; into.Append( main ); const uint8 nameLen = utf8::distance( itemName.begin(), itemName.end() ); into.Append( nameLen ); const Buffer::iterator<uint16> name = into.end<uint16>(); into.ResizeAt( name, nameLen ); utf8::utf8to16( itemName.begin(), itemName.end(), name ); }
void SystemBubble::_BubblecastAddBall( SystemEntity* about_who ) { if( m_dynamicEntities.empty() ) { _log( DESTINY__TRACE, "Add Ball: Nobody to receive." ); return; } Buffer* destinyBuffer = new Buffer; //create AddBalls header Destiny::AddBall_header head; head.more = 0; head.sequence = DestinyManager::GetStamp(); destinyBuffer->Append( head ); DoDestiny_AddBalls addballs; addballs.slims = new PyList; //encode destiny binary about_who->EncodeDestiny( *destinyBuffer ); addballs.destiny_binary = new PyBuffer( &destinyBuffer ); SafeDelete( destinyBuffer ); //encode damage state addballs.damages[ about_who->GetID() ] = about_who->MakeDamageState(); //encode SlimItem addballs.slims->AddItem( new PyObject( new PyString( "foo.SlimItem" ), about_who->MakeSlimItem() ) ); //bubblecast the update PyTuple* t = addballs.Encode(); BubblecastDestinyUpdate( &t, "AddBall" ); PySafeDecRef( t ); }
void SystemAsteroidBeltEntity::EncodeDestiny( Buffer& into ) const { BallHeader head; head.entityID = data.itemID; head.mode = Destiny::DSTBALL_RIGID; head.radius = static_cast<float>(data.radius); head.x = data.position.x; head.y = data.position.y; head.z = data.position.z; head.sub_type = IsGlobal; into.Append( head ); DSTBALL_RIGID_Struct main; main.formationID = 0xFF; into.Append( main ); }
bool Endpoint::Set(const char* ip_port, bool resolv) { const char* p; int port; bool ret; Buffer ipbuf; p = ip_port; if (!IsValidEndpoint(ReadBuffer(ip_port))) return false; p = strrchr(ip_port, ':'); if (p == NULL) { Log_Trace("No ':' in host specification"); return false; } ipbuf.Append(ip_port, p - ip_port); ipbuf.NullTerminate(); p++; port = -1; port = atoi(p); if (port < 1 || port > 65535) { Log_Trace("atoi() failed to produce a sensible value"); return false; } ret = Set(ipbuf.GetBuffer(), port, resolv); return ret; }
void Buffer::ToHexadecimal() { unsigned i; unsigned char x; Buffer printable; const char digits[] = "0123456789ABCDEF"; printable.Allocate(length * 3); for (i = 0; i < length; i++) { x = (unsigned char) buffer[i]; printable.Append(digits[x / 16]); printable.Append(digits[x % 16]); if (i != length - 1) printable.Append(' '); } Write(printable); }
long FFInterface::RegisterDomain (String& _rDomain) { if (true == b_UseLocalHeuristicEvaluator) return 0; SetStandalone (true); // send request ... String sRequest; sRequest << "+" << _rDomain; if (false == SendMessage (sRequest)) { cerr << "[ERROR] Request failed on RegisterDomain." << endl; SetStandalone (false); return -1; } // get response ... Buffer bufTemp; size_t iMessageSize = 0; while (true) { char zData [RECEIVE_BUFFER + 1]; long lBytes = ReceiveBlocking (zData, RECEIVE_BUFFER, 100); if (lBytes > 0) bufTemp.Append (zData, lBytes); if (false == bufTemp.ReadFromIndex (0, &iMessageSize, sizeof (size_t))) continue; if (iMessageSize > bufTemp.Length ()) continue; break; } SetStandalone (false); Buffer bufResponse = bufTemp.PopFirstMessageAsBuffer (iMessageSize); char cType = bufResponse [sizeof (size_t)]; if ('d' != cType) { cerr << "[ERROR] Bad line format in response to domain registration." << " expected 'd', got '" << cType << "'." << endl; return -1; } long lDomainId; if (false == bufResponse.ReadFromIndex (1 + sizeof (size_t), &lDomainId, sizeof (size_t))) { cerr << "[ERROR] Failed to read domain id from domain registration reponse." << endl; return -1; } return lDomainId; }
bool Endpoint::Set(ReadBuffer ip_port, bool resolv) { const char* p; const char* start; int port; bool ret; Buffer ipbuf; Buffer portbuf; if (!IsValidEndpoint(ReadBuffer(ip_port))) return false; start = p = ip_port.GetBuffer(); p = RevFindInBuffer(ip_port.GetBuffer(), ip_port.GetLength(), ':'); if (p == NULL) { Log_Trace("No ':' in host specification"); return false; } ipbuf.Append(start, p - start); ipbuf.NullTerminate(); p++; portbuf.Append(p, ip_port.GetLength() - (p - start)); portbuf.NullTerminate(); port = -1; port = atoi(portbuf.GetBuffer()); if (port < 1 || port > 65535) { Log_Trace("atoi() failed to produce a sensible value"); return false; } ret = Set(ipbuf.GetBuffer(), port, resolv); return ret; }
void SystemBubble::_SendAddBalls( SystemEntity* to_who ) { if( m_entities.empty() ) { _log( DESTINY__TRACE, "Add Balls: Nothing to send." ); return; } Buffer* destinyBuffer = new Buffer; Destiny::AddBall_header head; head.packet_type = 0; head.sequence = DestinyManager::GetStamp(); destinyBuffer->Append( head ); DoDestiny_AddBalls addballs; addballs.slims = new PyList; std::map<uint32, SystemEntity*>::const_iterator cur, end; cur = m_entities.begin(); end = m_entities.end(); for(; cur != end; ++cur) { if( cur->second->IsVisibleSystemWide() ) continue; //it is already in their destiny state //damageState addballs.damages[ cur->second->GetID() ] = cur->second->MakeDamageState(); //slim item addballs.slims->AddItem( new PyObject( "foo.SlimItem", cur->second->MakeSlimItem() ) ); //append the destiny binary data... cur->second->EncodeDestiny( *destinyBuffer ); } addballs.destiny_binary = new PyBuffer( &destinyBuffer ); SafeDelete( destinyBuffer ); _log( DESTINY__TRACE, "Add Balls:" ); addballs.Dump( DESTINY__TRACE, " " ); _log( DESTINY__TRACE, " Ball Binary:" ); _hex( DESTINY__TRACE, &( addballs.destiny_binary->content() )[0], addballs.destiny_binary->content().size() ); _log( DESTINY__TRACE, " Ball Decoded:" ); Destiny::DumpUpdate( DESTINY__TRACE, &( addballs.destiny_binary->content() )[0], addballs.destiny_binary->content().size() ); PyTuple* t = addballs.Encode(); to_who->QueueDestinyUpdate( &t ); //may consume, but may not. PySafeDecRef( t ); }
bool XdbAllKeys(Transaction *t, const Vector<TOperand*> &arguments, TOperand **result) { BACKEND_ARG_COUNT(1); BACKEND_ARG_STRING(0, db_name, db_length); XdbInfo &info = GetDatabaseInfo(db_name, false); // return an empty list if the database doesn't exist if (!info.xdb->Exists()) { *result = new TOperandList(t); return true; } TOperandList *list = new TOperandList(t); // scratch buffer for the key Buffer key; // bulk buffer for storing lots of keys. instead of continually // reallocating this, when we run out of space just make a new buffer. // the buffer will be pretty big to reduce the number of allocations // we end up going (we'll still have to do one allocation per key // for the TOperandString). Buffer *buf = NULL; for (uint32_t stream = info.xdb->MinDataStream(); stream <= info.xdb->MaxDataStream(); stream++) { // reset the scratch buffer and get the next key key.Reset(); info.xdb->LookupKey(stream, &key); size_t key_length = key.pos - key.base; if (!ValidString(key.base, key_length)) { logout << "ERROR: Database contains a key that is not NULL-terminated." << endl; return false; } if (buf == NULL || !buf->HasRemaining(key_length)) { buf = new Buffer(4096 * 16 + key_length); t->AddBuffer(buf); } list->PushOperand(new TOperandString(t, buf->pos, key_length)); buf->Append(key.base, key_length); } *result = list; return true; }
void StorageBloomPage::Write(Buffer& buffer) { uint32_t checksum; buffer.Allocate(size); buffer.Zero(); checksum = bloomFilter.GetBuffer().GetChecksum(); buffer.AppendLittle32(size); buffer.AppendLittle32(checksum); buffer.Append(bloomFilter.GetBuffer()); }
void SystemPlanetEntity::EncodeDestiny( Buffer& into ) const { BallHeader head; head.entityID = data.itemID; head.mode = Destiny::DSTBALL_RIGID; head.radius = data.radius; head.x = data.position.x; head.y = data.position.y; head.z = data.position.z; head.sub_type = IsMassive | IsGlobal; into.Append( head ); DSTBALL_RIGID_Struct main; main.formationID = 0xFF; into.Append( main ); const uint8 nameLen = utf8::distance( data.itemName.begin(), data.itemName.end() ); into.Append( nameLen ); const Buffer::iterator<uint16> name = into.end<uint16>(); into.ResizeAt( name, nameLen ); utf8::utf8to16( data.itemName.begin(), data.itemName.end(), name ); }
void SystemDungeonEntranceEntity::EncodeDestiny( Buffer& into ) const { const Vector3D& position = m_self->position(); const std::string itemName( GetName() ); BallHeader head; head.entityID = m_self->itemID(); head.mode = Destiny::DSTBALL_STOP; head.radius = GetRadius(); head.x = position.x; head.y = position.y; head.z = position.z; head.sub_type = HasMiniBalls; // I dono if this is correct... we'll see into.Append( head ); MassSector mass; mass.mass = 10000000000.00; mass.cloak = 0; mass.Harmonic = -1.0f; mass.corpID = m_self->ownerID(); //a little hacky... mass.allianceID = 0xFFFFFFFF; into.Append( mass ); DSTBALL_STOP_Struct main; main.formationID = 0xFF; into.Append( main ); const uint16 miniballCount = 1; into.Append( miniballCount ); MiniBall miniball; miniball.x = -7701.181; miniball.y = 8060.06; miniball.z = 27878.900; miniball.radius = 1639.241; into.Append( miniball ); }
int Socket::Read(Buffer& buffer) { int rbytes = 0; int r_ret = 0; char t_rbuf[READFRAME] = {0}; do { r_ret = read(fd_, t_rbuf,READFRAME); if (r_ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { r_ret = kReturnok; break; } else if (r_ret < 0) { return kReturnSysErr; } else if (r_ret == 0) { return kReturnCloseFd; } rbytes += r_ret; } while(1); buffer.Append(t_rbuf, rbytes); return r_ret; }
bool FFInterface::SendTask (size_t _iId, size_t _iDomain, String& _rProblem, size_t _iTimelimit) { if (NULL == p_Callback) { cerr << " [EE] Callback not set for FFInterface. Will not be able to relay FF responses back. Not sending task to FF." << endl; return false; } pthread_mutex_lock (&mtx_TaskList); pair <TaskIdToFFResponse_hmp_t::iterator, bool> pairInsert; FFResponse* pResponse = new FFResponse; pairInsert = hmp_TaskIdToFFResponse.insert (make_pair (_iId, pResponse)); _rProblem.Strip (); pResponse->i_Domain = _iDomain; pResponse->s_Problem = _rProblem; pthread_mutex_unlock (&mtx_TaskList); if (true == b_UseLocalHeuristicEvaluator) return true; // send request to cache... CompressedBuffer bufProblem (_rProblem); size_t iCompressedSize = bufProblem.CompressedSize (); size_t iUncompressedSize = bufProblem.UncompressedSize (); Buffer bufRequest; bufRequest.Append ("?", 1); bufRequest.Append (&_iId, sizeof (size_t)); bufRequest.Append (&_iTimelimit, sizeof (size_t)); bufRequest.Append (&_iDomain, sizeof (size_t)); bufRequest.Append (&iCompressedSize, sizeof (size_t)); bufRequest.Append (&iUncompressedSize, sizeof (size_t)); bufRequest.Append (bufProblem); if (false == SendMessage (bufRequest)) return false; return true; }
void StorageArchiveLogSegmentJob::EvalScriptVariables() { Buffer var; const char* p; bool inVar; p = script; inVar = false; while (*p) { // Replace $(variableName) in the script to the value of a config variable if (p[0] == '$' && p[1] == '(') { inVar = true; p += 2; // skip "$(" } if (inVar && p[0] == ')') { var.NullTerminate(); command.Append(GetVarValue(var.GetBuffer())); var.Reset(); inVar = false; p += 1; // skip ")" } if (*p == 0) break; if (inVar) var.Append(*p); else command.Append(*p); p++; } command.NullTerminate(); }
bool HTTPSession::RedirectLocalhost(HTTPConnection *conn, HTTPRequest &request) { ReadBuffer host; // fix Windows 7 IPv6 localhost name resolution issue host = request.header.GetField(HTTP_HEADER_HOST); if (host.BeginsWith("localhost")) { ReadBuffer userAgent; Buffer newHost; Buffer ha; unsigned i; int pos; userAgent = request.header.GetField(HTTP_HEADER_USER_AGENT); pos = userAgent.Find(WINDOWS_NT_USER_AGENT); if (pos < 0) return false; newHost.Write("127.0.0.1"); for (i = 0; i < host.GetLength(); i++) { if (host.GetCharAt(i) == ':') { host.Advance(i); newHost.Append(host); break; } } ha.Writef(HTTP_HEADER_LOCATION ": http://%B%R" HTTP_CS_CRLF, &newHost, &request.line.uri); ha.NullTerminate(); conn->ResponseHeader(HTTP_STATUS_CODE_TEMPORARY_REDIRECT, true, ha.GetBuffer()); conn->Flush(true); return true; } return false; }
void SystemDungeonEntranceEntity::EncodeDestiny( Buffer& into ) const { const GPoint& position = m_self->position(); const std::string itemName( GetName() ); BallHeader head; head.entityID = m_self->itemID(); head.mode = Destiny::DSTBALL_STOP; head.radius = GetRadius(); head.x = position.x; head.y = position.y; head.z = position.z; head.sub_type = HasMiniBalls; // I dono if this is correct... we'll see into.Append( head ); MassSector mass; mass.mass = 10000000000.00; mass.cloak = 0; mass.unknown52 = 0xFFFFFFFFFFFFFFFFLL; mass.corpID = m_self->ownerID(); //a little hacky... mass.allianceID = 0xFFFFFFFF; into.Append( mass ); DSTBALL_STOP_Struct main; main.formationID = 0xFF; into.Append( main ); const uint16 miniballCount = 1; into.Append( miniballCount ); MiniBall miniball; miniball.x = -7701.181; miniball.y = 8060.06; miniball.z = 27878.900; miniball.radius = 1639.241; into.Append( miniball ); const uint8 nameLen = utf8::distance( itemName.begin(), itemName.end() ); into.Append( nameLen ); const Buffer::iterator<uint16> name = into.end<uint16>(); into.ResizeAt( name, nameLen ); utf8::utf8to16( itemName.begin(), itemName.end(), name ); }
void ShipEntity::EncodeDestiny( Buffer& into ) const { const GPoint& position = GetPosition(); const std::string itemName( GetName() ); /*if(m_orbitingID != 0) { #pragma pack(1) struct AddBall_Orbit { BallHeader head; MassSector mass; ShipSector ship; DSTBALL_ORBIT_Struct main; NameStruct name; }; #pragma pack() into.resize(start + sizeof(AddBall_Orbit) + slen*sizeof(uint16) ); uint8 *ptr = &into[start]; AddBall_Orbit *item = (AddBall_Orbit *) ptr; ptr += sizeof(AddBall_Orbit); item->head.entityID = GetID(); item->head.mode = Destiny::DSTBALL_ORBIT; item->head.radius = m_self->radius(); item->head.x = x(); item->head.y = y(); item->head.z = z(); item->head.sub_type = IsMassive | IsFree; item->mass.mass = m_self->mass(); item->mass.unknown51 = 0; item->mass.unknown52 = 0xFFFFFFFFFFFFFFFFLL; item->mass.corpID = GetCorporationID(); item->mass.unknown64 = 0xFFFFFFFF; item->ship.max_speed = m_self->maxVelocity(); item->ship.velocity_x = m_self->maxVelocity(); //hacky hacky item->ship.velocity_y = 0.0; item->ship.velocity_z = 0.0; item->ship.agility = 1.0; //hacky item->ship.speed_fraction = 0.133f; //just strolling around. TODO: put in speed fraction! item->main.unknown116 = 0xFF; item->main.followID = m_orbitingID; item->main.followRange = 6000.0f; item->name.name_len = slen; // in number of unicode chars //strcpy_fake_unicode(item->name.name, GetName()); } else */{ BallHeader head; head.entityID = GetID(); head.mode = Destiny::DSTBALL_STOP; head.radius = GetRadius(); head.x = position.x; head.y = position.y; head.z = position.z; head.sub_type = IsMassive | IsFree; into.Append( head ); MassSector mass; mass.mass = GetMass(); mass.cloak = 0; mass.Harmonic = -1.0f; mass.corpID = GetCorporationID(); mass.allianceID = GetAllianceID(); into.Append( mass ); ShipSector ship; ship.max_speed = static_cast<float>(GetMaxVelocity()); ship.velocity_x = 0.0; ship.velocity_y = 0.0; ship.velocity_z = 0.0; ship.agility = static_cast<float>(GetAgility()); ship.speed_fraction = 0.0; into.Append( ship ); DSTBALL_STOP_Struct main; main.formationID = 0xFF; into.Append( main ); } }
void SystemManager::MakeSetState(const SystemBubble *bubble, DoDestiny_SetState &ss) const { Buffer* stateBuffer = new Buffer; AddBall_header head; head.more = 0; head.sequence = ss.stamp; stateBuffer->Append( head ); //I am not thrilled with this mechanism, but I cant think of a better //way to deal with it right now. The issue is that we need to send out // info for all system-wide entities (celestials, etc), as well as all // entities in our current bubble. Well, it is likely that some things // in our bubble are system-wide, and we would be sending out duplciates. // so, we use a set to enforce uniqueness. std::set<SystemEntity*> visibleEntities; { std::map<uint32, SystemEntity*>::const_iterator cur, end; cur = m_entities.begin(); end = m_entities.end(); for(; cur != end; ++cur) { if( !cur->second->IsVisibleSystemWide() ) { //_log(COMMON__WARNING, "%u is not visible!", cur->first); continue; } //_log(COMMON__WARNING, "%u is system wide visible!", cur->first); visibleEntities.insert( cur->second ); } } //bubble is null??? why??? bubble->GetEntities( visibleEntities ); PySafeDecRef( ss.slims ); ss.slims = new PyList; //go through all entities and gather the info we need... std::set<SystemEntity*>::const_iterator cur, end; cur = visibleEntities.begin(); end = visibleEntities.end(); for(; cur != end; ++cur) { SystemEntity* ent = *cur; //_log(COMMON__WARNING, "Encoding entity %u", ent->GetID()); //ss.damageState ss.damageState[ ent->GetID() ] = ent->MakeDamageState(); //ss.slims ss.slims->AddItem( new PyObject( new PyString( "foo.SlimItem" ), ent->MakeSlimItem() ) ); //append the destiny binary data... ent->EncodeDestiny( *stateBuffer ); } //ss.destiny_state ss.destiny_state = new PyBuffer( &stateBuffer ); SafeDelete( stateBuffer ); //ss.gangCorps //ss.aggressors //ss.droneState ss.droneState = m_db.GetSolDroneState( m_systemID ); if( NULL == ss.droneState ) { _log( SERVICE__ERROR, "Unable to query dronestate entity for destiny update in system %u!", m_systemID ); ss.droneState = new PyNone; } //ss.solItem ss.solItem = m_db.GetSolRow( m_systemID ); if( NULL == ss.solItem ) { _log( CLIENT__ERROR, "Unable to query solarsystem entity for destiny update in system %u!", m_systemID ); ss.solItem = new PyNone; } //ss.effectStates ss.effectStates = new PyList; //ss.allianceBridges ss.allianceBridges = new PyList; _log( DESTINY__TRACE, "Set State:" ); ss.Dump( DESTINY__TRACE, " " ); _log( DESTINY__TRACE, " Buffer:" ); _hex( DESTINY__TRACE, &( ss.destiny_state->content() )[0], ss.destiny_state->content().size() ); _log( DESTINY__TRACE, " Decoded:" ); Destiny::DumpUpdate( DESTINY__TRACE, &( ss.destiny_state->content() )[0], ss.destiny_state->content().size() ); }
void AsteroidEntity::EncodeDestiny( Buffer& into ) const { const Vector3D& position = GetPosition(); const std::string itemName( GetName() ); /*if(m_orbitingID != 0) { #pragma pack(1) struct AddBall_Orbit { BallHeader head; MassSector mass; ShipSector ship; DSTBALL_ORBIT_Struct main; NameStruct name; }; #pragma pack() into.resize(start + sizeof(AddBall_Orbit) + slen*sizeof(uint16) ); uint8 *ptr = &into[start]; AddBall_Orbit *item = (AddBall_Orbit *) ptr; ptr += sizeof(AddBall_Orbit); item->head.entityID = GetID(); item->head.mode = Destiny::DSTBALL_ORBIT; item->head.radius = m_self->radius(); item->head.x = x(); item->head.y = y(); item->head.z = z(); item->head.sub_type = IsMassive | IsFree; item->mass.mass = m_self->mass(); item->mass.unknown51 = 0; item->mass.unknown52 = 0xFFFFFFFFFFFFFFFFLL; item->mass.corpID = GetCorporationID(); item->mass.unknown64 = 0xFFFFFFFF; item->ship.max_speed = m_self->maxVelocity(); item->ship.velocity_x = m_self->maxVelocity(); //hacky hacky item->ship.velocity_y = 0.0; item->ship.velocity_z = 0.0; item->ship.agility = 1.0; //hacky item->ship.speed_fraction = 0.133f; //just strolling around. TODO: put in speed fraction! item->main.unknown116 = 0xFF; item->main.followID = m_orbitingID; item->main.followRange = 6000.0f; item->name.name_len = slen; // in number of unicode chars //strcpy_fake_unicode(item->name.name, GetName()); } else { BallHeader head; head.entityID = GetID(); head.mode = Destiny::DSTBALL_STOP; head.radius = GetRadius(); head.x = position.x; head.y = position.y; head.z = position.z; head.sub_type = IsMassive | IsFree; into.Append( head ); MassSector mass; mass.mass = GetMass(); mass.cloak = 0; mass.unknown52 = 0xFFFFFFFFFFFFFFFFLL; mass.corpID = GetCorporationID(); mass.allianceID = GetAllianceID(); into.Append( mass ); ShipSector ship; ship.max_speed = GetMaxVelocity(); ship.velocity_x = 0.0; ship.velocity_y = 0.0; ship.velocity_z = 0.0; ship.unknown_x = 0.0; ship.unknown_y = 0.0; ship.unknown_z = 0.0; ship.agility = GetAgility(); ship.speed_fraction = 0.0; into.Append( ship ); DSTBALL_STOP_Struct main; main.formationID = 0xFF; into.Append( main ); } */ BallHeader head; head.entityID = GetID(); head.mode = Destiny::DSTBALL_RIGID; head.radius = GetRadius(); head.x = position.x; head.y = position.y; head.z = position.z; head.sub_type = /*HasMiniBalls | */IsGlobal; into.Append( head ); DSTBALL_RIGID_Struct main; main.formationID = 0xFF; into.Append( main ); /* const uint16 miniballsCount = 1; into.Append( miniballsCount ); MiniBall miniball; miniball.x = -7701.181; miniball.y = 8060.06; miniball.z = 27878.900; miniball.radius = 1639.241; into.Append( miniball ); */ }
//TODO: ask the destiny manager to do this for us! void DynamicSystemEntity::EncodeDestiny( Buffer& into ) const { const GPoint& position = GetPosition(); const std::string itemName( GetName() ); /* if(m_warpActive) { #pragma pack(1) struct AddBall_Warp { BallHeader head; MassSector mass; ShipSector ship; DSTBALL_WARP_Struct main; NameStruct name; }; #pragma pack() into.resize(start + sizeof(AddBall_Warp) + slen*sizeof(uint16) ); uint8 *ptr = &into[start]; AddBall_Warp *item = (AddBall_Warp *) ptr; ptr += sizeof(AddBall_Warp); item->head.entityID = GetID(); item->head.mode = Destiny::DSTBALL_WARP; item->head.radius = Ship()->radius(); item->head.x = position.x; item->head.y = position.y; item->head.z = position.z; item->head.sub_type = IsFree | IsMassive | IsInteractive; item->mass.mass = Ship()->mass(); item->mass.unknown51 = 0; item->mass.unknown52 = 0xFFFFFFFFFFFFFFFFLL; item->mass.corpID = GetCorporationID(); item->mass.unknown64 = 0xFFFFFFFF; GVector vec(GetPosition(), m_movePoint); vec.normalize(); vec *= 45.0; //no idea what to use... item->ship.max_speed = Ship()->maxVelocity(); item->ship.velocity_x = vec.x; item->ship.velocity_y = vec.y; item->ship.velocity_z = vec.z; item->ship.agility = Ship()->agility(); item->ship.speed_fraction = 1.0; //TODO: put in speed fraction! item->main.unknown116 = 0xFF; item->main.unknown_x = m_movePoint.x; item->main.unknown_y = m_movePoint.y; item->main.unknown_z = m_movePoint.z; item->main.effectStamp = 0xFFFFFFFF; item->main.followRange = 1000.0; item->main.followID = 0; item->main.ownerID = 0x1e; //no idea. item->name.name_len = slen; // in number of unicode chars py_mbstowcs(item->name.name, GetName()); } else*/ { BallHeader head; head.entityID = GetID(); head.mode = Destiny::DSTBALL_STOP; head.radius = GetRadius(); head.x = position.x; head.y = position.y; head.z = position.z; head.sub_type = IsFree | IsMassive | IsInteractive; into.Append( head ); MassSector mass; mass.mass = GetMass(); mass.cloak = 0; mass.Harmonic = -1.0f; mass.corpID = GetCorporationID(); mass.allianceID = GetAllianceID(); into.Append( mass ); ShipSector ship; if( Destiny() == NULL ) // We dont have a destiny object or dont have one YET { ship.max_speed = static_cast<float>(GetMaxVelocity()); ship.velocity_x = 0.0; ship.velocity_y = 0.0; ship.velocity_z = 0.0; ship.agility = static_cast<float>(GetAgility()); ship.speed_fraction = 0.0; } else { ship.max_speed = static_cast<float>(GetMaxVelocity()); ship.velocity_x = Destiny()->GetVelocity().x; ship.velocity_y = Destiny()->GetVelocity().y; ship.velocity_z = Destiny()->GetVelocity().z; ship.agility = static_cast<float>(GetAgility()); ship.speed_fraction = static_cast<float>(Destiny()->GetSpeedFraction()); } into.Append( ship ); DSTBALL_STOP_Struct main; main.formationID = 0xFF; into.Append( main ); } }
int Test_HTTPClient::OnDataIn(unsigned char* pData, size_t nLen) { sbData_.Append(pData, nLen); return 1; }
int Test_CompareTCPHTTPData_TCPConnection::OnDataIn(unsigned char* pData, size_t nLen) { g_sbTest_CompareTCPHTTPData_TCPConnection.Append(pData, nLen); return 1; }
int Test_CompareTCPHTTPData_HTTPClient::OnDataIn(unsigned char* pData, size_t nLen) { g_sbTest_CompareTCPHTTPData_HTTPClient.Append(pData, nLen); return 1; }
bool FFInterface::Connect (void) { b_UseLocalHeuristicEvaluator = (1 == (int)(config)"use_local_heuristic_evaluator"); if (true == b_UseLocalHeuristicEvaluator) { if (false == InitHeuristicEvaluator ()) return false; b_Active = true; p_FFInterface = this; pthread_create (&thr_SocketLoop, NULL, RunThread, this); pthread_detach (thr_SocketLoop); return true; } String sServer = (config)"cache_host"; String sPort = (config)"cache_service"; if (false == ClientSocket::ConnectBlocking (sServer, sPort)) { cout << " [EE] Failed to connect to cache server at " << sServer << ':' << sPort << endl; return false; } b_KnownWorldOnly = (1 == (int)(config)"known_world_only"); if (true == b_KnownWorldOnly) { cout << "Activating known-world-only mode." << endl; SendMessage (String (":[known world only]")); SetStandalone (true); Buffer bufTemp; size_t iMessageSize = 0; while (true) { char zData [RECEIVE_BUFFER + 1]; long lBytes = ReceiveBlocking (zData, RECEIVE_BUFFER, 100); if (lBytes > 0) bufTemp.Append (zData, lBytes); if (false == bufTemp.ReadFromIndex (0, &iMessageSize, sizeof (size_t))) continue; if (iMessageSize > bufTemp.Length ()) continue; break; } Buffer bufResponse = bufTemp.PopFirstMessageAsBuffer (iMessageSize); bufResponse.DropFront (sizeof (size_t)); String sMessage = bufResponse; if (":Known-world-only mode active" == sMessage) cout << " Known world only mode active." << endl; else { cout << " [WARNING] Failed to activate known-world-only mode.\n" " Got following response from cache: [" << sMessage << ']' << endl; } SetStandalone (false); } ClearConnection (); b_Active = true; pthread_create (&thr_SocketLoop, NULL, RunThread, this); pthread_detach (thr_SocketLoop); return true; }