serveropcodes.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. Copyright (C) 2015 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 2.1 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #include "serveropcodes.h"
  18. const static ToServerCommandHandler null_command_handler = { "TOSERVER_NULL", TOSERVER_STATE_ALL, &Server::handleCommand_Null };
  19. const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] =
  20. {
  21. null_command_handler, // 0x00 (never use this)
  22. null_command_handler, // 0x01
  23. { "TOSERVER_INIT", TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_Init }, // 0x02
  24. null_command_handler, // 0x03
  25. null_command_handler, // 0x04
  26. null_command_handler, // 0x05
  27. null_command_handler, // 0x06
  28. null_command_handler, // 0x07
  29. null_command_handler, // 0x08
  30. null_command_handler, // 0x09
  31. null_command_handler, // 0x0a
  32. null_command_handler, // 0x0b
  33. null_command_handler, // 0x0c
  34. null_command_handler, // 0x0d
  35. null_command_handler, // 0x0e
  36. null_command_handler, // 0x0f
  37. null_command_handler, // 0x10
  38. { "TOSERVER_INIT2", TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_Init2 }, // 0x11
  39. null_command_handler, // 0x12
  40. null_command_handler, // 0x13
  41. null_command_handler, // 0x14
  42. null_command_handler, // 0x15
  43. null_command_handler, // 0x16
  44. { "TOSERVER_MODCHANNEL_JOIN", TOSERVER_STATE_INGAME, &Server::handleCommand_ModChannelJoin }, // 0x17
  45. { "TOSERVER_MODCHANNEL_LEAVE", TOSERVER_STATE_INGAME, &Server::handleCommand_ModChannelLeave }, // 0x18
  46. { "TOSERVER_MODCHANNEL_MSG", TOSERVER_STATE_INGAME, &Server::handleCommand_ModChannelMsg }, // 0x19
  47. null_command_handler, // 0x1a
  48. null_command_handler, // 0x1b
  49. null_command_handler, // 0x1c
  50. null_command_handler, // 0x1d
  51. null_command_handler, // 0x1e
  52. null_command_handler, // 0x1f
  53. null_command_handler, // 0x20
  54. null_command_handler, // 0x21
  55. null_command_handler, // 0x22
  56. { "TOSERVER_PLAYERPOS", TOSERVER_STATE_INGAME, &Server::handleCommand_PlayerPos }, // 0x23
  57. { "TOSERVER_GOTBLOCKS", TOSERVER_STATE_STARTUP, &Server::handleCommand_GotBlocks }, // 0x24
  58. { "TOSERVER_DELETEDBLOCKS", TOSERVER_STATE_INGAME, &Server::handleCommand_DeletedBlocks }, // 0x25
  59. null_command_handler, // 0x26
  60. null_command_handler, // 0x27
  61. null_command_handler, // 0x28
  62. null_command_handler, // 0x29
  63. null_command_handler, // 0x2a
  64. null_command_handler, // 0x2b
  65. null_command_handler, // 0x2c
  66. null_command_handler, // 0x2d
  67. null_command_handler, // 0x2e
  68. null_command_handler, // 0x2f
  69. null_command_handler, // 0x30
  70. { "TOSERVER_INVENTORY_ACTION", TOSERVER_STATE_INGAME, &Server::handleCommand_InventoryAction }, // 0x31
  71. { "TOSERVER_CHAT_MESSAGE", TOSERVER_STATE_INGAME, &Server::handleCommand_ChatMessage }, // 0x32
  72. null_command_handler, // 0x33
  73. null_command_handler, // 0x34
  74. { "TOSERVER_DAMAGE", TOSERVER_STATE_INGAME, &Server::handleCommand_Damage }, // 0x35
  75. null_command_handler, // 0x36
  76. { "TOSERVER_PLAYERITEM", TOSERVER_STATE_INGAME, &Server::handleCommand_PlayerItem }, // 0x37
  77. { "TOSERVER_RESPAWN", TOSERVER_STATE_INGAME, &Server::handleCommand_Respawn }, // 0x38
  78. { "TOSERVER_INTERACT", TOSERVER_STATE_INGAME, &Server::handleCommand_Interact }, // 0x39
  79. { "TOSERVER_REMOVED_SOUNDS", TOSERVER_STATE_INGAME, &Server::handleCommand_RemovedSounds }, // 0x3a
  80. { "TOSERVER_NODEMETA_FIELDS", TOSERVER_STATE_INGAME, &Server::handleCommand_NodeMetaFields }, // 0x3b
  81. { "TOSERVER_INVENTORY_FIELDS", TOSERVER_STATE_INGAME, &Server::handleCommand_InventoryFields }, // 0x3c
  82. null_command_handler, // 0x3d
  83. null_command_handler, // 0x3e
  84. null_command_handler, // 0x3f
  85. { "TOSERVER_REQUEST_MEDIA", TOSERVER_STATE_STARTUP, &Server::handleCommand_RequestMedia }, // 0x40
  86. { "TOSERVER_HAVE_MEDIA", TOSERVER_STATE_INGAME, &Server::handleCommand_HaveMedia }, // 0x41
  87. null_command_handler, // 0x42
  88. { "TOSERVER_CLIENT_READY", TOSERVER_STATE_STARTUP, &Server::handleCommand_ClientReady }, // 0x43
  89. null_command_handler, // 0x44
  90. null_command_handler, // 0x45
  91. null_command_handler, // 0x46
  92. null_command_handler, // 0x47
  93. null_command_handler, // 0x48
  94. null_command_handler, // 0x49
  95. null_command_handler, // 0x4a
  96. null_command_handler, // 0x4b
  97. null_command_handler, // 0x4c
  98. null_command_handler, // 0x4d
  99. null_command_handler, // 0x4e
  100. null_command_handler, // 0x4f
  101. { "TOSERVER_FIRST_SRP", TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_FirstSrp }, // 0x50
  102. { "TOSERVER_SRP_BYTES_A", TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_SrpBytesA }, // 0x51
  103. { "TOSERVER_SRP_BYTES_M", TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_SrpBytesM }, // 0x52
  104. };
  105. const static ClientCommandFactory null_command_factory = { "TOCLIENT_NULL", 0, false };
  106. /*
  107. Channels used for Server -> Client communication
  108. 2: Bulk data (mapblocks, media, ...)
  109. 1: HUD packets
  110. 0: everything else
  111. Packet order is only guaranteed inside a channel, so packets that operate on
  112. the same objects are *required* to be in the same channel.
  113. */
  114. const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
  115. {
  116. null_command_factory, // 0x00
  117. null_command_factory, // 0x01
  118. { "TOCLIENT_HELLO", 0, true }, // 0x02
  119. { "TOCLIENT_AUTH_ACCEPT", 0, true }, // 0x03
  120. { "TOCLIENT_ACCEPT_SUDO_MODE", 0, true }, // 0x04
  121. { "TOCLIENT_DENY_SUDO_MODE", 0, true }, // 0x05
  122. null_command_factory, // 0x06
  123. null_command_factory, // 0x07
  124. null_command_factory, // 0x08
  125. null_command_factory, // 0x09
  126. { "TOCLIENT_ACCESS_DENIED", 0, true }, // 0x0A
  127. null_command_factory, // 0x0B
  128. null_command_factory, // 0x0C
  129. null_command_factory, // 0x0D
  130. null_command_factory, // 0x0E
  131. null_command_factory, // 0x0F
  132. { "TOCLIENT_INIT", 0, true }, // 0x10
  133. null_command_factory, // 0x11
  134. null_command_factory, // 0x12
  135. null_command_factory, // 0x13
  136. null_command_factory, // 0x14
  137. null_command_factory, // 0x15
  138. null_command_factory, // 0x16
  139. null_command_factory, // 0x17
  140. null_command_factory, // 0x18
  141. null_command_factory, // 0x19
  142. null_command_factory, // 0x1A
  143. null_command_factory, // 0x1B
  144. null_command_factory, // 0x1C
  145. null_command_factory, // 0x1D
  146. null_command_factory, // 0x1E
  147. null_command_factory, // 0x1F
  148. { "TOCLIENT_BLOCKDATA", 2, true }, // 0x20
  149. { "TOCLIENT_ADDNODE", 0, true }, // 0x21
  150. { "TOCLIENT_REMOVENODE", 0, true }, // 0x22
  151. null_command_factory, // 0x23
  152. null_command_factory, // 0x24
  153. null_command_factory, // 0x25
  154. null_command_factory, // 0x26
  155. { "TOCLIENT_INVENTORY", 0, true }, // 0x27
  156. null_command_factory, // 0x28
  157. { "TOCLIENT_TIME_OF_DAY", 0, true }, // 0x29
  158. { "TOCLIENT_CSM_RESTRICTION_FLAGS", 0, true }, // 0x2A
  159. { "TOCLIENT_PLAYER_SPEED", 0, true }, // 0x2B
  160. { "TOCLIENT_MEDIA_PUSH", 0, true }, // 0x2C (sent over channel 1 too if legacy)
  161. null_command_factory, // 0x2D
  162. null_command_factory, // 0x2E
  163. { "TOCLIENT_CHAT_MESSAGE", 0, true }, // 0x2F
  164. null_command_factory, // 0x30
  165. { "TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD", 0, true }, // 0x31
  166. { "TOCLIENT_ACTIVE_OBJECT_MESSAGES", 0, true }, // 0x32 (may be sent as unrel over channel 1 too)
  167. { "TOCLIENT_HP", 0, true }, // 0x33
  168. { "TOCLIENT_MOVE_PLAYER", 0, true }, // 0x34
  169. null_command_factory, // 0x35
  170. { "TOCLIENT_FOV", 0, true }, // 0x36
  171. { "TOCLIENT_DEATHSCREEN", 0, true }, // 0x37
  172. { "TOCLIENT_MEDIA", 2, true }, // 0x38
  173. null_command_factory, // 0x39
  174. { "TOCLIENT_NODEDEF", 0, true }, // 0x3A
  175. null_command_factory, // 0x3B
  176. { "TOCLIENT_ANNOUNCE_MEDIA", 0, true }, // 0x3C
  177. { "TOCLIENT_ITEMDEF", 0, true }, // 0x3D
  178. null_command_factory, // 0x3E
  179. { "TOCLIENT_PLAY_SOUND", 0, true }, // 0x3f (may be sent as unrel too)
  180. { "TOCLIENT_STOP_SOUND", 0, true }, // 0x40
  181. { "TOCLIENT_PRIVILEGES", 0, true }, // 0x41
  182. { "TOCLIENT_INVENTORY_FORMSPEC", 0, true }, // 0x42
  183. { "TOCLIENT_DETACHED_INVENTORY", 0, true }, // 0x43
  184. { "TOCLIENT_SHOW_FORMSPEC", 0, true }, // 0x44
  185. { "TOCLIENT_MOVEMENT", 0, true }, // 0x45
  186. { "TOCLIENT_SPAWN_PARTICLE", 0, true }, // 0x46
  187. { "TOCLIENT_ADD_PARTICLESPAWNER", 0, true }, // 0x47
  188. null_command_factory, // 0x48
  189. { "TOCLIENT_HUDADD", 1, true }, // 0x49
  190. { "TOCLIENT_HUDRM", 1, true }, // 0x4a
  191. { "TOCLIENT_HUDCHANGE", 1, true }, // 0x4b
  192. { "TOCLIENT_HUD_SET_FLAGS", 1, true }, // 0x4c
  193. { "TOCLIENT_HUD_SET_PARAM", 1, true }, // 0x4d
  194. { "TOCLIENT_BREATH", 0, true }, // 0x4e
  195. { "TOCLIENT_SET_SKY", 0, true }, // 0x4f
  196. { "TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO", 0, true }, // 0x50
  197. { "TOCLIENT_LOCAL_PLAYER_ANIMATIONS", 0, true }, // 0x51
  198. { "TOCLIENT_EYE_OFFSET", 0, true }, // 0x52
  199. { "TOCLIENT_DELETE_PARTICLESPAWNER", 0, true }, // 0x53
  200. { "TOCLIENT_CLOUD_PARAMS", 0, true }, // 0x54
  201. { "TOCLIENT_FADE_SOUND", 0, true }, // 0x55
  202. { "TOCLIENT_UPDATE_PLAYER_LIST", 0, true }, // 0x56
  203. { "TOCLIENT_MODCHANNEL_MSG", 0, true }, // 0x57
  204. { "TOCLIENT_MODCHANNEL_SIGNAL", 0, true }, // 0x58
  205. { "TOCLIENT_NODEMETA_CHANGED", 0, true }, // 0x59
  206. { "TOCLIENT_SET_SUN", 0, true }, // 0x5a
  207. { "TOCLIENT_SET_MOON", 0, true }, // 0x5b
  208. { "TOCLIENT_SET_STARS", 0, true }, // 0x5c
  209. null_command_factory, // 0x5d
  210. null_command_factory, // 0x5e
  211. null_command_factory, // 0x5f
  212. { "TOCLIENT_SRP_BYTES_S_B", 0, true }, // 0x60
  213. { "TOCLIENT_FORMSPEC_PREPEND", 0, true }, // 0x61
  214. { "TOCLIENT_MINIMAP_MODES", 0, true }, // 0x62
  215. { "TOCLIENT_SET_LIGHTING", 0, true }, // 0x63
  216. };