OpenCoD2-Plus
Call of Duty 2 client & server, rebuilt
Loading...
Searching...
No Matches
cod2client.Client Class Reference
Inheritance diagram for cod2client.Client:
hit_location_test.Shooter plus_rules_test.Player

Public Member Functions

 __init__ (self, port, host='127.0.0.1', timeout=3.0)
 close (self)
 connect (self, protocol, name, plus=123, extra=None)
 receive (self, seconds)
 client_num (self)
 checksum_feed (self)
 commands (self, server_id, texts)
 command (self, server_id, text)
 resend (self, server_id, first)
 download (self, server_id, name, seconds=2.0)
 request_gamestate (self, server_id, seconds=5.0)
 enter_game (self, server_id, seconds=2.0)
 read_frames (self, seconds, forward=True)

Public Attributes

tuple addr = (host, port)
 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 qport = random.randint(1, 0xffff)
list redirects = []
int protocol = 0
int challenge = 0
int outgoing_sequence = 0
int incoming_sequence = 0
int command_sequence = 0
str last_command = ''
dict sent_commands = {0: ''}
 state = cod2snap.ServerState()
int parsed = 0
int parsed_clean = 0
list parse_errors = []
 fragment_sequence = None
 fragment_buffer = bytearray()
int server_time = 1000
int messages_received = 0
list voice_packets = []
 server_id = None
list pending_commands = []
 connect_reply = line

Protected Member Functions

 _oob (self, text, reply)
 _fragment_start (self, value=None)
 _transmit (self, message)
 _process (self, packet)
 _voice (self, data)
 _decode (self, sequence, data)
 _parse (self, sequence, data)
 _acknowledged (self)
 _send (self, server_id, payload)
 _write_commands (self, payload, texts)
 _write_move (self, payload, forward)
 _keep_moving (self, seconds, forward=True)

Constructor & Destructor Documentation

◆ __init__()

cod2client.Client.__init__ ( self,
port,
host = '127.0.0.1',
timeout = 3.0 )

Member Function Documentation

◆ _acknowledged()

cod2client.Client._acknowledged ( self)
protected
The last server command received, which the client acknowledges, and
its text: the server keys the XOR of client messages and the usercmds
with that slot of its command buffer.

◆ _decode()

cod2client.Client._decode ( self,
sequence,
data )
protected
Undoes SV_Netchan_Encode and the Huffman compression. The first 4
bytes, the last client command the server executed, are neither; the
key is the challenge XORed with the packet sequence, changed by the
text of that command (lastClientCommandString).

◆ _fragment_start()

cod2client.Client._fragment_start ( self,
value = None )
protected
1.3 sends fragment offsets as longs, older versions as shorts.

◆ _keep_moving()

cod2client.Client._keep_moving ( self,
seconds,
forward = True )
protected
Sends a move after each wait for server messages; returns the
parsed messages.

◆ _oob()

cod2client.Client._oob ( self,
text,
reply )
protected
Sends a connectionless packet and returns the reply line that starts
with reply or with error. Raises socket.timeout when none comes.

◆ _parse()

cod2client.Client._parse ( self,
sequence,
data )
protected
Decodes and parses one server message; see cod2snap.ServerState.parse.

Reimplemented in hit_location_test.Shooter, and plus_rules_test.Player.

◆ _process()

cod2client.Client._process ( self,
packet )
protected
Netchan_Process for server packets: returns (sequence, message) once a
message is complete, otherwise None.

◆ _send()

cod2client.Client._send ( self,
server_id,
payload )
protected
Sends a client message. Acknowledging the server commands keeps the
server from resending them all and from dropping the client once 128
are pending.

◆ _transmit()

cod2client.Client._transmit ( self,
message )
protected
Netchan_Transmit: messages of FRAGMENT_SIZE or more go in fragments,
and one ending exactly on a fragment boundary gets an empty last one.

◆ _voice()

cod2client.Client._voice ( self,
data )
protected
SV_SendClientVoiceData sends voice outside the netchan: "v", then the
packet count and, for each packet, the talker, the size and the Speex
data. Kept in voice_packets as (talker, data).

◆ _write_commands()

cod2client.Client._write_commands ( self,
payload,
texts )
protected

