2016-09-02 10:41:19 +00:00
# TODO: Rewrite this shit
2016-10-02 20:48:14 +00:00
from common import generalUtils
2016-11-20 10:31:51 +00:00
from constants import serverPackets
2016-05-18 17:12:46 +00:00
from objects import glob
2016-10-02 20:48:14 +00:00
2016-04-19 17:40:59 +00:00
2016-09-02 15:45:10 +00:00
class banchoConfig :
2016-04-19 17:40:59 +00:00
"""
Class that loads settings from bancho_settings db table
"""
config = { " banchoMaintenance " : False , " freeDirect " : True , " menuIcon " : " " , " loginNotification " : " " }
2016-08-17 14:41:05 +00:00
def __init__ ( self , loadFromDB = True ) :
2016-04-19 17:40:59 +00:00
"""
Initialize a banchoConfig object ( and load bancho_settings from db )
2016-09-02 10:41:19 +00:00
loadFromDB - - if True , load values from db . If False , don ' t load values. Optional.
2016-04-19 17:40:59 +00:00
"""
2016-08-17 14:41:05 +00:00
if loadFromDB :
2016-04-19 17:40:59 +00:00
try :
self . loadSettings ( )
except :
raise
2016-09-02 10:41:19 +00:00
2016-04-19 17:40:59 +00:00
def loadSettings ( self ) :
"""
( re ) load bancho_settings from DB and set values in config array
"""
2016-10-02 20:48:14 +00:00
self . config [ " banchoMaintenance " ] = generalUtils . stringToBool ( glob . db . fetch ( " SELECT value_int FROM bancho_settings WHERE name = ' bancho_maintenance ' " ) [ " value_int " ] )
self . config [ " freeDirect " ] = generalUtils . stringToBool ( glob . db . fetch ( " SELECT value_int FROM bancho_settings WHERE name = ' free_direct ' " ) [ " value_int " ] )
2016-04-19 17:40:59 +00:00
self . config [ " menuIcon " ] = glob . db . fetch ( " SELECT value_string FROM bancho_settings WHERE name = ' menu_icon ' " ) [ " value_string " ]
self . config [ " loginNotification " ] = glob . db . fetch ( " SELECT value_string FROM bancho_settings WHERE name = ' login_notification ' " ) [ " value_string " ]
2016-09-02 10:41:19 +00:00
2016-08-17 14:41:05 +00:00
def setMaintenance ( self , maintenance ) :
2016-04-19 17:40:59 +00:00
"""
Turn on / off bancho maintenance mode . Write new value to db too
2016-08-17 14:41:05 +00:00
maintenance - - if True , turn on maintenance mode . If false , turn it off
2016-04-19 17:40:59 +00:00
"""
2016-08-17 14:41:05 +00:00
self . config [ " banchoMaintenance " ] = maintenance
glob . db . execute ( " UPDATE bancho_settings SET value_int = %s WHERE name = ' bancho_maintenance ' " , [ int ( maintenance ) ] )
2016-11-20 10:31:51 +00:00
def reload ( self ) :
# Reload settings from bancho_settings
glob . banchoConf . loadSettings ( )
# Reload channels too
glob . channels . loadChannels ( )
# And chat filters
glob . chatFilters . loadFilters ( )
# Send new channels and new bottom icon to everyone
glob . streams . broadcast ( " main " , serverPackets . mainMenuIcon ( glob . banchoConf . config [ " menuIcon " ] ) )
glob . streams . broadcast ( " main " , serverPackets . channelInfoEnd ( ) )
for key , value in glob . channels . channels . items ( ) :
if value . publicRead == True and value . hidden == False :
glob . streams . broadcast ( " main " , serverPackets . channelInfo ( key ) )