1 /* $Id: LobbyClient.h,v 1.20 2003/07/29 16:52:15 nan Exp $ */
2 
3 // Copyright (C) 2001-2003  ���� �ȹ�(Kanna Yoshihiro)
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 
19 #ifndef _LobbyClient_
20 #define _LobbyClient_
21 
22 #include <gtk/gtk.h>
23 
24 #define LOBBYSERVER_NAME	"nan.p.utmc.or.jp"
25 #define LOBBYSERVER_PORT	(5735)
26 
27 class PlayerInfo;
28 class LobbyClientView;
29 
30 static struct {
31   char *code;
32   char *langname;
33   int langID;
34 } table[] = {
35   { "aa", _("Afar"), 0x00 },
36   { "ab", _("Abkhazian"), 0x00 },
37   { "ae", _("Avestan"), 0x00 },
38   { "af", _("Afrikaans"), 0x36 },
39   { "am", _("Amharic"), 0x00 },
40   { "ar", _("Arabic"), 0x01 },
41   { "as", _("Assamese"), 0x4d },
42   { "ay", _("Aymara"), 0x00 },
43   { "az", _("Azerbaijani"), 0x2c },
44   { "ba", _("Bashkir"), 0x00 },
45   { "be", _("Belarusian"), 0x23 },
46   { "bg", _("Bulgarian"), 0x02 },
47   { "bh", _("Bihari"), 0x00 },
48   { "bi", _("Bislama"), 0x00 },
49   { "bn", _("Bengali"), 0x45 },
50   { "bo", _("Tibetan"), 0x00 },
51   { "br", _("Breton"), 0x00 },
52   { "bs", _("Bosnian"), 0x00 },
53   { "ca", _("Catalan"), 0x03 },
54   { "ce", _("Chechen"), 0x00 },
55   { "ch", _("Chamorro"), 0x00 },
56   { "co", _("Corsican"), 0x00 },
57   { "cs", _("Czech"), 0x05 },
58   { "cu", _("Church Slavic"), 0x00 },
59   { "cv", _("Chuvash"), 0x00 },
60   { "cy", _("Welsh"), 0x00 },
61   { "da", _("Danish"), 0x06 },
62   { "de", _("German"), 0x07 },
63   { "dz", _("Dzongkha"), 0x00 },
64   { "el", _("Greek"), 0x08 },
65   { "en", _("English"), 0x09 },
66   { "eo", _("Esperanto"), 0x00 },
67   { "es", _("Spanish"), 0x0a },
68   { "et", _("Estonian"), 0x25 },
69   { "eu", _("Basque"), 0x2d },
70   { "fa", _("Persian"), 0x29 },
71   { "fi", _("Finnish"), 0x0b },
72   { "fj", _("Fijian"), 0x00 },
73   { "fo", _("Faroese"), 0x38 },
74   { "fr", _("French"), 0x0c },
75   { "fy", _("Frisian"), 0x00 },
76   { "ga", _("Irish"), 0x00 },
77   { "gd", _("Scots"), 0x00 },
78   { "gl", _("Galician"), 0x56 },
79   { "gn", _("Guarani"), 0x00 },
80   { "gu", _("Gujarati"), 0x47 },
81   { "gv", _("Manx"), 0x00 },
82   { "ha", _("Hausa"), 0x00 },
83   { "he", _("Hebrew"), 0x0d },
84   { "hi", _("Hindi"), 0x39 },
85   { "ho", _("Hiri Motu"), 0x00 },
86   { "hr", _("Croatian"), 0x1a },
87   { "hu", _("Hungarian"), 0x0e },
88   { "hy", _("Armenian"), 0x2b },
89   { "hz", _("Herero"), 0x00 },
90   { "ia", _("Interlingua"), 0x00 },
91   { "id", _("Indonesian"), 0x21 },
92   { "ie", _("Interlingue"), 0x00 },
93   { "ik", _("Inupiak"), 0x00 },
94   { "is", _("Icelandic"), 0x0f },
95   { "it", _("Italian"), 0x10 },
96   { "iu", _("Inuktitut"), 0x00 },
97   { "ja", _("Japanese"), 0x11 },
98   { "jw", _("Javanese"), 0x00 },
99   { "ka", _("Georgian"), 0x37 },
100   { "ki", _("Kikuyu"), 0x00 },
101   { "kj", _("Kuanyama"), 0x00 },
102   { "kk", _("Kazakh"), 0x3f },
103   { "kl", _("Kalaallisut"), 0x00 },
104   { "km", _("Khmer"), 0x00 },
105   { "kn", _("Kannada"), 0x4b },
106   { "ko", _("Korean"), 0x12 },
107   { "ks", _("Kashmiri"), 0x60 },
108   { "ku", _("Kurdish"), 0x00 },
109   { "kv", _("Komi"), 0x00 },
110   { "kw", _("Cornish"), 0x00 },
111   { "ky", _("Kirghiz"), 0x40 },
112   { "kok", _("Konkani"), 0x57 },
113   { "la", _("Latin"), 0x00 },
114   { "lb", _("Letzeburgesch"), 0x00 },
115   { "ln", _("Lingala"), 0x00 },
116   { "lo", _("Laotian"), 0x00 },
117   { "lt", _("Lithuanian"), 0x27 },
118   { "lv", _("Latvian"), 0x26 },
119   { "mg", _("Malagasy"), 0x00 },
120   { "mh", _("Marshall"), 0x00 },
121   { "mi", _("Maori"), 0x00 },
122   { "mk", _("Macedonian"), 0x2f },
123   { "ml", _("Malayalam"), 0x4c },
124   { "mn", _("Mongolian"), 0x50 },
125   { "mo", _("Moldavian"), 0x00 },
126   { "mr", _("Marathi"), 0x4e },
127   { "ms", _("Malay"), 0x3e },
128   { "mt", _("Maltese"), 0x00 },
129   { "my", _("Burmese"), 0x00 },
130   { "mni", _("Manipuri"), 0x58 },
131   { "na", _("Nauru"), 0x00 },
132   { "nb", _("Norwegian Bokmal"), 0x00 },
133   { "nd", _("North Ndebele"), 0x00 },
134   { "ne", _("Nepali"), 0x61 },
135   { "ng", _("Ndonga"), 0x00 },
136   { "nl", _("Dutch"), 0x13 },
137   { "nn", _("Norwegian Nynorsk"), 0x00 },
138   { "no", _("Norwegian"), 0x14 },
139   { "nr", _("South Ndebele"), 0x00 },
140   { "nv", _("Navajo"), 0x00 },
141   { "ny", _("Nyanja"), 0x00 },
142   { "oc", _("Occitan"), 0x00 },
143   { "om", _("(Afan) Oromo"), 0x00 },
144   { "or", _("Oriya"), 0x48 },
145   { "os", _("Ossetian"), 0x00 },
146   { "pa", _("Punjabi"), 0x46 },
147   { "pi", _("Pali"), 0x00 },
148   { "pl", _("Polish"), 0x15 },
149   { "ps", _("Pashto"), 0x00 },
150   { "pt", _("Portuguese"), 0x16 },
151   { "qu", _("Quechua"), 0x00 },
152   { "rm", _("Rhaeto-Roman"), 0x00 },
153   { "rn", _("Kirundi"), 0x00 },
154   { "ro", _("Romanian"), 0x18 },
155   { "ru", _("Russian"), 0x19 },
156   { "rw", _("Kinyarwanda"), 0x00 },
157   { "sa", _("Sanskrit"), 0x4f },
158   { "sc", _("Sardinian"), 0x00 },
159   { "sd", _("Sindhi"), 0x59 },
160   { "se", _("Northern Sami"), 0x00 },
161   { "sg", _("Sango"), 0x00 },
162   { "si", _("Sinhalese"), 0x00 },
163   { "sk", _("Slovak"), 0x1b },
164   { "sl", _("Slovenian"), 0x24 },
165   { "sm", _("Samoan"), 0x00 },
166   { "sn", _("Shona"), 0x00 },
167   { "so", _("Somali"), 0x00 },
168   { "sq", _("Albanian"), 0x1c },
169   { "sr", _("Serbian"), 0x1a },
170   { "ss", _("Siswati"), 0x00 },
171   { "st", _("Sesotho"), 0x00 },
172   { "su", _("Sundanese"), 0x00 },
173   { "sv", _("Swedish"), 0x1d },
174   { "sw", _("Swahili"), 0x41 },
175   { "ta", _("Tamil"), 0x49 },
176   { "te", _("Telugu"), 0x0a },
177   { "tg", _("Tajik"), 0x00 },
178   { "th", _("Thai"), 0x1e },
179   { "ti", _("Tigrinya"), 0x00 },
180   { "tk", _("Turkmen"), 0x00 },
181   { "tl", _("Tagalog"), 0x00 },
182   { "tn", _("Setswana"), 0x00 },
183   { "to", _("Tonga"), 0x00 },
184   { "tr", _("Turkish"), 0x1f },
185   { "ts", _("Tsonga"), 0x00 },
186   { "tt", _("Tatar"), 0x44 },
187   { "tw", _("Twi"), 0x00 },
188   { "ty", _("Tahitian"), 0x00 },
189   { "ug", _("Uighur"), 0x00 },
190   { "uk", _("Ukrainian"), 0x22 },
191   { "ur", _("Urdu"), 0x20 },
192   { "uz", _("Uzbek"), 0x43 },
193   { "vi", _("Vietnamese"), 0x2a },
194   { "vo", _("Volapuk"), 0x00 },
195   { "wo", _("Wolof"), 0x00 },
196   { "wen", _("Sorbian"), 0x00 },
197   { "xh", _("Xhosa"), 0x00 },
198   { "yi", _("Yiddish"), 0x00 },
199   { "yo", _("Yoruba"), 0x00 },
200   { "za", _("Zhuang"), 0x00 },
201   { "zh", _("Chinese"), 0x04 },
202   { "zu", _("Zulu"), 0x00 },
203   { "", "", -1 }
204 };
205 
206 class LobbyClient {
207 public:
208   ~LobbyClient();
209 
210   // A sort of singleton
211   static LobbyClient* Create();
TheLobbyClient()212   static LobbyClient* TheLobbyClient() { return m_lobbyClient; };
213 
214   bool Init( char *nickname, char *message );
215 
GetSocket()216   int GetSocket() { return m_socket; };
GetPlayerInfo()217   PlayerInfo *GetPlayerInfo() { return m_player; };
GetPlayerNum()218   long GetPlayerNum() { return m_playerNum; };
219 
220   static gint PollServerMessage( gpointer data );
221   static void Connect( GtkWidget *widget, gpointer data );
222 
223   void SendAP( long uniqID );
224   void SendSP();
225   void SendQP();
226   void SendDP( long uniqID);
227   void SendQT();
228   void SendSC( int score1, int score2 );
229   void SendMS( char *message, long channel );
230 
231   long m_playerNum;
232   PlayerInfo *m_player;
233 
234   long m_selected;		// Selected row of the table
235 
236   char m_nickname[32];
237 
GetLang()238   long GetLang() { return m_lang; };
239 
GetCanBeServer()240   bool GetCanBeServer() { return m_canBeServer; };
241 protected:
242   void ReadUI();
243   void UpdateTable();
244 
245   void ReadPI();
246   void ReadOI();
247   void ReadOV();
248   void ReadMS();
249 
250   LobbyClientView *m_view;
251 
252   int m_socket;
253   bool m_canBeServer;
254 
255   long m_lang;
256 
257 private:
258   LobbyClient();
259   static LobbyClient *m_lobbyClient;
260 };
261 
262 class PlayerInfo {
263 public:
264   PlayerInfo();
265   ~PlayerInfo();
266 
267   bool m_canBeServer;
268   bool m_playing;
269   long m_ID;
270   char m_nickname[32];
271   char m_message[64];
272 };
273 
274 #endif // _LobbyClient_
275