Added more test accounts
This commit is contained in:
parent
d1afccd4bd
commit
23a9567871
@ -1,30 +1,33 @@
|
||||
package game
|
||||
|
||||
var accounts = map[string]*Account{
|
||||
"user0": {
|
||||
ID: "4J6qpK1ve",
|
||||
Name: "user0",
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
var (
|
||||
SpawnPoint = Vector3{584.98, 9.5, 394.68}
|
||||
accounts = map[string]*Account{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
MakeTestAccounts()
|
||||
}
|
||||
|
||||
// MakeTestAccounts creates accounts for stress testing.
|
||||
func MakeTestAccounts() {
|
||||
for i := range 500 {
|
||||
angle := rand.Float64() * math.Pi * 2
|
||||
distance := rand.Float64() * 12.0
|
||||
|
||||
accounts[fmt.Sprintf("user%d", i)] = &Account{
|
||||
ID: fmt.Sprintf("id%d", i),
|
||||
Name: fmt.Sprintf("user%d", i),
|
||||
Password: "password",
|
||||
Position: Vector3{3, 0, 0},
|
||||
},
|
||||
"user1": {
|
||||
ID: "I_vyeZamg",
|
||||
Name: "user1",
|
||||
Password: "password",
|
||||
Position: Vector3{-3, 0, 0},
|
||||
},
|
||||
"user2": {
|
||||
ID: "VJOK1ckvx",
|
||||
Name: "user2",
|
||||
Password: "password",
|
||||
Position: Vector3{0, 0, 3},
|
||||
},
|
||||
"user3": {
|
||||
ID: "EkCcqbwFl",
|
||||
Name: "user3",
|
||||
Password: "password",
|
||||
Position: Vector3{0, 0, -3},
|
||||
},
|
||||
Position: Vector3{SpawnPoint.X + float32(math.Cos(angle)*distance), SpawnPoint.Y, SpawnPoint.Z + float32(math.Sin(angle)*distance)},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetAccountByName retrieves the account with the given name.
|
||||
|
@ -1,3 +1,3 @@
|
||||
module server
|
||||
|
||||
go 1.21.6
|
||||
go 1.22
|
||||
|
@ -1,3 +1,3 @@
|
||||
module stresstest
|
||||
|
||||
go 1.21.6
|
||||
go 1.22
|
||||
|
@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
@ -15,11 +18,19 @@ var (
|
||||
message = []byte{1, 0}
|
||||
)
|
||||
|
||||
func init() {
|
||||
func main() {
|
||||
flag.Parse()
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
for i := 0; i < *numClients; i++ {
|
||||
wg.Add(1)
|
||||
go udpClient(&wg, i)
|
||||
}
|
||||
|
||||
func udpClient(wg *sync.WaitGroup) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func udpClient(wg *sync.WaitGroup, id int) {
|
||||
defer wg.Done()
|
||||
|
||||
clientAddr, err := net.ResolveUDPAddr("udp", *address)
|
||||
@ -38,6 +49,18 @@ func udpClient(wg *sync.WaitGroup) {
|
||||
|
||||
defer conn.Close()
|
||||
|
||||
loginRequest := [2]string{fmt.Sprintf("user%d", id+1), sha256Text("password")}
|
||||
data, err := json.Marshal(loginRequest)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error creating JSON:", err)
|
||||
return
|
||||
}
|
||||
|
||||
request := append([]byte{2}, data...)
|
||||
fmt.Println(string(request))
|
||||
conn.Write(request)
|
||||
|
||||
for {
|
||||
_, err := conn.Write(message)
|
||||
|
||||
@ -50,13 +73,7 @@ func udpClient(wg *sync.WaitGroup) {
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
for i := 0; i < *numClients; i++ {
|
||||
wg.Add(1)
|
||||
go udpClient(&wg)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
func sha256Text(password string) string {
|
||||
sum := sha256.Sum256([]byte(password))
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user