private void ContinueStateMachineSetup() { mZoneManager = new ZoneIdManager(); mSessionManager = new SessionManager(); mUsersManager = new UsersManager(this); mServerObjectRepository = new ServerObjectRepository(this); mDistributedObjectIdManager = new DistributedObjectIdManager(); mServerEngine = new ServerEngine(mSessionManager, mServerObjectRepository, SendMessageToReflector); mConnectionHandler = new ConnectionHandler(this); // Extensions mRoomManager = new RoomManager(this); mFashionMinigameServer = new FashionMinigameServer(this); mFriendsManager = new FriendsManager(this); mFriendsManager.mFacebookFriendsReceivedEvent += mFashionMinigameServer.FacebookFriendsReady; mAvatarManager = new AvatarManager(this); mPaymentItemsManager = new PaymentItemsManager(this); mEscrowManager = new EscrowManager(this); mServerProcessingLoop.AddServerLoopWorker(RemoteCallToService.CallToServiceCallbackManager); mAdminManager = new AdminManager(this); // This needs to be called to instantiate the instance of TextFilter TextFilter tf = TextFilter.Instance; //this should be the last thing we create in our startup sequence!! the server message processor kicks off a loop to process incoming messages mServerMessageProcessor = new ServerMessageProcessor(this); mServerProcessingLoop.AddServerLoopWorker(mServerMessageProcessor.ServerReflector); }
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); } ); }
/// <summary> /// On level up, the user gains a little more max energy and their energy is refilled /// </summary> public void UserLeveledUp(ServerAccount account) { GetCurrentEnergyData(account, delegate(float energy, float maxEnergy, DateTime rechargeDate) { // not worried about this silly chain of messages because the client isn't waiting on it float newMaxEnergy = maxEnergy + Energy.MAX_ENERGY_INCREASE_PER_LEVEL; FashionMinigameServiceAPI.SetGameData(account, PLAYER_MAX_ENERGY, newMaxEnergy, delegate(XmlDocument maxEnergyResult) { FashionMinigameServer.VerifySuccess(maxEnergyResult); FashionMinigameServiceAPI.SetGameData(account, ENERGY_REGEN_DATE, DateTime.UtcNow, delegate(XmlDocument dateResult) { FashionMinigameServer.VerifySuccess(dateResult); FashionMinigameServiceAPI.SetGameData(account, PLAYER_ENERGY_KEY, newMaxEnergy.ToString(), delegate(XmlDocument currentEnergyResult) { FashionMinigameServer.VerifySuccess(currentEnergyResult); }); }); }); }); }