author | Medo <smaxein@googlemail.com> |
Sun, 16 Sep 2012 22:31:34 +0200 | |
changeset 7691 | 55c0a856ecd0 |
parent 7588 | 27e5857da6af |
child 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
1 |
/* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
4 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
9 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
13 |
* GNU General Public License for more details. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
14 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
18 |
*/ |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
19 |
|
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
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
|
21 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
22 |
import static org.hedgewars.hedgeroid.netplay.ThreadedNetConnection.ToNetMsgType.*; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
23 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
24 |
import java.io.IOException; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
25 |
import java.util.Arrays; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
26 |
import java.util.Collections; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
27 |
import java.util.LinkedList; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
28 |
import java.util.List; |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
30 |
import org.hedgewars.hedgeroid.RoomStateManager; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
31 |
import org.hedgewars.hedgeroid.Datastructures.GameConfig; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
32 |
import org.hedgewars.hedgeroid.Datastructures.MapRecipe; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
33 |
import org.hedgewars.hedgeroid.Datastructures.Player; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
34 |
import org.hedgewars.hedgeroid.Datastructures.PlayerInRoom; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
35 |
import org.hedgewars.hedgeroid.Datastructures.Room; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
36 |
import org.hedgewars.hedgeroid.Datastructures.Scheme; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
37 |
import org.hedgewars.hedgeroid.Datastructures.Schemes; |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
38 |
import org.hedgewars.hedgeroid.Datastructures.TeamInGame; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
39 |
import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
40 |
import org.hedgewars.hedgeroid.Datastructures.Weaponset; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
41 |
import org.hedgewars.hedgeroid.Datastructures.Weaponsets; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
42 |
import org.hedgewars.hedgeroid.netplay.ThreadedNetConnection.ToNetMsgType; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
43 |
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
|
44 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
/** |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
57 |
* 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
|
58 |
*/ |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
59 |
public class Netplay { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
60 |
public static enum State { NOT_CONNECTED, CONNECTING, LOBBY, ROOM } |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
61 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
62 |
// Extras in broadcasts |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
public static final String EXTRA_HAS_ERROR = "hasError"; |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
66 |
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
|
67 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
public static final String ACTION_LEFT_ROOM = ACTIONPREFIX+"LEFT_ROOM"; |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
74 |
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
|
75 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
76 |
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
|
77 |
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
|
78 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
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
|
80 |
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
|
81 |
private final FromNetHandler fromNetHandler = new FromNetHandler(); |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
82 |
public final Scheme defaultScheme; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
83 |
public final Weaponset defaultWeaponset; |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
84 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
85 |
private State state = State.NOT_CONNECTED; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
86 |
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
|
87 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
88 |
// null or stale if not in room state |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
89 |
private final NetRoomState netRoomState = new NetRoomState(this); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
90 |
|
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
91 |
// 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
|
92 |
private ThreadedNetConnection connection; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
93 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
public final MessageLog roomChatlog; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
99 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
100 |
private final List<GameMessageListener> gameMessageListeners = new LinkedList<GameMessageListener>(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
101 |
private final List<RunGameListener> runGameListeners = new LinkedList<RunGameListener>(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
102 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
103 |
public Netplay(Context appContext, Scheme defaultScheme, Weaponset defaultWeaponset) { |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
104 |
this.appContext = appContext; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
roomChatlog = new MessageLog(appContext); |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
108 |
this.defaultScheme = defaultScheme; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
109 |
this.defaultWeaponset = defaultWeaponset; |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
110 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
111 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
112 |
public RoomStateManager getRoomStateManager() { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
113 |
return netRoomState; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
114 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
115 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
116 |
private void clearLobbyState() { |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
117 |
lobbyPlayerlist.clear(); |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
118 |
roomList.clear(); |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
119 |
lobbyChatlog.clear(); |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
120 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
121 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
122 |
private void initRoomState(boolean chief) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
123 |
roomChatlog.clear(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
124 |
roomPlayerlist.clear(); |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
125 |
netRoomState.initRoomState(chief); |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
126 |
} |
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 |
public void registerGameMessageListener(GameMessageListener listener) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
129 |
gameMessageListeners.add(listener); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
130 |
} |
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 |
public void unregisterGameMessageListener(GameMessageListener listener) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
133 |
gameMessageListeners.remove(listener); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
134 |
} |
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 |
public void registerRunGameListener(RunGameListener listener) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
137 |
runGameListeners.add(listener); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
138 |
} |
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 |
public void unregisterRunGameListener(RunGameListener listener) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
141 |
runGameListeners.remove(listener); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
142 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
143 |
|
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
} |
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 |
/** |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
149 |
* 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
|
150 |
* |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
151 |
* 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
|
152 |
* 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
|
153 |
* 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
|
154 |
*/ |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
155 |
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
|
156 |
playerName = name; |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
157 |
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
|
158 |
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
|
159 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
160 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
161 |
clearLobbyState(); |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
162 |
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
|
163 |
connection = ThreadedNetConnection.startConnection(appContext, fromNetHandler, name, host, port); |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
164 |
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
|
165 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
166 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
167 |
public void sendNick(String nick) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
168 |
playerName = nick; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
169 |
sendToNet(MSG_SEND_NICK, nick); |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
170 |
} |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
171 |
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
|
172 |
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
|
173 |
public void sendRoomlistRequest() { sendToNet(MSG_SEND_ROOMLIST_REQUEST); } |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
public void sendKick(String player) { sendToNet(MSG_SEND_KICK, player); } |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
182 |
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
|
183 |
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
|
184 |
public void sendToggleReady() { sendToNet(MSG_SEND_TOGGLE_READY); } |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
185 |
public void sendStartGame() { sendToNet(MSG_SEND_START_GAME); } |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
186 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
187 |
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
|
188 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
189 |
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
|
190 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
191 |
/** |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
192 |
* 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
|
193 |
* 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
|
194 |
* |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
195 |
* @param applicationContext |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
196 |
* @return |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
197 |
*/ |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
198 |
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
|
199 |
if(instance == null) { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
200 |
// We will need some default values for rooms, best load them here |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
201 |
Scheme defaultScheme = null; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
202 |
Weaponset defaultWeaponset = null; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
203 |
try { |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
204 |
List<Scheme> schemes = Schemes.loadBuiltinSchemes(applicationContext); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
205 |
for(Scheme scheme : schemes) { |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
206 |
if(scheme.name.equals(GameConfig.DEFAULT_SCHEME)) { |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
207 |
defaultScheme = scheme; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
208 |
} |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
209 |
} |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
210 |
List<Weaponset> weaponsets = Weaponsets.loadBuiltinWeaponsets(applicationContext); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
211 |
for(Weaponset weaponset : weaponsets) { |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
212 |
if(weaponset.name.equals(GameConfig.DEFAULT_WEAPONSET)) { |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
213 |
defaultWeaponset = weaponset; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
214 |
} |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
215 |
} |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
216 |
} catch(IOException e) { |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
217 |
throw new RuntimeException(e); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
218 |
} |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
219 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
220 |
if(defaultScheme==null || defaultWeaponset==null) { |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
221 |
throw new RuntimeException("Unable to load default scheme or weaponset"); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
222 |
} |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
223 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
224 |
instance = new Netplay(applicationContext, defaultScheme, defaultWeaponset); |
7358
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 |
return instance; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
227 |
} |
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 |
public State getState() { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
230 |
return state; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
231 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
232 |
|
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
233 |
private void changeState(State newState) { |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
234 |
if(newState != state) { |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
235 |
state = newState; |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
236 |
broadcastManager.sendBroadcastSync(new Intent(ACTION_STATE_CHANGED)); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
237 |
} |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
238 |
} |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
239 |
|
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
240 |
public boolean isChief() { |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
241 |
if(netRoomState != null) { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
242 |
return netRoomState.getChiefStatus(); |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
243 |
} else { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
244 |
return false; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
245 |
} |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
246 |
} |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
247 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
248 |
public String getPlayerName() { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
249 |
return playerName; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
250 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
251 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
252 |
boolean sendToNet(ToNetMsgType what) { |
7485 | 253 |
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
|
254 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
255 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
256 |
boolean sendToNet(ToNetMsgType what, Object obj) { |
7485 | 257 |
return sendToNet(what, 0, obj); |
258 |
} |
|
259 |
||
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
260 |
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
|
261 |
if(connection != null) { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
262 |
Handler handler = connection.toNetHandler; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
263 |
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
|
264 |
} else { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
265 |
return false; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
266 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
267 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
268 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
269 |
private MessageLog getCurrentLog() { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
270 |
if(state == State.ROOM) { |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
271 |
return roomChatlog; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
272 |
} else { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
273 |
return lobbyChatlog; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
274 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
275 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
276 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
277 |
public static enum FromNetMsgType { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
278 |
MSG_LOBBY_JOIN, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
279 |
MSG_LOBBY_LEAVE, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
280 |
MSG_ROOM_JOIN, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
281 |
MSG_ROOM_LEAVE, |
7691
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
282 |
MSG_CLIENT_FLAGS, |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
283 |
MSG_CHAT, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
284 |
MSG_MESSAGE, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
285 |
MSG_ROOM_ADD, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
286 |
MSG_ROOM_UPDATE, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
287 |
MSG_ROOM_DELETE, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
288 |
MSG_ROOMLIST, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
289 |
MSG_CONNECTED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
290 |
MSG_DISCONNECTED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
291 |
MSG_PASSWORD_REQUEST, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
292 |
MSG_ENTER_ROOM_FROM_LOBBY, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
293 |
MSG_LEAVE_ROOM, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
294 |
MSG_TEAM_ADDED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
295 |
MSG_TEAM_DELETED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
296 |
MSG_TEAM_ACCEPTED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
297 |
MSG_TEAM_COLOR_CHANGED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
298 |
MSG_HOG_COUNT_CHANGED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
299 |
MSG_ENGINE_MESSAGE, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
300 |
MSG_RUN_GAME, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
301 |
MSG_SCHEME_CHANGED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
302 |
MSG_MAP_CHANGED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
303 |
MSG_SCRIPT_CHANGED, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
304 |
MSG_WEAPONSET_CHANGED; |
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 |
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
|
307 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
308 |
|
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
309 |
/** |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
310 |
* 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
|
311 |
*/ |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
312 |
@SuppressLint("HandlerLeak") |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
313 |
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
|
314 |
public FromNetHandler() { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
315 |
super(Looper.getMainLooper()); |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
316 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
317 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
318 |
@SuppressWarnings("unchecked") |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
319 |
@Override |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
320 |
public void handleMessage(Message msg) { |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
321 |
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
|
322 |
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
|
323 |
String name = (String)msg.obj; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
324 |
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
|
325 |
lobbyChatlog.appendPlayerJoin(name); |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
326 |
break; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
327 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
328 |
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
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
break; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
333 |
} |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
334 |
case MSG_ROOM_JOIN: { |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
335 |
String name = (String)msg.obj; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
336 |
Player p = lobbyPlayerlist.get(name); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
337 |
if(p==null) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
338 |
Log.w("Netplay", "Unknown player joined room: "+name); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
339 |
p = new Player(name, false, false); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
340 |
} |
7691
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
341 |
roomPlayerlist.put(name, new PlayerInRoom(p, false, false)); |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
342 |
roomChatlog.appendPlayerJoin(name); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
343 |
break; |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
344 |
} |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
345 |
case MSG_ROOM_LEAVE: { |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
346 |
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
|
347 |
roomPlayerlist.remove(args.first); |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
348 |
roomChatlog.appendPlayerLeave(args.first, args.second); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
349 |
break; |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
350 |
} |
7691
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
351 |
case MSG_CLIENT_FLAGS: { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
352 |
ClientFlagsUpdate upd = (ClientFlagsUpdate)msg.obj; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
353 |
PlayerInRoom pir = roomPlayerlist.get(upd.nick); |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
354 |
if(pir != null) { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
355 |
roomPlayerlist.put(upd.nick, upd.applyTo(pir)); |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
356 |
} |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
357 |
Player p = lobbyPlayerlist.get(upd.nick); |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
358 |
if(p != null) { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
359 |
lobbyPlayerlist.put(upd.nick, upd.applyTo(p)); |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
360 |
} else { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
361 |
Log.w("Netplay", "Received client flags for unknown player "+upd.nick); |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
362 |
} |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
363 |
if(playerName.equals(upd.nick) && upd.appliesTo(ClientFlagsUpdate.FLAG_CHIEF)) { |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
364 |
netRoomState.setChief(upd.newFlagState); |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
365 |
} |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
366 |
break; |
55c0a856ecd0
frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents:
7588
diff
changeset
|
367 |
} |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
368 |
case MSG_CHAT: { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
369 |
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
|
370 |
getCurrentLog().appendChat(args.first, args.second); |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
371 |
for(GameMessageListener listener : gameMessageListeners) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
372 |
listener.onChatMessage(args.first, args.second); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
373 |
} |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
374 |
break; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
375 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
376 |
case MSG_MESSAGE: { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
377 |
getCurrentLog().appendMessage(msg.arg1, (String)msg.obj); |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
378 |
for(GameMessageListener listener : gameMessageListeners) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
379 |
listener.onMessage(1, (String)msg.obj); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
380 |
} |
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_ROOM_ADD: { |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
384 |
Room room = (Room)msg.obj; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
385 |
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
|
386 |
break; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
387 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
388 |
case MSG_ROOM_UPDATE: { |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
389 |
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
|
390 |
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
|
391 |
break; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
392 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
393 |
case MSG_ROOM_DELETE: { |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
394 |
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
|
395 |
break; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
396 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
397 |
case MSG_ROOMLIST: { |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
398 |
Room[] rooms = (Room[])msg.obj; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
399 |
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
|
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_CONNECTED: { |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
403 |
playerName = (String)msg.obj; |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
404 |
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
|
405 |
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
|
406 |
break; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
407 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
408 |
case MSG_DISCONNECTED: { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
409 |
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
|
410 |
for(GameMessageListener listener : gameMessageListeners) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
411 |
listener.onNetDisconnected(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
412 |
} |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
413 |
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
|
414 |
connection = null; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
415 |
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
|
416 |
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
|
417 |
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
|
418 |
broadcastManager.sendBroadcastSync(intent); |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
419 |
break; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
420 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
broadcastManager.sendBroadcast(intent); |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
425 |
break; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
426 |
} |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
427 |
case MSG_ENTER_ROOM_FROM_LOBBY: { |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
428 |
initRoomState((Boolean)msg.obj); |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
429 |
changeState(State.ROOM); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
430 |
Intent intent = new Intent(ACTION_ENTERED_ROOM_FROM_LOBBY); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
431 |
broadcastManager.sendBroadcastSync(intent); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
432 |
break; |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
433 |
} |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
434 |
case MSG_LEAVE_ROOM: { |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
435 |
changeState(State.LOBBY); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
436 |
Intent intent = new Intent(ACTION_LEFT_ROOM); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
437 |
intent.putExtra(EXTRA_MESSAGE, (String)msg.obj); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
438 |
intent.putExtra(EXTRA_REASON, msg.arg1); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
439 |
broadcastManager.sendBroadcastSync(intent); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
440 |
break; |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
441 |
} |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
442 |
case MSG_TEAM_ADDED: { |
7568 | 443 |
TeamInGame newTeam = (TeamInGame)msg.obj; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
444 |
if(isChief()) { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
445 |
int freeColor = TeamInGame.getUnusedOrRandomColorIndex(netRoomState.getTeams().values()); |
7568 | 446 |
sendToNet(MSG_SEND_TEAM_HOG_COUNT, newTeam.ingameAttribs.hogCount, newTeam.team.name); |
447 |
sendToNet(MSG_SEND_TEAM_COLOR_INDEX, freeColor, newTeam.team.name); |
|
448 |
newTeam = newTeam.withAttribs(newTeam.ingameAttribs.withColorIndex(freeColor)); |
|
7485 | 449 |
} |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
450 |
netRoomState.putTeam(newTeam); |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
451 |
break; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
452 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
453 |
case MSG_TEAM_DELETED: { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
454 |
netRoomState.removeTeam((String)msg.obj); |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
455 |
break; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
456 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
457 |
case MSG_TEAM_ACCEPTED: { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
458 |
TeamInGame requestedTeam = netRoomState.requestedTeams.remove(msg.obj); |
7485 | 459 |
if(requestedTeam!=null) { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
460 |
netRoomState.putTeam(requestedTeam); |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
461 |
if(isChief()) { |
7568 | 462 |
// Not strictly necessary, but QtFrontend does it... |
463 |
sendToNet(MSG_SEND_TEAM_HOG_COUNT, requestedTeam.ingameAttribs.hogCount, requestedTeam.team.name); |
|
7485 | 464 |
} |
465 |
} else { |
|
466 |
Log.e("Netplay", "Got accepted message for team that was never requested."); |
|
467 |
} |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
468 |
break; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
469 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
470 |
case MSG_TEAM_COLOR_CHANGED: { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
471 |
TeamInGame oldEntry = netRoomState.getTeams().get((String)msg.obj); |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
472 |
if(oldEntry != null) { |
7568 | 473 |
/* |
474 |
* If we are chief, we ignore colors from the outside. They only come from the server |
|
475 |
* when someone adds a team then, and we override that choice anyway. |
|
476 |
* Worse, that color message arrives *after* we have overridden the color, so it would |
|
477 |
* re-override it right back. |
|
478 |
*/ |
|
479 |
if(!isChief()) { |
|
480 |
TeamIngameAttributes newAttribs = oldEntry.ingameAttribs.withColorIndex(msg.arg1); |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
481 |
netRoomState.putTeam(oldEntry.withAttribs(newAttribs)); |
7568 | 482 |
} |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
483 |
} else { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
484 |
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
|
485 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
486 |
break; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
487 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
488 |
case MSG_HOG_COUNT_CHANGED: { |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
489 |
TeamInGame oldEntry = netRoomState.getTeams().get((String)msg.obj); |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
490 |
if(oldEntry != null) { |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
491 |
TeamIngameAttributes newAttribs = oldEntry.ingameAttribs.withHogCount(msg.arg1); |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
492 |
netRoomState.putTeam(oldEntry.withAttribs(newAttribs)); |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
493 |
} else { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
494 |
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
|
495 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
496 |
break; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
497 |
} |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
498 |
case MSG_ENGINE_MESSAGE: { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
499 |
byte[] em = (byte[])msg.obj; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
500 |
for(GameMessageListener listener : gameMessageListeners) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
501 |
listener.onEngineMessage(em); |
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_RUN_GAME: { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
506 |
GameConfig config = (GameConfig)msg.obj; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
507 |
for(RunGameListener listener : runGameListeners) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
508 |
listener.runGame(config); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
509 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
510 |
break; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
511 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
512 |
case MSG_MAP_CHANGED: { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
513 |
netRoomState.setMapRecipe((MapRecipe)msg.obj); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
514 |
break; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
515 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
516 |
case MSG_SCHEME_CHANGED: { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
517 |
netRoomState.setScheme((Scheme)msg.obj); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
518 |
break; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
519 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
520 |
case MSG_SCRIPT_CHANGED: { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
521 |
netRoomState.setGameStyle((String)msg.obj); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
522 |
break; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
523 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
524 |
case MSG_WEAPONSET_CHANGED: { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
525 |
netRoomState.setWeaponset((Weaponset)msg.obj); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
526 |
break; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
527 |
} |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
528 |
default: { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
529 |
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
|
530 |
break; |
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 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
533 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
534 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
535 |
} |