001 /**
002 * Jetrix TetriNET Server
003 * Copyright (C) 2001-2004 Emmanuel Bourg
004 *
005 * This program is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU General Public License
007 * as published by the Free Software Foundation; either version 2
008 * of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018 */
019
020 package net.jetrix.commands;
021
022 import net.jetrix.*;
023 import net.jetrix.config.*;
024 import net.jetrix.messages.*;
025 import net.jetrix.messages.channel.CommandMessage;
026 import net.jetrix.messages.channel.PlineMessage;
027
028 import java.util.*;
029
030 /**
031 * Go to the channel of the specified player. The channel must not be password
032 * protected.
033 *
034 * @author Emmanuel Bourg
035 * @version $Revision: 860 $, $Date: 2010-05-06 13:21:05 +0200 (jeu., 06 mai 2010) $
036 */
037 public class GotoCommand extends AbstractCommand implements ParameterCommand
038 {
039 public String[] getAliases()
040 {
041 return (new String[] { "goto", "go" });
042 }
043
044 public String getUsage(Locale locale)
045 {
046 return "/goto <" + Language.getText("command.params.player_name", locale) + ">";
047 }
048
049 public int getParameterCount()
050 {
051 return 1;
052 }
053
054 public void execute(CommandMessage m)
055 {
056 Client client = (Client) m.getSource();
057
058 String targetName = m.getParameter(0);
059
060 ClientRepository repository = ClientRepository.getInstance();
061 Client target = repository.getClient(targetName);
062
063 if (target == null)
064 {
065 // no player found
066 PlineMessage response = new PlineMessage();
067 response.setKey("command.player_not_found", targetName);
068 client.send(response);
069 }
070 else
071 {
072 // player found
073 Channel channel = target.getChannel();
074 ChannelConfig channelConfig = channel.getConfig();
075
076 if (target == client)
077 {
078 PlineMessage cantgoto = new PlineMessage();
079 cantgoto.setKey("command.goto.yourself");
080 client.send(cantgoto);
081 }
082 else if (channel == client.getChannel())
083 {
084 PlineMessage cantgoto = new PlineMessage();
085 cantgoto.setKey("command.goto.same_channel", target.getUser().getName());
086 client.send(cantgoto);
087 }
088 else if (channel.isFull())
089 {
090 // send a channel full message
091 PlineMessage channelfull = new PlineMessage();
092 channelfull.setKey("command.join.full");
093 client.send(channelfull);
094 }
095 else if (client.getUser().getAccessLevel() < channelConfig.getAccessLevel())
096 {
097 // check the access level
098 PlineMessage accessDenied = new PlineMessage();
099 accessDenied.setKey("command.join.denied");
100 client.send(accessDenied);
101 }
102 else if (channelConfig.isPasswordProtected())
103 {
104 // check if the channel is password protected
105 PlineMessage accessDenied = new PlineMessage();
106 accessDenied.setKey("command.goto.password");
107 client.send(accessDenied);
108 }
109 else if (client.getUser().isPlayer() && !channelConfig.isProtocolAccepted(client.getProtocol().getName()))
110 {
111 // incompatible speed constraint
112 String type = channelConfig.getSpeed() == Speed.FAST ? "TetriFast" : "TetriNET";
113 client.send(new PlineMessage("command.join.speed", type));
114 }
115 else
116 {
117 // add the ADDPLAYER message to the queue of the target channel
118 AddPlayerMessage move = new AddPlayerMessage(client);
119 channel.send(move);
120 }
121 }
122 }
123 }