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); }); }); }
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); }); }
private void GetAvatarsForJob(Message message, Guid sessionId) { mLogger.Debug("GetAvatarsForJob: " + message.ToString()); if (message.Data.Count < 2) { mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 3, actual was " + message.Data.Count); return; } Jobs avatarJob = (Jobs)Enum.Parse(typeof(Jobs), message.Data[1].ToString()); ServerAccount localUserServerAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); Action <List <object> > returnFunc = delegate(List <object> resultData) { Message responseMessage = new Message(); resultData.Insert(0, message.Data[0]); // callbackId resultData.Insert(1, avatarJob.ToString()); responseMessage.FashionGameModelAssetMessage(resultData); SendMessageToClient(responseMessage, sessionId); }; if (avatarJob == Jobs.Model) { // Model is the same as other jobs, but it also has a listing for the local user's avatar GetFashionModelAvatars(localUserServerAccount, sessionId, returnFunc); } else { FashionMinigameServiceAPI.GetHiredFriendsForJob(localUserServerAccount, avatarJob, delegate(ICollection <long> hiredFriendIds) { ProcessHiredFriends(localUserServerAccount, returnFunc, new List <object>(), hiredFriendIds); }); } }
public ServerAccount GetServerAccountFromSessionId(Guid sessionId) { ServerAccount serverAccount = null; mSessionIdsToServerAccounts.TryGetValue(sessionId, out serverAccount); return(serverAccount); }
private void GetFriendsToHire(Message message, Guid sessionId) { mLogger.Debug("GetFriendsToHire: " + message.ToString()); if (message.Data.Count < 2) { mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 2, actual was " + message.Data.Count); return; } Jobs job = (Jobs)Enum.Parse(typeof(Jobs), message.Data[1].ToString()); ServerAccount serverAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); serverAccount.FacebookFriendsReadyCallbackId = (ulong)message.Data[0]; XmlDocument resultXml = new XmlDocument(); XmlElement rootElement = resultXml.CreateElement("FacebookFriends"); serverAccount.FacebookFriendsRequested = true; if (!serverAccount.FacebookFriendsPending) { FacebookFriendsReady(serverAccount, sessionId); } else { mLogger.Debug("Waiting for facebook friends to return for account: " + serverAccount.AccountId.ToString()); } }
private void UpdateAccountDataForUser(ServerAccount serverAccount, UserProperties userProperties, System.Action <XmlDocument> finishedUpdatingAccountDataCallback) { serverAccount.UserProperties = userProperties; XmlDocument accountDataXml = AccountsXmlUtil.CreateAccountDataXml(serverAccount); AccountsServiceAPI.UpdateAccountData(serverAccount.AccountId, accountDataXml, finishedUpdatingAccountDataCallback); }
public void CreateAccountForUser(string fbAccountId, string fbSessionKey, string nickName, string firstName, string lastName, string userIpAddress, string campaignId, string referrerId, Action <ServerAccount> createAccountForUserCallback) { mLogger.Debug(String.Format("CreateAccountForUser {0} {1} {2} {3} {4} {5} {6} {7}", fbAccountId, fbSessionKey, nickName, firstName, lastName, userIpAddress, campaignId, referrerId)); Action <XmlDocument> createServerAccountServiceCallback = delegate(XmlDocument receivedXmlCreateNewAccount) { XmlNode newAccountXmlNode = receivedXmlCreateNewAccount.SelectSingleNode("Accounts/Account"); //if we get a null xml node when trying to create an account, we need to throw an error if (newAccountXmlNode == null) { StateServerAssert.Assert(new System.Exception("Error: unable to create a new account.. do you have a valid facebook Account Id, Session key, nickname, firstname, lastname, campaignId, and referredId? Check your client data file! Returned Xml: " + receivedXmlCreateNewAccount.OuterXml)); createAccountForUserCallback(null); } else { ServerAccount serverAccount = AccountsXmlUtil.GetAccountFromXml(newAccountXmlNode); serverAccount.IpAddress = userIpAddress; SaveCurrentAccountData(serverAccount); CreatePaymentItemAccountForUser(serverAccount, userIpAddress, createAccountForUserCallback); Metrics.Log(LogGlobals.CATEGORY_ACCOUNT, LogGlobals.EVENT_ACCOUNT_CREATED, LogGlobals.ACCOUNT_ID_LABEL, serverAccount.AccountId.ToString(), serverAccount.AccountId.ToString()); } }; CallCreateServerAccountService(fbAccountId, fbSessionKey, nickName, firstName, lastName, userIpAddress, campaignId, referrerId, createServerAccountServiceCallback); }
public static void GetHiredFriendsForJob(ServerAccount serverAccount, IEnumerable <Jobs> jobs, Action <ICollection <long> > result) { List <string> jobNames = new List <string>(); foreach (Jobs job in jobs) { jobNames.Add(job.ToString()); } GetGameData(serverAccount, jobNames.ToArray(), delegate(XmlDocument hiredFriendsXml) { List <long> resultFriends = new List <long>(); foreach (string jobName in jobNames) { XmlNode hiredFriendsListNode = hiredFriendsXml.SelectSingleNode ( "//DataKey[@KeyName='" + jobName + "']" ); if (hiredFriendsListNode == null) { // No friends for this Job continue; } foreach (string hiredFriendId in hiredFriendsListNode.InnerText.Split(',')) { resultFriends.Add(long.Parse(hiredFriendId)); } } result(resultFriends); }); }
public static void GetGameData(ServerAccount serverAccount, string[] dataKeys, Action <XmlDocument> result) { if (mMockGetGameData == null) { string dataKeysCsv = String.Join(",", dataKeys); mLogger.DebugFormat("FashionMinigameServiceAPI - MiniGames.GetMiniGameUserData called accountId={0} dataKeys={1}", serverAccount.AccountId, dataKeysCsv); WebServiceRequest setDataService = new WebServiceRequest(mWebServicesBaseUrl, "MiniGames", "GetMiniGameUserData"); setDataService.Method = FormMethod.POST; setDataService.AddParam("accountId", serverAccount.AccountId.ToString()); setDataService.AddParam("miniGameId", FASHION_MINIGAME_SERVICE_ID.ToString()); setDataService.AddParam("miniGameName", FASHION_MINIGAME_NAME); setDataService.AddParam("dataKeyCSVList", dataKeysCsv); setDataService.GetWebResponseAsync(delegate(XmlDocument response) { mLogger.DebugFormat("FashionMinigameServiceAPI - MiniGames.GetMiniGameUserData responded accountId={0} xmlResponse={1}", serverAccount.AccountId, response.OuterXml); result(response); }); } else { mMockGetGameData(serverAccount, dataKeys, result); } }
/// <summary> /// the delegate returns null if there was no default room found /// will also throw an error if the default room is not enabled in the xml or if the xml is not formatted correctly /// this does NOT add the room to the RoomManager cache /// </summary> /// <param name="userAccount"></param> /// <param name="getDefaultRoomFinishedCallback"></param> private void GetDefaultRoom(ServerAccount userAccount, System.Action <IServerDistributedRoom> getDefaultRoomFinishedCallback) { Action <XmlDocument> getDefaultRoomServiceCallback = delegate(XmlDocument xmlResponse) { IServerDistributedRoom returnedDefaultRoom = null; XmlNode defaultRoomXmlNode = xmlResponse.SelectSingleNode("Rooms/Room"); //if the default Room is null, we want to create a new room and set that as the default room if (defaultRoomXmlNode != null) { RoomProperties roomProperties = RoomXmlUtil.GetRoomPropertiesFromXml(defaultRoomXmlNode, mServerStateMachine.ServerAssetRepository); IServerDistributedRoom defaultRoom = CreateServerDistributedRoom(roomProperties); if (defaultRoom == null) { StateServerAssert.Assert(new System.Exception("Error: the default room is either not enabled or does not contain proper data: " + defaultRoomXmlNode.OuterXml)); } else { //if the user's default room is already cached, we just return the room object we have stored // otherwise we add the newly created defaultRoom to the roomManager cache if (!mRoomIdToRoomDistributedObject.TryGetValue(defaultRoom.RoomId, out returnedDefaultRoom)) { returnedDefaultRoom = defaultRoom; } } } getDefaultRoomFinishedCallback(returnedDefaultRoom); }; RoomManagerServiceAPI.GetDefaultRoomService(userAccount.AccountId, getDefaultRoomServiceCallback); }
/// <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> /// this function returns back the default room for a user through the delegate OR /// if the user doesn't have a default room, it creates a room, and sets it as the default room for the user /// this does NOT cache any rooms as a side effect! /// </summary> public void GetOrCreateDefaultRoomForUser(Guid sessionId, ServerAccount userAccount, Action <IServerDistributedRoom> createDefaultRoomFinishedCallback) { GetDefaultRoom(userAccount, delegate(IServerDistributedRoom defaultRoom) { if (defaultRoom == null) { string roomName = userAccount.FirstName + " " + userAccount.LastName; if (roomName == string.Empty) { roomName = userAccount.Nickname; } CreateNewRoomInDatabase(sessionId, roomName, RoomType.GreenScreenRoom, PrivacyLevel.Private, delegate(IServerDistributedRoom newRoom) { if (newRoom != null) { SetDefaultRoom(userAccount, newRoom.RoomId); } createDefaultRoomFinishedCallback(newRoom); } ); } else { createDefaultRoomFinishedCallback(defaultRoom); } } ); }
/// <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); } ); }
public void SaveUserAccountForClient(Message receivedMessage, Guid senderId) { UserProperties userProperties = CheckType.TryAssignType <UserProperties>(receivedMessage.Data[0]); ServerAccount serverAccount = mSessionManager.GetServerAccountFromSessionId(senderId); serverAccount.UserProperties = userProperties; serverAccount.SaveCurrentAccountData(delegate(XmlDocument returnedXmlDocument){}); }
/// <summary> /// Get the PaymentItems User information /// </summary> /// <param name="serverAccount">The account object </param> /// <param name="userIpAddress">The ipAddress of the user</param> /// <returns></returns> public UserInfo GetPaymentItemsUserInfo(ServerAccount serverAccount, string userIpAddress) { UserInfo userInfo = new UserInfo(); userInfo.Name = String.Format("PI{0}", serverAccount.AccountId.ToString()); userInfo.ExternalKey = serverAccount.Nickname; userInfo.IPAddress = userIpAddress; return(userInfo); }
public ServerAccount GetServerAccountFromAccountId(AccountId accountId) { ServerAccount serverAccount = null; if (accountId != null) { mAccountIdsToServerAccounts.TryGetValue(accountId, out serverAccount); } return(serverAccount); }
public void GetAccountForUser(string fbAccountId, string fbSessionKey, string nickName, string firstName, string lastName, string userIpAddress, string campaignId, string referrerId, Action <ServerAccount> getAccountForUserCallback) { Action <XmlDocument> getAccountForFacebookIdCallback = delegate(XmlDocument receivedXmlGetAccount) { //<Accounts> // <Account accountId="" fbaccountid="" tfaccountId="" nickname="" firstname="" lastname=""/> //</Accounts> XmlNode accountXmlNode = receivedXmlGetAccount.SelectSingleNode("Accounts/Account"); if (accountXmlNode != null) { ServerAccount serverAccount = AccountsXmlUtil.GetAccountFromXml(accountXmlNode); if (serverAccount != null) { serverAccount.IpAddress = userIpAddress; mLogger.Info("GetAccountForUser, ServerAccount: " + serverAccount.ToString()); serverAccount.SaveCurrentAccountData(delegate(XmlDocument returnedXmlDocument) { }); if (serverAccount.PaymentItemUserId.Trim().Length == 0) { mLogger.Debug("GetAccountForUser.CreatePaymentItemsAccount"); CreatePaymentItemAccountForUser(serverAccount, userIpAddress, getAccountForUserCallback); } else { mLogger.Debug("GetAccountForUser, calling callback"); getAccountForUserCallback(serverAccount); } } else { StateServerAssert.Assert(new Exception("Could not extract the account from the Xml")); } } else { CreateAccountForUser(fbAccountId, fbSessionKey, nickName, firstName, lastName, userIpAddress, campaignId, referrerId, delegate(ServerAccount newServerAccount) { getAccountForUserCallback(newServerAccount); } ); } }; try { CallGetServerAccountForFacebookIdService(fbAccountId, getAccountForFacebookIdCallback); } catch (System.Exception) { mLogger.Warn("Could not get an account for facebook id: " + fbAccountId); getAccountForUserCallback(null); } }
public void RefillEnergy(ServerAccount account) { GetCurrentEnergyData ( account, delegate(float lastEnergy, float maxEnergy, DateTime lastUpdate) { SetEnergy(account, maxEnergy); } ); }
/// <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); }); }); }
/// <summary> /// /// </summary> /// <param name="serverAccount"></param> /// <param name="getAvatarForUserServiceCallback"></param> public static void GetAvatarForUser(ServerAccount serverAccount, Action <XmlDocument> getAvatarForUserServiceCallback) { mLogger.DebugFormat("GetAvatarForUser called accountId={0}", serverAccount.AccountId); WebServiceRequest getAvatarList = new WebServiceRequest(StateServerConfig.WebServicesBaseUrl, "Avatars", "GetAvatars"); getAvatarList.AddParam(kAccountId, serverAccount.AccountId.ToString()); getAvatarList.GetWebResponseAsync(delegate(XmlDocument xmlResponse) { mLogger.DebugFormat("GetAvatarForUser responded accountId={0}, xmlReponse={1}", serverAccount.AccountId, xmlResponse.OuterXml); getAvatarForUserServiceCallback(xmlResponse); }); }
/// <summary> /// Calling the Accounts service to update the Hangout PaymentItems information /// </summary> /// <param name="serverAccount">The account object </param> /// <param name="accountForUserCallback">The callback to call when finished</param> public void UpdateServerPaymentItemsAccount(ServerAccount serverAccount, Action <ServerAccount> accountForUserCallback) { Action <XmlDocument> updatePaymentItemAccountCallback = delegate(XmlDocument receivedXmlUpdatePaymentItemsAccount) { if (accountForUserCallback != null) { accountForUserCallback(serverAccount); } }; AccountsServiceAPI.UpdateServerPaymentItemsAccount(serverAccount.AccountId.ToString(), serverAccount.PaymentItemUserId, serverAccount.PaymentItemSecureKey, updatePaymentItemAccountCallback); }
/// <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); }); }
/// <summary> /// Removes the room from the database and also removes it from the RoomManager memory /// </summary> /// <param name="roomId"></param> /// <param name="roomDisabledInDatabaseFinishedCallback"></param> private void DisableRoomInDatabase(RoomId roomId, Guid sessionId, System.Action <bool> roomDisabledInDatabaseFinishedCallback) { ServerAccount account = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); System.Action <XmlDocument> disableRoomServiceCallback = delegate(XmlDocument xmlResponse) { //parse true / false out of xml XmlNode successNode = xmlResponse.SelectSingleNode("Success"); bool returnValue = Convert.ToBoolean(successNode.InnerXml); roomDisabledInDatabaseFinishedCallback(returnValue); }; RoomManagerServiceAPI.DisableRoomService(account.AccountId, roomId, disableRoomServiceCallback); }
protected virtual void SendClientAvailableRooms(Guid sessionId, MessageSubType roomRequestType) { ServerAccount account = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); Action <XmlDocument> getAvailableRoomsCallback = delegate(XmlDocument xmlResponse) { List <IServerDistributedRoom> availableRooms = new List <IServerDistributedRoom>(); List <RoomProperties> roomPropertiesList = RoomXmlUtil.GetRoomsPropertiesFromXml(xmlResponse, mServerStateMachine.ServerAssetRepository); foreach (RoomProperties roomProperties in roomPropertiesList) { availableRooms.Add(CreateServerDistributedRoom(roomProperties)); } Message availableRoomsMessage = GenerateSendClientAvailableRoomsMessage(availableRooms); //send message to client SendMessageToClient(availableRoomsMessage, sessionId); }; switch (roomRequestType) { case MessageSubType.ClientOwnedRooms: RoomManagerServiceAPI.GetSessionOwnedRoomsService(account.AccountId, getAvailableRoomsCallback); break; case MessageSubType.PublicRooms: RoomManagerServiceAPI.GetAllSystemRoomsService(getAvailableRoomsCallback); break; case MessageSubType.FriendsRooms: IList <AccountId> friendAccountIds = Functionals.MapImmediate <FacebookFriendInfo, AccountId> ( delegate(FacebookFriendInfo facebookFriendInfo) { return(facebookFriendInfo.AccountId); }, account.HangoutFacebookFriends ); RoomManagerServiceAPI.GetSessionOwnedRoomsWithPrivacyService(friendAccountIds, PrivacyLevel.Default, getAvailableRoomsCallback); break; default: //Console.WriteLine("be patient! not implemented yet!"); List <IServerDistributedRoom> availableRooms = new List <IServerDistributedRoom>(); Message availableRoomsMessage = GenerateSendClientAvailableRoomsMessage(availableRooms); //send message to client SendMessageToClient(availableRoomsMessage, sessionId); break; } }
private void SetDefaultRoom(ServerAccount userAccount, RoomId roomId) { WebServiceRequest setDefaultRoomService = new WebServiceRequest(StateServerConfig.WebServicesBaseUrl, "Rooms", "SetDefaultRoom"); setDefaultRoomService.AddParam("accountId", userAccount.AccountId.ToString()); setDefaultRoomService.AddParam("roomId", roomId.ToString()); Action <XmlDocument> setDefaultRoomServiceCallback = delegate(XmlDocument xmlResponse) { //TODO: error checking? }; setDefaultRoomService.GetWebResponseAsync(setDefaultRoomServiceCallback); }
/// <summary> /// After heading back from the db, now process the xml to add up coins, /// then clear the escrow db for this account. /// </summary> /// <param name="serverStateMachine"></param> /// <param name="serverAccount"></param> /// <param name="responseXml"></param> private void AwardMinigameCoins(ServerAccount serverAccount, XmlDocument responseXml, EscrowType escrowType, Guid sessionId) { int totalCoins = EscrowXmlUtil.GetTotalCoins(responseXml); // Clamp to max coins totalCoins = Math.Min(MAX_COINS, totalCoins); if (totalCoins <= 0) { // No coins to award, we are done. return; } // Ok, now process the coins ProcessCoinPayment(serverAccount, totalCoins, escrowType, sessionId); }
public void UseEnergy(Message message, Guid sessionId) { if (!FashionMinigameServer.VerifyMessageData(message, 2, mLogger)) { // Drop the message return; } ServerAccount serverAccount = mGuidToServerAccount(sessionId); float energyToUse = CheckType.TryAssignType <float>(message.Data[1]); GetCurrentEnergyData ( serverAccount, delegate(float lastEnergy, float maxEnergy, DateTime lastUpdate) { List <object> responseData = new List <object>(); responseData.Add(message.Data[0]); // callback Id float energy = Energy.CalculateCurrentEnergy(maxEnergy, lastEnergy, lastUpdate); if (energy >= energyToUse) { float newEnergy = energy - energyToUse; responseData.Add(Energy.UseRequestResult.Success.ToString()); responseData.Add(newEnergy.ToString()); responseData.Add(maxEnergy.ToString()); if (energy == maxEnergy) { SetEnergyRegenDate(serverAccount, DateTime.UtcNow); responseData.Add(DateTime.UtcNow.ToString()); } else { responseData.Add(lastUpdate.ToString()); } SetEnergy(serverAccount, newEnergy); } else { responseData.Add(Energy.UseRequestResult.NotEnoughEnergy.ToString()); } Message responseMessage = new Message(MessageType.FashionMinigame, responseData); mSendMessageToClientCallback(responseMessage, sessionId); } ); }
private void LoginError(Guid sessionId, ErrorIndex errorIndex, MessageSubType errorActionType) { ServerAccount serverAccount = mSessionManager.GetServerAccountFromSessionId(sessionId); string accountId = "unknown account"; if (serverAccount != null) { accountId = serverAccount.AccountId.ToString(); } mLogger.Warn(String.Format("LoginError | sessionId={0} | accountId={1}", sessionId, accountId)); Metrics.Log(LogGlobals.CATEGORY_CONNECTION, LogGlobals.EVENT_LOGIN, LogGlobals.LOGIN_FAILED, accountId); Message loginErrorMessage = StateServerError.ErrorToUser(errorIndex, errorActionType); SendMessageToReflector(loginErrorMessage, sessionId); DisconnectUser(sessionId); }
private void SetPlayerGameData(Message message, Guid sessionId) { mLogger.Debug("SetPlayerGameData: " + message.ToString()); if (message.Data.Count < 2) { mLogger.Error("Dropping Message (" + message + "), expected Data to be Count == 3, actual was " + message.Data.Count); return; } string dataKey = CheckType.TryAssignType <string>(message.Data[0]); string dataValue = CheckType.TryAssignType <string>(message.Data[1]); ServerAccount serverAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); FashionMinigameServiceAPI.SetGameData(serverAccount, dataKey, dataValue, VerifySuccess); }