func handleRoomEnter(p *entity.Player, req interface{}) error { pck, ok := req.(*olbattle.RoomEnter) if !ok { return protocol.ErrorInvalidProtocol } log.Debugf("%d:room enter", p.PlayerID) r := GetRoomMgr().RoomEnter(p, pck.BattleDataStr) if r == nil { pck.ErrorCode = int32(protocol.CERROR_ROOM_NOT_FIND) } else { r.addPlayer(p) } p.SendClient(pck) return nil } 注释每行代码
时间: 2024-03-02 10:49:08 浏览: 67
Sure, here's the commented code:
```go
// handleRoomEnter is a function that handles a player entering a room
func handleRoomEnter(p *entity.Player, req interface{}) error {
// Check if the request is of the correct type
pck, ok := req.(*olbattle.RoomEnter)
if !ok {
return protocol.ErrorInvalidProtocol
}
// Log that the player is entering the room
log.Debugf("%d:room enter", p.PlayerID)
// Try to enter the room
r := GetRoomMgr().RoomEnter(p, pck.BattleDataStr)
if r == nil {
// If the room cannot be found, set the error code
pck.ErrorCode = int32(protocol.CERROR_ROOM_NOT_FIND)
} else {
// If the room is found, add the player to the room
r.addPlayer(p)
}
// Send the response packet to the client
p.SendClient(pck)
return nil
}
```
阅读全文