MOAR EMPIRE xD
Posts tagged "ruby"
-
-
Empire grow…
-
Word Squared empire in just 5 hours :)
-
Word Squared Solver on GitHub! →
First commit! :)
-
WordSquared bot
Looks like i wrote a good enough bot for http://wordsquared.com/
Version 0.1b at youtube: http://www.youtube.com/watch?v=NilCjtRIvng
It was more laggy, than current :)As below log shows, its completing words with 2-4w per 1s, but this affected only by my current internet connection.
Later i’ll move it to dedicated server in hetzner.de to test European’s speed.P.S. from 3k point to 10k in 10 mins :) P.S.S. Still using http://wordsolver.net/ word’s database -.-
-
Dofus first AI… Roaming between wheet :) That later it will farm…
-
Ruby & Binary data… My way of parsing:
Wrote class, that help me reading binary data:
Usage
"\x11\x5f\x14".log # show hexdump "\x40\x40".readShort # & etcCode
module NetString LITTLE_ENDIAN = 1 BIG_ENDIAN = 2 SYS_ENDIAN = ([42].pack('i')[0].ord == 42) ? LITTLE_ENDIAN : BIG_ENDIAN def endian #@endian = SYS_ENDIAN if @endian.nil? @endian = BIG_ENDIAN if @endian.nil? @endian end def endianess=(endian) unless [BIG_ENDIAN, LITTLE_ENDIAN].include? endian raise 'Endianess should be set with const: NetString::LITTLE_ENDIAN or NetString::BIG_ENDIAN' exit end @endian = endian end def endianess data endian if @endian != SYS_ENDIAN data.reverse! end end def nsRead l, endian = true case self when String self.force_encoding 'ASCII-8BIT' if self.encoding.to_s == 'UTF-8' data = slice!(0, l) when File, StringIO data = read(l) end unless data.bytes.to_a.size == l self.log "self" pp l data.log "data" end raise 'NetString: incorrect length data read' unless data.bytes.to_a.size == l endianess(data) if endian data end def readByte; nsRead(1, false).unpack('c').first.to_i; end ## signed def readUByte; nsRead(1, false).unpack('C').first.to_i; end def readBoolean; !(readByte == 0); end def readShort; nsRead(2).unpack('s').first.to_i; end ## signed def readUShort; nsRead(2).unpack('S').first.to_i; end def readInt; nsRead(4).unpack('l').first.to_i; end ## signed def readUInt; nsRead(4).unpack('L').first.to_i; end def readDouble; nsRead(8, false).unpack('G').first.to_i; end ## Double-precision float def readFloat; puts '----------- CHECK ME READ FLOAT -----------'; nsRead(8).unpack('g').first.to_i; end ## Single-precision float def readQuad; nsRead(8).unpack('Q').first.to_i; end def readLongLong; a = readInt; b = readInt; a | (b << 32); end def readBytesAsString l; nsRead(l, false); end def readString; str = ''; while (char = readBytesAsString(1)) != "\x00"; str << char; end; str; end def readUTFString; s = readShort; readBytesAsString s; end alias_method :readUnsignedByte, :readUByte alias_method :readUnsignedShort, :readUShort alias_method :readUnsignedInt, :readUInt alias_method :readUTF, :readUTFString def nsWrite data, endian = true endianess(data) if endian case self.class.to_s when 'String' concat(data) when 'File' print data end self end def writeByte data; nsWrite([data].pack('c'), false); end def writeUByte data; nsWrite([data].pack('C'), false); end def writeBoolean data; nsWrite([data.to_i].pack('C'), false); end def writeShort data; nsWrite([data].pack('s')); end def writeUShort data; nsWrite([data].pack('S')); end def writeInt data; nsWrite([data].pack('l')); end def writeUInt data; nsWrite([data].pack('L')); end def writeDouble; puts '----------- CHECK ME WRITE DOUBLE -----------', nsWrite([data].pack('G')); end ## Double-precision float def writeFloat; puts '----------- CHECK ME WRITE FLOAT -----------', nsWrite([data].pack('g')); end ## Single-precision float def writeQuad data; nsWrite([data].pack('Q')); end def writeBytesAsString data; nsWrite(data, false); end def writeString data; nsWrite(data + "\x00", false); end def writeUTFString data; writeUShort(data.size); nsWrite(data, false); end def hexed(short = false) f = '%02X' j = ' ' if short f = '%02x' j = '' end h = bytes.to_a.collect { |c| f % c } h.join j end def to_ansi string = '' t = bytes.to_a.each do |byte| byte = 46 if byte < 33 or byte > 126 string += ' ' + byte.chr end string.strip end def log(name = nil, short = false) puts rlog(name, short) end def rlog(name, short = false) name = 'DATA DUMP' if name.nil? pad = '-' * 25 firstline = "#{pad} #{name} (#{length}) #{pad}" endline = '-' * firstline.length firstline << "\n" << to_ansi << "\n" << hexed(short) << "\n" << endline end def to_block(l = 50, params = {}) l /= 2 self.strip! puts "#{'-' * l} #{self} #{'-' * l}\n" params.each { |k, v| puts "#{k}: #{v}" } if params.size yield puts "#{'-' * (2 * l + length + 2)}" end end class String include NetString end class IO include NetString end class StringIO include NetString endBtw, it’s in beta currently, because i didn’t check float/double methods enough :)
-
Flickr & Ruby…
Simple ruby script, for downloading flickr’s photosets
Requirements
sudo gem install flickraw mechanizeUsage
ruby flickr.rbCode
#!/usr/local/rvm/ruby # encoding: utf-8 require "fileutils" require "flickraw" require "mechanize" m = Mechanize.new FlickRaw.api_key = "<YOU_API_KEY>" FlickRaw.shared_secret = "<YOR_API_SECRET>" photosets = %w{<PHOTOSTREAM_ID> <PHOTOSTREAM_ID> <PHOTOSTREAM_ID> <PHOTOSTREAM_ID>} photosets.each do |photoset_id| list = flickr.photosets.getPhotos(photoset_id: photoset_id, extras: 'url_o, url_l, url_m') h = list.to_hash h["photo"].each do |p| url = p["url_o"] || p["url_l"] || p["url_m"] filedir = "flickr/#{photoset_id}" filename = File.basename(url) filepath = "#{filedir}/#{filename}" next if File.exists?(filepath) file = m.get(url) FileUtils.mkdir_p(filedir) file.save_as(filepath) end end -
Oh yeah!
Now it can login, move, and say through console :)
[ INFO] [D2I] Parsing i18n_en.d2i [ INFO] [D2O] Parsing InfoMessages.d2o [ INFO] [D2O] Parsing Servers.d2o [ INFO] [D2O] Parsing ChatChannels.d2o [ INFO] Connected [ OK] Authentification successful [ INFO] Connected [ OK] Ticket accepted [ INFO] Position in character selection queue: 1 / 1 [ INFO] Position in character selection queue: 0 / 0 [ INFO] Position in character selection queue: 0 / 0 [ INFO] Character weight: 14 / 1000 [ OK] Welcome to DOFUS, and welcome to the World of Twelve! Remember that it is <b>strictly forbidden</b> to disclose your account name or password. [ OK] This account was last accessed on 13/07/2011 at 05:02. [CHAT] [GENERAL] : oops [CHAT] [GENERAL] : like i didn't did it wrong?! [CHAT] [GENERAL] : heh [CHAT] [PRIVATE] : asd [CHAT] [PRIVATE] : wanna join me ? ) say hellow world ) [CHAT] [GENERAL] : hellow world ) say bla bla bla [CHAT] [GENERAL] : bla bla bla -
Dofus «login -> game» sequence
Just got it…
def check_connection recv # receive packets case @state when STATE_NOT_CONNECTED reconnect when STATE_CONNECTED_TO_LOGIN @packets.pop do |packet| case packet when Com::AnkamaGames::Dofus::Network::Messages::Handshake::ProtocolRequired if packet.requiredVersion > $config.protocol_build log("Current protocol build: #{$config.protocol_build}, required build: #{packet.requiredVersion}", Logger::FATAL) end if packet.currentVersion < $config.protocol_required_build log("Current protocol build: #{$config.protocol_required_build}, is too new for the server version: #{packet.currentVersion}", Logger::FATAL) end when HelloConnectMessage $config.session_key = packet.sessionKey im = IdentificationMessage.new bytes = im.build!({ username: $config.username, password: $config.password, version: $config.version, session_key: $config.session_key }) send_data bytes when Com::AnkamaGames::Dofus::Network::Messages::Queues::LoginQueueStatusMessage l("Position in login queue: #{packet.position} / #{packet.total}") when IdentificationSuccessMessage l('Authentification successful', Logger::OK) @state = STATE_SERVERS_LIST else l("Incorrect packet at $net.STATE_CONNECTED_TO_LOGIN: #{packet.class}", Logger::FATAL) end end when STATE_SERVERS_LIST @packets.pop do |packet| case packet when ServersListMessage if !$config.server_id "Select server:".to_block(10) { packet.servers.select { |s| s.status == s.class::STATUS_ONLINE }.each do |s| printf("%5d %s %d %s\n", s.id, "-", s.charactersCount, s.status_t) end } while line = gets do line.strip! next if line.empty? exit if line.to_i == 0 server = packet.servers.find { |s| s.id == line.to_i } next unless server $config.server_id = server.id break end end ssm = ServerSelectionMessage.new.build!($config.server_id) send_data ssm when SelectedServerDataMessage @ip = packet.address @port = packet.port $config.ticket = packet.ticket reconnect @state = STATE_CONNECTED_TO_GAME else l("Incorrect packet at $net.STATE_SERVERS_LIST: #{packet.class}", Logger::FATAL) end end when STATE_CONNECTED_TO_GAME @packets.pop do |packet| case packet when Com::AnkamaGames::Dofus::Network::Messages::Handshake::ProtocolRequired if packet.requiredVersion > $config.protocol_build log("Current protocol build: #{$config.protocol_build}, required build: #{packet.requiredVersion}", Logger::FATAL) end if packet.currentVersion < $config.protocol_required_build log("Current protocol build: #{$config.protocol_required_build}, is too new for the server version: #{packet.currentVersion}", Logger::FATAL) end when HelloGameMessage atm = AuthenticationTicketMessage.new.build!('en', $config.ticket) send_data atm when AuthenticationTicketAcceptedMessage l("Ticket accepted", Logger::OK) when Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::BasicTimeMessage # nothing to do, just ignore when Com::AnkamaGames::Dofus::Network::Messages::Game::Approach::AccountCapabilitiesMessage $config.account_id = packet.account_id clrm = Com::AnkamaGames::Dofus::Network::Messages::Game::Character::Choice::CharactersListRequestMessage.new.build! send_data clrm @state = STATE_CHARACTER_SELECTION else l("Incorrect packet at $net.STATE_CONNECTED_TO_GAME: #{packet.class}", Logger::FATAL) end end when STATE_CHARACTER_SELECTION @packets.pop do |packet| case packet when Com::AnkamaGames::Dofus::Network::Messages::Queues::QueueStatusMessage l("Position in character selection queue: #{packet.position} / #{packet.total}") when Com::AnkamaGames::Dofus::Network::Messages::Secure::TrustStatusMessage, Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::BasicNoOperationMessage # nothing to do, ignore when Com::AnkamaGames::Dofus::Network::Messages::Game::Character::Choice::CharactersListMessage characters = packet.characters if !$config.character_id && characters.size > 0 puts "Choose your character:" fields = sprintf("%20s | %5s | %5s | %6s", 'Name', 'Level', 'Class', 'Sex') puts fields, '-' * fields.size characters.each do |c| puts sprintf("%20s | %5d | %5d | %6s", c.name, c.level, c.breed, c.sex ? 'Male' : 'Female') end while line = gets do line.strip! break if line.empty? character = characters.find { |c| c.name.downcase == line.downcase } next unless character $config.character_id = character.id break end csm = Com::AnkamaGames::Dofus::Network::Messages::Game::Character::Choice::CharacterSelectionMessage.new.build!($config.character_id) send_data csm @state = STATE_IN_GAME elsif characters.size == 0 l("No character created", Logger::FATAL) exit end else l("Incorrect packet at $net.STATE_CHARACTER_SELECTION: #{packet.class}", Logger::FATAL) end end when STATE_IN_GAME else l("Unknown state #{state} for $net", Logger::FATAL); exit end endOutput
[user host-122 ~/Documents/Projects/dofus] ./run.rb [ INFO] [D2O] Parsing Servers.d2o [ INFO] Connected [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Handshake::ProtocolRequired [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Connection::HelloConnectMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Connection::IdentificationMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Connection::IdentificationSuccessMessage [ OK] Authentification successful [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Connection::ServersListMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Connection::ServerSelectionMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Connection::SelectedServerDataMessage [ INFO] Connected [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Handshake::ProtocolRequired [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Approach::HelloGameMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Approach::AuthenticationTicketMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Approach::AuthenticationTicketAcceptedMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::BasicTimeMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Approach::AccountCapabilitiesMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Secure::TrustStatusMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::BasicNoOperationMessage [ OK] Ticket accepted [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Character::Choice::CharactersListRequestMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Queues::QueueStatusMessage [ INFO] Position in character selection queue: 1 / 1 [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Queues::QueueStatusMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::BasicNoOperationMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Queues::QueueStatusMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Character::Choice::CharactersListMessage [ INFO] Position in character selection queue: 0 / 0 [ INFO] Position in character selection queue: 0 / 0 Choose your character: Name | Level | Class | Sex --------------------------------------------- Char1 | 2 | 5 | Male Char2 | 4 | 3 | Female Char3 | 19 | 9 | Female Char1 [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Character::Choice::CharacterSelectionMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::BasicNoOperationMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Context::Notification::NotificationListMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Character::Choice::CharacterSelectedSuccessMessage [ INFO] Selected character: [------] Char1 (2) [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Inventory::Items::InventoryContentMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Inventory::Items::SetUpdateMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Shortcut::ShortcutBarContentMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Shortcut::ShortcutBarContentMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Context::Roleplay::Emote::EmoteListMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Pvp::AlignmentRankUpdateMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Pvp::AlignmentSubAreasListMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Chat::Channel::EnabledChannelsMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Inventory::Spells::SpellListMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Shortcut::ShortcutBarContentMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Initialization::SetCharacterRestrictionsMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Inventory::Items::InventoryWeightMessage [ INFO] Character weight: 14 / 1000 [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Friend::FriendWarnOnConnectionStateMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Friend::GuildMemberWarnOnConnectionStateMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Friend::FriendWarnOnLevelGainStateMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::TextInformationMessage [ WARN] Check Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::TextInformationMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::TextInformationMessage [ WARN] Check Com::AnkamaGames::Dofus::Network::Messages::Game::Basic::TextInformationMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Initialization::ServerExperienceModificatorMessage [DEBUG] Com::AnkamaGames::Dofus::Network::Messages::Game::Friend::SpouseStatusMessageP.S. Please don’t blame my ugly code :)

