project_files/frontlib/ipc/gameconn.c
author Medo <smaxein@googlemail.com>
Wed, 27 Jun 2012 18:02:45 +0200
changeset 7275 15f722e0b96f
parent 7271 5608ac657362
child 7314 6171f0bad318
permissions -rw-r--r--
frontlib: Getting there :) Added commandline client for testing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
#include "gameconn.h"
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
     2
#include "ipcbase.h"
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
#include "ipcprotocol.h"
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
#include "../util/logging.h"
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
     5
#include "../util/util.h"
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
#include "../hwconsts.h"
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
#include <stdbool.h>
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
#include <stdlib.h>
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
     9
#include <string.h>
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
typedef enum {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
	AWAIT_CONNECTION,
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
	CONNECTED,
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
	FINISHED
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
} gameconn_state;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
struct _flib_gameconn {
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
    18
	flib_ipcbase *ipcBase;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
    19
	flib_vector *configBuffer;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
    20
	flib_vector *demoBuffer;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
    21
	char *playerName;
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
	gameconn_state state;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
	bool netgame;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
	void (*onConnectCb)(void* context);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
	void *onConnectCtx;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
	void (*onDisconnectCb)(void* context, int reason);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
	void *onDisconnectCtx;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
	void (*onErrorMessageCb)(void* context, const char *msg);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
	void *onErrorMessageCtx;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
	void (*onChatCb)(void* context, const char *msg, bool teamchat);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
	void *onChatCtx;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
	void (*onGameRecordedCb)(void *context, const uint8_t *record, int size, bool isSavegame);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
	void *onGameRecordedCtx;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    41
	void (*onEngineMessageCb)(void *context, const uint8_t *em, size_t size);
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
    42
	void *onEngineMessageCtx;
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
	bool running;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
	bool destroyRequested;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
};
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
static void defaultCallback_onConnect(void* context) {}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
static void defaultCallback_onDisconnect(void* context, int reason) {}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
static void defaultCallback_onErrorMessage(void* context, const char *msg) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
	flib_log_w("Error from engine (no callback set): %s", msg);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
static void defaultCallback_onChat(void* context, const char *msg, bool teamchat) {}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
static void defaultCallback_onGameRecorded(void *context, const uint8_t *record, int size, bool isSavegame) {}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    55
static void defaultCallback_onEngineMessage(void *context, const uint8_t *em, size_t size) {}
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
static void clearCallbacks(flib_gameconn *conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
	conn->onConnectCb = &defaultCallback_onConnect;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
	conn->onDisconnectCb = &defaultCallback_onDisconnect;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
	conn->onErrorMessageCb = &defaultCallback_onErrorMessage;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
	conn->onChatCb = &defaultCallback_onChat;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
	conn->onGameRecordedCb = &defaultCallback_onGameRecorded;
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
    63
	conn->onEngineMessageCb = &defaultCallback_onEngineMessage;
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
static flib_gameconn *flib_gameconn_create_partial(bool record, const char *playerName, bool netGame) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
	flib_gameconn *result = NULL;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    68
	if(!log_badparams_if(!playerName)) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    69
		flib_gameconn *tempConn = flib_calloc(1, sizeof(flib_gameconn));
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    70
		if(tempConn) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    71
			tempConn->ipcBase = flib_ipcbase_create();
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    72
			tempConn->configBuffer = flib_vector_create();
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    73
			tempConn->playerName = flib_strdupnull(playerName);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    74
			if(tempConn->ipcBase && tempConn->configBuffer && tempConn->playerName) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    75
				if(record) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    76
					tempConn->demoBuffer = flib_vector_create();
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    77
				}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    78
				tempConn->state = AWAIT_CONNECTION;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    79
				tempConn->netgame = netGame;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    80
				clearCallbacks(tempConn);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    81
				result = tempConn;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    82
				tempConn = NULL;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
    83
			}
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
		}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    85
		flib_gameconn_destroy(tempConn);
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
	return result;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    89
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
    90
