func (c *RearrangeChoice) WritePacket() pnet.IPacket {
	packet := pnet.NewQTPacket()
	for i := 0; i < 6; i++ {
		packet.AddUint8(uint8(c.PokeIndexes[i]))
	}
	return packet
}
Example #2
0
func (t *TeamPoke) WritePacket() pnet.IPacket {
	packet := pnet.NewQTPacket()
	uIdPacket := t.UID.WritePacket()
	packet.AddBuffer(uIdPacket.GetBufferSlice())
	packet.AddString(t.Nick)
	packet.AddUint16(uint16(t.Item))
	packet.AddUint16(uint16(t.Ability))
	packet.AddUint8(uint8(t.Nature))
	packet.AddUint8(uint8(t.Gender))
	// packet.AddUint8(uint8(t.Gen)) // XXX Gen would go here
	packet.AddBool(t.Shiny)
	packet.AddUint8(uint8(t.Happiness))
	packet.AddUint8(uint8(t.Level))

	for i := 0; i < 4; i++ {
		packet.AddUint32(uint32(t.Moves[i]))
	}

	for i := 0; i < 6; i++ {
		packet.AddUint8(uint8(t.DVs[i]))
	}

	for i := 0; i < 6; i++ {
		packet.AddUint8(uint8(t.EVs[i]))
	}

	return packet
}
Example #3
0
func (b *Battle) sendBattleMessageCancel() {
	packet := pnet.NewQTPacket()
	packet.AddUint32(uint32(b.bID))
	bc := NewBattleChoice(b.me, CHOICETYPE_CANCELTYPE)
	packet.AddBuffer(bc.WritePacket().GetBufferSlice())

	b.owner.SendMessage(packet, COMMAND_BattleMessage)
}
Example #4
0
func (c *POClient) constructChallenge(_desc int, _opp int, _clauses int, _mode int) *pnet.QTPacket {
	packet := pnet.NewQTPacket()
	packet.AddUint8(uint8(_desc))
	packet.AddUint32(uint32(_opp))
	packet.AddUint32(uint32(_clauses))
	packet.AddUint8(uint8(_mode))
	return packet
}
Example #5
0
func (t *Team) WritePacket() pnet.IPacket {
	packet := pnet.NewQTPacket()
	packet.AddUint8(uint8(t.Gen))
	for i := 0; i < 6; i++ {
		packet.AddBuffer(t.Pokes[i].WritePacket().GetBufferSlice())
	}

	return packet
}
Example #6
0
// -------------------- Send Messages ----------------------
func (b *Battle) sendBattleMessageAttack(_attackSlot int) {
	packet := pnet.NewQTPacket()
	packet.AddUint32(uint32(b.bID))
	ac := NewAttackChoice(_attackSlot, b.opp)
	bc := NewBattleChoiceWithChoice(b.me, ac, CHOICETYPE_ATTACKTYPE)
	packet.AddBuffer(bc.WritePacket().GetBufferSlice())

	b.owner.SendMessage(packet, COMMAND_BattleMessage)
}
func (p *FullPlayerInfo) WritePacket() pnet.IPacket {
	packet := pnet.NewQTPacket()
	packet.AddBuffer(p.Team.WritePacket().GetBufferSlice())
	packet.AddBool(p.ladderEnabled)
	packet.AddBool(p.showTeam)
	packet.AddBuffer(p.nameColor.WritePacket().GetBufferSlice())

	return packet
}
Example #8
0
func (b *Battle) sendBattleMessageSwitch(_toSpot int) {
	packet := pnet.NewQTPacket()
	packet.AddUint32(uint32(b.bID))
	sc := NewSwitchChoice(_toSpot)
	bc := NewBattleChoiceWithChoice(b.me, sc, CHOICETYPE_SWITCHTYPE)
	packet.AddBuffer(bc.WritePacket().GetBufferSlice())

	b.owner.SendMessage(packet, COMMAND_BattleMessage)
}
Example #9
0
func (c *QColor) WritePacket() pnet.IPacket {
	packet := pnet.NewQTPacket()
	packet.AddUint8(c.Spec)
	packet.AddUint16(c.Alpha)
	packet.AddUint16(c.Red)
	packet.AddUint16(c.Green)
	packet.AddUint16(c.Blue)
	packet.AddUint16(c.Pad)
	return packet
}
Example #10
0
func (p *PlayerTeam) WritePacket() pnet.IPacket {
	packet := pnet.NewQTPacket()
	packet.AddString(p.Nick)
	packet.AddString(p.Info)
	packet.AddString(p.LoseMessage)
	packet.AddString(p.WinMessage)
	packet.AddUint16(uint16(p.avatar))
	packet.AddString(p.DefaultTier)
	packet.AddBuffer(p.Team.WritePacket().GetBufferSlice())

	return packet
}
func (s *POClientSocket) SendMessage(_buffer pnet.IPacket, _header int) {
	packet := pnet.NewQTPacket()
	packet.AddUint8(uint8(_header))
	if !packet.AddBuffer(_buffer.GetBufferSlice()) {
		fmt.Println("[ERROR] PACKET IS TOO LARGE, CAN NOT ADD BUFFER!")
		return
	}
	packet.SetHeader()

	fmt.Printf("Sending packet with header: %v\n", _header)

	// Send message to the big bad internetz and pray for it to arrive
	s.socket.Write(packet.Buffer[0:packet.MsgSize])
}
Example #12
0
func (b *BattleChoice) WritePacket() pnet.IPacket {
	packet := pnet.NewQTPacket()
	packet.AddUint8(uint8(b.PlayerSlot))
	packet.AddUint8(uint8(b.ChoiceType))

	switch b.ChoiceType {
	case CHOICETYPE_SWITCHTYPE:
		fallthrough
	case CHOICETYPE_ATTACKTYPE:
		fallthrough
	case CHOICETYPE_REARRANGETYPE:
		packet.AddBuffer(b.Choice.WritePacket().GetBufferSlice())
	}

	return packet
}
func (s *POClientSocket) ReceiveMessages() {
	for s.connected {
		var headerbuffer [2]uint8
		recv, err := s.socket.Read(headerbuffer[0:])
		if err != nil || recv == 0 {
			fmt.Println("[POCLIENTSOCKET] Disconnected")
			break
		}

		packet := pnet.NewQTPacket()
		copy(packet.Buffer[0:2], headerbuffer[0:2])
		packet.GetHeader()

		databuffer := make([]uint8, packet.MsgSize)

		reloop := false
		bytesReceived := uint16(0)
		for bytesReceived < packet.MsgSize {
			recv, err := io.ReadFull(s.socket, databuffer[bytesReceived:])
			if recv == 0 {
				reloop = true
				break
			} else if err != nil {
				fmt.Printf("[POCLIENTSOCKET] Read error: %v\n", err)
				reloop = true
				break
			}
			bytesReceived += uint16(recv)
		}

		if reloop {
			continue
		}
		copy(packet.Buffer[2:], databuffer[:])

		s.owner.ProcessPacket(packet)
	}

	fmt.Println("EXIT")

	s.connected = false
}
Example #14
0
func (c *SwitchChoice) WritePacket() pnet.IPacket {
	packet := pnet.NewQTPacket()
	packet.AddUint8(uint8(c.PokeSlot))
	return packet
}
Example #15
0
func (c *AttackChoice) WritePacket() pnet.IPacket {
	packet := pnet.NewQTPacket()
	packet.AddUint8(uint8(c.AttackSlot))
	packet.AddUint8(uint8(c.AttackTarget))
	return packet
}
Example #16
0
func (c *DrawChoice) WritePacket() pnet.IPacket {
	return pnet.NewQTPacket()
}
Example #17
0
func (c *MoveToCenterChoice) WritePacket() pnet.IPacket {
	return pnet.NewQTPacket()
}
Example #18
0
// --------------------- Send Packets --------------------------- //
func (c *POClient) keepAlive() {
	c.SendMessage(pnet.NewQTPacket(), COMMAND_KeepAlive)
}
func (s *POClientSocket) loginTest() {
	packet := pnet.NewQTPacket()
	packet.AddString("HerpDerp")    // Name
	packet.AddString("Dark Info")   // Info
	packet.AddString("Dark Lose")   // Lose text
	packet.AddString("Dark Winrar") // Win text
	packet.AddUint16(0)             // Avatar
	packet.AddString("1")           // Default Tier
	packet.AddUint8(5)              // Generation

	// TEAM - Loop Pokemon
	packet.AddUint16(16)       // pokemon number
	packet.AddUint8(0)         // sub number (alt-forms)
	packet.AddString("Pidgey") // nickname
	packet.AddUint16(0)        // item
	packet.AddUint16(65)       // ability
	packet.AddUint8(0)         // nature
	packet.AddUint8(1)         // gender
	packet.AddUint8(0)         // shiny
	packet.AddUint8(0)         // happiness
	packet.AddUint8(100)       // level

	// Team - Loop Pokemon - Loop Moves
	packet.AddUint32(16) // moveid
	packet.AddUint32(0)  // moveid
	packet.AddUint32(0)  // moveid
	packet.AddUint32(0)  // moveid
	// Team - Loop Pokemon - End Loop Moves
	// Team - Loop Pokemon - Loop DV
	packet.AddUint8(15) // hp
	packet.AddUint8(15) // attack
	packet.AddUint8(15) // defense
	packet.AddUint8(15) // SpAttack
	packet.AddUint8(15) // SpDefence
	packet.AddUint8(15) // Speed
	// Team - Loop Pokemon - End Loop DV
	// Team - Loop Pokemon - Loop EV
	packet.AddUint8(152)
	packet.AddUint8(92)
	packet.AddUint8(60)
	packet.AddUint8(64)
	packet.AddUint8(64)
	packet.AddUint8(76)
	// Team - Loop Pokemon - End Loop EV

	// Loop 5 more empty pokemon
	for i := 0; i < 5; i++ {
		packet.AddUint16(0)  // pokemon number
		packet.AddUint8(0)   // sub number (alt-forms)
		packet.AddString("") // nickname
		packet.AddUint16(0)  // item
		packet.AddUint16(0)  // ability
		packet.AddUint8(0)   // nature
		packet.AddUint8(0)   // gender
		packet.AddUint8(0)   // shiny
		packet.AddUint8(0)   // happiness
		packet.AddUint8(0)   // level

		packet.AddUint32(0) // moveid
		packet.AddUint32(0) // moveid
		packet.AddUint32(0) // moveid
		packet.AddUint32(0) // moveid

		packet.AddUint8(0) // hp
		packet.AddUint8(0) // attack
		packet.AddUint8(0) // defense
		packet.AddUint8(0) // SpAttack
		packet.AddUint8(0) // SpDefence
		packet.AddUint8(0) // Speed

		packet.AddUint8(0)
		packet.AddUint8(0)
		packet.AddUint8(0)
		packet.AddUint8(0)
		packet.AddUint8(0)
		packet.AddUint8(0)
	}

	// Team - End Loop Pokemon
	packet.AddUint8(1)  // Ladder
	packet.AddUint8(1)  // Show team
	packet.AddUint32(1) // Colour

	s.SendMessage(packet, COMMAND_Login)
}