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


C# IClient.GetServer方法代码示例

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


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

示例1: Use

        public void Use(IClient client, string commandName, string[] tokens)
        {
            if (tokens.Length < 2)
            {
                Help(client);
                return;
            }
            
            try
            {
                client.GetServer().GetBanSystem().AddToBanList(tokens[0], tokens[1], tokens.Length > 2 ? tokens : null);
            }
            catch (FormatException ex)
            {
                client.SendMessage(ex.Message);
                return;
            }

            foreach (var nClient in client.GetServer().GetClients(tokens[0]).ToList())
            {
                nClient.Kick(tokens[1]);
            }

            client.SendMessage(string.Format("{0} has been banned", tokens[0]));
        }
开发者ID:TheaP,项目名称:c-raft,代码行数:25,代码来源:CmdBan.cs

示例2: Use

        public void Use(IClient client, string commandName, string[] tokens)
        {
            if (tokens.Length < 1)
            {
                Help(client);
                return;
            }

            var toKick = client.GetServer().GetClients();


            if (toKick.Any() && tokens[0].ToLower() != "all")
            {
                foreach (var client1 in toKick.Where(client1 => !client1.GetOwner().CanUseCommand("chraft.kick.exempt")))
                {
                    client1.Kick(tokens.Length > 1 ? tokens[1] : "Kicked");
                    client.SendMessage("Kicked " + client1.GetOwner().Name);
                }
            }
            else
            {
                foreach (IClient t in toKick.Where(t => t.GetOwner().Name.ToLower() == tokens[0].ToLower()).Where(t => !t.GetOwner().CanUseCommand("chraft.kick.exempt")))
                {
                    t.Kick(tokens.Length > 1 ? tokens[1] : "Kicked");
                    client.SendMessage("Kicked " + t.GetOwner().Name);
                }
            }
        }
开发者ID:TheaP,项目名称:c-raft,代码行数:28,代码来源:CmdKick.cs

示例3: Use

 public void Use(IClient client, string commandName, string[] tokens)
 {
     if (tokens.Length < 1)
     {
         Help(client);
         return;
     }
     client.GetServer().GetBanSystem().RemoveFromBanList(tokens[0]);
     client.SendMessage(string.Format("{0} has been unbanned", tokens[0]));
 }
开发者ID:TheaP,项目名称:c-raft,代码行数:10,代码来源:CmdUnban.cs

示例4: GetPlayers

        public static string GetPlayers(IClient client, string pattern)
        {
            var parts = pattern.Split(' ');
            if (parts.Length > 1)
                pattern = parts[parts.Length - 1];
            var s = (from a in client.GetServer().GetClients() where a.Username.StartsWith(pattern, StringComparison.OrdinalIgnoreCase) select a).ToList();

            if (!s.Any())
                return string.Empty;
            var sb = new System.Text.StringBuilder();

            if (s.Count() > 1)
            {
                foreach (var c in s)
                    sb.Append(c.Username).Append('\0');
            }
            else
            {
                sb.Append(s[0].Username);
            }
            return sb.ToString();
        }
开发者ID:TheaP,项目名称:c-raft,代码行数:22,代码来源:AutoComplete.cs

示例5: Use

        public void Use(IClient client, string commandName, string[] tokens)
        {
            if (tokens.Length < 1)
            {
                Help(client);
                return;
            }

            switch (tokens[0].ToLower())
            {
                
                case "on":
                    ChraftConfig.SetWhitelist(true);
                    foreach (var cl in client.GetServer().GetClients())
                    {
                        if( !cl.GetOwner().CanUseCommand("chraft.whitelist.exempt") &&
                            client.GetServer().GetBanSystem().IsOnWhiteList(cl.GetOwner().Name))
                        {
                            cl.Kick(ChraftConfig.WhiteListMesasge);
                        }
                    }
                    client.SendMessage("Whitelist enabled");
                    break;
                case "off":
                    ChraftConfig.SetWhitelist(false);
                    client.SendMessage("Whitelist disabled");
                    break;
                case "add":
                    if (tokens.Length < 2)
                    {
                        Help(client);
                        return;
                    }
                    client.GetServer().GetBanSystem().AddToWhiteList(tokens[1]);
                    client.SendMessage(tokens[1] + " added to Whitelist");
                    break;
                case "remove":
                    if (tokens.Length < 2)
                    {
                        Help(client);
                        return;
                    }
                    client.GetServer().GetBanSystem().RemoveFromWhiteList(tokens[1]);
                    client.SendMessage(tokens[1] + " removed from Whitelist");
                    break;
                case "list":
                    foreach (var play in client.GetServer().GetBanSystem().ListWhiteList())
                    {
                        client.SendMessage(play);
                    }
                    break;
                case "message":
                    if (tokens.Length < 2)
                    {
                        Help(client);
                        return;
                    }
                    ChraftConfig.SetWhitelistMessage(tokens[1]);
                    client.SendMessage("Whitelist message set");
                    break;

            }
        }
