Skip to content

Commit a413d96

Browse files
committed
Clean-up
Linter and other misc cleaning
1 parent db71189 commit a413d96

27 files changed

+430
-255
lines changed

.gitignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
### Project specific ###
2+
tests
3+
resources
4+
tools
5+
6+
### Go ###
7+
# Binaries for programs and plugins
8+
*.exe
9+
*.exe~
10+
*.dll
11+
*.so
12+
*.dylib
13+
14+
# Test binary, built with `go test -c`
15+
*.test
16+
17+
# Output of the go coverage tool, specifically when used with LiteIDE
18+
*.out
19+
20+
# Dependency directories (remove the comment below to include it)
21+
# vendor/
22+
23+
### Go Patch ###
24+
/vendor/
25+
/Godeps/
26+
27+
### Goland ###
28+
*.iml
29+
*.ipr
30+
*.iws
31+
.idea/
32+
/build/
33+
/dist/
34+
/out/

.golangci.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This file contains all available configuration options
2+
# with their default values.
3+
4+
# options for analysis running
5+
run:
6+
# default concurrency is a available CPU number
7+
concurrency: 4
8+
9+
# which dirs to skip: issues from them won't be reported;
10+
# can use regexp here: generated.*, regexp is applied on full path;
11+
# default value is empty list, but default dirs are skipped independently
12+
# from this option's value (see skip-dirs-use-default).
13+
# "/" will be replaced by current OS file path separator to properly work
14+
# on Windows.
15+
skip-dirs:
16+
- tests
17+
18+
# all available settings of specific linters
19+
linters-settings:
20+
21+
gocyclo:
22+
# minimal code complexity to report, 30 by default (but we recommend 10-20)
23+
min-complexity: 10
24+
25+
linters:
26+
disable-all: true
27+
enable:
28+
- deadcode
29+
- errcheck
30+
- gosimple
31+
- govet
32+
- ineffassign
33+
- staticcheck
34+
- structcheck
35+
- typecheck
36+
- unused
37+
- varcheck
38+
- megacheck

README.md

+20-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ My slow attempt at an 'RE' of the SoulWorker protocol.
44
How to use:
55

66
1. Download and open in GoLand or whatever IDE (or not) you use
7-
2. Setup the database with the provided .sql file
7+
2. Set up the database with the provided .sql file
88

