-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
52 lines (44 loc) · 1.96 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Mock TCP communication using rathena models to test behavior and to
// benchmark performance of key operations.
//
// While most settings are configurable via cli flags, there is currently
// no change in behavior when changing the Packet Version used, whereas in
// the future we may need flags to validate alternative command structures and
// permutations of request/response model to support various client versions.
package integration
import (
"flag"
"math/rand"
"time"
)
// Constant set of accepted characters for RO names.
const AcceptedNameCharacters = "abcdefghijklmnopqrstuvwxyz0123456789"
// Client type sane default is 0.
const ClientType uint8 = 0
// Configurable options for running tests and benchmarks.
var packetVerInput = flag.Int("packetVer", 55, "numeric packet version in clientinfo.xml")
var clientVerInput = flag.Int("clientVer", 20151029, "date format packet version used by rathena at compile time")
var loginAddress = flag.String("loginAddress", "127.0.0.1:6900", "address for the login server")
var charAddress = flag.String("charAddress", "127.0.0.1:6121", "address for the char server")
var charCredentials = flag.String("charCredentials", "ragnarok:ragnarok", "colon separated credentials for a mock char server")
var mapAddress = flag.String("mapAddress", "127.0.0.1:5121", "address for the map server")
// The packet version is required as uint8.
var packetVer uint32 = uint32(*packetVerInput)
// The username is randomly generated by init, and password is static.
var password string = "secret"
var username string
// Preseed random and generate a username from accepted characters
func init() {
rand.Seed(time.Now().UTC().UnixNano())
username = randomName()
}
// Create a random name between 4 and 14 characters
// using only alphanumeric characters.
func randomName() string {
max := rand.Intn(10) + 4
name := make([]byte, max)
for i := 0; i < max; i++ {
name[i] = AcceptedNameCharacters[rand.Intn(len(AcceptedNameCharacters))]
}
return string(name)
}