2021-01-14 04:40:31 -08:00
|
|
|
package multiserver
|
|
|
|
|
2021-01-14 10:06:40 -08:00
|
|
|
import "encoding/binary"
|
2021-01-14 04:40:31 -08:00
|
|
|
|
|
|
|
const (
|
2021-01-14 08:09:06 -08:00
|
|
|
ToClientHello = 0x02
|
|
|
|
ToClientAuthAccept = 0x03
|
|
|
|
ToClientAcceptSudoMode = 0x04
|
|
|
|
ToClientDenySudoMode = 0x05
|
|
|
|
ToClientAccessDenied = 0x0A
|
|
|
|
ToClientBlockdata = 0x20
|
|
|
|
ToClientAddNode = 0x21
|
|
|
|
ToClientRemoveNode = 0x22
|
|
|
|
ToClientInventory = 0x27
|
|
|
|
ToClientTimeOfDay = 0x29
|
|
|
|
ToClientCsmRestrictionFlags = 0x2A
|
|
|
|
ToClientPlayerSpeed = 0x2B
|
|
|
|
ToClientMediaPush = 0x2C
|
|
|
|
ToClientChatMessage = 0x2F
|
2021-01-14 04:40:31 -08:00
|
|
|
ToClientActiveObjectRemoveAdd = 0x31
|
2021-01-14 08:09:06 -08:00
|
|
|
ToClientActiveObjectMessages = 0x32
|
|
|
|
ToClientHp = 0x33
|
|
|
|
ToClientMovePlayer = 0x34
|
|
|
|
ToClientFov = 0x36
|
|
|
|
ToClientDeathscreen = 0x37
|
|
|
|
ToClientMedia = 0x38
|
|
|
|
ToClientTooldef = 0x39
|
|
|
|
ToClientNodedef = 0x3A
|
|
|
|
ToClientCraftitemdef = 0x3B
|
|
|
|
ToClientAnnounceMedia = 0x3C
|
|
|
|
ToClientItemdef = 0x3D
|
|
|
|
ToClientPlaySound = 0x3F
|
|
|
|
ToClientStopSound = 0x40
|
|
|
|
ToClientPrivileges = 0x41
|
|
|
|
ToClientInventoryFormspec = 0x42
|
|
|
|
ToClientDetachedInventory = 0x43
|
|
|
|
ToClientShowFormspec = 0x44
|
|
|
|
ToClientMovement = 0x45
|
|
|
|
ToClientSpawnParticle = 0x46
|
|
|
|
ToClientAddParticlespawner = 0x47
|
|
|
|
ToClientHudAdd = 0x49
|
|
|
|
ToClientHudRm = 0x4A
|
|
|
|
ToClientHudChange = 0x4B
|
|
|
|
ToClientHudSetFlags = 0x4C
|
|
|
|
ToClientHudSetParam = 0x4D
|
|
|
|
ToClientBreath = 0x4E
|
|
|
|
ToClientSetSky = 0x4F
|
2021-01-14 04:40:31 -08:00
|
|
|
ToClientOverrideDayNightRatio = 0x50
|
|
|
|
ToClientLocalPlayerAnimations = 0x51
|
2021-01-14 08:09:06 -08:00
|
|
|
ToClientEyeOffset = 0x52
|
2021-01-14 04:40:31 -08:00
|
|
|
ToClientDeleteParticlespawner = 0x53
|
2021-01-14 08:09:06 -08:00
|
|
|
ToClientCloudParams = 0x54
|
|
|
|
ToClientFadeSound = 0x55
|
|
|
|
ToClientUpdatePlayerList = 0x56
|
|
|
|
ToClientModchannelMsg = 0x57
|
|
|
|
ToClientModchannelSignal = 0x58
|
|
|
|
ToClientNodeMetaChanged = 0x59
|
|
|
|
ToClientSetSun = 0x5A
|
|
|
|
ToClientSetMoon = 0x5B
|
|
|
|
ToClientSetStars = 0x5C
|
|
|
|
ToClientSrpBytesSB = 0x60
|
|
|
|
ToClientFormspecPrepend = 0x61
|
|
|
|
ToClientMinimapModes = 0x62
|
2021-01-14 04:40:31 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-01-14 08:09:06 -08:00
|
|
|
ToServerInit = 0x02
|
|
|
|
ToServerInit2 = 0x11
|
|
|
|
ToServerModchannelJoin = 0x17
|
2021-01-14 04:40:31 -08:00
|
|
|
ToServerModchannelLeave = 0x18
|
2021-01-14 08:09:06 -08:00
|
|
|
ToServerModchannelMsg = 0x19
|
|
|
|
ToServerPlayerPos = 0x23
|
|
|
|
ToServerGotblocks = 0x24
|
|
|
|
ToServerDeletedblocks = 0x25
|
2021-01-14 04:40:31 -08:00
|
|
|
ToServerInventoryAction = 0x31
|
2021-01-14 08:09:06 -08:00
|
|
|
ToServerChatMessage = 0x32
|
|
|
|
ToServerDamage = 0x35
|
|
|
|
ToServerPlayerItem = 0x37
|
|
|
|
ToServerRespawn = 0x38
|
|
|
|
ToServerInteract = 0x39
|
|
|
|
ToServerRemovedSounds = 0x3A
|
|
|
|
ToServerNodeMetaFields = 0x3B
|
2021-01-14 04:40:31 -08:00
|
|
|
ToServerInventoryFields = 0x3C
|
2021-01-14 08:09:06 -08:00
|
|
|
ToServerRequestMedia = 0x40
|
|
|
|
ToServerClientReady = 0x43
|
|
|
|
ToServerFirstSrp = 0x50
|
|
|
|
ToServerSrpBytesA = 0x51
|
|
|
|
ToServerSrpBytesM = 0x52
|
2021-01-14 04:40:31 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
AccessDeniedWrongPassword = iota
|
|
|
|
AccessDeniedUnexpectedData
|
|
|
|
AccessDeniedSingleplayer
|
|
|
|
AccessDeniedWrongVersion
|
|
|
|
AccessDeniedWrongCharsInName
|
|
|
|
AccessDeniedWrongName
|
|
|
|
AccessDeniedTooManyUsers
|
|
|
|
AccessDeniedEmptyPassword
|
|
|
|
AccessDeniedAlreadyConnected
|
|
|
|
AccessDeniedServerFail
|
|
|
|
AccessDeniedCustomString
|
|
|
|
AccessDeniedShutdown
|
|
|
|
AccessDeniedCrash
|
|
|
|
)
|
|
|
|
|
2021-01-14 08:09:06 -08:00
|
|
|
func processPktCommand(src, dst *Peer, pkt *Pkt) bool {
|
|
|
|
if src.IsSrv() {
|
2021-01-14 04:40:31 -08:00
|
|
|
switch cmd := binary.BigEndian.Uint16(pkt.Data[0:2]); cmd {
|
2021-01-14 08:09:06 -08:00
|
|
|
case ToClientActiveObjectRemoveAdd:
|
|
|
|
pkt.Data = processAoRmAdd(dst, pkt.Data)
|
|
|
|
return false
|
2021-01-14 04:40:31 -08:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch cmd := binary.BigEndian.Uint16(pkt.Data[0:2]); cmd {
|
|
|
|
case ToServerChatMessage:
|
2021-01-14 08:09:06 -08:00
|
|
|
return processChatMessage(src, *pkt)
|
|
|
|
case ToServerClientReady:
|
|
|
|
go processJoin(src)
|
|
|
|
return false
|
2021-01-14 04:40:31 -08:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|