<commit_before>;;; 
;;; Copyright (C) 2007 <NAME> <EMAIL>
;;; 
;;; All rights reserved.
;;; 
;;; Redistribution and use in source and binary forms, with or
;;; without modification, are permitted provided that the
;;; following conditions are met:
;;; 1. Redistributions of source code must retain the above
;;;    copyright notice, this list of conditions and the
;;;    following disclaimer.
;;; 2. Redistributions in binary form must reproduce the
;;;    above copyright notice, this list of conditions and
;;;    the following disclaimer in the documentation and/or
;;;    other materials provided with the distribution.
;;; 3. Neither the name of the project nor the names of
;;;    its contributors may be used to endorse or promote
;;;    products derived from this software without specific
;;;    prior written permission.
;;;  
;;; THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS
;;; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
;;; BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;;; DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS
;;; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
;;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
;;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
;;; IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
;;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
;;; OF SUCH DAMAGE.

;;; Version 1.0.0

;;; Socket functions
(load "sock.scm")
;;; Helper functions
(load "helper.scm")
;;; Network configuration
(load "pkth_config.scm")

;;; SCTP Payload Protocol Identifier for PKTH
(define pkth-ppid                               0)

;;; TCP/SCTP Port for PKTH
(define pkth-port                               7234)

;;; PKTH protocol version
(define pkth-version-major                      3)
(define pkth-version-minor                      0)

