tools/hw2irc/net/ercatec/hw2ircsvr/Connection.java
author nemo
Thu, 23 Mar 2023 16:21:39 -0400
changeset 15934 d754d03e4dfe
parent 15784 823cf18be1fc
permissions -rw-r--r--
and this one
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15784
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
     1
package net.ercatec.hw2ircsvr;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
     2
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
     3
import net.ercatec.hw.INetClient;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
     4
import net.ercatec.hw.ProtocolConnection;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
     5
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
     6
import java.io.BufferedReader;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
     7
import java.io.InputStream;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
     8
import java.io.InputStreamReader;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
     9
import java.io.OutputStream;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    10
import java.net.InetSocketAddress;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    11
import java.net.ServerSocket;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    12
import java.net.Socket;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    13
import java.util.ArrayList;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    14
import java.util.Arrays;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    15
import java.util.HashMap;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    16
import java.util.Hashtable;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    17
import java.util.List;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    18
import java.util.Map;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    19
import java.util.Queue;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    20
import java.util.concurrent.LinkedBlockingQueue;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    21
import java.util.Collections;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    22
import java.util.Vector;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    23
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    24
import java.util.regex.Pattern;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    25
import java.util.regex.PatternSyntaxException;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    26
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    27
import java.lang.IllegalArgumentException;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    28
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    29
// for auth files
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    30
import java.util.Properties;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    31
import java.io.FileInputStream;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    32
import java.io.IOException;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    33
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    34
/* TODO
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    35
 * disconnect clients that are not irc clients
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    36
 * disconnect excess flooders
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    37
 * recognizes stuff after : as single arg
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    38
 * collect pre-irc-join messages and show on join
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    39
 * allow negating regexps
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    40
 * ban
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    41
 * banlist
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    42
 * commandquery // wth did I mean by that?
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    43
 * more room info
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    44
 * filter rooms
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    45
 * warnings
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    46
 * global notice
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    47
 */
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    48
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    49
/**
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    50
 * @author sheepluva
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    51
 * 
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    52
 * based on jircs by Alexander Boyd
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    53
 */
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    54
public class Connection implements INetClient, Runnable
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    55
{
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    56
    private static final String DESCRIPTION_SHORT
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    57
        = "connect to hedgewars via irc!";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    58
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    59
    private static final String VERSION = "0.6.7-Alpha_2015-11-07";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    60
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    61
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    62
    private static final String MAGIC_BYTES       = "[\1\2\3]";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    63
    private static final char   MAGIC_BYTE_ACTION = ((char)1); // ^A
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    64
    private static final char   MAGIC_BYTE_BOLD   = ((char)2); // ^B
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    65
    private static final char   MAGIC_BYTE_COLOR  = ((char)3); // ^C
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    66
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    67
    private static final String[] DEFAULT_MOTD = {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    68
        "                                         ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    69
        " "+MAGIC_BYTE_COLOR+"06"+MAGIC_BYTE_BOLD+"                            SUCH FLUFFY!",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    70
        "                                         ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    71
        " "+MAGIC_BYTE_COLOR+"04 MUCH BAH     "+MAGIC_BYTE_COLOR+"00__  _                     ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    72
        " "+MAGIC_BYTE_COLOR+"00          .-.'  `; `-."+MAGIC_BYTE_COLOR+"00_  __  _          ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    73
        " "+MAGIC_BYTE_COLOR+"00         (_,         .-:'  `; `"+MAGIC_BYTE_COLOR+"00-._      ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    74
        " "+MAGIC_BYTE_COLOR+"14       ,'"+MAGIC_BYTE_COLOR+"02o "+MAGIC_BYTE_COLOR+"00(        (_,           )     ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    75
        " "+MAGIC_BYTE_COLOR+"14      (__"+MAGIC_BYTE_COLOR+"00,-'      "+MAGIC_BYTE_COLOR+"15,'"+MAGIC_BYTE_COLOR+"12o "+MAGIC_BYTE_COLOR+"00(            )>   ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    76
        " "+MAGIC_BYTE_COLOR+"00         (       "+MAGIC_BYTE_COLOR+"15(__"+MAGIC_BYTE_COLOR+"00,-'            )    ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    77
        " "+MAGIC_BYTE_COLOR+"00          `-'._.--._(             )     ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    78
        " "+MAGIC_BYTE_COLOR+"14             |||  |||"+MAGIC_BYTE_COLOR+"00`-'._.--._.-'      ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    79
        " "+MAGIC_BYTE_COLOR+"15                        |||  |||        ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    80
        " "+MAGIC_BYTE_COLOR+"07"+MAGIC_BYTE_BOLD+"  WOW!                                  ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    81
        " "+MAGIC_BYTE_COLOR+"09                   VERY SHEEP           ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    82
        "                                         ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    83
        "                                         ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    84
        "                                         ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    85
        " "+MAGIC_BYTE_COLOR+"4 Latest hw2irc crimes/changes:",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    86
        "     ping: ping of hwserver will only get reply if irc client pingable",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    87
        "     ping: pings of irc clients will only get reply if hwserver pingable",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    88
        "     rooms: id-rotation, make channel names at least 2 digits wide",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    89
        "     auth: support passhash being loaded local auth file and irc pass (sent as cleartext - DO NOT USE!)",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    90
        "                                         ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    91
        "                                         ",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    92
    };
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    93
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    94
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    95
    private static final String DEFAULT_QUIT_REASON = "User quit";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    96
    // NOT final
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    97
    private static char CHAT_COMMAND_CHAR = '\\';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    98
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
    99
    private final class Room {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   100
        public final int id;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   101
        public final String chan;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   102
        public String name;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   103
        private String owner = "";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   104
        public int nPlayers = 0;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   105
        public int nTeams   = 0;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   106
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   107
        public Room(final int id, final String name, final String owner) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   108
            this.id = id;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   109
            this.chan = (id<10?"#0":"#") + id;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   110
            this.name = name;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   111
            this.setOwner(owner);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   112
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   113
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   114
        public String getOwner() { return this.owner; }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   115
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   116
        public void setOwner(final String owner) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   117
            // don't to this for first owner
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   118
            if (!this.owner.isEmpty()) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   119
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   120
                // owner didn't change
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   121
                if (this.owner.equals(owner))
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   122
                    return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   123
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   124
                // update old room owner
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   125
                final Player oldOwner = allPlayers.get(this.owner);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   126
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   127
                if (oldOwner != null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   128
                    oldOwner.isRoomAdm = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   129
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   130
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   131
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   132
            // update new room owner
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   133
            final Player newOwner = allPlayers.get(owner);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   134
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   135
            if (newOwner != null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   136
                newOwner.isRoomAdm = true;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   137
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   138
            this.owner = owner;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   139
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   140
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   141
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   142
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   143
    private final class Player {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   144
        public final String nick;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   145
        public final String ircNick;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   146
        private boolean isAdm;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   147
        private boolean isCont;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   148
        private boolean isReg;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   149
        public boolean inRoom;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   150
        public boolean isRoomAdm;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   151
        private String ircId;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   152
        private String ircHostname;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   153
        private boolean announced;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   154
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   155
        // server info
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   156
        private String version = "";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   157
        private String ip = "";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   158
        private String room = "";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   159
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   160
        public Player(final String nick) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   161
            this.nick = nick;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   162
            this.ircNick = hwToIrcNick(nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   163
            this.announced = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   164
            updateIrcHostname();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   165
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   166
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   167
        public String getIrcHostname() { return ircHostname; }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   168
        public String getIrcId()       { return ircId; }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   169
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   170
        public String getRoom()        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   171
            if (room.isEmpty())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   172
                return room;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   173
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   174
            return "[" + ((isAdm?"@":"") + (isRoomAdm?"+":"") + this.room);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   175
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   176
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   177
        public boolean needsAnnounce() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   178
            return !announced;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   179
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   180
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   181
        public void setAnnounced() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   182
            announced = true;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   183
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   184
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   185
        public void setInfo(final String ip, final String version, final String room) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   186
            if (this.version.isEmpty()) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   187
                this.version = version;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   188
                this.ip = ip.replaceAll("^\\[|]$", "");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   189
                updateIrcHostname();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   190
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   191
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   192
            if (room.isEmpty())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   193
                this.room = room;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   194
            else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   195
                this.room = room.replaceAll("^\\[[@+]*", "");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   196
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   197
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   198
        public boolean isServerAdmin()  { return isAdm; }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   199
        //public boolean isContributor()  { return isCont; }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   200
        public boolean isRegistered()   { return isReg; }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   201
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   202
        public void setServerAdmin(boolean isAdm) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   203
            this.isAdm = isAdm; updateIrcHostname(); }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   204
        public void setContributor(boolean isCont) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   205
            this.isCont = isCont; updateIrcHostname(); }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   206
        public void setRegistered(boolean isReg) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   207
            this.isReg = isReg; updateIrcHostname(); }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   208
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   209
        private void updateIrcHostname() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   210
            ircHostname = ip.isEmpty()?"":(ip + '/');
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   211
            ircHostname += "hw/";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   212
            if (!version.isEmpty())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   213
                ircHostname += version;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   214
            if (isAdm)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   215
                ircHostname += "/admin";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   216
            else if (isCont)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   217
                ircHostname += "/contributor";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   218
            else if (isReg)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   219
                ircHostname += "/member";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   220
            else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   221
                ircHostname += "/player";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   222
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   223
            updateIrcId();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   224
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   225
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   226
        private void updateIrcId() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   227
            ircId = ircNick + "!~" + ircNick + "@" + ircHostname;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   228
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   229
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   230
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   231
    public String hw404NickToIrcId(String nick) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   232
        nick = hwToIrcNick(nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   233
        return nick + "!~" + nick + "@hw/404";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   234
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   235
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   236
    // hash tables are thread-safe
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   237
    private final Map<String,  Player>  allPlayers = new Hashtable<String,  Player>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   238
    private final Map<String,  Player> roomPlayers = new Hashtable<String,  Player>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   239
    private final Map<Integer, Room>   roomsById   = new Hashtable<Integer, Room>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   240
    private final Map<String,  Room>   roomsByName = new Hashtable<String,  Room>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   241
    private final List<Room> roomsSorted = new Vector<Room>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   242
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   243
    private final List<String> ircPingQueue = new Vector<String>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   244
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   245
    private static final String DEFAULT_SERVER_HOST = "netserver.hedgewars.org";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   246
    private static String SERVER_HOST = DEFAULT_SERVER_HOST;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   247
    private static int IRC_PORT = 46667;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   248
    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   249
    private String hostname;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   250
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   251
    private static final String LOBBY_CHANNEL_NAME = "#lobby";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   252
    private static final String  ROOM_CHANNEL_NAME = "#room";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   253
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   254
    // hack
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   255
    // TODO: ,
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   256
    private static final char MAGIC_SPACE   = ' ';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   257
    private static final char MAGIC_ATSIGN  = '៙';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   258
    private static final char MAGIC_PERCENT = '%';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   259
    private static final char MAGIC_PLUS    = '+';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   260
    private static final char MAGIC_EXCLAM  = '❢';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   261
    private static final char MAGIC_COMMA   = ',';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   262
    private static final char MAGIC_COLON   = ':';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   263
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   264
    private static String hwToIrcNick(final String nick) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   265
        return nick
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   266
            .replace(' ', MAGIC_SPACE)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   267
            .replace('@', MAGIC_ATSIGN)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   268
            .replace('%', MAGIC_PERCENT)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   269
            .replace('+', MAGIC_PLUS)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   270
            .replace('!', MAGIC_EXCLAM)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   271
            .replace(',', MAGIC_COMMA)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   272
            .replace(':', MAGIC_COLON)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   273
            ;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   274
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   275
    private static String ircToHwNick(final String nick) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   276
        return nick
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   277
            .replace(MAGIC_COLON,   ':')
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   278
            .replace(MAGIC_COMMA,   ',')
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   279
            .replace(MAGIC_EXCLAM,  '!')
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   280
            .replace(MAGIC_PLUS,    '+')
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   281
            .replace(MAGIC_PERCENT, '%')
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   282
            .replace(MAGIC_ATSIGN,  '@')
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   283
            .replace(MAGIC_SPACE,   ' ')
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   284
            ;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   285
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   286
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   287
    private ProtocolConnection hwcon;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   288
    private boolean joined = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   289
    private boolean ircJoined = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   290
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   291
    private void collectFurtherInfo() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   292
        hwcon.sendPing();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   293
        hwcon.processNextClientFlagsMessages();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   294
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   295
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   296
    public void onPing() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   297
        send("PING :" + globalServerName);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   298
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   299
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   300
    public void onPong() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   301
        if (!ircPingQueue.isEmpty())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   302
                send(":" + globalServerName + " PONG " + globalServerName
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   303
                        + " :" + ircPingQueue.remove(0));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   304
            
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   305
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   306
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   307
    public void onConnectionLoss() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   308
        quit("Connection Loss");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   309
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   310
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   311
    public void onDisconnect(final String reason) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   312
        quit(reason);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   313
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   314
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   315
    public String onPasswordHashNeededForAuth() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   316
        return passwordHash;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   317
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   318
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   319
    public void onMalformedMessage(String contents)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   320
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   321
        this.logError("MALFORMED MESSAGE: " + contents);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   322
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   323
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   324
    public void onChat(final String user, final String message) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   325
        String ircId;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   326
        Player player = allPlayers.get(user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   327
        if (player == null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   328
            // fake user - so probably a notice
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   329
            sendChannelNotice(message, hwToIrcNick(user));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   330
            //logWarning("onChat(): Couldn't find player with specified nick! nick: " + user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   331
            //send(":" + hw404NickToIrcId(user) + " PRIVMSG "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   332
                     //+ LOBBY_CHANNEL_NAME + " :" + hwActionToIrc(message));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   333
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   334
        else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   335
            send(":" + player.getIrcId() + " PRIVMSG "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   336
                     + LOBBY_CHANNEL_NAME + " :" + hwActionToIrc(message));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   337
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   338
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   339
    public void onWelcomeMessage(final String message) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   340
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   341
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   342
    public void onNotice(int number) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   343
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   344
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   345
    public void onBanListEntry(BanType type, String target, String duration, String reason) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   346
        // TODO
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   347
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   348
    public void onBanListEnd() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   349
        // TODO
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   350
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   351
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   352
    public String onNickCollision(final String nick) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   353
        return nick + "_";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   354
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   355
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   356
    public void onNickSet(final String nick) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   357
        final String newNick = hwToIrcNick(nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   358
        // tell irc client
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   359
        send(":" + ownIrcNick + "!~" + username + "@"
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   360
                            + hostname + " NICK :" + nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   361
        ownIrcNick = newNick;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   362
        updateLogPrefix();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   363
        logInfo("Nickname set to " + nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   364
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   365
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   366
    private void flagAsInLobby(final Player player) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   367
        if (!ircJoined)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   368
            return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   369
        final String ircNick = player.ircNick;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   370
        if (player.isServerAdmin())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   371
            send(":room-part!~@~ MODE " + LOBBY_CHANNEL_NAME + " -h+o " + ircNick + " " + ircNick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   372
        //else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   373
            //send(":room-part!~@~ MODE " + LOBBY_CHANNEL_NAME + " +v " + ircNick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   374
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   375
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   376
    private void flagAsInRoom(final Player player) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   377
        if (!ircJoined)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   378
            return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   379
        final String ircNick = player.ircNick;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   380
        if (player.isServerAdmin())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   381
            send(":room-join!~@~ MODE " + LOBBY_CHANNEL_NAME + " -o+h " + ircNick + " " + ircNick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   382
        //else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   383
            //send(":room-join!~@~ MODE " + LOBBY_CHANNEL_NAME + " -v " + ircNick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   384
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   385
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   386
// TODO somewhere: escape char for magic chars!
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   387
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   388
// TODO /join with playername => FOLLOW :D
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   389
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   390
    public void sendPlayerMode(final Player player) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   391
        char c;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   392
        if (player.isServerAdmin())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   393
            c = player.inRoom?'h':'o';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   394
        else if (player.isRegistered())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   395
            c = 'v';
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   396
        else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   397
            // no mode
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   398
            return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   399
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   400
        send(":server-join!~@~ MODE " + LOBBY_CHANNEL_NAME + " +" + c + " " + player.ircNick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   401
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   402
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   403
    private Player ownPlayer = null;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   404
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   405
    public void onLobbyJoin(final String[] users) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   406
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   407
        final List<Player> newPlayers = new ArrayList<Player>(users.length);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   408
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   409
        // process joins
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   410
        for (final String user : users) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   411
            final Player player = new Player(user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   412
            if (ownPlayer == null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   413
                ownPlayer = player;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   414
            newPlayers.add(player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   415
            allPlayers.put(user, player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   416
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   417
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   418
        // make sure we get the client flags before we announce anything
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   419
        collectFurtherInfo();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   420
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   421
        // get player info
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   422
        // NOTE: if player is in room, then info was already retrieved
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   423
        for (final Player player : newPlayers) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   424
            if (!player.inRoom)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   425
                hwcon.requestInfo(player.nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   426
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   427
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   428
        /* DISABLED - we'll announce later - when receiving info
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   429
        // announce joins
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   430
        if (ircJoined) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   431
            for (final Player player : newPlayers) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   432
                final String ircId = player.getIrcId();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   433
                send(":" + ircId
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   434
                         + " JOIN "+ lobbyChannel.name);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   435
                sendPlayerMode(player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   436
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   437
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   438
        */
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   439
        if (!ircJoined) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   440
            // don't announced players that were there before join already
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   441
            for (final Player player : newPlayers) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   442
                player.setAnnounced();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   443
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   444
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   445
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   446
        if (!joined) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   447
            joined = true;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   448
            // forget password hash, we don't need it anymore.
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   449
            passwordHash = "";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   450
            logInfo("Hedgewars server/lobby joined.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   451
            sendSelfNotice("Hedgewars server was joined successfully");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   452
            // do this after join so that rooms can be assigned to their owners
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   453
            hwcon.requestRoomsList();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   454
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   455
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   456
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   457
    private void makeIrcJoinLobby() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   458
            sendGlobal("INVITE " + ownIrcNick + " " + LOBBY_CHANNEL_NAME);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   459
            try{Thread.sleep(3000);}catch(Exception e){}
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   460
            join(lobbyChannel.name);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   461
            sendSelfNotice("Joining lobby-channel: " + lobbyChannel.name);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   462
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   463
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   464
    private void announcePlayerJoinLobby(final Player player) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   465
            player.setAnnounced();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   466
            send(":" + player.getIrcId()
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   467
                     + " JOIN "+ lobbyChannel.name);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   468
            sendPlayerMode(player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   469
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   470
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   471
    public void onLobbyLeave(final String user, final String reason) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   472
        final Player player = allPlayers.get(user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   473
        if (player == null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   474
            logWarning("onLobbyLeave(): Couldn't find player with specified nick! nick: " + user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   475
            sendIfJoined(":" + hw404NickToIrcId(user)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   476
                 + " PART " + lobbyChannel.name + " " + reason);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   477
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   478
        else {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   479
            if (ircJoined && player.needsAnnounce())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   480
                announcePlayerJoinLobby(player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   481
            sendIfJoined(":" + player.getIrcId()
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   482
                 + " PART " + lobbyChannel.name + " " + reason);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   483
            allPlayers.remove(user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   484
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   485
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   486
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   487
    private int lastRoomId = 0;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   488
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   489
    public void onRoomInfo(final String name, final String flags,
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   490
                           final String newName, final int nUsers,
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   491
                           final int nTeams, final String owner,
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   492
                           final String map, final String style,
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   493
                           final String scheme, final String weapons) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   494
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   495
        Room room = roomsByName.get(name);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   496
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   497
        if (room == null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   498
            // try to reuse old ids
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   499
            if (lastRoomId >= 90)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   500
                lastRoomId = 9;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   501
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   502
            // search for first free
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   503
            while(roomsById.containsKey(++lastRoomId)) { }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   504
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   505
            room = new Room(lastRoomId, newName, owner);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   506
            roomsById.put(lastRoomId, room);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   507
            roomsByName.put(newName, room);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   508
            roomsSorted.add(room);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   509
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   510
        else if (!room.name.equals(newName)) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   511
            room.name = newName;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   512
            roomsByName.put(newName, roomsByName.remove(name));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   513
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   514
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   515
        // update data
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   516
        room.setOwner(owner);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   517
        room.nPlayers = nUsers;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   518
        room.nTeams = nTeams;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   519
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   520
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   521
    public void onRoomDel(final String name) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   522
        final Room room = roomsByName.remove(name);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   523
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   524
        if (room != null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   525
            roomsById.remove(room.id);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   526
            roomsSorted.remove(room);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   527
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   528
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   529
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   530
    public void onRoomJoin(final String[] users) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   531
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   532
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   533
    public void onRoomLeave(final String[] users) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   534
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   535
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   536
    // TODO vector that remembers who's info was requested for manually
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   537
    List<String> requestedInfos =  new Vector<String>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   538
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   539
    public void onUserInfo(final String user, final String ip, final String version, final String room) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   540
        Player player = allPlayers.get(user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   541
        if (player != null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   542
            player.setInfo(ip, version, room);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   543
            if (ircJoined) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   544
                if (player.needsAnnounce())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   545
                    announcePlayerJoinLobby(player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   546
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   547
            else {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   548
                if (player == ownPlayer) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   549
                    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   550
                    makeIrcJoinLobby();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   551
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   552
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   553
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   554
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   555
        // if MANUAL send notice
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   556
        if (requestedInfos.remove(user)) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   557
            final String nick = hwToIrcNick(user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   558
            sendServerNotice(nick + " - " + buildInfoString(ip, version, room));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   559
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   560
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   561
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   562
    public void onUserFlagChange(final String user, final UserFlagType flag, final boolean newValue) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   563
        final Player player = allPlayers.get(user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   564
        if (player == null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   565
            logError("onUserFlagChange(): Couldn't find player with specified nick! nick: " + user);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   566
            return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   567
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   568
        switch (flag) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   569
            case ADMIN:
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   570
                player.setServerAdmin(newValue);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   571
                if (newValue) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   572
                    logDebug(user + " is server admin");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   573
                    //sendIfJoined(":server!~@~ MODE " + LOBBY_CHANNEL_NAME + " -v+o " + player.ircNick + " " + player.ircNick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   574
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   575
                break;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   576
            case INROOM:
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   577
                player.inRoom = newValue;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   578
                if (newValue) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   579
                    flagAsInRoom(player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   580
                    logDebug(user + " entered a room");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   581
                    // get new room info
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   582
                    hwcon.requestInfo(player.nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   583
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   584
                else {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   585
                    flagAsInLobby(player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   586
                    logDebug(user + " returned to lobby");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   587
                    player.inRoom = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   588
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   589
                break;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   590
            case REGISTERED:
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   591
                player.setRegistered(newValue);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   592
                break;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   593
            default: break;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   594
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   595
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   596
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   597
    public class Channel
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   598
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   599
        private String topic;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   600
        private final String name;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   601
        private final Map<String, Player> players;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   602
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   603
        public Channel(final String name, final String topic, final Map<String, Player> players) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   604
            this.name = name;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   605
            this.topic = topic;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   606
            this.players = players;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   607
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   608
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   609
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   610
    public void logInfo(final String message) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   611
        System.out.println(this.logPrefix + ": " + message);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   612
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   613
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   614
    public void logDebug(final String message) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   615
        System.out.println(this.logPrefix + "| " + message);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   616
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   617
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   618
    public void logWarning(final String message) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   619
        System.err.println(this.logPrefix + "? " + message);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   620
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   621
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   622
    public void logError(final String message) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   623
        System.err.println(this.logPrefix + "! " + message);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   624
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   625
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   626
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   627
    //private static final Object mutex = new Object();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   628
    private boolean joinSent = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   629
    private Socket socket;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   630
    private String username;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   631
    private String ownIrcNick;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   632
    private String description;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   633
    private static Map<String, Connection> connectionMap = new HashMap<String, Connection>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   634
    // TODO those MUST NOT be static!
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   635
    //private Map<String, Channel> channelMap = new HashMap<String, Channel>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   636
    private final Channel lobbyChannel;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   637
    private static String globalServerName;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   638
    private String logPrefix;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   639
    private final String clientId;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   640
    private String passwordHash = "";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   641
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   642
    private final Connection thisConnection;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   643
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   644
    public Connection(Socket socket, final String clientId) throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   645
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   646
        this.ownIrcNick = "NONAME";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   647
        this.socket = socket;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   648
        this.hostname = ((InetSocketAddress)socket.getRemoteSocketAddress())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   649
                 .getAddress().getHostAddress();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   650
        this.clientId = clientId;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   651
        updateLogPrefix();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   652
        thisConnection = this;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   653
        logInfo("New Connection");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   654
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   655
        this.hwcon = null;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   656
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   657
        try {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   658
            this.hwcon = new ProtocolConnection(this, SERVER_HOST);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   659
            logInfo("Connection to " + SERVER_HOST + " established.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   660
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   661
        catch(Exception ex) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   662
            final String errmsg = "Could not connect to " + SERVER_HOST + ": "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   663
                + ex.getMessage();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   664
            logError(errmsg);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   665
            sendQuit(errmsg);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   666
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   667
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   668
        final String lobbyTopic = " # " + SERVER_HOST + " - HEDGEWARS SERVER LOBBY # ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   669
        this.lobbyChannel = new Channel(LOBBY_CHANNEL_NAME, lobbyTopic, allPlayers);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   670
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   671
        // start in new thread
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   672
        if (hwcon != null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   673
            (this.hwcon.processMessages(true)).start();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   674
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   675
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   676
    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   677
    private void updateLogPrefix() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   678
        if (ownIrcNick == null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   679
            this.logPrefix = clientId + " ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   680
        else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   681
            this.logPrefix = clientId + " [" + ownIrcNick + "] ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   682
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   683
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   684
    private void setNick(final String nick) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   685
        if (passwordHash.isEmpty()) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   686
            try {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   687
              final Properties authProps = new Properties();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   688
              final String authFile = this.hostname + ".auth";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   689
              logInfo("Attempting to load auth info from " + authFile);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   690
              authProps.load(new FileInputStream(authFile));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   691
              passwordHash = authProps.getProperty(nick, "");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   692
              if (passwordHash.isEmpty())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   693
                logInfo("Auth info file didn't contain any password hash for: " + nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   694
            } catch (IOException e) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   695
                logInfo("Auth info file couldn't be loaded.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   696
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   697
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   698
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   699
        // append _ just in case
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   700
        if (!passwordHash.isEmpty() || nick.endsWith("_")) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   701
            ownIrcNick = nick;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   702
            hwcon.setNick(ircToHwNick(nick));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   703
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   704
        else {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   705
            final String nick_ = nick + "_";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   706
            ownIrcNick = nick_;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   707
            hwcon.setNick(ircToHwNick(nick_));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   708
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   709
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   710
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   711
    public String getRepresentation()
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   712
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   713
        return ownIrcNick + "!~" + username + "@" + hostname;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   714
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   715
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   716
    private static int lastClientId = 0;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   717
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   718
    /**
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   719
     * @param args
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   720
     */
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   721
    public static void main(String[] args) throws Throwable
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   722
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   723
        if (args.length > 0)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   724
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   725
            SERVER_HOST = args[0];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   726
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   727
        if (args.length > 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   728
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   729
            IRC_PORT = Integer.parseInt(args[1]);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   730
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   731
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   732
        globalServerName = "hw2irc";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   733
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   734
        if (!SERVER_HOST.equals(DEFAULT_SERVER_HOST))
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   735
            globalServerName += "~" + SERVER_HOST;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   736
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   737
        final int port = IRC_PORT;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   738
        ServerSocket ss = new ServerSocket(port);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   739
        System.out.println("Listening on port " + port);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   740
        while (true)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   741
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   742
            Socket s = ss.accept();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   743
            final String clientId = "client" + (++lastClientId) + '-'
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   744
                 + ((InetSocketAddress)s.getRemoteSocketAddress())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   745
                 .getAddress().getHostAddress();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   746
            try {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   747
                Connection clientCon = new Connection(s, clientId);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   748
                //clientCon.run();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   749
                Thread clientThread = new Thread(clientCon, clientId);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   750
                clientThread.start();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   751
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   752
            catch (Exception ex) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   753
                System.err.println("FATAL: Server connection thread " + clientId + " crashed on startup! " + ex.getMessage());
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   754
                ex.printStackTrace();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   755
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   756
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   757
            System.out.println("Note: Not accepting new clients for the next " + SLEEP_BETWEEN_LOGIN_DURATION + "s, trying to avoid reconnecting too quickly.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   758
            Thread.sleep(SLEEP_BETWEEN_LOGIN_DURATION * 1000);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   759
            System.out.println("Note: Accepting clients again!");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   760
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   761
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   762
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   763
    private static final int SLEEP_BETWEEN_LOGIN_DURATION = 122;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   764
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   765
    private boolean hasQuit = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   766
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   767
    public synchronized void quit(final String reason) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   768
        if (hasQuit)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   769
            return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   770
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   771
        hasQuit = true;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   772
        // disconnect from hedgewars server
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   773
        if (hwcon != null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   774
            hwcon.disconnect(reason);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   775
        // disconnect irc client
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   776
        sendQuit("Quit: " + reason);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   777
        // wait some time so that last data can be pushed
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   778
        try {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   779
            Thread.sleep(200);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   780
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   781
        catch (Exception e) { }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   782
        // terminate
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   783
        terminateConnection = true;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   784
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   785
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   786
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   787
    private static String hwActionToIrc(final String chatMsg) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   788
        if (!chatMsg.startsWith("/me ") || (chatMsg.length() <= 4))
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   789
            return chatMsg;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   790
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   791
        return MAGIC_BYTE_ACTION + "ACTION " + chatMsg.substring(4) + MAGIC_BYTE_ACTION;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   792
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   793
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   794
    private static String ircActionToHw(final String chatMsg) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   795
        if (!chatMsg.startsWith(MAGIC_BYTE_ACTION + "ACTION ") || (chatMsg.length() <= 9))
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   796
            return chatMsg;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   797
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   798
        return "/me " + chatMsg.substring(8, chatMsg.length() - 1);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   799
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   800
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   801
// TODO: why is still still being called when joining bogus channel name?
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   802
    public void join(String channelName)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   803
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   804
        if (ownPlayer == null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   805
            sendSelfNotice("Trying to join while ownPlayer == null. Aborting!");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   806
            quit("Something went horribly wrong.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   807
            return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   808
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   809
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   810
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   811
        final Channel channel = getChannel(channelName);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   812
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   813
        // TODO reserve special char for creating a new ROOM
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   814
        // it will be named after the player name by default
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   815
        // can be changed with /topic after
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   816
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   817
        // not a valid channel
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   818
        if (channel == null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   819
            sendSelfNotice("You cannot manually create channels here.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   820
            sendGlobal(ERR_NOSUCHCHANNEL + ownIrcNick + " " + channel.name
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   821
                    + " :No such channel");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   822
            return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   823
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   824
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   825
        // TODO if inRoom "Can't join rooms while still in room"
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   826
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   827
        // TODO set this based on room host/admin mode maybe
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   828
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   829
/* :testuser2131!~r@asdasdasdasd.at JOIN #asdkjasda
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   830
:weber.freenode.net MODE #asdkjasda +ns
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   831
:weber.freenode.net 353 testuser2131 @ #asdkjasda :@testuser2131
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   832
:weber.freenode.net 366 testuser2131 #asdkjasda :End of /NAMES list.
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   833
:weber.freenode.net NOTICE #asdkjasda :[freenode-info] why register and identify? your IRC nick is how people know you. http://freenode.net/faq.shtml#nicksetup
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   834
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   835
*/ 
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   836
        send(":" + ownPlayer.getIrcId() + " JOIN "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   837
         + channelName);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   838
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   839
        //send(":sheeppidgin!~r@localhost JOIN " + channelName);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   840
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   841
        ircJoined = true;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   842
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   843
        sendGlobal(":hw2irc MODE #lobby +nt");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   844
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   845
        sendTopic(channel);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   846
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   847
        sendNames(channel);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   848
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   849
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   850
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   851
    private void sendTopic(final Channel channel) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   852
        if (channel.topic != null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   853
            sendGlobal(RPL_TOPIC + ownIrcNick + " " + channel.name
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   854
                    + " :" + channel.topic);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   855
        else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   856
            sendGlobal(RPL_NOTOPIC + ownIrcNick + " " + channel.name
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   857
                    + " :No topic is set");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   858
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   859
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   860
    private void sendNames(final Channel channel) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   861
        // There is no error reply for bad channel names.
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   862
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   863
        if (channel != null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   864
            // send player list
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   865
            for (final Player player : channel.players.values()) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   866
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   867
                final String prefix;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   868
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   869
                if (player.isServerAdmin())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   870
                    prefix = (player.isServerAdmin())?"@":"%";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   871
                else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   872
                    prefix = (player.isRegistered())?"+":"";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   873
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   874
                sendGlobal(RPL_NAMREPLY + ownIrcNick + " = " + channel.name
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   875
                        + " :" + prefix + player.ircNick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   876
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   877
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   878
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   879
        sendGlobal(RPL_ENDOFNAMES + ownIrcNick + " " + channel.name
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   880
                + " :End of /NAMES list");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   881
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   882
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   883
    private void sendList(final String filter) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   884
        // id column size
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   885
        //int idl = 1 + String.valueOf(lastRoomId).length();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   886
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   887
        //if (idl < 3)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   888
            //idl = 3;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   889
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   890
        // send rooms list
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   891
        sendGlobal(RPL_LISTSTART + ownIrcNick 
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   892
            //+ String.format(" %1$" + idl + "s  #P  #T  Name", "ID"));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   893
            + String.format(" %1$s #P #T Name", "ID"));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   894
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   895
        if (filter.isEmpty() || filter.equals(".")) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   896
            // lobby
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   897
            if (filter.isEmpty())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   898
                sendGlobal(RPL_LIST + ownIrcNick + " " + LOBBY_CHANNEL_NAME
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   899
                    + " " + allPlayers.size() + " :" + lobbyChannel.topic);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   900
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   901
            // room list could be changed by server while we reply client
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   902
            synchronized (roomsSorted) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   903
                for (final Room room : roomsSorted) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   904
                    sendGlobal(RPL_LIST + ownIrcNick
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   905
                        //+ String.format(" %1$" + idl + "s  %2$2d  :%3$2d  %4$s",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   906
                        + String.format(" %1$s %2$d :%3$d  %4$s",
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   907
                            room.chan, room.nPlayers, room.nTeams, room.name));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   908
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   909
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   910
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   911
        // TODO filter
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   912
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   913
        sendGlobal(RPL_LISTEND + ownIrcNick + " " + " :End of /LIST");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   914
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   915
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   916
    private List<Player> findPlayers(final String expr) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   917
        List<Player> matches = new ArrayList<Player>(allPlayers.size());
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   918
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   919
        try {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   920
            final int flags = Pattern.CASE_INSENSITIVE + Pattern.UNICODE_CASE;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   921
            final Pattern regx = Pattern.compile(expr, flags);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   922
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   923
            for (final Player p : allPlayers.values()) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   924
                if ((regx.matcher(p.nick).find())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   925
                    || (regx.matcher(p.ircId).find())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   926
                    //|| (regx.matcher(p.version).find())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   927
                    //|| ((p.ip.length() > 2) && regx.matcher(p.ip).find())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   928
                    || (!p.getRoom().isEmpty() && regx.matcher(p.getRoom()).find())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   929
                ) matches.add(p);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   930
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   931
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   932
        catch(PatternSyntaxException ex) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   933
            sendSelfNotice("Pattern not understood: " + ex.getMessage());
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   934
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   935
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   936
        return matches;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   937
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   938
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   939
    private String buildInfoString(final String ip, final String version, final String room) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   940
        return (ip.equals("[]")?"":ip + " ") + version + (room.isEmpty()?"":" " + room);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   941
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   942
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   943
    private void sendWhoForPlayer(final Player player) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   944
        sendWhoForPlayer(LOBBY_CHANNEL_NAME, player.ircNick, (player.inRoom?player.getRoom():""), player.getIrcHostname());
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   945
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   946
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   947
    private void sendWhoForPlayer(final Player player, final String info) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   948
        sendWhoForPlayer(LOBBY_CHANNEL_NAME, player.ircNick, info, player.getIrcHostname());
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   949
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   950
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   951
    private void sendWhoForPlayer(final String nick, final String info) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   952
        sendWhoForPlayer(LOBBY_CHANNEL_NAME, nick, info);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   953
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   954
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   955
    private void sendWhoForPlayer(final String channel, final String nick, final String info) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   956
        final Player player = allPlayers.get(nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   957
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   958
        if (player == null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   959
            sendWhoForPlayer("OFFLINE", hwToIrcNick(nick), info, "hw/offline");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   960
        else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   961
            sendWhoForPlayer(channel,   player.ircNick,    info, player.getIrcHostname());
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   962
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   963
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   964
    private void sendWhoForPlayer(final String channel, final String ircNick, final String info, final String hostname) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   965
        sendGlobal(RPL_WHOREPLY + channel + " " + channel
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   966
                            + " ~" + ircNick + " " + hostname
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   967
                            + " " + globalServerName + " " + ircNick
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   968
                            + " H :0 " + info);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   969
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   970
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   971
    private void sendWhoEnd(final String ofWho) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   972
        send(RPL_ENDOFWHO + ownIrcNick + " " + ofWho
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   973
                        + " :End of /WHO list.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   974
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   975
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   976
    private void sendMotd() {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   977
        sendGlobal(RPL_MOTDSTART + ownIrcNick + " :- Message of the Day -");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   978
        final String mline = RPL_MOTD + ownIrcNick + " :";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   979
        for(final String line : DEFAULT_MOTD) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   980
            sendGlobal(mline + line);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   981
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   982
        sendGlobal(RPL_ENDOFMOTD + ownIrcNick + " :End of /MOTD command.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   983
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   984
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   985
    private Channel getChannel(final String name) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   986
        if (name.equals(LOBBY_CHANNEL_NAME)) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   987
            return lobbyChannel;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   988
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   989
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   990
        return null;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   991
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   992
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   993
    private enum Command
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   994
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   995
        PASS(1, 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   996
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   997
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   998
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
   999
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1000
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1001
                con.passwordHash = args[0];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1002
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1003
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1004
        NICK(1, 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1005
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1006
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1007
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1008
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1009
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1010
                con.setNick(args[0]);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1011
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1012
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1013
        USER(1, 4)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1014
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1015
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1016
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1017
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1018
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1019
                if (con.username != null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1020
                {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1021
                    con.send("NOTICE AUTH :You can't change your user "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1022
                            + "information after you've logged in right now.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1023
                    return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1024
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1025
                con.username = args[0];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1026
                String forDescription = args.length > 3 ? args[3]
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1027
                        : "(no description)";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1028
                con.description = forDescription;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1029
                /*
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1030
                 * Now we'll send the user their initial information.
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1031
                 */
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1032
                con.sendGlobal(RPL_WELCOME + con.ownIrcNick + " :Welcome to "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1033
                        + globalServerName + " - " + DESCRIPTION_SHORT);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1034
                con.sendGlobal("004 " + con.ownIrcNick + " " + globalServerName
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1035
                        + " " + VERSION);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1036
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1037
                con.sendMotd();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1038
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1039
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1040
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1041
        MOTD(0, 0)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1042
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1043
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1044
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1045
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1046
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1047
                con.sendMotd();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1048
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1049
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1050
        PING(1, 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1051
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1052
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1053
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1054
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1055
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1056
                con.ircPingQueue.add(args[0]);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1057
                con.hwcon.sendPing();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1058
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1059
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1060
        PONG(1, 2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1061
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1062
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1063
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1064
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1065
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1066
                con.hwcon.sendPong();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1067
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1068
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1069
        NAMES(1, 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1070
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1071
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1072
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1073
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1074
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1075
                final Channel channel = con.getChannel(args[0]);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1076
                con.sendNames(channel);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1077
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1078
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1079
        LIST(0, 2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1080
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1081
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1082
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1083
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1084
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1085
                // TODO filter by args[1] (comma sep list of chans), make # optional
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1086
                // ignore args[1] (server), TODO: maybe check and send RPL_NOSUCHSERVER if wrong
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1087
                con.sendList(args.length > 0?args[0]:"");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1088
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1089
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1090
        JOIN(1, 2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1091
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1092
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1093
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1094
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1095
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1096
                if (args.length < 1)  {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1097
                    con.sendSelfNotice("You didn't specify what you want to join!");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1098
                    return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1099
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1100
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1101
                if (con.ownPlayer == null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1102
                    con.sendSelfNotice("Lobby is not ready to be joined yet - hold on a second!");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1103
                    return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1104
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1105
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1106
                if (args[0].equals(LOBBY_CHANNEL_NAME)) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1107
                    //con.sendSelfNotice("Lobby can't be joined manually!");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1108
                    con.join(LOBBY_CHANNEL_NAME);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1109
                    return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1110
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1111
                con.sendSelfNotice("Joining rooms is not supported yet, sorry!");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1112
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1113
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1114
        WHO(0, 2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1115
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1116
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1117
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1118
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1119
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1120
                if (args.length < 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1121
                    return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1122
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1123
                final String target = args[0];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1124
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1125
                Map<String, Player> players = null;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1126
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1127
                if (target.equals(LOBBY_CHANNEL_NAME)) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1128
                    players = con.allPlayers;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1129
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1130
                // on channel join WHO is called on channel
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1131
                else if (target.equals(ROOM_CHANNEL_NAME)) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1132
                    players = con.roomPlayers;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1133
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1134
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1135
                if (players != null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1136
                    for (final Player player : players.values()) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1137
                        con.sendWhoForPlayer(player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1138
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1139
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1140
                // not a known channel. assume arg is player name
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1141
                // TODO support search expressions!
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1142
                else {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1143
                    final String nick = ircToHwNick(target);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1144
                    final Player player = con.allPlayers.get(nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1145
                    if (player != null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1146
                        con.sendWhoForPlayer(player);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1147
                    else {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1148
                        con.sendSelfNotice("WHO: No player named " + nick + ", interpreting term as pattern.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1149
                        List<Player> matches = con.findPlayers(target);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1150
                        if (matches.isEmpty())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1151
                            con.sendSelfNotice("No Match.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1152
                        else {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1153
                            for (final Player match : matches) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1154
                                con.sendWhoForPlayer(match);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1155
                            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1156
                        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1157
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1158
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1159
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1160
                con.sendWhoEnd(target);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1161
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1162
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1163
        WHOIS(1, 2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1164
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1165
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1166
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1167
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1168
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1169
                // there's an optional param in the beginning that we don't care about
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1170
                final String targets = args[args.length-1];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1171
                for (final String target : targets.split(",")) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1172
                    if (target.isEmpty())
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1173
                        continue;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1174
                    final String nick = ircToHwNick(target);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1175
                    // flag this nick as manually requested, so that response is shown
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1176
                    if (con.ircJoined) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1177
                        con.requestedInfos.add(nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1178
                        con.hwcon.requestInfo(nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1179
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1180
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1181
                    final Player player = con.allPlayers.get(nick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1182
                    if (player != null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1183
                        con.send(RPL_WHOISUSER + con.ownIrcNick + " " + target + " ~"
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1184
                                + target + " " + player.getIrcHostname() + " * : "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1185
                                + player.ircNick);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1186
                        // TODO send e.g. channels: @#lobby   or   @#123
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1187
                        con.send(RPL_ENDOFWHOIS + con.ownIrcNick + " " + target 
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1188
                                + " :End of /WHOIS list.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1189
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1190
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1191
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1192
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1193
        USERHOST(1, 5)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1194
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1195
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1196
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1197
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1198
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1199
                /*
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1200
                // TODO set server host
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1201
                con.hostname = "hw/" + SERVER_HOST;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1202
                
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1203
                ArrayList<String> replies = new ArrayList<String>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1204
                for (String s : arguments)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1205
                {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1206
                    Connection user = connectionMap.get(s);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1207
                    if (user != null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1208
                        replies.add(user.nick + "=+" + con.ownIrc + "@"
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1209
                                + con.hostname);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1210
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1211
                con.sendGlobal(RPL_USERHOST + con.ownIrcNick + " :"
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1212
                        + delimited(replies.toArray(new String[0]), " "));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1213
                */
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1214
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1215
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1216
        MODE(0, 2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1217
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1218
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1219
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1220
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1221
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1222
                final boolean forChan = args[0].startsWith("#");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1223
                
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1224
                if (args.length == 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1225
                {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1226
                    if (forChan) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1227
                        //con.sendGlobal(ERR_NOCHANMODES + args[0]
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1228
                        //                + " :Channel doesn't support modes");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1229
                        con.sendGlobal(RPL_CHANNELMODEIS + con.ownIrcNick + " " + args[0]
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1230
                                + " +nt");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1231
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1232
                    else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1233
                    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1234
                        // TODO
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1235
                        con.sendSelfNotice("User mode querying not supported yet.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1236
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1237
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1238
                else if (args.length == 2) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1239
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1240
                    if (forChan) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1241
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1242
                        final int l = args[1].length();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1243
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1244
                        for (int i = 0; i < l; i++) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1245
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1246
                            final char c = args[1].charAt(i);  
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1247
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1248
                            switch (c) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1249
                                case '+':
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1250
                                    // skip
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1251
                                    break;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1252
                                case '-':
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1253
                                    // skip
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1254
                                    break;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1255
                                case 'b':
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1256
                                    con.sendGlobal(RPL_ENDOFBANLIST
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1257
                                        + con.ownIrcNick + " " + args[0]
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1258
                                        + " :End of channel ban list");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1259
                                    break;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1260
                                case 'e':
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1261
                                    con.sendGlobal(RPL_ENDOFEXCEPTLIST
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1262
                                        + con.ownIrcNick + " " + args[0]
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1263
                                        + " :End of channel exception list");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1264
                                    break;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1265
                                default:
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1266
                                    con.sendGlobal(ERR_UNKNOWNMODE + c
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1267
                                        + " :Unknown MODE flag " + c);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1268
                                    break;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1269
                                    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1270
                            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1271
                        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1272
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1273
                    // user mode
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1274
                    else {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1275
                        con.sendGlobal(ERR_UMODEUNKNOWNFLAG + args[0]
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1276
                                        + " :Unknown MODE flag");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1277
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1278
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1279
                else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1280
                {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1281
                    con.sendSelfNotice("Specific modes not supported yet.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1282
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1283
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1284
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1285
        PART(1, 2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1286
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1287
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1288
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1289
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1290
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1291
                String[] channels = args[0].split(",");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1292
                boolean doQuit = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1293
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1294
                for (String channelName : channels)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1295
                {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1296
                    if (channelName.equals(LOBBY_CHANNEL_NAME)) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1297
                        doQuit = true;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1298
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1299
                    // TODO: part from room
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1300
                    /*
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1301
                    synchronized (mutex)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1302
                    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1303
                        Channel channel = channelMap.get(channelName);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1304
                        if (channelName == null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1305
                            con
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1306
                                    .sendSelfNotice("You're not a member of the channel "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1307
                                            + channelName
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1308
                                            + ", so you can't part it.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1309
                        else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1310
                        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1311
                            channel.send(":" + con.getRepresentation()
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1312
                                    + " PART " + channelName);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1313
                            channel.channelMembers.remove(con);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1314
                            if (channel.channelMembers.size() == 0)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1315
                                channelMap.remove(channelName);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1316
                        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1317
                    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1318
                    */
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1319
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1320
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1321
                final String reason;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1322
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1323
                if (args.length > 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1324
                    reason = args[1];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1325
                else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1326
                    reason = DEFAULT_QUIT_REASON;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1327
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1328
                // quit after parting
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1329
                if (doQuit)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1330
                    con.quit(reason);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1331
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1332
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1333
        QUIT(0, 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1334
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1335
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1336
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1337
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1338
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1339
                final String reason;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1340
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1341
                if (args.length == 0)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1342
                    reason = DEFAULT_QUIT_REASON;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1343
                else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1344
                    reason = args[0];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1345
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1346
                con.quit(reason);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1347
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1348
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1349
        PRIVMSG(2, 2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1350
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1351
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1352
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1353
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1354
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1355
                String message = ircActionToHw(args[1]);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1356
                if (message.charAt(0) == CHAT_COMMAND_CHAR) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1357
                    if (message.length() < 1 )
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1358
                        return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1359
                    message = message.substring(1);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1360
                    // TODO maybe \rebind CUSTOMCMDCHAR command
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1361
                    con.hwcon.sendCommand(con.ircToHwNick(message));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1362
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1363
                else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1364
                    con.hwcon.sendChat(con.ircToHwNick(message));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1365
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1366
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1367
        TOPIC(1, 2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1368
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1369
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1370
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1371
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1372
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1373
                final String chan = args[0];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1374
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1375
                final Channel channel = con.getChannel(chan);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1376
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1377
                if (channel == null) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1378
                    con.sendSelfNotice("No such channel for topic viewing: "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1379
                            + chan);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1380
                    return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1381
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1382
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1383
                // The user wants to see the channel topic.
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1384
                if (args.length == 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1385
                    con.sendTopic(channel);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1386
                // The user wants to set the channel topic.
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1387
                else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1388
                    channel.topic = args[1];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1389
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1390
        },
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1391
        KICK(3, 3)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1392
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1393
            @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1394
            public void run(final Connection con, final String prefix, final String[] args)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1395
                    throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1396
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1397
                final String victim = args[1];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1398
                con.logInfo("Issuing kick for " + victim);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1399
                // "KICK #channel nick :kick reason (not relevant)"
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1400
                con.hwcon.kick(ircToHwNick(victim));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1401
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1402
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1403
        ;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1404
        public final int minArgumentCount;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1405
        public final int maxArgumentCount;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1406
        
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1407
        private Command(int min, int max)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1408
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1409
            minArgumentCount = min;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1410
            maxArgumentCount = max;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1411
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1412
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1413
        public abstract void run(Connection con, String prefix,
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1414
                String[] arguments) throws Exception;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1415
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1416
    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1417
    public static String delimited(String[] items, String delimiter)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1418
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1419
        StringBuffer response = new StringBuffer();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1420
        boolean first = true;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1421
        for (String s : items)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1422
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1423
            if (first)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1424
                first = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1425
            else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1426
                response.append(delimiter);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1427
            response.append(s);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1428
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1429
        return response.toString();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1430
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1431
    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1432
    protected void sendQuit(String quitMessage)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1433
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1434
        send(":" + getRepresentation() + " QUIT :" + quitMessage);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1435
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1436
    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1437
    @Override
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1438
    public void run()
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1439
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1440
        try
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1441
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1442
            doServer();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1443
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1444
        catch (Exception e) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1445
            e.printStackTrace();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1446
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1447
        finally
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1448
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1449
            // TODO sense?
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1450
            if (ownIrcNick != null && connectionMap.get(ownIrcNick) == this) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1451
                quit("Client disconnected.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1452
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1453
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1454
            try {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1455
                socket.close();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1456
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1457
            catch (Exception e) { }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1458
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1459
            quit("Connection terminated.");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1460
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1461
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1462
    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1463
    protected void sendGlobal(String string)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1464
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1465
        send(":" + globalServerName + " " + string);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1466
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1467
    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1468
    private LinkedBlockingQueue<String> outQueue = new LinkedBlockingQueue<String>(
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1469
            1000);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1470
    
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1471
    private Thread outThread = new Thread()
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1472
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1473
        public void run()
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1474
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1475
            try
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1476
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1477
                OutputStream out = socket.getOutputStream();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1478
                while (!terminateConnection)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1479
                {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1480
                    String s = outQueue.take();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1481
                    s = s.replace("\n", "").replace("\r", "");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1482
                    s = s + "\r\n";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1483
                    out.write(s.getBytes());
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1484
                    out.flush();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1485
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1486
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1487
            catch (Exception ex)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1488
            {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1489
                thisConnection.logError("Outqueue died");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1490
                //ex.printStackTrace();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1491
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1492
            finally {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1493
                outQueue.clear();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1494
                outQueue = null;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1495
                try
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1496
                {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1497
                    socket.close();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1498
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1499
                catch (Exception e2)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1500
                {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1501
                    e2.printStackTrace();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1502
                }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1503
            }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1504
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1505
    };
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1506
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1507
    private boolean terminateConnection = false;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1508
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1509
    private void doServer() throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1510
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1511
        outThread.start();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1512
        InputStream socketIn = socket.getInputStream();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1513
        BufferedReader clientReader = new BufferedReader(new InputStreamReader(
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1514
                socketIn));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1515
        String line;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1516
        while (!terminateConnection && ((line = clientReader.readLine()) != null))
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1517
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1518
            processLine(line);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1519
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1520
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1521
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1522
    public void sanitizeInputs(final String[] inputs) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1523
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1524
        // no for-each loop, because we need write access to the elements
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1525
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1526
        final int l = inputs.length;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1527
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1528
        for (int i = 0; i < l; i++) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1529
            inputs[i] = inputs[i].replaceAll(MAGIC_BYTES, " ");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1530
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1531
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1532
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1533
    private void processLine(final String line) throws Exception
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1534
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1535
        String l = line;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1536
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1537
        // log things
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1538
        if (l.startsWith("PASS") || l.startsWith("pass"))
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1539
            this.logInfo("IRC-Client provided PASS");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1540
        else
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1541
            this.logDebug("IRC-Client: " + l);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1542
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1543
        String prefix = "";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1544
        if (l.startsWith(":"))
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1545
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1546
            String[] tokens = l.split(" ", 2);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1547
            prefix = tokens[0];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1548
            l = (tokens.length > 1 ? tokens[1] : "");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1549
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1550
        String[] tokens1 = l.split(" ", 2);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1551
        String command = tokens1[0];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1552
        l = tokens1.length > 1 ? tokens1[1] : "";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1553
        String[] tokens2 = l.split("(^| )\\:", 2);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1554
        String trailing = null;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1555
        l = tokens2[0];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1556
        if (tokens2.length > 1)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1557
            trailing = tokens2[1];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1558
        ArrayList<String> argumentList = new ArrayList<String>();
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1559
        if (!l.equals(""))
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1560
            argumentList.addAll(Arrays.asList(l.split(" ")));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1561
        if (trailing != null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1562
            argumentList.add(trailing);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1563
        final String[] args = argumentList.toArray(new String[0]);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1564
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1565
        // process command
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1566
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1567
        // numeric commands
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1568
        if (command.matches("[0-9][0-9][0-9]"))
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1569
            command = "N" + command;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1570
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1571
        final Command commandObject;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1572
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1573
        try {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1574
            commandObject = Command.valueOf(command.toUpperCase());
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1575
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1576
        catch (Exception ex) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1577
            // forward raw unknown command to hw server
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1578
            hwcon.sendCommand(ircToHwNick(line));
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1579
            return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1580
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1581
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1582
        if (args.length < commandObject.minArgumentCount
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1583
                || args.length > commandObject.maxArgumentCount)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1584
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1585
            sendSelfNotice("Invalid number of arguments for this"
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1586
                    + " command, expected not more than "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1587
                    + commandObject.maxArgumentCount + " and not less than "
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1588
                    + commandObject.minArgumentCount + " but got " + args.length
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1589
                    + " arguments");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1590
            return;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1591
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1592
        commandObject.run(this, prefix, args);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1593
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1594
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1595
    /**
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1596
     * Sends a notice from the server to the user represented by this
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1597
     * connection.
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1598
     * 
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1599
     * @param string
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1600
     *            The text to send as a notice
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1601
     */
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1602
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1603
    private void sendSelfNotice(final String string)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1604
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1605
        send(":" + globalServerName + " NOTICE " + ownIrcNick + " :" + string);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1606
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1607
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1608
    private void sendChannelNotice(final String string) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1609
        sendChannelNotice(string, globalServerName);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1610
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1611
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1612
    private void sendChannelNotice(final String string, final String from) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1613
        // TODO send to room if user is in room
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1614
        send(":" + from + " NOTICE " + LOBBY_CHANNEL_NAME + " :" + string);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1615
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1616
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1617
    private void sendServerNotice(final String string)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1618
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1619
        if (ircJoined)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1620
            sendChannelNotice(string, "[INFO]");
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1621
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1622
        sendSelfNotice(string);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1623
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1624
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1625
    private String[] padSplit(final String line, final String regex, int max)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1626
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1627
        String[] split = line.split(regex);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1628
        String[] output = new String[max];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1629
        for (int i = 0; i < output.length; i++)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1630
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1631
            output[i] = "";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1632
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1633
        for (int i = 0; i < split.length; i++)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1634
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1635
            output[i] = split[i];
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1636
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1637
        return output;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1638
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1639
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1640
    public void sendIfJoined(final String s) {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1641
        if (joined)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1642
            send(s);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1643
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1644
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1645
    public void send(final String s)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1646
    {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1647
        final Queue<String> testQueue = outQueue;
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1648
        if (testQueue != null)
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1649
        {
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1650
            this.logDebug("IRC-Server: " + s);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1651
            testQueue.add(s);
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1652
        }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1653
    }
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1654
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1655
final static String RPL_WELCOME = "001 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1656
final static String RPL_YOURHOST = "002 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1657
final static String RPL_CREATED = "003 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1658
final static String RPL_MYINFO = "004 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1659
final static String RPL_BOUNCE = "005 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1660
final static String RPL_TRACELINK = "200 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1661
final static String RPL_TRACECONNECTING = "201 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1662
final static String RPL_TRACEHANDSHAKE = "202 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1663
final static String RPL_TRACEUNKNOWN = "203 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1664
final static String RPL_TRACEOPERATOR = "204 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1665
final static String RPL_TRACEUSER = "205 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1666
final static String RPL_TRACESERVER = "206 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1667
final static String RPL_TRACESERVICE = "207 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1668
final static String RPL_TRACENEWTYPE = "208 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1669
final static String RPL_TRACECLASS = "209 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1670
final static String RPL_TRACERECONNECT = "210 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1671
final static String RPL_STATSLINKINFO = "211 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1672
final static String RPL_STATSCOMMANDS = "212 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1673
final static String RPL_STATSCLINE = "213 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1674
final static String RPL_STATSNLINE = "214 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1675
final static String RPL_STATSILINE = "215 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1676
final static String RPL_STATSKLINE = "216 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1677
final static String RPL_STATSQLINE = "217 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1678
final static String RPL_STATSYLINE = "218 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1679
final static String RPL_ENDOFSTATS = "219 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1680
final static String RPL_UMODEIS = "221 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1681
final static String RPL_SERVICEINFO = "231 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1682
final static String RPL_ENDOFSERVICES = "232 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1683
final static String RPL_SERVICE = "233 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1684
final static String RPL_SERVLIST = "234 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1685
final static String RPL_SERVLISTEND = "235 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1686
final static String RPL_STATSVLINE = "240 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1687
final static String RPL_STATSLLINE = "241 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1688
final static String RPL_STATSUPTIME = "242 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1689
final static String RPL_STATSOLINE = "243 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1690
final static String RPL_STATSHLINE = "244 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1691
final static String RPL_STATSPING = "246 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1692
final static String RPL_STATSBLINE = "247 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1693
final static String RPL_STATSDLINE = "250 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1694
final static String RPL_LUSERCLIENT = "251 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1695
final static String RPL_LUSEROP = "252 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1696
final static String RPL_LUSERUNKNOWN = "253 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1697
final static String RPL_LUSERCHANNELS = "254 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1698
final static String RPL_LUSERME = "255 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1699
final static String RPL_ADMINME = "256 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1700
final static String RPL_ADMINEMAIL = "259 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1701
final static String RPL_TRACELOG = "261 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1702
final static String RPL_TRACEEND = "262 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1703
final static String RPL_TRYAGAIN = "263 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1704
final static String RPL_NONE = "300 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1705
final static String RPL_AWAY = "301 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1706
final static String RPL_USERHOST = "302 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1707
final static String RPL_ISON = "303 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1708
final static String RPL_UNAWAY = "305 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1709
final static String RPL_NOWAWAY = "306 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1710
final static String RPL_WHOISUSER = "311 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1711
final static String RPL_WHOISSERVER = "312 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1712
final static String RPL_WHOISOPERATOR = "313 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1713
final static String RPL_WHOWASUSER = "314 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1714
final static String RPL_ENDOFWHO = "315 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1715
final static String RPL_WHOISCHANOP = "316 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1716
final static String RPL_WHOISIDLE = "317 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1717
final static String RPL_ENDOFWHOIS = "318 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1718
final static String RPL_WHOISCHANNELS = "319 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1719
final static String RPL_LISTSTART = "321 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1720
final static String RPL_LIST = "322 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1721
final static String RPL_LISTEND = "323 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1722
final static String RPL_CHANNELMODEIS = "324 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1723
final static String RPL_UNIQOPIS = "325 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1724
final static String RPL_NOTOPIC = "331 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1725
final static String RPL_TOPIC = "332 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1726
final static String RPL_INVITING = "341 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1727
final static String RPL_SUMMONING = "342 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1728
final static String RPL_INVITELIST = "346 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1729
final static String RPL_ENDOFINVITELIST = "347 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1730
final static String RPL_EXCEPTLIST = "348 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1731
final static String RPL_ENDOFEXCEPTLIST = "349 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1732
final static String RPL_VERSION = "351 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1733
final static String RPL_WHOREPLY = "352 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1734
final static String RPL_NAMREPLY = "353 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1735
final static String RPL_KILLDONE = "361 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1736
final static String RPL_CLOSING = "362 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1737
final static String RPL_CLOSEEND = "363 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1738
final static String RPL_LINKS = "364 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1739
final static String RPL_ENDOFLINKS = "365 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1740
final static String RPL_ENDOFNAMES = "366 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1741
final static String RPL_BANLIST = "367 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1742
final static String RPL_ENDOFBANLIST = "368 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1743
final static String RPL_ENDOFWHOWAS = "369 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1744
final static String RPL_INFO = "371 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1745
final static String RPL_MOTD = "372 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1746
final static String RPL_INFOSTART = "373 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1747
final static String RPL_ENDOFINFO = "374 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1748
final static String RPL_MOTDSTART = "375 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1749
final static String RPL_ENDOFMOTD = "376 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1750
final static String RPL_YOUREOPER = "381 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1751
final static String RPL_REHASHING = "382 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1752
final static String RPL_YOURESERVICE = "383 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1753
final static String RPL_MYPORTIS = "384 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1754
final static String RPL_TIME = "391 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1755
final static String RPL_USERSSTART = "392 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1756
final static String RPL_USERS = "393 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1757
final static String RPL_ENDOFUSERS = "394 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1758
final static String RPL_NOUSERS = "395 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1759
final static String ERR_NOSUCHNICK = "401 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1760
final static String ERR_NOSUCHSERVER = "402 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1761
final static String ERR_NOSUCHCHANNEL = "403 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1762
final static String ERR_CANNOTSENDTOCHAN = "404 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1763
final static String ERR_TOOMANYCHANNELS = "405 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1764
final static String ERR_WASNOSUCHNICK = "406 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1765
final static String ERR_TOOMANYTARGETS = "407 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1766
final static String ERR_NOSUCHSERVICE = "408 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1767
final static String ERR_NOORIGIN = "409 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1768
final static String ERR_NORECIPIENT = "411 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1769
final static String ERR_NOTEXTTOSEND = "412 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1770
final static String ERR_NOTOPLEVEL = "413 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1771
final static String ERR_WILDTOPLEVEL = "414 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1772
final static String ERR_BADMASK = "415 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1773
final static String ERR_UNKNOWNCOMMAND = "421 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1774
final static String ERR_NOMOTD = "422 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1775
final static String ERR_NOADMININFO = "423 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1776
final static String ERR_FILEERROR = "424 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1777
final static String ERR_NONICKNAMEGIVEN = "431 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1778
final static String ERR_ERRONEUSNICKNAME = "432 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1779
final static String ERR_NICKNAMEINUSE = "433 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1780
final static String ERR_NICKCOLLISION = "436 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1781
final static String ERR_UNAVAILRESOURCE = "437 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1782
final static String ERR_USERNOTINCHANNEL = "441 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1783
final static String ERR_NOTONCHANNEL = "442 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1784
final static String ERR_USERONCHANNEL = "443 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1785
final static String ERR_NOLOGIN = "444 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1786
final static String ERR_SUMMONDISABLED = "445 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1787
final static String ERR_USERSDISABLED = "446 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1788
final static String ERR_NOTREGISTERED = "451 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1789
final static String ERR_NEEDMOREPARAMS = "461 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1790
final static String ERR_ALREADYREGISTRED = "462 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1791
final static String ERR_NOPERMFORHOST = "463 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1792
final static String ERR_PASSWDMISMATCH = "464 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1793
final static String ERR_YOUREBANNEDCREEP = "465 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1794
final static String ERR_YOUWILLBEBANNED = "466 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1795
final static String ERR_KEYSET = "467 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1796
final static String ERR_CHANNELISFULL = "471 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1797
final static String ERR_UNKNOWNMODE = "472 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1798
final static String ERR_INVITEONLYCHAN = "473 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1799
final static String ERR_BANNEDFROMCHAN = "474 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1800
final static String ERR_BADCHANNELKEY = "475 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1801
final static String ERR_BADCHANMASK = "476 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1802
final static String ERR_NOCHANMODES = "477 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1803
final static String ERR_BANLISTFULL = "478 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1804
final static String ERR_NOPRIVILEGES = "481 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1805
final static String ERR_CHANOPRIVSNEEDED = "482 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1806
final static String ERR_CANTKILLSERVER = "483 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1807
final static String ERR_RESTRICTED = "484 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1808
final static String ERR_UNIQOPPRIVSNEEDED = "485 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1809
final static String ERR_NOOPERHOST = "491 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1810
final static String ERR_NOSERVICEHOST = "492 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1811
final static String ERR_UMODEUNKNOWNFLAG = "501 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1812
final static String ERR_USERSDONTMATCH = "502 ";
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1813
823cf18be1fc Hedgewars lobby to IRC proxy
sheepluva
parents:
diff changeset
  1814
}