BCDice/TRPGツールからの呼び出し方/オンセンルーム
< BCDice | TRPGツールからの呼び出し方
ナビゲーションに移動
検索に移動
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
オンセンルームからのBCDiceの呼び出し方。v1.01.07のソースコードを参考にしている。
ツール本体はPHP製だが、Rubyで書かれた簡潔なラッパースクリプトをCGIで呼び出している。
rb/plug.rb L6-L13
初期設定。CGIで送られてきたフラグを変数に格納している。"0"
だとダイスロールを行い、"1"
だとダイスボットの説明文を取得する。
cgi=CGI.new
flag="0" #0=roll 1=descript
bclocation='../BCDice/src'
dicebot_name='DiceBot'
dicebot_command=''
if !cgi['flag'].nil? && !cgi['flag'].empty? then
flag=cgi['flag']
end
rb/plug.rb L54-L60
共通設定。
bcdiceMarker=OnsenBCDiceMaker.new
bcdice=bcdiceMarker.newBcDice()
bcdice.setCollectRandResult(true);
if File.exist?(bclocation+'/extratables') then
bcdice.setDir(bclocation+'/extratables',dicebot_name)
end
bcdice.setGameByTitle(dicebot_name)
rb/plug.rb L61-L71
ダイスロールを行う。
if flag !="1" then
bcdice.setMessage(dicebot_command)
gmsg=bcdice.getMessage
res_msg,secret_flag=bcdice.dice_command
res_rand=bcdice.getRandResults
json_array={
'secret_flag'=>secret_flag,
'gmsg'=>gmsg,
'res_rand'=>res_rand,
'res_msg'=>res_msg
}
rb/plug.rb L72-L77
ダイスボットの説明文を取得する。
else
ght=bcdice.gotHelpMessage
json_array={
'ght'=>ght
}
end
rb/plug.rb L40-L53
独自クラスの定義。必要な機能を呼び出しやすくしているようだ。
class OnsenBCDiceMaker<BCDiceMaker
def newBcDice
bcdice=OnsenBCDice.new(self,@cardTrader,@diceBot,@counterInfos,@tableFileData)
return bcdice
end
end
class OnsenBCDice<BCDice
def getMessage
return @message
end
def gotHelpMessage
return @diceBot.getHelpMessage
end
end
rb/plug.rb のソースコード
アーカイブを展開しないと見られないため、rb/plug.rb のソースコードを以下に掲載する。ただし、インデントのためのタブとスペースが混在していたため、スペースのみに直してある。
#!/bin/ruby -Ku
print("Content-Type: text/plain;charset=utf-8\n\n")
require 'json.rb'
require 'cgi.rb'
cgi=CGI.new
flag="0" #0=roll 1=descript
bclocation='../BCDice/src'
dicebot_name='DiceBot'
dicebot_command=''
if !cgi['flag'].nil? && !cgi['flag'].empty? then
flag=cgi['flag']
end
if !cgi['bclocation'].nil? && !cgi['bclocation'].empty? then
bclocation=cgi['bclocation']+'src'
end
if !File.exist?(bclocation) then
json_array={
'error'=>'bac_location_error'
}
puts json_array.to_json
exit
end
$LOAD_PATH<<bclocation
if !cgi['dicebot_name'].nil? && !cgi['dicebot_name'].empty? then
dicebot_name=cgi['dicebot_name']
end
if !cgi['dicebot_command'].nil? && !cgi['dicebot_command'].empty? then
dicebot_command=cgi['dicebot_command']
end
if flag !="1" && dicebot_command=='' then
json_array={
'error'=>'not_exist_command'
}
puts json_array.to_json
exit
end
require 'bcdiceCore.rb'
require 'configBcDice.rb'
class OnsenBCDiceMaker<BCDiceMaker
def newBcDice
bcdice=OnsenBCDice.new(self,@cardTrader,@diceBot,@counterInfos,@tableFileData)
return bcdice
end
end
class OnsenBCDice<BCDice
def getMessage
return @message
end
def gotHelpMessage
return @diceBot.getHelpMessage
end
end
bcdiceMarker=OnsenBCDiceMaker.new
bcdice=bcdiceMarker.newBcDice()
bcdice.setCollectRandResult(true);
if File.exist?(bclocation+'/extratables') then
bcdice.setDir(bclocation+'/extratables',dicebot_name)
end
bcdice.setGameByTitle(dicebot_name)
if flag !="1" then
bcdice.setMessage(dicebot_command)
gmsg=bcdice.getMessage
res_msg,secret_flag=bcdice.dice_command
res_rand=bcdice.getRandResults
json_array={
'secret_flag'=>secret_flag,
'gmsg'=>gmsg,
'res_rand'=>res_rand,
'res_msg'=>res_msg
}
else
ght=bcdice.gotHelpMessage
json_array={
'ght'=>ght
}
end
puts json_array.to_json