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
}
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 *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
}
예제 #5
0
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
}
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
}
예제 #7
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
}
예제 #8
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
}
예제 #9
0
func (this *packetClientPlayerListCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetClientPlayerList := encode.(*PacketClientPlayerList)
	err = packet.WriteVarInt(writer, packetClientPlayerList.Action)
	if err != nil {
		return
	}
	err = packet.WriteVarInt(writer, len(packetClientPlayerList.Items))
	if err != nil {
		return
	}
	for _, item := range packetClientPlayerList.Items {
		err = packet.WriteUUID(writer, item.UUID)
		if err != nil {
			return
		}
		switch packetClientPlayerList.Action {
		case PACKET_CLIENT_PLAYER_LIST_ACTION_ADD:
			addPlayer := item.Info.(PacketClientPlayerListAddPlayer)
			err = packet.WriteString(writer, addPlayer.Name)
			if err != nil {
				return
			}
			err = packet.WriteVarInt(writer, len(addPlayer.Properties))
			if err != nil {
				return
			}
			for _, property := range addPlayer.Properties {
				err = packet.WriteString(writer, property.Name)
				if err != nil {
					return
				}
				err = packet.WriteString(writer, property.Value)
				if err != nil {
					return
				}
				if property.Signature == "" {
					err = packet.WriteBool(writer, false)
					if err != nil {
						return
					}
				} else {
					err = packet.WriteBool(writer, true)
					if err != nil {
						return
					}
					err = packet.WriteString(writer, property.Signature)
					if err != nil {
						return
					}
				}
			}
			err = packet.WriteVarInt(writer, addPlayer.Gamemode)
			if err != nil {
				return
			}
			err = packet.WriteVarInt(writer, addPlayer.Latency)
			if err != nil {
				return
			}
			if addPlayer.DisplayName == "" {
				err = packet.WriteBool(writer, false)
				if err != nil {
					return
				}
			} else {
				err = packet.WriteBool(writer, true)
				if err != nil {
					return
				}
				err = packet.WriteString(writer, addPlayer.DisplayName)
				if err != nil {
					return
				}
			}
		case PACKET_CLIENT_PLAYER_LIST_ACTION_UPDATE_GAMEMODE:
			updateGamemode := item.Info.(PacketClientPlayerListUpdateGamemode)
			err = packet.WriteVarInt(writer, updateGamemode.Gamemode)
			if err != nil {
				return
			}
		case PACKET_CLIENT_PLAYER_LIST_ACTION_UPDATE_LATENCY:
			updateLatency := item.Info.(PacketClientPlayerListUpdateLatency)
			err = packet.WriteVarInt(writer, updateLatency.Latency)
			if err != nil {
				return
			}
		case PACKET_CLIENT_PLAYER_LIST_ACTION_UPDATE_DISPLAY_NAME:
			updateDisplayName := item.Info.(PacketClientPlayerListUpdateDisplayName)
			if updateDisplayName.DisplayName == "" {
				err = packet.WriteBool(writer, false)
				if err != nil {
					return
				}
			} else {
				err = packet.WriteBool(writer, true)
				if err != nil {
					return
				}
				err = packet.WriteString(writer, updateDisplayName.DisplayName)
				if err != nil {
					return
				}
			}
		case PACKET_CLIENT_PLAYER_LIST_ACTION_REMOVE:
			// no payload
		default:
			err = errors.New(fmt.Sprintf("Encode, PacketClientPlayerList action is not valid: %d", packetClientPlayerList.Action))
		}
	}
	return
}
예제 #10
0
func (this *requestGetPlayersCodec) Encode(writer io.Writer, request Request) (err error) {
	err = packet.WriteBool(writer, request.(*RequestGetPlayers).List)
	return
}