1 /*** 2 * Jetrix TetriNET Server 3 * Copyright (C) 2001-2003 Emmanuel Bourg 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 */ 19 20 package net.jetrix.config; 21 22 import java.util.*; 23 24 /*** 25 * Channel configuration. 26 * 27 * @author Emmanuel Bourg 28 * @version $Revision: 860 $, $Date: 2010-05-06 13:21:05 +0200 (jeu., 06 mai 2010) $ 29 */ 30 public class ChannelConfig 31 { 32 private Settings settings; 33 private String name = "noname"; 34 private String password; 35 private String description; 36 private String topic; 37 private int maxPlayers = PLAYER_CAPACITY; 38 private int maxSpectators = SPECTATOR_CAPACITY; 39 private int accessLevel; 40 private boolean persistent; 41 private String winlistId; 42 private boolean idleAllowed; 43 private boolean visible = true; 44 private Speed speed = Speed.MIXED; 45 46 /*** extended properties */ 47 private Properties props; 48 49 /*** channel filter definitions */ 50 private List<FilterConfig> filters; 51 52 /*** Default spectator capacity */ 53 public static final int SPECTATOR_CAPACITY = 50; 54 55 /*** Default player capacity */ 56 public static final int PLAYER_CAPACITY = 6; 57 58 public ChannelConfig() 59 { 60 filters = new ArrayList<FilterConfig>(); 61 settings = new Settings(); 62 } 63 64 /*** 65 * Gets game parameters. 66 */ 67 public Settings getSettings() 68 { 69 return settings; 70 } 71 72 /*** 73 * Sets game parameters. 74 * 75 * @param settings 76 */ 77 public void setSettings(Settings settings) 78 { 79 this.settings = settings; 80 } 81 82 /*** 83 * Gets channel name. 84 */ 85 public String getName() 86 { 87 return name; 88 } 89 90 /*** 91 * Sets channel name. 92 * 93 * @param name 94 */ 95 public void setName(String name) 96 { 97 this.name = name; 98 } 99 100 /*** 101 * Gets the password. 102 */ 103 public String getPassword() 104 { 105 return password; 106 } 107 108 /*** 109 * Sets the password to enter the channel. 110 */ 111 public void setPassword(String password) 112 { 113 this.password = password; 114 } 115 116 /*** 117 * Gets channel description. 118 */ 119 public String getDescription() 120 { 121 return description; 122 } 123 124 /*** 125 * Sets the description shown on entering the channel. 126 */ 127 public void setDescription(String description) 128 { 129 this.description = description; 130 } 131 132 /*** 133 * Return the topic. 134 */ 135 public String getTopic() { 136 return topic; 137 } 138 139 /*** 140 * Set the topic. 141 */ 142 public void setTopic(String topic) { 143 this.topic = topic; 144 } 145 146 /*** 147 * Gets maximum number of players allowed. 148 */ 149 public int getMaxPlayers() 150 { 151 return maxPlayers; 152 } 153 154 /*** 155 * Sets the maximum number of players allowed at the same time in the channel. 156 * 157 * @param maxPlayers 158 */ 159 public void setMaxPlayers(int maxPlayers) 160 { 161 this.maxPlayers = maxPlayers; 162 } 163 164 /*** 165 * Gets maximum number of spectators allowed. 166 */ 167 public int getMaxSpectators() 168 { 169 return maxSpectators; 170 } 171 172 /*** 173 * Sets the maximum number of spectators allowed at the same time in the channel. 174 * 175 * @param maxSpectators 176 */ 177 public void setMaxSpectators(int maxSpectators) 178 { 179 this.maxSpectators = maxSpectators; 180 } 181 182 /*** 183 * Gets the minimum access level required to join the channel. 184 */ 185 public int getAccessLevel() 186 { 187 return accessLevel; 188 } 189 190 /*** 191 * Sets the minimum access level required to join the channel. 192 * 193 * @param accessLevel 194 */ 195 public void setAccessLevel(int accessLevel) 196 { 197 this.accessLevel = accessLevel; 198 } 199 200 /*** 201 * Tell if the channel will vanish once the last player leave 202 * 203 * @return <tt>true</tt> if the channel is persistent, <tt>false</tt> if not 204 */ 205 public boolean isPersistent() 206 { 207 return persistent; 208 } 209 210 /*** 211 * Sets channel persistence 212 * 213 * @param persistent 214 */ 215 public void setPersistent(boolean persistent) 216 { 217 this.persistent = persistent; 218 } 219 220 public String getWinlistId() 221 { 222 return winlistId; 223 } 224 225 public void setWinlistId(String winlistId) 226 { 227 this.winlistId = winlistId; 228 } 229 230 public String getProperty(String name) 231 { 232 return (props == null) ? null : props.getProperty(name); 233 } 234 235 public void setProperty(String name, String value) 236 { 237 if (props == null) 238 { 239 props = new Properties(); 240 } 241 props.setProperty(name, value); 242 } 243 244 /*** 245 * Tell if a password is required to enter the channel. 246 */ 247 public boolean isPasswordProtected() 248 { 249 return (password != null); 250 } 251 252 /*** 253 * Returns an iterator of registered filters. 254 */ 255 public Iterator<FilterConfig> getFilters() 256 { 257 return filters.iterator(); 258 } 259 260 /*** 261 * Registers a new filter. 262 */ 263 public void addFilter(FilterConfig fconf) 264 { 265 filters.add(fconf); 266 } 267 268 public boolean isIdleAllowed() 269 { 270 return idleAllowed; 271 } 272 273 public void setIdleAllowed(boolean idleAllowed) 274 { 275 this.idleAllowed = idleAllowed; 276 } 277 278 public boolean isVisible() 279 { 280 return visible; 281 } 282 283 public void setVisible(boolean visible) 284 { 285 this.visible = visible; 286 } 287 288 public Speed getSpeed() 289 { 290 return speed; 291 } 292 293 public void setSpeed(Speed speed) 294 { 295 this.speed = speed; 296 } 297 298 /*** 299 * Tells if the specified protocol is compatible with the speed restriction of the channel. 300 * 301 * @param protocol the name of the protocol 302 * @since 0.3 303 */ 304 public boolean isProtocolAccepted(String protocol) 305 { 306 switch (speed) 307 { 308 case NORMAL: 309 return !"tetrifast".equals(protocol); 310 case FAST: 311 return !"tetrinet".equals(protocol); 312 default: 313 return true; 314 } 315 } 316 }