public ServerMessageProcessor(ServerStateMachine serverStateMachine) { mLogger = LogManager.GetLogger("ServerMessageProcessor"); mServerStateMachine = serverStateMachine; mServerReflector = new ServerReflector(mServerStateMachine.ConnectionHandler.Disconnect, ReceiveMessageFromReflector); mServerReflector.StartServerReflector(StateServerConfig.ServerIp, int.Parse(StateServerConfig.ServerPort)); // Tell boss server that this server is online BossServerAPI.InitStateServer(StateServerConfig.ServerIp, StateServerConfig.ServerPort, delegate(XmlDocument xmlResponse) { XmlNode stateServerNode = xmlResponse.SelectSingleNode("StateServerId"); if (stateServerNode != null) { string stateServerId = stateServerNode.InnerText; serverStateMachine.StateServerId = stateServerId; mLogger.InfoFormat("Registered with Boss Server as stateserver id = {0}", stateServerId); } else { mLogger.Error("Received an invalid response from BossServer.InitStateServer: " + xmlResponse.OuterXml); } }); //TODO: uncomment this to enable admin console //mAdminReflector = new ServerReflector(Disconnect, ReceiveMessageFromReflector); //mAdminReflector.StartServerReflector(9090); //CallToService getFacebookUsers = new CallToService(StateServerConfig.WebServicesBaseUrl + "Facebook/GetTestUsers"); //getFacebookUsers.Send(); //XmlDocument response = getFacebookUsers.ServiceResponse; //Console.WriteLine(getFacebookUsers.ServiceResponse.OuterXml); }
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); }
protected void JoinRoom(Guid sessionId, RoomId newRoomId, Hangout.Shared.Action userJoinedRoomCallback) { GetRoomFromRoomId(newRoomId, delegate(IServerDistributedRoom serverDistributedRoomToJoin) { if (serverDistributedRoomToJoin != null) { if (!mRoomIdToRoomDistributedObject.ContainsKey(serverDistributedRoomToJoin.RoomId)) { AddRoomToRoomManager(serverDistributedRoomToJoin); } List <DistributedObjectId> distributedObjectsAssociatedWithSession = mServerStateMachine.ServerObjectRepository.GetDistributedObjectIdsOwnedBySessionId(sessionId); //find the zone for the new room the client wants to join ZoneId zoneIdToJoin = mServerStateMachine.ServerObjectRepository.GetZone(serverDistributedRoomToJoin); SendMessageToClient(BeginLoadingRoomMessage(newRoomId), sessionId); //open interest in the zones that the new room belongs to AddUserSessionToRoom(sessionId, serverDistributedRoomToJoin); //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), zoneIdToJoin); } // Save room id as LastRoomId for account ServerAccount account = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); account.LastRoomId = newRoomId; if (account != null) { account.UserProperties.SetProperty(UserAccountProperties.LastRoomId, newRoomId); account.SaveCurrentAccountData(delegate(XmlDocument returnedXml) { }); } BossServerAPI.UpdateSession(account.AccountId, sessionId.ToString(), "1", zoneIdToJoin.ToString(), mServerStateMachine.StateServerId, delegate(XmlDocument xmlDocument) { }); } userJoinedRoomCallback(); } ); }
/// <summary> /// Called by ConnectionHandler on successful login /// </summary> /// <param name="sessionId"></param> /// <param name="userAccount"></param> /// <param name="facebookSessionKey"></param> /// <param name="defaultAvatarId"></param> public void ProcessUserLogin(Guid sessionId, ServerAccount userAccount, string facebookSessionKey, AvatarId defaultAvatarId, Stopwatch loginTimer) { mSessionManager.AddSession(sessionId, userAccount); BossServerAPI.RegisterNewSession(userAccount.AccountId, sessionId.ToString(), "1", ZoneId.LimboZone.ToString(), mStateServerId, delegate(XmlDocument xmlDocument) { }); BossServerAPI.UpdateStateServer(mStateServerId, mServerMessageProcessor.ServerReflector.GetNumConnections(), "1", delegate(XmlDocument xmlDocument) { }); mAvatarManager.GetAvatar(sessionId, ZoneId.LimboZone, userAccount, defaultAvatarId, delegate(bool successfullyGotAvatar) { //send an error message to the client if we can't get or create an avatar if (successfullyGotAvatar == false) { LoginError(sessionId, ErrorIndex.CannotGetOrCreateAvatar, MessageSubType.UserLoginGetOrCreateAvatarError); } else { // We got all the required data for the avatar. Send a login success message. // Check for the room and get the facebook friends in the background, as these calls take too long and aren't required to let the user continue. LoginSuccess(sessionId, loginTimer); // Check if a user has a default room, and create a room for the user if it doesn't exist mRoomManager.GetOrCreateDefaultRoomForUser(sessionId, userAccount, delegate(IServerDistributedRoom room) { if (room == null) { //send an error message to the client if we can't get or create a room LoginError(sessionId, ErrorIndex.CannotGetOrCreateRoom, MessageSubType.UserLoginGetOrCreateRoomError); } else { // Get facebook friends, and cache it on the account. We have to do this now before the session id for facebook expires mFriendsManager.GetAllFacebookFriendsForUser(sessionId, userAccount.FacebookAccountId, facebookSessionKey, delegate(List <FacebookFriendInfo> friendInfos) { userAccount.AddFacebookFriends(friendInfos); }); } }); } }); }