开发者ID:TheaP,项目名称:c-raft,代码行数:63,代码来源:CmdWhitelist.cs

示例6: Use

        public void Use(IClient client, string commandName, string[] tokens)
        {
            if (tokens.Length < 1)
            {
                client.SendMessage("You must specify a player to mute");
                return;
            }

            IClient[] matchedClients = client.GetServer().GetClients(tokens[0]).ToArray();
            IClient clientToMute = null;
            if (matchedClients.Length < 1)
            {
                client.SendMessage("Unknown Player");
                return;
            }
            else if (matchedClients.Length == 1)
            {
                clientToMute = matchedClients[0];
            }
            else if (matchedClients.Length > 1)
            {
                // We've got more than 1 client. I.e. "Test" and "Test123" for the "test" pattern.
                // Looking for exact name match.
                int exactMatchClient = -1;
                for (int i = 0; i < matchedClients.Length; i++)
                {
                    if (matchedClients[i].GetOwner().DisplayName.ToLower() == tokens[0].ToLower())
                        exactMatchClient = i;
                }

                // If we found the player with the exactly same name - he is our target
                if (exactMatchClient != -1)
                {
                    clientToMute = matchedClients[exactMatchClient];
                } else
                {
                    // We do not found a proper target and aren't going to randomly punish anyone
                    client.SendMessage("More than one player found. Provide the exact name.");
                    return;
                }
            }
            bool clientMuted = clientToMute.GetOwner().IsMuted;
            clientToMute.GetOwner().IsMuted = !clientMuted;
            clientToMute.SendMessage(clientMuted ? "You have been unmuted" : "You have been muted");
            client.SendMessage(clientMuted ? clientToMute.GetOwner().DisplayName + " has been unmuted" : clientToMute.GetOwner().DisplayName + " has been muted");
        }
开发者ID:Nirad,项目名称:c-raft,代码行数:46,代码来源:CmdMute.cs

示例7: Use

        public void Use(IClient client, string commandName, string[] tokens)
        {
            MobType type = MobType.Sheep;
            int amount = 1;
            bool validMob = false;

            if (tokens.Length > 1)
                Int32.TryParse(tokens[1], out amount);

            if (tokens.Length > 0)
            {
                int mobId;
                Int32.TryParse(tokens[0], out mobId);
                string mobName = Enum.GetName(typeof(MobType), mobId);
                if (mobId == 0)
                {
                    if (mobId.ToString() != tokens[0])
                    {
                        Enum.TryParse(tokens[0], true, out type);
                        validMob = true;
                    }
                }
                else if (!string.IsNullOrEmpty(mobName))
                {
                    type = (MobType)Enum.Parse(typeof(MobType), mobName);
                    validMob = true;
                }
            }
            else
                validMob = true;

            if (amount < 1 || !validMob)
            {
                Help(client);
                return;
            }

            IServer server = client.GetServer();
            AbsWorldCoords position = client.GetOwner().Position;
            IMobFactory mobFactory = server.GetMobFactory();
            for (int i = 0; i < amount; i++)
            {
                var mob = mobFactory.CreateMob(client.GetOwner().GetWorld(), server, type, null);
                mob.Position = position;

                //Event
                EntitySpawnEventArgs e = new EntitySpawnEventArgs(mob, mob.Position);
                server.GetPluginManager().CallEvent(Event.EntitySpawn, e);
                if (e.EventCanceled)
                    continue;
                mob.Position = e.Location;
                //End Event

                server.AddEntity(mob);
            }
        }
