/* 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 23, 2005 */ package org.jbrain.qlink.state; import java.io.*; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.jbrain.qlink.*; import org.jbrain.qlink.chat.*; import org.jbrain.qlink.cmd.action.*; import org.jbrain.qlink.text.TextFormatter; import org.jbrain.qlink.user.AccountInfo; import org.jbrain.qlink.user.QHandle; import org.jbrain.qlink.user.UserManager; import org.jbrain.qlink.util.QuotedStringTokenizer; public class Chat extends AbstractChatState { private static Logger _log=Logger.getLogger(Chat.class); private int _iSeat; private RoomInfo[] _rooms; private int _roomPos; private ArrayList _alQuestion=new ArrayList(); public Chat(QSession session) { super(session); session.enableOLMs(true); } public void activate() throws IOException { QSeat[] seats; super.activate(); _log.debug(_session.getHandle() + " joins Lobby"); // find a Lobby to enter, get our seat number, etc. // need to make sure no enter/leaves slip by while in here. _room=_mgr.join(_session.getHandle(),getProfile(_session.getAccountInfo())); seats=addListener(); sendRoomInfo(seats); } /* (non-Javadoc) * @see org.jbrain.qlink.state.QState#execute(org.jbrain.qlink.cmd.Command) */ public boolean execute(Action a) throws IOException { boolean rc=false; QState state; AccountInfo info; QHandle handle; if(a instanceof RequestGame) { int id=((RequestGame)a).getID(); String name=((RequestGame)a).getTitle(); String type=((RequestGame)a).getType(); boolean order=((RequestGame)a).doesSystemPickOrder(); _log.debug(_session.getHandle() + " wants to play " + name); state=new PlayGame(_session,_room,id,name,type,order); state.activate(); } else if(a instanceof AcceptInvite) { Game game=_room.getPendingGame(); state=new PlayGame(_session,game); state.activate(); } else if(a instanceof DeclineInvite) { Game game=_room.getPendingGame(); game.declineInvite(); } else if(a instanceof ListRooms) { _log.debug("Listing Public rooms"); rc=true; _rooms=_mgr.getRoomInfoList(); _roomPos=0; sendRoomList(); } else if(a instanceof ListMoreRooms) { sendRoomList(); } else if(a instanceof ListGames) { _log.debug("Listing Games"); rc=true; GameInfo[] games=_room.getGameInfoList(); int i; if(games.length==0) { _session.send(new NoGames()); } else { for(i=0;i2) { QuotedStringTokenizer st=new QuotedStringTokenizer(text.substring(2)); String cmd=st.nextToken(" ").toLowerCase(); int pos=0; if(cmd.startsWith("mon") && _session.isStaff()) { // Monitor room; if(st.hasMoreTokens()) name=st.nextToken("\n"); if(name!= null) { _log.debug("Monitoring '" + name + "' public room "); monitorRoom(name,true); } } else { super.process(text); } } else { super.process(text); } } else { _room.say(text); } } /** * */ private void sendAuditoriumText() { _log.debug("Defining Auditorium text"); String text=_room.getInfo(); TextFormatter tf=new TextFormatter(); tf.add(text); tf.add("\n "); _log.info("Sending Auditorium Text"); List l=tf.getList(); int size=l.size(); for(int i=0;i