コード例 #1
0
        public string In(Interfaces.IUserAgent user, int seatIndex)
        {
            Protocol.Result result = new Protocol.Result();
            result.Success = true;

            if (user.Desk != null)
            {
                user.Desk.Exit(user);
            }
            for (int i = 0; i < Seats.Count; i++)
            {
                Interfaces.ISeat seat = Seats[i];
                if (seat.Index == seatIndex)
                {
                    lock (seat)
                    {
                        if (seat.User == null || seat.User == user)
                        {
                            if (user.Seat != null)
                            {
                                user.Seat.User = null;
                            }
                            seat.User = user;
                            user.Desk = this;
                            user.Seat = seat;
                            Room.UpdateDesk(this);
                        }
                        else
                        {
                            result.Success = false;
                            return("位置已经被占用!");
                        }
                    }
                }
            }
            lock (Visitors)
            {
                if (!Visitors.Contains(user))
                {
                    Visitors.Add(user);
                }
                System.Threading.Interlocked.Increment(ref mVersion);
            }
            return(null);
        }