| 1 | /** |
| 2 | * @file |
| 3 | * Defines various structures and values that are used for the |
| 4 | * new client server communication method. Values defined here are only |
| 5 | * used on the server side code. For shared client/server values, see |
| 6 | * @ref newclient.h |
| 7 | */ |
| 8 | |
| 9 | #ifndef NEWSERVER_H |
| 10 | #define NEWSERVER_H |
| 11 | |
| 12 | /** |
| 13 | * The lower bound for the number of objects to send for the 'look' window |
| 14 | * (container or ground view). |
| 15 | */ |
| 16 | #define MIN_NUM_LOOK_OBJECTS 3 /* 3=prev group, one object, next group */ |
| 17 | |
| 18 | /** |
| 19 | * Default value for the number of objects to send for the 'look' window |
| 20 | * (container or ground view). |
| 21 | */ |
| 22 | #define DEFAULT_NUM_LOOK_OBJECTS 50 |
| 23 | |
| 24 | /** |
| 25 | * The upper bound for the number of objects to send for the 'look' window |
| 26 | * (container or ground view). |
| 27 | */ |
| 28 | #define MAX_NUM_LOOK_OBJECTS 100 |
| 29 | |
| 30 | /** One map cell, as sent to the client. */ |
| 31 | struct map_cell_struct { |
| 32 | uint16_t faces[MAP_LAYERS]; /**< Face numbers. */ |
| 33 | int darkness; /**< Cell's darkness. */ |
| 34 | }; |
| 35 | |
| 36 | /** |
| 37 | * This basically defines the largest size an |
| 38 | * archetype may be - it is used for allocation of |
| 39 | * some structures, as well as determining how far |
| 40 | * we should look for the heads of big images. |
| 41 | */ |
| 42 | #define MAX_HEAD_OFFSET 8 |
| 43 | |
| 44 | #define MAX_CLIENT_X (MAP_CLIENT_X+MAX_HEAD_OFFSET) |
| 45 | #define MAX_CLIENT_Y (MAP_CLIENT_Y+MAX_HEAD_OFFSET) |
| 46 | |
| 47 | /** One map for a player. */ |
| 48 | struct Map { |
| 49 | struct map_cell_struct cells[MAX_CLIENT_X][MAX_CLIENT_Y]; |
| 50 | }; |
| 51 | |
| 52 | /** True max is 16383 given current map compaction method. */ |
| 53 | #define MAXANIMNUM 2000 |
| 54 | |
| 55 | /** Contains the last range/title information sent to client. */ |
| 56 | struct statsinfo { |
| 57 | char *range, *title; |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * What state a socket is in. |
| 63 | */ |
| 64 | enum Sock_Status { |
| 65 | Ns_Avail, |
| 66 | Ns_Add, |
| 67 | Ns_Dead |
| 68 | }; |
| 69 | |
| 70 | /** |
| 71 | * Contains parameters for socket() and bind() for listening sockets. |
| 72 | * This struct contains most fields of "struct addrinfo", but |
| 73 | * older systems do not know struct addrinfo yet. |
| 74 | */ |
| 75 | struct listen_info { |
| 76 | int family; |
| 77 | int socktype; |
| 78 | int protocol; |
| 79 | socklen_t addrlen; |
| 80 | struct sockaddr *addr; |
| 81 | }; |
| 82 | |
| 83 | /** How many times we are allowed to give the wrong password before being kicked. */ |
| 84 | #define MAX_PASSWORD_FAILURES 5 |
| 85 | |
| 86 | /** |
| 87 | * Socket structure, represents a client-server connection. |
| 88 | */ |
| 89 | typedef struct socket_struct { |
| 90 | enum Sock_Status status; |
| 91 | int fd; |
| 92 | struct listen_info *listen; |
| 93 | struct Map lastmap; |
| 94 | int8_t map_scroll_x, map_scroll_y; |
| 95 | size_t faces_sent_len; /**< This is the number of elements allocated in faces_sent[]. */ |
| 96 | uint8_t *faces_sent; /**< This is a bitmap on sent face status. */ |
| 97 | uint8_t anims_sent[MAXANIMNUM]; /**< What animations we sent. */ |
| 98 | struct statsinfo stats; |
| 99 | SockList inbuf; /**< If we get an incomplete packet, this is used to hold the data. */ |
| 100 | char *host; /**< Which host it is connected from (ip address). */ |
| 101 | uint8_t password_fails; /**< How many times the player has failed to give the right password. */ |
| 102 | uint32_t facecache:1; /**< If true, client is caching images. */ |
| 103 | uint32_t darkness:1; /**< True if client wants darkness information. */ |
| 104 | uint32_t update_look:1; /**< If true, we need to send the look window. */ |
| 105 | uint32_t update_inventory:1; /**< If true, we need to send the inventory list. */ |
| 106 | uint32_t tick:1; /**< Client wishes to get tick commands. */ |
| 107 | uint32_t is_bot:1; /**< Client shouldn't be reported to metaserver. */ |
| 108 | uint32_t want_pickup:1; /**< Client wants pickup information when logging in. */ |
| 109 | uint32_t extended_stats:1; /**< Client wants base and maximum statistics information. */ |
| 110 | uint32_t monitor_spells; /**< Client wishes to be informed when their spell list changes. */ |
| 111 | uint32_t sound; /**< Client sound mode. */ |
| 112 | bool heartbeat; /**< Client will send hearbeats. */ |
| 113 | uint32_t cs_version, sc_version; /**< Versions of the client. */ |
| 114 | uint16_t look_position; /**< Start of drawing of look window. */ |
| 115 | uint16_t container_position; /**< Start of container contents to send to client. */ |
| 116 | uint8_t mapx, mapy; /**< How large a map the client wants. */ |
| 117 | uint8_t faceset; /**< Set the client is using, default 0. */ |
| 118 | |
| 119 | /* Below are flags for extedend infos to pass to client |
| 120 | * with S->C mapextended command (note: this comment seems incorrect?) */ |
| 121 | int8_t sounds_this_tick; /**< Number of sounds sent this tick. */ |
| 122 | uint8_t num_look_objects; /**< The maximum number of objects to show on the ground view; |
| 123 | this number includes the prev/next group fake items. |
| 124 | Can be set through "num_look_objects" setup option; |
| 125 | defaults to DEFAULT_NUM_LOOK_OBJECTS. */ |
| 126 | char *account_name; /**< Name of the account logged in on this socket */ |
| 127 | Account_Char *account_chars; /**< Detailed information on characters on this account */ |
| 128 | uint8_t login_method; /**< Login method this client is using */ |
| 129 | uint16_t notifications; /**< Notifications this client wants to get. */ |
| 130 | uint32_t last_tick; /**< Number of ticks since last communication. */ |
| 131 | } socket_struct; |
| 132 | |
| 133 | /** |
| 134 | * Bitmask for the faces_sent[] array - what |
| 135 | * portion of the face have we sent? |
| 136 | */ |
| 137 | #define NS_FACESENT_FACE 0x1 |
| 138 | #define NS_FACESENT_SMOOTH 0x2 |
| 139 | |
| 140 | /** Holds some system-related information. */ |
| 141 | typedef struct Socket_Info { |
| 142 | struct timeval timeout; /**< Timeout for select. */ |
| 143 | int max_filedescriptor; /**< max filedescriptor on the system. */ |
| 144 | int allocated_sockets; /**< Number of allocated items in ::init_sockets. */ |
| 145 | } Socket_Info; |
| 146 | |
| 147 | extern Socket_Info socket_info; |
| 148 | |
| 149 | #define VERSION_CS 1023 /**< Version >= 1023 understand setup cmd */ |
| 150 | #define VERSION_SC 1029 |
| 151 | #define VERSION_INFO "Crossfire Server" |
| 152 | |
| 153 | #endif /* NEWSERVER_H */ |