mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-21 23:10:06 +00:00
server: split login/ and shard/
This commit is contained in:
parent
70e42b5d79
commit
727c68aef3
@ -4,7 +4,7 @@ A toy implementation of the [Fusionfall Packet Protocol](https://openpunk.com/pa
|
||||
|
||||
## Landwalker demo
|
||||
|
||||
An implementation of a landwalker server is located in `server/`. This includes a functional login server and a dummy shard (supporting the minimum amount of packets necessary). The DB implementation in `core/db/` matches the OpenFusion 1.4 SQLite tables, which the login server located in `server/` uses. There's no support for NPCs nor other players, and is liable to softlock the client.
|
||||
An implementation of a landwalker server is located in `login/` && `shard/`. This includes a functional login server and a dummy shard (supporting the minimum amount of packets necessary). The DB implementation in `core/db/` matches the OpenFusion 1.4 SQLite tables, which the login server uses. There's no support for NPCs nor other players, and is liable to softlock the client.
|
||||
|
||||
## Generating structures
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package server
|
||||
package login
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"github.com/CPunch/gopenfusion/core/db"
|
||||
"github.com/CPunch/gopenfusion/core/protocol"
|
||||
"github.com/CPunch/gopenfusion/shard"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -263,14 +264,14 @@ func (server *LoginServer) ShardSelect(peer *protocol.CNPeer, pkt protocol.Packe
|
||||
// TODO: verify peer->AccountID and selection->IPC_UID are valid!!!!
|
||||
|
||||
resp := protocol.SP_LS2CL_REP_SHARD_SELECT_SUCC{
|
||||
G_FE_ServerPort: int32(server.shard.port),
|
||||
G_FE_ServerPort: int32(server.shard.GetPort()),
|
||||
IEnterSerialKey: key,
|
||||
}
|
||||
|
||||
// the rest of the bytes in G_FE_ServerIP will be zero'd, so there's no need to write the NULL byte
|
||||
copy(resp.G_FE_ServerIP[:], []byte(config.SHARD_IP))
|
||||
|
||||
server.shard.QueueLogin(key, &LoginMetadata{
|
||||
server.shard.QueueLogin(key, &shard.LoginMetadata{
|
||||
FEKey: peer.FE_key,
|
||||
Timestamp: time.Now(),
|
||||
PlayerID: int32(selection.IPC_UID),
|
@ -1,4 +1,4 @@
|
||||
package server
|
||||
package login
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -8,8 +8,13 @@ import (
|
||||
|
||||
"github.com/CPunch/gopenfusion/core/db"
|
||||
"github.com/CPunch/gopenfusion/core/protocol"
|
||||
"github.com/CPunch/gopenfusion/shard"
|
||||
)
|
||||
|
||||
type PacketHandler func(peer *protocol.CNPeer, pkt protocol.Packet) error
|
||||
|
||||
func stubbedPacket(_ *protocol.CNPeer, _ protocol.Packet) error { /* stubbed */ return nil }
|
||||
|
||||
type LoginServer struct {
|
||||
listener net.Listener
|
||||
port int
|
||||
@ -17,7 +22,7 @@ type LoginServer struct {
|
||||
packetHandlers map[uint32]PacketHandler
|
||||
peers map[*protocol.CNPeer]bool
|
||||
peersLock sync.Mutex
|
||||
shard *ShardServer
|
||||
shard *shard.ShardServer
|
||||
}
|
||||
|
||||
func NewLoginServer(dbHndlr *db.DBHandler, port int) (*LoginServer, error) {
|
||||
@ -95,6 +100,6 @@ func (server *LoginServer) Connect(peer *protocol.CNPeer) {
|
||||
server.peersLock.Unlock()
|
||||
}
|
||||
|
||||
func (server *LoginServer) AddShard(shard *ShardServer) {
|
||||
func (server *LoginServer) AddShard(shard *shard.ShardServer) {
|
||||
server.shard = shard
|
||||
}
|
7
main.go
7
main.go
@ -5,7 +5,8 @@ import (
|
||||
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"github.com/CPunch/gopenfusion/core/db"
|
||||
"github.com/CPunch/gopenfusion/server"
|
||||
"github.com/CPunch/gopenfusion/login"
|
||||
"github.com/CPunch/gopenfusion/shard"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -15,12 +16,12 @@ func main() {
|
||||
}
|
||||
dbHndlr.Setup()
|
||||
|
||||
loginServer, err := server.NewLoginServer(dbHndlr, config.LOGIN_PORT)
|
||||
loginServer, err := login.NewLoginServer(dbHndlr, config.LOGIN_PORT)
|
||||
if err != nil {
|
||||
log.Panicf("failed to create login server: %v", err)
|
||||
}
|
||||
|
||||
shardServer, err := server.NewShardServer(dbHndlr, config.SHARD_PORT)
|
||||
shardServer, err := shard.NewShardServer(dbHndlr, config.SHARD_PORT)
|
||||
if err != nil {
|
||||
log.Panicf("failed to create shard server: %v", err)
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/CPunch/gopenfusion/core/protocol"
|
||||
)
|
||||
|
||||
type PacketHandler func(peer *protocol.CNPeer, pkt protocol.Packet) error
|
||||
|
||||
func stubbedPacket(_ *protocol.CNPeer, _ protocol.Packet) error { /* stubbed */ return nil }
|
@ -1,4 +1,4 @@
|
||||
package server
|
||||
package shard
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package server
|
||||
package shard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -18,6 +18,10 @@ type LoginMetadata struct {
|
||||
PlayerID int32
|
||||
}
|
||||
|
||||
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
|
||||
@ -69,6 +73,10 @@ func (server *ShardServer) Start() {
|
||||
}
|
||||
}
|
||||
|
||||
func (server *ShardServer) GetPort() int {
|
||||
return server.port
|
||||
}
|
||||
|
||||
func (server *ShardServer) HandlePacket(peer *protocol.CNPeer, typeID uint32, pkt protocol.Packet) error {
|
||||
if hndlr, ok := server.packetHandlers[typeID]; ok {
|
||||
if err := hndlr(peer, pkt); err != nil {
|
Loading…
Reference in New Issue
Block a user