public void ClientJoined(OpenRA.Server.Server server, Connection conn)
        {
            if (server.LobbyInfo.ClientWithIndex(conn.PlayerIndex).IsAdmin)
            {
                return;
            }

            var defaults = new Session.Global();

            LobbyCommands.LoadMapSettings(server, defaults, server.Map.Rules);

            var options = server.Map.Rules.Actors["player"].TraitInfos <ILobbyOptions>()
                          .Concat(server.Map.Rules.Actors["world"].TraitInfos <ILobbyOptions>())
                          .SelectMany(t => t.LobbyOptions(server.Map.Rules));

            var optionNames = new Dictionary <string, string>();

            foreach (var o in options)
            {
                optionNames[o.Id] = o.Name;
            }

            foreach (var kv in server.LobbyInfo.GlobalSettings.LobbyOptions)
            {
                Session.LobbyOptionState def;
                string optionName;
                if (!defaults.LobbyOptions.TryGetValue(kv.Key, out def) || kv.Value.Value != def.Value)
                {
                    if (optionNames.TryGetValue(kv.Key, out optionName))
                    {
                        server.SendOrderTo(conn, "Message", optionName + ": " + kv.Value.Value);
                    }
                }
            }
        }
Example #2
0
 public void UpdateServerSettings(Session.Global settings)
 {
     if (Cheats.HasValue)
     {
         settings.AllowCheats = Cheats.Value;
     }
     if (Crates.HasValue)
     {
         settings.Crates = Crates.Value;
     }
     if (Fog.HasValue)
     {
         settings.Fog = Fog.Value;
     }
     if (Shroud.HasValue)
     {
         settings.Shroud = Shroud.Value;
     }
     if (AllyBuildRadius.HasValue)
     {
         settings.AllyBuildRadius = AllyBuildRadius.Value;
     }
     if (StartingCash.HasValue)
     {
         settings.StartingCash = StartingCash.Value;
     }
     if (FragileAlliances.HasValue)
     {
         settings.FragileAlliances = FragileAlliances.Value;
     }
 }
        public void ClientJoined(OpenRA.Server.Server server, Connection conn)
        {
            lock (server.LobbyInfo)
            {
                if (server.LobbyInfo.ClientWithIndex(conn.PlayerIndex).IsAdmin)
                {
                    return;
                }

                var defaults = new Session.Global();
                LobbyCommands.LoadMapSettings(server, defaults, server.Map.Rules);

                var options = server.Map.Rules.Actors["player"].TraitInfos <ILobbyOptions>()
                              .Concat(server.Map.Rules.Actors["world"].TraitInfos <ILobbyOptions>())
                              .SelectMany(t => t.LobbyOptions(server.Map.Rules))
                              .ToDictionary(o => o.Id, o => o);

                foreach (var kv in server.LobbyInfo.GlobalSettings.LobbyOptions)
                {
                    if (!defaults.LobbyOptions.TryGetValue(kv.Key, out var def) || kv.Value.Value != def.Value)
                    {
                        if (options.TryGetValue(kv.Key, out var option))
                        {
                            server.SendOrderTo(conn, "Message", option.Name + ": " + option.Values[kv.Value.Value]);
                        }
                    }
                }
            }
        }
        public void ClientJoined(OpenRA.Server.Server server, Connection conn)
        {
            if (server.LobbyInfo.ClientWithIndex(conn.PlayerIndex).IsAdmin)
            {
                return;
            }

            var defaults = new Session.Global();

            FieldLoader.Load(defaults, Game.modData.Manifest.LobbyDefaults);

            if (server.LobbyInfo.GlobalSettings.FragileAlliances != defaults.FragileAlliances)
            {
                server.SendOrderTo(conn, "Message", "Diplomacy Changes: {0}".F(server.LobbyInfo.GlobalSettings.FragileAlliances));
            }

            if (server.LobbyInfo.GlobalSettings.AllowCheats != defaults.AllowCheats)
            {
                server.SendOrderTo(conn, "Message", "Allow Cheats: {0}".F(server.LobbyInfo.GlobalSettings.AllowCheats));
            }

            if (server.LobbyInfo.GlobalSettings.Shroud != defaults.Shroud)
            {
                server.SendOrderTo(conn, "Message", "Shroud: {0}".F(server.LobbyInfo.GlobalSettings.Shroud));
            }

            if (server.LobbyInfo.GlobalSettings.Fog != defaults.Fog)
            {
                server.SendOrderTo(conn, "Message", "Fog of war: {0}".F(server.LobbyInfo.GlobalSettings.Fog));
            }

            if (server.LobbyInfo.GlobalSettings.Crates != defaults.Crates)
            {
                server.SendOrderTo(conn, "Message", "Crates Appear: {0}".F(server.LobbyInfo.GlobalSettings.Crates));
            }

            if (server.LobbyInfo.GlobalSettings.AllyBuildRadius != defaults.AllyBuildRadius)
            {
                server.SendOrderTo(conn, "Message", "Build off Ally ConYards: {0}".F(server.LobbyInfo.GlobalSettings.AllyBuildRadius));
            }

            if (server.LobbyInfo.GlobalSettings.StartingUnitsClass != defaults.StartingUnitsClass)
            {
                var startUnitsInfo = server.Map.Rules.Actors["world"].Traits.WithInterface <MPStartUnitsInfo>();
                var selectedClass  = startUnitsInfo.Where(u => u.Class == server.LobbyInfo.GlobalSettings.StartingUnitsClass).Select(u => u.ClassName).FirstOrDefault();
                var className      = selectedClass != null ? selectedClass : server.LobbyInfo.GlobalSettings.StartingUnitsClass;
                server.SendOrderTo(conn, "Message", "Starting Units: {0}".F(className));
            }

            if (server.LobbyInfo.GlobalSettings.StartingCash != defaults.StartingCash)
            {
                server.SendOrderTo(conn, "Message", "Starting Cash: ${0}".F(server.LobbyInfo.GlobalSettings.StartingCash));
            }

            if (server.LobbyInfo.GlobalSettings.TechLevel != defaults.TechLevel)
            {
                server.SendOrderTo(conn, "Message", "Tech Level: {0}".F(server.LobbyInfo.GlobalSettings.TechLevel));
            }
        }
