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


C++ command_reader::parse方法代码示例

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


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

示例1:

		/* 
		 * /bezier -
		 * 
		 * Draws a beizer curvee using between user-specified control points.
		 * The curve will pass through the first and last points, but not necessarily
		 * through the rest.
		 * 
		 * Permissions:
		 *   - command.draw.bezier
		 *       Needed to execute the command.
		 */
		void
		c_bezier::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm ("command.draw.bezier"))
					return;
		
			if (!reader.parse (this, pl))
					return;
			if (reader.no_args () || reader.arg_count () > 2)
				{ this->show_summary (pl); return; }
			
			std::string str = reader.next ().as_str ();
			if (!sutils::is_block (str))
				{
					pl->message ("§c * §7Invalid block§f: §c" + str);
					return;
				}
			
			blocki bl = sutils::to_block (str);
			if (bl.id == BT_UNKNOWN)
				{
					pl->message ("§c * §7Unknown block§f: §c" + str);
					return;
				}
			
			int order = 2;
			if (reader.has_next ())
				{
					command_reader::argument arg = reader.next ();
					if (!arg.is_int ())
						{
							pl->message ("§c * §7Usage§f: §e/bezier §cblock §8[§corder§8]");
							return;
						}
					
					order = arg.as_int ();
					if (order <= 0 || order > 20)
						{
							pl->message ("§c * §7Invalid bezier curve order §f(§7Must be between §b1-20§f)");
							return;
						}
				}
			
			bezier_data *data = new bezier_data (pl->get_world (), bl, order);
			pl->create_data ("bezier", data,
				[] (void *ptr) { delete static_cast<bezier_data *> (ptr); });
			pl->get_nth_marking_callback (1) += on_blocks_marked;
			
			std::ostringstream ss;
			ss << "§5Draw§f: §3bezier curve §f[§7order§f: §8" << order << "§f, §7block§f: §8"
				 << block_info::from_id (bl.id)->name;
			if (bl.meta != 0)
				ss << ':' << (int)bl.meta;
			ss << "§f]:";
			pl->message (ss.str ());
			
			ss.str (std::string ()); ss.clear ();
			ss << "§7 | §ePlease mark §b" << (order + 1) << " §eblocks§f.";
			pl->message (ss.str ());
		}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:71,代码来源:bezier.cpp

示例2: if

		/* 
		 * /help -
		 * 
		 * When executed without any arguments, the command displays general tips,
		 * tricks and hints about what the player can do in the server. Otherwise,
		 * it displays detailed information about the supplied command.
		 * 
		 * Permissions:
		 *   - command.info.help
		 *       To execute the command.
		 */
		void
		c_help::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm ("command.info.help"))
				return;
			
			// we handle --help and --summary ourselves, instead of passing the work
			// to the command reader.
			reader.add_option ("help", "h", true);
			reader.add_option ("summary", "s");
			if (!reader.parse (this, pl, false))
				return;
			
			if (reader.opt ("summary")->found () && reader.no_args ())
				{ this->show_summary (pl); return; }
			else if (reader.opt ("help")->found ())
				{
					auto& opt = *reader.opt ("help");
					if (opt.got_args ())
						{
							auto& arg = opt.arg (0);
							if (!arg.is_int ())
								{ pl->message ("§c * §7Invalid page number§: §c" + arg.as_str ()); return; }
							int page = arg.as_int ();
							this->show_help (pl, page, 12);
						}
					else
						this->show_help (pl, 1, 12);
					return;
				}
			
			if (reader.arg_count () > 2)
				{ this->show_summary (pl); return; }
			else if (reader.arg_count () > 0)
				{
					command *cmd = pl->get_server ().get_commands ().find (reader.arg (0).c_str ());
					if (!cmd || !pl->has (cmd->get_exec_permission ()))
						{
							pl->message ("§c * §7Unable to find help for§f: §c" + reader.arg (0));
							return;
						}
					
					if (reader.opt ("summary")->found ())
						cmd->show_summary (pl);
					
					int page = 1;
					if (reader.arg_count () == 2)
						{
							if (!sutils::is_int (reader.arg (1)))
								{ pl->message ("§c * §7Invalid page number§: §c" + reader.arg (1)); return; }
							page = sutils::to_int (reader.arg (1));
						}
					cmd->show_help (pl, page, 12);
					
					return;
				}
			
			for (const std::string& str : pl->get_server ().msgs.help)
				pl->message (messages::compile (str, messages::environment (pl)));
		}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:71,代码来源:help.cpp

