public LobbyToolTipInfo(ServerRegistered _server) { mRoomNumber = _server.ServerID.ToString(); Pathea.PeGameMgr.ESceneMode mode = (Pathea.PeGameMgr.ESceneMode)_server.GameMode; switch (mode) { case Pathea.PeGameMgr.ESceneMode.Adventure: mGameMode = "Adventure"; break; case Pathea.PeGameMgr.ESceneMode.Build: mGameMode = "Build"; break; case Pathea.PeGameMgr.ESceneMode.Story: mGameMode = "Story"; break; case Pathea.PeGameMgr.ESceneMode.Custom: mGameMode = "Custom"; break; default: mGameMode = "Adventure"; break; } mMapName = ""; mTeamNo = ""; mSeedNo = ""; mAlienCamp = ""; mTown = ""; mMapSize = ""; mElevation = ""; }
void ConnectServer(bool needPasswold, ServerRegistered data) { if (null != data) { if (data.GameMode == (int)Pathea.PeGameMgr.ESceneMode.Custom) { if (string.IsNullOrEmpty(data.UID) || string.IsNullOrEmpty(data.MapName)) { return; } string filePath = Path.Combine(GameConfig.CustomDataDir, data.MapName); Pathea.CustomGameData.Mgr.Instance.curGameData = Pathea.CustomGameData.Mgr.Instance.GetCustomData(data.UID, filePath); if (null == Pathea.CustomGameData.Mgr.Instance.curGameData) { return; } Pathea.PeGameMgr.mapUID = data.UID; ScenarioIntegrityCheck check = ScenarioMapUtils.CheckIntegrityByPath(filePath); StartCoroutine(ProcessIntegrityCheck(check, needPasswold, data)); } else { Connect(needPasswold, data); } } }
public void JoinToServerByInvite() { if (mInviteServerData == null) { MessageBox_N.ShowOkBox(UIMsgBoxInfo.mRoomIsClose.GetString()); return; } bool mNeedPaseWord = (mInviteServerData.PasswordStatus == 1); if (mNeedPaseWord) { mPassWordWnd.SetActive(true); } else { ConnectServer(false, mInviteServerData); //SteamFriendPrcMgr.Instance.InviteClear(); } ServerRegistered mServerData = _curServerList.Find( delegate(ServerRegistered sr) { return(sr.ServerUID == roomUID); }); if (mServerData != null) { mRecentRoom_M.AddItem(mServerData.ServerUID, mServerData.ServerName, mServerData.ServerMasterName, mServerData.ServerVersion); } }
public void SetInviteServerData(long serverUID) { mInviteServerData = null; if (mInviteServerData == null) { mInviteServerData = _serverListInter.Find( delegate(ServerRegistered sr) { return(sr.ServerUID == serverUID); }); } if (mInviteServerData == null) { mInviteServerData = _serverListLan.Find( delegate(ServerRegistered sr) { return(sr.ServerUID == serverUID); }); } // if( mInviteServerData == null) // { // mInviteServerData = _serverListProxy.Find( // delegate(ServerRegistered sr) // { // return sr.ServerUID == serverUID; // }); // } }
//bool LockRoomList = false; IEnumerator UpdateRoomInfo() { mRoomListPage = 0; uLink.MasterServer.ipAddress = ClientConfig.ProxyIP; uLink.MasterServer.port = ClientConfig.ProxyPort; uLink.MasterServer.password = "******"; uLink.MasterServer.updateRate = 4f; uLink.MasterServer.RequestHostList("PatheaGame"); uLink.MasterServer.DiscoverLocalHosts("PatheaGame", 9900, 9915); yield return(new WaitForSeconds(3f)); while (true) { _serverListInter.Clear(); _serverListLan.Clear(); // Internet if (uLobby.Lobby.isConnected) { IEnumerable <uLobby.ServerInfo> lobbySrvs = uLobby.ServerRegistry.GetServers(); foreach (uLobby.ServerInfo server in lobbySrvs) { ServerRegistered reg = new ServerRegistered(); reg.AnalyseServer(server); _serverListInter.Add(reg); } } uLink.HostData[] servers = uLink.MasterServer.PollHostList(); foreach (uLink.HostData server in servers) { ProxyServerRegistered reg = new ProxyServerRegistered(); reg.AnalyseServer(server, false); _serverListInter.Add(reg); } uLink.HostData[] datas = uLink.MasterServer.PollDiscoveredHosts(); foreach (uLink.HostData data in datas) { ServerRegistered server = new ServerRegistered(); server.AnalyseServer(data, true); _serverListLan.Add(server); } uLink.MasterServer.ClearHostList(); uLink.MasterServer.ClearDiscoveredHosts(); RefreshRoomList(); uLink.MasterServer.RequestHostList("PatheaGame"); uLink.MasterServer.DiscoverLocalHosts("PatheaGame", 9900, 9915); bGetRoomInfo = true; yield return(new WaitForSeconds(5f)); } }
public ServerRegistered ToServerRegistered() { var rez = new ServerRegistered(); foreach (var field in typeof(ServerRegisteredLocal).GetFields()) { typeof(ServerRegistered).GetField(field.Name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?.SetValue(rez, field.GetValue(this)); } return(rez); }
void Connect(bool needPasswold, ServerRegistered data) { MyServerManager.LocalIp = data.IPAddress; MyServerManager.LocalPort = data.Port; MyServerManager.LocalPwd = needPasswold ? mCheckPasswordInput.text : ""; MyServerManager.LocalHost = data; GameClientNetwork.Connect(); PeSteamFriendMgr.Instance.mMyServerUID = data.ServerUID; }
void roomListChickItem(int index) { if (mRoomListPage == 0 || mRoomListPage == 1) { //lz-2016.11.15 Crush bug if (index >= 0 && index < _curServerList.Count) { roomUID = _curServerList[index].ServerUID; mSelectServerData = _curServerList[index]; checkIndex = index; } else { checkIndex = -1; } } else if (mRoomListPage == 2) { //lz-2016.11.15 Crush bug if (index >= 0 && index < mRecentRoom_M.mRecentRoomList.Count) { roomUID = mRecentRoom_M.mRecentRoomList[index].mUID; ServerRegistered mServerData = _curServerList.Find( delegate(ServerRegistered sr) { return(sr.ServerUID == roomUID); }); mSelectServerData = mServerData; checkIndex = index; } else { checkIndex = -1; } } }
void BtnJoinOnClick() { if (Input.GetMouseButtonUp(0) && 0 != roomUID) { //if(LockRoomList) // return; if (mSelectServerData == null) { MessageBox_N.ShowOkBox(UIMsgBoxInfo.mRoomIsClose.GetString()); return; } bool mNeedPaseWord = (mSelectServerData.PasswordStatus == 1); if (mNeedPaseWord) { mPassWordWnd.SetActive(true); } else { ConnectServer(false, mSelectServerData); } ServerRegistered mServerData = _curServerList.Find( delegate(ServerRegistered sr) { return(sr.ServerUID == roomUID); }); if (mServerData != null) { Debug.Log(mServerData.ServerUID); mRecentRoom_M.AddItem(mServerData.ServerUID, mServerData.ServerName, mServerData.ServerMasterName, mServerData.ServerVersion); } } }
public static bool CreateNewServer(MyServer ss) { #if SteamVersion //to do--check myServer is new if (LoadServer.ServerList.Contains(ss)) { Debug.Log("servername already existed!"); MessageBox_N.ShowOkBox(PELocalization.GetString(8000499)); return(false); } //to do--start server if (ss != null) { int serverport = uLink.NetworkUtility.FindAvailablePort(9900, 9915); if (!uLink.NetworkUtility.IsPortAvailable(serverport)) { MessageBox_N.ShowOkBox(string.Format(PELocalization.GetString(8000498), serverport)); return(false); } string srvRoot = Path.Combine(Environment.CurrentDirectory, "Server"); Directory.CreateDirectory(srvRoot); string srvDataPath = Path.Combine(srvRoot, "ServerData"); Directory.CreateDirectory(srvDataPath); string srvGamePath = Path.Combine(srvDataPath, "CommonGames"); Directory.CreateDirectory(srvGamePath); string serverDir = Path.Combine(srvGamePath, ss.gameName); Directory.CreateDirectory(serverDir); string serverConfig = Path.Combine(serverDir, "config.json"); ss.Create(serverConfig); string gameName = MyServer.ReplaceStr(ss.gameName); string args = string.Format("-batchmode startwithargs " + "{0}#{1}#{2}", gameName, ss.gameMode, SteamMgr.steamId); string path = string.Empty; System.Diagnostics.Process p = new System.Diagnostics.Process(); switch (Application.platform) { case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: { path = Path.Combine(srvRoot, "PE_Server.app/Contents/MacOS/PE_Server"); p.StartInfo.FileName = path; p.StartInfo.Arguments = args; } break; case RuntimePlatform.LinuxPlayer: { path = Path.Combine(srvRoot, "PE_Server.x86_64"); p.StartInfo.FileName = path; p.StartInfo.Arguments = args; } break; default: { path = Path.Combine(srvRoot, "PE_Server.exe"); p.StartInfo.FileName = path; p.StartInfo.Arguments = args; } break; } if (!File.Exists(path)) { MessageBox_N.ShowOkBox(PELocalization.GetString(8000061) + path); Debug.LogError(path + " does not exists."); return(false); } if (p.Start()) { LocalIp = "127.0.0.1"; LocalPort = serverport; LocalPwd = ss.gamePassword; LocalName = ss.gameName; LocalHost = null; OnServerHost(); return(true); } } #endif return(false); }
public static bool StartMyServer(MyServer ss) { #if SteamVersion if (ss != null) { //lz-2017.01.03 crash bug 错误 #8077 服务器名字正常情况下不会为null或空 if (string.IsNullOrEmpty(ss.gameName)) { MessageBox_N.ShowOkBox(PELocalization.GetString(8000018)); Debug.Log(string.Format("ServerName is null! gameName: {0},gameMode:{1},gameType:{2},seedStr:{3}", ss.gameName, ss.gameMode, ss.gameType, ss.seedStr)); return(false); } int serverport = uLink.NetworkUtility.FindAvailablePort(9900, 9915); if (!uLink.NetworkUtility.IsPortAvailable(serverport)) { MessageBox_N.ShowOkBox(string.Format(PELocalization.GetString(8000498), serverport)); return(false); } string srvRoot = Path.Combine(Environment.CurrentDirectory, "Server"); Directory.CreateDirectory(srvRoot); string srvDataPath = Path.Combine(srvRoot, "ServerData"); Directory.CreateDirectory(srvDataPath); string srvGamePath; if (ss.gameMode == (int)Pathea.PeGameMgr.ESceneMode.Custom) { srvGamePath = Path.Combine(srvDataPath, "CustomGames"); } else { srvGamePath = Path.Combine(srvDataPath, "CommonGames"); } Directory.CreateDirectory(srvGamePath); string serverDir = Path.Combine(srvGamePath, ss.gameName); Directory.CreateDirectory(serverDir); string serverConfig = Path.Combine(serverDir, "config.json"); ss.Create(serverConfig); string gameName = MyServer.ReplaceStr(ss.gameName); string args = string.Format("-batchmode startwithargs " + "{0}#{1}#{2}", gameName, ss.gameMode, SteamMgr.steamId); string path = string.Empty; System.Diagnostics.Process p = new System.Diagnostics.Process(); switch (Application.platform) { case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: { path = Path.Combine(srvRoot, "PE_Server.app/Contents/MacOS/PE_Server"); p.StartInfo.FileName = path; p.StartInfo.Arguments = args; } break; case RuntimePlatform.LinuxPlayer: { path = Path.Combine(srvRoot, "PE_Server.x86_64"); p.StartInfo.FileName = path; p.StartInfo.Arguments = args; } break; default: { path = Path.Combine(srvRoot, "PE_Server.exe"); p.StartInfo.FileName = path; p.StartInfo.Arguments = args; } break; } if (!File.Exists(path)) { MessageBox_N.ShowOkBox(PELocalization.GetString(8000061) + path); Debug.LogError(path + " does not exists."); return(false); } if (p.Start()) { LocalIp = "127.0.0.1"; LocalPort = serverport; LocalPwd = ss.gamePassword; LocalName = ss.gameName; LocalHost = null; OnServerHost(); return(true); } } #endif return(false); }
public static bool StartCustomServer(MyServer srv) { if (LoadServer.ServerList.Contains(srv)) { Debug.Log("servername already existed!"); MessageBox_N.ShowOkBox(PELocalization.GetString(8000499)); return(false); } string serverRoot = Path.Combine(Environment.CurrentDirectory, "Server"); Directory.CreateDirectory(serverRoot); string serverPath = Path.Combine(serverRoot, "ServerData"); Directory.CreateDirectory(serverPath); string gameDir = Path.Combine(serverPath, "CustomGames"); Directory.CreateDirectory(gameDir); string serverDir = Path.Combine(gameDir, srv.gameName); Directory.CreateDirectory(serverDir); string srvScenarioPath = Path.Combine(serverDir, "Scenario"); Directory.CreateDirectory(srvScenarioPath); string srvWorldPath = Path.Combine(serverDir, "Worlds"); Directory.CreateDirectory(srvWorldPath); string srvForceXml = Path.Combine(srvScenarioPath, "ForceSettings.xml"); string srvWorldXml = Path.Combine(srvScenarioPath, "WorldSettings.xml"); string srvUidFile = Path.Combine(serverDir, "MAP.uid"); string customRoot = Path.Combine(Environment.CurrentDirectory, "CustomGames"); string gamePath = Path.Combine(customRoot, Pathea.PeGameMgr.gameName); if (!Directory.Exists(gamePath)) { Debug.LogErrorFormat("Invalide custom game path:{0}", gamePath); return(false); } string scenarioPath = Path.Combine(gamePath, "Scenario"); string forceXml = Path.Combine(scenarioPath, "ForceSettings.xml"); string worldXml = Path.Combine(scenarioPath, "WorldSettings.xml"); string uidFile = Path.Combine(gamePath, "MAP.uid"); if (!File.Exists(uidFile)) { Debug.LogErrorFormat("{0} does not exist", uidFile); return(false); } if (!File.Exists(forceXml)) { Debug.LogErrorFormat("{0} does not exist", forceXml); return(false); } if (!File.Exists(worldXml)) { Debug.LogErrorFormat("{0} does not exist", worldXml); return(false); } string worldPath = Path.Combine(gamePath, "Worlds"); if (!Directory.Exists(worldPath)) { Debug.LogErrorFormat("Invalide custom worlds path:{0}", worldPath); return(false); } DirectoryInfo rootDir = new DirectoryInfo(worldPath); DirectoryInfo[] dirs = rootDir.GetDirectories(); if (dirs.Length <= 0) { Debug.LogErrorFormat("No worlds exist"); return(false); } for (int i = 0; i < dirs.Length; i++) { string worldDir = Path.Combine(worldPath, dirs[i].Name); string worldEntityXml = Path.Combine(worldDir, "WorldEntity.xml"); if (!File.Exists(worldEntityXml)) { Debug.LogErrorFormat("Invalide file:{0}", worldEntityXml); return(false); } string srvWorldDir = Path.Combine(srvWorldPath, dirs[i].Name); Directory.CreateDirectory(srvWorldDir); string srvWorldEntityXml = Path.Combine(srvWorldDir, "WorldEntity.xml"); File.Copy(worldEntityXml, srvWorldEntityXml, true); } File.Copy(forceXml, srvForceXml, true); File.Copy(worldXml, srvWorldXml, true); File.Copy(uidFile, srvUidFile, true); int serverPort = uLink.NetworkUtility.FindAvailablePort(9900, 9915); if (!uLink.NetworkUtility.IsPortAvailable(serverPort)) { MessageBox_N.ShowOkBox(string.Format(PELocalization.GetString(8000498), serverPort)); return(false); } string serverConfig = Path.Combine(serverDir, "config.json"); srv.Create(serverConfig); string gameName = MyServer.ReplaceStr(srv.gameName); string args = string.Format("-batchmode startwithargs " + "{0}#{1}#{2}", gameName, srv.gameMode, SteamMgr.steamId); string path = string.Empty; System.Diagnostics.Process p = new System.Diagnostics.Process(); switch (Application.platform) { case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: { path = Path.Combine(serverRoot, "PE_Server.app/Contents/MacOS/PE_Server"); p.StartInfo.FileName = path; p.StartInfo.Arguments = args; } break; case RuntimePlatform.LinuxPlayer: { path = Path.Combine(serverRoot, "PE_Server.x86_64"); p.StartInfo.FileName = path; p.StartInfo.Arguments = args; } break; default: { path = Path.Combine(serverRoot, "PE_Server.exe"); p.StartInfo.FileName = path; p.StartInfo.Arguments = args; } break; } if (!File.Exists(path)) { MessageBox_N.ShowOkBox(PELocalization.GetString(8000061) + path); Debug.LogError(path + " does not exists."); return(false); } if (p.Start()) { LocalIp = "127.0.0.1"; LocalPort = serverPort; LocalPwd = srv.gamePassword; LocalName = srv.gameName; LocalHost = null; OnServerHost(); return(true); } return(false); }
void RefreshRoomList() { if (mRoomList == null) { return; } _curServerList.Clear(); if (mRoomListPage == 0) { foreach (ServerRegistered server in _serverListInter) { if (QueryRoomText.Length > 0) { if (QueryItem(QueryRoomText, server.ServerID.ToString()) || QueryItem(QueryRoomText, server.ServerName)) { _curServerList.Add(server); } } else { _curServerList.Add(server); } } } else if (mRoomListPage == 1) { foreach (ServerRegistered lan in _serverListLan) { if (QueryRoomText.Length > 0) { if (QueryItem(QueryRoomText, lan.ServerID.ToString()) || QueryItem(QueryRoomText, lan.ServerName)) { _curServerList.Add(lan); } } else { _curServerList.Add(lan); } } } else if (mRoomListPage == 2) { foreach (ServerRegistered lan in _serverListLan) { _curServerList.Add(lan); } foreach (ServerRegistered server in _serverListInter) { _curServerList.Add(server); } } SortRoomList(); if (mRoomListPage == 0 || mRoomListPage == 1) { mRoomList.mItems.Clear(); int SeletedIndex = -1; for (int i = 0; i < _curServerList.Count; i++) { List <string> mLsit = ServerDataToList(_curServerList[i]); PageListItem item = new PageListItem(); item.mData = mLsit; item.mColor = Color.white; item.mEanbleICon = (_curServerList[i].PasswordStatus == 1); mRoomList.AddItem(item); if (roomUID == _curServerList[i].ServerUID) { SeletedIndex = i; } } mRoomList.mSelectedIndex = SeletedIndex; mRoomList.UpdateList(); } else if (mRoomListPage == 2) // recent { mRoomList.mItems.Clear(); int SeletedIndex = -1; for (int i = 0; i < mRecentRoom_M.mRecentRoomList.Count; i++) { long UID = mRecentRoom_M.mRecentRoomList[i].mUID; ServerRegistered mServerData = _curServerList.Find( delegate(ServerRegistered sr) { return(sr.ServerUID == UID); }); // Can Find if (mServerData != null) { List <string> mLsit = ServerDataToList(mServerData); PageListItem item = new PageListItem(); item.mData = mLsit; item.mColor = Color.white; item.mEanbleICon = (mServerData.PasswordStatus == 1); if (QueryRoomText.Length > 0 && mLsit.Count >= 2) { if (QueryItem(QueryRoomText, mLsit[0]) || QueryItem(QueryRoomText, mLsit[1])) { mRoomList.AddItem(item); } } else { mRoomList.AddItem(item); } } else { List <string> mLsit = new List <string>(); mLsit.Add(""); mLsit.Add(mRecentRoom_M.mRecentRoomList[i].mRoomName); mLsit.Add(mRecentRoom_M.mRecentRoomList[i].mCreator); mLsit.Add(""); mLsit.Add(""); mLsit.Add(""); mLsit.Add(""); mLsit.Add(""); mLsit.Add(mRecentRoom_M.mRecentRoomList[i].mVersion); PageListItem item = new PageListItem(); item.mData = mLsit; item.mColor = Color.gray; item.mEanbleICon = false; if (QueryRoomText.Length > 0 && mLsit.Count >= 2) { if (QueryItem(QueryRoomText, mLsit[1])) { mRoomList.AddItem(item); } } else { mRoomList.AddItem(item); } } if (roomUID == UID) { SeletedIndex = i; } } mRoomList.mSelectedIndex = SeletedIndex; mRoomList.UpdateList(); } }
List <string> ServerDataToList(ServerRegistered mServerData) { List <string> mLsit = new List <string>(); if (mServerData.ServerID <= -1) { mLsit.Add("[6666FF]OFFICIAL"); mLsit.Add("[6666FF]" + mServerData.ServerName); } else { if (mServerData.UseProxy) { mLsit.Add("[99CC00]Proxy"); mLsit.Add("[99CC00]" + mServerData.ServerName); } else { mLsit.Add(mServerData.ServerID.ToString()); mLsit.Add(mServerData.ServerName); } } mLsit.Add(mServerData.ServerMasterName); mLsit.Add(mServerData.CurConn.ToString() + "/" + mServerData.LimitedConn.ToString()); Pathea.PeGameMgr.EGameType type = (Pathea.PeGameMgr.EGameType)mServerData.GameType; string strTemp; switch (type) { case Pathea.PeGameMgr.EGameType.Cooperation: strTemp = "Cooperation"; break; case Pathea.PeGameMgr.EGameType.VS: strTemp = "VS"; break; case Pathea.PeGameMgr.EGameType.Survive: strTemp = "Survive"; break; default: strTemp = "Cooperation"; break; } mLsit.Add(strTemp); Pathea.PeGameMgr.ESceneMode mode = (Pathea.PeGameMgr.ESceneMode)mServerData.GameMode; switch (mode) { case Pathea.PeGameMgr.ESceneMode.Adventure: strTemp = "Adventure"; break; case Pathea.PeGameMgr.ESceneMode.Build: strTemp = "Build"; break; case Pathea.PeGameMgr.ESceneMode.Custom: strTemp = "Custom"; break; case Pathea.PeGameMgr.ESceneMode.Story: strTemp = "Story"; break; default: strTemp = "Adventure"; break; } mLsit.Add(strTemp); mLsit.Add(mServerData.Ping.ToString()); if (((EServerStatus)mServerData.ServerStatus & EServerStatus.Prepared) == EServerStatus.Prepared) { strTemp = "Waiting"; } else { strTemp = "InProgress"; } mLsit.Add(strTemp); mLsit.Add(mServerData.ServerVersion); return(mLsit); }
IEnumerator ProcessIntegrityCheck(ScenarioIntegrityCheck check, bool needPasswold, ServerRegistered data) { while (true) { if (check.integrated == true) { Connect(needPasswold, data); break; } else if (check.integrated == false) { MessageBox_N.ShowOkBox(PELocalization.GetString(8000484)); yield break; } yield return(null); } }