/* Copyright Jim Brain and Brain Innovations, 2005. This file is part of QLinkServer. QLinkServer is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QLinkServer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with QLinkServer; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @author Jim Brain Created on Jul 26, 2005 */ package org.jbrain.qlink.chat; import org.apache.log4j.Logger; import org.jbrain.qlink.user.QHandle; public class RoomDelegate extends AbstractRoomDelegate { private static Logger _log=Logger.getLogger(RoomDelegate.class); public static final int ROOM_CAPACITY=23; protected SeatInfo[] _users=new SeatInfo[ROOM_CAPACITY]; private GameDelegate[] _userGame = new GameDelegate[ROOM_CAPACITY]; public RoomDelegate(String name, boolean bPublic, boolean bLocked) { super(name,bPublic,bLocked); } /** * @param handle * @param delegate * @return * @throws UserNotInRoomException * @throws UserMismatchException */ public QSeat addUserToGame(QHandle handle, GameDelegate game) throws UserNotInRoomException { // we need to check seat and handle to make sure they match. synchronized(_htUsers) { SeatInfo info=(SeatInfo)getSeatInfo(handle); if(info==null) throw new UserNotInRoomException(); if(!info.isInGame()) { info.setGameStatus(true); _userGame[info.getSeatID()]=game; return info; } return null; } } /* (non-Javadoc) * @see org.jbrain.qlink.chat.AbstractRoomDelegate#getCapacity() */ public int getCapacity() { return ROOM_CAPACITY; } public QSeat[] getSeatInfoList(QHandle handle) { return (SeatInfo[])_htUsers.values().toArray(new SeatInfo[0]); } /** * @return */ public GameInfo[] getGameInfoList() { int size; GameDelegate game; GameInfo[] info; synchronized(_alGames) { size=_alGames.size(); info=new GameInfo[size]; for(int i=0;i