Merge pull request #2957 from Mailaender/dedicated-bot-order-exploits

Don't misinterpret AI orders as an exploit on dedicated servers anymore.
This commit is contained in:
Chris Forbes
2013-04-05 18:48:17 -07:00
6 changed files with 35 additions and 16 deletions

View File

@@ -57,6 +57,7 @@ namespace OpenRA.Network
public int Team;
public string Slot; // slot ID, or null for observer
public string Bot; // Bot type, null for real clients
public int BotControllerClientIndex; // who added the bot to the slot
public bool IsAdmin;
public bool IsReady { get { return State == ClientState.Ready; } }
public bool IsObserver { get { return Slot == null; } }

View File

@@ -528,6 +528,8 @@ namespace OpenRA.Server
SendDisconnected(toDrop); /* Report disconnection */
lobbyInfo.Clients.RemoveAll(c => c.Index == toDrop.PlayerIndex);
// remove the bots he added
lobbyInfo.Clients.RemoveAll(c => c.BotControllerClientIndex == toDrop.PlayerIndex);
// reassign admin if necessary
if (lobbyInfo.GlobalSettings.Dedicated && dropClient.IsAdmin && State == ServerState.WaitingPlayers)

View File

@@ -31,8 +31,7 @@ namespace OpenRA.Traits
return false;
}
// Hack: Assumes bots always run on clientId 0.
var isBotOrder = subjectClient.Bot != null && clientId == 0;
var isBotOrder = subjectClient.Bot != null && clientId == subjectClient.BotControllerClientIndex;
// Drop exploiting orders
if (subjectClientId != clientId && !isBotOrder)

View File

@@ -104,7 +104,11 @@ namespace OpenRA.Mods.RA.Server
s =>
{
int lag;
if (!int.TryParse(s, out lag)) { Log.Write("server", "Invalid order lag: {0}", s); return false; }
if (!int.TryParse(s, out lag))
{
Log.Write("server", "Invalid order lag: {0}", s);
return false;
}
Log.Write("server", "Order lag is now {0} frames.", lag);
@@ -190,7 +194,7 @@ namespace OpenRA.Mods.RA.Server
{
var parts = s.Split(' ');
if (parts.Length < 2)
if (parts.Length < 3)
{
server.SendChatTo(conn, "Malformed slot_bot command");
return true;
@@ -201,7 +205,13 @@ namespace OpenRA.Mods.RA.Server
var slot = server.lobbyInfo.Slots[parts[0]];
var bot = server.lobbyInfo.ClientInSlot(parts[0]);
var botType = parts.Skip(1).JoinWith(" ");
int controllerClientIndex;
if (!int.TryParse(parts[1], out controllerClientIndex))
{
Log.Write("server", "Invalid bot controller client index: {0}", parts[1]);
return false;
}
var botType = parts.Skip(2).JoinWith(" ");
// Invalid slot
if (bot != null && bot.Bot == null)
@@ -223,7 +233,8 @@ namespace OpenRA.Mods.RA.Server
Country = "random",
SpawnPoint = 0,
Team = 0,
State = Session.ClientState.NotReady
State = Session.ClientState.NotReady,
BotControllerClientIndex = controllerClientIndex
};
// pick a random color for the bot
@@ -465,7 +476,11 @@ namespace OpenRA.Mods.RA.Server
return true;
int team;
if (!int.TryParse(parts[1], out team)) { Log.Write("server", "Invalid team: {0}", s ); return false; }
if (!int.TryParse(parts[1], out team))
{
Log.Write("server", "Invalid team: {0}", s );
return false;
}
targetClient.Team = team;
server.SyncLobbyInfo();
@@ -546,7 +561,7 @@ namespace OpenRA.Mods.RA.Server
static Session.Slot MakeSlotFromPlayerReference(PlayerReference pr)
{
if (!pr.Playable) return null;
if (Game.Settings.Server.LockBots || Game.Settings.Server.Dedicated)
if (Game.Settings.Server.LockBots)
pr.AllowBots = false;
return new Session.Slot
{

View File

@@ -287,8 +287,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
var slot = orderManager.LobbyInfo.FirstEmptySlot();
var bot = Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name).FirstOrDefault();
var botController = orderManager.LobbyInfo.Clients.Where(c => c.IsAdmin).FirstOrDefault();
if (slot != null && bot != null)
orderManager.IssueOrder(Order.Command("slot_bot {0} {1}".F(slot, bot)));
orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot, botController.Index, bot)));
});
}

View File

@@ -71,8 +71,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
foreach (var b in Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
{
var bot = b;
var botController = orderManager.LobbyInfo.Clients.Where(c => c.IsAdmin).FirstOrDefault();
options.Add(new SlotDropDownOption("Bot: {0}".F(bot),
"slot_bot {0} {1}".F(slot.PlayerReference, bot),
"slot_bot {0} {1} {2}".F(slot.PlayerReference, botController.Index, bot),
() => client != null && client.Bot == bot));
}