99
To launch the KRSW OnStove client (+skipping Stove Authenticator):
1010
```
@@ -17,28 +17,31 @@ To bypass the OnStove authenticator without command line arguments, you can buil
1717

1818
Changelog:
1919

20+
* Oct 11, 2021
21+
* Re-base
22+
2023
* May 11, 2020
21-
* Major refactor
22-
* Small database implementation
23-
* Somehow made it ask for 2fa and don't know how to skip, so done for today
24+
* Major refactor
25+
* Small database implementation
26+
* Somehow made it ask for 2fa and don't know how to skip, so done for today
2427

2528
* August 2, 2019
26-
* No server sided updates, only client side discoveries.
29+
* No server sided updates, only client side discoveries.
2730

2831
* July 29, 2019
29-
* Moved hardcoded keyTable to globals where it's defined
30-
* Minimal file updates, just slight renaming on a few variables
31-
* Changed cringe server name
32-
* Added some tools/tests for `tb_*.res` table extraction/verification
33-
* Includes `tb_*` string dump and the ASM dump for functions regarding them
34-
* Includes the final go struct dump for all table structures
35-
* You can find the original script that I modified in this [Gist](https://gist.github.com/x1nixmzeng/a4a5c419f1cd4bc72cba30d5e647bc4f)
32+
* Moved hardcoded keyTable to globals where it's defined
33+
* Minimal file updates, just slight renaming on a few variables
34+
* Changed cringe server name
35+
* Added some tools/tests for `tb_*.res` table extraction/verification
36+
* Includes `tb_*` string dump and the ASM dump for functions regarding them
37+
* Includes the final go struct dump for all table structures
38+
* You can find the original script that I modified in this [Gist](https://gist.github.com/x1nixmzeng/a4a5c419f1cd4bc72cba30d5e647bc4f)
3639

3740
* July 13, 2019
38-
* Hardcoded keyTable instead of having it read from file
39-
* Updated some packets from NA client to KR/BSW client
40-
* Re-did some structs
41-
* Added some string utils
41+
* Hardcoded keyTable instead of having it read from file
42+
* Updated some packets from NA client to KR/BSW client
43+
* Re-did some structs
44+
* Added some string utils
4245

4346
* Dec 6, 2018
44-
* Uploaded with initial edit from 11/12/2018
47+
* Uploaded with initial edit from 11/12/2018

database/database.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
"fmt"
77
"log"
88

9-
. "../network/structures"
9+
. "soulworker-server/network/structures"
10+
1011
_ "github.com/go-sql-driver/mysql"
1112
)
1213

@@ -32,7 +33,7 @@ func Open() *sql.DB {
3233
return DB
3334
}
3435

35-
// CanConnect checks whether or not a database is accepting connections
36+
// CanConnect checks whether a database is accepting connections
3637
// It returns an error if not
3738
func CanConnect() error {
3839
fmt.Print("[Database]\tChecking connection... ")
@@ -73,7 +74,7 @@ func VerifyLoginCredentials(username string, password string) uint32 {
7374
return uint32(id)
7475
}
7576

76-
// Updates a given accountId's sessionKey in the database
77+
// UpdateSessionKey Updates a given accountId's sessionKey in the database
7778
func UpdateSessionKey(accountId uint32, sessionKey uint64) {
7879
stmt, err := DB.Prepare("UPDATE users SET session_key = ? WHERE id = ?")
7980
if err != nil {
@@ -95,7 +96,7 @@ func UpdateSessionKey(accountId uint32, sessionKey uint64) {
9596
log.Printf("ID = %d, affected = %d\n", lastId, rowCnt)
9697
}
9798

98-
// Verifies that an accountId's sessionKey matches the one in the database
99+
// VerifySessionKey Verifies that an accountId's sessionKey matches the one in the database
99100
func VerifySessionKey(accountId uint32, sessionKey uint64) int {
100101

101102
var id int
@@ -110,7 +111,7 @@ func VerifySessionKey(accountId uint32, sessionKey uint64) int {
110111
return id
111112
}
112113

113-
// Inserts an entry for the character table into the database from the contents of the CharacterInfo struct
114+
// InsertCharacterToDb Inserts an entry for the character table into the database from the contents of the CharacterInfo struct
114115
func InsertCharacterToDb(charInfo *CharacterInfo) int64 {
115116

116117
stmt, err := DB.Prepare("INSERT INTO characters(accountId, `index`, name, class, appearance, level) VALUES(?, ?, ?, ?, ?, ?)")
@@ -136,7 +137,7 @@ func InsertCharacterToDb(charInfo *CharacterInfo) int64 {
136137
return lastId
137138
}
138139

139-
// Fetches the number of characters the given accountId has on the server.
140+
// FetchUserCharacterCount Fetches the number of characters the given accountId has on the server.
140141
func FetchUserCharacterCount(accountId uint32) int {
141142
var count int
142143

@@ -149,7 +150,7 @@ func FetchUserCharacterCount(accountId uint32) int {
149150
return count
150151
}
151152

152-
// Fetches the user character with the given characterId on the given accountId.
153+
// FetchUserCharacter Fetches the user character with the given characterId on the given accountId.
153154
func FetchUserCharacter(accountId uint32, characterId uint32) (CharacterInfo, error) {
154155

155156
char := CharacterInfo{}
@@ -163,7 +164,7 @@ func FetchUserCharacter(accountId uint32, characterId uint32) (CharacterInfo, er
163164
return char, nil
164165
}
165166

166-
// Fetches the user character with the given characterId.
167+
// FetchUserCharacterByCharacterId Fetches the user character with the given characterId.
167168
func FetchUserCharacterByCharacterId(characterId uint32) (CharacterInfo, error) {
168169

169170
char := CharacterInfo{}

global/global.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ import (
88
// ServerMap - Array of Servers
99
var (
1010
KeyTable = []byte{
11-
0x57, 0x19, 0xC6, 0x2D, 0x56, 0x68, 0x3A, 0xCC,
12-
0x60, 0x3B, 0x0B, 0xB1, 0x90, 0x5C, 0x4A, 0xF8,
13-
14-
0x80, 0x28, 0xB1, 0x45, 0xB6, 0x85, 0xE7, 0x4C,
15-
0x06, 0x2D, 0x55, 0x83, 0xAF, 0x44, 0x99, 0x95,
16-
17-
0xD9, 0x98, 0xBF, 0xAE, 0x53, 0x43, 0x63, 0xC8,
18-
0x4A, 0x71, 0x80, 0x9D, 0x0B, 0xA1, 0x70, 0x8A,
19-
20-
0x0F, 0x54, 0x9C, 0x1B, 0x06, 0xC0, 0xEA, 0x3C,
21-
0xC0, 0x88, 0x71, 0x48, 0xB3, 0xB9, 0x45, 0x78,
11+
0xEE, 0x1B, 0xDE, 0xA6, 0x46, 0xE9, 0x2A, 0xDB, 0x97, 0x67, 0x9C, 0x02, 0x3C, 0xCE, 0x9A,
12+
//0x57, 0x19, 0xC6, 0x2D, 0x56, 0x68, 0x3A, 0xCC,
13+
//0x60, 0x3B, 0x0B, 0xB1, 0x90, 0x5C, 0x4A, 0xF8,
14+
//
15+
//0x80, 0x28, 0xB1, 0x45, 0xB6, 0x85, 0xE7, 0x4C,
16+
//0x06, 0x2D, 0x55, 0x83, 0xAF, 0x44, 0x99, 0x95,
17+
//
18+
//0xD9, 0x98, 0xBF, 0xAE, 0x53, 0x43, 0x63, 0xC8,
19+
//0x4A, 0x71, 0x80, 0x9D, 0x0B, 0xA1, 0x70, 0x8A,
20+
//
21+
//0x0F, 0x54, 0x9C, 0x1B, 0x06, 0xC0, 0xEA, 0x3C,
22+
//0xC0, 0x88, 0x71, 0x48, 0xB3, 0xB9, 0x45, 0x78,
2223
}
2324
ServerMap []Server
2425
LoginPort uint16 = 10000
@@ -49,4 +50,4 @@ func (server Server) GetName() string {
4950
// GetIP - Gets the IP of a Game Server
5051
func (server Server) GetIP() string {
5152
return server.IP
52-
}
53+
}

go.mod

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module soulworker-server
2+
3+
go 1.16
4+
5+
require (
6+
github.com/davecgh/go-spew v1.1.1
7+
github.com/go-sql-driver/mysql v1.6.0
8+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac
9+
)

go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
4+
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
5+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw=
6+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

main.go

+9-40
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,13 @@
11
package main
22

33
import (
4-
"bytes"
4+
"soulworker-server/database"
5+
. "soulworker-server/global"
6+
. "soulworker-server/network"
57
"time"
6-
7-
"encoding/hex"
8-
"fmt"
9-
10-
"./database"
11-
. "./global"
12-
. "./network"
13-
. "./network/packets"
148
)
159

16-
// quickDecode quickly decodes a series of encoded bytes.
17-
// This simulates a receive call from the server.
18-
// It returns a byte Buffer containing the decoded byte contents.
19-
func quickDecode(arr []byte) *bytes.Buffer {
20-
raw := Decrypt(arr)
21-
if packetID, _, err := UnmarshalPacket(raw); err != nil {
22-
fmt.Printf("err: %s\n", err)
23-
} else {
24-
fmt.Printf("ID=0x%04X, Size=%d, Total=%d\n", packetID, raw.Len(), raw.Len()+5)
25-
fmt.Println(hex.Dump(raw.Bytes()))
26-
return raw
27-
}
28-
return nil
29-
}
30-
3110
func main() {
32-
//packets := [][]byte{
33-
// {
34-
// },
35-
//}
36-
//
37-
//for i := 0; i < len(packets); i++ {
38-
// quickDecode(packets[i][5:])
39-
//
40-
// //charInfo := &structures.CharacterInfo{}
41-
// //charInfo.Read(buffer)
42-
//
43-
// //fmt.Printf("%#+v\n", charInfo)
44-
//
45-
// //spew.Dump(charInfo)
46-
//}
47-
4811
// List of game servers
4912
// Includes the server name and ip address
5013
ServerMap = []Server{
@@ -59,8 +22,14 @@ func main() {
5922
// It starts the three component servers--login network, game network, and game world--each in a new thread
6023
// It then waits indefinitely until it is cancelled by the console
6124
func start() {
25+
//defer profile.Start(profile.MemProfile).Stop()
26+
6227
Log("Starting...")
6328

29+
if len(KeyTable) < 1 {
30+
panic("Key table has not been initialized.")
31+
}
32+
6433
Log("Initializing database.")
6534
database.Open()
6635
if err := database.CanConnect(); err != nil {

0 commit comments

Comments
 (0)