Network.gd 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. extends Node
  2. #
  3. signal peer_update
  4. signal accounts_list_update
  5. signal characters_list_update
  6. signal online_accounts_update
  7. signal online_characters_update
  8. signal online_agents_update
  9. #
  10. var Client = null
  11. var ENetServer = null
  12. var WebSocketServer = null
  13. enum EChannel
  14. {
  15. CONNECT = 0,
  16. ACTION,
  17. MAP,
  18. NAVIGATION,
  19. ENTITY,
  20. BULK,
  21. }
  22. # Auth
  23. @rpc("any_peer", "call_remote", "reliable", EChannel.CONNECT)
  24. func CreateAccount(accountName : String, password : String, email : String, peerID : int = NetworkCommons.PeerAuthorityID) -> bool:
  25. return CallServer("CreateAccount", [accountName, password, email], peerID, NetworkCommons.DelayLogin)
  26. @rpc("any_peer", "call_remote", "reliable", EChannel.CONNECT)
  27. func ConnectAccount(accountName : String, password : String, peerID : int = NetworkCommons.PeerAuthorityID) -> bool:
  28. return CallServer("ConnectAccount", [accountName, password], peerID, NetworkCommons.DelayLogin)
  29. @rpc("authority", "call_remote", "reliable", EChannel.CONNECT)
  30. func AuthError(err : NetworkCommons.AuthError, peerID : int = NetworkCommons.PeerOfflineID):
  31. CallClient("AuthError", [err], peerID)
  32. @rpc("any_peer", "call_remote", "reliable", EChannel.CONNECT)
  33. func DisconnectAccount(peerID : int = NetworkCommons.PeerAuthorityID):
  34. CallServer("DisconnectAccount", [], peerID)
  35. # Character
  36. @rpc("authority", "call_remote", "reliable", EChannel.CONNECT)
  37. func CharacterInfo(info : Dictionary, equipment : Dictionary, peerID : int = NetworkCommons.PeerOfflineID):
  38. CallClient("CharacterInfo", [info, equipment], peerID)
  39. @rpc("any_peer", "call_remote", "reliable", EChannel.CONNECT)
  40. func CreateCharacter(charName : String, traits : Dictionary, attributes : Dictionary, peerID : int = NetworkCommons.PeerAuthorityID) -> bool:
  41. return CallServer("CreateCharacter", [charName, traits, attributes], peerID, NetworkCommons.DelayLogin)
  42. @rpc("any_peer", "call_remote", "reliable", EChannel.CONNECT)
  43. func DeleteCharacter(charName : String, peerID : int = NetworkCommons.PeerAuthorityID) -> bool:
  44. return CallServer("DeleteCharacter", [charName], peerID, NetworkCommons.DelayLogin)
  45. @rpc("any_peer", "call_remote", "reliable", EChannel.CONNECT)
  46. func ConnectCharacter(nickname : String, peerID : int = NetworkCommons.PeerAuthorityID) -> bool:
  47. return CallServer("ConnectCharacter", [nickname], peerID, NetworkCommons.DelayLogin)
  48. @rpc("authority", "call_remote", "reliable", EChannel.CONNECT)
  49. func CharacterError(err : NetworkCommons.CharacterError, peerID : int = NetworkCommons.PeerOfflineID):
  50. CallClient("CharacterError", [err], peerID)
  51. @rpc("any_peer", "call_remote", "reliable", EChannel.CONNECT)
  52. func DisconnectCharacter(peerID : int = NetworkCommons.PeerAuthorityID):
  53. CallServer("DisconnectCharacter", [], peerID)
  54. @rpc("any_peer", "call_remote", "reliable", EChannel.CONNECT)
  55. func CharacterListing(peerID : int = NetworkCommons.PeerAuthorityID):
  56. CallServer("CharacterListing", [], peerID)
  57. # Respawn
  58. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  59. func TriggerRespawn(peerID : int = NetworkCommons.PeerAuthorityID):
  60. CallServer("TriggerRespawn", [], peerID)
  61. # Warp
  62. @rpc("any_peer", "call_remote", "unreliable", EChannel.MAP)
  63. func TriggerWarp(peerID : int = NetworkCommons.PeerAuthorityID):
  64. CallServer("TriggerWarp", [], peerID)
  65. @rpc("authority", "call_remote", "reliable", EChannel.MAP)
  66. func WarpPlayer(mapID : int, playerPos : Vector2, peerID : int = NetworkCommons.PeerOfflineID):
  67. CallClient("WarpPlayer", [mapID, playerPos], peerID)
  68. # Entities
  69. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  70. func AddEntity(agentRID : int, actorType : ActorCommons.Type, currentShape : int, velocity : Vector2, position : Vector2i, orientation : Vector2, state : ActorCommons.State, skillCastID : int, peerID : int = NetworkCommons.PeerOfflineID):
  71. CallClient("AddEntity", [agentRID, actorType, currentShape, velocity, position, orientation, state, skillCastID], peerID)
  72. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  73. func AddPlayer(agentRID : int, actorType : ActorCommons.Type, shape : int, spirit : int, currentShape : int, nick : String, velocity : Vector2, position : Vector2i, orientation : Vector2, state : ActorCommons.State, skillCastID : int, level : int, health : int, hairstyle : int, haircolor : int, gender : ActorCommons.Gender, race : int, skintone : int, equipment : Dictionary, peerID : int = NetworkCommons.PeerOfflineID):
  74. CallClient("AddPlayer", [agentRID, actorType, shape, spirit, currentShape, nick, velocity, position, orientation, state, skillCastID, level, health, hairstyle, haircolor, gender, race, skintone, equipment], peerID)
  75. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  76. func RemoveEntity(agentRID : int, peerID : int = NetworkCommons.PeerOfflineID):
  77. CallClient("RemoveEntity", [agentRID], peerID)
  78. # Notification
  79. @rpc("any_peer", "call_remote", "unreliable_ordered", EChannel.MAP)
  80. func PushNotification(notif : String, peerID : int = NetworkCommons.PeerOfflineID):
  81. CallClient("PushNotification", [notif], peerID)
  82. # Navigation
  83. @rpc("any_peer", "call_remote", "unreliable_ordered", EChannel.NAVIGATION)
  84. func SetClickPos(pos : Vector2, peerID : int = NetworkCommons.PeerAuthorityID):
  85. CallServer("SetClickPos", [pos], peerID)
  86. @rpc("any_peer", "call_remote", "reliable", EChannel.NAVIGATION)
  87. func SetMovePos(pos : Vector2, peerID : int = NetworkCommons.PeerAuthorityID):
  88. CallServer("SetMovePos", [pos], peerID, NetworkCommons.DelayInstant)
  89. @rpc("authority", "call_remote", "unreliable_ordered", EChannel.NAVIGATION)
  90. func UpdateEntity(agentRID : int, velocity : Vector2, position : Vector2, peerID : int = NetworkCommons.PeerOfflineID):
  91. CallClient("UpdateEntity", [agentRID, velocity, position], peerID)
  92. @rpc("authority", "call_remote", "reliable", EChannel.NAVIGATION)
  93. func FullUpdateEntity(agentRID : int, velocity : Vector2, position : Vector2, orientation : Vector2, agentState : ActorCommons.State, skillCastID : int, peerID : int = NetworkCommons.PeerOfflineID):
  94. CallClient("FullUpdateEntity", [agentRID, velocity, position, orientation, agentState, skillCastID], peerID)
  95. @rpc("any_peer", "call_remote", "reliable", EChannel.NAVIGATION)
  96. func ClearNavigation(peerID : int = NetworkCommons.PeerAuthorityID):
  97. CallServer("ClearNavigation", [], peerID)
  98. # Emote
  99. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  100. func TriggerEmote(emoteID : int, peerID : int = NetworkCommons.PeerAuthorityID):
  101. CallServer("TriggerEmote", [emoteID], peerID)
  102. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  103. func EmotePlayer(senderagentRID : int, emoteID : int, peerID : int = NetworkCommons.PeerOfflineID):
  104. CallClient("EmotePlayer", [senderagentRID, emoteID], peerID)
  105. # Sit
  106. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  107. func TriggerSit(peerID : int = NetworkCommons.PeerAuthorityID):
  108. CallServer("TriggerSit", [], peerID)
  109. # Chat
  110. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  111. func TriggerChat(text : String, peerID : int = NetworkCommons.PeerAuthorityID):
  112. CallServer("TriggerChat", [text], peerID)
  113. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  114. func ChatAgent(agentRID : int, text : String, peerID : int = NetworkCommons.PeerOfflineID):
  115. CallClient("ChatAgent", [agentRID, text], peerID)
  116. # Context
  117. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  118. func ToggleContext(enable : bool, peerID : int = NetworkCommons.PeerOfflineID):
  119. CallClient("ToggleContext", [enable], peerID)
  120. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  121. func ContextText(author : String, text : String, peerID : int = NetworkCommons.PeerOfflineID):
  122. CallClient("ContextText", [author, text], peerID)
  123. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  124. func ContextContinue(peerID : int = NetworkCommons.PeerOfflineID):
  125. CallClient("ContextContinue", [], peerID)
  126. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  127. func ContextClose(peerID : int = NetworkCommons.PeerOfflineID):
  128. CallClient("ContextClose", [], peerID)
  129. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  130. func ContextChoice(texts : PackedStringArray, peerID : int = NetworkCommons.PeerOfflineID):
  131. CallClient("ContextChoice", [texts], peerID)
  132. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  133. func TriggerChoice(choiceID : int, peerID : int = NetworkCommons.PeerAuthorityID):
  134. CallServer("TriggerChoice", [choiceID], peerID)
  135. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  136. func TriggerCloseContext(peerID : int = NetworkCommons.PeerAuthorityID):
  137. CallServer("TriggerCloseContext", [], peerID)
  138. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  139. func TriggerNextContext(peerID : int = NetworkCommons.PeerAuthorityID):
  140. CallServer("TriggerNextContext", [], peerID)
  141. # Interact
  142. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  143. func TriggerInteract(targetRID : int, peerID : int = NetworkCommons.PeerAuthorityID):
  144. CallServer("TriggerInteract", [targetRID], peerID)
  145. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  146. func TriggerExplore(peerID : int = NetworkCommons.PeerAuthorityID):
  147. CallServer("TriggerExplore", [], peerID)
  148. # Combat
  149. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  150. func TriggerCast(targetRID : int, skillID : int, peerID : int = NetworkCommons.PeerAuthorityID):
  151. CallServer("TriggerCast", [targetRID, skillID], peerID, NetworkCommons.DelayShort)
  152. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  153. func TargetAlteration(agentRID : int, targetRID : int, value : int, alteration : ActorCommons.Alteration, skillID : int, peerID : int = NetworkCommons.PeerOfflineID):
  154. CallClient("TargetAlteration", [agentRID, targetRID, value, alteration, skillID], peerID)
  155. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  156. func Casted(agentRID : int, skillID: int, cooldown : float, peerID : int = NetworkCommons.PeerOfflineID):
  157. CallClient("Casted", [agentRID, skillID, cooldown], peerID)
  158. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  159. func ThrowProjectile(agentRID : int, targetPos : Vector2, skillID: int, peerID : int = NetworkCommons.PeerOfflineID):
  160. CallClient("ThrowProjectile", [agentRID, targetPos, skillID], peerID)
  161. # Morph
  162. @rpc("any_peer", "call_remote", "reliable", EChannel.ACTION)
  163. func TriggerMorph(peerID : int = NetworkCommons.PeerAuthorityID):
  164. CallServer("TriggerMorph", [], peerID)
  165. @rpc("authority", "call_remote", "reliable", EChannel.ACTION)
  166. func Morphed(agentRID : int, morphID : int, notifyMorphing : bool, peerID : int = NetworkCommons.PeerOfflineID):
  167. CallClient("Morphed", [agentRID, morphID, notifyMorphing], peerID)
  168. # Stats
  169. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  170. func UpdatePublicStats(agentRID : int, level : int, health : int, hairstyle : int, haircolor : int, gender : ActorCommons.Gender, race : int, skintone : int, currentShape : int, peerID : int = NetworkCommons.PeerOfflineID):
  171. CallClient("UpdatePublicStats", [agentRID, level, health, hairstyle, haircolor, gender, race, skintone, currentShape], peerID)
  172. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  173. func UpdatePrivateStats(experience : int, gp : int, mana : int, stamina : int, karma : int, weight : float, shape : int, spirit : int, peerID : int = NetworkCommons.PeerOfflineID):
  174. CallClient("UpdatePrivateStats", [experience, gp, mana, stamina, karma, weight, shape, spirit], peerID)
  175. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  176. func UpdateAttributes(strength : int, vitality : int, agility : int, endurance : int, concentration : int, peerID : int = NetworkCommons.PeerOfflineID):
  177. CallClient("UpdateAttributes", [strength, vitality, agility, endurance, concentration], peerID)
  178. @rpc("any_peer", "call_remote", "reliable", EChannel.ENTITY)
  179. func TriggerSelect(agentRID : int, peerID : int = NetworkCommons.PeerAuthorityID):
  180. CallServer("TriggerSelect", [agentRID], peerID)
  181. @rpc("any_peer", "call_remote", "reliable", EChannel.ENTITY)
  182. func SetAttributes(strength, vitality, agility, endurance, concentration, peerID : int = NetworkCommons.PeerAuthorityID):
  183. CallServer("SetAttributes", [strength, vitality, agility, endurance, concentration], peerID)
  184. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  185. func LevelUp(agentRID : int, peerID : int = NetworkCommons.PeerOfflineID):
  186. CallClient("LevelUp", [agentRID], peerID)
  187. # Inventory
  188. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  189. func ItemAdded(itemID : int, customfield : StringName, count : int, peerID : int = NetworkCommons.PeerOfflineID):
  190. CallClient("ItemAdded", [itemID, customfield, count], peerID)
  191. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  192. func ItemRemoved(itemID : int, customfield : StringName, count : int, peerID : int = NetworkCommons.PeerOfflineID):
  193. CallClient("ItemRemoved", [itemID, customfield, count], peerID)
  194. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  195. func ItemEquiped(agentRID : int, itemID : int, customfield : StringName, state : bool, peerID : int = NetworkCommons.PeerOfflineID):
  196. CallClient("ItemEquiped", [agentRID, itemID, customfield, state], peerID)
  197. @rpc("any_peer", "call_remote", "reliable", EChannel.ENTITY)
  198. func UseItem(itemID : int, peerID : int = NetworkCommons.PeerAuthorityID):
  199. CallServer("UseItem", [itemID], peerID)
  200. @rpc("any_peer", "call_remote", "reliable", EChannel.ENTITY)
  201. func DropItem(itemID : int, customfield : StringName, itemCount : int, peerID : int = NetworkCommons.PeerAuthorityID):
  202. CallServer("DropItem", [itemID, customfield, itemCount], peerID)
  203. @rpc("any_peer", "call_remote", "reliable", EChannel.ENTITY)
  204. func EquipItem(itemID : int, customfield : StringName, peerID : int = NetworkCommons.PeerAuthorityID):
  205. CallServer("EquipItem", [itemID, customfield], peerID)
  206. @rpc("any_peer", "call_remote", "reliable", EChannel.ENTITY)
  207. func UnequipItem(itemID : int, customfield : StringName, peerID : int = NetworkCommons.PeerAuthorityID):
  208. CallServer("UnequipItem", [itemID, customfield], peerID)
  209. @rpc("any_peer", "call_remote", "reliable", EChannel.ENTITY)
  210. func RetrieveInventory(peerID : int = NetworkCommons.PeerAuthorityID):
  211. CallServer("RetrieveInventory", [], peerID)
  212. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  213. func RefreshInventory(cells : Array[Dictionary], peerID : int = NetworkCommons.PeerOfflineID):
  214. CallClient("RefreshInventory", [cells], peerID)
  215. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  216. func RefreshEquipment(agentRID : int, equipment : Dictionary, peerID : int = NetworkCommons.PeerOfflineID):
  217. CallClient("RefreshEquipment", [agentRID, equipment], peerID)
  218. # Drop
  219. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  220. func DropAdded(dropID : int, itemID : int, customfield : StringName, pos : Vector2, peerID : int = NetworkCommons.PeerOfflineID):
  221. CallClient("DropAdded", [dropID, itemID, customfield, pos], peerID)
  222. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  223. func DropRemoved(dropID : int, peerID : int = NetworkCommons.PeerOfflineID):
  224. CallClient("DropRemoved", [dropID], peerID)
  225. @rpc("any_peer", "call_remote", "reliable", EChannel.ENTITY)
  226. func PickupDrop(dropID : int, peerID : int = NetworkCommons.PeerAuthorityID):
  227. CallServer("PickupDrop", [dropID], peerID)
  228. # Progress
  229. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  230. func UpdateSkill(skillID : int, level : int, peerID : int = NetworkCommons.PeerOfflineID):
  231. CallClient("UpdateSkill", [skillID, level], peerID)
  232. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  233. func UpdateBestiary(mobID : int, count : int, peerID : int = NetworkCommons.PeerOfflineID):
  234. CallClient("UpdateBestiary", [mobID, count], peerID)
  235. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  236. func UpdateQuest(questID : int, state : int, peerID : int = NetworkCommons.PeerOfflineID):
  237. CallClient("UpdateQuest", [questID, state], peerID)
  238. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  239. func RefreshProgress(skills : Dictionary, quests : Dictionary, bestiary : Dictionary, peerID : int = NetworkCommons.PeerOfflineID):
  240. CallClient("RefreshProgress", [skills, quests, bestiary], peerID)
  241. @rpc("any_peer", "call_remote", "reliable", EChannel.ENTITY)
  242. func RetrieveCharacterInformation(peerID : int = NetworkCommons.PeerAuthorityID):
  243. CallServer("RetrieveCharacterInformation", [], peerID)
  244. # Bulk RPC calls
  245. @rpc("authority", "call_remote", "reliable", EChannel.ENTITY)
  246. func BulkCall(methodName : StringName, bulkedArgs : Array, peerID : int = NetworkCommons.PeerOfflineID):
  247. if WebSocketServer and not WebSocketServer.isOffline and Peers.IsUsingWebSocket(peerID):
  248. WebSocketServer.multiplayerAPI.rpc(peerID, self, "BulkCall", [methodName, bulkedArgs])
  249. elif ENetServer and not ENetServer.isOffline:
  250. ENetServer.multiplayerAPI.rpc(peerID, self, "BulkCall", [methodName, bulkedArgs])
  251. else:
  252. for args in bulkedArgs:
  253. Client.callv.call_deferred(methodName, args + [peerID])
  254. func Bulk(methodName : StringName, args : Array, peerID : int):
  255. if Peers.IsUsingWebSocket(peerID):
  256. WebSocketServer.Bulk(methodName, args, peerID)
  257. else:
  258. ENetServer.Bulk(methodName, args, peerID)
  259. # Notify peers
  260. func NotifyNeighbours(agent : BaseAgent, callbackName : StringName, args : Array, inclusive : bool = true, bulk : bool = false):
  261. if not agent:
  262. assert(false, "Agent is misintantiated, could not notify instance players with " + callbackName)
  263. return
  264. var currentagentRID = agent.get_rid().get_id()
  265. if inclusive and agent is PlayerAgent:
  266. if bulk:
  267. Network.Bulk(callbackName, [currentagentRID] + args, agent.peerID)
  268. else:
  269. Network.callv(callbackName, [currentagentRID] + args + [agent.peerID])
  270. var inst : WorldInstance = WorldAgent.GetInstanceFromAgent(agent)
  271. if inst:
  272. for player in inst.players:
  273. if player != null and player != agent and player.peerID != NetworkCommons.PeerUnknownID:
  274. if bulk:
  275. Network.Bulk(callbackName, [currentagentRID] + args, player.peerID)
  276. else:
  277. Network.callv(callbackName, [currentagentRID] + args + [player.peerID])
  278. func NotifyInstance(inst : WorldInstance, callbackName : StringName, args : Array):
  279. if inst:
  280. for player in inst.players:
  281. if player != null:
  282. if player.peerID != NetworkCommons.PeerUnknownID:
  283. Network.callv(callbackName, args + [player.peerID])
  284. # Peer calls
  285. func CallServer(methodName : StringName, args : Array, peerID : int, actionDelta : int = NetworkCommons.DelayDefault) -> bool:
  286. if not Peers.Footprint(peerID, methodName, actionDelta):
  287. return false
  288. if Client and not Client.isOffline:
  289. Client.multiplayerAPI.rpc(peerID, self, methodName, args + [Client.interfaceID])
  290. elif Peers.IsUsingWebSocket(peerID):
  291. WebSocketServer.callv.call_deferred(methodName, args + [peerID])
  292. else:
  293. ENetServer.callv.call_deferred(methodName, args + [peerID])
  294. return true
  295. func CallClient(methodName : StringName, args : Array, peerID : int):
  296. if WebSocketServer and not WebSocketServer.isOffline and Peers.IsUsingWebSocket(peerID):
  297. WebSocketServer.multiplayerAPI.rpc(peerID, self, methodName, args + [peerID])
  298. elif ENetServer and not ENetServer.isOffline:
  299. ENetServer.multiplayerAPI.rpc(peerID, self, methodName, args + [peerID])
  300. else:
  301. Client.callv.call_deferred(methodName, args + [peerID])
  302. # Service handling
  303. func Mode(isClient : bool, isServer : bool):
  304. var isOffline : bool = isClient and isServer
  305. if isClient:
  306. Client = NetClient.new(LauncherCommons.isWeb, isOffline, isOffline or NetworkCommons.IsLocal)
  307. if isServer:
  308. if NetworkCommons.UseENet:
  309. ENetServer = NetServer.new(false, isOffline, NetworkCommons.IsLocal)
  310. if NetworkCommons.UseWebSocket and not isOffline:
  311. WebSocketServer = NetServer.new(true, isOffline, NetworkCommons.IsLocal)
  312. func _init():
  313. if not NetworkCommons.OnlineListPath.is_empty():
  314. online_agents_update.connect(OnlineList.UpdateJson)
  315. func Destroy():
  316. if Client:
  317. Client.Destroy()
  318. Client = null
  319. if ENetServer:
  320. ENetServer.Destroy()
  321. ENetServer = null
  322. if WebSocketServer:
  323. WebSocketServer.Destroy()
  324. WebSocketServer = null