project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ThreadedNetConnection.java
author Medo <smaxein@googlemail.com>
Sat, 18 Aug 2012 13:39:05 +0200
changeset 7558 983ff426f91e
parent 7508 763d3961400b
child 7568 75ba91f14ed5
permissions -rw-r--r--
Hedgeroid: Fixed JNA mapping of size_t
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
package org.hedgewars.hedgeroid.netplay;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
import static org.hedgewars.hedgeroid.netplay.Netplay.FromNetMsgType.*;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
import java.io.File;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
import java.io.FileNotFoundException;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
import java.util.Arrays;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
import java.util.Collections;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
import java.util.List;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
import org.hedgewars.hedgeroid.R;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
import org.hedgewars.hedgeroid.Datastructures.Scheme;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
import org.hedgewars.hedgeroid.Datastructures.Team;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
import org.hedgewars.hedgeroid.Datastructures.Weaponset;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
import org.hedgewars.hedgeroid.frontlib.Flib;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
import org.hedgewars.hedgeroid.frontlib.Frontlib;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
import org.hedgewars.hedgeroid.frontlib.Frontlib.BoolCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
import org.hedgewars.hedgeroid.frontlib.Frontlib.BytesCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
import org.hedgewars.hedgeroid.frontlib.Frontlib.GameSetupPtr;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
import org.hedgewars.hedgeroid.frontlib.Frontlib.IntStrCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
import org.hedgewars.hedgeroid.frontlib.Frontlib.MapIntCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
import org.hedgewars.hedgeroid.frontlib.Frontlib.MapRecipePtr;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
import org.hedgewars.hedgeroid.frontlib.Frontlib.NetconnPtr;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
import org.hedgewars.hedgeroid.frontlib.Frontlib.RoomArrayPtr;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
import org.hedgewars.hedgeroid.frontlib.Frontlib.RoomCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
import org.hedgewars.hedgeroid.frontlib.Frontlib.RoomListCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
import org.hedgewars.hedgeroid.frontlib.Frontlib.RoomPtr;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
import org.hedgewars.hedgeroid.frontlib.Frontlib.SchemeCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
import org.hedgewars.hedgeroid.frontlib.Frontlib.SchemePtr;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
import org.hedgewars.hedgeroid.frontlib.Frontlib.StrBoolCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
import org.hedgewars.hedgeroid.frontlib.Frontlib.StrCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
import org.hedgewars.hedgeroid.frontlib.Frontlib.StrIntCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
import org.hedgewars.hedgeroid.frontlib.Frontlib.StrRoomCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
import org.hedgewars.hedgeroid.frontlib.Frontlib.StrStrCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
import org.hedgewars.hedgeroid.frontlib.Frontlib.TeamCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
import org.hedgewars.hedgeroid.frontlib.Frontlib.TeamPtr;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
import org.hedgewars.hedgeroid.frontlib.Frontlib.VoidCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
import org.hedgewars.hedgeroid.frontlib.Frontlib.WeaponsetCallback;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
import org.hedgewars.hedgeroid.frontlib.Frontlib.WeaponsetPtr;
7558
983ff426f91e Hedgeroid: Fixed JNA mapping of size_t
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    41
import org.hedgewars.hedgeroid.frontlib.NativeSizeT;
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
import org.hedgewars.hedgeroid.netplay.Netplay.FromNetHandler;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
import org.hedgewars.hedgeroid.netplay.Netplay.FromNetMsgType;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
import org.hedgewars.hedgeroid.util.FileUtils;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
import org.hedgewars.hedgeroid.util.TickHandler;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
import android.annotation.SuppressLint;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
import android.content.Context;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
import android.content.res.Resources;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
import android.os.Handler;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
import android.os.HandlerThread;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
import android.os.Looper;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
import android.os.Message;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
import android.util.Log;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
import android.util.Pair;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
import com.sun.jna.Memory;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
import com.sun.jna.Pointer;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
/**
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
 * This class handles the actual communication with the networking library, running on a separate thread.
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
 * 
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
 * In order to process net messages, this class regularly runs a tick() function on the frontlib. This
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
 * usually happens several times per second, but it can be slowed down a lot if no fast reaction to
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
 * events is required (e.g. to conserve battery if the application is in the background).
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
 */
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
class ThreadedNetConnection {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
	private static final long TICK_INTERVAL_FAST = 100;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    69
	private static final long TICK_INTERVAL_SLOW = 5000;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
	private static final Frontlib FLIB = Flib.INSTANCE;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    71
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
	public final ToNetHandler toNetHandler;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
	private final Context appContext;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    75
	private final FromNetHandler fromNetHandler;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
	private final TickHandler tickHandler;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    77
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    78
	/**
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
	 * conn can only be null while connecting (the first thing in the thread), and directly after disconnecting,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
	 * in the same message (the looper is shut down on disconnect, so there will be no messages after that).
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    81
	 */
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
	private NetconnPtr conn;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    83
	private String playerName;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    85
	private ThreadedNetConnection(Context appContext, FromNetHandler fromNetHandler) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
		this.appContext = appContext;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
		this.fromNetHandler = fromNetHandler;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
		
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    89
		HandlerThread thread = new HandlerThread("NetThread");
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    90
		thread.start();
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    91
		toNetHandler = new ToNetHandler(thread.getLooper());
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
		tickHandler = new TickHandler(thread.getLooper(), TICK_INTERVAL_FAST, tickCb);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    93
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    94
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    95
	private void connect(final String name, final String host, final int port) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    96
		toNetHandler.post(new Runnable() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    97
			public void run() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    98
				playerName = name == null ? "Player" : name;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    99
				File dataPath;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   100
				try {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   101
					dataPath = FileUtils.getDataPathFile(appContext);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   102
				} catch (FileNotFoundException e) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   103
					shutdown(true, appContext.getString(R.string.sdcard_not_mounted));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   104
					return;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
				}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   106
				conn = FLIB.flib_netconn_create(playerName, dataPath.getAbsolutePath()+"/", host, port);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
				if(conn == null) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   108
					shutdown(true, appContext.getString(R.string.error_connection_failed));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   109
					return;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   110
				}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   111
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   112
				//FLIB.flib_netconn_onAdminAccess(conn, adminAccessCb, null)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   113
				FLIB.flib_netconn_onCfgScheme(conn, cfgSchemeCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   114
				FLIB.flib_netconn_onChat(conn, chatCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   115
				FLIB.flib_netconn_onConnected(conn, connectedCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   116
				FLIB.flib_netconn_onDisconnected(conn, disconnectCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   117
				FLIB.flib_netconn_onEngineMessage(conn, engineMessageCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   118
				FLIB.flib_netconn_onEnterRoom(conn, enterRoomCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   119
				FLIB.flib_netconn_onHogCountChanged(conn, hogCountChangedCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   120
				FLIB.flib_netconn_onLeaveRoom(conn, leaveRoomCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   121
				FLIB.flib_netconn_onLobbyJoin(conn, lobbyJoinCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   122
				FLIB.flib_netconn_onLobbyLeave(conn, lobbyLeaveCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   123
				FLIB.flib_netconn_onMapChanged(conn, mapChangedCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   124
				FLIB.flib_netconn_onMessage(conn, messageCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   125
				FLIB.flib_netconn_onPasswordRequest(conn, passwordRequestCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   126
				FLIB.flib_netconn_onReadyState(conn, readyStateCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   127
				FLIB.flib_netconn_onRoomAdd(conn, roomAddCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   128
				FLIB.flib_netconn_onRoomChiefStatus(conn, roomChiefStatusCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   129
				FLIB.flib_netconn_onRoomDelete(conn, roomDeleteCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   130
				FLIB.flib_netconn_onRoomJoin(conn, roomJoinCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   131
				FLIB.flib_netconn_onRoomLeave(conn, roomLeaveCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   132
				FLIB.flib_netconn_onRoomlist(conn, roomlistCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   133
				FLIB.flib_netconn_onRoomUpdate(conn, roomUpdateCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   134
				FLIB.flib_netconn_onRunGame(conn, runGameCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   135
				FLIB.flib_netconn_onScriptChanged(conn, scriptChangedCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   136
				// FLIB.flib_netconn_onServerVar(conn, serverVarCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   137
				FLIB.flib_netconn_onTeamAccepted(conn, teamAcceptedCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   138
				FLIB.flib_netconn_onTeamAdd(conn, teamAddedCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   139
				FLIB.flib_netconn_onTeamColorChanged(conn, teamColorChangedCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   140
				FLIB.flib_netconn_onTeamDelete(conn, teamDeletedCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   141
				FLIB.flib_netconn_onWeaponsetChanged(conn, weaponsetChangedCb, null);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   142
				
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   143
				tickHandler.start();
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   144
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   145
		});
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   146
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   147
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   148
	public static ThreadedNetConnection startConnection(Context appContext, FromNetHandler fromNetHandler, String playerName, String host, int port) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   149
		ThreadedNetConnection result = new ThreadedNetConnection(appContext, fromNetHandler);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   150
		result.connect(playerName, host, port);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   151
		return result;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   152
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   153
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   154
	public void setFastTickRate(boolean fastTickRate) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   155
		tickHandler.setInterval(fastTickRate ? TICK_INTERVAL_FAST : TICK_INTERVAL_SLOW);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   156
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   157
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   158
	private final Runnable tickCb = new Runnable() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   159
		public void run() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   160
			FLIB.flib_netconn_tick(conn);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   161
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   162
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   163
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   164
	private final SchemeCallback cfgSchemeCb = new SchemeCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   165
		public void callback(Pointer context, SchemePtr schemePtr) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   166
			sendFromNet(MSG_SCHEME_CHANGED, schemePtr.deref());
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   167
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   168
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   169
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   170
	private final MapIntCallback mapChangedCb = new MapIntCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   171
		public void callback(Pointer context, MapRecipePtr mapPtr, int updateType) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   172
			sendFromNet(MSG_MAP_CHANGED, updateType, mapPtr.deref());
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   173
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   174
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   175
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   176
	private final BoolCallback roomChiefStatusCb = new BoolCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   177
		public void callback(Pointer context, boolean chief) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   178
			sendFromNet(MSG_ROOM_CHIEF_STATUS_CHANGED, chief);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   179
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   180
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   181
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   182
	private final StrCallback scriptChangedCb = new StrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   183
		public void callback(Pointer context, String script) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   184
			sendFromNet(MSG_SCRIPT_CHANGED, script);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   185
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   186
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   187
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   188
	private final WeaponsetCallback weaponsetChangedCb = new WeaponsetCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   189
		public void callback(Pointer context, WeaponsetPtr weaponsetPtr) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   190
			sendFromNet(MSG_WEAPONSET_CHANGED, weaponsetPtr.deref());				
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   191
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   192
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   193
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   194
	private final StrCallback lobbyJoinCb = new StrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   195
		public void callback(Pointer context, String name) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   196
			sendFromNet(MSG_LOBBY_JOIN, name);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   197
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   198
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   199
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   200
	private final StrStrCallback lobbyLeaveCb = new StrStrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   201
		public void callback(Pointer context, String name, String msg) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   202
			sendFromNet(MSG_LOBBY_LEAVE, Pair.create(name, msg));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   203
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   204
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   205
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   206
	private final StrCallback roomJoinCb = new StrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   207
		public void callback(Pointer context, String name) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   208
			sendFromNet(MSG_ROOM_JOIN, name);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   209
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   210
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   211
	private final StrStrCallback roomLeaveCb = new StrStrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   212
		public void callback(Pointer context, String name, String message) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   213
			sendFromNet(MSG_ROOM_LEAVE, Pair.create(name, message));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   214
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   215
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   216
	private final StrStrCallback chatCb = new StrStrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   217
		public void callback(Pointer context, String name, String msg) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   218
			sendFromNet(MSG_CHAT, Pair.create(name, msg));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   219
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   220
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   221
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   222
	private final IntStrCallback messageCb = new IntStrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   223
		public void callback(Pointer context, int type, String msg) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   224
			sendFromNet(MSG_MESSAGE, type, msg);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   225
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   226
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   227
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   228
	private final RoomCallback roomAddCb = new RoomCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   229
		public void callback(Pointer context, RoomPtr roomPtr) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   230
			sendFromNet(MSG_ROOM_ADD, roomPtr.deref());
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   231
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   232
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   233
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   234
	private final StrRoomCallback roomUpdateCb = new StrRoomCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   235
		public void callback(Pointer context, String name, RoomPtr roomPtr) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   236
			sendFromNet(MSG_ROOM_UPDATE, Pair.create(name, roomPtr.deref()));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   237
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   238
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   239
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   240
	private final StrCallback roomDeleteCb = new StrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   241
		public void callback(Pointer context, final String name) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   242
			sendFromNet(MSG_ROOM_DELETE, name);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   243
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   244
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   245
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   246
	private final RoomListCallback roomlistCb = new RoomListCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   247
		public void callback(Pointer context, RoomArrayPtr arg1, int count) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   248
			sendFromNet(MSG_ROOMLIST, arg1.getRooms(count));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   249
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   250
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   251
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   252
	private final VoidCallback connectedCb = new VoidCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   253
		public void callback(Pointer context) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   254
			FLIB.flib_netconn_send_request_roomlist(conn);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   255
			playerName = FLIB.flib_netconn_get_playername(conn);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   256
			sendFromNet(MSG_CONNECTED, playerName);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   257
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   258
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   259
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   260
	private final StrCallback passwordRequestCb = new StrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   261
		public void callback(Pointer context, String nickname) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   262
			sendFromNet(MSG_PASSWORD_REQUEST, playerName);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   263
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   264
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   265
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   266
	private final BoolCallback enterRoomCb = new BoolCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   267
		public void callback(Pointer context, boolean isChief) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   268
			sendFromNet(MSG_ENTER_ROOM_FROM_LOBBY, isChief);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   269
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   270
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   271
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   272
	private final IntStrCallback leaveRoomCb = new IntStrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   273
		public void callback(Pointer context, int reason, String message) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   274
			sendFromNet(MSG_LEAVE_ROOM, reason, message);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   275
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   276
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   277
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   278
	private final StrBoolCallback readyStateCb = new StrBoolCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   279
		public void callback(Pointer context, String player, boolean ready) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   280
			sendFromNet(MSG_READYSTATE, Pair.create(player, ready));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   281
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   282
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   283
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   284
	private final TeamCallback teamAddedCb = new TeamCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   285
		public void callback(Pointer context, TeamPtr team) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   286
			sendFromNet(MSG_TEAM_ADDED, team.deref().team);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   287
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   288
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   289
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   290
	private final StrCallback teamDeletedCb = new StrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   291
		public void callback(Pointer context, String teamName) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   292
			sendFromNet(MSG_TEAM_DELETED, teamName);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   293
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   294
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   295
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   296
	private final StrCallback teamAcceptedCb = new StrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   297
		public void callback(Pointer context, String teamName) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   298
			sendFromNet(MSG_TEAM_ACCEPTED, teamName);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   299
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   300
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   301
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   302
	private final StrIntCallback teamColorChangedCb = new StrIntCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   303
		public void callback(Pointer context, String teamName, int colorIndex) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   304
			sendFromNet(MSG_TEAM_COLOR_CHANGED, colorIndex, teamName);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   305
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   306
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   307
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   308
	private final StrIntCallback hogCountChangedCb = new StrIntCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   309
		public void callback(Pointer context, String teamName, int hogCount) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   310
			sendFromNet(MSG_HOG_COUNT_CHANGED, hogCount, teamName);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   311
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   312
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   313
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   314
	private final BytesCallback engineMessageCb = new BytesCallback() {
7558
983ff426f91e Hedgeroid: Fixed JNA mapping of size_t
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
   315
		public void callback(Pointer context, Pointer buffer, NativeSizeT size) {
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   316
			sendFromNet(MSG_ENGINE_MESSAGE, buffer.getByteArray(0, size.intValue()));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   317
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   318
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   319
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   320
	private final VoidCallback runGameCb = new VoidCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   321
		public void callback(Pointer context) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   322
			GameSetupPtr configPtr = FLIB.flib_netconn_create_gamesetup(conn);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   323
			sendFromNet(MSG_RUN_GAME, configPtr.deref());
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   324
			FLIB.flib_gamesetup_destroy(configPtr);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   325
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   326
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   327
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   328
	private void shutdown(boolean error, String message) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   329
		if(conn != null) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   330
			FLIB.flib_netconn_destroy(conn);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   331
			conn = null;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   332
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   333
		tickHandler.stop();
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   334
		toNetHandler.getLooper().quit();
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   335
		sendFromNet(MSG_DISCONNECTED, Pair.create(error, message));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   336
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   337
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   338
	private final IntStrCallback disconnectCb = new IntStrCallback() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   339
		public void callback(Pointer context, int reason, String message) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   340
			Boolean error = reason != Frontlib.NETCONN_DISCONNECT_NORMAL;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   341
			String messageForUser = createDisconnectUserMessage(appContext.getResources(), reason, message);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   342
			shutdown(error, messageForUser);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   343
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   344
	};
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   345
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   346
	private static String createDisconnectUserMessage(Resources res, int reason, String message) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   347
		switch(reason) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   348
		case Frontlib.NETCONN_DISCONNECT_AUTH_FAILED:
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   349
			return res.getString(R.string.error_auth_failed);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   350
		case Frontlib.NETCONN_DISCONNECT_CONNLOST:
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   351
			return res.getString(R.string.error_connection_lost);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   352
		case Frontlib.NETCONN_DISCONNECT_INTERNAL_ERROR:
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   353
			return res.getString(R.string.error_unexpected, message);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   354
		case Frontlib.NETCONN_DISCONNECT_SERVER_TOO_OLD:
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   355
			return res.getString(R.string.error_server_too_old);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   356
		default:
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   357
			return message;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   358
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   359
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   360
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   361
	private boolean sendFromNet(FromNetMsgType what, Object obj) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   362
		return fromNetHandler.sendMessage(fromNetHandler.obtainMessage(what.ordinal(), obj));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   363
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   364
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   365
	private boolean sendFromNet(FromNetMsgType what, int arg1, Object obj) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   366
		return fromNetHandler.sendMessage(fromNetHandler.obtainMessage(what.ordinal(), arg1, 0, obj));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   367
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   368
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   369
	static enum ToNetMsgType {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   370
		MSG_SEND_NICK,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   371
		MSG_SEND_PASSWORD,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   372
		MSG_SEND_QUIT,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   373
		MSG_SEND_ROOMLIST_REQUEST,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   374
		MSG_SEND_PLAYER_INFO_REQUEST,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   375
		MSG_SEND_CHAT,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   376
		MSG_SEND_TEAMCHAT,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   377
		MSG_SEND_FOLLOW_PLAYER,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   378
		MSG_SEND_JOIN_ROOM,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   379
		MSG_SEND_CREATE_ROOM,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   380
		MSG_SEND_LEAVE_ROOM,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   381
		MSG_SEND_KICK,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   382
		MSG_SEND_ADD_TEAM,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   383
		MSG_SEND_REMOVE_TEAM,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   384
		MSG_DISCONNECT,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   385
		MSG_SEND_TEAM_COLOR_INDEX,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   386
		MSG_SEND_TEAM_HOG_COUNT,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   387
		MSG_SEND_ENGINE_MESSAGE,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   388
		MSG_SEND_ROUND_FINISHED,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   389
		MSG_SEND_TOGGLE_READY,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   390
		MSG_SEND_WEAPONSET,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   391
		MSG_SEND_MAP,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   392
		MSG_SEND_MAP_NAME,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   393
		MSG_SEND_MAP_GENERATOR,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   394
		MSG_SEND_MAP_TEMPLATE,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   395
		MSG_SEND_MAZE_SIZE,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   396
		MSG_SEND_MAP_SEED,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   397
		MSG_SEND_MAP_THEME,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   398
		MSG_SEND_MAP_DRAWDATA,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   399
		MSG_SEND_GAMESTYLE,
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   400
		MSG_SEND_SCHEME;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   401
		
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   402
		static final List<ThreadedNetConnection.ToNetMsgType> values = Collections.unmodifiableList(Arrays.asList(ToNetMsgType.values()));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   403
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   404
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   405
	/**
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   406
	 * Processes messages to the networking system. Runs on a non-main thread.
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   407
	 */
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   408
	@SuppressLint("HandlerLeak")
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   409
	public final class ToNetHandler extends Handler {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   410
		
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   411
		public ToNetHandler(Looper looper) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   412
			super(looper);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   413
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   414
		
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   415
		@Override
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   416
		public void handleMessage(Message msg) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   417
			switch(ToNetMsgType.values.get(msg.what)) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   418
			case MSG_SEND_NICK: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   419
				FLIB.flib_netconn_send_nick(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   420
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   421
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   422
			case MSG_SEND_PASSWORD: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   423
				FLIB.flib_netconn_send_password(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   424
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   425
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   426
			case MSG_SEND_QUIT: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   427
				FLIB.flib_netconn_send_quit(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   428
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   429
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   430
			case MSG_SEND_ROOMLIST_REQUEST: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   431
				FLIB.flib_netconn_send_request_roomlist(conn);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   432
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   433
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   434
			case MSG_SEND_PLAYER_INFO_REQUEST: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   435
				FLIB.flib_netconn_send_playerInfo(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   436
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   437
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   438
			case MSG_SEND_CHAT: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   439
				if(FLIB.flib_netconn_send_chat(conn, (String)msg.obj) == 0) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   440
					sendFromNet(MSG_CHAT, Pair.create(playerName, (String)msg.obj));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   441
				}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   442
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   443
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   444
			case MSG_SEND_TEAMCHAT: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   445
				FLIB.flib_netconn_send_teamchat(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   446
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   447
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   448
			case MSG_SEND_FOLLOW_PLAYER: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   449
				FLIB.flib_netconn_send_playerFollow(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   450
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   451
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   452
			case MSG_SEND_JOIN_ROOM: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   453
				FLIB.flib_netconn_send_joinRoom(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   454
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   455
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   456
			case MSG_SEND_CREATE_ROOM: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   457
				FLIB.flib_netconn_send_createRoom(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   458
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   459
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   460
			case MSG_SEND_LEAVE_ROOM: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   461
				if(FLIB.flib_netconn_send_leaveRoom(conn, (String)msg.obj) == 0) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   462
					sendFromNet(MSG_LEAVE_ROOM, -1, "");
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   463
				}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   464
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   465
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   466
			case MSG_SEND_KICK: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   467
				FLIB.flib_netconn_send_kick(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   468
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   469
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   470
			case MSG_SEND_ADD_TEAM: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   471
				FLIB.flib_netconn_send_addTeam(conn, TeamPtr.createJavaOwned((Team)msg.obj));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   472
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   473
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   474
			case MSG_SEND_REMOVE_TEAM: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   475
				if(FLIB.flib_netconn_send_removeTeam(conn, (String)msg.obj)==0) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   476
					sendFromNet(MSG_TEAM_DELETED, msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   477
				}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   478
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   479
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   480
			case MSG_DISCONNECT: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   481
				FLIB.flib_netconn_send_quit(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   482
				shutdown(false, "User quit");
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   483
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   484
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   485
			case MSG_SEND_TEAM_COLOR_INDEX: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   486
				if(FLIB.flib_netconn_send_teamColor(conn, (String)msg.obj, msg.arg1)==0) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   487
					sendFromNet(MSG_TEAM_COLOR_CHANGED, msg.arg1, msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   488
				}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   489
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   490
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   491
			case MSG_SEND_TEAM_HOG_COUNT: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   492
				if(FLIB.flib_netconn_send_teamHogCount(conn, (String)msg.obj, msg.arg1)==0) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   493
					sendFromNet(MSG_HOG_COUNT_CHANGED, msg.arg1, msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   494
				}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   495
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   496
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   497
			case MSG_SEND_ENGINE_MESSAGE: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   498
				byte[] message = (byte[])msg.obj;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   499
				Memory mem = new Memory(message.length);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   500
				mem.write(0, message, 0, message.length);
7558
983ff426f91e Hedgeroid: Fixed JNA mapping of size_t
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
   501
				FLIB.flib_netconn_send_engineMessage(conn, mem, NativeSizeT.valueOf(message.length));
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   502
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   503
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   504
			case MSG_SEND_ROUND_FINISHED: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   505
				FLIB.flib_netconn_send_roundfinished(conn, (Boolean)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   506
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   507
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   508
			case MSG_SEND_TOGGLE_READY: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   509
				FLIB.flib_netconn_send_toggleReady(conn);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   510
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   511
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   512
			case MSG_SEND_WEAPONSET: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   513
				FLIB.flib_netconn_send_weaponset(conn, WeaponsetPtr.createJavaOwned((Weaponset)msg.obj));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   514
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   515
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   516
			case MSG_SEND_MAP: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   517
				FLIB.flib_netconn_send_map(conn, MapRecipePtr.createJavaOwned((MapRecipe)msg.obj));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   518
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   519
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   520
			case MSG_SEND_MAP_NAME: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   521
				FLIB.flib_netconn_send_mapName(conn, (String)msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   522
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   523
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   524
			case MSG_SEND_MAP_GENERATOR: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   525
				FLIB.flib_netconn_send_mapGen(conn, msg.arg1);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   526
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   527
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   528
			case MSG_SEND_MAP_TEMPLATE: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   529
				FLIB.flib_netconn_send_mapTemplate(conn, msg.arg1);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   530
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   531
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   532
			case MSG_SEND_MAZE_SIZE: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   533
				FLIB.flib_netconn_send_mapMazeSize(conn, msg.arg1);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   534
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   535
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   536
			case MSG_SEND_MAP_SEED: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   537
				FLIB.flib_netconn_send_mapSeed(conn, (String) msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   538
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   539
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   540
			case MSG_SEND_MAP_THEME: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   541
				FLIB.flib_netconn_send_mapTheme(conn, (String) msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   542
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   543
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   544
			case MSG_SEND_MAP_DRAWDATA: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   545
				byte[] message = (byte[])msg.obj;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   546
				Memory mem = new Memory(message.length);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   547
				mem.write(0, message, 0, message.length);
7558
983ff426f91e Hedgeroid: Fixed JNA mapping of size_t
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
   548
				FLIB.flib_netconn_send_mapDrawdata(conn, mem, NativeSizeT.valueOf(message.length));
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   549
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   550
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   551
			case MSG_SEND_GAMESTYLE: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   552
				FLIB.flib_netconn_send_script(conn, (String) msg.obj);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   553
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   554
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   555
			case MSG_SEND_SCHEME: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   556
				FLIB.flib_netconn_send_scheme(conn, SchemePtr.createJavaOwned((Scheme) msg.obj));
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   557
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   558
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   559
			default: {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   560
				Log.e("ToNetHandler", "Unknown message type: "+msg.what);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   561
				break;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   562
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   563
			}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   564
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   565
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   566
}