OpenCoD2-Plus
Call of Duty 2 client & server, rebuilt
Loading...
Searching...
No Matches
plus_rules_test Namespace Reference

Classes

class  Player
class  Duel

Functions

 frames_until (player, done, seconds)
 settle (player, weapon, seconds=6)
 shot_interval (player, script, seconds=6)
 check_fast_reload (port, player, other, check)
 check_prone_peek (port, player, other, check)
 take_turret (port, player)
 check_mg_clip (port, player, other, check)
 shotgun_pellets (player, index)
 check_shotgun_spread (port, player, other, check)
 check_mg_rate (port, player, other, check)
 snapshots_per_second (player, seconds=3)
 check_snapshot_rate (port, player, other, check)
 check_archive_time (port, player, other, check)
 pump (players, seconds)
 check_lean_rewind (port, player, other, check)
 check_stance_rewind (port, player, other, check)
 check_vote_reconnect (port, player, other, check)
 check_error_repeats (port, player, other, check)
 check_wait_time (port, player, other, check)
 main ()

Variables

 ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
str RCON = 'plusrules'
 LOG = None
 BUTTON_ATTACK
 BUTTON_RELOAD
 BUTTON_LEANLEFT
 BUTTON_LEANRIGHT
 PRONE
 CROUCH
int BUTTON_USE = 8
int BUTTON_ADS = 4096
int EF_TURRET_ACTIVE = 0x300
dict STANCE_EVENTS = {140, 141, 142}
 WEAPON_READY
 WEAPON_FIRING
str OTHER = 'thompson_mp'
tuple RIFLES
str GAMETYPE
 ET_TURRET
 ET_EVENTS
 EV_BULLET_HIT_SMALL
 EV_SHOTGUN_HIT
list SPREAD_PATTERNS
int MG42_FIRE_TIME = 50
int TURRET_RETURN_SPEED = 200
dict CHECKS

Detailed Description

