mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-04-23 01:37:33 -05:00
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package natneg
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"wwfc/logging"
|
|
"wwfc/qr2"
|
|
|
|
"github.com/logrusorgru/aurora/v3"
|
|
)
|
|
|
|
func (session *NATNEGSession) handleReport(conn net.PacketConn, addr net.Addr, buffer []byte, _ string, version byte) {
|
|
response := createPacketHeader(version, NNReportReply, session.Cookie)
|
|
response = append(response, buffer[:9]...)
|
|
response[14] = 0
|
|
conn.WriteTo(response, addr)
|
|
|
|
// portType := buffer[0]
|
|
clientIndex := buffer[1]
|
|
result := buffer[2]
|
|
// natType := buffer[3]
|
|
// mappingScheme := buffer[7]
|
|
// gameName, err := common.GetString(buffer[11:])
|
|
|
|
moduleName := "NATNEG:" + fmt.Sprintf("%08x/", session.Cookie) + addr.String()
|
|
logging.Notice(moduleName, "Report from", aurora.BrightCyan(clientIndex), "result:", aurora.Cyan(result))
|
|
|
|
if client, exists := session.Clients[clientIndex]; exists {
|
|
client.Result[client.ConnectingIndex] = result
|
|
connecting := session.Clients[client.ConnectingIndex]
|
|
client.ConnectingIndex = clientIndex
|
|
client.ConnectAck = false
|
|
|
|
if otherResult, hasResult := connecting.Result[clientIndex]; hasResult {
|
|
if otherResult != 1 {
|
|
result = otherResult
|
|
}
|
|
qr2.ProcessNATNEGReport(result, client.ServerIP, connecting.ServerIP)
|
|
}
|
|
}
|
|
|
|
// Send remaining requests
|
|
session.sendConnectRequests(moduleName)
|
|
}
|