开发者ID:chraft,项目名称:c-raft-plugins,代码行数:56,代码来源:CmdSpawnMob.cs

示例8: Place

        protected void Place(IClient client, string[] tokens)
        {
            string schematicName = tokens[1];
            Schematic schematic = new Schematic(schematicName);

            bool loaded;
            try
            {
                loaded = schematic.LoadFromFile();
            }
            catch (FileNotFoundException)
            {
                client.SendMessage(string.Format("Schematic file is not found: {0}", schematicName));
                return;
            }
            catch (Exception ex)
            {
                loaded = false;
                var sb = new StringBuilder();
                sb.Append("Schematics: error has occured while loading schematic file ");
                sb.Append(schematicName);
                sb.Append(Environment.NewLine);
                sb.Append(ex.ToString());
                client.GetServer().GetLogger().Log(LogLevel.Warning, sb.ToString());
            }

            if (!loaded)
            {
                client.SendMessage("Can not load schematic file");
                return;
            }

            bool rotateByX = false;
            bool rotateByZ = false;
            bool rotateByXZ = false;

            if (tokens.Length >= 3)
            {
                string rotation = tokens[2].Trim().ToLower();
                if (rotation == "x")
                    rotateByX = true;
                else if (rotation == "z")
                    rotateByZ = true;
                else if (rotation == "xz")
                    rotateByXZ = true;
            }

            UniversalCoords coords = UniversalCoords.FromAbsWorld(client.GetOwner().Position);
            int width = ((rotateByX || rotateByXZ) ? -1 * schematic.Width : schematic.Width);
            int length = ((rotateByZ || rotateByXZ) ? -1 * schematic.Length : schematic.Length);

            if (!RequiredChunksExist(client.GetOwner().GetWorld(), coords, width, schematic.Height, length))
            {
                client.SendMessage("The schematic is too big - required chunks are not loaded/created yet");
                return;
            }

            int blockAmount = schematic.Width * schematic.Height * schematic.Length;
            byte[] blockIds = new byte[blockAmount];
            byte[] blockMetas = new byte[blockAmount];
            UniversalCoords blockCoords;
            IChunk chunk;
            int index;

            for (int dx = 0; dx < schematic.Width; dx++)
                for (int dy = 0; dy < schematic.Height; dy++)
                    for (int dz = 0; dz < schematic.Length; dz++)
                    {
                        int x = coords.WorldX + ((rotateByX || rotateByXZ) ? -dx : dx);
                        int y = coords.WorldY + dy;
                        int z = coords.WorldZ + ((rotateByZ || rotateByXZ) ? -dz : dz);
                        blockCoords = UniversalCoords.FromWorld(x, y, z);
                        chunk = client.GetOwner().GetWorld().GetChunk(blockCoords, false, false);
                        if (chunk == null)
                            continue;
                        index = schematic.ToIndex(dx, dy, dz);
                        blockIds[index] = (byte)chunk.GetType(blockCoords);
                        blockMetas[index] = chunk.GetData(blockCoords);
                        chunk.SetBlockAndData(blockCoords, schematic.BlockIds[index], schematic.BlockMetas[index]);
                    }

            SchematicAction action;
            if (_plugin.Actions.ContainsKey(client.Username))
                _plugin.Actions.TryRemove(client.Username, out action);

            action = new SchematicAction
                         {
                             StartingPoint = coords,
                             BlockIds = blockIds,
                             BlockMetas = blockMetas,
                             RotateByX = rotateByX,
                             RotateByZ = rotateByZ,
                             RotateByXZ = rotateByXZ,
                             Width = schematic.Width,
                             Height = schematic.Height,
                             Length = schematic.Length
                         };
            _plugin.Actions.TryAdd(client.Username, action);
            client.SendMessage(string.Format("Schematic {0} ({1} blocks) has been placed", schematic.SchematicName, blockAmount));
        }
开发者ID:chraft,项目名称:c-raft-plugins,代码行数:100,代码来源:CmdSchematic.cs

