forked from citizenfx/fivem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBindNetLibrary.cpp
More file actions
123 lines (99 loc) · 3.11 KB
/
BindNetLibrary.cpp
File metadata and controls
123 lines (99 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/
#include "StdInc.h"
#include <NetLibrary.h>
#include <CefOverlay.h>
#include <ICoreGameInit.h>
#include <GameInit.h>
#include <nutsnbolts.h>
#include <DrawCommands.h>
#include <FontRenderer.h>
#include <msgpack.hpp>
#include <CoreConsole.h>
#include <se/Security.h>
#include "ConVarsPacketHandler.h"
static InitFunction initFunction([] ()
{
seGetCurrentContext()->AddAccessControlEntry(se::Principal{ "system.internal" }, se::Object{ "builtin" }, se::AccessType::Allow);
static NetLibrary* netLibrary;
NetLibrary::OnNetLibraryCreate.Connect([] (NetLibrary* library)
{
netLibrary = library;
static std::string netLibWarningMessage;
static std::mutex netLibWarningMessageLock;
library->OnConnectOKReceived.Connect([](NetAddress)
{
std::unique_lock<std::mutex> lock(netLibWarningMessageLock);
netLibWarningMessage = "";
});
library->OnReconnectProgress.Connect([](const std::string& msg)
{
std::unique_lock<std::mutex> lock(netLibWarningMessageLock);
netLibWarningMessage = msg;
});
OnPostFrontendRender.Connect([]()
{
if (!netLibWarningMessage.empty())
{
std::unique_lock<std::mutex> lock(netLibWarningMessageLock);
TheFonts->DrawText(ToWide(netLibWarningMessage), CRect(40.0f, 40.0f, 800.0f, 500.0f), CRGBA(255, 0, 0, 255), 40.0f, 1.0f, "Comic Sans MS");
}
});
library->OnStateChanged.Connect([] (NetLibrary::ConnectionState curState, NetLibrary::ConnectionState lastState)
{
if (curState == NetLibrary::CS_ACTIVE)
{
ICoreGameInit* gameInit = Instance<ICoreGameInit>::Get();
if (!gameInit->GetGameLoaded())
{
trace("^2Network connected, triggering initial game load...\n");
gameInit->LoadGameFirstLaunch([]()
{
// download frame code
Sleep(1);
return netLibrary->AreDownloadsComplete();
});
}
else
{
trace("^2Network connected, triggering game reload...\n");
gameInit->ReloadGame();
}
}
});
OnKillNetwork.Connect([=] (const char* message)
{
{
std::unique_lock<std::mutex> lock(netLibWarningMessageLock);
netLibWarningMessage = "";
}
library->Disconnect(message);
Instance<ICoreGameInit>::Get()->ClearVariable("storyMode");
Instance<ICoreGameInit>::Get()->ClearVariable("localMode");
});
OnKillNetworkDone.Connect([=]()
{
library->Disconnect();
});
// Process ConVar values sent from the server
library->AddPacketHandler<fx::ConVarsPacketHandler>(true);
});
Instance<ICoreGameInit>::Get()->OnGameRequestLoad.Connect([]()
{
nui::SetMainUI(false);
nui::DestroyFrame("mpMenu");
auto context = (netLibrary->GetConnectionState() != NetLibrary::CS_IDLE) ? ("server_" + netLibrary->GetTargetContext()) : "game";
nui::SwitchContext(context);
});
// #TODOLIBERTY: ?
#ifndef GTA_NY
OnFirstLoadCompleted.Connect([] ()
{
g_gameInit.SetGameLoaded();
});
#endif
});