コード例 #1
0
        //-------------------------------------------------------------
        public static void LoadData(string path, ref DTO_Suggestion suggestion)
        //-------------------------------------------------------------
        {
            //Check for settings file
            string settingPath = path + "\\_kobberlan.config";

            if (File.Exists(settingPath))
            {
                DTO_SuggestionSettings settings = JsonConvert.DeserializeObject <DTO_SuggestionSettings>(File.ReadAllText(settingPath));

                //Fill data to suggestion object
                suggestion.description       = settings.description;
                suggestion.startGame         = settings.startGame;
                suggestion.startGameParams   = settings.startGameParams;
                suggestion.startServer       = settings.startServer;
                suggestion.startServerParams = settings.startServerParams;
                suggestion.version           = settings.version;
                suggestion.title             = settings.title;
                suggestion.maxPlayers        = settings.maxPlayers == null ? 0 : settings.maxPlayers.Value;

                //Load big image if available
                string imagePath = path + "\\" + settings.image;
                if (File.Exists(imagePath))
                {
                    suggestion.imageBig = Image.FromFile(imagePath);
                }
                else
                {
                    suggestion.imageBig = suggestion.imageCover; //Default image if missing
                }
            }
            else
            {
                suggestion.imageBig = suggestion.imageCover; //Default image if missing
            }
        }
コード例 #2
0
        //-------------------------------------------------------------
        private void HandleMessage(byte [] data, string RemoteIP)
        //-------------------------------------------------------------
        {
            Object dataObject = Helper.ByteArrayToObject(data);

            if (dataObject.GetType() == typeof(DTO_Suggestion))
            {
                DTO_Suggestion suggestion = (DTO_Suggestion)dataObject;
                Log.Get().Write("Communication server handle Suggestiongame: " + suggestion.title);
                kobberLanGui.Invoke(new Action(() =>
                {
                    kobberLanGui.AddSuggestedGame(suggestion, null, false, RemoteIP);
                }));
            }
            else if (dataObject.GetType() == typeof(DTO_Like))
            {
                DTO_Like like = (DTO_Like)dataObject;
                Log.Get().Write("Communication server handle Like: " + like.key);
                kobberLanGui.Invoke(new Action(() =>
                {
                    kobberLanGui.GotLike(like);
                }));
            }
            else if (dataObject.GetType() == typeof(DTO_AlreadyOwnIt))
            {
                DTO_AlreadyOwnIt alreadyOwnIt = (DTO_AlreadyOwnIt)dataObject;
                Log.Get().Write("Communication server handle alreadyOwnIt: " + alreadyOwnIt.key);
                kobberLanGui.Invoke(new Action(() =>
                {
                    kobberLanGui.GotAlreadyOwnIt(alreadyOwnIt);
                }));
            }
            else if (dataObject.GetType() == typeof(DTO_Torrent))
            {
                DTO_Torrent torrent = (DTO_Torrent)dataObject;
                Log.Get().Write("Communication server handle torrent: " + torrent.key);
                kobberLanGui.Invoke(new Action(() =>
                {
                    kobberLanGui.GotTorrent(torrent);
                }));
            }
            else if (dataObject.GetType() == typeof(DTO_TorrentStatus))
            {
                DTO_TorrentStatus torrent = (DTO_TorrentStatus)dataObject;
                Log.Get().Write("Communication server handle torrentStatus: " + torrent.key);
                kobberLanGui.Invoke(new Action(() =>
                {
                    kobberLanGui.GotTorrentStatus(torrent);
                }));
            }
            else if (dataObject.GetType() == typeof(DTO_GameStatus))
            {
                DTO_GameStatus gameStatus = (DTO_GameStatus)dataObject;
                Log.Get().Write("Communication server handle gameStatus: " + gameStatus.key);
                kobberLanGui.Invoke(new Action(() =>
                {
                    kobberLanGui.GotGameStatus(gameStatus);
                }));
            }
            else if (dataObject.GetType() == typeof(DTO_RequestAllSuggestions))
            {
                DTO_RequestAllSuggestions gameStatus = (DTO_RequestAllSuggestions)dataObject;
                Log.Get().Write("Communication server handle client get all Suggestions: " + gameStatus.address.ToString());
                kobberLanGui.Invoke(new Action(() =>
                {
                    kobberLanGui.UpdatePlayerSuggested(gameStatus.address.ToString());
                }));
            }
            else
            {
                Log.Get().Write("Communication server got unknown message", Log.LogType.Warning);
            }
        }