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


C# Server.SendChatTo方法代码示例

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


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

示例1: ValidateCommand

        public static bool ValidateCommand(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;
            }

            return true;
        }
开发者ID:romainhk,项目名称:OpenRA,代码行数:15,代码来源: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>>
            {
                { "name",
                    s =>
                    {
                        Log.Write("server", "[email protected]{0} is now known as {1}", conn.socket.RemoteEndPoint, s);
                        client.Name = s;
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "race",
                    s =>
                    {
                        client.Country = s;
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "team",
                    s =>
                    {
                        int team;
                        if (!int.TryParse(s, out team)) { Log.Write("server", "Invalid team: {0}", s ); return false; }

                        client.Team = team;
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "spawn",
                    s =>
                    {
                        int spawnPoint;
                        if (!int.TryParse(s, out spawnPoint) || spawnPoint < 0 || spawnPoint > server.Map.SpawnPoints.Count())
                        {
                            Log.Write("server", "Invalid spawn point: {0}", s);
                            return false;
                        }

                        if (server.lobbyInfo.Slots[client.Slot].Spectator)
                        {
                            server.SendChatTo( conn, "Can't select a spawnpoint as a spectator" );
                            return false;
                        }

                        if (server.lobbyInfo.Clients.Where( c => c != client ).Any( c => (c.SpawnPoint == spawnPoint) && (c.SpawnPoint != 0) ))
                        {
                            server.SendChatTo( conn, "You can't be at the same spawn point as another player" );
                            return true;
                        }

                        client.SpawnPoint = spawnPoint;
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "color",
                    s =>
                    {
                        var c = s.Split(',').Select(cc => int.Parse(cc)).ToArray();
                        client.ColorRamp = new ColorRamp((byte)c[0], (byte)c[1], (byte)c[2], (byte)c[3]);
                        server.SyncLobbyInfo();
                        return true;
                    }}
            };

            var cmdName = cmd.Split(' ').First();
            var cmdValue = string.Join(" ", cmd.Split(' ').Skip(1).ToArray());

            Func<string,bool> a;
            if (!dict.TryGetValue(cmdName, out a))
                return false;

            return a(cmdValue);
        }
开发者ID:katzsmile,项目名称:OpenRA,代码行数:85,代码来源:PlayerCommands.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: 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.SendChatTo( conn, "Only the host can do that" );
                return false;
            }

            return true;
        }
开发者ID:romainhk,项目名称:OpenRA,代码行数:16,代码来源:LobbyCommands.cs

示例5: InterpretCommand


//.........这里部分代码省略.........
                                    server.DropClient(occupantConn);
                                }
                            }
                        }

                        server.lobbyInfo.Slots[s].Closed = true;
                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "slot_open",
                    s =>
                    {
                        if (!ValidateSlotCommand( server, conn, client, s, true ))
                            return false;

                        var slot = server.lobbyInfo.Slots[s];
                        slot.Closed = false;

                        // Slot may have a bot in it
                        var occupant = server.lobbyInfo.ClientInSlot(s);
                        if (occupant != null && occupant.Bot != null)
                            server.lobbyInfo.Clients.Remove(occupant);

                        server.SyncLobbyInfo();
                        return true;
                    }},
                { "slot_bot",
                    s =>
                    {
                        var parts = s.Split(' ');

                        if (parts.Length < 2)
                        {
                            server.SendChatTo( conn, "Malformed slot_bot command" );
                            return true;
                        }

                        if (!ValidateSlotCommand( server, conn, client, parts[0], true ))
                            return false;

                        var slot = server.lobbyInfo.Slots[parts[0]];
                        var bot = server.lobbyInfo.ClientInSlot(parts[0]);
                        var botType = parts.Skip(1).JoinWith(" ");

                        // Invalid slot
                        if (bot != null && bot.Bot == null)
                        {
                            server.SendChatTo( conn, "Can't add bots to a slot with another client" );
                            return true;
                        }

                        slot.Closed = false;
                        if (bot == null)
                        {
                            // Create a new bot
                            bot = new Session.Client()
                            {
                                Index = server.ChooseFreePlayerIndex(),
                                Name = botType,
                                Bot = botType,
                                Slot = parts[0],
                                Country = "random",
                                SpawnPoint = 0,
                                Team = 0,
                                State = Session.ClientState.NotReady
                            };
开发者ID:romainhk,项目名称:OpenRA,代码行数:67,代码来源:LobbyCommands.cs


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