project_files/frontlib/net/netconn_send.c
author Medo <smaxein@googlemail.com>
Wed, 15 Aug 2012 23:40:10 +0200
changeset 7497 7e1d72fc03c7
parent 7482 d70a5b0d1190
child 7504 ed1d52c5aa94
permissions -rw-r--r--
frontlib: - Removed metascheme-reading and made metascheme a constant instead - Removed reference counting in favor of copying (less confusion about ownership)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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_quit(flib_netconn *conn, const char *quitmsg) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    58
	return sendStr(conn, "QUIT", (quitmsg && *quitmsg) ? quitmsg : "User quit");
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
int flib_netconn_send_chat(flib_netconn *conn, const char *chat) {
7316
f7b49b2c5d84 frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents: 7314
diff changeset
    62
	if(!flib_strempty(chat)) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    63
		return sendStr(conn, "CHAT", chat);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    64
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    65
	return 0;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
}
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
int flib_netconn_send_teamchat(flib_netconn *conn, const char *chat) {
7316
f7b49b2c5d84 frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents: 7314
diff changeset
    69
	if(!flib_strempty(chat)) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    70
		return sendStr(conn, "TEAMCHAT", chat);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    71
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
    72
	return 0;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    75
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
    76
	int result = -1;
7316
f7b49b2c5d84 frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents: 7314
diff changeset
    77
	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
    78
		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
    79
		if(tmpName) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
			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
    81
				free(conn->playerName);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
				conn->playerName = tmpName;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    83
				tmpName = NULL;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
				result = 0;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    85
			}
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
		free(tmpName);
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
7314
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    92
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
    93
	int result = -1;
7316
f7b49b2c5d84 frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents: 7314
diff changeset
    94
	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
    95
		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
    96
		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
    97
		char md5hex[33];
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
    98
		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
    99
		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
   100
		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
   101
		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
   102
			// 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
   103
			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
   104
		}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
		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
   106
	}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
	return result;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   108
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   109
7338
1ed603a54ebd frontlib:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   110
int flib_netconn_send_request_roomlist(flib_netconn *conn) {
1ed603a54ebd frontlib:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   111
	return sendVoid(conn, "LIST");
1ed603a54ebd frontlib:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   112
}
1ed603a54ebd frontlib:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   113
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   114
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
   115
	if(!sendStr(conn, "JOIN_ROOM", room)) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   116
		conn->isChief = false;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   117
		return 0;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   118
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   119
	return -1;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   120
}
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
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
   123
	if(!sendStr(conn, "CREATE_ROOM", room)) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   124
		conn->isChief = true;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   125
		return 0;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   126
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   127
	return -1;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   128
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   129
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   130
int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   131
	return sendStr(conn, "ROOM_NAME", roomName);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   132
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   133
7314
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
   134
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
   135
	int result = -1;
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   136
	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
   137
		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
   138
		if(!result) {
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
   139
			netconn_leaveRoom(conn);
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
   140
		}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   141
	}
7314
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
   142
	return result;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   143
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   144
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   145
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
   146
	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
   147
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   148
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   149
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
   150
	flib_team *teamcopy = flib_team_copy(team);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   151
	if(teamcopy) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   152
		teamcopy->remoteDriven = false;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   153
		free(teamcopy->ownerName);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   154
		teamcopy->ownerName = flib_strdupnull(conn->playerName);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   155
		if(teamcopy->ownerName) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   156
			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
   157
			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
   158
				teamcopy = NULL;
e704706008d4 frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents: 7316
diff changeset
   159
			}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   160
		}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   161
	}
7320
e704706008d4 frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents: 7316
diff changeset
   162
	flib_team_destroy(teamcopy);
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   163
}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   164
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   165
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
   166
	int result = -1;
