mirror of
https://github.com/CPunch/gopenfusion.git
synced 2025-10-06 01:30:07 +00:00
major refactoring: db.Player is now core.Player
- misc. cleanup - core/db/players.go: works with core.Player types, will also grab inventory table
This commit is contained in:
@@ -1,10 +1,25 @@
|
||||
package server
|
||||
|
||||
import "github.com/CPunch/gopenfusion/protocol"
|
||||
import "github.com/CPunch/gopenfusion/core/protocol"
|
||||
|
||||
func (server *ShardServer) RequestEnter(peer *protocol.CNPeer, pkt protocol.Packet) error {
|
||||
func (server *ShardServer) RequestEnter(peer *protocol.CNPeer, pkt protocol.Packet) (retErr error) {
|
||||
var enter protocol.SP_CL2FE_REQ_PC_ENTER
|
||||
pkt.Decode(&enter)
|
||||
|
||||
loginData, err := server.CheckLogin(enter.IEnterSerialKey)
|
||||
if err != nil {
|
||||
// the error codes for P_FE2CL_REP_PC_ENTER_FAIL aren't referenced in the client :(
|
||||
peer.Send(protocol.P_FE2CL_REP_PC_ENTER_FAIL, protocol.SP_FE2CL_REP_PC_ENTER_FAIL{})
|
||||
return err
|
||||
}
|
||||
|
||||
plr, err := server.dbHndlr.GetPlayer(int(loginData.PlayerID))
|
||||
if err != nil {
|
||||
peer.Send(protocol.P_FE2CL_REP_PC_ENTER_FAIL, protocol.SP_FE2CL_REP_PC_ENTER_FAIL{})
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO
|
||||
_ = plr
|
||||
return nil
|
||||
}
|
||||
|
@@ -6,9 +6,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"github.com/CPunch/gopenfusion/db"
|
||||
"github.com/CPunch/gopenfusion/protocol"
|
||||
"github.com/CPunch/gopenfusion/util"
|
||||
"github.com/CPunch/gopenfusion/core/db"
|
||||
"github.com/CPunch/gopenfusion/core/protocol"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -113,15 +112,14 @@ func (server *LoginServer) Login(peer *protocol.CNPeer, pkt protocol.Packet) err
|
||||
// build character list
|
||||
charInfo := [4]protocol.SP_LS2CL_REP_CHAR_INFO{}
|
||||
for i, plr := range plrs {
|
||||
PCStyle, PCStyle2 := util.Player2PCStyle(&plr)
|
||||
info := protocol.SP_LS2CL_REP_CHAR_INFO{
|
||||
ISlot: int8(plr.Slot),
|
||||
ILevel: int16(plr.Level),
|
||||
SPC_Style: PCStyle,
|
||||
SPC_Style2: PCStyle2,
|
||||
IX: int32(plr.XCoordinate),
|
||||
IY: int32(plr.YCoordinate),
|
||||
IZ: int32(plr.ZCoordinate),
|
||||
SPC_Style: plr.PCStyle,
|
||||
SPC_Style2: plr.PCStyle2,
|
||||
IX: int32(plr.X),
|
||||
IY: int32(plr.Y),
|
||||
IZ: int32(plr.Z),
|
||||
}
|
||||
|
||||
AEquip, err := server.dbHndlr.GetPlayerInventorySlots(plr.PlayerID, 0, config.AEQUIP_COUNT-1)
|
||||
@@ -227,11 +225,10 @@ func (server *LoginServer) CharacterCreate(peer *protocol.CNPeer, pkt protocol.P
|
||||
return SendFail(peer)
|
||||
}
|
||||
|
||||
PCStyle, PCStyle2 := util.Player2PCStyle(plr)
|
||||
return peer.Send(protocol.P_LS2CL_REP_CHAR_CREATE_SUCC, protocol.SP_LS2CL_REP_CHAR_CREATE_SUCC{
|
||||
ILevel: int16(plr.Level),
|
||||
SPC_Style: PCStyle,
|
||||
SPC_Style2: PCStyle2,
|
||||
SPC_Style: plr.PCStyle,
|
||||
SPC_Style2: plr.PCStyle2,
|
||||
SOn_Item: charPkt.SOn_Item, // if items were faked, we don't really care since the db only stores the sanitized fields
|
||||
})
|
||||
}
|
||||
|
@@ -6,8 +6,8 @@ import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/CPunch/gopenfusion/db"
|
||||
"github.com/CPunch/gopenfusion/protocol"
|
||||
"github.com/CPunch/gopenfusion/core/db"
|
||||
"github.com/CPunch/gopenfusion/core/protocol"
|
||||
)
|
||||
|
||||
type LoginServer struct {
|
||||
|
@@ -7,8 +7,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/CPunch/gopenfusion/db"
|
||||
"github.com/CPunch/gopenfusion/protocol"
|
||||
"github.com/CPunch/gopenfusion/core"
|
||||
"github.com/CPunch/gopenfusion/core/db"
|
||||
"github.com/CPunch/gopenfusion/core/protocol"
|
||||
)
|
||||
|
||||
type LoginMetadata struct {
|
||||
@@ -22,7 +23,7 @@ type ShardServer struct {
|
||||
port int
|
||||
dbHndlr *db.DBHandler
|
||||
packetHandlers map[uint32]PacketHandler
|
||||
peers sync.Map // [*protocol.CNPeer]*db.Player
|
||||
peers sync.Map // [*protocol.CNPeer]*core.Player
|
||||
loginMetadataQueue sync.Map // [int64]*LoginMetadata w/ int64 = serialKey
|
||||
}
|
||||
|
||||
@@ -88,19 +89,19 @@ func (server *ShardServer) Connect(peer *protocol.CNPeer) {
|
||||
server.peers.Store(peer, nil)
|
||||
}
|
||||
|
||||
func (server *ShardServer) JoinPlayer(peer *protocol.CNPeer, player *db.Player) {
|
||||
func (server *ShardServer) JoinPlayer(peer *protocol.CNPeer, player *core.Player) {
|
||||
server.peers.Store(peer, player)
|
||||
}
|
||||
|
||||
// Simple wrapper for server.peers.Range, if f returns false the iteration is stopped.
|
||||
func (server *ShardServer) RangePeers(f func(peer *protocol.CNPeer, player *db.Player) bool) {
|
||||
func (server *ShardServer) RangePeers(f func(peer *protocol.CNPeer, player *core.Player) bool) {
|
||||
server.peers.Range(func(key, value any) bool { // simple wrapper to cast the datatypes
|
||||
peer, ok := key.(*protocol.CNPeer)
|
||||
if !ok { // this should never happen
|
||||
panic(fmt.Errorf("ShardServer.peers has an invalid key: peers[%#v] = %#v", key, value))
|
||||
}
|
||||
|
||||
player, ok := value.(*db.Player)
|
||||
player, ok := value.(*core.Player)
|
||||
if !ok { // this should also never happen
|
||||
panic(fmt.Errorf("ShardServer.peers has an invalid value: peers[%#v] = %#v", key, value))
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/CPunch/gopenfusion/protocol"
|
||||
"github.com/CPunch/gopenfusion/core/protocol"
|
||||
)
|
||||
|
||||
type PacketHandler func(peer *protocol.CNPeer, pkt protocol.Packet) error
|
||||
|
Reference in New Issue
Block a user