コード例 #1
0
ファイル: unban.cpp プロジェクト: BizarreCake/hCraft
		/*
		 * /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);
		}
コード例 #2
0
ファイル: unban.cpp プロジェクト: NBY/hCraft
		/* /unban
		 * 
		 * Revokes a permanent ban from a specified player.
		 * 
		 * Permissions:
		 *   - command.admin.unban
		 *       Needed to execute the command.
		 */
		void
		c_unban::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  target_name = reader.next ().as_str ();
			std::string  reason = reader.has_next () ? reader.all_after (0)
				: "No reason specified";
			
			player *target = pl->get_server ().get_players ().find (target_name.c_str ());
			if (target)
				{
					if (target == pl)
						{
							pl->message ("§c * §7You are not banned§c.");
							return;
						}
					
					pl->message ("§c * §7That player is online§c...");
					return;
				}
				
			std::string target_colored_nick;
			server& srv = pl->get_server ();

			// record unban
			{
				auto& conn = pl->get_server ().sql ().pop ();
				try
					{
						if (!sqlops::player_exists (conn, target_name.c_str ()))
							{
								pl->message ("§c * §7No such player§f: §c" + target_name);
								pl->get_server ().sql ().push (conn);
								return;
							}
						
						if (!sqlops::is_banned (conn, target_name.c_str ()))
							{
								pl->message ("§c * §7Player is not banned§c.");
								pl->get_server ().sql ().push (conn);
								return;
							}
						
						target_name = sqlops::player_name (conn, target_name.c_str ());
						target_colored_nick = sqlops::player_colored_nick (conn, target_name.c_str (), pl->get_server ());
						sqlops::modify_ban_status (conn, target_name.c_str (), false);
						sqlops::record_unban (conn, target_name.c_str (),
							pl->get_username (), reason.c_str ());
					}
				catch (const std::exception& ex)
					{
						pl->message ("§4 * §cAn error has occurred while recording unban message");
					}
				
				pl->get_server ().sql ().push (conn);
				
				std::ostringstream ss;
				ss << "§7 | §eRecorded unban message§7: §c\"" << reason << "§c\"";
				pl->message (ss.str ());
			}
			
			{
				std::ostringstream ss;
				ss << "§8 > " << target_colored_nick << " §8has been unbanned by "
					 << pl->get_colored_nickname () << "§8!";
				srv.get_players ().message (ss.str ());
			}
		}
コード例 #3
0
ファイル: kick.cpp プロジェクト: NBY/hCraft
		/* /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 ());
		}