示例3:

/*
 * /ping -
 *
 * Displays to the player how much time it takes for the server to both
 * send and retreive a single keep alive (ping: 0x00) packet (in ms).
 *
 * Permissions:
 *   - command.misc.ping
 *       Needed to execute the command.
 */
void
c_ping::execute (player *pl, command_reader& reader)
{
    if (!pl->perm ("command.misc.ping"))
        return;

    if (!reader.parse (this, pl))
        return;

    if (reader.arg_count () > 1)
    {
        this->show_summary (pl);
        return;
    }

    if (reader.has_args ())
    {
        player *target = pl->get_server ().get_players ().find (reader.arg (0).c_str ());
        if (!target)
        {
            pl->message ("§c * §7No such player §f: §c" + reader.arg (0) + "§f.");
            return;
        }

        std::ostringstream ss;
        ss << "§a" << target->get_username () << "§e's ping§f: §c" << target->get_ping () << " §emilliseconds§f.";
        pl->message (ss.str ());
        return;
    }

    std::ostringstream ss;
    ss << "§ePing§f: §c" << pl->get_ping () << " §emilliseconds§f.";
    pl->message (ss.str ());
}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:44,代码来源:ping.cpp

示例4:

		/* 
		 * /whodid
		 * 
		 * Displays modification records for blocks selected by the user.
		 * 
		 * Permissions:
		 *   - command.info.whodid
		 *       Needed to execute the command.
		 */
		void
		c_whodid::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm (this->get_exec_permission ()))
					return;
		
			reader.add_option ("page", "p", 1, 1);
			if (!reader.parse (this, pl))
				return;
			
			int page = -1;
			auto opt_page = reader.opt ("page");
			if (opt_page->found ())
				{
					auto& arg = opt_page->arg (0);
					if (!arg.is_int () || (page = arg.as_int ()) <= 0)
						{
							pl->message ("§c * §7Option to §4--§cpage §7must be an integer > 0");
							return;
						}
				}
			
			whodid_data *data = new whodid_data {page - 1};
			pl->create_data ("whodid", data,
				[] (void *ptr) { delete static_cast<whodid_data *> (ptr); });
			pl->get_nth_marking_callback (1) += on_blocks_marked;
			
			pl->message ("§ePlease mark §bone §eblock.");
		}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:38,代码来源:whodid.cpp

示例5: void

		/*
		 * /zone
		 * 
		 * Zone management.
		 * 
		 * Permissions:
		 *   - command.world.zone
		 *       Needed to execute the command.
		 */
		void
		c_zone::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm (this->get_exec_permission ()))
				return;
			
			if (!reader.parse (this, pl))
				return;
			if (reader.no_args ())
				{ this->show_summary (pl); return; }
			
			std::string arg = reader.next ();
			static const std::unordered_map<cistring, void (*)(player *, command_reader&)> _map {
				{ "create", _handle_create },
				{ "delete", _handle_delete },
				{ "build-perms", _handle_build_perms },
				{ "enter-perms", _handle_enter_perms },
				{ "leave-perms", _handle_leave_perms },
				{ "enter-msg", _handle_enter_msg },
				{ "leave-msg", _handle_leave_msg },
				{ "select", _handle_select },
				{ "reset", _handle_reset },
				{ "check", _handle_check },
			};
			
			auto itr = _map.find (arg.c_str ());
			if (itr == _map.end ())
				{
					pl->message ("§c * §7Invalid sub-command§f: §c" + arg);
					return;
				}
			
			itr->second (pl, reader);
		}
开发者ID:projectapex,项目名称:hCraft,代码行数:43,代码来源:zone.cpp

示例6: void

		/* 
		 * /physics -
		 * 
		 * Changes the current state of physics of the player's world.
		 * 
		 * Permissions:
		 *   - command.world.physics
		 *       Needed to execute the command.
		 */
		void
		c_physics::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm ("command.world.physics"))
				return;
			
			if (!reader.parse (this, pl))
				return;
			
			if (reader.no_args () || reader.no_args ())
				{ this->show_summary (pl); return; }
			
			std::string& opt = reader.next ();
			static std::unordered_map<cistring, void (*)(player *, command_reader &)>
				funs {
						{ "on", handle_on },
						{ "off", handle_off },
						{ "pause", handle_pause },
						{ "threads", handle_threads },
					};
			
			auto itr = funs.find (opt.c_str ());
			if (itr == funs.end ())
				{
					pl->message ("§c * §7Invalid option§f: §c" + opt);
					return;
				}
			
			itr->second (pl, reader);
		}
