少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
using UnityEngine;
using System;
 
 
namespace vnxbqy.UI
{
    
    
    public class CrossServerLogin : Singleton<CrossServerLogin>
    {
        bool m_Busy = false;
        public bool busy {
            get { return m_Busy; }
            set { m_Busy = value; }
        }
 
        public bool reconnectBackGround { get; set; }
 
        Clock loginOverTimeClock;
        float lastLoginTime = 0f;
        int reLoginTimes = 0;
 
        public CrossServerOneVsOne oneVsOnePlayerData { get; private set; }
 
        LoginModel loginModel { get { return ModelCenter.Instance.GetModel<LoginModel>(); } }
 
        public void Init()
        {
            SnxxzGame.Instance.AddApplicationOutAction(OnApplicationOut);
        }
 
        public void UnInit()
        {
            SnxxzGame.Instance.RemoveApplicationOutAction(OnApplicationOut);
        }
 
        public string ipBuf { get; private set; }
        public int portBuf { get; private set; }
        public int gamePortBuf { get; private set; }
        public string accountBuf { get; private set; }
        public string passwordBuf { get; private set; }
 
        public void UpdateCrossServerOneVsOneData(HC001_tagGCCrossRealmPKMatchOK matchOK, bool isClient)
        {
            oneVsOnePlayerData = new CrossServerOneVsOne()
            {
                isClient = isClient,
                roomId = matchOK.RoomID,
                waitForLoginCrossServer = true,
                validTimeLimited = Time.time + 30f,
                autoEnsureTime = Time.time + 3f,
                myName = matchOK.PlayerName.Replace("@gm", ""),
                myJob = PlayerDatas.Instance.baseData.Job,
                myFace = AvatarHelper.GetMyAvatarID(),
                myFacePic = AvatarHelper.GetMyAvatarFrameID(),
                myBornPoint = matchOK.Number,
                opponentName = matchOK.MatchPlayer[0].PlayerName.Replace("@gm", ""),
                opponentJob = matchOK.MatchPlayer[0].Job,
                opponentFace = (int)matchOK.MatchPlayer[0].Face,
                opponentFacePic = (int)matchOK.MatchPlayer[0].FacePic,
                opponentMaxHp = matchOK.MatchPlayer[0].MaxHP + matchOK.MatchPlayer[0].MaxHPEx * Constants.ExpPointValue,
                opponentLevel = (int)matchOK.MatchPlayer[0].LV,
                opponentPlayerId = (int)matchOK.MatchPlayer[0].PlayerID,
                MaxProDef = (int)matchOK.MatchPlayer[0].MaxProDef,
            };
 
            Clock.AlarmAt(DateTime.Now + new TimeSpan(3 * TimeSpan.TicksPerSecond), () =>
            {
                if (oneVsOnePlayerData.waitForLoginCrossServer)
                {
                    if (oneVsOnePlayerData.isClient)
                    {
                        ClientCrossServerOneVsOne.StartClientCrossServerOneVsOne();
                    }
                    else
                    {
                        CrossServerOneVsOneLogin();
                    }
                }
            });
        }
 
        public void CrossServerOneVsOneLogin()
        {
            var loginModel = ModelCenter.Instance.GetModel<LoginModel>();
            var account = loginModel.accountBuf;
            var ip = GameNetSystem.Instance.crossServerData.ip;
            var port = GameNetSystem.Instance.crossServerData.port;
 
            LoadingWin.isCrossServerOneVsOne = true;
            WindowCenter.Instance.Open<LoadingWin>();
            SetWaitForLoginCrossServerState(false);
 
            AccountLogin(account, ip, port, false);
        }
 
        public void SetWaitForLoginCrossServerState(bool state)
        {
            oneVsOnePlayerData = oneVsOnePlayerData.SetWaitForLoginCrossServer(false);
        }
 
        public bool IsEnterCrossServerPreparing()
        {
            return oneVsOnePlayerData.IsCrossServerOneVsOneEntering();
        }
 
        public void CrossServerBossLogin()
        {
            var loginModel = ModelCenter.Instance.GetModel<LoginModel>();
            var account = loginModel.accountBuf;
            var ip = GameNetSystem.Instance.crossServerData.ip;
            var port = GameNetSystem.Instance.crossServerData.port;
 
            WindowCenter.Instance.Open<LoadingWin>();
            AccountLogin(account, ip, port, false);
        }
 
        public void AccountLogin(string account, string ip, int gamePort, bool reconnectBackGround)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                ConfirmCancel.ShowPopConfirm(
                    Language.Get("Mail101"),
                    Language.Get("L1116"),
                    () => { }
                    );
                return;
            }
 
            if (busy)
            {
                return;
            }
 
