示例#1
0
        /// <summary>
        /// Give coins to friends who were hired in this show.
        /// These coins are stored in the db in the escrow table until the friend logs in next time.
        /// </summary>
        /// <param name="serverAccount"></param>
        /// <param name="coins"></param>
        public static void GiveFashionMinigameHiredFriendsCoins(ServerAccount serverAccount, int coins)
        {
            if (coins <= 0)
            {
                // No coins to give, done.
                return;
            }

            FashionMinigameServiceAPI.GetAllHiredFriends(serverAccount, delegate(ICollection <long> friendList)
            {
                EscrowManagerServiceAPI.CreateEscrowTransaction(friendList, serverAccount.FacebookAccountId, EscrowType.FashionCityJobCoins.ToString(), coins, VerifyGiveCoinSuccess);
            });
        }
示例#2
0
        public void FacebookFriendsReady(ServerAccount serverAccount, Guid sessionId)
        {
            try
            {
                if (serverAccount.FacebookFriendsRequested)
                {
                    mLogger.Debug("FacebookFriendsReady: " + serverAccount.AccountId.ToString());
                    serverAccount.FacebookFriendsRequested = false;
                    IDictionary <long, FacebookFriendInfo> possibleHires = new Dictionary <long, FacebookFriendInfo>(serverAccount.FacebookFriendsLookupTable);

                    FashionMinigameServiceAPI.GetAllHiredFriends(serverAccount, delegate(ICollection <long> hiredFriendIds)
                    {
                        // Filter out any users that have already been hired
                        foreach (long facebookId in hiredFriendIds)
                        {
                            possibleHires.Remove(facebookId);
                        }

                        Message responseMessage    = new Message();
                        List <object> responseData = new List <object>();
                        responseData.Add(serverAccount.FacebookFriendsReadyCallbackId);                         // callback Id
                        if (possibleHires.Count == 0)
                        {
                            responseData.Add(false);
                        }
                        else
                        {
                            responseData.Add(possibleHires);
                        }
                        responseMessage.FashionGameFriendsToHire(responseData);
                        SendMessageToClient(responseMessage, sessionId);
                    });
                }
            }
            catch (System.Exception ex)
            {
                StateServerAssert.Assert(new Exception("Something went wrong with sending the facebook friends to the client.", ex));
            }
        }
示例#3
0
        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
                    );
                });
            });
        }