QTfrontend/xfire.cpp
author smxx
Mon, 01 Mar 2010 22:25:57 +0000
changeset 2908 bd1909984a09
parent 2830 571a9deffeac
child 2948 3f21a9dc93d0
permissions -rw-r--r--
Engine: * Added damage modifier to game mode/rule display * Added low gravity activation sound
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2821
67815ee123d7 Frontend:
smxx
parents:
diff changeset
     1
/*
67815ee123d7 Frontend:
smxx
parents:
diff changeset
     2
 * Hedgewars Xfire integration
67815ee123d7 Frontend:
smxx
parents:
diff changeset
     3
 * Copyright (c) 2010 Mario Liebisch <mario.liebisch AT googlemail.com>
67815ee123d7 Frontend:
smxx
parents:
diff changeset
     4
 *
67815ee123d7 Frontend:
smxx
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
67815ee123d7 Frontend:
smxx
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
67815ee123d7 Frontend:
smxx
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
67815ee123d7 Frontend:
smxx
parents:
diff changeset
     8
 *
67815ee123d7 Frontend:
smxx
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    12
 * GNU General Public License for more details.
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    13
 *
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    17
 */
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    18
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    19
#include <string>
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    20
#include <stdio.h>
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    21
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    22
#include "xfire.h"
2830
571a9deffeac Frontend:
smxx
parents: 2821
diff changeset
    23
#include "../misc/xfire/xfiregameclient.h"
2821
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    24
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    25
// use_xfire: stores if xfire is loaded and functions should do something at all
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    26
bool use_xfire = false;
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    27
char *keys[XFIRE_KEY_COUNT];
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    28
char *values[XFIRE_KEY_COUNT];
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    29
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    30
// xfire_init(): used to initialize all variables and set their default values
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    31
void xfire_init(void)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    32
{
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    33
	if(use_xfire)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    34
		return;
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    35
	use_xfire = XfireIsLoaded() == 1;
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    36
	
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    37
	if(!use_xfire)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    38
		return;
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    39
	
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    40
	for(int i = 0; i < XFIRE_KEY_COUNT; i++)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    41
	{
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    42
		keys[i] = new char[256];
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    43
		values[i] = new char[256];
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    44
		strcpy(keys[i], "");
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    45
		strcpy(values[i], "");
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    46
	}
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    47
	
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    48
	strcpy(keys[XFIRE_NICKNAME], "Nickname");
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    49
	strcpy(keys[XFIRE_ROOM], "Room");
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    50
	strcpy(keys[XFIRE_SERVER], "Server");
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    51
	strcpy(keys[XFIRE_STATUS], "Status");
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    52
	xfire_update();
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    53
}
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    54
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    55
// xfire_free(): used to free up ressources used etc.
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    56
void xfire_free(void)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    57
{
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    58
	if(!use_xfire)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    59
		return;
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    60
	
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    61
	for(int i = 0; i < XFIRE_KEY_COUNT; i++)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    62
	{
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    63
		delete [] keys[i];
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    64
		delete [] values[i];
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    65
	}
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    66
}
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    67
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    68
// xfire_setvalue(): set a specific value
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    69
void xfire_setvalue(const XFIRE_KEYS status, const char *value)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    70
{
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    71
	if(!use_xfire || strlen(value) > 255)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    72
		return;
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    73
	strcpy(values[status], value);
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    74
}
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    75
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    76
// xfire_update(): submits current values to the xfire app
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    77
void xfire_update(void)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    78
{
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    79
	if(!use_xfire)
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    80
		return;
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    81
	XfireSetCustomGameDataA(XFIRE_KEY_COUNT, (const char**)keys, (const char**)values);
67815ee123d7 Frontend:
smxx
parents:
diff changeset
    82
}