开发者ID:NBY,项目名称:hCraft,代码行数:39,代码来源:physics.cpp

示例7:

		/*
		 * /unban
		 * 
		 * Revokes a permanent ban from a specified player.
		 * 
		 * Permissions:
		 *   - command.admin.unban
		 *       Needed to execute the command.
		 *   - command.admin.unban.ip
		 *       Required to lift IP bans.
		 */
		void
		c_unban::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm (this->get_exec_permission ()))
					return;
			
			reader.add_option ("ip", "i");
			if (!reader.parse (this, pl))
					return;
			if (reader.no_args ())
				{ this->show_summary (pl); return; }
			
			std::string  target_name = reader.next ().as_str ();
			std::string  reason = reader.has_next () ? reader.all_after (0)
				: "No reason specified";
			
			if (reader.opt ("ip")->found ())
				{
					if (!pl->has ("command.admin.unban.ip"))
						{
							pl->message ("§c * §7You are not allowed to do that§c.");
							return;
						}
					
					_unban_ip (pl, target_name);
				}
			else
				_unban_player (pl, target_name, reason, false);
		}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:40,代码来源:unban.cpp

示例8:

		/* 
		 * /world - 
		 * 
		 * Lets the user modify or view world related information.
		 * 
		 * Permissions:
		 *   - command.world.world
		 *       Needed to execute the command.
		 *   - command.world.world.change-members
		 *       Needed to add\remove world members.
		 *   - command.world.world.change-owners
		 *       Needed to add\remove world owners.
		 *   - command.world.world.owner.change-members
		 *       If a world owner is allowed to add\remove members.
		 *   - command.world.world.owner.change-owners
		 *       If a world owner is allowed to add\remove owners.
		 *   - command.world.world.set-perms
		 *       Required to set build-perms or join-perms
		 *   - command.world.world.get-perms
		 *       Required to view build-perms or join-perms
		 *   - commands.world.world.def-gm
		 *       Needed to change the world's default gamemode.
		 *   - commands.world.world.resize
		 *       Required to resize the world.
		 *   - commands.world.world.regenerate
		 *       Required to regenerate the world.
		 *   - commands.world.world.save
		 *       Required to save the world.
		 *   - commands.world.world.time
		 *       Required to change the time of the world.
		 *   - commands.world.world.pvp
		 *       Required to turn PvP on or off.
		 */
		void
		c_world::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm ("command.world.world"))
				return;
			
			reader.add_option ("world", "w", 1, 1);
			if (!reader.parse (this, pl))
				return;
			
			world *w = pl->get_world ();
			auto opt_w = reader.opt ("world");
			if (opt_w->found ())
				{
					const std::string w_name = opt_w->arg (0).as_str ();
					w = pl->get_server ().get_worlds ().find (w_name.c_str ());
					if (!w)
						{
							pl->message ("§c * §7Unknown world§f: §c" + w_name);
							return;
						}
				}
			
			if (!reader.has_next ())
				_handle_no_args (pl, w);
			else
				{
					std::string arg1 = reader.next ().as_str ();
					
					static const std::unordered_map<cistring,
						void (*)(player *, world *, command_reader &)> _map {
						{ "owners", _handle_owners },
						{ "members", _handle_members },
						{ "build-perms", _handle_build_perms },
						{ "join-perms", _handle_join_perms },
						{ "def-gm", _handle_def_gm },
						{ "def-inv", _handle_def_inv },
						{ "resize", _handle_resize },
						{ "regenerate", _handle_regenerate },
						{ "backup", _handle_backup },
						{ "restore", _handle_restore },
						{ "save", _handle_save },
						{ "time", _handle_time },
						{ "pvp", _handle_pvp },
					};
					
					auto itr = _map.find (arg1.c_str ());
					if (itr == _map.end ())
						{
							pl->message ("§c * §7Unknown sub-command§f: §c" + arg1);
							return;
						}
					
					itr->second (pl, w, reader);
				}
		}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:89,代码来源:world.cpp

