Module: GTS::Core

Defined in:
scripts/01450 Systems/09000 GTS/09000 GTS.rb

Overview

GTS Core By A Dork of Pork, Rewritten by Nuri Yuri Core GTS functions (Basically this is what you need to make a complete GTS system)

Constant Summary collapse

LOCK =

Locking mutex

Mutex.new

Class Method Summary collapse

Class Method Details

.delete_pokemon(withdraw = true, party = PFM.game_state)

deletes your current pokemon from the server



883
884
885
886
887
888
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 883

def delete_pokemon(withdraw = true, party = PFM.game_state)
  r = execute('deletePokemon', id: party.online_id, withdraw: withdraw ? 'y' : 'n')
  ret = r == 'success'
  log_error(r) unless ret
  return ret
end

.download_pokemon(id)

downloads a pokemon string with the given online ID



865
866
867
868
869
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 865

def download_pokemon(id)
  r = execute('downloadPokemon', id: id)
  log_error('Empty response') if r.empty?
  return r.empty? ? false : r
end

.download_wanted_data(id)

downloads the wanted data with the given online ID



872
873
874
875
876
877
878
879
880
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 872

def download_wanted_data(id)
  r = execute('downloadWantedData', id: id)
  log_error('Empty response') if r.empty?
  return [] if r.empty?

  r = r.split(',').collect(&:to_i)
  r[3] = 0 if r[3] < 0
  return r
end

.execute(action, data = {})

Our main execution method, since I'm too lazy to write Settings::URL a lot



788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 788

def execute(action, data = {})
  data[:action] = action
  result = nil
  Thread.new do
    LOCK.synchronize do
      Thread.main.wakeup
      result = Net::HTTP.post_form(@uri, data).body
      Thread.main.wakeup
    end
  end
  sleep unless LOCK.locked? || result
  GTS.loading_screen&.process
  Graphics.update while LOCK.locked? # Security
  return result
end

.get_pokemon_list(*wanted_data)

gets a list of online IDs where the wanted data match up



891
892
893
894
895
896
897
898
899
900
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 891

def get_pokemon_list(*wanted_data)
  wanted_data = wanted_data[0] if wanted_data[0].is_a?(Array)
  r = execute('getPokemonList',
              id: PFM.game_state.online_id, species: wanted_data[0], levelMin: wanted_data[1],
              levelMax: wanted_data[2], gender: translate_gender(wanted_data[3]))
  return [r] if r == 'nothing'
  return r.split('/,,,/') if r.include?('/,,,/')

  return r.split(',')
end

.get_pokemon_list_from_wanted(pokemon)

Reverse Lookup pokemon



903
904
905
906
907
908
909
910
911
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 903

def get_pokemon_list_from_wanted(pokemon)
  r = execute('getPokemonListFromWanted',
              id: PFM.game_state.online_id, species: pokemon.id, level: pokemon.level,
              gender: translate_gender(pokemon.gender))
  return [r] if r == 'nothing'
  return r.split('/,,,/') if r.include?('/,,,/')

  return r.split(',')
end

.install

installs the MYSQL tables in the server



914
915
916
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 914

def install
  return execute('createTables')
end

.obtain_online_id

gets a new online ID from the server



805
806
807
808
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 805

def obtain_online_id
  r = execute('getOnlineID')
  return r.to_i
end

.pokemon_taken?(id = PFM.game_state.online_id) ⇒ Boolean

checks wether the pokemon with the give online ID is taken

Returns:

  • (Boolean)


834
835
836
837
838
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 834

def pokemon_taken?(id = PFM.game_state.online_id)
  r = execute('isTaken', id: id)
  log_error(r) unless r == 'yes' || r == 'no'
  return r == 'yes'
end

.pokemon_uploaded?(id = PFM.game_state.online_id) ⇒ Boolean

checks whether you have a pokemon uploaded in the server

Returns:

  • (Boolean)


819
820
821
822
823
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 819

def pokemon_uploaded?(id = PFM.game_state.online_id)
  r = execute('hasPokemonUploaded', id: id)
  log_error(r) unless r == 'yes' || r == 'no'
  return r == 'yes'
end

.register_online_id(id)

registers our new online ID to the server



811
812
813
814
815
816
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 811

def register_online_id(id)
  r = execute('setOnlineID', id: id)
  ret = r == 'success'
  log_error(r) unless ret
  return ret
end

.take_pokemon(id)

sets the pokemon with the given online ID to taken



826
827
828
829
830
831
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 826

def take_pokemon(id)
  r = execute('setTaken', id: id)
  ret = r == 'success'
  log_error(r) unless ret
  return ret
end

.test_connection

Tests connection to the server (not used anymore but kept for possible use)



780
781
782
783
784
785
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 780

def test_connection
  x = execute('test')
  return !x.empty?
rescue StandardError
  return false
end

.translate_gender(wanted)

Translate the wanted gender field for the server



919
920
921
922
923
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 919

def translate_gender(wanted)
  return -1 if wanted == 0

  return wanted
end

.update_uri

Update the URI



775
776
777
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 775

def update_uri
  @uri = URI(Settings::URL + Settings::GAMEID.to_s)
end

.upload_new_pokemon(id, pokemon)

uploads the newly traded pokemon to the given online ID to the server



856
857
858
859
860
861
862
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 856

def upload_new_pokemon(id, pokemon)
  pokemon.game_code = Settings::GAME_CODE
  r = execute('uploadNewPokemon', id: id, pokemon: pokemon.encode)
  ret = r == 'success'
  log_error(r) unless ret
  return ret
end

.upload_pokemon(pokemon, *wanted_data)

uploads a pokemon to the server



841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 841

def upload_pokemon(pokemon, *wanted_data)
  wanted_data = wanted_data[0] if wanted_data[0].is_a?(Array)
  pokemon.game_code = Settings::GAME_CODE
  data = {
    id: PFM.game_state.online_id, pokemon: pokemon.encode, species: pokemon.id, level: pokemon.level,
    gender: pokemon.gender, Wspecies: wanted_data[0], WlevelMin: wanted_data[1],
    WlevelMax: wanted_data[2], Wgender: translate_gender(wanted_data[3])
  }
  r = execute('uploadPokemon', data)
  ret = r == 'success'
  log_error(r) unless ret
  return ret
end