Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion ClientCore/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void RefreshSettings()

public string[] TrustedDomains => clientDefinitionsIni.GetStringListValue(SETTINGS, "TrustedDomains", string.Empty);

public string[] AlwaysTrustedDomains = {"cncnet.org", "gamesurge.net", "dronebl.org", "discord.com", "discord.gg", "youtube.com", "youtu.be"};
public string[] AlwaysTrustedDomains = { "cncnet.org", "gamesurge.net", "dronebl.org", "discord.com", "discord.gg", "youtube.com", "youtu.be" };

public (string Name, string Path) GetThemeInfoFromIndex(int themeIndex) => clientDefinitionsIni.GetStringValue("Themes", themeIndex.ToString(), ",").Split(',').AsTuple2();

Expand All @@ -287,6 +287,30 @@ public string GetThemePath(string themeName)
return null;
}

private string[] GetCoopDifficultyINIPaths()
{
List<string> paths = new List<string>();
var pathString = clientDefinitionsIni.GetStringValue(SETTINGS, nameof(CoopDifficultyINIPaths), string.Empty);

if (string.IsNullOrEmpty(pathString))
{
paths.Add(SafePath.CombineFilePath("INI", "Map Code", "Coop Difficulty Easy.ini"));
paths.Add(SafePath.CombineFilePath("INI", "Map Code", "Coop Difficulty Medium.ini"));
paths.Add(SafePath.CombineFilePath("INI", "Map Code", "Coop Difficulty Hard.ini"));
}
else
{
var pathStrings = pathString.Split(',', StringSplitOptions.RemoveEmptyEntries);

foreach (var path in pathStrings)
{
paths.Add(SafePath.CombineFilePath(path));
}
}

return paths.ToArray();
}

public string SettingsIniName => clientDefinitionsIni.GetStringValue(SETTINGS, "SettingsFile", "Settings.ini");

public string TranslationIniName => clientDefinitionsIni.GetStringValue(TRANSLATIONS, nameof(TranslationIniName), "Translation.ini");
Expand Down Expand Up @@ -348,6 +372,8 @@ private List<TranslationGameFile> ParseTranslationGameFiles()

public string MPMapsIniPath => SafePath.CombineFilePath(clientDefinitionsIni.GetStringValue(SETTINGS, "MPMapsPath", SafePath.CombineFilePath("INI", "MPMaps.ini")));

public string[] CoopDifficultyINIPaths => GetCoopDifficultyINIPaths();

public string KeyboardINI => clientDefinitionsIni.GetStringValue(SETTINGS, "KeyboardINI", "Keyboard.ini");

public int MinimumIngameWidth => clientDefinitionsIni.GetIntValue(SETTINGS, "MinimumIngameWidth", 640);
Expand Down
5 changes: 3 additions & 2 deletions ClientCore/ProgramConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static class ProgramConstants

public const string QRES_EXECUTABLE = "qres.dat";

public const string CNCNET_PROTOCOL_REVISION = "R13";
public const string LAN_PROTOCOL_REVISION = "RL8";
public const string CNCNET_PROTOCOL_REVISION = "R14";
public const string LAN_PROTOCOL_REVISION = "RL9";
public const int LAN_PORT = 1234;
public const int LAN_INGAME_PORT = 1234;
public const int LAN_LOBBY_PORT = 1232;
Expand Down Expand Up @@ -112,6 +112,7 @@ public static string GetAILevelName(int aiLevel)

// Static fields might be initialized before the translation file is loaded. Change to readonly properties here.
public static List<string> AI_PLAYER_NAMES => new List<string> { "Easy AI".L10N("Client:Main:EasyAIName"), "Medium AI".L10N("Client:Main:MediumAIName"), "Hard AI".L10N("Client:Main:HardAIName") };
public static List<string> DIFFICULTY_NAMES => new List<string> { "Easy".L10N("Client:Main:DifficultyEasy"), "Medium".L10N("Client:Main:DifficultyMedium"), "Hard".L10N("Client:Main:DifficultyHard") };

public static string LogFileName { get; set; }

