def idToCountry(self, countryId): """\ Convert country id to country representation. """ if 'code3' == self.cf_country_print_mode: return GeoIP.id_to_country_code3(countryId) elif 'name' == self.cf_country_print_mode: return GeoIP.id_to_country_name(countryId) else: # 'code' (default) return GeoIP.id_to_country_code(countryId)
def onPlayerConnect(self, client): """\ Examine players country and allow/deny to connect. """ self.debug('Connecting slot: %s, %s, %s' % (client.cid, client.name, client.ip)) countryId = self.gi.id_by_addr(str(client.ip)) countryCode = GeoIP.id_to_country_code(countryId) country = self.idToCountry(countryId) self.debug('Country: %s' % (country)) if self.isAllowConnect(countryCode): if 0 < len(self.cf_allow_message) and (not self.isMessageExcludeFrom(countryCode)): message = self.getMessage('cf_allow_message', { 'name':client.name, 'country':country}) self.console.say(message) pass # do nothing else: if 0 < len(self.cf_deny_message) and (not self.isMessageExcludeFrom(countryCode)): message = self.getMessage('cf_deny_message', { 'name':client.name, 'country':country}) self.console.say(message) client.kick(': Your Country was REJECTED by B3 - CountryFilter') self.debug('Connecting done.')
def cmd_playerinfo(self, data, client, cmd=None): """\ <player> - Find a player info """ input = self._adminPlugin.parseUserCmd(data) if input[0] == '': cmd.sayLoudOrPM(client,'Incorrect player searched') return True elif input[0]: # input[0] is the player id sclient = self._adminPlugin.findClientPrompt(input[0], client) if not sclient: # a player matchin the name was not found, a list of closest matches will be displayed # we can exit here and the user will retry with a more specific player return False else: countryId = self.gi.id_by_addr(str(sclient.ip)) countryCode = GeoIP.id_to_country_code(countryId) country = self.idToCountry(countryId) cmd.sayLoudOrPM(client,'^1%s (%s) ^7Guid: ^1%s ^9Country: ^1%s ^7ip: ^1%s ^7Level: ^1%s' % (sclient.exactName, str(sclient.id), str(sclient.guid), str(country), str(sclient.ip), str(sclient.maxLevel)))