project_files/cmdlineClient/cmdlineClient.c
author unc0rr
Tue, 20 Nov 2012 00:10:12 +0400
changeset 8070 66bc20d089fc
parent 7488 7e09947b6aa5
child 10017 de822cd3df3a
permissions -rw-r--r--
Okay, remove previous request only if it has same parent as this one. Fixes the last note of previous commit (which was nearly impossible to hit, but whatever, just cleaning implementation)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
/*
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
 *
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
 * modify it under the terms of the GNU General Public License
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
 * of the License, or (at your option) any later version.
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
 *
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
 * GNU General Public License for more details.
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
 *
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
 */
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
#include <frontlib.h>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
#include <util/logging.h>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
#include <util/util.h>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
#include <base64/base64.h>
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
    24
#include <model/schemelist.h>
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
#include <stdlib.h>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
#include <stdbool.h>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
#include <assert.h>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
#include <string.h>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
#include <conio.h>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
#include <windows.h>
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
#define ENGINE_DIR ".\\"
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
#define CONFIG_DIR "..\\share\\hedgewars"
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
#define DATA_DIR CONFIG_DIR"\\Data"
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
static flib_netconn *netconn;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
static flib_gameconn *gameconn;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
static flib_mapconn *mapconn;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
static char nickname[128];
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
    41