示例9: if

		/* 
		 * /wunload -
		 * 
		 * Saves and removes a requested world from the server's online world world
		 * list, optionally removing it from the autoload list as well.
		 * 
		 * Permissions:
		 *   - command.world.wunload
		 *       Needed to execute the command.
		 */
		void
		c_wunload::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm ("command.world.wunload"))
				return;
			
			reader.add_option ("autoload", "a");
			if (!reader.parse (this, pl))
				return;
			
			if (reader.no_args () || reader.arg_count () > 1)
				{ this->show_summary (pl); return; }
			
			std::string world_name = reader.arg (0);
			world *wr = pl->get_server ().find_world (world_name.c_str ());
			if (!wr)
				{
					if (reader.opt ("autoload")->found ())
						{
							if (remove_from_autoload (pl->get_server (), world_name))
								pl->message ("§eWorld §b" + world_name + " §ehas been removed from the autoload list§f.");
							else
								pl->message ("§cWorld §7" + world_name + " §cis not in the autoload list§7.");
						}
					else
						pl->message ("§c * §7World §b" + world_name + " §7is not loaded§f.");
					return;
				}
			else if (wr == pl->get_server ().get_main_world ())
				{
					pl->message ("§c * §7You can not unload the main world§f!");
					return;
				}
			
			world_name.assign (wr->get_name ());
			
			// transfer all players to the server's main world.
			std::vector<player *> to_transfer;
			wr->get_players ().populate (to_transfer);
			for (player *pl : to_transfer)
				pl->join_world (pl->get_server ().get_main_world ());
			pl->get_server ().remove_world (wr);
			
			if (reader.opt ("autoload")->found ())
				{
					if (remove_from_autoload (pl->get_server (), world_name))
						pl->message ("§eWorld §b" + world_name + " §ehas been removed from the autoload list§f.");
					else
						pl->message ("§cWorld §7" + world_name + " §cis not in the autoload list§7.");
				}
			pl->get_server ().get_players ().message (
				"§cWorld §4" + world_name + " §chas been unloaded§c!");
		}
开发者ID:hCraft,项目名称:hCraft,代码行数:63,代码来源:wunload.cpp

示例10:

		/* 
		 * /players
		 * 
		 * Displays a list of online players.
		 * 
		 * Permissions:
		 *   - command.info.players
		 *       Needed to execute the command.
		 */
		void
		c_players::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm (this->get_exec_permission ()))
				return;
			
			if (!reader.parse (this, pl))
				return;
			
			auto& players = pl->get_server ().get_players ();
			
			std::ostringstream ss;
			ss << "§eThere " << ((players.count () == 1) ? "is" : "are") << " currently §b" << players.count () << " §eplayer"
				<< ((players.count () == 1) ? "" : "s") << " online§f:";
			pl->message (ss.str ());
			
			server &srv = pl->get_server ();
			group_manager &gman = srv.get_groups ();
			
			// create a sorted list of groups (in descending values of power)
			std::vector<group *> group_list;
			for (auto itr = gman.begin (); itr != gman.end (); ++itr)
				group_list.push_back (itr->second);
			std::sort (group_list.begin (), group_list.end (),
				[] (const group *a, const group *b) -> bool
					{
						return (*a) > (*b);
					});
			
			for (group *grp : group_list)
				{
					std::vector<player *> vec;
					
					players.all (
						[&vec, grp] (player *pl)
							{
								if (pl->get_rank ().main () == grp)
									vec.push_back (pl);
							});
					
					if (!vec.empty ())
						{
							ss.str (std::string ());
							ss << "§" << grp->color << "  " << grp->name << _suffix (grp->name) << " §e(§7" << vec.size () << "§e): §7";
							for (player *pl : vec)
								ss << pl->get_username () << " ";
							pl->message_spaced (ss.str ());
						}
				}
		}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:59,代码来源:players.cpp

