import java.lang.*; import java.io.*; import java.awt.*; // Immutable class Message { public static final String teamshort[] = {"IND", "FED", "ROM", "X", "KLI", "X", "X", "X", "ORI", "X", "X", "X", "X", "X", "X", "ALL"}; public final int MVALID = 0x01; public final int MGOD = 0x10; public final int MMOO = 0x12; public final int MINDIV = 0x02; /* these go with MINDIV flag */ public final int MDBG = 0x20; public final int MCONFIG= 0x40; public final int MDIST = 0x60; public final int MMACRO = 0x80; public final int MTEAM = 0x04; /* these go with MTEAM flag */ public final int MTAKE = 0x20; public final int MDEST = 0x40; public final int MBOMB = 0x60; public final int MCOUP1 = 0x80; public final int MCOUP2 = 0xA0; public final int MDISTR = 0xC0; public final int MALL = 0x08; /* these go with MALL flag */ public final int MGENO = 0x20; /* MGENO is not used in INL server * but belongs here */ public final int MCONQ = 0x20; /* not enought bits to distinguish * MCONQ/MGENO :-*/ public final int MKILLA = 0x40; public final int MKILLP = 0x60; public final int MKILL = 0x80; public final int MLEAVE = 0xA0; public final int MJOIN = 0xC0; public final int MGHOST = 0xE0; /* MMASK not used in INL server */ public final int MWHOMSK = 0x1f; /* mask with this to find who msg to */ public final int MWHATMSK = 0xe0; /* mask with this to find what msg about */ public int m_flags; public int m_time; public int m_recpt; public byte[] m_data; public String m_msg; public Message(int from, int to, int flags, int len, byte data[], Players players) { m_flags = flags; m_data = new byte[len]; for (int i = 0; i < len; i++) m_data[i] = data[i]; m_msg = new String(m_data, 0, 0, len); m_msg = m_msg.substring(0, m_msg.indexOf(0)); if (players != null) createHeader(players, from, to); parseDistress(); } void createHeader(Players players, int from, int to) { String m_head; if (from == 255) m_head = "GOD->"; else m_head = " " + players.GetPlayer(from).p_mapchars + "->"; switch (m_flags & (MALL | MTEAM | MINDIV)) { case MTEAM: m_head = m_head + teamshort[players.GetSelf().p_team]; break; case MINDIV: m_head = m_head + players.GetPlayer(to).p_mapchars; break; case MALL: default: m_head = m_head + "ALL"; break; } m_msg = m_head + " " + m_msg; } void parseDistress() { if ((m_flags & (MDISTR | MTEAM)) == (MDISTR | MTEAM)) m_msg = m_msg.substring(0, 9) + ""; } String unparse() { return m_msg; } } class Messages implements Cloneable { final byte STEXTE = 32; final byte SHORT_WARNING = 33; final byte STEXTE_STRING = 34; Players players; Message messages[]; int m_current; byte buf[]; public Messages(int num, Players players) { this.players = players; messages = new Message[num]; for (int i = 0; i < num; i++) messages[i] = null; m_current = 0; buf = new byte[128]; } public Messages copy(Players players) { Messages ret = null; try { ret = (Messages) clone(); } catch(CloneNotSupportedException ex) { } ret.players = players; ret.messages = new Message[messages.length]; for (int i = 0; i < messages.length; i++) ret.messages[i] = messages[i]; return ret; } // struct mesg_spacket { // char type; /* SP_MESSAGE */ // unsigned char m_flags; // unsigned char m_recpt; // unsigned char m_from; // char mesg[80]; // }; public void handleMessage(DataInput data) throws IOException { int flags = data.readByte(); int recpt = data.readByte(); if (recpt < 0) recpt += 256; int from = data.readByte(); if (from < 0) from += 256; byte mesg[] = buf; data.readFully(mesg, 0, 80); Message msg = new Message(from, recpt, flags, 80, mesg, null); System.err.println(msg.unparse()); } // struct warning_spacket { // char type; /* SP_WARNING */ // char pad1; // char pad2; // char pad3; // char mesg[80]; // }; public void handleWarning(DataInput data) throws IOException { byte pad1 = data.readByte(); byte pad2 = data.readByte(); byte pad3 = data.readByte(); byte mesg[] = buf; data.readFully(mesg, 0, 80); } // struct mesg_s_spacket { // char type; /* SP_S_MESSAGE */ // unsigned char m_flags; // unsigned char m_recpt; // unsigned char m_from; // unsigned char length; /* Length of whole packet */ // char mesg; // char pad2; // char pad3; // char pad[76]; // }; public void handleSMessage(DataInput data) throws IOException { int flags = data.readByte(); int recpt = data.readByte(); if (recpt < 0) recpt += 256; int from = data.readByte(); if (from < 0) from += 256; byte length = data.readByte(); byte mesg[] = buf; data.readFully(mesg, 0, length-5); Message msg = new Message(from, recpt, flags, length-5, mesg, players); System.err.println(msg.unparse()); } // struct warning_s_spacket { /* SP_S_WARNING */ // char type; // unsigned char whichmessage; // char argument, argument2; /* for phaser etc ... */ // }; public void handleSWarning(DataInput data) throws IOException { byte which = data.readByte(); byte arg1 = data.readByte(); byte arg2 = data.readByte(); if (which == STEXTE_STRING || which == SHORT_WARNING) { byte mesg[] = buf; data.readFully(mesg, 0, arg2 - 4); } } }