7316
f7b49b2c5d84 frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents: 7314
diff changeset
   167
	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
   168
		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
   169
		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
   170
			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
   171
		}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   172
		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
   173
			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
   174
			if(vec) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   175
				bool error = false;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   176
				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
   177
				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
   178
					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
   179
				}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   180
				error |= flib_vector_appendf(vec, "\n");
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   181
				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
   182
					addTeamToPendingList(conn, team);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   183
					result = 0;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   184
				}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   185
			}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   186
			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
   187
		}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   188
	}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   189
	return result;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   190
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   191
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   192
int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname) {
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   193
	flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   194
	if(team && !team->remoteDriven && !sendStr(conn, "REMOVE_TEAM", teamname)) {
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   195
		flib_teamlist_delete(&conn->teamlist, teamname);
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   196
		return 0;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   197
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   198
	return -1;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   199
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   200
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   201
int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   202
	int result = -1;
7316
f7b49b2c5d84 frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents: 7314
diff changeset
   203
	if(!log_badargs_if2(conn==NULL, message==NULL && size>0)) {
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   204
		char *base64encout = NULL;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   205
		base64_encode_alloc((const char*)message, size, &base64encout);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   206
		if(base64encout) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   207
			result = flib_netbase_sendf(conn->netBase, "EM\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
   208
		}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   209
		free(base64encout);
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
	return result;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   212
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   213
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   214
int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount) {
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   215
	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
   216
			&& !flib_netbase_sendf(conn->netBase, "HH_NUM\n%s\n%i\n\n", teamname, hogcount)) {
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   217
		flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   218
		if(team) {
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   219
			team->hogsInGame = hogcount;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   220
		}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   221
		return 0;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   222
	}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   223
	return -1;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   224
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   225
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   226
int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex) {
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   227
	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
   228
			&& !flib_netbase_sendf(conn->netBase, "TEAM_COLOR\n%s\n%i\n\n", teamname, colorIndex)) {
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   229
		flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   230
		if(team) {
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   231
			team->colorIndex = colorIndex;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   232
		}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   233
		return 0;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   234
	}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   235
	return -1;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   236
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   237
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   238
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
   239
	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
   240
		char ammostring[WEAPONS_COUNT*4+1];
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   241
		strcpy(ammostring, weaponset->loadout);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   242
		strcat(ammostring, weaponset->crateprob);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   243
		strcat(ammostring, weaponset->delay);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   244
		strcat(ammostring, weaponset->crateammo);
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   245
		if(conn->isChief) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   246
			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
   247
				netconn_setWeaponset(conn, weaponset);
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   248
				return 0;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   249
			}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   250
		}
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   251
	}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   252
	return -1;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   253
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   254
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   255
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
   256
	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
   257
		return -1;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   258
	}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   259
	bool error = false;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   260
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   261
	if(map->seed) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   262
		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
   263
	}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   264
	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
   265
	if(map->theme) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   266
		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
   267
	}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   268
	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
   269
	error |= flib_netconn_send_mapMazeSize(conn, map->mazeSize);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   270
	if(map->name) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   271
		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
   272
	}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   273
	if(map->drawData && map->drawDataSize>0) {
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_mapDrawdata(conn, map->drawData, map->drawDataSize);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   275
	}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   276
	return error;
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
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   279
int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName) {
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   280
	if(log_badargs_if2(conn==NULL, mapName==NULL)) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   281
		return -1;
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   282
	}
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   283
	if(conn->isChief) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   284
		if(!sendStr(conn, "CFG\nMAP", mapName)) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   285
			char *copy = flib_strdupnull(mapName);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   286
			if(copy) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   287
				free(conn->map->name);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   288
				conn->map->name = copy;
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   289
				return 0;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   290
			}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   291
		}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   292
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   293
	return -1;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   294
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   295
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   296
int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen) {
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   297
	if(log_badargs_if(conn==NULL)) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   298
		return -1;
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   299
	}
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   300
	if(conn->isChief) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   301
		if(!sendInt(conn, "CFG\nMAPGEN", mapGen)) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   302
			conn->map->mapgen = mapGen;
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   303
			return 0;
7275
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
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   306
	return -1;
7271
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
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   309
int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter) {
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   310
	if(log_badargs_if(conn==NULL)) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   311
		return -1;
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   312
	}
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   313
	if(conn->isChief) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   314
		if(!sendInt(conn, "CFG\nTEMPLATE", templateFilter)) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   315
			conn->map->templateFilter = templateFilter;
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   316
			return 0;
7275
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
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   319
	return -1;
7271
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
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   322
int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize) {
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   323
	if(log_badargs_if(conn==NULL)) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   324
		return -1;
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   325
	}
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   326
	if(conn->isChief) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   327
		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
   328
			conn->map->mazeSize = mazeSize;
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   329
			return 0;
7275
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
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   332
	return -1;