static flib_metascheme *metacfg;
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
static bool netConnected = false;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
// Callback function that will be called when the map is rendered
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
static void handleMapGenerated(void *context, const uint8_t *bitmap, int numHedgehogs) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
	printf("Drawing map for %i brave little hogs...", numHedgehogs);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
	// Draw the map as ASCII art
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
	for(int y=0; y<MAPIMAGE_HEIGHT; y+=8) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
		for(int x=0; x<MAPIMAGE_WIDTH; x+=6) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
			int pixelnum = x + y*MAPIMAGE_WIDTH;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
			bool pixel = bitmap[pixelnum>>3] & (1<<(7-(pixelnum&7)));
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
			printf(pixel ? "#" : " ");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
		printf("\n");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
	flib_mapconn_destroy(mapconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
	mapconn = NULL;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
static void onGameDisconnect(void *context, int reason) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
	flib_log_i("Connection closed. Reason: %i", reason);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
	flib_gameconn_destroy(gameconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
	gameconn = NULL;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
	if(netconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
		flib_netconn_send_roundfinished(netconn, reason==GAME_END_FINISHED);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    69
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    71
// Callback function that will be called on error
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
static void handleMapFailure(void *context, const char *errormessage) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
	flib_log_e("Map rendering failed: %s", errormessage);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
	flib_mapconn_destroy(mapconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    75
	mapconn = NULL;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    77
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    78
static void startEngineMap(int port) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
	char cmdbuffer[255];
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
	char argbuffer[255];
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    81
	snprintf(cmdbuffer, 255, "%shwengine.exe", ENGINE_DIR);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
	snprintf(argbuffer, 255, "%s %i landpreview", CONFIG_DIR, port);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    83
	ShellExecute(NULL, NULL, cmdbuffer, argbuffer, NULL, SW_HIDE);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    85
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
static void startEngineGame(int port) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
	char cmdbuffer[255];
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
	char argbuffer[255];
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    89
	char base64PlayerName[255];
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    90
	base64_encode(nickname, strlen(nickname), base64PlayerName, sizeof(base64PlayerName));
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    91
	snprintf(cmdbuffer, 255, "%shwengine.exe", ENGINE_DIR);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
	snprintf(argbuffer, 255, "%s 1024 768 32 %i 0 0 0 10 10 %s 0 0 %s 0 0 en.txt", CONFIG_DIR, port, DATA_DIR, base64PlayerName);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    93
	ShellExecute(NULL, NULL, cmdbuffer, argbuffer, NULL, SW_HIDE);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    94
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    95
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    96
void handleNetDisconnect(void *context, int reason, const char *message) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    97
	printf("Disconnected: %s", message);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    98
	flib_netconn_destroy(netconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    99
	netconn = NULL;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   100
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   101
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   102
/*void printRoomList() {
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   103
	const flib_roomlist *roomlist = flib_netconn_get_roomlist(netconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   104
	if(roomlist) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
		if(roomlist->roomCount>0) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   106
			for(int i=0; i<roomlist->roomCount; i++) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
				if(i>0) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   108
					printf(", ");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   109
				}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   110
				flib_room *room = roomlist->rooms[i];
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   111
				printf("%s", room->name);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   112
			}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   113
		} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   114
			puts("Unfortunately, there are no rooms at the moment.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   115
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   116
	} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   117
		puts("Sorry, due to an error the room list is not available.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   118
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   119
	puts("\n");
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   120
}*/
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   121
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   122
void printTeamList() {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   123
	flib_gamesetup *setup = flib_netconn_create_gamesetup(netconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   124
	if(setup) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   125
		puts("The following teams are in this room:");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   126
		for(int i=0; i<setup->teamlist->teamCount; i++) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   127
			if(i>0) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   128
				printf(", ");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   129
			}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   130
			printf("%s", setup->teamlist->teams[i]->name);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   131
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   132
		puts("\n");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   133
	} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   134
		puts("Sorry, due to an error the team list is not available.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   135
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   136
	flib_gamesetup_destroy(setup);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   137
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   138
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   139
void handleNetConnected(void *context) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   140
	printf("You enter the lobby of a strange house inhabited by hedgehogs. Looking around, you see hallways branching off to these rooms:\n");
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   141
	//printRoomList();
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   142
	printf("\n\nNow, you can chat by just entering text, or join a room with /join <roomname>.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   143
	printf(" You can also /quit or let me /describe <roomname>. Once in a room, you can /add <teamname> and set yourself /ready. You can also /list the available rooms (in the lobby) or the teams (in a room).\n");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   144
	netConnected = true;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   145
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   146
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   147
void handleChat(void *context, const char *nick, const char *msg) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   148
	if(gameconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   149
		flib_gameconn_send_chatmsg(gameconn, nick, msg);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   150
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   151
	printf("%s: %s\n", nick, msg);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   152
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   153
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   154
void handleEnterRoom(void *context, bool isChief) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   155
	puts("You have entered the room.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   156
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   157
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   158
void handleRoomJoin(void *context, const char *nick) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   159
	if(strcmp(nick, nickname)) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   160
		printf("%s is here.\n", nick);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   161
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   162
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   163
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   164
void handleRoomLeave(void *context, const char *nick, const char *partmsg) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   165
	if(strcmp(nick, nickname)) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   166
		printf("%s leaves.\n", nick);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   167
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   168
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   169
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   170
void handleReady(void *context, const char *nick, bool ready) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   171
	if(strcmp(nick, nickname)) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   172
		if(ready) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   173
			printf("%s is ready to go.\n", nick);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   174
		} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   175
			printf("%s is not ready.\n", nick);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   176
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   177
	} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   178
		if(ready) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   179
			printf("You are ready to go.\n");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   180
		} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   181
			printf("You are not ready.\n");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   182
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   183
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   184
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   185
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   186
void handleEmFromNet(void *context, const uint8_t *em, size_t size) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   187
	if(gameconn) {
7488
7e09947b6aa5 Removed useless cast in cmdlineClient
Medo <smaxein@googlemail.com>
parents: 7473
diff changeset
   188
		flib_gameconn_send_enginemsg(gameconn, em, size);
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   189
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   190
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   191
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   192
void handleEmFromEngine(void *context, const uint8_t *em, size_t size) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   193
	if(netconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   194
		flib_netconn_send_engineMessage(netconn, em, size);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   195
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   196
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   197
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   198
void handleChatFromGame(void *context, const char *message, bool teamchat) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   199
	if(netconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   200
		if(teamchat) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   201
			flib_netconn_send_teamchat(netconn, message);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   202
		} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   203
			flib_netconn_send_chat(netconn, message);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   204
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   205
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   206
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   207
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   208
void handleRunGame(void *context) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   209
	flib_gamesetup *gamesetup = flib_netconn_create_gamesetup(netconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   210
	if(gameconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   211
		flib_log_e("Request to start game, but a game is already running.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   212
	} else if(gamesetup) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   213
		gameconn = flib_gameconn_create(nickname, gamesetup, true);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   214
		flib_gameconn_onEngineMessage(gameconn, handleEmFromEngine, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   215
		flib_gameconn_onDisconnect(gameconn, onGameDisconnect, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   216
		flib_gameconn_onChat(gameconn, handleChatFromGame, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   217
		startEngineGame(flib_gameconn_getport(gameconn));
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   218
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   219
	flib_gamesetup_destroy(gamesetup);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   220
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   221
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   222
void handleNickTaken(void *context, const char *nick) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   223
	printf("The nickname %s is already in use, please choose a different one:\n", nick);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   224
	flib_gets(nickname, sizeof(nickname));
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   225
	flib_netconn_send_nick(netconn, nickname);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   226
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   227
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   228
void handlePwRequest(void *context, const char *nick) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   229
	printf("A password is required to log in as %s, please enter (warning: shown in cleartext):\n", nick);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   230
	char password[256];
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   231
	flib_gets(password, sizeof(password));
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   232
	flib_netconn_send_password(netconn, password);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   233
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   234
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   235
void handleMessage(void *context, int type, const char *msg) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   236
	if(gameconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   237
		flib_gameconn_send_textmsg(gameconn, 1, msg);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   238
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   239
	printf("*** %s\n", msg);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   240
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   241
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   242
void handleTeamAccepted(void *context, const char *teamname) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   243
	printf("The team %s has been accepted.\n", teamname);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   244
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   245
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   246
void handleMapChanged(void *context, const flib_map *map, int changetype) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   247
	if(map->mapgen != MAPGEN_NAMED && changetype != NETCONN_MAPCHANGE_THEME) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   248
		if(mapconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   249
			flib_mapconn_destroy(mapconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   250
			mapconn = NULL;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   251
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   252
		mapconn = flib_mapconn_create(map);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   253
		if(mapconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   254
			flib_mapconn_onSuccess(mapconn, handleMapGenerated, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   255
			flib_mapconn_onFailure(mapconn, handleMapFailure, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   256
			startEngineMap(flib_mapconn_getport(mapconn));
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   257
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   258
	} else if(map->mapgen == MAPGEN_NAMED) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   259
		printf("The map %s has been selected.\n", map->name);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   260
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   261
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   262
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   263
void handleLeaveRoom(void *context, int reason, const char *msg) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   264
	if(reason == NETCONN_ROOMLEAVE_ABANDONED) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   265
		printf("The chief has abandoned the room.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   266
	} else if(reason == NETCONN_ROOMLEAVE_KICKED) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   267
		printf("You have been kicked from the room.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   268
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   269
	if(msg) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   270
		printf(" (%s)", msg);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   271
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   272
	puts(" You are back in the lobby.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   273
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   274
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   275
void handleSchemeChanged(void *context, const flib_scheme *scheme) {
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   276
	printf("Game scheme: %s.\n", scheme->name);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   277
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   278
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   279
void handleWeaponsetChanged(void *context, const flib_weaponset *weaponset) {
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   280
	printf("Weaponset: %s.\n", weaponset->name);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   281
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   282
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   283
void handleHogcountChanged(void *context, const char *team, int count) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   284
	printf("Team %s will send %i hogs into the fight.\n", team, count);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   285
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   286
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   287
void handleRoomAdd(void *context, const flib_room *room) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   288
	printf("%s created a new room called %s.\n", room->owner, room->name);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   289
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   290
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   291
void handleRoomDelete(void *context, const char *roomName) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   292
	printf("The room %s has collapsed.\n", roomName);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   293
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   294
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   295
void handleScriptChanged(void *context, const char *script) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   296
	printf("Game Type: %s\n", script);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   297
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   298
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   299
void handleTeamAdd(void *context, const flib_team *team) {
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   300
	printf("%s puts the team %s to the planning board.\n", team->ownerName, team->name);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   301
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   302
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   303
void handleTeamDelete(void *context, const char *teamName) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   304
	printf("The team %s decided not to fight this battle after all.\n", teamName);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   305
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   306
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   307
void handleTeamColorChanged(void *context, const char *name, int colorIndex) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   308
	static const char* colorNames[] = {"red", "blue", "teal", "purple", "pink", "green", "orange", "brown", "yellow"};
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   309
	const char *colorName = "strange";
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   310
	if(colorIndex>=0 && colorIndex < 9) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   311
		colorName = colorNames[colorIndex];
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   312
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   313
	printf("The team %s will wear %s uniforms today.\n", name, colorName);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   314
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   315
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   316
void tick() {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   317
	if(gameconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   318
		flib_gameconn_tick(gameconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   319
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   320
	if(netconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   321
		flib_netconn_tick(netconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   322
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   323
	if(mapconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   324
		flib_mapconn_tick(mapconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   325
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   326
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   327
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   328
static HANDLE hStdin;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   329
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   330
static int init() {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   331
	hStdin = GetStdHandle(STD_INPUT_HANDLE);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   332
	if(hStdin == INVALID_HANDLE_VALUE) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   333
		flib_log_e("Unable to get stdin handle");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   334
		return 1;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   335
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   336
	if(!flib_init(0)) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   337
		flib_log_setLevel(FLIB_LOGLEVEL_WARNING);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   338
		freopen( "CON", "w", stdout );
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   339
		freopen( "CON", "w", stderr );
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   340
		metacfg = flib_metascheme_from_ini("metasettings.ini");
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   341
		if(!metacfg) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   342
			flib_quit();
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   343
			return -1;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   344
		} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   345
			return 0;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   346
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   347
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   348
	return -1;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   349
}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   350
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   351
int main(int argc, char *argv[]) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   352
	if(init()) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   353
		return -1;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   354
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   355
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   356
	puts("Please enter a nickname:");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   357
	flib_gets(nickname, sizeof(nickname));
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   358
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   359
	netconn = flib_netconn_create(nickname, metacfg, DATA_DIR"\\", "140.247.62.101", 46631);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   360
	if(!netconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   361
		flib_quit();
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   362
		return -1;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   363
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   364
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   365
	flib_netconn_onConnected(netconn, handleNetConnected, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   366
	flib_netconn_onDisconnected(netconn, handleNetDisconnect, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   367
	flib_netconn_onChat(netconn, handleChat, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   368
	flib_netconn_onEnterRoom(netconn, handleEnterRoom, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   369
	flib_netconn_onRunGame(netconn, handleRunGame, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   370
	flib_netconn_onEngineMessage(netconn, handleEmFromNet, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   371
	flib_netconn_onRoomJoin(netconn, handleRoomJoin, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   372
	flib_netconn_onRoomLeave(netconn, handleRoomLeave, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   373
	flib_netconn_onReadyState(netconn, handleReady, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   374
	flib_netconn_onNickTaken(netconn, handleNickTaken, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   375
	flib_netconn_onPasswordRequest(netconn, handlePwRequest, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   376
	flib_netconn_onMessage(netconn, handleMessage, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   377
	flib_netconn_onTeamAccepted(netconn, handleTeamAccepted, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   378
	flib_netconn_onMapChanged(netconn, handleMapChanged, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   379
	flib_netconn_onLeaveRoom(netconn, handleLeaveRoom, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   380
	flib_netconn_onCfgScheme(netconn, handleSchemeChanged, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   381
	flib_netconn_onWeaponsetChanged(netconn, handleWeaponsetChanged, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   382
	flib_netconn_onHogCountChanged(netconn, handleHogcountChanged, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   383
	flib_netconn_onRoomAdd(netconn, handleRoomAdd, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   384
	flib_netconn_onRoomDelete(netconn, handleRoomDelete, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   385
	flib_netconn_onScriptChanged(netconn, handleScriptChanged, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   386
	flib_netconn_onTeamAdd(netconn, handleTeamAdd, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   387
	flib_netconn_onTeamDelete(netconn, handleTeamDelete, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   388
	flib_netconn_onTeamColorChanged(netconn, handleTeamColorChanged, NULL);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   389
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   390
	INPUT_RECORD inputRecord;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   391
	DWORD eventCount = 0;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   392
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   393
	while(netconn || gameconn) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   394
		tick();
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   395
		if(netconn && netConnected) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   396
			while(PeekConsoleInput(hStdin, &inputRecord, 1, &eventCount) && eventCount>0) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   397
				if(inputRecord.EventType != KEY_EVENT) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   398
					ReadConsoleInput(hStdin, &inputRecord, 1, &eventCount);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   399
				} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   400
					printf("%s: ", nickname);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   401
					char input[256];
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   402
					if(!flib_gets(input, sizeof(input))) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   403
						if(!memcmp("/quit", input, strlen("/quit"))) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   404
							flib_netconn_send_quit(netconn, "Player quit.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   405
						} else if(!memcmp("/describe ", input, strlen("/describe "))) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   406
							const char *roomname = input+strlen("/describe ");
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   407
							/*const flib_roomlist *roomlist = flib_netconn_get_roomlist(netconn);
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   408
							flib_room *room = flib_roomlist_find(roomlist, roomname);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   409
							if(!room) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   410
								puts("Unknown room.");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   411
							} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   412
								char *text = flib_asprintf(
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   413
										"%s is a room created by %s, where %i players (%i teams) are %s on %s%s, using the %s scheme and %s weaponset.",
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   414
										room->name,
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   415
										room->owner,
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   416
										room->playerCount,
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   417
										room->teamCount,
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   418
										room->inProgress ? "fighting" : "preparing to fight",
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   419
										room->map[0]=='+' ? "" : "the map ",
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   420
										!strcmp("+rnd+", room->map) ? "a random map" :
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   421
												!strcmp("+maze+", room->map) ? "a random maze" :
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   422
												!strcmp("+drawn+", room->map) ? "a hand-drawn map" :
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   423
												room->map,
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   424
										room->scheme,
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   425
										room->weapons);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   426
								if(text) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   427
									puts(text);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   428
								}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   429
								free(text);
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   430
							}*/
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   431
						} else if(!memcmp("/join ", input, strlen("/join "))) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   432
							const char *roomname = input+strlen("/join ");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   433
							flib_netconn_send_joinRoom(netconn, roomname);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   434
						} else if(!memcmp("/ready", input, strlen("/ready"))) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   435
							flib_netconn_send_toggleReady(netconn);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   436
						} else if(!memcmp("/loglevel ", input, strlen("/loglevel "))) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   437
							int loglevel = atoi(input+strlen("/loglevel "));
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   438
							flib_log_setLevel(loglevel);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   439
						} else if(!memcmp("/list", input, strlen("/list"))) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   440
							if(flib_netconn_is_in_room_context(netconn)) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   441
								printTeamList();
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   442
							} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   443
								puts("From this big and expansive lobby, hallways branch off to these rooms:");
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   444
								//printRoomList();
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   445
							}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   446
						} else if(!memcmp("/addteam ", input, strlen("/addteam "))) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   447
							const char *teamname = input+strlen("/addteam ");
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   448
							if(!flib_contains_dir_separator(teamname)) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   449
								char *teamfilename = flib_asprintf("%s.hwt", teamname);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   450
								if(teamfilename) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   451
									flib_team *team = flib_team_from_ini(teamfilename);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   452
									if(team) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   453
										flib_netconn_send_addTeam(netconn, team);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   454
									} else {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   455
										printf("Teamfile %s not found.\n", teamfilename);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   456
									}
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   457
									flib_team_destroy(team);
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   458
								}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   459
								free(teamfilename);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   460
							}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   461
						} else if(strlen(input)>0) {
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   462
							flib_netconn_send_chat(netconn, input);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   463
						}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   464
					}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   465
				}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   466
			}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   467
		}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   468
		fflush(stdout);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   469
		Sleep(10);
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   470
	}
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   471
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   472
7473
45b9f25ff611 frontlib: Brought commandline client (almost) up to date with the frontlib changes
Medo <smaxein@googlemail.com>
parents: 7340
diff changeset
   473
	flib_metascheme_release(metacfg);
7340
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   474
	return 0;
62043f5f7c67 Re-Added the commandline client, but it's not compilable agains the latest frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   475
}