author | Medo <smaxein@googlemail.com> |
Tue, 10 Jul 2012 19:33:57 +0200 | |
changeset 7320 | e704706008d4 |
parent 7316 | f7b49b2c5d84 |
child 7482 | d70a5b0d1190 |
permissions | -rw-r--r-- |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
1 |
/* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
4 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
9 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
13 |
* GNU General Public License for more details. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
14 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
18 |
*/ |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
19 |
|
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
#include "gameconn.h" |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
21 |
#include "ipcbase.h" |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
#include "ipcprotocol.h" |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
#include "../util/logging.h" |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
24 |
#include "../util/util.h" |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
#include "../hwconsts.h" |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
#include <stdbool.h> |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
#include <stdlib.h> |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
28 |
#include <string.h> |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
typedef enum { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
AWAIT_CONNECTION, |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
CONNECTED, |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
FINISHED |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
} gameconn_state; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
struct _flib_gameconn { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
37 |
flib_ipcbase *ipcBase; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
38 |
flib_vector *configBuffer; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
39 |
flib_vector *demoBuffer; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
40 |
char *playerName; |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
gameconn_state state; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
bool netgame; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
44 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
void (*onConnectCb)(void* context); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
void *onConnectCtx; |
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 |
void (*onDisconnectCb)(void* context, int reason); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
49 |
void *onDisconnectCtx; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
void (*onErrorMessageCb)(void* context, const char *msg); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
void *onErrorMessageCtx; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
void (*onChatCb)(void* context, const char *msg, bool teamchat); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
void *onChatCtx; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
|
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
57 |
void (*onGameRecordedCb)(void *context, const uint8_t *record, size_t size, bool isSavegame); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
void *onGameRecordedCtx; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
59 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
60 |
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
|
61 |
void *onEngineMessageCtx; |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
62 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
bool running; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
bool destroyRequested; |
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 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
67 |
static void defaultCallback_onErrorMessage(void* context, const char *msg) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
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
|
69 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
70 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
71 |
static void clearCallbacks(flib_gameconn *conn) { |
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
72 |
flib_gameconn_onConnect(conn, NULL, NULL); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
73 |
flib_gameconn_onDisconnect(conn, NULL, NULL); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
74 |
flib_gameconn_onErrorMessage(conn, NULL, NULL); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
75 |
flib_gameconn_onChat(conn, NULL, NULL); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
76 |
flib_gameconn_onGameRecorded(conn, NULL, NULL); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
77 |
flib_gameconn_onEngineMessage(conn, NULL, NULL); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
80 |
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
|
81 |
flib_gameconn *result = NULL; |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
82 |
flib_gameconn *tempConn = flib_calloc(1, sizeof(flib_gameconn)); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
83 |
if(tempConn) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
84 |
tempConn->ipcBase = flib_ipcbase_create(); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
85 |
tempConn->configBuffer = flib_vector_create(); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
86 |
tempConn->playerName = flib_strdupnull(playerName); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
87 |
if(tempConn->ipcBase && tempConn->configBuffer && tempConn->playerName) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
88 |
if(record) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
89 |
tempConn->demoBuffer = flib_vector_create(); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
90 |
} |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
91 |
tempConn->state = AWAIT_CONNECTION; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
92 |
tempConn->netgame = netGame; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
93 |
clearCallbacks(tempConn); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
94 |
result = tempConn; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
95 |
tempConn = NULL; |
7179
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 |
} |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
98 |
flib_gameconn_destroy(tempConn); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
99 |
return result; |
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 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
102 |
flib_gameconn *flib_gameconn_create(const char *playerName, const flib_gamesetup *setup, bool netgame) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
103 |
if(log_badargs_if2(playerName==NULL, setup==NULL)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
104 |
return NULL; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
105 |
} |
7179
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(true, playerName, netgame); |
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_ipc_append_fullconfig(tempConn->configBuffer, setup, netgame)) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
110 |
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
|
111 |
} else { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
112 |
result = tempConn; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
113 |
tempConn = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
114 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
115 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
116 |
flib_gameconn_destroy(tempConn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
117 |
return result; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
118 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
119 |
|
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
120 |
flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demo, size_t size) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
121 |
if(log_badargs_if(demo==NULL && size>0)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
122 |
return NULL; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
123 |
} |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
124 |
flib_gameconn *result = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
125 |
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
|
126 |
if(tempConn) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
127 |
if(!flib_vector_append(tempConn->configBuffer, demo, size)) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
128 |
result = tempConn; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
129 |
tempConn = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
130 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
131 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
132 |
flib_gameconn_destroy(tempConn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
133 |
return result; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
134 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
135 |
|
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
136 |
flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *save, size_t size) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
137 |
if(log_badargs_if(save==NULL && size>0)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
138 |
return NULL; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
139 |
} |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
140 |
flib_gameconn *result = NULL; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
141 |
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
|
142 |
if(tempConn) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
143 |
if(!flib_vector_append(tempConn->configBuffer, save, size)) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
144 |
result = tempConn; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
145 |
tempConn = NULL; |
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 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
148 |
flib_gameconn_destroy(tempConn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
149 |
return result; |
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 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
152 |
flib_gameconn *flib_gameconn_create_campaign(const char *playerName, const char *seed, const char *script) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
153 |
if(log_badargs_if3(playerName==NULL, seed==NULL, script==NULL)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
154 |
return NULL; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
155 |
} |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
if(tempConn) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
159 |
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
|
160 |
&& !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
|
161 |
&& !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
|
162 |
&& !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
|
163 |
result = tempConn; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
164 |
tempConn = NULL; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
165 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
166 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
167 |
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
|
168 |
return result; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
169 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
170 |
|
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
171 |
void flib_gameconn_destroy(flib_gameconn *conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
172 |
if(conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
173 |
if(conn->running) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
174 |
/* |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
175 |
* 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
|
176 |
* 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
|
177 |
* sent to prevent surprises. |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
178 |
*/ |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
179 |
clearCallbacks(conn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
180 |
conn->destroyRequested = true; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
181 |
} else { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
182 |
flib_ipcbase_destroy(conn->ipcBase); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
183 |
flib_vector_destroy(conn->configBuffer); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
184 |
flib_vector_destroy(conn->demoBuffer); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
185 |
free(conn->playerName); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
186 |
free(conn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
187 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
188 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
189 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
190 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
191 |
int flib_gameconn_getport(flib_gameconn *conn) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
192 |
if(log_badargs_if(conn==NULL)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
193 |
return 0; |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
194 |
} |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
195 |
return flib_ipcbase_port(conn->ipcBase); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
196 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
197 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
198 |
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
|
199 |
if(conn->demoBuffer) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
200 |
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
|
201 |
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
|
202 |
flib_vector_destroy(conn->demoBuffer); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
203 |
conn->demoBuffer = NULL; |
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 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
208 |
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
|
209 |
size_t msglen = strlen(message); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
210 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
211 |
// 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
|
212 |
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
|
213 |
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
|
214 |
int size = snprintf((char*)buffer+1, 256, template, playerName, meMessage ? message+4 : message); |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
215 |
if(log_e_if(size<=0, "printf error")) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
216 |
return -1; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
217 |
} else { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
218 |
buffer[0] = size>255 ? 255 : size; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
219 |
return 0; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
220 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
221 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
222 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
223 |
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
|
224 |
// 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
|
225 |
uint8_t converted[257]; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
226 |
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
|
227 |
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
|
228 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
229 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
230 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
231 |
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
|
232 |
size_t msgStart = 0; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
233 |
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
|
234 |
while(msgStart+2 < buf.size) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
235 |
if(!memcmp(data+msgStart, "\x02T", 2)) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
236 |
data[msgStart+2] = gamemode; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
237 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
238 |
msgStart += (uint8_t)data[msgStart]+1; |
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 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
242 |
int flib_gameconn_send_enginemsg(flib_gameconn *conn, const uint8_t *data, size_t len) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
243 |
if(log_badargs_if2(conn==NULL, data==NULL && len>0)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
244 |
return -1; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
245 |
} |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
246 |
int result = flib_ipcbase_send_raw(conn->ipcBase, data, len); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
247 |
if(!result) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
248 |
demo_append(conn, data, len); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
249 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
250 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
251 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
252 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
253 |
int flib_gameconn_send_textmsg(flib_gameconn *conn, int msgtype, const char *msg) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
254 |
if(log_badargs_if2(conn==NULL, msg==NULL)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
255 |
return -1; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
256 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
257 |
int result = -1; |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
258 |
uint8_t converted[257]; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
259 |
int size = snprintf((char*)converted+1, 256, "s%c%s", (char)msgtype, msg); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
260 |
if(size>0) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
261 |
converted[0] = size>255 ? 255 : size; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
262 |
if(!flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
263 |
demo_append(conn, converted, converted[0]+1); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
264 |
result = 0; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
265 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
266 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
267 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
268 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
269 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
270 |
int flib_gameconn_send_chatmsg(flib_gameconn *conn, const char *playername, const char *msg) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
271 |
if(log_badargs_if3(conn==NULL, playername==NULL, msg==NULL)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
272 |
return -1; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
273 |
} |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
274 |
uint8_t converted[257]; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
275 |
if(!format_chatmessage(converted, playername, msg) |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
276 |
&& !flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
277 |
demo_append(conn, converted, converted[0]+1); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
278 |
return 0; |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
279 |
} |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
280 |
return -1; |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
281 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
282 |
|
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
283 |
/** |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
284 |
* This macro generates a callback setter function. It uses the name of the callback to |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
285 |
* automatically generate the function name and the fields to set, so a consistent naming |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
286 |
* convention needs to be enforced (not that that is a bad thing). If null is passed as |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
287 |
* callback to the generated function, the defaultCb will be set instead (with conn |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
288 |
* as the context). |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
289 |
*/ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
290 |
#define GENERATE_CB_SETTER(cbName, cbParameterTypes, defaultCb) \ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
291 |
void flib_gameconn_##cbName(flib_gameconn *conn, void (*callback)cbParameterTypes, void *context) { \ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
292 |
if(!log_badargs_if(conn==NULL)) { \ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
293 |
conn->cbName##Cb = callback ? callback : &defaultCb; \ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
294 |
conn->cbName##Ctx = callback ? context : conn; \ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
295 |
} \ |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
296 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
297 |
|
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
298 |
/** |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
299 |
* Generate a callback setter function like GENERATE_CB_SETTER, and automatically generate a |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
300 |
* no-op callback function as well that is used as default. |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
301 |
*/ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
302 |
#define GENERATE_CB_SETTER_AND_DEFAULT(cbName, cbParameterTypes) \ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
303 |
static void _noop_callback_##cbName cbParameterTypes {} \ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
304 |
GENERATE_CB_SETTER(cbName, cbParameterTypes, _noop_callback_##cbName) |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
305 |
|
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
306 |
GENERATE_CB_SETTER_AND_DEFAULT(onConnect, (void *context)); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
307 |
GENERATE_CB_SETTER_AND_DEFAULT(onDisconnect, (void* context, int reason)); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
308 |
GENERATE_CB_SETTER(onErrorMessage, (void* context, const char *msg), defaultCallback_onErrorMessage); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
309 |
GENERATE_CB_SETTER_AND_DEFAULT(onChat, (void* context, const char *msg, bool teamchat)); |
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
310 |
GENERATE_CB_SETTER_AND_DEFAULT(onGameRecorded, (void *context, const uint8_t *record, size_t size, bool isSavegame)); |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
311 |
GENERATE_CB_SETTER_AND_DEFAULT(onEngineMessage, (void *context, const uint8_t *em, size_t size)); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
312 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
313 |
#undef GENERATE_CB_SETTER_AND_DEFAULT |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
314 |
#undef GENERATE_CB_SETTER |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
315 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
316 |
static void flib_gameconn_wrappedtick(flib_gameconn *conn) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
317 |
if(conn->state == AWAIT_CONNECTION) { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
318 |
flib_ipcbase_accept(conn->ipcBase); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
319 |
switch(flib_ipcbase_state(conn->ipcBase)) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
320 |
case IPC_CONNECTED: |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
321 |
{ |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
322 |
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
|
323 |
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
|
324 |
conn->state = FINISHED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
325 |
conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
326 |
return; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
327 |
} else { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
328 |
demo_append(conn, configBuffer.data, configBuffer.size); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
329 |
conn->state = CONNECTED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
330 |
conn->onConnectCb(conn->onConnectCtx); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
331 |
if(conn->destroyRequested) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
332 |
return; |
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 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
335 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
336 |
break; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
337 |
case IPC_NOT_CONNECTED: |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
338 |
conn->state = FINISHED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
339 |
conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
340 |
return; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
341 |
default: |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
342 |
break; |
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 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
345 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
346 |
if(conn->state == CONNECTED) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
347 |
uint8_t msgbuffer[257]; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
348 |
int len; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
349 |
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
|
350 |
if(len<2) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
351 |
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
|
352 |
continue; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
353 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
354 |
switch(msgbuffer[1]) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
355 |
case '?': // Ping |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
356 |
// The pong is already part of the config message |
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 'C': // Config query |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
359 |
// And we already send the config message on connecting. |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
360 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
361 |
case 'E': // Error message |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
362 |
if(len>=3) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
363 |
msgbuffer[len-2] = 0; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
364 |
conn->onErrorMessageCb(conn->onErrorMessageCtx, (char*)msgbuffer+2); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
365 |
} |
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 'i': // Statistics |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
368 |
// TODO stats |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
369 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
370 |
case 'Q': // Game interrupted |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
371 |
case 'H': // Game halted |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
372 |
case 'q': // game finished |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
373 |
{ |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
374 |
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
|
375 |
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
|
376 |
if(conn->demoBuffer) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
377 |
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
|
378 |
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
|
379 |
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
|
380 |
if(conn->destroyRequested) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
381 |
return; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
382 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
383 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
384 |
conn->state = FINISHED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
385 |
conn->onDisconnectCb(conn->onDisconnectCtx, reason); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
386 |
return; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
387 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
388 |
case 's': // Chat message |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
389 |
if(len>=3) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
390 |
msgbuffer[len-2] = 0; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
391 |
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
|
392 |
|
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
393 |
conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, false); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
394 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
395 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
396 |
case 'b': // Teamchat message |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
397 |
if(len>=3) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
398 |
msgbuffer[len-2] = 0; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
399 |
conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, true); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
400 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
401 |
break; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
402 |
default: // Engine message |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
403 |
demo_append(conn, msgbuffer, len); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
404 |
|
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
405 |
conn->onEngineMessageCb(conn->onEngineMessageCtx, msgbuffer, len); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
406 |
break; |
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 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
409 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
410 |
|
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
411 |
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
|
412 |
conn->state = FINISHED; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
413 |
conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR); |
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 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
416 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
417 |
void flib_gameconn_tick(flib_gameconn *conn) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
418 |
if(!log_badargs_if(conn == NULL) |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
419 |
&& !log_w_if(conn->running, "Call to flib_gameconn_tick from a callback") |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
420 |
&& !log_w_if(conn->state == FINISHED, "We are already done.")) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
421 |
conn->running = true; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
422 |
flib_gameconn_wrappedtick(conn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
423 |
conn->running = false; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
424 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
425 |
if(conn->destroyRequested) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
426 |
flib_gameconn_destroy(conn); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
427 |
} |
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 |
} |