Exemplo n.º 1
0
func (this *Session) Serve() {
	this.pipeline = packet.NewPacketPipeline()
	this.pipeline.AddLast("varIntLength", packet.NewPacketCodecVarIntLength())
	this.pipeline.AddLast("registry", connect.PacketCodec)
	this.connCodec = packet.NewPacketConnCodec(this.conn, this.pipeline, 10*time.Second)
	this.connCodec.ReadConn(this)
}
Exemplo n.º 2
0
func (this *Session) Serve() {
	this.pipeline = packet.NewPacketPipeline()
	this.pipeline.AddLast("varIntLength", packet.NewPacketCodecVarIntLength())
	this.pipeline.AddLast("registry", minecraft.HandshakePacketServerCodec)
	this.connCodec = packet.NewPacketConnCodec(this.conn, this.pipeline, 30*time.Second)
	this.connCodec.ReadConn(this)
}
func (this *SessionOutBridge) Serve() {
	this.pipeline = packet.NewPacketPipeline()
	this.pipeline.AddLast("varIntLength", packet.NewPacketCodecVarIntLength())
	this.pipeline.AddLast("registry", minecraft.HandshakePacketClientCodec)
	this.connCodec = packet.NewPacketConnCodec(this.conn, this.pipeline, 30*time.Second)

	inRemotePort, _ := strconv.ParseUint(this.session.remotePort, 10, 16)
	outRemotePort, _ := strconv.ParseUint(this.remotePort, 10, 16)
	loginPayload := LoginPayload{
		SecurityKey: this.server.SecurityKey,
		Host:        this.session.serverAddress,
		RealIp:      this.session.remoteIp,
		RealPort:    int(inRemotePort),
		Name:        this.session.name,
		UUID:        this.session.profile.Id,
		Properties:  make([]LoginPayloadProperty, 0),
	}
	for _, property := range this.session.profile.Properties {
		loginPayload.Properties = append(loginPayload.Properties, LoginPayloadProperty{property.Name, property.Value, property.Signature})
	}
	this.Write(minecraft.NewPacketServerHandshake(this.session.protocolVersion, EncodeLoginPayload(loginPayload), uint16(outRemotePort), 2))

	if this.session.protocol17 {
		this.pipeline.Replace("registry", minecraft.LoginPacketClientCodec17)
	} else {
		this.pipeline.Replace("registry", minecraft.LoginPacketClientCodec)
	}
	this.Write(minecraft.NewPacketServerLoginStart(this.session.name))

	this.state = STATE_LOGIN
	go this.connCodec.ReadConn(this)
}
Exemplo n.º 4
0
func (this *ConnectImpl) Connect(addr string) (err error) {
	this.Disconnect()
	this.conn, err = net.Dial("tcp", addr)
	if err != nil {
		return
	}
	this.recordsMutex.Lock()
	defer this.recordsMutex.Unlock()
	this.records = make(map[int32]*RequestRecord)
	this.pipeline = packet.NewPacketPipeline()
	this.pipeline.AddLast("varIntLength", packet.NewPacketCodecVarIntLength())
	this.pipeline.AddLast("registry", NewCodecRegistry(this))
	this.connCodec = packet.NewPacketConnCodec(this.conn, this.pipeline, 10*time.Second)
	go this.connCodec.ReadConn(this)
	return
}
Exemplo n.º 5
0
	REQUEST_GET_WHOAMI:    &RequestGetWhoamiCodec{},
	REQUEST_MESSAGE:       &RequestMessageCodec{},
	REQUEST_REDIRECT:      &RequestRedirectCodec{},
	REQUEST_GET_PLAYERS:   &RequestGetPlayersCodec{},
	REQUEST_NOTIFY_PLAYER: &RequestNotifyPlayerCodec{},
	REQUEST_GET_DETAILS:   &RequestGetDetailsCodec{},
}

