1 /** 2 * The freechess.org connection library. 3 * More information is available at http://www.jinchess.com/. 4 * Copyright (C) 2002 Alexander Maryanovsky. 5 * All rights reserved. 6 * 7 * The freechess.org connection library is free software; you can redistribute 8 * it and/or modify it under the terms of the GNU Lesser General Public License 9 * as published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) any later version. 11 * 12 * The freechess.org connection library is distributed in the hope that it will 13 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with the freechess.org connection library; if not, write to the Free 19 * Software Foundation, Inc., 20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 package free.freechess; 24 25 import java.util.Hashtable; 26 27 28 /** 29 * Represents an ivar (interface variable) on FICS. 30 */ 31 32 public class Ivar{ 33 34 35 /** 36 * Maps ivar indices to ivars. 37 */ 38 39 private final static Hashtable INDEX_TO_IVAR = new Hashtable(); 40 41 42 43 /** 44 * Maps ivar names to ivars. 45 */ 46 47 private final static Hashtable NAME_TO_IVAR = new Hashtable(); 48 49 50 51 /** 52 * The compressmove ivar. Issue "help iv_compressmove" on FICS for more 53 * information. 54 */ 55 56 public static final Ivar COMPRESSMOVE = new Ivar("compressmove", 0); 57 58 59 60 /** 61 * The audiochar ivar. No idea what it does. 62 */ 63 64 public static final Ivar AUDIOCHAT = new Ivar("audiochat", 1); 65 66 67 68 /** 69 * The seekremove ivar. Issue "help iv_seekremove" on FICS for more 70 * information. 71 */ 72 73 public static final Ivar SEEKREMOVE = new Ivar("seekremove", 2); 74 75 76 77 /** 78 * The defprompt ivar. Issue "help iv_defprompt" on FICS for more information. 79 */ 80 81 public static final Ivar DEFPROMPT = new Ivar("defprompt", 3); 82 83 84 85 /** 86 * The lock ivar. Issue "help iv_lock" on FICS for more information. 87 */ 88 89 public static final Ivar LOCK = new Ivar("lock", 4); 90 91 92 93 /** 94 * The startpos ivar. Issue "help iv_startpos" on FICS for more information. 95 */ 96 97 public static final Ivar STARTPOS = new Ivar("startpos", 5); 98 99 100 101 /** 102 * The block ivar. Issue "help iv_block" on FICS for more information. 103 */ 104 105 public static final Ivar BLOCK = new Ivar("block", 6); 106 107 108 109 /** 110 * The gameinfo ivar. Issue "help iv_gameinfo" on FICS for more information. 111 */ 112 113 public static final Ivar GAMEINFO = new Ivar("gameinfo", 7); 114 115 116 117 /** 118 * The xdr ivar. No idea what it does. 119 */ 120 121 public static final Ivar XDR = new Ivar("xdr", 8); 122 123 124 125 /** 126 * The pendinfo ivar. Issue "help iv_pendinfo" on FICS for more information. 127 */ 128 129 public static final Ivar PENDINFO = new Ivar("pendinfo", 9); 130 131 132 133 /** 134 * The graph ivar. Issue "help iv_graph" on FICS for more information. 135 */ 136 137 public static final Ivar GRAPH = new Ivar("graph", 10); 138 139 140 141 /** 142 * The seekinfo ivar. Issue "help iv_seekinfo" on FICS for more information. 143 */ 144 145 public static final Ivar SEEKINFO = new Ivar("seekinfo", 11); 146 147 148 149 /** 150 * The extascii ivar. No idea what it does. 151 */ 152 153 public static final Ivar EXTASCII = new Ivar("extascii", 12); 154 155 156 157 /** 158 * The nohighlight ivar. Probably disables some kind of special server 159 * signals. 160 */ 161 162 public static final Ivar NOHIGHLIGHT = new Ivar("nohighlight", 13); 163 164 165 166 /** 167 * The vt_highlight ivar. Probably enables some kind of special server signals 168 * designed to highlight things on terminals. 169 */ 170 171 public static final Ivar VT_HIGHLIGHT = new Ivar("vt_highlight", 14); 172 173 174 175 /** 176 * The showserver ivar. No idea what it does. 177 */ 178 179 public static final Ivar SHOWSERVER = new Ivar("showserver", 15); 180 181 182 183 /** 184 * The pin ivar. Probably enables and disables notifications about players 185 * arriving and departing. 186 */ 187 188 public static final Ivar PIN = new Ivar("pin", 16); 189 190 191 192 /** 193 * The ms ivar. Asks the server to send current time in style12 in 194 * milliseconds instead of seconds. 195 */ 196 197 public static final Ivar MS = new Ivar("ms", 17); 198 199 200 201 /** 202 * The pinginfo ivar. No idea what it does. 203 */ 204 205 public static final Ivar PINGINFO = new Ivar("pinginfo", 18); 206 207 208 209 /** 210 * The boardinfo ivar. No idea what it does. 211 */ 212 213 public static final Ivar BOARDINFO = new Ivar("boardinfo", 19); 214 215 216 217 /** 218 * The extuserinfo ivar. No idea what it does. 219 */ 220 221 public static final Ivar EXTUSERINFO = new Ivar("extuserinfo", 20); 222 223 224 225 /** 226 * The seekca ivar. No idea what it does. 227 */ 228 229 public static final Ivar SEEKCA = new Ivar("seekca", 21); 230 231 232 233 /** 234 * The showownseek ivar. Asks the server to send the user's own seek as part 235 * of seekinfo. 236 */ 237 238 public static final Ivar SHOWOWNSEEK = new Ivar("showownseek", 22); 239 240 241 242 /** 243 * The premove ivar. Interfaces can set this (useless) variable on if they 244 * support premove. 245 */ 246 247 public static final Ivar PREMOVE = new Ivar("premove", 23); 248 249 250 251 /** 252 * The smartmove ivar. No idea what it does, but presumably the same as the 253 * premove ivar. 254 */ 255 256 public static final Ivar SMARTMOVE = new Ivar("smartmove", 24); 257 258 259 260 /** 261 * The movecase ivar. No idea what it does. 262 */ 263 264 public static final Ivar MOVECASE = new Ivar("movecase", 25); 265 266 267 268 /** 269 * The suicide ivar. No idea what it does. 270 */ 271 272 public static final Ivar SUICIDE = new Ivar("suicide", 26); 273 274 275 276 /** 277 * The crazyhouse ivar. No idea what it does. 278 */ 279 280 public static final Ivar CRAZYHOUSE = new Ivar("crazyhouse", 27); 281 282 283 284 /** 285 * The losers ivar. No idea what it does. 286 */ 287 288 public static final Ivar LOSERS = new Ivar("losers", 28); 289 290 291 292 /** 293 * The wildcastle ivar. No idea what it does. 294 */ 295 296 public static final Ivar WILDCASTLE = new Ivar("wildcastle", 29); 297 298 299 300 /** 301 * The fr ivar. No idea what it does. 302 */ 303 304 public static final Ivar FR = new Ivar("fr", 30); 305 306 307 308 /** 309 * The nowrap ivar. Disables server wrapping the text. 310 */ 311 312 public static final Ivar NOWRAP = new Ivar("nowrap", 31); 313 314 315 316 /** 317 * The allresults ivar. No idea what it does. 318 */ 319 320 public static final Ivar ALLRESULTS = new Ivar("allresults", 32); 321 322 323 324 /** 325 * The obsping ivar. No idea what it does. 326 */ 327 328 public static final Ivar OBSPING = new Ivar("obsping", 33); 329 330 331 332 /** 333 * The singleboard ivar. No idea what it does. 334 */ 335 336 public static final Ivar SINGLEBOARD = new Ivar("singleboard", 34); 337 338 339 340 /** 341 * The index of the ivar when its value is specified on the login prompt. 342 */ 343 344 private final int index; 345 346 347 348 /** 349 * The name of the ivar. 350 */ 351 352 private final String name; 353 354 355 356 /** 357 * Creates an ivar with the specified name and index. 358 */ 359 Ivar(String name, int index)360 private Ivar(String name, int index){ 361 name = name.toLowerCase(); 362 363 this.name = name; 364 this.index = index; 365 366 Object ivar = INDEX_TO_IVAR.put(new Integer(index), this); 367 if (ivar != null){ 368 INDEX_TO_IVAR.put(new Integer(index), ivar); 369 throw new IllegalArgumentException("The index "+index+" is already taken by "+ivar); 370 } 371 372 ivar = NAME_TO_IVAR.put(name, this); 373 if (ivar != null){ 374 NAME_TO_IVAR.put(name, ivar); 375 throw new IllegalArgumentException("The name "+name+" is already taken by "+ivar); 376 } 377 } 378 379 380 381 /** 382 * Returns the index of the ivar when its value is specified on the login 383 * line. Indices start at 0. 384 */ 385 getIndex()386 public int getIndex(){ 387 return index; 388 } 389 390 391 392 /** 393 * Returns the name of the variable. 394 */ 395 getName()396 public String getName(){ 397 return name; 398 } 399 400 401 402 /** 403 * Returns the ivar with the specified index, or null if no such ivar exists. 404 */ 405 getByIndex(int index)406 public static Ivar getByIndex(int index){ 407 return (Ivar)INDEX_TO_IVAR.get(new Integer(index)); 408 } 409 410 411 412 /** 413 * Returns the ivar with the specified name, case insensitively. 414 */ 415 getByName(String name)416 public static Ivar getByName(String name){ 417 name = name.toLowerCase(); 418 419 return (Ivar)NAME_TO_IVAR.get(name); 420 } 421 422 423 424 /** 425 * Returns a textual representation of this ivar. 426 */ 427 toString()428 public String toString(){ 429 return getName(); 430 } 431 432 433 434 }