mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-21 15:00:07 +00:00
minor refactoring, fixed go-staticcheck warnings
This commit is contained in:
parent
670d4a514c
commit
83b664da93
@ -31,7 +31,7 @@ func (pkt Packet) encodeStructField(field reflect.StructField, value reflect.Val
|
||||
case reflect.String: // all strings in fusionfall packets are encoded as utf16, we'll need to encode it
|
||||
sz, err := strconv.Atoi(field.Tag.Get("size"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to grab string 'size' tag!!")
|
||||
return fmt.Errorf("failed to grab string 'size' tag")
|
||||
}
|
||||
|
||||
buf16 := utf16.Encode([]rune(value.String()))
|
||||
@ -100,7 +100,7 @@ func (pkt Packet) decodeStructField(field reflect.StructField, value reflect.Val
|
||||
case reflect.String: // all strings in fusionfall packets are encoded as utf16, we'll need to decode it
|
||||
sz, err := strconv.Atoi(field.Tag.Get("size"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to grab string 'size' tag!!")
|
||||
return fmt.Errorf("failed to grab string 'size' tag")
|
||||
}
|
||||
|
||||
buf16 := make([]uint16, sz)
|
||||
|
@ -11,9 +11,9 @@ import (
|
||||
|
||||
func (server *ShardServer) attachPlayer(peer *protocol.CNPeer, meta redis.LoginMetadata) (*entity.Player, error) {
|
||||
// resending a shard enter packet?
|
||||
old, err := server.getPlayer(peer)
|
||||
old, _ := server.getPlayer(peer)
|
||||
if old != nil {
|
||||
return nil, fmt.Errorf("resent enter packet!")
|
||||
return nil, fmt.Errorf("resent enter packet")
|
||||
}
|
||||
|
||||
// attach player
|
||||
|
@ -16,8 +16,6 @@ import (
|
||||
|
||||
type PacketHandler func(peer *protocol.CNPeer, pkt protocol.Packet) error
|
||||
|
||||
func stubbedPacket(_ *protocol.CNPeer, _ protocol.Packet) error { /* stubbed */ return nil }
|
||||
|
||||
type ShardServer struct {
|
||||
listener net.Listener
|
||||
port int
|
||||
@ -67,18 +65,17 @@ func NewShardServer(dbHndlr *db.DBHandler, redisHndlr *redis.RedisHandler, port
|
||||
}
|
||||
|
||||
func (server *ShardServer) handleEvents() {
|
||||
for {
|
||||
select {
|
||||
case event := <-server.eRecv:
|
||||
switch event.Type {
|
||||
case protocol.EVENT_CLIENT_DISCONNECT:
|
||||
server.disconnect(event.Peer)
|
||||
case protocol.EVENT_CLIENT_PACKET:
|
||||
defer pool.Put(event.Pkt)
|
||||
if err := server.handlePacket(event.Peer, event.PktID, protocol.NewPacket(event.Pkt)); err != nil {
|
||||
event.Peer.Kill()
|
||||
}
|
||||
for event := range server.eRecv {
|
||||
switch event.Type {
|
||||
case protocol.EVENT_CLIENT_DISCONNECT:
|
||||
server.disconnect(event.Peer)
|
||||
case protocol.EVENT_CLIENT_PACKET:
|
||||
if err := server.handlePacket(event.Peer, event.PktID, protocol.NewPacket(event.Pkt)); err != nil {
|
||||
event.Peer.Kill()
|
||||
}
|
||||
|
||||
// the packet is given to us by the event, so we'll need to make sure to return it to the pool
|
||||
pool.Put(event.Pkt)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,7 +140,7 @@ func (server *ShardServer) connect(peer *protocol.CNPeer) {
|
||||
func (server *ShardServer) getPlayer(peer *protocol.CNPeer) (*entity.Player, error) {
|
||||
plr, ok := server.peers[peer]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Player not found")
|
||||
return nil, fmt.Errorf("player not found")
|
||||
}
|
||||
|
||||
return plr, nil
|
||||
|
Loading…
Reference in New Issue
Block a user