Example #1
0
        private void AddUser(ChannelUser user)
        {
            XNAListBoxItem item = new XNAListBoxItem();

            item.Tag = user;

            if (user.IsAdmin)
            {
                item.Text      = user.IRCUser.Name + " (Admin)";
                item.TextColor = cAdminNameColor;
                item.Texture   = adminGameIcon;
            }
            else
            {
                item.Text      = user.IRCUser.Name;
                item.TextColor = UISettings.AltColor;

                if (user.IRCUser.GameID < 0 || user.IRCUser.GameID >= gameCollection.GameList.Count)
                {
                    item.Texture = unknownGameIcon;
                }
                else
                {
                    item.Texture = gameCollection.GameList[user.IRCUser.GameID].Texture;
                }
            }

            lbPlayerList.AddItem(item);
        }
        public override void Load()
        {
            lbUpdateServerList.Clear();

            foreach (var updaterMirror in CUpdater.UPDATEMIRRORS)
            {
                lbUpdateServerList.AddItem(updaterMirror.Name + " (" + updaterMirror.Location + ")");
            }

            chkAutoCheck.Checked = IniSettings.CheckForUpdates;
        }
Example #3
0
        public void ListBattles()
        {
            lbCampaignList.Clear();

            CampaignHandler.Instance.BattleList.ForEach(mission =>
            {
                XNAListBoxItem item = new XNAListBoxItem();
                item.Tag            = mission;
                item.Text           = mission.GUIName;
                if (!mission.Enabled)
                {
                    item.TextColor = UISettings.ActiveSettings.DisabledItemColor;
                }
                else if (string.IsNullOrEmpty(mission.Scenario) && string.IsNullOrWhiteSpace(mission.CampaignInternalName))
                {
                    item.TextColor = AssetLoader.GetColorFromString(
                        ClientConfiguration.Instance.ListBoxHeaderColor);
                    item.IsHeader   = true;
                    item.Selectable = false;
                }
                else if (mission.RequiresUnlocking && !mission.IsUnlocked)
                {
                    item.TextColor = UISettings.ActiveSettings.DisabledItemColor;
                    item.Text      = "Locked Mission";
                    item.Texture   = AssetLoader.LoadTexture("randomicon.png");
                }
                else
                {
                    item.TextColor = lbCampaignList.DefaultItemColor;
                }

                if (item.Texture == null && !string.IsNullOrEmpty(mission.IconPath))
                {
                    item.Texture = AssetLoader.LoadTexture(mission.IconPath);
                }

                lbCampaignList.AddItem(item);
            });
        }
Example #4
0
        private void HandleNetworkMessage(string data, IPEndPoint endPoint)
        {
            string[] commandAndParams = data.Split(' ');

            if (commandAndParams.Length < 2)
            {
                return;
            }

            string command = commandAndParams[0];

            string[] parameters = data.Substring(command.Length + 1).Split(
                new char[] { ProgramConstants.LAN_DATA_SEPARATOR },
                StringSplitOptions.RemoveEmptyEntries);

            LANLobbyUser user = players.Find(p => p.EndPoint.Equals(endPoint));

            switch (command)
            {
            case "ALIVE":
                if (parameters.Length < 2)
                {
                    return;
                }

                int    gameIndex = Conversions.IntFromString(parameters[0], -1);
                string name      = parameters[1];

                if (user == null)
                {
                    Texture2D gameTexture = unknownGameIcon;

                    if (gameIndex > -1 && gameIndex < gameCollection.GameList.Count)
                    {
                        gameTexture = gameCollection.GameList[gameIndex].Texture;
                    }

                    user = new LANLobbyUser(name, gameTexture, endPoint);
                    players.Add(user);
                    lbPlayerList.AddItem(user.Name, gameTexture);
                }

                user.TimeWithoutRefresh = TimeSpan.Zero;

                break;

            case "CHAT":
                if (user == null)
                {
                    return;
                }

                if (parameters.Length < 2)
                {
                    return;
                }

                int colorIndex = Conversions.IntFromString(parameters[0], -1);

                if (colorIndex < 0 || colorIndex >= chatColors.Length)
                {
                    return;
                }

                lbChatMessages.AddMessage(new ChatMessage(user.Name,
                                                          chatColors[colorIndex].XNAColor, DateTime.Now, parameters[1]));

                break;

            case "QUIT":
                if (user == null)
                {
                    return;
                }

                int index = players.FindIndex(p => p == user);

                players.RemoveAt(index);
                lbPlayerList.Items.RemoveAt(index);
                break;

            case "GAME":
                if (user == null)
                {
                    return;
                }

                HostedLANGame game = new HostedLANGame();
                if (!game.SetDataFromStringArray(gameCollection, parameters))
                {
                    return;
                }
                game.EndPoint = endPoint;

                int existingGameIndex = lbGameList.HostedGames.FindIndex(g => ((HostedLANGame)g).EndPoint.Equals(endPoint));

                if (existingGameIndex > -1)
                {
                    lbGameList.HostedGames[existingGameIndex] = game;
                }
                else
                {
                    lbGameList.HostedGames.Add(game);
                }

                lbGameList.Refresh();

                break;
            }
        }
        /// <summary>
        /// Parses a Battle(E).ini file. Returns true if succesful (file found), otherwise false.
        /// </summary>
        /// <param name="path">The path of the file, relative to the game directory.</param>
        /// <returns>True if succesful, otherwise false.</returns>
        private bool ParseBattleIni(string path)
        {
            Logger.Log("Attempting to parse " + path + " to populate mission list.");

            string battleIniPath = ProgramConstants.GamePath + path;

            if (!File.Exists(battleIniPath))
            {
                Logger.Log("File " + path + " not found. Ignoring.");
                return(false);
            }

            IniFile battleIni = new IniFile(battleIniPath);

            List <string> battleKeys = battleIni.GetSectionKeys("Battles");

            if (battleKeys == null)
            {
                return(false); // File exists but [Battles] doesn't
            }
            foreach (string battleEntry in battleKeys)
            {
                string battleSection = battleIni.GetStringValue("Battles", battleEntry, "NOT FOUND");

                if (!battleIni.SectionExists(battleSection))
                {
                    continue;
                }

                var mission = new Mission(battleIni, battleSection);

                Missions.Add(mission);

                XNAListBoxItem item = new XNAListBoxItem();
                item.Text = mission.GUIName;
                if (!mission.Enabled)
                {
                    item.TextColor = UISettings.ActiveSettings.DisabledItemColor;
                }
                else if (string.IsNullOrEmpty(mission.Scenario))
                {
                    item.TextColor = AssetLoader.GetColorFromString(
                        ClientConfiguration.Instance.ListBoxHeaderColor);
                    item.IsHeader   = true;
                    item.Selectable = false;
                }
                else
                {
                    item.TextColor = lbCampaignList.DefaultItemColor;
                }

                if (!string.IsNullOrEmpty(mission.IconPath))
                {
                    item.Texture = AssetLoader.LoadTexture(mission.IconPath + "icon.png");
                }

                lbCampaignList.AddItem(item);
            }

            Logger.Log("Finished parsing " + path + ".");
            return(true);
        }