def setUp(self): # create a Iourt42 parser parser_conf = XmlConfigParser() parser_conf.loadFromString(dedent(r""" <configuration> <settings name="server"> <set name="game_log"></set> </settings> </configuration> """)) self.parser_conf = MainConfig(parser_conf) self.console = Iourt42Parser(self.parser_conf) # initialize some fixed cvars which will be used by both the plugin and the iourt42 parser when(self.console).getCvar('auth').thenReturn(Cvar('auth', value='0')) when(self.console).getCvar('fs_basepath').thenReturn(Cvar('fs_basepath', value='/fake/basepath')) when(self.console).getCvar('fs_homepath').thenReturn(Cvar('fs_homepath', value='/fake/homepath')) when(self.console).getCvar('fs_game').thenReturn(Cvar('fs_game', value='q3ut4')) when(self.console).getCvar('gamename').thenReturn(Cvar('gamename', value='q3urt42')) # start the parser self.console.startup() with logging_disabled(): self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini') self.adminPlugin.onLoadConfig() self.adminPlugin.onStartup() # make sure the admin plugin obtained by other plugins is our admin plugin when(self.console).getPlugin('admin').thenReturn(self.adminPlugin) self.conf = CfgConfigParser() self.conf.loadFromString(dedent(r""" [settings] demorecord: no skipstandardmaps: yes minleveldelete: senioradmin [commands] delrecord: guest maprecord: guest mapinfo: guest record: guest setway: senioradmin topruns: guest map: fulladmin maps: user setnextmap: admin """)) self.p = JumperPlugin(self.console, self.conf) self.p.onLoadConfig() self.p.onStartup() # load fixed json data (do not contact urtjumpers api for testing) when(self.p).getMapsDataFromApi().thenReturn(json.loads(MAPDATA_JSON))
def setCvar(self, key, value): """ Set a server variable. """ print("set cvar %s" % key) c = Cvar(name=key, value=value) self.cvars[key] = c
def setUp(self): # create a Iourt42 parser parser_conf = XmlConfigParser() parser_conf.loadFromString(dedent(r""" <configuration> <settings name="server"> <set name="game_log"></set> </settings> </configuration> """)) self.parser_conf = MainConfig(parser_conf) self.console = Iourt42Parser(self.parser_conf) # initialize some fixed cvars which will be used by both the plugin and the iourt42 parser when(self.console).getCvar('auth').thenReturn(Cvar('auth', value='0')) when(self.console).getCvar('fs_basepath').thenReturn(Cvar('fs_basepath', value='/fake/basepath')) when(self.console).getCvar('fs_homepath').thenReturn(Cvar('fs_homepath', value='/fake/homepath')) when(self.console).getCvar('fs_game').thenReturn(Cvar('fs_game', value='q3ut4')) when(self.console).getCvar('gamename').thenReturn(Cvar('gamename', value='q3urt42')) # start the parser self.console.startup() with logging_disabled(): self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini') self.adminPlugin.onLoadConfig() self.adminPlugin.onStartup() # make sure the admin plugin obtained by other plugins is our admin plugin when(self.console).getPlugin('admin').thenReturn(self.adminPlugin) with logging_disabled(): from b3.fake import FakeClient # create some clients self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", team=TEAM_RED, groupBits=128) self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", team=TEAM_BLUE, groupBits=16) self.mark = FakeClient(console=self.console, name="Mark", guid="markguid", team=TEAM_RED, groupBits=2) self.sara = FakeClient(console=self.console, name="Sara", guid="saraguid", team=TEAM_SPEC, groupBits=1) self.conf = CfgConfigParser() self.p = CallvotePlugin(self.console, self.conf)
def setUp(self): super(Test_cmd_pagear, self).setUp() self.conf = CfgConfigParser() self.conf.loadFromString(""" [commands] pagear-gear: 20 """) self.p = PoweradminurtPlugin(self.console, self.conf) when(self.console).getCvar('timelimit').thenReturn(Cvar('timelimit', value=20)) when(self.console).getCvar('g_maxGameClients').thenReturn(Cvar('g_maxGameClients', value=16)) when(self.console).getCvar('sv_maxclients').thenReturn(Cvar('sv_maxclients', value=16)) when(self.console).getCvar('sv_privateClients').thenReturn(Cvar('sv_privateClients', value=0)) when(self.console).getCvar('g_allowvote').thenReturn(Cvar('g_allowvote', value=0)) when(self.console).getCvar('g_modversion').thenReturn(Cvar('g_modversion', value="4.1")) self.given_forbidden_weapon_are(G_NONE) self.p.onLoadConfig() self.p.onStartup() self.sleep_patcher = patch.object(time, 'sleep') self.sleep_patcher.start() self.setCvar_patcher = patch.object(self.console, 'setCvar') self.setCvar_mock = self.setCvar_patcher.start() self.superadmin.connects("2")
def init_default_cvar(self): when(self.console).getCvar('timelimit').thenReturn(Cvar('timelimit', value=20)) when(self.console).getCvar('g_maxGameClients').thenReturn(Cvar('g_maxGameClients', value=16)) when(self.console).getCvar('sv_maxclients').thenReturn(Cvar('sv_maxclients', value=16)) when(self.console).getCvar('sv_privateClients').thenReturn(Cvar('sv_privateClients', value=0)) when(self.console).getCvar('g_allowvote').thenReturn(Cvar('g_allowvote', value=0)) when(self.console).getCvar('g_gear').thenReturn(Cvar('g_gear', value=''))
def getCvar(self, cvarName): """ Return a CVAR from the game server. :param cvarName: The CVAR name """ if not cvarName: self.warning('trying to query empty cvar %r' % cvarName) return None rv = self.output.write(cvarName) m = re.search(RE_CVAR, rv) if m: return Cvar(cvarName, value=m.group('value'), default=m.group('default')) else: return None
def setUp(self): # create a Iourt42 parser self.parser_conf = XmlConfigParser() self.parser_conf.loadFromString( dedent(r""" <configuration> <settings name="server"> <set name="game_log"></set> </settings> </configuration> """)) self.console = Iourt42Parser(self.parser_conf) # initialize some fixed cvars which will be used by both the plugin and the iourt42 parser when(self.console).getCvar('auth').thenReturn(Cvar('auth', value='0')) when(self.console).getCvar('fs_basepath').thenReturn( Cvar('fs_basepath', value='/fake/basepath')) when(self.console).getCvar('fs_homepath').thenReturn( Cvar('fs_homepath', value='/fake/homepath')) when(self.console).getCvar('fs_game').thenReturn( Cvar('fs_game', value='q3ut4')) when(self.console).getCvar('gamename').thenReturn( Cvar('gamename', value='q3urt42')) # start the parser self.console.startup() with logging_disabled(): self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini') self.adminPlugin.onLoadConfig() self.adminPlugin.onStartup() # make sure the admin plugin obtained by other plugins is our admin plugin when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
def setUp(self): self.status_response = None # defaults to STATUS_RESPONSE module attribute self.conf = XmlConfigParser() self.conf.loadFromString("""<configuration></configuration>""") self.parser = EtproParser(self.conf) self.parser.output = Mock() self.parser.output.write = Mock(wraps=sys.stdout.write) adminPlugin_conf = CfgConfigParser() adminPlugin_conf.load(ADMIN_CONFIG_FILE) adminPlugin = AdminPlugin(self.parser, adminPlugin_conf) adminPlugin.onLoadConfig() adminPlugin.onStartup() when(self.parser).getPlugin('admin').thenReturn(adminPlugin) when(self.parser).getCvar('b_privatemessages').thenReturn(Cvar('b_privatemessages', value='1')) self.parser.startup()
def setUp(self): self.parser_conf = CfgConfigParser() self.parser_conf.loadFromString(dedent(""" [server] name: game_log """)) self.parser = EtproParser(self.parser_conf) self.parser.output = Mock() self.parser.output.write = Mock(wraps=self.output_write) self.evt_queue = [] def queue_event(evt): self.evt_queue.append(evt) self.queueEvent_patcher = patch.object(self.parser, "queueEvent", wraps=queue_event) self.queueEvent_mock = self.queueEvent_patcher.start() when(self.parser).getCvar('b_privatemessages').thenReturn(Cvar('b_privatemessages', value='1')) self.parser.startup()
def getCvar_proxy(var_name): if var_name == 'vehicleSpawnAllowed': return Cvar('vehicleSpawnAllowed', value='false') else: return Mock()
def given_forbidden_weapon_are(self, g_gear_value): when(self.console).getCvar('g_gear').thenReturn(Cvar('g_gear', value=str(g_gear_value)))
def setUp(self): with logging_disabled(): # create a Iourt41 parser self.parser_conf = XmlConfigParser() self.parser_conf.loadFromString( """<configuration><settings name="server"><set name="game_log"></set></settings></configuration>""" ) self.console = Iourt41Parser(self.parser_conf) self.console.startup() # load the admin plugin if B3version(b3_version) >= B3version("1.10dev"): admin_plugin_conf_file = '@b3/conf/plugin_admin.ini' else: admin_plugin_conf_file = '@b3/conf/plugin_admin.xml' with logging_disabled(): self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file) self.adminPlugin.onStartup() # make sure the admin plugin obtained by other plugins is our admin plugin when(self.console).getPlugin('admin').thenReturn(self.adminPlugin) # when starting the PoweradminurtPlugin expects the game server to provide a few cvar values when(self.console).getCvar('timelimit').thenReturn( Cvar('timelimit', value=20)) when(self.console).getCvar('g_maxGameClients').thenReturn( Cvar('g_maxGameClients', value=16)) when(self.console).getCvar('sv_maxclients').thenReturn( Cvar('sv_maxclients', value=16)) when(self.console).getCvar('sv_privateClients').thenReturn( Cvar('sv_privateClients', value=0)) when(self.console).getCvar('g_allowvote').thenReturn( Cvar('g_allowvote', value=0)) # prepare a few players self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=TEAM_UNKNOWN, teamId=0, squad=0) self.simon = FakeClient(self.console, name="Simon", exactName="Simon", guid="qsdfdsqfdsqf", groupBits=0, team=TEAM_UNKNOWN, teamId=0, squad=0) self.reg = FakeClient(self.console, name="Reg", exactName="Reg", guid="qsdfdsqfdsqf33", groupBits=4, team=TEAM_UNKNOWN, teamId=0, squad=0) self.moderator = FakeClient(self.console, name="Moderator", exactName="Moderator", guid="sdf455ezr", groupBits=8, team=TEAM_UNKNOWN, teamId=0, squad=0) self.admin = FakeClient(self.console, name="Level-40-Admin", exactName="Level-40-Admin", guid="875sasda", groupBits=16, team=TEAM_UNKNOWN, teamId=0, squad=0) self.superadmin = FakeClient(self.console, name="God", exactName="God", guid="f4qfer654r", groupBits=128, team=TEAM_UNKNOWN, teamId=0, squad=0)
def setUp(self): # create a Iourt42 parser self.parser_conf = XmlConfigParser() self.parser_conf.loadFromString( dedent(r""" <configuration> <settings name="server"> <set name="game_log"></set> </settings> </configuration> """)) self.console = Iourt42Parser(self.parser_conf) # initialize some fixed cvars which will be used by both the plugin and the iourt42 parser when(self.console).getCvar('auth').thenReturn(Cvar('auth', value='0')) when(self.console).getCvar('fs_basepath').thenReturn( Cvar('g_maxGameClients', value='/fake/basepath')) when(self.console).getCvar('fs_homepath').thenReturn( Cvar('sv_maxclients', value='/fake/homepath')) when(self.console).getCvar('fs_game').thenReturn( Cvar('fs_game', value='q3ut4')) when(self.console).getCvar('gamename').thenReturn( Cvar('gamename', value='q3urt42')) # start the parser self.console.startup() self.admin_plugin_conf = CfgConfigParser() self.admin_plugin_conf.loadFromString( dedent(r""" [warn] pm_global: yes alert_kick_num: 3 instant_kick_num: 5 tempban_num: 6 tempban_duration: 1d max_duration: 1d message: ^1WARNING^7 [^3$warnings^7]: $reason warn_delay: 15 reason: ^7too many warnings: $reason duration_divider: 30 alert: ^1ALERT^7: $name^7 auto-kick from warnings if not cleared [^3$warnings^7] $reason warn_command_abusers: no""")) with logging_disabled(): self.adminPlugin = AdminPlugin(self.console, self.admin_plugin_conf) self.adminPlugin.onLoadConfig() self.adminPlugin.onStartup() # make sure the admin plugin obtained by other plugins is our admin plugin when(self.console).getPlugin('admin').thenReturn(self.adminPlugin) with logging_disabled(): from b3.fake import FakeClient # create some clients self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", team=TEAM_RED, groupBits=1) self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", team=TEAM_BLUE, groupBits=1) self.mark = FakeClient(console=self.console, name="Mark", guid="markguid", team=TEAM_BLUE, groupBits=128) self.conf = CfgConfigParser() self.p = SpawnkillPlugin(self.console, self.conf)
def setCvar(self, key, value): print "set cvar %s" % key c = Cvar(name=key, value=value) self.cvars[key] = c
def setUp(self): # create a Iourt42 parser parser_conf = XmlConfigParser() parser_conf.loadFromString( dedent(r""" <configuration> <settings name="server"> <set name="game_log"></set> </settings> </configuration> """)) self.parser_conf = MainConfig(parser_conf) self.console = Iourt42Parser(self.parser_conf) # initialize some fixed cvars which will be used by both the plugin and the iourt42 parser when(self.console).getCvar('auth').thenReturn(Cvar('auth', value='0')) when(self.console).getCvar('fs_basepath').thenReturn( Cvar('fs_basepath', value='/fake/basepath')) when(self.console).getCvar('fs_homepath').thenReturn( Cvar('fs_homepath', value='/fake/homepath')) when(self.console).getCvar('fs_game').thenReturn( Cvar('fs_game', value='q3ut4')) when(self.console).getCvar('gamename').thenReturn( Cvar('gamename', value='q3urt42')) # start the parser self.console.startup() with logging_disabled(): self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini') self.adminPlugin.onLoadConfig() self.adminPlugin.onStartup() # make sure the admin plugin obtained by other plugins is our admin plugin when(self.console).getPlugin('admin').thenReturn(self.adminPlugin) self.conf = CfgConfigParser() self.conf.loadFromString( dedent(r""" [settings] firstkill: on firsttk: on firsths: on [commands] firstkill: superadmin firsttk: superadmin firsths: superadmin [messages] ## $client = the client who made the kill ## $target = the client who suffered the kill first_kill: ^2First Kill^3: $client killed $target first_kill_by_headshot: ^2First Kill ^5by Headshot^3: $client killed $target first_teamkill: ^1First TeamKill^3: $client teamkilled $target """)) self.p = FirstkillPlugin(self.console, self.conf) self.p.onLoadConfig() self.p.onStartup() with logging_disabled(): from b3.fake import FakeClient # create some clients self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", team=TEAM_BLUE, groupBits=1) self.mark = FakeClient(console=self.console, name="Mark", guid="markguid", team=TEAM_BLUE, groupBits=1) self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", team=TEAM_RED, groupBits=1) self.mike.connects("1") self.bill.connects("2") self.mark.connects("3")
def getCvar_proxy(var_name): if var_name == 'gunMasterWeaponsPreset': return Cvar('gunMasterWeaponsPreset', value='1') else: return Mock()