rendered paste body/*
Alex "Y_Less" Cole's server system
This is the main filterscript, it is the only one you need to run
but you won't get much functionality out of it alone.print Others
need to be added to the main ini, they each have their own ini too
Commands:
/commands - lists all the commands registered
/help - gives help on the script and commands
/loadmodule - loads a filterscript for use with the script
/unloadmodule - unloads a filterscript used by the script
/listmodules - lists all the modules loaded
*/
// Major version number
#define VERSION_MAJ 2
// Minor version number
#define VERSION_MID 2
// Build (if I can be arsed)
#define VERSION_MIN 1
#define RELOAD_SELF "reloadfs yadmin2"
#include <a_samp>
#include "YSScommon.pwn"
#define PROCESS CallRemoteFunction("YSProcess", "");
//#define CALLFUNC CallRemoteFunction(GetFunction(i), "isi", playerid, cmd[len + 1], help)
//#define CALLFUNCE CallRemoteFunction(GetFunction(i), "isi", playerid, "", help)
#define CALLFUNC CallRemoteFunction(gFuncFunctions[i], "isi", playerid, cmd[len + 1], help)
#define CALLFUNCE CallRemoteFunction(gFuncFunctions[i], "isi", playerid, "\x01", help)
//#define YS_ALT_NAMES_ON
//#define YS_ALT_NAMES_OFF
#define YS_ALT_NAMES_SEL
//#define YS_USE_PREFIX_ON
//#define YS_USE_PREFIX_OFF
#define YS_USE_PREFIX_SEL
#define YS_COMSET_USE_PREFIX 0x01
#define YS_COMSET_USE_WARNINGS 0x02
#define YS_COMSET_USE_ALT 0x04
#define __NONE__ group = 0;
#define YS_INI_MESSAGES 1
#define YS_INI_MEMBERLEVELS 2
#define YS_INI_COMMANDLEVELS 3
#define YS_INI_ALTNAMES 4
#define YS_INI_SETTINGS 5
#define YS_INI_IGNORECOMMANDS 6
#define YS_INI_FILTERCOMMANDS 7
#define YS_INI_LOGGING 8
#define YS_INI_MODULES 9
/*enum YS_COMMAND_FORMAT
{
COM_NAME[MAX_STRING],
#if !defined YS_ALT_NAMES_OFF
ALT_NAME[MAX_STRING], // May throw up a warning - ignore it
#endif
FUNCTION[MAX_FUNC_NAME],
LEVEL
}
new gCommands[MAX_COMMANDS][YS_COMMAND_FORMAT];*/
new gFuncNames[MAX_COMMANDS][MAX_FUNC_NAME];
#if !defined YS_ALT_NAMES_OFF
new gAltNames[MAX_COMMANDS][MAX_FUNC_NAME];
#endif
new gFuncLevels[MAX_COMMANDS];
new gFuncFunctions[MAX_COMMANDS][MAX_FUNC_NAME];
new gComSet = -1;
new gComCount = 0;
new gModules[MAX_MODULES][MAX_FUNC_NAME];
new gModNames[MAX_MODULES][MAX_STRING];
new gModCount = 0;
new gModHidden[MAX_MODULES];
new gDateFormat[12];
// Forward declarations for public functions
forward RegisterCommand(command[], function[], level);
forward AddModule(modname[], disname[], hidden);
forward RemoveModule(modname[]);
forward ComLevel(command[]);
forward SendClientMessageToLevel(level, color, msg[]);
forward SendFormattedMessage(playerid, color, text[]);
forward SendFormattedMessageToAll(color, text[]);
forward ReadINI(update);
forward GameFormattedMessage(playerid, text[], time, style);
forward GameFormattedMessageToAll(text[], time, style);
forward ProcessCall();
COMFOR(dcmd_commands)
COMFOR(dcmd_help)
COMFOR(dcmd_loadmod)
COMFOR(dcmd_unloadmod)
COMFOR(dcmd_listmod)
COMFOR(dcmd_reloadadmin)
COMFOR(dcmd_setlevel)
COMFOR(dcmd_reloadini)
#include "yadmincom.pwn"
public OnFilterScriptInit()
{
//RegisterCommand("commands", 8, "dcmd_commands", 13, 0);
REGISTER("commands", "dcmd_commands", 0) // command name, function name, level
REGISTER("help", "dcmd_help", 0)
REGISTER("unloadmodule", "dcmd_unloadmod", 5)
REGISTER("loadmodule", "dcmd_loadmod", 0)
REGISTER("listmodules", "dcmd_listmod", 0)
REGISTER("reloadself", "dcmd_reloadadmin", 0)
REGISTER("setlevel", "dcmd_setlevel", 0)
REGISTER("reloadini", "dcmd_reloadini", 0)
print("\n====================================");
print("| |");
print("| Y_Less's server script |");
print("| ------------------------ |");
print("| |");
print("| By Alex \"Y_Less\" Cole - (c) 2006 |");
print("| |");
print("====================================\n");
ReadINI(0);
//READINI // No others should exist!
SetTimer("ProcessCall", PROCESS_LOOP_DELAY, 1);
return 1;
}
public ReadINI(update)
{
new File:inifile;
static once = 0;
if (fexist(INI_NAME))
{
inifile = fopen(INI_NAME, io_read);
if (inifile)
{
new str[MAX_INI_LINE];
new group = 0;
while (fread(inifile, str))
{
// Read line first
if (str[0] == '[')
{
StripNL(str);
INI_GROUP(COMMANDLEVELS)
else INI_GROUP(ALTNAMES)
else INI_GROUP(SETTINGS)
else INI_GROUP(MODULES)
else __NONE__
}
else
{
switch (group)
{
case YS_INI_MODULES:
{
if (once) continue; // NEVER reload these!
INIT // Skips if this isn't a full read
StripNL(str);
if (str[0])
{
new com[MAX_STRING];
format(com, sizeof (com), "loadfs YSS_%s", str);
SendRconCommand(com);
}
}
case YS_INI_COMMANDLEVELS:
{
INIT
StripNL(str);
if (str[0])
{
new com[MAX_FUNC_NAME];
new i, j;
i = GetININame(com, str);
for (j = 0; j < sizeof (gFuncNames); j++)
{
if (strcmp(gFuncNames[j], com, true) == 0)
{
gFuncLevels[j] = strval(ReturnINIValue(str[i]));
//CallRemoteFunction("SetComLevel", "ii", j, strval(ReturnINIValue(str[i])));
break;
}
}
if (j == sizeof (gFuncNames)) printf("YSS warning: Could not find command for level: %s", com);
}
}
#if !defined YS_ALT_NAMES_OFF
case YS_INI_ALTNAMES:
{
StripNL(str);
if (str[0])
{
new com[MAX_FUNC_NAME];
new i, j;
i = GetININame(com, str);
while (str[i] == ' ' || str[i] == '=' || str[i] == '/') i++;
for (j = 0; j < sizeof (gFuncNames); j++)
{
if (strcmp(gFuncNames[j], com, true) == 0)
{
strmid(gAltNames[j], str, i, strlen(str));
break;
}
}
if (j == sizeof (gFuncNames)) printf("YSS warning: Could not find command for alt name: %s", com);
}
}
#endif
case YS_INI_SETTINGS:
{
INIT
INI_GET_B(CommandWarnings, YS_COMSET_USE_WARNINGS, 15, gComSet)
else INI_GET_S(DateFormat, gDateFormat, 10)
#if !defined YS_ALT_NAMES_OFF
else INI_GET_B(UseAltNames, YS_COMSET_USE_ALT, 11, gComSet)
#endif
#if !defined YS_USE_PREFIX_OFF
else INI_GET_B(UsePrefix, YS_COMSET_USE_PREFIX, 9, gComSet)
else if (strcmp(str, "Prefix", true, 6) == 0)
{
format(gPrefix, sizeof (gPrefix), "%s%s", strfind(str, "/", false, 6) == -1 ? "/" : "", ReturnINIValue(str[6]));
StripNL(gPrefix);
}
#endif
}
default:
{
}
}
}
}
if (update || once) goto end;
print("YSS message: Settings loaded");
}
else
{
print("YSS warning: Could not read ini file, default settings loaded");
}
}
else
{
print("YSS warning: Could not find ini file, default settings loaded");
}
once = 1;
end:
//firsttime = 1;
}
public OnFilterScriptExit()
{
new str[32];
for (new i = 0; i < MAX_MODULES; i++)
{
if (gModules[i][0] != 0)
{
format(str, sizeof (str), "unloadfs YSS_%s", gModules[i]);
SendRconCommand(str);
}
}
return 1;
}
/*public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
return 1;
}
public OnPlayerConnect(playerid)
{
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}*/
/*public OnPlayerText(playerid, text[])
{
SendRconCommand(text);
return 1;
}*/
/*public OnPlayerPrivmsg(playerid, senderid, text[])
{
return 0;
}*/
public OnPlayerCommandText(playerid, cmdtext[])
{
//printf("hi: %s", "1"); //comname("", 0));
//printf("hi: %s", comname("", 0));
//printf("hi: %s", "2"); //comname("", 0));
#if defined YS_USE_PREFIX_ON
new len = strlen(gPrefix);
if (strcmp(cmdtext, gPrefix, true, len) == 0 && ((cmdtext[len] == 32 && ProcessCommand(playerid, cmdtext[len + 1], 0)) || (cmdtext[len] == 0 && dcmd_commands(playerid, "", false)))) return 1;
#else
#if defined YS_USE_PREFIX_OFF
new len = 1;
if (ProcessCommand(playerid, cmdtext[1], 0)) return 1;
#else
new len = strlen(gPrefix);
new prefix = gComSet & YS_COMSET_USE_PREFIX ? 1 : 0;
if ((prefix ? (strcmp(cmdtext, gPrefix, true, len) == 0) : true) && (prefix ? (cmdtext[len] == 32 ? true : (cmdtext[len] == 0 && !dcmd_commands(playerid, "", false))) : true) && ProcessCommand(playerid, cmdtext[(prefix * len) + 1], 0)) return 1;
#endif
#endif
return 0;
}
/*public OnPlayerInfoChange(playerid)
{
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}*/
ProcessCommand(playerid, cmd[], help)
{
new len;
//new empty[1] = "";
for (new i = 0; i < gComCount; i++)
{
#if defined YS_ALT_NAMES_ON
if (gAltNames[i][0] ? (len = strlen(gAltNames[i])) && strcmp(cmd, gAltNames[i], true, len) == 0 : (len = strlen(gFuncNames[i])) && strcmp(cmd, gFuncNames[i], true, len) == 0)
{
// Command entered
if (gFuncLevels[i] <= CallRemoteFunction("YSGetUserLevel", "i", playerid))
{
if ((cmd[len] == 0 && CALLFUNCE) || (cmd[len] == 32 && CALLFUNC)) return 1;
}
else
{
if (gComSet & YS_COMSET_USE_WARNINGS)
{
SendFormattedMessage(playerid, 0xFF0000FF, "*** You cannot use that command");
}
}
break;
}
#else
#if defined YS_ALT_NAMES_OFF
len = strlen(gFuncNames[i]);
if (strcmp(cmd, gFuncNames[i], true, len) == 0) // return 1;
{
// Command entered
if (gFuncLevels[i] <= CallRemoteFunction("YSGetUserLevel", "i", playerid))
{
if ((cmd[len] == 0 && CALLFUNCE) || (cmd[len] == 32 && CALLFUNC)) return 1;
}
else
{
if (gComSet & YS_COMSET_USE_WARNINGS)
{
SendFormattedMessage(playerid, 0xFF0000FF, "*** You cannot use that command");
}
}
}
#else
if (((gComSet & YS_COMSET_USE_ALT) && (gAltNames[i][0] != 0)) ? (len = strlen(gAltNames[i])) && strcmp(cmd, gAltNames[i], true, len) == 0 : (len = strlen(gFuncNames[i])) && strcmp(cmd, gFuncNames[i], true, len) == 0)
{
// Command entered
if (gFuncLevels[i] <= CallRemoteFunction("YSGetUserLevel", "i", playerid))
{
//new funcname[MAX_STRING];
//funcname = GetFunction(i);
if ((cmd[len] == 0 && CALLFUNCE) || (cmd[len] == 32 && CALLFUNC)) return 1;
}
else
{
if (gComSet & YS_COMSET_USE_WARNINGS)
{
SendFormattedMessage(playerid, 0xFF0000AA, "*** You cannot use that command");
return 1;
}
}
}
#endif
#endif
}
return 0;
}
public RegisterCommand(command[], function[], level)
{
REQUIRE_STR(command)
REQUIRE_STR(function)
if (gComCount < MAX_COMMANDS)
{
//gFuncNames[gComCount] = "";
//gFuncFunctions[gComCount] = "";
//strcat(gFuncNames[gComCount], command); //, 0, cmdlen);
//strcat(gFuncFunctions[gComCount], function); //, 0, funclen);
strmid(gFuncNames[gComCount], command, 0, strlen(command), MAX_FUNC_NAME);
strmid(gFuncFunctions[gComCount], function, 0, strlen(function), MAX_FUNC_NAME);
gFuncLevels[gComCount] = level;
/*new i;
for (i = 0; i < cmdlen; i++)
{
gFuncNames[gComCount][i] = command[i]; //, 0, cmdlen);
//gFuncFunctions[gComCount][i] = function[i]; //, 0, funclen);
//printf("stuff: %d %d", gFuncNames[gComCount][i], gFuncFunctions[gComCount][i]);
}
for (i = 0; i < funclen; i++)
{
gFuncFunctions[gComCount][i] = function[i]; //, 0, cmdlen);
}
gFuncLevels[gComCount] = level;*/
gAltNames[gComCount][0] = 0;
gComCount++;
}
else return 0;
return 1;
}
public ComLevel(command[])
{
if ((command[0] & 0xFFFFFF00) || (command[0] == 1)) return -1;
// Custom REQUIRE_STRING ^ (for return -1)
for (new i = 0; i < MAX_COMMANDS; i++)
{
if (strcmp(command, gFuncNames[i]) == 0) return gFuncLevels[i];
}
return -1;
}
public SendClientMessageToLevel(level, color, msg[])
{
REQUIRE_STR(msg)
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i) && level <= CallRemoteFunction("YSGetUserLevel", "i", i)) SendFormattedMessage(i, color, msg);
}
return 1;
}
public AddModule(modname[], disname[], hidden)
{
REQUIRE_STR(modname)
REQUIRE_STR(disname)
if (gModCount < MAX_MODULES)
{
new i;
for (i = 0 ; i < MAX_MODULES; i++)
{
if (gModules[i][0] == 0) break;
}
strmid(gModules[i], modname, 0, strlen(modname), MAX_FUNC_NAME);
strmid(gModNames[i], disname, 0, strlen(disname), MAX_STRING);
gModHidden[i] = hidden;
gModCount++;
new str[48];
format(str, sizeof (str), "*** Module \"%s\" loaded as %d", modname, i);
SendClientMessageToLevel(ComLevel("loadmodule"), LG_MSG_COLOR, str);
}
else return 0;
return 1;
}
public RemoveModule(modname[])
{
REQUIRE_STR(modname)
new i;
for (i = 0; i < MAX_MODULES; i++)
{
if (gModules[i][0] == 0) continue;
if (strcmp(gModules[i], modname) == 0) break;
}
if (i == MAX_MODULES) return 0;
gModules[i][0] = 0;
gModNames[i][0] = 0;
gModHidden[i] = 0;
gModCount--;
new str[48];
format(str, sizeof (str), "*** Module %d (%s) unloaded", i, modname);
SendClientMessageToLevel(ComLevel("unloadmodule"), LG_MSG_COLOR, str);
return 1;
}
public GameFormattedMessage(playerid, text[], time, style)
{
REQUIRE_STR(text)
new str[MAX_STRING];
str = FormatFuncMessage(text);
GameTextForPlayer(playerid, str, time, style);
return 1;
}
public GameFormattedMessageToAll(text[], time, style)
{
REQUIRE_STR(text)
new str[MAX_STRING];
str = FormatFuncMessage(text);
GameTextForAll(str, time, style);
return 1;
}
public SendFormattedMessage(playerid, color, text[])
{
REQUIRE_STR(text)
new str[MAX_STRING];
str = FormatFuncMessage(text);
SendClientMessage(playerid, color, str);
return 1;
}
public SendFormattedMessageToAll(color, text[])
{
REQUIRE_STR(text)
new str[MAX_STRING];
str = FormatFuncMessage(text);
SendClientMessageToAll(color, str);
return 1;
}
FormatFuncMessage(text[])
{
new str[MAX_STRING];
new index = 0, point = 0, i = 0;
while ((index = strfind(text, "%n", false, index)) != -1)
{
for ( ; point < index; point++, i++)
{
str[i] = text[point];
}
index += 2;
format(str, sizeof (str), "%s%s", str, comname(strtok2(text, index)));
point = index;
i = strlen(str);
}
index = strlen(text);
for ( ; point < index; point++, i++)
{
str[i] = text[point];
}
return str;
}
/*GetCommand(i)
{
new str[MAX_STRING] = "";
new j, k;
printf("%d, %d", i, gFuncNames[i][0]);
for (j = 0, k = strlen(gFuncNames[i]); j < k; j++)
{
str[j] = gFuncNames[i][j];
}
str[j] = 0;
printf("command: %s %s :yeah", str, gFuncNames[i]);
return str;
}
#if !defined YS_ALT_NAMES_OFF
GetAltName(i)
{
new str[MAX_STRING] = "";
new j, k;
for (j = 0, k = strlen(gAltNames[i]); j < k; j++)
{
str[j] = gAltNames[i][j];
}
str[j] = 0;
return str;
}
#endif
GetFunction(i)
{
new str[MAX_STRING] = "";
new j, k;
for (j = 0, k = strlen(gFuncFunctions[i]); j < k; j++)
{
str[j] = gFuncFunctions[i][j];
}
str[j] = 0;
return str;
}*/
strtok2(string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] < '0')) // Delimit by any things
{
index++; // Strip leading spaces
}
new offset = index;
new result[32];
while ((index < length) && (string[index] >= '0') && ((index - offset) < (sizeof (result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
/*while ((index < length) && (string[index] <= ' '))
{
index++; // Strip trailing spaces (required now)
}*/
return result;
}
public ProcessCall()
{
PROCESS
}