clientopcodes.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 "clientopcodes.h"
  18. #include "client/client.h"
  19. const static ToClientCommandHandler null_command_handler =
  20. {"TOCLIENT_NULL", TOCLIENT_STATE_ALL, &Client::handleCommand_Null};
  21. const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
  22. {
  23. null_command_handler, // 0x00 (never use this)
  24. null_command_handler, // 0x01
  25. { "TOCLIENT_HELLO", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_Hello }, // 0x02
  26. { "TOCLIENT_AUTH_ACCEPT", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_AuthAccept }, // 0x03
  27. { "TOCLIENT_ACCEPT_SUDO_MODE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_AcceptSudoMode}, // 0x04
  28. { "TOCLIENT_DENY_SUDO_MODE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_DenySudoMode}, // 0x05
  29. null_command_handler, // 0x06
  30. null_command_handler, // 0x07
  31. null_command_handler, // 0x08
  32. null_command_handler, // 0x09
  33. { "TOCLIENT_ACCESS_DENIED", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_AccessDenied }, // 0x0A
  34. null_command_handler, // 0x0B
  35. null_command_handler, // 0x0C
  36. null_command_handler, // 0x0D
  37. null_command_handler, // 0x0E
  38. null_command_handler, // 0x0F
  39. null_command_handler, // 0x10
  40. null_command_handler,
  41. null_command_handler,
  42. null_command_handler,
  43. null_command_handler,
  44. null_command_handler,
  45. null_command_handler,
  46. null_command_handler,
  47. null_command_handler,
  48. null_command_handler,
  49. null_command_handler,
  50. null_command_handler,
  51. null_command_handler,
  52. null_command_handler,
  53. null_command_handler,
  54. null_command_handler,
  55. { "TOCLIENT_BLOCKDATA", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_BlockData }, // 0x20
  56. { "TOCLIENT_ADDNODE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_AddNode }, // 0x21
  57. { "TOCLIENT_REMOVENODE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_RemoveNode }, // 0x22
  58. null_command_handler,
  59. null_command_handler,
  60. null_command_handler,
  61. null_command_handler,
  62. { "TOCLIENT_INVENTORY", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_Inventory }, // 0x27
  63. null_command_handler,
  64. { "TOCLIENT_TIME_OF_DAY", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_TimeOfDay }, // 0x29
  65. { "TOCLIENT_CSM_RESTRICTION_FLAGS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_CSMRestrictionFlags }, // 0x2A
  66. { "TOCLIENT_PLAYER_SPEED", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_PlayerSpeed }, // 0x2B
  67. { "TOCLIENT_MEDIA_PUSH", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MediaPush }, // 0x2C
  68. null_command_handler,
  69. null_command_handler,
  70. { "TOCLIENT_CHAT_MESSAGE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ChatMessage }, // 0x2F
  71. null_command_handler, // 0x30
  72. { "TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ActiveObjectRemoveAdd }, // 0x31
  73. { "TOCLIENT_ACTIVE_OBJECT_MESSAGES", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ActiveObjectMessages }, // 0x32
  74. { "TOCLIENT_HP", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HP }, // 0x33
  75. { "TOCLIENT_MOVE_PLAYER", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MovePlayer }, // 0x34
  76. { "TOCLIENT_ACCESS_DENIED_LEGACY", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_AccessDenied }, // 0x35
  77. { "TOCLIENT_FOV", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_Fov }, // 0x36
  78. { "TOCLIENT_DEATHSCREEN", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_DeathScreen }, // 0x37
  79. { "TOCLIENT_MEDIA", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_Media }, // 0x38
  80. null_command_handler,
  81. { "TOCLIENT_NODEDEF", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_NodeDef }, // 0x3a
  82. null_command_handler,
  83. { "TOCLIENT_ANNOUNCE_MEDIA", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_AnnounceMedia }, // 0x3c
  84. { "TOCLIENT_ITEMDEF", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ItemDef }, // 0x3d
  85. null_command_handler,
  86. { "TOCLIENT_PLAY_SOUND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_PlaySound }, // 0x3f
  87. { "TOCLIENT_STOP_SOUND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_StopSound }, // 0x40
  88. { "TOCLIENT_PRIVILEGES", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_Privileges }, // 0x41
  89. { "TOCLIENT_INVENTORY_FORMSPEC", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_InventoryFormSpec }, // 0x42
  90. { "TOCLIENT_DETACHED_INVENTORY", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_DetachedInventory }, // 0x43
  91. { "TOCLIENT_SHOW_FORMSPEC", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ShowFormSpec }, // 0x44
  92. { "TOCLIENT_MOVEMENT", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_Movement }, // 0x45
  93. { "TOCLIENT_SPAWN_PARTICLE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_SpawnParticle }, // 0x46
  94. { "TOCLIENT_ADD_PARTICLESPAWNER", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_AddParticleSpawner }, // 0x47
  95. null_command_handler,
  96. { "TOCLIENT_HUDADD", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudAdd }, // 0x49
  97. { "TOCLIENT_HUDRM", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudRemove }, // 0x4a
  98. { "TOCLIENT_HUDCHANGE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudChange }, // 0x4b
  99. { "TOCLIENT_HUD_SET_FLAGS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetFlags }, // 0x4c
  100. { "TOCLIENT_HUD_SET_PARAM", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetParam }, // 0x4d
  101. { "TOCLIENT_BREATH", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_Breath }, // 0x4e
  102. { "TOCLIENT_SET_SKY", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetSky }, // 0x4f
  103. { "TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_OverrideDayNightRatio }, // 0x50
  104. { "TOCLIENT_LOCAL_PLAYER_ANIMATIONS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_LocalPlayerAnimations }, // 0x51
  105. { "TOCLIENT_EYE_OFFSET", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_EyeOffset }, // 0x52
  106. { "TOCLIENT_DELETE_PARTICLESPAWNER", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_DeleteParticleSpawner }, // 0x53
  107. { "TOCLIENT_CLOUD_PARAMS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_CloudParams }, // 0x54
  108. { "TOCLIENT_FADE_SOUND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_FadeSound }, // 0x55
  109. { "TOCLIENT_UPDATE_PLAYER_LIST", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_UpdatePlayerList }, // 0x56
  110. { "TOCLIENT_MODCHANNEL_MSG", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ModChannelMsg }, // 0x57
  111. { "TOCLIENT_MODCHANNEL_SIGNAL", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ModChannelSignal }, // 0x58
  112. { "TOCLIENT_NODEMETA_CHANGED", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_NodemetaChanged }, // 0x59
  113. { "TOCLIENT_SET_SUN", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetSun }, // 0x5a
  114. { "TOCLIENT_SET_MOON", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetMoon }, // 0x5b
  115. { "TOCLIENT_SET_STARS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetStars }, // 0x5c
  116. { "TOCLIENT_MOVE_PLAYER_REL", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MovePlayerRel }, // 0x5d,
  117. null_command_handler,
  118. null_command_handler,
  119. { "TOCLIENT_SRP_BYTES_S_B", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_SrpBytesSandB }, // 0x60
  120. { "TOCLIENT_FORMSPEC_PREPEND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_FormspecPrepend }, // 0x61,
  121. { "TOCLIENT_MINIMAP_MODES", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MinimapModes }, // 0x62,
  122. { "TOCLIENT_SET_LIGHTING", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_SetLighting }, // 0x63,
  123. };
  124. const static ServerCommandFactory null_command_factory = { nullptr, 0, false };
  125. /*
  126. Channels used for Client -> Server communication
  127. 2: Notifications back to the server (e.g. GOTBLOCKS)
  128. 1: Init and Authentication
  129. 0: everything else
  130. Packet order is only guaranteed inside a channel, so packets that operate on
  131. the same objects are *required* to be in the same channel.
  132. */
  133. const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] =
  134. {
  135. null_command_factory, // 0x00
  136. null_command_factory, // 0x01
  137. { "TOSERVER_INIT", 1, false }, // 0x02
  138. null_command_factory, // 0x03
  139. null_command_factory, // 0x04
  140. null_command_factory, // 0x05
  141. null_command_factory, // 0x06
  142. null_command_factory, // 0x07
  143. null_command_factory, // 0x08
  144. null_command_factory, // 0x09
  145. null_command_factory, // 0x0a
  146. null_command_factory, // 0x0b
  147. null_command_factory, // 0x0c
  148. null_command_factory, // 0x0d
  149. null_command_factory, // 0x0e
  150. null_command_factory, // 0x0f
  151. null_command_factory, // 0x10
  152. { "TOSERVER_INIT2", 1, true }, // 0x11
  153. null_command_factory, // 0x12
  154. null_command_factory, // 0x13
  155. null_command_factory, // 0x14
  156. null_command_factory, // 0x15
  157. null_command_factory, // 0x16
  158. { "TOSERVER_MODCHANNEL_JOIN", 0, true }, // 0x17
  159. { "TOSERVER_MODCHANNEL_LEAVE", 0, true }, // 0x18
  160. { "TOSERVER_MODCHANNEL_MSG", 0, true }, // 0x19
  161. null_command_factory, // 0x1a
  162. null_command_factory, // 0x1b
  163. null_command_factory, // 0x1c
  164. null_command_factory, // 0x1d
  165. null_command_factory, // 0x1e
  166. null_command_factory, // 0x1f
  167. null_command_factory, // 0x20
  168. null_command_factory, // 0x21
  169. null_command_factory, // 0x22
  170. { "TOSERVER_PLAYERPOS", 0, false }, // 0x23
  171. { "TOSERVER_GOTBLOCKS", 2, true }, // 0x24
  172. { "TOSERVER_DELETEDBLOCKS", 2, true }, // 0x25
  173. null_command_factory, // 0x26
  174. null_command_factory, // 0x27
  175. null_command_factory, // 0x28
  176. null_command_factory, // 0x29
  177. null_command_factory, // 0x2a
  178. null_command_factory, // 0x2b
  179. null_command_factory, // 0x2c
  180. null_command_factory, // 0x2d
  181. null_command_factory, // 0x2e
  182. null_command_factory, // 0x2f
  183. null_command_factory, // 0x30
  184. { "TOSERVER_INVENTORY_ACTION", 0, true }, // 0x31
  185. { "TOSERVER_CHAT_MESSAGE", 0, true }, // 0x32
  186. null_command_factory, // 0x33
  187. null_command_factory, // 0x34
  188. { "TOSERVER_DAMAGE", 0, true }, // 0x35
  189. null_command_factory, // 0x36
  190. { "TOSERVER_PLAYERITEM", 0, true }, // 0x37
  191. { "TOSERVER_RESPAWN", 0, true }, // 0x38
  192. { "TOSERVER_INTERACT", 0, true }, // 0x39
  193. { "TOSERVER_REMOVED_SOUNDS", 2, true }, // 0x3a
  194. { "TOSERVER_NODEMETA_FIELDS", 0, true }, // 0x3b
  195. { "TOSERVER_INVENTORY_FIELDS", 0, true }, // 0x3c
  196. null_command_factory, // 0x3d
  197. null_command_factory, // 0x3e
  198. null_command_factory, // 0x3f
  199. { "TOSERVER_REQUEST_MEDIA", 1, true }, // 0x40
  200. { "TOSERVER_HAVE_MEDIA", 2, true }, // 0x41
  201. null_command_factory, // 0x42
  202. { "TOSERVER_CLIENT_READY", 1, true }, // 0x43
  203. null_command_factory, // 0x44
  204. null_command_factory, // 0x45
  205. null_command_factory, // 0x46
  206. null_command_factory, // 0x47
  207. null_command_factory, // 0x48
  208. null_command_factory, // 0x49
  209. null_command_factory, // 0x4a
  210. null_command_factory, // 0x4b
  211. null_command_factory, // 0x4c
  212. null_command_factory, // 0x4d
  213. null_command_factory, // 0x4e
  214. null_command_factory, // 0x4f
  215. { "TOSERVER_FIRST_SRP", 1, true }, // 0x50
  216. { "TOSERVER_SRP_BYTES_A", 1, true }, // 0x51
  217. { "TOSERVER_SRP_BYTES_M", 1, true }, // 0x52
  218. { "TOSERVER_UPDATE_CLIENT_INFO", 2, true }, // 0x53
  219. };