mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-21 23:10:06 +00:00
absolute minimal login server
This commit is contained in:
parent
8f3f31d354
commit
4d0bd4b1c1
@ -3,7 +3,6 @@ package protocol
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"unicode/utf16"
|
"unicode/utf16"
|
||||||
@ -78,7 +77,7 @@ func (pkt *Packet) readByte() byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pkt *Packet) encodeStructField(field reflect.StructField, value reflect.Value) {
|
func (pkt *Packet) encodeStructField(field reflect.StructField, value reflect.Value) {
|
||||||
log.Printf("Encoding '%s', current cursor: %d", field.Name, len(pkt.Buf))
|
// log.Printf("Encoding '%s', current cursor: %d", field.Name, len(pkt.Buf))
|
||||||
|
|
||||||
switch field.Type.Kind() {
|
switch field.Type.Kind() {
|
||||||
case reflect.String: // all strings in fusionfall packets are encoded as utf16, we'll need to encode it
|
case reflect.String: // all strings in fusionfall packets are encoded as utf16, we'll need to encode it
|
||||||
@ -102,7 +101,6 @@ func (pkt *Packet) encodeStructField(field reflect.StructField, value reflect.Va
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("sending %d", len(buf))
|
|
||||||
pkt.Write(buf)
|
pkt.Write(buf)
|
||||||
default:
|
default:
|
||||||
pkt.Encode(value.Addr().Interface())
|
pkt.Encode(value.Addr().Interface())
|
||||||
@ -168,7 +166,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', current cursor: %d", field.Name, pkt.cursor)
|
// log.Printf("Decoding '%s', current cursor: %d", field.Name, pkt.cursor)
|
||||||
|
|
||||||
switch field.Type.Kind() {
|
switch field.Type.Kind() {
|
||||||
case reflect.String: // all strings in fusionfall packets are encoded as utf16, we'll need to decode it
|
case reflect.String: // all strings in fusionfall packets are encoded as utf16, we'll need to decode it
|
||||||
@ -193,7 +191,6 @@ func (pkt *Packet) decodeStructField(field reflect.StructField, value reflect.Va
|
|||||||
}
|
}
|
||||||
|
|
||||||
str := string(utf16.Decode(buf16[:realSize]))
|
str := string(utf16.Decode(buf16[:realSize]))
|
||||||
log.Printf(" got: %#.v or '%s'", buf16, str)
|
|
||||||
value.SetString(str)
|
value.SetString(str)
|
||||||
default:
|
default:
|
||||||
pkt.Decode(value.Addr().Interface())
|
pkt.Decode(value.Addr().Interface())
|
||||||
@ -222,7 +219,6 @@ func (pkt *Packet) Decode(data interface{}) {
|
|||||||
sz := rv.Len()
|
sz := rv.Len()
|
||||||
|
|
||||||
// decode data
|
// decode data
|
||||||
log.Print("reading array length ", sz, " cursor: ", pkt.cursor)
|
|
||||||
for i := 0; i < sz; i++ {
|
for i := 0; i < sz; i++ {
|
||||||
elem := rv.Index(i)
|
elem := rv.Index(i)
|
||||||
pkt.Decode(elem.Addr().Interface())
|
pkt.Decode(elem.Addr().Interface())
|
||||||
|
@ -61,19 +61,13 @@ func (client *Client) Send(data interface{}, typeID uint32) {
|
|||||||
if _, err := client.conn.Write(tmp); err != nil {
|
if _, err := client.conn.Write(tmp); err != nil {
|
||||||
panic(fmt.Errorf("[FATAL] failed to write packet body! %v", err))
|
panic(fmt.Errorf("[FATAL] failed to write packet body! %v", err))
|
||||||
}
|
}
|
||||||
log.Printf("sent!")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) Login(pkt *protocol.Packet) {
|
func (client *Client) AcceptLogin(SZID string, IClientVerC int32, ISlotNum int8, data []protocol.SP_LS2CL_REP_CHAR_INFO) {
|
||||||
var loginPkt protocol.SP_CL2LS_REQ_LOGIN
|
|
||||||
pkt.Decode(&loginPkt)
|
|
||||||
log.Printf("Got packet: %#v", loginPkt)
|
|
||||||
|
|
||||||
// !! TODO
|
|
||||||
resp := &protocol.SP_LS2CL_REP_LOGIN_SUCC{
|
resp := &protocol.SP_LS2CL_REP_LOGIN_SUCC{
|
||||||
SZID: loginPkt.SZID,
|
SZID: SZID,
|
||||||
ICharCount: 0,
|
ICharCount: int8(len(data)),
|
||||||
ISlotNum: 1,
|
ISlotNum: ISlotNum,
|
||||||
IPaymentFlag: 1,
|
IPaymentFlag: 1,
|
||||||
IOpenBetaFlag: 0,
|
IOpenBetaFlag: 0,
|
||||||
UISvrTime: uint64(time.Now().Unix()),
|
UISvrTime: uint64(time.Now().Unix()),
|
||||||
@ -87,9 +81,14 @@ func (client *Client) Login(pkt *protocol.Packet) {
|
|||||||
)
|
)
|
||||||
client.fe_key = protocol.CreateNewKey(
|
client.fe_key = protocol.CreateNewKey(
|
||||||
binary.LittleEndian.Uint64([]byte(protocol.DEFAULT_KEY)),
|
binary.LittleEndian.Uint64([]byte(protocol.DEFAULT_KEY)),
|
||||||
uint64(loginPkt.IClientVerC),
|
uint64(IClientVerC),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// send characters (if any)
|
||||||
|
for i := 0; i < len(data); i++ {
|
||||||
|
client.Send(data[i], protocol.P_LS2CL_REP_CHAR_INFO)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) ClientHandler() {
|
func (client *Client) ClientHandler() {
|
||||||
@ -121,16 +120,12 @@ func (client *Client) ClientHandler() {
|
|||||||
|
|
||||||
// decrypt && grab typeID
|
// decrypt && grab typeID
|
||||||
protocol.DecryptData(tmp[:sz], client.e_key)
|
protocol.DecryptData(tmp[:sz], client.e_key)
|
||||||
typeID := int(binary.LittleEndian.Uint32(tmp[:4]))
|
typeID := uint32(binary.LittleEndian.Uint32(tmp[:4]))
|
||||||
|
|
||||||
|
// dispatch packet
|
||||||
log.Printf("Got packet ID: %x, with a sizeof: %d\n", typeID, sz)
|
log.Printf("Got packet ID: %x, with a sizeof: %d\n", typeID, sz)
|
||||||
pkt := protocol.NewPacket(tmp[4:sz])
|
pkt := protocol.NewPacket(tmp[4:sz])
|
||||||
switch typeID {
|
client.server.handlePacket(client, typeID, pkt)
|
||||||
case protocol.P_CL2LS_REQ_LOGIN:
|
|
||||||
client.Login(pkt)
|
|
||||||
default:
|
|
||||||
log.Printf("[WARN] unsupported packet ID: %x\n", typeID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset tmp
|
// reset tmp
|
||||||
tmp = tmp[:4]
|
tmp = tmp[:4]
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/CPunch/GopenFusion/protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
@ -48,6 +50,38 @@ func (server *Server) Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (server *Server) handlePacket(client *Client, typeID uint32, pkt *protocol.Packet) {
|
||||||
|
switch typeID {
|
||||||
|
case protocol.P_CL2LS_REQ_LOGIN:
|
||||||
|
var loginPkt protocol.SP_CL2LS_REQ_LOGIN
|
||||||
|
pkt.Decode(&loginPkt)
|
||||||
|
|
||||||
|
// TODO: for now, we're a dummy server
|
||||||
|
client.AcceptLogin(loginPkt.SZID, loginPkt.IClientVerC, 1, []protocol.SP_LS2CL_REP_CHAR_INFO{})
|
||||||
|
case protocol.P_CL2LS_REQ_CHECK_CHAR_NAME:
|
||||||
|
var charPkt protocol.SP_CL2LS_REQ_CHECK_CHAR_NAME
|
||||||
|
pkt.Decode(&charPkt)
|
||||||
|
|
||||||
|
client.Send(&protocol.SP_LS2CL_REP_CHECK_CHAR_NAME_SUCC{
|
||||||
|
SZFirstName: charPkt.SZFirstName,
|
||||||
|
SZLastName: charPkt.SZLastName,
|
||||||
|
}, protocol.P_LS2CL_REP_CHECK_CHAR_NAME_SUCC)
|
||||||
|
case protocol.P_CL2LS_REQ_SAVE_CHAR_NAME:
|
||||||
|
var charPkt protocol.SP_CL2LS_REQ_SAVE_CHAR_NAME
|
||||||
|
pkt.Decode(&charPkt)
|
||||||
|
|
||||||
|
client.Send(&protocol.SP_LS2CL_REP_SAVE_CHAR_NAME_SUCC{
|
||||||
|
IPC_UID: 1,
|
||||||
|
ISlotNum: charPkt.ISlotNum,
|
||||||
|
IGender: charPkt.IGender,
|
||||||
|
SZFirstName: charPkt.SZFirstName,
|
||||||
|
SZLastName: charPkt.SZLastName,
|
||||||
|
}, protocol.P_LS2CL_REP_SAVE_CHAR_NAME_SUCC)
|
||||||
|
default:
|
||||||
|
log.Printf("[WARN] unsupported packet ID: %x\n", typeID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
server := newServer()
|
server := newServer()
|
||||||
server.Start()
|
server.Start()
|
||||||
|
Loading…
Reference in New Issue
Block a user