mirror of
https://github.com/imayushsaini/Bombsquad-Ballistica-Modded-Server.git
synced 2025-10-20 00:00:39 +00:00
updated ban command
This commit is contained in:
parent
7f11eca20b
commit
79aaf7a48b
5 changed files with 80 additions and 9 deletions
|
|
@ -219,7 +219,7 @@ def ban(arguments):
|
|||
ac_id=""
|
||||
for ros in ba.internal.get_game_roster():
|
||||
if ros["client_id"]==cl_id:
|
||||
_thread.start_new_thread(pdata.ban_player,(ros['account_id'],))
|
||||
pdata.ban_player(ros['account_id'])
|
||||
|
||||
ac_id=ros['account_id']
|
||||
if ac_id in serverdata.clients:
|
||||
|
|
|
|||
11
dist/ba_root/mods/playersData/blacklist.json
vendored
Normal file
11
dist/ba_root/mods/playersData/blacklist.json
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"ban": {
|
||||
"ids": [
|
||||
],
|
||||
"ips": [
|
||||
],
|
||||
"deviceids": [
|
||||
]
|
||||
},
|
||||
"muted-ids": []
|
||||
}
|
||||
52
dist/ba_root/mods/playersData/pdata.py
vendored
52
dist/ba_root/mods/playersData/pdata.py
vendored
|
|
@ -16,7 +16,7 @@ from tools.file_handle import OpenJson
|
|||
import _ba
|
||||
import ba.internal
|
||||
import json
|
||||
|
||||
import datetime
|
||||
if TYPE_CHECKING:
|
||||
pass
|
||||
|
||||
|
|
@ -34,6 +34,7 @@ class CacheData: # pylint: disable=too-few-public-methods
|
|||
custom: dict = {}
|
||||
profiles: dict = {}
|
||||
whitelist: list[str] = []
|
||||
blacklist: dict = {}
|
||||
|
||||
|
||||
def get_info(account_id: str) -> dict | None:
|
||||
|
|
@ -65,8 +66,12 @@ def get_profiles() -> dict:
|
|||
"""
|
||||
if CacheData.profiles=={}:
|
||||
try:
|
||||
f=open(PLAYERS_DATA_PATH + "profiles.json","r")
|
||||
profiles = json.load(f)
|
||||
if os.stat(PLAYERS_DATA_PATH+"profiles.json").st_size > 1000:
|
||||
shutil.copyfile(PLAYERS_DATA_PATH + "profiles.json",PLAYERS_DATA_PATH + "profiles.json"+str(datetime.datetime.now()))
|
||||
profiles = {"pb-sdf":{}}
|
||||
else:
|
||||
f=open(PLAYERS_DATA_PATH + "profiles.json","r")
|
||||
profiles = json.load(f)
|
||||
CacheData.profiles=profiles
|
||||
f.close()
|
||||
except:
|
||||
|
|
@ -78,6 +83,27 @@ def get_profiles() -> dict:
|
|||
else:
|
||||
return CacheData.profiles
|
||||
|
||||
def get_blacklist() -> dict:
|
||||
if CacheData.blacklist == {}:
|
||||
try:
|
||||
f = open(PLAYERS_DATA_PATH + "blacklist.json","r")
|
||||
CacheData.blacklist = json.load(f)
|
||||
except:
|
||||
print('error opening blacklist json')
|
||||
return {
|
||||
"ban":{
|
||||
"ids":[],
|
||||
"ips":[],
|
||||
"deviceids":[]
|
||||
},
|
||||
"muted-ids":[]
|
||||
}
|
||||
|
||||
return CacheData.blacklist
|
||||
|
||||
def update_blacklist():
|
||||
with open(PLAYERS_DATA_PATH + "blacklist.json","w") as f:
|
||||
json.dump(CacheData.blacklist,f,indent=4)
|
||||
|
||||
def commit_profiles(data={}) -> None:
|
||||
"""Commits the given profiles in the database.
|
||||
|
|
@ -141,6 +167,9 @@ def add_profile(
|
|||
device_id = _ba.get_client_public_device_uuid(cid)
|
||||
if(device_id==None):
|
||||
device_id = _ba.get_client_device_uuid(cid)
|
||||
if device_id in get_blacklist()["ban"]["deviceids"]:
|
||||
serverdata.clients[account_id]["isBan"]=True
|
||||
ba.internal.disconnect_client(cid)
|
||||
serverdata.clients[account_id]["deviceUUID"] = device_id
|
||||
|
||||
|
||||
|
|
@ -213,8 +242,21 @@ def ban_player(account_id: str) -> None:
|
|||
if account_id in profiles:
|
||||
profiles[account_id]["isBan"] = True
|
||||
CacheData.profiles=profiles
|
||||
_thread.start_new_thread(commit_profiles, (profiles,))
|
||||
# _thread.start_new_thread(commit_profiles, (profiles,))
|
||||
cid = -1
|
||||
for ros in ba.internal.get_game_roster():
|
||||
if ros['account_id'] == account_id:
|
||||
cid = ros['client_id']
|
||||
ip = _ba.get_client_ip(cid)
|
||||
|
||||
device_id = _ba.get_client_public_device_uuid(cid)
|
||||
if(device_id==None):
|
||||
device_id = _ba.get_client_device_uuid(cid)
|
||||
CacheData.blacklist["ban"]["ips"].append(ip)
|
||||
|
||||
CacheData.blacklist["ban"]["ids"].append(account_id)
|
||||
CacheData.blacklist["ban"]["deviceids"].append(device_id)
|
||||
_thread.start_new_thread(update_blacklist,())
|
||||
|
||||
def mute(account_id: str) -> None:
|
||||
"""Mutes the player.
|
||||
|
|
@ -602,5 +644,5 @@ def dump_cache():
|
|||
custom= copy.deepcopy(CacheData.custom)
|
||||
with open(PLAYERS_DATA_PATH + "custom.json", "w") as f:
|
||||
json.dump(custom, f, indent=4)
|
||||
time.sleep(20)
|
||||
time.sleep(60)
|
||||
dump_cache()
|
||||
|
|
|
|||
7
dist/ba_root/mods/tools/logger.py
vendored
7
dist/ba_root/mods/tools/logger.py
vendored
|
|
@ -9,7 +9,7 @@ from typing import TYPE_CHECKING
|
|||
from dataclasses import dataclass, field
|
||||
|
||||
import os
|
||||
import datetime
|
||||
import datetime,shutil
|
||||
import threading
|
||||
import setting
|
||||
import _ba
|
||||
|
|
@ -92,7 +92,10 @@ class dumplogs(threading.Thread):
|
|||
log_path = SERVER_DATA_PATH + "cmndusage.log"
|
||||
else:
|
||||
log_path = SERVER_DATA_PATH + "logs.log"
|
||||
|
||||
if os.path.exists(log_path):
|
||||
if os.stat(log_path).st_size > 1000:
|
||||
shutil.copy(log_path, log_path+str(datetime.datetime.now()))
|
||||
os.remove(log_path)
|
||||
with open(log_path, mode="a+", encoding="utf-8") as file:
|
||||
for msg in self.msg:
|
||||
file.write(msg)
|
||||
|
|
|
|||
17
dist/ba_root/mods/tools/servercheck.py
vendored
17
dist/ba_root/mods/tools/servercheck.py
vendored
|
|
@ -18,8 +18,9 @@ import setting
|
|||
import _thread
|
||||
from tools import logger
|
||||
from features import profanity
|
||||
from playersData import pdata
|
||||
|
||||
|
||||
blacklist = pdata.get_blacklist()
|
||||
|
||||
settings = setting.get_settings_data()
|
||||
|
||||
|
|
@ -88,6 +89,7 @@ def on_player_join_server(pbid, player_data):
|
|||
for ros in ba.internal.get_game_roster():
|
||||
if ros["account_id"] == pbid:
|
||||
clid = ros["client_id"]
|
||||
|
||||
if pbid in serverdata.clients:
|
||||
rejoinCount = serverdata.clients[pbid]["rejoincount"]
|
||||
spamCount = serverdata.clients[pbid]["spamCount"]
|
||||
|
|
@ -126,6 +128,8 @@ def on_player_join_server(pbid, player_data):
|
|||
return
|
||||
else:
|
||||
if pbid not in serverdata.clients:
|
||||
if check_ban(clid,pbid):
|
||||
return
|
||||
serverdata.clients[pbid] = player_data
|
||||
serverdata.clients[pbid]["warnCount"] = 0
|
||||
serverdata.clients[pbid]["lastWarned"] = time.time()
|
||||
|
|
@ -175,6 +179,17 @@ def on_player_join_server(pbid, player_data):
|
|||
|
||||
# pdata.add_profile(pbid,d_string,d_string)
|
||||
|
||||
def check_ban(clid,pbid):
|
||||
ip = _ba.get_client_ip(clid)
|
||||
|
||||
device_id = _ba.get_client_public_device_uuid(clid)
|
||||
if(device_id==None):
|
||||
device_id = _ba.get_client_device_uuid(clid)
|
||||
if (ip in blacklist["ban"]['ips'] or device_id in blacklist['ban']['deviceids'] or pbid in blacklist["ban"]["ids"]):
|
||||
_ba.chatmessage('sad ,your account is flagged contact server owner for unban',clients=[clid])
|
||||
ba.internal.disconnect_client(clid)
|
||||
return True
|
||||
return False
|
||||
|
||||
def verify_account(pb_id, p_data):
|
||||
d_string = ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue