private void GetPlayerGameData(Message message, Guid sessionId) { mLogger.Debug("GetPlayerGameData: " + message.ToString()); if (message.Data.Count < 2) { mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 2, actual was " + message.Data.Count); return; } string callbackId = CheckType.TryAssignType <string>(message.Data[0]); string dataKey = CheckType.TryAssignType <string>(message.Data[1]); ServerAccount serverAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); mLogger.Debug("GetGameData: SENT"); FashionMinigameServiceAPI.GetGameData(serverAccount, dataKey, delegate(XmlDocument resultXml) { mLogger.Debug("GetGameData: RECEIVED"); Message responseMessage = new Message(); List <object> responseData = new List <object>(); responseData.Add(callbackId); responseData.Add(resultXml.OuterXml); responseMessage.FashionGameGetData(responseData); SendMessageToClient(responseMessage, sessionId); }); }
/// <summary> /// Calculates all the parameters required to call Energy.CalculateCurrentEnergy /// </summary> /// <param name="serverAccount"></param> /// <param name="result">returns (float lastEnergy, float maxEnergy, DateTime rechargeDate)</param> public void GetCurrentEnergyData(ServerAccount serverAccount, Action <float, float, DateTime> result) { FashionMinigameServiceAPI.GetGameData ( serverAccount, new string[] { PLAYER_ENERGY_KEY, ENERGY_REGEN_DATE, PLAYER_MAX_ENERGY }, delegate(XmlDocument resultXml) { string playerEnergyData = null; string energyRegenDateData = null; string playerMaxEnergyData = null; foreach (XmlNode dataNode in resultXml.SelectNodes("//DataKey")) { switch (dataNode.Attributes["KeyName"].InnerText) { case PLAYER_ENERGY_KEY: playerEnergyData = dataNode.InnerText; break; case ENERGY_REGEN_DATE: energyRegenDateData = dataNode.InnerText; break; case PLAYER_MAX_ENERGY: playerMaxEnergyData = dataNode.InnerText; break; default: throw new Exception("Error in FashionMinigameServiceAPI.GetGameData, result XML has an unexpected key: " + dataNode.Attributes["KeyName"].InnerText + "\nXML:\n" + resultXml.OuterXml); } } if (playerMaxEnergyData == null) { SetMaxEnergy(serverAccount, INITIAL_MAX_ENERGY); playerMaxEnergyData = INITIAL_MAX_ENERGY.ToString(); } if (energyRegenDateData == null) { SetEnergyRegenDate(serverAccount, DateTime.UtcNow); energyRegenDateData = DateTime.UtcNow.ToString(); } if (playerEnergyData == null) { SetEnergy(serverAccount, INITIAL_MAX_ENERGY); playerEnergyData = playerMaxEnergyData; } float lastEnergy = float.Parse(playerEnergyData); float maxEnergy = float.Parse(playerMaxEnergyData); DateTime lastUpdate = DateTime.Parse(energyRegenDateData); result(lastEnergy, maxEnergy, lastUpdate); } ); }
/// <summary> /// Saves a friend as hired for the provided job and then returns that friend's avatar's DNA to the client /// </summary> /// <param name="message"></param> private void HireFriend(Message message, Guid sessionId) { mLogger.Debug("HireFriend: " + message.ToString()); if (message.Data.Count != 3) { mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 4, actual was " + message.Data.Count); return; } long facebookId; if (!long.TryParse(message.Data[1].ToString(), out facebookId)) { mLogger.Error("Dropping Message (" + message + "), expected Data[1] to be able to parse to long. Value: " + message.Data[1]); return; } Jobs job = (Jobs)Enum.Parse(typeof(Jobs), message.Data[2].ToString()); string jobName = job.ToString(); ServerAccount serverAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); FashionMinigameServiceAPI.GetGameData(serverAccount, jobName, delegate(XmlDocument resultXml) { XmlNode hiredFriendsListNode = resultXml.SelectSingleNode ( "//DataKey[@KeyName='" + jobName + "']" ); string dataValue; if (hiredFriendsListNode == null) { dataValue = facebookId.ToString(); } else { dataValue = String.Format("{0},{1}", hiredFriendsListNode.InnerText, facebookId.ToString()); } FashionMinigameServiceAPI.SetGameData(serverAccount, jobName, dataValue, delegate(XmlDocument responseXml) { VerifySuccess(responseXml); Action <List <object> > returnHiredFriend = delegate(List <object> responseData) { Message responseMessage = new Message(); responseData.Insert(0, message.Data[0]); // callback Id responseData.Insert(1, jobName); responseMessage.FashionGameHireFriend(responseData); SendMessageToClient(responseMessage, sessionId); }; ProcessHiredFriends(serverAccount, returnHiredFriend, new List <object>(), new long[] { facebookId }); }); }); }
private void BuildFashionGameLoadingInfo(Message message, Guid sessionId) { mLogger.Debug("BuildFashionGameLoadingInfo: " + message.ToString()); if (message.Data.Count < 1) { mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 2, actual was " + message.Data.Count); return; } // TODO: Hard coded values XmlDocument modelDefaultsXml = mServerStateMachine.ServerAssetRepository.GetXmlDna(new ItemId[] { new ItemId(135u), new ItemId(136u), new ItemId(137u) }); // TODO: Replace these items with the real station worker defaults XmlDocument stationWorkerDefaultsXml = mServerStateMachine.ServerAssetRepository.GetXmlDna(new ItemId[] { new ItemId(240u), new ItemId(244u) }); ServerAccount localUserServerAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); mEnergyManager.GetCurrentEnergyData(localUserServerAccount, delegate(float lastEnergy, float maxEnergy, DateTime lastUpdate) { FashionMinigameServiceAPI.GetGameData(localUserServerAccount, GameDataKeys.PLAYER_EXPERIENCE_KEY, delegate(XmlDocument resultXml) { XmlNode minigameUserDataNode = resultXml.SelectSingleNode("MiniGameUserData"); if (minigameUserDataNode == null) { throw new Exception("The server is returning playerData in an unexpected format: " + resultXml.OuterXml); } XmlNode xpNode = minigameUserDataNode.SelectSingleNode("//DataKey[@KeyName='" + GameDataKeys.PLAYER_EXPERIENCE_KEY + "']"); string xpString; if (xpNode != null) { xpString = xpNode.InnerText; } else // No experience node, this is a new user { xpString = "0"; } Message responseMessage = new Message(); List <object> responseData = new List <object>(); responseData.Add(message.Data[0]); // callback Id responseData.Add(modelDefaultsXml.OuterXml); responseData.Add(stationWorkerDefaultsXml.OuterXml); responseData.Add(lastEnergy); responseData.Add(maxEnergy); responseData.Add(lastUpdate.ToString()); responseData.Add(uint.Parse(xpString)); responseData.Add((uint)localUserServerAccount.EntourageSize); responseMessage.FashionGameLoadingInfoMessage(responseData); SendMessageToClient(responseMessage, sessionId); }); }); }