project_files/frontlib/test.c
author Medo <smaxein@googlemail.com>
Thu, 21 Jun 2012 21:32:12 +0200
changeset 7269 5b0aeef8ba2a
parent 7234 613998625a3c
child 7271 5608ac657362
permissions -rw-r--r--
More progress on the netplay part of the frontlib
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
#include "frontlib.h"
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
#include "util/logging.h"
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
     3
#include "util/buffer.h"
7269
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
     4
#include "util/util.h"
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
#include "model/map.h"
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
     6
#include "model/weapon.h"
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
     7
#include "model/schemelist.h"
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
#include "ipc/mapconn.h"
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
#include "ipc/gameconn.h"
7269
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
    10
#include "net/netconn.h"
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
#include <stdlib.h>
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
#include <stdbool.h>
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
#include <assert.h>
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
    15
#include <string.h>
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
// Callback function that will be called when the map is rendered
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
static void handleMapSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
	printf("Drawing map for %i brave little hogs...", numHedgehogs);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
	// Draw the map as ASCII art
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
	for(int y=0; y<MAPIMAGE_HEIGHT; y++) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
		for(int x=0; x<MAPIMAGE_WIDTH; x++) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
			int pixelnum = x + y*MAPIMAGE_WIDTH;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
			bool pixel = bitmap[pixelnum>>3] & (1<<(7-(pixelnum&7)));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
			printf(pixel ? "#" : " ");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
		}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
		printf("\n");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
	// Destroy the connection object (this will end the "tick" loop below)
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
	flib_mapconn **connptr = context;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
	flib_mapconn_destroy(*connptr);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
	*connptr = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
static void onDisconnect(void *context, int reason) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
	flib_log_i("Connection closed. Reason: %i", reason);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
	flib_gameconn **connptr = context;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
	flib_gameconn_destroy(*connptr);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
	*connptr = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
static void onGameRecorded(void *context, const uint8_t *record, int size, bool isSavegame) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
	flib_log_i("Writing %s (%i bytes)...", isSavegame ? "savegame" : "demo", size);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
	FILE *file = fopen(isSavegame ? "testsave.42.hws" : "testdemo.42.hwd", "wb");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
	fwrite(record, 1, size, file);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
	fclose(file);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
// Callback function that will be called on error
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
static void handleMapFailure(void *context, const char *errormessage) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
	flib_log_e("Map rendering failed: %s", errormessage);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
	// Destroy the connection object (this will end the "tick" loop below)
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
	flib_mapconn **connptr = context;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
	flib_mapconn_destroy(*connptr);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
	*connptr = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
