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