📄 report.java
字号:
/* * MegaMek - * Copyright (C) 2000,2001,2002,2003,2004,2005 Ben Mazur (bmazur@sev.org) * * This program 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. * * This program 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. */package megamek.common;import java.io.Serializable;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;import megamek.common.Entity;/** * This class defines a single server report. It holds information such * as the report ID, who the report is about, who should see the report, * and some formatting information. * <p> * Typically, the report will be created by the relevant section in * the <code>Server</code>, and added to the phase report vector. The * actual text of the report must also be added to the * <i>report-messages.properties</i> file. * <p> * Example: * <p> * <code>Report r = new Report(3455);<br> * r.subject = entity.getId();<br> * r.indent();<br> * r.addDesc(entity);<br> * r.add(6);<br> * r.choose(true);<br> * vPhaseReport.addElement(r);</code> * <p> * Then the following line would be added to <i>report-messages.properties</i>: * <p> * 3455::<data> (<data>) does <data> damage to the <msg:3456,3457>.<br> * 3456::tank<br> * 3457::building * <p> * When the client parses the report, it will fill in the <data> tags * with the values that were given to the <code>add</code> methods called * on the report object. * <p> * The example above might produce a report such as this when the <code>getText</code> method was called: * <p> * " Crusader (Bob) does 6 damage to the tank." * * @author Ryan McConnell (oscarmm) * @version $Revision: 4775 $ * @since 0.30 */public class Report implements Serializable { /* Note: some fields are marked transient because they are only used by the server (or only the client). This shaves a few bytes off the packet size, helping the dial-up people :) */ /** Required - associates this object with its text. */ public int messageId = Report.MESSAGE_NONE; private static final int MESSAGE_NONE = -1; /** The number of spaces this report should be indented. */ private int indentation = 0; /** The number of newlines to add at the end of this report. Defaults to one. */ public int newlines = 1; /** The data values to fill in the report with. */ private Vector tagData = new Vector(); /** How this report is handled when double-blind play is in effect. See constants below for more details. */ //Maybe should be simple isPublic boolean? Or do we want to ever mix // obscured and totally hidden reports? public transient int type = Report.HIDDEN; /** Report is visible to all players. */ public static final int PUBLIC = 0; /** Report is visible to all players, but all data marked for obscuration remains hidden. Note: Not used at this time, since all reports are considered <code>obscured</code> unless explicitly marked <code>public</code>. */ public static final int OBSCURED = 1; /** Report is only visible to those players who can see the subject. Note: Not used at this time, since all reports are considered <code>obscured</code> unless explicitly marked <code>public</code>. */ public static final int HIDDEN = 2; /** Testing only - remove me later. */ //debugReport public static final int TESTING = 3; /** The entity this report concerns, if applicable. If this is left blank, then the report will be considered <code>public</code>. */ public transient int subject = Entity.NONE; /** This hash table will store the tagData Vector indexes that are supposed to be obscured before sending to clients. This only applies when the report type is "obscured". */ private Hashtable obscuredIndexes = new Hashtable(); /** Vector to store the player names of those who received an obscured version of this report. Used to reconstruct individual client's reports from the master copy stored by the server. */ private Vector obscuredRecipients = new Vector(); /** Keep track of what data we have already substituted for tags. */ private transient int tagCounter = 0; /** The string that appears in the report to obscure certain information. */ public static final String OBSCURED_STRING = "????"; /** Number of spaces to use per indentation level. */ private static final int DEFAULT_INDENTATION = 4; /** Default constructor, note that using this means the <code>messageId</code> field must be explicitly set. */ public Report() { ; } /** * Create a new report associated with the given report text. * * @param id the int value of the report from * <i>report-messages.properties</i> */ public Report(int id) { this.messageId = id; } /** * Create a new report associated with the given report text and * having the given type. * * @param id the int value of the report from * <i>report-messages.properties</i> * @param type the constant specifying the visibility of the * report (PUBLIC, OBSCURED, or HIDDEN) */ public Report(int id, int type) { this.messageId = id; this.type = type; } /** * Create a new report which is an exact copy of the given report. * * @param r the report to be copied */ public Report(Report r) { this.messageId = r.messageId; this.indentation = r.indentation; this.newlines = r.newlines; this.tagData = (Vector)r.tagData.clone(); this.type = r.type; this.subject = r.subject; this.obscuredIndexes = (Hashtable)r.obscuredIndexes.clone(); this.obscuredRecipients = (Vector)r.obscuredRecipients.clone(); this.tagCounter = r.tagCounter; } /** * Add the given int to the list of data that will be substituted * for the <data> tags in the report. The order in which * items are added must match the order of the tags in the report * text. * * @param data the int to be substituted */ public void add(int data) { add(data, false); } /** * Add the given int to the list of data that will be substituted * for the <data> tags in the report, and mark it as * double-blind sensitive information if <code>obscure</code> is * true. The order in which items are added must match the order * of the tags in the report text. * * @param data the int to be substituted * @param obscure boolean indicating whether the data is * double-blind sensitive */ public void add(int data, boolean obscure) { if (obscure) { this.obscuredIndexes.put(new Integer(this.tagData.size()), new Boolean(true)); } this.tagData.addElement(String.valueOf(data)); } /** * Add the given String to the list of data that will be substituted * for the <data> tags in the report. The order in which * items are added must match the order of the tags in the report * text. * * @param data the String to be substituted */ public void add(String data) { add(data, true); } /** * Add the given String to the list of data that will be substituted * for the <data> tags in the report, and mark it as * double-blind sensitive information if <code>obscure</code> is * true. The order in which items are added must match the order * of the tags in the report text. * * @param data the String to be substituted * @param obscure boolean indicating whether the data is * double-blind sensitive */ public void add(String data, boolean obscure) { if (obscure) { this.obscuredIndexes.put(new Integer(this.tagData.size()), new Boolean(true)); } this.tagData.addElement(data); } /** * Indicate which of two possible messages should be substituted * for the <code><msg:<i>n</i>,<i>m</i>> tag. An argument of * <code>true</code> would select message <i>n</i> while an * argument of <code>false</code> would select <i>m</i>. In the * future, this capability may be expanded to support more than * two choices. * * @param choice boolean indicating which message to substitute */ public void choose(boolean choice) { this.tagData.addElement(String.valueOf(choice)); } /** * Not currently used. May be removed in the future. */ private void choose(boolean data, boolean obscure) { if (obscure) { this.obscuredIndexes.put(new Integer(this.tagData.size()), new Boolean(true)); } this.tagData.addElement(String.valueOf(data)); } /** * Shortcut method for adding entity name and owner data at the * same time. Assumes that the entity name should be obscured, * but the owner should not. * * @param entity the entity you wish to add */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -