implement statuscode in packets
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m2s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m2s
This commit is contained in:
@@ -69,13 +69,24 @@ func (m *TCPCartServerMux) handleFunction(connection net.Conn, messageType uint3
|
||||
m.mu.RUnlock()
|
||||
if ok {
|
||||
responseType, responseData, err := fn(id, data)
|
||||
|
||||
if err != nil {
|
||||
errData := []byte(err.Error())
|
||||
err = binary.Write(connection, binary.LittleEndian, CartPacket{
|
||||
Version: CurrentPacketVersion,
|
||||
MessageType: responseType,
|
||||
DataLength: uint32(len(errData)),
|
||||
StatusCode: 500,
|
||||
Id: id,
|
||||
})
|
||||
_, err = connection.Write(errData)
|
||||
return true, err
|
||||
}
|
||||
err = binary.Write(connection, binary.LittleEndian, CartPacket{
|
||||
Version: CurrentPacketVersion,
|
||||
MessageType: responseType,
|
||||
DataLength: uint64(len(responseData)),
|
||||
DataLength: uint32(len(responseData)),
|
||||
StatusCode: 200,
|
||||
Id: id,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -101,7 +112,10 @@ func (m *TCPCartServerMux) HandleConnection(connection net.Conn) error {
|
||||
log.Printf("Error receiving packet: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if packet.Version != CurrentPacketVersion {
|
||||
log.Printf("Incorrect packet version: %d\n", packet.Version)
|
||||
continue
|
||||
}
|
||||
data, err := GetPacketData(connection, packet.DataLength)
|
||||
if err != nil {
|
||||
log.Printf("Error getting packet data: %v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user