/// <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); }
private void AddUserSessionToRoom(Guid sessionId, IServerDistributedRoom room) { //look up ZoneId for DistributedObjectId ZoneId zoneId = mServerStateMachine.ServerObjectRepository.GetZone(room); //look up all DistributedObjectId's for ZoneId... this is done already when you process an open interest in a zone mServerStateMachine.ServerEngine.ProcessOpenZoneInterest(sessionId, zoneId); room.IncrementPopulation(sessionId); }
private void LeaveRoom(Guid sessionId, RoomId oldRoomId) { //lose interest in the zones that belong to the room the client is leaving IServerDistributedRoom serverDistributedRoomToLeave = null; if (mRoomIdToRoomDistributedObject.TryGetValue(oldRoomId, out serverDistributedRoomToLeave)) { LeaveRoom(sessionId, serverDistributedRoomToLeave); } }
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); }); }
public bool GetRoomDistributedObjectId(RoomId roomId, out DistributedObjectId distributedObjectId) { distributedObjectId = null; IServerDistributedRoom serverDistributedRoom = null; if (mRoomIdToRoomDistributedObject.TryGetValue(roomId, out serverDistributedRoom)) { distributedObjectId = serverDistributedRoom.DistributedObjectId; return(true); } return(false); }
virtual protected void GetRoomFromRoomId(RoomId roomId, System.Action <IServerDistributedRoom> getRoomCallback) { //if the new room doesn't exist in memory, we need to create it! IServerDistributedRoom serverDistributedRoom = null; if (!mRoomIdToRoomDistributedObject.TryGetValue(roomId, out serverDistributedRoom)) { GetRoomFromRoomIdService(roomId, getRoomCallback); } else { getRoomCallback(serverDistributedRoom); } }
private IServerDistributedRoom CreateServerDistributedRoom(RoomProperties roomProperties) { IServerDistributedRoom newServerDistributedRoom = null; switch (roomProperties.RoomType) { case RoomType.GreenScreenRoom: newServerDistributedRoom = new ServerDistributedGreenScreenRoom(mServerStateMachine.ServerObjectRepository, mServerStateMachine.ServerAssetRepository, roomProperties.AccountCreatingRoom, roomProperties.RoomName, roomProperties.RoomId, roomProperties.PrivacyLevel, mServerStateMachine.DistributedObjectIdManager.GetNewId(), roomProperties.RoomItemsXml); break; case RoomType.MiniGameRoom: newServerDistributedRoom = new ServerDistributedMiniGameRoom(mServerStateMachine.ServerObjectRepository, roomProperties.AccountCreatingRoom, roomProperties.RoomName, roomProperties.RoomId, roomProperties.PrivacyLevel, mServerStateMachine.DistributedObjectIdManager.GetNewId(), roomProperties.RoomItemsXml); break; } return(newServerDistributedRoom); }
public void LeaveRoom(Guid sessionId, IServerDistributedRoom serverDistributedRoomToLeave) { serverDistributedRoomToLeave.DecrementPopulation(sessionId); ZoneId zoneIdToLeave = mServerStateMachine.ServerObjectRepository.GetZone(serverDistributedRoomToLeave); List <ZoneId> zoneIdsToLeave = new List <ZoneId>(); zoneIdsToLeave.Add(zoneIdToLeave); mServerStateMachine.ServerEngine.ProcessCloseZoneInterest(sessionId, zoneIdsToLeave); List <DistributedObjectId> distributedObjectsAssociatedWithSession = mServerStateMachine.ServerObjectRepository.GetDistributedObjectIdsOwnedBySessionId(sessionId); //move any distributed objects belonging to the client from the old zone to the new zone foreach (DistributedObjectId distributedObjectId in distributedObjectsAssociatedWithSession) { mServerStateMachine.ServerEngine.ProcessZoneChange((ServerDistributedObject)mServerStateMachine.ServerObjectRepository.GetObject(distributedObjectId), ZoneId.LimboZone); } }
/// <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 void ProcessDisconnectSession(Guid sessionIdToClose) { IServerDistributedRoom roomToLeave = mRoomManager.FindRoomForUser(sessionIdToClose); if (roomToLeave != null) { mRoomManager.LeaveRoom(sessionIdToClose, roomToLeave); } ServerAccount serverAccount = mSessionManager.GetServerAccountFromSessionId(sessionIdToClose); if (serverAccount != null) { BossServerAPI.RemoveSession(serverAccount.AccountId, sessionIdToClose.ToString(), delegate(XmlDocument xmlDocument) { }); } BossServerAPI.UpdateStateServer(mStateServerId, mServerMessageProcessor.ServerReflector.GetNumConnections(), "1", delegate(XmlDocument xmlDocument) { }); mServerEngine.ProcessDisconnectSession(sessionIdToClose); }
/// <summary> /// This function creates in ram the room distributed object for the RoomManager /// roomDnaXmlNode is expected to be in the format of: /// <RoomDna RoomName="" RoomType=""> /// <Items>1, 2, 3, 4 </Items> /// </RoomData> /// </summary> private void AddRoomToRoomManager(IServerDistributedRoom newServerDistributedRoom) { //create a new zone Id for the room ZoneId zoneId = mServerStateMachine.ZoneManager.GetNewZoneId(); //register the new room with the server object repository mServerStateMachine.ServerObjectRepository.AddObject(newServerDistributedRoom); //register the new room with the zone mServerStateMachine.ServerEngine.ProcessZoneChange(newServerDistributedRoom, zoneId); //add the new room to our dictionary listing indexed by room Id if (!mRoomIdToRoomDistributedObject.ContainsKey(newServerDistributedRoom.RoomId)) { mRoomIdToRoomDistributedObject.Add(newServerDistributedRoom.RoomId, newServerDistributedRoom); } else { StateServerAssert.Assert(new System.Exception("Trying to create a room that has a non-unique RoomId.")); } }
/// <summary> /// Removes the specified room from the RoomManager memory /// </summary> /// <param name="roomId"></param> private void DeleteRoomInRoomManager(RoomId roomId) { IServerDistributedRoom serverDistributedRoomForDelete = null; if (mRoomIdToRoomDistributedObject.TryGetValue(roomId, out serverDistributedRoomForDelete)) { ZoneId zoneId = mServerStateMachine.ServerObjectRepository.GetZone(serverDistributedRoomForDelete); List <Guid> sessionIdsToLeaveRoom = new List <Guid>(mServerStateMachine.SessionManager.GetSessionIdsInterestedInZoneId(zoneId)); foreach (Guid sessionId in sessionIdsToLeaveRoom) { LeaveRoom(sessionId, serverDistributedRoomForDelete); } //unregister the room with the zone mServerStateMachine.ServerEngine.RemoveObjectFromServer(serverDistributedRoomForDelete); //remove roomId from dictionary mRoomIdToRoomDistributedObject.Remove(roomId); } }
private Message GenerateSendClientAvailableRoomsMessage(List <IServerDistributedRoom> rooms) { List <object> messageData = new List <object>(); foreach (IServerDistributedRoom room in rooms) { //if this room is cached locally, get the most up to date info from the server.. eventually this info should be updated via services IServerDistributedRoom cachedRoom = null; if (mRoomIdToRoomDistributedObject.TryGetValue(room.RoomId, out cachedRoom)) { messageData.Add(new KeyValuePair <RoomId, List <object> >(cachedRoom.RoomId, cachedRoom.Data)); } else { messageData.Add(new KeyValuePair <RoomId, List <object> >(room.RoomId, room.Data)); } } Message sendClientAvailableRoomsMessage = new Message(); sendClientAvailableRoomsMessage.Callback = (int)MessageSubType.ReceiveRooms; sendClientAvailableRoomsMessage.RoomMessage(messageData); return(sendClientAvailableRoomsMessage); }