Crossfire Client, Trunk
sound.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2013 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, see the
9  * 'LICENSE' and 'COPYING' files.
10  *
11  * The authors can be reached via e-mail to crossfire-devel@real-time.com
12  */
13 
21 #include "client.h"
22 #include "sound.h"
23 
24 #include "client-vala.h"
25 
26 int init_sounds() {
27  return cf_snd_init() == 0;
28 }
29 
38 void Sound2Cmd(unsigned char *data, int len) {
39  gint8 x, y;
40  guint8 dir, vol, type, len_sound, len_source;
41  char *sound = NULL;
42  char *source = NULL;
43 
52  if (len < 8) {
54  "gtk-v2::Sound2Cmd", "Sound command too short: %d\n bytes", len);
55  return;
56  }
57 
58  x = data[0];
59  y = data[1];
60  dir = data[2];
61  vol = data[3];
62  type = data[4];
63  len_sound = data[5];
64  /*
65  * The minimum size of data is 1 for each byte in the command (7) plus the
66  * size of the sound string. If we do not have that, the data is bogus.
67  */
68  if (6 + len_sound + 1 > len) {
70  "gtk-v2::Sound2Cmd", "sound length check: %i len: %i\n",
71  len_sound, len);
72  return;
73  }
74 
75  len_source = data[6 + len_sound];
76  if (len_sound != 0) {
77  sound = (char *) data + 6;
78  data[6 + len_sound] = '\0';
79  }
80  /*
81  * The minimum size of data is 1 for each byte in the command (7) plus the
82  * size of the sound string, and the size of the source string.
83  */
84  if (6 + len_sound + 1 + len_source > len) {
86  "gtk-v2::Sound2Cmd", "source length check: %i len: %i\n",
87  len_source, len);
88  return;
89  }
90  /*
91  * Though it looks like there is potential for writing a null off the end
92  * of the buffer, there is always room for a null (see do_client()).
93  */
94  if (len_source != 0) {
95  source = (char *) data + 6 + len_sound + 1;
96  data[6 + len_sound + 1 + len_source] = '\0';
97  }
98 
99  if (use_config[CONFIG_SOUND]) {
100  cf_play_sound(x, y, dir, vol, type, sound, source);
101  }
102 }
103 
113 void MusicCmd(const char *data, int len) {
121  // Check for null terminator.
122  if (data[len]) {
123  LOG(LOG_ERROR, "gtk-v2::MusicCmd",
124  "Music command string is not null-terminated.");
125  return;
126  }
127  if (use_config[CONFIG_SOUND]) {
128  cf_play_music(data);
129  }
130 }
init_sounds
int init_sounds()
Definition: sound.c:26
LOG_WARNING
@ LOG_WARNING
Warning that something might not work.
Definition: client.h:435
cf_snd_init
int cf_snd_init()
Definition: cfsndserv.c:80
Sound2Cmd
void Sound2Cmd(unsigned char *data, int len)
Definition: sound.c:38
LOG
void LOG(LogLevel level, const char *origin, const char *format,...)
Definition: misc.c:111
MusicCmd
void MusicCmd(const char *data, int len)
Definition: sound.c:113
LOG_ERROR
@ LOG_ERROR
Warning that something definitely didn't work.
Definition: client.h:436
CONFIG_SOUND
#define CONFIG_SOUND
Definition: client.h:195
cf_play_sound
void cf_play_sound(gint8 x, gint8 y, guint8 dir, guint8 vol, guint8 type, char const sound[static 1], char const source[static 1])
Definition: cfsndserv.c:131
use_config
gint16 use_config[CONFIG_NUMS]
Definition: client.h:242
sound.h
client.h
cf_play_music
void cf_play_music(const char *music_name)
Definition: cfsndserv.c:172