forked from torgtaitai/DodontoF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDodontoFServer.rb
6573 lines (4785 loc) · 168 KB
/
DodontoFServer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/local/bin/ruby -Ku
#--*-coding:utf-8-*--
$LOAD_PATH << File.dirname(__FILE__) + "/src_ruby"
$LOAD_PATH << File.dirname(__FILE__) + "/src_bcdice"
$LOAD_PATH << File.dirname(__FILE__) # require_relative対策
#CGI通信の主幹クラス用ファイル
#ファイルアップロード系以外は全てこのファイルへ通知が送られます。
#クライアント通知されたJsonデータからセーブデータ(.jsonテキスト)を読み出し・書き出しするのが主な作業。
#変更可能な設定は config.rb にまとめているため、環境設定のためにこのファイルを変更する必要は基本的には無いです。
#サーバCGIとクライアントFlashのバージョン一致確認用
$versionOnly = "Ver.1.44.01"
$versionDate = "2014/04/15"
$version = "#{$versionOnly}(#{$versionDate})"
if( RUBY_VERSION >= '1.9.0' )
Encoding.default_external = 'utf-8'
else
require 'jcode'
end
require 'kconv'
require 'cgi'
require 'stringio'
require 'logger'
require 'uri'
require 'fileutils'
require 'json/jsonParser'
if( $isFirstCgi )
require 'cgiPatch_forFirstCgi'
end
require "config.rb"
begin
require "config_local.rb"
rescue Exception
end
if( $loginCountFileFullPath.nil? )
$loginCountFileFullPath = File.join($SAVE_DATA_DIR, 'saveData', $loginCountFile)
end
require "loggingFunction.rb"
require "FileLock.rb"
require "saveDirInfo.rb"
$dodontofWarning = nil
if( $isMessagePackInstalled )
# gem install msgpack してる場合はこちら。
begin
require 'rubygems'
require 'msgpack'
rescue Exception
$dodontofWarning = {"key" => "youNeedInstallMsgPack"}
end
else
if( RUBY_VERSION >= '1.9.0' )
# msgpack のRuby1.9用
require 'msgpack/msgpack19'
else
# MessagePackPure バージョン
require 'msgpack/msgpackPure'
end
end
$saveFileNames = File.join($saveDataTempDir, 'saveFileNames.json');
$imageUrlText = File.join($imageUploadDir, 'imageUrl.txt');
$chatMessageDataLogAll = 'chatLongLines.txt'
$loginUserInfo = 'login.json'
$playRoomInfo = 'playRoomInfo.json'
$playRoomInfoTypeName = 'playRoomInfo'
$saveFiles = {
'chatMessageDataLog' => 'chat.json',
'map' => 'map.json',
'characters' => 'characters.json',
'time' => 'time.json',
'effects' => 'effects.json',
$playRoomInfoTypeName => $playRoomInfo,
};
$recordKey = 'record'
$record = 'record.json'
class DodontoFServer
def initialize(saveDirInfo, cgiParams)
@cgiParams = cgiParams
@saveDirInfo = saveDirInfo
roomIndexKey = "room"
initSaveFiles( getRequestData(roomIndexKey) )
@isAddMarker = false
@jsonpCallBack = nil
@isWebIf = false
@isJsonResult = true
@isRecordEmpty = false
@diceBotTablePrefix = 'diceBotTable_'
@fullBackupFileBaseName = "DodontoFFullBackup"
@allSaveDataFileExt = '.tar.gz'
@defaultAllSaveData = 'default.sav'
@defaultChatPallete = 'default.cpd'
@card = nil
end
def initSaveFiles(roomNumber)
@saveDirInfo.init(roomNumber, $saveDataMaxCount, $SAVE_DATA_DIR)
@saveFiles = {}
$saveFiles.each do |saveDataKeyName, saveFileName|
logging(saveDataKeyName, "saveDataKeyName")
logging(saveFileName, "saveFileName")
@saveFiles[saveDataKeyName] = @saveDirInfo.getTrueSaveFileName(saveFileName)
end
end
def getRequestData(key)
logging(key, "getRequestData key")
value = @cgiParams[key]
# logging(@cgiParams, "@cgiParams")
# logging(value, "getRequestData value")
if( value.nil? )
if( @isWebIf )
@cgi ||= CGI.new
value = @cgi.params[key].first
end
end
# logging(value, "getRequestData result")
return value
end
attr :isAddMarker
attr :jsonpCallBack
attr :isJsonResult
def getCardsInfo
require "card.rb"
return @card unless( @card.nil? )
@card = Card.new();
return @card
end
def getSaveFileLockReadOnly(saveFileName)
getSaveFileLock(saveFileName, true)
end
def getSaveFileLockReadOnlyRealFile(saveFileName)
getSaveFileLockRealFile(saveFileName, true)
end
def self.getLockFileName(saveFileName)
defaultLockFileName = (saveFileName + ".lock")
if( $SAVE_DATA_LOCK_FILE_DIR.nil? )
return defaultLockFileName;
end
if( saveFileName.index($SAVE_DATA_DIR) != 0 )
return defaultLockFileName
end
subDirName = saveFileName[$SAVE_DATA_DIR.size .. -1]
lockFileName = File.join($SAVE_DATA_LOCK_FILE_DIR, subDirName) + ".lock"
return lockFileName
end
#override
def getSaveFileLock(saveFileName, isReadOnly = false)
getSaveFileLockRealFile(saveFileName, isReadOnly)
end
def getSaveFileLockRealFile(saveFileName, isReadOnly = false)
begin
lockFileName = self.class.getLockFileName(saveFileName)
return FileLock.new(lockFileName);
#return FileLock2.new(saveFileName + ".lock", isReadOnly)
rescue => e
loggingForce(@saveDirInfo, "when getSaveFileLock error : @saveDirInfo");
raise e
end
end
#override
def isExist?(fileName)
File.exist?(fileName)
end
#override
def isExistDir?(dirName)
File.exist?(dirName)
end
#override
def readLines(fileName)
lines = File.readlines(fileName)
end
def loadSaveFileForLongChatLog(typeName, saveFileName)
saveFileName = @saveDirInfo.getTrueSaveFileName($chatMessageDataLogAll)
saveFileLock = getSaveFileLockReadOnly(saveFileName)
lines = []
saveFileLock.lock do
if( isExist?(saveFileName) )
lines = readLines(saveFileName)
end
@lastUpdateTimes[typeName] = getSaveFileTimeStampMillSecond(saveFileName);
end
if( lines.empty? )
return {}
end
chatMessageDataLog = lines.collect{|line| getJsonDataFromText(line.chomp) }
saveData = {"chatMessageDataLog" => chatMessageDataLog}
return saveData
end
def loadSaveFile(typeName, saveFileName)
logging("loadSaveFile begin")
saveData = nil
begin
if( isLongChatLog(typeName) )
saveData = loadSaveFileForLongChatLog(typeName, saveFileName)
elsif( $isUseRecord and isCharacterType(typeName) )
logging("isCharacterType")
saveData = loadSaveFileForCharacter(typeName, saveFileName)
else
saveData = loadSaveFileForDefault(typeName, saveFileName)
end
rescue => e
loggingException(e)
raise e
end
logging(saveData, saveFileName)
logging("loadSaveFile end")
return saveData
end
def isLongChatLog(typeName)
return ( $IS_SAVE_LONG_CHAT_LOG and isChatType(typeName) and @lastUpdateTimes[typeName] == 0 )
end
def isChatType(typeName)
(typeName == 'chatMessageDataLog')
end
def isCharacterType(typeName)
(typeName == "characters")
end
def loadSaveFileForCharacter(typeName, saveFileName)
logging(@lastUpdateTimes, "loadSaveFileForCharacter begin @lastUpdateTimes")
characterUpdateTime = getSaveFileTimeStampMillSecond(saveFileName);
#後の操作順序に依存せずRecord情報が取得できるよう、ここでRecordをキャッシュしておく。
#こうしないとRecordを取得する順序でセーブデータと整合性が崩れる場合があるため
getRecordCash
saveData = getRecordSaveDataFromCash()
logging(saveData, "getRecordSaveDataFromCash saveData")
if( saveData.nil? )
saveData = loadSaveFileForDefault(typeName, saveFileName)
else
@lastUpdateTimes[typeName] = characterUpdateTime
end
@lastUpdateTimes['recordIndex'] = getLastRecordIndexFromCash
logging(@lastUpdateTimes, "loadSaveFileForCharacter End @lastUpdateTimes")
logging(saveData, "loadSaveFileForCharacter End saveData")
return saveData
end
def getRecordSaveDataFromCash()
recordIndex = @lastUpdateTimes['recordIndex']
logging("getRecordSaveDataFromCash begin")
logging(recordIndex, "recordIndex")
logging(@record, "@record")
return nil if( recordIndex.nil? )
return nil if( recordIndex == 0 )
return nil if( @record.nil? )
return nil if( @record.empty? )
currentSender = getCommandSender
isFound = false
recordData = []
@record.each do |params|
index, command, list, sender = params
logging(index, "@record.each index")
if( index == recordIndex )
isFound = true
next
end
next unless( isFound )
if( isSendReocrd?(sender, currentSender, command) )
recordData << params
end
end
saveData = nil
if( isFound )
logging(recordData, "recordData")
saveData = {'record' => recordData}
end
return saveData
end
def isSendReocrd?(sender, currentSender, command)
#自分のコマンドでも…Record送信して欲しいときはあるよねっ!
return true if( @isGetOwnRecord )
#自分が送ったコマンドであっても結果を取得しないといけないコマンド名はここに列挙
#キャラクター追加なんかのコマンドは字自分のコマンドでも送信しないとダメなんだよね
recordCommandsByForce = ['addCharacter']
return true if( recordCommandsByForce.include?(command) )
#でも基本的には、自分が送ったコマンドは受け取りたくないんですよ
return false if( currentSender == sender )
return true
end
def getLastRecordIndexFromCash
recordIndex = 0
record = getRecordCash
last = record.last
unless( last.nil? )
recordIndex = last[0]
end
logging(recordIndex, "getLastRecordIndexFromCash recordIndex")
return recordIndex
end
def getRecordCash
unless( @record.nil? )
return @record
end
trueSaveFileName = @saveDirInfo.getTrueSaveFileName($record)
saveData = loadSaveFileForDefault($recordKey, trueSaveFileName)
@record = getRecordFromSaveData(saveData)
return @record
end
def loadSaveFileForDefault(typeName, saveFileName)
saveFileLock = getSaveFileLockReadOnly(saveFileName)
saveDataText = ""
saveFileLock.lock do
@lastUpdateTimes[typeName] = getSaveFileTimeStampMillSecond(saveFileName);
saveDataText = getSaveTextOnFileLocked(saveFileName)
end
saveData = getJsonDataFromText(saveDataText)
return saveData
end
def getSaveData(saveFileName)
isReadOnly = true
saveFileLock = getSaveFileLock(saveFileName, isReadOnly)
text = nil
saveFileLock.lock do
text = getSaveTextOnFileLocked(saveFileName)
end
saveData = getJsonDataFromText(text)
yield(saveData)
end
def changeSaveData(saveFileName)
isCharacterSaveData = ( @saveFiles['characters'] == saveFileName )
saveFileLock = getSaveFileLock(saveFileName)
saveFileLock.lock do
saveDataText = getSaveTextOnFileLocked(saveFileName)
saveData = getJsonDataFromText(saveDataText)
if( isCharacterSaveData )
saveCharacterHsitory(saveData) do
yield(saveData)
end
else
yield(saveData)
end
saveDataText = getTextFromJsonData(saveData)
createFile(saveFileName, saveDataText)
end
end
def saveCharacterHsitory(saveData)
logging("saveCharacterHsitory begin")
before = deepCopy( saveData['characters'] )
logging(before, "saveCharacterHsitory BEFORE")
yield
after = saveData['characters']
logging(after, "saveCharacterHsitory AFTER")
added = getNotExistCharacters(after, before)
removed = getNotExistCharacters(before, after)
changed = getChangedCharacters(before, after)
removedIds = removed.collect{|i| i['imgId']}
trueSaveFileName = @saveDirInfo.getTrueSaveFileName($record)
changeSaveData(trueSaveFileName) do |saveData|
if( @isRecordEmpty )
clearRecord(saveData)
else
writeRecord(saveData, 'removeCharacter', removedIds)
writeRecord(saveData, 'addCharacter', added)
writeRecord(saveData, 'changeCharacter', changed)
end
end
logging("saveCharacterHsitory end")
end
def deepCopy(obj)
Marshal.load( Marshal.dump(obj) )
end
def getNotExistCharacters(first, second)
result = []
first.each do |a|
same = second.find{|b| a['imgId'] == b['imgId']}
if( same.nil? )
result << a
end
end
return result
end
def getChangedCharacters(before, after)
result = []
after.each do |a|
logging(a, "getChangedCharacters find a")
b = before.find{|i| a['imgId'] == i['imgId']}
next if( b.nil? )
logging(b, "getChangedCharacters find b")
next if( a == b )
result << a
end
logging(result, "getChangedCharacters result")
return result
end
def writeRecord(saveData, key, list)
logging("writeRecord begin")
logging(list, "list")
if( list.nil? or list.empty? )
logging("list is empty.")
return;
end
record = getRecordFromSaveData(saveData)
logging(record, "before record")
while( record.length >= $recordMaxCount )
record.shift
break if( record.length == 0 )
end
recordIndex = 1
last = record.last
unless( last.nil? )
recordIndex = last[0].to_i + 1
end
sender = getCommandSender
record << [recordIndex, key, list, sender]
logging(record, "after record")
logging("writeRecord end")
end
def clearRecord(saveData)
logging("clearRecord Begin")
record = getRecordFromSaveData(saveData)
record.clear
logging("clearRecord End")
end
def getCommandSender
if( @commandSender.nil? )
@commandSender = getRequestData('own')
end
logging(@commandSender, "@commandSender")
return @commandSender
end
def setdNoBodyCommanSender
@commandSender = "-\t-"
end
def setRecordWriteEmpty
@isRecordEmpty = true
end
def getRecordFromSaveData(saveData)
saveData ||= {}
saveData['record'] ||= []
record = saveData['record']
return record
end
def createSaveFile(saveFileName, text)
logging(saveFileName, 'createSaveFile saveFileName')
existFiles = nil
logging($saveFileNames, "$saveFileNames")
changeSaveData($saveFileNames) do |saveData|
existFiles = saveData["fileNames"]
existFiles ||= []
logging(existFiles, 'pre existFiles')
unless( existFiles.include?(saveFileName) )
existFiles << saveFileName
end
createFile(saveFileName, text)
saveData["fileNames"] = existFiles
end
logging(existFiles, 'createSaveFile existFiles')
end
#override
def createFile(saveFileName, text)
begin
File.open(saveFileName, "w+") do |file|
file.write(text.toutf8)
end
rescue => e
loggingException(e)
raise e
end
end
def getTextFromJsonData(jsonData)
self.class.getTextFromJsonData(jsonData)
end
def self.getTextFromJsonData(jsonData)
return JsonBuilder.new.build(jsonData)
end
def getDataFromMessagePack(data)
self.class.getDataFromMessagePack(data)
end
def self.getDataFromMessagePack(data)
MessagePack.pack(data)
end
def getJsonDataFromText(text)
self.class.getJsonDataFromText(text)
end
def self.getJsonDataFromText(text)
jsonData = nil
begin
logging(text, "getJsonDataFromText start")
begin
jsonData = JsonParser.new.parse(text)
logging("getJsonDataFromText 1 end")
rescue => e
text = CGI.unescape(text)
jsonData = JsonParser.new.parse(text)
logging("getJsonDataFromText 2 end")
end
rescue => e
# loggingException(e)
jsonData = {}
end
return jsonData
end
def getMessagePackFromData(data)
self.class.getMessagePackFromData(data)
end
def self.getMessagePackFromData(data)
logging("getMessagePackFromData Begin")
messagePack = {}
if( data.nil? )
logging("data is nil")
return messagePack
end
begin
messagePack = MessagePack.unpack(data)
rescue Exception => e
loggingForce("getMessagePackFromData Exception rescue")
loggingException(e)
end
logging(messagePack, "messagePack")
if( isWebIfMessagePack(messagePack) )
logging(data, "data is webif.")
messagePack = parseWebIfMessageData(data)
end
logging(messagePack, "getMessagePackFromData End messagePack")
return messagePack
end
def self.isWebIfMessagePack(messagePack)
logging(messagePack, "isWebif messagePack")
unless( messagePack.kind_of?(Hash) )
logging("messagePack is NOT Hash")
return true
end
return false
end
def self.parseWebIfMessageData(data)
params = CGI.parse(data)
logging(params, "params")
messagePack = {}
params.each do |key, value|
messagePack[key] = value.first
end
return messagePack
end
#override
def getSaveTextOnFileLocked(fileName)
empty = "{}"
return empty unless( isExist?(fileName) )
text = ''
open(fileName, 'r') do |file|
text = file.read
end
return empty if( text.empty? )
return text
end
def analyzeCommand
commandName = getRequestData('cmd')
logging(commandName, "commandName")
if( commandName.nil? or commandName.empty? )
return getResponseTextWhenNoCommandName
end
hasReturn = "hasReturn";
hasNoReturn = "hasNoReturn";
commands = [
['refresh', hasReturn],
['getGraveyardCharacterData', hasReturn],
['resurrectCharacter', hasReturn],
['clearGraveyard', hasReturn],
['getLoginInfo', hasReturn],
['getPlayRoomStates', hasReturn],
['getPlayRoomStatesByCount', hasReturn],
['deleteImage', hasReturn],
['uploadImageUrl', hasReturn],
['save', hasReturn],
['saveMap', hasReturn],
['saveAllData', hasReturn],
['load', hasReturn],
['loadAllSaveData', hasReturn],
['getDiceBotInfos', hasReturn],
['getBotTableInfos', hasReturn],
['addBotTable', hasReturn],
['changeBotTable', hasReturn],
['removeBotTable', hasReturn],
['requestReplayDataList', hasReturn],
['uploadReplayData', hasReturn],
['removeReplayData', hasReturn],
['checkRoomStatus', hasReturn],
['loginPassword', hasReturn],
['uploadFile', hasReturn],
['uploadImageData', hasReturn],
['createPlayRoom', hasReturn],
['changePlayRoom', hasReturn],
['removePlayRoom', hasReturn],
['removeOldPlayRoom', hasReturn],
['getImageTagsAndImageList', hasReturn],
['addCharacter', hasReturn],
['getWaitingRoomInfo', hasReturn],
['exitWaitingRoomCharacter', hasReturn],
['enterWaitingRoomCharacter', hasReturn],
['sendDiceBotChatMessage', hasReturn],
['deleteChatLog', hasReturn],
['sendChatMessageAll', hasReturn],
['undoDrawOnMap', hasReturn],
['logout', hasNoReturn],
['changeCharacter', hasNoReturn],
['removeCharacter', hasNoReturn],
# Card Command Get
['getMountCardInfos', hasReturn],
['getTrushMountCardInfos', hasReturn],
['getCardList', hasReturn],
# Card Command Set
['drawTargetCard', hasReturn],
['drawTargetTrushCard', hasReturn],
['drawCard', hasReturn],
['addCard', hasNoReturn],
['addCardZone', hasNoReturn],
['initCards', hasReturn],
['returnCard', hasNoReturn],
['shuffleCards', hasNoReturn],
['shuffleForNextRandomDungeon', hasNoReturn],
['dumpTrushCards', hasNoReturn],
['clearCharacterByType', hasNoReturn],
['moveCharacter', hasNoReturn],
['changeMap', hasNoReturn],
['drawOnMap', hasNoReturn],
['clearDrawOnMap', hasNoReturn],
['sendChatMessage', hasNoReturn],
['changeRoundTime', hasNoReturn],
['addResource', hasNoReturn],
['changeResource', hasNoReturn],
['changeResourcesAll', hasNoReturn],
['removeResource', hasNoReturn],
['addEffect', hasNoReturn],
['changeEffect', hasNoReturn],
['changeEffectsAll', hasNoReturn],
['removeEffect', hasNoReturn],
['changeImageTags', hasNoReturn],
]
commands.each do |command, commandType|
next unless( command == commandName )
logging(commandType, "commandType")
case commandType
when hasReturn
return eval( command )
when hasNoReturn
eval( command )
return nil
end
end
throw Exception.new("\"" + commandName.untaint + "\" is invalid command")
end
def getResponseTextWhenNoCommandName
logging("getResponseTextWhenNoCommandName Begin")
response = analyzeWebInterface
if( response.nil? )
response = getTestResponseText
end
return response
end
def analyzeWebInterface
result = { 'result'=> 'NG' }
begin
result = analyzeWebInterfaceCatched
logging("analyzeWebInterfaceCatched end result", result)
setJsonpCallBack
rescue => e
result['result'] = e.to_s
end
return result
end
def analyzeWebInterfaceCatched
logging("analyzeWebInterfaceCatched begin")
@isWebIf = true
@isJsonResult = true
commandName = getRequestData('webif')
logging(commandName, 'commandName')
if( isInvalidRequestParam(commandName) )
return nil
end
marker = getRequestData('marker')
if( isInvalidRequestParam(marker) )
@isAddMarker = false
end
logging(commandName, "commandName")
case commandName
when 'getBusyInfo'
return getBusyInfo
when 'getServerInfo'
return getWebIfServerInfo
when 'getRoomList'
return getWebIfRoomList
when 'getLoginInfo'
return getWebIfLoginInfo
end
loginOnWebInterface
case commandName
when 'chat'
return getWebIfChatText
when 'talk'
return sendWebIfChatText
when 'addCharacter'
return sendWebIfAddCharacter
when 'changeCharacter'
return sendWebIfChangeCharacter
when 'addMemo'
return sendWebIfAddMemo
when 'getRoomInfo'
return getWebIfRoomInfo
when 'setRoomInfo'
return setWebIfRoomInfo
when 'getChatColor'
return getChatColor
when 'refresh'
return getWebIfRefresh
when 'getLoginUserInfo'
return getWebIfLoginUserInfo
end
return {'result'=> "command [#{commandName}] is NOT found"}
end
def getWebIfLoginInfo
uniqueId = getRequestData('uniqueId')
uniqueId ||= createUniqueId()
return {'uniqueId' => uniqueId}
end
def getWebIfLoginUserInfo
uniqueId = getWebIfRequestText('uniqueId')
userName = getWebIfRequestText('name', '')
isVisiter = getWebIfRequestBoolean('isVisiter', false)
getLoginUserInfo(userName, uniqueId, isVisiter)
end
def loginOnWebInterface
roomNumberText = getRequestData('room')
if( isInvalidRequestParam(roomNumberText) )
raise "プレイルーム番号(room)を指定してください"
end
unless( /^\d+$/ === roomNumberText )
raise "プレイルーム番号(room)には半角数字のみを指定してください"
end
roomNumber = roomNumberText.to_i
password = getRequestData('password')
visiterMode = true
checkResult = checkLoginPassword(roomNumber, password, visiterMode)
if( checkResult['resultText'] != "OK" )
result['result'] = result['resultText']
return result
end
initSaveFiles(roomNumber)
end
def isInvalidRequestParam(param)
return ( param.nil? or param.empty? )
end
def setJsonpCallBack
callBack = getRequestData('callback')
logging('callBack', callBack)
if( isInvalidRequestParam(callBack) )
return
end
@jsonpCallBack = callBack
end
def getTestResponseText
unless ( FileTest::directory?( $SAVE_DATA_DIR + '/saveData') )
return "Error : saveData ディレクトリ(#{$SAVE_DATA_DIR + '/saveData'}) が存在しません。"
end
if ( Dir::mkdir( $SAVE_DATA_DIR + '/saveData/data_checkTestResponse') )
Dir::rmdir($SAVE_DATA_DIR + '/saveData/data_checkTestResponse' )
end
unless ( FileTest::directory?( $imageUploadDir ) )
return "Error : 画像保存用ディレクトリ #{$imageUploadDir} が存在しません。"
end
if ( Dir::mkdir( $imageUploadDir + '/data_checkTestResponse' ) )
Dir::rmdir($imageUploadDir + '/data_checkTestResponse' )
end
return "「どどんとふ」の動作環境は正常に起動しています。"
end