Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* not an actual program, just an idea I had */
- #define QUIT_TIME 300 /* seconds after join */
- #define MAX_LEAVES /* maximum count of leaves allowed */
- class user{
- public:
- std::string userName;
- uint32_t userID; /* 2^32 values for users is enough,
- we do not expect half of the population to play this game */
- uint16_t mapID; /* 65536 values to identify map is enough */
- uint16_t lastMapID;
- uint8_t leaveCount; /* 256 values to keep track of leaves is enough */
- uint64_t joinTime; /* same time as linux epoch */
- uint64_t leaveTime;
- ... /* more variables for user */
- };
- /**
- * @brief check if user quits before certain time
- * @param pointer to user
- * @return true if user quits before QUIT_TIME
- */
- bool quitAfterJoin(user *usr){
- /* if user leaves in first 5 minutes after join, time can be changed */
- if(abs(user->joinTime - user->leaveTime) < QUIT_TIME){
- /* set last map ID and retur flag that user quit before certain time */
- usr->lastMapID = map.ID;
- if(usr->lastMapID == usr->mapID){
- usr->leaveCount++;
- return true;
- }
- }
- return false;
- }
- /**
- * @brief function called after user joins in the game
- * @param pointer to user
- * @return true if join is successful
- */
- bool join(user *usr){
- usr->mapID = map.ID;
- ... /* etc. */
- }
- /**
- * @brief overloaded function to join with preferences
- * @param mapID mapID which user does not want to join
- * @return true if joining was successful
- */
- bool tryToJoin(uint16_t mapID){
- /* exclude map from list of possible maps */
- excludeMap(mapID);
- /* other operations before joining */
- ...
- }
- /**
- * @brief default function to join without preferences
- * @param mapID mapID which user does not want to join
- * @return true if joining was successful
- */
- bool tryToJoin(){
- /* normal joining procedure */
- ...
- }
- /**
- * @brief user joins Q
- * @param pointer to user
- * @return true if queueing up is successful
- */
- bool queueUp(user *usr){
- ... /* some preparations */
- /* if user quits game before certain time, we can be sure he does not want to play
- in that game, therefore we will NOT match him in that game
- */
- try{
- if(usr->leaveCount > MAX_LEAVES){
- /* try to join excluding this certain map */
- tryToJoin(usr->lastMapID);
- } else {
- tryToJoin();
- }
- }
- catch{
- /* procedure that is called when Q failed */
- abortQueue();
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement