Debian Codegraph @

src/network/lgs.cpp

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22
23 #include <string.h>
24 #include "lgs.h"
25 #include "consoledispatch.h"
26 #include "room.h"
27 #include "boarddispatch.h"
28 #include "gamedialog.h"
29 #include "talk.h"
30 #include "playergamelistings.h"
31
32 LGSConnection::LGSConnection(const ConnectionCredentials credentials) :
33 IGSConnection(credentials) {}
34
35 QString LGSConnection::getPlaceString(void)
36 {
37 return "LGS";
38 }
39
40 void LGSConnection::sendPlayersRequest(void)
41 {
42 sendText("who\r\n"); //no userlist, user gives simple info
43 }
44
45 void LGSConnection::sendToggle(const QString & param, bool val)
46 {
47 if(param == "looking" || param == "open")
48 return; //FIXME
49 IGSConnection::sendToggle(param, val);
50 }
51
52 void LGSConnection::requestGameInfo(unsigned int game_id)
53 {
54 char string[20];
55 snprintf(string, 20, "refresh %d\r\n", game_id);
56 sendText(string);
57 snprintf(string, 20, "all %d\r\n", game_id);
58 sendText(string);
59 }
60
61 void LGSConnection::onReady(void)
62 {
63 if(firstonReadyCall)
64 {
65 if(connectionState != PasswordSent)
66 return;
67 firstonReadyCall = 0;
68 setState(Connected);
69 setKeepAlive(600);
70 sendPlayersRequest();
71 sendGamesRequest();
72 //dispatch->recvRoomListing(new RoomListing(0, "Lobby"));
73 //sendRoomListRequest();
74 //qDebug("Ready!\n");
75 }
76 }
77
78 void LGSConnection::handle_info(QString line)
79 {
80 static PlayerListing * statsPlayer;
81 BoardDispatch * boarddispatch;
82 Room * room = getDefaultRoom();
83 MoveRecord * aMove = new MoveRecord();
84 static QString memory_str;
85 static int memory = 0;
86 qDebug("9: %s", line.toLatin1().constData());
87 line = line.remove(0, 2).trimmed(); //remove command code
88 // status messages
89 if (line.contains("Set open to be"))
90 {
91 bool val = (line.indexOf("False") == -1);
92 room->recvToggle(0, val);
93 }
94 else if (line.contains("Setting you open for matches"))
95 room->recvToggle(0, true);
96 else if (line.contains("Set looking to be"))
97 {
98 bool val = (line.indexOf("False") == -1);
99 room->recvToggle(1, val);
100 }
101 // 9 Set quiet to be False.
102 else if (line.contains("Set quiet to be"))
103 {
104 bool val = (line.indexOf("False") == -1);
105 room->recvToggle(2, val);
106 }
107 else if (line.indexOf("Channel") == 0)
108 {
109 // channel messages
110 QString e1 = element(line, 1, " ");
111 if (e1.at(e1.length()-1) == ':')
112 e1.truncate(e1.length()-1);
113 #ifdef FIXME
114 int nr = e1.toInt();
115
116 if (line.contains("turned on."))
117 {
118 // turn on channel
119 emit signal_channelinfo(nr, QString("*on*"));
120 }
121 else if (line.contains("turned off."))
122 {
123 // turn off channel
124 emit signal_channelinfo(nr, QString("*off*"));
125 }
126 else if (!line.contains("Title:") || gsName == GS_UNKNOWN)
127 {
128 // keep in memory to parse next line correct
129 memory = nr;
130 emit signal_channelinfo(memory, line);
131 memory_str = "CHANNEL";
132 }
133 #endif //FIXME
134 // return IT_OTHER;
135 }
136 #ifdef FIXME
137 else if (memory != 0 && !memory_str.isEmpty() && memory_str == "CHANNEL")
138 {
139 //emit signal_channelinfo(memory, line);
140
141 // reset memory
142 memory = 0;
143 memory_str = QString();
144 // return IT_OTHER;
145 }
146 #endif //FIXME
147 // IGS: channelinfo
148 // 9 #42 Title: Untitled -- Open
149 // 9 #42 broesel zero815 Granit
150 else if (line.contains("#"))
151 {
152 #ifdef FIXME
153 int nr = element(line, 0, "#", " ").toInt();
154 QString msg = element(line, 0, " ", "EOL");
155 emit signal_channelinfo(nr, msg);
156 #endif //FIXME
157 }
158 // NNGS: channels
159 else if (line.contains("has left channel") || line.contains("has joined channel"))
160 {
161 QString e1 = element(line, 3, " ", ".");
162 #ifdef FIXME
163 int nr = e1.toInt();
164
165 // turn on channel to get full info
166 emit signal_channelinfo(nr, QString("*on*"));
167 #endif //FIXME
168 }
169 else if (line.contains("Game is titled:"))
170 {
171 QString t = element(line, 0, ":", "EOL");
172 //emit signal_title(t);
173 return;
174 }
175 else if (line.contains("offers a new komi "))
176 {
177 // NNGS: 9 physician offers a new komi of 1.5.
178 QString komi = element(line, 6, " ");
179 if (komi.at(komi.length()-1) == '.')
180 komi.truncate(komi.length() - 1);
181 QString opponent = element(line, 0, " ");
182
183 // true: request
184 //emit signal_komi(opponent, komi, true);
185 }
186 else if (line.contains("Komi set to"))
187 {
188 // NNGS: 9 Komi set to -3.5 in match 10
189 QString komi = element(line, 3, " ");
190 QString game_id = element(line, 6, " ");
191
192 // false: no request
193 //emit signal_komi(game_id, komi, false);
194 }
195 else if (line.contains("wants the komi to be"))
196 {
197 // IGS: 9 qGoDev wants the komi to be 1.5
198 QString komi = element(line, 6, " ");
199 QString opponent = element(line, 0, " ");
200
201 // true: request
202 //emit signal_komi(opponent, komi, true);
203 }
204 else if (line.contains("Komi is now set to"))
205 {
206 // 9 Komi is now set to -3.5. -> oppenent set for our game
207 QString komi = element(line, 5, " ");
208 // error? "9 Komi is now set to -3.5.9 Komi is now set to -3.5"
209 if (komi.contains(".9"))
210 komi = komi.left(komi.length() - 2);
211
212 // false: no request
213 //emit signal_komi(QString(), komi, false);
214 }
215 else if (line.contains("Set the komi to"))
216 {
217 // NNGS: 9 Set the komi to -3.5 - I set for own game
218 QString komi = element(line, 4, " ");
219
220 // false: no request
221 //emit signal_komi(QString(), komi, false);
222 }
223 else if (line.contains("game will count"))
224 {
225 // IGS: 9 Game will not count towards ratings.
226 // 9 Game will count towards ratings.
227 //emit signal_freegame(false);
228 }
229 else if (line.contains("game will not count", Qt::CaseInsensitive))
230 {
231 // IGS: 9 Game will not count towards ratings.
232 // 9 Game will count towards ratings.
233 //emit signal_freegame(true);
234 }
235 else if ((line.contains("[") || line.contains("yes")) && line.length() < 6)
236 {
237 // 9 [20] ... channelinfo
238 // 9 yes ... ayt
239 return;
240 }
241 else if (line.contains("has restarted your game") ||
242 line.contains("has restored your old game"))
243 {
244 if (line.contains("restarted"))
245 // memory_str -> see case 15 for continuation
246 memory_str = element(line, 0, " ");
247 }
248 else if (line.contains("I suggest that"))
249 {
250 memory_str = line;
251 return;
252 }
253 else if (line.contains("and set komi to"))
254 {
255 #ifdef FIXME
256 // suggest message ...
257 if (!memory_str.isEmpty())
258 // something went wrong...
259 return;
260
261 line = line.simplified();
262
263 QString p1 = element(memory_str, 3, " ");
264 QString p2 = element(memory_str, 6, " ", ":");
265 bool p1_play_white = memory_str.contains("play White");
266
267 QString h, k;
268 if (line.contains("even game"))
269 h = "0";
270 else
271 h = element(line, 3, " ");
272
273 k = element(line, 9, " ", ".");
274
275 int size = 19;
276 if (line.contains("13x13"))
277 size = 13;
278 else if (line.contains("9x 9"))
279 {
280 size = 9;
281 memory_str = QString();
282 }
283
284 if (p1_play_white)
285 emit signal_suggest(p1, p2, h, k, size);
286 else
287 emit signal_suggest(p2, p1, h, k, size);
288 #endif //FIXME
289 return;
290 }
291 // 9 Match [19x19] in 1 minutes requested with xxxx as White.
292 // 9 Use <match xxxx B 19 1 10> or <decline xxxx> to respond.
293 // 9 NMatch requested with yfh2test(B 3 19 60 600 25 0 0 0).
294 // 9 Use <nmatch yfh2test B 3 19 60 600 25 0 0 0> or <decline yfh2test> to respond.
295 else if (line.contains("<decline") && line.contains("match"))
296 {
297 // false -> not my request: used in mainwin.cpp
298 line = element(line, 0, "<", ">");
299 MatchRequest * aMatch = new MatchRequest();
300 aMatch->opponent = line.section(" ", 1, 1);
301 if(line.section(" ",2,2) == "B")
302 aMatch->color_request = MatchRequest::BLACK;
303 else if(line.section(" ",2,2) == "N")
304 aMatch->color_request = MatchRequest::NIGIRI;
305 else
306 aMatch->color_request = MatchRequest::WHITE;
307 if(line.contains("nmatch"))
308 {
309 aMatch->handicap = line.section(" ",3,3).toInt();
310 aMatch->board_size = line.section(" ",4,4).toInt();
311 //what kind of time? var name?
312 aMatch->maintime = line.section(" ",5,5).toInt();
313 aMatch->periodtime = line.section(" ",6,6).toInt();
314 aMatch->stones_periods = line.section(" " ,7,7).toInt();
315 //what is "nmatch"?
316 aMatch->nmatch = true;
317 qDebug("nmatch in parser");
318 }
319 else
320 {
321 aMatch->board_size = line.section(" ",3,3).toInt();
322 aMatch->maintime = line.section(" ",4,4).toInt();
323 aMatch->periodtime = line.section(" ",5,5).toInt();
324 aMatch->nmatch = false;
325 }
326 PlayerListing * p = getPlayerListingNeverFail(aMatch->opponent);
327 const PlayerListing * us = getOurListing();
328 if(us)
329 {
330 aMatch->our_name = us->name;
331 aMatch->our_rank = us->rank;
332 }
333 aMatch->their_rank = p->rank;
334
335 GameDialog * gameDialogDispatch = getGameDialog(p);
336 gameDialogDispatch->recvRequest(aMatch);
337 delete aMatch;
338 }
339 // 9 Match [5] with guest17 in 1 accepted.
340 // 9 Creating match [5] with guest17.
341 else if (line.contains("Creating match"))
342 {
343 QString nr = element(line, 0, "[", "]");
344 // maybe there's a blank within the brackets: ...[ 5]...
345 QString dummy = element(line, 0, "]", ".").trimmed();
346 QString opp = element(dummy, 1, " ");
347
348 // We let the 15 game record message create the board
349 //GameDialog * gameDialogDispatch = getGameDialog(opp);
350 //gameDialogDispatch->closeAndCreate();
351 //GameDialog * gameDialogDispatch =
352 // getGameDialog(opp);
353 //MatchRequest * mr = gameDialogDispatch->getMatchRequest();
354 //created_match_request = new MatchRequest(*mr);
355 //closeGameDialog(opp);
356 ////emit signal_matchCreate(nr, opp);
357 // automatic opening of a dialog tab for further conversation
358 ////emit signal_talk(opp, "", true);
359 }
360 else if (line.contains("Match") && line.contains("accepted"))
361 {
362 QString nr = element(line, 0, "[", "]");
363 QString opp = element(line, 3, " ");
364 ////emit signal_matchCreate(nr, opp);
365
366 }
367 // 9 frosla withdraws the match offer.
368 // 9 guest17 declines your request for a match.
369 else if (line.contains("declines your request for a match") ||
370 line.contains("withdraws the match offer"))
371 {
372 QString opp = element(line, 0, " ");
373 PlayerListing * p = getPlayerListingNeverFail(opp);
374 GameDialog * gameDialogDispatch = getGameDialog(p);
375 gameDialogDispatch->recvRefuseMatch(1);
376 }
377 //9 yfh2test declines undo
378 else if (line.contains("declines undo"))
379 {
380 // not the cleanest way : we should send this to a message box
381 //emit signal_kibitz(0, element(line, 0, " "), line);
382 return;
383 }
384
385 //9 yfh2test left this room
386 //9 yfh2test entered this room
387 else if (line.contains("this room"))
388 {} //emit signal_refresh(10);
389
390 //9 Requesting match in 10 min with frosla as Black.
391 else if (line.contains("Requesting match in"))
392 {
393 QString opp = element(line, 6, " ");
394 //emit signal_opponentopen(opp);
395 }
396 // NNGS: 9 Removing @ K8
397 // IGS: 9 Removing @ B5
398 // 49 Game 265 qGoDev is removing @ B5
399 else if (line.contains("emoving @"))
400 {
401 /* FIXME DOUBLE CHECK!!! */
402 /*if (gsName != IGS)
403 {
404 QString pt = element(line, 2, " ");
405 //emit signal_removeStones(pt, 0);
406 }*/
407 if(protocol_save_int < 0)
408 {
409 qDebug("Received stone removal message without game in scoring mode");
410 return;
411 }
412 else
413 {
414 boarddispatch = getBoardDispatch(protocol_save_int);
415 QString pt = element(line, 2, " ");
416 aMove->flags = MoveRecord::REMOVE;
417 aMove->x = (int)(pt.toLatin1().at(0));
418 aMove->x -= 'A';
419 if(aMove->x < 9) //no I on IGS
420 aMove->x++;
421 pt.remove(0,1);
422 aMove->y = element(pt, 0, " ").toInt();
423 /* Do we need the board size here???*/
424 aMove->y = 20 - aMove->y;
425 boarddispatch->recvMove(aMove);
426 // FIXME Set protocol_save_int to -1???
427 delete aMove;
428 }
429 }
430 // 9 You can check your score with the score command, type 'done' when finished.
431 else if (line.contains("check your score with the score command"))
432 {
433 // if (gsName == IGS)
434 // IGS: store and wait until game number is known
435 // memory_str = QString("rmv@"); // -> continuation see 15
436 // else
437 ////emit signal_removestones(0, 0);
438 ////emit signal_enterScoreMode();
439 memory_str = QString("rmv@");
440 }
441 // IGS: 9 Board is restored to what it was when you started scoring
442 else if (line.contains("what it was when you"))
443 {
444 //emit signal_restoreScore();
445 }
446 // WING: 9 Use <adjourn> to adjourn, or <decline adjourn> to decline.
447 else if (line.contains("Use adjourn to") || line.contains("Use <adjourn> to"))
448 {
449 qDebug("parser->case 9: Use adjourn to");
450 ////emit signal_requestDialog("adjourn", "decline adjourn", 0, 0);
451 boarddispatch = getBoardDispatch(memory);
452 boarddispatch->recvRequestAdjourn();
453 }
454 // 9 frosla requests to pause the game.
455 else if (line.contains("requests to pause"))
456 {
457 //emit signal_requestDialog("pause", 0, 0, 0);
458 }
459 else if (line.contains("been adjourned"))
460 {
461 // remove game from list - special case: own game
462 #ifdef FIXME
463 aGame->nr = "@";
464 aGame->running = false;
465
466 //emit signal_game(aGame);
467 #endif //FIXME
468 /* There's several after the fact server INFO messages about
469 * games adjourning so we only need to close for one of them
470 * The 21 message might actually be better FIXME*/
471 boarddispatch = getIfBoardDispatch(memory);
472 if(boarddispatch)
473 {
474 boarddispatch->adjournGame();
475 closeBoardDispatch(memory);
476 }
477 }
478 // 9 Game 22: frosla vs frosla has adjourned.
479 else if (line.contains("has adjourned"))
480 {
481 int number = element(line, 0, " ", ":").toInt();
482 GameListing * aGame = room->getGameListing(number);
483 aGame->running = false;
484
485 // for information
486 //aGame->Sz = "has adjourned.";
487
488 #ifdef OLD
489 //emit signal_game(aGame);
490 // //emit signal_move(aGame);
491 #endif //OLD
492 // No need to get existing listing because
493 // this is just to falsify the listing
494 room->recvGameListing(aGame);
495 }
496 // 9 Removing game 30 from observation list.
497 else if (line.contains("from observation list"))
498 {
499 // is done from qGoIF
500 // //emit signal_addToObservationList(-1);
501 // aGame->nr = element(line, 2, " ").toInt();
502 // aGame->Sz = "-";
503 // aGame->running = false;
504 //emit signal_observedGameClosed(element(line, 2, " ").toInt());
505 return;
506 }
507 // 9 Adding game to observation list.
508 else if (line.contains("to observation list"))
509 {
510 /* Unfortunately, LGS and IGS have no number here, so
511 * we have to either guess or get it from the observe send
512 * which is easiest */
513 getBoardDispatch(protocol_save_int);
514 protocol_save_int = -1;
515 return;
516 }
517 // 9 Games currently being observed: 31, 36, 45.
518 else if (line.contains("Games currently being observed"))
519 {
520 if (line.contains("None"))
521 {
522 //emit signal_addToObservationList(0);
523 }
524 else
525 {
526 #ifdef FIXME
527 // don't work correct at IGS!!!
528 int i = line.count(',');
529 qDebug(QString("observing %1 games").arg(i+1).toLatin1());
530 // //emit signal_addToObservationList(i+1);
531 #endif //FIXME
532 }
533
534 // return IT_OTHER;
535 }
536 // 9 1 minutes were added to your opponents clock
537 else if (line.contains("minutes were added"))
538 {
539 #ifdef FIXME
540 int t = element(line, 0, " ").toInt();
541 emit signal_timeAdded(t, false);
542 #endif //FIXME
543 }
544 // 9 Your opponent has added 1 minutes to your clock.
545 else if (line.contains("opponent has added"))
546 {
547 #ifdef FIXME
548 int t = element(line, 4, " ").toInt();
549 emit signal_timeAdded(t, true);
550 #endif //FIXME
551 }
552 // NNGS: 9 Game clock paused. Use "unpause" to resume.
553 else if (line.contains("Game clock paused"))
554 {
555 #ifdef FIXME
556 emit signal_timeAdded(-1, true);
557 #endif //FIXME
558 }
559 // NNGS: 9 Game clock resumed.
560 else if (line.contains("Game clock resumed"))
561 {
562 #ifdef FIXME
563 emit signal_timeAdded(-1, false);
564 #endif //FIXME
565 }
566 // 9 Increase frosla's time by 1 minute
567 else if (line.contains("s time by"))
568 {
569 #ifdef FIXME
570 int t = element(line, 4, " ").toInt();
571 if (line.contains(getUsername()))
572 emit signal_timeAdded(t, true);
573 else
574 emit signal_timeAdded(t, false);
575 #endif //FIXME
576 }
577 // 9 Setting your . to Banana [text] (idle: 0 minutes)
578 else if (line.contains("Setting your . to"))
579 {
580 QString busy = element(line, 0, "[", "]");
581 if (!busy.isEmpty())
582 {
583 QString player = element(line, 4, " ");
584 // true = player
585 ////emit signal_talk(player, "[" + busy + "]", true);
586 }
587 }
588 /* I don't think we care about the case 9 messages like this.
589 * maybe in order to update the game lists !!!
590 * but not for the board. */
591 else if (line.contains("resigns.") ||
592 line.contains("adjourned.") ||
593 //don't intefere with status
594 //line.contains(" : W ", Qt::CaseSensitive) ||
595 //line.contains(" : B ", Qt::CaseSensitive) ||
596 line.contains("forfeits on") ||
597 line.contains("lost by"))
598 {
599 GameResult * aGameResult;
600 int number = element(line, 0, " ", ":").toInt();
601 GameListing * aGame = room->getGameListing(number);
602 aGame->running = false;
603 // for information
604 aGame->result = element(line, 4, " ", "}");
605
606 boarddispatch = getIfBoardDispatch(aGame->number);
607 /* FIXME: This shouldn't create a new board if
608 * we're not watching it.
609 * Also WING sometimes sends 9 and sometimes sends 21 perhaps
610 * depending on whether its observed or resign versus score/result
611 * we don't want to send double messages.*/
612 if(boarddispatch)
613 {
614 aGameResult = new GameResult();
615
616 if(line.contains(" : W ", Qt::CaseSensitive) ||
617 line.contains(" : B ", Qt::CaseSensitive))
618 {
619 aGameResult->result = GameResult::SCORE;
620
621 int posw, posb;
622 posw = aGame->result.indexOf("W ");
623 posb = aGame->result.indexOf("B ");
624 bool wfirst = posw < posb;
625 float sc1, sc2;
626 sc1 = aGame->result.mid(posw+1, posb-posw-2).toFloat();
627 //sc2 = aGame->result.right(aGame->result.length()-posb-1).toFloat();
628 /* FIXME This may be right for IGS and wrong for WING */
629 //sc2 = aGame->result.mid(posb +1, posb + 6).toFloat();
630 sc2 = element(aGame->result, 4, " ").toFloat();
631 qDebug("sc1: %f sc2: %f\n", sc1, sc2);
632 if(sc1 > sc2)
633 {
634 aGameResult->winner_score = sc1;
635 aGameResult->loser_score = sc2;
636 }
637 else
638 {
639 aGameResult->winner_score = sc2;
640 aGameResult->loser_score = sc1;
641
642 }
643
644 if (!wfirst)
645 {
646 int h = posw;
647 posw = posb;
648 posb = h;
649 if(sc2 > sc1)
650
651 aGameResult->winner_color = stoneWhite;
652 else
653 aGameResult->winner_color = stoneBlack;
654 }
655 else
656 {
657 if(sc1 > sc2)
658 aGameResult->winner_color = stoneWhite;
659 else
660 aGameResult->winner_color = stoneBlack;
661 }
662
663
664 }
665 else if(line.contains("forfeits on time"))
666 {
667 aGameResult->result = GameResult::TIME;
668 if(line.contains("Black"))
669 {
670 aGameResult->winner_color = stoneWhite;
671 }
672 else
673 {
674 aGameResult->winner_color = stoneBlack;
675 }
676 }
677 else if(line.contains("resign", Qt::CaseInsensitive))
678 {
679 aGameResult->result = GameResult::RESIGN;
680 if(line.contains("Black"))
681 {
682 aGameResult->winner_color = stoneWhite;
683 }
684 else
685 {
686 aGameResult->winner_color = stoneBlack;
687 }
688 }
689 else if(line.contains("lost by"))
690 {
691 aGameResult->result = GameResult::SCORE;
692 if(line.contains("Black"))
693 {
694 aGameResult->winner_color = stoneWhite;
695 }
696 else
697 {
698 aGameResult->winner_color = stoneBlack;
699
700 }
701
702 }
703 }
704
705
706 if (aGame->result.isEmpty())
707 aGame->result = "-";
708 else if (aGame->result.indexOf(":") != -1)
709 aGame->result.remove(0,2);
710
711 if(boarddispatch)
712 {
713 qDebug("Receiving result!!!");
714 boarddispatch->recvResult(aGameResult);
715 /* is kibitzing this here what we want?*/
716 /* FIXME... should be a shortened list, not the full
717 * result msg kibitz */
718 boarddispatch->recvKibitz("", line);
719 }
720 room->recvGameListing(aGame);
721 return;
722 }
723 // NNGS: 9 Messages: (after 'message' cmd)
724 // 8 File
725 // <msg>
726 // 8 File
727 // 9 Please type "erase" to erase your messages after reading
728 else if (line.contains("Messages:"))
729 {
730 // parse like IGS cmd nr 14: Messages
731 memory = 14;
732 }
733 // IGS: 9 You have a message. To read your messages, type: message
734 // NNGS: 9 You have 1 messages. Type "messages" to display them
735 else if (line.contains("You have") && line.contains("messages"))
736 {
737 // remove cmd nr
738 line = line.trimmed();
739 line = line.remove(0, 2);
740 getConsoleDispatch()->recvText(line.toLatin1().constData());
741 return;
742 }
743 // 9 Observing game 2 (chmeng vs. myao) :
744 // 9 shanghai 9k* henry 15k
745 // 9 Found 2 observers.
746 else if (line.contains("Observing game ", Qt::CaseSensitive))
747 {
748 // right now: only need for observers of teaching game
749 // game number
750 bool ok;
751 memory = element(line, 2, " ").toInt(&ok);
752 if (ok)
753 {
754 memory_str = "observe";
755 // FIXME
756 //emit signal_clearObservers(memory);
757 BoardDispatch * boarddispatch = getIfBoardDispatch(memory);
758 if(boarddispatch)
759 {
760 GameData * g = boarddispatch->getGameData();
761 g->white_name = element(line, 0, "(", " ");
762 g->black_name = element(line, 4, " ", ")");
763 boarddispatch->gameDataChanged();
764 }
765 return;
766 }
767 }
768 else if (!memory_str.isEmpty() && memory_str == "observe" && line.contains("."))
769 {
770 // QString cnt = element(line, 1, " ");
771 // //emit signal_kibitz(memory, "00", "");
772
773 memory = 0;
774 memory_str = QString();
775
776 return;
777 }
778 else if (!memory_str.isEmpty() && memory_str == "observe")
779 {
780 QString name = element(line, 0, " ");
781 QString rank;
782 boarddispatch = getBoardDispatch(memory);
783 if(!boarddispatch)
784 {
785 qDebug("No boarddispatch for observer list\n");
786 return;
787 }
788
789 for (int i = 1; ! name.isEmpty(); i++)
790 {
791 rank = element(line, i, " ");
792 fixRankString(&rank);
793 // send as kibitz from "0"
794 PlayerListing * p = getPlayerListingNeverFail(name);
795 boarddispatch->recvObserver(p, true);
796 name = element(line, ++i , " ");
797 }
798
799 return;
800 }
801 else if(line.contains("Found") && line.contains("observers"))
802 {
803 memory = 0;
804 memory_str = QString();
805 }
806 else if (line.contains("****") && line.contains("Players"))
807 return;
808
809 // 9 qGoDev has resigned the game.
810 else if (line.contains("has resigned the game"))
811 {
812 boarddispatch = getBoardDispatch(memory);
813 if(!boarddispatch)
814 {
815 qDebug("No board dispatch for \"resigned the game\"\n");
816 return;
817 }
818 #ifdef FIXME
819 aGame->running = false;
820 #endif //FIXME
821
822 GameResult * aGameResult = new GameResult();
823 aGameResult->loser_name = element(line, 0, " ");
824 aGameResult->result = GameResult::RESIGN;
825 /* We need to set unknown/none color here */
826 boarddispatch->recvResult(aGameResult);
827 return;
828
829 }
830 else if (line.contains("has run out of time"))
831 {
832 boarddispatch = getBoardDispatch(protocol_save_int);
833 if(!boarddispatch)
834 {
835 qDebug("No board dispatch for \"has run out of time\"\n");
836 return;
837 }
838 #ifdef FIXME
839 aGame->running = false;
840 #endif //FIXME
841
842 GameResult * aGameResult = new GameResult();
843 aGameResult->loser_name = element(line, 0, " ");
844 aGameResult->result = GameResult::TIME;
845 /* We need to set unknown/none color here */
846 boarddispatch->recvResult(aGameResult);
847 return;
848
849 }
850
851
852
853 //9 Player: yfh2
854 //9 Game: go (1)
855 //9 Language: default
856 //9 Rating: 6k* 23
857 //9 Rated Games: 21
858 //9 Rank: 8k 21
859 //9 Wins: 13
860 //9 Losses: 16
861 //9 Idle Time: (On server) 0s
862 //9 Address: [email protected]
863 //9 Country: France
864 //9 Reg date: Tue Nov 18 04:01:05 2003
865 //9 Info: yfh2
866 //9 Defaults (help defs): time 0, size 0, byo-yomi time 0, byo-yomi stones 0
867 //9 Verbose Bell Quiet Shout Automail Open Looking Client Kibitz Chatter
868 //9 Off On On On On Off Off On On On
869
870 else if (line.contains("Player:"))
871 {
872 QString name = element(line, 1, " ");
873 statsPlayer = getPlayerListingNeverFail(name);
874 #ifdef FIXME
875 /* So this would have cleared the structure, but
876 * we're just creating a new empty object later.
877 * One HUGE FIXME question is what we might be
878 * overriding on the other side. Maybe we need
879 * a bit vector specifying what has updated when
880 * the message is passed. So the notion before
881 * was that the structure was held until
882 * completely filled and then passed up*/
883
884 statsPlayer->extInfo = "";
885 statsPlayer->won = "";
886 statsPlayer->lost = "";
887 statsPlayer->country = "";
888 statsPlayer->nmatch_settings = "";
889 statsPlayer->rank = "";
890 statsPlayer->info = "";
891 statsPlayer->address = "";
892 statsPlayer->play_str = "";
893 statsPlayer->obs_str = "";
894 statsPlayer->idle = "";
895 statsPlayer->rated = "";
896 // not sure it is the best way : above code seem to make use of "signal"
897 // but we don't need this apparently for handling stats
898 #endif //FIXME
899 protocol_save_string = "STATS";
900 return;
901 }
902
903 else if (line.contains("Address:"))
904 {
905 statsPlayer->email_address = element(line, 1, " ");
906 return;
907 }
908
909 else if (line.contains("Last Access"))
910 {
911 statsPlayer->idletime = element(line, 4, " ")+ " " + element(line, 5, " ")+" " + element(line, 6, " ");
912 statsPlayer->seconds_idle = idleTimeToSeconds(statsPlayer->idletime);
913 return;
914 }
915
916 else if (line.contains("Rating:"))
917 {
918 statsPlayer->rank = element(line, 1, " ");
919 fixRankString(&(statsPlayer->rank));
920 statsPlayer->rank_score = rankToScore(statsPlayer->rank);
921 return;
922 }
923
924 else if (line.contains("Wins:"))
925 {
926 statsPlayer->wins = element(line, 1, " ").toInt();
927 return;
928 }
929
930 else if (line.contains("Losses:"))
931 {
932 statsPlayer->losses = element(line, 1, " ").toInt();
933 return;
934 }
935
936 else if ((line.contains("Country:"))||(line.contains("From:"))) //IGS || LGS
937 {
938 statsPlayer->country = element(line, 0, " ","EOL");
939 return;
940 }
941 else if (line.contains("User Level:")) //LGS
942 {
943 statsPlayer->extInfo = line;
944 return;
945 }
946
947
948 else if ((line.contains("Info:"))&& !(line.contains("Rank Info:")))
949 {
950 #ifdef FIXME
951 if (! statsPlayer->info.isEmpty())
952 statsPlayer->info.append("\n");
953 statsPlayer->info.append(line);
954 //emit signal_statsPlayer(statsPlayer);
955 #endif //FIXME
956 return;
957 }
958 else if (line.contains("Idle Time:"))
959 {
960 statsPlayer->idletime = element(line, 2, " ");
961 statsPlayer->seconds_idle = idleTimeToSeconds(statsPlayer->idletime);
962 return;
963 }
964 else if (line.contains("Playing in game:")) //IGS and LGS
965 {
966 statsPlayer->playing = element(line, 3, " ").toInt();
967
968 return;
969 }
970 /*else if (line.contains("(playing game"))
971 {
972 //FIXME this is missing!!
973 statsPlayer->playing = element(line, 1, " ",":").toInt();
974 return;
975 }*/
976 else if (line.left(5) == "19x19") //LGS syntax
977 {
978 statsPlayer->rank = element(line, 4, " ");
979 fixRankString(&(statsPlayer->rank));
980 statsPlayer->rank_score = rankToScore(statsPlayer->rank);
981 statsPlayer->rated_games = element(line, 7, " ").toInt();
982 return;
983 }
984
985 else if (line.contains("Wins/Losses")) //LGS syntax
986 {
987 statsPlayer->wins = element(line, 2, " ").toInt();
988 statsPlayer->losses = element(line, 4, " ").toInt();
989 return;
990 }
991
992 else if (line.contains("Last Access"))
993 {
994 statsPlayer->idletime = "not on";
995 return;
996 }
997
998 else if(line.contains("Full Name"))
999 {
1000 if(statsPlayer)
1001 {
1002 qDebug("talk name: %s", statsPlayer->name.toLatin1().constData());
1003 Talk * talk = getDefaultRoom()->getTalk(statsPlayer);
1004 if(talk)
1005 talk->updatePlayerListing();
1006 statsPlayer = 0;
1007 }
1008 }
1009
1010 //9 ROOM 01: FREE GAME ROOM;PSMNYACF;自由対局室;19;1;10;1,19,60,600,30,25,10,60,0
1011 //9 ROOM 10: SLOW GAME ROOM;PSMNYACF;スロー対局室;19;1;20
1012 //9 ROOM 92: PANDA OPEN ROOM;X;月例大会;19;10;15
1013 else if (! line.left(5).compare("ROOM "))
1014 {
1015
1016 //emit signal_room(element(line,0," ",";"),(element(line, 1,";")=="X") || (element(line, 1,";")=="P"));
1017 return;
1018 }
1019 else if(line.contains("File"))
1020 return;
1021 if (protocol_save_string != "STATS")
1022 getConsoleDispatch()->recvText(line.toLatin1().constData());
1023 }
1024 #ifdef OLD
1025 void WING_kibitz::handleMsg(QString line)
1026 {
1027 static QString memory_str;
1028 static int memory = 0;
1029 line = line.remove(0, 2).trimmed();
1030 BoardDispatch * boarddispatch;
1031 qDebug("kibitz: %s", line.toLatin1().constData());
1032 if (line.contains("Kibitz"))
1033 {
1034 // who is kibitzer
1035 memory_str = element(line, 0, " ", ":");
1036 // game number
1037 memory = element(line, 1, "[", "]").toInt();
1038 }
1039 else
1040 {
1041 if (memory_str.isEmpty())
1042 // something went wrong...
1043 return;
1044 if(line.contains("Starting observation"))
1045 {
1046 QString name = element(memory_str, 0 , " ");
1047 QString rank = element(memory_str, 1, "[", "]");
1048 fixRankString(&rank);
1049 qDebug("%s %s joining", name.toLatin1().constData(), rank.toLatin1().constData());
1050 // send as kibitz from "0"
1051 ObserverListing ob(true, name, rank, rankToScore(rank));
1052 boarddispatch = getBoardDispatch(memory);
1053 if(!boarddispatch)
1054 {
1055 qDebug("No board dispatch for this game!");
1056 return;
1057 }
1058 boarddispatch->recvObserver(&ob);
1059 memory = 0;
1060 memory_str.clear();
1061 return;
1062 }
1063 else if(line.contains("has entered byo-yomi again") ||
1064 line.contains("is entering byo-yomi"))
1065 {
1066 qDebug("byo-yomi message");
1067 memory = 0;
1068 memory_str.clear();
1069 // just ignore though we could FIXME use it to
1070 // reset the time
1071 return;
1072 }
1073 else if(memory_str.contains("SgfComment"))
1074 {
1075 if(line.contains("dead @"))
1076 {
1077 boarddispatch = getBoardDispatch(memory);
1078 if(!boarddispatch)
1079 {
1080 qDebug("No board dispatch for this game!");
1081 return;
1082 }
1083 boarddispatch->recvEnterScoreMode();
1084 /* FIXME What if we're already in score mode,
1085 * what about the double pass signifying this??? */
1086 MoveRecord * aMove = new MoveRecord();
1087 aMove->flags = MoveRecord::REMOVE;
1088 QString point = element(line, 5, " ", "EOL");
1089 qDebug("Removal point: %s", point.toLatin1().constData());
1090
1091 aMove->x = (int)(point.toLatin1().at(0));
1092 aMove->x -= 'A';
1093 point.remove(0,1);
1094 aMove->y = element(point, 0, " ").toInt();
1095 GameListing * l = getDefaultRoom()->getGameListing(memory);
1096 if(!l)
1097 {
1098 qDebug("Move for unlisted game");
1099 delete aMove;
1100 return;
1101 }
1102 if(l->board_size > 9)
1103 {
1104 if(aMove->x < 9) //no I on IGS
1105 aMove->x++;
1106 aMove->y = 20 - aMove->y;
1107 }
1108 boarddispatch->recvMove(aMove);
1109 delete aMove;
1110 }
1111 memory = 0;
1112 memory_str.clear();
1113 return;
1114 }
1115 /* FIXME: Kibitz has this ugly little "->" which we might
1116 * want to cut off */
1117 //emit signal_kibitz(memory, memory_str, line);
1118 boarddispatch = getBoardDispatch(memory);
1119 if(boarddispatch)
1120 boarddispatch->recvKibitz(memory_str, line);
1121 memory = 0;
1122 memory_str.clear();
1123 }
1124 }
1125 #endif //OLD