2 // CommandParser
\83N
\83\89\83X
\r
4 function CommandParser()
\r
6 //
\83R
\83}
\83\93\83h
\83\8a\83X
\83g
\82ð
\95\
\82·
\r
7 //
\83R
\83}
\83\93\83h
\83\8a\83X
\83g
\82Ì
\8ae
\97v
\91f
\82É
\82Ífunction(msg,word){}
\82ð
\92Ç
\89Á
\82µ
\82È
\82¯
\82ê
\82Î
\82È
\82ç
\82È
\82¢
\r
8 //
\97á
\81j/test
\83R
\83}
\83\93\83h
\82ð
\92Ç
\89Á
\r
9 //this.CommandList["test"] = function(msg,word){}
\r
11 //
\82Ç
\82Ì
\83R
\83}
\83\93\83h
\82É
\82à
\8aY
\93\96\82µ
\82È
\82¢
\8e\9e\82É
\8cÄ
\82Ñ
\82³
\82ê
\82é
\8aÖ
\90\94\r
12 this.DefaultCommand = function(msg)
\r
17 this.parse = function(msg)
\r
19 var word = msg.message.split(" ");
\r
20 if(this.CommandList[word[0]])
\r
21 return this.CommandList[word[0]](msg,word);
\r
23 return this.DefaultCommand(msg);
\r
28 // CommandParserWhenGet
\83N
\83\89\83X
\r
30 // function(msg,word)
\r
32 // msg
\83I
\83u
\83W
\83F
\83N
\83g
\r
34 //
\83g
\81[
\83N
\83\93\83\8a\83X
\83g
\r
36 //
\83^
\83O
\82à
\82µ
\82
\82Í
\95¶
\8e\9a\97ñ
\82ð
\95Ô
\82·
\r
37 // null
\82ð
\95Ô
\82µ
\82½
\8fê
\8d\87\81A
\83\81\83b
\83Z
\81[
\83W
\83\8a\83X
\83g
\82É
\82Í
\89½
\82à
\95\
\8e¦
\82³
\82ê
\82È
\82
\82È
\82é
\r
38 function CommandParserWhenGet()
\r
40 this.DefaultCommand = function(msg)
\r
42 return parseBBCode(msg.message);
\r
44 this.CommandList = new Array;
\r
45 this.CommandList["/tell"] = function(msg,word)
\r
47 if((word[2] == "all")||
\r
48 (word[2] == document.enter_form.name.value)||
\r
49 (word[1] == document.enter_form.name.value)
\r
51 return $("<span/>").attr("id","whisper").append(parseBBCode(word[3]));
\r
56 this.CommandList["/enteredby"] = function(msg,word)
\r
59 var color = word[2];
\r
60 var mailto = word[3];
\r
61 var text = sprintf($entered_message,name);
\r
62 var date = new Date(Date.parse(msg.date));
\r
63 $names[name] = CreateNameInfo(date.getTime(),color,mailto);
\r
67 this.CommandList["/quitedby"] = function(msg,word)
\r
70 var text = sprintf($quited_message,name);
\r
71 delete $names[name];
\r
76 CommandParserWhenGet.prototype = new CommandParser;
\r
79 // CommandParserWhenPost
\83N
\83\89\83X
\r
82 // msg
\83I
\83u
\83W
\83F
\83N
\83g
\r
84 // word[0]
\81@
\83R
\83}
\83\93\83h
\96¼
\r
85 // word[1]
\81@
\92P
\8cê1
\r
87 // word[n]
\81@
\92P
\8cên
\r
89 //
\95¶
\8e\9a\97ñ
\82ð
\95Ô
\82·
\r
90 // null
\82ð
\95Ô
\82µ
\82½
\8fê
\8d\87\81A
\91\97\90M
\91\80\8dì
\82ª
\8ds
\82í
\82ê
\82È
\82
\82È
\82é
\r
91 function CommandParserWhenPost()
\r
93 this.CommandList = new Array;
\r
94 this.CommandList["/tell"] = function(msg,word)
\r
99 return word.join(" ");
\r
101 this.CommandList["/dice"] = function(msg,word)
\r
103 if(word.length == 1)
\r
104 text = CastDice("6d1");
\r
106 text = CastDice(word[1]);
\r
109 this.CommandList["/send"] = function(msg,word)
\r
111 if(word.length != 3)
\r
112 return msg.message;
\r
114 var message = sprintf($send_message,document.enter_form.name.value,word[2]);
\r
116 if(word[1] == document.chat_form.rno.value)
\r
117 $socket.json.emit("send msg",{name:$system_name,message:message});
\r
119 var socket = io.connect(location.hostname + "/" + word[1] + "?token="+ encodeURIComponent(document.chat_form.token.value));
\r
120 socket.on("error",getErrorMessage);
\r
121 socket.on("connect",function(){
\r
122 socket.json.emit("send msg",{name:$system_name,message:message});
\r
127 this.CommandList["/setpassword"] = function(msg,word)
\r
129 if(word.length != 2)
\r
130 return msg.message;
\r
132 $socket.json.emit("set password",{owner:document.enter_form.name.value,password:word[1]});
\r
137 CommandParserWhenPost.prototype = new CommandParser;
\r
139 $PostCommandParser = new CommandParserWhenPost();
\r
140 $GetCommandParser = new CommandParserWhenGet();
\r
142 function ParseDiceParam(number,option)
\r
144 if(typeof(number) != "undefined")
\r
146 var result = new Object();
\r
147 result.option = typeof(option) == "undefined" ? null : option;
\r
148 result.number = parseInt(number);
\r
154 function CastDice(text){
\r
155 var p = text.match(/(\d+)D(\d+)C*(\d+)?(\-|\+)?F*(\d+)?(\-|\+)?/i);
\r
156 var max = parseInt(p[1]);
\r
157 var dice_num = parseInt(p[2]);
\r
158 var critical = ParseDiceParam(p[3],p[4]);
\r
159 var fanble = ParseDiceParam(p[5],p[6]);
\r
161 var hasCritical = true;
\r
162 var hasFanble = true;
\r
163 var util = new Util();
\r
165 text = "[" + text + "] -> ";
\r
166 for(var i = 0; i < dice_num; i++)
\r
168 var t = util.get_random_number(1,max);
\r
172 if(hasCritical && critical != null)
\r
174 if(critical.option == "-" && t <= critical.number)
\r
175 hasCritical = true;
\r
176 else if(critical.option == "+" && t >= critical.number)
\r
177 hasCritical = true;
\r
178 else if(critical.option == null && t == critical.number)
\r
179 hasCritical = true;
\r
181 hasCritical = false;
\r
184 if(hasFanble && fanble != null)
\r
186 if(fanble.option == "-" && t <= fanble.number)
\r
188 else if(fanble.option == "+" && t >= fanble.number)
\r
190 else if(fanble.option == null && t == fanble.number)
\r
197 text = text.slice(0,text.length - 3); //
\8dÅ
\8cã
\82É
\95t
\82" + "
\82ð
\8eæ
\82è
\8f\9c\82
\r
198 text += " = " + total;
\r
200 if(critical == null)
\r
201 hasCritical = false;
\r
206 text = sprintf($critical_message,text);
\r
208 text = sprintf($fanble_message,text);
\r