flib_gameconn *flib_gameconn_create(const char *playerName, const flib_gamesetup *setup, bool netgame) {
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    91
	flib_gameconn *result = NULL;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
	flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, netgame);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    93
	if(tempConn) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    94
		if(flib_ipc_append_fullconfig(tempConn->configBuffer, setup, netgame)) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    95
			flib_log_e("Error generating full game configuration for the engine.");
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    96
		} else {
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    97
			result = tempConn;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    98
			tempConn = NULL;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    99
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   100
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   101
	flib_gameconn_destroy(tempConn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   102
	return result;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   103
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   104
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demo, int size) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   106
	flib_gameconn *result = NULL;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
	flib_gameconn *tempConn = flib_gameconn_create_partial(false, "Player", false);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   108
	if(tempConn) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   109
		if(!flib_vector_append(tempConn->configBuffer, demo, size)) {
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   110
			result = tempConn;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   111
			tempConn = NULL;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   112
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   113
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   114
	flib_gameconn_destroy(tempConn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   115
	return result;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   116
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   117
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   118
flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *save, int size) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   119
	flib_gameconn *result = NULL;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   120
	flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, false);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   121
	if(tempConn) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   122
		if(!flib_vector_append(tempConn->configBuffer, save, size)) {
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   123
			result = tempConn;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   124
			tempConn = NULL;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   125
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   126
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   127
	flib_gameconn_destroy(tempConn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   128
	return result;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   129
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   130
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   131
flib_gameconn *flib_gameconn_create_campaign(const char *playerName, const char *seed, const char *script) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   132
	flib_gameconn *result = NULL;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   133
	flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, false);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   134
	if(tempConn) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   135
		if(!flib_ipc_append_message(tempConn->configBuffer, "TL")
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   136
				&& !flib_ipc_append_seed(tempConn->configBuffer, seed)
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   137
				&& !flib_ipc_append_script(tempConn->configBuffer, script)
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   138
				&& !flib_ipc_append_message(tempConn->configBuffer, "!")) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   139
			result = tempConn;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   140
			tempConn = NULL;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   141
		}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   142
	}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   143
	flib_gameconn_destroy(tempConn);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   144
	return result;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   145
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   146
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   147
void flib_gameconn_destroy(flib_gameconn *conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   148
	if(conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   149
		if(conn->running) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   150
			/*
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   151
			 * The function was called from a callback, so the tick function is still running
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   152
			 * and we delay the actual destruction. We ensure no further callbacks will be
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   153
			 * sent to prevent surprises.
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   154
			 */
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   155
			clearCallbacks(conn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   156
			conn->destroyRequested = true;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   157
		} else {
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   158
			flib_ipcbase_destroy(conn->ipcBase);
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   159
			flib_vector_destroy(conn->configBuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   160
			flib_vector_destroy(conn->demoBuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   161
			free(conn->playerName);
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   162
			free(conn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   163
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   164
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   165
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   166
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   167
int flib_gameconn_getport(flib_gameconn *conn) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   168
	if(!log_badparams_if(!conn)) {
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   169
		return flib_ipcbase_port(conn->ipcBase);
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   170
	}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   171
	return 0;
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   172
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   173
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   174
static void demo_append(flib_gameconn *conn, const void *data, size_t len) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   175
	if(conn->demoBuffer) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   176
		if(flib_vector_append(conn->demoBuffer, data, len)) {
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   177
			flib_log_e("Error recording demo: Out of memory.");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   178
			flib_vector_destroy(conn->demoBuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   179
			conn->demoBuffer = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   180
		}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   181
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   182
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   183
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   184
static int format_chatmessage(uint8_t buffer[257], const char *playerName, const char *message) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   185
	size_t msglen = strlen(message);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   186
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   187
	// If the message starts with /me, it will be displayed differently.
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   188
	bool meMessage = msglen >= 4 && !memcmp(message, "/me ", 4);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   189
	const char *template = meMessage ? "s\x02* %s %s  " : "s\x01%s: %s  ";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   190
	int size = snprintf((char*)buffer+1, 256, template, playerName, meMessage ? message+4 : message);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   191
	if(size>0) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   192
		buffer[0] = size>255 ? 255 : size;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   193
		return 0;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   194
	} else {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   195
		return -1;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   196
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   197
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   198
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   199
static void demo_append_chatmessage(flib_gameconn *conn, const char *message) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   200
	// Chat messages are reformatted to make them look as if they were received, not sent.
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   201
	uint8_t converted[257];
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   202
	if(!format_chatmessage(converted, conn->playerName, message)) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   203
		demo_append(conn, converted, converted[0]+1);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   204
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   205
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   206
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   207
static void demo_replace_gamemode(flib_buffer buf, char gamemode) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   208
	size_t msgStart = 0;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   209
	uint8_t *data = (uint8_t*)buf.data;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   210
	while(msgStart+2 < buf.size) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   211
		if(!memcmp(data+msgStart, "\x02T", 2)) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   212
			data[msgStart+2] = gamemode;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   213
		}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   214
		msgStart += (uint8_t)data[msgStart]+1;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   215
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   216
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   217
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   218
int flib_gameconn_send_enginemsg(flib_gameconn *conn, const uint8_t *data, size_t len) {
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   219
	int result = -1;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   220
	if(!log_badparams_if(!conn || (!data && len>0))
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   221
			&& !flib_ipcbase_send_raw(conn->ipcBase, data, len)) {
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   222
		demo_append(conn, data, len);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   223
		result = 0;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   224
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   225
	return result;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   226
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   227
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   228
int flib_gameconn_send_textmsg(flib_gameconn *conn, int msgtype, const char *msg) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   229
	int result = -1;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   230
	if(!conn || !msg) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   231
		flib_log_e("null parameter in flib_gameconn_send_textmsg");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   232
	} else {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   233
		uint8_t converted[257];
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   234
		int size = snprintf((char*)converted+1, 256, "s%c%s", (char)msgtype, msg);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   235
		if(size>0) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   236
			converted[0] = size>255 ? 255 : size;
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   237
			if(!flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) {
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   238
				demo_append(conn, converted, converted[0]+1);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   239
				result = 0;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   240
			}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   241
		}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   242
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   243
	return result;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   244
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   245
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   246
int flib_gameconn_send_chatmsg(flib_gameconn *conn, const char *playername, const char *msg) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   247
	int result = -1;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   248
	uint8_t converted[257];
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   249
	if(!conn || !playername || !msg) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   250
		flib_log_e("null parameter in flib_gameconn_send_chatmsg");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   251
	} else if(format_chatmessage(converted, playername, msg)) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   252
		flib_log_e("Error formatting message in flib_gameconn_send_chatmsg");
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   253
	} else if(!flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) {
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   254
		demo_append(conn, converted, converted[0]+1);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   255
		result = 0;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   256
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   257
	return result;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   258
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   259
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   260
void flib_gameconn_onConnect(flib_gameconn *conn, void (*callback)(void* context), void* context) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   261
	if(!conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   262
		flib_log_e("null parameter in flib_gameconn_onConnect");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   263
	} else {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   264
		conn->onConnectCb = callback ? callback : &defaultCallback_onConnect;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   265
		conn->onConnectCtx = context;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   266
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   267
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   268
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   269
void flib_gameconn_onDisconnect(flib_gameconn *conn, void (*callback)(void* context, int reason), void* context) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   270
	if(!conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   271
		flib_log_e("null parameter in flib_gameconn_onDisconnect");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   272
	} else {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   273
		conn->onDisconnectCb = callback ? callback : &defaultCallback_onDisconnect;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   274
		conn->onDisconnectCtx = context;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   275
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   276
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   277
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   278
void flib_gameconn_onErrorMessage(flib_gameconn *conn, void (*callback)(void* context, const char *msg), void* context) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   279
	if(!conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   280
		flib_log_e("null parameter in flib_gameconn_onErrorMessage");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   281
	} else {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   282
		conn->onErrorMessageCb = callback ? callback : &defaultCallback_onErrorMessage;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   283
		conn->onErrorMessageCtx = context;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   284
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   285
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   286
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   287
void flib_gameconn_onChat(flib_gameconn *conn, void (*callback)(void* context, const char *msg, bool teamchat), void* context) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   288
	if(!conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   289
		flib_log_e("null parameter in flib_gameconn_onChat");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   290
	} else {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   291
		conn->onChatCb = callback ? callback : &defaultCallback_onChat;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   292
		conn->onChatCtx = context;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   293
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   294
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   295
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   296
void flib_gameconn_onGameRecorded(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *record, int size, bool isSavegame), void* context) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   297
	if(!conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   298
		flib_log_e("null parameter in flib_gameconn_onGameRecorded");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   299
	} else {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   300
		conn->onGameRecordedCb = callback ? callback : &defaultCallback_onGameRecorded;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   301
		conn->onGameRecordedCtx = context;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   302
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   303
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   304
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   305
void flib_gameconn_onEngineMessage(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *em, size_t size), void* context) {
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   306
	if(!conn) {
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   307
		flib_log_e("null parameter in flib_gameconn_onEngineMessage");
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   308
	} else {
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   309
		conn->onEngineMessageCb = callback ? callback : &defaultCallback_onEngineMessage;
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   310
		conn->onEngineMessageCtx = context;
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   311
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   312
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   313
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   314
static void flib_gameconn_wrappedtick(flib_gameconn *conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   315
	if(conn->state == AWAIT_CONNECTION) {
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   316
		flib_ipcbase_accept(conn->ipcBase);
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   317
		switch(flib_ipcbase_state(conn->ipcBase)) {
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   318
		case IPC_CONNECTED:
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   319
			{
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   320
				flib_constbuffer configBuffer = flib_vector_as_constbuffer(conn->configBuffer);
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   321
				if(flib_ipcbase_send_raw(conn->ipcBase, configBuffer.data, configBuffer.size)) {
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   322
					conn->state = FINISHED;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   323
					conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   324
					return;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   325
				} else {
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   326
					demo_append(conn, configBuffer.data, configBuffer.size);
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   327
					conn->state = CONNECTED;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   328
					conn->onConnectCb(conn->onConnectCtx);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   329
					if(conn->destroyRequested) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   330
						return;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   331
					}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   332
				}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   333
			}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   334
			break;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   335
		case IPC_NOT_CONNECTED:
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   336
			conn->state = FINISHED;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   337
			conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   338
			return;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   339
		default:
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   340
			break;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   341
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   342
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   343
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   344
	if(conn->state == CONNECTED) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   345
		uint8_t msgbuffer[257];
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   346
		int len;
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   347
		while(!conn->destroyRequested && (len = flib_ipcbase_recv_message(conn->ipcBase, msgbuffer))>=0) {
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   348
			if(len<2) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   349
				flib_log_w("Received short message from IPC (<2 bytes)");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   350
				continue;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   351
			}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   352
			switch(msgbuffer[1]) {
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   353
			case '?':	// Ping
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   354
				// The pong is already part of the config message
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   355
				break;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   356
			case 'C':	// Config query
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   357
				// And we already send the config message on connecting.
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   358
				break;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   359
			case 'E':	// Error message
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   360
				if(len>=3) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   361
					msgbuffer[len-2] = 0;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   362
					conn->onErrorMessageCb(conn->onErrorMessageCtx, (char*)msgbuffer+2);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   363
				}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   364
				break;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   365
			case 'i':	// Statistics
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   366
				// TODO stats
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   367
				break;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   368
			case 'Q':	// Game interrupted
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   369
			case 'H':	// Game halted
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   370
			case 'q':	// game finished
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   371
				{
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   372
					int reason = msgbuffer[1]=='Q' ? GAME_END_INTERRUPTED : msgbuffer[1]=='H' ? GAME_END_HALTED : GAME_END_FINISHED;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   373
					bool savegame = (reason != GAME_END_FINISHED) && !conn->netgame;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   374
					if(conn->demoBuffer) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   375
						flib_buffer demoBuffer = flib_vector_as_buffer(conn->demoBuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   376
						demo_replace_gamemode(demoBuffer, savegame ? 'S' : 'D');
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   377
						conn->onGameRecordedCb(conn->onGameRecordedCtx, demoBuffer.data, demoBuffer.size, savegame);
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   378
						if(conn->destroyRequested) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   379
							return;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   380
						}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   381
					}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   382
					conn->state = FINISHED;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   383
					conn->onDisconnectCb(conn->onDisconnectCtx, reason);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   384
					return;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   385
				}
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   386
			case 's':	// Chat message
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   387
				if(len>=3) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   388
					msgbuffer[len-2] = 0;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   389
					demo_append_chatmessage(conn, (char*)msgbuffer+2);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   390
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   391
					conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, false);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   392
				}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   393
				break;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   394
			case 'b':	// Teamchat message
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   395
				if(len>=3) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   396
					msgbuffer[len-2] = 0;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   397
					conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, true);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   398
				}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   399
				break;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   400
			default:	// Engine message
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   401
				demo_append(conn, msgbuffer, len);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   402
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   403
				conn->onEngineMessageCb(conn->onEngineMessageCtx, msgbuffer, len);
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   404
				break;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   405
			}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   406
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   407
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   408
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   409
	if(flib_ipcbase_state(conn->ipcBase) == IPC_NOT_CONNECTED) {
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   410
		conn->state = FINISHED;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   411
		conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   412
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   413
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   414
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   415
void flib_gameconn_tick(flib_gameconn *conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   416
	if(!conn) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   417
		flib_log_e("null parameter in flib_gameconn_tick");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   418
	} else if(conn->running) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   419
		flib_log_w("Call to flib_gameconn_tick from a callback");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   420
	} else if(conn->state == FINISHED) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   421
		flib_log_w("Call to flib_gameconn_tick, but we are already done.");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   422
	} else {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   423
		conn->running = true;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   424
		flib_gameconn_wrappedtick(conn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   425
		conn->running = false;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   426
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   427
		if(conn->destroyRequested) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   428
			flib_gameconn_destroy(conn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   429
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   430
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   431
}