All pastes #208196 Raw Edit

yadmincom.pwn

public text v1 · immutable
#208196 ·published 2006-10-18 13:56 UTC
rendered paste body

public dcmd_commands(playerid, text[], help)
{
	CHECK_STR(text)
	if (help)
	{
		YS_HELP("*** Lists all available commands at your level");
	}
	else
	{
		new props, pages;
		new level = 0;
		level = CallRemoteFunction("YSGetUserLevel", "i", playerid);
		for (new i = 0; i < gComCount; i++)
		{
		    if (gFuncLevels[i] <= level) props++;
		}
		pages = (props + 7) / 8;

		new page = strval(text);
		new string[64];
		if (props == 0)
		{
			SendFormattedMessage(playerid, LG_MSG_COLOR, "*** No modules found");
		}
		else if (props > 8)
		{
			if (page)
			{
				if (page <= pages)
				{
			        for (new i = 0, j = 0, k = (page - 1) * 8, n = k + 8; i < gComCount && j < n; i++)
			        {
			            if (gFuncLevels[i] <= level)
			            {
							if (j >= k)
							{
								format(string, sizeof (string), "*** /%s", comname("", i));
								SendFormattedMessage(playerid, LG_MSG_COLOR, string);
							}
							j++;
						}
			        }
				}
				format(string, sizeof (string), "*** Use \"/%ncommands #\" where # is 1 - %d to list", pages);
				SendFormattedMessage(playerid, LG_MSG_COLOR, string);
		    }
			else
			{
				SendFormattedMessage(playerid, LG_MSG_COLOR, "*** More than 8 commands found");
				format(string, sizeof (string), "*** Use \"/%ncommands #\" where # is 1 - %d to list", pages);
				SendFormattedMessage(playerid, LG_MSG_COLOR, string);
			}
		}
		else
		{
			//print("1");
			for (new j = 0, i = 0; i < props && j < gComCount; j++)
			{
				//print("2");
				if (gFuncLevels[j] <= level)
				{
					//print("3");
					format(string, sizeof (string), "*** /%s", comname("", j));
					SendFormattedMessage(playerid, LG_MSG_COLOR, string);
					i++;
				}
	        }
		}
	}
	return 1;
}

public dcmd_help(playerid, text[], help)
{
	CHECK_STR(text)
	if (help)
	{
		//new str[64];
		//format(str, sizeof (str), "Provides information on the server script and commands"));
		YS_HELP("*** Provides information on the server script and commands");
	}
	else
	{
		if (text[0])
		{
			if (!ProcessCommand(playerid, text, 1))
			{
				YS_HELP("*** Unknown command, no help available");
			}
		}
		else
		{
			new str[MAX_STRING];
			YS_HELP(" ");
			YS_HELP("*** Alex \"Y_Less\" Cole's server admin script (c) 2006");
			format(str, sizeof (str), "*** Version %d.%02d.%02d", VERSION_MAJ, VERSION_MID, VERSION_MIN);
			YS_HELP(str);
			YS_HELP("***");
			YS_HELP("*** Scripting help: mabako, DracoBlue, D-Kynen");
			YS_HELP("*** Thanks to the SA:MP team and beteteam");
			YS_HELP("***");
			//format(str, sizeof (str), "*** Type \"/%s <command>\" for more", comname("help"));
			//YS_HELP(str);
			YS_HELP("*** Type \"/%nhelp <command>\" for more");
			YS_HELP("*** info on a specific command");
			//format(str, sizeof (str), "*** Type \"/%s\" for commands", comname("commands"));
			YS_HELP("*** Type \"/%ncommands\" for commands");
			//YS_HELP(str);
		}
		//#pragma unused playerid, text, help
	}
	return 1;
}

comname(name[], num = -1, incpre = 1)
{
	new str[MAX_STRING] = ""; // Not really a very MAX string but meh
	/*#if defined YS_ALT_NAMES_OFF
		//#define comname(%1) %1
		if (num != -1) format(str, sizeof (str), "%s%s", prename(), GetCommand(num));
		else format(str, sizeof (str), "%s%s", prename(), name);
		//return str;
	#else
		format(str, sizeof (str), "%s%s", prename(), name);
		#if !defined YS_ALT_NAMES_ON
			if (gComSet & YS_COMSET_USE_ALT)
			{
		#endif*/
	if (num != -1)
	{
		format(str, sizeof (str), "%s%s", incpre ? prename() : "", GetComName(num)); //gAltNames[num][0] ? GetAltName(num) : GetCommand(num));
		//printf("%s %d %s %s", str, gAltNames[num][0], GetAltName(num), GetCommand(num));
		//str = "hi";
		//return str;
	}
	else
	{
		for (new i = 0; i < gComCount; i++)
		{
			//printf("%s %s", name, GetCommand(i));
			if (strcmp(name, gFuncNames[i]) == 0)
			{
				format(str, sizeof (str), "%s%s", incpre ? prename() : "", GetComName(i));
				//return str;
				break;
			}
		}
	}
		/*#if !defined YS_ALT_NAMES_ON
			}
		#endif
		//return str;
	#endif*/
	return str;
}

GetComName(num)
{
	//new str[MAX_STRING] = ""; // Not really a very MAX string but meh
	//format(str, sizeof (str), "%s%s", prename(), gAltNames[num][0] ? GetAltName(num) : GetCommand(num));
	#if !defined YS_ALT_NAMES_OFF
		#if !defined YS_ALT_NAMES_ON
			if (gAltNames[num][0])
			{
		#endif
				/*for (new i = 0, j = strlen(gAltNames[num]); i < j; i++)
				{
					str[i] = gAltNames[num][i];
					printf("%c", str[i]);
				}*/
				//str = GetAltName(num);
				return gAltNames[num];
		#if !defined YS_ALT_NAMES_ON
			}
			else
			{
		#endif
	#endif
				/*for (new i = 0, j = strlen(gFuncNames[num]); i < j; i++)
				{
					str[i] = gFuncNames[num][i];
					printf("%c", str[i]);
				}*/
				//str = GetCommand(num);
				return gFuncNames[num];
	#if !defined YS_ALT_NAMES_OFF && !defined YS_ALT_NAMES_ON
			}
	#endif
	//format(str, sizeof (str), "%s%s", prename(), str);
	// WHY I have to do all that I have no idea, can't be efficient
	// But for some reason just using my old style format breaks.
	// OK, it seems it was the ? in format that was breaking it.
	//printf("%s", str);
	//return str;
	new str[MAX_FUNC_NAME] = "";
	//str = "";
	return str;
}

prename()
{
	new str[9] = "";
	#if !defined YS_USE_PREFIX_OFF
		#if !defined YS_USE_PREFIX_ON
			if (YS_COMSET_USE_PREFIX & gComSet)
			{
		#endif
				format(str, sizeof (str), "%s ", gPrefix[1]);
		#if !defined YS_USE_PREFIX_ON
			}
		#endif
	#endif
	return str;
}

public dcmd_loadmod(playerid, text[], help)
{
	CHECK_STR(text)
	if (help)
	{
		YS_HELP("*** Loads a module by name (YSS_<name>.amx)");
	}
	else
	{
		if (text[0] == 0)
		{
			SendFormattedMessage(playerid, LG_MSG_COLOR, "*** You must enter a module name");
		}
		else
		{
			new str[64];
			format(str, sizeof (str), "reloadfs YSS_%s", text);
			SendRconCommand(str);
		}
	}
	return 1;
}

public dcmd_unloadmod(playerid, text[], help)
{
	CHECK_STR(text)
	if (help)
	{
		YS_HELP("*** Unloads a script module by number");
		//new str[32];
		//format(str, sizeof (str), "*** Type \"/%s\" to list modules", comname("listmodules"));
		YS_HELP("*** Type \"/%nlistmodules\" to list modules");
	}
	else
	{
		if (text[0] == 0)
		{
			SendFormattedMessage(playerid, 0xFF0000FF, "*** You must enter a module number");
		}
		else
		{
			new num = strval(text);
			if (num < MAX_MODULES)
			{
				new str[64];
				format(str, sizeof (str), "unloadfs YSS_%s", gModules[num]);
				SendRconCommand(str);
			}
			else
			{
				SendFormattedMessage(playerid, 0xFF0000FF, "*** Invalid module number");
			}
		}
	}
	return 1;
}

public dcmd_reloadadmin(playerid, text[], help)
{
	CHECK_STR(text)
	if (help)
	{
		YS_HELP("*** Reloads the admin script entirely");
		YS_HELP("*** NOTE: Any unsaved settings will be lost");
	}
	else
	{
		SendRconCommand("reloadfs YSS_rcon"); //RELOAD_SELF);
	}
	return 1;
}

public dcmd_listmod(playerid, text[], help)
{
	CHECK_STR(text)
	if (help)
	{
		YS_HELP("*** Lists loaded server script modules");
	}
	else
	{
		new props, pages, level = 0;
		level = CallRemoteFunction("YSGetUserLevel", "i", playerid) >= ComLevel("unloadmodule") ? 1 : 0;
		for (new i = 0; i < MAX_MODULES; i++)
		{
		    if ((gModules[i][0] != 0) && (gModHidden[i] != 0 ? level : 1)) props++;
		}
		pages = (props + 7) / 8;

		new page = strval(text);
		new string[64];
		if (props == 0)
		{
			SendFormattedMessage(playerid, LG_MSG_COLOR, "*** No modules found");
		}
		else if (props > 8)
		{
			if (page)
			{
				if (page <= pages)
				{
			        for (new i = 0, j = 0, k = (page - 1) * 8, n = k + 8; i < MAX_MODULES && j < n; i++)
			        {
			            if ((gModules[i][0] != 0) && (gModHidden[i] ? level : 1))
			            {
							if (j >= k)
							{
								format(string, sizeof (string), "*** Module %d: %s", i, gModNames[i]);
								SendFormattedMessage(playerid, LG_MSG_COLOR, string);
							}
							j++;
						}
			        }
				}
				format(string, sizeof (string), "*** Use \"/%nlistmodules #\" where # is 1 - %d to list", pages);
				SendFormattedMessage(playerid, LG_MSG_COLOR, string);
		    }
			else
			{
				SendFormattedMessage(playerid, LG_MSG_COLOR, "*** More than 8 modules found");
				format(string, sizeof (string), "*** Use \"/%nlistmodules #\" where # is 1 - %d to list", pages);
				SendFormattedMessage(playerid, LG_MSG_COLOR, string);
			}
		}
		else
		{
			//print("1");
			for (new j = 0, i = 0; i < props && j < MAX_MODULES; j++)
			{
				//print("2");
				if (gModules[j][0] != 0 && gModHidden[j] ? level : 1)
				{
					//print("3");
					format(string, sizeof (string), "*** Module %d: %s", i, gModNames[i]);
					SendFormattedMessage(playerid, LG_MSG_COLOR, string);
					i++;
				}
	        }
		}
	}
	return 1;
}

public dcmd_setlevel(playerid, text[], help)
{
	CHECK_STR(text)
	if (help)
	{
		YS_HELP("*** Sets the userlevel required to use a command");
		YS_HELP("*** Parameters: <function name> <level = 0>");
		YS_HELP("*** NOTE: <function name> must be the REAL function name");
		YS_HELP("*** NOT an alternate name defined via the ini if used");
	}
	else
	{
		new str[MAX_FUNC_NAME];
		if (text[0] == 0)
		{
			SendFormattedMessage(playerid, 0xFF0000FF, "*** You must enter some paramters");
			return 1;
		}
		new index = 0;
		str = strtok(text, index);
		/*if (str[0] == 0)
		{
			SendFormattedMessage(playerid, 0xFF0000FF, "*** You must enter some paramters");
			format(str, sizeof (str), "*** Type \"/%s %s\" for more help", comname("help"), comname("setlevel", -1, 0));
			return 1;
		}*/
		/*if (text[index] == 0)
		{*/
		new i;
		for (i = 0; i < MAX_COMMANDS; i++)
		{
			if (strcmp(gFuncNames[i], str, true, index) == 0)
			{
				gFuncLevels[i] = strval(strtok(text, index));
				SendFormattedMessage(playerid, LG_MSG_COLOR, "*** Command level set");
				break;
			}
		}
		if (i == MAX_COMMANDS)
		{
			SendFormattedMessage(playerid, 0xFF0000FF, "*** Command not found");
		}
	}
	return 1;
}

public dcmd_reloadini(playerid, text[], help)
{
	CHECK_STR(text)
	if (help)
	{
		YS_HELP("*** Reloads ALL settings from the ini files");
	}
	else
	{
		//SendFormattedMessage(playerid, LG_MSG_COLOR, "*** Settings reloading");
		//READINI
		CallRemoteFunction("ReadINI", "i", 0);
		SendFormattedMessage(playerid, LG_MSG_COLOR, "*** Settings reloaded");
		//CallRemoteFunction("ReadINI", "");
	}
	return 1;
}