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