//------------------------------------------------------------- public SuggestedGameInternetControl(DTO_Suggestion dto, KobberLan parent) //------------------------------------------------------------- { //Init control InitializeComponent(); kobberLan = parent; dto_suggestion = dto; Likes = new List <IPAddress>(); label_GameTitle.Text = dto.title; pictureBox_Cover.Image = dto.imageCover; //Set mouseover tooltip CustomToolTip tip = new CustomToolTip(dto, this); tip.InitImage(dto.imageBig); tip.SetToolTip(pictureBox_Cover, "Details"); //Check for startup value if (!(string.IsNullOrEmpty(dto.startGame) && string.IsNullOrEmpty(dto.startServer))) { button_Play.Enabled = true; } //Show popup notification about the new game kobberLan.Invoke(new Action(() => { kobberLan.ShowBallonTip("Kobberlan internet suggested", "Game: " + dto_suggestion.title); })); }
//------------------------------------------------------------- public CustomToolTip(DTO_Suggestion suggestion, SuggestedGame form) //------------------------------------------------------------- { dto_suggestion = suggestion; suggestedGameForm = form; this.OwnerDraw = true; this.Popup += new PopupEventHandler(this.OnPopup); this.Draw += new DrawToolTipEventHandler(this.OnDraw); }
//------------------------------------------------------------- public SuggestedGameControl(DTO_Suggestion dto, KobberLan parent) //------------------------------------------------------------- { //Init control InitializeComponent(); finishedDownloaded = false; kobberLan = parent; dto_suggestion = dto; Likes = new List <IPAddress>(); label_GameTitle.Text = dto.title; pictureBox_Cover.Image = dto.imageCover; state = TorrentState.Starting; if (dto.torrent == null) { button_Get.Enabled = false; button_Get.Visible = false; } else //Internet suggestion { button_Get.Enabled = true; button_Get.Visible = true; } //Set mouseover tooltip CustomToolTip tip = new CustomToolTip(dto, this); tip.InitImage(dto.imageBig); tip.SetToolTip(pictureBox_Cover, "Details"); //------------------------------------------------------------- //Check for startup value //------------------------------------------------------------- if (!(string.IsNullOrEmpty(dto.startGame) && string.IsNullOrEmpty(dto.startServer))) { button_Play.Visible = true; button_Play.Enabled = false; //------------------------------------------------------------- //Check if player already got the game //------------------------------------------------------------- var path = Helper.GetDirection(); if (Directory.Exists(path + "\\" + dto_suggestion.key)) { button_Play.Enabled = true; } } //Show popup notification about the new game kobberLan.Invoke(new Action(() => { kobberLan.ShowBallonTip("Kobberlan game suggested", "Game: " + dto_suggestion.title); })); }
//------------------------------------------------------------- public SuggestedGameOwnerControl(DTO_Suggestion dto, string pathHDD, KobberLan parent, bool ownSuggestions = false) //------------------------------------------------------------- { //Init control InitializeComponent(); torrentPeers = new List <string>(); torrentPeers.Add("127.0.0.1"); // Inclusive owner torrentDownloadCompleted = new List <string>(); torrentDownloadStarted = new List <string>(); ingame = new List <string>(); metaProgress = 0; state = TorrentState.Starting; kobberLan = parent; path = pathHDD; dto_suggestion = dto; Likes = new List <IPAddress>(); label_GameTitle.Text = dto.title; pictureBox_Cover.Image = dto.imageCover; //Set mouseover tooltip CustomToolTip tip = new CustomToolTip(dto, this); tip.InitImage(dto.imageBig); tip.SetToolTip(pictureBox_Cover, "Details"); torrentShared = false; //Check for startup value if (!(string.IsNullOrEmpty(dto.startGame) && string.IsNullOrEmpty(dto.startServer))) { button_Play.Enabled = true; } //Hide peers/downloads/remove if not own suggestions this.ownSuggestions = ownSuggestions; if (!ownSuggestions) { pictureBox_Downloaded.Visible = false; pictureBox_Peers.Visible = false; label_Downloading.Visible = false; label_Peers.Visible = false; button_Clear.Visible = false; } }
//------------------------------------------------------------- public void SuggestInternetGame(SuggestInternetGame suggestForm) //------------------------------------------------------------- { DTO_Suggestion game = new DTO_Suggestion() { type = Code.SuggestionType.Internet, title = "Unknown", author = Helper.GetHostIP().ToString(), imageCover = Properties.Resources.no_cover //Default image }; game.description = suggestForm.GetDescription(); game.title = suggestForm.GetTitle(); //Key / title is the same game.key = suggestForm.GetTitle(); //Key / title is the same game.version = suggestForm.GetVersion(); game.startGame = suggestForm.GetStartLocation(); game.maxPlayers = suggestForm.GetMaxPlayers(); //Get images var imageBigUrl = suggestForm.GetImageBig(); var imageCoverUrl = suggestForm.GetImageCover(); //Get images from Internet WebClient client = new WebClient(); Stream stream = client.OpenRead(imageCoverUrl); game.imageCover = Bitmap.FromStream(stream); stream.Close(); stream = client.OpenRead(imageBigUrl); game.imageBig = Bitmap.FromStream(stream); stream.Close(); client.Dispose(); //Send suggestion to LAN Log.Get().Write("Communication client prepare to send Internet suggested"); communication.ClientSend(game); //Update own GUI with suggested game AddSuggestedGame(game); //Destroy InternetForm suggestForm.Dispose(); suggestForm = null; }
//------------------------------------------------------------- public void AddSuggestedGame(DTO_Suggestion suggestion, string path = null, bool ownSuggestions = false, string remoteIP = "") //------------------------------------------------------------- { //Check if title exist if (!suggestedGames.Any(L => L.GetKey().Equals(suggestion.key))) { //Add suggested game SuggestedGame suggestedGame; if (suggestion.type == SuggestionType.Internet) { suggestedGame = new SuggestedGameInternetControl(suggestion, this); } else if (ownSuggestions) { //Add game as owner suggestedGame = new SuggestedGameOwnerControl(suggestion, path, this, ownSuggestions); } else { suggestedGame = new SuggestedGameControl(suggestion, this); if (Directory.Exists(Helper.GetDirection() + "\\" + suggestion.key)) { //Already own the game, tell server about it DTO_AlreadyOwnIt alreadyOwnIt = new DTO_AlreadyOwnIt() { address = Helper.GetHostIP(), key = suggestion.key }; communication.ClientSend(alreadyOwnIt, remoteIP); } } flowLayoutPanel_SuggestedGames.Controls.Add(suggestedGame); suggestedGames.Add(suggestedGame); } else { //Warning, tried to add already exisiting game Log.Get().Write("Game " + suggestion.key + " already exist. Note this would happen if BroadCast is active, all player gets suggested game again.", Log.LogType.Info); } }
//------------------------------------------------------------- public void SuggestGameLoadFromPath(string folder) //------------------------------------------------------------- { DTO_Suggestion game = new DTO_Suggestion() { type = Code.SuggestionType.HDD, title = "Unknown", author = Helper.GetHostIP().ToString(), imageCover = Properties.Resources.no_cover //Default image }; //Set uniq key (foldername) and default title game.key = game.title = new DirectoryInfo(folder).Name; //Check for version number in key/foldername if (!game.key.Any(char.IsDigit)) { Log.Get().Write("Consider adding version number to game foldername. Key is: " + game.key, Log.LogType.Warning); } //Check for cover image string coverPath = folder + "\\_kobberlan.jpg"; if (File.Exists(coverPath)) { game.imageCover = Image.FromFile(coverPath); } //Load JSON settings file DTO_SuggestionSettings.LoadData(folder, ref game); //Send packet to LAN Log.Get().Write("Communication client prepare to send suggested"); communication.ClientSend(game); //Update own GUI with suggested game AddSuggestedGame(game, folder, true); }