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