#pragma once #include "V8Tree/Instance.h" #include "V8Tree/Service.h" namespace RBX { extern const char* const sPointsService; class PointsService : public DescribedCreatable , public Service { public: typedef std::pair)>, boost::function > AwardPointYieldFunction; typedef std::vector AwardPointYieldFunctions; typedef std::pair PointRequestValue; typedef boost::unordered_map PointRequestMap; private: typedef DescribedCreatable Super; rbx::signals::scoped_connection heartbeatSignalConnection; boost::mutex batchAwardPointsMutex; PointRequestMap batchAwardPointRequests; int numOfAwardPointCallsLastMinute; double timeSinceLastMaxAwardPointReset; double timeSinceLastAwardPointCall; bool shouldBatchAwardPoints; bool isAtAwardPointsLimit(); void onHeartbeat(const Heartbeat& heartbeat); static void startAwardPointsBatching(weak_ptr weakDm); //////////////////////////////////////////////////// // Instance /*override*/ void onServiceProvider(ServiceProvider* oldProvider, ServiceProvider* newProvider); bool canUseService(); void internalGetPointBalance(int userId, int placeId, shared_ptr methodName, shared_ptr keyToReturn, boost::function resumeFunction, boost::function errorFunction); public: PointsService(); rbx::remote_signal pointsAwardedSignal; void getUserPointBalanceInUniverse(int userId, boost::function resumeFunction, boost::function errorFunction); void getUserPointBalance(int userId, boost::function resumeFunction, boost::function errorFunction); int getAwardableBalance(); void awardPoints(int userId, int amount, boost::function)> resumeFunction, boost::function errorFunction); void firePointsAwardedSignal(int userId, int amount, int userBalanceInUniverse, int userBalance); bool doBatchAwardPoints(); void resetPointAwardCount(); void listenToHeartbeat(); }; }