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


C# Server.DropClient方法代码示例

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


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

示例1: ReadData

        public void ReadData(Server server)
        {
            if (ReadDataInner(server))
                while (data.Count >= ExpectLength)
                {
                    var bytes = PopBytes(ExpectLength);
                    switch (State)
                    {
                        case ReceiveState.Header:
                            {
                                ExpectLength = BitConverter.ToInt32(bytes, 0) - 4;
                                Frame = BitConverter.ToInt32(bytes, 4);
                                State = ReceiveState.Data;

                                if (ExpectLength < 0 || ExpectLength > MaxOrderLength)
                                {
                                    server.DropClient(this);
                                    Log.Write("server", "Dropping client {0} for excessive order length = {1}", PlayerIndex, ExpectLength);
                                    return;
                                }
                            } break;

                        case ReceiveState.Data:
                            {
                                server.DispatchOrders(this, Frame, bytes);
                                MostRecentFrame = Frame;
                                ExpectLength = 8;
                                State = ReceiveState.Header;

                            } break;
                    }
                }
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:33,代码来源:Connection.cs

示例2: ReadDataInner

		bool ReadDataInner(Server server)
		{
			var rx = new byte[1024];
			var len = 0;

			for (;;)
			{
				try
				{
					// NOTE(jsd): Poll the socket first to see if there's anything there.
					// This avoids the exception with SocketErrorCode == `SocketError.WouldBlock` thrown
					// from `socket.Receive(rx)`.
					if (!Socket.Poll(0, SelectMode.SelectRead)) break;

					if (0 < (len = Socket.Receive(rx)))
						Data.AddRange(rx.Take(len));
					else
					{
						if (len == 0)
							server.DropClient(this);
						break;
					}
				}
				catch (SocketException e)
				{
					// NOTE(jsd): This should no longer be needed with the socket.Poll call above.
					if (e.SocketErrorCode == SocketError.WouldBlock) break;

					server.DropClient(this);
					Log.Write("server", "Dropping client {0} because reading the data failed: {1}", PlayerIndex, e);
					return false;
				}
			}

			lastReceivedTime = Game.RunTime;
			TimeoutMessageShown = false;

			return true;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:39,代码来源:Connection.cs

示例3: 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

示例4: InterpretCommand


//.........这里部分代码省略.........
                            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;

                        /* kick any player that's in the slot */
                        var occupant = server.lobbyInfo.Clients.FirstOrDefault( c => c.Slot == slotData.Index );
                        if (occupant != null)
                        {
                            var occupantConn = server.conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index );
                            if (occupantConn != null)
                                server.DropClient( occupantConn, new Exception() );
                        }

                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "slot_open",
                    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 = false;
                        slotData.Bot = null;

                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "slot_bot",
                    s =>
                    {
                        var parts = s.Split(' ');
开发者ID:geckosoft,项目名称:OpenRA,代码行数:66,代码来源:LobbyCommands.cs

示例5: InterpretCommand


//.........这里部分代码省略.........
                            return true;
                        }
                        else
                            return false;
                    }
                },
                { "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);
                                server.SyncLobbyClients();
                                var ping = server.LobbyInfo.PingFromClient(occupant);
                                if (ping != null)
                                {
                                    server.LobbyInfo.ClientPings.Remove(ping);
                                    server.SyncClientPing();
                                }
                            }
                            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.SyncLobbySlots();
                        return true;
                    }
                },
                { "slot_open",
                    s =>
                    {
                        if (!ValidateSlotCommand(server, conn, client, s, true))
                            return false;

                        var slot = server.LobbyInfo.Slots[s];
                        slot.Closed = false;
                        server.SyncLobbySlots();

                        // Slot may have a bot in it
                        var occupant = server.LobbyInfo.ClientInSlot(s);
                        if (occupant != null && occupant.Bot != null)
                        {
                            server.LobbyInfo.Clients.Remove(occupant);
                            var ping = server.LobbyInfo.PingFromClient(occupant);
                            if (ping != null)
                            {
                                server.LobbyInfo.ClientPings.Remove(ping);
                                server.SyncClientPing();
                            }
                        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:66,代码来源: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();

                        CheckAutoStart(server, conn, client);

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

                        if (server.lobbyInfo.Slots.Any(sl => sl.Value.Required &&
                            server.lobbyInfo.ClientInSlot(sl.Key) == null))
                        {
                            server.SendOrderTo(conn, "Message", "Unable to start the game until required slots are full.");
                            return true;
                        }
                        server.StartGame();
                        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();
                        CheckAutoStart(server, conn, client);

                        return true;
                    }},
                { "spectate",
                    s =>
                    {
                        client.Slot = null;
                        client.SpawnPoint = 0;
                        client.Color = HSLColor.FromRGB(255, 255, 255);
                        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;
                    }},
//.........这里部分代码省略.........
开发者ID:TiriliPiitPiit,项目名称:OpenRA,代码行数:101,代码来源:LobbyCommands.cs

示例7: 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

示例8: InterpretCommand


//.........这里部分代码省略.........
							return true;
						}
						else
							return false;
					}
				},
				{ "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);
								server.SyncLobbyClients();
								var ping = server.LobbyInfo.PingFromClient(occupant);
								if (ping != null)
								{
									server.LobbyInfo.ClientPings.Remove(ping);
									server.SyncClientPing();
								}
							}
							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.SyncLobbySlots();
						return true;
					}
				},
				{ "slot_open",
					s =>
					{
						if (!ValidateSlotCommand(server, conn, client, s, true))
							return false;

						var slot = server.LobbyInfo.Slots[s];
						slot.Closed = false;
						server.SyncLobbySlots();

						// Slot may have a bot in it
						var occupant = server.LobbyInfo.ClientInSlot(s);
						if (occupant != null && occupant.Bot != null)
						{
							server.LobbyInfo.Clients.Remove(occupant);
							var ping = server.LobbyInfo.PingFromClient(occupant);
							if (ping != null)
							{
								server.LobbyInfo.ClientPings.Remove(ping);
								server.SyncClientPing();
							}
						}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:66,代码来源:LobbyCommands.cs

示例9: 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

示例10: ReadDataInner

        bool ReadDataInner( Server server )
        {
            var rx = new byte[1024];
            var len = 0;

            for (; ; )
            {
                try
                {
                    if (0 < (len = socket.Receive(rx)))
                        data.AddRange(rx.Take(len));
                    else
                    {
                        if (len == 0)
                            server.DropClient(this);
                        break;
                    }

                }
                catch (SocketException e)
                {
                    if (e.SocketErrorCode == SocketError.WouldBlock) break;
                    server.DropClient(this);
                    return false;
                }
            }

            return true;
        }
开发者ID:sonygod,项目名称:OpenRA-Dedicated-20120504,代码行数:29,代码来源:Connection.cs

示例11: ReadDataInner

        bool ReadDataInner( Server server )
        {
            var rx = new byte[1024];
            var len = 0;

            for (; ; )
            {
                try
                {
                    // NOTE(jsd): Poll the socket first to see if there's anything there.
                    // This avoids the exception with SocketErrorCode == `SocketError.WouldBlock` thrown
                    // from `socket.Receive(rx)`.
                    if (!socket.Poll(0, SelectMode.SelectRead)) break;

                    if (0 < (len = socket.Receive(rx)))
                        data.AddRange(rx.Take(len));
                    else
                    {
                        if (len == 0)
                            server.DropClient(this);
                        break;
                    }
                }
                catch (SocketException e)
                {
                    // NOTE(jsd): This should no longer be needed with the socket.Poll call above.
                    if (e.SocketErrorCode == SocketError.WouldBlock) break;

                    server.DropClient(this);
                    return false;
                }
            }

            return true;
        }
开发者ID:Tsher,项目名称:OpenRA,代码行数:35,代码来源:Connection.cs


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