QTfrontend/util/platform/xfire.cpp
changeset 8381 588a8e6e2041
parent 6952 7f70f37bbf08
child 9080 9b42757d7e71
equal deleted inserted replaced
8380:0b375a3ceaa0 8381:588a8e6e2041
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.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 <cstring>
       
    21 #include <stdio.h>
       
    22 
       
    23 #include "xfire.h"
       
    24 #include "xfiregameclient.h"
       
    25 
       
    26 #ifdef USE_XFIRE
       
    27 // use_xfire: stores if xfire is loaded and functions should do something at all
       
    28 bool use_xfire = false;
       
    29 char *keys[XFIRE_KEY_COUNT];
       
    30 char *values[XFIRE_KEY_COUNT];
       
    31 
       
    32 // xfire_init(): used to initialize all variables and set their default values
       
    33 void xfire_init(void)
       
    34 {
       
    35     if(use_xfire)
       
    36         return;
       
    37     use_xfire = XfireIsLoaded() == 1;
       
    38 
       
    39     if(!use_xfire)
       
    40         return;
       
    41 
       
    42     for(int i = 0; i < XFIRE_KEY_COUNT; i++)
       
    43     {
       
    44         keys[i] = new char[256];
       
    45         values[i] = new char[256];
       
    46         strcpy(keys[i], "");
       
    47         strcpy(values[i], "");
       
    48     }
       
    49 
       
    50     strcpy(keys[XFIRE_NICKNAME], "Nickname");
       
    51     strcpy(keys[XFIRE_ROOM], "Room");
       
    52     strcpy(keys[XFIRE_SERVER], "Server");
       
    53     strcpy(keys[XFIRE_STATUS], "Status");
       
    54     xfire_update();
       
    55 }
       
    56 
       
    57 // xfire_free(): used to free up ressources used etc.
       
    58 void xfire_free(void)
       
    59 {
       
    60     if(!use_xfire)
       
    61         return;
       
    62 
       
    63     for(int i = 0; i < XFIRE_KEY_COUNT; i++)
       
    64     {
       
    65         delete [] keys[i];
       
    66         delete [] values[i];
       
    67     }
       
    68 }
       
    69 
       
    70 // xfire_setvalue(): set a specific value
       
    71 void xfire_setvalue(const XFIRE_KEYS status, const char *value)
       
    72 {
       
    73     if(!use_xfire || strlen(value) > 255)
       
    74         return;
       
    75     strcpy(values[status], value);
       
    76 }
       
    77 
       
    78 // xfire_update(): submits current values to the xfire app
       
    79 void xfire_update(void)
       
    80 {
       
    81     if(!use_xfire)
       
    82         return;
       
    83     XfireSetCustomGameDataA(XFIRE_KEY_COUNT, (const char**)keys, (const char**)values);
       
    84 }
       
    85 #endif // USE_XFIRE