72 #include <sys/types.h>
74 #include <sys/socket.h>
75 #include <netinet/in.h>
76 #include <netinet/tcp.h>
84 #ifdef HAVE_SYS_TIME_H
132 for (s = 0; s < len; ) {
136 for (; buf[s] && buf[s] !=
' '; s++)
142 while (buf[s] ==
' ')
148 for (; buf[s] && buf[s] !=
' '; s++)
152 while (s < len && buf[s] ==
' ')
157 if (!strcmp(cmd,
"sound")) {
161 }
else if (!strcmp(cmd,
"sound2")) {
164 }
else if (!strcmp(cmd,
"exp64")) {
167 }
else if (!strcmp(cmd,
"spellmon")) {
170 monitor_spells = atoi(param);
171 if (monitor_spells != 0 && monitor_spells != 1) {
177 }
else if (!strcmp(cmd,
"darkness")) {
180 darkness = atoi(param);
181 if (darkness != 0 && darkness != 1) {
187 }
else if (!strcmp(cmd,
"map2cmd")) {
190 map2cmd = atoi(param);
196 }
else if (!strcmp(cmd,
"newmapcmd")) {
199 newmapcmd = atoi(param);
200 if (newmapcmd != 0 && newmapcmd != 1) {
206 }
else if (!strcmp(cmd,
"facecache")) {
209 facecache = atoi(param);
210 if (facecache != 0 && facecache != 1) {
216 }
else if (!strcmp(cmd,
"faceset")) {
222 }
else if (!strcmp(cmd,
"itemcmd")) {
225 }
else if (!strcmp(cmd,
"mapsize")) {
228 if (sscanf(param,
"%dx%d%n", &x, &y, &n) != 2 || n != (
int)strlen(param)) {
246 }
else if (!strcmp(cmd,
"extendedMapInfos")) {
248 }
else if (!strcmp(cmd,
"extendedTextInfos")) {
249 int has_readable_type;
251 has_readable_type = atoi(param);
252 if (has_readable_type != 0 && has_readable_type != 1) {
258 }
else if (!strcmp(cmd,
"tick")) {
262 if (tick != 0 && tick != 1) {
268 }
else if (!strcmp(cmd,
"bot")) {
271 is_bot = atoi(param);
272 if (is_bot != 0 && is_bot != 1) {
278 }
else if (!strcmp(cmd,
"want_pickup")) {
281 want_pickup = atoi(param);
282 if (want_pickup != 0 && want_pickup != 1) {
288 }
else if (!strcmp(cmd,
"inscribe")) {
290 }
else if (!strcmp(cmd,
"num_look_objects")) {
347 SockList_AddString(&sl,
"drawinfo 3 Warning: Your client is too old to receive map data. Please update to a new client at http://sourceforge.net/project/showfiles.php ?group_id=13833");
362 int info, nextinfo, smooth = 0;
368 while (info < len && buf[info] ==
' ')
373 while (nextinfo < len && buf[nextinfo] !=
' ')
375 if (nextinfo-info >= 49)
377 strncpy(command, &buf[info], nextinfo-info);
378 command[nextinfo-info] =
'\0';
380 if (!strcmp(
"smooth", command)) {
401 int info, nextinfo, i, flag;
407 while (info < len && buf[info] ==
' ')
412 while (nextinfo < len && buf[nextinfo] !=
' ')
414 if (nextinfo-info >= 49)
416 strncpy(command, &buf[info], nextinfo-info);
417 command[nextinfo-info] =
'\0';
419 i = sscanf(command,
"%d", &flag);
499 LOG(
llevDebug,
"Corrupt ncom command - not long enough - discarding\n");
512 strncpy(command, (
char *)buf+6, len-4);
513 command[len-4] =
'\0';
522 "You can not issue commands - state is not ST_PLAYING (%s)",
523 "You can not issue commands - state is not ST_PLAYING (%s)",
530 LOG(
llevError,
"Player has negative time - shouldn't do command.\n");
570 LOG(
llevError,
"Got reply message with ST_PLAYING input state\n");
625 LOG(
llevError,
"CS: received corrupted version command\n");
636 cp = strchr(buf+1,
' ');
645 cp = strchr(cp+1,
' ');
647 LOG(
llevDebug,
"CS: connection from client of type <%s>, ip %s\n", cp, ns->
host);
702 for (i = 0; i < 2; i++) {
704 if (!(buf = strchr(buf,
' '))) {
736 #define AddIfInt64(Old, New, Type) \
739 SockList_AddChar(&sl, Type); \
740 SockList_AddInt64(&sl, New); \
743 #define AddIfInt(Old, New, Type) \
746 SockList_AddChar(&sl, Type); \
747 SockList_AddInt(&sl, New); \
750 #define AddIfShort(Old, New, Type) \
753 SockList_AddChar(&sl, Type); \
754 SockList_AddShort(&sl, New); \
757 #define AddIfFloat(Old, New, Type) \
760 SockList_AddChar(&sl, Type); \
761 SockList_AddInt(&sl, (long)(New*FLOAT_MULTI));\
764 #define AddIfString(Old, New, Type) \
765 if (Old == NULL || strcmp(Old, New)) { \
768 Old = strdup_local(New); \
769 SockList_AddChar(&sl, Type); \
770 SockList_AddLen8Data(&sl, New, strlen(New));\
788 if (pl->
ob != NULL) {
904 LOG(
llevError,
"esrv_send_anim (%d) out of bounds??\n", anim_num);
935 memset(cell->
faces, face,
sizeof(cell->
faces));
938 #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y)
976 uint8 nlayer, smoothlevel = 0;
1006 if (bx < ax || by < ay) {
1007 LOG(
llevError,
"map2_add_ob: bx (%d) or by (%d) is less than ax (%d) or ay (%d)\n", bx, by, ax, ay);
1014 for (l = layer-1; l <= layer+1; l++) {
1017 if (heads[by][bx][l] == head)
1024 if (!heads[by][bx][layer])
1025 heads[by][bx][layer] = head;
1026 else if (layer+1 <
MAP_LAYERS && !heads[by][bx][layer+1])
1027 heads[by][bx][layer+1] = head;
1047 uint8 len, anim_speed = 0, i;
1054 nlayer = 0x10+layer;
1076 anim_speed = (int)(1.0/
FABS(ob->
speed));
1124 nlayer = 0x10+layer+(2<<5);
1149 int layer, got_one = 0, del_one = 0, oldlen, has_obj = 0;
1156 for (layer = 0; layer <
MAP_LAYERS; layer++) {
1159 head = heads[ay][ax][layer];
1164 got_one +=
map2_add_ob(ax, ay, layer, head, sl, ns, &has_obj, 1);
1177 if (!del_one && !got_one) {
1179 }
else if (del_one && !has_obj) {
1195 int x, y, ax, ay, d, min_x, max_x, min_y, max_y, oldlen, layer;
1216 memset(heads, 0,
sizeof(heads));
1230 for (y = min_y; y < max_y; y++, ay++) {
1232 for (x = min_x; x < max_x; x++, ax++) {
1281 int have_darkness = 0, has_obj = 0, got_one = 0, del_one = 0, g1;
1311 for (layer = 0; layer <
MAP_LAYERS; layer++) {
1339 if (!del_one && !got_one && !have_darkness) {
1341 }
else if (del_one && !has_obj) {
1362 if (sl.
len > startlen) {
1376 int min_x, min_y, max_x, max_y;
1379 LOG(
llevError,
"draw_client_map called with non player/non eric-server\n");
1403 for (j = min_y; j < max_y; j++) {
1404 for (i = min_x; i < max_x; i++) {
1448 for (x = 0; x < mx; x++) {
1449 for (y = 0; y < my; y++) {
1450 if (x >= ns->
mapx || y >= ns->
mapy) {
1452 memset(&newmap.
cells[x][y], 0,
sizeof(newmap.
cells[x][y]));
1453 }
else if (x+dx < 0 || x+dx >= ns->
mapx || y+dy < 0 || y+dy >= ns->
mapy) {
1455 memset(&newmap.
cells[x][y], 0,
sizeof(newmap.
cells[x][y]));
1492 LOG(
llevError,
"Buffer overflow in send_exp_table, not sending all information\n");
1516 LOG(
llevError,
"Buffer overflow in send_skill_info, not sending all skill information\n");
1541 LOG(
llevError,
"Buffer overflow in send_spell_paths, not sending all spell information\n");
1580 static int sl_initialized = 0;
1582 if (!sl_initialized) {
1644 static int sl_initialized = 0;
1646 if (!sl_initialized) {
1690 for (spell = pl->
ob->
inv; spell != NULL; spell = spell->
below) {
1730 if (!pl || !spell || spell->
env != pl->
ob) {
1762 int len, i, skill = 0;
1802 len = strlen(spell->
msg);
1816 LOG(
llevError,
"esrv_add_spells, tried to add a spell to a NULL player\n");
1826 for (spell = pl->
ob->
inv; spell != NULL; spell = spell->
below) {
1847 LOG(
llevError,
"Asked to send a non-spell object as a spell\n");
1871 if (setsockopt(pl->
socket.
fd, IPPROTO_TCP, TCP_NODELAY, &tmp,
sizeof(tmp)))
1872 LOG(
llevError,
"send_tick: Unable to turn on TCP_NODELAY\n");
1876 if (setsockopt(pl->
socket.
fd, IPPROTO_TCP, TCP_NODELAY, &tmp,
sizeof(tmp)))
1877 LOG(
llevError,
"send_tick: Unable to turn off TCP_NODELAY\n");
void map_newmap_cmd(socket_struct *ns)
void SockList_AddPrintf(SockList *sl, const char *format,...)
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny)
#define CS_STAT_SPELL_DENY
#define ST_GET_PARTY_PASSWORD
void send_spell_paths(socket_struct *ns, char *params)
void SockList_Reset(SockList *sl)
void esrv_add_spells(player *pl, object *spell)
int find_smooth(uint16 face, uint16 *smoothed)
static void send_smooth(socket_struct *ns, uint16 face)
void new_player_cmd(uint8 *buf, int len, player *pl)
static int map2_delete_layer(int ax, int ay, int layer, SockList *sl, socket_struct *ns)
void SockList_Init(SockList *sl)
void send_skill_info(socket_struct *ns, char *params)
void receive_player_password(object *op)
int GetInt_String(const unsigned char *data)
EXTERN int num_animations
#define CS_STAT_SPELL_ATTUNE
void send_tick(player *pl)
void send_race_list(socket_struct *ns, char *params)
void SockList_AddShort(SockList *sl, uint16 data)
void key_roll_stat(object *op, char key)
#define ST_CHANGE_PASSWORD_CONFIRM
static object * heads[MAX_HEAD_POS][MAX_HEAD_POS][MAP_LAYERS]
#define NS_FACESENT_SMOOTH
void map_redraw_cmd(char *buf, int len, player *pl)
#define CS_STAT_RES_BLIND
#define ST_CONFIRM_PASSWORD
const char * skill_names[NUM_SKILLS]
int is_valid_faceset(int fsn)
int SP_level_dam_adjust(const object *caster, const object *spob)
#define CS_STAT_SPELL_REPEL
#define AddIfInt64(Old, New, Type)
#define ST_CHANGE_PASSWORD_NEW
void set_sound_cmd(char *buf, int len, socket_struct *ns)
void esrv_remove_spell(player *pl, object *spell)
#define AddIfString(Old, New, Type)
#define CS_STAT_RES_POISON
void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format,...)
sint64 last_skill_exp[NUM_SKILLS]
void send_class_info(socket_struct *ns, char *params)
const char *const spellpathnames[NRSPELLPATHS]
static void build_race_list_reply(SockList *sl)
#define CS_STAT_RES_DEPLETE
#define MAP_LAYER_LIVING2
void version_cmd(char *buf, int len, socket_struct *ns)
client_spell * get_client_spell_state(player *pl, object *spell)
#define MAX_NUM_LOOK_OBJECTS
#define CS_STAT_SKILLINFO
#define FLAG_CLIENT_ANIM_RANDOM
void SockList_AddInt64(SockList *sl, uint64 data)
void move_cmd(char *buf, int len, player *pl)
void SockList_AddData(SockList *sl, const void *data, size_t len)
#define AddIfInt(Old, New, Type)
void key_change_class(object *op, char key)
void draw_client_map(object *pl)
static const short atnr_cs_stat[NROFATTACKS]
void receive_party_password(object *op)
void key_confirm_quit(object *op, char key)
void add_player(socket_struct *ns)
short GetShort_String(const unsigned char *data)
void SockList_Term(SockList *sl)
#define CS_STAT_RES_DEATH
#define FLAG_CLIENT_ANIM_SYNC
static void build_class_list_reply(SockList *sl)
void send_exp_table(socket_struct *ns, char *params)
void update_position(mapstruct *m, int x, int y)
static void append_spell(player *pl, SockList *sl, object *spell)
void SockList_AddString(SockList *sl, const char *data)
#define AddIfFloat(Old, New, Type)
mapstruct * get_map_from_coord(mapstruct *m, sint16 *x, sint16 *y)
EXTERN Animations * animations
size_t SockList_Avail(const SockList *sl)
archetype * try_find_archetype(const char *name)
#define QUERY_FLAG(xyz, p)
struct map_cell_struct cells[MAX_CLIENT_X][MAX_CLIENT_Y]
int execute_newserver_command(object *pl, char *command)
#define CS_STAT_RES_DRAIN
uint32 last_path_repelled
void send_query(socket_struct *ns, uint8 flags, const char *text)
void ask_smooth_cmd(char *buf, int len, socket_struct *ns)
#define MIN_NUM_LOOK_OBJECTS
uint32 supported_readables
void draw_client_map2(object *pl)
#define AddIfShort(Old, New, Type)
void add_me_cmd(char *buf, int len, socket_struct *ns)
void SockList_AddChar(SockList *sl, char c)
static const flag_definition flags[]
client_spell * spell_state
void receive_player_name(object *op)
sint16 resist[NROFATTACKS]
int snprintf(char *dest, int max, const char *format,...)
#define GET_MAP_FACE_OBJ(M, X, Y, L)
#define MAP_LAYER_LIVING1
sint16 last_resist[NROFATTACKS]
void set_up_cmd(char *buf, int len, socket_struct *ns)
#define NUM_ANIMATIONS(ob)
void esrv_send_face(socket_struct *ns, short face_num, int nocache)
void esrv_update_spells(player *pl)
static void check_space_for_heads(int ax, int ay, SockList *sl, socket_struct *ns)
void send_plugin_custom_message(object *pl, char *buf)
void esrv_send_pickup(player *pl)
void SockList_AddLen8Data(SockList *sl, const void *data, size_t len)
void send_class_list(socket_struct *ns, char *params)
static void map_clearcell(struct map_cell_struct *cell, int face, int count)
#define ST_CHANGE_PASSWORD_OLD
sint16 SP_level_spellpoint_cost(object *caster, object *spell, int flags)
const uint32 weight_limit[MAX_STAT+1]
void update_los(object *op)
void receive_play_again(object *op, char key)
void esrv_send_animation(socket_struct *ns, short anim_num)
void toggle_extended_infos_cmd(char *buf, int len, socket_struct *ns)
void esrv_update_stats(player *pl)
void LOG(LogLevel logLevel, const char *format,...)
uint8 anims_sent[MAXANIMNUM]
void set_title(const object *pl, char *buf, size_t len)
object * last_skill_ob[NUM_SKILLS]
void rangetostring(const object *pl, char *obuf, size_t len)
#define CS_STAT_RES_HOLYWORD
#define CS_STAT_WEIGHT_LIM
static int map2_add_ob(int ax, int ay, int layer, object *ob, SockList *sl, socket_struct *ns, int *has_obj, int is_head)
void reply_cmd(char *buf, int len, player *pl)
#define CS_STAT_TURN_UNDEAD
void SockList_AddInt(SockList *sl, uint32 data)
#define MSG_TYPE_COMMAND_ERROR
EXTERN archetype * first_archetype
void esrv_new_player(player *pl, uint32 weight)
void toggle_extended_text_cmd(char *buf, int len, socket_struct *ns)
#define MAP2_COORD_ENCODE(x, y, flags)
void esrv_map_scroll(socket_struct *ns, int dx, int dy)
void send_race_info(socket_struct *ns, char *params)
sint8 blocked_los[MAP_CLIENT_X][MAP_CLIENT_Y]
void Send_With_Handling(socket_struct *ns, SockList *sl)
void esrv_move_object(object *pl, tag_t to, tag_t tag, long nrof)
#define CS_STAT_RES_GHOSTHIT