Advertisement
D3ad

WT Matchmaker

Jun 6th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. /* not an actual program, just an idea I had */
  2.  
  3. #define QUIT_TIME 300   /* seconds after join */
  4. #define MAX_LEAVES  /* maximum count of leaves allowed */
  5.  
  6. class user{
  7. public:
  8.     std::string userName;
  9.     uint32_t userID;    /* 2^32 values for users is enough,
  10.                    we do not expect half of the population to play this game */
  11.     uint16_t mapID;     /* 65536 values to identify map is enough */
  12.     uint16_t lastMapID;
  13.     uint8_t leaveCount;     /* 256 values to keep track of leaves is enough */
  14.     uint64_t joinTime;      /* same time as linux epoch */
  15.     uint64_t leaveTime;
  16.     ...             /* more variables for user */
  17. };
  18.  
  19.  
  20. /**
  21.  * @brief check if user quits before certain time
  22.  * @param pointer to user
  23.  * @return true if user quits before QUIT_TIME
  24.  */
  25. bool quitAfterJoin(user *usr){
  26.     /* if user leaves in first 5 minutes after join, time can be changed */
  27.     if(abs(user->joinTime - user->leaveTime) < QUIT_TIME){
  28.         /* set last map ID and retur flag that user quit before certain time */
  29.         usr->lastMapID = map.ID;
  30.         if(usr->lastMapID == usr->mapID){
  31.             usr->leaveCount++;
  32.             return true;
  33.         }
  34.     }
  35.     return false;
  36. }
  37.  
  38. /**
  39.  * @brief function called after user joins in the game
  40.  * @param pointer to user
  41.  * @return true if join is successful
  42.  */
  43. bool join(user *usr){
  44.     usr->mapID = map.ID;
  45.     ... /* etc. */
  46. }
  47.  
  48. /**
  49.  * @brief overloaded function to join with preferences
  50.  * @param mapID mapID which user does not want to join
  51.  * @return true if joining was successful
  52.  */
  53. bool tryToJoin(uint16_t mapID){
  54.     /* exclude map from list of possible maps */
  55.     excludeMap(mapID);
  56.    
  57.     /* other operations before joining */
  58.     ...
  59. }
  60.  
  61. /**
  62.  * @brief default function to join without preferences
  63.  * @param mapID mapID which user does not want to join
  64.  * @return true if joining was successful
  65.  */
  66. bool tryToJoin(){
  67.     /* normal joining procedure */
  68.     ...
  69. }
  70.  
  71. /**
  72.  * @brief user joins Q
  73.  * @param pointer to user
  74.  * @return true if queueing up is successful
  75.  */
  76. bool queueUp(user *usr){   
  77.     ...     /* some preparations */
  78.     /* if user quits game before certain time, we can be sure he does not want to play
  79.        in that game, therefore we will NOT match him in that game
  80.     */
  81.     try{
  82.         if(usr->leaveCount > MAX_LEAVES){
  83.             /* try to join excluding this certain map */
  84.             tryToJoin(usr->lastMapID); 
  85.         } else {
  86.             tryToJoin();
  87.         }  
  88.     }
  89.     catch{
  90.         /* procedure that is called when Q failed */
  91.         abortQueue();
  92.         return false;
  93.     }
  94.     return true;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement