public ClientNetworkStateContainer(Prompter prompter) { NotConnected = new NotConnected(); PendingLogOn = new PendingLogOn(prompter); WaitingForBoard = new WaitingForBoard(); PendingBoard = new PendingBoard(prompter); WaitingForGame = new WaitingForGame(prompter); FoundGame = new FoundGame(prompter); InitialGame = new InitialGame(prompter); MyTurn = new MyTurn(); TheirTurn = new TheirTurn(prompter); Waiting = new Waiting(prompter); }
public ServerNetworkStateContainer(BspSender sender, IBspDisconnecter disconnecter, GameTypeRepository gameTypeRepo, UserRepository userRepo, MatchMaker matchMaker) { var state = new BspServerState(); NotConnected = new NotConnected(state, sender, gameTypeRepo, userRepo); PendingLogOn = new PendingLogOn(); WaitingForBoard = new WaitingForBoard(state, sender, gameTypeRepo, matchMaker); PendingBoard = new PendingBoard(); WaitingForGame = new WaitingForGame(state, sender, disconnecter, userRepo); FoundGame = new FoundGame(state, sender, disconnecter, userRepo); InitialGame = new InitialGame(); MyTurn = new MyTurn(state, sender, disconnecter, userRepo); TheirTurn = new TheirTurn(); Waiting = new Waiting(); }
void Update() { // Check for any new listings from the Unity master server HostData[] hostData = MasterServer.PollHostList(); if (hostData.Length > 0) { foreach (HostData host in hostData) { FoundGame foundGame = new FoundGame(); foundGame.ipAddress = IPFromStringArray(host.ip); if (IsDedicatedServerByComment(host.comment)) { foundGame.isDedicated = true; foundGame.playerCount = host.connectedPlayers - 1; foundGame.maxPlayerCount = host.playerLimit - 1; } else { foundGame.isDedicated = false; foundGame.playerCount = host.connectedPlayers; foundGame.maxPlayerCount = host.playerLimit; } foundGame.ping = new Ping(foundGame.ipAddress); foundGame.isOnLAN = false; foundWANGames.Add(foundGame); } MasterServer.ClearHostList(); } // Update our LAN listings from the LAN broadcast service. This list has a list of all received // UDP packets in the last five seconds. foundLANGames.Clear(); foreach (LANBroadcastService.ReceivedMessage m in lanBroadcastService.ReceivedMessages) { if (m.bIsReady) { // This is a host announcing its presence FoundGame foundGame = new FoundGame(); foundGame.ipAddress = m.strIP; foundGame.ping = new Ping(foundGame.ipAddress); foundGame.isOnLAN = true; foundLANGames.Add(foundGame); } } }
public static TaskFunc GameCopyTask(FoundGame game) { return((Tasker tasker, Object sync) => { if (game.Desktop.Code.StartsWith("CLV-")) { long dataTransferred = 0; var destinationPath = Path.Combine(NesApplication.GamesDirectory, game.Desktop.Code); tasker?.SetStatus($"{game.Desktop.Name}"); if (Directory.Exists(destinationPath)) { Directory.Delete(destinationPath, true); } Directory.CreateDirectory(destinationPath); foreach (var folder in hakchi.Shell.ExecuteSimple($"cd {Shared.EscapeShellArgument(game.RemotePath)}; find -type d").Split('\n')) { Directory.CreateDirectory(Path.Combine(destinationPath, folder)); } FtpClient ftp = null; if (hakchi.Shell is INetworkShell) { ftp = new FtpClient(new Uri($"ftp://{(hakchi.Shell as INetworkShell).IPAddress}"), new NetworkCredential("root", "root")); } foreach (Match match in new Regex(@"^(\d+)\s*\./(.*)$", RegexOptions.Multiline).Matches(hakchi.Shell.ExecuteSimple($"cd {Shared.EscapeShellArgument(game.RemotePath)}; find -type f -exec du {"{}"} \\;"))) { var size = long.Parse(match.Groups[1].Value) * 1024; var filename = match.Groups[2].Value; using (var file = File.Create(Path.Combine(destinationPath, filename))) using (var tracker = new TrackableStream(file)) { tracker.OnProgress += (long transferred, long length) => { var totalTransferred = Math.Min(dataTransferred + transferred, game.Size); tasker?.SetProgress(totalTransferred, game.Size); tasker?.SetStatus($"{game.Desktop.Name} ({Shared.SizeSuffix(totalTransferred, 2)} / {Shared.SizeSuffix(game.Size, 2)})"); }; if (hakchi.Shell is INetworkShell) { using (var ftpStream = ftp.Retr($"{game.RemotePath}/{filename}")) { ftpStream.CopyTo(tracker); } } else { hakchi.Shell.Execute($"cat {Shared.EscapeShellArgument($"{game.RemotePath}/{filename}")}", null, tracker, throwOnNonZero: true); } dataTransferred += size; } } ftp?.Dispose(); ftp = null; game.Desktop.Save(Path.Combine(destinationPath, $"{game.Desktop.Code}.desktop")); if (!ConfigIni.Instance.SelectedGames.Contains(game.Desktop.Code)) { ConfigIni.Instance.SelectedGames.Add(game.Desktop.Code); } return Conclusion.Success; } return Conclusion.Error; }); }