static void startEngineMap(int port) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
	char commandbuffer[255];
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
	const char *enginePath = "C:\\Programmieren\\Hedgewars\\bin";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
	const char *configPath = "C:\\Programmieren\\Hedgewars\\share\\hedgewars";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
	snprintf(commandbuffer, 255, "start %s\\hwengine.exe %s %i landpreview", enginePath, configPath, port);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
	system(commandbuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    69
static void startEngineGame(int port) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
	char commandbuffer[255];
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    71
	const char *enginePath = "C:\\Programmieren\\Hedgewars\\bin";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
	const char *configPath = "C:\\Programmieren\\Hedgewars\\share\\hedgewars";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
	const char *dataPath = "C:\\Programmieren\\Hedgewars\\share\\hedgewars\\Data";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
	snprintf(commandbuffer, 255, "start %s\\hwengine.exe %s 1024 768 32 %i 0 0 0 10 10 %s 0 0 TWVkbzQy 0 0 en.txt", enginePath, configPath, port, dataPath);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    75
	flib_log_d("Starting engine with CMD: %s", commandbuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
	system(commandbuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    77
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    78
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
void testMapPreview() {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
	// Create a map description and check that there was no error
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    81
	flib_map *map = flib_map_create_maze("Jungle", MAZE_SIZE_SMALL_TUNNELS);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
	assert(map);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    83
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
	// Create a new connection to the engine and check that there was no error
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    85
	flib_mapconn *mapConnection = flib_mapconn_create("This is the seed value", map);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
	assert(mapConnection);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
	// We don't need the map description anymore
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
    89
	flib_map_release(map);
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    90
	map = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    91
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
	// Register the callback functions
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    93
	flib_mapconn_onFailure(mapConnection, &handleMapFailure, &mapConnection);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    94
	flib_mapconn_onSuccess(mapConnection, &handleMapSuccess, &mapConnection);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    95
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    96
	// Start the engine process and tell it which port the frontlib is listening on
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    97
	startEngineMap(flib_mapconn_getport(mapConnection));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    98
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    99
	// Usually, flib_mapconn_tick will be called in an event loop that runs several
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   100
	// times per second. It handles I/O operations and progress, and calls
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   101
	// callbacks when something interesting happens.
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   102
	while(mapConnection) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   103
		flib_mapconn_tick(mapConnection);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   104
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   106
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
void testGame() {
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   108
	flib_cfg_meta *metaconf = flib_cfg_meta_from_ini("metasettings.ini");
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   109
	assert(metaconf);
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   110
	flib_weaponset *weapons = flib_weaponset_create("Defaultweaps");
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   111
	flib_schemelist *schemelist = flib_schemelist_from_ini(metaconf, "schemes.ini");
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   112
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   113
	flib_gamesetup setup;
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   114
	setup.gamescheme = flib_schemelist_find(schemelist, "Default");
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   115
	setup.map = flib_map_create_maze("Jungle", MAZE_SIZE_MEDIUM_TUNNELS);
7227
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   116
	setup.seed = "asparagus";
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   117
	setup.script = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   118
	setup.teamcount = 2;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   119
	setup.teams = calloc(2, sizeof(flib_team*));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   120
	setup.teams[0] = calloc(1, sizeof(flib_team));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   121
	setup.teams[0]->color = 0xffff0000;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   122
	setup.teams[0]->flag = "australia";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   123
	setup.teams[0]->fort = "Plane";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   124
	setup.teams[0]->grave = "Bone";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   125
	setup.teams[0]->hogsInGame = 2;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   126
	setup.teams[0]->name = "Team Awesome";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   127
	setup.teams[0]->voicepack = "British";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   128
	setup.teams[0]->hogs[0].difficulty = 2;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   129
	setup.teams[0]->hogs[0].hat = "NoHat";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   130
	setup.teams[0]->hogs[0].initialHealth = 100;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   131
	setup.teams[0]->hogs[0].name = "Harry 120";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   132
	setup.teams[0]->hogs[1].difficulty = 2;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   133
	setup.teams[0]->hogs[1].hat = "chef";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   134
	setup.teams[0]->hogs[1].initialHealth = 100;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   135
	setup.teams[0]->hogs[1].name = "Chefkoch";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   136
	setup.teams[1] = flib_team_from_ini("Cave Dwellers.hwt");
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   137
	setup.teams[1]->color = 0xFF0000F0;
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   138
	setup.teams[1]->hogsInGame = 8;
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   139
	flib_team_set_weaponset(setup.teams[0], weapons);
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   140
	flib_team_set_weaponset(setup.teams[1], weapons);
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   141
	flib_weaponset_release(weapons);
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   142
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   143
	flib_gameconn *gameconn = flib_gameconn_create("Medo42", &setup, false);
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   144
	assert(gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   145
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   146
	flib_gameconn_onDisconnect(gameconn, &onDisconnect, &gameconn);
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   147
	//flib_gameconn_onGameRecorded(gameconn, &onGameRecorded, &gameconn);
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   148
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   149
	startEngineGame(flib_gameconn_getport(gameconn));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   150
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   151
	while(gameconn) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   152
		flib_gameconn_tick(gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   153
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   154
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   155
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   156
void testDemo() {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   157
	FILE *demofile = fopen("testdemo.42.hwd", "rb");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   158
	assert(demofile);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   159
	flib_vector *vec = flib_vector_create();
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   160
	uint8_t demobuf[512];
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   161
	int len;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   162
	while((len=fread(demobuf, 1, 512, demofile))>0) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   163
		flib_vector_append(vec, demobuf, len);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   164
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   165
	fclose(demofile);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   166
	flib_constbuffer constbuf = flib_vector_as_constbuffer(vec);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   167
	flib_gameconn *gameconn = flib_gameconn_create_playdemo(constbuf.data, constbuf.size);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   168
	flib_vector_destroy(vec);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   169
	assert(gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   170
	flib_gameconn_onDisconnect(gameconn, &onDisconnect, &gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   171
	flib_gameconn_onGameRecorded(gameconn, &onGameRecorded, &gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   172
	startEngineGame(flib_gameconn_getport(gameconn));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   173
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   174
	while(gameconn) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   175
		flib_gameconn_tick(gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   176
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   177
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   178
7227
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   179
void testSave() {
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   180
	FILE *demofile = fopen("testsave.42.hws", "rb");
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   181
	assert(demofile);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   182
	flib_vector *vec = flib_vector_create();
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   183
	uint8_t demobuf[512];
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   184
	int len;
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   185
	while((len=fread(demobuf, 1, 512, demofile))>0) {
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   186
		flib_vector_append(vec, demobuf, len);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   187
	}
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   188
	fclose(demofile);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   189
	flib_constbuffer constbuf = flib_vector_as_constbuffer(vec);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   190
	flib_gameconn *gameconn = flib_gameconn_create_loadgame("Medo42", constbuf.data, constbuf.size);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   191
	flib_vector_destroy(vec);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   192
	assert(gameconn);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   193
	flib_gameconn_onDisconnect(gameconn, &onDisconnect, &gameconn);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   194
	flib_gameconn_onGameRecorded(gameconn, &onGameRecorded, &gameconn);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   195
	startEngineGame(flib_gameconn_getport(gameconn));
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   196
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   197
	while(gameconn) {
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   198
		flib_gameconn_tick(gameconn);
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   199
	}
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   200
}
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   201
7269
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   202
void handleNetDisconnect(void *context, int reason, const char *message) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   203
	flib_log_i("Disconnected: %s", message);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   204
	flib_netconn_destroy(*(flib_netconn**)context);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   205
	*(flib_netconn**)context = NULL;
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   206
}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   207
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   208
void handleNetConnected(void *context) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   209
	const flib_roomlist *roomlist = flib_netconn_get_roomlist(*(flib_netconn**)context);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   210
	flib_log_i("List of rooms:");
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   211
	for(int i=0; i<roomlist->roomCount; i++) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   212
		flib_roomlist_room *room = roomlist->rooms[i];
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   213
		flib_log_i("%1s %20s %20s %2i %2i %20s %20s %20s", room->inProgress ? "X" : " ", room->name, room->owner, room->playerCount, room->teamCount, room->map, room->scheme, room->weapons);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   214
	}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   215
}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   216
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   217
void handleLobbyJoin(void *context, const char *nick) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   218
	flib_log_i("%s joined", nick);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   219
}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   220
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   221
void handleChat(void *context, const char *nick, const char *msg) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   222
	flib_log_i("%s: %s", nick, msg);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   223
	if(!memcmp("frontbot ", msg, strlen("frontbot "))) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   224
		const char *command = msg+strlen("frontbot ");
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   225
		if(!memcmp("quit", command, strlen("quit"))) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   226
			flib_netconn_send_quit(*(flib_netconn**)context, "Yeth Mathter");
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   227
		} else if(!memcmp("describe ", command, strlen("describe "))) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   228
			const char *roomname = command+strlen("describe ");
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   229
			const flib_roomlist *roomlist = flib_netconn_get_roomlist(*(flib_netconn**)context);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   230
			flib_roomlist_room *room = flib_roomlist_find((flib_roomlist*)roomlist, roomname);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   231
			if(!room) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   232
				flib_netconn_send_chat(*(flib_netconn**)context, "Unknown room.");
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   233
			} else {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   234
				char *text = flib_asprintf(
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   235
						"%s is a room created by %s, where %i players (%i teams) are %s on %s%s, using the %s scheme and %s weaponset.",
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   236
						room->name,
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   237
						room->owner,
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   238
						room->playerCount,
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   239
						room->teamCount,
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   240
						room->inProgress ? "fighting" : "preparing to fight",
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   241
						room->map[0]=='+' ? "" : "the map ",
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   242
						!strcmp("+rnd+", room->map) ? "a random map" :
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   243
								!strcmp("+maze+", room->map) ? "a random maze" :
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   244
								!strcmp("+drawn+", room->map) ? "a hand-drawn map" :
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   245
								room->map,
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   246
						room->scheme,
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   247
						room->weapons);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   248
				if(text) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   249
					flib_netconn_send_chat(*(flib_netconn**)context, text);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   250
				}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   251
				free(text);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   252
			}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   253
		}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   254
	}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   255
}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   256
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   257
void handleAskPass(void *context, const char *nick) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   258
	flib_netconn_send_password((flib_netconn*)context, "Lorem");
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   259
}
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   260
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   261
int main(int argc, char *argv[]) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   262
	flib_init(0);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   263
	flib_log_setLevel(FLIB_LOGLEVEL_ALL);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   264
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   265
	//testMapPreview();
7227
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   266
	//testDemo();
1c859f572d72 frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents: 7224
diff changeset
   267
	//testSave();
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   268
	//testGame();
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   269
7269
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   270
	flib_cfg_meta *meta = flib_cfg_meta_from_ini("metasettings.ini");
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   271
	assert(meta);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   272
	flib_netconn *conn = flib_netconn_create("Medo42", meta, "140.247.62.101", 46631);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   273
	assert(conn);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   274
	flib_cfg_meta_release(meta);
7230
240620f46dd7 Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents: 7227
diff changeset
   275
7269
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   276
	flib_netconn_onConnected(conn, handleNetConnected, &conn);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   277
	flib_netconn_onDisconnected(conn, handleNetDisconnect, &conn);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   278
	flib_netconn_onLobbyJoin(conn, handleLobbyJoin, &conn);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   279
	flib_netconn_onChat(conn, handleChat, &conn);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   280
	flib_netconn_onPasswordRequest(conn, handleAskPass, conn);
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   281
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   282
	while(conn) {
5b0aeef8ba2a More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
   283
		flib_netconn_tick(conn);
7234
613998625a3c frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents: 7230
diff changeset
   284
	}
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   285
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   286
	flib_quit();
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   287
	return 0;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   288
}