mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-05-06 13:40:04 -05:00
Natneg: Apply lint suggestions
This commit is contained in:
parent
5258702a04
commit
7ca8f4777a
|
|
@ -69,13 +69,13 @@ func (client *NATNEGClient) sendConnectRequestPacket(conn net.PacketConn, destin
|
|||
connectHeader = append(connectHeader, 0x42, 0x00)
|
||||
|
||||
destIPAddr, err := net.ResolveUDPAddr("udp", destination.NegotiateIP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
conn.WriteTo(connectHeader, destIPAddr)
|
||||
common.ShouldNotError(err)
|
||||
_, _ = conn.WriteTo(connectHeader, destIPAddr)
|
||||
}
|
||||
|
||||
func (session *NATNEGSession) handleConnectReply(conn net.PacketConn, addr net.Addr, buffer []byte, moduleName string, version byte) {
|
||||
common.MaybeUnused(conn, addr, buffer, moduleName, version)
|
||||
|
||||
// portType := buffer[0]
|
||||
clientIndex := buffer[1]
|
||||
// useGamePort := buffer[2]
|
||||
|
|
|
|||
|
|
@ -51,7 +51,10 @@ func (session *NATNEGSession) handleInit(conn net.PacketConn, addr net.Addr, buf
|
|||
ackHeader := createPacketHeader(version, NNInitReply, session.Cookie)
|
||||
ackHeader = append(ackHeader, portType, clientIndex)
|
||||
ackHeader = append(ackHeader, 0xff, 0xff, 0x6d, 0x16, 0xb5, 0x7d, 0xea)
|
||||
conn.WriteTo(ackHeader, addr)
|
||||
if _, err := conn.WriteTo(ackHeader, addr); err != nil {
|
||||
logging.Error(moduleName, "Error writing init acknowledgement:", err)
|
||||
return
|
||||
}
|
||||
|
||||
sender, exists := session.Clients[clientIndex]
|
||||
if !exists {
|
||||
|
|
|
|||
|
|
@ -106,15 +106,12 @@ func StartServer(reload bool) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer func() {
|
||||
common.ShouldNotError(file.Close())
|
||||
}()
|
||||
|
||||
decoder := gob.NewDecoder(file)
|
||||
|
||||
err = decoder.Decode(&sessions)
|
||||
file.Close()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
common.ShouldNotError(decoder.Decode(&sessions))
|
||||
|
||||
for _, session := range sessions {
|
||||
cur := session
|
||||
|
|
@ -132,7 +129,9 @@ func StartServer(reload bool) {
|
|||
defer waitGroup.Done()
|
||||
|
||||
// Close the listener when the application closes.
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
common.ShouldNotError(conn.Close())
|
||||
}()
|
||||
logging.Notice("NATNEG", "Listening on", aurora.BrightCyan(address))
|
||||
|
||||
for {
|
||||
|
|
@ -155,7 +154,7 @@ func StartServer(reload bool) {
|
|||
|
||||
func Shutdown() {
|
||||
inShutdown.SetTrue()
|
||||
natnegConn.Close()
|
||||
common.ShouldNotError(natnegConn.Close())
|
||||
waitGroup.Wait()
|
||||
|
||||
// Save state
|
||||
|
|
@ -166,15 +165,12 @@ func Shutdown() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer func() {
|
||||
common.ShouldNotError(file.Close())
|
||||
}()
|
||||
|
||||
encoder := gob.NewEncoder(file)
|
||||
|
||||
err = encoder.Encode(sessions)
|
||||
file.Close()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
common.ShouldNotError(encoder.Encode(sessions))
|
||||
|
||||
logging.Notice("NATNEG", "Saved", aurora.Cyan(len(sessions)), "sessions")
|
||||
}
|
||||
|
|
@ -314,21 +310,19 @@ func closeSession(moduleName string, session *NATNEGSession) {
|
|||
continue
|
||||
}
|
||||
|
||||
logging.Info("NATNEG", "Disconnecting client", aurora.Cyan(client.Index))
|
||||
logging.Info(moduleName, "Disconnecting client", aurora.Cyan(client.Index))
|
||||
// Send report ack, which will cause the client to cancel
|
||||
reportAck := createPacketHeader(session.Version, NNReportReply, session.Cookie)
|
||||
reportAck = append(reportAck, 0x00, client.Index, 0x00)
|
||||
reportAck = append(reportAck, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00)
|
||||
|
||||
addr, err := net.ResolveUDPAddr("udp", client.NegotiateIP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
common.ShouldNotError(err)
|
||||
|
||||
natnegConn.WriteTo(reportAck, addr)
|
||||
_, _ = natnegConn.WriteTo(reportAck, addr)
|
||||
}
|
||||
|
||||
logging.Info("NATNEG", "Deleted session")
|
||||
logging.Info(moduleName, "Deleted session")
|
||||
}
|
||||
|
||||
func getPortTypeName(portType byte) string {
|
||||
|
|
@ -350,6 +344,8 @@ func getPortTypeName(portType byte) string {
|
|||
}
|
||||
}
|
||||
|
||||
var _ = common.MaybeUnused(getPortTypeName)
|
||||
|
||||
func (client *NATNEGClient) isMapped() bool {
|
||||
if client.NegotiateIP == "" || client.ServerIP == "" {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -39,5 +39,5 @@ func (session *NATNEGSession) handlePreinit(conn net.PacketConn, addr net.Addr,
|
|||
packet := createPacketHeader(version, NNPreInitReply, session.Cookie)
|
||||
buffer[1] = NNPreInitReady
|
||||
packet = append(packet, buffer[:6]...)
|
||||
conn.WriteTo(packet, addr)
|
||||
_, _ = conn.WriteTo(packet, addr)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func (session *NATNEGSession) handleReport(conn net.PacketConn, addr net.Addr, b
|
|||
response := createPacketHeader(version, NNReportReply, session.Cookie)
|
||||
response = append(response, buffer[:9]...)
|
||||
response[14] = 0
|
||||
conn.WriteTo(response, addr)
|
||||
_, _ = conn.WriteTo(response, addr)
|
||||
|
||||
// portType := buffer[0]
|
||||
clientIndex := buffer[1]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user