mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-04-21 16:57:17 -05:00
44 lines
902 B
Go
44 lines
902 B
Go
package master
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"strconv"
|
|
"strings"
|
|
"wwfc/common"
|
|
)
|
|
|
|
func sendChallenge(conn net.PacketConn, addr net.Addr, sessionId uint32) {
|
|
addrString := strings.Split(addr.String(), ":")
|
|
|
|
// Generate challenge and send to server
|
|
var hexIP string
|
|
for _, i := range strings.Split(addrString[0], ".") {
|
|
val, err := strconv.ParseUint(i, 10, 64)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
hexIP += fmt.Sprintf("%02X", val)
|
|
}
|
|
|
|
port, err := strconv.ParseUint(addrString[1], 10, 64)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
hexPort := fmt.Sprintf("%04X", port)
|
|
|
|
challenge := common.RandomString(6) + "00" + hexIP + hexPort
|
|
mutex.Lock()
|
|
session := sessions[sessionId]
|
|
session.Challenge = challenge
|
|
mutex.Unlock()
|
|
|
|
response := createResponseHeader(CommandChallenge, sessionId)
|
|
response = append(response, []byte(challenge)...)
|
|
response = append(response, 0)
|
|
|
|
conn.WriteTo(response, addr)
|
|
}
|