public Player ClaimPlayerSlotReservation(Connection connection, string reservationKey, string correlationId) { PlayerSlotReservation reservation = reservations[reservationKey]; Validate.NotNull(reservation); if (reservation.CorrelationId != correlationId) { throw new UncorrelatedMessageException();; } Player player = new Player(reservation.PlayerId, connection); lock (playersByConnection) { lock (currentPlayerNames) { currentPlayerNames.Add(reservation.PlayerId); } playersByConnection[connection] = player; lock (reservations) { reservations.Remove(reservationKey); } } return(player); }
public override void Process(ReservePlayerSlot packet, Connection connection) { Log.Info("Processing reservation request..."); string correlationId = packet.CorrelationId; string playerId = packet.PlayerName; PlayerSlotReservation reservation = playerManager.ReservePlayerSlot(correlationId, playerId); Log.Info($"Reservation processed successfully: { reservation.ToString() }..."); connection.SendPacket(reservation, null); }
public PlayerSlotReservation ReservePlayerSlot(string correlationId, string playerId) { if (currentPlayerNames.Contains(playerId)) { PlayerSlotReservationState rejectedReservationState = PlayerSlotReservationState.Rejected | PlayerSlotReservationState.UniquePlayerNameConstraintViolated; return(new PlayerSlotReservation(correlationId, rejectedReservationState)); } string reservationKey = Guid.NewGuid().ToString(); PlayerSlotReservation reservation = new PlayerSlotReservation(correlationId, reservationKey, playerId); lock (reservations) { reservations.Add(reservationKey, reservation); } return(reservation); }