author | Medo <smaxein@googlemail.com> |
Mon, 25 Jun 2012 00:42:07 +0200 | |
changeset 7271 | 5608ac657362 |
parent 7234 | 613998625a3c |
child 7275 | 15f722e0b96f |
permissions | -rw-r--r-- |
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 |
|
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
41 |
void (*onEngineMessageCb)(void *context, const uint8_t *em, int size); |
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) {} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
55 |
static void defaultCallback_onEngineMessage(void *context, const uint8_t *em, int 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; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
68 |
flib_gameconn *tempConn = flib_calloc(1, sizeof(flib_gameconn)); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
69 |
if(tempConn) { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
70 |
tempConn->ipcBase = flib_ipcbase_create(); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
71 |
tempConn->configBuffer = flib_vector_create(); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
72 |
tempConn->playerName = flib_strdupnull(playerName); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
73 |
if(tempConn->ipcBase && tempConn->configBuffer && tempConn->playerName) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
74 |
if(record) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
75 |
tempConn->demoBuffer = flib_vector_create(); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
76 |
} |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
77 |
tempConn->state = AWAIT_CONNECTION; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
tempConn->netgame = netGame; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
clearCallbacks(tempConn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
80 |
result = tempConn; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
81 |
tempConn = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
82 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
83 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
84 |
flib_gameconn_destroy(tempConn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
85 |
return result; |
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 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
88 |
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
|
89 |
flib_gameconn *result = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
90 |
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
|
91 |
if(tempConn) { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
92 |
if(!flib_ipc_append_fullconfig(tempConn->configBuffer, setup, netgame)) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
93 |
result = tempConn; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
94 |
tempConn = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
95 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
96 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
97 |
flib_gameconn_destroy(tempConn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
98 |
return result; |
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 *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
|
102 |
flib_gameconn *result = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
103 |
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
|
104 |
if(tempConn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
105 |
if(flib_vector_append(tempConn->configBuffer, demo, size) == size) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
106 |
result = tempConn; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
107 |
tempConn = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
108 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
109 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
110 |
flib_gameconn_destroy(tempConn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
111 |
return result; |
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 *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
|
115 |
flib_gameconn *result = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
116 |
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
|
117 |
if(tempConn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
118 |
if(flib_vector_append(tempConn->configBuffer, save, size) == size) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
119 |
result = tempConn; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
120 |
tempConn = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
121 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
122 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
123 |
flib_gameconn_destroy(tempConn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
124 |
return result; |
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 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
if(tempConn) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
131 |
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
|
132 |
&& !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
|
133 |
&& !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
|
134 |
&& !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
|
135 |
result = tempConn; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
136 |
tempConn = NULL; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
137 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
138 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
139 |
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
|
140 |
return result; |
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 |
|
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
143 |
void flib_gameconn_destroy(flib_gameconn *conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
144 |
if(conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
145 |
if(conn->running) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
146 |
/* |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
147 |
* 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
|
148 |
* 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
|
149 |
* sent to prevent surprises. |
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 |
clearCallbacks(conn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
152 |
conn->destroyRequested = true; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
153 |
} else { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
154 |
flib_ipcbase_destroy(conn->ipcBase); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
155 |
flib_vector_destroy(conn->configBuffer); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
156 |
flib_vector_destroy(conn->demoBuffer); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
157 |
free(conn->playerName); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
158 |
free(conn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
159 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
160 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
161 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
162 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
163 |
int flib_gameconn_getport(flib_gameconn *conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
164 |
if(!conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
165 |
flib_log_e("null parameter in flib_gameconn_getport"); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
166 |
return 0; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
167 |
} else { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
168 |
return flib_ipcbase_port(conn->ipcBase); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
169 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
170 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
171 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
172 |
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
|
173 |
if(conn->demoBuffer) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
174 |
if(flib_vector_append(conn->demoBuffer, data, len) < len) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
175 |
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
|
176 |
flib_vector_destroy(conn->demoBuffer); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
177 |
conn->demoBuffer = NULL; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
178 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
179 |
} |
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 |
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
|
183 |
size_t msglen = strlen(message); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
184 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
185 |
// 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
|
186 |
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
|
187 |
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
|
188 |
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
|
189 |
if(size>0) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
190 |
buffer[0] = size>255 ? 255 : size; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
191 |
return 0; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
192 |
} else { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
193 |
return -1; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
194 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
195 |
} |
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 |
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
|
198 |
// 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
|
199 |
uint8_t converted[257]; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
200 |
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
|
201 |
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
|
202 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
203 |
} |
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 |
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
|
206 |
size_t msgStart = 0; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
207 |
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
|
208 |
while(msgStart+2 < buf.size) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
209 |
if(!memcmp(data+msgStart, "\x02T", 2)) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
210 |
data[msgStart+2] = gamemode; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
211 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
212 |
msgStart += (uint8_t)data[msgStart]+1; |
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 |
} |
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 |
int flib_gameconn_send_enginemsg(flib_gameconn *conn, uint8_t *data, int len) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
217 |
int result = -1; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
218 |
if(!conn || (!data && len>0)) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
219 |
flib_log_e("null parameter in flib_gameconn_send_enginemsg"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
220 |
} else if(!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
|
221 |
demo_append(conn, data, len); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
222 |
result = 0; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
223 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
224 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
225 |
} |
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 |
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
|
228 |
int result = -1; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
229 |
if(!conn || !msg) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
230 |
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
|
231 |
} else { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
232 |
uint8_t converted[257]; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
233 |
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
|
234 |
if(size>0) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
235 |
converted[0] = size>255 ? 255 : size; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
236 |
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
|
237 |
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
|
238 |
result = 0; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
239 |
} |
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 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
243 |
} |
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 |
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
|
246 |
int result = -1; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
247 |
uint8_t converted[257]; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
248 |
if(!conn || !playername || !msg) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
249 |
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
|
250 |
} 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
|
251 |
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
|
252 |
} 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
|
253 |
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
|
254 |
result = 0; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
255 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
256 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
257 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
258 |
|
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
259 |
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
|
260 |
if(!conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
261 |
flib_log_e("null parameter in flib_gameconn_onConnect"); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
262 |
} else { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
263 |
conn->onConnectCb = callback ? callback : &defaultCallback_onConnect; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
264 |
conn->onConnectCtx = context; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
265 |
} |
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 |
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
|
269 |
if(!conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
270 |
flib_log_e("null parameter in flib_gameconn_onDisconnect"); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
271 |
} else { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
272 |
conn->onDisconnectCb = callback ? callback : &defaultCallback_onDisconnect; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
273 |
conn->onDisconnectCtx = context; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
274 |
} |
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 |
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
|
278 |
if(!conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
279 |
flib_log_e("null parameter in flib_gameconn_onErrorMessage"); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
280 |
} else { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
281 |
conn->onErrorMessageCb = callback ? callback : &defaultCallback_onErrorMessage; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
282 |
conn->onErrorMessageCtx = context; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
283 |
} |
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 |
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
|
287 |
if(!conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
288 |
flib_log_e("null parameter in flib_gameconn_onChat"); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
289 |
} else { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
290 |
conn->onChatCb = callback ? callback : &defaultCallback_onChat; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
291 |
conn->onChatCtx = context; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
292 |
} |
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 |
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
|
296 |
if(!conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
297 |
flib_log_e("null parameter in flib_gameconn_onGameRecorded"); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
298 |
} else { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
299 |
conn->onGameRecordedCb = callback ? callback : &defaultCallback_onGameRecorded; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
300 |
conn->onGameRecordedCtx = context; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
301 |
} |
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 |
|
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
304 |
void flib_gameconn_onEngineMessage(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *em, int size), void* context) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
305 |
if(!conn) { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
306 |
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
|
307 |
} else { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
308 |
conn->onEngineMessageCb = callback ? callback : &defaultCallback_onEngineMessage; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
309 |
conn->onEngineMessageCtx = context; |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
310 |
} |
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 |
static void flib_gameconn_wrappedtick(flib_gameconn *conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
314 |
if(conn->state == AWAIT_CONNECTION) { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
315 |
flib_ipcbase_accept(conn->ipcBase); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
316 |
switch(flib_ipcbase_state(conn->ipcBase)) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
317 |
case IPC_CONNECTED: |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
318 |
{ |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
319 |
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
|
320 |
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
|
321 |
conn->state = FINISHED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
322 |
conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
323 |
return; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
324 |
} else { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
325 |
demo_append(conn, configBuffer.data, configBuffer.size); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
326 |
conn->state = CONNECTED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
327 |
conn->onConnectCb(conn->onConnectCtx); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
328 |
if(conn->destroyRequested) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
329 |
return; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
330 |
} |
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 |
break; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
334 |
case IPC_NOT_CONNECTED: |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
335 |
conn->state = FINISHED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
336 |
conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
337 |
return; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
338 |
default: |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
339 |
break; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
340 |
} |
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 |
if(conn->state == CONNECTED) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
344 |
uint8_t msgbuffer[257]; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
345 |
int len; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
346 |
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
|
347 |
if(len<2) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
348 |
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
|
349 |
continue; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
350 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
351 |
switch(msgbuffer[1]) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
352 |
case '?': // Ping |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
353 |
// The pong is already part of the config message |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
354 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
355 |
case 'C': // Config query |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
356 |
// And we already send the config message on connecting. |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
357 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
358 |
case 'E': // Error message |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
359 |
if(len>=3) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
360 |
msgbuffer[len-2] = 0; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
361 |
conn->onErrorMessageCb(conn->onErrorMessageCtx, (char*)msgbuffer+2); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
362 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
363 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
364 |
case 'i': // Statistics |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
365 |
// TODO stats |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
366 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
367 |
case 'Q': // Game interrupted |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
368 |
case 'H': // Game halted |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
369 |
case 'q': // game finished |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
370 |
{ |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
371 |
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
|
372 |
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
|
373 |
if(conn->demoBuffer) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
if(conn->destroyRequested) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
378 |
return; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
379 |
} |
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 |
conn->state = FINISHED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
382 |
conn->onDisconnectCb(conn->onDisconnectCtx, reason); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
383 |
return; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
384 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
385 |
case 's': // Chat message |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
386 |
if(len>=3) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
387 |
msgbuffer[len-2] = 0; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
388 |
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
|
389 |
|
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
390 |
conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, false); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
391 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
392 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
393 |
case 'b': // Teamchat message |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
394 |
if(len>=3) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
395 |
msgbuffer[len-2] = 0; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
396 |
conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, true); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
397 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
398 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
399 |
default: // Engine message |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
400 |
demo_append(conn, msgbuffer, len); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
401 |
|
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
402 |
conn->onEngineMessageCb(conn->onEngineMessageCtx, msgbuffer, len); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
403 |
break; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
404 |
} |
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 |
|
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
408 |
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
|
409 |
conn->state = FINISHED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
410 |
conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
411 |
} |
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 |
void flib_gameconn_tick(flib_gameconn *conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
415 |
if(!conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
416 |
flib_log_e("null parameter in flib_gameconn_tick"); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
417 |
} else if(conn->running) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
418 |
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
|
419 |
} else if(conn->state == FINISHED) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
420 |
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
|
421 |
} else { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
422 |
conn->running = true; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
423 |
flib_gameconn_wrappedtick(conn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
424 |
conn->running = false; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
425 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
426 |
if(conn->destroyRequested) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
427 |
flib_gameconn_destroy(conn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
428 |
} |
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 |
} |