Last active
December 22, 2015 02:39
-
-
Save oh-sky/6404680 to your computer and use it in GitHub Desktop.
艦隊をコマンドで操作したかった・・・
※ちょっと待て、使う前に利用規約をちゃんと読め → http://www.dmm.com/rule/=/category=onlinegame_service/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
# configure | |
API_VERNO = 1 | |
API_TOKEN = '' | |
KNKR_HOST = '' | |
$header = { | |
'Referer' => "http://#{KNKR_HOST}/kcs/port.swf?version=1.3.7", | |
} | |
#PROXY_ADDR = '' | |
#PROXY_PORT = 8888 | |
require 'net/http' | |
require 'json' | |
#履歴情報取得関数 | |
def getActionLog (http) | |
queryString = '/kcsapi/api_get_member/actionlog' | |
postData = "api_verno=#{API_VERNO}&api_token=#{API_TOKEN}" | |
response = http.post(queryString, postData, $header) | |
if response.code == '200' | |
p JSON.load(response.body.sub(/.*?{/, '{')) | |
return true | |
else | |
p response | |
return false | |
end | |
end | |
#艦隊情報取得 | |
def getDeckPort (http) | |
queryString = '/kcsapi/api_get_member/deck_port' | |
postData = "api_verno=#{API_VERNO}&api_token=#{API_TOKEN}" | |
response = http.post(queryString, postData, $header) | |
if response.code == '200' | |
deckData = JSON.load(response.body.sub(/.*?{/, '{')) | |
deckData['api_data'].each do |deckDatum| | |
puts deckDatum['api_name'] | |
#遠征へ行っているかどうかの確認 | |
if deckDatum['api_mission'][3].zero? | |
puts '出撃可' | |
elsif deckDatum['api_mission'][3] < Time.now.to_i | |
puts '帰投中(getMissionResultで迎えてあげてください)' | |
else | |
puts "遠征中 (終了予定日時 #{Time.at(deckDatum['api_mission'][3])})" | |
end | |
end | |
return true | |
else | |
p response | |
return false | |
end | |
end | |
#遠征から帰投した艦隊の迎え入れ | |
def getMissionResult (http, deckId) | |
queryString = '/kcsapi/api_req_mission/result' | |
postData = "api_deck_id=#{deckId}&api_verno=#{API_VERNO}&api_token=#{API_TOKEN}" | |
response = http.post(queryString, postData, $header) | |
if response.code == '200' | |
missionResult = JSON.load(response.body.sub(/.*?{/, '{')) | |
#遠征の結果 | |
puts "第#{deckId}艦隊の遠征結果" | |
if !missionResult['api_clear_result'].zero? | |
puts '成功' | |
else | |
puts '失敗' | |
end | |
return true | |
else | |
p response | |
return false | |
end | |
end | |
#遠征へ出撃 | |
def startMission (http, deckId, missionId) | |
queryString = '/kcsapi/api_req_mission/start' | |
postData = "api_deck_id=#{deckId}&api_mission_id=#{missionId}&api_verno=#{API_VERNO}&api_token=#{API_TOKEN}" | |
response = http.post(queryString, postData, $header) | |
if response.code == '200' | |
missionData = JSON.load(response.body.sub(/.*?{/, '{')) | |
puts "第#{deckId}艦隊の遠征終了予定時刻" | |
puts missionData['api_data']['api_complatetime_str'] | |
return true | |
else | |
p response | |
return false | |
end | |
end | |
#Net::HTTP::Proxy(PROXY_ADDR, PROXY_PORT).start(KNKR_HOST, 80) do |http| | |
Net::HTTP.start(KNKR_HOST, 80) do |http| | |
#ログイン状態の確認 | |
queryString = '/kcsapi/api_auth_member/logincheck' | |
postData = "api_verno=#{API_VERNO}&api_token=#{API_TOKEN}" | |
response = http.post(queryString, postData, $header) | |
if response.code == '200' | |
p JSON.load(response.body.sub(/.*?{/, '{')) | |
functionName = ARGV[0] | |
arguments = ARGV | |
arguments.delete_at(0) | |
__send__(*([functionName, http] + arguments)) | |
else | |
# ログインできていない | |
p response | |
puts 'API_TOKENが無効です' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment