project_files/frontlib/ipc/gameconn.h
author koda
Mon, 18 Mar 2013 20:10:27 +0100
branchcmake_pascal
changeset 8761 801cf78707f2
parent 7576 65d29988fd3d
child 10017 de822cd3df3a
permissions -rw-r--r--
partial reodering of units so that dependency tracking is done with cmake
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7314
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
     1
/*
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
     4
 *
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
     5
 * This program is free software; you can redistribute it and/or
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
     6
 * modify it under the terms of the GNU General Public License
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
     8
 * of the License, or (at your option) any later version.
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
     9
 *
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    13
 * GNU General Public License for more details.
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    14
 *
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    15
 * You should have received a copy of the GNU General Public License
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    16
 * along with this program; if not, write to the Free Software
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    18
 */
6171f0bad318 frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents: 7275
diff changeset
    19
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    20
/**
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    21
 * This file contains functions for starting and interacting with a game run by the engine.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    22
 * The general usage is to first create a gameconn object by calling one of the flib_gameconn_create
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    23
 * functions. That will cause the frontlib to listen on a random port which can be queried using
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    24
 * flib_gameconn_getport(). You should also register your callback functions right at the start
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    25
 * to ensure you don't miss any callbacks.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    26
 *
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    27
 * Next, start the engine (that part is up to you) with the appropriate command line arguments
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    28
 * for starting a game.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    29
 *
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    30
 * In order to allow the gameconn to run, you should regularly call flib_gameconn_tick(), which
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    31
 * performs network I/O and calls your callbacks on interesting events.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    32
 *
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    33
 * Once the engine connects, the gameconn will send it the required commands for starting the
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    34
 * game you requested in your flib_gameconn_create call.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    35
 *
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    36
 * When the game is finished (or the connection is lost), you will receive the onDisconnect
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    37
 * message. This is the signal to destroy the gameconn and stop calling tick().
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    38
 */
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    39
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
#ifndef GAMECONN_H_
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
#define GAMECONN_H_
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
#include "../model/gamesetup.h"
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
#include <stddef.h>
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
#include <stdint.h>
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
#include <stdbool.h>
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    49
/*
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    50
 * Different reasons for a disconnect. Only GAME_END_FINISHED signals a correctly completed game.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    51
 */
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
#define GAME_END_FINISHED 0
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
#define GAME_END_INTERRUPTED 1
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
#define GAME_END_HALTED 2
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
#define GAME_END_ERROR 3
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
typedef struct _flib_gameconn flib_gameconn;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    59
/**
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    60
 * Create a gameconn that will start a local or network game with the indicated configuration.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    61
 */
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
    62
flib_gameconn *flib_gameconn_create(const char *playerName, const flib_gamesetup *setup, bool netgame);
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    63
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    64
/**
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    65
 * Create a gameconn that will play back a demo.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    66
 */
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    67
flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demoFileContent, size_t size);
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    68
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    69
/**
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    70
 * Create a gameconn that will continue from a saved game.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    71
 */
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    72
flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *saveFileContent, size_t size);
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    73
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    74
/**
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    75
 * Create a gameconn that will start a campaign or training mission with the indicated script.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    76
 * seed is the random seed to use as entropy source (any string).
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    77
 * script is the path and filename of a Campaign or Training script, relative to the Data directory
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    78
 * (e.g. "Missions/Training/Basic_Training_-_Bazooka.lua")
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    79
 */
7271
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
    80
