mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-13 03:30:05 +00:00
Compare commits
2 Commits
e8f8129b35
...
7d83732e44
Author | SHA1 | Date | |
---|---|---|---|
7d83732e44 | |||
7eece044c5 |
@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||||
"github.com/bitcomplete/sqltestutil"
|
"github.com/bitcomplete/sqltestutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ var (
|
|||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
psql, err := sqltestutil.StartPostgresContainer(ctx, "latest")
|
psql, err := sqltestutil.StartPostgresContainer(ctx, "15")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -47,4 +48,77 @@ func TestDBAccount(t *testing.T) {
|
|||||||
if acc.Login != "test" {
|
if acc.Login != "test" {
|
||||||
t.Error("account username is not test")
|
t.Error("account username is not test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err = testDB.TryLogin("test", "wrongpassword"); err != ErrLoginInvalidPassword {
|
||||||
|
t.Error("expected ErrLoginInvalidPassword")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
test data has been collected by running the following commands in a postgresql shell started with:
|
||||||
|
docker exec -it gofusion-postgresql-1 psql -U gopenfusion -W gopenfusion
|
||||||
|
|
||||||
|
gopenfusion=# SELECT * FROM Players;
|
||||||
|
playerid | accountid | firstname | lastname | namecheck | slot | created | lastlogin | level | nano1 | nano2 | nano3 | appearanceflag | tutorialflag | payzoneflag | xcoordinate | ycoordinate | zcoordinate | angle | hp | fusionmatter | taros | batteryw | batteryn | mentor | currentmissionid | warplocationflag | skywaylocationflag | firstuseflag | quests
|
||||||
|
----------+-----------+-----------+----------+-----------+------+---------+-----------+-------+-------+-------+-------+----------------+--------------+-------------+-------------+-------------+-------------+-------+------+--------------+-------+----------+----------+--------+------------------+------------------+------------------------------------+------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
1 | 1 | Neil | Mcscout | 1 | 1 | 76476 | 76476 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 632032 | 187177 | -5500 | 0 | 1000 | 0 | 0 | 0 | 0 | 5 | 0 | 0 | \x00000000000000000000000000000000 | \x00000000000000000000000000000000 | \x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
|
||||||
|
gopenfusion=# SELECT * FROM Appearances;
|
||||||
|
playerid | body | eyecolor | facestyle | gender | haircolor | hairstyle | height | skincolor
|
||||||
|
----------+------+----------+-----------+--------+-----------+-----------+--------+-----------
|
||||||
|
1 | 2 | 3 | 5 | 1 | 11 | 3 | 0 | 9
|
||||||
|
|
||||||
|
gopenfusion=# SELECT * FROM Inventory;
|
||||||
|
playerid | slot | id | type | opt | timelimit
|
||||||
|
----------+------+-----+------+-----+-----------
|
||||||
|
1 | 1 | 328 | 1 | 1 | 0
|
||||||
|
1 | 2 | 359 | 2 | 1 | 0
|
||||||
|
1 | 3 | 194 | 3 | 1 | 0
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
func TestDBPlayer(t *testing.T) {
|
||||||
|
if _, err := testDB.NewAccount("testplayer", "test"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// now try to retrieve account data
|
||||||
|
acc, err := testDB.TryLogin("testplayer", "test")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
plrID, err := testDB.NewPlayer(acc.AccountID, "Neil", "Mcscout", 1)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = testDB.FinishPlayer(&protocol.SP_CL2LS_REQ_CHAR_CREATE{
|
||||||
|
PCStyle: protocol.SPCStyle{
|
||||||
|
IPC_UID: int64(plrID),
|
||||||
|
INameCheck: 1,
|
||||||
|
SzFirstName: "Neil",
|
||||||
|
SzLastName: "Mcscout",
|
||||||
|
IGender: 1,
|
||||||
|
IFaceStyle: 5,
|
||||||
|
IHairColor: 11,
|
||||||
|
ISkinColor: 9,
|
||||||
|
IEyeColor: 3,
|
||||||
|
IHeight: 0,
|
||||||
|
IBody: 2,
|
||||||
|
IHairStyle: 3,
|
||||||
|
},
|
||||||
|
SOn_Item: protocol.SOnItem{
|
||||||
|
IEquipUBID: 328,
|
||||||
|
IEquipLBID: 359,
|
||||||
|
IEquipFootID: 194,
|
||||||
|
},
|
||||||
|
}, acc.AccountID); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = testDB.FinishTutorial(plrID, acc.AccountID); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,10 @@ WARN_INVALID = False
|
|||||||
|
|
||||||
class StructTranspiler:
|
class StructTranspiler:
|
||||||
class StructField:
|
class StructField:
|
||||||
def __init__(self, name: str, type: str, marshal: str) -> None:
|
def __init__(self, name: str, csType: str, marshal: str) -> None:
|
||||||
self.marshal = marshal
|
self.marshal = marshal
|
||||||
self.type = type
|
self.type = csType
|
||||||
self.ctype = type # for transpilation to c
|
self.ctype = csType # for transpilation to c
|
||||||
self.tags = ""
|
self.tags = ""
|
||||||
self.size = 0
|
self.size = 0
|
||||||
self.padding = 0
|
self.padding = 0
|
||||||
@ -43,87 +43,88 @@ class StructTranspiler:
|
|||||||
self.cname = self.name
|
self.cname = self.name
|
||||||
self.needsPatching = False
|
self.needsPatching = False
|
||||||
|
|
||||||
if type == "byte":
|
match csType:
|
||||||
self.type = "uint8"
|
case "byte":
|
||||||
self.ctype = "char"
|
self.type = "uint8"
|
||||||
self.size = 1
|
self.ctype = "char"
|
||||||
elif type == "sbyte":
|
|
||||||
self.type = "int8"
|
|
||||||
self.ctype = "char"
|
|
||||||
self.size = 1
|
|
||||||
elif type == "short":
|
|
||||||
self.type = "int16"
|
|
||||||
self.ctype = "short"
|
|
||||||
self.size = 2
|
|
||||||
elif type == "int":
|
|
||||||
self.type = "int32"
|
|
||||||
self.ctype = "int"
|
|
||||||
self.size = 4
|
|
||||||
elif type == "uint":
|
|
||||||
self.type = "uint32"
|
|
||||||
self.ctype = "int"
|
|
||||||
self.size = 4
|
|
||||||
elif type == "float":
|
|
||||||
self.type = "float32"
|
|
||||||
self.ctype = "float"
|
|
||||||
self.size = 4
|
|
||||||
elif type == "long":
|
|
||||||
self.type = "int64"
|
|
||||||
self.ctype = "long"
|
|
||||||
self.size = 8
|
|
||||||
elif type == "ulong":
|
|
||||||
self.type = "uint64"
|
|
||||||
self.ctype = "long"
|
|
||||||
self.size = 8
|
|
||||||
elif type == "byte[]":
|
|
||||||
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
|
||||||
self.type = "[%d]byte" % self.size
|
|
||||||
self.ctype = "char"
|
|
||||||
self.cname += "[%d]" % self.size
|
|
||||||
elif type == "short[]":
|
|
||||||
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
|
||||||
self.type = "[%d]int16" % self.size
|
|
||||||
self.ctype = "short"
|
|
||||||
self.cname += "[%d]" % self.size
|
|
||||||
self.size *= 2
|
|
||||||
elif type == "string":
|
|
||||||
# all strings in fusionfall are utf16, in a uint16 array
|
|
||||||
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
|
||||||
self.type = "string"
|
|
||||||
self.addTag("size:\"%d\"" % self.size) # special tag to tell our decoder/encoder the size of the uint16[] array
|
|
||||||
self.ctype = "short"
|
|
||||||
self.cname += "[%d]" % self.size
|
|
||||||
self.size *= 2
|
|
||||||
elif type == "int[]":
|
|
||||||
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
|
||||||
self.type = "[%d]int32" % self.size
|
|
||||||
self.ctype = "int"
|
|
||||||
self.cname += "[%d]" % self.size
|
|
||||||
self.size *= 4
|
|
||||||
elif type == "float[]":
|
|
||||||
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
|
||||||
self.type = "[%d]float32" % self.size
|
|
||||||
self.ctype = "float"
|
|
||||||
self.cname += "[%d]" % self.size
|
|
||||||
self.size *= 4
|
|
||||||
elif type == "long[]":
|
|
||||||
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
|
||||||
self.type = "[%d]int64" % self.size
|
|
||||||
self.ctype = "long"
|
|
||||||
self.cname += "[%d]" % self.size
|
|
||||||
self.size *= 8
|
|
||||||
else:
|
|
||||||
# assume it's a structure that will be defined later
|
|
||||||
if type.find("[]") != -1: # it's an array!
|
|
||||||
type = type.replace("[]", "")
|
|
||||||
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
|
||||||
self.cname = self.name + "[%d]" % self.size
|
|
||||||
else:
|
|
||||||
self.cname = self.name
|
|
||||||
self.size = 1
|
self.size = 1
|
||||||
self.type = sanitizeName(type)
|
case "sbyte":
|
||||||
self.ctype = sanitizeName(type)
|
self.type = "int8"
|
||||||
self.needsPatching = True
|
self.ctype = "char"
|
||||||
|
self.size = 1
|
||||||
|
case "short":
|
||||||
|
self.type = "int16"
|
||||||
|
self.ctype = "short"
|
||||||
|
self.size = 2
|
||||||
|
case "int":
|
||||||
|
self.type = "int32"
|
||||||
|
self.ctype = "int"
|
||||||
|
self.size = 4
|
||||||
|
case "uint":
|
||||||
|
self.type = "uint32"
|
||||||
|
self.ctype = "int"
|
||||||
|
self.size = 4
|
||||||
|
case "float":
|
||||||
|
self.type = "float32"
|
||||||
|
self.ctype = "float"
|
||||||
|
self.size = 4
|
||||||
|
case "long":
|
||||||
|
self.type = "int64"
|
||||||
|
self.ctype = "long"
|
||||||
|
self.size = 8
|
||||||
|
case "ulong":
|
||||||
|
self.type = "uint64"
|
||||||
|
self.ctype = "long"
|
||||||
|
self.size = 8
|
||||||
|
case "byte[]":
|
||||||
|
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
||||||
|
self.type = "[%d]byte" % self.size
|
||||||
|
self.ctype = "char"
|
||||||
|
self.cname += "[%d]" % self.size
|
||||||
|
case "short[]":
|
||||||
|
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
||||||
|
self.type = "[%d]int16" % self.size
|
||||||
|
self.ctype = "short"
|
||||||
|
self.cname += "[%d]" % self.size
|
||||||
|
self.size *= 2
|
||||||
|
case "string":
|
||||||
|
# all strings in fusionfall are utf16, in a uint16 array
|
||||||
|
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
||||||
|
self.type = "string"
|
||||||
|
self.addTag("size:\"%d\"" % self.size) # special tag to tell our decoder/encoder the size of the uint16[] array
|
||||||
|
self.ctype = "short"
|
||||||
|
self.cname += "[%d]" % self.size
|
||||||
|
self.size *= 2
|
||||||
|
case "int[]":
|
||||||
|
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
||||||
|
self.type = "[%d]int32" % self.size
|
||||||
|
self.ctype = "int"
|
||||||
|
self.cname += "[%d]" % self.size
|
||||||
|
self.size *= 4
|
||||||
|
case "float[]":
|
||||||
|
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
||||||
|
self.type = "[%d]float32" % self.size
|
||||||
|
self.ctype = "float"
|
||||||
|
self.cname += "[%d]" % self.size
|
||||||
|
self.size *= 4
|
||||||
|
case "long[]":
|
||||||
|
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
||||||
|
self.type = "[%d]int64" % self.size
|
||||||
|
self.ctype = "long"
|
||||||
|
self.cname += "[%d]" % self.size
|
||||||
|
self.size *= 8
|
||||||
|
case _:
|
||||||
|
# assume it's a structure that will be defined later
|
||||||
|
if csType.find("[]") != -1: # it's an array!
|
||||||
|
csType = csType.replace("[]", "")
|
||||||
|
self.size = int(marshal[(marshal.find("SizeConst = ") + len("SizeConst = ")):marshal.find(")]")])
|
||||||
|
self.cname = self.name + "[%d]" % self.size
|
||||||
|
else:
|
||||||
|
self.cname = self.name
|
||||||
|
self.size = 1
|
||||||
|
self.type = sanitizeName(csType)
|
||||||
|
self.ctype = sanitizeName(csType)
|
||||||
|
self.needsPatching = True
|
||||||
|
|
||||||
def addTag(self, tag: str) -> None:
|
def addTag(self, tag: str) -> None:
|
||||||
if len(self.tags) > 0: # if there's already a tag defined, make sure there's a space separating them
|
if len(self.tags) > 0: # if there's already a tag defined, make sure there's a space separating them
|
||||||
|
Loading…
Reference in New Issue
Block a user