Checks the rules a Plus server plays by with a Plus client (Plus version 123,
docs/architecture/plus-protocol.md#version-123).

    python3 scripts/plus_rules_test.py /path/to/CoD2 [--binary bin/cod2rev_lnxded] [--only NAME,...] [--fps N]

Runs the server with a mod whose dm gametype spawns the player with
thompson_mp and a bolt-action, and a minimal client (cod2client) that sends
scripted usercmds and reads its playerstate from the snapshots:

- fast reload: for each bolt-action (and the shotgun), it fires, presses
  reload, switches to the thompson and back while the rifle still drops, at
  several times around the bolt, then fires as soon as it can. No time between
  the two shots may be shorter than with no switch, give or take a command
  (50 ms, how closely the snapshots time a shot). The shotgun gains about
  that much on a stock build, so only the rifles show the bug there.
- prone peek: crouched and leaning, it goes prone, crouches and goes prone
  again, to each side. The lean, which halves going prone, may come back no
  faster than when the lean key is let go (0.5 in 280 ms): it used to halve
  in one frame.
- mg clip: it takes a turret from 20 units to its side, which moves it behind
  the gun, and leaves it with the use button. It must stay where the turret
  held it: the stock game takes it back to where it stood when it took the
  turret, behind cover if it stood there. Leaving adds no playerstate event
  but the one that restores the stance.
- shotgun spread: turned to a wall the whole spread meets, with
  g_shotgun_spread_fix 1, the distances of a shot's 8 impacts from the aim
  must be one of the two patterns', whatever the turn, and both must come;
  with 0 they must not. This is not a Plus rule: it passes on every build.
- mg rate: on the turret, aimed at the ground, it holds fire: one impact
  every 50 ms (mg42's fireTime), timed from the first to the last; left, the
  turret turns back at 200 degrees a second. With --fps N the server runs at
  that sv_fps, with a snapshot every frame; other builds fail above 20 Hz.
- snapshot rate: with sv_lanForceRate 0, so the test client counts as one on
  the internet, it gets a snapshot every frame and a rate of 1,000 bytes a
  second per Hz (25,000 at least), and g_forceSnaps 10 set by rcon gives it 10
  snapshots a second at once. Other builds have no sv_lanForceRate.
- archive time: a bot moves 100 units a second, and the player follows it a
  second back, as a killcam: the bot's origin must be from the newest frame
  at least a second old. Stock counted sv_fps frames a second, 960 ms at
  sv_fps 60.
- lean rewind: a second client 600 ms behind, down the sights with no
  spread, shoots at where the player's head was while it leaned, after it
  let go of the lean: the antilag must hit the head, which only the Plus
  build's pose rewind does. A shot into the wall over the head first measures
  how far the bullet leaves from the view. It sets g_antilag 1, which a game
  folder's config can turn off.
- stance rewind: the same client shoots at where the player's head was
  before it crouched, went prone or stood up from a crouch, once its head
  has left it: the antilag must rewind the animation of the stance, not only its
  flags, which only the Plus build does.

Exits with 0 when every check passes. On a build without the rules (any
build but make PLUS=1) the other checks fail: that is how they catch the bugs.

Function Documentation

◆ check_archive_time()

plus_rules_test.check_archive_time ( port,
player,
other,
check )
Following a bot a second back, as a killcam, the player gets the bot's
playerstate from the last frame at least a second old: the bot moves at
100 units a second, so its origin tells how far back that was. The
antilag finds its frames the same way. (The archived commandTime is moved
to the present, so it cannot tell.)

◆ check_error_repeats()

plus_rules_test.check_error_repeats ( port,
player,
other,
check )
With logErrors 1 the same runtime error every frame for 11 s prints once,
then as a count after 10 s, then the count it left when it stopped, not 220
times.

◆ check_fast_reload()

plus_rules_test.check_fast_reload ( port,
player,
other,
check )

◆ check_lean_rewind()

plus_rules_test.check_lean_rewind ( port,
player,
other,
check )
The shooter shoots at where the player's head was while it leaned,
after the player let go of the lean: the antilag must put the head back
where the shooter saw it.

◆ check_mg_clip()

plus_rules_test.check_mg_clip ( port,
player,
other,
check )

◆ check_mg_rate()

plus_rules_test.check_mg_rate ( port,
player,
other,
check )
Manned, the MG fires once a fireTime at any sv_fps; left, it turns back
to its rest at the same speed.

◆ check_prone_peek()

plus_rules_test.check_prone_peek ( port,
player,
other,
check )

◆ check_shotgun_spread()

plus_rules_test.check_shotgun_spread ( port,
player,
other,
check )

◆ check_snapshot_rate()

plus_rules_test.check_snapshot_rate ( port,
player,
other,
check )
With sv_lanForceRate 0 the test client gets an internet client's rate:
on a Plus server, a snapshot every frame and 1,000 bytes a second per Hz
(25,000 at least), whatever its snaps and rate; g_forceSnaps and
g_forceRate set by rcon take effect at once.

◆ check_stance_rewind()

plus_rules_test.check_stance_rewind ( port,
player,
other,
check )
The shooter shoots at where the player's head was before it changed
stance, once the player's head has left it: the antilag must rewind the
stance's animation too, not only its flags. On the server going down
holds the head a little over standing for about 450 ms (crouch) or 700 ms
(prone) before it drops, and standing up raises it at once, so each shot
comes when the 600 ms ago it rewinds to still has the head there.

◆ check_vote_reconnect()

plus_rules_test.check_vote_reconnect ( port,
player,
other,
check )
A player who voted and reconnects in the same vote cannot vote again
(ClientConnect clears the whole client). With two more clients the vote
neither passes nor fails while the voter is away.

◆ check_wait_time()

plus_rules_test.check_wait_time ( port,
player,
other,
check )
40 x wait 0.05 take 2 s and 4 x wait 1 take 4 s, to a frame, at any
sv_fps: the fraction of a frame a wait leaves carries to the next.

◆ frames_until()

plus_rules_test.frames_until ( player,
done,
seconds )
Snapshots' playerstates until done(playerstates) or seconds pass.

◆ main()

plus_rules_test.main ( )

◆ pump()

plus_rules_test.pump ( players,
seconds )
Keeps every client sending commands for that long.

◆ settle()

plus_rules_test.settle ( player,
weapon,
seconds = 6 )
Holds weapon until it is ready and stays so for half a second.

◆ shot_interval()

plus_rules_test.shot_interval ( player,
script,
seconds = 6 )
Runs script from a ready weapon; the time from its first shot to the
next one, in ms, or None.

◆ shotgun_pellets()

plus_rules_test.shotgun_pellets ( player,
index )
Fires the shotgun once; its pellets' distances from the aim, as above,
from the impacts the server sends, or the count of impacts if not 8.

◆ snapshots_per_second()

plus_rules_test.snapshots_per_second ( player,
seconds = 3 )

◆ take_turret()

plus_rules_test.take_turret ( port,
player )
Has the player take the turret, twice if the first useTurret did not
take (now and then it does not); the playerstates until it is on.

Variable Documentation

◆ BUTTON_ADS

int plus_rules_test.BUTTON_ADS = 4096

◆ BUTTON_ATTACK

plus_rules_test.BUTTON_ATTACK

◆ BUTTON_LEANLEFT

plus_rules_test.BUTTON_LEANLEFT

◆ BUTTON_LEANRIGHT

plus_rules_test.BUTTON_LEANRIGHT

◆ BUTTON_RELOAD

plus_rules_test.BUTTON_RELOAD

◆ BUTTON_USE

int plus_rules_test.BUTTON_USE = 8

◆ CHECKS

dict plus_rules_test.CHECKS
Initial value:
1= {'fast_reload': check_fast_reload, 'prone_peek': check_prone_peek, 'shotgun_spread': check_shotgun_spread,
2 'mg_clip': check_mg_clip, 'mg_rate': check_mg_rate, 'snapshot_rate': check_snapshot_rate,
3 'lean_rewind': check_lean_rewind, 'stance_rewind': check_stance_rewind,
4 'archive_time': check_archive_time, 'vote_reconnect': check_vote_reconnect, 'wait_time': check_wait_time,
5 'error_repeats': check_error_repeats}

◆ CROUCH

plus_rules_test.CROUCH

◆ EF_TURRET_ACTIVE

int plus_rules_test.EF_TURRET_ACTIVE = 0x300

◆ ET_EVENTS

plus_rules_test.ET_EVENTS

◆ ET_TURRET

plus_rules_test.ET_TURRET

◆ EV_BULLET_HIT_SMALL

plus_rules_test.EV_BULLET_HIT_SMALL

◆ EV_SHOTGUN_HIT

plus_rules_test.EV_SHOTGUN_HIT

◆ GAMETYPE

str plus_rules_test.GAMETYPE

◆ LOG

plus_rules_test.LOG = None

◆ MG42_FIRE_TIME

int plus_rules_test.MG42_FIRE_TIME = 50

◆ OTHER

str plus_rules_test.OTHER = 'thompson_mp'

◆ PRONE

plus_rules_test.PRONE

◆ RCON

str plus_rules_test.RCON = 'plusrules'

◆ RIFLES

tuple plus_rules_test.RIFLES
Initial value:
1= ('kar98k_mp', 'kar98k_sniper_mp', 'enfield_mp', 'enfield_scope_mp', 'mosin_nagant_mp',
2 'mosin_nagant_sniper_mp', 'springfield_mp', 'shotgun_mp')

◆ ROOT

plus_rules_test.ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

◆ SPREAD_PATTERNS

list plus_rules_test.SPREAD_PATTERNS
Initial value:
1= [sorted(x for x in (0, .4, .4, .4, .4, .8, .72 ** .5, .72 ** .5)),
2 [.1, .1, .5, .5, 1, 1, 1, 1]]

◆ STANCE_EVENTS

dict plus_rules_test.STANCE_EVENTS = {140, 141, 142}

◆ TURRET_RETURN_SPEED

int plus_rules_test.TURRET_RETURN_SPEED = 200

◆ WEAPON_FIRING

plus_rules_test.WEAPON_FIRING

◆ WEAPON_READY

plus_rules_test.WEAPON_READY