… | |
… | |
75 | * current state. we set up our on buffers for sending/receiving, so we can |
75 | * current state. we set up our on buffers for sending/receiving, so we can |
76 | * handle some higher level functions. fd is the actual file descriptor we |
76 | * handle some higher level functions. fd is the actual file descriptor we |
77 | * are using. |
77 | * are using. |
78 | */ |
78 | */ |
79 | |
79 | |
80 | enum Sock_Status { Ns_Avail, Ns_Add, Ns_Dead, Ns_Old }; |
80 | enum Sock_Status { Ns_Add, Ns_Dead }; |
81 | |
|
|
82 | /* Reserver 0 for neither of these being set */ |
|
|
83 | enum Old_Mode { Old_Listen = 1, Old_Player = 2 }; |
|
|
84 | |
81 | |
85 | /* Only one map mode can actually be used, so lets make it a switch |
82 | /* Only one map mode can actually be used, so lets make it a switch |
86 | * instead of having a bunch of different fields that needed to |
83 | * instead of having a bunch of different fields that needed to |
87 | * get toggled. |
84 | * get toggled. |
88 | */ |
85 | */ |
… | |
… | |
98 | int start; |
95 | int start; |
99 | int len; |
96 | int len; |
100 | }; |
97 | }; |
101 | |
98 | |
102 | /* how many times we are allowed to give the wrong password before being kicked. */ |
99 | /* how many times we are allowed to give the wrong password before being kicked. */ |
103 | # define MAX_PASSWORD_FAILURES 5 |
100 | #define MAX_PASSWORD_FAILURES 5 |
104 | |
101 | |
105 | ACC_CLASS (client_socket) // should become player when newsocket is a baseclass of player |
102 | ACC_CLASS (client_socket) // should become player when newsocket is a baseclass of player |
106 | struct client_socket : zero_initialised |
103 | struct client_socket : zero_initialised, attachable_base |
107 | { |
104 | { |
108 | enum Sock_Status status; |
105 | enum Sock_Status status; |
109 | int ACC (RW, fd); |
106 | int ACC (RW, fd); |
110 | unsigned int inbuf_len; // number of bytes valid in inbuf |
107 | unsigned int inbuf_len; // number of bytes valid in inbuf |
111 | struct Map lastmap; |
108 | struct Map lastmap; |
… | |
… | |
115 | struct statsinfo stats; |
112 | struct statsinfo stats; |
116 | |
113 | |
117 | char *ACC (RW, host); /* Which host it is connected from (ip address) */ |
114 | char *ACC (RW, host); /* Which host it is connected from (ip address) */ |
118 | uint8 ACC (RW, password_fails); /* how many times the player has failed to give the right password */ |
115 | uint8 ACC (RW, password_fails); /* how many times the player has failed to give the right password */ |
119 | Buffer outputbuffer; /* For undeliverable data */ |
116 | Buffer outputbuffer; /* For undeliverable data */ |
|
|
117 | |
120 | uint32 ACC (RO, facecache):1; /* If true, client is caching images */ |
118 | bool ACC (RW, facecache); /* If true, client is caching images */ |
121 | uint32 ACC (RO, sent_scroll):1; |
119 | bool ACC (RW, sent_scroll); |
122 | uint32 ACC (RO, sound):1; /* does the client want sound */ |
120 | bool ACC (RW, sound); /* does the client want sound */ |
123 | uint32 ACC (RO, exp64):1; /* Client wants 64 bit exp data, as well as skill data */ |
121 | bool ACC (RW, exp64); /* Client wants 64 bit exp data, as well as skill data */ |
124 | uint32 ACC (RO, newmapcmd):1; /* Send newmap command when entering new map SMACFIGGEN */ |
122 | bool ACC (RW, newmapcmd); /* Send newmap command when entering new map SMACFIGGEN */ |
125 | uint32 ACC (RO, plugincmd):1; /* CF+ extend the protocol through a plug-in */ |
123 | bool ACC (RW, plugincmd); /* CF+ extend the protocol through a plug-in */ |
126 | uint32 ACC (RO, mapinfocmd):1; /* CF+ return map info and send map change info */ |
124 | bool ACC (RW, mapinfocmd); /* CF+ return map info and send map change info */ |
127 | uint32 ACC (RO, extcmd):1; /* CF+ call into extensions/plugins */ |
125 | bool ACC (RW, extcmd); /* CF+ call into extensions/plugins */ |
128 | uint32 ACC (RO, extmap):1; /* CF+ extend map comamnd with extra data */ |
126 | bool ACC (RW, extmap); /* CF+ extend map comamnd with extra data */ |
129 | uint32 ACC (RO, buggy_mapscroll):1; /* CF+ client crashes on large mapscrolls */ |
127 | bool ACC (RW, buggy_mapscroll); /* CF+ client crashes on large mapscrolls */ |
130 | uint32 ACC (RO, darkness):1; /* True if client wants darkness information */ |
128 | bool ACC (RW, darkness); /* True if client wants darkness information */ |
131 | uint32 ACC (RO, image2):1; /* Client wants image2/face2 commands */ |
129 | bool ACC (RW, image2); /* Client wants image2/face2 commands */ |
132 | uint32 ACC (RO, update_look):1; /* If true, we need to send the look window */ |
130 | bool ACC (RW, update_look); /* If true, we need to send the look window */ |
133 | uint32 ACC (RO, can_write):1; /* Can we write to this socket? */ |
|
|
134 | uint32 ACC (RO, has_readable_type):1; /* If true client accept additional text information |
131 | bool ACC (RW, has_readable_type); /* If true client accept additional text information */ |
135 | used to arrange text in books, scrolls, or scripted dialogs */ |
132 | /* used to arrange text in books, scrolls, or scripted dialogs */ |
136 | uint32 ACC (RO, monitor_spells):1; /* Client wishes to be informed when their spell list changes */ |
133 | bool ACC (RW, monitor_spells); /* Client wishes to be informed when their spell list changes */ |
137 | uint32 ACC (RO, ext_mapinfos):1; /* If true client accept additionnal info on maps */ |
134 | bool ACC (RW, ext_mapinfos); /* If true client accept additionnal info on maps */ |
138 | /* Below are flags for extedend infos to pass to client |
135 | /* Below are flags for extedend infos to pass to client |
139 | * with S->C mapextended command */ |
136 | * with S->C mapextended command */ |
140 | uint32 ACC (RO, EMI_smooth):1; /* Send smooth in extendmapinfos */ |
137 | bool ACC (RW, EMI_smooth); /* Send smooth in extendmapinfos */ |
|
|
138 | |
141 | uint32 ACC (RW, supported_readables); /* each bit is a readable supported by client */ |
139 | uint32 ACC (RW, supported_readables); /* each bit is a readable supported by client */ |
142 | uint32 ACC (RW, cs_version), ACC (RW, sc_version); /* versions of the client */ |
140 | uint32 ACC (RW, cs_version), ACC (RW, sc_version); /* versions of the client */ |
143 | enum MapMode mapmode; /* Type of map commands the client wants. */ |
141 | enum MapMode mapmode; /* Type of map commands the client wants. */ |
144 | uint16 ACC (RW, look_position); /* start of drawing of look window */ |
142 | uint16 ACC (RW, look_position); /* start of drawing of look window */ |
145 | uint8 ACC (RW, mapx), ACC (RW, mapy); /* How large a map the client wants */ |
143 | uint8 ACC (RW, mapx), ACC (RW, mapy); /* How large a map the client wants */ |
… | |
… | |
150 | int ACC (RW, current_x), ACC (RW, current_y); // CF+ last/current map position |
148 | int ACC (RW, current_x), ACC (RW, current_y); // CF+ last/current map position |
151 | char ACC (RW, client)[64]; // CF+ client name/version |
149 | char ACC (RW, client)[64]; // CF+ client name/version |
152 | |
150 | |
153 | /* If we get an incomplete packet, this is used to hold the data. */ |
151 | /* If we get an incomplete packet, this is used to hold the data. */ |
154 | uint8 inbuf[MAXSOCKBUF]; |
152 | uint8 inbuf[MAXSOCKBUF]; |
|
|
153 | player *pl;//TODO should not be here, preferably |
155 | |
154 | |
156 | client_socket (); |
155 | iow socket_ev; void socket_cb (iow &w, int got); |
|
|
156 | |
|
|
157 | client_socket (int fd, const char *from_ip); |
157 | ~client_socket (); |
158 | ~client_socket (); |
158 | void init (const char *from_ip); |
|
|
159 | |
159 | |
160 | int read_packet (); // returns length of packet or 0 |
160 | int read_packet (); // returns length of packet or 0 |
161 | void skip_packet (int len); // we have processed the packet, skip it |
161 | void skip_packet (int len); // we have processed the packet, skip it |
162 | |
162 | |
|
|
163 | void flush (); |
|
|
164 | void write_outputbuffer (); |
163 | void send (void *buf_, int len); |
165 | void send (void *buf_, int len); |
164 | |
166 | |
165 | void send_packet (const char *buf); |
167 | void send_packet (const char *buf); |
166 | void send_packet (const char *buf, int len); |
168 | void send_packet (const char *buf, int len); |
167 | void send_packet (packet &sl); |
169 | void send_packet (packet &sl); |
… | |
… | |
205 | #define EMI_HASMOREBITS 0x80 |
207 | #define EMI_HASMOREBITS 0x80 |
206 | |
208 | |
207 | #define FACE_TYPES 1 |
209 | #define FACE_TYPES 1 |
208 | #define PNG_FACE_INDEX 0 |
210 | #define PNG_FACE_INDEX 0 |
209 | |
211 | |
210 | struct Socket_Info |
|
|
211 | { |
|
|
212 | struct timeval timeout; /* Timeout for select */ |
|
|
213 | int max_filedescriptor; /* max filedescriptor on the system */ |
|
|
214 | int nconns; /* Number of connections */ |
|
|
215 | int allocated_sockets; /* number of allocated in init_sockets */ |
|
|
216 | }; |
|
|
217 | |
|
|
218 | extern Socket_Info socket_info; |
|
|
219 | |
|
|
220 | #define VERSION_CS 1023 /* version >= 1023 understand setup cmd */ |
212 | #define VERSION_CS 1023 /* version >= 1023 understand setup cmd */ |
221 | #define VERSION_SC 1027 |
213 | #define VERSION_SC 1027 |
222 | #define VERSION_INFO "Crossfire+ Server" |
214 | #define VERSION_INFO "Crossfire+ Server" |
223 | |
215 | |
|
|
216 | typedef unordered_vector<client_socket *> sockvec; |
|
|
217 | |
|
|
218 | extern sockvec client_sockets; |
|
|
219 | extern int nrofpixmaps; //TODO: hrmpf, should go |
|
|
220 | |
224 | #endif |
221 | #endif |
225 | |
222 | |