;;; PokerTH game version
(define pkth-game-version                       #x0006)
(define pkth-beta-revision                      #x0000)

(define pkth-type-init                          #x0001)
(define pkth-type-init-ack                      #x0002)
(define pkth-type-retrieve-avatar               #x0003)
(define pkth-type-avatar-header                 #x0004)
(define pkth-type-avatar-file                   #x0005)
(define pkth-type-avatar-end                    #x0006)
(define pkth-type-unknown-avatar                #x0007)
(define pkth-type-game-list-new                 #x0010)
(define pkth-type-game-list-update              #x0011)
(define pkth-type-game-list-player-joined       #x0012)
(define pkth-type-game-list-player-left         #x0013)
(define pkth-type-game-list-admin-changed       #x0014)
(define pkth-type-retrieve-player-info          #x0020)
(define pkth-type-player-info                   #x0021)
(define pkth-type-unknown-player-id             #x0022)
(define pkth-type-create-game                   #x0030)
(define pkth-type-join-game                     #x0031)
(define pkth-type-join-game-ack                 #x0032)
(define pkth-type-join-game-failed              #x0033)
(define pkth-type-player-joined                 #x0034)
(define pkth-type-player-left                   #x0035)
(define pkth-type-game-admin-changed            #x0036)
(define pkth-type-kick-player                   #x0040)
(define pkth-type-leave-current-game            #x0041)
(define pkth-type-start-event                   #x0042)
(define pkth-type-start-event-ack               #x0043)
(define pkth-type-game-start                    #x0050)
(define pkth-type-hand-start                    #x0051)
(define pkth-type-players-turn                  #x0052)
(define pkth-type-players-action                #x0053)
(define pkth-type-players-action-done           #x0054)
(define pkth-type-players-action-rejected       #x0055)
(define pkth-type-deal-flop-cards               #x0060)
(define pkth-type-deal-turn-card                #x0061)
(define pkth-type-deal-river-card               #x0062)
(define pkth-type-all-in-show-cards             #x0063)
(define pkth-type-end-of-hand-show-cards        #x0064)
(define pkth-type-end-of-hand-hide-cards        #x0065)
(define pkth-type-end-of-game                   #x0070)
(define pkth-type-statistics-changed            #x0080)

(define pkth-type-removed-from-game             #x0100)

(define pkth-type-send-chat-text                #x0200)
(define pkth-type-chat-text                     #x0201)

(define pkth-type-error                         #x0400)

(define pkth-game-flag-password-protected       #x01)

(define pkth-player-flag-human                  #x01)
(define pkth-player-flag-has-avatar             #x02)

(define pkth-start-flag-fill-with-cpu-players   #x01)

(define pkth-privacy-flag-show-avatar           #x01)

;;; Reasons why join game failed.
(define pkth-join-failed-game-full              #x0001)
(define pkth-join-failed-game-already-running   #x0002)
(define pkth-join-failed-invalid-password       #x0003)
(define pkth-join-failed-other-reason           #xFFFF)

;;; Reasons for being removed from a game.
(define pkth-removed-on-request                 #x0000)
(define pkth-removed-game-full                  #x0001)
(define pkth-removed-game-already-running       #x0002)
(define pkth-removed-kicked                     #x0003)
(define pkth-removed-other-reason               #xFFFF)

;;; Internal error codes.
(define pkth-err-reserved                       #x0000)
(define pkth-err-init-version-not-supported     #x0001)
(define pkth-err-init-server-full               #x0002)
(define pkth-err-init-invalid-password          #x<PASSWORD>)
(define pkth-err-init-player-name-in-use        #x0005)
(define pkth-err-init-invalid-player-name       #x0006)
(define pkth-err-init-server-maintenance        #x0007)
(define pkth-err-avatar-too-large               #x0010)
(define pkth-err-avatar-wrong-size              #x0011)
(define pkth-err-join-game-unknown-game         #x0020)
(define pkth-err-general-invalid-packet         #xFF01)
(define pkth-err-general-invalid-state          #xFF02)
(define pkth-err-general-player-kicked          #xFF03)
(define pkth-err-other                          #xFFFF)

;;; Constant for reserved
(define pkth-reserved                           0)

;;; Header lengths
(define pkth-header-length-common               4)

;;; Common header value lengths
(define pkth-length-type                        2)
(define pkth-length-msg-length                  2)

;;; Value lengths
(define pkth-length-version                     2)
(define pkth-length-revision                    2)
(define pkth-length-string-length               2)
(define pkth-length-flags                       2)
(define pkth-length-reserved                    2)
(define pkth-length-player-id                   4)
(define pkth-length-session-id                  4)
(define pkth-length-md5                         16)
(define pkth-length-blind-value                 2)

;;; Value offsets common header
(define pkth-offset-type                        0)
(define pkth-offset-msg-length                  (+ pkth-offset-type pkth-length-type))
(define pkth-offset-data                        (+ pkth-offset-msg-length pkth-length-msg-length))

;;; Value offsets pkth-type-init
(define pkth-init-offset-version-major          pkth-offset-data)
(define pkth-init-offset-version-minor          (+ pkth-init-offset-version-major pkth-length-version))
(define pkth-init-offset-password-length        (+ pkth-init-offset-version-minor pkth-length-version))
(define pkth-init-offset-player-name-length     (+ pkth-init-offset-password-length pkth-length-string-length))
(define pkth-init-offset-privacy-flags          (+ pkth-init-offset-player-name-length pkth-length-string-length))
(define pkth-init-offset-reserved               (+ pkth-init-offset-privacy-flags pkth-length-flags))
(define pkth-init-offset-avatar-md5             (+ pkth-init-offset-reserved pkth-length-reserved))
(define pkth-init-offset-password               (+ pkth-init-offset-avatar-md5 pkth-length-md5))

;;; Value offsets pkth-type-init-ack
(define pkth-init-ack-offset-game-version       pkth-offset-data)
(define pkth-init-ack-offset-beta-revision      (+ pkth-init-ack-offset-game-version pkth-length-version))
(define pkth-init-ack-offset-session-id         (+ pkth-init-ack-offset-beta-revision pkth-length-revision))
(define pkth-init-ack-offset-player-id          (+ pkth-init-ack-offset-session-id pkth-length-session-id))

;;; Minimum/maximum packet length
(define pkth-minimum-message-length             8)
(define pkth-maximum-message-length             268)

;;; Receive buf length
(define pkth-buf-length                         #xffff)

;;; Game info constants
(define pkth-raise-interval-mode-on-hand        1)
(define pkth-raise-interval-mode-on-minute      2)

(define pkth-raise-mode-double-blinds           1)
(define pkth-raise-mode-manual-blinds-order     2)

(define pkth-end-raise-mode-double-blinds       1)
(define pkth-end-raise-mode-raise               2)
(define pkth-end-raise-mode-keep-last-blind     3)

;;;
;;; Header constructors
;;;<commit_msg>Fixed minimum message size issue.<commit_after>;;; 
;;; Copyright (C) 2007 <NAME> <EMAIL>
;;; 
;;; All rights reserved.
;;; 
;;; Redistribution and use in source and binary forms, with or
;;; without modification, are permitted provided that the
;;; following conditions are met:
;;; 1. Redistributions of source code must retain the above
;;;    copyright notice, this list of conditions and the
;;;    following disclaimer.
;;; 2. Redistributions in binary form must reproduce the
;;;    above copyright notice, this list of conditions and
;;;    the following disclaimer in the documentation and/or
;;;    other materials provided with the distribution.
;;; 3. Neither the name of the project nor the names of
;;;    its contributors may be used to endorse or promote
;;;    products derived from this software without specific
;;;    prior written permission.
;;;  
;;; THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS
;;; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
;;; BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;;; DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS
;;; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
;;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
;;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
;;; IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
;;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
;;; OF SUCH DAMAGE.

;;; Version 1.0.0

;;; Socket functions
(load "sock.scm")
;;; Helper functions
(load "helper.scm")
;;; Network configuration
(load "pkth_config.scm")

;;; SCTP Payload Protocol Identifier for PKTH
(define pkth-ppid                               0)

;;; TCP/SCTP Port for PKTH
(define pkth-port                               7234)

;;; PKTH protocol version
(define pkth-version-major                      3)
(define pkth-version-minor                      0)

;;; PokerTH game version
(define pkth-game-version                       #x0006)
(define pkth-beta-revision                      #x0000)

(define pkth-type-init                          #x0001)
(define pkth-type-init-ack                      #x0002)
(define pkth-type-retrieve-avatar               #x0003)
(define pkth-type-avatar-header                 #x0004)
(define pkth-type-avatar-file                   #x0005)
(define pkth-type-avatar-end                    #x0006)
(define pkth-type-unknown-avatar                #x0007)
(define pkth-type-game-list-new                 #x0010)
(define pkth-type-game-list-update              #x0011)
(define pkth-type-game-list-player-joined       #x0012)
(define pkth-type-game-list-player-left         #x0013)
(define pkth-type-game-list-admin-changed       #x0014)
(define pkth-type-retrieve-player-info          #x0020)
(define pkth-type-player-info                   #x0021)
(define pkth-type-unknown-player-id             #x0022)
(define pkth-type-create-game                   #x0030)
(define pkth-type-join-game                     #x0031)
(define pkth-type-join-game-ack                 #x0032)
(define pkth-type-join-game-failed              #x0033)
(define pkth-type-player-joined                 #x0034)
(define pkth-type-player-left                   #x0035)
(define pkth-type-game-admin-changed            #x0036)
(define pkth-type-kick-player                   #x0040)
(define pkth-type-leave-current-game            #x0041)
(define pkth-type-start-event                   #x0042)
(define pkth-type-start-event-ack               #x0043)
(define pkth-type-game-start                    #x0050)
(define pkth-type-hand-start                    #x0051)
(define pkth-type-players-turn                  #x0052)
(define pkth-type-players-action                #x0053)
(define pkth-type-players-action-done           #x0054)
(define pkth-type-players-action-rejected       #x0055)
(define pkth-type-deal-flop-cards               #x0060)
(define pkth-type-deal-turn-card                #x0061)
(define pkth-type-deal-river-card               #x0062)
(define pkth-type-all-in-show-cards             #x0063)
(define pkth-type-end-of-hand-show-cards        #x0064)
(define pkth-type-end-of-hand-hide-cards        #x0065)
(define pkth-type-end-of-game                   #x0070)
(define pkth-type-statistics-changed            #x0080)

(define pkth-type-removed-from-game             #x0100)

(define pkth-type-send-chat-text                #x0200)
(define pkth-type-chat-text                     #x0201)

(define pkth-type-error                         #x0400)

(define pkth-game-flag-password-protected       #x01)

(define pkth-player-flag-human                  #x01)
(define pkth-player-flag-has-avatar             #x02)

(define pkth-start-flag-fill-with-cpu-players   #x01)

(define pkth-privacy-flag-show-avatar           #x01)

;;; Reasons why join game failed.
(define pkth-join-failed-game-full              #x0001)
(define pkth-join-failed-game-already-running   #x0002)
(define pkth-join-failed-invalid-password       #x<PASSWORD>)
(define pkth-join-failed-other-reason           #xFFFF)

;;; Reasons for being removed from a game.
(define pkth-removed-on-request                 #x0000)
(define pkth-removed-game-full                  #x0001)
(define pkth-removed-game-already-running       #x0002)
(define pkth-removed-kicked                     #x0003)
(define pkth-removed-other-reason               #xFFFF)

;;; Internal error codes.
(define pkth-err-reserved                       #x0000)
(define pkth-err-init-version-not-supported     #x0001)
(define pkth-err-init-server-full               #x0002)
(define pkth-err-init-invalid-password          #x0004)
(define pkth-err-init-player-name-in-use        #x0005)
(define pkth-err-init-invalid-player-name       #x0006)
(define pkth-err-init-server-maintenance        #x0007)
(define pkth-err-avatar-too-large               #x0010)
(define pkth-err-avatar-wrong-size              #x0011)
(define pkth-err-join-game-unknown-game         #x0020)
(define pkth-err-general-invalid-packet         #xFF01)
(define pkth-err-general-invalid-state          #xFF02)
(define pkth-err-general-player-kicked          #xFF03)
(define pkth-err-other                          #xFFFF)

;;; Constant for reserved
(define pkth-reserved                           0)

;;; Header lengths
(define pkth-header-length-common               4)

;;; Common header value lengths
(define pkth-length-type                        2)
(define pkth-length-msg-length                  2)

;;; Value lengths
(define pkth-length-version                     2)
(define pkth-length-revision                    2)
(define pkth-length-string-length               2)
(define pkth-length-flags                       2)
(define pkth-length-reserved                    2)
(define pkth-length-player-id                   4)
(define pkth-length-session-id                  4)
(define pkth-length-md5                         16)
(define pkth-length-blind-value                 2)

;;; Value offsets common header
(define pkth-offset-type                        0)
(define pkth-offset-msg-length                  (+ pkth-offset-type pkth-length-type))
(define pkth-offset-data                        (+ pkth-offset-msg-length pkth-length-msg-length))

;;; Value offsets pkth-type-init
(define pkth-init-offset-version-major          pkth-offset-data)
(define pkth-init-offset-version-minor          (+ pkth-init-offset-version-major pkth-length-version))
(define pkth-init-offset-password-length        (+ pkth-init-offset-version-minor pkth-length-version))
(define pkth-init-offset-player-name-length     (+ pkth-init-offset-password-length pkth-length-string-length))
(define pkth-init-offset-privacy-flags          (+ pkth-init-offset-player-name-length pkth-length-string-length))
(define pkth-init-offset-reserved               (+ pkth-init-offset-privacy-flags pkth-length-flags))
(define pkth-init-offset-avatar-md5             (+ pkth-init-offset-reserved pkth-length-reserved))
(define pkth-init-offset-password               (+ pkth-init-offset-avatar-md5 pkth-length-md5))

;;; Value offsets pkth-type-init-ack
(define pkth-init-ack-offset-game-version       pkth-offset-data)
(define pkth-init-ack-offset-beta-revision      (+ pkth-init-ack-offset-game-version pkth-length-version))
(define pkth-init-ack-offset-session-id         (+ pkth-init-ack-offset-beta-revision pkth-length-revision))
(define pkth-init-ack-offset-player-id          (+ pkth-init-ack-offset-session-id pkth-length-session-id))

;;; Minimum/maximum packet length
(define pkth-minimum-message-length             pkth-header-length-common)
(define pkth-maximum-message-length             268)

;;; Receive buf length
(define pkth-buf-length                         #xffff)

;;; Game info constants
(define pkth-raise-interval-mode-on-hand        1)
(define pkth-raise-interval-mode-on-minute      2)

(define pkth-raise-mode-double-blinds           1)
(define pkth-raise-mode-manual-blinds-order     2)

(define pkth-end-raise-mode-double-blinds       1)
(define pkth-end-raise-mode-raise               2)
(define pkth-end-raise-mode-keep-last-blind     3)

;;;
;;; Header constructors
;;;
{'fraction_non_alphanumeric': 0.11672735061040908, 'fraction_numerical': 0.0332512315270936, 'mean_word_length': 2.198664154821031, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1624415', 'n_tokens_mistral': 6573, 'n_tokens_neox': 5950, 'n_words': 1322}