flib_gameconn *flib_gameconn_create_campaign(const char *playerName, const char *seed, const char *script);
5608ac657362 frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents: 7234
diff changeset
    81
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    82
/**
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    83
 * Release all resources of this gameconn, including the network connection, and free its memory.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    84
 * It is safe to call this function from a callback.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
    85
 */
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
void flib_gameconn_destroy(flib_gameconn *conn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
/**
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    89
 * Returns the port on which the gameconn is listening. Only fails if you
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    90
 * pass NULL (not allowed), in that case 0 is returned.
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    91
 */
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
int flib_gameconn_getport(flib_gameconn *conn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    93
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    94
/**
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    95
 * Perform I/O operations and call callbacks if something interesting happens.
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    96
 * Should be called regularly.
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    97
 */
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    98
void flib_gameconn_tick(flib_gameconn *conn);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    99
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   100
/**
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   101
 * Send an engine message to the engine. Only needed in net games, where you receive engine
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   102
 * messages from the server and have to pass them here.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   103
 */
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   104
int flib_gameconn_send_enginemsg(flib_gameconn *conn, const uint8_t *data, size_t len);
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   105
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   106
/**
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   107
 * Send an info message to the engine that will be displayed in the game's chatlog.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   108
 * The msgtype determines the color of the message;  in the QTFrontend, info messages and
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   109
 * normal chat messages use 1, emote-messages (those starting with /me) use 2, and
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   110
 * join/leave messages use 3. You should use flib_gameconn_send_chatmsg for chat messages
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   111
 * though because it automatically formats /me messages.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   112
 *
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   113
 * Generally only needed in net games.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   114
 */
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   115
int flib_gameconn_send_textmsg(flib_gameconn *conn, int msgtype, const char *msg);
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   116
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   117
/**
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   118
 * Send a chat message to be displayed in the game's chatlog. Messages starting with /me are
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   119
 * automatically formatted correctly.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   120
 *
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   121
 * Generally only needed in net games.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   122
 */
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents: 7179
diff changeset
   123
int flib_gameconn_send_chatmsg(flib_gameconn *conn, const char *playername, const char *msg);
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   124
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   125
/**
7576
65d29988fd3d Fix engine crashes on game end
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   126
 * Request the engine to stop the game (efinish).
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   127
 * You can use this to shut down a game early without directly killing the engine process.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   128
 */
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   129
int flib_gameconn_send_quit(flib_gameconn *conn);
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   130
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   131
/**
7576
65d29988fd3d Fix engine crashes on game end
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   132
 * Send an arbitrary command to the engine, e.g. "eforcequit" to shut down the engine
65d29988fd3d Fix engine crashes on game end
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   133
 * quickly. Commands prefixed with "e" will be processed by the engine's ProcessCommand
65d29988fd3d Fix engine crashes on game end
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   134
 * method (with the e removed, so e.g. efinish will be parsed as finish).
65d29988fd3d Fix engine crashes on game end
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   135
 */
65d29988fd3d Fix engine crashes on game end
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   136
int flib_gameconn_send_cmd(flib_gameconn *conn, const char *cmdString);
65d29988fd3d Fix engine crashes on game end
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   137
65d29988fd3d Fix engine crashes on game end
Medo <smaxein@googlemail.com>
parents: 7482
diff changeset
   138
/**
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   139
 * Expected callback signature: void handleConnect(void *context)
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   140
 * The engine has successfully connected. You don't have to react to this in any way.
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   141
 */
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   142
void flib_gameconn_onConnect(flib_gameconn *conn, void (*callback)(void* context), void* context);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   143
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   144
/**
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   145
 * Expected callback signature: void handleDisconnect(void *context, int reason)
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   146
 * The connection to the engine was closed, either because the game has ended normally, or
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   147
 * because it was interrupted/halted, or because of an error. The reason is provided as one
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   148
 * of the GAME_END_xxx constants.
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   149
 *
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   150
 * You should destroy the gameconn and - in a netgame - notify the server that the game has ended.
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   151
 */
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   152
void flib_gameconn_onDisconnect(flib_gameconn *conn, void (*callback)(void* context, int reason), void* context);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   153
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   154
/**
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   155
 * Expected callback signature: void handleErrorMessage(void* context, const char *msg)
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   156
 * The engine sent an error message, you should probably display it to the user or at least log it.
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   157
 */
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   158
void flib_gameconn_onErrorMessage(flib_gameconn *conn, void (*callback)(void* context, const char *msg), void* context);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   159
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   160
/**
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   161
 * Expected callback signature: void handleChat(void* context, const char *msg, bool teamchat)
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   162
 * The player entered a chat or teamchat message. In a netgame, you should send it on to the server.
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   163
 */
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   164
void flib_gameconn_onChat(flib_gameconn *conn, void (*callback)(void* context, const char *msg, bool teamchat), void* context);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   165
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   166
/**
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   167
 * Expected callback signature: void handleGameRecorded(void *context, const uint8_t *record, size_t size, bool isSavegame)
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   168
 * The game has stopped, and a demo or savegame is available. You can store it in a file and later pass it back
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   169
 * to the engine to either watch a replay (if it's a demo) or to continue playing (if it's a savegame).
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   170
 */
7320
e704706008d4 frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents: 7316
diff changeset
   171
void flib_gameconn_onGameRecorded(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *record, size_t size, bool isSavegame), void* context);
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   172
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   173
/**
7482
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   174
 * Expected callback signature: void handleEngineMessage(void *context, const uint8_t *em, size_t size)
d70a5b0d1190 frontlib improvements:
Medo <smaxein@googlemail.com>
parents: 7320
diff changeset
   175
 * The engine has generated a message with player input. In a netgame, you should send it on to the server.
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   176
 */
7275
15f722e0b96f frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents: 7271
diff changeset
   177
void flib_gameconn_onEngineMessage(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *em, size_t size), void* context);
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   178
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff changeset
   179
#endif