123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- using Cysharp.Threading.Tasks;
- using ET.EventType;
- using FairyGUI;
- using Sirenix.Utilities;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- namespace ET.Client
- {
- [Event]
- public class ShowLoginUIEventHandle : BEvent<EventType.ShowLoginUIEvent>
- {
- private string mIP;
- private int mPort;
- private string strRoomToken;
- protected override async ETTask OnEvent(ShowLoginUIEvent a)
- {
- var args = Environment.GetCommandLineArgs();
- for (var i = 0; i < args.Length; i++)
- {
- Log.Debug("args: " + args[i]);
- if (args[i].StartsWith("-token="))
- {
- strRoomToken = args[i][7..];
- Log.Debug($"env token: {strRoomToken}");
- break;
- }
- }
- GRoot.inst.RemoveChildren();
- var view = await UIHelper.Create( "Login" );
- InitLogin( view ).Coroutine();
- UIPackage.RemovePackage( "CheckForResUpdate" );
- }
- private void InitServerList(GComboBox list)
- {
- var saveip = GameSetting.Instance.GetString(GameSetting.Sets.Server_str);
- int select = -1;
- List<string> servers = new();
- foreach (var info in ServerInfo.ServerList)
- {
- servers.Add(info.ShowName);
- if (select < 0 && !saveip.IsNullOrWhitespace())
- {
- if (saveip == info.HostStr)
- {
- select = servers.Count - 1;
- }
- }
- }
- if(select < 0 && !saveip.IsNullOrWhitespace())
- {
- try
- {
- var ipendpoint = NetworkHelper.ToIPEndPoint(saveip);
- servers.Add($"Custom[{saveip}]");
- ServerInfo.ServerList.Add(new ServerInfo()
- {
- ShowName = $"Custom[{saveip}]",
- Ip = ipendpoint.Address.ToString(),
- Port = ipendpoint.Port,
- }) ;
- select = servers.Count - 1;
- }
- catch(Exception)
- {
- Log.Error($"error save ip: {saveip}");
- }
- }
- if(select < 0)
- {
- select = 0;
- }
- var cur = ServerInfo.ServerList[select];
- mIP = cur.Ip;
- mPort = cur.Port;
- list.items = servers.ToArray();
- list.selectedIndex = select;
- list.onChanged.Set(() =>
- {
- var info = ServerInfo.ServerList[list.selectedIndex];
- GameSetting.Instance.SetString(GameSetting.Sets.Server_str, info.HostStr);
- mIP = info.Ip;
- mPort = info.Port;
- });
- }
- private void InitResolutionList(GComboBox list)
- {
- #if UNITY_EDITOR
- list.visible = false;
- #elif UNITY_STANDALONE
- list.visible = true;
- int val = GameSetting.Instance.GetInt(GameSetting.Sets.Resolution_int, 0);
- int select = -1;
- List<string> showlist = new();
- foreach (var info in ResolutionInfo.ResolutionList)
- {
- showlist.Add(info.ShowName);
- if (select < 0 && val == info.Y)
- {
- select = showlist.Count - 1;
- }
- }
- if (select < 0)
- {
- select = 0;
- }
- var cur = ResolutionInfo.ResolutionList[select];
- Screen.SetResolution(cur.X, cur.Y, false);
- Log.Debug($"Default resolution x:{cur.X}, y:{cur.Y}");
- list.items = showlist.ToArray();
- list.selectedIndex = select;
- list.onChanged.Set(() =>
- {
- var info = ResolutionInfo.ResolutionList[list.selectedIndex];
- GameSetting.Instance.SetInt(GameSetting.Sets.Resolution_int, info.Y);
- Screen.SetResolution(info.X, info.Y, false);
- Log.Debug($"SetResolution x:{info.X}, y:{info.Y}");
- });
- #endif
- }
- private async ETTask InitLogin(GComponent view)
- {
- var comp = view.GetChild("comp_login") as GComponent;
- var listSvr = view.GetChild("listServer").asComboBox;
- var listResolution = view.GetChild("listResolution").asComboBox;
- InitServerList(listSvr);
- InitResolutionList(listResolution);
- var tips = comp.GetChild( "txt_tips" );
- var inputID = comp.GetChild("txtID").asTextInput;
- var imgtips = comp.GetChild("img_tips");
-
- inputID.text = strRoomToken;
- var btn = comp.GetChild("btn_go").asButton;
- btn.onClick.Add(async () =>
- {
- tips.visible = false;
- imgtips.visible = true;
- btn.visible = false;
- var ret = await LoginHelper.Login(mIP, mPort, strRoomToken);
- if (ret != ErrorCode.ERR_Success)
- {
- imgtips.visible = false;
- tips.visible = true;
- btn.visible = true;
- if (ret == ErrorCode.ERR_UserNameOrPasswordFormatError ||
- ret == ErrorCode.ERR_UserNameOrPasswordError)
- {
- tips.text = "用户名或密码错误";
- }
- else
- {
- tips.text = "连接服务器过程中出现了问题\n" +
- "如重试后还是不行,请与客服联系" +
- "\n抖音:[color=#FF0000]奥陌陌网络科技[/color]" +
- "\n微信:[color=#FF0000]omm_wh[/color]";
- }
- }
-
- });
- if (strRoomToken.IsNullOrWhitespace())
- {
- tips.visible = true;
- tips.text = "获得直播间token失败,请重新启动\n" +
- "如重试后还是不行,请与客服联系" +
- "\n抖音:[color=#FF0000]奥陌陌网络科技[/color]" +
- "\n微信:[color=#FF0000]omm_wh[/color]";
- strRoomToken = "NoToken";
- Log.Info("start without token");
- }
- else
- {
-
-
- }
- }
- }
- }
|