◆ _write_move()

cod2client.Client._write_move ( self,
payload,
forward )
protected
One usercmd as MSG_ReadDeltaUsercmdKey reads it against the default
command: absolute server time, then changed fields XORed with the key.

Reimplemented in hit_location_test.Shooter, and plus_rules_test.Player.

◆ checksum_feed()

cod2client.Client.checksum_feed ( self)

◆ client_num()

cod2client.Client.client_num ( self)

◆ close()

cod2client.Client.close ( self)

◆ command()

cod2client.Client.command ( self,
server_id,
text )

◆ commands()

cod2client.Client.commands ( self,
server_id,
texts )
Sends reliable client commands in one message; returns the number of
packets it took.

◆ connect()

cod2client.Client.connect ( self,
protocol,
name,
plus = 123,
extra = None )
Returns None once connected, otherwise the server's reply. plus is the
CoD2 Plus version to send, or None for a stock client. extra, given the
challenge, returns more userinfo to send (the Plus ID keys).

◆ download()

cod2client.Client.download ( self,
server_id,
name,
seconds = 2.0 )
Asks for a file as the client's auto-download does, before entering
the game, and returns what the svc_download blocks of the following
messages carried: file data, or the error text of a refusal. The key
of each message is the command its header says the server executed
last, so messages sent before the download command decode too.

◆ enter_game()

cod2client.Client.enter_game ( self,
server_id,
seconds = 2.0 )
Validates the iwds the way a client that references none would, then
keeps moving forward. The first move makes the server put the client in
the world. Needs request_gamestate first. The snapshots received
meanwhile are dropped; server commands wait for read_frames.

◆ read_frames()

cod2client.Client.read_frames ( self,
seconds,
forward = True )
Keeps moving as enter_game does for up to seconds and returns one
frame per snapshot received: {'server_time', 'commands' (server
commands received since the previous frame, those of the gamestate
included), 'entities' {number: fields}, 'clients' {number: fields},
'ps', 'flags'}. Arrays are lists, e.g. entity['pos.trBase']; see
cod2snap for the field names. Needs enter_game first.

◆ receive()

cod2client.Client.receive ( self,
seconds )
Reads server packets for up to seconds; returns the complete messages.

◆ request_gamestate()

cod2client.Client.request_gamestate ( self,
server_id,
seconds = 5.0 )
Sends a message from an older map, which makes the server send the
gamestate, and parses it: configstrings, baselines, client number and
checksum feed. Returns True once it is received.

◆ resend()

cod2client.Client.resend ( self,
server_id,
first )
Sends the commands from sequence first on again, as a client does
until the server acknowledges them.

Member Data Documentation

◆ addr

cod2client.Client.addr = (host, port)

◆ challenge

int cod2client.Client.challenge = 0

◆ command_sequence

cod2client.Client.command_sequence = 0

◆ connect_reply

cod2client.Client.connect_reply = line

◆ fragment_buffer

cod2client.Client.fragment_buffer = bytearray()

◆ fragment_sequence

cod2client.Client.fragment_sequence = None

◆ incoming_sequence

int cod2client.Client.incoming_sequence = 0

◆ last_command

str cod2client.Client.last_command = ''

◆ messages_received

int cod2client.Client.messages_received = 0

◆ outgoing_sequence

int cod2client.Client.outgoing_sequence = 0

◆ parse_errors

list cod2client.Client.parse_errors = []

◆ parsed

int cod2client.Client.parsed = 0

◆ parsed_clean

int cod2client.Client.parsed_clean = 0

◆ pending_commands

list cod2client.Client.pending_commands = []

◆ protocol

int cod2client.Client.protocol = 0

◆ qport

cod2client.Client.qport = random.randint(1, 0xffff)

◆ redirects

list cod2client.Client.redirects = []

◆ sent_commands

dict cod2client.Client.sent_commands = {0: ''}

◆ server_id

cod2client.Client.server_id = None

◆ server_time

cod2client.Client.server_time = 1000

◆ sock

cod2client.Client.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

◆ state

cod2client.Client.state = cod2snap.ServerState()

◆ voice_packets

list cod2client.Client.voice_packets = []

The documentation for this class was generated from the following file: