 
 # Notifies the server about achievements to add to the user
 # All achievements are separated by server result and passed to next
-notifyServer = (playerName, achievements, next) ->
+# Note: In the current implementation, playerId is actually a name
+# If playerId is refactored to a numerical id, the server will need to be updated
+notifyServer = (playerId, achievements, next) ->
   achievementsByStatus =
     success: []
     duplicate: []


  battle.once 'ratingsUpdated', =>
    for player in battle.players
      @checkAndAwardAchievements(server, player)


# Returns the achievements a player is eligible for, including already earned ones
# id is the rating key used to identify the player
checkAchievements = (id, next) ->
  ratings.getRatio id, (err, ratio) ->
    ratings.getStreak id, (err, streak) ->
      achievements = ACHIEVEMENTS.filter((o) -> o.conditionFn(ratio, streak))

      # Send everything except the conditionFn attribute

    do (achievement) -> (callback) ->
      request.post {
        url: "https://www.pokebattle.com/api/v1/achievements/"
        json: { user: playerId, achievement: achievement.name }
      }, (err, res, data) ->
        status = "success"
        status = "error"  if err
