View Javadoc
1 /*** 2 * Copyright (c) 2003 held jointly by the individual authors. 3 * 4 * This library is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU Lesser General Public License as published 6 * by the Free Software Foundation; either version 2.1 of the License, or 7 * (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, but 10 * WITHOUT ANY WARRANTY; with out even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this library; if not, write to the Free Software Foundation, 16 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 17 * 18 * > http://www.gnu.org/copyleft/lesser.html 19 * > http://www.opensource.org/licenses/lgpl-license.php 20 */ 21 package net.mlw.gfw.ext.basic.server.event; 22 23 import net.mlw.gfw.event.Event; 24 import net.mlw.gfw.event.impl.ConnectEvent; 25 import net.mlw.gfw.ext.basic.event.ChatEvent; 26 import net.mlw.gfw.ext.basic.event.ChooseTeamEvent; 27 import net.mlw.gfw.ext.basic.event.RoleEvent; 28 import net.mlw.gfw.ext.basic.event.SitEvent; 29 import net.mlw.gfw.ext.basic.server.Player; 30 import net.mlw.gfw.ext.basic.server.TurnBasedGame; 31 import net.mlw.gfw.server.impl.AbstractServerEventHandler; 32 33 /*** 34 * @author Matthew L. Wilson 35 * @version $Revision: 1.3 $ $Date: 2004/07/01 14:31:39 $ 36 */ 37 public class ConnectEventHandler extends AbstractServerEventHandler 38 { 39 protected TurnBasedGame game; 40 41 /*** 42 * @param game 43 */ 44 public ConnectEventHandler(TurnBasedGame game) 45 { 46 this.game = game; 47 } 48 49 /*** 50 * @see net.mlw.gfw.event.EventHandler#onEvent(net.mlw.gfw.event.Event) 51 */ 52 public void onEvent(Event event) 53 { 54 ConnectEvent ce = (ConnectEvent) event; 55 56 /*** Send a welcome message. * */ 57 context.getClients().onEvent(ce.getUserName(), new ChatEvent("mlavwilson@hotmail.com", "Welcome, and enjoy the game ;)")); 58 59 /*** Send the people already seated. * */ 60 for (int i = 0, size = game.getNumberOfSeats(); i < size; i++) 61 { 62 Player player = game.getPlayerSeatedAt(i); 63 if (player != null) 64 { 65 context.getClients().onEvent(ce.getUserName(), new ChooseTeamEvent(player.getUserName(), (i % game.getNumberOfPlayersPerTeam()))); 66 context.getClients().onEvent(ce.getUserName(), new SitEvent(player.getUserName(), i)); 67 } 68 } 69 70 /*** Send an admin role if this it the first person connection. * */ 71 if (game.getNumberSeated() == 0) 72 { 73 context.getClients().onEvent(ce.getUserName(), new RoleEvent("admin")); 74 } 75 76 /*** Get recommended Team, if there are any seats left.* */ 77 for (int i = 0, size = game.getNumberOfSeats(); i < size; i++) 78 { 79 /*** If there is room on any team, send a prompt to choose a team * */ 80 if (game.getPlayerSeatedAt(i) == null) 81 { 82 context.getClients().onEvent(ce.getUserName(), new ChooseTeamEvent("", (i % game.getNumberOfPlayersPerTeam()), true)); 83 break; 84 } 85 } 86 87 } 88 }

This page was automatically generated by Maven