Skip to content

Commit

Permalink
🚑 Symmetric NAT and hotspot connection now is compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyJavaBean committed Sep 15, 2021
1 parent e2ef0e0 commit 7a05ca1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/client_sniffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func checkPacket(packet gopacket.Packet) {
//todo: udp connection can be reused.
func call(msg []byte) {

//fixme when quickly send 2 packets it goes wrong!
lAddr := &net.UDPAddr{IP: net.ParseIP("localhost"), Port: constant.MapSendPort}
rAddr := &net.UDPAddr{IP: net.ParseIP(constant.ServerIp), Port: utils.GetMapPort()}
conn, err := net.DialUDP("udp", lAddr, rAddr)
Expand Down
4 changes: 3 additions & 1 deletion main/cohvs_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func main() {
for _, arg := range os.Args {
if arg=="server"{
serverMode = true
break
}
if arg=="cson"{
server.SwitchOnCompatiSymmetric()
}
if arg=="mock"{
fmt.Println("start up as mock mode")
Expand Down
1 change: 1 addition & 0 deletions server/multi_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func GetMultiServer() *MultiServer {
func (server *MultiServer) Work() {

fmt.Println("Server start......")
fmt.Println("compatiSymmetric switch is ",compatiSymmetric)

server.controller.work()

Expand Down
19 changes: 18 additions & 1 deletion server/v_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,30 @@ func (p *VPlayer) handle(msg []byte, raddr *net.UDPAddr) {
func (controller *VPlayerController) findUser(addr *net.UDPAddr) *VPlayer {
for i := range controller.players {
p := &controller.players[i]
if p.playerAddr != nil && p.playerAddr.String() == addr.String() {
if ipUserCheck(p.playerAddr,addr){
return p
}
}
return nil
}

func SwitchOnCompatiSymmetric(){
compatiSymmetric = true
}

var compatiSymmetric = false

func ipUserCheck(local *net.UDPAddr,remote *net.UDPAddr) bool{
if local==nil{
return false
}
if compatiSymmetric{
return local.IP.String()==remote.IP.String()
}else{
return local.String()==remote.String()
}
}

func (controller *VPlayerController) register(addr *net.UDPAddr) string{
for i := range controller.players {
p := &controller.players[i]
Expand Down

0 comments on commit 7a05ca1

Please sign in to comment.