Esempio n. 1
0
// 第一个参数表示连接是否正常
func (m *Player) ProcessLogic() (bool, error) {
	for {
		sendSize, err := m.connection.ProcessOutput()
		if err != nil {
			return true, err
		}

		if sendSize <= 0 {
			break
		}
	}

	for {
		if nil == m.packetExecuter {
			break
		}
		newPacket, err := m.connection.ProcessInput()
		if nil != err {
			module.CacheLog("Player.ProcessLogic, get packet error, ", err.Error())
			return true, err
		}
		if nil == newPacket {
			break
		}

		err = newPacket.Execute(m.packetExecuter)

		if nil != err {
			module.CacheLog("Player.ProcessLogic, execute packet error, ", err.Error())
			return false, err
		}
	}

	return false, nil
}
Esempio n. 2
0
func (m *PlayerManager) RemovePlayer(id int) *Player {
	player, ok := m.playerMap[id]
	if ok {
		module.CacheLog("remove player: ", player.ID, player.Name)
		delete(m.playerMap, id)
	} else {
		module.CacheLog("remove player error: player id not found id:%d", id)
	}

	return player
}
Esempio n. 3
0
func NewPlayer(conn net.Conn, playerID int) *Player {
	player := &Player{
		connection: network.NewConnection(conn),
		ID:         playerID,
	}
	module.CacheLog("player.NewPlayer, add new player: ", player.ID, player.Name)
	return player
}
Esempio n. 4
0
func (m *PlayerManager) Tick() {
	for _, curPlayer := range m.playerMap {
		isConnectError, err := curPlayer.ProcessLogic()
		if err != nil {
			module.CacheLog("PlayerManager:Tick processLogic error", err.Error())
			if isConnectError {
				m.removePlayerList = append(m.removePlayerList, curPlayer.ID)
			}
		}
	}

	for removePlayerID := range m.removePlayerList {
		m.RemovePlayer(removePlayerID)
	}

	m.removePlayerList = m.removePlayerList[:0]

	//module.DebugLog("player manager tick")
}