/// <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> /// the expected node for the item xml is the following: /// <item id="1061" name="106" appName="HANGOUT_FAMILY_Application_1" itemTypeName="Room Backdrop" buttonName="Two Fast Two Furious" description="Live life a quarter mile at a time" smallImageUrl="http://s3.amazonaws.com/HangoutDevFileBucket/48141004.jpg" mediumImageUrl="" largeImageUrl="http://s3.amazonaws.com/HangoutDevFileBucket/48141004.jpg" available="-1"> /// <Assets /> /// </item> /// </summary> /// <param name="receivedMessage"></param> private void ChangeBackground(Message receivedMessage) { mRoomBackgroundItemId = CheckType.TryAssignType <ItemId>(receivedMessage.Data[0]); List <ItemId> roomItems = UpdateRoomItems(); XmlDocument updatedRoomDna = RoomXmlUtil.CreateRoomDnaXml(this.RoomName, this.RoomType, roomItems); //update the database with the new items RoomManagerServiceAPI.UpdateRoomDnaService(this.RoomId, updatedRoomDna, delegate(XmlDocument xmlResponse) { XmlNode successNode = xmlResponse.SelectSingleNode("Success"); if (successNode != null && successNode.InnerText == "true") { XmlNode backgroundItemXml = mServerAssetRepository.GetXmlDna(new ItemId[] { mRoomBackgroundItemId }); List <object> backgroundChangeMessageData = new List <object>(); backgroundChangeMessageData.Add(backgroundItemXml.OuterXml); Message broadcastBackgroundChangeMessage = new Message(); broadcastBackgroundChangeMessage.UpdateObjectMessage(true, false, this.DistributedObjectId, (int)MessageSubType.ChangeBackground, backgroundChangeMessageData); BroadcastMessage(broadcastBackgroundChangeMessage); } else { StateServerAssert.Assert(new System.Exception("Error setting background in room on database.")); } } ); }
protected void GetRoomFromRoomIdService(RoomId roomId, System.Action <IServerDistributedRoom> getRoomCallback) { RoomManagerServiceAPI.GetRoomService(roomId, delegate(XmlDocument xmlResponse) { RoomProperties roomProperties = RoomXmlUtil.GetRoomPropertiesFromXml(xmlResponse, mServerStateMachine.ServerAssetRepository); IServerDistributedRoom serverDistributedRoom = CreateServerDistributedRoom(roomProperties); getRoomCallback(serverDistributedRoom); }); }
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; } }
/// <summary> /// This function creates the room on the database... /// ...and then uses AddRoomToManager to update the RoomManager class' internal data structures /// </summary> public virtual void CreateNewRoomInDatabase(Guid sessionId, string roomName, RoomType roomType, PrivacyLevel privacyLevel, System.Action <IServerDistributedRoom> createRoomFinishedCallback) { Action <XmlDocument> createRoomServiceCallback = delegate(XmlDocument xmlResponse) { RoomId roomId = null; XmlNode newRoomNode = xmlResponse.SelectSingleNode("Rooms/Room"); AccountId accountId = null; List <ItemId> itemIds = new List <ItemId>(); RoomXmlUtil.GetRoomInfoFromRoomXmlNode(newRoomNode, out accountId, out privacyLevel, out roomName, out roomId, out roomType, out itemIds); XmlDocument roomItemsDnaXml = mServerStateMachine.ServerAssetRepository.GetXmlDna(itemIds); IServerDistributedRoom newRoom = CreateServerDistributedRoom(accountId, roomName, roomId, roomType, privacyLevel, roomItemsDnaXml); AddRoomToRoomManager(newRoom); createRoomFinishedCallback(newRoom); }; CreateNewRoomInDatabaseService(sessionId, roomName, privacyLevel, createRoomServiceCallback); }
public static RoomProperties GetRoomPropertiesFromXml(XmlNode roomXmlNode, IServerAssetRepository serverAssetRepository) { RoomProperties returnRoomProperties = null; string roomName = string.Empty; RoomId roomId = null; RoomType roomType = RoomType.Default; List <ItemId> itemIds = new List <ItemId>(); AccountId accountId = null; PrivacyLevel privacyLevel = PrivacyLevel.Default; //if we find a room that's marked as Enabled="true", load it into memory if (RoomXmlUtil.GetRoomInfoFromRoomXmlNode(roomXmlNode, out accountId, out privacyLevel, out roomName, out roomId, out roomType, out itemIds)) { XmlDocument roomItemsDnaXml = serverAssetRepository.GetXmlDna(itemIds); returnRoomProperties = new RoomProperties(accountId, roomName, roomId, roomType, privacyLevel, roomItemsDnaXml); } return(returnRoomProperties); }