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