Skip to content

Commit

Permalink
🚑 fix map info sending logic so now multiple player mode can work fine.
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyJavaBean committed Sep 15, 2021
1 parent 13668b6 commit e2ef0e0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions client/client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
3 changes: 3 additions & 0 deletions server/multi_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions server/v_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
Expand Down Expand Up @@ -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)
}
}

0 comments on commit e2ef0e0

Please sign in to comment.