2 "$Id: commands.c 9719 2008-08-04 18:57:47Z ryo_saeba $";
79 LOG(
LOG_ERROR,
"common::get_exp_info",
"no max level info from server provided");
86 for (level = 1; level <=
exp_table_max && pos < len; level++) {
92 "Incomplete table sent - got %d entries, wanted %d", level,
exp_table_max);
102 nl = strchr(cp,
'\n');
107 sn = strchr(cp,
':');
109 LOG(
LOG_WARNING,
"common::get_skill_info",
"corrupt line: /%s/", cp);
118 LOG(
LOG_WARNING,
"common::get_skill_info",
"invalid skill number %d", val);
125 }
while (cp < data+len);
140 for (i = 0; i < len; i++) {
142 if (*(buf+i) ==
' ' || *(buf+i) ==
'\n') {
151 LOG(
LOG_DEBUG,
"common::ReplyInfoCmd",
"Never found a space in the replyinfo");
158 if (!strcmp((
char*)buf,
"image_info")) {
160 }
else if (!strcmp((
char*)buf,
"image_sums")) {
162 }
else if (!strcmp((
char*)buf,
"skill_info")) {
164 }
else if (!strcmp((
char*)buf,
"exp_table")) {
193 for (; buf[s] && buf[s] !=
' '; s++)
196 while (buf[s] ==
' ') {
205 for (; buf[s] && buf[s] !=
' '; s++)
208 while (s < len && buf[s] ==
' ') {
216 if (!strcmp(cmd,
"sound2")) {
220 }
else if (!strcmp(cmd,
"sound")) {
222 if (strcmp(param,
"FALSE")) {
225 }
else if (!strcmp(cmd,
"mapsize")) {
229 if (!strcasecmp(param,
"false")) {
239 for (cp = param; *cp != 0; cp++) {
240 if (*cp ==
'x' || *cp ==
'X') {
255 snprintf(tmpbuf,
sizeof(tmpbuf),
"Server supports a max mapsize of %d x %d - requesting a %d x %d mapsize",
266 snprintf(tmpbuf,
sizeof(tmpbuf),
"Unable to set mapsize on server - we wanted %d x %d, server returned %d x %d",
270 }
else if (!strcmp(cmd,
"sexp") || !strcmp(cmd,
"darkness") ||
271 !strcmp(cmd,
"newmapcmd") || !strcmp(cmd,
"spellmon")) {
275 if (!strcmp(param,
"FALSE")) {
276 LOG(
LOG_WARNING,
"common::SetupCmd",
"Server returned FALSE on setup command %s", cmd);
281 if (!strcmp(cmd,
"newmapcmd") && fog_of_war ==
TRUE) {
282 fprintf(stderr,
"**Warning: Fog of war is active but server does not support the newmap command\n");
286 }
else if (!strcmp(cmd,
"facecache")) {
292 }
else if (!strcmp(cmd,
"faceset")) {
293 if (!strcmp(param,
"FALSE")) {
294 draw_info(
"Server does not support other image sets, will use default",
NDI_RED);
297 }
else if (!strcmp(cmd,
"map2cmd")) {
298 if (!strcmp(param,
"FALSE")) {
308 }
else if (!strcmp(cmd,
"itemcmd")) {
314 }
else if (!strcmp(cmd,
"exp64")) {
319 if (!strcmp(param,
"FALSE")) {
331 }
else if (!strcmp(cmd,
"extendedMapInfos")) {
332 if (!strcmp(param,
"FALSE")) {
342 }
else if (!strcmp(cmd,
"extendedTextInfos")) {
343 if (strcmp(param,
"FALSE")) {
351 snprintf(exttext,
sizeof(exttext),
"toggleextendedtext %d", manager->
type);
353 manager = manager->
next;
356 }
else if (!strcmp(cmd,
"want_pickup")) {
358 }
else if (!strcmp(cmd,
"inscribe")) {
359 if (strcmp(param,
"FALSE"))
364 LOG(
LOG_INFO,
"common::SetupCmd",
"Got setup for a command we don't understand: %s %s",
391 LOG(
LOG_INFO,
"common::AddMeFail",
"addme_failed received.");
402 LOG(
LOG_INFO,
"common::AddMeSuccess",
"addme_success received.");
415 LOG(
LOG_WARNING,
"common::GoodbyeCmd",
"Received goodbye command from server - exiting");
426 if (anum < 0 || anum >
MAXANIM) {
427 LOG(
LOG_WARNING,
"common::AnimCmd",
"animation number invalid: %d", anum);
433 if (animations[anum].num_animations < 1) {
435 animations[anum].num_animations);
438 animations[anum].
faces = malloc(
sizeof(
uint16)*animations[anum].num_animations);
439 for (i = 4, j = 0; i < len; i += 2, j++) {
443 if (j != animations[anum].num_animations) {
445 "Calculated animations does not equal stored animations? (%d!=%d)",
446 j, animations[anum].num_animations);
449 animations[anum].
speed = 0;
451 animations[anum].
phase = 0;
453 LOG(
LOG_DEBUG,
"common::AnimCmd",
"Received animation %d, %d faces", anum, animations[anum].num_animations);
476 int color = atoi(data);
481 buf = strchr(data,
' ');
500 while (current != NULL) {
501 if (current->
type == type) {
505 current = current->
next;
508 current->
type = type;
511 firstTextManager = current;
516 while (current != NULL) {
517 if (current->
type == type) {
520 current = current->
next;
533 while (wordCount > 0) {
534 while (buf[0] ==
' ') {
538 while (buf[0] !=
' ') {
539 if (buf[0] ==
'\0') {
541 "common::DrawExtInfoCmd",
"Data is missing %d parameters %s",
553 wordCount = sscanf(data,
"%d %d %d", &color, &type, &subtype);
554 if (wordCount != 3) {
556 "common::DrawExtInfoCmd",
"Wrong parameters received. Could only parse %d out of 3 int in %s",
564 "common::DrawExtInfoCmd",
"Server send us a type %d but i can't find any callback for it",
568 fnct(color, type, subtype, buf);
592 }
while(next != skill_id && next >= 0);
597 int i = 0, c, redraw = 0;
684 int rlen = data[i++];
685 strncpy(
cpl.
range, (
const char*)data+i, rlen);
692 int rlen = data[i++];
693 strncpy(
cpl.
title, (
const char*)data+i, rlen);
700 LOG(
LOG_WARNING,
"common::StatsCmd",
"Unknown stat number %d", c);
708 LOG(
LOG_WARNING,
"common::StatsCmd",
"got stats overflow, processed %d bytes out of %d", i, len);
719 uint8 flags = atoi(data);
733 buf = strchr(data,
' ');
741 while ((buf = strchr(buf,
'\n')) != NULL) {
784 int tag, weight, face, i = 0, nlen;
791 memcpy(name, (
const char*)data+i, nlen);
796 LOG(
LOG_WARNING,
"common::PlayerCmd",
"lengths do not match (%d!=%d)", len, i);
821 int weight, loc, tag, face, flags, pos = 0, nlen, anim, nrof, type;
829 LOG(
LOG_WARNING,
"common::common_item_command",
"Got location with no other data");
831 }
else if (loc < 0) {
832 LOG(
LOG_WARNING,
"common::common_item_command",
"Got location with negative value (%d)", loc);
841 memcpy(name, (
char*)data+pos, nlen);
845 animspeed = data[pos++];
848 update_item(tag, loc, name, weight, face, flags, anim, animspeed, nrof, type);
852 LOG(
LOG_WARNING,
"common::common_item_cmd",
"Overread buffer: %d > %d", pos, len);
863 int weight, loc, tag, face, sendflags, flags, pos = 0, nlen, anim;
866 item *ip, *env = NULL;
896 LOG(
LOG_WARNING,
"common::UpdateItemCmd",
"Got tag of unknown object (%d) for new location", loc);
913 memcpy(name, (
char*)data+pos, nlen);
918 LOG(
LOG_WARNING,
"common::UpdateItemCmd",
"Overread buffer: %d > %d", pos, len);
926 animspeed = data[pos++];
937 update_item(tag, loc, name, weight, face, flags, anim, animspeed, nrof, ip->
type);
952 LOG(
LOG_WARNING,
"common::DeleteItem",
"Cannot find tag %d", tag);
956 LOG(
LOG_WARNING,
"common::DeleteItem",
"Overread buffer: %d > %d", pos, len);
966 tag = atoi((
const char*)data);
971 LOG(
LOG_WARNING,
"common::DeleteInventory",
"Invalid tag: %d", tag);
982 Spell *newspell, *tmp;
985 newspell = calloc(1,
sizeof(
Spell));
996 strncpy(newspell->
name, (
char*)data+pos, nlen); pos += nlen;
997 newspell->
name[nlen] =
'\0';
999 strncpy(newspell->
message, (
char*)data+pos, mlen); pos += mlen;
1000 newspell->
message[mlen] =
'\0';
1009 tmp->
next = newspell;
1014 LOG(
LOG_WARNING,
"common::AddspellCmd",
"Overread buffer: %d > %d", pos, len);
1020 int flags, tag, pos = 0;
1024 LOG(
LOG_WARNING,
"common::UpdspellCmd",
"I know no spells to update");
1046 LOG(
LOG_WARNING,
"common::UpdspellCmd",
"Overread buffer: %d > %d", pos, len);
1053 Spell *tmp, *target;
1056 LOG(
LOG_WARNING,
"common::DeleteSpell",
"I know no spells to delete");
1114 #define NUM_LAYERS (MAP1_LAYERS-1)
1117 int mask, x, y, pos = 0, space_len, value;
1167 space_len = type>>5;
1173 }
else if (type == 1) {
1174 value = data[pos++];
1177 }
else if (type >= 0x10 && type <= 0x1a) {
1187 LOG(
LOG_WARNING,
"commands.c::Map2Cmd",
"got layer >= MAXLAYERS!");
1190 assert(0 <= layer && layer <
MAXLAYERS);
1198 if (space_len > 2) {
1200 if (value&FACE_IS_ANIM) {
1209 if (space_len > 3) {
1228 buf = strchr(data,
' ');
1244 int ExtSmooth(
unsigned char *data,
int len,
int x,
int y,
int layer) {
1245 static int dx[8] = { 0, 1, 1, 1, 0, -1, -1, -1, };
1246 static int dy[8] = { -1, -1, 0, 1, 1, 1, 0, -1, };
1259 for (i = 0; i < 8; i++) {
1279 int mask, x, y, pos = 0, layer;
1304 while (pos+entrysize+2 <= len) {
1306 x = (mask>>10)&0x3f;
1308 for (layer =
NUM_LAYERS; layer >= 0; layer--) {
1309 if (mask&(1<<layer)) {
1311 if (pos+entrysize > len) {
1314 startpackentry = pos;
1326 pos = startpackentry+entrysize;
1342 LOG(
LOG_WARNING,
"common::MagicMapCmd",
"Was not able to properly extract magic map size, pos");
1349 for (cp = data, i = 0; i < 4 && cp < data+len; cp++) {
1355 LOG(
LOG_WARNING,
"common::MagicMapCmd",
"Was unable to find start of magic map data");
1360 LOG(
LOG_WARNING,
"common::MagicMapCmd",
"Magic map size mismatch. Have %d bytes, should have %d",
void DeleteItem(unsigned char *data, int len)
#define CS_STAT_SPELL_DENY
void handle_query(char *data, int len)
void SetupCmd(char *buf, int len)
void mapdata_set_anim_layer(int x, int y, uint16 anim, uint8 anim_speed, int layer)
void DrawInfoCmd(char *data, int len)
void mapdata_set_check_space(int x, int y)
void mapdata_clear_space(int x, int y)
#define CS_STAT_SKILLEXP_PHYSIQUE
#define CS_STAT_SKILLEXP_WISDOM
#define CS_STAT_SPELL_ATTUNE
void set_weight_limit(uint32 wlim)
void setTextManager(int type, ExtTextManager callback)
void AddMeFail(char *data, int len)
short GetShort_String(const unsigned char *data)
Animations animations[MAXANIM]
void(* ExtTextManager)(int flag, int type, int subtype, char *message)
#define CS_STAT_SKILLEXP_START
char GetChar_String(const unsigned char *data)
void close_container(item *op)
void ExtendedInfoSetCmd(char *data, int len)
#define CS_STAT_SKILLEXP_WILEVEL
Face_Information face_info
void DeleteSpell(unsigned char *data, int len)
void MagicMapCmd(unsigned char *data, int len)
#define CS_STAT_SPELL_REPEL
sint16 want_config[CONFIG_NUMS]
void reset_player_data(void)
sint64 skill_exp[MAX_SKILL]
void DeleteInventory(unsigned char *data, int len)
void display_map_startupdate(void)
char * skill_names[MAX_SKILL]
void mapdata_newmap(void)
void Item2Cmd(unsigned char *data, int len)
void client_pickup(uint32 pickup)
#define CS_STAT_SKILLEXP_PELEVEL
#define CS_STAT_SKILLEXP_MELEVEL
void draw_stats(int redraw)
#define CS_STAT_SKILLEXP_MAGIC
void LOG(LogLevel level, const char *origin, const char *format,...)
void Map2Cmd(unsigned char *data, int len)
#define CS_STAT_SKILLEXP_AGILITY
int ExtSmooth(unsigned char *data, int len, int x, int y, int layer)
#define CS_STAT_SKILLINFO
void SinkCmd(unsigned char *data, int len)
TextManager * firstTextManager
void display_map_doneupdate(int redraw, int notice)
void SmoothCmd(unsigned char *data, int len)
void TickCmd(uint8 *data, int len)
int cs_print_string(int fd, const char *str,...)
void addsmooth(uint16 face, uint16 smooth_face)
void draw_message_window(int redraw)
sint16 use_config[CONFIG_NUMS]
void use_skill(int skill_id)
void item_actions(item *op)
void UpdateItemCmd(unsigned char *data, int len)
void mapdata_clear_old(int x, int y)
void PickupCmd(uint8 *data, int len)
const char *const rcsid_common_commands_c
#define CS_STAT_SKILLEXP_AGLEVEL
static void get_skill_info(char *data, int len)
void StatsCmd(unsigned char *data, int len)
#define CS_QUERY_SINGLECHAR
void NewmapCmd(unsigned char *data, int len)
void get_image_sums(char *data, int len)
void new_player(long tag, char *name, long weight, long face)
#define CS_STAT_SKILLEXP_PHLEVEL
void draw_color_info(int colr, const char *buf)
void send_reply(const char *text)
void mapdata_set_face_layer(int x, int y, sint16 face, int layer)
#define CS_STAT_RESIST_END
int last_used_skills[MAX_SKILL+1]
void GoodbyeCmd(char *data, int len)
struct Spell_struct * next
void SendSetFaceMode(ClientSocket csock, int mode)
void script_lua_stats(void)
void AddMeSuccess(char *data, int len)
void map_scrollCmd(char *data, int len)
item * locate_item(sint32 tag)
void AnimCmd(unsigned char *data, int len)
void mapdata_scroll(int dx, int dy)
static void get_exp_info(const unsigned char *data, int len)
void update_item(int tag, int loc, char *name, int weight, int face, int flags, int anim, int animspeed, uint32 nrof, int type)
void DrawExtInfoCmd(char *data, int len)
void UpdspellCmd(unsigned char *data, int len)
#define CS_STAT_SKILLEXP_MENTAL
static ExtTextManager getTextManager(int type)
#define CS_STAT_SKILLEXP_PERSONAL
char * strdup_local(const char *str)
void client_tick(uint32 tick)
struct TextManager * next
void PlayerCmd(unsigned char *data, int len)
void remove_item_inventory(item *op)
#define MAP2_COORD_OFFSET
void ReplyInfoCmd(uint8 *buf, int len)
#define CS_STAT_RESIST_START
void AddspellCmd(unsigned char *data, int len)
void draw_info(const char *str, int color)
void draw_magic_map(void)
void resize_map_window(int x, int y)
void open_container(item *op)
#define CS_QUERY_HIDEINPUT
sint64 GetInt64_String(const unsigned char *data)
sint16 skill_level[MAX_SKILL]
void draw_prompt(const char *str)
static void common_item_command(uint8 *data, int len)
#define CS_STAT_WEIGHT_LIM
#define CS_STAT_SKILLEXP_MALEVEL
int GetInt_String(const unsigned char *data)
void mapdata_set_size(int viewx, int viewy)
void get_image_info(uint8 *data, int len)
void remove_item(item *op)
void mapdata_set_darkness(int x, int y, int darkness)
void MapExtendedCmd(unsigned char *data, int len)
void mapdata_set_smooth(int x, int y, int smooth, int layer)