mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-21 23:10:06 +00:00
protocol/packet: switch away from allocation
- Packet struct is small enough that allocation for it is really unnecessary, and can be passed around by value fairly easily
This commit is contained in:
parent
985890d351
commit
f1552830a0
@ -19,14 +19,13 @@ type Packet struct {
|
||||
readWriter io.ReadWriter
|
||||
}
|
||||
|
||||
func NewPacket(readWriter io.ReadWriter) *Packet {
|
||||
pkt := &Packet{
|
||||
func NewPacket(readWriter io.ReadWriter) Packet {
|
||||
return Packet{
|
||||
readWriter: readWriter,
|
||||
}
|
||||
return pkt
|
||||
}
|
||||
|
||||
func (pkt *Packet) encodeStructField(field reflect.StructField, value reflect.Value) {
|
||||
func (pkt Packet) encodeStructField(field reflect.StructField, value reflect.Value) {
|
||||
log.Printf("Encoding '%s'", field.Name)
|
||||
|
||||
switch field.Type.Kind() {
|
||||
@ -65,7 +64,7 @@ func (pkt *Packet) encodeStructField(field reflect.StructField, value reflect.Va
|
||||
}
|
||||
}
|
||||
|
||||
func (pkt *Packet) Encode(data interface{}) {
|
||||
func (pkt Packet) Encode(data interface{}) {
|
||||
rv := reflect.Indirect(reflect.ValueOf(data))
|
||||
|
||||
switch rv.Kind() {
|
||||
@ -81,7 +80,7 @@ func (pkt *Packet) Encode(data interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (pkt *Packet) decodeStructField(field reflect.StructField, value reflect.Value) {
|
||||
func (pkt Packet) decodeStructField(field reflect.StructField, value reflect.Value) {
|
||||
log.Printf("Decoding '%s'", field.Name)
|
||||
|
||||
switch field.Type.Kind() {
|
||||
@ -116,7 +115,7 @@ func (pkt *Packet) decodeStructField(field reflect.StructField, value reflect.Va
|
||||
}
|
||||
}
|
||||
|
||||
func (pkt *Packet) Decode(data interface{}) {
|
||||
func (pkt Packet) Decode(data interface{}) {
|
||||
rv := reflect.Indirect(reflect.ValueOf(data))
|
||||
|
||||
switch rv.Kind() {
|
||||
|
@ -54,7 +54,7 @@ func (server *LoginServer) AcceptLogin(peer *Peer, SzID string, IClientVerC int3
|
||||
}
|
||||
}
|
||||
|
||||
func (server *LoginServer) Login(peer *Peer, pkt *protocol.Packet) {
|
||||
func (server *LoginServer) Login(peer *Peer, pkt protocol.Packet) {
|
||||
var loginPkt protocol.SP_CL2LS_REQ_LOGIN
|
||||
pkt.Decode(&loginPkt)
|
||||
|
||||
@ -125,7 +125,7 @@ func (server *LoginServer) Login(peer *Peer, pkt *protocol.Packet) {
|
||||
server.AcceptLogin(peer, loginPkt.SzID, loginPkt.IClientVerC, 1, charInfo)
|
||||
}
|
||||
|
||||
func (server *LoginServer) CheckCharacterName(peer *Peer, pkt *protocol.Packet) {
|
||||
func (server *LoginServer) CheckCharacterName(peer *Peer, pkt protocol.Packet) {
|
||||
var charPkt protocol.SP_CL2LS_REQ_CHECK_CHAR_NAME
|
||||
pkt.Decode(&charPkt)
|
||||
|
||||
@ -136,7 +136,7 @@ func (server *LoginServer) CheckCharacterName(peer *Peer, pkt *protocol.Packet)
|
||||
}, protocol.P_LS2CL_REP_CHECK_CHAR_NAME_SUCC)
|
||||
}
|
||||
|
||||
func (server *LoginServer) SaveCharacterName(peer *Peer, pkt *protocol.Packet) {
|
||||
func (server *LoginServer) SaveCharacterName(peer *Peer, pkt protocol.Packet) {
|
||||
var charPkt protocol.SP_CL2LS_REQ_SAVE_CHAR_NAME
|
||||
pkt.Decode(&charPkt)
|
||||
|
||||
@ -187,7 +187,7 @@ func validateCharacterCreation(character *protocol.SP_CL2LS_REQ_CHAR_CREATE) boo
|
||||
return true
|
||||
}
|
||||
|
||||
func (server *LoginServer) CharacterCreate(peer *Peer, pkt *protocol.Packet) {
|
||||
func (server *LoginServer) CharacterCreate(peer *Peer, pkt protocol.Packet) {
|
||||
var charPkt protocol.SP_CL2LS_REQ_CHAR_CREATE
|
||||
pkt.Decode(&charPkt)
|
||||
|
||||
@ -216,7 +216,7 @@ func (server *LoginServer) CharacterCreate(peer *Peer, pkt *protocol.Packet) {
|
||||
}, protocol.P_LS2CL_REP_CHAR_CREATE_SUCC)
|
||||
}
|
||||
|
||||
func (server *LoginServer) CharacterDelete(peer *Peer, pkt *protocol.Packet) {
|
||||
func (server *LoginServer) CharacterDelete(peer *Peer, pkt protocol.Packet) {
|
||||
var charPkt protocol.SP_CL2LS_REQ_CHAR_DELETE
|
||||
pkt.Decode(&charPkt)
|
||||
|
||||
@ -231,7 +231,7 @@ func (server *LoginServer) CharacterDelete(peer *Peer, pkt *protocol.Packet) {
|
||||
}, protocol.P_LS2CL_REP_CHAR_DELETE_SUCC)
|
||||
}
|
||||
|
||||
func (server *LoginServer) FinishTutorial(peer *Peer, pkt *protocol.Packet) {
|
||||
func (server *LoginServer) FinishTutorial(peer *Peer, pkt protocol.Packet) {
|
||||
var charPkt protocol.SP_CL2LS_REQ_SAVE_CHAR_TUTOR
|
||||
pkt.Decode(&charPkt)
|
||||
|
||||
|
@ -42,7 +42,7 @@ func (server *LoginServer) Start() {
|
||||
}
|
||||
}
|
||||
|
||||
func (server *LoginServer) HandlePacket(peer *Peer, typeID uint32, pkt *protocol.Packet) {
|
||||
func (server *LoginServer) HandlePacket(peer *Peer, typeID uint32, pkt protocol.Packet) {
|
||||
switch typeID {
|
||||
case protocol.P_CL2LS_REQ_LOGIN:
|
||||
server.Login(peer, pkt)
|
||||
|
@ -18,7 +18,7 @@ const (
|
||||
)
|
||||
|
||||
type PeerHandler interface {
|
||||
HandlePacket(client *Peer, typeID uint32, pkt *protocol.Packet)
|
||||
HandlePacket(client *Peer, typeID uint32, pkt protocol.Packet)
|
||||
Connect(client *Peer)
|
||||
Disconnect(client *Peer)
|
||||
}
|
||||
@ -116,8 +116,6 @@ func (client *Peer) ClientHandler() {
|
||||
panic(fmt.Errorf("[FATAL] failed to read packet body! %v", err))
|
||||
}
|
||||
|
||||
fmt.Printf("%#v", buf)
|
||||
|
||||
// decrypt
|
||||
protocol.DecryptData(buf.Bytes(), client.E_key)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user