From e2ef0e02f0409006955e212acd9868e5619f6602 Mon Sep 17 00:00:00 2001 From: Lehr Date: Wed, 15 Sep 2021 15:56:52 +0800 Subject: [PATCH] :ambulance: fix map info sending logic so now multiple player mode can work fine. --- client/client_mock.go | 1 + server/multi_server.go | 3 +++ server/v_player.go | 10 ++++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/client_mock.go b/client/client_mock.go index 560c7fb..3ff6708 100644 --- a/client/client_mock.go +++ b/client/client_mock.go @@ -29,6 +29,7 @@ func Mock() { raddrs = append(raddrs, raddr) if len(msg) > 300 { fmt.Println("【Get A Map Info】") + //todo fix upcoming actions } else { fmt.Println(raddr.String()+" => :", string(msg)) } diff --git a/server/multi_server.go b/server/multi_server.go index d2444be..03c9164 100644 --- a/server/multi_server.go +++ b/server/multi_server.go @@ -60,6 +60,9 @@ func (server *MultiServer) Work() { //syncMap //Get big packets from map port and broadcast them to all vplayers. +//1. host player create a room and then send udp broadcast packets about 700 bytes +//2. other players get this and reply a join packets about 200 bytes right to the host player's ip +// so, the map packets must be sent from the right port, otherwise the reply steps will fail. func (server *MultiServer) syncMap() { for { msg,rAddr,err := utils.ParseMsg(server.mapConn) diff --git a/server/v_player.go b/server/v_player.go index 8338e0b..7ae55a8 100644 --- a/server/v_player.go +++ b/server/v_player.go @@ -48,15 +48,15 @@ func (p *VPlayer) handle(msg []byte, raddr *net.UDPAddr) { } // if current vplayer has no player to present, just ignore the msg. // if remote player send msg to itself vplayer, also ignore it. - fmt.Println(sender.id+" and "+p.id) + if p.playerAddr == nil || p==sender{ - fmt.Println("ignore!") return } //forward // current vplayer send the package to target vplayer's real raddr - fmt.Println("simply forward packets ...") + fmt.Print("simply forward packets ...") + fmt.Println(sender.id+" to "+p.id) sender.netter.send(msg, p.playerAddr) } @@ -89,9 +89,11 @@ func (controller *VPlayerController) work() { } } +//todo +// since there's no identitiy part, now only send packets as the first register player func (controller *VPlayerController) broadcast(msg []byte) { for i := range controller.players { p := &controller.players[i] - p.netter.send(msg, p.playerAddr) + controller.players[0].netter.send(msg, p.playerAddr) } }