本文整理汇总了C#中OpenRA.Network.Session类的典型用法代码示例。如果您正苦于以下问题:C# Session类的具体用法?C# Session怎么用?C# Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Session类属于OpenRA.Network命名空间,在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSpawnOccupants
public static Dictionary<CPos, SpawnOccupant> GetSpawnOccupants(Session lobbyInfo, MapPreview preview)
{
var spawns = preview.SpawnPoints;
return lobbyInfo.Clients
.Where(c => (c.SpawnPoint - 1 >= 0) && (c.SpawnPoint - 1 < spawns.Length))
.ToDictionary(c => spawns[c.SpawnPoint - 1], c => new SpawnOccupant(c));
}
示例2: Replay
public Replay(string filename)
{
Filename = filename;
var lastFrame = 0;
var hasSeenGameStart = false;
var lobbyInfo = null as Session;
using (var conn = new ReplayConnection(filename))
conn.Receive((client, packet) =>
{
var frame = BitConverter.ToInt32(packet, 0);
if (packet.Length == 5 && packet[4] == 0xBF)
return; // disconnect
else if (packet.Length >= 5 && packet[4] == 0x65)
return; // sync
else if (frame == 0)
{
/* decode this to recover lobbyinfo, etc */
var orders = packet.ToOrderList(null);
foreach (var o in orders)
if (o.OrderString == "StartGame")
hasSeenGameStart = true;
else if (o.OrderString == "SyncInfo" && !hasSeenGameStart)
lobbyInfo = Session.Deserialize(o.TargetString);
}
else
lastFrame = Math.Max(lastFrame, frame);
});
Duration = lastFrame * Game.NetTickScale;
LobbyInfo = lobbyInfo;
}
示例3: LoadMapSettings
public static void LoadMapSettings(Session.Global gs, Ruleset rules)
{
var devMode = rules.Actors["player"].TraitInfo<DeveloperModeInfo>();
gs.AllowCheats = devMode.Enabled;
var crateSpawner = rules.Actors["world"].TraitInfoOrDefault<CrateSpawnerInfo>();
gs.Crates = crateSpawner != null && crateSpawner.Enabled;
var shroud = rules.Actors["player"].TraitInfo<ShroudInfo>();
gs.Fog = shroud.FogEnabled;
gs.Shroud = !shroud.ExploredMapEnabled;
var resources = rules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
gs.StartingCash = resources.DefaultCash;
var startingUnits = rules.Actors["world"].TraitInfoOrDefault<SpawnMPUnitsInfo>();
gs.StartingUnitsClass = startingUnits == null ? "none" : startingUnits.StartingUnitsClass;
var mapBuildRadius = rules.Actors["world"].TraitInfoOrDefault<MapBuildRadiusInfo>();
gs.AllyBuildRadius = mapBuildRadius != null && mapBuildRadius.AllyBuildRadiusEnabled;
var mapCreeps = rules.Actors["world"].TraitInfoOrDefault<MapCreepsInfo>();
gs.Creeps = mapCreeps != null && mapCreeps.Enabled;
var mapOptions = rules.Actors["world"].TraitInfo<MapOptionsInfo>();
gs.ShortGame = mapOptions.ShortGameEnabled;
gs.TechLevel = mapOptions.TechLevel;
gs.Difficulty = mapOptions.Difficulty ?? mapOptions.Difficulties.FirstOrDefault();
}
示例4: ShowSlotDropDown
public static void ShowSlotDropDown(Ruleset rules, DropDownButtonWidget dropdown, Session.Slot slot,
Session.Client client, OrderManager orderManager)
{
var options = new Dictionary<string, IEnumerable<SlotDropDownOption>>() {{"Slot", new List<SlotDropDownOption>()
{
new SlotDropDownOption("Open", "slot_open "+slot.PlayerReference, () => (!slot.Closed && client == null)),
new SlotDropDownOption("Closed", "slot_close "+slot.PlayerReference, () => slot.Closed)
}}};
var bots = new List<SlotDropDownOption>();
if (slot.AllowBots)
{
foreach (var b in rules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
{
var bot = b;
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
bots.Add(new SlotDropDownOption(bot,
"slot_bot {0} {1} {2}".F(slot.PlayerReference, botController.Index, bot),
() => client != null && client.Bot == bot));
}
}
options.Add(bots.Any() ? "Bots" : "Bots Disabled", bots);
Func<SlotDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
o.Selected,
() => orderManager.IssueOrder(Order.Command(o.Order)));
item.Get<LabelWidget>("LABEL").GetText = () => o.Title;
return item;
};
dropdown.ShowDropDown<SlotDropDownOption>("LABEL_DROPDOWN_TEMPLATE", 167, options, setupItem);
}
示例5: ShowSlotDropDown
public static void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot,
Session.Client client, OrderManager orderManager)
{
var options = new List<SlotDropDownOption>()
{
new SlotDropDownOption("Open", "slot_open "+slot.PlayerReference, () => (!slot.Closed && client == null)),
new SlotDropDownOption("Closed", "slot_close "+slot.PlayerReference, () => slot.Closed)
};
if (slot.AllowBots)
foreach (var b in Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
{
var bot = b;
options.Add(new SlotDropDownOption("Bot: {0}".F(bot),
"slot_bot {0} {1}".F(slot.PlayerReference, bot),
() => client != null && client.Bot == bot));
}
Func<SlotDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
o.Selected,
() => orderManager.IssueOrder(Order.Command(o.Order)));
item.GetWidget<LabelWidget>("LABEL").GetText = () => o.Title;
return item;
};
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
}
示例6: FindPlayerByClient
static Player FindPlayerByClient(this World world, Session.Client c)
{
/* TODO: this is still a hack.
* the cases we're trying to avoid are the extra players on the host's client -- Neutral, other MapPlayers,..*/
return world.Players.FirstOrDefault(
p => (p.ClientIndex == c.Index && p.PlayerReference.Playable));
}
示例7: SpawnOccupant
public SpawnOccupant(Session.Client client)
{
Color = client.Color;
ClientIndex = client.Index;
PlayerName = client.Name;
Team = client.Team;
Country = client.Country;
SpawnPoint = client.SpawnPoint;
}
示例8: Player
public Player(World world, Session.Client client, PlayerReference pr)
{
string botType;
World = world;
InternalName = pr.Name;
PlayerReference = pr;
// Real player or host-created bot
if (client != null)
{
ClientIndex = client.Index;
Color = client.Color;
PlayerName = client.Name;
botType = client.Bot;
Faction = ChooseFaction(world, client.Faction, !pr.LockFaction);
DisplayFaction = ChooseDisplayFaction(world, client.Faction);
}
else
{
// Map player
ClientIndex = 0; // Owned by the host (TODO: fix this)
Color = pr.Color;
PlayerName = pr.Name;
NonCombatant = pr.NonCombatant;
Playable = pr.Playable;
Spectating = pr.Spectating;
botType = pr.Bot;
Faction = ChooseFaction(world, pr.Faction, false);
DisplayFaction = ChooseDisplayFaction(world, pr.Faction);
}
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
Shroud = PlayerActor.Trait<Shroud>();
fogVisibilities = PlayerActor.TraitsImplementing<IFogVisibilityModifier>().ToArray();
// Enable the bot logic on the host
IsBot = botType != null;
if (IsBot && Game.IsHost)
{
var logic = PlayerActor.TraitsImplementing<IBot>().FirstOrDefault(b => b.Info.Name == botType);
if (logic == null)
Log.Write("debug", "Invalid bot type: {0}", botType);
else
logic.Activate(this);
}
stanceColors.Self = ChromeMetrics.Get<Color>("PlayerStanceColorSelf");
stanceColors.Allies = ChromeMetrics.Get<Color>("PlayerStanceColorAllies");
stanceColors.Enemies = ChromeMetrics.Get<Color>("PlayerStanceColorEnemies");
stanceColors.Neutrals = ChromeMetrics.Get<Color>("PlayerStanceColorNeutrals");
}
示例9: LatencyDescription
public static string LatencyDescription(Session.ClientPing ping)
{
if (ping == null)
return "Unknown";
if (ping.Latency < 0)
return "Unknown";
if (ping.Latency < 300)
return "Good";
if (ping.Latency < 600)
return "Moderate";
return "Poor";
}
示例10: SyncClientToPlayerReference
public static void SyncClientToPlayerReference(Session.Client c, PlayerReference pr)
{
if (pr == null)
return;
if (pr.LockFaction)
c.Faction = pr.Faction;
if (pr.LockSpawn)
c.SpawnPoint = pr.Spawn;
if (pr.LockTeam)
c.Team = pr.Team;
c.Color = pr.LockColor ? pr.Color : c.PreferredColor;
}
示例11: ShowTeamDropDown
public static void ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Client client,
OrderManager orderManager, int teamCount)
{
Func<int, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => client.Team == ii,
() => orderManager.IssueOrder(Order.Command("team {0} {1}".F(client.Index, ii))));
item.Get<LabelWidget>("LABEL").GetText = () => ii == 0 ? "-" : ii.ToString();
return item;
};
var options = Exts.MakeArray(teamCount + 1, i => i).ToList();
dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem);
}
示例12: ValidateCommand
public static bool ValidateCommand(S server, Connection conn, Session.Client client, string cmd)
{
if (server.State == ServerState.GameStarted)
{
server.SendOrderTo(conn, "Message", "Cannot change state when game started. ({0})".F(cmd));
return false;
}
else if (client.State == Session.ClientState.Ready && !(cmd.StartsWith("state") || cmd == "startgame"))
{
server.SendOrderTo(conn, "Message", "Cannot change state when marked as ready.");
return false;
}
return true;
}
示例13: SyncClientToPlayerReference
public static void SyncClientToPlayerReference(Session.Client c, PlayerReference pr)
{
if (pr == null)
return;
if (pr.LockColor)
c.Color = pr.Color;
else
c.Color = c.PreferredColor;
if (pr.LockRace)
c.Country = pr.Race;
if (pr.LockSpawn)
c.SpawnPoint = pr.Spawn;
if (pr.LockTeam)
c.Team = pr.Team;
}
示例14: LatencyColor
public static Color LatencyColor(Session.ClientPing ping)
{
if (ping == null)
return Color.Gray;
// Levels set relative to the default order lag of 3 net ticks (360ms)
// TODO: Adjust this once dynamic lag is implemented
if (ping.Latency < 0)
return Color.Gray;
if (ping.Latency < 300)
return Color.LimeGreen;
if (ping.Latency < 600)
return Color.Orange;
return Color.Red;
}
示例15: ValidateSlotCommand
static bool ValidateSlotCommand(S server, Connection conn, Session.Client client, string arg, bool requiresHost)
{
if (!server.LobbyInfo.Slots.ContainsKey(arg))
{
Log.Write("server", "Invalid slot: {0}", arg);
return false;
}
if (requiresHost && !client.IsAdmin)
{
server.SendOrderTo(conn, "Message", "Only the host can do that.");
return false;
}
return true;
}