var resultCodecs = []ResultCodec{
	REQUEST_AUTHENTICATE:  &ResultAuthenticateCodec{},
	REQUEST_AS_SERVER:     &ResultAsServerCodec{},
	REQUEST_AS_PROXY:      &ResultAsProxyCodec{},
	REQUEST_GET_SALT:      &ResultGetSaltCodec{},
	REQUEST_GET_WHOAMI:    &ResultGetWhoamiCodec{},
	REQUEST_MESSAGE:       &ResultMessageCodec{},
	REQUEST_REDIRECT:      &ResultRedirectCodec{},
	REQUEST_GET_PLAYERS:   &ResultGetPlayersCodec{},
	REQUEST_NOTIFY_PLAYER: &ResultNotifyPlayerCodec{},
	REQUEST_GET_DETAILS:   &ResultGetDetailsCodec{},
}

var PacketCodecs = []packet.PacketCodec{
	PACKET_KEEPALIVE:      &PacketKeepaliveCodec{},
	PACKET_REQUEST:        &PacketRequestCodec{},
	PACKET_RESULT:         &PacketResultCodec{nil},
	PACKET_MESSAGE_EVENT:  &PacketMessageEventCodec{},
	PACKET_REDIRECT_EVENT: &PacketRedirectEventCodec{},
	PACKET_SERVER_EVENT:   &PacketServerEventCodec{},
}
var PacketCodec = packet.NewPacketCodecVarIntLength(packet.NewPacketCodecRegistry(PacketCodecs))
Exemplo n.º 6
0
	PACKET_SERVER_PLUGIN_MESSAGE                = 0x17

	PACKET_CLIENT_STATUS_RESPONSE = 0x00
	PACKET_CLIENT_STATUS_PING     = 0x01
	PACKET_SERVER_STATUS_REQUEST  = 0x00
	PACKET_SERVER_STATUS_PING     = 0x01

	PACKET_CLIENT_LOGIN_DISCONNECT       = 0x00
	PACKET_CLIENT_LOGIN_ENCRYPT_REQUEST  = 0x01
	PACKET_CLIENT_LOGIN_SUCCESS          = 0x02
	PACKET_SERVER_LOGIN_START            = 0x00
	PACKET_SERVER_LOGIN_ENCRYPT_RESPONSE = 0x01
)

var HandshakePacketClientCodecs = []packet.PacketCodec{}
var HandshakePacketClientCodec = packet.NewPacketCodecVarIntLength(packet.NewPacketCodecRegistry(HandshakePacketClientCodecs))

var HandshakePacketServerCodecs = []packet.PacketCodec{
	PACKET_SERVER_HANDSHAKE: &PacketServerHandshakeCodec{},
}
var HandshakePacketServerCodec = packet.NewPacketCodecVarIntLength(packet.NewPacketCodecRegistry(HandshakePacketServerCodecs))

var PlayPacketClientCodecs = []packet.PacketCodec{
	PACKET_CLIENT_KEEPALIVE:                     &PacketGenericCodec{PACKET_CLIENT_KEEPALIVE},
	PACKET_CLIENT_JOIN_GAME:                     &PacketClientJoinGameCodec{},
	PACKET_CLIENT_CHAT:                          &PacketGenericCodec{PACKET_CLIENT_CHAT},
	PACKET_CLIENT_TIME_UPDATE:                   &PacketGenericCodec{PACKET_CLIENT_TIME_UPDATE},
	PACKET_CLIENT_ENTITY_EQUIPMENT:              &PacketGenericCodec{PACKET_CLIENT_ENTITY_EQUIPMENT},
	PACKET_CLIENT_SPAWN_POSITION:                &PacketGenericCodec{PACKET_CLIENT_SPAWN_POSITION},
	PACKET_CLIENT_UPDATE_HEALTH:                 &PacketGenericCodec{PACKET_CLIENT_UPDATE_HEALTH},
	PACKET_CLIENT_RESPAWN:                       &PacketClientRespawnCodec{},
Exemplo n.º 7
0
func NewCodec(connectClient Connect) packet.PacketCodec {
	packetCodecs := make([]packet.PacketCodec, len(connect.PacketCodecs))
	copy(packetCodecs, connect.PacketCodecs)
	packetCodecs[connect.PACKET_RESULT] = connect.NewPacketResultCodec(connectClient)
	return packet.NewPacketCodecVarIntLength(packet.NewPacketCodecRegistry(packetCodecs))
}