示例11: if

		/* 
		 * /portal - 
		 * 
		 * Turns blocks in the user's selected area to portals.
		 * 
		 * Permissions:
		 *   - command.world.portal
		 *       Needed to execute the command.
		 *   - command.world.portal.interworld
		 *       Needed to place portals between different worlds.
		 */
		void
		c_portal::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm (this->get_exec_permission ()))
				return;
			
			if (!reader.parse (this, pl))
				return;
			if (reader.no_args ())
				{
					pl->message ("§c * §7Usage§f: §e/portal §ctarget-block §8[§creplace-block§8]");
					return;
				}
			
			std::string& target_block_str = reader.next ().as_str ();
			if (sutils::iequals (target_block_str, "exit"))
				{
					_finish_portal (pl);
					return;
				}
			else if (sutils::iequals (target_block_str, "cancel"))
				{
					_cancel_portal (pl);
					return;
				}
			else
				{
					portal_data *data = static_cast<portal_data *> (pl->get_data ("portal"));
					if (data)
						{
							pl->message ("§c * §7Type §c/portal cancel §7to cancel your previous portal§c.");
							return;
						}
				}
			
			if (pl->selections.empty ())
				{ pl->message ("§c * §7You§f'§7re not selecting anything§f."); return; }
			world_selection *sel = pl->curr_sel;
			world *w = pl->get_world ();
			
			blocki target_block;
			if (!(target_block = sutils::to_block (target_block_str)).valid ())
				{
					pl->message ("§c * §7Invalid block§f: §c" + target_block_str);
					return;
				}
			
			blocki replace_block = target_block;
			if (reader.has_next ())
				{
					std::string& replace_block_str = reader.next ().as_str ();
					if (!(replace_block = sutils::to_block (replace_block_str)).valid ())
						{
							pl->message ("§c * §7Invalid block§f: §c" + replace_block_str);
							return;
						}
				}
			
			if (!pl->get_world ()->security ().can_build (pl))
				{
					pl->message ("§4 * §cYou are not allowed to build here§4.");
					return;
				}
			
			int blocks = 0;
			sparse_edit_stage *es = new sparse_edit_stage (pl->get_world ());
			portal *ptl = new portal ();
			
			block_pos smin = sel->min (), smax = sel->max ();
			if (smin.y < 0) smin.y = 0;
			if (smin.y > 255) smin.y = 255;
			if (smax.y < 0) smax.y = 0;
			if (smax.y > 255) smax.y = 255;
			for (int x = smin.x; x <= smax.x; ++x)
				for (int y = smin.y; y <= smax.y; ++y)
					for (int z = smin.z; z <= smax.z; ++z)
						{
							if (!w->in_bounds (x, y, z)) continue;
							if (sel->contains (x, y, z))
								{
									block_data bd = w->get_block (x, y, z);
									if (bd.id == target_block.id && bd.meta == target_block.meta)
										{
											es->set (x, y, z, replace_block.id, replace_block.meta, BE_PORTAL);
											ptl->affected.emplace_back (x, y, z);
											++ blocks;
										}
								}
						}
//.........这里部分代码省略.........
开发者ID:projectapex,项目名称:hCraft,代码行数:101,代码来源:portal.cpp

示例12: if

		/* 
		 * /gm -
		 * 
		 * Changes the gamemode of the executor or of a specified player.
		 * 
		 * Permissions:
		 *   - command.admin.gm
		 *       Needed to execute the command.
		 */
		void
		c_gm::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm ("command.admin.gm"))
					return;
		
			if (!reader.parse (this, pl))
					return;
			if (reader.no_args () || reader.arg_count () > 2)
				{ this->show_summary (pl); return; }
			
			player *target = pl;
			if (reader.arg_count () == 2)
				{
					std::string& plname = reader.next ().as_str ();
					target = pl->get_server ().get_players ().find (plname.c_str ());
					if (!target)
						{
							pl->message ("§c * §7No such player§f: §c" + plname);
							return;
						}
				}
			
			std::string& gmstr = reader.next ().as_str ();
			gamemode_type gm   = GT_SURVIVAL;
			if (gmstr.size () == 1)
				{
					switch (gmstr[0])
						{
						case 's': break;
						case 'c': gm = GT_CREATIVE; break;
						//case 'a': gm = GT_ADVENTURE; break;
						
						default:
							pl->message ("§c * §7Invalid gamemode type§f: §c" + gmstr);
							return;
						}
				}
			else
				{
					if (sutils::iequals (gmstr, "survival"))
						;
					else if (sutils::iequals (gmstr, "creative"))
						gm = GT_CREATIVE;
					//else if (sutils::iequals (gmstr, "adventure"))
					//	gm = GT_ADVENTURE;
					else
						{
							pl->message ("§c * §7Invalid gamemode type§f: §c" + gmstr);
							return;
						}
				}

			if (gm == target->gamemode ())
				{
					if (pl == target)
						target->message ("§c * §7You already have that gamemode set§f.");
					else
						{
							std::ostringstream ss;
							ss << "§c * §7" << target->get_colored_username ()
								 << " §7already has that gamemode set§f.";
							target->message (ss.str ());
						}
					return;
				}
			
			const char *gm_name = (gm == GT_SURVIVAL) ? "survival"
				: ((gm == GT_CREATIVE) ? "creative" : "adventure");
			if (pl != target)
				{
					std::ostringstream ss;
					ss << target->get_colored_username () << " §egamemode has been set to§f: §4" << gm_name;
					pl->message (ss.str ());
				}
			
			target->change_gamemode (gm);
			
			/*
			// Commented out due to Minecraft's ugly "Your gamemode has been updated."
			// message.
			
			std::ostringstream ss;
			ss << "§6Your gamemode has been set to§f: §c" << gm_name;
			target->message (ss.str ());
			*/
		}
