DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
InviteMenu.c
См. документацию.
1class InviteMenu extends UIScriptedMenu
2{
4 protected const int LOGOUT_REPLY_TIMEOUT_MS = 5000;
6 protected const int JOIN_LEAD_TIME_S = 1;
7
9 private MultilineTextWidget m_DescriptionText;
10 private int m_iTime;
11 private bool m_bJoining;
12
14
16 {
17 // the countdown is driven by the server, it is unknown until it answers the logout request
18 m_iTime = 0;
19
21
22 if (g_Game.GetMission())
23 {
24 g_Game.GetMission().AddActiveInputExcludes({"menu"});
25
26 g_Game.GetMission().GetHud().ShowHudUI(false);
27 g_Game.GetMission().GetHud().ShowQuickbarUI(false);
28 }
29 }
30
32 {
33 if (g_Game && g_Game.GetMission())
34 {
35 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
36 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.OnLogoutReplyTimeout);
37
38 // deliberately no LogoutRequestCancel here, see Init
39
40 g_Game.GetMission().RemoveActiveInputExcludes({"menu"},true);
41
42 g_Game.GetMission().GetHud().ShowHudUI(true);
43 g_Game.GetMission().GetHud().ShowQuickbarUI(true);
44 }
45 }
46
47 override Widget Init()
48 {
49 layoutRoot = g_Game.GetWorkspace().CreateWidgets("gui/layouts/day_z_invite_dialog.layout");
50
51 m_LogoutTimeText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtLogoutTime"));
52 m_DescriptionText = MultilineTextWidget.Cast(layoutRoot.FindAnyWidget("txtDescription"));
53
54 m_DescriptionText.SetText("#layout_logout_dialog_note_invite");
55 m_DescriptionText.Update();
56
57 // accepting the invite commits the player to the join, there is no way back out of it
58 layoutRoot.FindAnyWidget("bCancel").Show(false);
59 layoutRoot.FindAnyWidget("BottomConsoleToolbar").Show(false);
60
61 // a logout the player started themselves may already be running. Take it over before
62 // asking for our own, otherwise the server ignores the request as a duplicate and the
63 // stale dialog cancels the logout we are waiting on. Releasing the old dialog clears the
64 // emote launcher, so this has to happen before we start our own sit emote.
65 MissionGameplay mission = MissionGameplay.Cast(g_Game.GetMission());
66 if (mission)
67 mission.TakeOverLogoutMenu();
68
69 // player should sit down if possible
70 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
71 if (player && player.GetEmoteManager() && !player.IsRestrained() && !player.IsUnconscious())
72 {
73 player.GetEmoteManager().CreateEmoteCBFromMenu(EmoteConstants.ID_EMOTE_SITA);
74 player.GetEmoteManager().GetEmoteLauncher().SetForced(EmoteLauncher.FORCE_DIFFERENT);
75 }
76
77 // The target server only accepts us once this server has released the account on the
78 // lobby backend, which happens at the end of the regular logout, so request one and
79 // wait for it instead of dropping the connection straight away.
80 // Once this request is out the logout is final. Nothing here ever sends
81 // LogoutRequestCancel, not even on an irregular close, because being able to time that
82 // cancel against the server's deadline is exploitable. If this dialog is destroyed
83 // before the join (lag dialogue, death, respawn or login screens) the server's own
84 // deadline resolves the session and the character is saved as usual.
85 g_Game.LogoutRequestTime();
88
89 return layoutRoot;
90 }
91
93 {
94 m_LogoutTimeText.SetText(" ");
95 }
96
98 void StartCountdown(int time)
99 {
100 if (m_bJoining)
101 return;
102
103 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.OnLogoutReplyTimeout);
104
105 if (time > JOIN_LEAD_TIME_S)
106 {
107 SetTime(time);
108 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
109 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(UpdateTime, 1000, true);
110 }
111 else
112 {
113 // nothing worth waiting for, the server is logging us out right away
115 }
116 }
117
120 protected void OnLogoutReplyTimeout()
121 {
122 Print("[Invite]: No logout time received from the server, joining the target server anyway");
124 }
125
126 void SetTime(int time)
127 {
128 m_iTime = time;
129 string text = "#layout_logout_dialog_until_logout_";
130
131 TimeConversions.ConvertSecondsToFullTime(time, m_FullTime);
132
133 if (m_FullTime.m_Days > 0)
134 text += "dhms";
135 else if (m_FullTime.m_Hours > 0)
136 text += "hms";
137 else if (m_FullTime.m_Minutes > 0)
138 text += "ms";
139 else
140 text += "s";
141
142 text = Widget.TranslateString(text);
143 text = string.Format(text, m_FullTime.m_Seconds, m_FullTime.m_Minutes, m_FullTime.m_Hours, m_FullTime.m_Days);
144 m_LogoutTimeText.SetText(text);
145 }
146
148 {
149 m_iTime -= 1;
150
151 // Leave before the server reaches its own logout deadline. Once it gets there it
152 // terminates the session, which takes us to the main menu and loses the invite. The
153 // lobby refusal caused by leaving early is absorbed by the retry in the connect itself.
156 else
158 }
159
160 protected void JoinTargetServer()
161 {
162 m_bJoining = true;
163 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
164 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.OnLogoutReplyTimeout);
165
166 string ip;
167 int port;
169 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Call(g_Game.ConnectFromJoin, ip, port);
170 }
171}
DayZGame g_Game
Определения DayZGame.c:4074
Mission mission
Определения DisplayStatus.c:28
static const int FORCE_DIFFERENT
Определения EmoteManager.c:62
Определения EmoteManager.c:60
struct that keeps Time relevant information for future formatting
Определения TimeConversions.c:5
static void GetInviteServerInfo(out string ip, out int port)
Определения OnlineServices.c:191
Определения OnlineServices.c:2
Определения PlayerBaseClient.c:2
Определения EnWidgets.c:220
void JoinTargetServer()
Определения InviteMenu.c:160
void InviteMenu()
Определения InviteMenu.c:15
const int LOGOUT_REPLY_TIMEOUT_MS
How long to wait for the server to answer the logout request before joining regardless.
Определения InviteMenu.c:4
TextWidget m_LogoutTimeText
Определения InviteMenu.c:8
void SetTime(int time)
Определения InviteMenu.c:126
void ~InviteMenu()
Определения InviteMenu.c:31
void UpdateTime()
Определения InviteMenu.c:147
void SetLogoutTime()
Определения InviteMenu.c:92
MultilineTextWidget m_DescriptionText
Определения InviteMenu.c:9
bool m_bJoining
Определения InviteMenu.c:11
ref FullTimeData m_FullTime
Определения InviteMenu.c:13
void OnLogoutReplyTimeout()
Определения InviteMenu.c:120
const int JOIN_LEAD_TIME_S
How much of the logout is left when we start joining, see UpdateTime.
Определения InviteMenu.c:6
void StartCountdown(int time)
Called once the server answered the logout request with the time it needs to log us out.
Определения InviteMenu.c:98
override Widget Init()
Определения InviteMenu.c:47
int m_iTime
Определения InviteMenu.c:10
Определения DayZGame.c:64
Определения EnWidgets.c:190
proto void Print(void var)
Prints content of variable to console/log.
const int ID_EMOTE_SITA
Определения 3_Game/DayZ/constants.c:381
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
const int CALL_CATEGORY_SYSTEM
Определения 3_Game/DayZ/tools/tools.c:8