当前位置: 首页>>代码示例>>C#>>正文


C# Server.GetClient方法代码示例

本文整理汇总了C#中OpenRA.Server.Server.GetClient方法的典型用法代码示例。如果您正苦于以下问题:C# Server.GetClient方法的具体用法?C# Server.GetClient怎么用?C# Server.GetClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenRA.Server.Server的用法示例。


在下文中一共展示了Server.GetClient方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ClientJoined

        public void ClientJoined(S server, Connection conn)
        {
            var client = server.GetClient(conn);

            // Validate whether color is allowed and get an alternative if it isn't
            if (client.Slot == null || !server.LobbyInfo.Slots[client.Slot].LockColor)
                client.Color = SanitizePlayerColor(server, client.Color, client.Index);
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:8,代码来源:LobbyCommands.cs

示例2: Tick

        public void Tick(S server)
        {
            if ((Game.RunTime - lastPing > PingInterval) || isInitialPing)
            {
                isInitialPing = false;
                lastPing = Game.RunTime;
                foreach (var c in server.Conns.ToList())
                {
                    if (c.TimeSinceLastResponse < ConnTimeout)
                    {
                        server.SendOrderTo(c, "Ping", Game.RunTime.ToString());
                        if (!c.TimeoutMessageShown && c.TimeSinceLastResponse > PingInterval * 2)
                        {
                            server.SendMessage(server.GetClient(c).Name + " is experiencing connection problems.");
                            c.TimeoutMessageShown = true;
                        }
                    }
                    else
                    {
                        server.SendMessage(server.GetClient(c).Name + " has been dropped after timing out.");
                        server.DropClient(c, -1);
                    }
                }
            }

            if (Game.RunTime - lastConnReport > ConnReportInterval)
            {
                lastConnReport = Game.RunTime;

                var timeouts = server.Conns
                    .Where(c => c.TimeSinceLastResponse > ConnReportInterval && c.TimeSinceLastResponse < ConnTimeout)
                    .OrderBy(c => c.TimeSinceLastResponse);

                foreach (var c in timeouts)
                    server.SendMessage("{0} will be dropped in {1} seconds.".F(
                        server.GetClient(c).Name, (ConnTimeout - c.TimeSinceLastResponse) / 1000));
            }
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:38,代码来源:PlayerPinger.cs

示例3: InterpretCommand

        public bool InterpretCommand(S server, Connection conn, Session.Client client, string cmd)
        {
            if (server.GameStarted)
            {
                server.SendChatTo(conn, "Cannot change state when game started. ({0})".F(cmd));
                return false;
            }
            else if (client.State == Session.ClientState.Ready && !(cmd == "ready" || cmd == "startgame"))
            {
                server.SendChatTo(conn, "Cannot change state when marked as ready.");
                return false;
            }

            var dict = new Dictionary<string, Func<string, bool>>
            {
                { "ready",
                    s =>
                    {
                        // if we're downloading, we can't ready up.
                        if (client.State == Session.ClientState.NotReady)
                            client.State = Session.ClientState.Ready;
                        else if (client.State == Session.ClientState.Ready)
                            client.State = Session.ClientState.NotReady;

                        Log.Write("server", "Player @{0} is {1}",
                            conn.socket.RemoteEndPoint, client.State);

                        server.SyncLobbyInfo();

                        if (server.conns.Count > 0 && server.conns.All(c => server.GetClient(c).State == Session.ClientState.Ready))
                            InterpretCommand(server, conn, client, "startgame");

                        return true;
                    }},
                { "startgame",
                    s =>
                    {
                        server.StartGame();
                        return true;
                    }},
                { "lag",
                    s =>
                    {
                        int lag;
                        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);

                        server.lobbyInfo.GlobalSettings.OrderLatency = lag;
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "spectator",
                    s =>
                        {
                            var slotData = server.lobbyInfo.Slots.Where(ax => ax.Spectator && !server.lobbyInfo.Clients.Any(l => l.Slot == ax.Index)).FirstOrDefault();
                            if (slotData == null)
                                return true;

                            client.Slot = slotData.Index;
                            SyncClientToPlayerReference(client, slotData.MapPlayer != null ? server.Map.Players[slotData.MapPlayer] : null);

                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "slot",
                    s =>
                    {
                        int slot;
                        if (!int.TryParse(s, out slot)) { Log.Write("server", "Invalid slot: {0}", s ); return false; }

                        var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
                        if (slotData == null || slotData.Closed || slotData.Bot != null
                            || server.lobbyInfo.Clients.Any( c => c.Slot == slot ))
                            return false;

                        client.Slot = slot;
                        SyncClientToPlayerReference(client, slotData.MapPlayer != null ? server.Map.Players[slotData.MapPlayer] : null);

                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "slot_close",
                    s =>
                    {
                        int slot;
                        if (!int.TryParse(s, out slot)) { Log.Write("server", "Invalid slot: {0}", s ); return false; }

                        var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
                        if (slotData == null)
                            return false;

                        if (conn.PlayerIndex != 0)
                        {
                            server.SendChatTo( conn, "Only the host can alter slots" );
                            return true;
                        }

                        slotData.Closed = true;
                        slotData.Bot = null;
//.........这里部分代码省略.........
开发者ID:geckosoft,项目名称:OpenRA,代码行数:101,代码来源:LobbyCommands.cs

示例4: InterpretCommand


//.........这里部分代码省略.........
                            return true;
                        }

                        server.LobbyInfo.GlobalSettings.GameSpeedType = s;
                        server.LobbyInfo.GlobalSettings.Timestep = speed.Timestep;
                        server.LobbyInfo.GlobalSettings.OrderLatency =
                            server.LobbyInfo.IsSinglePlayer ? 1 : speed.OrderLatency;

                        server.SyncLobbyInfo();
                        server.SendMessage("{0} changed Game Speed to {1}.".F(client.Name, speed.Name));

                        return true;
                    }
                },
                { "kick",
                    s =>
                    {
                        if (!client.IsAdmin)
                        {
                            server.SendOrderTo(conn, "Message", "Only the host can kick players.");
                            return true;
                        }

                        var split = s.Split(' ');
                        if (split.Length < 2)
                        {
                            server.SendOrderTo(conn, "Message", "Malformed kick command");
                            return true;
                        }

                        int kickClientID;
                        Exts.TryParseIntegerInvariant(split[0], out kickClientID);

                        var kickConn = server.Conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == kickClientID);
                        if (kickConn == null)
                        {
                            server.SendOrderTo(conn, "Message", "No-one in that slot.");
                            return true;
                        }

                        var kickClient = server.GetClient(kickConn);

                        Log.Write("server", "Kicking client {0}.", kickClientID);
                        server.SendMessage("{0} kicked {1} from the server.".F(client.Name, kickClient.Name));
                        server.SendOrderTo(kickConn, "ServerError", "You have been kicked from the server.");
                        server.DropClient(kickConn);

                        bool tempBan;
                        bool.TryParse(split[1], out tempBan);

                        if (tempBan)
                        {
                            Log.Write("server", "Temporarily banning client {0} ({1}).", kickClientID, kickClient.IpAddress);
                            server.SendMessage("{0} temporarily banned {1} from the server.".F(client.Name, kickClient.Name));
                            server.TempBans.Add(kickClient.IpAddress);
                        }

                        server.SyncLobbyClients();
                        server.SyncLobbySlots();

                        return true;
                    }
                },
                { "name",
                    s =>
                    {
开发者ID:CH4Code,项目名称:OpenRA,代码行数:67,代码来源:LobbyCommands.cs

示例5: InterpretCommand


//.........这里部分代码省略.........
                            server.SendOrderTo(conn, "Message", "Only the host can set that option");
                            return true;
                        }

                        if (server.Map.Options.StartingCash.HasValue)
                        {
                            server.SendOrderTo(conn, "Message", "Map has disabled cash configuration");
                            return true;
                        }

                        server.lobbyInfo.GlobalSettings.StartingCash = int.Parse(s);
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "kick",
                    s =>
                    {
                        if (!client.IsAdmin)
                        {
                            server.SendOrderTo(conn, "Message", "Only the host can kick players");
                            return true;
                        }

                        var split = s.Split(' ');
                        if (split.Length < 2)
                        {
                            server.SendOrderTo(conn, "Message", "Malformed kick command");
                            return true;
                        }

                        int kickClientID;
                        int.TryParse(split[0], out kickClientID);

                        var kickConn = server.conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == kickClientID);
                        if (kickConn == null)
                        {
                            server.SendOrderTo(conn, "Message", "Noone in that slot.");
                            return true;
                        }

                        var kickConnIP = server.GetClient(kickConn).IpAddress;

                        Log.Write("server", "Kicking client {0} as requested", kickClientID);
                        server.SendOrderTo(kickConn, "ServerError", "You have been kicked from the server");
                        server.DropClient(kickConn);

                        bool tempBan;
                        bool.TryParse(split[1], out tempBan);

                        if (tempBan)
                        {
                            Log.Write("server", "Temporarily banning client {0} ({1}) as requested", kickClientID, kickConnIP);
                            server.TempBans.Add(kickConnIP);
                        }

                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "name",
                    s =>
                    {
                        Log.Write("server", "[email protected]{0} is now known as {1}", conn.socket.RemoteEndPoint, s);
                        client.Name = s;
                        server.SyncLobbyInfo();
                        return true;
                    }},
开发者ID:TiriliPiitPiit,项目名称:OpenRA,代码行数:67,代码来源:LobbyCommands.cs

示例6: InterpretCommand

        public bool InterpretCommand(S server, Connection conn, Session.Client client, string cmd)
        {
            if (!ValidateCommand(server, conn, client, cmd))
                return false;

            var dict = new Dictionary<string, Func<string, bool>>
            {
                { "ready",
                    s =>
                    {
                        // if we're downloading, we can't ready up.
                        if (client.State == Session.ClientState.NotReady)
                            client.State = Session.ClientState.Ready;
                        else if (client.State == Session.ClientState.Ready)
                            client.State = Session.ClientState.NotReady;

                        Log.Write("server", "Player @{0} is {1}",
                            conn.socket.RemoteEndPoint, client.State);

                        server.SyncLobbyInfo();

                        if (server.conns.Count > 0 && server.conns.All(c => server.GetClient(c).State == Session.ClientState.Ready))
                            InterpretCommand(server, conn, client, "startgame");

                        return true;
                    }},
                { "startgame",
                    s =>
                    {
                        server.StartGame();
                        return true;
                    }},
                { "lag",
                    s =>
                    {
                        int lag;
                        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);

                        server.lobbyInfo.GlobalSettings.OrderLatency = lag;
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "slot",
                    s =>
                    {
                        if (!server.lobbyInfo.Slots.ContainsKey(s))
                        {
                            Log.Write("server", "Invalid slot: {0}", s );
                            return false;
                        }
                        var slot = server.lobbyInfo.Slots[s];

                        if (slot.Closed || server.lobbyInfo.ClientInSlot(s) != null)
                            return false;

                        client.Slot = s;
                        S.SyncClientToPlayerReference(client, server.Map.Players[s]);

                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "spectate",
                    s =>
                    {
                        client.Slot = null;
                        client.SpawnPoint = 0;
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "slot_close",
                    s =>
                    {
                        if (!ValidateSlotCommand( server, conn, client, s, true ))
                            return false;

                        // kick any player that's in the slot
                        var occupant = server.lobbyInfo.ClientInSlot(s);
                        if (occupant != null)
                        {
                            if (occupant.Bot != null)
                                server.lobbyInfo.Clients.Remove(occupant);
                            else
                            {
                                var occupantConn = server.conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index );
                                if (occupantConn != null)
                                {
                                    server.SendOrderTo(occupantConn, "ServerError", "Your slot was closed by the host");
                                    server.DropClient(occupantConn);
                                }
                            }
                        }

                        server.lobbyInfo.Slots[s].Closed = true;
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "slot_open",
                    s =>
//.........这里部分代码省略.........
开发者ID:romainhk,项目名称:OpenRA,代码行数:101,代码来源:LobbyCommands.cs

示例7: ClientJoined

        public void ClientJoined(S server, Connection conn)
        {
            var client = server.GetClient(conn);

            // Validate whether color is allowed and get an alternative if it isn't
            if (client.Slot == null || !server.LobbyInfo.Slots[client.Slot].LockColor)
                client.Color = SanitizePlayerColor(server, client.Color, client.Index);

            // Report any custom map details
            // HACK: this isn't the best place for this to live, but if we move it somewhere else
            // then we need a larger hack to hook the map change event.
            var briefing = MissionBriefingOrDefault(server);
            if (briefing != null)
                server.SendOrderTo(conn, "Message", briefing);
        }
开发者ID:OpenRA,项目名称:OpenRA,代码行数:15,代码来源:LobbyCommands.cs

示例8: CheckAutoStart

        void CheckAutoStart(S server, Connection conn, Session.Client client)
        {
            var actualPlayers = server.conns
                .Select(c => server.GetClient(c))
                .Where(c => c.Slot != null);

            if (actualPlayers.Count() > 0 && actualPlayers.All(c => c.State == Session.ClientState.Ready))
                InterpretCommand(server, conn, client, "startgame");
        }
开发者ID:nevelis,项目名称:OpenRA,代码行数:9,代码来源:LobbyCommands.cs

示例9: InterpretCommand


//.........这里部分代码省略.........
							return true;
						}

						server.LobbyInfo.GlobalSettings.GameSpeedType = s;
						server.LobbyInfo.GlobalSettings.Timestep = speed.Timestep;
						server.LobbyInfo.GlobalSettings.OrderLatency =
							server.LobbyInfo.IsSinglePlayer ? 1 : speed.OrderLatency;

						server.SyncLobbyInfo();
						server.SendMessage("{0} changed Game Speed to {1}.".F(client.Name, speed.Name));

						return true;
					}
				},
				{ "kick",
					s =>
					{
						if (!client.IsAdmin)
						{
							server.SendOrderTo(conn, "Message", "Only the host can kick players.");
							return true;
						}

						var split = s.Split(' ');
						if (split.Length < 2)
						{
							server.SendOrderTo(conn, "Message", "Malformed kick command");
							return true;
						}

						int kickClientID;
						Exts.TryParseIntegerInvariant(split[0], out kickClientID);

						var kickConn = server.Conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == kickClientID);
						if (kickConn == null)
						{
							server.SendOrderTo(conn, "Message", "Noone in that slot.");
							return true;
						}

						var kickClient = server.GetClient(kickConn);

						Log.Write("server", "Kicking client {0}.", kickClientID);
						server.SendMessage("{0} kicked {1} from the server.".F(client.Name, kickClient.Name));
						server.SendOrderTo(kickConn, "ServerError", "You have been kicked from the server.");
						server.DropClient(kickConn);

						bool tempBan;
						bool.TryParse(split[1], out tempBan);

						if (tempBan)
						{
							Log.Write("server", "Temporarily banning client {0} ({1}).", kickClientID, kickClient.IpAddress);
							server.SendMessage("{0} temporarily banned {1} from the server.".F(client.Name, kickClient.Name));
							server.TempBans.Add(kickClient.IpAddress);
						}

						server.SyncLobbyClients();
						server.SyncLobbySlots();

						return true;
					}
				},
				{ "name",
					s =>
					{
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:67,代码来源:LobbyCommands.cs

示例10: Tick

		public void Tick(S server)
		{
			if ((Game.RunTime - lastPing > PingInterval) || isInitialPing)
			{
				isInitialPing = false;
				lastPing = Game.RunTime;

				// Ignore client timeout in singleplayer games to make debugging easier
				if (server.LobbyInfo.IsSinglePlayer && !server.Settings.Dedicated)
					foreach (var c in server.Conns.ToList())
						server.SendOrderTo(c, "Ping", Game.RunTime.ToString());
				else
				{
					foreach (var c in server.Conns.ToList())
					{
						if (c == null || c.Socket == null)
							continue;

						var client = server.GetClient(c);
						if (client == null)
						{
							server.DropClient(c, -1);
							server.SendMessage("A player has been dropped after timing out.");
							continue;
						}

						if (c.TimeSinceLastResponse < ConnTimeout)
						{
							server.SendOrderTo(c, "Ping", Game.RunTime.ToString());
							if (!c.TimeoutMessageShown && c.TimeSinceLastResponse > PingInterval * 2)
							{
								server.SendMessage(client.Name + " is experiencing connection problems.");
								c.TimeoutMessageShown = true;
							}
						}
						else
						{
							server.SendMessage(client.Name + " has been dropped after timing out.");
							server.DropClient(c, -1);
						}
					}

					if (Game.RunTime - lastConnReport > ConnReportInterval)
					{
						lastConnReport = Game.RunTime;

						var timeouts = server.Conns
							.Where(c => c.TimeSinceLastResponse > ConnReportInterval && c.TimeSinceLastResponse < ConnTimeout)
							.OrderBy(c => c.TimeSinceLastResponse);

						foreach (var c in timeouts)
						{
							if (c == null || c.Socket == null)
								continue;

							var client = server.GetClient(c);
							if (client != null)
								server.SendMessage("{0} will be dropped in {1} seconds.".F(client.Name, (ConnTimeout - c.TimeSinceLastResponse) / 1000));
						}
					}
				}
			}
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:63,代码来源:PlayerPinger.cs


注:本文中的OpenRA.Server.Server.GetClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。