diff --git a/README.md b/README.md index a51858a..561ab68 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/server/login.go b/login/login.go similarity index 98% rename from server/login.go rename to login/login.go index d44bf8c..87864aa 100644 --- a/server/login.go +++ b/login/login.go @@ -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), diff --git a/server/loginServer.go b/login/loginServer.go similarity index 89% rename from server/loginServer.go rename to login/loginServer.go index 36caecd..0a4ca50 100644 --- a/server/loginServer.go +++ b/login/loginServer.go @@ -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 } diff --git a/main.go b/main.go index 7f3e810..49b5cd6 100644 --- a/main.go +++ b/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) } diff --git a/server/shared.go b/server/shared.go deleted file mode 100644 index 935c59a..0000000 --- a/server/shared.go +++ /dev/null @@ -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 } diff --git a/server/join.go b/shard/join.go similarity index 99% rename from server/join.go rename to shard/join.go index 33d09d0..33a6bcb 100644 --- a/server/join.go +++ b/shard/join.go @@ -1,4 +1,4 @@ -package server +package shard import ( "fmt" diff --git a/server/shardServer.go b/shard/shardServer.go similarity index 94% rename from server/shardServer.go rename to shard/shardServer.go index c0467f5..21f4cfa 100644 --- a/server/shardServer.go +++ b/shard/shardServer.go @@ -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 {