void DirEntity::PackDataObjects(BaseMessage& theMsgR, const DataObjectTypeSet& theSetR, unsigned long theFlags) { WTRACE("DirEntity::PackDataObjects"); WDBG_LL("DirEntity::PackDataObject Packing data objects, size=" << theSetR.size()); theMsgR.AppendShort(theSetR.size()); bool packType = ((theFlags & WONMsg::GF_ADDDOTYPE) != 0); bool packData = ((theFlags & WONMsg::GF_ADDDODATA) != 0); DataObjectTypeSet::const_iterator anItr(theSetR.begin()); for (; anItr != theSetR.end(); anItr++) { if (packType) { unsigned char aTypeLen = anItr->GetDataType().size(); theMsgR.AppendByte(aTypeLen); theMsgR.AppendBytes(aTypeLen, anItr->GetDataType().data()); } if (packData) { unsigned short aDataLen = anItr->GetData().size(); theMsgR.AppendShort(aDataLen); theMsgR.AppendBytes(aDataLen, anItr->GetData().data()); } } }
void DirEntity::UnpackDataObjects(BaseMessage& theMsgR, DataObjectTypeSet& theSetR, unsigned long theFlags) { WTRACE("DirEntity::UnpackDataObjects"); unsigned short aCt = theMsgR.ReadShort(); WDBG_LL("DirEntity::UnpackDataObjects Unpacking data objects, size=" << aCt); theSetR.clear(); bool unpackType = ((theFlags & WONMsg::GF_ADDDOTYPE) != 0); bool unpackData = ((theFlags & WONMsg::GF_ADDDODATA) != 0); for (int i=0; i < aCt; i++) { DataObject anObj; if (unpackType) { unsigned char aLen = theMsgR.ReadByte(); anObj.GetDataType().assign(reinterpret_cast<const unsigned char*>(theMsgR.ReadBytes(aLen)), aLen); } else anObj.GetDataType().assign(reinterpret_cast<const unsigned char*>(&i), sizeof(i)); if (unpackData) { unsigned short aLen = theMsgR.ReadShort(); anObj.GetData().assign(reinterpret_cast<const unsigned char*>(theMsgR.ReadBytes(aLen)), aLen); } theSetR.insert(anObj); } }
void Matchmaker::GetTitanServerList() { #ifdef DLLSAMPLE mNewAuthServers.clear(); mNewContestServers.clear(); mNewEventServers.clear(); mNewFirewallServers.clear(); mNewProfileServers.clear(); HWONDATAOBJECT aDataObjectH = WONDataObjectCreate(OBJ_VALIDVERSIONS.c_str(), OBJ_VALIDVERSIONS.size(), NULL, 0); WONError aError = WONDirGetDirectoryW(NULL, mDirServers, mNumDirServers, DIR_TITANSERVER, NULL, NULL, WONDir_GF_DECOMPROOT | WONDir_GF_DECOMPRECURSIVE | WONDir_GF_DECOMPSERVICES | WONDir_GF_ADDTYPE | WONDir_GF_SERVADDNAME | WONDir_GF_SERVADDNETADDR | WONDir_GF_ADDDOTYPE | WONDir_GF_ADDDODATA, &aDataObjectH, 1, TitanServerEntityCallback, this, gRequestTimeout); CopySTLAddressListToArray(mNewAuthServers, &mAuthServers, &mNumAuthServers); CopySTLAddressListToArray(mNewContestServers, &mContestServers, &mNumContestServers); CopySTLAddressListToArray(mNewEventServers, &mEventServers, &mNumEventServers); CopySTLAddressListToArray(mNewFirewallServers, &mFirewallServers, &mNumFirewallServers); CopySTLAddressListToArray(mNewProfileServers, &mProfileServers, &mNumProfileServers); #else DataObjectTypeSet aDataObjectSet; aDataObjectSet.insert(WONCommon::DataObject(OBJ_VALIDVERSIONS)); WONMsg::DirEntityList entityList; Error aError = GetDirectory(NULL, // no identity needed to get TitanServers (after all, the AuthServers are listed in there) mDirServers, mNumDirServers, NULL, DIR_TITANSERVER, &entityList, WONMsg::GF_DECOMPROOT | WONMsg::GF_DECOMPRECURSIVE | WONMsg::GF_DECOMPSERVICES | WONMsg::GF_ADDTYPE | WONMsg::GF_SERVADDNAME | WONMsg::GF_SERVADDNETADDR | WONMsg::GF_ADDDOTYPE | WONMsg::GF_ADDDODATA, aDataObjectSet, 0, 0, gRequestTimeout); switch(aError) { case Error_Success: { delete[] mAuthServers; mNumAuthServers = 0; mAuthServers = new IPSocket::Address[entityList.size()]; delete[] mContestServers; mNumContestServers = 0; mContestServers = new IPSocket::Address[entityList.size()]; delete[] mEventServers; mNumEventServers = 0; mEventServers = new IPSocket::Address[entityList.size()]; delete[] mFirewallServers; mNumFirewallServers = 0; mFirewallServers = new IPSocket::Address[entityList.size()]; delete[] mProfileServers; mNumProfileServers = 0; mProfileServers = new IPSocket::Address[entityList.size()]; DirEntityList::const_iterator aDirEntityListItr = entityList.begin(); for( ; aDirEntityListItr != entityList.end(); ++aDirEntityListItr) { if (aDirEntityListItr->mType == WONMsg::DirEntity::ET_DIRECTORY) { DataObjectTypeSet::const_iterator aDataObjectSetItr = aDirEntityListItr->mDataObjects.begin(); for( ; aDataObjectSetItr != aDirEntityListItr->mDataObjects.end(); ++aDataObjectSetItr) { if (aDataObjectSetItr->GetDataType() == OBJ_VALIDVERSIONS) mValidVersions = reinterpret_cast<const char*>(aDataObjectSetItr->GetData().c_str()); } } else if (aDirEntityListItr->mName == SERVERNAME_AUTH) mAuthServers[mNumAuthServers++] = IPSocket::Address(*aDirEntityListItr); else if (aDirEntityListItr->mName == SERVERNAME_CONTEST) mContestServers[mNumContestServers++] = IPSocket::Address(*aDirEntityListItr); else if (aDirEntityListItr->mName == SERVERNAME_EVENT) mEventServers[mNumEventServers++] = IPSocket::Address(*aDirEntityListItr); else if (aDirEntityListItr->mName == SERVERNAME_FIREWALL) mFirewallServers[mNumFirewallServers++] = IPSocket::Address(*aDirEntityListItr); else if (aDirEntityListItr->mName == SERVERNAME_PROFILE) mProfileServers[mNumProfileServers++] = IPSocket::Address(*aDirEntityListItr); } break; } case StatusDir_DirNotFound: OutputError("Directory containing Titan servers not found"); break; default: OutputError("Failed to get list of Titan servers!", aError); break; } #endif // DLLSAMPLE }
unsigned long DirEntity::ComputeSize(unsigned long theGetFlags, const DataObjectTypeSet& theSetR) const { unsigned long aSize = 0; // Add type if needed if (theGetFlags & WONMsg::GF_ADDTYPE) aSize += sizeof(mType); // Entity specific fields switch (mType) { case DirEntity::ET_DIRECTORY: // Add dir path if needed if (theGetFlags & WONMsg::GF_DIRADDPATH) aSize += TRawMsg::ComputeWStringPackSize(mPath); // Add dir name if needed if (theGetFlags & WONMsg::GF_DIRADDNAME) aSize += TRawMsg::ComputeWStringPackSize(mName); // Add dir visibility if needed if (theGetFlags & WONMsg::GF_DIRADDVISIBLE) aSize += sizeof(mVisible); break; case DirEntity::ET_SERVICE: // Add serv path if needed if (theGetFlags & WONMsg::GF_SERVADDPATH) aSize += TRawMsg::ComputeWStringPackSize(mPath); // Add serv name if needed if (theGetFlags & WONMsg::GF_SERVADDNAME) aSize += TRawMsg::ComputeWStringPackSize(mName); // Add serv netaddress if needed if (theGetFlags & WONMsg::GF_SERVADDNETADDR) aSize += sizeof(unsigned char) + mNetAddress.size(); break; } // Add displayName if needed if (theGetFlags & WONMsg::GF_ADDDISPLAYNAME) aSize += TRawMsg::ComputeWStringPackSize(mDisplayName); // Add lifespan if needed if (theGetFlags & WONMsg::GF_ADDLIFESPAN) aSize += sizeof(mLifespan); // Add create date if needed if (theGetFlags & WONMsg::GF_ADDCREATED) aSize += sizeof(mCreated); // Add touched date if needed if (theGetFlags & WONMsg::GF_ADDTOUCHED) aSize += sizeof(mTouched); // Add CRC if needed if (theGetFlags & WONMsg::GF_ADDCRC) aSize += sizeof(mCRC); // Add UserIds if needed if (theGetFlags & WONMsg::GF_ADDUIDS) aSize += sizeof(mCreateId) + sizeof(mTouchId); // Data Objects bool packAllObjs = ((theGetFlags & WONMsg::GF_ADDDATAOBJECTS) != 0); if ((packAllObjs) || (! theSetR.empty())) { aSize += sizeof(unsigned short); // data object count bool packType = ((theGetFlags & WONMsg::GF_ADDDOTYPE) != 0); bool packData = ((theGetFlags & WONMsg::GF_ADDDODATA) != 0); DataObjectTypeSet::const_iterator anItr(mDataObjects.begin()); for (; anItr != mDataObjects.end(); ++anItr) { if ((packAllObjs) || (theSetR.find(*anItr) != theSetR.end())) { if (packType) aSize += sizeof(unsigned char) + anItr->GetDataType().size(); if (packData) aSize += sizeof(unsigned short) + anItr->GetData().size(); } } } // Add ACLs if needed if (theGetFlags & WONMsg::GF_ADDACLS) { aSize += sizeof(unsigned short); // ACL count DirACLList::const_iterator anItr(mACLs.begin()); for (; anItr != mACLs.end(); ++anItr) aSize += sizeof(unsigned char) + sizeof(unsigned short) + (anItr->mACL.size() * sizeof(Permission)); } return aSize; }
void DirEntity::Pack(BaseMessage& theMsgR, unsigned long theGetFlags, const DataObjectTypeSet& theSetR) const { WTRACE("DirEntity::Pack"); WDBG_LL("DirEntity::Pack Packing entity, type=" << mType); // Add type if needed if (theGetFlags & WONMsg::GF_ADDTYPE) theMsgR.AppendByte(mType); // Entity specific fields switch (mType) { case DirEntity::ET_DIRECTORY: // Add dir path if needed if (theGetFlags & WONMsg::GF_DIRADDPATH) theMsgR.Append_PW_STRING(mPath); // Add dir name if needed if (theGetFlags & WONMsg::GF_DIRADDNAME) theMsgR.Append_PW_STRING(mName); // Add dir visibility if needed if (theGetFlags & WONMsg::GF_DIRADDVISIBLE) theMsgR.AppendByte(mVisible); break; case DirEntity::ET_SERVICE: // Add serv path if needed if (theGetFlags & WONMsg::GF_SERVADDPATH) theMsgR.Append_PW_STRING(mPath); // Add serv name if needed if (theGetFlags & WONMsg::GF_SERVADDNAME) theMsgR.Append_PW_STRING(mName); // Add serv netaddress if needed if (theGetFlags & WONMsg::GF_SERVADDNETADDR) { theMsgR.AppendByte(mNetAddress.size()); theMsgR.AppendBytes(mNetAddress.size(), mNetAddress.data()); } break; } // Add displayName if needed if (theGetFlags & WONMsg::GF_ADDDISPLAYNAME) theMsgR.Append_PW_STRING(mDisplayName); // Add lifespan if needed if (theGetFlags & WONMsg::GF_ADDLIFESPAN) theMsgR.AppendLong(mLifespan); // Add create date if needed if (theGetFlags & WONMsg::GF_ADDCREATED) theMsgR.AppendLong(mCreated); // Add touched date if needed if (theGetFlags & WONMsg::GF_ADDTOUCHED) theMsgR.AppendLong(mTouched); // Add CRC if needed if (theGetFlags & WONMsg::GF_ADDCRC) theMsgR.AppendLong(mCRC); // Add UserIds if needed if (theGetFlags & WONMsg::GF_ADDUIDS) { theMsgR.AppendLong(mCreateId); theMsgR.AppendLong(mTouchId); } // Add all data objects if needed if (theGetFlags & WONMsg::GF_ADDDATAOBJECTS) PackDataObjects(theMsgR, mDataObjects, theGetFlags); // Otherwise, add requested data objects (if any) else if (theSetR.size() > 0) { DataObjectTypeSet aPackSet; DataObjectTypeSet::const_iterator anItr(theSetR.begin()); for (; anItr != theSetR.end(); anItr++) { DataObjectTypeSet::const_iterator aSrch(mDataObjects.find(*anItr)); if (aSrch != mDataObjects.end()) aPackSet.insert(*aSrch); } PackDataObjects(theMsgR, aPackSet, theGetFlags); } // Add ACLs if needed (deferred) if (theGetFlags & WONMsg::GF_ADDACLS) PackACLs(theMsgR); }