Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added !sk and randommap (Sourcery refactored) #135

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 69 additions & 13 deletions spunky.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@
'ts': {'desc': 'change gametype to Team Survivor', 'syntax': '^7Usage: ^2!ts', 'level': 90},
'ungroup': {'desc': 'remove admin level from a player', 'syntax': '^7Usage: ^2!ungroup ^7<name>', 'level': 90},
'password': {'desc': 'set private server password', 'syntax': '^7Usage: ^2!password ^7[<password>]', 'level': 90},
##SK
'sk':{'desc':'shuffle teams to match skill level','syntax':'^7Usage: ^2!sk', 'level':90},
##rmap
'rmap':{'desc':'changes the current map to a randomly selected one from the maplist','syntax':'^7Usage: ^2!rmap','level':90},
'reload': {'desc': 'reload map', 'syntax': '^7Usage: ^2!reload', 'level': 90}}

REASONS = {'obj': 'go for objective',
Expand Down Expand Up @@ -237,29 +241,22 @@ def __init__(self):
self.admin_cmds.append(key)
self.fulladmin_cmds.append(key)
self.senioradmin_cmds.append(key)
self.superadmin_cmds.append(key)
elif value['level'] == 40:
self.admin_cmds.append(key)
self.fulladmin_cmds.append(key)
self.senioradmin_cmds.append(key)
self.superadmin_cmds.append(key)
elif value['level'] == 60:
self.fulladmin_cmds.append(key)
self.senioradmin_cmds.append(key)
self.superadmin_cmds.append(key)
elif value['level'] == 80:
self.senioradmin_cmds.append(key)
self.superadmin_cmds.append(key)
elif value['level'] >= 90:
self.superadmin_cmds.append(key)
else:
elif value['level'] < 90:
self.user_cmds.append(key)
self.mod_cmds.append(key)
self.admin_cmds.append(key)
self.fulladmin_cmds.append(key)
self.senioradmin_cmds.append(key)
self.superadmin_cmds.append(key)

self.superadmin_cmds.append(key)
Comment on lines 247 to +259
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LogParser.__init__ refactored with the following changes:

# alphabetic sort of the commands
self.user_cmds.sort()
self.mod_cmds.sort()
Expand Down Expand Up @@ -338,7 +335,7 @@ def __init__(self):
logger.info("Configuration loaded : OK")
# enable/disable option to get Head Admin by checking existence of head admin in database
curs.execute("SELECT COUNT(*) FROM `xlrstats` WHERE `admin_role` = 100")
self.iamgod = True if int(curs.fetchone()[0]) < 1 else False
self.iamgod = int(curs.fetchone()[0]) < 1
logger.info("Connecting to Database: OK")
logger.debug("Cmd !iamgod available : %s", self.iamgod)
self.uptime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
Expand Down Expand Up @@ -399,6 +396,16 @@ def rotating_messages(self):
self.game.rcon_say("^7Time: %s" % time.strftime("%H:%M", time.localtime(time.time())))
elif "@bigtext" in line:
self.game.rcon_bigtext("^7%s" % line.split('@bigtext')[-1].strip())
##Random slap START
elif "@randomslap" in line:
player_list = [player for player in self.game.players.itervalues() if player.get_team() == 1 or player.get_team()==2 and not player.get_team_lock() and player.get_alive()]
victima=random.choice(player_list)
self.game.send_rcon("slap %d" % victima.get_player_num())
self.game.rcon_say("^1Slap winner is: %s" % victima.get_name())
self.game.rcon_say("^2Slap winner is: %s" % victima.get_name())
self.game.rcon_say("^3Slap winner is: %s" % victima.get_name())
self.game.rcon_say("^5Slap winner is: %s" % victima.get_name())
##Random slap END
else:
if self.output_rules == 'chat':
self.game.rcon_say("^2%s" % line.strip())
Expand Down Expand Up @@ -1697,7 +1704,37 @@ def handle_say(self, line):
self.game.send_rcon('shuffleteams')
else:
self.game.rcon_tell(sar['player_num'], "^7Command is disabled for this game mode")

##SK START
elif (sar['command'] == '!sk') and self.game.players[sar['player_num']].get_admin_role() >= COMMANDS['sk']['level']:
if not self.ffa_lms_gametype:
game_data = self.game.get_gamestats()
#Defino array para tener [player,ratio]
plst=[]
#Obtengo lista de player del team rojo y azul
player_list = [player for player in self.game.players.itervalues() if player.get_team() == 1 or player.get_team()==2 and not player.get_team_lock()]
#Calculo diferencia
diff=abs(sum((player.dame_ratio()) for player in self.game.players.itervalues() if player.get_team() == 1 and not player.get_team_lock())-sum((player.dame_ratio()) for player in self.game.players.itervalues() if player.get_team() == 2 and not player.get_team_lock()))
#Si la diferencia es mayor a 1 reordeno
if diff > 1.0:
#Lleno el array con [player,ratio]
for i in player_list:
plst.insert(player_list.index(i),[i,i.dame_ratio()])
#Ordeno el array por ratio, de mayor a menor
plst.sort(key=lambda x: x[1], reverse=True)
#Reparto macacos miti miti
for q in plst:
#q[0]
if (plst.index(q)%2)==0:
if q[0].get_team()==2:
self.game.rcon_forceteam(q[0].get_player_num(), Player.teams[1])
else:
if q[0].get_team()==1:
self.game.rcon_forceteam(q[0].get_player_num(), Player.teams[2])
diff2=abs(sum((player.dame_ratio()) for player in self.game.players.itervalues() if player.get_team() == 1 and not player.get_team_lock())-sum((player.dame_ratio()) for player in self.game.players.itervalues() if player.get_team() == 2 and not player.get_team_lock()))
self.game.rcon_say("^0Skill difference was ^1%s^0, now is ^2%s" % (diff,diff2))
else:
self.game.rcon_say("^0No need to !sk (^5%s^0)" % diff)
##SK END
# spec - move yourself to spectator
elif sar['command'] in ('!spec', '!sp') and self.game.players[sar['player_num']].get_admin_role() >= COMMANDS['spec']['level']:
self.game.rcon_forceteam(sar['player_num'], 'spectator')
Expand Down Expand Up @@ -1993,7 +2030,8 @@ def handle_say(self, line):
else:
if sar['player_num'] == victim.get_player_num():
self.game.rcon_tell(sar['player_num'], "^7You cannot kick yourself")
elif victim.get_admin_role() >= self.game.players[sar['player_num']].get_admin_role():
#kick_original elif victim.get_admin_role() >= self.game.players[sar['player_num']].get_admin_role():
elif victim.get_admin_role() > self.game.players[sar['player_num']].get_admin_role():
self.game.rcon_tell(sar['player_num'], "^3Insufficient privileges to kick an admin")
else:
msg = "^2%s ^7was kicked by %s" % (victim.get_name(), self.game.players[sar['player_num']].get_name())
Expand Down Expand Up @@ -2156,7 +2194,8 @@ def handle_say(self, line):
if not found:
self.game.rcon_tell(sar['player_num'], msg)
else:
if victim.get_admin_role() >= self.game.players[sar['player_num']].get_admin_role():
#slap_original if victim.get_admin_role() >= self.game.players[sar['player_num']].get_admin_role():
if victim.get_admin_role() > self.game.players[sar['player_num']].get_admin_role():
self.game.rcon_tell(sar['player_num'], "^3Insufficient privileges to slap an admin")
else:
for _ in xrange(0, number):
Expand Down Expand Up @@ -2756,6 +2795,16 @@ def handle_say(self, line):
# reload
elif sar['command'] == '!reload' and self.game.players[sar['player_num']].get_admin_role() >= COMMANDS['reload']['level']:
self.game.send_rcon('reload')

#rmap
elif sar['command'] == '!rmap' and self.game.players[sar['plater_num']].get_admin_role() >= COMMANDS['rmap']['level']:
self.game.rcon_tell(sar['player_num'], "^7Holis 1")
map_lista = self.game.get_all_maps()
newmapa=random.choice(map_lista)
self.game.send_rcon('g_nextmap %' % newmapa)
self.game.next_mapname = newmapa
self.game.rcon_tell(sar['player_num'], "^7Changing Map to: ^3%s" % newmapa)
self.game.send_rcon('cyclemap')

# ungroup - remove the admin level from a player
elif sar['command'] == '!ungroup' and self.game.players[sar['player_num']].get_admin_role() >= COMMANDS['ungroup']['level']:
Expand Down Expand Up @@ -3513,6 +3562,13 @@ def set_team(self, team):

def get_team(self):
return self.team
#SK
def dame_ratio(self):
if self.get_registered_user():
ratio = round(float(self.get_db_kills()) / float(self.get_db_deaths()), 2) if self.get_db_deaths() > 0 else 1.0
else:
ratio = 1.0
return ratio

def get_team_lock(self):
return self.team_lock
Expand Down