Custom
Server
Command
System is intended to replace Munk's Server Pack and allow for much greater modularity over MSP.
CSCS allows server hosts to add (or remove) drop-in commands created by them or other players. Commands remain separate from each other in their own respective script to allow for easier editing/updating and more specific detection of errors if need be.
It is also much easier for non TGE-savvy players to add commands, as it functions like the add-on system. Simply placing a script in
config/server/CSCS/cmds and running
/restartcscs on the server will allow it to be used. Removing a script obviously will remove it from CSCS listings.
TODO: null a removed commandThe system also allows easier editing of permissions for these commands as each command is given a permission limit in a prefs.cs file (by default at
config/server/CSCS/prefs.cs), or by editing
$Pref::CSCS::Allow[command]Command variables on the server.
Each time a command is used, it can also optionally be logged, both on successes and failures.
TODO: Server_Permissions support? idkCSCS formatOnly
//COMMAND and its first field,
//LIMIT, and
//enabled are required metadata, as the CSCS core needs these for commands to function correctly.
Setting
//enabled to something else will disable the addon from being executed upon initialization (or reinitialization) of CSCS scripts.
//COMMAND^command^arg1 describe;arg2 the;arg3 arguments
//AUTHOR^name^bl_id
//INFO^describe the command
//LIMIT^host (3), super admin (2), admin (1), none (0) [see server.cs for alternate names, e.g. H, SA, RA, etc.]
//enabled^ denotes a field (TAB)Included CSCS functionsGameConnection::isHost(%this) -- Checks if the client is the host
GameConnection::isCSCSAllowed(%this,%var,%silent) -- Checks to see if the client can use the command specified (%var would be
$Pref::CSCS::Allow[command]Command variables)
GameConnection::checkCSCSCommandSpam(%this) -- Checks to make sure the client isn't spamming commands
GameConnection::CSCSError(%this,%msg) -- Gives the client a chat message denoting an error in your command (see
slap.cs below)
GameConnection::logCSCSCommand(%this,%cmd,%args,%success) -- Logs the command a client triggered (%args would be a space separated list or etc.). The logs are actually CSV files, but are named with the .txt extension to allow for viewing in most text editors without any hassle.
Example CSCS command scriptscmds/dfg.cs//COMMAND dfg
//AUTHOR TheBlackParrot 18701
//INFO Randomizes all of your bricks' color
//LIMIT none
//enabled
$Pref::CSCS::DFGLimit = 10000; // extra prefs CAN be defined and exported, the CSCS core takes care of exporting
function serverCmdDFG(%this) {
if(!%this.isCSCSAllowed($Pref::CSCS::AllowDFGCommand)) {
// this if statement will check to see if the player is allowed to use the command
// $Pref::CSCS::Allow[command]Command is the syntax
%this.logCSCSCommand("dfg","",0);
return;
}
if(!%this.checkCSCSCommandSpam()) {
// built in spam checker, this applies to all commands that have this if statement
return;
}
// logs that the user could use the command
%this.logCSCSCommand("dfg","",1);
%group = "BrickGroup_" @ %this.bl_id;
if(%this.isAdmin || %group.getCount < $Pref::CSCS::DFGLimit) {
%count = %group.getCount();
} else {
%count = $Pref::CSCS::DFGLimit;
}
for(%i=0;%i<%count;%i++) {
%brick = %group.getObject(%i);
if(%brick.originColor $= "") {
%brick.originColor = %brick.colorID;
}
%brick.setColor(getRandom(0,4));
}
}
cmds/list.cs//COMMAND cmds
//AUTHOR TheBlackParrot 18701
//INFO Lists all available CSCS commands
//LIMIT none
//enabled
function serverCmdCmds(%this) {
if(!%this.isCSCSAllowed($Pref::CSCS::AllowResetCommand)) {
%this.logCSCSCommand("cmds","",0);
return;
}
if(!%this.checkCSCSCommandSpam()) {
return;
}
%this.logCSCSCommand("cmds","",1);
messageClient(%this,'',"\c4Command list:");
for(%i=0;%i<$CSCS::CommandCount;%i++) {
%args = "";
%arg = "";
%argstr = "";
%name = $CSCS::Command[%i,name] @ "Command";
%val = $Pref::CSCS::Allow[%name];
if(%this.isCSCSAllowed(%val,1)) {
%c++;
%args = $CSCS::Command[%i,args];
while(strLen(%args)) {
if(stripos(%args,";") != -1) {
%arg = getSubStr(%args,0,stripos(%args,";"));
} else {
%arg = %args;
}
if(%argstr $= "") {
%argstr = "[" @ %arg @ "]";
} else {
%argstr = %argstr SPC "[" @ %arg @ "]";
}
if(stripos(%args,";") != -1) {
%args = getSubStr(%args,stripos(%args,";")+1,strLen(%args));
} else {
%args = "";
}
}
%argstr = "\c5" @ %argstr @ " ";
switch(%val) {
case 0:
%limitstr = "";
case 1:
%limitstr = "<color:aaaaaa>(Admin)";
case 2:
%limitstr = "<color:ffbb00>(Super Admin)";
case 3:
%limitstr = "<color:00ffff>(Host)";
}
messageClient(%this,'',"\c2" @ %c @ ". \c3/" @ $CSCS::Command[%i,name] SPC %argstr @ "\c7--\c6" SPC $CSCS::Command[%i,desc] SPC %limitstr);
}
}
}
function serverCmdCommands(%this) { serverCmdCmds(%this); }
function serverCmdCSCS(%this) { serverCmdCmds(%this); }
function serverCmdCmdList(%this) { serverCmdCmds(%this); }
cmds/slap.cs//COMMAND slap player or id
//AUTHOR TheBlackParrot 18701
//INFO Moves players out of the way
//LIMIT admin
//enabled
function serverCmdSlap(%this,%target) {
if(!%this.isCSCSAllowed($Pref::CSCS::AllowSlapCommand)) {
%this.logCSCSCommand("slap",%target,0);
return;
}
if(!%this.checkCSCSCommandSpam()) {
return;
}
%targetObject = findClientByName(%target);
if(!isObject(%targetObject)) {
%targetObject = findClientByBL_ID(%targetObject);
if(!isObject(%targetObject)) {
%this.CSCSError(%target SPC "does not exist!");
return;
}
}
if(!isObject(%targetObject.player)) {
%this.CSCSError(%targetObject.name SPC "has not spawned!");
return;
}
%this.logCSCSCommand("slap",%target,1);
messageClient(%targetObject,'',"\c3" @ %this.name SPC "\c6slapped you!");
%targetObject.play2D(CSCS_slap);
messageClient(%this,'',"\c6You have slapped\c3" SPC %targetObject.name);
%targetObject.player.addVelocity(getRandom(-20,20) SPC getRandom(-20,20) SPC getRandom(0,20));
}
I'm open to suggestions on things to add (wrappers for common, simple multi-line functions would be great too), feel free to mess around with it!