Move skirmish bot creation to the server.
This commit is contained in:
33
OpenRA.Mods.Common/ServerTraits/SkirmishLogic.cs
Normal file
33
OpenRA.Mods.Common/ServerTraits/SkirmishLogic.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright (c) The OpenRA Developers and Contributors
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Server;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using S = OpenRA.Server.Server;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Server
|
||||||
|
{
|
||||||
|
public class SkirmishLogic : ServerTrait, IClientJoined
|
||||||
|
{
|
||||||
|
public void ClientJoined(S server, Connection conn)
|
||||||
|
{
|
||||||
|
if (server.Type != ServerType.Skirmish)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var slot = server.LobbyInfo.FirstEmptyBotSlot();
|
||||||
|
var bot = server.Map.PlayerActorInfo.TraitInfos<IBotInfo>().Select(t => t.Type).FirstOrDefault();
|
||||||
|
var botController = server.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
||||||
|
if (slot != null && bot != null)
|
||||||
|
server.InterpretCommand($"slot_bot {slot} {botController.Index} {bot}", conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -98,7 +98,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Session.MapStatus mapStatus;
|
Session.MapStatus mapStatus;
|
||||||
|
|
||||||
bool chatEnabled;
|
bool chatEnabled;
|
||||||
bool addBotOnMapLoad;
|
|
||||||
bool disableTeamChat;
|
bool disableTeamChat;
|
||||||
bool insufficientPlayerSpawns;
|
bool insufficientPlayerSpawns;
|
||||||
bool teamChat;
|
bool teamChat;
|
||||||
@@ -552,10 +551,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a bot on the first lobbyinfo update
|
|
||||||
if (skirmishMode)
|
|
||||||
addBotOnMapLoad = true;
|
|
||||||
|
|
||||||
if (logicArgs.TryGetValue("ChatLineSound", out var yaml))
|
if (logicArgs.TryGetValue("ChatLineSound", out var yaml))
|
||||||
chatLineSound = yaml.Value;
|
chatLineSound = yaml.Value;
|
||||||
if (logicArgs.TryGetValue("PlayerJoinedSound", out yaml))
|
if (logicArgs.TryGetValue("PlayerJoinedSound", out yaml))
|
||||||
@@ -647,22 +642,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
map = modData.MapCache[uid];
|
map = modData.MapCache[uid];
|
||||||
|
|
||||||
|
// Tell the server that we have the map
|
||||||
if (map.Status == MapStatus.Available)
|
if (map.Status == MapStatus.Available)
|
||||||
{
|
|
||||||
// Tell the server that we have the map
|
|
||||||
orderManager.IssueOrder(Order.Command($"state {Session.ClientState.NotReady}"));
|
orderManager.IssueOrder(Order.Command($"state {Session.ClientState.NotReady}"));
|
||||||
|
|
||||||
if (addBotOnMapLoad)
|
// We don't have the map
|
||||||
{
|
|
||||||
var slot = orderManager.LobbyInfo.FirstEmptyBotSlot();
|
|
||||||
var bot = map.PlayerActorInfo.TraitInfos<IBotInfo>().Select(t => t.Type).FirstOrDefault();
|
|
||||||
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
|
||||||
if (slot != null && bot != null)
|
|
||||||
orderManager.IssueOrder(Order.Command($"slot_bot {slot} {botController.Index} {bot}"));
|
|
||||||
|
|
||||||
addBotOnMapLoad = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (map.Status != MapStatus.DownloadAvailable && Game.Settings.Game.AllowDownloading)
|
else if (map.Status != MapStatus.DownloadAvailable && Game.Settings.Game.AllowDownloading)
|
||||||
modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { uid });
|
modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { uid });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ LoadScreen: CncLoadScreen
|
|||||||
|
|
||||||
ServerTraits:
|
ServerTraits:
|
||||||
LobbyCommands
|
LobbyCommands
|
||||||
|
SkirmishLogic
|
||||||
PlayerPinger
|
PlayerPinger
|
||||||
MasterServerPinger
|
MasterServerPinger
|
||||||
LobbySettingsNotification
|
LobbySettingsNotification
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ LoadScreen: LogoStripeLoadScreen
|
|||||||
|
|
||||||
ServerTraits:
|
ServerTraits:
|
||||||
LobbyCommands
|
LobbyCommands
|
||||||
|
SkirmishLogic
|
||||||
PlayerPinger
|
PlayerPinger
|
||||||
MasterServerPinger
|
MasterServerPinger
|
||||||
LobbySettingsNotification
|
LobbySettingsNotification
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ LoadScreen: LogoStripeLoadScreen
|
|||||||
|
|
||||||
ServerTraits:
|
ServerTraits:
|
||||||
LobbyCommands
|
LobbyCommands
|
||||||
|
SkirmishLogic
|
||||||
PlayerPinger
|
PlayerPinger
|
||||||
MasterServerPinger
|
MasterServerPinger
|
||||||
LobbySettingsNotification
|
LobbySettingsNotification
|
||||||
|
|||||||
@@ -219,6 +219,7 @@ LoadScreen: LogoStripeLoadScreen
|
|||||||
|
|
||||||
ServerTraits:
|
ServerTraits:
|
||||||
LobbyCommands
|
LobbyCommands
|
||||||
|
SkirmishLogic
|
||||||
PlayerPinger
|
PlayerPinger
|
||||||
MasterServerPinger
|
MasterServerPinger
|
||||||
LobbySettingsNotification
|
LobbySettingsNotification
|
||||||
|
|||||||
Reference in New Issue
Block a user