7271
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
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   335
int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed) {
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   336
	if(log_badargs_if2(conn==NULL, seed==NULL)) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   337
		return -1;
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   338
	}
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   339
	if(conn->isChief) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   340
		if(!sendStr(conn, "CFG\nSEED", seed)) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   341
			char *copy = flib_strdupnull(seed);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   342
			if(copy) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   343
				free(conn->map->seed);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   344
				conn->map->seed = copy;
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   345
				return 0;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   346
			}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   347
		}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   348
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   349
	return -1;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   350
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   351
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   352
int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme) {
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   353
	if(log_badargs_if2(conn==NULL, theme==NULL)) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   354
		return -1;
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   355
	}
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   356
	if(conn->isChief) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   357
		if(!sendStr(conn, "CFG\nTHEME", theme)) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   358
			char *copy = flib_strdupnull(theme);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   359
			if(copy) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   360
				free(conn->map->theme);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   361
				conn->map->theme = copy;
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   362
				return 0;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   363
			}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   364
		}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   365
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   366
	return -1;
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   367
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   368
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   369
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
   370
	int result = -1;
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   371
	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
   372
		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
   373
		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
   374
		if(zipped) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   375
			// 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
   376
			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
   377
			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
   378
			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
   379
			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
   380
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   381
			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
   382
				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
   383
			} else {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   384
				char *base64encout = NULL;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   385
				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
   386
				if(!base64encout) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   387
					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
   388
				} else {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   389
					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
   390
				}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   391
				free(base64encout);
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
		}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   394
		free(zipped);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   395
	}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   396
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   397
	if(!result) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   398
		uint8_t *copy = flib_bufdupnull(drawData, size);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   399
		if(copy) {
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   400
			free(conn->map->drawData);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   401
			conn->map->drawData = copy;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   402
			conn->map->drawDataSize = size;
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   403
		}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   404
	}
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   405
	return result;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   406
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   407
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   408
int flib_netconn_send_script(flib_netconn *conn, const char *scriptName) {
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   409
	if(log_badargs_if2(conn==NULL, scriptName==NULL)) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   410
		return -1;
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   411
	}
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   412
	if(conn->isChief) {
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   413
		if(!sendStr(conn, "CFG\nSCRIPT", scriptName)) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   414
			netconn_setScript(conn, scriptName);
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   415
			return 0;
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   416
		}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   417
	}
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   418
	return -1;
7271
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
7320
e704706008d4 frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents: 7316
diff changeset
   421
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
   422
	int result = -1;
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   423
	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
   424
		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
   425
		if(vec) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   426
			bool error = false;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   427
			error |= flib_vector_appendf(vec, "CFG\nSCHEME\n%s\n", scheme->name);
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   428
			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
   429
				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
   430
			}
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   431
			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
   432
				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
   433
			}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   434
			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
   435
			if(!error) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   436
				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
   437
			}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   438
		}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   439
		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
   440
	}
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   441
7497
7e1d72fc03c7 frontlib:
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   442
	if(!result) {
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   443
		netconn_setScheme(conn, scheme);
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   444
	}
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   445
	return result;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   446
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   447
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   448
int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError) {
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7458
diff changeset
   449
	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
   450
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   451
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   452
int flib_netconn_send_ban(flib_netconn *conn, const char *playerName) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   453
	return sendStr(conn, "BAN", playerName);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   454
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   455
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   456
int flib_netconn_send_kick(flib_netconn *conn, const char *playerName) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   457
	return sendStr(conn, "KICK", playerName);
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_playerInfo(flib_netconn *conn, const char *playerName) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   461
	return sendStr(conn, "INFO", playerName);
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_playerFollow(flib_netconn *conn, const char *playerName) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   465
	return sendStr(conn, "FOLLOW", playerName);
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_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
   469
	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
   470
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   471
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   472
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
   473
	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
   474
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   475
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   476
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
   477
	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
   478
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   479
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   480
int flib_netconn_send_clearAccountsCache(flib_netconn *conn) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   481
	return sendVoid(conn, "CLEAR_ACCOUNTS_CACHE");
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   482
}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   483
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   484
int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value) {
7316
f7b49b2c5d84 frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents: 7314
diff changeset
   485
	if(log_badargs_if3(conn==NULL, flib_strempty(name), flib_strempty(value))) {
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   486
		return -1;
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   487
	}
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   488
	return flib_netbase_sendf(conn->netBase, "%s\n%s\n%s\n\n", "SET_SERVER_VAR", name, value);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   489
}
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
int flib_netconn_send_getServerVars(flib_netconn *conn) {
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   492
	return sendVoid(conn, "GET_SERVER_VAR");
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
diff changeset
   493
}