Network.gd 19 KB

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