Expand Down
4 changes: 1 addition & 3 deletions DXMainClient/DXGUI/Campaign/CampaignSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class CampaignSelector : XNAWindow

private const string SETTINGS_PATH = "Client/CampaignSettings.ini";

private static string[] DifficultyNames = new string[] { "Easy", "Medium", "Hard" };

private static string[] DifficultyIniPaths = new string[]
{
"INI/Map Code/Difficulty Easy.ini",
Expand Down Expand Up @@ -364,7 +362,7 @@ private void LaunchMission(Mission mission)
spawnIni.WriteIniFile();

var difficultyIni = new IniFile(SafePath.CombineFilePath(ProgramConstants.GamePath, DifficultyIniPaths[trbDifficultySelector.Value]));
string difficultyName = DifficultyNames[trbDifficultySelector.Value];
string difficultyName = ProgramConstants.DIFFICULTY_NAMES[trbDifficultySelector.Value];

if (copyMapsToSpawnmapINI)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ private void BroadcastGame()
sb.Append(ClientConfiguration.Instance.DefaultSkillLevelIndex); // we don't know the original skill level
sb.Append(";");
sb.Append(string.Empty); // MapHash
sb.Append(";");
sb.Append(CoopDifficulty);

broadcastChannel.SendCTCPMessage(sb.ToString(), QueuedMessageType.SYSTEM_MESSAGE, 20);
}
Expand Down
5 changes: 4 additions & 1 deletion DXMainClient/DXGUI/Multiplayer/CnCNet/CnCNetLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ private void GameBroadcastChannel_CTCPReceived(object sender, ChannelCTCPEventAr
string msg = e.Message.Substring(5); // Cut out GAME part
string[] splitMessage = msg.Split(new char[] { ';' });

if (splitMessage.Length != 13)
if (splitMessage.Length != 14)
{
Logger.Log("Ignoring CTCP game message because of an invalid amount of parameters.");

Expand Down Expand Up @@ -1550,6 +1550,8 @@ private void GameBroadcastChannel_CTCPReceived(object sender, ChannelCTCPEventAr
string loadedGameId = splitMessage[10];
int skillLevel = int.Parse(splitMessage[11]);
string mapHash = splitMessage[12];
int difficulty = int.Parse(splitMessage[13]);


CnCNetGame cncnetGame = gameCollection.GameList.Find(g => g.GameBroadcastChannel == channel.ChannelName);

Expand Down Expand Up @@ -1611,6 +1613,7 @@ private void GameBroadcastChannel_CTCPReceived(object sender, ChannelCTCPEventAr
game.Incompatible = cncnetGame == localGame && game.GameVersion != ProgramConstants.GAME_VERSION;
game.TunnelServer = tunnel;
game.SkillLevel = skillLevel;
game.Difficulty = difficulty;

if (isClosed)
{
Expand Down
3 changes: 3 additions & 0 deletions DXMainClient/DXGUI/Multiplayer/GameInformationPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public void SetInfo(GenericHostedGame game)
string translatedGameModeName = string.IsNullOrEmpty(game.GameMode)
? "Unknown".L10N("Client:Main:Unknown") : game.GameMode.L10N($"INI:GameModes:{game.GameMode}:UIName", notify: false);

if (game.Difficulty >= 0 && game.Difficulty < ProgramConstants.DIFFICULTY_NAMES.Count)
translatedGameModeName += $" ({ProgramConstants.DIFFICULTY_NAMES[game.Difficulty]})";

lblGameMode.Text = Renderer.GetStringWithLimitedWidth("Game mode:".L10N("Client:Main:GameInfoGameMode") + " " + Renderer.GetSafeString(translatedGameModeName, lblGameMode.FontIndex),
lblGameMode.FontIndex, Width - lblGameMode.X);
lblGameMode.Visible = true;
Expand Down
8 changes: 8 additions & 0 deletions DXMainClient/DXGUI/Multiplayer/GameLoadingLobbyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public GameLoadingLobbyBase(WindowManager windowManager, DiscordHandler discordH
protected XNAClientButton btnLoadGame;
protected XNAClientButton btnLeaveGame;

protected int CoopDifficulty;

private List<MultiplayerColor> MPColors = new List<MultiplayerColor>();

private string loadedGameID;
Expand All @@ -75,6 +77,8 @@ public GameLoadingLobbyBase(WindowManager windowManager, DiscordHandler discordH

public override void Initialize()
{
CoopDifficulty = -1;

Name = "GameLoadingLobby";
ClientRectangle = new Rectangle(0, 0, 590, 510);
BackgroundTexture = AssetLoader.LoadTexture("loadmpsavebg.png");
Expand Down Expand Up @@ -409,6 +413,10 @@ public virtual void Refresh(bool isHost)
uniqueGameId = spawnSGIni.GetIntValue("Settings", "GameID", -1);

int playerCount = spawnSGIni.GetIntValue("Settings", "PlayerCount", 0);
CoopDifficulty = spawnSGIni.GetIntValue("Settings", "CoopDifficulty", -1);

if (CoopDifficulty >= 0 && CoopDifficulty < ProgramConstants.DIFFICULTY_NAMES.Count)
lblMapNameValue.Text += $" ({ProgramConstants.DIFFICULTY_NAMES[CoopDifficulty]})";

SavedGamePlayer localPlayer = new SavedGamePlayer();
localPlayer.Name = ProgramConstants.PLAYERNAME;
Expand Down
35 changes: 27 additions & 8 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/CnCNetGameLobby.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;

using ClientCore;
using ClientCore.Extensions;

using ClientGUI;
using DTAClient.Domain.Multiplayer;

using DTAClient.Domain;
using DTAClient.Domain.Multiplayer;
using DTAClient.Domain.Multiplayer.CnCNet;
using DTAClient.DXGUI.Generic;
using DTAClient.DXGUI.Multiplayer.CnCNet;
using DTAClient.DXGUI.Multiplayer.GameLobby.CommandHandlers;
using DTAClient.Online;
using DTAClient.Online.EventArguments;

using Microsoft.Xna.Framework;

using Rampastring.Tools;
using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using DTAClient.Domain.Multiplayer.CnCNet;
using ClientCore.Extensions;

namespace DTAClient.DXGUI.Multiplayer.GameLobby
{
Expand Down Expand Up @@ -1049,6 +1055,7 @@ protected override void OnGameOptionChanged()
sb.Append(RandomSeed);
sb.Append(Convert.ToInt32(RemoveStartingLocations));
sb.Append(Map?.UntranslatedName ?? string.Empty);
sb.Append(ddDifficulty?.SelectedIndex ?? -1);

channel.SendCTCPMessage(sb.ToString(), QueuedMessageType.GAME_SETTINGS_MESSAGE, 11);
}
Expand Down Expand Up @@ -1223,6 +1230,15 @@ private void ApplyGameOptions(string sender, string message)
Convert.ToInt32(RemoveStartingLocations)));
SetRandomStartingLocations(removeStartingLocations);

if (GameMode != null && GameMode.UseDifficultyDropDown && ddDifficulty != null)
{
int newIndex = Conversions.IntFromString(parts[partIndex + 9], ddDifficulty.SelectedIndex);
ddDifficulty.SelectedIndex = newIndex;

if (ddDifficulty.SelectedIndex >= 0)
AddNotice(string.Format("The game host has set {0} to {1}".L10N("Client:Main:HostSetOption"), "Difficulty".L10N("Client:Main:DifficultyOptionName"), ddDifficulty.SelectedItem.Text));
}

RandomSeed = randomSeed;
}

Expand Down Expand Up @@ -2086,10 +2102,13 @@ private void BroadcastGame()
sb.Append(skillLevel); // SkillLevel
sb.Append(";");
sb.Append(Map?.SHA1);
sb.Append(";");
sb.Append(ddDifficulty?.SelectedIndex ?? -1);

broadcastChannel.SendCTCPMessage(sb.ToString(), QueuedMessageType.SYSTEM_MESSAGE, 20);
}


#endregion

public override string GetSwitchName() => "Game Lobby".L10N("Client:Main:GameLobby");
Expand Down
Loading
Loading