开发者ID:NBY,项目名称:hCraft,代码行数:96,代码来源:gm.cpp

示例13: if

		/* /kick
		 * 
		 * Kicks a player from the server.
		 * 
		 * Permissions:
		 *   - command.admin.kick
		 *       Needed to execute the command.
		 */
		void
		c_kick::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm (this->get_exec_permission ()))
					return;
			
			reader.add_option ("message", "m", 1, 1);
			if (!reader.parse (this, pl))
					return;
			if (reader.no_args ())
				{ this->show_summary (pl); return; }
			
			std::string& target_name = reader.next ().as_str ();
			std::string  reason = reader.has_next () ? reader.all_after (0)
				: "No reason specified";
			std::string  kick_msg = "§c";
			{
				auto opt = reader.opt ("message");
				if (opt->found ())
					kick_msg.append (opt->arg (0).as_str ());
				else
					kick_msg.append ("You have been kicked from the server");
			}
			
			player *target = pl->get_server ().get_players ().find (target_name.c_str ());
			if (!target)
				{
					pl->message ("§c * §7No such player§f: §c" + target_name);
					return;
				}
			else if (target->bad ()) return;
			
			server& srv = pl->get_server ();
			
			// record kick
			{
				auto& conn = pl->get_server ().sql ().pop ();
				try
					{
						sqlops::record_kick (conn, target->get_username (),
							pl->get_username (), reason.c_str ());
					}
				catch (const std::exception& ex)
					{
						pl->message ("§4 * §cAn error has occurred while recording kick message");
					}
				
				pl->get_server ().sql ().push (conn);
				
				std::ostringstream ss;
				ss << "§7 | §eRecorded kick message§7: §c\"" << reason << "§c\"";
				pl->message (ss.str ());
			}
			
			{
				std::ostringstream ss;
				ss << "§4 > " << target->get_colored_nickname () << " §chas been kicked by "
					 << pl->get_colored_nickname () << "§c!";
				srv.get_players ().message (ss.str ());
			}
			target->kick (kick_msg.c_str (), reason.c_str ());
		}
开发者ID:NBY,项目名称:hCraft,代码行数:70,代码来源:kick.cpp

