diff options
| author | BiSaXa <1669855+BiSaXa@users.noreply.github.com> | 2022-08-27 13:02:35 +0300 |
|---|---|---|
| committer | BiSaXa <1669855+BiSaXa@users.noreply.github.com> | 2022-08-27 13:02:35 +0300 |
| commit | f108a577658c9aab8496da4ebd0fb4f0216093e8 (patch) | |
| tree | e484a8a8b54c92ca4a393f267ebc755ec6434c8d /messages/messages.go | |
| download | sdp.go-f108a577658c9aab8496da4ebd0fb4f0216093e8.tar.gz sdp.go-f108a577658c9aab8496da4ebd0fb4f0216093e8.tar.bz2 sdp.go-f108a577658c9aab8496da4ebd0fb4f0216093e8.zip | |
init
Diffstat (limited to 'messages/messages.go')
| -rw-r--r-- | messages/messages.go | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/messages/messages.go b/messages/messages.go new file mode 100644 index 0000000..db9d027 --- /dev/null +++ b/messages/messages.go | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "os" | ||
| 6 | "parser/classes" | ||
| 7 | "parser/utils" | ||
| 8 | ) | ||
| 9 | |||
| 10 | func MessageTypeCheck(file *os.File) (statusCode int) { | ||
| 11 | var MSSC int32 = 2 | ||
| 12 | Type := make([]byte, 1) | ||
| 13 | Tick := make([]byte, 4) | ||
| 14 | Slot := make([]byte, 1) | ||
| 15 | file.Read(Type) | ||
| 16 | file.Read(Tick) | ||
| 17 | file.Read(Slot) | ||
| 18 | switch Type[0] { | ||
| 19 | case 0x01: // SignOn | ||
| 20 | var packet Packet | ||
| 21 | var cmdinfo classes.CmdInfo | ||
| 22 | packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC) | ||
| 23 | packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 24 | packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 25 | packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 26 | packet.Data = utils.ReadByteFromFile(file, packet.Size) | ||
| 27 | cmdinfo = classes.CmdInfoInit(packet.PacketInfo) | ||
| 28 | fmt.Println(cmdinfo) | ||
| 29 | return 1 | ||
| 30 | case 0x02: // Packet | ||
| 31 | var packet Packet | ||
| 32 | var cmdinfo classes.CmdInfo | ||
| 33 | packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC) | ||
| 34 | packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 35 | packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 36 | packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 37 | packet.Data = utils.ReadByteFromFile(file, packet.Size) | ||
| 38 | cmdinfo = classes.CmdInfoInit(packet.PacketInfo) | ||
| 39 | fmt.Printf("[%d] %v\n", utils.IntFromBytes(Tick), cmdinfo) | ||
| 40 | return 2 | ||
| 41 | case 0x03: // SyncTick | ||
| 42 | return 3 | ||
| 43 | case 0x04: // Consolecmd | ||
| 44 | var consolecmd ConsoleCmd | ||
| 45 | consolecmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 46 | consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size)) | ||
| 47 | fmt.Printf("[%d] %s\n", utils.IntFromBytes(Tick), consolecmd.Data) | ||
| 48 | return 4 | ||
| 49 | case 0x05: // Usercmd FIXME: Correct bit-packing inside classes | ||
| 50 | var usercmd UserCmd | ||
| 51 | //var usercmdinfo classes.UserCmdInfo | ||
| 52 | usercmd.Cmd = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 53 | usercmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 54 | usercmd.Data = utils.ReadByteFromFile(file, usercmd.Size) | ||
| 55 | //usercmdinfo = classes.UserCmdInfoInit(usercmd.Data, int(usercmd.Size)) | ||
| 56 | //fmt.Printf("[%d] UserCmd: %v\n", utils.IntFromBytes(Tick), usercmdinfo) | ||
| 57 | return 5 | ||
| 58 | case 0x06: // DataTables | ||
| 59 | var datatables DataTables | ||
| 60 | //var stringtable classes.StringTable | ||
| 61 | datatables.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) | ||
| 62 | datatables.Data = utils.ReadByteFromFile(file, datatables.Size) | ||
| 63 | // stringtable = classes.StringTableInit(Data) | ||
| 64 | // fmt.Printf("[%d] DataTables: %v\n", utils.IntFromBytes(Size), stringtable) | ||
| 65 | return 6 | ||
| 66 | case 0x07: // Stop | ||
| 67 | fmt.Println("Stop") | ||
| 68 | return 7 | ||
| 69 | case 0x08: // CustomData | ||
| 70 | Unknown := make([]byte, 4) | ||
| 71 | file.Read(Unknown) | ||
| 72 | Size := make([]byte, 4) | ||
| 73 | file.Read(Size) | ||
| 74 | Data := make([]byte, utils.IntFromBytes(Size)) | ||
| 75 | file.Read(Data) | ||
| 76 | return 8 | ||
| 77 | case 0x09: // StringTables | ||
| 78 | Size := make([]byte, 4) | ||
| 79 | file.Read(Size) | ||
| 80 | Data := make([]byte, utils.IntFromBytes(Size)) | ||
| 81 | file.Read(Data) | ||
| 82 | return 9 | ||
| 83 | default: | ||
| 84 | return 0 | ||
| 85 | } | ||
| 86 | //fmt.Println(Type[0]) | ||
| 87 | //fmt.Println(utils.IntFromBytes(Tick)) | ||
| 88 | //fmt.Println(Slot[0]) | ||
| 89 | } | ||