project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Netplay.java
author Wuzzy <almikes@aol.com>
Fri, 28 Apr 2017 02:45:19 +0200
changeset 12377 35e76306b016
parent 10017 de822cd3df3a
child 15516 fb23e49b2d4e
permissions -rw-r--r--
ACF, mission 3: Fix Lua error spam when Dense Cloud dies in the pit sequence
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     1
/*
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     4
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     5
 * This program is free software; you can redistribute it and/or
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     6
 * modify it under the terms of the GNU General Public License
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     8
 * of the License, or (at your option) any later version.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
     9
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    13
 * GNU General Public License for more details.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    14
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    15
 * You should have received a copy of the GNU General Public License
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    16
 * along with this program; if not, write to the Free Software
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    18
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    19
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    20
package org.hedgewars.hedgeroid.netplay;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    21
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    22
import static org.hedgewars.hedgeroid.netplay.ThreadedNetConnection.ToNetMsgType.*;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    23
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    24
import java.io.IOException;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    25
import java.util.Arrays;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    26
import java.util.Collections;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    27
import java.util.LinkedList;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    28
import java.util.List;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    29
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    30
import org.hedgewars.hedgeroid.RoomStateManager;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    31
import org.hedgewars.hedgeroid.Datastructures.GameConfig;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    32
import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    33
import org.hedgewars.hedgeroid.Datastructures.Player;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    34
import org.hedgewars.hedgeroid.Datastructures.PlayerInRoom;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    35
import org.hedgewars.hedgeroid.Datastructures.Room;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    36
import org.hedgewars.hedgeroid.Datastructures.Scheme;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    37
import org.hedgewars.hedgeroid.Datastructures.Schemes;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    38
import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    39
import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    40
import org.hedgewars.hedgeroid.Datastructures.Weaponset;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    41
import org.hedgewars.hedgeroid.Datastructures.Weaponsets;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    42
import org.hedgewars.hedgeroid.netplay.ThreadedNetConnection.ToNetMsgType;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    43
import org.hedgewars.hedgeroid.util.ObservableTreeMap;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    44
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    45
import android.annotation.SuppressLint;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    46
import android.content.Context;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    47
import android.content.Intent;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    48
import android.os.Handler;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    49
import android.os.Looper;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    50
import android.os.Message;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    51
import android.support.v4.content.LocalBroadcastManager;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    52
import android.util.Log;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    53
import android.util.Pair;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    54
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    55
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    56
/**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    57
 * This class manages the application's networking state.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    58
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    59
public class Netplay {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    60
    public static enum State { NOT_CONNECTED, CONNECTING, LOBBY, ROOM }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    61
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    62
    // Extras in broadcasts
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    63
    public static final String EXTRA_PLAYERNAME = "playerName";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    64
    public static final String EXTRA_MESSAGE = "message";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    65
    public static final String EXTRA_HAS_ERROR = "hasError";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    66
    public static final String EXTRA_REASON = "reason";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    67
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    68
    private static final String ACTIONPREFIX = "org.hedgewars.hedgeroid.netconn.";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    69
    public static final String ACTION_DISCONNECTED = ACTIONPREFIX+"DISCONNECTED";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    70
    public static final String ACTION_CONNECTED = ACTIONPREFIX+"CONNECTED";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    71
    public static final String ACTION_PASSWORD_REQUESTED = ACTIONPREFIX+"PASSWORD_REQUESTED";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    72
    public static final String ACTION_ENTERED_ROOM_FROM_LOBBY = ACTIONPREFIX+"ENTERED_ROOM";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    73
    public static final String ACTION_LEFT_ROOM = ACTIONPREFIX+"LEFT_ROOM";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    74
    public static final String ACTION_STATE_CHANGED = ACTIONPREFIX+"STATE_CHANGED";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    75
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    76
    public static final String DEFAULT_SERVER = "netserver.hedgewars.org";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    77
    public static final int DEFAULT_PORT = 46631;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    78
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    79
    private final Context appContext;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    80
    private final LocalBroadcastManager broadcastManager;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    81
    private final FromNetHandler fromNetHandler = new FromNetHandler();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    82
    public final Scheme defaultScheme;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    83
    public final Weaponset defaultWeaponset;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    84
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    85
    private State state = State.NOT_CONNECTED;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    86
    private String playerName;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    87
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    88
    // null or stale if not in room state
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    89
    private final NetRoomState netRoomState = new NetRoomState(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    90
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    91
    // null if there is no running connection (==state is NOT_CONNECTED)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    92
    private ThreadedNetConnection connection;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    93
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    94
    public final ObservableTreeMap<String, Player> lobbyPlayerlist = new ObservableTreeMap<String, Player>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    95
    public final ObservableTreeMap<String, PlayerInRoom> roomPlayerlist = new ObservableTreeMap<String, PlayerInRoom>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    96
    public final Roomlist roomList = new Roomlist();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    97
    public final MessageLog lobbyChatlog;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    98
    public final MessageLog roomChatlog;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    99
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   100
    private final List<GameMessageListener> gameMessageListeners = new LinkedList<GameMessageListener>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   101
    private final List<RunGameListener> runGameListeners = new LinkedList<RunGameListener>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   102
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   103
    public Netplay(Context appContext, Scheme defaultScheme, Weaponset defaultWeaponset) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   104
        this.appContext = appContext;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   105
        broadcastManager = LocalBroadcastManager.getInstance(appContext);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   106
        lobbyChatlog = new MessageLog(appContext);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   107
        roomChatlog = new MessageLog(appContext);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   108
        this.defaultScheme = defaultScheme;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   109
        this.defaultWeaponset = defaultWeaponset;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   110
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   111
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   112
    public RoomStateManager getRoomStateManager() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   113
        return netRoomState;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   114
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   115
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   116
    private void clearLobbyState() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   117
        lobbyPlayerlist.clear();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   118
        roomList.clear();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   119
        lobbyChatlog.clear();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   120
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   121
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   122
    private void initRoomState(boolean chief) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   123
        roomChatlog.clear();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   124
        roomPlayerlist.clear();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   125
        netRoomState.initRoomState(chief);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   126
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   127
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   128
    public void registerGameMessageListener(GameMessageListener listener) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   129
        gameMessageListeners.add(listener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   130
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   131
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   132
    public void unregisterGameMessageListener(GameMessageListener listener) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   133
        gameMessageListeners.remove(listener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   134
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   135
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   136
    public void registerRunGameListener(RunGameListener listener) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   137
        runGameListeners.add(listener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   138
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   139
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   140
    public void unregisterRunGameListener(RunGameListener listener) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   141
        runGameListeners.remove(listener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   142
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   143
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   144
    public void connectToDefaultServer(String playerName) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   145
        connect(playerName, DEFAULT_SERVER, DEFAULT_PORT);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   146
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   147
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   148
    /**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   149
     * Establish a new connection. Only call if the current state is NOT_CONNECTED.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   150
     *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   151
     * The state will switch to CONNECTING immediately. After that, it can asynchronously change to any other state.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   152
     * State changes are indicated by broadcasts. In particular, if an error occurs while trying to connect, the state
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   153
     * will change back to NOT_CONNECTED and an ACTION_DISCONNECTED broadcast is sent.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   154
     */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   155
    public void connect(String name, String host, int port) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   156
        playerName = name;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   157
        if(state != State.NOT_CONNECTED) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   158
            throw new IllegalStateException("Attempt to start a new connection while the old one was still running.");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   159
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   160
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   161
        clearLobbyState();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   162
        changeState(State.CONNECTING);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   163
        connection = ThreadedNetConnection.startConnection(appContext, fromNetHandler, name, host, port);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   164
        connection.setFastTickRate(true);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   165
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   166
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   167
    public void sendNick(String nick) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   168
        playerName = nick;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   169
        sendToNet(MSG_SEND_NICK, nick);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   170
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   171
    public void sendPassword(String password) { sendToNet(MSG_SEND_PASSWORD, password); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   172
    public void sendQuit(String message) { sendToNet(MSG_SEND_QUIT, message); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   173
    public void sendRoomlistRequest() { sendToNet(MSG_SEND_ROOMLIST_REQUEST); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   174
    public void sendPlayerInfoQuery(String name) { sendToNet(MSG_SEND_PLAYER_INFO_REQUEST, name); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   175
    public void sendChat(String s) { sendToNet(MSG_SEND_CHAT, s); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   176
    public void sendTeamChat(String s) { sendToNet(MSG_SEND_TEAMCHAT, s); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   177
    public void sendFollowPlayer(String nick) { sendToNet(MSG_SEND_FOLLOW_PLAYER, nick); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   178
    public void sendJoinRoom(String name) { sendToNet(MSG_SEND_JOIN_ROOM, name); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   179
    public void sendCreateRoom(String name) { sendToNet(MSG_SEND_CREATE_ROOM, name); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   180
    public void sendLeaveRoom(String message) { sendToNet(MSG_SEND_LEAVE_ROOM, message); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   181
    public void sendKick(String player) { sendToNet(MSG_SEND_KICK, player); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   182
    public void sendEngineMessage(byte[] engineMessage) { sendToNet(MSG_SEND_ENGINE_MESSAGE, engineMessage); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   183
    public void sendRoundFinished(boolean withoutError) { sendToNet(MSG_SEND_ROUND_FINISHED, Boolean.valueOf(withoutError)); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   184
    public void sendToggleReady() { sendToNet(MSG_SEND_TOGGLE_READY); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   185
    public void sendStartGame() { sendToNet(MSG_SEND_START_GAME); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   186
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   187
    public void disconnect() { sendToNet(MSG_DISCONNECT, "User Quit"); }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   188
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   189
    private static Netplay instance;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   190
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   191
    /**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   192
     * Retrieve the single app-wide instance of the netplay interface, creating it if it
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   193
     * does not exist yet.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   194
     *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   195
     * @param applicationContext
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   196
     * @return
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   197
     */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   198
    public static Netplay getAppInstance(Context applicationContext) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   199
        if(instance == null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   200
            // We will need some default values for rooms, best load them here
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   201
            Scheme defaultScheme = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   202
            Weaponset defaultWeaponset = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   203
            try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   204
                List<Scheme> schemes = Schemes.loadBuiltinSchemes(applicationContext);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   205
                for(Scheme scheme : schemes) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   206
                    if(scheme.name.equals(GameConfig.DEFAULT_SCHEME)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   207
                        defaultScheme = scheme;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   208
                    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   209
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   210
                List<Weaponset> weaponsets = Weaponsets.loadBuiltinWeaponsets(applicationContext);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   211
                for(Weaponset weaponset : weaponsets) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   212
                    if(weaponset.name.equals(GameConfig.DEFAULT_WEAPONSET)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   213
                        defaultWeaponset = weaponset;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   214
                    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   215
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   216
            } catch(IOException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   217
                throw new RuntimeException(e);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   218
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   219
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   220
            if(defaultScheme==null || defaultWeaponset==null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   221
                throw new RuntimeException("Unable to load default scheme or weaponset");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   222
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   223
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   224
            instance = new Netplay(applicationContext, defaultScheme, defaultWeaponset);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   225
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   226
        return instance;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   227
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   228
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   229
    public State getState() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   230
        return state;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   231
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   232
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   233
    private void changeState(State newState) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   234
        if(newState != state) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   235
            state = newState;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   236
            broadcastManager.sendBroadcastSync(new Intent(ACTION_STATE_CHANGED));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   237
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   238
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   239
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   240
    public boolean isChief() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   241
        if(netRoomState != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   242
            return netRoomState.getChiefStatus();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   243
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   244
            return false;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   245
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   246
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   247
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   248
    public String getPlayerName() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   249
        return playerName;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   250
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   251
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   252
    boolean sendToNet(ToNetMsgType what) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   253
        return sendToNet(what, 0, null);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   254
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   255
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   256
    boolean sendToNet(ToNetMsgType what, Object obj) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   257
        return sendToNet(what, 0, obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   258
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   259
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   260
    boolean sendToNet(ToNetMsgType what, int arg1, Object obj) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   261
        if(connection != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   262
            Handler handler = connection.toNetHandler;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   263
            return handler.sendMessage(handler.obtainMessage(what.ordinal(), arg1, 0, obj));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   264
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   265
            return false;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   266
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   267
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   268
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   269
    private MessageLog getCurrentLog() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   270
        if(state == State.ROOM) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   271
            return roomChatlog;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   272
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   273
            return lobbyChatlog;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   274
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   275
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   276
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   277
    public static enum FromNetMsgType {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   278
        MSG_LOBBY_JOIN,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   279
        MSG_LOBBY_LEAVE,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   280
        MSG_ROOM_JOIN,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   281
        MSG_ROOM_LEAVE,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   282
        MSG_CLIENT_FLAGS,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   283
        MSG_CHAT,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   284
        MSG_MESSAGE,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   285
        MSG_ROOM_ADD,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   286
        MSG_ROOM_UPDATE,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   287
        MSG_ROOM_DELETE,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   288
        MSG_ROOMLIST,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   289
        MSG_CONNECTED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   290
        MSG_DISCONNECTED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   291
        MSG_PASSWORD_REQUEST,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   292
        MSG_ENTER_ROOM_FROM_LOBBY,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   293
        MSG_LEAVE_ROOM,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   294
        MSG_TEAM_ADDED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   295
        MSG_TEAM_DELETED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   296
        MSG_TEAM_ACCEPTED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   297
        MSG_TEAM_COLOR_CHANGED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   298
        MSG_HOG_COUNT_CHANGED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   299
        MSG_ENGINE_MESSAGE,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   300
        MSG_RUN_GAME,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   301
        MSG_SCHEME_CHANGED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   302
        MSG_MAP_CHANGED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   303
        MSG_SCRIPT_CHANGED,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   304
        MSG_WEAPONSET_CHANGED;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   305
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   306
        static final List<FromNetMsgType> values = Collections.unmodifiableList(Arrays.asList(FromNetMsgType.values()));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   307
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   308
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   309
    /**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   310
     * Processes messages from the networking system. Always runs on the main thread.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   311
     */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   312
    @SuppressLint("HandlerLeak")
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   313
    final class FromNetHandler extends Handler {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   314
        public FromNetHandler() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   315
            super(Looper.getMainLooper());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   316
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   317
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   318
        @SuppressWarnings("unchecked")
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   319
        @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   320
        public void handleMessage(Message msg) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   321
            switch(FromNetMsgType.values.get(msg.what)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   322
            case MSG_LOBBY_JOIN: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   323
                String name = (String)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   324
                lobbyPlayerlist.put(name, new Player(name, false, false));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   325
                lobbyChatlog.appendPlayerJoin(name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   326
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   327
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   328
            case MSG_LOBBY_LEAVE: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   329
                Pair<String, String> args = (Pair<String, String>)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   330
                lobbyPlayerlist.remove(args.first);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   331
                lobbyChatlog.appendPlayerLeave(args.first, args.second);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   332
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   333
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   334
            case MSG_ROOM_JOIN: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   335
                String name = (String)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   336
                Player p = lobbyPlayerlist.get(name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   337
                if(p==null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   338
                    Log.w("Netplay", "Unknown player joined room: "+name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   339
                    p = new Player(name, false, false);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   340
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   341
                roomPlayerlist.put(name, new PlayerInRoom(p, false, false));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   342
                roomChatlog.appendPlayerJoin(name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   343
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   344
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   345
            case MSG_ROOM_LEAVE: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   346
                Pair<String, String> args = (Pair<String, String>)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   347
                roomPlayerlist.remove(args.first);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   348
                roomChatlog.appendPlayerLeave(args.first, args.second);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   349
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   350
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   351
            case MSG_CLIENT_FLAGS: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   352
                ClientFlagsUpdate upd = (ClientFlagsUpdate)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   353
                PlayerInRoom pir = roomPlayerlist.get(upd.nick);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   354
                if(pir != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   355
                    roomPlayerlist.put(upd.nick, upd.applyTo(pir));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   356
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   357
                Player p = lobbyPlayerlist.get(upd.nick);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   358
                if(p != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   359
                    lobbyPlayerlist.put(upd.nick, upd.applyTo(p));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   360
                } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   361
                    Log.w("Netplay", "Received client flags for unknown player "+upd.nick);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   362
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   363
                if(playerName.equals(upd.nick) && upd.appliesTo(ClientFlagsUpdate.FLAG_CHIEF)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   364
                    netRoomState.setChief(upd.newFlagState);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   365
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   366
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   367
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   368
            case MSG_CHAT: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   369
                Pair<String, String> args = (Pair<String, String>)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   370
                getCurrentLog().appendChat(args.first, args.second);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   371
                for(GameMessageListener listener : gameMessageListeners) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   372
                    listener.onChatMessage(args.first, args.second);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   373
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   374
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   375
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   376
            case MSG_MESSAGE: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   377
                getCurrentLog().appendMessage(msg.arg1, (String)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   378
                for(GameMessageListener listener : gameMessageListeners) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   379
                    listener.onMessage(1, (String)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   380
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   381
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   382
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   383
            case MSG_ROOM_ADD: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   384
                Room room = (Room)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   385
                roomList.addRoomWithNewId(room);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   386
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   387
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   388
            case MSG_ROOM_UPDATE: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   389
                Pair<String, Room> args = (Pair<String, Room>)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   390
                roomList.updateRoom(args.first, args.second);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   391
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   392
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   393
            case MSG_ROOM_DELETE: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   394
                roomList.remove((String)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   395
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   396
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   397
            case MSG_ROOMLIST: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   398
                Room[] rooms = (Room[])msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   399
                roomList.updateList(rooms);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   400
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   401
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   402
            case MSG_CONNECTED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   403
                playerName = (String)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   404
                changeState(State.LOBBY);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   405
                broadcastManager.sendBroadcast(new Intent(ACTION_CONNECTED));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   406
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   407
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   408
            case MSG_DISCONNECTED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   409
                Pair<Boolean, String> args = (Pair<Boolean, String>)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   410
                for(GameMessageListener listener : gameMessageListeners) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   411
                    listener.onNetDisconnected();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   412
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   413
                changeState(State.NOT_CONNECTED);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   414
                connection = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   415
                Intent intent = new Intent(ACTION_DISCONNECTED);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   416
                intent.putExtra(EXTRA_HAS_ERROR, args.first);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   417
                intent.putExtra(EXTRA_MESSAGE, args.second);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   418
                broadcastManager.sendBroadcastSync(intent);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   419
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   420
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   421
            case MSG_PASSWORD_REQUEST: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   422
                Intent intent = new Intent(ACTION_PASSWORD_REQUESTED);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   423
                intent.putExtra(EXTRA_PLAYERNAME, (String)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   424
                broadcastManager.sendBroadcast(intent);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   425
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   426
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   427
            case MSG_ENTER_ROOM_FROM_LOBBY: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   428
                initRoomState((Boolean)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   429
                changeState(State.ROOM);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   430
                Intent intent = new Intent(ACTION_ENTERED_ROOM_FROM_LOBBY);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   431
                broadcastManager.sendBroadcastSync(intent);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   432
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   433
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   434
            case MSG_LEAVE_ROOM: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   435
                changeState(State.LOBBY);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   436
                Intent intent = new Intent(ACTION_LEFT_ROOM);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   437
                intent.putExtra(EXTRA_MESSAGE, (String)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   438
                intent.putExtra(EXTRA_REASON, msg.arg1);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   439
                broadcastManager.sendBroadcastSync(intent);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   440
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   441
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   442
            case MSG_TEAM_ADDED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   443
                TeamInGame newTeam = (TeamInGame)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   444
                if(isChief()) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   445
                    int freeColor = TeamInGame.getUnusedOrRandomColorIndex(netRoomState.getTeams().values());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   446
                    sendToNet(MSG_SEND_TEAM_HOG_COUNT, newTeam.ingameAttribs.hogCount, newTeam.team.name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   447
                    sendToNet(MSG_SEND_TEAM_COLOR_INDEX, freeColor, newTeam.team.name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   448
                    newTeam = newTeam.withAttribs(newTeam.ingameAttribs.withColorIndex(freeColor));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   449
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   450
                netRoomState.putTeam(newTeam);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   451
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   452
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   453
            case MSG_TEAM_DELETED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   454
                netRoomState.removeTeam((String)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   455
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   456
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   457
            case MSG_TEAM_ACCEPTED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   458
                TeamInGame requestedTeam = netRoomState.requestedTeams.remove(msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   459
                if(requestedTeam!=null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   460
                    netRoomState.putTeam(requestedTeam);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   461
                    if(isChief()) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   462
                        // Not strictly necessary, but QtFrontend does it...
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   463
                        sendToNet(MSG_SEND_TEAM_HOG_COUNT, requestedTeam.ingameAttribs.hogCount, requestedTeam.team.name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   464
                    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   465
                } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   466
                    Log.e("Netplay", "Got accepted message for team that was never requested.");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   467
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   468
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   469
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   470
            case MSG_TEAM_COLOR_CHANGED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   471
                TeamInGame oldEntry = netRoomState.getTeams().get((String)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   472
                if(oldEntry != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   473
                    /*
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   474
                     * If we are chief, we ignore colors from the outside. They only come from the server
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   475
                     * when someone adds a team then, and we override that choice anyway.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   476
                     * Worse, that color message arrives *after* we have overridden the color, so it would
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   477
                     * re-override it right back.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   478
                     */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   479
                    if(!isChief()) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   480
                        TeamIngameAttributes newAttribs = oldEntry.ingameAttribs.withColorIndex(msg.arg1);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   481
                        netRoomState.putTeam(oldEntry.withAttribs(newAttribs));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   482
                    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   483
                } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   484
                    Log.e("Netplay", "Color update for unknown team "+msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   485
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   486
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   487
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   488
            case MSG_HOG_COUNT_CHANGED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   489
                TeamInGame oldEntry = netRoomState.getTeams().get((String)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   490
                if(oldEntry != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   491
                    TeamIngameAttributes newAttribs = oldEntry.ingameAttribs.withHogCount(msg.arg1);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   492
                    netRoomState.putTeam(oldEntry.withAttribs(newAttribs));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   493
                } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   494
                    Log.e("Netplay", "Hog count update for unknown team "+msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   495
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   496
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   497
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   498
            case MSG_ENGINE_MESSAGE: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   499
                byte[] em = (byte[])msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   500
                for(GameMessageListener listener : gameMessageListeners) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   501
                    listener.onEngineMessage(em);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   502
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   503
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   504
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   505
            case MSG_RUN_GAME: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   506
                GameConfig config = (GameConfig)msg.obj;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   507
                for(RunGameListener listener : runGameListeners) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   508
                    listener.runGame(config);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   509
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   510
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   511
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   512
            case MSG_MAP_CHANGED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   513
                netRoomState.setMapRecipe((MapRecipe)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   514
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   515
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   516
            case MSG_SCHEME_CHANGED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   517
                netRoomState.setScheme((Scheme)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   518
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   519
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   520
            case MSG_SCRIPT_CHANGED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   521
                netRoomState.setGameStyle((String)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   522
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   523
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   524
            case MSG_WEAPONSET_CHANGED: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   525
                netRoomState.setWeaponset((Weaponset)msg.obj);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   526
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   527
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   528
            default: {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   529
                Log.e("FromNetHandler", "Unknown message type: "+msg.what);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   530
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   531
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   532
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   533
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   534
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
   535
}