func (this *packetClientScoreboardObjectiveCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientScoreboardObjective := encode.(*PacketClientScoreboardObjective)
	err = packet.WriteString(writer, util, packetClientScoreboardObjective.Name)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientScoreboardObjective.Action)
	if err != nil {
		return
	}
	switch packetClientScoreboardObjective.Action {
	case PACKET_CLIENT_SCOREBOARD_OBJECTIVE_ACTION_ADD:
		fallthrough
	case PACKET_CLIENT_SCOREBOARD_OBJECTIVE_ACTION_UPDATE:
		err = packet.WriteString(writer, util, packetClientScoreboardObjective.Value)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, util, packetClientScoreboardObjective.Type)
	case PACKET_CLIENT_SCOREBOARD_OBJECTIVE_ACTION_REMOVE:
		// no payload
	default:
		err = errors.New(fmt.Sprintf("Encode, PacketClientScoreboardObjective action is not valid: %d", packetClientScoreboardObjective.Action))
	}
	return
}
Example #2
0
func (this *PacketRedirectEventCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetRedirectEvent := encode.(*PacketRedirectEvent)
	err = packet.WriteString(writer, util, packetRedirectEvent.Server)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, packetRedirectEvent.Player)
	return
}
func (this *requestAuthenticateCodec) Encode(writer io.Writer, request Request) (err error) {
	requestAuthenticate := request.(*RequestAuthenticate)
	err = packet.WriteString(writer, requestAuthenticate.Username)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, requestAuthenticate.Password)
	return
}
func (this *packetClientLoginSuccessCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetClientLoginSuccess := encode.(*PacketClientLoginSuccess)
	err = packet.WriteString(writer, packetClientLoginSuccess.UUID)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, packetClientLoginSuccess.Name)
	return
}
func (this *requestRedirectCodec) Encode(writer io.Writer, util []byte, request Request) (err error) {
	requestRedirect := request.(*RequestRedirect)
	err = packet.WriteString(writer, util, requestRedirect.Server)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, requestRedirect.Player)
	return
}
func (this *packetClientScoreboardObjectiveCodec17) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetClientScoreboardObjective := encode.(*PacketClientScoreboardObjective)
	err = packet.WriteString(writer, packetClientScoreboardObjective.Name)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, packetClientScoreboardObjective.Value)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientScoreboardObjective.Action)
	return
}
func (this *packetClientJoinGameCodec17) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetClientJoinGame := encode.(*PacketClientJoinGame)
	err = packet.WriteInt32(writer, packetClientJoinGame.EntityId)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientJoinGame.Gamemode)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientJoinGame.Dimension)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientJoinGame.Difficulty)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientJoinGame.MaxPlayers)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, packetClientJoinGame.LevelType)
	return
}
func (this *packetServerClientSettingsCodec17) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetServerClientSettings := encode.(*PacketServerClientSettings)
	err = packet.WriteString(writer, util, packetServerClientSettings.Locale)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, util, packetServerClientSettings.ViewDistance)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, util, packetServerClientSettings.ChatFlags)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, util, packetServerClientSettings.ChatColours)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, util, packetServerClientSettings.difficulty17)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, util, packetServerClientSettings.ShowCape)
	return
}
func (this *packetClientJoinGameCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientJoinGame := encode.(*PacketClientJoinGame)
	err = packet.WriteInt32(writer, util, packetClientJoinGame.EntityId)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientJoinGame.Gamemode)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientJoinGame.Dimension)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientJoinGame.Difficulty)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientJoinGame.MaxPlayers)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, packetClientJoinGame.LevelType)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, util, packetClientJoinGame.ReducedDebugInfo)
	return
}
Example #10
0
func (this *packetMessageEventCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetMessageEvent := encode.(*PacketMessageEvent)
	err = packet.WriteString(writer, packetMessageEvent.Sender)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, packetMessageEvent.Channel)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, uint16(len(packetMessageEvent.Payload)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetMessageEvent.Payload)
	return
}
Example #11
0
func (this *resultGetDetailsCodec) Encode(writer io.Writer, result Result) (err error) {
	resultGetDetails := result.(*ResultGetDetails)
	err = packet.WriteString(writer, resultGetDetails.Ip)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, resultGetDetails.Port)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, resultGetDetails.Motd)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, resultGetDetails.Version)
	return
}
Example #12
0
func (this *RequestAsServerCodec) Encode(writer io.Writer, util []byte, request Request) (err error) {
	requestAsServer := request.(*RequestAsServer)
	err = packet.WriteString(writer, util, requestAsServer.Address)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, requestAsServer.Port)
	return
}
func (this *packetServerPluginMessageCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetServerPluginMessage := encode.(*PacketServerPluginMessage)
	err = packet.WriteString(writer, packetServerPluginMessage.Channel)
	if err != nil {
		return
	}
	_, err = writer.Write(packetServerPluginMessage.Data)
	return
}
func (this *requestNotifyPlayerCodec) Encode(writer io.Writer, util []byte, request Request) (err error) {
	requestNotifyPlayer := request.(*RequestNotifyPlayer)
	err = packet.WriteBool(writer, util, requestNotifyPlayer.Add)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, requestNotifyPlayer.Player)
	return
}
func (this *requestAsProxyCodec) Encode(writer io.Writer, util []byte, request Request) (err error) {
	requestAsProxy := request.(*RequestAsProxy)
	err = packet.WriteString(writer, util, requestAsProxy.Address)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, requestAsProxy.Port)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, requestAsProxy.Motd)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, requestAsProxy.Version)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, requestAsProxy.MaxPlayers)
	return
}
func (this *packetClientPlayerListCodec17) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetClientPlayerList := encode.(*PacketClientPlayerList17)
	err = packet.WriteString(writer, packetClientPlayerList.Name)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, packetClientPlayerList.Online)
	if err != nil {
		return
	}
	err = packet.WriteInt16(writer, packetClientPlayerList.Ping)
	return
}
Example #17
0
func (this *PacketClientTeamsCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientTeams := encode.(*PacketClientTeams)
	err = packet.WriteString(writer, util, packetClientTeams.Name)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientTeams.Action)
	if packetClientTeams.Action == 0 || packetClientTeams.Action == 2 {
		if err != nil {
			return
		}
		err = packet.WriteString(writer, util, packetClientTeams.DisplayName)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, util, packetClientTeams.Prefix)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, util, packetClientTeams.Suffix)
		if err != nil {
			return
		}
		err = packet.WriteInt8(writer, util, packetClientTeams.FriendlyFire)
	}
	if packetClientTeams.Action == 0 || packetClientTeams.Action == 3 || packetClientTeams.Action == 4 {
		if err != nil {
			return
		}
		err = packet.WriteUint16(writer, util, uint16(len(packetClientTeams.Players)))
		for i := 0; i < len(packetClientTeams.Players); i++ {
			if err != nil {
				return
			}
			err = packet.WriteString(writer, util, packetClientTeams.Players[i])
		}
	}
	return
}
func (this *packetServerPluginMessageCodec17) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetServerPluginMessage := encode.(*PacketServerPluginMessage)
	err = packet.WriteString(writer, util, packetServerPluginMessage.Channel)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, uint16(len(packetServerPluginMessage.Data)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetServerPluginMessage.Data)
	return
}
func (this *PacketClientPlayerListItemCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientPlayerListItem := encode.(*PacketClientPlayerListItem)
	err = packet.WriteString(writer, util, packetClientPlayerListItem.Name)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, util, packetClientPlayerListItem.Online)
	if err != nil {
		return
	}
	err = packet.WriteInt16(writer, util, packetClientPlayerListItem.Ping)
	return
}
Example #20
0
func (this *packetServerEventCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetServerEvent := encode.(*PacketServerEvent)
	err = packet.WriteBool(writer, packetServerEvent.Add)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, packetServerEvent.Server)
	if packetServerEvent.Add {
		if err != nil {
			return
		}
		err = packet.WriteString(writer, packetServerEvent.SecurityKey)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, packetServerEvent.Address)
		if err != nil {
			return
		}
		err = packet.WriteUint16(writer, packetServerEvent.Port)
	}
	return
}
Example #21
0
func (this *requestMessageCodec) Encode(writer io.Writer, request Request) (err error) {
	requestMessage := request.(*RequestMessage)
	err = packet.WriteUint16(writer, uint16(len(requestMessage.Recipients)))
	for i := 0; i < len(requestMessage.Recipients); i++ {
		if err != nil {
			return
		}
		err = packet.WriteString(writer, requestMessage.Recipients[i])
	}
	if err != nil {
		return
	}
	err = packet.WriteString(writer, requestMessage.Channel)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, uint16(len(requestMessage.Message)))
	if err != nil {
		return
	}
	_, err = writer.Write(requestMessage.Message)
	return
}
func (this *packetClientRespawnCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientRespawn := encode.(*PacketClientRespawn)
	err = packet.WriteInt32(writer, util, packetClientRespawn.Dimension)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientRespawn.Difficulty)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientRespawn.Gamemode)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, packetClientRespawn.LevelType)
	return
}
Example #23
0
func (this *PacketServerHandshakeCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetServerHandshake := encode.(*PacketServerHandshake)
	err = packet.WriteVarInt(writer, util, packetServerHandshake.ProtocolVersion)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, packetServerHandshake.ServerAddress)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, packetServerHandshake.ServerPort)
	if err != nil {
		return
	}
	err = packet.WriteVarInt(writer, util, packetServerHandshake.State)
	return
}
func (this *packetClientLoginEncryptRequestCodec17) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientLoginEncryptRequest := encode.(*PacketClientLoginEncryptRequest)
	err = packet.WriteString(writer, util, packetClientLoginEncryptRequest.ServerId)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, uint16(len(packetClientLoginEncryptRequest.PublicKey)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetClientLoginEncryptRequest.PublicKey)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, uint16(len(packetClientLoginEncryptRequest.VerifyToken)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetClientLoginEncryptRequest.VerifyToken)
	return
}
func (this *packetClientLoginEncryptRequestCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetClientLoginEncryptRequest := encode.(*PacketClientLoginEncryptRequest)
	err = packet.WriteString(writer, packetClientLoginEncryptRequest.ServerId)
	if err != nil {
		return
	}
	err = packet.WriteVarInt(writer, len(packetClientLoginEncryptRequest.PublicKey))
	if err != nil {
		return
	}
	_, err = writer.Write(packetClientLoginEncryptRequest.PublicKey)
	if err != nil {
		return
	}
	err = packet.WriteVarInt(writer, len(packetClientLoginEncryptRequest.VerifyToken))
	if err != nil {
		return
	}
	_, err = writer.Write(packetClientLoginEncryptRequest.VerifyToken)
	return
}
func (this *packetServerClientSettingsCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetServerClientSettings := encode.(*PacketServerClientSettings)
	err = packet.WriteString(writer, packetServerClientSettings.Locale)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, packetServerClientSettings.ViewDistance)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, packetServerClientSettings.ChatFlags)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, packetServerClientSettings.ChatColours)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, packetServerClientSettings.SkinParts)
	return
}
Example #27
0
func (this *packetClientTeamsCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetClientTeams := encode.(*PacketClientTeams)
	err = packet.WriteString(writer, packetClientTeams.Name)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientTeams.Action)
	if packetClientTeams.Action == 0 || packetClientTeams.Action == 2 {
		if err != nil {
			return
		}
		err = packet.WriteString(writer, packetClientTeams.DisplayName)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, packetClientTeams.Prefix)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, packetClientTeams.Suffix)
		if err != nil {
			return
		}
		err = packet.WriteInt8(writer, packetClientTeams.FriendlyFire)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, packetClientTeams.NameTagVisibility)
		if err != nil {
			return
		}
		err = packet.WriteInt8(writer, packetClientTeams.Color)
	}
	if packetClientTeams.Action == 0 || packetClientTeams.Action == 3 || packetClientTeams.Action == 4 {
		if err != nil {
			return
		}
		err = packet.WriteVarInt(writer, len(packetClientTeams.Players))
		for i := 0; i < len(packetClientTeams.Players); i++ {
			if err != nil {
				return
			}
			err = packet.WriteString(writer, packetClientTeams.Players[i])
		}
	}
	return
}
Example #28
0
func (this *resultGetPlayersCodec) Encode(writer io.Writer, result Result) (err error) {
	resultGetPlayers := result.(*ResultGetPlayers)
	err = packet.WriteBool(writer, resultGetPlayers.List)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, resultGetPlayers.CurrentPlayers)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, resultGetPlayers.MaxPlayers)
	if resultGetPlayers.List {
		var i uint16
		for i = 0; i < resultGetPlayers.CurrentPlayers; i++ {
			if err != nil {
				return
			}
			err = packet.WriteString(writer, resultGetPlayers.Players[i])
		}
	}
	return
}
func (this *packetClientLoginDisconnectCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientLoginDisconnect := encode.(*PacketClientLoginDisconnect)
	err = packet.WriteString(writer, util, packetClientLoginDisconnect.Json)
	return
}
Example #30
0
func (this *ResultAsServerCodec) Encode(writer io.Writer, util []byte, result Result) (err error) {
	err = packet.WriteString(writer, util, result.(*ResultAsServer).SecurityKey)
	return
}