Atrinik Server 2.5
server/statistics.c
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00037 #include <global.h>
00038 
00040 static int fd = -1;
00042 static struct sockaddr_in insock;
00043 
00046 void statistics_init()
00047 {
00048     struct protoent *protoent;
00049 
00050     protoent = getprotobyname("udp");
00051 
00052     if (!protoent)
00053     {
00054         return;
00055     }
00056 
00057     fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto);
00058 
00059     if (fd == -1)
00060     {
00061         return;
00062     }
00063 
00064     insock.sin_family = AF_INET;
00065     insock.sin_port = htons((unsigned short) 13324);
00066     insock.sin_addr.s_addr = inet_addr("127.0.0.1");
00067 }
00068 
00076 void statistic_update(const char *type, object *op, sint64 i, const char *buf)
00077 {
00078     SockList sl;
00079     unsigned char sl_buf[MAXSOCKBUF];
00080 
00081     if (!i || fd == -1)
00082     {
00083         return;
00084     }
00085 
00086     sl.buf = sl_buf;
00087     sl.len = 0;
00088 
00089     SockList_AddString(&sl, type);
00090     SockList_AddString(&sl, op->name);
00091     SockList_AddInt64(&sl, i);
00092 
00093     if (buf)
00094     {
00095         SockList_AddString(&sl, buf);
00096     }
00097 
00098     sendto(fd, (void *) sl.buf, sl.len, 0, (struct sockaddr *) &insock, sizeof(insock));
00099 }
00100 
00105 void statistics_player_logout(player *pl)
00106 {
00107     statistic_update("deaths", pl->ob, pl->stat_deaths, NULL);
00108     statistic_update("kills_mob", pl->ob, pl->stat_kills_mob, NULL);
00109     statistic_update("kills_pvp", pl->ob, pl->stat_kills_pvp, NULL);
00110     statistic_update("damage_taken", pl->ob, pl->stat_damage_taken, NULL);
00111     statistic_update("damage_dealt", pl->ob, pl->stat_damage_dealt, NULL);
00112     statistic_update("hp_regen", pl->ob, pl->stat_hp_regen, NULL);
00113     statistic_update("sp_regen", pl->ob, pl->stat_sp_regen, NULL);
00114     statistic_update("grace_regen", pl->ob, pl->stat_grace_regen, NULL);
00115     statistic_update("food_consumed", pl->ob, pl->stat_food_consumed, NULL);
00116     statistic_update("food_num_consumed", pl->ob, pl->stat_food_num_consumed, NULL);
00117     statistic_update("damage_healed", pl->ob, pl->stat_damage_healed, NULL);
00118     statistic_update("damage_healed_other", pl->ob, pl->stat_damage_healed_other, NULL);
00119     statistic_update("damage_heal_received", pl->ob, pl->stat_damage_heal_received, NULL);
00120     statistic_update("steps_taken", pl->ob, pl->stat_steps_taken, NULL);
00121     statistic_update("spells_cast", pl->ob, pl->stat_spells_cast, NULL);
00122     statistic_update("prayers_cast", pl->ob, pl->stat_prayers_cast, NULL);
00123     statistic_update("time_played", pl->ob, pl->stat_time_played, NULL);
00124     statistic_update("time_afk", pl->ob, pl->stat_time_afk, NULL);
00125     statistic_update("arrows_fired", pl->ob, pl->stat_arrows_fired, NULL);
00126     statistic_update("missiles_thrown", pl->ob, pl->stat_missiles_thrown, NULL);
00127     statistic_update("books_read", pl->ob, pl->stat_books_read, NULL);
00128     statistic_update("unique_books_read", pl->ob, pl->stat_unique_books_read, NULL);
00129     statistic_update("potions_used", pl->ob, pl->stat_potions_used, NULL);
00130     statistic_update("scrolls_used", pl->ob, pl->stat_scrolls_used, NULL);
00131     statistic_update("exp_gained", pl->ob, pl->stat_exp_gained, NULL);
00132     statistic_update("items_dropped", pl->ob, pl->stat_items_dropped, NULL);
00133     statistic_update("items_picked", pl->ob, pl->stat_items_picked, NULL);
00134     statistic_update("corpses_searched", pl->ob, pl->stat_corpses_searched, NULL);
00135     statistic_update("traps_found", pl->ob, pl->stat_traps_found, NULL);
00136     statistic_update("traps_disarmed", pl->ob, pl->stat_traps_disarmed, NULL);
00137     statistic_update("traps_sprung", pl->ob, pl->stat_traps_sprung, NULL);
00138     statistic_update("afk_used", pl->ob, pl->stat_afk_used, NULL);
00139     statistic_update("formed_party", pl->ob, pl->stat_formed_party, NULL);
00140     statistic_update("joined_party", pl->ob, pl->stat_joined_party, NULL);
00141     statistic_update("renamed_items", pl->ob, pl->stat_renamed_items, NULL);
00142     statistic_update("emotes_used", pl->ob, pl->stat_emotes_used, NULL);
00143     statistic_update("books_inscribed", pl->ob, pl->stat_books_inscribed, NULL);
00144 }