From 8fce58cc80ec97b95b348c0c7a4331257bd212a7 Mon Sep 17 00:00:00 2001 From: guava Date: Sun, 29 Jan 2017 23:27:13 +0100 Subject: [PATCH] 'new' sessionmanager resource --- .../[system]/sessionmanager/__resource.lua | 10 +- .../client/activationhandler.lua | 27 ---- .../sessionmanager/client/hostservice.lua | 55 -------- .../sessionmanager/client/initial.lua | 124 ------------------ .../sessionmanager/client/leavehandler.lua | 31 ----- .../sessionmanager/client/sessionstarter.lua | 26 ---- .../sessionmanager/server/host_lock.lua | 2 + 7 files changed, 3 insertions(+), 272 deletions(-) delete mode 100644 resources/[system]/sessionmanager/client/activationhandler.lua delete mode 100644 resources/[system]/sessionmanager/client/hostservice.lua delete mode 100644 resources/[system]/sessionmanager/client/initial.lua delete mode 100644 resources/[system]/sessionmanager/client/leavehandler.lua delete mode 100644 resources/[system]/sessionmanager/client/sessionstarter.lua diff --git a/resources/[system]/sessionmanager/__resource.lua b/resources/[system]/sessionmanager/__resource.lua index 70dc952..fddef85 100644 --- a/resources/[system]/sessionmanager/__resource.lua +++ b/resources/[system]/sessionmanager/__resource.lua @@ -1,11 +1,3 @@ -client_scripts { - 'client/initial.lua', - 'client/leavehandler.lua', - 'client/activationhandler.lua', - 'client/hostservice.lua', - 'client/sessionstarter.lua' -} +resource_manifest_version '77731fab-63ca-442c-a67b-abc70f28dfa5' server_script 'server/host_lock.lua' - -export 'serviceHostStuff' diff --git a/resources/[system]/sessionmanager/client/activationhandler.lua b/resources/[system]/sessionmanager/client/activationhandler.lua deleted file mode 100644 index 43ef662..0000000 --- a/resources/[system]/sessionmanager/client/activationhandler.lua +++ /dev/null @@ -1,27 +0,0 @@ --- triggers an event when the local network player becomes active -AddEventHandler('sessionInitialized', function() - local playerId = GetPlayerId() - - -- create a looping thread - CreateThread(function() - -- wait until the player becomes active - while not IsNetworkPlayerActive(playerId) do - Wait(0) - end - - -- set some defaults - AllowGameToPauseForStreaming(true) - - SetMaxWantedLevel(6) - SetWantedMultiplier(0.9999999) - SetCreateRandomCops(true) - SetDitchPoliceModels(false) - - DisplayPlayerNames(true) - NetworkSetHealthReticuleOption(true) - - -- trigger an event on both the local client and the server - TriggerEvent('playerActivated') - TriggerServerEvent('playerActivated') - end) -end) diff --git a/resources/[system]/sessionmanager/client/hostservice.lua b/resources/[system]/sessionmanager/client/hostservice.lua deleted file mode 100644 index b731ad4..0000000 --- a/resources/[system]/sessionmanager/client/hostservice.lua +++ /dev/null @@ -1,55 +0,0 @@ --- serving the duties of the office of the host - --- two functions from GTA script; they do 'something lock-ish' -local function acquireHostLock() - if IsThisMachineTheServer() then - SetThisMachineRunningServerScript(true) - return true - end - - return false -end - -local function releaseHostLock() - SetThisMachineRunningServerScript(false) -end - --- handle msgGetReadyToStartPlaying sending -function serviceHostStuff() - -- acquire the host lock - if acquireHostLock() then - -- check if players want to join - for i = 0, 31 do - -- does this index? - if PlayerWantsToJoinNetworkGame(i) then - -- well, get ready to start playing! - TellNetPlayerToStartPlaying(i, 0) - - TriggerServerEvent('playerJoining', i) - end - end - - -- release the host lock - releaseHostLock() - end -end - --- host service loop -CreateThread(function() - NetworkSetScriptLobbyState(false) - SwitchArrowAboveBlippedPickups(true) - UsePlayerColourInsteadOfTeamColour(true) - LoadAllPathNodes(true) - SetSyncWeatherAndGameTime(true) - - while true do - Wait(0) - - serviceHostStuff() - - -- launch the local player, for the initial host scenario - if LocalPlayerIsReadyToStartPlaying() then - LaunchLocalPlayerInNetworkGame() - end - end -end) diff --git a/resources/[system]/sessionmanager/client/initial.lua b/resources/[system]/sessionmanager/client/initial.lua deleted file mode 100644 index 34674ce..0000000 --- a/resources/[system]/sessionmanager/client/initial.lua +++ /dev/null @@ -1,124 +0,0 @@ --- state variable for session host lock -local sessionHostPending = false -local sessionHostResult - -AddEventHandler('sessionHostResult', function(result) - if not sessionHostPending then - return - end - - sessionHostResult = result - sessionHostPending = false -end) - -local attempts = 0 - --- allow early script to create the player -AddEventHandler('playerInfoCreated', function() - CreateThread(function() - -- so that the game won't trigger the citizen disconnect handler - SafeguardDisconnect(true) - - -- loop for 3 times - while attempts < 3 do - -- 'find' games (this will store the host session in memory, or if no host exists, tell us later) - NetworkFindGame(16, false, 0, 0) - - -- we don't have to wait for the finding to complete; TestSessionFind.cpp in hooks_ny will instantly return - local gamesFound = NetworkGetNumberOfGames(_r) - - -- if we found at least one game (if the game isn't hooked, this can be any amount; but - -- we can't trust the implementation in that case anyway) - local needsToHost = true -- whether we need to host after completing a possible join - - if gamesFound > 0 then - -- join the game - NetworkJoinGame(0) - - SetLoadingText('Entering session') -- status text - - -- wait for the join to complete - while NetworkJoinGamePending() do - Wait(0) - end - - -- if we succeeded, we're now a session member, and will not need to host - if NetworkJoinGameSucceeded() then - needsToHost = false - break - end - end - - -- if we didn't find any games, or a join timed out, we'll *consider* hosting - if needsToHost then - -- make sure we don't have an actual other host waiting for us - sessionHostPending = true -- to trigger a wait loop below - - TriggerServerEvent('hostingSession') - - SetLoadingText('Initializing session') -- some vague status text - - -- wait for the server to respond to our request - while sessionHostPending do - Wait(0) - end - - if sessionHostResult == 'wait' then - -- TODO: not implemented yet: wait for a message from the server, then attempt finding a game/joining a game again - sessionHostPending = true - - while sessionHostPending do - Wait(0) - end - - if sessionHostResult == 'free' then - goto endLoop - end - end - - if sessionHostResult == 'conflict' and gamesFound > 0 then - -- there's already a host which is working perfectly fine; show a message to the player - --error('session creation conflict: could not connect to original host') - echo("session creation conflict\n") - goto endLoop - end - - -- we got a green light to host; start hosting - if not NetworkHostGameE1(16, false, 32, false, 0, 0) then - echo("session creation failure from NetworkHostGameE1\n") - error('failed to initialize session') - end - - -- wait for internal processing to complete - while NetworkHostGamePending() do - Wait(0) - end - - -- another failure check - if not NetworkHostGameSucceeded() then - echo("session creation failure from NetworkHostGameSucceeded\n") - error('failed to initialize session') - end - - TriggerServerEvent('hostedSession') - - break - end - - ::endLoop:: - attempts = attempts + 1 - end - - SafeguardDisconnect(false) - - if attempts >= 3 then - error("Could not connect to session provider.") - end - - SetLoadingText('Look at that!') - - -- signal local game-specific resources to start - TriggerEvent('sessionInitialized') - TriggerServerEvent('sessionInitialized') - end) -end) diff --git a/resources/[system]/sessionmanager/client/leavehandler.lua b/resources/[system]/sessionmanager/client/leavehandler.lua deleted file mode 100644 index c6aca3c..0000000 --- a/resources/[system]/sessionmanager/client/leavehandler.lua +++ /dev/null @@ -1,31 +0,0 @@ --- handles the script end of the flag the 'leave game' option in the pause menu sets -CreateThread(function() - while true do - Wait(0) - - -- if the flag is set - if DoesGameCodeWantToLeaveNetworkSession() then - -- if we're part of a started session; end it first (FIXME: will this break others when we're host?) - if NetworkIsSessionStarted() then - NetworkEndSession() - - -- wait for the session to be ended - while NetworkEndSessionPending() do - Wait(0) - end - end - - -- attempt to leave the game - NetworkLeaveGame() - - -- while we're waiting to leave... - while NetworkLeaveGamePending() do - Wait(0) - end - - -- reinitialize the game as a network game (TODO: call into citigame for UI/NetLibrary leaving) - --ShutdownAndLaunchNetworkGame(0) -- episode id is arg - ShutdownNetworkCit('Left'); - end - end -end) diff --git a/resources/[system]/sessionmanager/client/sessionstarter.lua b/resources/[system]/sessionmanager/client/sessionstarter.lua deleted file mode 100644 index a5233d8..0000000 --- a/resources/[system]/sessionmanager/client/sessionstarter.lua +++ /dev/null @@ -1,26 +0,0 @@ --- more rline stuff, this does some late-term session management (which I think has some race condition with launching the network player?) -AddEventHandler('sessionInitialized', function() - if IsThisMachineTheServer() then - -- unknown stuff, seems needed though - NetworkChangeExtendedGameConfigCit() - - CreateThread(function() - Wait(1500) - - if not NetworkIsSessionStarted() then - NetworkStartSession() - - while NetworkStartSessionPending() do - Wait(0) - end - - if not NetworkStartSessionSucceeded() then - ForceLoadingScreen(0) - SetMsgForLoadingScreen("MO_SNI") - - return - end - end - end) - end -end) diff --git a/resources/[system]/sessionmanager/server/host_lock.lua b/resources/[system]/sessionmanager/server/host_lock.lua index ee25f4e..1a71da4 100644 --- a/resources/[system]/sessionmanager/server/host_lock.lua +++ b/resources/[system]/sessionmanager/server/host_lock.lua @@ -65,3 +65,5 @@ AddEventHandler('hostedSession', function() currentHosting = nil end) + +EnableEnhancedHostSupport(true) \ No newline at end of file