mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-12 19:20:06 +00:00
absolute minimal login server
This commit is contained in:
parent
8f3f31d354
commit
4d0bd4b1c1
@ -3,7 +3,6 @@ package protocol
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"unicode/utf16"
|
||||
@ -78,7 +77,7 @@ func (pkt *Packet) readByte() byte {
|
||||
}
|
||||
|
||||
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() {
|
||||
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)
|
||||
default:
|
||||
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) {
|
||||
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() {
|
||||
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]))
|
||||
log.Printf(" got: %#.v or '%s'", buf16, str)
|
||||
value.SetString(str)
|
||||
default:
|
||||
pkt.Decode(value.Addr().Interface())
|
||||
@ -222,7 +219,6 @@ func (pkt *Packet) Decode(data interface{}) {
|
||||
sz := rv.Len()
|
||||
|
||||
// decode data
|
||||
log.Print("reading array length ", sz, " cursor: ", pkt.cursor)
|
||||
for i := 0; i < sz; i++ {
|
||||
elem := rv.Index(i)
|
||||
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 {
|
||||
panic(fmt.Errorf("[FATAL] failed to write packet body! %v", err))
|
||||
}
|
||||
log.Printf("sent!")
|
||||
}
|
||||
|
||||
func (client *Client) Login(pkt *protocol.Packet) {
|
||||
var loginPkt protocol.SP_CL2LS_REQ_LOGIN
|
||||
pkt.Decode(&loginPkt)
|
||||
log.Printf("Got packet: %#v", loginPkt)
|
||||
|
||||
// !! TODO
|
||||
func (client *Client) AcceptLogin(SZID string, IClientVerC int32, ISlotNum int8, data []protocol.SP_LS2CL_REP_CHAR_INFO) {
|
||||
resp := &protocol.SP_LS2CL_REP_LOGIN_SUCC{
|
||||
SZID: loginPkt.SZID,
|
||||
ICharCount: 0,
|
||||
ISlotNum: 1,
|
||||
SZID: SZID,
|
||||
ICharCount: int8(len(data)),
|
||||
ISlotNum: ISlotNum,
|
||||
IPaymentFlag: 1,
|
||||
IOpenBetaFlag: 0,
|
||||
UISvrTime: uint64(time.Now().Unix()),
|
||||
@ -87,9 +81,14 @@ func (client *Client) Login(pkt *protocol.Packet) {
|
||||
)
|
||||
client.fe_key = protocol.CreateNewKey(
|
||||
binary.LittleEndian.Uint64([]byte(protocol.DEFAULT_KEY)),
|
||||
uint64(loginPkt.IClientVerC),
|
||||
uint64(IClientVerC),
|
||||
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() {
|
||||
@ -121,16 +120,12 @@ func (client *Client) ClientHandler() {
|
||||
|
||||
// decrypt && grab typeID
|
||||
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)
|
||||
pkt := protocol.NewPacket(tmp[4:sz])
|
||||
switch typeID {
|
||||
case protocol.P_CL2LS_REQ_LOGIN:
|
||||
client.Login(pkt)
|
||||
default:
|
||||
log.Printf("[WARN] unsupported packet ID: %x\n", typeID)
|
||||
}
|
||||
client.server.handlePacket(client, typeID, pkt)
|
||||
|
||||
// reset tmp
|
||||
tmp = tmp[:4]
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/CPunch/GopenFusion/protocol"
|
||||
)
|
||||
|
||||
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() {
|
||||
server := newServer()
|
||||
server.Start()
|
||||
|
Loading…
Reference in New Issue
Block a user