            reLoginTimes = 0;
            busy = true;
            try
            {
                this.reconnectBackGround = reconnectBackGround;
                accountBuf = account;
                ipBuf = ip;
                gamePortBuf = gamePort;
 
                StopLoginOverTimeProcess();
                loginOverTimeClock = Clock.AlarmAt(DateTime.Now.AddSeconds(30), () =>
                  {
                      busy = false;
                      ReAccountLogin();
                  });
 
                GameNetSystem.Instance.BeginConnectCrossServer(ipBuf, gamePortBuf, OnGameServerConnected);
                NetLinkWin.Show();
            }
            catch (Exception ex)
            {
                Debug.Log(ex);
                busy = false;
            }
        }
 
        public void ReAccountLogin()
        {
            if (busy)
            {
                return;
            }
 
            busy = true;
            reLoginTimes++;
            if (reLoginTimes > 1)
            {
                ProcessLoginFailure();
                return;
            }
 
            try
            {
                this.reconnectBackGround = true;
                StopLoginOverTimeProcess();
                loginOverTimeClock = Clock.AlarmAt(DateTime.Now.AddSeconds(30), () =>
                   {
                       busy = false;
                       ReAccountLogin();
                   });
                GameNetSystem.Instance.BeginConnectCrossServer(ipBuf, gamePortBuf, OnGameServerConnected);
                NetLinkWin.Show();
            }
            catch (Exception ex)
            {
                Debug.Log(ex);
                busy = false;
            }
        }
 
        public void StopLoginOverTimeProcess()
        {
            if (loginOverTimeClock != null)
            {
                Clock.Stop(loginOverTimeClock);
            }
 
            loginOverTimeClock = null;
        }
 
        private void OnGameServerConnected(bool ok)
        {
            if (ok)
            {
                var sendInfo = new C0123_tagCClientPackVersion();
                sendInfo.Version = LoginModel.DwVersionNo;
                GameNetSystem.Instance.SendToCrossServer(sendInfo);
            }
            else
            {
                busy = false;
            }
        }
 
        public void AccessLogin(H0101_tagServerPrepared _serverInfo)
        {
            GameNetSystem.Instance.SendToCrossServer(loginModel.Get0101SendPackage(_serverInfo)); // 登录
            NetLinkWin.Show();
        }
 
        public void CheckClientVersion()
        {
            var sendInfo = new C010D_tagCClientVersion();
            sendInfo.Version = "10.1000.1";
            GameNetSystem.Instance.SendToCrossServer(sendInfo);
            NetLinkWin.Show();
        }
 
        public void OnGetPlayerLoginInfo(byte _type)
        {
            NetLinkWin.Hide();
            busy = false;
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                ConfirmCancel.ShowPopConfirm(
                    Language.Get("Mail101"),
                    Language.Get("L1116"),
                    () => { }
                    );
                return;
            }
 
            var tagCRoleLoginAsk = new C0108_tagCRoleLoginAsk();
            tagCRoleLoginAsk.Type = (byte)_type;//进入游戏
            tagCRoleLoginAsk.ClientID = ynmbxxjUtil.Instance.RegistrationID;
            GameNetSystem.Instance.SendToCrossServer(tagCRoleLoginAsk);
 
            NetLinkWin.Show();
        }
 
        private void ProcessLoginFailure()
        {
            StopLoginOverTimeProcess();
            busy = false;
 
 
            var sendInfo = new CC003_tagCGForceQuitCrossState();
            GameNetSystem.Instance.SendInfo(sendInfo);
            GameNetSystem.Instance.crossServerConnected_Loigc = false;
            Clock.AlarmAt(DateTime.Now + new TimeSpan(2 * TimeSpan.TicksPerSecond), () =>
            {
                GameNetSystem.Instance.Reconnect();
            });
        }
 
        private void OnApplicationOut()
        {
            var sendInfo = new C0103_tagCPlayerLogOut();
            sendInfo.Type = 1;
            GameNetSystem.Instance.SendToCrossServer(sendInfo);
        }
 
    }
 
    public struct CrossServerOneVsOne
    {
        public bool isClient;
        public int roomId;
        public bool waitForLoginCrossServer;
        public float autoEnsureTime;
        public float validTimeLimited;
        public string myName;
        public int myJob;
        public int myFace;
        public int myFacePic;
        public int myBornPoint;//1-左;2-右
        public int opponentPlayerId;
        public string opponentName;
        public int opponentJob;
        public int opponentFace;
        public int opponentFacePic;
        public int opponentLevel;
        public ulong opponentMaxHp;
        public int MaxProDef;// 最大护盾
 
        public CrossServerOneVsOne SetWaitForLoginCrossServer(bool waitForLoginCrossServer)
        {
            this.waitForLoginCrossServer = waitForLoginCrossServer;
            return this;
        }
 
        public bool IsCrossServerOneVsOneEntering()
        {
            return autoEnsureTime > Time.time;
        }
 
    }
 
}