Example #5
0
        public static void LoadMapSettings(S server, Session.Global gs, Ruleset rules)
        {
            lock (server.LobbyInfo)
            {
                var options = rules.Actors["player"].TraitInfos <ILobbyOptions>()
                              .Concat(rules.Actors["world"].TraitInfos <ILobbyOptions>())
                              .SelectMany(t => t.LobbyOptions(rules));

                foreach (var o in options)
                {
                    var value          = o.DefaultValue;
                    var preferredValue = o.DefaultValue;
                    if (gs.LobbyOptions.TryGetValue(o.Id, out var state))
                    {
                        // Propagate old state on map change
                        if (!o.IsLocked)
                        {
                            if (o.Values.Keys.Contains(state.PreferredValue))
                            {
                                value = state.PreferredValue;
                            }
                            else if (o.Values.Keys.Contains(state.Value))
                            {
                                value = state.Value;
                            }
                        }

                        preferredValue = state.PreferredValue;
                    }
                    else
                    {
                        state = new Session.LobbyOptionState();
                    }

                    state.IsLocked        = o.IsLocked;
                    state.Value           = value;
                    state.PreferredValue  = preferredValue;
                    gs.LobbyOptions[o.Id] = state;

                    if (o.Id == "gamespeed")
                    {
                        var speed = server.ModData.Manifest.Get <GameSpeeds>().Speeds[value];
                        gs.Timestep     = speed.Timestep;
                        gs.OrderLatency = speed.OrderLatency;
                    }
                }
            }
        }
