diff --git a/jtserv/English b/jtserv/English new file mode 100644 index 0000000..43bf388 --- /dev/null +++ b/jtserv/English @@ -0,0 +1,80 @@ +one two three four five six seven eight nine ten. +Sunday Monday Tuesday Wednesday Thursday Friday Saturday. +January February March April May June July August September October +November December. +Twinkle, twinkle, little star, +How I wonder what you are! +Up above the world so high, +Like a diamond in the sky. +When the blazing sun is gone, +When he nothing shines upon, +Then you show your little light, +Twinkle, twinkle, all the night. +Then the traveller in the dark, +Thanks you for your tiny spark, +He could not see which way to go, +If you did not twinkle so. +In the dark blue sky you keep, +And often through my curtains peep, +For you never shut your eye, +Till the sun is in the sky. +As your bright and tiny spark, +Lights the traveller in the dark, -- +Though I know not what you are, +Twinkle, twinkle, little star. +London Bridge is falling down, +Falling down, falling down. +London Bridge is falling down, +My fair lady! +Build it up with iron bars, +Iron bars, iron bars. +Build it up with iron bars, +My fair lady! +Iron bars will bend and break, +Bend and break, bend and break. +Iron bars will bend and break, +My fair lady! +Build it up with needles and pins, +Needles and pins, needles and pins. +Build it up with needles and pins, +My fair lady! +Pins and needles rust and bend, +Rust and bend, rust and bend. +Pins and needles rust and bend, +My fair lady! +Build it up with penny loaves, +Penny loaves, penny loaves. +Build it up with penny loaves, +My fair lady! +Penny loaves will tumble down, +Tumble down, tumble down. +Penny loaves will tumble down, +My fair lady! +Build it up with silver and gold, +Silver and gold, silver and gold. +Build it up with silver and gold, +My fair lady! +Gold and silver I've not got, +I've not got, I've not got. +Gold and silver I've not got, +My fair lady! +Here's a prisoner I have got, +I have got, I have got. +Here's a prisoner I have got, +My fair lady! +What's the prisoner done to you, +Done to you, done to you? +What's the prisoner done to you, +My fair lady! +Stole my watch and broke my chain, +Broke my chain, broke my chain. +Stole my watch and broke my chain, +My fair lady! +What'll you take to set him free, +Set him free, set him free? +What'll you take to set him free, +My fair lady! +One hundred pounds will set him free, +Set him free, set him free. +One hundred pounds will set him free, +My fair lady! diff --git a/jtserv/Home_Position b/jtserv/Home_Position new file mode 100644 index 0000000..41a307b --- /dev/null +++ b/jtserv/Home_Position @@ -0,0 +1,72 @@ +fjfjfj fjfjfj jfjfjf jfjfjf dkdkdk dkdkdk kdkdkd kdkdkd slslsl lslsls. +a;a;a; ;a;a;a rururu ururur eieiei ieieie wowowo owowow qpqpqp pqpqpq. +vmvmvm mvmvmv c,c,c, ,c,c,c x.x.x. .x.x.x z/z/z/ /z/z/z. +ghghgh hghghg tytyty ytytyt bnbnbn nbnbnb ajajaj jajaja sksksk ksksks. +dldldl ldldld f;f;f; ;f;f;f aiaiai iaiaia auauau uauaua aoaoao oaoaoa. +qyqyqy yqyqyq wuwuwu uwuwuw ororor rororo ptptpt tptptp 101010 010101. +292929 929292 383838 838383 747474 474747 565656 656565. +-1 -1 -2 -2 wawa keke wake wake lala keke lake lake fafa keke fake fake. +fjfjfj fjfjfj jfjfjf jfjfjf dkdkdk dkdkdk kdkdkd kdkdkd slslsl lslsls. +a;a;a; ;a;a;a rururu ururur eieiei ieieie wowowo owowow qpqpqp pqpqpq. +vmvmvm mvmvmv c,c,c, ,c,c,c x.x.x. .x.x.x z/z/z/ /z/z/z. +ghghgh hghghg tytyty ytytyt bnbnbn nbnbnb ajajaj jajaja sksksk ksksks. +dldldl ldldld f;f;f; ;f;f;f aiaiai iaiaia auauau uauaua aoaoao oaoaoa. +qyqyqy yqyqyq wuwuwu uwuwuw ororor rororo ptptpt tptptp 101010 010101. +292929 929292 383838 838383 747474 474747 565656 656565. +-1 -1 -2 -2 wawa keke wake wake lala keke lake lake fafa keke fake fake. +fjfjfj fjfjfj jfjfjf jfjfjf dkdkdk dkdkdk kdkdkd kdkdkd slslsl lslsls. +a;a;a; ;a;a;a rururu ururur eieiei ieieie wowowo owowow qpqpqp pqpqpq. +vmvmvm mvmvmv c,c,c, ,c,c,c x.x.x. .x.x.x z/z/z/ /z/z/z. +ghghgh hghghg tytyty ytytyt bnbnbn nbnbnb ajajaj jajaja sksksk ksksks. +dldldl ldldld f;f;f; ;f;f;f aiaiai iaiaia auauau uauaua aoaoao oaoaoa. +qyqyqy yqyqyq wuwuwu uwuwuw ororor rororo ptptpt tptptp 101010 010101. +292929 929292 383838 838383 747474 474747 565656 656565. +-1 -1 -2 -2 wawa keke wake wake lala keke lake lake fafa keke fake fake. +fjfjfj fjfjfj jfjfjf jfjfjf dkdkdk dkdkdk kdkdkd kdkdkd slslsl lslsls. +a;a;a; ;a;a;a rururu ururur eieiei ieieie wowowo owowow qpqpqp pqpqpq. +vmvmvm mvmvmv c,c,c, ,c,c,c x.x.x. .x.x.x z/z/z/ /z/z/z. +ghghgh hghghg tytyty ytytyt bnbnbn nbnbnb ajajaj jajaja sksksk ksksks. +dldldl ldldld f;f;f; ;f;f;f aiaiai iaiaia auauau uauaua aoaoao oaoaoa. +qyqyqy yqyqyq wuwuwu uwuwuw ororor rororo ptptpt tptptp 101010 010101. +292929 929292 383838 838383 747474 474747 565656 656565. +-1 -1 -2 -2 wawa keke wake wake lala keke lake lake fafa keke fake fake. +fjfjfj fjfjfj jfjfjf jfjfjf dkdkdk dkdkdk kdkdkd kdkdkd slslsl lslsls. +a;a;a; ;a;a;a rururu ururur eieiei ieieie wowowo owowow qpqpqp pqpqpq. +vmvmvm mvmvmv c,c,c, ,c,c,c x.x.x. .x.x.x z/z/z/ /z/z/z. +ghghgh hghghg tytyty ytytyt bnbnbn nbnbnb ajajaj jajaja sksksk ksksks. +dldldl ldldld f;f;f; ;f;f;f aiaiai iaiaia auauau uauaua aoaoao oaoaoa. +qyqyqy yqyqyq wuwuwu uwuwuw ororor rororo ptptpt tptptp 101010 010101. +292929 929292 383838 838383 747474 474747 565656 656565. +-1 -1 -2 -2 wawa keke wake wake lala keke lake lake fafa keke fake fake. +fjfjfj fjfjfj jfjfjf jfjfjf dkdkdk dkdkdk kdkdkd kdkdkd slslsl lslsls. +a;a;a; ;a;a;a rururu ururur eieiei ieieie wowowo owowow qpqpqp pqpqpq. +vmvmvm mvmvmv c,c,c, ,c,c,c x.x.x. .x.x.x z/z/z/ /z/z/z. +ghghgh hghghg tytyty ytytyt bnbnbn nbnbnb ajajaj jajaja sksksk ksksks. +dldldl ldldld f;f;f; ;f;f;f aiaiai iaiaia auauau uauaua aoaoao oaoaoa. +qyqyqy yqyqyq wuwuwu uwuwuw ororor rororo ptptpt tptptp 101010 010101. +292929 929292 383838 838383 747474 474747 565656 656565. +-1 -1 -2 -2 wawa keke wake wake lala keke lake lake fafa keke fake fake. +fjfjfj fjfjfj jfjfjf jfjfjf dkdkdk dkdkdk kdkdkd kdkdkd slslsl lslsls. +a;a;a; ;a;a;a rururu ururur eieiei ieieie wowowo owowow qpqpqp pqpqpq. +vmvmvm mvmvmv c,c,c, ,c,c,c x.x.x. .x.x.x z/z/z/ /z/z/z. +ghghgh hghghg tytyty ytytyt bnbnbn nbnbnb ajajaj jajaja sksksk ksksks. +dldldl ldldld f;f;f; ;f;f;f aiaiai iaiaia auauau uauaua aoaoao oaoaoa. +qyqyqy yqyqyq wuwuwu uwuwuw ororor rororo ptptpt tptptp 101010 010101. +292929 929292 383838 838383 747474 474747 565656 656565. +-1 -1 -2 -2 wawa keke wake wake lala keke lake lake fafa keke fake fake. +fjfjfj fjfjfj jfjfjf jfjfjf dkdkdk dkdkdk kdkdkd kdkdkd slslsl lslsls. +a;a;a; ;a;a;a rururu ururur eieiei ieieie wowowo owowow qpqpqp pqpqpq. +vmvmvm mvmvmv c,c,c, ,c,c,c x.x.x. .x.x.x z/z/z/ /z/z/z. +ghghgh hghghg tytyty ytytyt bnbnbn nbnbnb ajajaj jajaja sksksk ksksks. +dldldl ldldld f;f;f; ;f;f;f aiaiai iaiaia auauau uauaua aoaoao oaoaoa. +qyqyqy yqyqyq wuwuwu uwuwuw ororor rororo ptptpt tptptp 101010 010101. +292929 929292 383838 838383 747474 474747 565656 656565. +-1 -1 -2 -2 wawa keke wake wake lala keke lake lake fafa keke fake fake. +fjfjfj fjfjfj jfjfjf jfjfjf dkdkdk dkdkdk kdkdkd kdkdkd slslsl lslsls. +a;a;a; ;a;a;a rururu ururur eieiei ieieie wowowo owowow qpqpqp pqpqpq. +vmvmvm mvmvmv c,c,c, ,c,c,c x.x.x. .x.x.x z/z/z/ /z/z/z. +ghghgh hghghg tytyty ytytyt bnbnbn nbnbnb ajajaj jajaja sksksk ksksks. +dldldl ldldld f;f;f; ;f;f;f aiaiai iaiaia auauau uauaua aoaoao oaoaoa. +qyqyqy yqyqyq wuwuwu uwuwuw ororor rororo ptptpt tptptp 101010 010101. +292929 929292 383838 838383 747474 474747 565656 656565. +-1 -1 -2 -2 wawa keke wake wake lala keke lake lake fafa keke fake fake. diff --git a/jtserv/Romaji b/jtserv/Romaji new file mode 100644 index 0000000..90e92d7 --- /dev/null +++ b/jtserv/Romaji @@ -0,0 +1,26 @@ +aiu aiu aiu eo eo eo aiu eo aiueo. +ka ka ka ki ki ki ku ku ku ke ke ke ko ko ko kakikukeko. +kya kya kya kyu kyu kyu kyo kyo kyo. +sa sa sa si si si shi shi shi su su su se se se so so so. +ja ja ja ju ju ju jo jo jo. +ta ta ta ti ti ti chi chi chi tu tu tu tsu tsu tsu te te te to to to. +cha cha cha chu chu chu cho cho cho. +na na na ni ni ni nu nu nu ne ne ne no no no. +nya nya nya nyu nyu nyu nyo nyo nyo. +ha ha ha hi hi hi fu fu fu he he he ho ho ho. +hya hya hya hyu hyu hyu hyo hyo hyo pya pya pya pyu pyu pyu pyo pyo. +bya bya bya byu byu byu byo byo byo. +ma ma ma ma mi mi mi mu mu mu me me me mo mo mo. +mya mya mya myu myu myu myo myo myo. +ya ya ya yu yu yu yo yo yo lya lya lya lya lyu lyu lyu lyo lyo lyo. +ra ra ra ri ri ri ru ru ru re re re ro ro ro rya rya rya ryu ryu ryu +ryo ryo ryo. +wa wa wa wo wo wo. n nn. +wa wa, ta ta, shi shi, no no, wa ta shi no, watashino, +na na, ma ma, e, na ma e ha, namaeha. +tou tou, ho ho, ku ku, kou kou, eki eki, bunka bunka. +touhoku touhoku touhoku, koueki koueki koueki, bunka bunka bunka. +ake ake ake, mashite mashite, akemashite, akemashite, akemashite. +na na na ni ni ni nu nu nu ne ne ne no no no. +nya nya nya nyu nyu nyu nyo nyo nyo. +motto motto, appi appi, zetttai zettai, yama kawa, yama kawa. diff --git a/jtserv/TEXT b/jtserv/TEXT new file mode 100644 index 0000000..aeb2ca2 --- /dev/null +++ b/jtserv/TEXT @@ -0,0 +1,4 @@ +Home_Position,ホームポジション +Romaji,ローマ字 +English,英語初級 +The_Constitution_Of_JAPAN,日本国憲法 diff --git a/jtserv/The_Constitution_Of_JAPAN b/jtserv/The_Constitution_Of_JAPAN new file mode 100644 index 0000000..c8ad6c2 --- /dev/null +++ b/jtserv/The_Constitution_Of_JAPAN @@ -0,0 +1,462 @@ + THE CONSTITUTION OF JAPAN(November 3, 1946). We, the Japanese +people, acting through our duly elected representatives in the +National Diet, determined that we shall secure for ourselves and our +posterity the fruits of peaceful cooperation with all nations and the +blessings of liberty throughout this land, and resolved that never +again shall we be visited with the horrors of war through the action +of government, do proclaim that sovereign power resides with the +people and do firmly establish this Constitution. Government is a +sacred trust of the people, the authority for which is derived from +the people, the powers of which are exercised by the representatives +of the people, and the benefits of which are enjoyed by the people. +This is a universal principle of mankind upon which this Constitution +is founded. We reject and revoke all constitutions, laws ordinances, +and rescripts in conflict herewith. We, the Japanese people, desire +peace for all time and are deeply conscious of the high ideals +controlling human relationship and we have determined to preserve our +security and existence, trusting in the justice and faith of the +peace-loving peoples of the world. We desire to occupy an honored +place in an international society striving for the preservation of +peace, and the banishment of tyranny and slavery, oppression and +intolerance for all time from the earth. We recognize that all peoples +of the world have the right to live in peace, free from fear and want. +We believe that no nation is responsible to itself alone, but that +laws of political morality are universal; and that obedience to such +laws is incumbent upon all nations who would sustain their own +sovereignty and justify their sovereign relationship with other +nations. We, the Japanese people, pledge our national honor to +accomplish these high ideals and purposes with all our resources. +CHAPTER I: THE EMPEROR. Article 1: The Emperor shall be the symbol of +the State and the unity of the people, deriving his position from the +will of the people with whom resides sovereign power. Article 2: The +Imperial Throne shall be dynastic and succeeded to in accordance with +the Imperial House Law passed by the Diet. Article 3: The advice and +approval of the Cabinet shall be required for all acts of the Emperor +in matters of state, and the Cabinet shall be responsible therefor. +Article 4: The Emperor shall perform only such acts in matters of +state as are provided for in this Constitution and he shall not have +powers related to government. 2) The Emperor may delegate the +performance of his acts in matters of state as may be provided for by +law. Article 5: When, in accordance with the Imperial House Law, a +Regency is established, the Regent shall perform his acts in matters +of state in the Emperor's name. In this case, paragraph one of the +preceding Article will be applicable. Article 6: The Emperor shall +appoint the Prime Minister as designated by the Diet. 2) The Emperor +shall appoint the Chief Judge of the Supreme Court as designated by +the Cabinet. Article 7: The Emperor shall, with the advice and +approval of the Cabinet, perform the following acts in matters of +state on behalf of the people: (1) Promulgation of amendments of the +constitution, laws, cabinet orders and treaties. (2) Convocation of +the Diet. (3) Dissolution of the House of Representatives. (4) +Proclamation of general election of members of the Diet. (5) +Attestation of the appointment and dismissal of Ministers of State and +other officials as provided for by law, and of full powers and +credentials of Ambassadors and Ministers. (6) Attestation of general +and special amnesty, commutation of punishment, reprieve, and +restoration of rights. (7) Awarding of honors. (8) Attestation of +instruments of ratification and other diplomatic documents as provided +for by law. (9) Receiving foreign ambassadors and ministers. (10) +Performance of ceremonial functions. Article 8: No property can be +given to, or received by, the Imperial House, nor can any gifts be +made therefrom, without the authorization of the Diet. CHAPTER II: +RENUNCIATION OF WAR. Article 9: Aspiring sincerely to an +international peace based on justice and order, the Japanese people +forever renounce war as a sovereign right of the nation and the threat +or use of force as means of settling international disputes. 2) In +order to accomplish the aim of the preceding paragraph, land, sea, and +air forces, as well as other war potential, will never be maintained. +The right of belligerency of the state will not be recognized. +CHAPTER III: RIGHTS AND DUTIES OF THE PEOPLE. Article 10: The +conditions necessary for being a Japanese national shall be determined +by law. Article 11: The people shall not be prevented from enjoying +any of the fundamental human rights. These fundamental human rights +guaranteed to the people by this Constitution shall be conferred upon +the people of this and future generations as eternal and inviolate +rights. Article 12: The freedoms and rights guaranteed to the people +by this Constitution shall be maintained by the constant endeavor of +the people, who shall refrain from any abuse of these freedoms and +rights and shall always be responsible for utilizing them for the +public welfare. Article 13: All of the people shall be respected as +individuals. Their right to life, liberty, and the pursuit of +happiness shall, to the extent that it does not interfere with the +public welfare, be the supreme consideration in legislation and in +other governmental affairs. Article 14: All of the people are equal +under the law and there shall be no discrimination in political, +economic or social relations because of race, creed, sex, social +status or family origin. 2) Peers and peerage shall not be recognized. +3) No privilege shall accompany any award of honor, decoration or any +distinction, nor shall any such award be valid beyond the lifetime of +the individual who now holds or hereafter may receive it. Article 15: +The people have the inalienable right to choose their public officials +and to dismiss them. 2) All public officials are servants of the whole +community and not of any group thereof. 3) Universal adult suffrage is +guaranteed with regard to the election of public officials. 4) In all +elections, secrecy of the ballot shall not be violated. A voter shall +not be answerable, publicly or privately, for the choice he has made. +Article 16: Every person shall have the right of peaceful petition for +the redress of damage, for the removal of public officials, for the +enactment, repeal or amendment of laws, ordinances or regulations and +for other matters; nor shall any person be in any way discriminated +against for sponsoring such a petition. Article 17: Every person may +sue for redress as provided by law from the State or a public entity, +in case he has suffered damage through illegal act of any public +official. Article 18: No person shall be held in bondage of any kind. +Involuntary servitude, except as punishment for crime, is prohibited. +Article 19: Freedom of thought and conscience shall not be violated. +Article 20: Freedom of religion is guaranteed to all. No religious +organization shall receive any privileges from the State, nor exercise +any political authority. 2) No person shall be compelled to take part +in any religious acts, celebration, rite or practice. 3) The State and +its organs shall refrain from religious education or any other +religious activity. Article 21: Freedom of assembly and association +as well as speech, press and all other forms of expression are +guaranteed. 2) No censorship shall be maintained, nor shall the +secrecy of any means of communication be violated. Article 22: Every +person shall have freedom to choose and change his residence and to +choose his occupation to the extent that it does not interfere with +the public welfare. 2) Freedom of all persons to move to a foreign +country and to divest themselves of their nationality shall be +inviolate. Article 23: Academic freedom is guaranteed. Article 24: +Marriage shall be based only on the mutual consent of both sexes and +it shall be maintained through mutual cooperation with the equal +rights of husband and wife as a basis. 2) With regard to choice of +spouse, property rights, inheritance, choice of domicile, divorce and +other matters pertaining to marriage and the family, laws shall be +enacted from the standpoint of individual dignity and the essential +equality of the sexes. Article 25: All people shall have the right to +maintain the minimum standards of wholesome and cultured living. 2) In +all spheres of life, the State shall use its endeavors for the +promotion and extension of social welfare and security, and of public +health. Article 26: All people shall have the right to receive an +equal education correspondent to their ability, as provided for by +law. 2) All people shall be obligated to have all boys and girls +under their protection receive ordinary education as provided for by +law. Such compulsory education shall be free. Article 27: All people +shall have the right and the obligation to work. 2) Standards for +wages, hours, rest and other working conditions shall be fixed by law. +3) Children shall not be exploited. Article 28: The right of workers +to organize and to bargain and act collectively is guaranteed. +Article 29: The right to own or to hold property is inviolable. 2) +Property rights shall be defined by law, in conformity with the public +welfare. 3) Private property may be taken for public use upon just +compensation therefor. Article 30: The people shall be liable to +taxation as provided for by law. Article 31: No person shall be +deprived of life or liberty, nor shall any other criminal penalty be +imposed, except according to procedure established by law. Article +32: No person shall be denied the right of access to the courts. +Article 33: No person shall be apprehended except upon warrant issued +by a competent judicial officer which specifies the offense with which +the person is charged, unless he is apprehended, the offense being +committed. Article 34: No person shall be arrested or detained +without being at once informed of the charges against him or without +the immediate privilege of counsel; nor shall he be detained without +adequate cause; and upon demand of any person such cause must be +immediately shown in open court in his presence and the presence of +his counsel. Article 35: The right of all persons to be secure in +their homes, papers and effects against entries, searches and seizures +shall not be impaired except upon warrant issued for adequate cause +and particularly describing the place to be searched and things to be +seized, or except as provided by Article 33. 2) Each search or seizure +shall be made upon separate warrant issued by a competent judicial +officer. Article 36: The infliction of torture by any public officer +and cruel punishments are absolutely forbidden. Article 37: In all +criminal cases the accused shall enjoy the right to a speedy and +public trial by an impartial tribunal. 2) He shall be permitted full +opportunity to examine all witnesses, and he shall have the right of +compulsory process for obtaining witnesses on his behalf at public +expense. 3) At all times the accused shall have the assistance of +competent counsel who shall, if the accused is unable to secure the +same by his own efforts, be assigned to his use by the State. Article +38: No person shall be compelled to testify against himself. 2) +Confession made under compulsion, torture or threat, or after +prolonged arrest or detention shall not be admitted in evidence. 3) No +person shall be convicted or punished in cases where the only proof +against him is his own confession. Article 39: No person shall be +held criminally liable for an act which was lawful at the time it was +committed, or of which he had been acquitted, nor shall he be placed +in double jeopardy. Article 40: Any person may, in case he is +acquitted after he has been arrested or detained, sue the State for +redress as provided for by law. CHAPTER IV: THE DIET. Article 41: +The Diet shall be the highest organ of the state power, and shall be +the sole law-making organ of the State. Article 42: The Diet shall +consist of two Houses, namely the House of Representatives and the +House of Councillors. Article 43: Both Houses shall consist of +elected members, representative of all the people. 2) The number of +the members of each House shall be fixed by law. Article 44: The +qualifications of members of both Houses and their electors shall be +fixed by law. However, there shall be no discrimination because of +race, creed, sex, social status, family origin, education, property or +income. Article 45: The term of office of members of the House of +Representatives shall be four years. However, the term shall be +terminated before the full term is up in case the House of +Representatives is dissolved. Article 46: The term of office of +members of the House of Councillors shall be six years, and election +for half the members shall take place every three years. Article 47: +Electoral districts, method of voting and other matters pertaining to +the method of election of members of both Houses shall be fixed by +law. Article 48: No person shall be permitted to be a member of both +Houses simultaneously. Article 49: Members of both Houses shall +receive appropriate annual payment from the national treasury in +accordance with law. Article 50: Except in cases as provided for by +law, members of both Houses shall be exempt from apprehension while +the Diet is in session, and any members apprehended before the opening +of the session shall be freed during the term of the session upon +demand of the House. Article 51: Members of both Houses shall not be +held liable outside the House for speeches, debates or votes cast +inside the House. Article 52: An ordinary session of the Diet shall +be convoked once per year. Article 53: The Cabinet may determine to +convoke extraordinary sessions of the Diet. When a quarter or more of +the total members of either House makes the demand, the Cabinet must +determine on such convocation. Article 54: When the House of +Representatives is dissolved, there must be a general election of +members of the House of Representatives within forty(40) days from the +date of dissolution, and the Diet must be convoked within thirty(30) +days from the date of the election. 2) When the House of +Representatives is dissolved, the House of Councillors is closed at +the same time. However, the Cabinet may, in time of national +emergency, convoke the House of Councillors in emergency session. 3) +Measures taken at such session as mentioned in the proviso of the +preceding paragraph shall be provisional and shall become null and +void unless agreed to by the House of Representatives within a period +of ten(10) days after the opening of the next session of the Diet. +Article 55: Each House shall judge disputes related to qualifications +of its members. However, in order to deny a seat to any member, it is +necessary to pass a resolution by a majority of two-thirds or more of +the members present. Article 56: Business cannot be transacted in +either House unless one-third or more of total membership is present. +2) All matters shall be decided, in each House, by a majority of those +present, except as elsewhere provided for in the Constitution, and in +case of a tie, the presiding officer shall decide the issue. Article +57: Deliberation in each House shall be public. However, a secret +meeting may be held where a majority of two-thirds or more of those +members present passes a resolution therefor. 2) Each House shall keep +a record of proceedings. This record shall be published and given +general circulation, excepting such parts of proceedings of secret +session as may be deemed to require secrecy. 3) Upon demand of +one-fifth or more of the members present, votes of the members on any +matter shall be recorded in the minutes. Article 58: Each House shall +select its own president and other officials. 2) Each House shall +establish its rules pertaining to meetings, proceedings and internal +discipline, and may punish members for disorderly conduct. However, in +order to expel a member, a majority of two-thirds or more of those +members present must pass a resolution thereon. Article 59: A bill +becomes a law on passage by both Houses, except as otherwise provided +for by the Constitution. 2) A bill, which is passed by the House of +Representatives, and upon which the House of Councillors makes a +decision different from that of the House of Representatives, becomes +a law when passed a second time by the House of Representatives by a +majority of two-thirds or more of the members present. 3) The +provision of the preceding paragraph does not preclude the House of +Representatives from calling for the meeting of a joint committee of +both Houses, provided for by law. 4) Failure by the House of +Councillors to take final action within sixty(60) days after receipt +of a bill passed by the House of Representatives, time in recess +excepted, may be determined by the House of Representatives to +constitute a rejection of the said bill by the House of Councillors. +Article 60: The budget must first be submitted to the House of +Representatives. 2) Upon consideration of the budget, when the House +of Councillors makes a decision different from that of the House of +Representatives, and when no agreement can be reached even through a +joint committee of both Houses, provided for by law, or in the case of +failure by the House of Councillors to take final action within +thirty(30) days, the period of recess excluded, after the receipt of +the budget passed by the House of Representatives, the decision of the +House of Representatives shall be the decision of the Diet. Article +61: The second paragraph of the preceding Article applies also the the +Diet approval required for the conclusion of treaties. Article 62: +Each House may conduct investigations in relation to government, and +may demand the presence and testimony of witnesses, and the production +of records. Article 63: The Prime Minister and other Ministers of +State may, at any time, appear in either House for the purpose of +speaking on bills, regardless of whether they are members of the House +or not. They must appear when their presence is required in order to +give answers or explanations. Article 64: The Diet shall set up an +impeachment court from among the members of both Houses for the +purposes of trying those judges against whom removal proceedings have +been instituted. 2) Matters relating to impeachment shall be provided +for by law. Article 65: Executive power shall be vested in the +Cabinet. Article 66: The Cabinet shall consist of the Prime Minister, +who shall be its head, and other Ministers of State, as provided for +by law. 2) The Prime Minister and other Ministers of State must be +civilians. 3) The Cabinet shall, in the exercise of executive power, +be collectively responsible to the Diet. Article 67: The Prime +Minister shall be designated from among the members of the Diet by a +resolution of the Diet. This designation shall precede all other +business. 2) If the House of Representatives and the House of +Councillors disagree and if no agreement can be reached even through a +joint committee of both Houses, provided for by law, or the House of +Councillors fails to make designation within ten(10) days, exclusive +of the period of recess, after the House of Representatives has made +designation, the decision of the House of Representatives shall be the +decision of the Diet. Article 68: The Prime Minister shall appoint +the Ministers of State. However, a majority of their number must be +chosen from among the members of the Diet. 2) The Prime Minister may +remove the Ministers of State as he chooses. Article 69: If the House +of Representatives passes a non-confidence resolution, or rejects a +confidence resolution, the Cabinet shall resign en masse, unless the +House of Representatives is dissolved within ten(10) days. Article +70: When there is a vacancy in the post of Prime Minister, or upon the +first convocation of the Diet after a general election of members of +the House of Representatives, the Cabinet shall resign en masse. +Article 71: In the cases mentioned in the two preceding Articles, the +Cabinet shall continue its functions until the time when a new Prime +Minister is appointed. Article 72: The Prime Minister, representing +the Cabinet, submits bills, reports on general national affairs and +foreign relations to the Diet and exercises control and supervision +over various administrative branches. Article 73: The Cabinet shall, +in addition to other general administrative functions, perform the +following functions: (1) Administer the law faithfully; conduct +affairs of state. (2) Manage foreign affairs. (3) Conclude treaties. +However, it shall obtain prior or, depending on circumstances +sudsequent approval of the Diet. (4) Administer the civil service, in +accordance with standards established by law. (5) Prepare the budget, +and present it to the Diet. (6) Enact cabinet orders in order to +execute the provisions of this Constitution and of the law. However, +it cannot include penal provisions in such cabinet orders unless +authorized by such law. (7) Decide on general amnesty, special +amnesty, commutation of punishment, reprieve, and restoration of +rights. Article 74: All laws and cabinet orders shall be signed by +the competent Minister of State and countersigned by the Prime +Minister. Article 75: The Ministers of State shall not, during their +tenure of office, be subject to legal action without the consent of +the Prime Minister. However, the right to take that action is not +impaired hereby. CHAPTER VI: JUDICIARY. Article 76: The whole +judicial power is vested in a Supreme Court and in such inferior +courts as are established by law. 2) No extraordinary tribunal shall +be established, nor shall any organ or agency of the Executive be +given final judicial power. 3) All judges shall be independent in the +exercise of their conscience and shall be bound only by this +Constitution and the laws. Article 77: The Supreme Court is vested +with the rule-making power under which it determines the rules of +procedure and of practice, and of matters relating to attorneys, the +internal discipline of the courts and the administration of judicial +affairs. 2) Public procurators shall be subject to the rule-making +power of the Supreme Court. 3) The Supreme Court may delegate the +power to make rules for inferior courts to such courts. Article 78: +Judges shall not be removed except by public impeachment unless +judicially declared mentally or physically incompetent to perform +official duties. No disciplinary action against judges shall be +administered by any executive organ or agency. Article 79: The +Supreme Court shall consist of a Chief Judge and such number of judges +as may be determined by law; all such judges excepting the Chief Judge +shall be appointed by the Cabinet. 2) The appointment of the judges of +the Supreme Court shall be reviewed by the people at the first general +election of members of the House of Representatives following their +appointment, and shall be reviewed again at the first general election +of members of the House of Representatives after a lapse of ten(10) +years, and in the same manner thereafter. Article 80: The judges of +the inferior courts shall be appointed by the Cabinet from a list of +persons nominated by the Supreme Court. All such judges shall hold +office for a term of ten(10) years with privilege of reappointment, +provided that they shall be retired upon the attainment of the age as +fixed by law. 2) The judges of the inferior courts shall receive, at +regular stated intervals, adequate compensation which shall not be +decreased during their terms of office. Article 81: The Supreme Court +is the court of last resort with power to determine the +constitutionality of any law, order, regulation or official act. +Article 82: Trials shall be conducted and judgement declared publicly. +2) Where a court unanimously determines publicity to be dangerous to +public order or morals, a trial may be conducted privately, but trials +of political offenses, offenses involving the press or cases wherein +the rights of people as guaranteed in Chapter III of this Constitution +are in question shall always be conducted publicly. CHAPTER VII: +FINANCE. Article 83: The power to administer national finances shall +be exercised as the Diet shall determine. Article 84: No new taxes +shall be imposed or existing ones modified except by law or under such +conditions as law may prescribe. Article 85: No money shall be +expended, nor shall the State obligate itself, except as authorized by +the Diet. Article 86: The Cabinet shall prepare and submit to the +Diet for its consideration and decision a budget for each fiscal year. +Article 87: In order to provide for unforeseen deficiencies in the +budget, a reserve fund may be authorized by the Diet to be expended +upon the responsibility of the Cabinet. 2) The Cabinet must get +subsequent approval of the Diet for all payments from the reserve +fund. Article 88: All property of the Imperial Household shall belong +to the State. All expenses of the Imperial Household shall be +appropriated by the Diet in the budget. Article 89: No public money +or other property shall be expended or appropriated for the use, +benefit or maintenance of any religious institution or association, or +for any charitable, educational or benevolent enterprises not under +the control of public authority. Article 90: Final accounts of the +expenditures and revenues of the State shall be audited annually by a +Board of Audit and submitted by the Cabinet to the Diet, together with +the statement of audit, during the fiscal year immediately following +the period covered. 2) The organization and competency of the Board of +Audit shall be determined by law. Article 91: At regular intervals +and at least annually the Cabinet shall report to the Diet and the +people on the state of national finances. CHAPTER VIII: LOCAL +SELF-GOVERNMENT. Article 92: Regulations concerning organization and +operations of local public entities shall be fixed by law in +accordance with the principle of local autonomy. Article 93: The +local public entities shall establish assemblies as their deliberative +organs, in accordance with law. 2) The chief executive officers of all +local public entities, the members of their assemblies, and such other +local officials as may be determined by law shall be elected by direct +popular vote within their several communities. Article 94: Local +public entities shall have the right to manage their property, affairs +and administration and to enact their own regulations within law. +Article 95: A special law, applicable only to one local public entity, +cannot be enacted by the Diet without the consent of the majority of +the voters of the local public entity concerned, obtained in +accordance with law. CHAPTER IX: AMENDMENTS. Article 96: Amendments +to this Constitution shall be initiated by the Diet, through a +concurring vote of two-thirds or more of all the members of each House +and shall thereupon be submitted to the people for ratification, which +shall require the affirmative vote of a majority of all votes cast +thereon, at a special referendum or at such election as the Diet shall +specify. 2) Amendments when so ratified shall immediately be +promulgated by the Emperor in the name of the people, as an integral +part of this Constitution. CHAPTER X: SUPREME LAW. Article 97: The +fundamental human rights by this Constitution guaranteed to the people +of Japan are fruits of the age-old struggle of man to be free; they +have survived the many exacting tests for durability and are conferred +upon this and future generations in trust, to be held for all time +inviolate. Article 98: This Constitution shall be the supreme law of +the nation and no law, ordinance, imperial rescript or other act of +government, or part thereof, contrary to the provisions hereof, shall +have legal force or validity. 2) The treaties concluded by Japan and +established laws of nations shall be faithfully observed. Article 99: +The Emperor or the Regent as well as Ministers of State, members of +the Diet, judges, and all other public officials have the obligation +to respect and uphold this Constitution. CHAPTER XI: SUPPLEMENTARY +PROVISIONS. Article 100: This Constitution shall be enforced as from +the day when the period of six months will have elapsed counting from +the day of its promulgation. 2) The enactment of laws necessary for +the enforcement of this Constitution, the election of members of the +House of Councillors and the procedure for the convocation of the Diet +and other preparatory procedures necessary for the enforcement of this +Constitution may be executed before the day prescribed in the +preceding paragraph. Article 101: If the House of Councillors is not +constituted before the effective date of this Constitution, the House +of Representatives shall function as the Diet until such time as the +House of Councillors shall be constituted. Article 102: The term of +office for half the members of the House of Councillors serving in the +first term under this Constitution shall be three years. Members +falling under this category shall be determined in accordance with +law. Article 103: The Ministers of State, members of the House of +Representatives, and judges in office on the effective date of this +Constitution, and all other public officials who occupy positions +corresponding to such positions as are recognized by this Constitution +shall not forfeit their positions automatically on account of the +enforcement of this Constitution unless otherwise specified by law. +When, however, successors are elected or appointed under the +provisions of this Constitution, they shall forfeit their positions as +a matter of course. THE CONSTITUTION OF JAPAN(November 3, 1946). I +rejoice that the foundation for the construction of a new Japan has +been laid according to the will of the Japanese people, and hereby +sanction and promulgate the amendments of the Imperial Japanese +Constitution effected following the consultation with the Privy +Council and the decision of the Imperial Diet made in accordance with +Article 73 of the said Constitution. Signed: HIROHITO, Seal of the +Emperor, This third day of the eleventh month of the twenty-first year +of Showa(November 3, 1946). Countersigned: Prime Minister and +concurrently Minister for Foreign Affairs -- YOSHIDA Shigeru, Minister +of State -- Baron SHIDEHARA Kijuro, Minister of Justice -- KIMURA +Tokutaro, Minister for Home Affairs -- OMURA Seiichi, Minister of +Education -- TANAKA Kotaro, Minister of Agriculture and Forestry -- +WADA Hiroo, Minister of State -- SAITO Takao, Minister of +Communication -- HITOTSUMATSU Sadayoshi, Minister of Commerce and +Industry -- HOSHIJIMA Jiro, Minister of Welfare -- KAWAI Yoshinari, +Minister of State -- UEHARA Etsujiro, Minister of Transportation -- +HIRATSUKA Tsunejiro, Minister of Finance -- ISHIBASHI Tanzan, Minister +of State -- KANAMORI Tokujiro, Minister of State -- ZEN Keinosuke. diff --git a/jtserv/jtserv.rb b/jtserv/jtserv.rb new file mode 100755 index 0000000..529cf16 --- /dev/null +++ b/jtserv/jtserv.rb @@ -0,0 +1,501 @@ +#!/usr/bin/env ruby +# coding: utf-8 +require 'em-websocket' +require 'json' +require 'csv' +require 'sqlite3' + +PORT = 8814 + +# Interchange of Information is done in JSON form. +# (IN) {"cmd": Command, OtherArgs...} +# (OUT) +# +# Command is one of: +# team +# text + + +class UserDB + def initialize() + @db = SQLite3::Database.new("users.sq3") + ### @db.results_as_hash = true + @expireskey = '+3 days' + @expiretmpkey = '+1 hour' + @from = 'postmaster@koeki-prj.org' + @rank = %w(必須 標準 目標 一流 超一流 頂点) + dbinit + end + def dbinit() + # "at" field is like: YYYY-MM-DDThh:mm:ss at finish time + @db.execute_batch(<<~EOF) + -- DROP TABLE score; + CREATE TABLE IF NOT EXISTS score( + user, at, text, + step INTEGER, score INTEGER, types INTEGER, + miss INTEGER, time INTEGER, + UNIQUE(user, at), + FOREIGN KEY(user) REFERENCES users(user) + ON DELETE CASCADE ON UPDATE CASCADE + ); + EOF + end + def email(user) + r = @db.execute("SELECT email FROM users WHERE user = ?", user) + if r[0] && /.+@.+/ =~ r[0][0] then + r[0][0] + else + nil + end + end + def sendmail(rcpt, subj, body) + require 'nkf' + rcpt = rcpt.join(" ") if rcpt.is_a?(Array) + sj = NKF.nkf('-jM', subj) + body = NKF.nkf('-j', body) + + open("| sendmail -f#{@from} #{rcpt}", "w") do |m| + m.puts(<<~EOF) + Subject: #{sj} + From: jsTrr Admin <#{@from}> + Mime-Version: 1.0 + Content-type: text/plain; charset=iso-2022-jp + + EOF + m.puts(body) + end + end + def genToken(user, email) + d1 = ("a".."z").to_a.sample + d2 = ("a".."z").to_a.sample + token = d1 + d2 + sprintf("%02d", rand(100)) + sendmail(email, 'jsTrr: passcode', + "Your(%s) passcode = %s\n" % [user, token]) + token + end + def expire + @db.execute("DELETE FROM skey WHERE expire < datetime('now','localtime')") + end + def genKey(n=50) + rand(10**n).to_s(36) + end + def genSkey(user) + # First, erase expired session keys + expire + sKey = genKey + @db.execute("INSERT INTO skey VALUES(?, ?, + datetime('now', 'localtime', '#{@expireskey}'));", user, sKey) + sKey + end + def storeTmpKey(user, token) + # First, erase expired session keys + @db.execute("DELETE FROM tmpkey + WHERE expire < datetime('now','localtime')") + tmpkey = genKey + @db.execute("INSERT INTO tmpkey + VALUES(?, ?, ?, datetime('now', 'localtime', '#{@expiretmpkey}'));", + user, tmpkey, token) + tmpkey + end + def authTmpKey(user, tmpkey, token) + r = @db.execute("SELECT user FROM tmpkey + WHERE user=? AND tmpkey=? AND token=?", user, tmpkey, token) + p token + p r[0] + if r && r[0] && r[0].length==1 + # Auth OK! + genSkey(user) + end + end + def updateSkey(user, skey) + @db.execute("REPLACE INTO skey VALUES(?, ?, + datetime('now', 'localtime', '#{@expireskey}'));", user, skey) + skey + end + def authKey(user, skey) + r = @db.execute("SELECT user FROM skey + WHERE user=? AND skey=?", user, skey) + if r && r[0] && r[0].length==1 + # Auth OK! + updateSkey(user, skey) + end + end + def userScoreInfo(user) + rval = Hash.new + @db.execute("SELECT text, max(score), max(step), count(user) FROM score + WHERE user=? GROUP BY user, text;", user) do |row| + rval[row[0]] = {"highscore" => row[1].to_i, "step" => row[2].to_i, + "trial" => row[3].to_i} + end + if r=@db.execute("SELECT gecos FROM users WHERE user=?", user) + rval["gecos"] = r[0][0] + end + steptrial = Hash.new{|k, v| k[v]=Hash.new} + @db.execute("SELECT text, step, count(step) FROM score + WHERE user=? GROUP BY user, text, step;", user) do |row| + txt, step, trial = row + steptrial[txt][step] = trial + end + rval["steptrial"] = steptrial + p rval + rval + end + ################### Trr STEP Calculation ################### + def msgBeginner(s) + if s <= 0 + "0点というのは問題だわ。これからかなりの努力が必要よ。道のりは長いけど頑張りましょう。" + elsif s <40 + "少なくとも英文字ぐらいは絶対覚えること。業界必須の100点に向けてこれから頑張りましょう。" + elsif s < 80 + "キー配置も大分覚えたようだけどまだまだだわ。業界必須の100点に向けてこれから頑張りましょう。" + elsif s < 130 + "基礎的な技術は身に付けているようだけどまだまだだわ。業界標準の200点に向けてこれから頑張りましょう。" + elsif s < 180 + "なかなかの実力ね。でもスピードと正確さが少し足りないわ。業界標準の200点に向けてもう少し頑張りましょう。" + elsif s < 280 + "なかなかやるわね。もう少し頑張れば業界目標の300点をきっと突破できるわ。" + elsif s < 380 + "すごいわね。初めてでこれぐらい出せれば十分だわ。でも業界一流の400点に向けてもう少し頑張りましょう。" + elsif s < 480 + "すっごい!こんな点を出す人は滅多にいないわよ。ひょっとしてプロではないかしら?" + else + "あまりにも超人的だわ。きっとギネスブックに載るわよ。" + end + end + def msgForRecordBreaker(s) + rank = (s/100).to_i + sxx = s%100 +STDERR.printf("s=%d, rank=%d, sxx=%d\n", s, rank, sxx) + if s < 600 + sprintf("業界%sの%d点%s。", + @rank[rank], rank*100+100, + sxx < 67 ? "目指して頑張って" : "までもうすぐよ") + else + "よくここまでやるわね。あなたの目標は一体何なの?" + end + end + def msgSpecialForRecordBreaker(s) + rank = (s/100).to_i + sprintf("ついに業界%sの%d点突破ね!これからは業界%sの%d点を目指して頑張りましょう。", + @rank[rank], rank*100+100, + @rank[rank+1], rank*100+200) + end + def msgSuccess(user, step, highscore, score) + diff = [highscore - score, 0].max + trial = 0 + if r=@db.execute("SELECT count(score) FROM score + WHERE user=? AND step=? GROUP BY user, step", + user, step) + trial = r[0][0].to_i + end + STDERR.printf("Trial=%d\n", trial) + if (score-step*10) > 100 + "あなたには簡単すぎたようね。" + else + m = %w(軽く突破したわね。 わりと簡単に突破したわね。 + ちょっと手こずったようね。 だいぶ手こずったようね。 + よく頑張ったわね。 随分苦労したようね。 苦しみ抜いたわね。) + m[[Math.log2(trial)-1, m.length-1].min] + end + end + def msgFail(diff, highscore, score, missratio) + if diff<10 + "あとほんの少しだったのに...本当に惜しかったわね。" + elsif diff<20 + "惜しかったわね。" + elsif diff<30 + "その調子よ。" + elsif diff<40 + "もう一息だわ。でも息抜きはだめよ。。" + elsif diff<50 + "頑張ればきっとできるわ。" + elsif diff < 60 + "努力あるのみよ。" + elsif diff < 100 || missratio > 30 + if missratio > 60 + "練習に練習を重ねなさい。" + elsif missratio > 40 + "ミスが多過ぎるわ。初心に帰って一つ一つ慎重に打つ練習をしなさい。" + elsif missratio > 24 + "ミスが多いわ。正確に打つ練習をしなさい。" + elsif missratio > 8 + "練習に練習を重ねなさい。" + else + "正確に打ってるようだけどスピードが遅すぎるわ。速く打つ練習に励みなさい。" + end + elsif diff < 110 + "「trrの道は一日にしてならず」" + elsif diff < 120 + "「trrに王道なし」" + elsif diff < 130 + "あらまぁ。%d点を出した人がたったの%d点なんていったいどうしたのよ。" \ + % [highscore, score] + elsif diff < 140 + "%d点はまぐれだったの?" % [highscore] + else + "あなたの実力ってこの程度だったのね。" + end + end + def evalStep(user, h) # h == Hash from client + # Return the Hash whose keys are "step", "message", "time" + highscore = step = 0 + update = nil # Break Hiscore + pass = nil # Go to next step + beginner = nil # Beginner flag + time = h["finish"] - h["start"] + types = h["types"].to_i + miss = h["miss"].to_i + text = h["text"] + speed = (60*types/time).to_i + score = [(60*(types-miss)/time).to_i, 0].max + missratio = 1000*h["miss"].to_i/h["types"].to_i # 1/1000!!! + r = @db.execute("SELECT max(score) ms,max(step) mst + FROM score WHERE user=? AND text=? + GROUP BY user, text", user, text) + if r && r[0] && r[0][0] + highscore, step = r[0] + if score >= step*10 # Qualify current step + step += 1; pass = true + end + update = (score > highscore) + else + step = score/10; beginner = true + end + if time <= 1 + return {"step" => h["step"], + "message" => "ごめんなさい。時間計るの忘れてたわ。"} + end + # p score + # user, at, text, step, score, types, miss, time + @db.execute(<<~EOF, user, text, step, score, types, miss, time) + REPLACE INTO score VALUES( + ?, datetime('now', 'localtime'), ?, ?, ?, ?, ?, ?); + EOF + diff = step*10 - score + recbreaker = (score > highscore && highscore/100 != score/100) + msg = if score > 750 + "そんなことでいいの? 恥を知りなさい。" + elsif beginner + msgBeginner(score) + elsif pass # STEP clear! + sprintf("ステップ%d突破%sおめでとう!\n%s", + step, + update ? "そして記録更新" : "", + recbreaker ? + msgSpecialForRecordBreaker(highscore) + : msgForRecordBreaker(highscore) + ) + + elsif update + "記録更新おめでとう!\n"+msgSuccess(user, step, highscore, score) + else + msgFail(diff, highscore, score, missratio) + end + rv = {"score" => score, "step" => step, "time" => time.round(1), + "speed" => speed, "message" => msg, "types"=>types, + "highscore" => [highscore, score].max} + if false + # Peek trial count of this level + r = @db.execute("SELECT count(*) FROM score + WHERE user=? AND text=? AND step=? + GROUP BY user, text, step;", user, text, step) + rv["strial"] = r[0][0].to_i + r = @db.execute("SELECT count(*) FROM score + WHERE user=? AND text=? GROUP by user, text", user, text) + rv["trial"] = r[0][0].to_i + else + rv["scoreinfo"] = userScoreInfo(user) + end + return rv + end + def ranking(text) + @db.execute(<<~EOF, text) + SELECT user, max(score), max(step), count(score), + cast(round(sum(time)/60) as INT), max(at) + FROM score WHERE text=? GROUP BY user; + EOF + end +end +class Text + def initialize() + @textlist = {} + IO.readlines("TEXT").each do |tx| + file, title = tx.split(",") + @textlist[file] = {"title" => title, "text" => IO.readlines(file)} + end + end + def getFilledText(file, lines, fill) + text = @textlist[file]["text"] + array = [] + return nil unless text + buffer = 5; n=text.length-lines-buffer + text = text[rand(n), lines+buffer] + if /^[0-9A-Z]/ !~ text[0] + text[0].sub!(/.*?\. */, "") + end + subtxt = text.join(" ") + thisline = "" + subtxt.gsub(/\s+/, " ").split(" ").each do |w| + if thisline.length + w.length < fill + w += " " if /\.$/ =~ w + thisline += (w + " ") + else + array << thisline.strip + thisline = "" + break if array.length >= lines + end + end + array.join("\n")+"\n" + end + def textfiles + @textlist.collect{|file,v| {"file" => file, "title" => v["title"]}} + end +end + +db = UserDB.new +textDB = Text.new +connections = {} +team = Hash.new{|h,k| h[k]=Hash.new} +broadcast = lambda{|hash| + printf("sending %s\n", hash) + connections.keys.each do |c| + c.send(JSON.generate(hash)) + end +} +EM::WebSocket.start({:host => "0.0.0.0", :port => PORT}) do |ws_conn| + Thread.new { + while cmd = gets + case cmd.chop + when 's' + broadcast.call({start: Time.now.to_f}) + end + end + } + ws_conn.onopen do + connections[ws_conn] = {} + ws_conn.send(JSON.generate({myid: connections.length})) + STDERR.printf("OP: %d clients\n", connections.length) + end + ws_conn.onclose do + connections.delete(ws_conn) + STDERR.printf("CL: %d clients\n", connections.length) + end + ws_conn.onmessage do |msg| + begin + json = JSON.parse(msg) + rescue + return + end + userinfo = connections[ws_conn] + user, skey = userinfo['user'], userinfo['skey'] + STDERR.printf("RECV%s: [%s]\n", user ? "("+user+")" : "", msg) + if skey then + if json["team"] then + #team[json["team"]][json["name"]] ||= nil + userinfo = {"team" => json["team"], "name" => json["name"]} + elsif json["settext"] + # {"松" => {"name1"=>1, "name2" => 2}} + tm = userinfo["team"] + nm = userinfo["name"] + team[tm][nm] = json["text"] + connections.each do |k, v| + p v["team"] + next unless tm == v["team"] # Skip other team + next if ws_conn==k # Skip myself + k.send(JSON.generate({"disable" => json["text"]})) + end + userinfo["text"] = json["text"].to_i + si = {"scoreinfo" => db.userScoreInfo(userinfo["user"])} + ws_conn.send(JSON.generate(si)) + elsif json["finish"] + user = userinfo["user"] + if user && user > "" + if false + ## start = # json["start"].to_i + start = userinfo["start"] + ## finish = json["finish"].to_i + finish = Time.now.to_f + types = json["types"].to_i + STDERR.printf("types=%d", types) + miss = json["miss"].to_i + text = json["text"] + time = finish-start + score = 60*(types - 10*miss)/time + end + json["start"] = userinfo["start"] + json["finish"] = Time.now.to_f +STDERR.printf("Start=%.2f, Finish=%.2f\n", json["start"], json["finish"]) + eval = db.evalStep(user, json) + ws_conn.send(JSON.generate(eval)) + userinfo.delete("typelist") + end + elsif json["types"] + unless userinfo["typelist"] + p "START!" + userinfo["start"] = Time.now.to_f + userinfo["typelist"] = Hash.new + end + userinfo["typelist"][json["types"]] = Time.now.to_f + elsif json["ranking"] + text = json["ranking"] + p rank=db.ranking(text) + ws_conn.send(JSON.generate({"ranking": db.ranking(text)})) + elsif json["gettext"] + db.updateSkey(user, skey) + r = textDB.getFilledText(json["gettext"], json["lines"], json["fill"]) + ws_conn.send(JSON.generate({"yourtext" => r})) + end + else ########## Before authenticated + if json["Login"] + user = json["Login"] + email = db.email(user) + token = db.genToken(user, email) + tmpkey = db.storeTmpKey(user, token) + j = JSON.generate({"email" => email, "tmpkey" => tmpkey, "user" => user}) + p token + ws_conn.send(j) + elsif json["skey"] + user, skey = json["user"], json["skey"] + skey = db.authKey(user, json["skey"]) + STDERR.printf("SKey=%s", skey) + userinfo["skey"] = skey # Cache skey + STDERR.printf("CACHE skey for user %s\n", user) + userinfo["user"] = user # Cache User + if skey + si = db.userScoreInfo(user) + STDERR.printf("scoreinfo = %s\n", si) + r = {"user"=>user, "skey"=>skey, "scoreinfo"=>si} + r["textfiles"] = textDB.textfiles + j = JSON.generate(r) +p textDB.textfiles + ws_conn.send(j) # Login success by skey + else + ws_conn.send(JSON.generate({"fail" => "nokey"})) + end + elsif json["Passcode"] + token = json["Passcode"] + tmpkey = json["tmpkey"] + user = json["user"] + authkey = db.authTmpKey(user, tmpkey, token) + STDERR.printf("authkey=%s", authkey) + if authkey + userinfo["skey"] = authkey # Cache skey + STDERR.printf("Cache skey for user %s\n", user) + userinfo["user"] = user # Cache User + si = db.userScoreInfo(user) + r = {"user"=>user, "skey"=>authkey, "scoreinfo"=>si} + r["textfiles"] = textDB.textfiles + j = JSON.generate(r) + ws_conn.send(j) # Login success by token+tmpkey + else + j = JSON.generate({"user" => user, "fail" => "fail"}) + ws_conn.send(j) # Login failure by token + end + else + ws_conn.send("No such user") + ws_conn.close # Force guest out + end + # broadcast.call({"message" => msg}) + end + end +end