Debian Codegraph @

doc/Developers/protocol.txt

raw
1 Crossfire Protocol Handbook
2 ===========================
3 Crossfire Development Team <[email protected]>
4 :numbered:
5 :toc:
6
7 This handbook is the collective result of various authors compiled together
8 over the course of many years, most of the time after the actual code was
9 already written (for a long time). As such it will surely contain errors, omit
10 certain important details, and possibly make life miserable. Nevertheless, any
11 new developer or curious player should be able to find most of the relevant
12 information here. If inconsistencies are found or this documentation proves to
13 be inadequate, consider the latest server-side protocol code in the public
14 source code repository as the authoritative reference.
15
16 Introduction
17 ------------
18 If you were ever curious enough to `telnet` or `netcat` to a Crossfire server,
19 chances are you were sorely disappointed. While the protocol may seem to use
20 plain text at first, it actually uses a mix of ASCII and binary data. This
21 handbook attempts to document various aspects of the Crossfire protocol.
22
23 As always, consult the 'README' file to find out how to get in touch with
24 helpful people via mailing lists, IRC, and more.
25
26 History
27 ~~~~~~~
28 Originally, the communications plan was set to be a text based system. It
29 was up to the server and client to parse these messages and determine what
30 to do. These messages were assumed to be 1 line per message.
31
32 At a reasonably early stage of development, Eric Anderson wrote a fairly
33 (but not totally) complete client/server that used his eutl package. This
34 package pretty much set up packets with subpackets - these subpackets would
35 have a tag for the data type, then the data itself. Thus, you could send
36 many data types, and after transmission, the other end could decode these
37 commands.
38
39 This works fairly well, but I think the creation of numerous sub packets has
40 some performance hit. Also, the eutl was not especially well documented, so
41 writing a client for a different platform became more difficult (you needed
42 to first port over eutl.) An example such of this is the Java client. Also,
43 Eric left to work on other products shortly after writing his client, which
44 didn't really leave anyone with a full understanding of the socket code.
45
46 I have decided to remove the eutl dependency. At least one advantage is that
47 having this network related code directly in the client and server makes
48 error handling a bit easier/cleaner.
49
50 Packet Format
51 ~~~~~~~~~~~~~
52 IMPORTANT: Instead of a straight text method, the outside packet method is:
53 <size (2 bytes)><data (size bytes)> The <size> is the size of the data
54 packet, the 2 byte size for the size information is not included here.
55
56 Eutl originally used 4 bytes for the size - to me, 2 bytes seems plenty
57 (gives a maximum packet of 32767 - I can't see ever going beyond a few
58 thousand, simply because in a fast action game, transmission size of such a
59 packet would probably not make things playable.) While saving 2 bytes might
60 not be much, it makes a least some sense.
61
62 The actual data is something of the nature of the commands listed below. It
63 is a text command, followed by possible other data. The remaining data can
64 be binary - it is up to the client and server to decode what it sent.
65
66 The commands as described below is just the data portion of the packet. If
67 writing a new client, remember that you must take into account the size of
68 the packet. There is no termination of packets, other than knowing how long
69 it should be.
70
71 For now, most everything that is sent is text. This is more or less how
72 things worked under eutl, except it packed the ints into 4 bytes in a known
73 order. In some cases, we handle ints as strings, in others, they are sent as
74 binary information. How any command handles it is detailed below in the
75 command description.
76
77 The S and C represent the direction of the data (S->C represents something
78 the server sends to the client, C->S represents something the client sends
79 to the server.)
80
81 In terms of all binary values, we use MSB order (same as eutl used). MSB
82 order is also network byte order. This includes the initial length
83 information, as well as any ints or shorts that get sent inside the packets.
84 All packets are defined to have at least one word of text, followed by a
85 space, then followed by optional data (which can be binary.)
86
87 NOTE: Generally, the data the client sends to the server is text, but a fair
88 amount of data the server sends to the client is binary. This has somewhat
89 to do with who wrote what code, and also has to do that the S->C bandwidth
90 is going to more the more serious limitation - the client generally won't be
91 sending so much data that the its flow is much problem.
92
93 Note that all the commands as detailed below are up to date descriptions I
94 removed a lot of the old notes on this file, because they were out of date,
95 and while might be good ideas, were not all that relevant to how things
96 currently work.
97
98 Summary: Packets sent back and forth have a 2 byte header (MSB order) which
99 contains the length of the rest of the packet.
100
101 Implementation Notes
102 ~~~~~~~~~~~~~~~~~~~~
103 We are using a TCP/IP socket. Other methods could be used, but the
104 present protocol does not make very good provisions for missing data, so
105 it needs to be something that corrects errors/does resends automatically
106 (or just doesn't get errors in the first place.)
107
108 For now, we set non blocking output on the server side. This means we don't
109 have to worry about internal buffering.
110
111 If the connection is lost (which will also happen if the output buffer
112 overflowing), the player is saved and the server cleans up. This does
113 open up some abuses, but there is no perfect solution here.
114
115 The server only reads data from the socket if the player has an action.
116 This isn't really good, since many of the commands below might not be actual
117 commands for the player. The alternative is to look at the data, and if it
118 is a player command and there isn't time, store it away to be processed later.
119 But this increases complexity, in that the server must start buffering the
120 commands. Fortunately, for now, there are few such client commands.
121
122 If it becomes a case where the client is requesting images/sounds, dual
123 channels could probably be used, since requesting that data is not related
124 to the actual playing of the game (or a special daemon that serves those
125 requests could also be done.) Better solution might be for that data to
126 be on a separate server that can be downloaded by more efficient mechanisms
127 (eg, ftp)
128
129 SUMMARY: TCP/IP sockets are used for exchange data. Server uses non
130 blocking i/o when writing to the socket, and the server only reads from the
131 socket when the player actually has time for an action.
132
133 Data Type Conventions
134 ~~~~~~~~~~~~~~~~~~~~~
135 In the listing of the protocol commands below, different terms are used
136 to describe the data. This section is used to clarify what the different
137 types are:
138
139 string: A set of ASCII characters. If a protocol command has several string
140 fields, then spaces are used to separate the strings.
141
142 length prefixed string: An 8 bit length field prepends the string. EG:
143 <length><string>
144 length prefixed strings are often used in cases where the string
145 contains space, and the protocol command includes several strings
146 or there are other fields following the string. The receiving
147 end can decode the length, know how much data to copy and where
148 the start of the next field is.
149
150 string value of integer data: This notes that the data is stored on
151 the server (and client) as integer data, but it is converted to
152 string data before sending (eg, sprintf(buf,"%d", val)).
153 It means that the receiver will need to use atoi or the like
154 to convert it back into the appropriate type.
155
156 binary X bit value (also X bit binary value): This notes that the data
157 is sent as raw binary data of the given size. shorts would be
158 16 bit, ints 32 bit, long longs 64 bit, etc.
159
160
161 Commands
162 --------
163 Object tags: Many of the commands below refer to 'object tags'. Whenever
164 the server creates an object, it creates a unique tag for that object
165 (starting at 1 when the server is first run, and ever increasing.) Tags are
166 unique, but are not consistent between runs. Thus, the client can not store
167 tags when it exits and hope to re-use them when it joins the server at a
168 later time - tags are only valid for the current connection.
169
170 The protocol commands are broken into various sections which based somewhat
171 on what the commands are for (ie, item related commands, map commands, image
172 commands, etc.) In this way, all the commands related to similar
173 functionality is in the same place.
174
175 General Commands
176 ~~~~~~~~~~~~~~~~
177 failure
178 ^^^^^^^
179 S->C: failure <protocol command> <failure string>
180
181 All fields are strings.
182
183 <protocol command> is the command (just the command portion, eg, version,
184 accountlogin, not with any additional data) that generated the failure.
185
186 <failure string> is a message which notes the failure - it will be displayed
187 to the player, so should be informative to the player so they can take
188 corrective action (omit illegal characters from their username, etc)
189
190 This command is used to denote failure in some way (as detailed in failure
191 string) of a protocol command. This does not mean that there was an error
192 in the protocol (which typically results in a command being dropped), but
193 rather that the server was unable to complete the given protocol request.
194
195 As of this writing (Jan 2010), this is used only in the account login code -
196 if the user enters incorrect login information, it will generate a failure
197 message.
198
199 The use of this protocol command, and it including the protocol command
200 which failed, better informs the client it needs to retry. For example, if
201 the user enters wrong account information, the server will send `failure
202 accountlogin wrong user name or password`. With this, the client can
203 display the message in the correct location, but also knows it needs to go
204 back to the point of asking for login information. draw_info provides no
205 mechanism to tell the client to retry an event.
206
207 This command is really meant for areas where the client is interacting with
208 the users. This command is not especially good in cases where the client
209 has sent several protocol commands of the same type - this command will only
210 tell that a command of that name failed, but may not include enough
211 information to note which of several commands failed.
212
213 Note that the format of message, while text data, can contain other
214 information. In particular, some messages may have the first 'word' be a
215 number which denotes some type of status - this will be detailed in the
216 protocol area for that command. For example:
217
218 failure accountaddplayer 0 That name is too long failure accountaddplayer 1
219 That character is associated with another account
220
221 The client should intercept that number and not display it, but this may
222 indicate that the command is retriable by changing a parameter - in the case
223 of accountaddplayer, if force is set, the second message there is not an
224 error.
225
226 version
227 ^^^^^^^
228 C->S: version <csval> [scval [vinfo]]
229 S->C: version <csval> [scval [vinfo]]
230
231 All fields are strings.
232
233 Through the version command, the client and server exchange what version of
234 the protocol they understand. Neither send this in response to the other -
235 they should both send this shortly after a connection is established.
236
237 csval is the version level of C->S communications. scval is the version
238 level of S->C communications. vinfo is a string that is purely for
239 informative that general client/server info (ie, javaclient, x11client,
240 winclient, sinix server, etc). It is purely of interest of server admins
241 who can see what type of clients people are using.
242
243 If a new command is added to the protocol in the C->S direction, then the
244 version number in csval will get increased. Likewise, the same is true for
245 the scval.
246
247 As far as the client is concerned, its scval must be at least equal to the
248 server, and its csval should not be newer than the server.
249
250 The server does not care about the version command it receives right now -
251 all it currently does is log mismatches. In theory, the server should keep
252 track of what the client has, and adjust the commands it sends respectively
253 in the S->C direction. The server is resilant enough that it won't crash
254 with a version mismatch (however, client may end up sending commands that
255 the server just ignores). It is really up to the client to enforce
256 versioning and quit if the versions don't match.
257
258 scval and vinfo was added starting in 1020. Before that version, there was
259 only one version sent in the version command.
260
261 The version are currently integers, in the form ABCD. A = 1, and will
262 likely for quite a while. This will only really change if needed from
263 rollover of B.
264
265 B represents major protocol changes - if B mismatches, the clients will be
266 totally unusable. Such an example would be change of map or item sending
267 commands (either new commands or new format.)
268
269 C represents more minor but still significant changes - clients might still
270 work together, but some features that used to work may now fail due to the
271 mismatch. An example may be a change in the meaning of some field in some
272 command - providing the field is the same size, it still should be decoded
273 properly, but the meaning won't be processed properly.
274
275 D represents very minor changes or new commands. Things should work no
276 worse if D does not match, however if they do match, some new features might
277 be included. An example of the would be the C->S mark command to mark
278 items. Server not understanding this just means that the server can not
279 process it, and will ignore it.
280
281 NOTE: Since all packets have the length as the first 2 bytes, all that
282 either the client or server needs to be able to do is look at the first
283 string and see if it understands it. If not, it knows how many bytes it can
284 skip. As such, exact version matches should not be necessary for proper
285 operation - however, both the client and server needs to be coded to handle
286 such cases.
287
288 NOTE: For the most part, this has been obsoleted by the setup command
289 which always return status and whether it understood the command or not.
290 However there are still some cases where using this versioning is useful -
291 an example it the addition of the requestinfo/replyinfo commands - the
292 client wants to wait for acknowledge of all the replyinfo commands it has
293 issued before sending the addme command. However, if the server doesn't
294 understand these options, the client will never get a response. With the
295 versioning, the client can look at the version and know if it should wait
296 for a response or if the server will never send back.
297
298 accountlogin and accountnew
299 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
300 C->S: accountlogin <account name><account password>
301 C->S: accountnew <account name><account password>
302 S->C: failure <protocol command> <message>
303
304 <account name> is a length prefixed string of the account name. <account
305 password> is a length prefixed string of the password.
306
307 Under new login support (loginmethod >=1) the client will query the user for
308 account information - this sends that information to the server. In the
309 first place, the user is trying to log in with an established account, in
310 the second, the user is trying to create a new account.
311
312 It is up to the client to determine what is trying to be done - in general,
313 this means that player should be hitting a 'new account' type button or a
314 the like. It is up to the client to do double confirmation of passwords,
315 etc.
316
317 account name and account password are strings, with the first byte being the
318 length of the string.
319
320 If the login or creation fails, a failure protocol message is generated.
321 That is documented up above. The client should retry in that case.
322
323 accountplayers
324 ^^^^^^^^^^^^^^
325 S->C: accountplayers <num characters><char data1><char data2>...
326
327 [options="autowidth,header"]
328 |===========================
329 |Field|
330 Description
331
332 |<num characters>|
333 8 bit binary value noting how many characters on this account. It may be
334 zero.
335
336 |<char data>|
337 length prefixed data on character. The ACL_... values in newclient.h
338 define these. The format of each data value is:
339
340 <len><type><value>
341
342 <len> is an 8 bit value which is the length of type + value - in this way,
343 the client can skip over the entire field in cases where it does not know
344 the type. If len is 0, it notes that there is no more information for
345 this character.
346
347 <type> is an 8 bit value which is an ACL_ type value.
348
349 |<value>|
350 type specific - if a string value, it is just a string value. If binary,
351 its length can be determined. Except for noted values, all value types are
352 strings. Exceptions:
353
354 ACL_LEVEL:: is a 16 bit binary value.
355 ACL_FACE_NUM:: is a 16 bit binary value.
356 |===========================
357
358 NOTE: There is no requirement that the server sends all fields (may choose
359 to not send empty fields.) Likewise, there is no requirement they get sent
360 in a specific order.
361
362 This is a list of the players (characters) associated with this account. In
363 the case of new accounts, the num characters will be zero.
364
365 This is sent after the server receives a successful login or accountnew
366 request. The client can thus use the receipt of this command, even if
367 empty, to note that the user has logged in.
368
369 accountplay
370 ^^^^^^^^^^^
371 C->S: accountplay <char name>
372
373 <char name> string value of the character to play.
374
375 Play character of the given name. This must be one of the character names
376 returned by the accountplayers command - otherwise it will generate an
377 failure protocol command. On choosing a character, the game will log in and
378 play will start.
379
380 Upon receipt of this command, the server will do necessary setup to start
381 play. This removes the need for the addme command below.
382
383 accountaddplayer
384 ^^^^^^^^^^^^^^^^
385 C->S: accountaddplayer <force> <char name> <char password>
386
387 <force> - 8 bit binary data to force this association (see description
388 below. This is not an optional field - it must always be sent.
389
390 <char name> length prefixed string of the character name.
391
392 <char password> length prefixed string of the characters password.
393
394 Add a character to the logged in account. Both the name and password are
395 needed. In the event that the given character is already associated with an
396 account (and not this one), a failure message will be generated unless force
397 is on.
398
399 The flow in that case would be user enter name/password and hitting submit,
400 client sends to server, server sends failure event to client saying
401 character is already associated with account, client asks player if he wants
402 to override that setting, and if they hit yes, command is then sent with
403 force set to 1.
404
405 On success, the server will send a new accountplayers command, with all
406 characters for this account. On failure, a failure message will be
407 generated.
408
409 The failure message for accountaddplayer does include the optional integer
410 parameter - if 0, the command is not retriable - if set to 1, then this
411 account may succeed if force is set.
412
413 createplayer
414 ^^^^^^^^^^^^
415 C->S: createplayer <name><password>
416
417 The player wants to make a new player - this is done on the client -
418 this basically tells the server to send the client information regarding
419 making new characters (races, classes, etc).
420
421 Loginmethod 1 supports following:
422 <name>: Length prefixed string - desired character name.
423 <password>: Length prefixed string - password
424
425 Loginmethod 2 adds the following (each of these blocks are length
426 prefixed so the server can easily skip lines). To make processing
427 simpler, the null byte is included in the processing here.
428
429 race <race arch name>
430 class <class arch name>
431 <statname> <statvalue> (eg, Str 18)
432 starting_map <map arch>
433 choice <choice name> <choice value>
434
435 The client should query the player for these values through some method.
436 The statvalues that are sent are the values _before_ race and class
437 adjustments.
438
439 The <map arch> for starting_map is the value of INFO_MAP_ARCH_NAME as
440 returned by the 'startingmap' requestinfo.
441
442 The choice values are included in the race/class information as retrieved by
443 requestinfo. If the server is providing choices, it must also accept them
444 in return.
445
446 createplayer can return failure in case of invalid name, name already in
447 use, invalid race or class, stat value at of range, sum of stats too high,
448 etc.etc.
449
450 NOTE: Expected that this command will expand with new character creation
451 method.
452
453 accountpw
454 ^^^^^^^^^
455 C->S: accountpw <current account password><new account password>
456 S->C: failure accountpw <message>
457
458 <current account password> is a length prefixed string of the current
459 password.
460
461 <account password> is a length prefixed string of the new password.
462
463 Tells the server to change the password for the current account. A failure
464 message is generated if something is wrong. If all goes well the server will
465 send the character list for the account.
466
467 addme
468 ^^^^^
469 C->S: addme
470
471 Tells the server that it should add me (the client) to the game.
472 Generally, the client will always send this command, but I suppose there
473 can be actions the client wants to do before being added.
474
475 Deprecated - this has been superseded by the accountplay command.
476
477 S->C: addme_failed
478 S->C: addme_success
479
480 This are responses to the last addme command. I really think these should
481 be discontinued, as they are one of the few messages which is just a
482 confirmation of a previous message. The addme_failed should really be
483 replaced with a terminate type of of message (player quits game, server
484 could inform us nicely and exit out). addme_success is really of no use -
485 client just throws it away.
486
487 NOTE: With account based login method, server will send the addme_success in
488 certain circumstances - this is really to tell the client that play has
489 started and hide any login/character selection information. However the
490 note above still applies - addme_failed could get replaced by a 'failure
491 addme ...' type response, and there is probably some use for having a
492 'success' type protocol response to tell the client that something has
493 worked - right now, this is done by the client seeing the next message in a
494 protocol state (eg, accountplayers follows an accountlogin request)
495
496 goodbye
497 ^^^^^^^
498 S->C: goodbye (Added in SC protocol version 1022)
499
500 Informs the client that the server has finished transmitting data to the
501 client. This is a bit cleaner than the client detecting a read error. In
502 theory, a C->S of the same type could be done, but I don't think it would
503 make a big difference for the server (is going to do the same thing
504 regardless of a clean connection drop or a bad one).
505
506 Also see the `setfacemode` command below.
507
508 Info Window Input/Output
509 ~~~~~~~~~~~~~~~~~~~~~~~~
510
511 C->S: ncom <packet> <repeat> <command>
512
513 (ncom = new command)
514
515 <packet> is a 16 bit binary value the server will send back through comc to
516 inform the client of execution of this command. It is up to the client to
517 determine how it wants to number these, but incrementing by one is the
518 easiest way.
519
520 <repeat> is a 32 bit binary value and is the repeat value, or a count value
521 used for instance for dropping.
522
523 <command> string value of the actual command data (north, whatever).
524
525 Client sends a command to the server. Ordinary commands (ie, north, west,
526 apply, maps, etc), might be sent, commands with options may be sent (ie,
527 'invoke create food of booze', 'cast medium fireball'). There are a few
528 special commands that can also be sent.
529
530 'fire' command is a special case. The server will handle repeat firing.
531
532 'fire_stop' will be sent to inform the server to stop firing. A different
533 command name has been chosen to make things easier on the server
534 ('fire_stop' should be a 0 time command, with the rest of the fire commands
535 actually taking some time.) In some cases, 'fire_stop' may be sent almost
536 immediately after the first fire (in cases where the player only wants to
537 fire once).
538
539 S->C: comc <packet> <time>
540
541 (comc = completed command)
542
543 <packet> 16 bit binary value of command just completed.
544
545 <time> 32 bit binary value
546
547 This is used in the window of the ncom command above. packet is the command
548 number we just executed, and time is a 32 bit value represent how many
549 milliseconds the player is currently taking to execute commands. This
550 information can be used by the client to do some throttling.
551
552 C->S: reply <text>
553
554 <text> is string data.
555
556 ends <text> as a reply to the last query command sent.
557
558 S->C: query <flags> [text]
559
560 <flags> is string value of integer data.
561
562 [text] is optional text in string format.
563
564 Asks the client program for input. This is only used in a few places -
565 mostly in creating a character and login, but in fact anyplace in the server
566 that changes the input state (pl->contr->state, ST_*), should send a query.
567
568 <flags> are detailed in the <newclient.h> file, which is common to both the
569 client and server. The flags of relevance to this command are the CS_QUERY
570 flags. <flags> are sent in plaintext form.
571
572 The client is free to ignore the flags. However, if the server just wants a
573 single character as a reply, that is all it uses, even if the client sends a
574 long string (Server will use the first character.)
575
576 [text] is the question/prompt that should be printed. Right now, it is
577 typically just a ':'. Client should display it no matter what it is,
578 however. Text is an optional field. Note - as of 0.94.2, text may be multi
579 line, delimited by newlines. Client should handle this appropriately.
580
581 S->C: drawextinfo <color> <type> <subtype> message
582
583 <color> string integer data - color to draw text in.
584
585 <type> string integer data - type of message
586
587 <subtype> string integer data - subtype (flavor) of message.
588
589 <message> is a string representation of textual message. Content of message
590 may very well vary depending on the type.
591
592 Tell the client to draw specific text. Color are specified in newclient.h,
593 and is sent as a string (look for NDI values). The client is free to do
594 whatever it wants with the color information (it may very well ignore it.)
595
596 The list of types and subtypes is fully listed in the newclient.h file -
597 look for the MSG_TYPE fields. The subtypes of a given type are listed with
598 longer macro definition.
599
600 It is up to the client on how it wants to display the different message
601 types - it may have a nice graphic to display certain messages, route them
602 to certain windows, change color, etc.
603
604 Item Manipulation
605 ~~~~~~~~~~~~~~~~~
606 move
607 ^^^^
608 C->S: move <to> <tag> <nrof>
609
610 <to> string integer data. Tag of destination object.
611
612 <tag> string integer data. Tag of object to move.
613
614 <nrof> string integer data. Number of objects to move.
615
616 This command is used to pickup/drop objects. If <to> or <tag> is zero, the
617 object is being moved from/to the ground. This command is used to move items
618 from a container into inventory and vice versa. if nrof is zero, all objects
619 will be moved.
620
621 examine
622 ^^^^^^^
623 C->S: examine <val>
624
625 <val> string integer data. Tag of object to examine.
626
627 Tells the server that I want to examine object <val>, where <val> is a text
628 string that represents that objects tag.
629
630 apply
631 ^^^^^
632 C->S: apply <val>
633
634 <val> string integer data. Tag of object to apply.
635
636 Tells the server that I want to apply the object <val>.
637
638 lock
639 ^^^^
640 C->S: lock <val><tag>
641
642 <val> binary 1 byte data. 0=unlock, 1=lock
643
644 <tag> binary 4 byte data. tag of object to lock
645
646 Tells to server to set the inventory lock flag of item tag to val. val of 1
647 means that the item should be locked, 0 means unlocked. The server should
648 send an 'upditem' command with new flags to reflect this change.
649
650 mark
651 ^^^^
652 C->S: mark <tag>
653
654 <tag> binary 4 byte data - tag of item to mark.
655
656 'marks' and item for secondary usage. Some actions in crossfire require an
657 action that uses another item (improvement scrolls, flint & steel). In order
658 not to rely on inventory ordering or other gimmicks, this 'marked' item is
659 used. Only one item can be marked at a time - server will only keep track of
660 the latest mark sent. <tag> is a 4 byte binary value. The server will
661 generally send a drawinfo command informing the player, but there is no
662 especially easy way for the client to know what the marked item is (although,
663 client knowing this is not strictly needed)
664
665 inscribe
666 ^^^^^^^^
667 C->S: inscribe <version><spell tag><scroll tag>
668
669 <version> binary 1 byte value - version of inscribe command. Current, only
670 supported value here is 0.
671
672 <spell tag> binary 4 byte data - tag of spell to write. <scroll tag> binary 4
673 byte data. Scroll to write spell onto..
674
675 Player wants to write spell on scroll . This is roughly equivalent of manually
676 marking an item, readying the spell, and using the inscription skill.
677
678 item2
679 ^^^^^
680 S->C: item2 <location><tag1><flags1><weight1><face1><name1><anim1>
681 <animspeed1><nrof1><type1><object2....>
682
683 <location> 4 byte binary data. Location of the object - 0=ground, any other
684 value is where it is - container or player.
685
686 <tag1> 4 byte binary data. Unique item tag for this object. Note that the
687 server will use this command to note that objects have moved locations, so the
688 client should examine all objects it knows about for this tag - it should not
689 assume this is a new item.
690
691
692 <flags1> 4 byte binary data. Various flags on the item (curse, applied, etc).
693 They are detailed in newclient.h
694
695 <weight1> 4 byte binary data. The weight of single one of these objects (in
696 grams). The client will need to figure the total weight on its own. Note that
697 for containers, weight will the the total weight (that of the container plus
698 contents)
699
700 <face1> 4 byte binary data. This is the face number. These are not guaranteed
701 to be the same across different runs of the game (however, in reality, they
702 will only change on the one server if they make changes to the archetypes and
703 rebuild.) Some face information will be sent from the server to the client
704 before actually sending a face number.
705
706 <name1> length prefixed string. The name of the object. Starting at SC 1024,
707 this name is two strings, with a null separation. The first of these strings
708 is the singular form, the second is the name to use for multiple (plural
709 version) The first byte (length) is the length for both of these strings. This
710 name information is just the information of what the object is called. It does
711 not include how many of the items there are.
712
713 <anim1> 2 byte binary data. This is the animation sequence id to use. The
714 server will send an 'anim' command for this before sending an item1 command
715 with this anim command.
716
717 <animspeed1> 1 byte binary data. How often the object should be animated. This
718 is the number of ticks that should pass between each animation (a value of 1
719 means it should be animated every tick.) 1 byte limits this to once every 255
720 ticks - I can't see anything being animated slower than that.
721
722 <nrof1> 4 byte binary data. How many objects comprise this item. This is used
723 for the name field and calculating total weight.
724
725 <type1> 2 byte binary data. A numeric type id for the item. The only meaning
726 of this value is really for sorting - all armors will have type values the
727 same or near that each other. The client is free to ignore this.
728
729 Note that multiple items can be sent with a single item2 command - there is
730 only 1 location for all items, so all items have to be in the same spot, but
731 in the case of a players inventory, a single item2 with a large number of
732 items can be sent.
733
734 upditem
735 ^^^^^^^
736 S->C: upditem <flags><tag><vals>+
737
738 <flags> 1 byte binary value. flags determines what values are sent and to be
739 updated (for a definition of the flag values, see the UPD_ flags in
740 newclient.h file.)
741
742 <tag> 4 byte binary data. Tag of the item to update.
743
744 <vals> binary data of varying length. The data to be updated. The format of
745 the data is the same as the item2 command above. The order of the data is that
746 the the UPD_ flags from LSB to MSB (thus, location, flags, weight, ...)
747
748 Only one item can be updated with the upditem command. An item command should
749 have been sent by the server before an upditem command is set.
750
751 delitem
752 ^^^^^^^
753 S->C: delitem <tag1>[tag2]...
754
755 <tag> 4 byte binary data. These are the tags of the items to delete. Multiple
756 tags can be sent with one delitem to delete multiple items, but as of this
757 writing (Jan 2010), the server only ever sends a single tag
758
759 Tells the client to delete items with the tag values. These items are
760 considered gone from the game, so the client should delete all reference it
761 has to them.
762
763 delinv
764 ^^^^^^
765 S->C delinv <tag>
766
767 <tag> string integer data.
768
769 Tells the client to delete items carried in/by the object <tag>. Tag of 0
770 means to delete all items on the space tech character is standing on. This
771 command only affects the inventory of the object. To fully delete a container
772 object, a delinv followed by a delitem should be issued.
773
774 addspell
775 ^^^^^^^^
776 S->C addspell <tag1> <level1> <casting time1> <mana1> <grace1> <damage1>
777 <skill> <path1> <name1> <display name1> <message1> <usage information>
778 <requirements> <spell2 ....>
779
780 Tells the client to add the spell(s) listed to the list of spells
781 the client knows about. This will be sent at login, and again whenever
782 new spells are sent.
783
784 [options="autowidth,header"]
785 |===========================
786 |Field|
787 Description
788
789 |<tag> - (4 bytes - int)|
790 The ID number for the spell item. This is going to be unique, for each
791 spell and will be used to refer to it henceforth. The string form of this
792 should also be appended to the cast/invoke commands in order to cast the
793 spell.
794
795 |<level> (2 bytes, signed int)|
796 The level of the spell.
797
798 |<casting time> (2 bytes, signed int)|
799 The time it will take to cast the spell, in server ticks.
800
801 |<mana> (2 bytes, signed int)|
802 The mana cost to cast the spell (may be zero)
803
804 |<grace> (2 bytes, signed int)|
805 The grace cost to cast the spell (may be zero)
806
807 |<damage> (2 bytes, signed int)|
808 The current damage done by the spell. Note that the meaning of this number
809 is to a large part spell dependent, what damage it actually does will
810 depend on how the spell works.
811
812 |<skill> (1 byte, unsigned int)|
813 The skill that the spell uses to be cast, if zero, no skill is used in the
814 casting of this spell. The numbers are the same as for requestinfo
815 skill_info
816
817 |<path> (4 bytes, unsigned integer)|
818 The path that the spell belongs to. The client should determine the
819 effect of this by comparing these values to both the spell_paths
820 requestinfo data and the stats info concerning attunement/repulsion, etc.
821
822 |<face> (4 bytes, signed int)|
823 The number of the face that corresponds to the spell, the client can
824 request this facenumber if they want to show a graphical spell
825 representation.
826
827 |<name> (1 (non-zero)|
828 length byte, followed by that many bytes of ASCII text) This is a name to
829 identify the spell, which the client can use for display purposes, it
830 should /NOT/ be used with the 'cast' command, whilst it might work, no
831 such guarantee is made by the server. - Use tag instead.
832
833 |<message>|
834 (2 length bytes (which may be zero) followed by that many bytes of ASCII
835 text) The description of the spell. Note that this has an extra length
836 byte because the messages may well be longer than 256 bytes in length.
837
838 <usage information> (1 byte)
839 Only sent if 'spellmon 2' was setup by the client.
840 Values are:
841 - 0: spell needs no argument.
842 - 1: spell needs the name of another spell.
843 - 2: spell can use a freeform string argument.
844 - 3: spell requires a freeform string argument.
845
846 <requirements> (1 byte of length, then that many bytes of ASCII text)
847 Only sent if 'spellmon 2' was setup by the client.
848 If the spell required items to be cast, then this is the list of
849 those items. Comma-separated, potential number of items, singular
850 names (like the ingredients for alchemy).
851 |===========================
852
853 updspell
854 ^^^^^^^^
855 S->C updspell <flags><tag><vals>+
856
857 <flags> 1 byte binary. Values include in this update. Uses the UPD_SP_.. from
858 'newclient.h'
859
860 <tag> 4 byte binary. Tag of the spell.
861
862 This updates some spell (of tag) with new values. The flags are 1 byte and
863 determine which values have been updated, and should be re-read. Not all
864 fields may be updated by this command, only those that can be changed.
865
866 If new fields are added in future, they will extend the flags bitmask and the
867 order will remain the LSB order of the flags - that is, the value associated
868 with bit 1 set is sent first, then bit 2, etc.
869
870 The format of the values is same as the `addspell` command above.
871
872 Only one spell can be updated with the `updspell` command. A spell command
873 should have been sent by the server before an `updspell` command is set.
874
875 delspell
876 ^^^^^^^^
877 S->C delspell <tag>
878
879 <tag> 4 byte binary data.
880
881 Tells the client to remove its information about the spell. Tag is a 4 byte
882 value, the same as the one sent when the spell was added.
883
884 addquest
885 ^^^^^^^^
886 S->C addquest <code1> <title> <face> <replay> <parent> <end> <step> <code2
887 ...>
888
889 Tells the client to add the quest(s) listed to the list of quests the player
890 is doing. This will be sent at login, and again whenever new quests are
891 started, if notifications is 1 or greater.
892
893 <code> - (4 bytes - unsigned int) The ID number for the quest item. This is
894 going to be unique, for each quest and will be used to refer
895 to it henceforth.
896
897 <title> (2 bytes length, unsigned int, then string of specified length)
898 The quest title.
899
900 <face> (4 bytes, signed int)
901 The number of the face that corresponds to the quest, which will be sent
902 before this packet if needed.
903
904 <replay> (1 byte, unsigned int)
905 If 1, then the quest can be replayed, else it can't.
906
907 <parent> (4 bytes, unsigned int)
908 Code of this quest's parent, 0 if top-level quest.
909
910 <end> (1 byte, unsigned int)
911 If 1, the quest was completed.
912
913 <step> (2 bytes length, unsigned int, then string of specified length)
914 The current step's description, can be an empty string (length 0).
915
916 updquest
917 ^^^^^^^^
918 S->C updquest <code><end><step>
919
920 <code> - (4 bytes - unsigned int) The ID number for the quest item.
921
922 <end> (1 byte, unsigned int) If 1, the quest was completed.
923
924 <step> (2 bytes length, unsigned int, then string of specified length) The
925 current step's description, can be an empty string (length 0).
926
927 This updates some quest (of tag) with new values, if notifications is 1 or
928 greater.
929
930 Only one quest can be updated with the `updspell` command. A `addquest`
931 command should have been sent by the server before an `addspell` command is
932 set with the same ID.
933
934 addknowledge
935 ^^^^^^^^^^^^
936 S->C addknowledge <code1> <type> <title> <face> <code2 ...>
937
938 Tells the client to add the knowledge item(s) listed to the list of things
939 the player knows. This will be sent at login, and again whenever
940 new knowledge is learnt, if 'notifications' is 2 or greater.
941
942 <code> - (4 bytes - unsigned int) The ID number for the knowledge item. This
943 is going to be unique, for each knowledge and will be used to refer to it
944 henceforth. It is the same number the player sees with the 'knowledge'
945 commands.
946
947 <type> (2 bytes length, unsigned int, then string of specified length) The
948 knowledge's type, as defined in the knowledge_info reply.
949
950 <title> (2 bytes length, unsigned int, then string of specified length) The
951 knowledge title.
952
953 <face> (4 bytes, signed int) The number of the face that corresponds to the
954 knowledge item, which will be sent before this packet if needed.
955
956 Player Object and Stats
957 ~~~~~~~~~~~~~~~~~~~~~~~
958 player
959 ^^^^^^
960 S->C: player <tag><weight><face><name>
961
962 All fields are the same as described in item above. The only difference is
963 that player tells the client that this is the central object it needs to care
964 about.
965
966 stats
967 ^^^^^
968 S->C: stats <stat1><val1><stat2><val2>...
969
970 <stat> 1 byte binary data. One of the CS_STAT values from 'newclient.h'
971
972 <val> binary data. All are 16 bit values except for following exceptions:
973
974 weight limit:: 32 bit
975
976 speed, weapon_sp:: 32 bit value. This is float converted to an
977 integer by multiply by FLOAT_MULTI. The client needs to divide by
978 that value to get it back to a float.
979
980 range, title:: Length prefixed strings.
981
982 experience:: if CS_STAT_EXP64 is sent, 64 bit experience
983 value. 64 bit is the only option now - 32 bit exp is no longer
984 sent.
985
986 skill experience:: 64 bit.
987
988 spellpaths:: 32 bit. Only sent if spellmon is set in setup.
989 The CS_STATS_RACE_xxx and CS_STATS_BASE_xxx are only sent if
990 extended_stats was used in setup.
991
992 This is a server message that tells the client values of the various stats.
993 Multiple stats can be sent on one command.
994
995 Image Information
996 ~~~~~~~~~~~~~~~~~
997 anim
998 ^^^^
999 S->C: anim <num><flags><face1><face2>...
1000
1001 <num> 2 byte binary data. animation number we are defining. The server will
1002 only send the anim command for a particular <num> once per run - the client
1003 needs to keep track what has been sent. On new runs, anim commands will be
1004 resent.
1005
1006
1007 <flags> 2 byte binary data. Currently unused, but is included because I think
1008 there may end up being cases were more about the animation than just the num
1009 and faces are needed.
1010
1011 <face1>... 2 byte binary data. This is the various faces that comprise the
1012 animation sequence. The number of faces can be determined by checking the
1013 length of the packet. These values correspond in the same way as all
1014 references to face do.
1015
1016 This command informs the client of an animation sequence. The client is
1017 responsible for animating the objects in the inventory window, and upditem and
1018 other items command will refer to the animation number with num above. All
1019 values are 2 byte binary values.
1020
1021 Note that how fast the object is animated is contained in the item commands.
1022
1023 image2
1024 ^^^^^^
1025 S->C: image2 <face><set><len><data>
1026
1027 <face> 4 byte binary data - face number.
1028 <set> 1 byte binary data. Which faceset the image belongs to.
1029 <len> 4 byte binary data. Length of face data.
1030 <data> Binary data - actual face (png) information.
1031
1032 Sends a png version of an image to the client.
1033
1034 face2
1035 ^^^^^
1036 S->C: face2 <num><setnum><checksum><name>
1037
1038 <num> 2 byte binary data. Face number.
1039 <setnum> 1 byte binary data. Which set this face belongs to.
1040 <checksum> 4 byte binary data. Checksum of face data.
1041 <name> character data
1042
1043 Informs the client that image <num> of faceset <setnum> is associated with
1044 <name>. This is used when the client is caching images. In normal operation,
1045 when the server runs across a face that it hasn't sent the client, it sends a
1046 png for that face. If the face mode is none, the server then sends this
1047 command. The client can then check to see if it might have cached this face,
1048 and if not, should then request it from the server. Note that the num to name
1049 mappings can change between server and different runs of the server. For this
1050 reason, this data needs to be sent each time it is run. The client should be
1051 able to load/determine what face to load via the name.
1052
1053 askface
1054 ^^^^^^^
1055 C->S: askface <num>
1056
1057 <num> string of integer value.
1058
1059 Requests that the server send the client face <num>. The server will
1060 use values from setup to determine what faceset to send.
1061
1062 smooth
1063 ^^^^^^
1064 S->C: smooth <face><smoothpic>
1065
1066 <face> 2 byte binary data - face number
1067 <smoothpic> 2 byte binary data. Face to use for smoothing.
1068
1069 This command informs the client on how to smooth an image. Following are the
1070 facenbr of the picture involved in the smoothing algorithm. See doc on
1071 smoothing on how to use them. The server will send this to the client just
1072 like it sends faces, but client can also make explicit requests.
1073
1074 asksmooth
1075 ^^^^^^^^^
1076 C->S: asksmooth <face>
1077
1078 <face> string of integer value.
1079
1080 Ask server to send a smooth sequence. Server will respond with a
1081 smooth command. <facenbr> is an integer telling server which face
1082 we want smooth information on.
1083
1084 Map Update
1085 ~~~~~~~~~~
1086 map2
1087 ^^^^
1088 S->C: map2 <coord1><len1/type1><data1><len2/type2><data2>...<coord2>
1089
1090 This is an update of the map2 command above. It is meant to be
1091 extensible. It is also meant to incorporate the ideas of the
1092 extended map info command.
1093
1094 All data is in standard binary form.
1095
1096 <coord> 2 byte binary
1097
1098 the coord values are length + x + y values.
1099 The data represented looks like this:
1100
1101 first 6 bits: The x coordinate (0-63)
1102 next 6 bits: the y coordinate (0-63)
1103 LSB 0-3: Has the following meaning:
1104 0: Normal coordinate
1105 1: Use this coordinate for scroll information and not an
1106 actual coordinate. This removes the need for the
1107 mapscroll command. Note that coordinate are still
1108 modified with the MAP2_COORD_OFFSET as described below
1109 - as an example, if 14, 14 is passed, that means
1110 effective scroll of -1, -1. This should only be set in
1111 the first coordinate value. Another (real) coordinate
1112 pair will immediately follow this coordinate pair.
1113 2-15: Unused/reserved.
1114
1115
1116 The x & y coordinates are offset by MAP2_COORD_OFFSET (15).
1117 This is necessary because there may be effects noticeable to the
1118 player (light sources) that to the left/above the visible map. By
1119 using this offset, we can use a coordinate like 10, 27 to denote
1120 that something is 5 spaces above the top of the map.
1121
1122 <len/type> 1 byte binary data. This describes the data that is to follow. If
1123 this byte is 255, then this is a coordinate termination byte - this means a 7+
1124 length field of type 1f is not possible.
1125
1126 The top 3 bits (len) denote the number of bytes that follow - it is possible
1127 that this is zero, to denote all the relevant information is included in the
1128 type. If this is 7 (all bits set) then the following byte is an additive
1129 length value. Currently, nothing has a 7+ bit length.
1130
1131 The bottom 5 bits is the type of data - this allows for 31 different types of
1132 data (0-31/0x0-0x1f). The meaning of the data itself depends on what the type
1133 is. List of various types:
1134
1135 0x0:: Denotes this space should be cleared. Length in this
1136 case should also be zero, as there is no data that
1137 follows. Clear in this context means that all data
1138 associated with the space should be purged, eg, images,
1139 sound, darkness, whatever.
1140
1141 0x1:: Darkness information - a single byte follows on how
1142 light/dark the space is. 0 is completely dark, 255 is
1143 full bright. Note that 0 will never be sent - if the
1144 space is completely dark, players won't be able to see it.
1145
1146 0x2:: Not used. Possible future enhancement to hold sound data.
1147
1148 0x3:: Not used. Possible future enhancement to hold light sources.
1149
1150 0x4 - 0xf:: Unused
1151
1152 0x10 - 0x19:: Image information. Layer 0x10 is the lowest, 0x19 is the
1153 highest. There are several forms of this data depending on the
1154 length:
1155
1156 2 bytes: This is only the face number.
1157 3 bytes: <face num>[<smooth>|<animspeed>]
1158 4 bytes: <face num><animspeed><smooth>
1159
1160 smooth is a single byte for smoothing information. if
1161 face_num has the high bit set, then this object has an
1162 animation, and the byte after the animation is animation
1163 speed (see below for more details). Smooth information
1164 may still be sent for animations, and that would follow
1165 the animspeed.
1166
1167 If face is 0, that means that the face (or animation)
1168 is no longer visible, and smooth information should also be
1169 cleared.
1170
1171 For animations:
1172 face will have the high bit set to denote it is not a
1173 face but an animation id.
1174
1175 MSB-1, MSB-2: These are used to denote type of animation:
1176 0: Normal animation - start at first phase, etc.
1177 1: Randomize - randomize the animation phase & timing.
1178 2: Synchronize - this animation should be in the same phase
1179 as other animations with the same id. Used for things
1180 like oceans.
1181
1182 Like the itemcmd, the server will send information for
1183 the animation to the client before using the animation
1184 id.
1185
1186 Animations have an extra byte after the animation id -
1187 this is the animation speed. Like the itemcmd, it is
1188 how long, in ticks, between animations. 1 means it should
1189 be animated every tick.
1190
1191 Some notes:
1192
1193 Coordinates outside the viewable map may be sent. In these cases, it means
1194 that a big image that extends onto the viewable map is on that space. For big
1195 images, only the bottom right coordinate is sent - this is why it may be off
1196 the viewable coordinates. For such spaces, only the actual big image itself
1197 will be sent for that space.
1198
1199 Note that all operations are considered updates to the space (eg, new image,
1200 new light level, etc). The exception would be the clear command, which means
1201 clear all data with the space.
1202
1203 Note that while not used now, order of these subpackets is important. A clear
1204 (0x00) followed by other data should be parsed in that order - clear the data,
1205 then process the data. In contrast, sending data followed by a clear byte
1206 makes no sense. This functionality will likely be used in the future - for
1207 example, if 6 layers need to be cleared and the other 2 remain the same, it
1208 will be more efficient to send that clear byte followed by the 2 layers to
1209 redisplay instead of sending 6 layers with an empty face..
1210
1211 Relative to the map1/map1a commands, this is more bandwidth intensive -
1212 basically, an additional byte is needed for each piece of data sent. Thus, on
1213 a 25x25 map, if we presume 1.5 objects/space, this is an extra 940 bytes to
1214 send. OTOH, typically the entire map is not being sent - only those bits that
1215 change, so this may not be as costly as that.
1216
1217 If the player is using smoothing, this may actually save bytes, as the
1218 redundant coordinates and type/length information does not need to be sent.
1219 With the map2 command, the mapextend command is deprecated and is not used.
1220
1221 General design notes: For data types that vary in length because of optional
1222 data, the required data should be sent first, followed by optional data if
1223 appropriate. An example of this is the face information - we send the 2 face
1224 bytes first, then follow that with optional data (smoothing and/or animation
1225 data). This makes parsing on the client easier - basically, the client should
1226 be able to parse the data a byte (or pairing at a time).
1227
1228 tick
1229 ^^^^
1230 S->C: tick <tickno>
1231
1232 <tickno> 4 byte binary data (unsigned)
1233
1234 This just tells the client what the current tick is. Right now, the client
1235 only uses this to know when to animate the images that the client is
1236 responsible for animating. This will only be sent if negotiated with the setup
1237 command.
1238
1239 map_scroll
1240 ^^^^^^^^^^
1241 S->C: map_scroll <dx> <dy>
1242
1243 <dx><dy> string of integer value.
1244
1245 This tells the client to scroll the map dx and dy direction. dx and dy will
1246 typically be -1, 0, or 1, depending on how the player moved. <dx> and <dy>
1247 are sent as plaintext. positive values are down and to the right respectively,
1248 negative values are opposite.
1249
1250 mapredraw
1251 ^^^^^^^^^
1252 C->S: mapredraw
1253 Requests that the server resend the entire map to the client -
1254 can be useful if the client or client player knows that the map
1255 is out of date/corrupted. Note that the server is not required
1256 to honor this command, and currently just ignores it.
1257
1258 newmap
1259 ^^^^^^
1260 S->C: newmap
1261
1262 This tells the client to clear the map state. Used when player is moving
1263 between maps to invalidate all map state information in the client.
1264
1265 magicmap
1266 ^^^^^^^^
1267 S->C: magicmap <width> <height> <px> <py> <data>
1268
1269 <width> <height> string of integer values - width & height of magicmap
1270
1271 <px> <py> string of integer values. Players position on magic map.
1272
1273 <data> binary data - one byte per space. Low nibble contains color
1274 information, high nibble contains FACE_FLOOR and FACE_WALL (see newclient.h)
1275 to denote nature of object on that space. This string of data represents the
1276 space from left to right, then up to down.
1277
1278 Sound
1279 ~~~~~
1280 sound2
1281 ^^^^^^
1282 S->C: sound2 <x><y><dir><volume><type><action><name>
1283
1284 'x' and 'y' contain one byte of binary data each, representing the location of
1285 the sound relative to the player.
1286
1287 'dir' contains one byte of binary data, indicating which direction the sound
1288 is moving, using the standard direction map (values 0 through 8).
1289
1290 <volume> 1 byte binary data. Value of 1-100, arbitrary intensity of sound.
1291
1292 <type> 1 byte binary value. The major sound type.
1293
1294 <action> Length prefixed string. String describes subtype information The
1295 length is an 8-bit value.
1296
1297 <name> Length prefixed string. Name of the source of the sound - typically
1298 object name, but in the case of player generated sounds, will be the race of
1299 the player. The length prefix is an 8-bit value.
1300
1301 Plays a sound. See the 'doc/Developers/sound' document for more information.
1302
1303 music
1304 ^^^^^
1305 S->C: music <song>
1306
1307 <song> string data of sound to play.
1308
1309 Change background music. Server will send NONE as the string to stop any
1310 music from playing. This song data is set in a map property. (Due to
1311 someone forgetting to update this file when he/she implemented the
1312 command, it is unknown what exactly should be done with the string
1313 parameter, is it a filename? If yes: relative what?)
1314
1315
1316 Miscellaneous
1317 ~~~~~~~~~~~~~
1318 beat
1319 ^^^^
1320 C->S: beat
1321
1322 No-op command, used in conjunction with the `beat` setup command.
1323
1324 lookat
1325 ^^^^^^
1326 C->S: lookat <dx> <dy>
1327
1328 Where 'dx' and 'dy' are textual representations of integers.
1329
1330 Client (player) is looking at space 'dx', 'dy'. 'dx' and 'dy' are delta
1331 offsets from the player (client doesn't know where the player is on the map,
1332 so this is the only real way to deal with it.) This is only a request to the
1333 server - a response will typically come back in drawinfo commands.
1334
1335 setup
1336 ^^^^^
1337 C->S:
1338 S->C: setup <option1> <value1> <option2> <value2>
1339
1340 All arguments are strings, and the server will make the necessary conversions.
1341
1342 Client first sends a setup command to the server to request a change in some
1343 value (option1). This can be at any point during the life of connection
1344 between client and server.
1345
1346 All data in the setup command is in ASCII text form. options and values can
1347 not have whitespace - the client and server use whitespace to split the
1348 options and values.
1349
1350 The server only sends a setup command in response to one from the client. The
1351 sc_version should be updated in the server if commands have been obsoleted
1352 such that old clients may not be able to play.
1353
1354 There are really 2 set of setup commands here:
1355
1356 . Those that control preferences of the client (how big is the map,
1357 what faceset to use, etc).
1358 . Those that describe capabilities of the client (client supports
1359 this protocol command or that)
1360
1361 .Setup Options
1362 [options="autowidth,header"]
1363 |===========================
1364 |Command|
1365 Description
1366
1367 |beat|
1368 Ask the server to enable heartbeat support. When heartbeat is enabled,
1369 the client must send the server a command every three seconds.
1370
1371 If no commands need to be sent, use the `beat` no-op command. Clients
1372 that do not contact the server within the interval are assumed to have
1373 a temporary connection failure.
1374
1375 |bot (0/1 value)|
1376 If set to 1, the client will not be considered a player when
1377 updating information to the metaserver. This is to avoid having
1378 a server with many bots appear more crowded than others.
1379
1380 |darkness (0/1 value)|
1381 If set to 1 (default), the server will send darkness information
1382 in the map protocol commands. If 0, the server will not
1383 include darkness, thus saving a minor amount of bandwidth.
1384 Since the client is free to ignore the darkness information,
1385 this does not allow the client to cheat. In the case of the
1386 old 'map' protocol command, turning darkness off will result
1387 in the masking faces not getting sent to the client.
1388
1389 |extended_stats (0/1 value)|
1390 If set to 1, the server will send the CS_STATS_RACE_xxx and
1391 CS_STATS_BASE_xxx values too, so the client can display
1392 various status related to statistics. Default is 0.
1393
1394 |facecache (0/1)|
1395 Determines if the client is caching images (1) or wants the
1396 images sent to it without caching them (0). Default is 0. This
1397 replaces the setfacemode command.
1398
1399 |faceset (8 bit)|
1400 Faceset the client wishes to use. If the faceset is not
1401 valid, the server returns the faceset the client will be
1402 using (default 0).
1403
1404 |loginmethod (8 bit)|
1405 Client sends this to server to note login support. This is basically
1406 used as a subset of the csversion/scversion to find out what level of
1407 login support the server and client support. Current defined values:
1408 0: no advanced support - only legacy login method
1409 1: account based login (described more below)
1410 2: new character creation support
1411
1412 This list may grow - for example, advanced character creation could
1413 become a feature.
1414
1415 |map2cmd: (1)|
1416 This indicates client support for the map2 protocol command.
1417 See the map2 protocol details above for the main differences.
1418 Obsolete: This is the only supported mode now, but many clients use
1419 it as a sanity check for protocol versions, so the server still
1420 replies. It doesn't do anything with the data
1421
1422 |mapsize x X y|
1423 Sets the map size to x X y. Note the spaces here are only for
1424 clarity - there should be no spaces when actually sent (it
1425 should be 11x11 or 25x25). The default map size unless changed
1426 is 11x11. The minimum map size the server will allow is 9x9
1427 (no technical reason this could be smaller, but I don't think
1428 the game would be smaller). The maximum map size supported in the
1429 current protocol is 63x63. However, each server can have its
1430 maximum map size sent to most any value.
1431
1432 If the client sends a mapsize command out of valid range, the
1433 server will respond with a mapsize with the maximum size
1434 the server supports. Thus, if the client wants to know the maximum
1435 map size, it can just do a 'mapsize 0x0' and it will get the
1436 maximum size back.
1437
1438 The server will only set the mapsize for the client if both x & y values
1439 are valid. For example, if the maximum map size is 25x25, and the
1440 client sends a 31x23 mapsize request, the mapsize will remain at
1441 11x11 (default) and the server will send back a mapsize 25x25
1442 setup command.
1443
1444 When the values are valid, the server will send back a mapsize
1445 XxY setup command. Note that this is from its parsed values,
1446 so it may not match stringwise with what the client sent, but will
1447 match 0 wise. For example, the client may send a 'mapsize 025X025'
1448 command, in which case the server will respond with a
1449 'mapsize 25x25' command - the data is functionally the same.
1450
1451 While the server in theory supports non square viewing regions,
1452 this has not be tested.
1453
1454 The server will send an updated map view when this command is sent.
1455
1456 |notifications (int value)|
1457 Value indicating what notifications the client accepts.
1458 It is incremental, a value means "all notifications till this level".
1459 The following levels are supported:
1460 1: quest-related notifications ("addquest" and "updquest")
1461 2: knowledge-related notifications ("addknowledge")
1462
1463 |num_look_objects (int value)|
1464 The maximum number of objects shown in the ground view. If more
1465 objects are present, fake objects are created for selecting the
1466 previous/next group of items. Defaults to 50 if not set. The server
1467 may adjust the given value to a suitable one; this applies to both
1468 the lower and the upper limit. Returned is the number of items
1469 actually used; this value can differ from the given one if it has
1470 been adjusted.
1471 Updated ground view will be sent to the client if the connection
1472 is for a player.
1473
1474 Note: the requested int value is the total number of objects
1475 including fake objects (prev/next group and transport icons). The
1476 intention for this option is to enable clients to use a fixed
1477 number of slots for displaying ground view objects.
1478
1479 |sound2 (bitmask)|
1480 New sound support. Check above for more information.
1481 1=send sound effects
1482 2=send music
1483 64=mute sound; same as "sound" ncom command
1484
1485 |spellmon (0/1/2)|
1486 If set to 1 the client has indicated that it wishes to be
1487 sent the spell list and updated when it changes.
1488 If set to 2, like 1 but with extra information (see "addspell").
1489
1490 |tick (0/1)|
1491 If set, the client want tick commands so it knows animation
1492 timing.
1493
1494 |want_pickup (0/1)|
1495 If set, the client wants to be informed of pickup mode changes.
1496 Mode will be sent when the player successfully logs in, and
1497 afterward any time the value is changed (for instance by the
1498 player through the direct use of 'pickup' command).
1499 The value is the same bit format the client sends through menus
1500 and such.
1501 |===========================
1502
1503 requestinfo and replyinfo
1504 ^^^^^^^^^^^^^^^^^^^^^^^^^
1505 This section describes the requestinfo and replyinfo commands.
1506 Because these commands may handle different types of data with different
1507 return formats, this section is formatted a bit differently to make
1508 it easier to read the different structures.
1509
1510 C->S: requestinfo <info_type> [options]
1511 S->C: replyinfo <info_type> [options] <data>
1512
1513 <info_type> is a string value, describing what information is wanted/sent
1514 [options] is string data - specific to the type of data.
1515 <data> is the actual data. The format of this data will vary based on
1516 what the info_type is.
1517
1518 The requestinfo command is a general purpose way for the client to request
1519 some piece of data the server may have. The server still needs to be
1520 coded to respond to the specific info_type, but if the passed info_type is
1521 not supported, the server will still respond with the replyinfo, but with
1522 an empty data list.
1523
1524 This mechanism allows the client to send requests for data and not need to
1525 do complicated checking if the server would understand the specific
1526 request - if the server understands it, the data gets sent back. If the
1527 server doesn't understand it, the client gets no data, but does get the
1528 replyinfo so that it knows that the server does not support that
1529 particular aspect.
1530
1531 Only one info_type is allowed for each requestinfo. If the client
1532 requests many pieces of information (say image sets available, spell
1533 listings, etc), it should send multiple requestinfos.
1534
1535 [options] is specific to the info_type - it could be a range of values, or
1536 empty.
1537
1538 Requestinfo requests will not change any data on the server - the setup
1539 command should be used for that. The requestinfo just requests data.
1540 Note that since the requests can be made before a player logs in, the
1541 requestinfo command will not generally support getting information related
1542 to the player object.
1543
1544 As a general rule, the information returned is static - if the
1545 client makes a second requestinfo with same parameters during the
1546 same session, it will get the same data back. Thus, the client
1547 can safely cache the data instead of making multiple requests.
1548 There could be rare cases where information changes (eg, server
1549 admin is updating the new file), but these would be rare and
1550 generally are not something that needs to be designed for.
1551
1552 .Supported Info Types
1553 [options="autowidth,header"]
1554 |===========================
1555 |Type|
1556 Description
1557
1558 |image_info (no options)|
1559 Request basic image information the server has. The data is
1560 sent in text format - the replyinfo is newline terminated.
1561 Since the packet length is sent in the header, that is used
1562 to figure out the length of returned data.
1563
1564 Line 1: The last image number the server has. Note that
1565 there is no image 0, so this also amounts to the number of
1566 images if you start counting from one.
1567
1568 Line 2: checksum of all the image name information. This can
1569 basically be used to determine if the number to name mapping
1570 is the same, eg, if on server 1 the total is 123456, and the
1571 player goes to server 2 and the total is the same, we can say
1572 with a high degree of confidence that the name to number
1573 mappings are the name. If instead the numbers differ, we
1574 know we can't rely on using the same mappings.
1575
1576 Line 3+:The image set information the client has. The format
1577 is the same as the format in the image_info file, sans
1578 comments. The server will ignore any parameters the client
1579 sends.
1580
1581 An example response:
1582
1583 replyinfo image_info
1584 3512
1585 1169234
1586 0:base:standard:0:32x32:none:The standard image set.
1587 1:clsc:classic:0:32x32:none:Classic and new styling.
1588
1589
1590 |image_sums <start> <stop>|
1591 Request the image number to name (and checksum) values - in
1592 this way, the client can build all images before play starts
1593 and also request any missing images. The returned data is
1594
1595 image_sums <start> <stop> <imagenum><checksum><faceset><namelength><name>
1596
1597 There is an initial space after the stop value, but no spaces
1598 after that point. The <start> and <stop> values are ASCII
1599 text (same format as it is sent to the server in). The start
1600 and stop values are inclusive - thus, if the start is 0 and
1601 the stop is 100, 101 checksums will be set.
1602
1603 imagenum is 16 bit binary data.
1604 checksum is 32 bit binary data. It contains the checksum for
1605 the image in the current selected set, and will use whatever
1606 fallback logic the imagesets specify.
1607 faceset is 8 bit binary data. It contains the actually selected
1608 faceset.
1609 namelength is 8 bit binary data. It is the length of the
1610 name field below, including the null terminator.
1611 name is character data. It is null terminated to make processing
1612 easier - in this way, the client doesn't need to copy the data
1613 to make it null terminated.
1614
1615 Note that due to possible OS system constraints on the maximum
1616 single write supported to a socket, the complete set can not
1617 be requested at once - instead, the images information should
1618 be requested in blocks of less than 1000. The server will not
1619 process a block larger than 1000 at a time. Smaller blocks
1620 may be desired if the client wants to try to reduce the
1621 potential lag caused.
1622
1623 Multiple requests for all the information can be sent at once,
1624 as the server will buffer the response data, but constraints
1625 prevent the server from sending the entire data back in one
1626 replyinfo (one being that the data would be beyond 65535
1627 bytes, so the length information in the packet would not be
1628 accurate.)
1629
1630 If the client sends invalid data (stop is less than start,
1631 missing stop parameter, stop is beyond the number of images,
1632 or asking for more than 1000 at a time), the reply will just
1633 be an empty list.
1634
1635 Note that the server will track that it has sent the face
1636 information for the requested images, and thus will not send
1637 it again (unless requested via requestinfo). Thus, this
1638 request should always do the right thing with the returned
1639 information.
1640
1641 |exp_table|
1642 This requests the experience table (what exp is needed for
1643 each level) from the server. With this data, the client can
1644 easily display how much experience is needed for the different
1645 skills or total exp value for next level. Data format:
1646
1647 <num_levels>: uint16 - max level/how many exp values follow.
1648 <level1> ... <level num_levels>: uint64 - amount of exp needed
1649 for the level.
1650
1651 Note that num_levels and the actual exp values are transmitted
1652 as binary values.
1653
1654 |knowledge_info|
1655 This returns the list of knowledge types the server uses.
1656 One item per line, in the format:
1657 type:display name:face number:attempt
1658
1659 'type' and 'display name' are strings.
1660 'attempt' is 0 if the knowledge type isn't alchemy-like, 1 if it can be 'attempted'.
1661
1662 The first line will always contain empty types and names, to indicate the
1663 face of the 'generic' type.
1664
1665 |skill_info (empty or '1')|
1666
1667 This returns the skill number to skill name mappings. In this
1668 way, new skills can be added in the server, and the client can
1669 use this new skill information with no changes to the code.
1670
1671 All data below is in text format. If the additional value is empty then format is:
1672
1673 stat number:skill name
1674
1675 else format is
1676
1677 stat number:skill name:face number
1678
1679 Where stat number is the number that will be used to send
1680 that skill information. Example:
1681 141:lockpicking
1682 142:hiding
1683 143:smithery
1684
1685 |spell_paths|
1686
1687 This returns a list of all spell paths in the game, along with
1688 the number associated with them. This should be used to parse
1689 spell_path data in the stats command. The number is a bitmask
1690 but is sent as a decimal value.
1691
1692 All data is sent in text format. Format is:
1693
1694 number:name
1695
1696 eg
1697
1698 16:missiles
1699
1700 |race_list|
1701 Returns the races players can choose.
1702 The names can be used to request more information with race_info.
1703 Reply format is: replyinfo race_list |race1|race2|...|racen
1704
1705 Note that the names returned are archetype names, and thus not
1706 really suitable to display to the player.
1707
1708 |race_info|
1709 Returns information about specified playable race (one from
1710 race_list above). Format is:
1711
1712 name <namelen><namedata>
1713 msg <desc len><description>
1714 stats <statno1><adj1><statno2><adj2>....0
1715 choice <len><choice name><len><choice description>
1716 <len>arch name<len>arch_desc(repeat arch)0
1717
1718 name is the name that the player sees (data returned by
1719 race_list above is archetype name). It is a length
1720 prefixed string.
1721
1722 stats is a literal string value, and what follows are binary
1723 statno and adjustment values. statno uses the CS_STAT value
1724 that is used by the stats command, and the type of adjustment
1725 matches that for stats (eg, if statno1 is a 32 bit type, a 32
1726 bit type will be used here). Any/all of the CS_STAT types
1727 could be sent, but in general only a subset will be sent. The
1728 server will only send stats which are not zero, so the client
1729 should assume all stats that are not sent have a zero value. 0
1730 is used for a statno to denote there are no more stats.
1731
1732 description is a text description. It is length prefixed (2
1733 bytes) to allow for possible expansion (with it having a known
1734 length, additional fields could be set to follow the
1735 description. NOTE: The length parameter here is unusual in
1736 that most strings use only an 8 bit length value, but for
1737 messages that would not be long enough, hence the 16 bit value.
1738
1739 choice is a choice of values to present the player for character
1740 creation - it is a choice of one of many archetypes - it could
1741 be skill, ability, or potentially even choice of items. All
1742 of the field in the choice are 1 byte length prefixed, since
1743 they may contain spaces. An example values (where | would
1744 be the length value - | is used to improve readability):
1745
1746 choice |race_choice_1|Choose a racial skill|
1747 skill_smithery|Smithery|skill_jeweler|jeweler0
1748
1749 When the client replies in the create player, it would include
1750 the choice name and archetype name, eg:
1751
1752 choice race_choice_1 skill_smithery
1753
1754 This makes it easier for the server to check the returned values -
1755 if it is a racial skill, it knows to check the race, if a class
1756 skill, it checks the class, etc.
1757
1758 There is currently no way to do something like 'choose 2 out of
1759 4 skills' - however, this could be done by using multiple choice
1760 (choice race_choice_1 ... choice race_choice_2 ...)
1761
1762 For the choice command, all the passed values come in pairs -
1763 choice name/choice description, arch_name/arch_description
1764
1765 Note that the race archetype name will be included in the replyinfo
1766 header, eg, 'replyinfo race_info dwarf_pl'.
1767
1768 Note also that the order of the fields here is not fixed - the
1769 server could send them in 'stats, msg, name' order - the
1770 client should be able to handle any order. Note also that it
1771 is conceivable that the server will send multiple stats
1772 command if new stats are to be sent - in this way, the client
1773 can process as much as possible, and then stop processing once it gets
1774 something it does not understand.
1775
1776 |class_list|
1777
1778 |class_info <class name>|
1779 The format of the data returned is exactly the same as for the
1780 race_.. command of the same name - the only difference is this
1781 is class information.
1782
1783 |startingmap|
1784 Sends data about starting map choices to the client. Format is:
1785
1786 <type><length><data>
1787
1788 <type> is a single byte binary - the INFO_MAP values define this.
1789 <length> is a 2 byte binary - length of following data. This is
1790 two bytes because some of the string data that can be
1791 sent here will be beyond 255 that a single byte can handle.
1792 <data> is actual data - as of now, this is all text data (name,
1793 description, etc), but could potentially be binary data
1794 (face number)
1795
1796 A single map info command will contain information on all the maps.
1797 Once the client gets an INFO_MAP_ARCH_NAME, all following map information
1798 that follows is for that map until the next INFO_MAP_ARCH_NAME is found
1799 or the end of the packet is reached.
1800
1801 |newcharinfo|
1802 This sends information to the client for creating a new character through
1803 the 'createplayer' command. The information sent multiple length prefixed
1804 strings - each string corresponds to an entire line/variable set.
1805
1806 The idea behind this is that new types/options for character creation
1807 can get added without needing to rewrite the entire protocol commands
1808 or increase the protocol version - the client requests this information
1809 and see if it understands all the data the server wants. If so, it
1810 can then create a character.
1811
1812 While this setup looks fairly complicated, the simplest way
1813 for the client to handle it is to just make sure it
1814 understands all the variables present (ignoring type) and it
1815 gets all the ones it expects, and if it doesn't, just throw up
1816 an error that client needs to be updated in order to create a
1817 character on that server. One reason for the extra complexity
1818 here (instead of just making a set of assumptions that are
1819 fixed in the protocol) is that lots of discussions have gone
1820 on about character creation changes, so this allows for many
1821 of them.
1822
1823 <type> <variable name> <values>
1824 type is a single character which denotes the type of data
1825 that is in this line, currently values are:
1826
1827 R: required - needed value in the createplayer command.
1828 O: optional - if not present in createplayer, server can fill in
1829 some default value. If a client does not understand
1830 an Optional type but understands all the other types,
1831 it could still create the character.
1832
1833 V: values - this contains some values which are used in character
1834 creation but may not be sent back in the actual
1835 createplayer command. An example here is the number of
1836 points the player has to spend on stats - the client
1837 does not send that back, but rather sends the actual
1838 stat values during the createplayer command, but it
1839 needs this value to do so.
1840
1841 I: Informational - some piece of information that the
1842 client should communicate to the player. An example
1843 here could be a requestinfo that is related to class
1844 or race choices for new characters - one may not want
1845 to put it in the news since it is only relevant for
1846 people creating new characters.
1847
1848 <variable name> name of variable - race, class, map, etc are
1849 all possible names. The only constraint on name is that
1850 it can not contain any spaces.
1851
1852 Short description of variables currently supported:
1853
1854 points: How many total points the character has to spend -
1855 at current time these are just used for stats, but
1856 possible in future they could get used for other
1857 things.
1858
1859 race, class: Notes that race and class information need to
1860 be sent to the server. This is a fixed assumption
1861 now, but if at some point someone wanted to remove
1862 either races or classes (or both) and reduce the
1863 number of choices, this provides a mechanism to do so.
1864
1865 statrange: The minimum and maximum value for a stat.
1866
1867 statname: The name of the different statistics. Like race
1868 & class above, this is a fixed assumption now, but if
1869 a stat was to get removed, or a new one added, this
1870 provides a mechanism for the client to know it.
1871
1872 startingmap: Provide choice of starting maps for the player.
1873 List of maps is provided through the 'startingmap'
1874 requestinfo command.
1875
1876 <values> value tends to be specific to the variable itself.
1877 In general, the client will need to be able to parse each
1878 required and value variable - if it is unable to do so, it
1879 is likely it will not be able to properly generate a
1880 character. requestinfo is used for some variables to note
1881 that a requestinfo protocol command should be used to
1882 retrieve additional data. Note that the client will have
1883 to have support for that requestinfo command, and still
1884 has know the actual mapping of variable name to
1885 requestinfo name. In the case of race and class, it would
1886 have to do the race_list/class_list, and when it gets the
1887 response from that would then have to know to do the
1888 race_info/class_info
1889
1890 Below is a sample for first set of supported values (note in
1891 the actual protocol, each of these lines is prefixed by a
1892 single length byte). Note that all values should be
1893 considered case insensitive. Each line is also null
1894 terminated by the server.
1895
1896 V points 200
1897 V statrange 1 20
1898 V statname Str Dex Con Wis Cha Int Pow
1899 R race requestinfo
1900 R class requestinfo
1901
1902 Possible future extensions (these are provided as an example):
1903 V statpointcosts 0 1 2 3 4 ....
1904 : If different stat points have different costs (nonlinear) this can
1905 be used to return a list of the costs. Instead of values, this could
1906 also point to a requestinfo.
1907 O skill skill1 skill2 ...
1908 If at some point the player can choose some of the skills for their
1909 character, this would be used.
1910
1911 |news/rules/motd|
1912 Send the news/rules/motd file information to the client. This
1913 is mainly useful as a way for the client to easily capture
1914 this information instead of getting it from drawinfo commands.
1915 This is most useful in that the client can more easily choose
1916 where to display this information. The sent data is null terminated
1917 to make string handling easier on the client.
1918 |===========================
1919
1920 Sample Session
1921 --------------
1922 The client first opens a connection to the server.
1923
1924 S->C: version 1001
1925 C->S: version 1001
1926
1927 The client/server are exchanging version information, to verify that
1928 they can both properly communicate with each other. If there is
1929 a mismatch, one or both of the sides might close the connection.
1930
1931
1932 C->S: setfacemode 2
1933
1934 The client is informing the server that is wants to use XPM images. Note
1935 that setfacemode is an optional command - if the client wants to live with
1936 the default (XPM) mode, it doesn't need to send this.
1937
1938 C->S: addme
1939 S->C: addme_success
1940
1941 Client is informing the server it wants to be added to the game. Server
1942 is telling client that the command has succeeded, and it will then
1943 be added.
1944
1945 NOTE: I am not sure if this is the exact order of the next few commands,
1946 since a whole bunch of stuff is being done at once.
1947
1948 S->C: pixmap (All that the map command uses will be sent.)
1949 S->C: map (display starting town map.)
1950 S->C: stats (display default character stats)
1951 S->C: drawinfo (display motd)
1952 S->C: query (get player name)
1953 C->S: reply (return player name)
1954 S->C: drawinfo (inform player to enter password)
1955 S->C: query (request password)
1956 C->S: reply (return player password.)
1957
1958 At this point, things could deviate two ways - player could be
1959 starting a new character, in which case, numerous draw infos, query's
1960 (stat rolling), replies, stats (change stats that were just
1961 rolled), map updates (player changing class) could be sent. However,
1962 we will assume that the player actually entered the proper password
1963 and an existing character is rejoining the game.
1964
1965 Once again, I am not positive this is the correct order or not.
1966
1967 S->C: player (send player object.)
1968 S->C: stats (send player stats)
1969 S->C: pixmap (assuming on different map and we haven't sent some of
1970 the images before)
1971 S->C: map (map player was saved on)
1972 S->C: pixmap (assuming we have not sent image for item before)
1973 S->C: item (item in players inventory or where he is standing)
1974
1975 After that is established, a loop is established that typically will result
1976 in these commands being sent at various times:
1977
1978 S->C: stats - to inform the client when stats go up or down.
1979 S->C: map_scroll (when the player moves)
1980 S->C: map (update after map_scroll, or when player changes maps.)
1981 S->C: pixmap/bitmap (with maps commands) to update faces.
1982 S->C: drawinfo (Tell about hitting creatures, applying, etc.)
1983 S->C: item (tell what objects are in players inventory, or space he is standing
1984 on.
1985 C->S: command (general commands, like north, fire, cast, etc.)
1986 C->S: apply (applying and object.)
1987 C->S: move (moving and object)
1988 C->S: examine (examine an object.)
1989
1990 S->C: query (keypress for shop listing, some other areas)
1991 C->S: reply (from last query)
1992
1993 Deprecated Commands
1994 -------------------
1995 These are no longer used in latest versions of the server and client. In
1996 some cases, the code may exist in either client or server in order for them
1997 to support more different versions (so that more clients can play on a server,
1998 or so you can use the client to play on more servers).
1999
2000 The reasons for them being deprecated is noted - in most cases it is because
2001 they have been replaced by a newer command, or have become de facto defaults.
2002
2003 S->C: drawinfo <color> <text>
2004 <color> string value of integer data
2005 <text> string of text message.
2006
2007 Tell the client to draw whatever text in color. Color are specified
2008 in newclient.h, and is sent as a string. The client is free to do
2009 whatever it wants with the color information (which may very well
2010 mean ignore it.)
2011
2012 C->S: toggleextendedtext <type>...
2013 Deprecated: Server will use drawextinfo for all types, so
2014 requesting this type information is no longer needed.
2015
2016 Ask the server to send extended text information for a given type.
2017 type is a list of decimal integers.
2018 Currently supported/reserved values for types are described in drawextinfo
2019
2020 S->C: ExtendedTextSet <type1> <type2> .... <typen>
2021 Deprecated: Server will use drawextinfo for all types, so
2022 requesting this type information is no longer needed.
2023
2024 Tell client what actually are the extended infos server may
2025 send to the client when this is needed. All those infos will
2026 be related to the map and send through mapextended command.
2027 Each string represent an info which is enabled. Look
2028 at toggleextendedinfos and drawextinfo for details.
2029
2030 C->S: setfacemode <val>
2031 Deprecated: Only one facemode (PNG) is supported. Client uses setup
2032 to request caching (or not)
2033
2034 This tells the server what type of display mode the client is using.
2035 <val> is a plaintext integer. 0=no faces, 1=bitmap, 2=xpm (pixmap).
2036 3=png (added in CS version 1022)
2037 If the 5'th bit is true (ie, 0x10 & val is true), that then informs
2038 the server that client is caching the images, and only send image
2039 names.
2040
2041 C->S: toggleextendedinfos <string1> <string2> .... <stringn>
2042 Deprecated: Rolled into map2 protocol command, which is standard.
2043
2044 Ask the server to send some additional information about the map.
2045 This command is followed by 1 or more strings. String are separated
2046 with spaces. Each string toggle an info. The server will respond
2047 with the command ExtendedInfoSet telling client what actual
2048 extended infos will be send to the client.
2049 Valid extended infos are as follow:
2050 smooth
2051 send smoothlevel information to the client.
2052
2053 S->C: ExtendedInfoSet <string1> <string2> .... <stringn>
2054 Deprecated: Rolled into map2 protocol command, which is standard.
2055
2056 Tell client what actually are the extended infos server may
2057 send to the client when this is needed. All those infos will
2058 be related to the map and send through mapextended command.
2059 Each string represent an info which is enabled. Look
2060 at toggleextendedinfos and mapextended for details.
2061
2062 C->S: setsound <val>
2063
2064 Deprecated: Replaced with setup options
2065 Obsolete command, should not be used, will be removed at some point.
2066
2067 S->C: sound <x><y><num><type>
2068
2069 Deprecated: Replaced by sound2
2070 Obsolete, will never be sent.
2071
2072 Deprecated Setup Options
2073 ~~~~~~~~~~~~~~~~~~~~~~~~
2074 The setup command is still in use, but over time, many options have become
2075 defaults. This documents those now obsolete values.
2076
2077 [options="autowidth,header"]
2078 |===========================
2079 |Command|
2080 Description
2081
2082 |exp64|
2083 If true, client can handle the 64 bit exp values that
2084 are now used. Otherwise, values are sent as 32 bit. Setting
2085 this flag also means that skill exp will be sent, and it will
2086 be sent in revised method as described in the stats command.
2087 Value is an integer in string format.
2088 Deprecated: This is always the default on servers with protocol version >=1028.
2089
2090 |extendedMapInfos (0/1)|
2091 Toggle sending from server of extended map informations.
2092 What lies in this extended info depended on what extended
2093 infos the client asked. See toggleextendedinfos command for
2094 details.
2095 Deprecated - server will always including smoothing information
2096 in map2 data.
2097
2098 |extendedTextInfos (0/1)|
2099 Toggle sending from server of extended text informations.
2100 What lies in this extended info depended on what extended
2101 infos the client asked. See toggleextendedtext command for details.
2102 Deprecated - server will always use drawextinfo
2103
2104 |inscribe (0/1)|
2105 Client will probably always send 1. Server will reply with 1 if it
2106 supports the 'inscribe' command, 0 else.
2107 Deprecated - client should presume all servers support this
2108
2109 |newmapcmd (0/1)|
2110 This tells the server if the client understands the newmap
2111 protocol command. This is used by the client in the fog
2112 of war mode to receive newmap commands from the server each time
2113 the player changes maps.
2114 Deprecated - server will assume clients support newmapcmd
2115
2116 |sound (bitmask)|
2117 Obsolete, server will return FALSE.
2118 Deprecated - replaced with sound2 setup command.
2119 |===========================
2120
2121 Programming Notes
2122 -----------------
2123 These are a few quick notes on how things work. Note that they really
2124 only apply to the code in the standard distribution, most of the direct
2125 i/o is handled by functions that are talked about. If writing a client
2126 from scratch, you will need to port this over (or write your own - it
2127 isn't very complicated.)
2128
2129 For the server and the C client, a SockList structure is used for basic
2130 data handling. Basically, this is just a structure that has an unsigned
2131 character buffer and a length field (which contains the length of data in
2132 the buffer, not the actual buffer length.)
2133
2134 As a side note, when sending a packet, you can supply the length of the
2135 data and the sending routines will take care of sending the 2 bytes of
2136 length information.
2137
2138 When getting a packet, these 2 bytes are at the start of the buffer and
2139 not removed.
2140
2141 In the client, there is a file called newsocket.c - except for the
2142 SockList data type, it could probably be used by itself. The
2143 newsocket.c file contains some routines to pack ints, shorts, and
2144 single chars into SockList structs, as well as functions for the
2145 reverse. It also contains a function to send socklists, as well as
2146 read them. The Add??? functions increase the len field of the
2147 socklist, the Get??? functions do not change the pointer in anyway.
2148 Thus, to get an int and move the buffer, you do something like:
2149
2150 int = GetIntString(data); data+=4
2151
2152 As a side note, if you malloc the data for the buffer, make sure to free
2153 it when done.
2154
2155 There is also the newclient.h file which is shared between the client and
2156 server. This file contains the definition of the SockList, as well as
2157 many defined values for constants of varying means (ie, that in the
2158 stats command, a stat value of 1 is hit points, etc.) When porting to
2159 a new system, you will need to grab these constant values for yourself.
2160 Many of the constants in this file are used in the protocol to denote
2161 types.
2162
2163 Image Caching
2164 ~~~~~~~~~~~~~
2165 Image caching has been implemented on the client, with necessary server
2166 support to handle it. This section will briefly describe how image
2167 caching works on the protocol level, as well as how the current client does
2168 it.
2169
2170 First, the client checks for an option denoting the image caching
2171 is desired. If so, we initialize all the images to a default value - this
2172 means we don't need to put special checks into the drawing code to see if
2173 we have an image - we just draw the default images (I use a question mark
2174 pixmap, since that makes it very easy to see what stuff is cached.) We
2175 also initialize an array which will hold the number to name mapping so
2176 that when we actually get the image, we know what filename to store it
2177 as.
2178
2179 Second, we request the server to do image caching. This is done
2180 by or-ing the cache directive to the image mode we want.
2181
2182 C->S: setup facecache 1
2183
2184 Then, when the server finds an image number that it has not send to the
2185 client, it sends us a name command information us the number to name mapping:
2186
2187 S->C: face2 65 1 5264 CSword.115
2188
2189 Note that this is not exactly how the data is sent - the numbers are
2190 actually sent in binary form, and there is no space between that the
2191 and the name. Such formating is difficult here, but the above example
2192 illustrates the data is sent.
2193
2194 The client then checks for the existence of the image locally. It is
2195 up to the client to organize images appropriately (based on name,
2196 faceset, etc). The current client stores images in
2197 ~/.crossfire/images, and then splits them into sub directories based
2198 on the first 2 letters - in the above example, the file would be
2199 ~/.crossfire/images/CS/CSword.115
2200
2201 If the client does not have the image or otherwise needs a copy from the
2202 server, it then requests it:
2203
2204 C->S: askface 65
2205
2206 The server will then send the image via image2 protocol commands.
2207
2208 S->C: image2 <face><set><len><data>
2209
2210 Because image2 does not include the image name, the client must store
2211 the name & number mapping someplace before sending the askface. In
2212 the C client, this is done by using an array of character pointers, so
2213 then in position 65, we do a strdup of the name, store it, then use it
2214 when the pixmap/bitmap command comes in, and free that data.
2215
2216 Also, the client does occasional redraws of all data if it has received
2217 new images and is running in cached mode. Otherwise, the map can remain
2218 out of date indefinitely (although, once the player moves, things will get
2219 redrawn.)
2220
2221 This has the effect that first time running in cached mode, performance
2222 will actually be a little bit worse for the client (after all, it needs
2223 to still request all the images, but is still doing pretty constant redraws
2224 of the data.) But times after that, performance is greatly improved.
2225
2226 Changes
2227 -------
2228 This area documents changes in the protocol version and what happened between
2229 them. Note that this is not a complete list, as the setup command
2230 is used to control many cases.:
2231
2232 Client
2233 ~~~~~~
2234 CS version 1022 -> 1023: just to sync version with server
2235
2236 CS version 1021 -> 1022: Client supports sending of verbal image type
2237 questions.
2238
2239 Server
2240 ~~~~~~
2241 SC version 1022 -> 1023: Server supports sending png images (addition of
2242 image command).
2243
2244 SC version 1023 -> 1024: Server will send two part names (described in
2245 item command) which contains the singular & plural form of the name)
2246
2247 SC version 1024 -> 1025: Support for sending all resistance
2248 values in the stats command.
2249
2250 SC version 1025 -> 1026: Add face1 command that includes the image
2251 checksum.
2252
2253 SC version 1026 -> 1027: Add requestinfo/replyinfo commands - client
2254 can check this to know if it should expect a replyinfo to its requestinfo.
2255
2256 SC version 1027 -> 1028: mostly remove obsolete commands:
2257 image, face, face1, map, map1, map1a, command
2258
2259 SC version 1028 -> 1029: Changes the way weapon_speed is reported for
2260 the player - version 1028 needed the client to divide weapon speed
2261 by player speed to get actual value, version 1029 just reports weapon
2262 speed as it should be displayed.
2263
2264 Todo
2265 ----
2266 It probably makes more sense to do a more preemptive handling of socket
2267 events. That is, instead of sleeping 120 ms, then checking all the
2268 sockets, we do a select on all the file descriptors with an appropriate
2269 sleep time.
2270
2271 If we get input, we handle it at that time if the player has an action. In
2272 this way, instead of handling all the actions after sleeping for the 120ms,
2273 we can instead spread them out more. Only when the 120ms expire do we
2274 then do all the actions like move the monsters, regenerate HP, etc.
2275
2276 The only potential problem I see with this right now is that select will
2277 return immediately if there is data on the socket (player has used up all
2278 their time, are paralyzed, etc.) This would probably mean that the server
2279 needs to do internal buffering, which complicates things some. The
2280 potential advantage with this is that we could peek at the data, and
2281 if the command is not a player action (ie, maybe requesting an image, or
2282 a misc command like who), we could still execute it. Actually, we can
2283 get around the select problem by only adding the file descriptors from
2284 sockets that actually have time to perform actions.