Example #6
0
        public static void LoadMapSettings(S server, Session.Global gs, MapPreview map)
        {
            lock (server.LobbyInfo)
            {
                var options = map.PlayerActorInfo.TraitInfos <ILobbyOptions>()
                              .Concat(map.WorldActorInfo.TraitInfos <ILobbyOptions>())
                              .SelectMany(t => t.LobbyOptions(map));

                foreach (var o in options)
                {
                    var value          = o.DefaultValue;
                    var preferredValue = o.DefaultValue;
                    if (gs.LobbyOptions.TryGetValue(o.Id, out var state))
                    {
                        // Propagate old state on map change
                        if (!o.IsLocked)
                        {
                            if (o.Values.Keys.Contains(state.PreferredValue))
                            {
                                value = state.PreferredValue;
                            }
                            else if (o.Values.Keys.Contains(state.Value))
                            {
                                value = state.Value;
                            }
                        }

                        preferredValue = state.PreferredValue;
                    }
                    else
                    {
                        state = new Session.LobbyOptionState();
                    }

                    state.IsLocked        = o.IsLocked;
                    state.Value           = value;
                    state.PreferredValue  = preferredValue;
                    gs.LobbyOptions[o.Id] = state;
                }
            }
        }
        public void ClientJoined(OpenRA.Server.Server server, Connection conn)
        {
            if (server.LobbyInfo.ClientWithIndex(conn.PlayerIndex).IsAdmin)
            {
                return;
            }

            var defaults = new Session.Global();

            LobbyCommands.LoadMapSettings(defaults, server.Map.Rules);

            if (server.LobbyInfo.GlobalSettings.AllowCheats != defaults.AllowCheats)
            {
                server.SendOrderTo(conn, "Message", "Allow Cheats: {0}".F(server.LobbyInfo.GlobalSettings.AllowCheats));
            }

            if (server.LobbyInfo.GlobalSettings.Shroud != defaults.Shroud)
            {
                server.SendOrderTo(conn, "Message", "Explored map: {0}".F(!server.LobbyInfo.GlobalSettings.Shroud));
            }

            if (server.LobbyInfo.GlobalSettings.Fog != defaults.Fog)
            {
                server.SendOrderTo(conn, "Message", "Fog of war: {0}".F(server.LobbyInfo.GlobalSettings.Fog));
            }

            if (server.LobbyInfo.GlobalSettings.Crates != defaults.Crates)
            {
                server.SendOrderTo(conn, "Message", "Crates Appear: {0}".F(server.LobbyInfo.GlobalSettings.Crates));
            }

            if (server.LobbyInfo.GlobalSettings.Creeps != defaults.Creeps)
            {
                server.SendOrderTo(conn, "Message", "Creeps Spawn: {0}".F(server.LobbyInfo.GlobalSettings.Creeps));
            }

            if (server.LobbyInfo.GlobalSettings.AllyBuildRadius != defaults.AllyBuildRadius)
            {
                server.SendOrderTo(conn, "Message", "Build off Ally ConYards: {0}".F(server.LobbyInfo.GlobalSettings.AllyBuildRadius));
            }

            if (server.LobbyInfo.GlobalSettings.StartingUnitsClass != defaults.StartingUnitsClass)
            {
                var startUnitsInfo = server.Map.Rules.Actors["world"].TraitInfos <MPStartUnitsInfo>();
                var selectedClass  = startUnitsInfo.Where(u => u.Class == server.LobbyInfo.GlobalSettings.StartingUnitsClass).Select(u => u.ClassName).FirstOrDefault();
                var className      = selectedClass != null ? selectedClass : server.LobbyInfo.GlobalSettings.StartingUnitsClass;
                server.SendOrderTo(conn, "Message", "Starting Units: {0}".F(className));
            }

            if (server.LobbyInfo.GlobalSettings.StartingCash != defaults.StartingCash)
            {
                server.SendOrderTo(conn, "Message", "Starting Cash: ${0}".F(server.LobbyInfo.GlobalSettings.StartingCash));
            }

            if (server.LobbyInfo.GlobalSettings.TechLevel != defaults.TechLevel)
            {
                server.SendOrderTo(conn, "Message", "Tech Level: {0}".F(server.LobbyInfo.GlobalSettings.TechLevel));
            }

            if (server.LobbyInfo.GlobalSettings.ShortGame != defaults.ShortGame)
            {
                server.SendOrderTo(conn, "Message", "Short Game: {0}".F(server.LobbyInfo.GlobalSettings.ShortGame));
            }
        }