/// <summary> /// Get a reference system avatar. This avatar is used to fill in missing required info when pulling an avatar from the db /// </summary> private void GetReferenceAvatar(Action <Dna> gotReferenceAvatarFinished) { Action <XmlDocument> systemAvatarCallback = delegate(XmlDocument xmlResponse) { // Get the avatars for the friends without Hangout Avatars XmlNode avatarXmlNode = xmlResponse.SelectSingleNode("/Avatars/Avatar[@AvatarId='1']"); AvatarId avatarId; List <ItemId> itemIds = null; if (AvatarXmlUtil.GetAvatarInfoFromAvatarXmlNode(avatarXmlNode, out avatarId, out itemIds)) { //use the ServerAssetRepo to composite the List<ItemId> into an XmlNode XmlDocument itemsXml = mServerAssetRepository.GetXmlDna(itemIds); // Get a list of AssetInfos from this xml IEnumerable <AssetInfo> assetInfoList = ServerAssetInfo.Parse(itemsXml); // Make dna mReferenceAvatarDna = new Dna(); mReferenceAvatarDna.UpdateDna(assetInfoList); gotReferenceAvatarFinished(mReferenceAvatarDna); mLogger.Debug("System avatar xml = " + xmlResponse.OuterXml); } else { StateServerAssert.Assert(new Exception("Didn't get a valid system avatar for reference avatar, using an empty DNA")); mReferenceAvatarDna = new Dna(); gotReferenceAvatarFinished(mReferenceAvatarDna); } }; if (mReferenceAvatarDna == null) { AvatarManagerServiceAPI.GetSystemAvatars(systemAvatarCallback); } else { gotReferenceAvatarFinished(mReferenceAvatarDna); } }
private void ProcessHiredFriends(ServerAccount serverAccount, Action <List <object> > returnFunc, List <object> responseData, ICollection <long> hiredFriendIds) { if (hiredFriendIds.Count > 0) { Dictionary <AccountId, FacebookFriendInfo> friendAccounts = new Dictionary <AccountId, FacebookFriendInfo>(); List <FacebookFriendInfo> friendsWithoutAccounts = new List <FacebookFriendInfo>(); foreach (long facebookId in hiredFriendIds) { if (facebookId == serverAccount.FacebookAccountId) { friendAccounts.Add(serverAccount.AccountId, null); continue; } HandleFriendCase ( serverAccount, facebookId, delegate(FacebookFriendInfo ffi) { friendAccounts.Add(ffi.AccountId, ffi); }, delegate(FacebookFriendInfo ffi) { friendsWithoutAccounts.Add(ffi); }, delegate() { friendsWithoutAccounts.Add(new FacebookFriendInfo(new AccountId(0u), facebookId, "Unfriended", "", "")); } ); } AvatarManagerServiceAPI.GetAvatarForUsers(friendAccounts.Keys, delegate(XmlDocument friendAccountsAvatars) { AvatarManagerServiceAPI.GetSystemAvatars(delegate(XmlDocument npcAvatarsXml) { // Get the Avatars for the friends with Hangout Avatars foreach (XmlNode friendAvatarNode in friendAccountsAvatars.SelectNodes("Avatars/Avatar")) { // This is a little weird... the dictionary doesn't actually contain the new object, but that object // will index properly into the dictionary for what we want. If we didn't do this weirdness we'd have // to make a new data structure or search linearly AccountId accountId = new AccountId(uint.Parse(friendAvatarNode.SelectSingleNode("@AccountId").InnerText)); FacebookFriendInfo facebookFriend; if (!friendAccounts.TryGetValue(accountId, out facebookFriend)) { StateServerAssert.Assert ( new Exception ( "Facebook friend ID provided by the client (" + accountId + ") was not found in Account ID (" + serverAccount.AccountId + ")'s friend list while trying to process hired friends" ) ); return; } XmlElement friendAvatarElement = (XmlElement)friendAvatarNode; ReplaceItemIdsWithDna(friendAvatarElement); AddFacebookData(friendAvatarNode, facebookFriend); responseData.Add(friendAvatarNode.OuterXml); } // Get the avatars for the friends without Hangout Avatars XmlNodeList npcAvatarNodes = npcAvatarsXml.SelectNodes("/Avatars/Avatar"); foreach (FacebookFriendInfo facebookFriend in friendsWithoutAccounts) { XmlNode npcAvatarNode = npcAvatarNodes[mRand.Next(0, npcAvatarNodes.Count)]; // Local avatar is already expanded to assets XmlElement npcElement = (XmlElement)npcAvatarNode; ReplaceItemIdsWithDna(npcElement); AddFacebookData(npcAvatarNode, facebookFriend); responseData.Add(npcAvatarNode.OuterXml); } returnFunc(responseData); }); }); } else { returnFunc(responseData); } }