/// <summary> /// Method used to start a ProcessMessage blocking method call /// If this is a cached message then retreive the data from the response data from the cache /// <param name="xmlClientMessage">PaymentItem client message</param> /// <param name="xmlClientMessage"></param> /// <returns>PaymentItems xml string response</returns> public string ProcessMessageBlocking(string xmlClientMessage, ServerStores serverStores, getUserIdDelegate getUserIdCall) { string response = ""; try { PaymentItemsProcessClientMessage clientMessage = new PaymentItemsProcessClientMessage(); ServiceCommand serviceCommand = (ServiceCommand)clientMessage.ProcessMessage(xmlClientMessage, getUserIdCall); if (clientMessage.IsCachedMessage((PaymentCommand)serviceCommand, serverStores)) { response = clientMessage.GetCachedStoreData((PaymentCommand)serviceCommand, serverStores); } else { response = InvokeServiceBlocking(serviceCommand); } } catch (Exception ex) { response = String.Format("<Error><Message>{0}</Message></Error>", ex); mLogger.Error(String.Format("Error ProcessMessageBlocking: {0}", response)); } return(response); }
/// <summary> /// Method used to start a ProcessMessage async method call /// This method processes PaymentItems messages /// If this is a cached message then retreive the data from the response data from the cache /// </summary> /// <param name="xmlClientMessage">PaymentItem client message</param> /// <param name="sender">List of session GUID's to send the response to</param> /// <param name="callback">Callback that is called on response from service</param> /// <returns>blank if no error else the error message</returns> public string ProcessMessageAsync(string xmlClientMessage, System.Action <string> callback, ServerStores serverStores, getUserIdDelegate getUserIdCall) { string response = ""; try { PaymentItemsProcessClientMessage clientMessage = new PaymentItemsProcessClientMessage(); ServiceCommand serviceCommand = (ServiceCommand)clientMessage.ProcessMessage(xmlClientMessage, getUserIdCall); if (clientMessage.IsCachedMessage((PaymentCommand)serviceCommand, serverStores)) { response = clientMessage.GetCachedStoreData((PaymentCommand)serviceCommand, serverStores); clientMessage.PaymentItemsReturn(response, callback); } else if (clientMessage.IsDoNothing((PaymentCommand)serviceCommand)) { response = clientMessage.createDoNothingResponse((PaymentCommand)serviceCommand); clientMessage.PaymentItemsReturn(response, callback); } else { InvokeServiceAsync(serviceCommand, callback); } } catch (Exception ex) { response = String.Format("<Error><Message>{0}</Message></Error>", ex); mLogger.Error(String.Format("Error ProcessMessageAsync: {0}", response)); } return(response); }
/// <summary> /// Use the payment system to award this account with this number of coins. /// </summary> /// <param name="serverStateMachine"></param> /// <param name="serverAccount"></param> /// <param name="totalCoins"></param> private void ProcessCoinPayment(ServerAccount serverAccount, int totalCoins, EscrowType escrowType, Guid sessionId) { NameValueCollection args = new NameValueCollection(); args.Add("userId", serverAccount.PaymentItemUserId); args.Add("amount", totalCoins.ToString()); args.Add("ipAddress", serverAccount.IpAddress); PaymentItemsProcessClientMessage clientMessage = new PaymentItemsProcessClientMessage(); PaymentCommand cmd = clientMessage.AddVirtualCoinForUser(args); mServerStateMachine.PaymentItemsManager.ProcessPaymentCommand(cmd, delegate(string response) { XmlDocument xmlResponse = new XmlDocument(); xmlResponse.LoadXml(response); //send message to client Message processCoinPaymentMessage = new Message(); List <object> processCoinPaymentMessageData = new List <object>(); processCoinPaymentMessageData.Add(escrowType); processCoinPaymentMessageData.Add(totalCoins); processCoinPaymentMessage.EscrowMessage(processCoinPaymentMessageData); processCoinPaymentMessage.Callback = (int)MessageSubType.ProcessEscrowTransaction; SendMessageToClient(processCoinPaymentMessage, sessionId); }); }
/// <summary> /// The PaymentItems Service return, used in async PaymentItems remote method calls /// </summary> /// <param name="response">The PaymentItems response message</param> /// <param name="type">The message type not used for the PaymentItem calls</param> /// <param name="callback">Callback that is called on response from service</param> protected override void InvokeServiceReturn(string response, string type, System.Action <string> callback) { try { PaymentItemsProcessClientMessage clientMessage = new PaymentItemsProcessClientMessage(); clientMessage.PaymentItemsReturn(response, callback); } catch (Exception ex) { mLogger.Error("Error InvokeServiceReturn ", ex); } }
/// <summary> /// Parser for PaymentITems command /// </summary> /// <param name="message">The message from the client</param> /// <param name="senderId">The senderId GUID</param> public override void ReceiveRequest(Message message, Guid senderId) { string xmlData = (string)message.Data[0]; System.Action <string> asyncCallback = delegate(string paymentItemsCommand) { try { XmlDocument response = new XmlDocument(); response.LoadXml(paymentItemsCommand); string noun = response.SelectSingleNode("/Response").Attributes["noun"].InnerText; string verb = response.SelectSingleNode("/Response").Attributes["verb"].InnerText; // Append special info to response for some payment items commands PaymentItemsProcessClientMessage clientMessage = new PaymentItemsProcessClientMessage(); response = clientMessage.SpecialResponse(response, noun, verb, mServerStores); // Award items in the hangout db that correspond with this purchase AwardPurchasedItems(response, noun, verb, senderId); response = GetPaymentItemSecurePaymentInfoEncrypted(response, noun, verb, senderId); Message paymentItemsResponse = new Message(); List <object> dataObject = new List <object>(); dataObject.Add(response.InnerXml); paymentItemsResponse.PaymentItemsMessage(dataObject); paymentItemsResponse.Callback = message.Callback; mLogger.DebugFormat("ProcessMessageAsync responded: {0},{1}. Response Size:{2}", noun, verb, paymentItemsCommand.Length); mServerStateMachine.SendMessageToReflector(paymentItemsResponse, senderId); } catch (System.Exception ex) { mLogger.ErrorFormat("Error in PaymentItems asyncCallback {0} {1}", ex, paymentItemsCommand); } }; getUserIdDelegate getUserId = new getUserIdDelegate(GetPaymentItemsUserId); XmlDocument xmlRequest = new XmlDocument(); xmlRequest.LoadXml(xmlData); mLogger.DebugFormat("ProcessMessageAsync called: {0}", xmlRequest.SelectSingleNode("/Request").Attributes["verb"].InnerText); mPaymentItems.ProcessMessageAsync(xmlData, asyncCallback, mServerStores, getUserId); }
private void SetLevelComplete(Message message, Guid sessionId) { mLogger.Debug("SetLevelComplete: " + message.ToString()); if (message.Data.Count < 4) { mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 3, actual was " + message.Data.Count); return; } int totalXP = CheckType.TryAssignType <int>(message.Data[1]); int XPEarnedOnThisLevel = CheckType.TryAssignType <int>(message.Data[2]); bool leveledUp = CheckType.TryAssignType <bool>(message.Data[3]); ServerAccount serverAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); // Save experience to the database FashionMinigameServiceAPI.SetGameData(serverAccount, GameDataKeys.PLAYER_EXPERIENCE_KEY, totalXP.ToString(), VerifySuccess); // Reward coins for experience int coinsEarned = Rewards.GetCoinsFromExperience(XPEarnedOnThisLevel); NameValueCollection args = new NameValueCollection(); args.Add("userId", mServerStateMachine.PaymentItemsManager.GetPaymentItemsUserId(sessionId)); args.Add("amount", coinsEarned.ToString()); args.Add("ipAddress", mServerStateMachine.ServerMessageProcessor.ServerReflector.GetClientIPAddress(sessionId)); PaymentItemsProcessClientMessage clientMessage = new PaymentItemsProcessClientMessage(); PaymentCommand cmd = clientMessage.AddVirtualCoinForUser(args); mServerStateMachine.PaymentItemsManager.ProcessPaymentCommand(cmd, delegate(string response) { XmlDocument xmlResponse = new XmlDocument(); xmlResponse.LoadXml(response); mLogger.Debug("SetLevelComplete success: " + response); XmlElement vcoinNode = (XmlElement)xmlResponse.SelectSingleNode("//accounts/account[@currencyName='VCOIN']"); // Convert to double, cast to int and then back to string to strip off decimal points string totalCoins = String.Empty; if (vcoinNode != null) { totalCoins = ((int)Double.Parse(vcoinNode.GetAttribute("balance"))).ToString(); } Hangout.Shared.Action resultMessage = delegate() { // Return a message to the user with the results of SetLevelComplete List <object> data = new List <object>(); data.Add(message.Data[0]); // callback id data.Add(coinsEarned.ToString()); data.Add(totalCoins); Message responseMessage = new Message(MessageType.FashionMinigame, data); SendMessageToClient(responseMessage, sessionId); }; }); // Award friends a fraction of earned coins for working in this show int friendEscrowCoins = Rewards.GetFriendCoins(XPEarnedOnThisLevel, serverAccount.EntourageSize); if (friendEscrowCoins > 0) { EscrowManager.GiveFashionMinigameHiredFriendsCoins(serverAccount, friendEscrowCoins); } if (leveledUp) { mEnergyManager.UserLeveledUp(serverAccount); } }