/// <summary> /// Received a DNA update from the client. Save the DNA via the AvatarManagerServiceAPI and broadcast to other clients /// TODO: Verify the dna is valid /// </summary> /// <param name="message"></param> private void RecvDnaUpdate(Message message) { string newDnaString = CheckType.TryAssignType <string>(message.Data[0]); XmlDocument newDna = new XmlDocument(); newDna.LoadXml(newDnaString); mLogger.Info("RecvDnaUpdate: " + mAvatarId.ToString() + ": " + newDnaString); // Get list of ItemIds from DNA List <ItemId> itemIds; AvatarXmlUtil.GetItemIdsFromAvatarDnaNode(newDna, out itemIds); // Get XML of assets from ItemIds XmlDocument assetXml = mServerAssetRepository.GetXmlDna(itemIds); // Replace the DNA in the message with the asset xml message.Data[0] = assetXml.OuterXml; mObjectData[3] = assetXml.InnerXml; // Broadcast the change out BroadcastMessage(message); // Save the dna to the DB AvatarManagerServiceAPI.UpdateAvatarDna(mAvatarId, newDna, delegate(XmlDocument xmlResponse) { mLogger.Info("RecvDnaUpdate, DNA saved: " + mAvatarId.ToString() + "\n" + xmlResponse.OuterXml); }); }
private void GetFashionModelAvatars(ServerAccount serverAccount, Guid sessionId, Action <List <object> > returnFunc) { // Get the local avatar assets AvatarManagerServiceAPI.GetAvatarForUser(serverAccount, delegate(XmlDocument localAvatarXml) { List <object> responseData = new List <object>(); XmlElement avatarNode = (XmlElement)localAvatarXml.SelectSingleNode("//Avatar"); XmlAttribute localAvatarAttrib = localAvatarXml.CreateAttribute("LocalAvatar"); localAvatarAttrib.InnerText = "true"; avatarNode.Attributes.Append(localAvatarAttrib); ReplaceItemIdsWithDna(avatarNode); AddFacebookData ( avatarNode, new FacebookFriendInfo ( serverAccount.AccountId, serverAccount.FacebookAccountId, serverAccount.Nickname, "", "" ) ); responseData.Add(avatarNode.OuterXml); FashionMinigameServiceAPI.GetHiredFriendsForJob(serverAccount, Jobs.Model, delegate(ICollection <long> hiredFriendIds) { ProcessHiredFriends(serverAccount, returnFunc, responseData, hiredFriendIds); }); }); }
public void CreateNewAvatarForAccount(Guid sessionId, ZoneId zoneId, ServerAccount serverAccount, AvatarId defaultAvatarId, System.Action <bool> createAvatarFinishedCallback) { Action <XmlDocument> createAvatarServiceCallback = delegate(XmlDocument xmlResponse) { XmlNode avatarXmlNode = xmlResponse.SelectSingleNode("Avatars/Avatar"); if (avatarXmlNode != null) { Metrics.Log(LogGlobals.CATEGORY_ACCOUNT, LogGlobals.EVENT_AVATAR_CREATED, LogGlobals.AVATAR_ID_LABEL, defaultAvatarId.ToString(), serverAccount.AccountId.ToString()); GetAvatarServiceResponse(avatarXmlNode, serverAccount.Nickname, sessionId, zoneId, createAvatarFinishedCallback); } else { StateServerAssert.Assert(new System.Exception("Error: Could not create avatar: " + xmlResponse.InnerText)); createAvatarFinishedCallback(false); } }; AvatarManagerServiceAPI.CreateAvatarForUser(serverAccount, defaultAvatarId, createAvatarServiceCallback); }
public void GetAvatar(Guid sessionId, ZoneId zoneId, ServerAccount serverAccount, AvatarId defaultAvatarId, System.Action <bool> getAvatarFinishedCallback) { Action <XmlDocument> getAvatarCallback = delegate(XmlDocument xmlResponse) { XmlNode avatarXmlNode = xmlResponse.SelectSingleNode("Avatars/Avatar"); //if no avatars were found for this account, create one! if (avatarXmlNode == null) { CreateNewAvatarForAccount(sessionId, zoneId, serverAccount, defaultAvatarId, getAvatarFinishedCallback); } //otherwise, just grab the first avatar out of the avatar returned list else { GetAvatarServiceResponse(avatarXmlNode, serverAccount.Nickname, sessionId, zoneId, getAvatarFinishedCallback); } }; AvatarManagerServiceAPI.GetAvatarForUser(serverAccount, getAvatarCallback); }
/// <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); } }
private void GetAllHiredAvatars(Message message, Guid sessionId) { ServerAccount localUserServerAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); AvatarManagerServiceAPI.GetAvatarForUser(localUserServerAccount, delegate(XmlDocument localAvatarXml) { FashionMinigameServiceAPI.GetAllHiredFriends(localUserServerAccount, delegate(XmlDocument hiredFriendsXml) { Dictionary <long, Jobs> friendFbIds = Functionals.Reduce <Dictionary <long, Jobs> > ( delegate(Dictionary <long, Jobs> accumulator, object friendIdNode) { XmlNode friendNode = (XmlNode)friendIdNode; foreach (string idText in friendNode.InnerText.Split(',')) { accumulator.Add(long.Parse(idText), (Jobs)Enum.Parse(typeof(Jobs), friendNode.SelectSingleNode("@KeyName").InnerText)); } return(accumulator); }, hiredFriendsXml.SelectNodes("//DataKey") ); List <object> resultData = new List <object>(); XmlNode localAvatarNode = localAvatarXml.SelectSingleNode("//Avatar"); XmlAttribute fbidAttrib = localAvatarXml.CreateAttribute("FBID"); fbidAttrib.InnerText = localUserServerAccount.FacebookAccountId.ToString(); localAvatarNode.Attributes.Append(fbidAttrib); XmlAttribute firstnameAttrib = localAvatarXml.CreateAttribute("FirstName"); firstnameAttrib.InnerText = localUserServerAccount.Nickname; localAvatarNode.Attributes.Append(firstnameAttrib); XmlAttribute lastnameAttrib = localAvatarXml.CreateAttribute("LastName"); lastnameAttrib.InnerText = ""; localAvatarNode.Attributes.Append(lastnameAttrib); resultData.Add(localAvatarXml.OuterXml); ProcessHiredFriends ( localUserServerAccount, delegate(List <object> messageData) { friendFbIds.Add(localUserServerAccount.FacebookAccountId, Jobs.Model); Message responseMessage = new Message(); List <object> responseData = new List <object>(); responseData.Insert(0, message.Data[0]); // callbackId // Build asset lists for all the avatars and add minigame data foreach (XmlDocument avatarXml in MessageUtil.GetXmlDocumentsFromMessageData(messageData)) { XmlNode avatarNode = avatarXml.SelectSingleNode("//Avatar"); ReplaceItemIdsWithDna((XmlElement)avatarNode); // The job name will be the DataKey the FBID was stored under XmlAttribute avatarJobAttrib = avatarXml.CreateAttribute("job"); long fbid = long.Parse(avatarNode.SelectSingleNode("@FBID").InnerText); Jobs friendJob; if (friendFbIds.TryGetValue(fbid, out friendJob)) { avatarJobAttrib.InnerText = friendJob.ToString(); } else if (fbid == 0) // Unknown user { } else { string errorMessage = "Unable to find job info for FBID: " + fbid; mLogger.Error(errorMessage); avatarJobAttrib.InnerText = errorMessage; } avatarNode.Attributes.Append(avatarJobAttrib); responseData.Add(avatarNode.OuterXml); } responseMessage.FashionGameModelAssetMessage(responseData); SendMessageToClient(responseMessage, sessionId); }, resultData, friendFbIds.Keys ); }); }); }