153 lines
4.4 KiB
Go
153 lines
4.4 KiB
Go
|
package donnees
|
||
|
|
||
|
import (
|
||
|
"ConspiracyDecoder/binary"
|
||
|
)
|
||
|
|
||
|
type InfoPartie struct {
|
||
|
Id int32
|
||
|
TypeCarte byte
|
||
|
NbJoueurs byte
|
||
|
Nom string
|
||
|
|
||
|
IdCreateur int32
|
||
|
|
||
|
Classee bool
|
||
|
Privee bool
|
||
|
TirageAleatoire bool
|
||
|
Anonyme bool
|
||
|
|
||
|
Langue byte
|
||
|
|
||
|
Joueurs []*InfoJoueur
|
||
|
|
||
|
DureeMvt int32
|
||
|
DureeAjust int32
|
||
|
NbAnneeFin int16
|
||
|
HeureDemarrage int32
|
||
|
HeureRepriseJeu int32
|
||
|
DureeJouable int32
|
||
|
|
||
|
DateCreation int32
|
||
|
DateDebut int32
|
||
|
DateFin int32
|
||
|
DatePause int32
|
||
|
DateNegoFin int32
|
||
|
NbPhase int16
|
||
|
DateResolution int32
|
||
|
|
||
|
IdEmpireReqMatchNul byte
|
||
|
PhaseReqNul int16
|
||
|
EmpirePause byte
|
||
|
|
||
|
ResultatJoueur []byte
|
||
|
AnneeFinJoueur []byte
|
||
|
DeltaClassement []int16
|
||
|
|
||
|
JoueurIdEmpire byte
|
||
|
OrdresAttendus bool
|
||
|
resolImm bool
|
||
|
|
||
|
Ordres []int64
|
||
|
|
||
|
MasqueEmpiresBloques int16
|
||
|
MasqueEmpiresAyantBloqueJoueur int16
|
||
|
|
||
|
JoueurNbMsg int32
|
||
|
MessagesNonLus []int64
|
||
|
}
|
||
|
|
||
|
func ReadInfoPartie(bytes []byte) (InfoPartie, error) {
|
||
|
partie := InfoPartie{}
|
||
|
readSize := 0
|
||
|
s := 0
|
||
|
|
||
|
partie.Id = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.TypeCarte = bytes[s]; s += 1
|
||
|
partie.NbJoueurs = bytes[s]; s += 1
|
||
|
partie.Nom, readSize = binary.BinaryGetString(bytes, s); s += readSize
|
||
|
|
||
|
partie.IdCreateur = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.Classee = binary.BinaryGetBool(bytes, s); s++
|
||
|
partie.Privee = binary.BinaryGetBool(bytes, s); s++
|
||
|
partie.TirageAleatoire = binary.BinaryGetBool(bytes, s); s++
|
||
|
partie.Anonyme = binary.BinaryGetBool(bytes, s); s++
|
||
|
|
||
|
partie.Langue = bytes[s]; s++
|
||
|
|
||
|
// Lecture des joueurs.
|
||
|
partie.Joueurs = make([]*InfoJoueur, partie.NbJoueurs)
|
||
|
for i := 0; i < int(partie.NbJoueurs); i++ {
|
||
|
infosJoueurExistent := binary.BinaryGetBool(bytes, s); s++
|
||
|
|
||
|
if infosJoueurExistent {
|
||
|
infosJoueur, err := ReadInfoJoueur(bytes, &s) // Lecture des informations du joueur.
|
||
|
if err != nil {
|
||
|
partie.Joueurs[i] = nil // Les informations sur le joueur `i` n'existent pas.
|
||
|
} else {
|
||
|
partie.Joueurs[i] = infosJoueur // Les informations sur le joueur `i` existent, on les sauvegarde.
|
||
|
}
|
||
|
} else {
|
||
|
partie.Joueurs[i] = nil // Les informations sur le joueur `i` n'existent pas.
|
||
|
}
|
||
|
}
|
||
|
|
||
|
partie.DureeMvt = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.DureeAjust = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.NbAnneeFin = int16(binary.BinaryGetInt(bytes, s, 2)); s += 2
|
||
|
partie.HeureDemarrage = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.HeureRepriseJeu = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.DureeJouable = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
|
||
|
partie.DateCreation = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.DateDebut = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.DateFin = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.DatePause = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.DateNegoFin = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.NbPhase = int16(binary.BinaryGetInt(bytes, s, 2)); s += 2
|
||
|
partie.DateResolution = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
|
||
|
partie.IdEmpireReqMatchNul = bytes[s]; s++
|
||
|
partie.PhaseReqNul = int16(binary.BinaryGetInt(bytes, s, 2)); s += 2
|
||
|
partie.EmpirePause = bytes[s]; s++
|
||
|
|
||
|
partie.ResultatJoueur = make([]byte, partie.NbJoueurs)
|
||
|
partie.AnneeFinJoueur = make([]byte, partie.NbJoueurs)
|
||
|
partie.DeltaClassement = make([]int16, partie.NbJoueurs)
|
||
|
for i := 0; i < int(partie.NbJoueurs); i++ {
|
||
|
partie.ResultatJoueur[i] = bytes[s]; s++
|
||
|
partie.AnneeFinJoueur[i] = bytes[s]; s++
|
||
|
partie.DeltaClassement[i] = int16(binary.BinaryGetInt(bytes, s, 2)); s += 2
|
||
|
}
|
||
|
|
||
|
// Ordres du joueur.
|
||
|
nbBytes := GetOrdresNbBytes(partie.TypeCarte)
|
||
|
nbOrdres := int16(binary.BinaryGetInt(bytes, s, 2)); s += 2
|
||
|
partie.Ordres = make([]int64, nbOrdres)
|
||
|
for i := 0; i < int(nbOrdres); i++ {
|
||
|
partie.Ordres[i] = binary.BinaryGetInt(bytes, s, nbBytes); s += nbBytes
|
||
|
}
|
||
|
|
||
|
partie.MasqueEmpiresBloques = int16(binary.BinaryGetInt(bytes, s, 2)); s += 2
|
||
|
partie.MasqueEmpiresAyantBloqueJoueur = int16(binary.BinaryGetInt(bytes, s, 2)); s += 2
|
||
|
partie.JoueurNbMsg = int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
|
||
|
nbMessagesNonLus := int32(binary.BinaryGetInt(bytes, s, 4)); s += 4
|
||
|
partie.MessagesNonLus = make([]int64, nbMessagesNonLus)
|
||
|
for i := 0; i < int(nbMessagesNonLus); i++ {
|
||
|
partie.MessagesNonLus[i] = binary.BinaryGetInt(bytes, s, 8); s += 8
|
||
|
}
|
||
|
|
||
|
s += 4 // Octets de séparation ?
|
||
|
|
||
|
return partie, nil
|
||
|
}
|
||
|
|
||
|
func GetOrdresNbBytes(typeCarte byte) int {
|
||
|
if typeCarte == 1 {
|
||
|
return 4
|
||
|
} else {
|
||
|
return 5
|
||
|
}
|
||
|
}
|