Skip to content

Instantly share code, notes, and snippets.

@cetteup
Created February 11, 2026 21:10
Show Gist options
  • Select an option

  • Save cetteup/fb61f3e9da79f7cfaccce2bfb60b324a to your computer and use it in GitHub Desktop.

Select an option

Save cetteup/fb61f3e9da79f7cfaccce2bfb60b324a to your computer and use it in GitHub Desktop.
Battlefield 2 ModManager module to handle player verification
"""
Player verification module
======================
Verify player's accounts as players join.
===== Config =====
# Add a bypass IP address
# You can let players bypass verification based on their IP address.
# If your server uses "idle bots", make sure to add bypass using their IP address, else they will get banned.
mm_verifier.addBypassIp "<ip address>"
# Example
mm_verifier.addBypassIp "135.125.56.26"
====
# The ban reason for name spoofing
mm_verifier.nameSpoofingBanReason "Name spoofing"
# The ban reason for player id spoofing
mm_verifier.pidSpoofingBanReason "Player id spoofing"
# The in-game announcement for name spoofing
mm_verifier.nameSpoofingBanAnnouncement "Player: '%s' real name: '%s' was kicked and banned for name spoofing"
# The in-game announcement for player id spoofing
mm_verifier.pidSpoofingBanAnnouncement "Player: '%s' tried to use player id: %s when their real player id is %s and was kicked and banned for player id spoofing"
# The number of seconds to wait before kicking spoofing players
mm_verifier.kickDelay 5
# The method to use to ban the player, must be either "Key" or "Address"
mm_verifier.banType "Key"
# The duration of the ban
mm_verifier.banPeriod "Perm"
===== Notes =====
This module is a simplified, dedicated-purpose version of mm_playerconnect.
"""
import bf2
import host
import mm_utils
__version__ = 1.0
__required_modules__ = {
'modmanager': 1.6
}
__supports_reload__ = True
__supported_games__ = {
'bf2': True,
'bf2142': False, # Not tested
'bfheroes': False, # Not tested
'bfp4f': False # Not tested
}
__description__ = 'Verifier v%s' % __version__
configDefaults = {
'nameSpoofingBanReason': "Name spoofing",
'pidSpoofingBanReason': "Player id spoofing",
'nameSpoofingBanAnnouncement': "Player: '%s' real name: '%s' was kicked and banned for name spoofing",
'pidSpoofingBanAnnouncement': "Player: '%s' tried to use player id: %s when their real player id is %s and was kicked and banned for player id spoofing",
'kickDelay': 5,
'banType': mm_utils.BanMethod.key,
'banPeriod': 'Perm',
'bypassIps': []
}
class Verifier(object):
def __init__(self, modManager):
"""Create a new instance."""
self.mm = modManager
self.__state = 0
def init(self):
"""Provides default initialisation."""
self.__config = self.mm.getModuleConfig(configDefaults)
if self.__state == 0:
host.registerHandler('ValidatePlayerNameResponse', self.onPlayerNameValidated, 1)
self.__state = 1
# onPlayerNameValidated is called by the engine when the VerifyPlayer response from GameSpy arrives.
def onPlayerNameValidated(self, realNick, oldNick, realPID, oldPID, player):
try:
ip = player.getAddress()
except RuntimeError:
# Should only fail if player already left (according to mm_banmanager)
# Return to avoid banning a bypass IP
return
self.mm.debug(3, "Player Name Validated realNick: '%s', oldNick: '%s', realPID: %s, oldPID: %s, ip: %s" % (
realNick, oldNick, realPID, oldPID, ip
))
if ip in self.__config['bypassIps']:
return
if realNick != oldNick:
# Nick spoofer ban
self.mm.banManager().banPlayer(
player,
self.__config['nameSpoofingBanReason'],
self.__config['banPeriod'],
mm_utils.KickBanType.rcon,
self.__config['banType'],
'ModManager Verifier',
self.__config['kickDelay']
)
# Announcement
if self.__config['nameSpoofingBanAnnouncement']:
msg = self.__config['nameSpoofingBanAnnouncement'] % (oldNick, realNick)
mm_utils.msg_server(msg)
self.mm.info(msg)
return
if realPID != oldPID:
# PID spoofer ban
self.mm.banManager().banPlayer(
player,
self.__config['pidSpoofingBanReason'],
self.__config['banPeriod'],
mm_utils.KickBanType.rcon,
self.__config['banType'],
'ModManager Verifier',
self.__config['kickDelay']
)
# Announcement
if self.__config['pidSpoofingBanAnnouncement']:
msg = self.__config['pidSpoofingBanAnnouncement'] % (oldNick, oldPID, realPID)
mm_utils.msg_server(msg)
self.mm.info(msg)
def shutdown(self):
"""Shutdown and stop processing."""
self.__state = 2
#
# ModManager load
#
def mm_load(modManager):
"""Creates and returns your object."""
return Verifier(modManager)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment