mirror of
https://github.com/ChocoTaco1/TacoServer.git
synced 2026-01-20 00:24:49 +00:00
Remote Unbanning
This commit is contained in:
parent
3d876eb0de
commit
4d7cc2cc55
230
Classic/scripts/autoexec/dtBanSystem.cs
Executable file → Normal file
230
Classic/scripts/autoexec/dtBanSystem.cs
Executable file → Normal file
|
|
@ -11,12 +11,12 @@
|
|||
//$dtBanList::GUID3555379 = "4\t2021\t18\t31\t518400";
|
||||
|
||||
//TO UNBAN SOMEONE WITHOUT RESTARTING THE SERVER
|
||||
//unban(%guid,%ip); in console
|
||||
//banList();in console
|
||||
//unbanIndex(%index) %index is the number next to the players name from listBans();
|
||||
//Example: unban(555555,"22.222.222.222"); put ip in quotes
|
||||
|
||||
package dtBan
|
||||
{
|
||||
|
||||
function ClassicLoadBanlist()
|
||||
{
|
||||
$ClassicPermaBans = 0;
|
||||
|
|
@ -30,21 +30,35 @@ function BanList::add(%guid, %ipAddress, %time){
|
|||
if(%time > 999999){
|
||||
%time = "BAN";
|
||||
}
|
||||
%name = getClientBanName(%guid, %ipAddress);
|
||||
if (%guid > 0){
|
||||
$dtBanList::GUID[%guid] = dtBanMark() TAB %time;
|
||||
$dtBanList::GUID[%guid] = dtBanMark() TAB %time TAB %name;
|
||||
}
|
||||
if (getSubStr(%ipAddress, 0, 3) $= "IP:"){
|
||||
// add IP ban
|
||||
%bareIP = getSubStr(%ipAddress, 3, strLen(%ipAddress));
|
||||
%bareIP = getSubStr(%bareIP, 0, strstr(%bareIP, ":"));
|
||||
%bareIP = strReplace(%bareIP, ".", "_"); // variable access bug workaround
|
||||
|
||||
$dtBanList::IP[%bareIP] = dtBanMark() TAB %time;
|
||||
//error("ban" SPC %bareIP SPC $dtBanList::IP[%bareIP]);
|
||||
// add IP ban
|
||||
$dtBanList::IP[%bareIP] = dtBanMark() TAB %time TAB %name;
|
||||
}
|
||||
%found = 0;
|
||||
for (%i = 0; %i < $dtBanList::NameListCount; %i++){
|
||||
if(getField($dtBanList::NameList[%i], 0) $= %name){
|
||||
%found =1;
|
||||
if(%guid > 0)
|
||||
$dtBanList::NameList[%i] = setField($dtBanList::NameList[%i], 1, %guid);
|
||||
if(getSubStr(%ipAddress, 0, 3) $= "IP:")
|
||||
$dtBanList::NameList[%i] = setField($dtBanList::NameList[%i], 2, %bareIP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!%found){
|
||||
$dtBanList::NameListCount = ($dtBanList::NameListCount > 0) ? $dtBanList::NameListCount : 0;
|
||||
$dtBanList::NameList[$dtBanList::NameListCount] = %name TAB %guid TAB %bareIP;
|
||||
$dtBanList::NameListCount++;
|
||||
}
|
||||
|
||||
// write out the updated bans to the file
|
||||
export("$dtBanList*", $Host::dtBanlist);
|
||||
saveBanList();
|
||||
}
|
||||
|
||||
function banList_checkIP(%client){
|
||||
|
|
@ -56,14 +70,19 @@ function banList_checkIP(%client){
|
|||
%time = $dtBanList::IP[%ip];
|
||||
if(%time $= "BAN")
|
||||
return 1;
|
||||
if (%time !$= "" && %time != 0){
|
||||
if (getFieldCount(%time) > 0){
|
||||
%delta = getBanCount(getField(%time,0), getField(%time,1),getField(%time,2),getField(%time,3));
|
||||
if (%delta < getField(%time,4))
|
||||
return 1;
|
||||
else{
|
||||
for (%i = 0; %i < $dtBanList::NameListCount; %i++){
|
||||
if(getField($dtBanList::NameList[%i], 2) $= %ip){
|
||||
unbanIndex(%i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$dtBanList::IP[%ip] = "";
|
||||
schedule(1000,0,"export","$dtBanList*", $Host::dtBanlist);
|
||||
//export("$dtBanList*", "prefs/dtBanlist.cs");
|
||||
saveBanList();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -73,14 +92,19 @@ function banList_checkGUID(%guid){
|
|||
%time = $dtBanList::GUID[%guid];
|
||||
if(%time $= "BAN")
|
||||
return 1;
|
||||
if (%time !$= "" && %time != 0){
|
||||
if (getFieldCount(%time) > 0){
|
||||
%delta = getBanCount(getField(%time,0), getField(%time,1),getField(%time,2),getField(%time,3));
|
||||
if (%delta < getField(%time,4))
|
||||
return 1;
|
||||
else{
|
||||
$dtBanList::GUID[%guid] = "";
|
||||
schedule(500,0,"export","$dtBanList*", $Host::dtBanlist);
|
||||
//export("$dtBanList*", "prefs/dtBanlist.cs");
|
||||
for (%i = 0; %i < $dtBanList::NameListCount; %i++){
|
||||
if(getField($dtBanList::NameList[%i], 1) $= %guid){
|
||||
unbanIndex(%i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$dtBanList::GUID[%guid] = "";
|
||||
saveBanList();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -88,31 +112,63 @@ function banList_checkGUID(%guid){
|
|||
|
||||
};
|
||||
|
||||
if (!isActivePackage(dtBan))
|
||||
if (!isActivePackage(dtBan)){
|
||||
activatePackage(dtBan);
|
||||
}
|
||||
|
||||
function saveBanList(){
|
||||
if(!isEventPending($banEvent))
|
||||
$banEvent = schedule(1000,0,"export","$dtBanList*", $Host::dtBanlist);
|
||||
}
|
||||
function getClientBanName(%guid, %ip){
|
||||
%found = 0;
|
||||
for (%i = 0; %i < ClientGroup.getCount(); %i++){
|
||||
%client = ClientGroup.getObject(%i);
|
||||
if(%guid > 0 && %client.guid $= %guid){
|
||||
%found = 1;
|
||||
break;
|
||||
}
|
||||
else if(%client.getAddress() $= %ip){
|
||||
%found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(%found){
|
||||
%authInfo = %client.getAuthInfo();
|
||||
%realName = getField( %authInfo, 0 );
|
||||
if(%realName !$= "")
|
||||
%name = %realName;
|
||||
else
|
||||
%name = stripChars( detag( getTaggedString( %client.name ) ), "\cp\co\c6\c7\c8\c9\c0" );
|
||||
return trim(%name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getBanCount(%d, %year, %h, %n){
|
||||
%dif = formattimestring("yy") - %year;
|
||||
%days += 365 * (%dif-1);
|
||||
%days += 365 - %d;
|
||||
%days += dtBanDay();
|
||||
%ht = %nt = 0;
|
||||
if(formattimestring("H") > %h){
|
||||
%ht = formattimestring("H") - %h;
|
||||
if(%d && %year && %h && %n){
|
||||
%dif = formattimestring("yy") - %year;
|
||||
%days += 365 * (%dif-1);
|
||||
%days += 365 - %d;
|
||||
%days += dtBanDay();
|
||||
%ht = %nt = 0;
|
||||
if(formattimestring("H") > %h){
|
||||
%ht = formattimestring("H") - %h;
|
||||
}
|
||||
else if(formattimestring("H") < %h){
|
||||
%ht = 24 - %h;
|
||||
%ht = formattimestring("H")+ %ht;
|
||||
}
|
||||
if(formattimestring("n") > %n){
|
||||
%nt = formattimestring("n") - %n;
|
||||
}
|
||||
else if(formattimestring("n") < %n){
|
||||
%nt = 60 - %n;
|
||||
%nt = formattimestring("n") + %nt;
|
||||
}
|
||||
return mfloor((%days * 1440) + (%ht*60) + %nt);
|
||||
}
|
||||
else if(formattimestring("H") < %h){
|
||||
%ht = 24 - %h;
|
||||
%ht = formattimestring("H")+ %ht;
|
||||
}
|
||||
if(formattimestring("n") > %n){
|
||||
%nt = formattimestring("n") - %n;
|
||||
}
|
||||
else if(formattimestring("n") < %n){
|
||||
%nt = 60 - %n;
|
||||
%nt = formattimestring("n") + %nt;
|
||||
}
|
||||
return mfloor((%days * 1440) + (%ht*60) + %nt);
|
||||
return 0;
|
||||
//return mfloor((%days * 1440) + (%ht*60) + %nt) TAB (%days * 1440) TAB (%ht*60) TAB %nt;
|
||||
}
|
||||
|
||||
|
|
@ -146,15 +202,109 @@ function dtBanMark(){
|
|||
return %count + %d TAB formattimestring("yy") TAB formattimestring("H") TAB formattimestring("n");
|
||||
}
|
||||
|
||||
function unban(%guid,%ip){
|
||||
function banList(){
|
||||
$dtBanList::NameListCount = ($dtBanList::NameListCount > 0) ? $dtBanList::NameListCount : 0;
|
||||
if(!$dtBanList::NameListCount){
|
||||
error("No bans, see" SPC $Host::dtBanlist SPC "for older system entries");
|
||||
}
|
||||
else{
|
||||
for (%i = 0; %i < $dtBanList::NameListCount; %i++){
|
||||
%fieldList = $dtBanList::NameList[%i];
|
||||
error("index:" @ %i SPC "Name:" @ getField(%fieldList,0) SPC "GUID:" @ getField(%fieldList,1) SPC "IP:" @ getField(%fieldList,2));
|
||||
}
|
||||
if($dtBanList::NameListCount > 0){
|
||||
error("Use unbanIndex(%index); to unban user from the list ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function unbanIndex(%index){
|
||||
%fieldList = $dtBanList::NameList[%index];
|
||||
%name = getField(%fieldList, 0);
|
||||
if(getFieldCount(%fieldList) > 1){
|
||||
for(%i = %index; %i < $dtBanList::NameListCount -1; %i++) {
|
||||
$dtBanList::NameList[%i] =$dtBanList::NameList[%i+1];
|
||||
}
|
||||
$dtBanList::NameList[%i] = "";
|
||||
$dtBanList::NameListCount--;
|
||||
error("Name" SPC getField(%fieldList,0) SPC "UNBANNED");
|
||||
%guid = getField(%fieldList,1);
|
||||
if($dtBanList::GUID[%guid] !$= ""){
|
||||
$dtBanList::GUID[%guid] = "";
|
||||
error("GUID" SPC %guid SPC "UNBANNED");
|
||||
}
|
||||
%ip = getField(%fieldList,2);
|
||||
if($dtBanList::IP[%ip] !$= ""){
|
||||
$dtBanList::IP[%ip] = "";
|
||||
error("IP" SPC %ip SPC "UNBANNED");
|
||||
}
|
||||
}
|
||||
else{
|
||||
for(%i = %index; %i < $dtBanList::NameListCount -1; %i++) {
|
||||
$dtBanList::NameList[%i] =$dtBanList::NameList[%i+1];
|
||||
}
|
||||
$dtBanList::NameList[%i] = "";
|
||||
$dtBanList::NameListCount--;
|
||||
error("Error removing invalid index");
|
||||
}
|
||||
saveBanList();
|
||||
return %name;
|
||||
}
|
||||
|
||||
|
||||
function banListClean(){
|
||||
%count = 0;
|
||||
for(%i = 0; %i < $dtBanList::NameListCount; %i++) {
|
||||
%ban = 1;
|
||||
%banField = $dtBanList::NameList[%i];
|
||||
%guid = getField(%banField,1);
|
||||
%ip = getField(%banField,2);
|
||||
|
||||
%time = $dtBanList::IP[%ip];
|
||||
if(%time !$= "BAN" && getFieldCount(%time) > 0){
|
||||
%delta = getBanCount(getField(%time,0), getField(%time,1),getField(%time,2),getField(%time,3));
|
||||
if (%delta > getField(%time,4)){
|
||||
$dtBanList::IP[%ip] = "";
|
||||
%ban = 0;
|
||||
}
|
||||
}
|
||||
|
||||
%time = $dtBanList::GUID[%guid];
|
||||
if(%time !$= "BAN" && getFieldCount(%time) > 0){
|
||||
%delta = getBanCount(getField(%time,0), getField(%time,1),getField(%time,2),getField(%time,3));
|
||||
if (%delta > getField(%time,4)){
|
||||
$dtBanList::GUID[%guid] = "";
|
||||
%ban = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(%banField !$= "" && %ban){
|
||||
%tempList[%count] = %banField;
|
||||
%count++;
|
||||
}
|
||||
}
|
||||
for(%i = 0; %i < %count; %i++) {
|
||||
$dtBanList::NameList[%i] = %tempList[%i];
|
||||
}
|
||||
$dtBanList::NameListCount = %count;
|
||||
}
|
||||
|
||||
//old method
|
||||
function unbanold(%guid,%ip){
|
||||
%ip = strReplace(%ip, ".", "_");
|
||||
for (%i = 0; %i < $dtBanList::NameListCount; %i++){
|
||||
if(getField($dtBanList::NameList[%i], 2) $= %ip || getField($dtBanList::NameList[%i], 1) $= %guid){
|
||||
unbanIndex(%i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if($dtBanList::GUID[%guid] !$= ""){
|
||||
$dtBanList::GUID[%guid] = "";
|
||||
error("GUID" SPC %guid SPC "UNBANNED");
|
||||
}
|
||||
%ip = strReplace(%ip, ".", "_");
|
||||
if($dtBanList::IP[%ip] !$= ""){
|
||||
$dtBanList::IP[%ip] = "";
|
||||
error("IP" SPC %ip SPC "UNBANNED");
|
||||
}
|
||||
export("$dtBanList*", $Host::dtBanlist);
|
||||
}
|
||||
saveBanList();
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
//exec("scripts/autoexec/zzDiscordBot.cs");
|
||||
|
||||
//ip of the bot
|
||||
$discordBot::IP = "";
|
||||
$discordBot::IP = "127.0.0.1:28003";
|
||||
$discordBot::reconnectTimeout = 3 * 60000;
|
||||
//auto connect on start
|
||||
$discordBot::autoStart = 0;
|
||||
|
|
@ -203,7 +203,6 @@ function discordBotProcess(%type, %var1, %var2, %var3, %var4, %var5, %var6)
|
|||
sendToDiscordEmote(%msg, $discordBot::serverFeed);
|
||||
}
|
||||
}
|
||||
|
||||
function sendToDiscord(%msg,%channel)
|
||||
{
|
||||
if(isObject(discord) && %msg !$= "")
|
||||
|
|
@ -353,6 +352,33 @@ function discord::onLine(%this, %line){
|
|||
discord.schedule((%i+1)*32,"send","PROCSTACK" @ $discordBot::cmdSplit @ ($discordBot::monitorChannel) @ $discordBot::cmdSplit @ "msgList" @ "\r\n");
|
||||
}
|
||||
}
|
||||
case "BANLIST":
|
||||
if($dtBanList::NameListCount){
|
||||
for (%i = 0; %i < $dtBanList::NameListCount; %i++){
|
||||
%fieldList = $dtBanList::NameList[%i];
|
||||
%msg = "Index:" @ %i SPC "Name:" @ getField(%fieldList,0) SPC "GUID:" @ getField(%fieldList,1) SPC "IP:" @ getField(%fieldList,2);
|
||||
discord.schedule(%i*32,"send","MSGSTACK" @ $discordBot::cmdSplit @ ($discordBot::monitorChannel) @ $discordBot::cmdSplit @ %msg @ "\r\n");
|
||||
}
|
||||
discord.schedule((%i+1)*32,"send","PROCSTACK" @ $discordBot::cmdSplit @ ($discordBot::monitorChannel) @ $discordBot::cmdSplit @ "banList" @ "\r\n");
|
||||
}
|
||||
else{
|
||||
sendToDiscord("No active bans, see ban file for manual/older entries", $discordBot::monitorChannel);
|
||||
}
|
||||
case "UNBANINDEX":
|
||||
%var = getWord(%lineStrip,1);
|
||||
if(%var < $dtBanList::NameListCount){
|
||||
%name = unbanIndex(%var);
|
||||
if(%name !$= ""){
|
||||
sendToDiscord("User:" @ %name SPC "has been unbanned", $discordBot::monitorChannel);
|
||||
}
|
||||
else{
|
||||
sendToDiscord("Index Removed", $discordBot::monitorChannel);
|
||||
}
|
||||
}
|
||||
else{
|
||||
sendToDiscord("Invalid Index", $discordBot::monitorChannel);
|
||||
}
|
||||
|
||||
default:
|
||||
error("Discord Bad Command" SPC %line);
|
||||
}
|
||||
|
|
@ -482,4 +508,5 @@ function pathMapData(){ //loop to collect player position data
|
|||
error("Player Plot Tracking Has Ended");
|
||||
sendPrx(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue