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( 'Checking player: %s, name: %s, ip: %s, level: %s' % (client.cid, client.name, client.ip, client.maxLevel)) 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, client): if (0 < len(self.cf_allow_message) and ( not self.isMessageExcludeFrom(countryCode))) and client.guid and self.console.upTime() > 300: 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(silent=True) self.debug('Checking done.')
def cmd_cfcountry(self, data, client, cmd=None): """\ <player> - What country is this player from? """ # this will split the player name and the message (oops, no message...) _input = self._adminPlugin.parseUserCmd(data) if _input: # 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: client.message('^7Invalid or missing data, try !help cfcountry') return False # are we still here? Let's get the country 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^7 is connecting from ^1%s (%s)^7' % (sclient.name, country, countryCode)) return True