示例9: Info

        protected void Info(IClient client, string schematicName)
        {
            Schematic schematic = new Schematic(schematicName);

            bool loaded;
            try
            {
                loaded = schematic.LoadFromFile(true);
            }
            catch (FileNotFoundException)
            {
                client.SendMessage(string.Format("Schematic file is not found: {0}", schematicName));
                return;
            }
            catch (Exception ex)
            {
                loaded = false;
                var sb = new StringBuilder();
                sb.Append("Schematics: error has occured while loading schematic file ");
                sb.Append(schematicName);
                sb.Append(Environment.NewLine);
                sb.Append(ex.ToString());
                client.GetServer().GetLogger().Log(LogLevel.Warning, sb.ToString());
            }

            if (!loaded)
            {
                client.SendMessage("Can not load schematic file");
                return;
            }

            client.SendMessage(string.Format("Width(X) x Height(Y) x Length(Z): {0} x {1} x {2} ({3} blocks)", schematic.Width, schematic.Height, schematic.Length, (schematic.Width * schematic.Height * schematic.Length)));
        }
开发者ID:chraft,项目名称:c-raft-plugins,代码行数:33,代码来源:CmdSchematic.cs

示例10: Use

        public void Use(IClient client, string commandName, string[] tokens)
        {
            short amount;
            IClient target;

            if (tokens.Length == 1)
            {
                if (short.TryParse(tokens[0], out amount))
                {
                    client.GetOwner().AddExperience(amount);
                    client.SendMessage(string.Format("{0}You has been granted with {1} exp", ChatColor.Red, amount));
                    return;
                }
                Help(client);
                return;
            }

            if (tokens.Length == 2)
            {
                IClient[] matchedClients = client.GetServer().GetClients(tokens[0]).ToArray();
                if (matchedClients.Length < 1)
                {
                    client.SendMessage("Unknown Player");
                    return;
                }
                if (matchedClients.Length == 1)
                {
                    target = matchedClients[0];
                }
                else
                {
                    int exactMatchClient = -1;
                    for (int i = 0; i < matchedClients.Length; i++)
                    {
                        if (matchedClients[i].GetOwner().DisplayName.ToLower() == tokens[0].ToLower())
                            exactMatchClient = i;
                    }

                    // If we found the player with the exactly same name - he is our target
                    if (exactMatchClient != -1)
                    {
                        target = matchedClients[exactMatchClient];
                    }
                    else
                    {
                        // We do not found a proper target and aren't going to randomly punish anyone
                        client.SendMessage("More than one player found. Provide the exact name.");
                        return;
                    }
                }

                if (short.TryParse(tokens[1], out amount))
                {
                    target.GetOwner().AddExperience(amount);
                    target.SendMessage(string.Format("{0}{1} has been granted with {2} exp", ChatColor.Red, target.GetOwner().DisplayName, amount));
                }
                else
                {
                    Help(client);
                }
                return;
            }

            Help(client);
        }
开发者ID:chraft,项目名称:c-raft-plugins,代码行数:65,代码来源:CmdGiveXP.cs

示例11: Use

        public void Use(IClient client, string commandName, string[] tokens)
        {
            int newTime = -1;
            if (tokens.Length < 1)
            {
                client.SendMessage("You must specify a time value between 0 and 24000 or <sunrise|day|sunset|night>");
                return;
            }
            if (int.TryParse(tokens[0], out newTime) && newTime >= 0 && newTime <= 24000)
            {
                client.GetOwner().GetWorld().Time = newTime;
            }
            else if (tokens[0].ToLower() == "sunrise")
            {
                client.GetOwner().GetWorld().Time = 0;
            }
            else if (tokens[0].ToLower() == "day")
            {
                client.GetOwner().GetWorld().Time = 6000;
            }
            else if (tokens[0].ToLower() == "sunset")
            {
                client.GetOwner().GetWorld().Time = 12000;
            }

            else if (tokens[0].ToLower() == "night")
            {
                client.GetOwner().GetWorld().Time = 18000;
            }
            else
            {
                client.SendMessage("You must specify a time value between 0 and 24000 or <sunrise|day|sunset|night>");
                return;
            }

            client.GetServer().BroadcastTimeUpdate(client.GetOwner().GetWorld());
        }
开发者ID:Nirad,项目名称:c-raft,代码行数:37,代码来源:CmdTime.cs


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