示例#1
0
文件: router.go 项目: gemrs/gem
func Dispatch(player player.Player, packet encoding.Decodable) {
	typeString := reflect.TypeOf(packet).String()
	if handler, ok := routingTable[typeString]; ok {
		handler(player, packet)
	} else {
		player.Log().Info("Unhandled packet of type %v: %v", typeString, packet)
	}
}
示例#2
0
文件: game_service.go 项目: gemrs/gem
// packetConsumer is the goroutine which picks packets from the readQueue and does something with them
func (svc *GameService) packetConsumer(client player.Player) {
L:
	for {
		select {
		case <-client.Conn().DisconnectChan:
			break L
		case pkt := <-client.Conn().Read:
			if _, ok := pkt.(*game_protocol.UnknownPacket); ok {
				/* unknown packet; dump to the log */
				client.Log().Debug("Got unknown packet: %v", pkt)
				continue
			}
			packet.Dispatch(client, pkt)
		}

	}
}
示例#3
0
文件: game_login.go 项目: gemrs/gem
// decodeLoginBlock handles the unencrypted login block
func (svc *GameService) decodeLoginBlock(client player.Player) error {
	loginBlock := game_protocol.InboundLoginBlock{}
	if err := loginBlock.Decode(client.Conn().ReadBuffer, nil); err != nil {
		return err
	}

	expectedSecureBlockSize := int(loginBlock.LoginLen) - ((9 * 4) + 1 + 1 + 1 + 2)
	if expectedSecureBlockSize != int(loginBlock.SecureBlockSize) {
		client.Log().Error("Secure block size mismatch: got %v expected %v", loginBlock.SecureBlockSize, expectedSecureBlockSize)
		client.Conn().Disconnect()
	}

	client.SetSecureBlockSize(int(loginBlock.SecureBlockSize))

	client.SetDecodeFunc(svc.decodeSecureBlock)
	return nil
}