2005-10-20 17:45:00 +02:00
|
|
|
/*
|
2005-11-26 17:52:51 +01:00
|
|
|
xml_loadsave_users.c
|
|
|
|
|
2005-10-20 17:45:00 +02:00
|
|
|
Bygfoot Football Manager -- a small and simple GTK2-based
|
|
|
|
football management game.
|
|
|
|
|
|
|
|
http://bygfoot.sourceforge.net
|
|
|
|
|
|
|
|
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2005-10-27 23:10:15 +02:00
|
|
|
#include "bet_struct.h"
|
2005-04-06 00:14:39 +02:00
|
|
|
#include "file.h"
|
2005-10-27 23:10:15 +02:00
|
|
|
#include "fixture.h"
|
2005-04-06 00:14:39 +02:00
|
|
|
#include "misc.h"
|
|
|
|
#include "team.h"
|
|
|
|
#include "user.h"
|
|
|
|
#include "variables.h"
|
|
|
|
#include "xml.h"
|
|
|
|
#include "xml_loadsave_live_game.h"
|
2005-07-08 19:34:10 +02:00
|
|
|
#include "xml_loadsave_players.h"
|
2005-04-06 00:14:39 +02:00
|
|
|
#include "xml_loadsave_users.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TAG_USERS = TAG_START_USERS,
|
|
|
|
TAG_USER,
|
|
|
|
TAG_USER_COUNTER,
|
|
|
|
TAG_USER_MONEY,
|
|
|
|
TAG_USER_DEBT,
|
2008-11-06 09:03:09 +01:00
|
|
|
TAG_USER_DEBT_INTEREST,
|
2008-11-07 09:38:55 +01:00
|
|
|
TAG_USER_ALR_START_WEEK,
|
|
|
|
TAG_USER_ALR_WEEKLY_INSTALLMENT,
|
2005-04-06 00:14:39 +02:00
|
|
|
TAG_USER_MONEY_INS,
|
|
|
|
TAG_USER_MONEY_IN,
|
|
|
|
TAG_USER_MONEY_OUTS,
|
|
|
|
TAG_USER_MONEY_OUT,
|
|
|
|
TAG_USER_SCOUT,
|
|
|
|
TAG_USER_PHYSIO,
|
2005-04-16 09:46:04 +02:00
|
|
|
TAG_USER_HISTORY,
|
|
|
|
TAG_USER_HISTORY_SEASON,
|
|
|
|
TAG_USER_HISTORY_WEEK,
|
|
|
|
TAG_USER_HISTORY_TYPE,
|
2005-12-01 12:50:54 +01:00
|
|
|
TAG_USER_HISTORY_TEAM_NAME,
|
|
|
|
TAG_USER_HISTORY_STRING,
|
2005-05-30 17:54:20 +02:00
|
|
|
TAG_USER_EVENT,
|
|
|
|
TAG_USER_EVENT_TYPE,
|
|
|
|
TAG_USER_EVENT_VALUE1,
|
|
|
|
TAG_USER_EVENT_VALUE2,
|
|
|
|
TAG_USER_EVENT_VALUE_STRING,
|
2005-06-20 14:46:57 +02:00
|
|
|
TAG_USER_SPONSOR_NAME,
|
|
|
|
TAG_USER_SPONSOR_CONTRACT,
|
|
|
|
TAG_USER_SPONSOR_BENEFIT,
|
2005-07-08 19:34:10 +02:00
|
|
|
TAG_USER_YA_COACH,
|
|
|
|
TAG_USER_YA_PERCENTAGE,
|
|
|
|
TAG_USER_YA_AV_COACH,
|
|
|
|
TAG_USER_YA_AV_PERCENTAGE,
|
|
|
|
TAG_USER_YA_COUNTER,
|
2005-10-27 23:10:15 +02:00
|
|
|
TAG_USER_BET0,
|
|
|
|
TAG_USER_BET1,
|
|
|
|
TAG_USER_BET_WAGER,
|
|
|
|
TAG_USER_BET_OUTCOME,
|
|
|
|
TAG_USER_BET_FIX_ID,
|
2008-10-24 11:25:27 +02:00
|
|
|
TAG_USER_YA_PREFERENCE,
|
2009-08-31 14:31:24 +02:00
|
|
|
TAG_USER_DEFAULT_TEAM,
|
|
|
|
TAG_USER_DEFAULT_STRUCTURE,
|
2012-02-02 16:40:22 +01:00
|
|
|
TAG_USER_DEFAULT_STYLE,
|
|
|
|
TAG_USER_DEFAULT_BOOST,
|
2005-04-06 00:14:39 +02:00
|
|
|
TAG_END
|
|
|
|
};
|
|
|
|
|
2005-12-13 14:01:52 +01:00
|
|
|
gint state, idx_mon_in, idx_mon_out, idx,
|
2009-08-31 14:31:24 +02:00
|
|
|
idx_bet, idx_cnt, new_default_team_player, new_default_structure;
|
2005-04-06 00:14:39 +02:00
|
|
|
User new_user;
|
2005-04-16 09:46:04 +02:00
|
|
|
UserHistory new_history;
|
2005-05-30 17:54:20 +02:00
|
|
|
Event new_event;
|
2005-10-27 23:10:15 +02:00
|
|
|
BetUser new_bet;
|
2005-04-06 00:14:39 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
xml_loadsave_users_start_element (GMarkupParseContext *context,
|
|
|
|
const gchar *element_name,
|
|
|
|
const gchar **attribute_names,
|
|
|
|
const gchar **attribute_values,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_loadsave_users_start_element\n");
|
|
|
|
#endif
|
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
gint i;
|
|
|
|
gint tag = xml_get_tag_from_name(element_name);
|
|
|
|
gboolean valid_tag = FALSE;
|
|
|
|
|
|
|
|
for(i=TAG_USERS;i<TAG_END;i++)
|
|
|
|
if(tag == i)
|
|
|
|
{
|
|
|
|
state = i;
|
|
|
|
valid_tag = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=TAG_NAME;i<=TAG_ROUND;i++)
|
|
|
|
if(tag == i)
|
|
|
|
{
|
|
|
|
state = i;
|
|
|
|
valid_tag = TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-08 19:34:10 +02:00
|
|
|
if(tag == TAG_USER)
|
2005-04-06 00:14:39 +02:00
|
|
|
{
|
|
|
|
new_user = user_new();
|
2005-12-13 14:01:52 +01:00
|
|
|
idx = idx_mon_out = idx_mon_in = idx_cnt = 0;
|
2005-04-06 00:14:39 +02:00
|
|
|
}
|
2005-12-01 12:50:54 +01:00
|
|
|
else if(tag >= TAG_START_PLAYERS && tag <= TAG_END_PLAYERS)
|
2005-07-08 19:34:10 +02:00
|
|
|
{
|
|
|
|
state = TAG_START_PLAYERS;
|
|
|
|
valid_tag = TRUE;
|
|
|
|
|
|
|
|
if(tag == TAG_START_PLAYERS)
|
2005-12-13 14:01:52 +01:00
|
|
|
new_user.youth_academy.players =
|
|
|
|
g_array_new(FALSE, FALSE, sizeof(Player));
|
2005-07-08 19:34:10 +02:00
|
|
|
|
|
|
|
xml_loadsave_players_start_element(tag, new_user.tm);
|
|
|
|
}
|
2005-12-01 12:50:54 +01:00
|
|
|
else if(tag == TAG_USER_HISTORY)
|
|
|
|
{
|
2005-04-06 00:14:39 +02:00
|
|
|
idx = 0;
|
2005-12-01 12:50:54 +01:00
|
|
|
new_history.team_name =
|
|
|
|
new_history.string[0] =
|
|
|
|
new_history.string[1] =
|
|
|
|
new_history.string[2] = NULL;
|
|
|
|
}
|
2005-10-09 11:35:44 +02:00
|
|
|
else if(tag == TAG_USER_EVENT)
|
|
|
|
new_event.value_string = NULL;
|
2005-12-01 12:50:54 +01:00
|
|
|
else if(tag == TAG_USER_MONEY_OUTS ||
|
|
|
|
tag == TAG_USER_MONEY_INS)
|
|
|
|
idx = 0;
|
|
|
|
else if(tag == TAG_USER_BET0 ||
|
|
|
|
tag == TAG_USER_BET1)
|
|
|
|
idx_bet = (tag == TAG_USER_BET1);
|
2005-10-09 11:35:44 +02:00
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
if(!valid_tag)
|
2009-04-29 19:18:54 +02:00
|
|
|
debug_print_message("xml_loadsave_users_start_element: unknown tag: %s; I'm in state %d\n",
|
2005-04-06 00:14:39 +02:00
|
|
|
element_name, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xml_loadsave_users_end_element (GMarkupParseContext *context,
|
2005-07-08 19:34:10 +02:00
|
|
|
const gchar *element_name,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2005-04-06 00:14:39 +02:00
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_loadsave_users_end_element\n");
|
|
|
|
#endif
|
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
gint tag = xml_get_tag_from_name(element_name);
|
2005-12-13 14:01:52 +01:00
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
if(tag == TAG_USER)
|
|
|
|
{
|
|
|
|
state = TAG_USERS;
|
|
|
|
g_array_append_val(users, new_user);
|
|
|
|
}
|
|
|
|
else if(tag == TAG_USER_COUNTER ||
|
|
|
|
tag == TAG_USER_MONEY ||
|
|
|
|
tag == TAG_USER_DEBT ||
|
2008-11-06 09:03:09 +01:00
|
|
|
tag == TAG_USER_DEBT_INTEREST ||
|
2008-11-07 09:38:55 +01:00
|
|
|
tag == TAG_USER_ALR_START_WEEK ||
|
|
|
|
tag == TAG_USER_ALR_WEEKLY_INSTALLMENT ||
|
2005-04-06 00:14:39 +02:00
|
|
|
tag == TAG_USER_MONEY_INS ||
|
|
|
|
tag == TAG_USER_MONEY_OUTS ||
|
|
|
|
tag == TAG_USER_SCOUT ||
|
|
|
|
tag == TAG_USER_PHYSIO ||
|
2005-06-20 14:46:57 +02:00
|
|
|
tag == TAG_USER_SPONSOR_NAME ||
|
|
|
|
tag == TAG_USER_SPONSOR_CONTRACT ||
|
|
|
|
tag == TAG_USER_SPONSOR_BENEFIT ||
|
2005-04-06 00:14:39 +02:00
|
|
|
tag == TAG_NAME ||
|
2005-04-16 09:46:04 +02:00
|
|
|
tag == TAG_TEAM_ID ||
|
2005-05-30 17:54:20 +02:00
|
|
|
tag == TAG_USER_HISTORY ||
|
2005-07-08 19:34:10 +02:00
|
|
|
tag == TAG_USER_EVENT ||
|
|
|
|
tag == TAG_USER_YA_COACH ||
|
|
|
|
tag == TAG_USER_YA_PERCENTAGE ||
|
|
|
|
tag == TAG_USER_YA_AV_COACH ||
|
|
|
|
tag == TAG_USER_YA_AV_PERCENTAGE ||
|
2008-10-24 12:59:20 +02:00
|
|
|
tag == TAG_USER_YA_PREFERENCE ||
|
2005-10-27 23:10:15 +02:00
|
|
|
tag == TAG_USER_YA_COUNTER ||
|
|
|
|
tag == TAG_USER_BET0 ||
|
2009-08-31 14:31:24 +02:00
|
|
|
tag == TAG_USER_BET1 ||
|
|
|
|
tag == TAG_USER_DEFAULT_TEAM ||
|
2012-02-02 16:40:22 +01:00
|
|
|
tag == TAG_USER_DEFAULT_STRUCTURE ||
|
|
|
|
tag == TAG_USER_DEFAULT_STYLE ||
|
|
|
|
tag == TAG_USER_DEFAULT_BOOST)
|
2005-04-06 00:14:39 +02:00
|
|
|
{
|
|
|
|
state = TAG_USER;
|
|
|
|
if(tag == TAG_USER_COUNTER)
|
2005-12-13 14:01:52 +01:00
|
|
|
idx_cnt++;
|
2005-04-06 00:14:39 +02:00
|
|
|
else if(tag == TAG_USER_MONEY_OUTS)
|
|
|
|
idx_mon_out++;
|
|
|
|
else if(tag == TAG_USER_MONEY_INS)
|
|
|
|
idx_mon_in++;
|
2005-04-16 09:46:04 +02:00
|
|
|
else if(tag == TAG_USER_HISTORY)
|
|
|
|
g_array_append_val(new_user.history, new_history);
|
2005-05-30 17:54:20 +02:00
|
|
|
else if(tag == TAG_USER_EVENT)
|
|
|
|
g_array_append_val(new_user.events, new_event);
|
2005-10-27 23:10:15 +02:00
|
|
|
else if(tag == TAG_USER_BET0 ||
|
|
|
|
tag == TAG_USER_BET1)
|
|
|
|
g_array_append_val(new_user.bets[idx_bet], new_bet);
|
2005-04-06 00:14:39 +02:00
|
|
|
}
|
|
|
|
else if(tag == TAG_USER_MONEY_OUT)
|
|
|
|
{
|
|
|
|
state = TAG_USER_MONEY_OUTS;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
else if(tag == TAG_USER_MONEY_IN)
|
|
|
|
{
|
|
|
|
state = TAG_USER_MONEY_INS;
|
|
|
|
idx++;
|
|
|
|
}
|
2005-04-16 09:46:04 +02:00
|
|
|
else if(tag == TAG_USER_HISTORY_SEASON ||
|
|
|
|
tag == TAG_USER_HISTORY_WEEK ||
|
|
|
|
tag == TAG_USER_HISTORY_TYPE ||
|
2005-12-01 12:50:54 +01:00
|
|
|
tag == TAG_USER_HISTORY_TEAM_NAME ||
|
|
|
|
tag == TAG_USER_HISTORY_STRING)
|
|
|
|
{
|
2005-04-16 09:46:04 +02:00
|
|
|
state = TAG_USER_HISTORY;
|
2005-12-01 12:50:54 +01:00
|
|
|
|
|
|
|
if(tag == TAG_USER_HISTORY_STRING)
|
|
|
|
idx++;
|
|
|
|
}
|
2005-05-30 17:54:20 +02:00
|
|
|
else if(tag == TAG_USER_EVENT_TYPE ||
|
|
|
|
tag == TAG_USER_EVENT_VALUE1 ||
|
|
|
|
tag == TAG_USER_EVENT_VALUE2 ||
|
|
|
|
tag == TAG_USER_EVENT_VALUE_STRING)
|
|
|
|
state = TAG_USER_EVENT;
|
2005-10-27 23:10:15 +02:00
|
|
|
else if(tag == TAG_USER_BET_FIX_ID ||
|
|
|
|
tag == TAG_USER_BET_WAGER ||
|
|
|
|
tag == TAG_USER_BET_OUTCOME)
|
|
|
|
state = (idx_bet == 0) ? TAG_USER_BET0 : TAG_USER_BET1;
|
2005-07-08 19:34:10 +02:00
|
|
|
else if(tag >= TAG_START_PLAYERS && tag <= TAG_END_PLAYERS)
|
|
|
|
{
|
|
|
|
xml_loadsave_players_end_element(tag, new_user.youth_academy.players);
|
|
|
|
if(tag == TAG_START_PLAYERS)
|
|
|
|
state = TAG_USER;
|
|
|
|
}
|
2005-04-06 00:14:39 +02:00
|
|
|
else if(tag != TAG_USERS)
|
2009-04-29 19:18:54 +02:00
|
|
|
debug_print_message("xml_loadsave_users_end_element: unknown tag: %s; I'm in state %d\n",
|
2005-04-06 00:14:39 +02:00
|
|
|
element_name, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xml_loadsave_users_text (GMarkupParseContext *context,
|
2005-07-08 19:34:10 +02:00
|
|
|
const gchar *text,
|
|
|
|
gsize text_len,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2005-04-06 00:14:39 +02:00
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_loadsave_users_text\n");
|
|
|
|
#endif
|
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
gchar buf[SMALL];
|
|
|
|
gint int_value = -1;
|
2005-07-08 19:34:10 +02:00
|
|
|
gfloat float_value = -1;
|
2005-04-06 00:14:39 +02:00
|
|
|
|
|
|
|
strncpy(buf, text, text_len);
|
|
|
|
buf[text_len] = '\0';
|
|
|
|
|
|
|
|
int_value = (gint)g_ascii_strtod(buf, NULL);
|
2005-07-08 19:34:10 +02:00
|
|
|
float_value = (gfloat)g_ascii_strtod(text, NULL) / 10000;
|
2005-04-06 00:14:39 +02:00
|
|
|
|
|
|
|
if(state == TAG_NAME)
|
2005-10-09 11:35:44 +02:00
|
|
|
misc_string_assign(&new_user.name, buf);
|
2005-04-06 00:14:39 +02:00
|
|
|
else if(state == TAG_TEAM_ID)
|
2005-04-13 15:01:59 +02:00
|
|
|
{
|
|
|
|
new_user.tm = team_of_id(int_value);
|
|
|
|
new_user.team_id = int_value;
|
2005-07-14 18:05:10 +02:00
|
|
|
new_user.youth_academy.tm = new_user.tm;
|
2005-04-13 15:01:59 +02:00
|
|
|
}
|
2005-04-06 00:14:39 +02:00
|
|
|
else if(state == TAG_USER_MONEY)
|
|
|
|
new_user.money = int_value;
|
|
|
|
else if(state == TAG_USER_DEBT)
|
|
|
|
new_user.debt = int_value;
|
2008-11-06 09:03:09 +01:00
|
|
|
else if(state == TAG_USER_DEBT_INTEREST)
|
|
|
|
new_user.debt_interest = float_value;
|
2008-11-07 09:38:55 +01:00
|
|
|
else if(state == TAG_USER_ALR_START_WEEK)
|
|
|
|
new_user.alr_start_week = int_value;
|
|
|
|
else if(state == TAG_USER_ALR_WEEKLY_INSTALLMENT)
|
|
|
|
new_user.alr_weekly_installment = int_value;
|
2005-04-06 00:14:39 +02:00
|
|
|
else if(state == TAG_USER_SCOUT)
|
|
|
|
new_user.scout = int_value;
|
|
|
|
else if(state == TAG_USER_PHYSIO)
|
|
|
|
new_user.physio = int_value;
|
2005-06-20 14:46:57 +02:00
|
|
|
else if(state == TAG_USER_SPONSOR_NAME)
|
2005-06-20 16:24:54 +02:00
|
|
|
{
|
|
|
|
misc_string_replace_token(buf, "AND", "&");
|
2009-03-23 14:20:59 +01:00
|
|
|
g_string_printf(new_user.sponsor.name, buf, NULL);
|
2005-06-20 16:24:54 +02:00
|
|
|
}
|
2005-06-20 14:46:57 +02:00
|
|
|
else if(state == TAG_USER_SPONSOR_CONTRACT)
|
|
|
|
new_user.sponsor.contract = int_value;
|
|
|
|
else if(state == TAG_USER_SPONSOR_BENEFIT)
|
|
|
|
new_user.sponsor.benefit = int_value;
|
2005-04-06 00:14:39 +02:00
|
|
|
else if(state == TAG_USER_COUNTER)
|
2005-12-13 14:01:52 +01:00
|
|
|
new_user.counters[idx_cnt] = int_value;
|
2005-04-06 00:14:39 +02:00
|
|
|
else if(state == TAG_USER_MONEY_IN)
|
|
|
|
new_user.money_in[idx_mon_in][idx] = int_value;
|
|
|
|
else if(state == TAG_USER_MONEY_OUT)
|
|
|
|
new_user.money_out[idx_mon_out][idx] = int_value;
|
2005-04-16 09:46:04 +02:00
|
|
|
else if(state == TAG_USER_HISTORY_SEASON)
|
|
|
|
new_history.season = int_value;
|
|
|
|
else if(state == TAG_USER_HISTORY_WEEK)
|
|
|
|
new_history.week = int_value;
|
|
|
|
else if(state == TAG_USER_HISTORY_TYPE)
|
|
|
|
new_history.type = int_value;
|
2005-12-01 12:50:54 +01:00
|
|
|
else if(state == TAG_USER_HISTORY_TEAM_NAME)
|
|
|
|
new_history.team_name = g_strdup(buf);
|
|
|
|
else if(state == TAG_USER_HISTORY_STRING)
|
|
|
|
new_history.string[idx] = (strlen(buf) == 0) ? NULL : g_strdup(buf);
|
2005-05-30 17:54:20 +02:00
|
|
|
else if(state == TAG_USER_EVENT_TYPE)
|
|
|
|
new_event.type = int_value;
|
|
|
|
else if(state == TAG_USER_EVENT_VALUE1)
|
|
|
|
new_event.value1 = int_value;
|
|
|
|
else if(state == TAG_USER_EVENT_VALUE2)
|
|
|
|
new_event.value2 = int_value;
|
|
|
|
else if(state == TAG_USER_EVENT_VALUE_STRING)
|
2005-12-01 12:50:54 +01:00
|
|
|
new_event.value_string = g_strdup(buf);
|
2005-07-08 19:34:10 +02:00
|
|
|
else if(state == TAG_USER_YA_COACH)
|
|
|
|
new_user.youth_academy.coach = int_value;
|
|
|
|
else if(state == TAG_USER_YA_PERCENTAGE)
|
|
|
|
new_user.youth_academy.percentage = int_value;
|
|
|
|
else if(state == TAG_USER_YA_AV_COACH)
|
|
|
|
new_user.youth_academy.av_coach = float_value;
|
|
|
|
else if(state == TAG_USER_YA_AV_PERCENTAGE)
|
|
|
|
new_user.youth_academy.av_percentage = float_value;
|
|
|
|
else if(state == TAG_USER_YA_COUNTER)
|
|
|
|
new_user.youth_academy.counter_youth = float_value;
|
2008-10-24 11:25:27 +02:00
|
|
|
else if(state == TAG_USER_YA_PREFERENCE)
|
|
|
|
new_user.youth_academy.pos_pref = int_value;
|
2005-10-27 23:10:15 +02:00
|
|
|
else if(state == TAG_USER_BET_WAGER)
|
|
|
|
new_bet.wager = int_value;
|
|
|
|
else if(state == TAG_USER_BET_OUTCOME)
|
|
|
|
new_bet.outcome = int_value;
|
|
|
|
else if(state == TAG_USER_BET_FIX_ID)
|
2005-10-31 17:19:14 +01:00
|
|
|
new_bet.fix_id = int_value;
|
2009-08-31 14:31:24 +02:00
|
|
|
else if(state == TAG_USER_DEFAULT_TEAM)
|
|
|
|
g_array_append_val(new_user.default_team, int_value);
|
|
|
|
else if(state == TAG_USER_DEFAULT_STRUCTURE)
|
|
|
|
new_user.default_structure = int_value;
|
2012-02-02 16:40:22 +01:00
|
|
|
else if(state == TAG_USER_DEFAULT_STYLE)
|
|
|
|
new_user.default_style = int_value;
|
|
|
|
else if(state == TAG_USER_DEFAULT_BOOST)
|
|
|
|
new_user.default_boost = int_value;
|
2005-07-08 19:34:10 +02:00
|
|
|
else if(state >= TAG_START_PLAYERS && state <= TAG_END_PLAYERS)
|
|
|
|
xml_loadsave_players_text(buf);
|
2005-04-06 00:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xml_loadsave_users_read(const gchar *dirname, const gchar *basename)
|
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_loadsave_users_read\n");
|
|
|
|
#endif
|
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
GMarkupParser parser = {xml_loadsave_users_start_element,
|
|
|
|
xml_loadsave_users_end_element,
|
|
|
|
xml_loadsave_users_text, NULL, NULL};
|
|
|
|
GMarkupParseContext *context;
|
|
|
|
gchar *file_contents;
|
2006-06-04 19:10:08 +02:00
|
|
|
gsize length;
|
2005-04-06 00:14:39 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar file[SMALL];
|
|
|
|
|
2005-10-24 22:50:48 +02:00
|
|
|
sprintf(file, "%s%s%s___users.xml", dirname, G_DIR_SEPARATOR_S, basename);
|
2005-04-06 00:14:39 +02:00
|
|
|
|
|
|
|
context =
|
|
|
|
g_markup_parse_context_new(&parser, 0, NULL, NULL);
|
|
|
|
|
|
|
|
if(!g_file_get_contents(file, &file_contents, &length, &error))
|
|
|
|
{
|
2009-04-29 19:18:54 +02:00
|
|
|
debug_print_message("xml_loadsave_users_read: error reading file %s\n", file);
|
2005-04-06 00:14:39 +02:00
|
|
|
misc_print_error(&error, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(g_markup_parse_context_parse(context, file_contents, length, &error))
|
|
|
|
{
|
|
|
|
g_markup_parse_context_end_parse(context, NULL);
|
|
|
|
g_markup_parse_context_free(context);
|
|
|
|
g_free(file_contents);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-29 19:18:54 +02:00
|
|
|
debug_print_message("xml_loadsave_users_read: error parsing file %s\n", file);
|
2005-04-06 00:14:39 +02:00
|
|
|
misc_print_error(&error, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xml_loadsave_users_write(const gchar *prefix)
|
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_loadsave_users_write\n");
|
|
|
|
#endif
|
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
gint i, j, k;
|
|
|
|
gchar buf[SMALL];
|
|
|
|
FILE *fil = NULL;
|
|
|
|
|
|
|
|
for(i=0;i<users->len;i++)
|
|
|
|
{
|
|
|
|
sprintf(buf, "%s___user_%02d_options", prefix, i);
|
|
|
|
file_save_opt_file(buf, &usr(i).options);
|
|
|
|
|
|
|
|
sprintf(buf, "%s___user_%02d_live_game.xml", prefix, i);
|
|
|
|
xml_loadsave_live_game_write(buf, &usr(i).live_game);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(buf, "%s___users.xml", prefix);
|
|
|
|
file_my_fopen(buf, "w", &fil, TRUE);
|
|
|
|
|
|
|
|
fprintf(fil, "<_%d>\n", TAG_USERS);
|
|
|
|
|
|
|
|
for(i=0;i<users->len;i++)
|
|
|
|
{
|
|
|
|
fprintf(fil, "<_%d>\n", TAG_USER);
|
|
|
|
|
2005-10-09 11:35:44 +02:00
|
|
|
xml_write_string(fil, usr(i).name, TAG_NAME, I1);
|
2005-04-13 15:01:59 +02:00
|
|
|
xml_write_int(fil, usr(i).team_id, TAG_TEAM_ID, I1);
|
2005-04-06 00:14:39 +02:00
|
|
|
xml_write_int(fil, usr(i).money, TAG_USER_MONEY, I1);
|
|
|
|
xml_write_int(fil, usr(i).debt, TAG_USER_DEBT, I1);
|
2008-11-06 09:03:09 +01:00
|
|
|
xml_write_float(fil, usr(i).debt_interest, TAG_USER_DEBT_INTEREST, I1);
|
2008-11-07 09:38:55 +01:00
|
|
|
xml_write_int(fil, usr(i).alr_start_week, TAG_USER_ALR_START_WEEK, I1);
|
|
|
|
xml_write_int(fil, usr(i).alr_weekly_installment, TAG_USER_ALR_WEEKLY_INSTALLMENT, I1);
|
2005-04-06 00:14:39 +02:00
|
|
|
xml_write_int(fil, usr(i).scout, TAG_USER_SCOUT, I1);
|
|
|
|
xml_write_int(fil, usr(i).physio, TAG_USER_PHYSIO, I1);
|
|
|
|
|
2005-06-20 16:24:54 +02:00
|
|
|
strcpy(buf, usr(i).sponsor.name->str);
|
|
|
|
misc_string_replace_token(buf, "&", "AND");
|
|
|
|
xml_write_string(fil, buf, TAG_USER_SPONSOR_NAME, I1);
|
2005-06-20 14:46:57 +02:00
|
|
|
xml_write_int(fil, usr(i).sponsor.contract, TAG_USER_SPONSOR_CONTRACT, I1);
|
|
|
|
xml_write_int(fil, usr(i).sponsor.benefit, TAG_USER_SPONSOR_BENEFIT, I1);
|
|
|
|
|
2005-10-27 23:10:15 +02:00
|
|
|
xml_user_write_history(fil, usr(i).history);
|
|
|
|
xml_user_write_events(fil, usr(i).events);
|
|
|
|
xml_user_write_bets(fil, usr(i).bets);
|
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
for(j=0;j<COUNT_USER_END;j++)
|
|
|
|
xml_write_int(fil, usr(i).counters[j], TAG_USER_COUNTER, I1);
|
|
|
|
|
|
|
|
for(j=0;j<2;j++)
|
|
|
|
{
|
|
|
|
fprintf(fil, "%s<_%d>\n", I1, TAG_USER_MONEY_INS);
|
|
|
|
for(k=0;k<MON_IN_END;k++)
|
|
|
|
xml_write_int(fil, usr(i).money_in[j][k], TAG_USER_MONEY_IN, I2);
|
|
|
|
fprintf(fil, "%s</_%d>\n", I1, TAG_USER_MONEY_INS);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(j=0;j<2;j++)
|
|
|
|
{
|
|
|
|
fprintf(fil, "%s<_%d>\n", I1, TAG_USER_MONEY_OUTS);
|
|
|
|
for(k=0;k<MON_OUT_END;k++)
|
2005-12-13 14:01:52 +01:00
|
|
|
xml_write_int(fil, usr(i).money_out[j][k], TAG_USER_MONEY_OUT, I2);
|
2005-04-06 00:14:39 +02:00
|
|
|
fprintf(fil, "%s</_%d>\n", I1, TAG_USER_MONEY_OUTS);
|
|
|
|
}
|
|
|
|
|
2005-07-08 19:34:10 +02:00
|
|
|
xml_write_int(fil, usr(i).youth_academy.coach, TAG_USER_YA_COACH, I1);
|
|
|
|
xml_write_int(fil, usr(i).youth_academy.percentage, TAG_USER_YA_PERCENTAGE, I1);
|
|
|
|
xml_write_float(fil, usr(i).youth_academy.av_coach, TAG_USER_YA_AV_COACH, I1);
|
2005-12-13 14:01:52 +01:00
|
|
|
xml_write_float(fil, usr(i).youth_academy.av_percentage,
|
|
|
|
TAG_USER_YA_AV_PERCENTAGE, I1);
|
2005-07-08 19:34:10 +02:00
|
|
|
xml_write_float(fil, usr(i).youth_academy.counter_youth, TAG_USER_YA_COUNTER, I1);
|
2008-10-24 11:25:27 +02:00
|
|
|
xml_write_int(fil, usr(i).youth_academy.pos_pref, TAG_USER_YA_PREFERENCE, I1);
|
2009-08-31 14:31:24 +02:00
|
|
|
for (j=0; j < usr(i).default_team->len; j++){
|
|
|
|
xml_write_int(fil, g_array_index(usr(i).default_team, gint, j), TAG_USER_DEFAULT_TEAM, I1);
|
|
|
|
}
|
|
|
|
xml_write_int(fil, usr(i).default_structure, TAG_USER_DEFAULT_STRUCTURE, I1);
|
2012-02-02 16:40:22 +01:00
|
|
|
xml_write_int(fil, usr(i).default_style, TAG_USER_DEFAULT_STYLE, I1);
|
|
|
|
xml_write_int(fil, usr(i).default_boost, TAG_USER_DEFAULT_BOOST, I1);
|
2005-07-08 19:34:10 +02:00
|
|
|
xml_loadsave_players_write(fil, usr(i).youth_academy.players);
|
|
|
|
|
2008-10-24 11:25:27 +02:00
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
fprintf(fil, "</_%d>\n", TAG_USER);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fil, "</_%d>\n", TAG_USERS);
|
|
|
|
|
|
|
|
fclose(fil);
|
|
|
|
}
|
2005-10-27 23:10:15 +02:00
|
|
|
|
|
|
|
/** Write the history of a user into the file. */
|
|
|
|
void
|
|
|
|
xml_user_write_history(FILE *fil, const GArray *history)
|
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_user_write_history\n");
|
|
|
|
#endif
|
|
|
|
|
2005-12-01 12:50:54 +01:00
|
|
|
gint i, j;
|
2005-10-27 23:10:15 +02:00
|
|
|
|
|
|
|
for(i=0;i<history->len;i++)
|
|
|
|
{
|
|
|
|
fprintf(fil, "%s<_%d>\n", I1, TAG_USER_HISTORY);
|
|
|
|
|
|
|
|
xml_write_int(fil, g_array_index(history, UserHistory, i).season,
|
|
|
|
TAG_USER_HISTORY_SEASON, I2);
|
|
|
|
xml_write_int(fil, g_array_index(history, UserHistory, i).week,
|
|
|
|
TAG_USER_HISTORY_WEEK, I2);
|
|
|
|
xml_write_int(fil, g_array_index(history, UserHistory, i).type,
|
|
|
|
TAG_USER_HISTORY_TYPE, I2);
|
2005-12-01 12:50:54 +01:00
|
|
|
xml_write_string(fil, g_array_index(history, UserHistory, i).team_name,
|
|
|
|
TAG_USER_HISTORY_TEAM_NAME, I2);
|
|
|
|
for(j=0;j<3;j++)
|
|
|
|
if(g_array_index(history, UserHistory, i).string[j] != NULL)
|
|
|
|
xml_write_string(fil, g_array_index(history, UserHistory, i).string[j],
|
|
|
|
TAG_USER_HISTORY_STRING, I2);
|
|
|
|
else
|
|
|
|
xml_write_string(fil, "", TAG_USER_HISTORY_STRING, I2);
|
2005-10-27 23:10:15 +02:00
|
|
|
|
|
|
|
fprintf(fil, "%s</_%d>\n", I1, TAG_USER_HISTORY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Write the events of a user into the file. */
|
|
|
|
void
|
|
|
|
xml_user_write_events(FILE *fil, const GArray *events)
|
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_user_write_events\n");
|
|
|
|
#endif
|
|
|
|
|
2005-10-27 23:10:15 +02:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
for(i=0;i<events->len;i++)
|
|
|
|
{
|
|
|
|
fprintf(fil, "%s<_%d>\n", I1, TAG_USER_EVENT);
|
|
|
|
|
|
|
|
xml_write_int(fil, g_array_index(events, Event, i).type,
|
|
|
|
TAG_USER_EVENT_TYPE, I2);
|
|
|
|
xml_write_int(fil, g_array_index(events, Event, i).value1,
|
|
|
|
TAG_USER_EVENT_VALUE1, I2);
|
|
|
|
xml_write_int(fil, g_array_index(events, Event, i).value2,
|
|
|
|
TAG_USER_EVENT_VALUE2, I2);
|
|
|
|
xml_write_string(fil, g_array_index(events, Event, i).value_string,
|
|
|
|
TAG_USER_EVENT_VALUE_STRING, I2);
|
|
|
|
|
|
|
|
fprintf(fil, "%s</_%d>\n", I1, TAG_USER_EVENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Write the bets of a user into the file. */
|
|
|
|
void
|
|
|
|
xml_user_write_bets(FILE *fil, GArray **bets)
|
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_user_write_bets\n");
|
|
|
|
#endif
|
|
|
|
|
2005-10-27 23:10:15 +02:00
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
for(i=0;i<2;i++)
|
|
|
|
for(j=0;j<bets[i]->len;j++)
|
|
|
|
{
|
|
|
|
fprintf(fil, "%s<_%d>\n", I1,
|
|
|
|
(i == 0) ? TAG_USER_BET0 : TAG_USER_BET1);
|
|
|
|
xml_write_int(fil, g_array_index(bets[i], BetUser, j).wager,
|
|
|
|
TAG_USER_BET_WAGER, I2);
|
|
|
|
xml_write_int(fil, g_array_index(bets[i], BetUser, j).outcome,
|
|
|
|
TAG_USER_BET_OUTCOME, I2);
|
2005-10-31 17:19:14 +01:00
|
|
|
xml_write_int(fil, g_array_index(bets[i], BetUser, j).fix_id,
|
2005-10-27 23:10:15 +02:00
|
|
|
TAG_USER_BET_FIX_ID, I2);
|
|
|
|
fprintf(fil, "%s</_%d>\n", I1,
|
|
|
|
(i == 0) ? TAG_USER_BET0 : TAG_USER_BET1);
|
|
|
|
}
|
|
|
|
}
|