Atrinik Server  4.0
statistics.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
37 #include <global.h>
38 #include <toolkit/packet.h>
39 #include <player.h>
40 #include <object.h>
41 
43 static int fd = -1;
45 static struct sockaddr_in insock;
46 
50 void statistics_init(void)
51 {
52  struct protoent *protoent;
53 
54  protoent = getprotobyname("udp");
55 
56  if (!protoent) {
57  return;
58  }
59 
60  fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto);
61 
62  if (fd == -1) {
63  return;
64  }
65 
66  insock.sin_family = AF_INET;
67  insock.sin_port = htons((unsigned short) 13324);
68  insock.sin_addr.s_addr = inet_addr("127.0.0.1");
69 }
70 
83 void statistic_update(const char *type, object *op, int64_t i, const char *buf)
84 {
85  packet_struct *packet;
86 
87  if (!i || fd == -1) {
88  return;
89  }
90 
91  packet = packet_new(0, 256, 256);
92  packet_append_string_terminated(packet, type);
93  packet_append_string_terminated(packet, op->name);
94  packet_append_int64(packet, i);
95 
96  if (buf) {
97  packet_append_string_terminated(packet, buf);
98  }
99 
100  sendto(fd, (const void *) packet->data, packet->len, 0,
101  (struct sockaddr *) &insock, sizeof(insock));
102  packet_free(packet);
103 }
104 
112 {
113  statistic_update("deaths", pl->ob, pl->stat_deaths, NULL);
114  statistic_update("kills_mob", pl->ob, pl->stat_kills_mob, NULL);
115  statistic_update("kills_pvp", pl->ob, pl->stat_kills_pvp, NULL);
116  statistic_update("damage_taken", pl->ob, pl->stat_damage_taken, NULL);
117  statistic_update("damage_dealt", pl->ob, pl->stat_damage_dealt, NULL);
118  statistic_update("hp_regen", pl->ob, pl->stat_hp_regen, NULL);
119  statistic_update("sp_regen", pl->ob, pl->stat_sp_regen, NULL);
120  statistic_update("food_consumed", pl->ob, pl->stat_food_consumed, NULL);
121  statistic_update("food_num_consumed", pl->ob, pl->stat_food_num_consumed, NULL);
122  statistic_update("damage_healed", pl->ob, pl->stat_damage_healed, NULL);
123  statistic_update("damage_healed_other", pl->ob, pl->stat_damage_healed_other, NULL);
124  statistic_update("damage_heal_received", pl->ob, pl->stat_damage_heal_received, NULL);
125  statistic_update("steps_taken", pl->ob, pl->stat_steps_taken, NULL);
126  statistic_update("spells_cast", pl->ob, pl->stat_spells_cast, NULL);
127  statistic_update("time_played", pl->ob, pl->stat_time_played, NULL);
128  statistic_update("time_afk", pl->ob, pl->stat_time_afk, NULL);
129  statistic_update("arrows_fired", pl->ob, pl->stat_arrows_fired, NULL);
130  statistic_update("missiles_thrown", pl->ob, pl->stat_missiles_thrown, NULL);
131  statistic_update("books_read", pl->ob, pl->stat_books_read, NULL);
132  statistic_update("unique_books_read", pl->ob, pl->stat_unique_books_read, NULL);
133  statistic_update("potions_used", pl->ob, pl->stat_potions_used, NULL);
134  statistic_update("scrolls_used", pl->ob, pl->stat_scrolls_used, NULL);
135  statistic_update("exp_gained", pl->ob, pl->stat_exp_gained, NULL);
136  statistic_update("exp_lost", pl->ob, pl->stat_exp_lost, NULL);
137  statistic_update("items_dropped", pl->ob, pl->stat_items_dropped, NULL);
138  statistic_update("items_picked", pl->ob, pl->stat_items_picked, NULL);
139  statistic_update("corpses_searched", pl->ob, pl->stat_corpses_searched, NULL);
140  statistic_update("traps_found", pl->ob, pl->stat_traps_found, NULL);
141  statistic_update("traps_disarmed", pl->ob, pl->stat_traps_disarmed, NULL);
142  statistic_update("traps_sprung", pl->ob, pl->stat_traps_sprung, NULL);
143  statistic_update("afk_used", pl->ob, pl->stat_afk_used, NULL);
144  statistic_update("formed_party", pl->ob, pl->stat_formed_party, NULL);
145  statistic_update("joined_party", pl->ob, pl->stat_joined_party, NULL);
146  statistic_update("renamed_items", pl->ob, pl->stat_renamed_items, NULL);
147  statistic_update("emotes_used", pl->ob, pl->stat_emotes_used, NULL);
148  statistic_update("books_inscribed", pl->ob, pl->stat_books_inscribed, NULL);
149 }
uint64_t stat_books_inscribed
Definition: player.h:431
uint8_t type
One of operation types.
Definition: sound_ambient.c:45
uint64_t stat_spells_cast
Definition: player.h:359
void statistic_update(const char *type, object *op, int64_t i, const char *buf)
Definition: statistics.c:83
uint64_t stat_exp_gained
Definition: player.h:389
uint64_t stat_arrows_fired
Definition: player.h:371
uint64_t stat_damage_taken
Definition: player.h:329
object * ob
Definition: player.h:185
uint64_t stat_books_read
Definition: player.h:377
uint64_t stat_deaths
Definition: player.h:320
uint64_t stat_potions_used
Definition: player.h:383
uint64_t stat_damage_heal_received
Definition: player.h:353
uint64_t stat_kills_pvp
Definition: player.h:326
uint64_t stat_items_picked
Definition: player.h:398
static int fd
Definition: statistics.c:43
uint64_t stat_joined_party
Definition: player.h:419
uint64_t stat_afk_used
Definition: player.h:413
void statistics_init(void)
Definition: statistics.c:50
uint64_t stat_unique_books_read
Definition: player.h:380
uint64_t stat_missiles_thrown
Definition: player.h:374
const char * name
Definition: object.h:168
uint64_t stat_food_consumed
Definition: player.h:341
uint64_t stat_formed_party
Definition: player.h:416
static struct sockaddr_in insock
Definition: statistics.c:45
uint64_t stat_damage_dealt
Definition: player.h:332
uint64_t stat_traps_sprung
Definition: player.h:410
uint64_t stat_traps_disarmed
Definition: player.h:407
uint64_t stat_kills_mob
Definition: player.h:323
uint64_t stat_corpses_searched
Definition: player.h:401
uint64_t stat_damage_healed_other
Definition: player.h:350
void statistics_player_logout(player *pl)
Definition: statistics.c:111
uint64_t stat_steps_taken
Definition: player.h:356
uint64_t stat_scrolls_used
Definition: player.h:386
uint64_t stat_items_dropped
Definition: player.h:395
uint64_t stat_damage_healed
Definition: player.h:347
uint64_t stat_traps_found
Definition: player.h:404
uint64_t stat_exp_lost
Definition: player.h:392
uint64_t stat_time_played
Definition: player.h:362
uint64_t stat_renamed_items
Definition: player.h:422
uint64_t stat_emotes_used
Definition: player.h:425
uint64_t stat_time_afk
Definition: player.h:365
uint64_t stat_hp_regen
Definition: player.h:335
uint64_t stat_food_num_consumed
Definition: player.h:344
uint64_t stat_sp_regen
Definition: player.h:338