author | Periklis Ntanasis <pntanasis@gmail.com> |
Thu, 12 Sep 2013 03:19:31 +0300 | |
branch | spacecampaign |
changeset 9614 | 7fa70d381c75 |
parent 7580 | c92596feac0d |
child 10017 | de822cd3df3a |
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 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
#include "netconn_internal.h" |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
#include "../util/logging.h" |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
#include "../util/util.h" |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
#include "../util/buffer.h" |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
#include "../md5/md5.h" |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
#include "../base64/base64.h" |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
|
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
28 |
#include <zlib.h> |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
29 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
#include <stdlib.h> |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
#include <string.h> |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
32 |
#include <limits.h> |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
// cmdname is always given as literal from functions in this file, so it is never null. |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
static int sendVoid(flib_netconn *conn, const char *cmdname) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
36 |
if(log_e_if(!conn, "Invalid parameter sending %s command", cmdname)) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
return -1; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
38 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
return flib_netbase_sendf(conn->netBase, "%s\n\n", cmdname); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
42 |
// Testing for !*str prevents sending 0-length parameters (they trip up the protocol) |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
static int sendStr(flib_netconn *conn, const char *cmdname, const char *str) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
44 |
if(log_e_if(!conn || flib_strempty(str), "Invalid parameter sending %s command", cmdname)) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
return -1; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
return flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", cmdname, str); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
49 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
static int sendInt(flib_netconn *conn, const char *cmdname, int param) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
51 |
if(log_e_if(!conn, "Invalid parameter sending %s command", cmdname)) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
return -1; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
return flib_netbase_sendf(conn->netBase, "%s\n%i\n\n", cmdname, param); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
57 |
int flib_netconn_send_nick(flib_netconn *conn, const char *nick) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
int result = -1; |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
59 |
if(!log_badargs_if2(conn==NULL, flib_strempty(nick))) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
60 |
char *tmpName = flib_strdupnull(nick); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
61 |
if(tmpName) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
62 |
if(!flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "NICK", nick)) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
free(conn->playerName); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
conn->playerName = tmpName; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
tmpName = NULL; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
66 |
result = 0; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
67 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
69 |
free(tmpName); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
70 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
71 |
return result; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
72 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
73 |
|
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
74 |
int flib_netconn_send_password(flib_netconn *conn, const char *passwd) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
75 |
int result = -1; |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
76 |
if(!log_badargs_if2(conn==NULL, passwd==NULL)) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
77 |
md5_state_t md5state; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
uint8_t md5bytes[16]; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
char md5hex[33]; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
80 |
md5_init(&md5state); |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
81 |
md5_append(&md5state, (unsigned char*)passwd, strlen(passwd)); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
82 |
md5_finish(&md5state, md5bytes); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
83 |
for(int i=0;i<sizeof(md5bytes); i++) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
84 |
// Needs to be lowercase - server checks case sensitive |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
85 |
snprintf(md5hex+i*2, 3, "%02x", (unsigned)md5bytes[i]); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
86 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
87 |
result = flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "PASSWORD", md5hex); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
88 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
89 |
return result; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
90 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
91 |
|
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
92 |
int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
93 |
return sendStr(conn, "QUIT", (quitmsg && *quitmsg) ? quitmsg : "User quit"); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
94 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
95 |
|
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
96 |
int flib_netconn_send_chat(flib_netconn *conn, const char *chat) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
97 |
if(!flib_strempty(chat)) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
98 |
return sendStr(conn, "CHAT", chat); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
99 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
100 |
return 0; |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
101 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
102 |
|
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
103 |
int flib_netconn_send_kick(flib_netconn *conn, const char *playerName) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
104 |
return sendStr(conn, "KICK", playerName); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
105 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
106 |
|
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
107 |
int flib_netconn_send_playerInfo(flib_netconn *conn, const char *playerName) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
108 |
return sendStr(conn, "INFO", playerName); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
109 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
110 |
|
7338 | 111 |
int flib_netconn_send_request_roomlist(flib_netconn *conn) { |
112 |
return sendVoid(conn, "LIST"); |
|
113 |
} |
|
114 |
||
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
115 |
int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
116 |
if(!sendStr(conn, "JOIN_ROOM", room)) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
117 |
conn->isChief = false; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
118 |
return 0; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
119 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
120 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
121 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
122 |
|
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
123 |
int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
124 |
return sendStr(conn, "FOLLOW", playerName); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
125 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
126 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
127 |
int flib_netconn_send_createRoom(flib_netconn *conn, const char *room) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
128 |
if(!sendStr(conn, "CREATE_ROOM", room)) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
129 |
conn->isChief = true; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
130 |
return 0; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
131 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
132 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
133 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
134 |
|
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
135 |
int flib_netconn_send_ban(flib_netconn *conn, const char *playerName) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
136 |
return sendStr(conn, "BAN", playerName); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
137 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
138 |
|
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
139 |
int flib_netconn_send_clearAccountsCache(flib_netconn *conn) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
140 |
return sendVoid(conn, "CLEAR_ACCOUNTS_CACHE"); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
141 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
142 |
|
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
143 |
int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
144 |
if(log_badargs_if3(conn==NULL, flib_strempty(name), flib_strempty(value))) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
145 |
return -1; |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
146 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
147 |
return flib_netbase_sendf(conn->netBase, "%s\n%s\n%s\n\n", "SET_SERVER_VAR", name, value); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
148 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
149 |
|
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
150 |
int flib_netconn_send_getServerVars(flib_netconn *conn) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
151 |
return sendVoid(conn, "GET_SERVER_VAR"); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
152 |
} |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
153 |
int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *str) { |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
154 |
int result = -1; |
7482 | 155 |
if(conn->netconnState==NETCONN_STATE_ROOM) { |
7458
fec6fa1e460e
frontlib: Fixed flib_netconn_send_leaveRoom returning -1 even though there was no error.
Medo <smaxein@googlemail.com>
parents:
7338
diff
changeset
|
156 |
result = (str && *str) ? sendStr(conn, "PART", str) : sendVoid(conn, "PART"); |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
157 |
if(!result) { |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
158 |
netconn_leaveRoom(conn); |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
159 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
160 |
} |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
161 |
return result; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
162 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
163 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
164 |
int flib_netconn_send_toggleReady(flib_netconn *conn) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
165 |
return sendVoid(conn, "TOGGLE_READY"); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
166 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
167 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
168 |
static void addTeamToPendingList(flib_netconn *conn, const flib_team *team) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
169 |
flib_team *teamcopy = flib_team_copy(team); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
170 |
if(teamcopy) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
171 |
teamcopy->remoteDriven = false; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
172 |
free(teamcopy->ownerName); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
173 |
teamcopy->ownerName = flib_strdupnull(conn->playerName); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
174 |
if(teamcopy->ownerName) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
175 |
flib_teamlist_delete(&conn->pendingTeamlist, team->name); |
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
176 |
if(!flib_teamlist_insert(&conn->pendingTeamlist, teamcopy, 0)) { |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
177 |
teamcopy = NULL; |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
178 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
179 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
180 |
} |
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
181 |
flib_team_destroy(teamcopy); |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
182 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
183 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
184 |
int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
185 |
int result = -1; |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
186 |
if(!log_badargs_if2(conn==NULL, team==NULL)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
187 |
bool missingInfo = flib_strempty(team->name) || flib_strempty(team->grave) || flib_strempty(team->fort) || flib_strempty(team->voicepack) || flib_strempty(team->flag); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
188 |
for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
189 |
missingInfo |= flib_strempty(team->hogs[i].name) || flib_strempty(team->hogs[i].hat); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
190 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
191 |
if(!log_e_if(missingInfo, "Incomplete team definition")) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
192 |
flib_vector *vec = flib_vector_create(); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
193 |
if(vec) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
194 |
bool error = false; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
195 |
error |= flib_vector_appendf(vec, "ADD_TEAM\n%s\n%i\n%s\n%s\n%s\n%s\n%i\n", team->name, team->colorIndex, team->grave, team->fort, team->voicepack, team->flag, team->hogs[0].difficulty); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
196 |
for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
197 |
error |= flib_vector_appendf(vec, "%s\n%s\n", team->hogs[i].name, team->hogs[i].hat); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
198 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
199 |
error |= flib_vector_appendf(vec, "\n"); |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
200 |
if(!error && !flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec))) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
201 |
addTeamToPendingList(conn, team); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
202 |
result = 0; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
203 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
204 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
205 |
flib_vector_destroy(vec); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
206 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
207 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
208 |
return result; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
209 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
210 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
211 |
int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname) { |
7482 | 212 |
flib_team *team = flib_teamlist_find(&conn->teamlist, teamname); |
213 |
if(team && !team->remoteDriven && !sendStr(conn, "REMOVE_TEAM", teamname)) { |
|
214 |
flib_teamlist_delete(&conn->teamlist, teamname); |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
215 |
return 0; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
216 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
217 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
218 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
219 |
|
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
220 |
int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
221 |
return sendStr(conn, "ROOM_NAME", roomName); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
222 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
223 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
224 |
int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount) { |
7482 | 225 |
if(!log_badargs_if5(conn==NULL, flib_strempty(teamname), hogcount<1, hogcount>HEDGEHOGS_PER_TEAM, !conn->isChief) |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
226 |
&& !flib_netbase_sendf(conn->netBase, "HH_NUM\n%s\n%i\n\n", teamname, hogcount)) { |
7482 | 227 |
flib_team *team = flib_teamlist_find(&conn->teamlist, teamname); |
228 |
if(team) { |
|
229 |
team->hogsInGame = hogcount; |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
230 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
231 |
return 0; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
232 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
233 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
234 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
235 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
236 |
int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex) { |
7482 | 237 |
if(!log_badargs_if3(conn==NULL, flib_strempty(teamname), !conn->isChief) |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
238 |
&& !flib_netbase_sendf(conn->netBase, "TEAM_COLOR\n%s\n%i\n\n", teamname, colorIndex)) { |
7482 | 239 |
flib_team *team = flib_teamlist_find(&conn->teamlist, teamname); |
240 |
if(team) { |
|
241 |
team->colorIndex = colorIndex; |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
242 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
243 |
return 0; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
244 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
245 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
246 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
247 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
248 |
int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
249 |
if(!log_badargs_if3(conn==NULL, weaponset==NULL, flib_strempty(weaponset->name))) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
250 |
char ammostring[WEAPONS_COUNT*4+1]; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
251 |
strcpy(ammostring, weaponset->loadout); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
252 |
strcat(ammostring, weaponset->crateprob); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
253 |
strcat(ammostring, weaponset->delay); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
254 |
strcat(ammostring, weaponset->crateammo); |
7497 | 255 |
if(conn->isChief) { |
256 |
if(!flib_netbase_sendf(conn->netBase, "CFG\nAMMO\n%s\n%s\n\n", weaponset->name, ammostring)) { |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
257 |
netconn_setWeaponset(conn, weaponset); |
7497 | 258 |
return 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
259 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
260 |
} |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
261 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
262 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
263 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
264 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
265 |
int flib_netconn_send_map(flib_netconn *conn, const flib_map *map) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
266 |
if(log_badargs_if2(conn==NULL, map==NULL)) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
267 |
return -1; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
268 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
269 |
bool error = false; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
270 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
271 |
if(map->seed) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
272 |
error |= flib_netconn_send_mapSeed(conn, map->seed); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
273 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
274 |
error |= flib_netconn_send_mapTemplate(conn, map->templateFilter); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
275 |
if(map->theme) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
276 |
error |= flib_netconn_send_mapTheme(conn, map->theme); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
277 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
278 |
error |= flib_netconn_send_mapGen(conn, map->mapgen); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
279 |
error |= flib_netconn_send_mapMazeSize(conn, map->mazeSize); |
7504
ed1d52c5aa94
frontlib: Moved mapname sending to the end of flib_netconn_send_map
Medo <smaxein@googlemail.com>
parents:
7497
diff
changeset
|
280 |
if(map->drawData && map->drawDataSize>0) { |
ed1d52c5aa94
frontlib: Moved mapname sending to the end of flib_netconn_send_map
Medo <smaxein@googlemail.com>
parents:
7497
diff
changeset
|
281 |
error |= flib_netconn_send_mapDrawdata(conn, map->drawData, map->drawDataSize); |
ed1d52c5aa94
frontlib: Moved mapname sending to the end of flib_netconn_send_map
Medo <smaxein@googlemail.com>
parents:
7497
diff
changeset
|
282 |
} |
ed1d52c5aa94
frontlib: Moved mapname sending to the end of flib_netconn_send_map
Medo <smaxein@googlemail.com>
parents:
7497
diff
changeset
|
283 |
// Name is sent last, because the QtFrontend uses this to update its preview, and to show/hide |
ed1d52c5aa94
frontlib: Moved mapname sending to the end of flib_netconn_send_map
Medo <smaxein@googlemail.com>
parents:
7497
diff
changeset
|
284 |
// certain fields |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
285 |
if(map->name) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
286 |
error |= flib_netconn_send_mapName(conn, map->name); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
287 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
288 |
return error; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
289 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
290 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
291 |
int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName) { |
7497 | 292 |
if(log_badargs_if2(conn==NULL, mapName==NULL)) { |
293 |
return -1; |
|
294 |
} |
|
295 |
if(conn->isChief) { |
|
296 |
if(!sendStr(conn, "CFG\nMAP", mapName)) { |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
297 |
char *copy = flib_strdupnull(mapName); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
298 |
if(copy) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
299 |
free(conn->map->name); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
300 |
conn->map->name = copy; |
7497 | 301 |
return 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
302 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
303 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
304 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
305 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
306 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
307 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
308 |
int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen) { |
7497 | 309 |
if(log_badargs_if(conn==NULL)) { |
310 |
return -1; |
|
311 |
} |
|
312 |
if(conn->isChief) { |
|
313 |
if(!sendInt(conn, "CFG\nMAPGEN", mapGen)) { |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
314 |
conn->map->mapgen = mapGen; |
7497 | 315 |
return 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
316 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
317 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
318 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
319 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
320 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
321 |
int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter) { |
7497 | 322 |
if(log_badargs_if(conn==NULL)) { |
323 |
return -1; |
|
324 |
} |
|
325 |
if(conn->isChief) { |
|
326 |
if(!sendInt(conn, "CFG\nTEMPLATE", templateFilter)) { |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
327 |
conn->map->templateFilter = templateFilter; |
7497 | 328 |
return 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
329 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
330 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
331 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
332 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
333 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
334 |
int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize) { |
7497 | 335 |
if(log_badargs_if(conn==NULL)) { |
336 |
return -1; |
|
337 |
} |
|
338 |
if(conn->isChief) { |
|
339 |
if(!sendInt(conn, "CFG\nMAZE_SIZE", mazeSize)) { |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
340 |
conn->map->mazeSize = mazeSize; |
7497 | 341 |
return 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
342 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
343 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
344 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
345 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
346 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
347 |
int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed) { |
7497 | 348 |
if(log_badargs_if2(conn==NULL, seed==NULL)) { |
349 |
return -1; |
|
350 |
} |
|
351 |
if(conn->isChief) { |
|
352 |
if(!sendStr(conn, "CFG\nSEED", seed)) { |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
353 |
char *copy = flib_strdupnull(seed); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
354 |
if(copy) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
355 |
free(conn->map->seed); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
356 |
conn->map->seed = copy; |
7497 | 357 |
return 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
358 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
359 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
360 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
361 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
362 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
363 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
364 |
int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme) { |
7497 | 365 |
if(log_badargs_if2(conn==NULL, theme==NULL)) { |
366 |
return -1; |
|
367 |
} |
|
368 |
if(conn->isChief) { |
|
369 |
if(!sendStr(conn, "CFG\nTHEME", theme)) { |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
370 |
char *copy = flib_strdupnull(theme); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
371 |
if(copy) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
372 |
free(conn->map->theme); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
373 |
conn->map->theme = copy; |
7497 | 374 |
return 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
375 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
376 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
377 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
378 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
379 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
380 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
381 |
int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
382 |
int result = -1; |
7497 | 383 |
if(!log_badargs_if3(conn==NULL, drawData==NULL && size>0, size>SIZE_MAX/2) && conn->isChief) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
384 |
uLongf zippedSize = compressBound(size); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
385 |
uint8_t *zipped = flib_malloc(zippedSize+4); // 4 extra bytes for header |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
386 |
if(zipped) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
387 |
// Create the QCompress size header (uint32 big endian) |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
388 |
zipped[0] = (size>>24) & 0xff; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
389 |
zipped[1] = (size>>16) & 0xff; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
390 |
zipped[2] = (size>>8) & 0xff; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
391 |
zipped[3] = (size) & 0xff; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
392 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
393 |
if(compress(zipped+4, &zippedSize, drawData, size) != Z_OK) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
394 |
flib_log_e("Error compressing drawn map data."); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
395 |
} else { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
396 |
char *base64encout = NULL; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
397 |
base64_encode_alloc((const char*)zipped, zippedSize+4, &base64encout); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
398 |
if(!base64encout) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
399 |
flib_log_e("Error base64-encoding drawn map data."); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
400 |
} else { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
401 |
result = flib_netbase_sendf(conn->netBase, "CFG\nDRAWNMAP\n%s\n\n", base64encout); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
402 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
403 |
free(base64encout); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
404 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
405 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
406 |
free(zipped); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
407 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
408 |
|
7497 | 409 |
if(!result) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
410 |
uint8_t *copy = flib_bufdupnull(drawData, size); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
411 |
if(copy) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
412 |
free(conn->map->drawData); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
413 |
conn->map->drawData = copy; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
414 |
conn->map->drawDataSize = size; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
415 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
416 |
} |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
417 |
return result; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
418 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
419 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
420 |
int flib_netconn_send_script(flib_netconn *conn, const char *scriptName) { |
7497 | 421 |
if(log_badargs_if2(conn==NULL, scriptName==NULL)) { |
422 |
return -1; |
|
423 |
} |
|
424 |
if(conn->isChief) { |
|
425 |
if(!sendStr(conn, "CFG\nSCRIPT", scriptName)) { |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
426 |
netconn_setScript(conn, scriptName); |
7497 | 427 |
return 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
428 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
429 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
430 |
return -1; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
431 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
432 |
|
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
433 |
int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
434 |
int result = -1; |
7497 | 435 |
if(!log_badargs_if3(conn==NULL, scheme==NULL, flib_strempty(scheme->name)) && conn->isChief) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
436 |
flib_vector *vec = flib_vector_create(); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
437 |
if(vec) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
438 |
bool error = false; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
439 |
error |= flib_vector_appendf(vec, "CFG\nSCHEME\n%s\n", scheme->name); |
7497 | 440 |
for(int i=0; i<flib_meta.modCount; i++) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
441 |
error |= flib_vector_appendf(vec, "%s\n", scheme->mods[i] ? "true" : "false"); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
442 |
} |
7497 | 443 |
for(int i=0; i<flib_meta.settingCount; i++) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
444 |
error |= flib_vector_appendf(vec, "%i\n", scheme->settings[i]); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
445 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
446 |
error |= flib_vector_appendf(vec, "\n"); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
447 |
if(!error) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
448 |
result = flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec)); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
449 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
450 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
451 |
flib_vector_destroy(vec); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
452 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
453 |
|
7497 | 454 |
if(!result) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
455 |
netconn_setScheme(conn, scheme); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
456 |
} |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
457 |
return result; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
458 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
459 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
460 |
int flib_netconn_send_startGame(flib_netconn *conn) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
461 |
return sendVoid(conn, "START_GAME"); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
462 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
463 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
464 |
int flib_netconn_send_toggleRestrictJoins(flib_netconn *conn) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
465 |
return sendVoid(conn, "TOGGLE_RESTRICT_JOINS"); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
466 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
467 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
468 |
int flib_netconn_send_toggleRestrictTeams(flib_netconn *conn) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
469 |
return sendVoid(conn, "TOGGLE_RESTRICT_TEAMS"); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
470 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
471 |
|
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
472 |
int flib_netconn_send_teamchat(flib_netconn *conn, const char *chat) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
473 |
if(!flib_strempty(chat)) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
474 |
return sendStr(conn, "TEAMCHAT", chat); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
475 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
476 |
return 0; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
477 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
478 |
|
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
479 |
int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
480 |
int result = -1; |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
481 |
if(!log_badargs_if2(conn==NULL, message==NULL && size>0)) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
482 |
char *base64encout = NULL; |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
483 |
base64_encode_alloc((const char*)message, size, &base64encout); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
484 |
if(base64encout) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
485 |
result = flib_netbase_sendf(conn->netBase, "EM\n%s\n\n", base64encout); |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
486 |
} |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
487 |
free(base64encout); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
488 |
} |
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
489 |
return result; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
490 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
491 |
|
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
492 |
int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError) { |
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
493 |
return sendInt(conn, "ROUNDFINISHED", withoutError ? 1 : 0); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
494 |
} |
7580
c92596feac0d
frontlib: Improved documentation of netconn, unified naming of a callback
Medo <smaxein@googlemail.com>
parents:
7504
diff
changeset
|
495 |