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


C# Server.StartGame方法代码示例

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


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

示例1: CheckAutoStart

		static void CheckAutoStart(S server)
		{
			var playerClients = server.LobbyInfo.Clients.Where(c => c.Bot == null && c.Slot != null);

			// Are all players ready?
			if (!playerClients.Any() || playerClients.Any(c => c.State != Session.ClientState.Ready))
				return;

			// Are the map conditions satisfied?
			if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null))
				return;

			server.StartGame();
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:14,代码来源:LobbyCommands.cs

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

示例3: InterpretCommand

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

            var dict = new Dictionary<string, Func<string, bool>>
            {
                { "state",
                    s =>
                    {
                        var state = Session.ClientState.Invalid;
                        if (!Enum<Session.ClientState>.TryParse(s, false, out state))
                        {
                            server.SendOrderTo(conn, "Message", "Malformed state command");
                            return true;
                        }

                        client.State = state;

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

                        server.SyncLobbyClients();

                        CheckAutoStart(server);

                        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;
                        }

                        if (server.Settings.DisableSinglePlayer &&
                            server.LobbyInfo.Clients.Where(c => c.Bot == null && c.Slot != null).Count() == 1)
                        {
                            server.SendOrderTo(conn, "Message", "Unable to start the game until another player joins.");
                            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;

                        // If the previous slot had a locked spawn then we must not carry that to the new slot
                        var oldSlot = client.Slot != null ? server.LobbyInfo.Slots[client.Slot] : null;
                        if (oldSlot != null && oldSlot.LockSpawn)
                            client.SpawnPoint = 0;

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

                        if (!slot.LockColor)
                            client.PreferredColor = client.Color = SanitizePlayerColor(server, client.Color, client.Index, conn);

                        server.SyncLobbyClients();
                        CheckAutoStart(server);

                        return true;
                    }
                },
                { "allow_spectators",
                    s =>
                    {
                        if (bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowSpectators))
                        {
                            server.SyncLobbyGlobalSettings();
                            return true;
                        }
                        else
                        {
                            server.SendOrderTo(conn, "Message", "Malformed allow_spectate command");
                            return true;
                        }
//.........这里部分代码省略.........
开发者ID:CH4Code,项目名称:OpenRA,代码行数:101,代码来源:LobbyCommands.cs

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

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

示例6: CheckAutoStart

        static void CheckAutoStart(S server)
        {
            // A spectating admin is included for checking these rules
            var playerClients = server.LobbyInfo.Clients.Where(c => (c.Bot == null && c.Slot != null) || c.IsAdmin);

            // Are all players ready?
            if (!playerClients.Any() || playerClients.Any(c => c.State != Session.ClientState.Ready))
                return;

            // Are the map conditions satisfied?
            if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null))
                return;

            // Does server have only one player?
            if (!server.LobbyInfo.GlobalSettings.EnableSingleplayer && playerClients.Count() == 1)
                return;

            server.StartGame();
        }
开发者ID:OpenRA,项目名称:OpenRA,代码行数:19,代码来源:LobbyCommands.cs

示例7: InterpretCommand

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

			var dict = new Dictionary<string, Func<string, bool>>
			{
				{ "state",
					s =>
					{
						var state = Session.ClientState.Invalid;
						if (!Enum<Session.ClientState>.TryParse(s, false, out state))
						{
							server.SendOrderTo(conn, "Message", "Malformed state command");
							return true;
						}

						client.State = state;

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

						server.SyncLobbyClients();

						CheckAutoStart(server);

						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.MapPlayers.Players[s]);

						var validatedColor = ColorValidator.ValidatePlayerColorAndGetAlternative(server, client.Color, client.Index, conn);
						client.PreferredColor = client.Color = validatedColor;

						server.SyncLobbyClients();
						CheckAutoStart(server);

						return true;
					}
				},
				{ "allow_spectators",
					s =>
					{
						if (bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowSpectators))
						{
							server.SyncLobbyGlobalSettings();
							return true;
						}
						else
						{
							server.SendOrderTo(conn, "Message", "Malformed allow_spectate command");
							return true;
						}
					}
				},
				{ "spectate",
					s =>
					{
						if (server.LobbyInfo.GlobalSettings.AllowSpectators || client.IsAdmin)
						{
							client.Slot = null;
							client.SpawnPoint = 0;
							client.Color = HSLColor.FromRGB(255, 255, 255);
							server.SyncLobbyClients();
							return true;
//.........这里部分代码省略.........
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:101,代码来源:LobbyCommands.cs


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