示例14:

		/* 
		 * /sphere -
		 * 
		 * Draws a three-dimensional sphere centered at a point.
		 * 
		 * Permissions:
		 *   - command.draw.sphere
		 *       Needed to execute the command.
		 */
		void
		c_sphere::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm (this->get_exec_permission ()))
					return;
		
			reader.add_option ("fill", "f");
			if (!reader.parse (this, pl))
					return;
			if (reader.no_args () || reader.arg_count () > 3)
				{ this->show_summary (pl); return; }
			
			bool do_fill = reader.opt ("fill")->found ();
			
			std::string& str = reader.next ().as_str ();
			if (!sutils::is_block (str))
				{
					pl->message ("§c * §7Invalid block§f: §c" + str);
					return;
				}
			
			blocki bl = sutils::to_block (str);
			if (bl.id == BT_UNKNOWN)
				{
					pl->message ("§c * §7Unknown block§f: §c" + str);
					return;
				}
			
			int radius = -1;
			if (reader.has_next ())
				{
					command_reader::argument arg = reader.next ();
					if (!arg.is_int ())
						{
							pl->message ("§c * §7Usage§f: §e/sphere §cblock §8[§cradius§8]");
							return;
						}
					
					radius = arg.as_int ();
					if (radius <= 0)
						{
							pl->message ("§c * §7Radius must be greater than zero.§f");
							return;
						}
				}
			
			sphere_data *data = new sphere_data {bl, radius, do_fill};
			pl->create_data ("sphere", data,
				[] (void *ptr) { delete static_cast<sphere_data *> (ptr); });
			pl->get_nth_marking_callback ((radius == -1) ? 2 : 1) += on_blocks_marked;
			
			std::ostringstream ss;
			ss << "§8Sphere §7(";
			if (radius != -1)
				ss << "§8Radius§7: §b" << radius << "§7, ";
			ss << "§8Block§7: §b" << str << "§7):";
			pl->message (ss.str ());
			
			ss.str (std::string ()); ss.clear ();
			ss << "§8 * §7Please mark §b" << ((radius == -1) ? 2 : 1) << " §7block"
				 << ((radius == -1) ? "s" : "") << "§7.";
			pl->message (ss.str ());
		}
开发者ID:hCraft,项目名称:hCraft,代码行数:72,代码来源:sphere.cpp

示例15: if

		/* /rank
		 * 
		 * Changes the rank of a specified player.
		 * 
		 * Permissions:
		 *   - command.admin.rank
		 *       Needed to execute the command.
		 */
		void
		c_rank::execute (player *pl, command_reader& reader)
		{
			if (!pl->perm (this->get_exec_permission ()))
					return;
			
			reader.add_option ("quiet", "q");
			if (!reader.parse (this, pl))
					return;
			if (reader.arg_count () != 2)
				{ this->show_summary (pl); return; }
			
			bool quiet = reader.opt ("quiet")->found ();
			
			enum
				{
					ACT_RANK,
					ACT_PROMOTE,
					ACT_DEMOTE,
				} action = ACT_RANK;
			std::string target_name;
			rank new_rank;
				
			std::string arg1 = reader.next ();
			if (sutils::iequals (arg1, "promote"))
				{
					action = ACT_PROMOTE;
					target_name = reader.next ().as_str ();
				}
			else if (sutils::iequals (arg1, "demote"))
				{
					action = ACT_DEMOTE;
					target_name = reader.next ().as_str ();
				}
			else
				{
					target_name = arg1;
					std::string rank_str = reader.next ();
					if (sutils::iequals (rank_str, "up"))
						action = ACT_PROMOTE;
					else if (sutils::iequals (rank_str, "down"))
						action = ACT_DEMOTE;
					else
						{
							try
								{
									new_rank.set (rank_str.c_str (), pl->get_server ().get_groups ());
								}
							catch (const std::exception& str)
								{
									pl->message ("§c * §7Invalid rank§f: §c" + rank_str);
										return;
								}
						}
				}
			
			player *target = nullptr;
			sqlops::player_info pinf;
			{
				soci::session sql (pl->get_server ().sql_pool ());
				if (!sqlops::player_data (sql, target_name.c_str (), pl->get_server (), pinf))
					{
						pl->message ("§c * §7Unknown player§f: §c" + target_name);
						return;
					}
				
				target_name.assign (pinf.name);
				target = pl->get_server ().get_players ().find (target_name.c_str ());
				if (action == ACT_PROMOTE || action == ACT_DEMOTE)
					{
						if (!get_next_rank (pl, pinf.rnk, new_rank, action == ACT_PROMOTE))
							return;
					}
				
				if (!pl->is_op ())
					{
						if (target_name == pl->get_username ())
							{
								pl->message ("§c * §7You cannot change your own rank§c.");
								return;
							}
						else if (pinf.rnk >= pl->get_rank ())
							{
								pl->message ("§c * §7You cannot change the rank of someone higher than you§c.");
								return;
							}
						else if (new_rank >= pl->get_rank ())
							{
								pl->message ("§c * §7You cannot give a player a rank that is higher than yours§c.");
								return;
							}
					}
//.........这里部分代码省略.........
开发者ID:BizarreCake,项目名称:hCraft,代码行数:101,代码来源:rank.cpp


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