| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2011 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 <math.h> |
| 25 | #include "cyberoroconnection.h" |
| 26 | #include "cyberoroprotocol.h" |
| 27 | #include "consoledispatch.h" |
| 28 | #include "room.h" |
| 29 | #include "boarddispatch.h" |
| 30 | #include "gamedialog.h" |
| 31 | #include "talk.h" |
| 32 | #include "serverlistdialog.h" |
| 33 | #include "codecwarndialog.h" |
| 34 | #include "matchinvitedialog.h" |
| 35 | #include "gamedialogflags.h" |
| 36 | #include "orosetphrasechat.h" |
| 37 | #include "setphrasepalette.h" |
| 38 | #include "createroomdialog.h" |
| 39 | #include "gamedata.h" |
| 40 | #include "playergamelistings.h" |
| 41 | #include "quickconnection.h" |
| 42 | #include "matchnegotiationstate.h" |
| 43 | #include <QMessageBox> |
| 44 | |
| 45 | #ifdef NEWPROTOCOL |
| 46 | #include "protocol.h" |
| 47 | #endif //NEWPROTOCOL |
| 48 | |
| 49 | #define ALLOW_ALL_INVITES 0 |
| 50 | #define ALLOW_STRONGER_INVITE 1 |
| 51 | #define ALLOW_EVEN_INVITE 2 |
| 52 | #define ALLOW_WEAKER_INVITE 3 |
| 53 | #define ALLOW_PAIR_INVITE 4 |
| 54 | #define IGNORE_ALL_INVITES 5 |
| 55 | |
| 56 | #define PLAYERLIST_SKIPNUMBER_UNSET 0xffff |
| 57 | |
| 58 | //#define RE_DEBUG |
| 59 | |
| 60 | const char * KoreanCodec = "eucKR"; |
| 61 | const char * ChineseCodec = "GB2312"; |
| 62 | const char * JapaneseCodec = "Shift-JIS"; |
| 63 | const char * LatinCodec = "ISO-8859-1"; |
| 64 | |
| 65 | CyberOroConnection::CyberOroConnection(const ConnectionCredentials credentials) |
| 66 | : NetworkConnection(credentials) |
| 67 | { |
| 68 | //Note that this is not world.cyberoro.com |
| 69 | //which right now is 91.91. |
| 70 | //This is gateway server which is sent login |
| 71 | //information and authenticates us to other |
| 72 | //servers that are provided on a list. */ |
| 73 | if(openConnection(hostname, port, NOT_MAIN_CONNECTION)) |
| 74 | { |
| 75 | setState(Login); |
| 76 | } |
| 77 | else |
| 78 | qDebug("Can't open Connection\n"); //throw error? |
| 79 | |
| 80 | textCodec = QTextCodec::codecForLocale(); |
| 81 | serverCodec = QTextCodec::codecForLocale(); |
| 82 | //FIXME check for validity of codecs ??? |
| 83 | ORO_setup_setphrases(); |
| 84 | |
| 85 | current_server_index = -1; |
| 86 | challenge_response = 0; |
| 87 | codetable = 0; |
| 88 | |
| 89 | room_were_in = 0; //lobby? |
| 90 | connecting_to_game_number = 0; |
| 91 | |
| 92 | matchKeepAliveTimerID = 0; |
| 93 | matchRequestKeepAliveTimerID = 0; |
| 94 | |
| 95 | /* We should either create the palette on creation of |
| 96 | * the connection, or have a button to activate it that |
| 97 | * appears when the room is connected */ |
| 98 | setphrasepalette = new SetPhrasePalette(this); |
| 99 | setphrasepalette->show(); |
| 100 | } |
| 101 | |
| 102 | CyberOroConnection::~CyberOroConnection() |
| 103 | { |
| 104 | if(setphrasepalette) |
| 105 | delete setphrasepalette; |
| 106 | qDebug("Destroying CyberORO connection"); |
| 107 | closeConnection(); |
| 108 | std::vector<ServerItem*>::iterator iter; |
| 109 | for(iter = serverList.begin(); iter != serverList.end(); iter++) |
| 110 | delete *iter; |
| 111 | if(challenge_response) |
| 112 | delete[] challenge_response; |
| 113 | if(codetable) |
| 114 | delete[] codetable; |
| 115 | } |
| 116 | |
| 117 | void CyberOroConnection::OnConnected() |
| 118 | { |
| 119 | /* Likely client version info */ |
| 120 | if(connectionState == Login) |
| 121 | { |
| 122 | sendLogin(); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void CyberOroConnection::sendText(QString) |
| 127 | { |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | void CyberOroConnection::sendDisconnect(void) |
| 132 | { |
| 133 | /* Yeah, FIXME, we don't want to send this |
| 134 | * when we're reconnecting... which means we |
| 135 | * need a special connection state ... yada yada */ |
| 136 | if(connectionState == Connected) |
| 137 | sendDisconnectMsg(); |
| 138 | } |
| 139 | |
| 140 | void CyberOroConnection::sendText(const char * text) |
| 141 | { |
| 142 | qDebug("Wanted to send %s", text); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | /* What about a room_id?? */ |
| 147 | void CyberOroConnection::sendMsg(unsigned int id, QString text) |
| 148 | { |
| 149 | if(id == 0) |
| 150 | { |
| 151 | sendServerChat(text); |
| 152 | return; |
| 153 | } |
| 154 | sendRoomChat(text.toLatin1().constData()); |
| 155 | } |
| 156 | |
| 157 | void CyberOroConnection::sendMsg(PlayerListing * player, QString text) |
| 158 | { |
| 159 | sendPersonalChat(player, text.toLatin1().constData()); |
| 160 | } |
| 161 | |
| 162 | void CyberOroConnection::sendToggle(const QString & param, bool val) |
| 163 | { |
| 164 | /* FIXME, more to do here probably */ |
| 165 | qDebug("Setting open %d", val); |
| 166 | if(param == "open") |
| 167 | sendInvitationSettings(val); |
| 168 | } |
| 169 | |
| 170 | /* If we can observe something besides games, |
| 171 | * like rooms or people, then this name is a bit |
| 172 | * iffy too... */ |
| 173 | void CyberOroConnection::sendObserve(const GameListing *game) |
| 174 | { |
| 175 | connecting_to_game_number = game->number; |
| 176 | sendObserveAfterJoining(game); |
| 177 | } |
| 178 | |
| 179 | void CyberOroConnection::adjournGame(const GameListing * ) |
| 180 | { |
| 181 | } |
| 182 | |
| 183 | void CyberOroConnection::closeBoardDispatch(unsigned int game_id) |
| 184 | { |
| 185 | /* This isn't quite right, we need to send a leave if |
| 186 | * we close a window, but its not necessarily an adjournGame. |
| 187 | * At the same time, I think dispatch needs to remain open |
| 188 | * after game like a room, to talk in */ |
| 189 | GameListing * g = getDefaultRoom()->getGameListing(game_id); |
| 190 | /* I've been saving boards that have results but I think maybe that's |
| 191 | * supposed to be for betting matches in general. I.e., we should check |
| 192 | * here if we need to save the board */ |
| 193 | if(g->isBetting || g->result != QString()) |
| 194 | { |
| 195 | BoardDispatch * b = getIfBoardDispatch(game_id); |
| 196 | b->saveRecordToGameData(); |
| 197 | } |
| 198 | /* Looks like finish observing is sent for both |
| 199 | * also possibly finish observing used in matches somehow as well? */ |
| 200 | /* Order here matters apparently, leave is for leaving the room, |
| 201 | FinishObserving says we're no longer looking at board. |
| 202 | FIXME doublecheck |
| 203 | No, that didn't fix it.*/ |
| 204 | if(room_were_in == g->number) |
| 205 | sendLeave(g); |
| 206 | sendFinishObserving(g); |
| 207 | |
| 208 | NetworkConnection::closeBoardDispatch(game_id); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | /* I'd like to just send the match invite, but only if we're not |
| 213 | * in the same room... actually, maybe its almost like a room invite */ |
| 214 | void CyberOroConnection::sendMatchRequest(MatchRequest * mr) |
| 215 | { |
| 216 | /* Right now, we're working with this from the stand point of |
| 217 | * the counter offer. The gamedialog needs to check if |
| 218 | * anything has changed and then do acceptOffer. */ |
| 219 | sendMatchOffer(*mr, true); |
| 220 | } |
| 221 | |
| 222 | /* Note that we could ignore the dispute time one and change whatever |
| 223 | * we wanted to, but its kind of cheap to the other player who can't |
| 224 | * see what we changed. */ |
| 225 | unsigned long CyberOroConnection::getGameDialogFlags(void) |
| 226 | { |
| 227 | return (GDF_CANADIAN | GDF_BYOYOMI | GDF_TVASIA | GDF_FREE_RATED_CHOICE |
| 228 | | GDF_RATED_SIZE_FIXED | GDF_RATED_HANDICAP_FIXED |
| 229 | | GDF_NIGIRI_EVEN | GDF_ONLY_DISPUTE_TIME |
| 230 | | GDF_BY_CAN_MAIN_MIN); |
| 231 | } |
| 232 | |
| 233 | void CyberOroConnection::declineMatchOffer(const PlayerListing * opponent) |
| 234 | { |
| 235 | qDebug("Declining match offer"); |
| 236 | /* If this is our offer, we need to sendMatchOfferCancel FIXME */ |
| 237 | sendDeclineMatchOffer(opponent); |
| 238 | // do we also need to leave the room? |
| 239 | } |
| 240 | |
| 241 | void CyberOroConnection::cancelMatchOffer(const PlayerListing * opponent) |
| 242 | { |
| 243 | qDebug("Canceling match offer"); |
| 244 | sendMatchOfferCancel(opponent); |
| 245 | } |
| 246 | |
| 247 | void CyberOroConnection::acceptMatchOffer(const PlayerListing * /*opponent*/, MatchRequest * mr) |
| 248 | { |
| 249 | /* FIXME, we should really just move the real code in here instead |
| 250 | * of the extra layer of indication... when its done. */ |
| 251 | sendMatchOffer(*mr); |
| 252 | } |
| 253 | |
| 254 | void CyberOroConnection::handlePendingData() |
| 255 | { |
| 256 | unsigned char * c; |
| 257 | unsigned char header[4]; |
| 258 | unsigned int packet_size; |
| 259 | int bytes; |
| 260 | |
| 261 | /* We need better connection states, but we'll use the old |
| 262 | * for now */ |
| 263 | |
| 264 | switch(connectionState) |
| 265 | { |
| 266 | case Login: |
| 267 | bytes = qsocket->bytesAvailable(); |
| 268 | if(bytes) |
| 269 | { |
| 270 | QByteArray data = qsocket->readAll(); |
| 271 | //0004064d |
| 272 | |
| 273 | #ifdef RE_DEBUG |
| 274 | for(int i = 0; i < bytes; i++) |
| 275 | printf("%02x", c[i]); |
| 276 | printf("\n"); |
| 277 | #endif //RE_DEBUG |
| 278 | //1f27080015270000 |
| 279 | if(data.constData()[0] == 0x1f) |
| 280 | { |
| 281 | qDebug("CyberOroConnection::handlePendingData() : Bad password or login"); |
| 282 | setState(PassFailed); |
| 283 | //closeConnection(); |
| 284 | return; |
| 285 | } |
| 286 | /* First packet is list of servers and ips */ |
| 287 | else if(data.constData()[0] == 0x24) |
| 288 | handleServerList((unsigned char *)data.data()); |
| 289 | } |
| 290 | break; |
| 291 | case Connected: |
| 292 | while((bytes = qsocket->bytesAvailable()) > 0) |
| 293 | { |
| 294 | qsocket->peek((char *)header, 4); |
| 295 | #ifdef RE_DEBUG |
| 296 | printf("%02x%02x%02x%02x\n", header[0], header[1], header[2], header[3]); |
| 297 | #endif //RE_DEBUG |
| 298 | packet_size = header[2] + (header[3] << 8); |
| 299 | if((unsigned)bytes < packet_size) |
| 300 | break; |
| 301 | c = new unsigned char[packet_size]; |
| 302 | qsocket->read((char*)c, packet_size); |
| 303 | handleMessage(c, packet_size); |
| 304 | delete[] c; |
| 305 | } |
| 306 | break; |
| 307 | case Canceled: |
| 308 | case Reconnecting: |
| 309 | break; |
| 310 | /*case AUTH_FAILED: |
| 311 | qDebug("Auth failed\n"); |
| 312 | break;*/ |
| 313 | default: |
| 314 | qDebug("connection state not handled by ORO"); |
| 315 | break; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /* FIXME, these need to be const msg refs I think */ |
| 320 | /* They also need to be reordered in a more intuitive manner |
| 321 | * after we get the IGS cruft out */ |
| 322 | void CyberOroConnection::handleServerList(unsigned char * msg) |
| 323 | { |
| 324 | unsigned char * p = msg; |
| 325 | unsigned char * s; |
| 326 | int servers, i; |
| 327 | int ip_string_length, server_name_length; |
| 328 | ServerItem * si; |
| 329 | |
| 330 | if(p[0] != 0x24 || p[1] != 0x27) |
| 331 | { |
| 332 | qDebug("Non standard server list msg header"); //unnecessary check FIXME |
| 333 | printf("%02x %02x", p[0], p[1]); |
| 334 | } |
| 335 | p += 4; |
| 336 | challenge_response = new unsigned char[106]; |
| 337 | for(i = 0; i < 106; i++) |
| 338 | challenge_response[i] = p[i]; |
| 339 | p += 108; //106 + 01 00 |
| 340 | servers = p[1]; |
| 341 | /* FIXME, I no longer think that this is the number of |
| 342 | * servers. I think there are always 8 */ |
| 343 | /* Actually, I think it is the number of servers but some of them |
| 344 | * are not game servers... */ |
| 345 | servers = 8; |
| 346 | #ifdef RE_DEBUG |
| 347 | qDebug("Servers: %d", servers); |
| 348 | printf("\n"); |
| 349 | for(i = 0; i < 20; i++) |
| 350 | printf("%02x ", p[i]); |
| 351 | printf("\n"); |
| 352 | #endif //RE_DEBUG |
| 353 | p += 2; |
| 354 | for(i = 0; i < servers; i++) |
| 355 | { |
| 356 | /* If the first byte is 0x0a, right before the ip, that |
| 357 | * might indicate full, the byte before that then might |
| 358 | * be the language of the previous server entry. */ |
| 359 | si = new ServerItem(); |
| 360 | ip_string_length = 0; |
| 361 | server_name_length = 0; |
| 362 | s = p + 16; |
| 363 | strncpy(si->ipaddress, (const char *)p, 16); |
| 364 | while(p < s && *p != 0x00) |
| 365 | { |
| 366 | #ifdef RE_DEBUG |
| 367 | printf("%c", *p); |
| 368 | #endif //RE_DEBUG |
| 369 | p++; |
| 370 | ip_string_length++; |
| 371 | } |
| 372 | #ifdef RE_DEBUG |
| 373 | printf(" -> "); |
| 374 | #endif //RE_DEBUG |
| 375 | // pad out to 15 (max ip length |
| 376 | p += (16 - ip_string_length); |
| 377 | s = p + 16; |
| 378 | //strncpy(si->name, (const char *)p, 18); |
| 379 | si->name = QString((char *)p); |
| 380 | while(p < s && *p != 0x00) |
| 381 | { |
| 382 | #ifdef RE_DEBUG |
| 383 | printf("%c", *p); |
| 384 | #endif //RE_DEBUG |
| 385 | p++; |
| 386 | server_name_length++; |
| 387 | } |
| 388 | |
| 389 | p += (16 - server_name_length); |
| 390 | printf("\n"); |
| 391 | serverList.push_back(si); |
| 392 | #ifdef RE_DEBUG |
| 393 | printf("Language byte: %02x\n", p[0]); |
| 394 | #endif //RE_DEBUG |
| 395 | switch(p[0]) |
| 396 | { |
| 397 | case 1: |
| 398 | si->codec = (char *)KoreanCodec; |
| 399 | break; |
| 400 | case 2: |
| 401 | si->codec = (char *)ChineseCodec; |
| 402 | break; |
| 403 | case 3: |
| 404 | si->codec = (char *)JapaneseCodec; |
| 405 | break; |
| 406 | case 6: |
| 407 | si->codec = (char *)LatinCodec; |
| 408 | break; |
| 409 | default: |
| 410 | break; |
| 411 | } |
| 412 | p += 2; |
| 413 | } |
| 414 | /* We should really check for overflows here so that we don't run out |
| 415 | * of packet. FIXME FIXME FIXME 1046 bytes every time*/ |
| 416 | |
| 417 | /* We close here because this first time, its going to close |
| 418 | * anyway, and if we don't close here, we'll get an error |
| 419 | * and lose the object */ |
| 420 | |
| 421 | |
| 422 | //requestAccountInfo(); //this will close this connection |
| 423 | closeConnection(false); |
| 424 | setState(Reconnecting); |
| 425 | requestAccountInfo(); |
| 426 | if(reconnectToServer() < 0) |
| 427 | { |
| 428 | qDebug("User canceled"); |
| 429 | setState(Canceled); |
| 430 | return; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | void CyberOroConnection::changeServer(void) |
| 435 | { |
| 436 | qDebug("changeServer called"); |
| 437 | if(connectionState != Connected) |
| 438 | return; |
| 439 | if(reconnectToServer() < 0) |
| 440 | { |
| 441 | qDebug("User canceled"); |
| 442 | return; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | void CyberOroConnection::createRoom(void) |
| 447 | { |
| 448 | CreateRoomDialog * createroomdialog = new CreateRoomDialog(this); |
| 449 | createroomdialog->exec(); |
| 450 | } |
| 451 | |
| 452 | /* FIXME we need error handling here, a return value, something |
| 453 | * or at least we need to call the right destructors throughout, |
| 454 | * and safely. */ |
| 455 | int CyberOroConnection::reconnectToServer(void) |
| 456 | { |
| 457 | /* FIXME, we need to add something to specify the server we're |
| 458 | * currently on */ |
| 459 | /* FIXME, why does the serverReconnectDialog disappear the ui |
| 460 | * elements in the server window ?!?!? */ |
| 461 | ServerListDialog * serverReconnectDialog = new ServerListDialog(serverList, current_server_index); |
| 462 | int server_i = serverReconnectDialog->exec(); |
| 463 | if(server_i < 0 || server_i == QDialog::Rejected) |
| 464 | return -1; |
| 465 | server_i--; |
| 466 | if(!this) |
| 467 | { |
| 468 | /* FIXME, this needs to be much better. It should be, |
| 469 | * to start with, irrelevant. */ |
| 470 | qDebug("Waited too long to connect"); |
| 471 | return -1; |
| 472 | } |
| 473 | current_server_index = server_i; |
| 474 | |
| 475 | /* FIXME |
| 476 | * Might be neat if we listed the server that one was currently on |
| 477 | * somewhere, like on the main window. */ |
| 478 | if(serverList.size() <= (unsigned)server_i) |
| 479 | { |
| 480 | qDebug("serverList has probably been freed when you weren't looking"); |
| 481 | return -1; |
| 482 | } |
| 483 | |
| 484 | qDebug("Reconnecting to %s: %s...", serverList[server_i]->name.toLatin1().constData(), serverList[server_i]->ipaddress); |
| 485 | |
| 486 | if(connectionState == Connected) |
| 487 | closeConnection(false); |
| 488 | /* Though connection isn't really negotiated yet, |
| 489 | * we can get here without a playerListingIDRegistry as soon |
| 490 | * as the connection is opened, so we're going to do this |
| 491 | * first. FIXME for other protocols */ |
| 492 | onAuthenticationNegotiated(); |
| 493 | if(openConnection(serverList[server_i]->ipaddress, 7002)) |
| 494 | { |
| 495 | qDebug("Reconnected"); |
| 496 | setState(Connected); |
| 497 | game_code_to_number.clear(); |
| 498 | } |
| 499 | else |
| 500 | { |
| 501 | /* FIXME This can happen, for instance two of the china servers gave connection refused errors |
| 502 | * which left the select server drop down menu grayed out!!! Add handling for this! */ |
| 503 | qDebug("Can't open Connection!!"); |
| 504 | } |
| 505 | /* FIXME, really we should set server init variables in a function |
| 506 | * called from here on every reconnect, not on connection object allocation*/ |
| 507 | playerlist_skipnumber = PLAYERLIST_SKIPNUMBER_UNSET; |
| 508 | playerlist_received = 0; |
| 509 | roomlist_observers = 0; |
| 510 | playerlist_roomnumber = 1; |
| 511 | playerlist_observernumber = 0; |
| 512 | |
| 513 | if(server_i > 6) |
| 514 | qDebug("Please don't try to connect to the voice, we don't know what that is"); |
| 515 | |
| 516 | serverCodec = QTextCodec::codecForName(getCodecString()); |
| 517 | if(!serverCodec) |
| 518 | { |
| 519 | new CodecWarnDialog(getCodecString()); |
| 520 | serverCodec = QTextCodec::codecForLocale(); |
| 521 | } |
| 522 | |
| 523 | // this is the initial packet |
| 524 | const unsigned char packet[8] = { 0x0a, 0xfa, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 525 | if(write((const char *)packet, 8) < 0) |
| 526 | qWarning("*** failed sending init packet to reconnected host"); |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | /* Check comment in networkconnection code, FIXME */ |
| 531 | // Why is this function different for this connection type? |
| 532 | // Because player tracking is by ID, not name, for CyberOro |
| 533 | const PlayerListing * CyberOroConnection::getOurListing(void) |
| 534 | { |
| 535 | ourListing = getDefaultRoom()->getPlayerListing(our_player_id); |
| 536 | return ourListing; |
| 537 | } |
| 538 | |
| 539 | void CyberOroConnection::sendPersonalChat(const PlayerListing * player, const char * text) |
| 540 | { |
| 541 | unsigned int length = strlen(text) + 12; |
| 542 | char *packet = new char[length]; |
| 543 | int i; |
| 544 | |
| 545 | packet[0] = 0xe2; |
| 546 | packet[1] = 0x59; |
| 547 | packet[2] = length & 0x00ff; |
| 548 | packet[3] = (length >> 8); |
| 549 | packet[4] = player->id & 0x00ff; |
| 550 | packet[5] = (player->id >> 8); |
| 551 | packet[6] = player->specialbyte; |
| 552 | packet[7] = 0x00; |
| 553 | packet[8] = our_player_id & 0x00ff; |
| 554 | packet[9] = (our_player_id >> 8); |
| 555 | //their id 93[62]00 (maybe a room), id?, 00 00 |
| 556 | packet[10] = 0x00; |
| 557 | packet[11] = 0x00; |
| 558 | for(i = 12; i < (int)length; i++) |
| 559 | packet[i] = text[i - 12]; |
| 560 | #ifdef RE_DEBUG |
| 561 | printf("Before encode\n"); |
| 562 | for(i = 0; i < (int)length; i++) |
| 563 | printf("%02x ", (unsigned char)packet[i]); |
| 564 | printf("\n"); |
| 565 | #endif //RE_DEBUG |
| 566 | encode((unsigned char *)packet, 0xc); |
| 567 | #ifdef RE_DEBUG |
| 568 | printf("Sending personal chat\n"); |
| 569 | for(i = 0; i < (int)length; i++) |
| 570 | printf("%02x ", (unsigned char)packet[i]); |
| 571 | printf("\n"); |
| 572 | #endif //RE_DEBUG |
| 573 | if(write((const char *)packet, length) < 0) |
| 574 | qWarning("*** failed sending personal chat"); |
| 575 | delete[] packet; |
| 576 | } |
| 577 | |
| 578 | // there's a room chat, looks like |
| 579 | //ec 59 size our_id 00 00 text with encode 8 |
| 580 | /* But I don't see the room id so I'm confused */ |
| 581 | //FIXME |
| 582 | /* Now I'm thinking it just goes to the room we're in */ |
| 583 | void CyberOroConnection::sendRoomChat(const char * text) |
| 584 | { |
| 585 | unsigned int length = strlen(text) + 8; |
| 586 | char *packet = new char[length]; |
| 587 | int i; |
| 588 | |
| 589 | packet[0] = 0xec; |
| 590 | packet[1] = 0x59; |
| 591 | packet[2] = length & 0x00ff; |
| 592 | packet[3] = (length >> 8); |
| 593 | packet[4] = our_player_id & 0x00ff; |
| 594 | packet[5] = (our_player_id >> 8); |
| 595 | packet[6] = 0x00; |
| 596 | packet[7] = 0x00; //dc? font? |
| 597 | for(i = 8; i < (int)length; i++) |
| 598 | packet[i] = text[i - 8]; |
| 599 | #ifdef RE_DEBUG |
| 600 | printf("Before encode\n"); |
| 601 | for(i = 0; i < (int)length; i++) |
| 602 | printf("%02x ", (unsigned char)packet[i]); |
| 603 | printf("\n"); |
| 604 | #endif //RE_DEBUG |
| 605 | encode((unsigned char *)packet, 0x8); |
| 606 | #ifdef RE_DEBUG |
| 607 | printf("Sending room chat\n"); |
| 608 | for(i = 0; i < (int)length; i++) |
| 609 | printf("%02x ", (unsigned char)packet[i]); |
| 610 | printf("\n"); |
| 611 | #endif //RE_DEBUG |
| 612 | if(write((const char *)packet, length) < 0) |
| 613 | qWarning("*** failed sending room chat"); |
| 614 | delete[] packet; |
| 615 | } |
| 616 | |
| 617 | void CyberOroConnection::sendServerChat(QString text) |
| 618 | { |
| 619 | unsigned int length = text.size() + 8; |
| 620 | unsigned char *packet = new unsigned char[length]; |
| 621 | int i; |
| 622 | |
| 623 | packet[0] = 0x0a; |
| 624 | packet[1] = 0x5a; |
| 625 | packet[2] = length & 0x00ff; |
| 626 | packet[3] = (length >> 8); |
| 627 | packet[4] = our_player_id & 0x00ff; |
| 628 | packet[5] = (our_player_id >> 8); |
| 629 | packet[6] = 0x00; |
| 630 | packet[7] = 0x00; //i've seen 40 here |
| 631 | for(i = 8; i < (int)length; i++) |
| 632 | packet[i] = text.toLatin1().constData()[i - 8]; |
| 633 | |
| 634 | encode(packet, 0x8); |
| 635 | if(write((const char *)packet, length) < 0) |
| 636 | qWarning("*** failed sending server char"); |
| 637 | delete[] packet; |
| 638 | } |
| 639 | |
| 640 | void CyberOroConnection::sendSetChatMsg(unsigned short phrase_id) |
| 641 | { |
| 642 | unsigned int length = 20; |
| 643 | unsigned char *packet = new unsigned char[length]; |
| 644 | |
| 645 | packet[0] = 0x55; |
| 646 | packet[1] = 0xc3; |
| 647 | packet[2] = length & 0x00ff; |
| 648 | packet[3] = (length >> 8); |
| 649 | packet[4] = our_player_id & 0x00ff; |
| 650 | packet[5] = (our_player_id >> 8); |
| 651 | packet[6] = 0xff; //probably their id if directed? |
| 652 | packet[7] = 0xff; |
| 653 | packet[8] = 0x01; |
| 654 | packet[9] = 0x00; |
| 655 | packet[10] = 0x00; |
| 656 | packet[11] = 0x00; |
| 657 | packet[12] = phrase_id & 0x00ff; |
| 658 | packet[13] = (phrase_id >> 8); |
| 659 | packet[14] = 0x00; |
| 660 | packet[15] = 0x00; |
| 661 | |
| 662 | packet[16] = 0x00; |
| 663 | packet[17] = 0x00; |
| 664 | packet[18] = 0x00; |
| 665 | packet[19] = 0x00; |
| 666 | |
| 667 | encode(packet, 0x14); |
| 668 | if(write((const char *)packet, length) < 0) |
| 669 | qWarning("*** failed sending set chat msg"); |
| 670 | delete[] packet; |
| 671 | } |
| 672 | |
| 673 | void CyberOroConnection::sendJoinRoom(const RoomListing & room, const char * password) |
| 674 | { |
| 675 | unsigned int length = 18; |
| 676 | unsigned char * packet = new unsigned char[length]; |
| 677 | int i; |
| 678 | |
| 679 | packet[0] = 0xde; |
| 680 | packet[1] = 0x5d; |
| 681 | packet[2] = 0x12; |
| 682 | packet[3] = 0x00;; |
| 683 | packet[4] = our_player_id & 0x00ff; |
| 684 | packet[5] = (our_player_id >> 8); |
| 685 | packet[6] = room.number & 0x00ff; |
| 686 | packet[7] = (room.number >> 8); |
| 687 | //password padded out to ten bytes with zeroes |
| 688 | //FIXME, but password only 8 in create room??? |
| 689 | if(password) |
| 690 | { |
| 691 | for(i = 0; i < (int)strlen(password); i++) |
| 692 | packet[8 + i] = password[i]; |
| 693 | for(i = 9; i >= (int)strlen(password); i--) |
| 694 | packet[8 + i] = 0x00; |
| 695 | } |
| 696 | else |
| 697 | { |
| 698 | for(i = 8; i < 18; i++) |
| 699 | packet[i] = 0x00; |
| 700 | } |
| 701 | qDebug("Sending join room"); |
| 702 | encode(packet, 0x12); |
| 703 | if(write((const char *)packet, length) < 0) |
| 704 | qWarning("*** failed sending join room"); |
| 705 | delete[] packet; |
| 706 | } |
| 707 | |
| 708 | void CyberOroConnection::sendObserveOutside(const GameListing *game) |
| 709 | { |
| 710 | unsigned int length = 10; |
| 711 | char *packet = new char[length]; |
| 712 | |
| 713 | /* We need to turn this to a join if its a room, not a game |
| 714 | * otherwise bad things happen FIXME */ |
| 715 | if(!game->game_code) |
| 716 | { |
| 717 | qDebug("No game code for %d", game->number); |
| 718 | // can we send number instead? where was the game code? |
| 719 | delete[] packet; |
| 720 | return; |
| 721 | } |
| 722 | packet[0] = 0x40; |
| 723 | packet[1] = 0x9c; |
| 724 | packet[2] = 0x0a; |
| 725 | packet[3] = 0x00; |
| 726 | packet[4] = our_player_id & 0x00ff; |
| 727 | packet[5] = (our_player_id >> 8); |
| 728 | packet[6] = game->game_code & 0x00ff; |
| 729 | packet[7] = (game->game_code >> 8); |
| 730 | packet[8] = 0x00; |
| 731 | packet[9] = 0x00; //careful could be something else? FIXME |
| 732 | //our id game id then ED0B, maybe two random bytes? time? |
| 733 | #ifdef RE_DEBUG |
| 734 | printf("Sending observe outside to %s vs %s: %d ", game.white_name().toLatin1().constData(), game.black_name().toLatin1().constData(), game.game_code); |
| 735 | for(unsigned int i = 0; i < length; i++) |
| 736 | printf("%02x ", (unsigned char)packet[i]); |
| 737 | printf("\n"); |
| 738 | #endif //RE_DEBUG |
| 739 | encode((unsigned char *)packet, 0xa); |
| 740 | if(write((const char *)packet, length) < 0) |
| 741 | qWarning("*** failed sending observe outside"); |
| 742 | delete[] packet; |
| 743 | |
| 744 | connecting_to_game_number = game->number; |
| 745 | } |
| 746 | |
| 747 | /* This is a subcase of sendJoinRoom, we should fix that up |
| 748 | * and add a password prompt FIXME */ |
| 749 | void CyberOroConnection::sendObserveAfterJoining(const GameListing *game) |
| 750 | { |
| 751 | unsigned int length = 18; |
| 752 | char *packet = new char[length]; |
| 753 | int i; |
| 754 | |
| 755 | /* Observing a room definitely uses game number over game_code. |
| 756 | * weird... DOUBLECHECK */ |
| 757 | packet[0] = 0xde; |
| 758 | packet[1] = 0x5d; |
| 759 | packet[2] = 0x12; |
| 760 | packet[3] = 0x00; |
| 761 | packet[4] = our_player_id & 0x00ff; |
| 762 | packet[5] = (our_player_id >> 8); |
| 763 | packet[6] = game->number & 0x00ff; |
| 764 | packet[7] = (game->number >> 8); |
| 765 | for(i = 8; i < (int)length; i++) |
| 766 | packet[i] = 0x00; //password in here? all password? |
| 767 | #ifdef RE_DEBUG |
| 768 | printf("Sending observe to %s vs %s: %d (%d)\n", game.white_name().toLatin1().constData(), game.black_name().toLatin1().constData(), game.game_code, game.number); //crash here ?!?! |
| 769 | for(i = 0; i < (int)length; i++) |
| 770 | printf("%02x ", (unsigned char)packet[i]); |
| 771 | printf("\n"); |
| 772 | #endif //RE_DEBUG |
| 773 | encode((unsigned char *)packet, 0x12); |
| 774 | if(write((const char *)packet, length) < 0) |
| 775 | qWarning("*** failed sending observe"); |
| 776 | delete[] packet; |
| 777 | setRoomNumber(game->number); |
| 778 | } |
| 779 | |
| 780 | void CyberOroConnection::sendFinishObserving(const GameListing *game) |
| 781 | { |
| 782 | unsigned int length = 14; |
| 783 | char *packet = new char[length]; |
| 784 | int i; |
| 785 | |
| 786 | packet[0] = 0x45; |
| 787 | packet[1] = 0x9c; |
| 788 | packet[2] = 0x0e; |
| 789 | packet[3] = 0x00; |
| 790 | packet[4] = game->game_code & 0x00ff; |
| 791 | packet[5] = (game->game_code >> 8); |
| 792 | packet[6] = our_player_id & 0x00ff; |
| 793 | packet[7] = (our_player_id >> 8); |
| 794 | for(i = 8; i < 14; i++) |
| 795 | packet[i] = 0x00; |
| 796 | //and then? 0x54 instead of last 0x00? //I'm thinking 0e encode |
| 797 | // overwrites this and then it gets passed back to us in reply |
| 798 | encode((unsigned char *)packet, 0xe); |
| 799 | #ifdef RE_DEBUG |
| 800 | qDebug("Sending finish observing"); |
| 801 | #endif //RE_DEBUG |
| 802 | if(write((const char *)packet, length) < 0) |
| 803 | qWarning("*** failed sending finish observing"); |
| 804 | delete[] packet; |
| 805 | //setRoomNumber(0); |
| 806 | } |
| 807 | |
| 808 | void CyberOroConnection::sendCreateRoom(RoomCreate * room) |
| 809 | { |
| 810 | unsigned int length = 64; |
| 811 | char *packet = new char[length]; |
| 812 | int i; |
| 813 | |
| 814 | if(!room) |
| 815 | { |
| 816 | qDebug("CreateRoom called on NULL room!!"); |
| 817 | delete[] packet; |
| 818 | return; |
| 819 | } |
| 820 | if((room->title && strlen((const char *)room->title) > 20) || |
| 821 | (room->password && strlen((const char *)room->password) > 8)) |
| 822 | { |
| 823 | qDebug("Can't create room, bad title or password"); |
| 824 | delete[] packet; |
| 825 | return; |
| 826 | } |
| 827 | packet[0] = 0xca; |
| 828 | packet[1] = 0x5d; |
| 829 | packet[2] = 0x40; |
| 830 | packet[3] = 0x00; |
| 831 | packet[4] = our_player_id & 0x00ff; |
| 832 | packet[5] = (our_player_id >> 8); |
| 833 | packet[6] = 0x00; |
| 834 | packet[7] = 0x00; |
| 835 | packet[8] = 0x00; |
| 836 | packet[9] = 0x00; |
| 837 | |
| 838 | |
| 839 | packet[10] = (room->title ? 0x80 : 0x00) | (room->password ? 0x40 : 0x00); |
| 840 | //packet[10] = 0xc0; //80 open //stronger quick 1:1 general password |
| 841 | |
| 842 | //set 0 before hand |
| 843 | packet[11] = 0x00; |
| 844 | packet[12] = 0x00; |
| 845 | packet[13] = 0x00; |
| 846 | packet[14] = 0x00; |
| 847 | packet[15] = 0x00; |
| 848 | packet[16] = 0x00; |
| 849 | switch(room->type) |
| 850 | { |
| 851 | /* gomoku appears to use settings from game tab |
| 852 | * what's the difference? it automatically starts when |
| 853 | * someone joins? */ |
| 854 | //gomoku equal player standard time |
| 855 | //00 09 11 |
| 856 | case RoomCreate::GOMOKU: |
| 857 | case RoomCreate::GAME: |
| 858 | if(room->type == RoomCreate::GOMOKU) |
| 859 | packet[11] = 0x09; |
| 860 | else |
| 861 | packet[11] = 0x00; |
| 862 | packet[12] = ((unsigned char)room->opponentStrength << 4) | |
| 863 | (unsigned char)room->timeLimit; |
| 864 | |
| 865 | break; |
| 866 | case RoomCreate::CHAT: |
| 867 | packet[11] = 0xc0 | (unsigned char)room->topic; |
| 868 | packet[12] = 0x00 | (unsigned char)room->location; |
| 869 | //chat c1 21 movies -9 china |
| 870 | //chat c0 c0 baduk all ages korea |
| 871 | //chat cf 08 etc 70+ etc |
| 872 | //chat c5 a3 manga 40-49 thai |
| 873 | //chat c6 c4 humour 50-59 US |
| 874 | qDebug("Unsupported Room Type"); |
| 875 | return; |
| 876 | break; |
| 877 | case RoomCreate::REVIEW: |
| 878 | packet[11] = 0x80; |
| 879 | |
| 880 | packet[14] = 0x02; //live //00 teaching |
| 881 | //below 10k live commentary review |
| 882 | //00 80 00 00 02 10 |
| 883 | //below 11k teaching focused |
| 884 | //00 80 00 00 00 11 04 |
| 885 | //below 6d live |
| 886 | //00 80 00 00 02 01 |
| 887 | qDebug("Unsupported Room Type"); |
| 888 | return; |
| 889 | break; |
| 890 | case RoomCreate::MULTI: |
| 891 | //multi must be below or at(doublecheck?) your rank |
| 892 | //multi 7 20m 20m below 10k |
| 893 | //00 80 00 07 03 10 02 |
| 894 | //multi 6 15m 30m below 13k |
| 895 | //00 80 00 06 04 13 01 |
| 896 | qDebug("Unsupported Room Type"); |
| 897 | return; |
| 898 | break; |
| 899 | case RoomCreate::VARIATION: |
| 900 | qDebug("Unsupported Room Type"); |
| 901 | return; |
| 902 | break; |
| 903 | } |
| 904 | |
| 905 | for(i = 17; i < 26; i++) |
| 906 | packet[i] = 0x00; |
| 907 | //title padded to 20 |
| 908 | if(room->title) |
| 909 | { |
| 910 | for(i = 0; i < (int)strlen((const char *)room->title); i++) |
| 911 | packet[26 + i] = room->title[i]; |
| 912 | for(i = 19; i >= (int)strlen((const char *)room->title); i--) |
| 913 | packet[26 + i] = 0x00; |
| 914 | } |
| 915 | else |
| 916 | { |
| 917 | for(i = 26; i < 46; i++) |
| 918 | packet[i] = 0x00; |
| 919 | } |
| 920 | for(i = 46; i < 56; i++) |
| 921 | packet[i] = 0x00; |
| 922 | //password padded to 8 |
| 923 | if(room->password) |
| 924 | { |
| 925 | for(i = 0; i < (int)strlen((const char *)room->password); i++) |
| 926 | packet[56 + i] = room->password[i]; |
| 927 | for(i = 7; i >= (int)strlen((const char *)room->password); i--) |
| 928 | packet[56 + i] = 0x00; |
| 929 | } |
| 930 | else |
| 931 | { |
| 932 | for(i = 56; i < 64; i++) |
| 933 | packet[i] = 0x00; |
| 934 | } |
| 935 | |
| 936 | encode((unsigned char *)packet, 0x1a); |
| 937 | qDebug("Sending create room"); |
| 938 | if(write((const char *)packet, length) < 0) |
| 939 | qWarning("*** failed sending create room"); |
| 940 | delete[] packet; |
| 941 | //setRoomNumber(0); |
| 942 | delete room; |
| 943 | } |
| 944 | |
| 945 | void CyberOroConnection::sendMatchInvite(const PlayerListing * player) |
| 946 | { |
| 947 | qDebug("room were in %d room there in %d", room_were_in, player->observing); |
| 948 | /* We'll need to check that they're in the same room as we |
| 949 | * are, in which case, we could just popup the dialog */ |
| 950 | if(room_were_in && player->observing == room_were_in) |
| 951 | { |
| 952 | sendMatchOfferPending(player); |
| 953 | } |
| 954 | else |
| 955 | sendMatchInvite(player, false); |
| 956 | } |
| 957 | |
| 958 | /* note that this only enters the match offer dialog |
| 959 | * it doesn't accept the game.*/ |
| 960 | void CyberOroConnection::sendMatchInvite(const PlayerListing * player, bool accepting) |
| 961 | { |
| 962 | #ifdef FIXME |
| 963 | if(!match_negotiation_state->newMatchAllowed()) //really should be handled elsewhere FIXME |
| 964 | return; |
| 965 | #endif //FIXME |
| 966 | unsigned int length = 16; |
| 967 | unsigned char * packet = new unsigned char[length]; |
| 968 | |
| 969 | if(accepting) |
| 970 | packet[0] = 0x86; |
| 971 | else |
| 972 | packet[0] = 0x22; |
| 973 | packet[1] = 0x79; |
| 974 | packet[2] = 0x10; |
| 975 | packet[3] = 0x00; |
| 976 | if(accepting) |
| 977 | { |
| 978 | packet[4] = player->id & 0x00ff; |
| 979 | packet[5] = (player->id >> 8); |
| 980 | packet[6] = player->specialbyte; |
| 981 | } |
| 982 | else |
| 983 | { |
| 984 | packet[4] = our_player_id & 0x00ff; |
| 985 | packet[5] = (our_player_id >> 8); |
| 986 | packet[6] = our_special_byte; |
| 987 | } |
| 988 | packet[7] = 0x00; |
| 989 | if(accepting) |
| 990 | { |
| 991 | packet[8] = our_player_id & 0x00ff; |
| 992 | packet[9] = (our_player_id >> 8); |
| 993 | packet[10] = our_special_byte; |
| 994 | } |
| 995 | else |
| 996 | { |
| 997 | packet[8] = player->id & 0x00ff; |
| 998 | packet[9] = (player->id >> 8); |
| 999 | packet[10] = player->specialbyte; |
| 1000 | } |
| 1001 | packet[11] = 0x00; |
| 1002 | |
| 1003 | packet[12] = 0x00; |
| 1004 | packet[13] = 0x00; |
| 1005 | packet[14] = 0x00; |
| 1006 | packet[15] = 0x00; //or 7b? random??? FIXME |
| 1007 | #ifdef RE_DEBUG |
| 1008 | printf("match invite packet: "); |
| 1009 | for(int i = 0; i < (int)length; i++) |
| 1010 | printf("%02x ", packet[i]); |
| 1011 | printf("\n"); |
| 1012 | #endif //RE_DEBUG |
| 1013 | encode(packet, 0x10); |
| 1014 | #ifdef RE_DEBUG |
| 1015 | qDebug("Sending accept match request or invite"); |
| 1016 | #endif //RE_DEBUG |
| 1017 | if(write((const char *)packet, length) < 0) |
| 1018 | qWarning("*** failed sending accept match request or invite"); |
| 1019 | delete[] packet; |
| 1020 | match_negotiation_state->sendMatchInvite((PlayerListing *)&player); |
| 1021 | } |
| 1022 | |
| 1023 | void CyberOroConnection::sendDeclineMatchInvite(const PlayerListing * player) |
| 1024 | { |
| 1025 | unsigned int length = 12; |
| 1026 | unsigned char * packet = new unsigned char[length]; |
| 1027 | |
| 1028 | packet[0] = 0xa4; |
| 1029 | packet[1] = 0x79; |
| 1030 | packet[2] = 0x0c; |
| 1031 | packet[3] = 0x00; |
| 1032 | packet[4] = our_player_id & 0x00ff; |
| 1033 | packet[5] = (our_player_id >> 8); |
| 1034 | packet[6] = player->id & 0x00ff; |
| 1035 | packet[7] = (player->id >> 8); |
| 1036 | packet[8] = player->specialbyte; |
| 1037 | packet[9] = 0x00; |
| 1038 | packet[10] = 0x00; |
| 1039 | packet[11] = 0x00; |
| 1040 | encode(packet, 0xc); |
| 1041 | qDebug("Sending decline match request"); |
| 1042 | if(write((const char *)packet, length) < 0) |
| 1043 | qWarning("*** failed sending decline match request"); |
| 1044 | delete[] packet; |
| 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | /* This is also apparently sent automatically when |
| 1049 | * too much time passes after a request. But I missed |
| 1050 | * that last byte, I think it was 1b, but it could have |
| 1051 | * been anything. FIXME |
| 1052 | * There's also a chance I got this wrong and it |
| 1053 | * wasn't a decline message at all but something else. !!!*/ |
| 1054 | void CyberOroConnection::sendDeclineMatchOffer(const PlayerListing * player) |
| 1055 | { |
| 1056 | unsigned int length = 10; |
| 1057 | unsigned char * packet = new unsigned char[length]; |
| 1058 | |
| 1059 | packet[0] = 0x32; |
| 1060 | packet[1] = 0x7d; |
| 1061 | packet[2] = 0x0a; |
| 1062 | packet[3] = 0x00; |
| 1063 | packet[4] = player->id & 0x00ff; |
| 1064 | packet[5] = (player->id >> 8); |
| 1065 | packet[6] = our_player_id & 0x00ff; |
| 1066 | packet[7] = (our_player_id >> 8); |
| 1067 | packet[8] = 0x00; |
| 1068 | packet[9] = 0x00; //FIXME |
| 1069 | //32 7d 0a 00 49 04 d3 04 00 xx |
| 1070 | encode(packet, 0xa); |
| 1071 | qDebug("Sending decline request"); |
| 1072 | if(write((const char *)packet, length) < 0) |
| 1073 | qWarning("*** failed sending decline request"); |
| 1074 | delete[] packet; |
| 1075 | } |
| 1076 | |
| 1077 | void CyberOroConnection::sendMatchOfferPending(const PlayerListing * player) |
| 1078 | { |
| 1079 | unsigned int length = 10; |
| 1080 | unsigned char * packet = new unsigned char[length]; |
| 1081 | |
| 1082 | packet[0] = 0x1e; |
| 1083 | packet[1] = 0x7d; |
| 1084 | packet[2] = 0x0a; |
| 1085 | packet[3] = 0x00; |
| 1086 | packet[4] = our_player_id & 0x00ff; |
| 1087 | packet[5] = (our_player_id >> 8); |
| 1088 | packet[6] = player->id & 0x00ff; |
| 1089 | packet[7] = (player->id >> 8); |
| 1090 | packet[8] = 0x00; |
| 1091 | packet[9] = 0x00; |
| 1092 | |
| 1093 | encode(packet, 0xa); |
| 1094 | qDebug("Sending match offer pending"); |
| 1095 | if(write((const char *)packet, length) < 0) |
| 1096 | qWarning("*** failed sending match offer pending"); |
| 1097 | delete[] packet; |
| 1098 | match_negotiation_state->sendMatchOfferPending(); |
| 1099 | } |
| 1100 | |
| 1101 | void CyberOroConnection::sendMatchOfferCancel(const PlayerListing * ) |
| 1102 | { |
| 1103 | unsigned int length = 8; |
| 1104 | unsigned char * packet = new unsigned char[length]; |
| 1105 | |
| 1106 | packet[0] = 0x28; |
| 1107 | packet[1] = 0x7d; |
| 1108 | packet[2] = 0x08; |
| 1109 | packet[3] = 0x00; |
| 1110 | packet[4] = our_player_id & 0x00ff; |
| 1111 | packet[5] = (our_player_id >> 8); |
| 1112 | packet[6] = 0x00; |
| 1113 | packet[7] = 0x00; //FIXME |
| 1114 | |
| 1115 | |
| 1116 | encode(packet, 0x8); |
| 1117 | qDebug("Sending match offer cancel"); |
| 1118 | if(write((const char *)packet, length) < 0) |
| 1119 | qWarning("*** failed sending match offer cancel"); |
| 1120 | delete[] packet; |
| 1121 | } |
| 1122 | |
| 1123 | void CyberOroConnection::sendMatchOffer(const MatchRequest & mr, bool offercounteroffer) |
| 1124 | { |
| 1125 | unsigned int length = 0xa0; |
| 1126 | unsigned char * packet = new unsigned char[length]; |
| 1127 | Room * room = getDefaultRoom(); |
| 1128 | PlayerListing * opponent = room->getPlayerListing(mr.opponent_id); |
| 1129 | if(!opponent) |
| 1130 | { |
| 1131 | qDebug("Can't get opponent listing for match request\n"); |
| 1132 | delete[] packet; |
| 1133 | return; |
| 1134 | } |
| 1135 | int i; |
| 1136 | if(offercounteroffer) |
| 1137 | packet[0] = 0xc8; |
| 1138 | else |
| 1139 | packet[0] = 0xcd; |
| 1140 | packet[1] = 0xaf; |
| 1141 | packet[2] = 0xa0; |
| 1142 | packet[3] = 0x00; |
| 1143 | |
| 1144 | /* This is supposed to be their id for some reason... always? |
| 1145 | * or only on accept? */ |
| 1146 | if(offercounteroffer || mr.rematch) |
| 1147 | { |
| 1148 | // Careful, might only be our id when we send |
| 1149 | packet[4] = our_player_id & 0x00ff; |
| 1150 | packet[5] = (our_player_id >> 8); |
| 1151 | //commenting this out fixed the resign that we see to have (W) |
| 1152 | //but it still makes them see it wrong |
| 1153 | //also, it probably affects the "is challenger stuff so I'm not |
| 1154 | //so sure I want to do this |
| 1155 | //but then we still can't play black and the (W) is wrong |
| 1156 | //... |
| 1157 | // FIXME FIXME this all needs to be carefully redone |
| 1158 | //I think I should start really by seeing what the resigns |
| 1159 | //are sent as, i.e., with whos id. I think its difficult because |
| 1160 | //there's no good way to see what id one is assigned |
| 1161 | //no, I think at the very least when accepting this |
| 1162 | //should not be commented out |
| 1163 | //don't know what mr.rematch is though |
| 1164 | } |
| 1165 | else |
| 1166 | { |
| 1167 | packet[4] = mr.opponent_id & 0x00ff; |
| 1168 | packet[5] = (mr.opponent_id >> 8); |
| 1169 | } |
| 1170 | packet[6] = mr.last_game_code & 0x00ff; |
| 1171 | packet[7] = (mr.last_game_code >> 8); |
| 1172 | packet[8] = 0x00; |
| 1173 | packet[9] = 0x02; //02 or 00 |
| 1174 | /* Looks like rated is forced if there's a (greater than one stone? ) |
| 1175 | * rank difference ? FIXME */ |
| 1176 | if(mr.free_rated == RATED) |
| 1177 | packet[10] = 0x00; |
| 1178 | else |
| 1179 | packet[10] = 0x01; //friendly |
| 1180 | packet[11] = mr.flags; |
| 1181 | if(mr.color_request == MatchRequest::NIGIRI) |
| 1182 | packet[11] |= 0x08; |
| 1183 | switch(mr.board_size) |
| 1184 | { |
| 1185 | case 19: |
| 1186 | packet[12] = 0x00; |
| 1187 | break; |
| 1188 | case 13: |
| 1189 | packet[12] = 0x01; |
| 1190 | break; |
| 1191 | case 9: |
| 1192 | packet[12] = 0x02; |
| 1193 | break; |
| 1194 | case 7: |
| 1195 | packet[12] = 0x03; |
| 1196 | break; |
| 1197 | case 5: |
| 1198 | packet[12] = 0x04; |
| 1199 | break; |
| 1200 | default: |
| 1201 | printf("Bad board size: %d\n", mr.board_size); |
| 1202 | return; |
| 1203 | break; |
| 1204 | } |
| 1205 | //looks like 13 is just whether there is a handicap |
| 1206 | if(mr.handicap > 1) |
| 1207 | { |
| 1208 | packet[13] = 0x01; |
| 1209 | |
| 1210 | } |
| 1211 | else |
| 1212 | packet[13] = 0x00; |
| 1213 | #ifdef RE_DEBUG |
| 1214 | printf("challenger is black, 13: %d %d\n", mr.challenger_is_black, packet[13]); |
| 1215 | #endif //RE_DEBUG |
| 1216 | packet[14] = mr.handicap; //handicap I'd warrant |
| 1217 | /* FIXME |
| 1218 | * handicap may force komi = 0.5 rather than whatever we've set it at. Really |
| 1219 | * gamedialog should set this up properly with some flag. Also, we don't seem to |
| 1220 | * check the komi later and we should, actually looks like oro ignores it even if its set */ |
| 1221 | //if this is 0x01, then its negative komi, taken from white |
| 1222 | packet[15] = (mr.komi < 0 ? 0x01 : 0x00); //not sure about this |
| 1223 | packet[16] = (int)(fabs(mr.komi) - 0.5); |
| 1224 | #ifdef RE_DEBUG |
| 1225 | printf("komi: %02x %f %f\n", packet[16], mr.komi, fabs(mr.komi) - .5); |
| 1226 | #endif //RE_DEBUG |
| 1227 | packet[17] = 0x00; |
| 1228 | //a4 01 a4 01 a4 01 |
| 1229 | //6 bytes of time settings |
| 1230 | /* FIXME, in real life, we're probably going to need the old |
| 1231 | * match request to fill this out properly |
| 1232 | * (later) ... or not... I think its just because same |
| 1233 | * game struct is used for loading new games, a struct |
| 1234 | * we should USE FIXME*/ |
| 1235 | packet[18] = mr.maintime & 0x00ff; |
| 1236 | packet[19] = (mr.maintime >> 8); |
| 1237 | packet[20] = mr.maintime & 0x00ff; |
| 1238 | packet[21] = (mr.maintime >> 8); |
| 1239 | packet[22] = mr.maintime & 0x00ff; |
| 1240 | packet[23] = (mr.maintime >> 8); |
| 1241 | switch(mr.timeSystem) |
| 1242 | { |
| 1243 | case canadian: |
| 1244 | packet[31] = 0x01; |
| 1245 | break; |
| 1246 | case byoyomi: |
| 1247 | packet[31] = 0x00; |
| 1248 | break; |
| 1249 | case tvasia: |
| 1250 | packet[31] = 0x02; |
| 1251 | break; |
| 1252 | default: |
| 1253 | qDebug("Unknown time system!!"); |
| 1254 | break; |
| 1255 | } |
| 1256 | packet[24] = mr.stones_periods; |
| 1257 | packet[25] = mr.stones_periods; |
| 1258 | packet[28] = mr.periodtime & 0x00ff; |
| 1259 | packet[29] = (mr.periodtime >> 8); |
| 1260 | packet[30] = mr.stones_periods; |
| 1261 | packet[26] = 0x00; |
| 1262 | packet[27] = 0x00; |
| 1263 | //[32] 01 may indicate white's handicap |
| 1264 | packet[32] = 0x02; |
| 1265 | //packet[32] = 0x01; //definitely not on send, this throws it back to us |
| 1266 | #ifdef RE_DEBUG |
| 1267 | printf("byte 32: %02x\n", packet[32]); |
| 1268 | #endif //RE_DEBUG |
| 1269 | packet[33] = 0x00; |
| 1270 | packet[34] = 0x00; |
| 1271 | packet[35] = 0x00; |
| 1272 | #ifdef RE_DEBUG |
| 1273 | printf("Room number: %d\n", mr.number); |
| 1274 | #endif //RE_DEBUG |
| 1275 | packet[36] = mr.number & 0xff; |
| 1276 | packet[37] = (mr.number >> 8); |
| 1277 | packet[38] = 0x00; //room number again sometimes? |
| 1278 | packet[39] = 0x00; |
| 1279 | for(i = 40; i < 52; i++) |
| 1280 | packet[i] = 0x00; |
| 1281 | packet[52] = 0x1f; //??? FIXME |
| 1282 | /*packet[52] = ~0x1f; |
| 1283 | * this was an extra bad idea, setting this to e0 |
| 1284 | * launches some weird special game type. */ |
| 1285 | packet[53] = 0x00; |
| 1286 | for(i = 54; i < 62; i++) |
| 1287 | packet[i] = 0x00; |
| 1288 | //10 zeroes, though first might be part of our 1f friend |
| 1289 | packet[62] = 0x00; |
| 1290 | #ifdef RE_DEBUG |
| 1291 | printf("opponent special byte: %02x\n", opponent->specialbyte); |
| 1292 | #endif //RE_DEBUG |
| 1293 | packet[63] = 0x00; |
| 1294 | packet[63] = 0x00; |
| 1295 | //challengers name first... |
| 1296 | // maybe challenger first if nigiri? otherwise black first? |
| 1297 | const QString * first_name, * second_name; |
| 1298 | unsigned short first_id, second_id; |
| 1299 | switch(mr.color_request) |
| 1300 | { |
| 1301 | case MatchRequest::NIGIRI: |
| 1302 | /* Pretty sure if we reverse these it |
| 1303 | * screws up who sends the nigiri |
| 1304 | * possibly among other things. */ |
| 1305 | if(mr.opponent_is_challenger) |
| 1306 | { |
| 1307 | first_name = &opponent->name; |
| 1308 | first_id = mr.opponent_id; |
| 1309 | second_name = &getUsername(); |
| 1310 | second_id = our_player_id; |
| 1311 | } |
| 1312 | else |
| 1313 | { |
| 1314 | first_name = &getUsername(); |
| 1315 | first_id = our_player_id; |
| 1316 | second_name = &opponent->name; |
| 1317 | second_id = mr.opponent_id; |
| 1318 | } |
| 1319 | break; |
| 1320 | case MatchRequest::BLACK: |
| 1321 | first_name = &getUsername(); |
| 1322 | first_id = our_player_id; |
| 1323 | second_name = &opponent->name; |
| 1324 | second_id = mr.opponent_id; |
| 1325 | break; |
| 1326 | case MatchRequest::WHITE: |
| 1327 | first_name = &opponent->name; |
| 1328 | first_id = mr.opponent_id; |
| 1329 | second_name = &getUsername(); |
| 1330 | second_id = our_player_id; |
| 1331 | break; |
| 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | for(i = 0; i < first_name->size(); i++) |
| 1337 | packet[64 + i] = first_name->at(i).cell(); |
| 1338 | for(i = 9; i >= first_name->size(); i--) |
| 1339 | packet[64 + i] = 0x00; |
| 1340 | packet[74] = first_id & 0x00ff; |
| 1341 | packet[75] = (first_id >> 8); |
| 1342 | |
| 1343 | for(i = 0; i < second_name->size(); i++) |
| 1344 | packet[76 + i] = second_name->at(i).cell(); |
| 1345 | for(i = 9; i >= second_name->size(); i--) |
| 1346 | packet[76 + i] = 0x00; |
| 1347 | packet[86] = second_id & 0x00ff; |
| 1348 | packet[87] = (second_id >> 8); |
| 1349 | |
| 1350 | for(i = 88; i < 98; i++) |
| 1351 | packet[i] = 0x00; |
| 1352 | packet[98] = 0x10; |
| 1353 | packet[99] = 0x27; |
| 1354 | for(i = 100; i < (int)length; i++) |
| 1355 | packet[i] = 0x00; |
| 1356 | //10 zeroes |
| 1357 | //packet[103] = 0x10; |
| 1358 | //packet[104] = 0x27; |
| 1359 | // 10 zeroes |
| 1360 | //packet[115] = 0x10; |
| 1361 | //packet[116] = 0x27; |
| 1362 | // 3 * 16 zeroes |
| 1363 | |
| 1364 | match_negotiation_state->offerMatchTerms((MatchRequest *)&mr); |
| 1365 | match_negotiation_state->setGameId(mr.number); |
| 1366 | |
| 1367 | #ifdef RE_DEBUG |
| 1368 | printf("match packet we are sending now: "); |
| 1369 | for(i = 0; i < (int)length; i++) |
| 1370 | printf("%02x", packet[i]); |
| 1371 | printf("\n"); |
| 1372 | #endif //RE_DEBUG |
| 1373 | |
| 1374 | encode(packet, 0x40); |
| 1375 | #ifdef RE_DEBUG |
| 1376 | qDebug("Sending accept request"); |
| 1377 | #endif //RE_DEBUG |
| 1378 | if(write((const char *)packet, length) < 0) |
| 1379 | qWarning("*** failed sending accept request"); |
| 1380 | delete[] packet; |
| 1381 | } |
| 1382 | |
| 1383 | /* I don't have a fucking clue what this is, only that |
| 1384 | * it comes up constantly practically without warning. |
| 1385 | * it could be a "typing message", maybe there's one similar |
| 1386 | * when you check the score, etc.. to notify the other player |
| 1387 | * of what you're doing. But since we've seen them before... |
| 1388 | * I don't know. Either way, I'm not certain that its |
| 1389 | * a necessary message */ |
| 1390 | /* These are necessary before moves are accepted I think... |
| 1391 | * and if they aren't... well for some reason moves aren't |
| 1392 | * getting played. |
| 1393 | * I tend to think this is how the time stuff works... |
| 1394 | * and we potentially have to send one of these initially.*/ |
| 1395 | void CyberOroConnection::sendGameUpdate(unsigned short game_code) |
| 1396 | { |
| 1397 | unsigned int length = 0xa; |
| 1398 | unsigned char * packet = new unsigned char[length]; |
| 1399 | packet[0] = 0x50; |
| 1400 | packet[1] = 0xc3; |
| 1401 | packet[2] = 0x0a; |
| 1402 | packet[3] = 0x00; |
| 1403 | packet[4] = game_code & 0x00ff; |
| 1404 | packet[5] = (game_code >> 8); |
| 1405 | |
| 1406 | /* Okay looks like packet[6] controls the smiley faces ? |
| 1407 | * 0b might be 0 shaped mouth, 0a could be yawn with tear? */ |
| 1408 | packet[6] = 0x09; //huh?? 0b |
| 1409 | /* Also seen 0x0b 0x0d 0x12 0x11 0x0b which might be a preplay mode, an estimate, possibly |
| 1410 | * a clear or a return to preplay mode or something else and then back to match */ |
| 1411 | packet[7] = 0x00; |
| 1412 | |
| 1413 | packet[8] = 0x00; |
| 1414 | packet[9] = 0x00; |
| 1415 | //50 c3 0a 00 cd 01 0b 00 00 00 |
| 1416 | //50 c3 0a 00 0b 09 00 fc f6 08 //? |
| 1417 | encode(packet, 0x0a); |
| 1418 | qDebug("Sending game update"); |
| 1419 | if(write((const char *)packet, length) < 0) |
| 1420 | qWarning("*** failed sending game update"); |
| 1421 | delete[] packet; |
| 1422 | } |
| 1423 | |
| 1424 | void CyberOroConnection::sendKeepAlive(const GameListing *game) |
| 1425 | { |
| 1426 | unsigned int length = 0x10; |
| 1427 | unsigned char * packet = new unsigned char[length]; |
| 1428 | BoardDispatch * boarddispatch = getIfBoardDispatch(game->number); |
| 1429 | if(!boarddispatch) |
| 1430 | { |
| 1431 | qDebug("tried to sendKeepAlive on nonexistent board %d", game->number); |
| 1432 | delete[] packet; |
| 1433 | return; |
| 1434 | } |
| 1435 | TimeRecord tr = boarddispatch->getOurTimeRecord(); |
| 1436 | GameData * gr = boarddispatch->getGameData(); |
| 1437 | packet[0] = 0x64; |
| 1438 | packet[1] = 0xc3; |
| 1439 | packet[2] = 0x10; |
| 1440 | packet[3] = 0x00; |
| 1441 | packet[4] = our_player_id & 0x00ff; |
| 1442 | packet[5] = (our_player_id >> 8); |
| 1443 | packet[6] = game->game_code & 0x00ff; |
| 1444 | packet[7] = (game->game_code >> 8); |
| 1445 | if(gr->white_name == getUsername()) |
| 1446 | packet[8] = 0x01; //color? |
| 1447 | else |
| 1448 | packet[8] = 0x00; |
| 1449 | packet[9] = 0x00; |
| 1450 | |
| 1451 | //time |
| 1452 | packet[10] = tr.time & 0x00ff; |
| 1453 | packet[11] = (tr.time >> 8); |
| 1454 | //periods |
| 1455 | packet[12] = tr.stones_periods & 0x00ff; |
| 1456 | packet[13] = (tr.stones_periods >> 8); |
| 1457 | packet[14] = 0x00; //probably whether we're in byo yomi? |
| 1458 | packet[15] = 0x00; //FIXME |
| 1459 | |
| 1460 | encode(packet, 0x10); |
| 1461 | qDebug("Sending keep alive"); |
| 1462 | if(write((const char *)packet, length) < 0) |
| 1463 | qWarning("*** failed sending keep alive"); |
| 1464 | delete[] packet; |
| 1465 | } |
| 1466 | |
| 1467 | /* Unnecessary but we don't want to raise suspicion */ |
| 1468 | void CyberOroConnection::sendRequestKeepAlive(const GameListing *game) |
| 1469 | { |
| 1470 | unsigned int length = 0x0c; |
| 1471 | unsigned char * packet = new unsigned char[length]; |
| 1472 | BoardDispatch * boarddispatch = getIfBoardDispatch(game->number); |
| 1473 | if(!boarddispatch) |
| 1474 | { |
| 1475 | qDebug("tried to sendRequestKeepAlive on nonexistent board %d", game->number); |
| 1476 | delete[] packet; |
| 1477 | return; |
| 1478 | } |
| 1479 | GameData * gr = boarddispatch->getGameData(); |
| 1480 | packet[0] = 0x5c; |
| 1481 | packet[1] = 0x4e; |
| 1482 | packet[2] = 0x0c; |
| 1483 | packet[3] = 0x00; |
| 1484 | packet[4] = our_player_id & 0x00ff; |
| 1485 | packet[5] = (our_player_id >> 8); |
| 1486 | packet[6] = game->game_code & 0x00ff; |
| 1487 | packet[7] = (game->game_code >> 8); |
| 1488 | packet[8] = gr->moves & 0x00ff; |
| 1489 | packet[9] = (gr->moves >> 8); |
| 1490 | packet[10] = 0x00; //probably whether we're in byo yomi? |
| 1491 | packet[11] = 0x00; //FIXME |
| 1492 | |
| 1493 | qDebug("sending request keepalive on moves: %d", gr->moves); |
| 1494 | encode(packet, 0x0c); |
| 1495 | qDebug("Sending request keep alive"); |
| 1496 | if(write((const char *)packet, length) < 0) |
| 1497 | qWarning("*** failed sending keep alive2"); |
| 1498 | delete[] packet; |
| 1499 | } |
| 1500 | |
| 1501 | void CyberOroConnection::saveIfDoesntSave(GameData * data) |
| 1502 | { |
| 1503 | GameListing * listing = getDefaultRoom()->getGameListing(data->number); |
| 1504 | listing->gameData = new GameData(data); |
| 1505 | } |
| 1506 | |
| 1507 | void CyberOroConnection::timerEvent(QTimerEvent * event) |
| 1508 | { |
| 1509 | if(event->timerId() == matchKeepAliveTimerID || |
| 1510 | event->timerId() == matchRequestKeepAliveTimerID) |
| 1511 | { |
| 1512 | Room * room = getDefaultRoom(); |
| 1513 | GameListing * listing = room->getGameListing(match_negotiation_state->getGameId()); |
| 1514 | if(event->timerId() == matchKeepAliveTimerID) |
| 1515 | sendKeepAlive(listing); |
| 1516 | else |
| 1517 | sendRequestKeepAlive(listing); |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | void CyberOroConnection::sendMove(unsigned int game_id, MoveRecord * move) |
| 1522 | { |
| 1523 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_id); |
| 1524 | if(!boarddispatch) |
| 1525 | { |
| 1526 | qDebug("Can't get board for send move: %d", game_id); |
| 1527 | } |
| 1528 | GameData * r = boarddispatch->getGameData(); |
| 1529 | switch(move->flags) |
| 1530 | { |
| 1531 | case MoveRecord::RESIGN: |
| 1532 | sendResign(r->game_code); |
| 1533 | killActiveMatchTimers(); |
| 1534 | return; |
| 1535 | break; |
| 1536 | |
| 1537 | case MoveRecord::REMOVE: |
| 1538 | case MoveRecord::UNREMOVE: |
| 1539 | sendRemoveStones(r->game_code, move); |
| 1540 | return; |
| 1541 | break; |
| 1542 | case MoveRecord::DONE_SCORING: |
| 1543 | sendDoneScoring(r->game_code, r->opponent_id); |
| 1544 | return; |
| 1545 | break; |
| 1546 | case MoveRecord::REQUESTUNDO: |
| 1547 | sendUndo(r->game_code, move); |
| 1548 | return; |
| 1549 | break; |
| 1550 | case MoveRecord::UNDO: |
| 1551 | sendAcceptUndo(r->game_code, move); |
| 1552 | return; |
| 1553 | break; |
| 1554 | case MoveRecord::REFUSEUNDO: |
| 1555 | sendDeclineUndo(r->game_code, move); |
| 1556 | return; |
| 1557 | break; |
| 1558 | default: |
| 1559 | break; |
| 1560 | } |
| 1561 | |
| 1562 | unsigned int length = 0x14; |
| 1563 | unsigned char * packet = new unsigned char[length]; |
| 1564 | |
| 1565 | packet[0] = 0xdc; |
| 1566 | packet[1] = 0xaf; |
| 1567 | packet[2] = 0x14; |
| 1568 | packet[3] = 0x00; |
| 1569 | packet[4] = r->game_code & 0x00ff; |
| 1570 | packet[5] = (r->game_code >> 8); |
| 1571 | packet[6] = our_player_id & 0x00ff; |
| 1572 | packet[7] = (our_player_id >> 8); |
| 1573 | /* I've seen black moves sent with this... could be that non |
| 1574 | * challenger sends 0101?, or maybe challenger does... */ |
| 1575 | if(r->white_name == getOurListing()->name) |
| 1576 | { |
| 1577 | packet[8] = 0x01; //both ones? |
| 1578 | packet[9] = 0x01; |
| 1579 | } |
| 1580 | else |
| 1581 | { |
| 1582 | packet[8] = 0x00; //this maybe has to be for color? |
| 1583 | packet[9] = 0x00; |
| 1584 | } |
| 1585 | // this may be off, 1 too high in even games |
| 1586 | move->number++; //wtf FIXME |
| 1587 | packet[10] = (move->number & 0x00ff); |
| 1588 | packet[11] = (move->number >> 8); |
| 1589 | if(move->flags == MoveRecord::PASS) |
| 1590 | { |
| 1591 | packet[12] = 0; |
| 1592 | packet[13] = 0; |
| 1593 | } |
| 1594 | else |
| 1595 | { |
| 1596 | packet[12] = move->x; |
| 1597 | packet[13] = move->y; |
| 1598 | } |
| 1599 | TimeRecord t = getBoardDispatch(game_id)->getOurTimeRecord(); |
| 1600 | if(move->number == 1 || move->number == 2) |
| 1601 | { |
| 1602 | /* We apparently don't start the clock until 3rd move |
| 1603 | * so this should fix that up. */ |
| 1604 | packet[14] = r->maintime & 0x00ff; |
| 1605 | packet[15] = (r->maintime >> 8); |
| 1606 | } |
| 1607 | else |
| 1608 | { |
| 1609 | packet[14] = t.time & 0x00ff; |
| 1610 | packet[15] = (t.time >> 8); |
| 1611 | } |
| 1612 | if(t.stones_periods == -1) |
| 1613 | { |
| 1614 | //UGLY FIXME |
| 1615 | t.stones_periods = r->stones_periods; |
| 1616 | #ifdef RE_DEBUG |
| 1617 | printf("r->periods here %d\n", r->stones_periods); |
| 1618 | #endif //RE_DEBUG |
| 1619 | packet[17] = 0x00; |
| 1620 | } |
| 1621 | else |
| 1622 | packet[17] = 0x01; |
| 1623 | packet[16] = t.stones_periods; |
| 1624 | //packet[17] = (t.stones_periods >> 8); |
| 1625 | packet[18] = 0x00; |
| 1626 | packet[19] = 0x00; |
| 1627 | |
| 1628 | //move |
| 1629 | //dc af 14 00 fa 01 ec 05 00 00 0a 00 04 08 6e 04 |
| 1630 | //03 00 00 00 |
| 1631 | //pass |
| 1632 | //dc af 14 00 6a e2 ec 05 00 00 02 00 00 00 b0 04 |
| 1633 | //03 00 00 00 |
| 1634 | |
| 1635 | //we send |
| 1636 | //dc af 14 00 49 0d 2b 07 00 00 01 00 07 07 78 00 03 00 00 00 |
| 1637 | |
| 1638 | #ifdef RE_DEBUG |
| 1639 | printf("movepacket: "); |
| 1640 | for(unsigned int i = 0; i < length; i++) |
| 1641 | printf("%02x ", packet[i]); |
| 1642 | printf("\n"); |
| 1643 | #endif //RE_DEBUG |
| 1644 | encode(packet, 0x14); |
| 1645 | #ifdef RE_DEBUG |
| 1646 | qDebug("Sending move"); |
| 1647 | #endif //RE_DEBUG |
| 1648 | if(write((const char *)packet, length) < 0) |
| 1649 | qWarning("*** failed sending move packet"); |
| 1650 | delete[] packet; |
| 1651 | |
| 1652 | if(matchKeepAliveTimerID) |
| 1653 | { |
| 1654 | killTimer(matchKeepAliveTimerID); |
| 1655 | matchKeepAliveTimerID = 0; |
| 1656 | matchRequestKeepAliveTimerID = startTimer(39000); |
| 1657 | } |
| 1658 | |
| 1659 | } |
| 1660 | |
| 1661 | void CyberOroConnection::sendUndo(unsigned int game_code, const MoveRecord * move) |
| 1662 | { |
| 1663 | unsigned int length = 0x0e; |
| 1664 | unsigned char * packet = new unsigned char[length]; |
| 1665 | GameData * aGameData; |
| 1666 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_code_to_number[game_code]); |
| 1667 | if(!boarddispatch) |
| 1668 | { |
| 1669 | qDebug("How can there not be a board dispatch, it just sent us an undo"); |
| 1670 | delete[] packet; |
| 1671 | return; |
| 1672 | } |
| 1673 | aGameData = boarddispatch->getGameData(); |
| 1674 | packet[0] = 0xe6; |
| 1675 | packet[1] = 0xaf; |
| 1676 | packet[2] = 0x0e; |
| 1677 | packet[3] = 0x00; |
| 1678 | packet[4] = our_player_id & 0x00ff; |
| 1679 | packet[5] = (our_player_id >> 8); |
| 1680 | packet[6] = game_code & 0x00ff; |
| 1681 | packet[7] = (game_code >> 8); |
| 1682 | if(aGameData->white_name == getUsername()) |
| 1683 | packet[8] = 0x01; |
| 1684 | else |
| 1685 | packet[8] = 0x00; |
| 1686 | packet[9] = 0x00; |
| 1687 | packet[10] = move->number & 0x00ff; //this is the move to start from (10) |
| 1688 | packet[11] = (move->number >> 8); |
| 1689 | packet[12] = 0x00; |
| 1690 | packet[13] = 0x00; |
| 1691 | |
| 1692 | //from sender perspective encode(e) |
| 1693 | //e6af 0e00 b50d 4c02 01 00 0a 00 00 00 |
| 1694 | #ifdef RE_DEBUG |
| 1695 | printf("undo packet: "); |
| 1696 | for(int i = 0; i < (int)length; i++) |
| 1697 | printf("%02x ", packet[i]); |
| 1698 | printf("\n"); |
| 1699 | #endif //RE_DEBUG |
| 1700 | encode(packet, 0xe); |
| 1701 | qDebug("Sending undo"); |
| 1702 | if(write((const char *)packet, length) < 0) |
| 1703 | qWarning("*** failed sending undo packet"); |
| 1704 | delete[] packet; |
| 1705 | } |
| 1706 | |
| 1707 | /* FIXME oro client can't seem to play after an undo, but we can if |
| 1708 | * its our turn. We need to make sure that this is an ORO bug, and not |
| 1709 | * us screwing up the move number we send back */ |
| 1710 | void CyberOroConnection::sendDeclineUndo(unsigned int game_code, const MoveRecord * move) |
| 1711 | { |
| 1712 | unsigned int length = 14; |
| 1713 | unsigned char * packet = new unsigned char[length]; |
| 1714 | GameData * aGameData; |
| 1715 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_code_to_number[game_code]); |
| 1716 | if(!boarddispatch) |
| 1717 | { |
| 1718 | qDebug("How can there not be a board dispatch, it just sent us a timeloss"); |
| 1719 | delete[] packet; |
| 1720 | return; |
| 1721 | } |
| 1722 | aGameData = boarddispatch->getGameData(); |
| 1723 | packet[0] = 0xf0; |
| 1724 | packet[1] = 0xaf; |
| 1725 | packet[2] = 0x0e; |
| 1726 | packet[3] = 0x00; |
| 1727 | packet[4] = our_player_id & 0x00ff; |
| 1728 | packet[5] = (our_player_id >> 8); |
| 1729 | packet[6] = game_code & 0x00ff; |
| 1730 | packet[7] = (game_code >> 8); |
| 1731 | if(aGameData->white_name == getUsername()) //opposite color |
| 1732 | packet[8] = 0x00; |
| 1733 | else |
| 1734 | packet[8] = 0x01; |
| 1735 | packet[9] = 0x00; |
| 1736 | packet[10] = move->number & 0x00ff; |
| 1737 | packet[11] = (move->number >> 8); |
| 1738 | packet[12] = 0x00; |
| 1739 | packet[13] = 0x00; |
| 1740 | |
| 1741 | encode(packet, 0x0e); |
| 1742 | qDebug("Sending decline undo"); |
| 1743 | if(write((const char *)packet, length) < 0) |
| 1744 | qWarning("*** failed sending decline undo"); |
| 1745 | delete[] packet; |
| 1746 | } |
| 1747 | |
| 1748 | void CyberOroConnection::sendAcceptUndo(unsigned int game_code, const MoveRecord * move) |
| 1749 | { |
| 1750 | unsigned int length = 14; |
| 1751 | unsigned char * packet = new unsigned char[length]; |
| 1752 | GameData * aGameData; |
| 1753 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_code_to_number[game_code]); |
| 1754 | if(!boarddispatch) |
| 1755 | { |
| 1756 | qDebug("How can there not be a board dispatch, it just sent us a timeloss"); |
| 1757 | delete[] packet; |
| 1758 | return; |
| 1759 | } |
| 1760 | aGameData = boarddispatch->getGameData(); |
| 1761 | packet[0] = 0xeb; |
| 1762 | packet[1] = 0xaf; |
| 1763 | packet[2] = 0x0e; |
| 1764 | packet[3] = 0x00; |
| 1765 | packet[4] = our_player_id & 0x00ff; |
| 1766 | packet[5] = (our_player_id >> 8); |
| 1767 | packet[6] = game_code & 0x00ff; |
| 1768 | packet[7] = (game_code >> 8); |
| 1769 | if(aGameData->white_name == getUsername()) |
| 1770 | packet[8] = 0x01; |
| 1771 | else |
| 1772 | packet[8] = 0x00; |
| 1773 | packet[9] = 0x00; |
| 1774 | packet[10] = move->number & 0x00ff; |
| 1775 | packet[11] = (move->number >> 8); |
| 1776 | packet[12] = 0x00; |
| 1777 | packet[13] = 0x00; |
| 1778 | |
| 1779 | encode(packet, 0x0e); |
| 1780 | qDebug("Sending accept undo"); |
| 1781 | if(write((const char *)packet, length) < 0) |
| 1782 | qWarning("*** failed sending accept undo"); |
| 1783 | delete[] packet; |
| 1784 | } |
| 1785 | |
| 1786 | void CyberOroConnection::sendEndgame12Msg(unsigned int game_id, unsigned short msg_code) |
| 1787 | { |
| 1788 | unsigned int length = 0x0c; |
| 1789 | unsigned char * packet = new unsigned char[length]; |
| 1790 | GameData * aGameData; |
| 1791 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_id); |
| 1792 | if(!boarddispatch) |
| 1793 | { |
| 1794 | qDebug("How can there not be a board dispatch, it just sent us an endgame msg"); |
| 1795 | delete[] packet; |
| 1796 | return; |
| 1797 | } |
| 1798 | aGameData = boarddispatch->getGameData(); |
| 1799 | /* FIXME looking at this suggests that we have all the msg codes byte order backwards if they're |
| 1800 | * to be consistent!! Interesting */ |
| 1801 | packet[0] = (msg_code >> 8); |
| 1802 | packet[1] = msg_code & 0x00ff; |
| 1803 | packet[2] = 0x0c; |
| 1804 | packet[3] = 0x00; |
| 1805 | packet[4] = our_player_id & 0x00ff; |
| 1806 | packet[5] = (our_player_id >> 8); |
| 1807 | packet[6] = aGameData->game_code & 0x00ff; |
| 1808 | packet[7] = (aGameData->game_code >> 8); |
| 1809 | if(aGameData->white_name == getUsername()) |
| 1810 | packet[8] = 0x01; |
| 1811 | else |
| 1812 | packet[8] = 0x00; |
| 1813 | packet[9] = 0x00; |
| 1814 | packet[10] = 0x00; |
| 1815 | packet[11] = 0x00; |
| 1816 | |
| 1817 | encode(packet, 0xc); |
| 1818 | qDebug("Sending %d endgame msg", msg_code); |
| 1819 | if(write((const char *)packet, length) < 0) |
| 1820 | qWarning("*** failed sending request count packet"); |
| 1821 | delete[] packet; |
| 1822 | } |
| 1823 | |
| 1824 | /* FIXME Most of these messages all seem to be the same and I would love to clean up all of this |
| 1825 | * code with a single case statement or something */ |
| 1826 | void CyberOroConnection::sendRequestCount(unsigned int game_id) |
| 1827 | { |
| 1828 | sendEndgame12Msg(game_id, 0xc4b3); |
| 1829 | killActiveMatchTimers(); |
| 1830 | } |
| 1831 | |
| 1832 | void CyberOroConnection::sendAcceptCountRequest(GameData * data) |
| 1833 | { |
| 1834 | sendEnterScoring(data->game_code); |
| 1835 | } |
| 1836 | |
| 1837 | void CyberOroConnection::sendRefuseCountRequest(GameData * data) |
| 1838 | { |
| 1839 | sendEndgame12Msg(data->number, 0xceb3); |
| 1840 | BoardDispatch * boarddispatch = getIfBoardDispatch(data->number); |
| 1841 | if(!boarddispatch) |
| 1842 | { |
| 1843 | qDebug("How can there not be a board dispatch, it just sent us a send refuse count request"); |
| 1844 | return; |
| 1845 | } |
| 1846 | startMatchTimers(boarddispatch->getBlackTurn() ? (data->black_name == getUsername()) : (data->white_name == getUsername())); |
| 1847 | } |
| 1848 | |
| 1849 | void CyberOroConnection::sendRequestMatchMode(unsigned int game_id) |
| 1850 | { |
| 1851 | sendEndgame12Msg(game_id, 0x05b4); |
| 1852 | killActiveMatchTimers(); //does killing the match timers like this also stop the clock from ticking doublecheck FIXME? |
| 1853 | match_negotiation_state->sendMatchModeRequest(); |
| 1854 | } |
| 1855 | |
| 1856 | void CyberOroConnection::sendAcceptRequestMatchMode(unsigned int game_id) |
| 1857 | { |
| 1858 | unsigned int length = 0x08; |
| 1859 | unsigned char * packet = new unsigned char[length]; |
| 1860 | GameData * aGameData; |
| 1861 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_id); |
| 1862 | if(!boarddispatch) |
| 1863 | { |
| 1864 | qDebug("How can there not be a board dispatch, it just sent us a accept request match mode"); |
| 1865 | delete[] packet; |
| 1866 | return; |
| 1867 | } |
| 1868 | aGameData = boarddispatch->getGameData(); |
| 1869 | packet[0] = 0x8c; |
| 1870 | packet[1] = 0xc3; |
| 1871 | packet[2] = 0x08; |
| 1872 | packet[3] = 0x00; |
| 1873 | packet[4] = aGameData->game_code & 0x00ff; |
| 1874 | packet[5] = (aGameData->game_code >> 8); |
| 1875 | packet[6] = 0x00; |
| 1876 | packet[7] = 0x00; |
| 1877 | |
| 1878 | encode(packet, 0x8); |
| 1879 | qDebug("Sending accept request match mode"); |
| 1880 | if(write((const char *)packet, length) < 0) |
| 1881 | qWarning("*** failed sending request match mode packet"); |
| 1882 | delete[] packet; |
| 1883 | //FIXME this isn't starting thematch timers properly FIXME |
| 1884 | startMatchTimers(boarddispatch->getBlackTurn() ? (aGameData->black_name == getUsername()) : (aGameData->white_name == getUsername())); |
| 1885 | } |
| 1886 | |
| 1887 | void CyberOroConnection::sendDeclineRequestMatchMode(unsigned int game_id) |
| 1888 | { |
| 1889 | sendEndgame12Msg(game_id, 0x0ab4); |
| 1890 | } |
| 1891 | |
| 1892 | void CyberOroConnection::sendTimeLoss(unsigned int game_id) |
| 1893 | { |
| 1894 | sendEndgame12Msg(game_id, 0xf6b3); |
| 1895 | killActiveMatchTimers(); |
| 1896 | } |
| 1897 | |
| 1898 | void CyberOroConnection::sendRemoveStones(unsigned int game_code, const MoveRecord * move) |
| 1899 | { |
| 1900 | unsigned int length = 0x10; |
| 1901 | unsigned char * packet = new unsigned char[length]; |
| 1902 | |
| 1903 | packet[0] = 0xe2; |
| 1904 | packet[1] = 0xb3; |
| 1905 | packet[2] = 0x10; |
| 1906 | packet[3] = 0x00; |
| 1907 | packet[4] = our_player_id & 0x00ff; |
| 1908 | packet[5] = (our_player_id >> 8); |
| 1909 | packet[6] = game_code & 0x00ff; |
| 1910 | packet[7] = (game_code >> 8); |
| 1911 | packet[8] = our_player_id & 0x00ff; //why our id again?? |
| 1912 | packet[9] = (our_player_id >> 8); |
| 1913 | //packet[10] = (move.number & 0x00ff); //what the hell are these? |
| 1914 | //packet[11] = (move.number >> 8); // FIXME scores??? |
| 1915 | if(move->flags == MoveRecord::REMOVE) |
| 1916 | packet[12] = 0x01; //probably unremove bit |
| 1917 | else //if(move->flags == MoveRecord::UNREMOVE) |
| 1918 | packet[12] = 0x02; |
| 1919 | packet[13] = 0x00; |
| 1920 | |
| 1921 | packet[14] = move->x; |
| 1922 | packet[15] = move->y; |
| 1923 | |
| 1924 | //e2 b3 10 00 ec 05 fa 01 ec 05 01 00 01 00 03 04 |
| 1925 | //e2 b3 10 00 ec 05 fa 01 ec 05 98 66 01 00 03 10 |
| 1926 | #ifdef RE_DEBUG |
| 1927 | printf("remove stones packet: "); |
| 1928 | for(unsigned int i = 0; i < length; i++) |
| 1929 | printf("%02x ", packet[i]); |
| 1930 | printf("\n"); |
| 1931 | #endif //RE_DEBUG |
| 1932 | encode(packet, 0x0c); |
| 1933 | qDebug("Sending remove stones"); |
| 1934 | if(write((const char *)packet, length) < 0) |
| 1935 | qWarning("*** failed sending remove stones packet"); |
| 1936 | delete[] packet; |
| 1937 | } |
| 1938 | |
| 1939 | /* Looks like we send this, for instance, as white if we pass |
| 1940 | * and then receive a black pass */ |
| 1941 | void CyberOroConnection::sendEnterScoring(unsigned int game_code) |
| 1942 | { |
| 1943 | sendEndgame12Msg(game_code_to_number[game_code], 0xc9b3); |
| 1944 | } |
| 1945 | |
| 1946 | void CyberOroConnection::sendDoneScoring(unsigned int game_code, unsigned short opp_id) |
| 1947 | { |
| 1948 | unsigned int length = 14 + (deadStonesList.size() * 2) + (deadStonesList.size() ? 2 : 0); |
| 1949 | unsigned char * packet = new unsigned char[length]; |
| 1950 | int i; |
| 1951 | bool receivedOppDone = match_negotiation_state->receivedDoneCounting(); |
| 1952 | |
| 1953 | if(receivedOppDone) |
| 1954 | { |
| 1955 | packet[0] = 0xe7; |
| 1956 | packet[1] = 0xb3; |
| 1957 | } |
| 1958 | else |
| 1959 | { |
| 1960 | packet[0] = 0xf1; |
| 1961 | packet[1] = 0xb3; |
| 1962 | } |
| 1963 | packet[2] = length & 0x00ff; |
| 1964 | packet[3] = (length >> 8); |
| 1965 | packet[4] = our_player_id & 0x00ff; |
| 1966 | packet[5] = (our_player_id >> 8); |
| 1967 | packet[6] = game_code & 0x00ff; |
| 1968 | packet[7] = (game_code >> 8); |
| 1969 | /* I think bytes 8 and 9 are opponents id if we haven't |
| 1970 | * received a done from them yet and ours if we have. FIXME */ |
| 1971 | if(receivedOppDone) |
| 1972 | { |
| 1973 | packet[8] = our_player_id & 0x00ff; |
| 1974 | packet[9] = (our_player_id >> 8); |
| 1975 | } |
| 1976 | else |
| 1977 | { |
| 1978 | packet[8] = opp_id & 0x00ff; |
| 1979 | packet[9] = (opp_id >> 8); |
| 1980 | } |
| 1981 | //packet[8] = our_player_id & 0x00ff; //why our id again?? |
| 1982 | //packet[9] = (our_player_id >> 8); |
| 1983 | //packet[10] = (move.number & 0x00ff); //what the hell are these? |
| 1984 | //packet[11] = (move.number >> 8); // FIXME scores??? |
| 1985 | //packet[10] = 0x00; //possible scores, random? |
| 1986 | if(receivedOppDone) |
| 1987 | { |
| 1988 | unsigned short done_response = match_negotiation_state->getCountingVerification(); |
| 1989 | packet[10] = done_response & 0x00ff; |
| 1990 | packet[11] = (done_response >> 8); |
| 1991 | } |
| 1992 | else |
| 1993 | { |
| 1994 | //FIXME what the hell? |
| 1995 | //packet[10] = 0x82; //these seems to be kept... |
| 1996 | //packet[11] = 0x45; //should be random? = 63? |
| 1997 | /* I'm going to assume that these are random, to ensure that scores can't be spoofed. |
| 1998 | * i.e., we should check their response */ |
| 1999 | packet[10] = rand() % 256; |
| 2000 | packet[11] = rand() % 256; |
| 2001 | match_negotiation_state->setCountingVerification(packet[10] + (packet[11] << 8)); |
| 2002 | } |
| 2003 | |
| 2004 | packet[12] = 0x01; |
| 2005 | packet[13] = deadStonesList.size(); |
| 2006 | if(deadStonesList.size()) |
| 2007 | { |
| 2008 | /* We're supposed to send the last one */ |
| 2009 | packet[14] = deadStonesList[deadStonesList.size() - 1].x; |
| 2010 | packet[15] = deadStonesList[deadStonesList.size() - 1].y; |
| 2011 | for(i = 0; i < (int)deadStonesList.size(); i++) |
| 2012 | { |
| 2013 | packet[16 + (i * 2)] = deadStonesList[i].x; |
| 2014 | packet[17 + (i * 2)] = deadStonesList[i].y; |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | //f1 b3 18 00 ec 05 fa 01 ec 05 98 82 01 04 03 10 |
| 2019 | //11 0f 11 05 03 04 03 10 |
| 2020 | #ifdef RE_DEBUG |
| 2021 | printf("done scoring packet: "); |
| 2022 | for(i = 0; i < (int)length; i++) |
| 2023 | printf("%02x ", packet[i]); |
| 2024 | printf("\n"); |
| 2025 | #endif //RE_DEBUG |
| 2026 | encode(packet, 0x0c); //doublecheck that scoring works FIXME |
| 2027 | qDebug("Sending done scoring"); |
| 2028 | if(write((const char *)packet, length) < 0) |
| 2029 | qWarning("*** failed sending done scoring"); |
| 2030 | delete[] packet; |
| 2031 | |
| 2032 | if(receivedOppDone) |
| 2033 | { |
| 2034 | match_negotiation_state->setDoneCounting(); |
| 2035 | sendMatchResult(game_code); |
| 2036 | } |
| 2037 | else |
| 2038 | match_negotiation_state->sendDoneCounting(); |
| 2039 | } |
| 2040 | |
| 2041 | /* I don't think we're allowed to send this in score phase or |
| 2042 | * after opponent has pressed done or something */ |
| 2043 | void CyberOroConnection::sendResign(unsigned int game_code) |
| 2044 | { |
| 2045 | sendEndgame12Msg(game_code_to_number[game_code], 0xb0b3); |
| 2046 | } |
| 2047 | |
| 2048 | void CyberOroConnection::sendAdjournRequest(void) |
| 2049 | { |
| 2050 | sendEndgame12Msg(match_negotiation_state->getGameId(), 0xb5b3); |
| 2051 | } |
| 2052 | |
| 2053 | void CyberOroConnection::sendAdjourn(void) |
| 2054 | { |
| 2055 | sendEndgame12Msg(match_negotiation_state->getGameId(), 0xbab3); |
| 2056 | } |
| 2057 | |
| 2058 | void CyberOroConnection::sendRefuseAdjourn(void) |
| 2059 | { |
| 2060 | sendEndgame12Msg(match_negotiation_state->getGameId(), 0xbfb3); |
| 2061 | } |
| 2062 | |
| 2063 | |
| 2064 | /* So far, we know this is sent by client that responded |
| 2065 | * to done or by loser. The margin seems to be ignored |
| 2066 | * by opposing client but maybe its registered by |
| 2067 | * server. */ |
| 2068 | void CyberOroConnection::sendMatchResult(unsigned short game_code) |
| 2069 | { |
| 2070 | unsigned int length = 20; |
| 2071 | unsigned char * packet = new unsigned char[length]; |
| 2072 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_code_to_number[game_code]); |
| 2073 | if(!boarddispatch) |
| 2074 | { |
| 2075 | qDebug("Can't get board for %d for match result send", game_code_to_number[game_code]); |
| 2076 | delete[] packet; |
| 2077 | return; |
| 2078 | } |
| 2079 | /* We need to notify boarddispatch of finished game so we can |
| 2080 | * get the full result */ |
| 2081 | boarddispatch->recvResult(0); |
| 2082 | GameData *aGameData = boarddispatch->getGameData(); |
| 2083 | packet[0] = 0x80; |
| 2084 | packet[1] = 0xbb; |
| 2085 | packet[2] = 0x14; |
| 2086 | packet[3] = 0x00; |
| 2087 | packet[4] = our_player_id & 0x00ff; |
| 2088 | packet[5] = (our_player_id >> 8); |
| 2089 | packet[6] = game_code & 0x00ff; |
| 2090 | packet[7] = (game_code >> 8); |
| 2091 | packet[8] = 0x03; //? |
| 2092 | if(aGameData->white_name == getUsername()) //doublecheck |
| 2093 | packet[9] = 0x01; |
| 2094 | else |
| 2095 | packet[9] = 0x00; |
| 2096 | if(!aGameData->fullresult) |
| 2097 | { |
| 2098 | qDebug("No result on game data to send result"); |
| 2099 | return; |
| 2100 | } |
| 2101 | float margin = aGameData->fullresult->winner_score - aGameData->fullresult->loser_score; |
| 2102 | packet[10] = (int)margin & 0x00ff; |
| 2103 | packet[11] = ((int)margin >> 8); |
| 2104 | packet[12] = 0x1a; //?? 04 |
| 2105 | packet[13] = 0x00; |
| 2106 | packet[14] = 0x00; //?? 01 |
| 2107 | packet[15] = 0x00; |
| 2108 | packet[16] = 0x00; //?? 01 |
| 2109 | packet[17] = 0x00; |
| 2110 | packet[18] = 0x00; |
| 2111 | packet[19] = 0x00; |
| 2112 | |
| 2113 | encode(packet, 0x14); |
| 2114 | qDebug("Sending match result"); |
| 2115 | if(write((const char *)packet, length) < 0) |
| 2116 | qWarning("*** failed sending match result"); |
| 2117 | delete[] packet; |
| 2118 | } |
| 2119 | |
| 2120 | /* It seems like this appears like a match invite if opponent closes |
| 2121 | * the window */ |
| 2122 | void CyberOroConnection::sendRematchRequest(void) |
| 2123 | { |
| 2124 | if(!room_were_in) |
| 2125 | { |
| 2126 | qDebug("Trying to send rematch request but not in a room"); |
| 2127 | return; |
| 2128 | } |
| 2129 | unsigned int length = 10; |
| 2130 | unsigned char * packet = new unsigned char[length]; |
| 2131 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_were_in); |
| 2132 | if(!boarddispatch) |
| 2133 | { |
| 2134 | qDebug("Can't get board for %d for rematch send", room_were_in); |
| 2135 | return; |
| 2136 | } |
| 2137 | GameData * gr = boarddispatch->getGameData(); |
| 2138 | packet[0] = 0x69; |
| 2139 | packet[1] = 0xc3; |
| 2140 | packet[2] = 0x0a; |
| 2141 | packet[3] = 0x00; |
| 2142 | packet[4] = our_player_id & 0x00ff; |
| 2143 | packet[5] = (our_player_id >> 8); |
| 2144 | packet[6] = gr->opponent_id & 0x00ff; |
| 2145 | packet[7] = (gr->opponent_id >> 8); |
| 2146 | packet[8] = 0x12; //? |
| 2147 | packet[9] = 0x00; //? |
| 2148 | |
| 2149 | encode(packet, 0xa); |
| 2150 | qDebug("Sending rematch request"); |
| 2151 | if(write((const char *)packet, length) < 0) |
| 2152 | qWarning("*** failed sending rematch request"); |
| 2153 | delete[] packet; |
| 2154 | |
| 2155 | /* Since end of game resets the match state */ |
| 2156 | PlayerListing * player = getDefaultRoom()->getPlayerListing(gr->opponent_id); |
| 2157 | match_negotiation_state->sendRematch(player); |
| 2158 | } |
| 2159 | |
| 2160 | void CyberOroConnection::sendRematchAccept(void) |
| 2161 | { |
| 2162 | if(!room_were_in) |
| 2163 | { |
| 2164 | qDebug("Trying to send rematch accept but we aren't in room"); |
| 2165 | return; |
| 2166 | } |
| 2167 | unsigned int length = 10; |
| 2168 | unsigned char * packet = new unsigned char[length]; |
| 2169 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_were_in); |
| 2170 | if(!boarddispatch) |
| 2171 | { |
| 2172 | qDebug("Can't get board for %d for rematch accept send", room_were_in); |
| 2173 | return; |
| 2174 | } |
| 2175 | GameData * gr = boarddispatch->getGameData(); |
| 2176 | packet[0] = 0x6e; |
| 2177 | packet[1] = 0xc3; |
| 2178 | packet[2] = 0x0a; |
| 2179 | packet[3] = 0x00; |
| 2180 | packet[4] = gr->opponent_id & 0x00ff; |
| 2181 | packet[5] = (gr->opponent_id >> 8); |
| 2182 | packet[6] = our_player_id & 0x00ff; |
| 2183 | packet[7] = (our_player_id >> 8); |
| 2184 | packet[8] = 0x12; //? is this a room? |
| 2185 | packet[9] = 0x00; //? |
| 2186 | |
| 2187 | encode(packet, 0xa); |
| 2188 | qDebug("Sending rematch request accept"); |
| 2189 | if(write((const char *)packet, length) < 0) |
| 2190 | qWarning("*** failed sending rematch request accept"); |
| 2191 | delete[] packet; |
| 2192 | match_negotiation_state->sendRematchAccept(); |
| 2193 | //prepare for rematch func? |
| 2194 | } |
| 2195 | |
| 2196 | /* I think this double as both our odd/even guess as well |
| 2197 | * as the number we send. But I think... well I assume |
| 2198 | * that the challenged player is holding the stones out? */ |
| 2199 | void CyberOroConnection::sendNigiri(unsigned short game_code, bool /*odd*/) |
| 2200 | { |
| 2201 | unsigned short room_number = game_code_to_number[game_code]; |
| 2202 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_number); |
| 2203 | if(!boarddispatch) |
| 2204 | { |
| 2205 | qDebug("Can't get board for %d for nigiri send", room_number); |
| 2206 | return; |
| 2207 | } |
| 2208 | unsigned int length = 12; |
| 2209 | unsigned char * packet = new unsigned char[length]; |
| 2210 | GameData * gr = boarddispatch->getGameData(); |
| 2211 | packet[0] = 0xf5; |
| 2212 | packet[1] = 0xaf; |
| 2213 | packet[2] = 0x0c; |
| 2214 | packet[3] = 0x00; |
| 2215 | packet[4] = game_code & 0x00ff; |
| 2216 | packet[5] = (game_code >> 8); |
| 2217 | packet[6] = room_number & 0x00ff; |
| 2218 | packet[7] = (room_number >> 8); |
| 2219 | //packet[8] = rand() % 255; //this is both odd and even |
| 2220 | /* If its 0x0_, it looks like its an odd choice |
| 2221 | * 0x2_ looks like an even choice, |
| 2222 | * then the second four bits seem to be the number that gets |
| 2223 | * sent. But we can still seemingly confuse the oro client, |
| 2224 | * like we're supposed to send something else... it lets it |
| 2225 | * play for the right turn, but the colors aren't set. And |
| 2226 | * then in addition, we can't seem to play, like we're supposed |
| 2227 | * to send something else first |
| 2228 | * But so its like the first 4 bits are our choice of odd 0 or even 2 |
| 2229 | * and then the second 4 bits are the number of stones that our |
| 2230 | * opponent is holding. But actually, I've seen 0, 2, and 3 sent!*/ |
| 2231 | /* FIXME I think we can say definitively that its simpler than we think |
| 2232 | * but it definitely doesn't work */ |
| 2233 | packet[8] = (rand() % 0xd) + 2; |
| 2234 | packet[8] |= (rand() % 0x19) + 1; //19? d??? I guess it doesn't matter but... |
| 2235 | we_send_nigiri = true; |
| 2236 | |
| 2237 | /* I've seen the new version of this here work at least for one color */ |
| 2238 | //if((((packet[8] & 0xe0) >> 4) % 2) == ((packet[8] & 0x1f) % 2)) |
| 2239 | //if(((((packet[8] & 0xe0) >> 5) + 1) % 2) == ((packet[8] & 0x1f) % 2)) |
| 2240 | if((!(packet[8] & 0x20)) == ((packet[8] & 0x1f) % 2)) |
| 2241 | { |
| 2242 | //0x38 even 24 we play black |
| 2243 | #ifdef RE_DEBUG |
| 2244 | qDebug("nigiri successful"); |
| 2245 | #endif //RE_DEBUG |
| 2246 | boarddispatch->recvKibitz(QString(), "Opponent plays white"); |
| 2247 | if(gr->black_name != getUsername()) |
| 2248 | boarddispatch->swapColors(); |
| 2249 | else |
| 2250 | boarddispatch->swapColors(true); |
| 2251 | } |
| 2252 | else |
| 2253 | { |
| 2254 | packet[8] |= 0x80; //nigiri failure we play white |
| 2255 | //0xaf even 15 we play white |
| 2256 | #ifdef RE_DEBUG |
| 2257 | qDebug("nigiri failure"); |
| 2258 | #endif //RE_DEBUG |
| 2259 | boarddispatch->recvKibitz(QString(), "Opponent plays black"); |
| 2260 | if(gr->white_name != getUsername()) |
| 2261 | boarddispatch->swapColors(); |
| 2262 | else |
| 2263 | boarddispatch->swapColors(true); |
| 2264 | } |
| 2265 | //QMessageBox::information(0 , tr("sending niri"), tr("sending ") + QString::number(packet[8], 16) + tr(" nigiri.")); |
| 2266 | |
| 2267 | packet[9] = 0x00; //? |
| 2268 | packet[10] = 0x00; |
| 2269 | packet[11] = 0x00; |
| 2270 | |
| 2271 | /* Its possible to send this and confuse the ORO client |
| 2272 | * actually, if we send this, when we are challenging, |
| 2273 | * it thinks that the ORO client sent it.. ?!?! */ |
| 2274 | #ifdef RE_DEBUG |
| 2275 | printf("nigiri packet: "); |
| 2276 | for(int i = 0; i < (int)length; i++) |
| 2277 | printf("%02x ", packet[i]); |
| 2278 | printf("\n"); |
| 2279 | #endif //RE_DEBUG |
| 2280 | encode(packet, 0xc); |
| 2281 | qDebug("Sending nigiri"); |
| 2282 | if(write((const char *)packet, length) < 0) |
| 2283 | qWarning("*** failed sending nigiri"); |
| 2284 | delete[] packet; |
| 2285 | |
| 2286 | gr = boarddispatch->getGameData(); //get again |
| 2287 | /* FIXME don't think we start until second move */ |
| 2288 | startMatchTimers(gr->black_name == getUsername()); |
| 2289 | |
| 2290 | // we seem to immediately send keep alive here |
| 2291 | if(gr->black_name == getUsername()) |
| 2292 | sendGameUpdate(gr->game_code); |
| 2293 | } |
| 2294 | |
| 2295 | /* As in leave a played or in room game? Maybe rooms as well? |
| 2296 | * Double check, all those zeroes are suspicious. |
| 2297 | * Actually, probably same as sendObserve message for joining |
| 2298 | * a game? room? but with no possible password and no id. |
| 2299 | * Yeah, leave is basically the same thing as joining a room |
| 2300 | * except it joins the 00 room, I guess the lobby. |
| 2301 | * Also seems like we can observe after joining other rooms |
| 2302 | * without error, it just moves us. */ |
| 2303 | void CyberOroConnection::sendLeave(const GameListing *) |
| 2304 | { |
| 2305 | /* Find why leaving a joined game sends two leaves... */ |
| 2306 | if(room_were_in == 0) |
| 2307 | { |
| 2308 | qDebug("Attempted to sendLeave but in lobby!"); |
| 2309 | return; |
| 2310 | } |
| 2311 | #ifdef RE_DEBUG |
| 2312 | qDebug("Sending leave"); |
| 2313 | #endif //RE_DEBUG |
| 2314 | |
| 2315 | sendJoinRoom(0, NULL); |
| 2316 | |
| 2317 | setRoomNumber(0); |
| 2318 | } |
| 2319 | |
| 2320 | void CyberOroConnection::requestAccountInfo(void) |
| 2321 | { |
| 2322 | //QuickConnection * c = new QuickConnection(getQSocket(), NULL, this, QuickConnection::sendRequestAccountInfo); |
| 2323 | metaserverQC = new QuickConnection(hostname, port, NULL, this, QuickConnection::sendRequestAccountInfo); |
| 2324 | } |
| 2325 | |
| 2326 | char * CyberOroConnection::sendRequestAccountInfo(int * size, void *) |
| 2327 | { |
| 2328 | *size = 0x1a; |
| 2329 | char * packet = new char[*size]; |
| 2330 | packet[0] = 0x88; |
| 2331 | packet[1] = 0x27; |
| 2332 | packet[2] = 0x1a; |
| 2333 | packet[3] = 0x00; |
| 2334 | |
| 2335 | packet[4] = 0x40; |
| 2336 | packet[5] = 0x00; |
| 2337 | writeZeroPaddedString(&(packet[6]), getUsername(), 10); |
| 2338 | packet[16] = 0x43; |
| 2339 | packet[17] = 0x00; |
| 2340 | packet[18] = 0x12; |
| 2341 | packet[19] = 0x0f; |
| 2342 | packet[20] = 0xdc; |
| 2343 | packet[21] = 0x02; |
| 2344 | for(int i= 22; i < *size; i++) |
| 2345 | packet[i] = 0x00; |
| 2346 | #ifdef RE_DEBUG |
| 2347 | printf("requesting account info:\n"); |
| 2348 | for(int i = 0; i < (int)*size; i++) |
| 2349 | printf("%02x", packet[i]); |
| 2350 | printf("\n"); |
| 2351 | #endif //RE_DEBUG |
| 2352 | return packet; |
| 2353 | } |
| 2354 | |
| 2355 | void CyberOroConnection::handleAccountInfoMsg(int size, char * msg) |
| 2356 | { |
| 2357 | unsigned short message_type = msg[1] + (msg[0] << 8); |
| 2358 | |
| 2359 | msg += 4; |
| 2360 | size -=4; |
| 2361 | switch(message_type) |
| 2362 | { |
| 2363 | case 0x8129: |
| 2364 | handleFriends((unsigned char *)msg, size); |
| 2365 | metaserverQC->deleteLater(); |
| 2366 | metaserverQC = 0; |
| 2367 | break; |
| 2368 | case 0x7c29: |
| 2369 | //7c29 1a00 789e 0800 8800 b502 e0b0 887c |
| 2370 | //78de 0800 0100 0000 709e |
| 2371 | |
| 2372 | //7c29 1a00 000b 0900 ffff ffa0 00ff ffff |
| 2373 | //b502 ffff ffe0 ffff ffb0 ffff ff88 7c00 |
| 2374 | //4b09 0001 0000 00ff ffff f80a |
| 2375 | default: |
| 2376 | #ifdef RE_DEBUG |
| 2377 | msg -= 4; //FIXME |
| 2378 | printf("Strange account info: %02x%02x: \n", msg[0], msg[1]); |
| 2379 | for(int i = 2; i < (int)size + 4; i++) |
| 2380 | printf("%02x", msg[i]); |
| 2381 | printf("\n"); |
| 2382 | #endif //RE_DEBUG |
| 2383 | break; |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | void CyberOroConnection::sendLogin(void) |
| 2388 | { |
| 2389 | //term code could be version, probably just junk |
| 2390 | unsigned char term_code[2] = { 0x57, 0x04 }; //= { 0x5b, 0x02 }; |
| 2391 | int length = 0x1a; //10 + user and pass padded to 10 |
| 2392 | unsigned char * packet = new unsigned char[length]; |
| 2393 | unsigned char * p = packet; |
| 2394 | int i; |
| 2395 | |
| 2396 | p[0] = 0x0b; //= 0x6e; |
| 2397 | p[1] = 0xe1; //= 0xe2; |
| 2398 | p[2] = length; |
| 2399 | p[3] = 0x00; |
| 2400 | p += 4; |
| 2401 | |
| 2402 | writeZeroPaddedString((char *)p, username, 10); |
| 2403 | p += 10; |
| 2404 | |
| 2405 | writeZeroPaddedString((char *)p, password, 10); |
| 2406 | p += 10; |
| 2407 | for(i = 0; i < 2; i++) |
| 2408 | p[i] = term_code[i]; |
| 2409 | #ifdef RE_DEBUG |
| 2410 | for(i = 0; i < length; i++) |
| 2411 | printf("%02x ", packet[i]); |
| 2412 | printf("\n"); |
| 2413 | #endif //RE_DEBUG |
| 2414 | if(write((const char *)packet, length) < 0) |
| 2415 | qWarning("*** failed sending login packet to host"); |
| 2416 | delete[] packet; |
| 2417 | } |
| 2418 | |
| 2419 | void CyberOroConnection::sendInvitationSettings(bool invite) |
| 2420 | { |
| 2421 | unsigned int length = 0x0c; |
| 2422 | unsigned char * packet = new unsigned char[length]; |
| 2423 | packet[0] = 0x9a; |
| 2424 | packet[1] = 0x65; |
| 2425 | packet[2] = 0x0c; |
| 2426 | packet[3] = 0x00; |
| 2427 | packet[4] = our_player_id & 0x00ff; |
| 2428 | packet[5] = (our_player_id >> 8); |
| 2429 | packet[6] = 0x00; |
| 2430 | packet[7] = 0x00; |
| 2431 | packet[8] = (invite ? ALLOW_ALL_INVITES : IGNORE_ALL_INVITES); |
| 2432 | packet[9] = 0x00; |
| 2433 | packet[10] = 0x00; |
| 2434 | packet[11] = 0x00; //weird byte??? |
| 2435 | |
| 2436 | #ifdef RE_DEBUG |
| 2437 | printf("Sending invite settings: "); |
| 2438 | for(int i = 0; i < (int)length; i++) |
| 2439 | printf("%02x ", packet[i]); |
| 2440 | printf("\n"); |
| 2441 | #endif //RE_DEBUG |
| 2442 | encode(packet, 0xc); |
| 2443 | qDebug("Sending invitation settings\n"); |
| 2444 | if(write((const char *)packet, length) < 0) |
| 2445 | qWarning("*** failed sending invitation settings"); |
| 2446 | delete[] packet; |
| 2447 | } |
| 2448 | |
| 2449 | /* These four require separate connection to meta |
| 2450 | * server! */ |
| 2451 | void CyberOroConnection::addFriend(PlayerListing * player) |
| 2452 | { |
| 2453 | if(metaserverQC) |
| 2454 | { |
| 2455 | qDebug("Already connected to accounts server, please wait."); |
| 2456 | //silent no error might be okay |
| 2457 | return; |
| 2458 | } |
| 2459 | metaserverQC = new QuickConnection(hostname, port, (void *)player, this, QuickConnection::sendAddFriend); |
| 2460 | NetworkConnection::addFriend(player); |
| 2461 | } |
| 2462 | |
| 2463 | char * CyberOroConnection::sendFriendsBlocksMsg(int * size, void *p, enum FriendsBlocksMsgType f) |
| 2464 | { |
| 2465 | PlayerListing * player = (PlayerListing *)p; |
| 2466 | *size = 0x1a; |
| 2467 | char * packet = new char[*size]; |
| 2468 | if(f == fbm_addFriend || f == fbm_addBlock) |
| 2469 | packet[0] = 0x13; |
| 2470 | else |
| 2471 | packet[0] = 0x77; |
| 2472 | packet[1] = 0x29; |
| 2473 | packet[2] = (*size & 0xff); |
| 2474 | packet[3] = (*size >> 8); |
| 2475 | if(f == fbm_addFriend || f == fbm_removeFriend) |
| 2476 | packet[4] = 0x01; |
| 2477 | else |
| 2478 | packet[4] = 0x02; |
| 2479 | packet[5] = 0x00; |
| 2480 | writeZeroPaddedString((char *)&(packet[6]), getUsername(), 10); |
| 2481 | writeZeroPaddedString((char *)&(packet[16]), player->name, 10); |
| 2482 | return packet; |
| 2483 | } |
| 2484 | |
| 2485 | char * CyberOroConnection::sendAddFriend(int * size, void * p) |
| 2486 | { |
| 2487 | return sendFriendsBlocksMsg(size, p, fbm_addFriend); |
| 2488 | } |
| 2489 | |
| 2490 | #ifdef RE_DEBUG |
| 2491 | void CyberOroConnection::recvFriendResponse(int size, char * msg) |
| 2492 | #else |
| 2493 | void CyberOroConnection::recvFriendResponse(int size, char * /*msg*/) |
| 2494 | #endif //RE_DEBUG |
| 2495 | { |
| 2496 | if(size != 8) |
| 2497 | { |
| 2498 | qDebug("received friends list response of strange size: %d\n", size); |
| 2499 | //return; |
| 2500 | } |
| 2501 | //1f2708001a270000 |
| 2502 | #ifdef RE_DEBUG |
| 2503 | int i; |
| 2504 | printf("recvFriendResponse:\n"); |
| 2505 | for(i = 0; i < size; i++) |
| 2506 | printf("%02x", msg[i]); |
| 2507 | printf("\n"); |
| 2508 | #endif //RE_DEBUG |
| 2509 | metaserverQC->deleteLater(); |
| 2510 | metaserverQC = 0; |
| 2511 | } |
| 2512 | |
| 2513 | void CyberOroConnection::removeFriend(PlayerListing * player) |
| 2514 | { |
| 2515 | if(metaserverQC) |
| 2516 | { |
| 2517 | qDebug("Already connected to accounts server, please wait."); |
| 2518 | //silent no error might be okay |
| 2519 | return; |
| 2520 | } |
| 2521 | metaserverQC = new QuickConnection(hostname, port, (void *)player, this, QuickConnection::sendRemoveFriend); |
| 2522 | NetworkConnection::removeFriend(player); |
| 2523 | } |
| 2524 | |
| 2525 | char * CyberOroConnection::sendRemoveFriend(int * size, void * p) |
| 2526 | { |
| 2527 | return sendFriendsBlocksMsg(size, p, fbm_removeFriend); |
| 2528 | } |
| 2529 | |
| 2530 | void CyberOroConnection::addBlock(PlayerListing * player) |
| 2531 | { |
| 2532 | if(metaserverQC) |
| 2533 | { |
| 2534 | qDebug("Already connected to accounts server, please wait."); |
| 2535 | //silent no error might be okay |
| 2536 | return; |
| 2537 | } |
| 2538 | metaserverQC = new QuickConnection(hostname, port, (void *)player, this, QuickConnection::sendAddBlock); |
| 2539 | NetworkConnection::addBlock(player); |
| 2540 | } |
| 2541 | |
| 2542 | void CyberOroConnection::removeBlock(PlayerListing * player) |
| 2543 | { |
| 2544 | if(metaserverQC) |
| 2545 | { |
| 2546 | qDebug("Already connected to accounts server, please wait."); |
| 2547 | //silent no error might be okay |
| 2548 | return; |
| 2549 | } |
| 2550 | metaserverQC = new QuickConnection(hostname, port, (void *)player, this, QuickConnection::sendRemoveBlock); |
| 2551 | NetworkConnection::removeBlock(player); |
| 2552 | } |
| 2553 | |
| 2554 | char * CyberOroConnection::sendAddBlock(int * size, void * p) |
| 2555 | { |
| 2556 | return sendFriendsBlocksMsg(size, p, fbm_addBlock); |
| 2557 | } |
| 2558 | |
| 2559 | char * CyberOroConnection::sendRemoveBlock(int * size, void * p) |
| 2560 | { |
| 2561 | return sendFriendsBlocksMsg(size, p, fbm_removeBlock); |
| 2562 | } |
| 2563 | |
| 2564 | void CyberOroConnection::sendDisconnectMsg(void) |
| 2565 | { |
| 2566 | if(!codetable) |
| 2567 | return; |
| 2568 | unsigned char * packet = new unsigned char[8]; |
| 2569 | packet[0] = 0x1c; |
| 2570 | packet[1] = 0x52; |
| 2571 | packet[2] = 0x08; |
| 2572 | packet[3] = 0x00; |
| 2573 | packet[4] = our_player_id & 0x00ff; |
| 2574 | packet[5] = (our_player_id >> 8); |
| 2575 | packet[6] = 0x00; //zeroes for fun?? FIXME |
| 2576 | packet[7] = 0x00; |
| 2577 | |
| 2578 | encode(packet, 8); |
| 2579 | #ifdef RE_DEBUG |
| 2580 | qDebug("Sending disconnect msg"); |
| 2581 | #endif //RE_DEBUG |
| 2582 | if(write((const char *)packet, 8) < 0) |
| 2583 | qWarning("*** failed sending disconnect packet"); |
| 2584 | delete[] packet; |
| 2585 | } |
| 2586 | |
| 2587 | /* This is a challenge-response message. The meta-server validates |
| 2588 | * the name and password and sends a chunk of something which is |
| 2589 | * then passed to whatever servers the client connects to */ |
| 2590 | /* This isn't a challenge response probably but just a server |
| 2591 | * connect packet... that's my guess. |
| 2592 | * It seems like this is sent when we switch servers mid session so |
| 2593 | * yeah...*/ |
| 2594 | void CyberOroConnection::sendChallengeResponse(void) |
| 2595 | { |
| 2596 | int i; |
| 2597 | unsigned char * p; |
| 2598 | unsigned char packet[120]; |
| 2599 | p = packet; |
| 2600 | /* The opening four bytes are operated on by some kind of cyclic |
| 2601 | * xor in a table... we're still working it out. Also below |
| 2602 | * may have two options as well. DONE */ |
| 2603 | p[0] = 0x07; |
| 2604 | p[1] = 0x52; |
| 2605 | p[2] = 0x78; |
| 2606 | p[3] = 0x00; |
| 2607 | encode(p, 6); |
| 2608 | p += 4; |
| 2609 | for(i = 0; i < 106; i++) |
| 2610 | p[i] = challenge_response[i]; |
| 2611 | p += 106; |
| 2612 | /* I think this 05 can change but I'm not certain. */ |
| 2613 | p[0] = 0x05; |
| 2614 | p[1] = 0x00; |
| 2615 | p += 2; |
| 2616 | /* These 4 bytes are literally random, we can put |
| 2617 | * anything here */ |
| 2618 | p[0] = 0x01; |
| 2619 | p[1] = 0x02; |
| 2620 | p[2] = 0x03; |
| 2621 | p[3] = 0x04; |
| 2622 | p += 4; |
| 2623 | p[0] = 0x31; |
| 2624 | p[1] = 0x2e; |
| 2625 | p[2] = 0x33; |
| 2626 | p[3] = 0x38; |
| 2627 | #ifdef RE_DEBUG |
| 2628 | printf("Sending challenge response\n"); |
| 2629 | for(i = 0; i < 120; i++) |
| 2630 | printf("%02x ", packet[i]); |
| 2631 | printf("\n"); |
| 2632 | #endif //RE_DEBUG |
| 2633 | if(write((const char *)packet, 120) < 0) |
| 2634 | qWarning("*** failed sending challenge response"); |
| 2635 | } |
| 2636 | |
| 2637 | /* I think the codetable is used so that the session can't |
| 2638 | * be violated or forged. In other words, since we're the |
| 2639 | * only client with the right codetable and the right IV |
| 2640 | * position in that code table as by all the messages we've |
| 2641 | * sent, no one can, for instance, send a move packet with |
| 2642 | * our name and make us make a move that we don't intend. |
| 2643 | * Seems that there could be simpler ways to do it and I |
| 2644 | * do wonder if its partly for obfuscation still.*/ |
| 2645 | void CyberOroConnection::encode(unsigned char * h, unsigned int cycle_size) |
| 2646 | { |
| 2647 | int i; |
| 2648 | unsigned char a = 0xff; |
| 2649 | int IV3 = cycle_size; //maybe we're passed this? |
| 2650 | |
| 2651 | IV3 -= 3; |
| 2652 | /* sub edx, eax jl */ |
| 2653 | IV3++; |
| 2654 | for(i = 0; i < IV3; i++) |
| 2655 | { |
| 2656 | h[i] = h[i] ^ codetable[codetable_IV]; |
| 2657 | a = h[i] ^ a; |
| 2658 | codetable_IV++; |
| 2659 | codetable_IV %= 1000; //double check!!! could be /!! |
| 2660 | if(codetable_IV == 0) //should probably be % 1000 ==, not %=!!! |
| 2661 | { |
| 2662 | codetable_IV2++; |
| 2663 | qDebug("incrementing codetable_IV2: %d", codetable_IV2); |
| 2664 | } |
| 2665 | } |
| 2666 | if(cycle_size >= 8) |
| 2667 | { |
| 2668 | /* 16000f points to the byte before the header for some reason */ |
| 2669 | h[cycle_size - 1/* + [codetable +34d3]*/] = a; |
| 2670 | } |
| 2671 | if(codetable_IV2 >= 10) |
| 2672 | { |
| 2673 | if(codetable_IV >= 900) |
| 2674 | { |
| 2675 | /* looks like we zero codetable_IV2 and |
| 2676 | * then do some crazy repeated shit */ |
| 2677 | } |
| 2678 | } |
| 2679 | } |
| 2680 | |
| 2681 | void CyberOroConnection::handleMessage(QString) |
| 2682 | { |
| 2683 | } |
| 2684 | |
| 2685 | /* We may convert everything here to unsigned char *s, delete the old... |
| 2686 | * we're still sort of hung up on all the things we were doing |
| 2687 | * to work with the IGS code. */ |
| 2688 | void CyberOroConnection::handleMessage(unsigned char * msg, unsigned int size) |
| 2689 | { |
| 2690 | unsigned short message_type = msg[1] + (msg[0] << 8); |
| 2691 | //message_type = msg[0]; |
| 2692 | //message_type >>= 8; |
| 2693 | //message_type += msg[1]; |
| 2694 | /* Third byte is likely the size of the message meaning multiple |
| 2695 | * messages per packet, etc. */ |
| 2696 | /*if((message_type & 0x00ff) == 0x00b3) |
| 2697 | {*/ |
| 2698 | #ifdef RE_DEBUG |
| 2699 | //seems unnecessary even for debug |
| 2700 | /*printf("****: \n"); |
| 2701 | for(unsigned int i = 0; i < size; i++) |
| 2702 | printf("%02x", msg[i]); |
| 2703 | printf("\n");*/ |
| 2704 | #endif //RE_DEBUG |
| 2705 | /*}*/ |
| 2706 | msg += 4; |
| 2707 | size -=4; |
| 2708 | switch(message_type) |
| 2709 | { |
| 2710 | case ORO_CODETABLE: |
| 2711 | handleCodeTable(msg, size); |
| 2712 | break; |
| 2713 | case 0x2652: |
| 2714 | handleConnected(msg, size); |
| 2715 | break; |
| 2716 | case ORO_PLAYERLIST: |
| 2717 | handlePlayerList(msg, size); |
| 2718 | break; |
| 2719 | /*case 0xfa00: |
| 2720 | printf("likely game message\n"); |
| 2721 | break;*/ |
| 2722 | case 0x2c56: |
| 2723 | #ifdef RE_DEBUG |
| 2724 | printf("0x2c56: some kind of logon"); |
| 2725 | for(unsigned int i = 0; i < size; i++) |
| 2726 | printf("%02x", msg[i]); |
| 2727 | printf("\n"); |
| 2728 | #endif //RE_DEBUG |
| 2729 | break; |
| 2730 | case ORO_BROADCASTLIST: |
| 2731 | //boardcast games list |
| 2732 | handleBroadcastGamesList(msg, size); |
| 2733 | break; |
| 2734 | case ORO_ROOMLIST: |
| 2735 | handleRoomList(msg, size); |
| 2736 | break; |
| 2737 | case 0xb261: |
| 2738 | #ifdef RE_DEBUG |
| 2739 | printf("0xb261: "); |
| 2740 | for(unsigned int i = 0; i < size; i++) |
| 2741 | printf("%02x", msg[i]); |
| 2742 | printf("\n"); |
| 2743 | #endif //RE_DEBUG |
| 2744 | break; |
| 2745 | case 0xee61: |
| 2746 | #ifdef RE_DEBUG |
| 2747 | printf("0xee61: "); |
| 2748 | for(unsigned int i = 0; i < size; i++) |
| 2749 | printf("%02x", msg[i]); |
| 2750 | printf("\n"); |
| 2751 | #endif //RE_DEBUG |
| 2752 | break; |
| 2753 | case 0xdf61: |
| 2754 | #ifdef RE_DEBUG |
| 2755 | printf("0xdf61: "); |
| 2756 | for(unsigned int i = 0; i < size; i++) |
| 2757 | printf("%02x", msg[i]); |
| 2758 | printf("\n"); |
| 2759 | #endif //RE_DEBUG |
| 2760 | break; |
| 2761 | case 0xe461: |
| 2762 | handleMsg2(msg, size); |
| 2763 | break; |
| 2764 | case 0x62f2: //0x94 bytes, this looks a LIVE GO game listing entry |
| 2765 | /*0000 0600 5046 cc13 b91d 0303 0000 3c03 0200 4873 6965 682e 592e 4d00 0000 |
| 2766 | 0000 0000 5375 7a75 6b69 2e41 0000 0000 0000 0000 |
| 2767 | 8ed3 88cb 9ddf 0000 0000 0000 0000 0000 97e9 96d8 95e0 0000 |
| 2768 | 0000 0000 0000 0000 0303 c4c4 0305 0000 0000 0000 |
| 2769 | 91e6 3237 8afa 8f97 97ac 967b 88f6 9656 90ed 91e6 318b |
| 2770 | c700000000000000000000000000000000000000000000000100001f*/ |
| 2771 | #ifdef RE_DEBUG |
| 2772 | printf("0x62f2: "); |
| 2773 | for(unsigned int i = 0; i < size; i++) |
| 2774 | printf("%02x", msg[i]); |
| 2775 | printf("\n"); |
| 2776 | #endif //RE_DEBUG |
| 2777 | break; |
| 2778 | case 0x68f6: |
| 2779 | //could this mean connected? |
| 2780 | #ifdef RE_DEBUG |
| 2781 | printf("0x68f6: "); |
| 2782 | for(unsigned int i = 0; i < size; i++) |
| 2783 | printf("%02x", msg[i]); |
| 2784 | printf("\n"); |
| 2785 | #endif //RE_DEBUG |
| 2786 | break; |
| 2787 | case ORO_GAMELIST: |
| 2788 | handleGamesList(msg, size); |
| 2789 | break; |
| 2790 | case ORO_PLAYERROOMJOIN: |
| 2791 | handlePlayerRoomJoin(msg, size); |
| 2792 | break; |
| 2793 | case 0x0456: |
| 2794 | handlePlayerConnect(msg, size); |
| 2795 | break; |
| 2796 | case 0x5ac3: |
| 2797 | handleGamePhaseUpdate(msg, size); |
| 2798 | break; |
| 2799 | case 0x50c3: |
| 2800 | handleMsg3(msg, size); |
| 2801 | break; |
| 2802 | case 0x38f4: |
| 2803 | /* FIXME, this needs to maybe open a board, |
| 2804 | * maybe not... but something needs to */ |
| 2805 | handleBettingMatchStart(msg, size); |
| 2806 | break; |
| 2807 | case 0x56f4: |
| 2808 | handleBettingMatchResult(msg, size); |
| 2809 | break; |
| 2810 | case ORO_BROADCASTMOVE: //betting match? |
| 2811 | case ORO_MOVE: |
| 2812 | handleMove(msg, size); |
| 2813 | break; |
| 2814 | case ORO_UNDO: |
| 2815 | handleUndo(msg, size); |
| 2816 | break; |
| 2817 | case ORO_DECLINEUNDO: |
| 2818 | handleDeclineUndo(msg, size); |
| 2819 | break; |
| 2820 | case ORO_ACCEPTUNDO: |
| 2821 | handleAcceptUndo(msg, size); //generic undo? |
| 2822 | break; |
| 2823 | case ORO_MOVELIST: |
| 2824 | handleMoveList(msg, size); |
| 2825 | break; |
| 2826 | case ORO_BROADCASTMOVELIST: |
| 2827 | handleMoveList2(msg, size); |
| 2828 | break; |
| 2829 | case 0xd2af: |
| 2830 | handleMatchOpened(msg, size); |
| 2831 | break; |
| 2832 | case 0x5fc3: |
| 2833 | handleResumeMatch(msg, size); |
| 2834 | break; |
| 2835 | //case 0x38f4: |
| 2836 | // handleObserveAfterJoining(msg, size); |
| 2837 | // break; |
| 2838 | case 0x9a65: |
| 2839 | handleInvitationSettings(msg, size); |
| 2840 | break; |
| 2841 | case 0xf5af: |
| 2842 | handleNigiri(msg, size); |
| 2843 | break; |
| 2844 | case 0x1e7d: //match invite accept |
| 2845 | handleMatchOfferPending(msg, size); |
| 2846 | break; |
| 2847 | case 0x147d: |
| 2848 | handleAcceptMatchInvite(msg, size); |
| 2849 | break; |
| 2850 | case 0x459c: |
| 2851 | #ifdef RE_DEBUG |
| 2852 | // we send this as finish observing |
| 2853 | printf("0x459c: finish observing?"); |
| 2854 | for(unsigned int i = 0; i < size; i++) |
| 2855 | printf("%02x", msg[i]); |
| 2856 | printf("\n"); |
| 2857 | #endif //RE_DEBUG |
| 2858 | break; |
| 2859 | case 0x2279: |
| 2860 | handleMatchInvite(msg, size); |
| 2861 | break; |
| 2862 | case 0x1a7d: |
| 2863 | #ifdef RE_DEBUG |
| 2864 | printf("0x1a7d: game starting? "); |
| 2865 | for(unsigned int i = 0; i < size; i++) |
| 2866 | printf("%02x", msg[i]); |
| 2867 | printf("\n"); |
| 2868 | #endif //RE_DEBUG |
| 2869 | break; |
| 2870 | case 0x0a7d: |
| 2871 | handleNewRoom(msg, size); |
| 2872 | break; |
| 2873 | case 0x1a81: |
| 2874 | handleGameMsg(msg, size); |
| 2875 | break; |
| 2876 | case ORO_CREATEROOM: //was WantsMatch |
| 2877 | handleCreateRoom(msg, size); |
| 2878 | break; |
| 2879 | case ORO_RESIGN: |
| 2880 | handleResign(msg, size); |
| 2881 | break; |
| 2882 | case ORO_REMOVESTONES: |
| 2883 | handleRemoveStones(msg, size); |
| 2884 | break; |
| 2885 | case ORO_STONESDONE: |
| 2886 | handleStonesDone(msg, size); |
| 2887 | break; |
| 2888 | case 0xe7b3: //response to our done |
| 2889 | handleScore(msg, size); |
| 2890 | break; |
| 2891 | case 0x8fbb: |
| 2892 | #ifdef RE_DEBUG |
| 2893 | //thinking this is just a match result |
| 2894 | printf("0xtime: 8fbb: "); |
| 2895 | for(unsigned int i = 0; i < size; i++) |
| 2896 | printf("%02x", msg[i]); |
| 2897 | printf("\n"); |
| 2898 | #endif //RE_DEBUG |
| 2899 | break; |
| 2900 | case 0x85bb: |
| 2901 | handleNewGame(msg, size); //really game result? |
| 2902 | break; |
| 2903 | case 0xecb3: //something to do with done messages in matches |
| 2904 | #ifdef RE_DEBUG |
| 2905 | /* Its possible, see out151, that one of these |
| 2906 | * bytes is just supposed to be passed back |
| 2907 | * or even that the ecb3 is like an angry, |
| 2908 | * response to a bad done message*/ |
| 2909 | printf("0xecb3: "); |
| 2910 | for(unsigned int i = 0; i < size; i++) |
| 2911 | printf("%02x", msg[i]); |
| 2912 | printf("\n"); |
| 2913 | #endif //RE_DEBUG |
| 2914 | break; |
| 2915 | /* One of the below 6 indicates we've joined an adjourned |
| 2916 | * game that's already in score mode */ |
| 2917 | /* Actually I think eede just means we've resumed the game. |
| 2918 | * we're just going to make the moveList aware of it */ |
| 2919 | case 0xeede: |
| 2920 | // this looks like an end observer list msg |
| 2921 | /* Its probably this one, its immediately followed by |
| 2922 | * a game id*/ |
| 2923 | #ifdef RE_DEBUG |
| 2924 | printf("0xeede: "); |
| 2925 | for(unsigned int i = 0; i < size; i++) |
| 2926 | printf("%02x", msg[i]); |
| 2927 | printf("\n"); |
| 2928 | #endif //RE_DEBUG |
| 2929 | break; |
| 2930 | case 0xdfde: |
| 2931 | //probably not observer list!!! |
| 2932 | handleObserverList(msg, size); |
| 2933 | break; |
| 2934 | case 0xadde: |
| 2935 | #ifdef RE_DEBUG |
| 2936 | printf("0xadde: "); |
| 2937 | for(unsigned int i = 0; i < size; i++) |
| 2938 | printf("%02x", msg[i]); |
| 2939 | printf("\n"); |
| 2940 | #endif //RE_DEBUG |
| 2941 | break; |
| 2942 | case 0xa8de: |
| 2943 | #ifdef RE_DEBUG |
| 2944 | printf("a8de: "); |
| 2945 | for(unsigned int i = 0; i < size; i++) |
| 2946 | printf("%02x", msg[i]); |
| 2947 | printf("\n"); |
| 2948 | #endif //RE_DEBUG |
| 2949 | break; |
| 2950 | case 0xc4fe: |
| 2951 | #ifdef RE_DEBUG |
| 2952 | printf("0xc4fe: "); |
| 2953 | for(unsigned int i = 0; i < size; i++) |
| 2954 | printf("%02x", msg[i]); |
| 2955 | printf("\n"); |
| 2956 | #endif //RE_DEBUG |
| 2957 | break; |
| 2958 | case 0xedfd: |
| 2959 | #ifdef RE_DEBUG |
| 2960 | printf("0xedfd: "); |
| 2961 | for(unsigned int i = 0; i < size; i++) |
| 2962 | printf("%02x", msg[i]); |
| 2963 | printf("\n"); |
| 2964 | #endif //RE_DEBUG |
| 2965 | break; |
| 2966 | case 0x06fe: |
| 2967 | #ifdef RE_DEBUG |
| 2968 | printf("0x06fe: "); |
| 2969 | for(unsigned int i = 0; i < size; i++) |
| 2970 | printf("%02x", msg[i]); |
| 2971 | printf("\n"); |
| 2972 | #endif //RE_DEBUG |
| 2973 | break; |
| 2974 | case 0x01fe: |
| 2975 | #ifdef RE_DEBUG |
| 2976 | printf("0x01fe: "); |
| 2977 | for(unsigned int i = 0; i < size; i++) |
| 2978 | printf("%02x", msg[i]); |
| 2979 | printf("\n"); |
| 2980 | #endif //RE_DEBUG |
| 2981 | break; |
| 2982 | case 0x0bfe: |
| 2983 | #ifdef RE_DEBUG |
| 2984 | printf("0x0bfe: "); |
| 2985 | for(unsigned int i = 0; i < size; i++) |
| 2986 | printf("%02x", msg[i]); |
| 2987 | printf("\n"); |
| 2988 | #endif //RE_DEBUG |
| 2989 | break; |
| 2990 | //82c3: 0a00b60ca23a6816 |
| 2991 | //*** |
| 2992 | case 0x82c3: |
| 2993 | #ifdef RE_DEBUG |
| 2994 | printf("0x82c3: "); |
| 2995 | for(unsigned int i = 0; i < size; i++) |
| 2996 | printf("%02x", msg[i]); |
| 2997 | printf("\n"); |
| 2998 | #endif //RE_DEBUG |
| 2999 | break; |
| 3000 | case 0xc4b3: |
| 3001 | handleRequestCount(msg, size); |
| 3002 | break; |
| 3003 | case 0xceb3: |
| 3004 | handleRejectCountRequest(msg, size); |
| 3005 | break; |
| 3006 | case 0x05b4: |
| 3007 | handleRequestMatchMode(msg, size); |
| 3008 | break; |
| 3009 | case 0x0ab4: |
| 3010 | handleRejectMatchModeRequest(msg, size); |
| 3011 | break; |
| 3012 | case 0x20cb: |
| 3013 | { |
| 3014 | #ifdef RE_DEBUG |
| 3015 | PlayerListing * p = getDefaultRoom()->getPlayerListing(msg[0] + (msg[1] << 8)); |
| 3016 | printf("0x20cb %s: ", (p ? p->name.toLatin1().constData() : "-")); |
| 3017 | for(unsigned int i = 0; i < size; i++) |
| 3018 | printf("%02x", msg[i]); |
| 3019 | printf("\n"); |
| 3020 | #endif //RE_DEBUG |
| 3021 | } |
| 3022 | break; |
| 3023 | case ORO_TIMELOSS: |
| 3024 | handleTimeLoss(msg, size); |
| 3025 | break; |
| 3026 | case 0x69c3: |
| 3027 | handleRematchRequest(msg, size); |
| 3028 | break; |
| 3029 | case 0x6ec3: |
| 3030 | handleRematchAccept(msg, size); |
| 3031 | break; |
| 3032 | case ORO_SETPHRASECHAT: |
| 3033 | handleSetPhraseChatMsg(msg, size); |
| 3034 | break; |
| 3035 | case 0x327d: |
| 3036 | handleMatchDecline(msg, size); |
| 3037 | break; |
| 3038 | case 0xbc61: |
| 3039 | #ifdef RE_DEBUG |
| 3040 | printf("0xbc61: "); |
| 3041 | for(unsigned int i = 0; i < size; i++) |
| 3042 | printf("%02x", msg[i]); |
| 3043 | printf("\n"); |
| 3044 | #endif //RE_DEBUG |
| 3045 | break; |
| 3046 | case 0x162b: |
| 3047 | #ifdef RE_DEBUG |
| 3048 | printf("0x162b: "); |
| 3049 | for(unsigned int i = 0; i < size; i++) |
| 3050 | printf("%02x", msg[i]); |
| 3051 | printf("\n"); |
| 3052 | #endif //RE_DEBUG |
| 3053 | break; |
| 3054 | case 0x60f4: |
| 3055 | #ifdef RE_DEBUG |
| 3056 | printf("0x60f4: "); |
| 3057 | for(unsigned int i = 0; i < size; i++) |
| 3058 | printf("%02x", msg[i]); |
| 3059 | printf("\n"); |
| 3060 | #endif //RE_DEBUG |
| 3061 | break; |
| 3062 | case 0x78c3: |
| 3063 | #ifdef RE_DEBUG |
| 3064 | printf("0x78c3: "); |
| 3065 | for(unsigned int i = 0; i < size; i++) |
| 3066 | printf("%02x", msg[i]); |
| 3067 | printf("\n"); |
| 3068 | #endif //RE_DEBUG |
| 3069 | break; |
| 3070 | case 0xa479: |
| 3071 | handleDeclineMatchInvite(msg, size); |
| 3072 | break; |
| 3073 | case 0x285a: //maybe a special tournament announcement or something |
| 3074 | case ORO_SERVERANNOUNCE: |
| 3075 | handleServerAnnouncement(msg, size); |
| 3076 | break; |
| 3077 | case ORO_SERVERANNOUNCELINK: |
| 3078 | handleServerAnnouncementwithLink(msg, size); |
| 3079 | break; |
| 3080 | case 0x0c2b: |
| 3081 | #ifdef RE_DEBUG |
| 3082 | printf("0x0c2b: "); |
| 3083 | for(unsigned int i = 0; i < size; i++) |
| 3084 | printf("%02x", msg[i]); |
| 3085 | printf("\n"); |
| 3086 | #endif //RE_DEBUG |
| 3087 | break; |
| 3088 | case 0x39cb: |
| 3089 | { |
| 3090 | #ifdef RE_DEBUG |
| 3091 | PlayerListing * p = getDefaultRoom()->getPlayerListing(msg[0] + (msg[1] << 8)); |
| 3092 | printf("0x39cb %s: ", (p ? p->name.toLatin1().constData() : "-")); |
| 3093 | for(unsigned int i = 0; i < size; i++) |
| 3094 | printf("%02x", msg[i]); |
| 3095 | printf("\n"); |
| 3096 | #endif //RE_DEBUG |
| 3097 | } |
| 3098 | break; |
| 3099 | case 0x3ff2: |
| 3100 | #ifdef RE_DEBUG |
| 3101 | printf("0x3ff2: "); |
| 3102 | for(unsigned int i = 0; i < size; i++) |
| 3103 | printf("%02x", msg[i]); |
| 3104 | printf("\n"); |
| 3105 | #endif //RE_DEBUG |
| 3106 | break; |
| 3107 | case 0x482b: //bad challenge response response? |
| 3108 | /* I think this might indicate a full server */ |
| 3109 | QMessageBox::information(0, tr("Server full"), tr("Server full, try another")); |
| 3110 | if(reconnectToServer() < 0) |
| 3111 | { |
| 3112 | qDebug("User canceled"); |
| 3113 | setState(Canceled); |
| 3114 | return; |
| 3115 | } |
| 3116 | #ifdef RE_DEBUG |
| 3117 | printf("0x482b: "); |
| 3118 | for(unsigned int i = 0; i < size; i++) |
| 3119 | printf("%02x", msg[i]); |
| 3120 | printf("\n"); |
| 3121 | #endif //RE_DEBUG |
| 3122 | break; |
| 3123 | case 0x022b: |
| 3124 | #ifdef RE_DEBUG |
| 3125 | /* This looks like its trying to correct the protocol |
| 3126 | * or something, like its giving us either the msg type |
| 3127 | * we should have sent or the last one sent */ |
| 3128 | printf("0x022b: "); |
| 3129 | for(unsigned int i = 0; i < size; i++) |
| 3130 | printf("%02x", msg[i]); |
| 3131 | printf("\n"); |
| 3132 | #endif //RE_DEBUG |
| 3133 | break; |
| 3134 | case 0x1356: |
| 3135 | #ifdef RE_DEBUG |
| 3136 | printf("0x1356 likely player disconnect: "); |
| 3137 | for(unsigned int i = 0; i < size; i++) |
| 3138 | printf("%02x", msg[i]); |
| 3139 | printf("\n"); |
| 3140 | #endif //RE_DEBUG |
| 3141 | break; |
| 3142 | case ORO_ENTERSCORING: |
| 3143 | handleEnterScoring(msg, size); |
| 3144 | break; |
| 3145 | case ORO_ADJOURNREQUEST: |
| 3146 | handleAdjournRequest(msg, size); |
| 3147 | break; |
| 3148 | case ORO_ADJOURNDECLINE: |
| 3149 | handleAdjournDecline(msg ,size); |
| 3150 | break; |
| 3151 | case ORO_ADJOURN: |
| 3152 | handleAdjourn(msg, size); |
| 3153 | break; |
| 3154 | case ORO_LOBBYCHAT: |
| 3155 | handleServerRoomChat(msg, size); |
| 3156 | /* We'll eventually need to translate these into unicode characters |
| 3157 | * and it looks like they have a player id that comes before */ |
| 3158 | break; |
| 3159 | case ORO_ROOMCHAT: |
| 3160 | handleRoomChat(msg, size); |
| 3161 | break; |
| 3162 | case ORO_PERSONALCHAT: |
| 3163 | handlePersonalChat(msg, size); |
| 3164 | break; |
| 3165 | case 0xe1af: //FIXME maybe not |
| 3166 | handleGameEnded(msg, size); |
| 3167 | break; |
| 3168 | case 0x4a9c: |
| 3169 | handlePlayerDisconnect2(msg, size); |
| 3170 | break; |
| 3171 | case ORO_MATCHOFFER: |
| 3172 | handleMatchOffer(msg, size); |
| 3173 | break; |
| 3174 | default: |
| 3175 | #ifdef RE_DEBUG |
| 3176 | msg -= 4; //FIXME |
| 3177 | printf("Two bytestrange: %02x%02x: \n", msg[0], msg[1]); |
| 3178 | //#ifdef RE_DEBUG |
| 3179 | for(unsigned int i = 2; i < size + 4; i++) |
| 3180 | printf("%02x", msg[i]); |
| 3181 | printf("\n"); |
| 3182 | #endif //RE_DEBUG |
| 3183 | break; |
| 3184 | } |
| 3185 | } |
| 3186 | |
| 3187 | /* Last byte is a kind of initialization vector, IV */ |
| 3188 | void CyberOroConnection::handleCodeTable(unsigned char * msg, unsigned int size) |
| 3189 | { |
| 3190 | unsigned char * p = msg; |
| 3191 | int i; |
| 3192 | |
| 3193 | if(size != 1002) |
| 3194 | qDebug("code table message of size: %d", size); |
| 3195 | if(codetable) |
| 3196 | delete[] codetable; |
| 3197 | codetable = new unsigned char[1000]; |
| 3198 | for(i = 0; i < 1000; i++) |
| 3199 | codetable[i] = p[i]; |
| 3200 | codetable_IV = p[1000]; |
| 3201 | codetable_IV2 = 0; |
| 3202 | |
| 3203 | sendChallengeResponse(); |
| 3204 | } |
| 3205 | |
| 3206 | void CyberOroConnection::handleConnected(unsigned char * msg, unsigned int size) |
| 3207 | { |
| 3208 | unsigned char * p = msg; |
| 3209 | if(size != 10) |
| 3210 | qDebug("handleConnected size: %d", size); |
| 3211 | our_player_id = p[0] + (p[1] << 8); |
| 3212 | #ifdef RE_DEBUG |
| 3213 | qDebug("our id: %02x%02x %02x\n", p[0], p[1], p[2]); |
| 3214 | #endif //RE_DEBUG |
| 3215 | our_special_byte = p[2]; |
| 3216 | p += 6; |
| 3217 | |
| 3218 | onReady(); //is this okay? |
| 3219 | |
| 3220 | //try this here |
| 3221 | //sendInvitationSettings(true); //for now |
| 3222 | // FIXME, toggle is doing this now, but is it kosher with initial state? |
| 3223 | // i.e., when we first join what happens? where does that get checked? |
| 3224 | } |
| 3225 | |
| 3226 | #ifdef NEWPROTOCOL |
| 3227 | /*OROPlayerListPacket::OROPlayerListPacket(char * p) |
| 3228 | { |
| 3229 | data = p; |
| 3230 | }*/ |
| 3231 | |
| 3232 | //void * ZeroPaddedString::operator new[] (size_t s) { size = s; }; |
| 3233 | |
| 3234 | void CyberOroConnection::handlePlayerList(unsigned char * msg, unsigned int size) |
| 3235 | { |
| 3236 | unsigned char * p = msg; |
| 3237 | unsigned char name[11]; |
| 3238 | int players; |
| 3239 | unsigned char rankbyte, invitebyte; |
| 3240 | int i; |
| 3241 | unsigned short id; |
| 3242 | OROPlayerListPacket packet((char *)msg); |
| 3243 | Room * room = getDefaultRoom(); |
| 3244 | PlayerListing * newPlayer = new PlayerListing(); |
| 3245 | PlayerListing * aPlayer; |
| 3246 | PlayerListing * backPlayer; |
| 3247 | newPlayer->online = true; |
| 3248 | newPlayer->info = "??"; |
| 3249 | newPlayer->playing = 0; |
| 3250 | newPlayer->observing = 0; |
| 3251 | newPlayer->idletime = "-"; |
| 3252 | |
| 3253 | players = p[2]; |
| 3254 | |
| 3255 | #ifdef RE_DEBUG |
| 3256 | printf("%02x%02x\n", p[0], p[1]); |
| 3257 | #endif //RE_DEBUG |
| 3258 | printf("new players: %d\n", packet.h.playerRecords); |
| 3259 | p += 2; |
| 3260 | //676c696c696e6e000000 770a 16a4 02c3 0000 9b72 e607 e407 0000 0056 |
| 3261 | while(p < (msg + size)) |
| 3262 | { |
| 3263 | #ifdef RE_DEBUG |
| 3264 | for(i = 0; i < 28; i++) |
| 3265 | printf("%02x", p[i]); |
| 3266 | printf("\n"); |
| 3267 | #endif //RE_DEBUG |
| 3268 | strncpy((char *)name, (char *)p, 10); name[10] = 0x00; |
| 3269 | #ifdef RE_DEBUG |
| 3270 | printf("%s ", name); |
| 3271 | #endif //RE_DEBUG |
| 3272 | p += 10; |
| 3273 | id = p[0] + (p[1] << 8); |
| 3274 | aPlayer = room->getPlayerListing(id); |
| 3275 | if(!aPlayer) |
| 3276 | { |
| 3277 | aPlayer = newPlayer; |
| 3278 | newPlayer->playing = 0; |
| 3279 | } |
| 3280 | aPlayer->id = id; |
| 3281 | if(strncmp((char *)name, "jguest", 6) == 0 || strncmp((char *)name, "jpguest", 7) == 0) |
| 3282 | aPlayer->hidden = true; |
| 3283 | else |
| 3284 | aPlayer->hidden = false; |
| 3285 | //aPlayer->name = QString((char*)name); |
| 3286 | aPlayer->name = serverCodec->toUnicode((const char *)name, strlen((const char *)name)); |
| 3287 | |
| 3288 | p += 2; |
| 3289 | //a byte here seems to be a send msg byte, or something |
| 3290 | aPlayer->specialbyte = p[0]; |
| 3291 | //p++; |
| 3292 | #ifdef RE_DEBUG |
| 3293 | for(i = 0; i < 8; i++) |
| 3294 | printf("%02x", p[i]); |
| 3295 | #endif //RE_DEBUG |
| 3296 | // That's right, its the pro bit |
| 3297 | rankbyte = p[1]; |
| 3298 | if(rankbyte & 0x40) |
| 3299 | { |
| 3300 | aPlayer->pro = true; |
| 3301 | } |
| 3302 | else |
| 3303 | aPlayer->pro = false; |
| 3304 | |
| 3305 | //lost interest, its not the game |
| 3306 | //aPlayer->observing = p[2]; //FIXME, what is this? |
| 3307 | //this fourth byte here is country I think. |
| 3308 | // but its really unreliable, almost like its something |
| 3309 | // that clients from these countries have as a setting |
| 3310 | // or maybe part of a bit field. |
| 3311 | aPlayer->country = getCountryFromCode(p[3]); |
| 3312 | //fifth byte is their open status |
| 3313 | invitebyte = p[4]; |
| 3314 | aPlayer->nmatch_settings = QString::number(p[0]) + QString(" ") + QString::number((p[1])) + QString(" ") + QString::number(p[2]) + QString(" ") + QString::number(p[3]); |
| 3315 | p += 6; |
| 3316 | aPlayer->rank_score = p[0] + (p[1] << 8); |
| 3317 | if(aPlayer->pro) |
| 3318 | aPlayer->rank = QString::number(rankbyte & 0x1f) + QString("dp"); |
| 3319 | else |
| 3320 | aPlayer->rank = rating_pointsToRank(aPlayer->rank_score); |
| 3321 | aPlayer->info = getStatusFromCode(invitebyte, aPlayer->rank); |
| 3322 | aPlayer->wins = p[2] + (p[3] << 8); |
| 3323 | aPlayer->losses = p[4] + (p[5] << 8); |
| 3324 | p += 6; |
| 3325 | #ifdef RE_DEBUG |
| 3326 | printf(" RP: %d W/L: %d/%d ", aPlayer->rank_score, aPlayer->wins, aPlayer->losses); |
| 3327 | for(i = 0; i < 4; i++) |
| 3328 | printf("%02x", p[i]); |
| 3329 | printf("\n"); |
| 3330 | #endif //RE_DEBUG |
| 3331 | p += 3; |
| 3332 | p++; |
| 3333 | room->recvPlayerListing(aPlayer); |
| 3334 | |
| 3335 | playerlist_received++; |
| 3336 | if(playerlist_skipnumber != PLAYERLIST_SKIPNUMBER_UNSET |
| 3337 | && playerlist_skipnumber < playerlist_received) |
| 3338 | { |
| 3339 | #ifdef RE_DEBUG |
| 3340 | printf("Playerlist received %d skip number %d\n", playerlist_received, playerlist_skipnumber); |
| 3341 | #endif //RE_DEBUG |
| 3342 | /* get next room with observers */ |
| 3343 | GameListing * gamelisting = room->getGameListing(playerlist_roomnumber); |
| 3344 | if(!gamelisting) |
| 3345 | goto label_playerlist_nogame; |
| 3346 | if(gamelisting->observers > 0 && playerlist_observernumber == gamelisting->observers) |
| 3347 | { |
| 3348 | playerlist_observernumber = 0; |
| 3349 | gamelisting = room->getGameListing(++playerlist_roomnumber); |
| 3350 | if(!gamelisting) |
| 3351 | goto label_playerlist_nogame; |
| 3352 | } |
| 3353 | else if(gamelisting->observers > 0) |
| 3354 | { |
| 3355 | playerlist_observernumber++; |
| 3356 | } |
| 3357 | else |
| 3358 | { |
| 3359 | while(gamelisting->observers == 0) |
| 3360 | { |
| 3361 | playerlist_roomnumber++; |
| 3362 | gamelisting = room->getGameListing(playerlist_roomnumber); |
| 3363 | if(!gamelisting) |
| 3364 | goto label_playerlist_nogame; |
| 3365 | } |
| 3366 | } |
| 3367 | backPlayer = room->getPlayerListing(aPlayer->id); |
| 3368 | if(backPlayer->playing != playerlist_roomnumber) |
| 3369 | { |
| 3370 | /* add room to player, ORO is one room per player */ |
| 3371 | backPlayer->observing = playerlist_roomnumber; |
| 3372 | /* add player to room */ |
| 3373 | gamelisting->observer_list.push_back(backPlayer); |
| 3374 | #ifdef RE_DEBUG |
| 3375 | printf("Adding player %s %d to game %d\n", backPlayer->name.toLatin1().constData(), backPlayer->id, playerlist_roomnumber); |
| 3376 | #endif //RE_DEBUG |
| 3377 | } |
| 3378 | } |
| 3379 | label_playerlist_nogame: |
| 3380 | /* If the game can't be found it either means that the player is not in a room |
| 3381 | * or it means we don't have the room yet because that list hasn't come in.*/ |
| 3382 | |
| 3383 | backPlayer = room->getPlayerListing(aPlayer->id); |
| 3384 | playerlist_inorder.push_back(backPlayer); |
| 3385 | } |
| 3386 | delete newPlayer; |
| 3387 | #ifdef RE_DEBUG |
| 3388 | printf("*** Players %d\n", players); |
| 3389 | #endif //RE_DEBUG |
| 3390 | } |
| 3391 | #endif //NEWPROTOCOL |
| 3392 | |
| 3393 | #ifdef RE_DEBUG |
| 3394 | //#define PLAYERLIST_DEBUG |
| 3395 | #endif //RE_DEBUG |
| 3396 | /* I've finally realized how ORO does this safely. It waits until its received |
| 3397 | * everything, before it displays anything. Worries me a bit, the way we do it but... |
| 3398 | * we can make it safe... I just wonder if it could be better, especially if it would |
| 3399 | * be cleaner to have a "loading" dialog block user input until everything is up */ |
| 3400 | void CyberOroConnection::handlePlayerList(unsigned char * msg, unsigned int size) |
| 3401 | { |
| 3402 | unsigned char * p = msg; |
| 3403 | unsigned char name[11]; |
| 3404 | unsigned char rankbyte, invitebyte; |
| 3405 | unsigned short id; |
| 3406 | Room * room = getDefaultRoom(); |
| 3407 | PlayerListing * aPlayer; |
| 3408 | |
| 3409 | int players = p[2]; |
| 3410 | |
| 3411 | p += 2; |
| 3412 | //676c696c696e6e000000 770a 16a4 02c3 0000 9b72 e607 e407 0000 0056 |
| 3413 | while(p < (msg + size)) |
| 3414 | { |
| 3415 | strncpy((char *)name, (char *)p, 10); |
| 3416 | name[10] = 0x00; |
| 3417 | p += 10; |
| 3418 | id = p[0] + (p[1] << 8); |
| 3419 | aPlayer = room->getPlayerListing(id); |
| 3420 | if(strncmp((char *)name, "jguest", 6) == 0 || strncmp((char *)name, "jpguest", 7) == 0) |
| 3421 | aPlayer->hidden = true; |
| 3422 | else |
| 3423 | aPlayer->hidden = false; |
| 3424 | aPlayer->name = serverCodec->toUnicode((const char *)name, strlen((const char *)name)); |
| 3425 | |
| 3426 | p += 2; |
| 3427 | //a byte here seems to be a send msg byte, or something |
| 3428 | aPlayer->specialbyte = p[0]; |
| 3429 | // That's right, its the pro bit |
| 3430 | rankbyte = p[1]; |
| 3431 | aPlayer->pro = bool(rankbyte & 0x40); |
| 3432 | |
| 3433 | //lost interest, its not the game |
| 3434 | //aPlayer->observing = p[2]; //FIXME, what is this? |
| 3435 | //this fourth byte here is country I think. |
| 3436 | // but its really unreliable, almost like its something |
| 3437 | // that clients from these countries have as a setting |
| 3438 | // or maybe part of a bit field. |
| 3439 | aPlayer->country = getCountryFromCode(p[3]); |
| 3440 | //fifth byte is their open status |
| 3441 | invitebyte = p[4]; |
| 3442 | aPlayer->nmatch_settings = QString::number(p[0]) + QString(" ") + QString::number((p[1])) + QString(" ") + QString::number(p[2]) + QString(" ") + QString::number(p[3]); |
| 3443 | p += 6; |
| 3444 | aPlayer->rank_score = p[0] + (p[1] << 8); |
| 3445 | if(aPlayer->pro) |
| 3446 | aPlayer->rank = QString::number(rankbyte & 0x1f) + QString("dp"); |
| 3447 | else |
| 3448 | aPlayer->rank = rating_pointsToRank(aPlayer->rank_score); |
| 3449 | aPlayer->info = getStatusFromCode(invitebyte, aPlayer->rank); |
| 3450 | aPlayer->wins = p[2] + (p[3] << 8); |
| 3451 | aPlayer->losses = p[4] + (p[5] << 8); |
| 3452 | p += 6; |
| 3453 | p += 3; |
| 3454 | p++; |
| 3455 | emit playerListingReceived(aPlayer); |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | QString CyberOroConnection::rating_pointsToRank(unsigned int rp) |
| 3460 | { |
| 3461 | int rem = rp % 1000; |
| 3462 | rp -= rem; |
| 3463 | rp /= 1000; |
| 3464 | if(rp < 26) |
| 3465 | { |
| 3466 | rp = 26 - rp; |
| 3467 | return QString::number(rp) + QString("k"); |
| 3468 | } |
| 3469 | else |
| 3470 | { |
| 3471 | rp -= 25; |
| 3472 | return QString::number(rp) + QString("d"); |
| 3473 | } |
| 3474 | return QString("?"); |
| 3475 | } |
| 3476 | |
| 3477 | unsigned int CyberOroConnection::rankToScore(QString rank) |
| 3478 | { |
| 3479 | QString buffer = rank; |
| 3480 | //buffer.replace(QRegExp("[pdk+?\\*\\s]"), ""); |
| 3481 | buffer.replace(QRegExp("[pdk]"), ""); |
| 3482 | int ordinal = buffer.toInt(); |
| 3483 | unsigned int rp; |
| 3484 | |
| 3485 | if(rank.contains("k")) |
| 3486 | rp = (26 - ordinal) * 1000; |
| 3487 | else if(rank.contains("d")) |
| 3488 | rp = 25000 + (ordinal * 1000); |
| 3489 | else if(rank.contains("p")) |
| 3490 | rp = 36000 + (ordinal * 1000); |
| 3491 | else |
| 3492 | return 0; |
| 3493 | |
| 3494 | return rp; |
| 3495 | } |
| 3496 | |
| 3497 | /* FIXME What are the other bits for ?!?!?!*/ |
| 3498 | QString CyberOroConnection::getCountryFromCode(unsigned char code) |
| 3499 | { |
| 3500 | code &= 0x0f; |
| 3501 | switch(code) |
| 3502 | { |
| 3503 | case 1: |
| 3504 | return "KOREA"; |
| 3505 | break; |
| 3506 | case 2: |
| 3507 | return "CHINA"; |
| 3508 | break; |
| 3509 | case 3: |
| 3510 | return "JAPAN"; |
| 3511 | break; |
| 3512 | case 4: |
| 3513 | return "INTL"; |
| 3514 | break; |
| 3515 | case 5: |
| 3516 | return "THAILAND"; |
| 3517 | break; |
| 3518 | case 6: |
| 3519 | //that blue flag... |
| 3520 | return "UN?"; |
| 3521 | break; |
| 3522 | case 7: |
| 3523 | return "USA"; |
| 3524 | break; |
| 3525 | case 8: |
| 3526 | return "HONGKONG"; |
| 3527 | break; |
| 3528 | case 9: |
| 3529 | return "SINGAPORE"; |
| 3530 | break; |
| 3531 | case 0xa: |
| 3532 | return "CANADA"; |
| 3533 | break; |
| 3534 | case 0xb: |
| 3535 | return "GERMANY"; |
| 3536 | break; |
| 3537 | case 0xc: |
| 3538 | return "FRANCE"; |
| 3539 | break; |
| 3540 | case 0xd: |
| 3541 | return "AUSTRALIA"; |
| 3542 | break; |
| 3543 | case 0xe: |
| 3544 | return "RUSSIA"; |
| 3545 | break; |
| 3546 | case 0xf: |
| 3547 | return "UKRAINE"; |
| 3548 | break; |
| 3549 | } |
| 3550 | return QString("-"); |
| 3551 | } |
| 3552 | |
| 3553 | //c661 |
| 3554 | void CyberOroConnection::handleRoomList(unsigned char * msg, unsigned int size) |
| 3555 | { |
| 3556 | unsigned char * p = msg; |
| 3557 | unsigned int number_of_games; |
| 3558 | unsigned short number; |
| 3559 | unsigned int i; |
| 3560 | PlayerListing * player; |
| 3561 | GameListing * aGameListing; |
| 3562 | Room * room = getDefaultRoom(); |
| 3563 | bool be_adding_observers; |
| 3564 | |
| 3565 | if(playerlist_skipnumber != PLAYERLIST_SKIPNUMBER_UNSET && |
| 3566 | roomlist_observers < playerlist_received) |
| 3567 | be_adding_observers = true; |
| 3568 | else |
| 3569 | be_adding_observers = false; |
| 3570 | |
| 3571 | number_of_games = p[0] + (p[1] << 8); |
| 3572 | p += 4; |
| 3573 | #ifdef RE_DEBUG |
| 3574 | printf("c661 Number of games in this list: %d\n", number_of_games); |
| 3575 | printf("roomlist_observers %d versus %d\n", roomlist_observers, playerlist_received); |
| 3576 | #endif //RE_DEBUG |
| 3577 | // 4, 4 for one player, 4 for the second player, another 4 |
| 3578 | while(number_of_games--) |
| 3579 | { |
| 3580 | number = p[0] + (p[1] << 8); |
| 3581 | if(number == 0) |
| 3582 | { |
| 3583 | /* There's no 0th record except maybe total number of |
| 3584 | * games and those 01 tagged records are weird, like |
| 3585 | * their either empty or they're for particular |
| 3586 | * players... they might be player stats but they |
| 3587 | * don't show up in official ORO app so who knows.*/ |
| 3588 | /* FIXME, these are probably important and I just |
| 3589 | * have no idea. */ |
| 3590 | unsigned char * q = p; |
| 3591 | #ifdef RE_DEBUG |
| 3592 | printf("0record:\n"); //unnecessary even for debug |
| 3593 | #endif //RE_DEBUG |
| 3594 | /* I think the third and fourth bytes here are |
| 3595 | * the number of players not in rooms, or to |
| 3596 | * skip from player lists before adding players |
| 3597 | * to games */ |
| 3598 | playerlist_skipnumber = p[2] + (p[3] << 8); |
| 3599 | if(playerlist_received >= playerlist_skipnumber) |
| 3600 | be_adding_observers = true; |
| 3601 | for(i = 0; i < 4; i++) |
| 3602 | { |
| 3603 | #ifdef RE_DEBUG |
| 3604 | printf("%02x%02x%02x%02x ", q[0], q[1], q[2], q[3]); |
| 3605 | #endif //RE_DEBUG |
| 3606 | q += 4; |
| 3607 | } |
| 3608 | #ifdef RE_DEBUG |
| 3609 | printf("\n"); |
| 3610 | #endif //RE_DEBUG |
| 3611 | p += 16; |
| 3612 | continue; |
| 3613 | } |
| 3614 | aGameListing = room->getGameListing(number); |
| 3615 | aGameListing->running = true; |
| 3616 | unsigned char * q = p; |
| 3617 | for(i = 0; i < 4; i++) |
| 3618 | { |
| 3619 | #ifdef RE_DEBUG |
| 3620 | printf("%02x%02x%02x%02x ", q[0], q[1], q[2], q[3]); |
| 3621 | #endif //RE_DEBUG |
| 3622 | q += 4; |
| 3623 | } |
| 3624 | #ifdef RE_DEBUG |
| 3625 | printf("\n"); |
| 3626 | #endif //RE_DEBUG |
| 3627 | if(p[4] & 0x70) |
| 3628 | aGameListing->isLocked = true; //I don't think this is always the case |
| 3629 | //p[4] & 0x70 = locked game password |
| 3630 | /* |
| 3631 | 3c review game records 7d replay |
| 3632 | 16 waiting for pair match team even + stronger |
| 3633 | 2a even pair game ongoing with p[5] == c0 |
| 3634 | 02 bit could be pair game, but which, even or stronger? |
| 3635 | */ |
| 3636 | /* I think phase is or can be unreliable for broadcast |
| 3637 | * games, maybe others */ |
| 3638 | /*FIXME, setting observers here skews setAttached*/ |
| 3639 | aGameListing->observers = p[2]; |
| 3640 | int phase = getPhase(p[6]); |
| 3641 | if(phase != -1) |
| 3642 | aGameListing->moves = phase; |
| 3643 | else |
| 3644 | aGameListing->moves = 0; |
| 3645 | aGameListing->owner_id = p[8] + (p[9] << 8); |
| 3646 | if(!aGameListing->white) |
| 3647 | { |
| 3648 | player = room->getPlayerListing(aGameListing->owner_id); |
| 3649 | aGameListing->white = player; |
| 3650 | } |
| 3651 | else |
| 3652 | player = 0; |
| 3653 | /* These are really like room owners */ |
| 3654 | if(!aGameListing->black) |
| 3655 | { |
| 3656 | //new sets this to 0 |
| 3657 | //FIXME so why even have a conditional here? |
| 3658 | //also does this get unset if its found to |
| 3659 | //be a game later? |
| 3660 | aGameListing->_black_name = getRoomTag(p[4]); |
| 3661 | aGameListing->isRoomOnly = true; |
| 3662 | } |
| 3663 | else |
| 3664 | aGameListing->FR = getRoomTag(p[4]); |
| 3665 | |
| 3666 | room->recvGameListing(aGameListing); |
| 3667 | aGameListing = room->getGameListing(aGameListing->number); |
| 3668 | aGameListing->observer_list.clear(); |
| 3669 | |
| 3670 | if(player) |
| 3671 | { |
| 3672 | //after recv |
| 3673 | //FIXME |
| 3674 | setAttachedGame(player, aGameListing->number); |
| 3675 | } |
| 3676 | p += 16; |
| 3677 | #ifdef RE_DEBUG |
| 3678 | printf("Observers: %d\n", aGameListing->observers); |
| 3679 | #endif //RE_DEBUG |
| 3680 | /* Because player and room listing messages apparently |
| 3681 | * come in any order, probably because there's some |
| 3682 | * underlying MS database that spits all this stuff out |
| 3683 | * from separate places, even separate servers... : */ |
| 3684 | if(be_adding_observers) |
| 3685 | { |
| 3686 | for(i = 0; i < aGameListing->observers; i++) |
| 3687 | { |
| 3688 | if(roomlist_observers + playerlist_skipnumber < playerlist_inorder.size()) |
| 3689 | { |
| 3690 | player = playerlist_inorder[roomlist_observers + playerlist_skipnumber]; |
| 3691 | if(player->playing != number) |
| 3692 | { |
| 3693 | /* add room to player, ORO is one room per player */ |
| 3694 | player->observing = number; |
| 3695 | /* add player to room */ |
| 3696 | aGameListing->observer_list.push_back(player); |
| 3697 | #ifdef RE_DEBUG |
| 3698 | printf("Adding player %s %d to game %d\n", player->name.toLatin1().constData(), player->id, number); |
| 3699 | #endif //RE_DEBUG |
| 3700 | } |
| 3701 | playerlist_observernumber++; |
| 3702 | if(playerlist_observernumber == aGameListing->observers) |
| 3703 | { |
| 3704 | playerlist_observernumber = 0; |
| 3705 | playerlist_roomnumber = number + 1; //at least |
| 3706 | } |
| 3707 | } |
| 3708 | roomlist_observers++; |
| 3709 | } |
| 3710 | } |
| 3711 | else |
| 3712 | roomlist_observers += aGameListing->observers; |
| 3713 | } |
| 3714 | if(p != msg + size) |
| 3715 | qDebug("handleRoomList: doesn't match size %d", size); |
| 3716 | //FIXME try without |
| 3717 | } |
| 3718 | |
| 3719 | /* We might FIXME replace the return on this with a QString |
| 3720 | * when we alter the list view to handle different columns. |
| 3721 | * But for now, moves is pretty accurate for the field */ |
| 3722 | int CyberOroConnection::getPhase(unsigned char byte) |
| 3723 | { |
| 3724 | switch(byte) |
| 3725 | { |
| 3726 | case 0: |
| 3727 | return 0; |
| 3728 | //open |
| 3729 | break; |
| 3730 | case 1: |
| 3731 | return 30; |
| 3732 | //early |
| 3733 | break; |
| 3734 | case 2: |
| 3735 | return 50; |
| 3736 | //middle |
| 3737 | break; |
| 3738 | case 3: |
| 3739 | return 130; |
| 3740 | //end |
| 3741 | break; |
| 3742 | case 11: |
| 3743 | //looks like wished opponent |
| 3744 | default: |
| 3745 | return -1; |
| 3746 | break; |
| 3747 | } |
| 3748 | } |
| 3749 | |
| 3750 | QString CyberOroConnection::getRoomTag(unsigned char byte) |
| 3751 | { |
| 3752 | switch(byte) |
| 3753 | { |
| 3754 | case 0x1f: |
| 3755 | case 0x3d: |
| 3756 | //normal and broadcast in progress |
| 3757 | return QString(); |
| 3758 | break; |
| 3759 | case 0x04: |
| 3760 | return QString("** chat 04"); |
| 3761 | break; |
| 3762 | case 0x1a: |
| 3763 | return QString("** chat 1a"); |
| 3764 | break; |
| 3765 | case 0x70: |
| 3766 | //likely chat 0 locked? |
| 3767 | return QString("** chat 70"); |
| 3768 | break; |
| 3769 | case 0x3c: |
| 3770 | return QString("** review 3c"); |
| 3771 | break; |
| 3772 | case 0x19: |
| 3773 | return QString("** chat 19"); |
| 3774 | break; |
| 3775 | case 0x1c: |
| 3776 | return QString("** quit? 19"); |
| 3777 | break; |
| 3778 | case 0x0b: |
| 3779 | return QString("** wished 0b"); |
| 3780 | break; |
| 3781 | case 0x0f: |
| 3782 | return QString("** one color 0f"); |
| 3783 | break; |
| 3784 | default: |
| 3785 | return (QString("** ") + QString::number(byte, 16)); |
| 3786 | break; |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | //f861 These are broadcasted games I think. They're not players on the service |
| 3791 | void CyberOroConnection::handleBroadcastGamesList(unsigned char * msg, unsigned int size) |
| 3792 | { |
| 3793 | unsigned char * p = msg; |
| 3794 | unsigned char * game_record; |
| 3795 | unsigned int number_of_games; |
| 3796 | int number; |
| 3797 | unsigned char name[11]; |
| 3798 | name[10] = 0x00; |
| 3799 | #ifdef RE_DEBUG |
| 3800 | unsigned int i; |
| 3801 | #endif //RE_DEBUG |
| 3802 | |
| 3803 | Room * room = getDefaultRoom(); |
| 3804 | GameListing * aGameListing; |
| 3805 | |
| 3806 | number_of_games = p[0] + (p[1] << 8); |
| 3807 | p += 2; |
| 3808 | #ifdef RE_DEBUG |
| 3809 | printf("Number of games: %d\n", number_of_games); |
| 3810 | #endif //RE_DEBUG |
| 3811 | while(number_of_games--) |
| 3812 | { |
| 3813 | game_record = p; |
| 3814 | number = p[0] + (p[1] << 8); |
| 3815 | aGameListing = room->getGameListing(number); |
| 3816 | aGameListing->running = true; |
| 3817 | p += 2; |
| 3818 | aGameListing->game_code = game_record[2] + (game_record[3] << 8); |
| 3819 | p += 2; |
| 3820 | strncpy((char *)name, (char *)&(game_record[4]), 10); |
| 3821 | aGameListing->black = 0; |
| 3822 | //aGameListing->_black_name = QString((char *)name); |
| 3823 | aGameListing->_black_name = serverCodec->toUnicode((const char *)name, strlen((const char *)name)); |
| 3824 | p += 10; |
| 3825 | strncpy((char *)name, (char *)&(game_record[14]), 10); |
| 3826 | aGameListing->white = 0; |
| 3827 | //aGameListing->_white_name = QString((char *)name); |
| 3828 | aGameListing->_white_name = serverCodec->toUnicode((const char *)name, strlen((const char *)name)); |
| 3829 | |
| 3830 | p += 10; |
| 3831 | #ifdef RE_DEBUG |
| 3832 | printf("br %02x wr %02x\n", p[0], p[1]); |
| 3833 | #endif //RE_DEBUG |
| 3834 | if((game_record[24] & 0xC0) == 0xC0) |
| 3835 | { |
| 3836 | aGameListing->_black_rank = QString::number(game_record[24] & 0x0f) + "p"; |
| 3837 | aGameListing->_black_rank_score = 34000 + ((game_record[24] & 0x0f) * 1000); |
| 3838 | } |
| 3839 | else if((game_record[24] & 0xA0) == 0xA0) |
| 3840 | { |
| 3841 | aGameListing->_black_rank = QString::number(game_record[24] & 0x0f) + "d"; |
| 3842 | aGameListing->_black_rank_score = 25000 + ((game_record[24] & 0x0f) * 1000); |
| 3843 | } |
| 3844 | if((game_record[25] & 0xC0) == 0xC0) |
| 3845 | { |
| 3846 | aGameListing->_white_rank = QString::number(game_record[25] & 0x0f) + "p"; |
| 3847 | aGameListing->_white_rank_score = 34000 + ((game_record[25] & 0x0f) * 1000); |
| 3848 | } |
| 3849 | else if((game_record[25] & 0xA0) == 0xA0) |
| 3850 | { |
| 3851 | aGameListing->_white_rank = QString::number(game_record[25] & 0x0f) + "d"; |
| 3852 | aGameListing->_white_rank_score = 25000 + ((game_record[25] & 0x0f) * 1000); |
| 3853 | } |
| 3854 | p += 2; |
| 3855 | /* The next two bytes are the country codes for each player, |
| 3856 | * but I'm not sure where to display them. FIXME */ |
| 3857 | /* [K] [C] [J], let's not kid ourself about the pro game countries */ |
| 3858 | QString country = getCountryFromCode(game_record[27]); |
| 3859 | aGameListing->_black_name += ("[" + country[0] + "]"); |
| 3860 | country = getCountryFromCode(p[1]); |
| 3861 | aGameListing->_white_name += ("[" + country[0] + "]"); |
| 3862 | p += 2; |
| 3863 | |
| 3864 | #ifdef RE_DEBUG |
| 3865 | printf("broadcast %d: ", aGameListing->number); |
| 3866 | for(i = 0; i < 48; i++) |
| 3867 | printf("%02x", (p - 28)[i]); |
| 3868 | printf("\n"); |
| 3869 | #endif //RE_DEBUG |
| 3870 | aGameListing->game_code = aGameListing->number; //just for these broadcasts |
| 3871 | |
| 3872 | /* Looks like if the last two 4 bytes are 0xf190 ed00, then |
| 3873 | * its game-over */ |
| 3874 | p += 28; |
| 3875 | /* This seems to be wrong */ |
| 3876 | if(p[0] == 0xf1 && p[1] == 0x90 && p[2] == 0xed && p[3] == 0x00) |
| 3877 | { |
| 3878 | aGameListing->FR = "Ended"; |
| 3879 | //also, use moves = -1 I think FIXME |
| 3880 | } |
| 3881 | //aGameListing->FR = QString::number(p[0], 16) + QString::number(p[1], 16) + QString::number(p[2], 16) + QString::number(p[3], 16); |
| 3882 | p += 4; |
| 3883 | aGameListing->isRoomOnly = false; |
| 3884 | aGameListing->isBroadcast = true; |
| 3885 | //to prevent broadcast games from closing FIXME |
| 3886 | emit gameListingReceived(aGameListing); |
| 3887 | } |
| 3888 | if(p != (msg + size)) |
| 3889 | qDebug("bad p: line: %d", __LINE__); |
| 3890 | } |
| 3891 | |
| 3892 | /* Turns out, in this initial, game joining list, its possible to get ids |
| 3893 | * from players we haven't received yet. So we need to, either postpone |
| 3894 | * posting the list or... something... until we get the full |
| 3895 | * player list. If this is only a problem initially... and I think |
| 3896 | * that is generally the case... but... I have to think about how |
| 3897 | * to handle this. (maybe if we knew total number of players?) FIXME FIXME*/ |
| 3898 | //da61 |
| 3899 | void CyberOroConnection::handleGamesList(unsigned char * msg, unsigned int size) |
| 3900 | { |
| 3901 | unsigned char * p = msg; |
| 3902 | unsigned int number_of_games; |
| 3903 | unsigned int id; |
| 3904 | #ifdef RE_DEBUG |
| 3905 | unsigned int i; |
| 3906 | #endif //RE_DEBUG |
| 3907 | |
| 3908 | Room * room = getDefaultRoom(); |
| 3909 | PlayerListing * white, * black; |
| 3910 | GameListing * aGameListing; |
| 3911 | int number; |
| 3912 | |
| 3913 | /* Looks like the [] QList index error might be coming from this |
| 3914 | * and its fatal!!! so watch out... probably number of games is |
| 3915 | * wrong. We need to differentiate the different game list msg |
| 3916 | * types |
| 3917 | * Its like the second time we have to use the temp trick, it |
| 3918 | * bugs out... maybe the reference doesn't actually change...*/ |
| 3919 | number_of_games = p[0] + (p[1] << 8); |
| 3920 | p += 2; |
| 3921 | /*printf("Number of games: %d\n", number_of_games); |
| 3922 | for(i = 0; i < size; i++) |
| 3923 | printf("%02x", msg[i]); |
| 3924 | printf("\n"); |
| 3925 | return;*/ |
| 3926 | |
| 3927 | while(number_of_games-- && p < (msg + size - 9)) //check probably unnecessary FIXME |
| 3928 | { |
| 3929 | number = p[0] + (p[1] << 8); |
| 3930 | aGameListing = room->getGameListing(number); |
| 3931 | aGameListing->running = true; |
| 3932 | p += 2; |
| 3933 | #ifdef RE_DEBUG |
| 3934 | printf("da61: %d %02x%02x\n", aGameListing->number, p[0], p[1]); |
| 3935 | for(i = 0; i < 8; i++) |
| 3936 | printf(" %02x", p[i]); |
| 3937 | printf("\n"); |
| 3938 | #endif //RE_DEBUG |
| 3939 | p += 2; |
| 3940 | aGameListing->game_code = p[0] + (p[1] << 8); |
| 3941 | game_code_to_number[aGameListing->game_code] = aGameListing->number; //weird? |
| 3942 | p += 2; |
| 3943 | |
| 3944 | id = p[0] + (p[1] << 8); |
| 3945 | black = room->getPlayerListing(id); |
| 3946 | aGameListing->black = black; |
| 3947 | |
| 3948 | p += 2; |
| 3949 | id = p[0] + (p[1] << 8); |
| 3950 | white = room->getPlayerListing(id); |
| 3951 | aGameListing->white = white; |
| 3952 | |
| 3953 | p += 2; |
| 3954 | #ifdef RE_DEBUG |
| 3955 | if(white && black) |
| 3956 | printf("Adding listing for %s vs %s\n", |
| 3957 | white->name.toLatin1().constData(), |
| 3958 | black->name.toLatin1().constData()); |
| 3959 | #endif //RE_DEBUG |
| 3960 | aGameListing->isRoomOnly = false; |
| 3961 | //aGameListing->observers = 2; //the players |
| 3962 | room->recvGameListing(aGameListing); |
| 3963 | //after recv |
| 3964 | #ifdef FIXME //maybe we need this here?!? |
| 3965 | owner = room->getPlayerListing(aGameListing->owner_id); |
| 3966 | if(owner != black) |
| 3967 | setAttachedGame(black, aGameListing->number); |
| 3968 | if(owner != white) |
| 3969 | setAttachedGame(white, aGameListing->number); |
| 3970 | //detach owner if any, players are attached alread |
| 3971 | if(owner && owner != black && owner != white) |
| 3972 | setAttachedGame(owner, 0); |
| 3973 | #endif //FIXME |
| 3974 | setAttachedGame(black, aGameListing->number); |
| 3975 | setAttachedGame(white, aGameListing->number); |
| 3976 | } |
| 3977 | if(p != (msg + size)) |
| 3978 | printf("gameslist3 error: %d %ld\n", size, p - msg); |
| 3979 | } |
| 3980 | |
| 3981 | //0456 |
| 3982 | void CyberOroConnection::handlePlayerConnect(unsigned char * msg, unsigned int size) |
| 3983 | { |
| 3984 | unsigned char * p = msg; |
| 3985 | unsigned char name[11]; |
| 3986 | name[10] = 0x00; |
| 3987 | unsigned char name2[11]; |
| 3988 | name2[10] = 0x00; |
| 3989 | unsigned char rankbyte; |
| 3990 | unsigned short id; |
| 3991 | Room * room = getDefaultRoom(); |
| 3992 | PlayerListing * aPlayer; |
| 3993 | |
| 3994 | if(size != 42) |
| 3995 | qDebug("handlePlayerConnect of size: %d\n", size); |
| 3996 | strncpy((char *)name, (char *)p, 10); |
| 3997 | #ifdef RE_DEBUG |
| 3998 | printf("0456 %s connected, ", name); |
| 3999 | #endif //RE_DEBUG |
| 4000 | |
| 4001 | p += 10; |
| 4002 | strncpy((char *)name2, (char *)p, 10); |
| 4003 | #ifdef RE_DEBUG |
| 4004 | printf("or player %s, ", name2); |
| 4005 | #endif //RE_DEBUG |
| 4006 | |
| 4007 | |
| 4008 | p += 10; //name again; |
| 4009 | #ifdef RE_DEBUG |
| 4010 | printf("id: %02x%02x\n", p[0], p[1]); |
| 4011 | #endif //RE_DEBUG |
| 4012 | id = p[0] + (p[1] << 8); |
| 4013 | aPlayer = room->getPlayerListing(id); |
| 4014 | aPlayer->id = id; |
| 4015 | //aPlayer->name = (char *)name; |
| 4016 | if(strncmp((char *)name, "jguest", 6) == 0 || strncmp((char *)name, "jpguest", 7) == 0) |
| 4017 | aPlayer->hidden = true; |
| 4018 | else |
| 4019 | aPlayer->hidden = false; |
| 4020 | aPlayer->name = serverCodec->toUnicode((const char *)name2, strlen((const char *)name2)); |
| 4021 | aPlayer->notnickname = serverCodec->toUnicode((const char *)name, strlen((const char *)name)); |
| 4022 | /* It actually looks like this catches more unicode foreign names, then the |
| 4023 | * second name. But I get the feeling that one is the text username or |
| 4024 | * something... not sure */ |
| 4025 | /* Yeah, FIXME, the first name appears to allow asian characters, the second is just |
| 4026 | * username. We might want an option to turn them on and off */ |
| 4027 | //aPlayer->name = (char *)name2; |
| 4028 | //aPlayer->name = serverCodec->toUnicode((const char *)name2, strlen((const char *)name2)); |
| 4029 | |
| 4030 | /* I think we want to take the first name if we take the second |
| 4031 | * here, I think the second is allowed to be unicode or something... |
| 4032 | * done FIXME, still not sure of this, we should |
| 4033 | * really just add unicode support !!!*/ |
| 4034 | |
| 4035 | |
| 4036 | // are you my special msg byte??? FIXME |
| 4037 | p += 2; |
| 4038 | aPlayer->specialbyte = p[0]; |
| 4039 | p++; |
| 4040 | rankbyte = p[0]; |
| 4041 | if(rankbyte & 0x40) |
| 4042 | aPlayer->pro = true; |
| 4043 | p++; |
| 4044 | aPlayer->wins = p[0] + (p[1] << 8); |
| 4045 | aPlayer->losses = p[2] + (p[3] << 8); |
| 4046 | p += 4; |
| 4047 | p += 4; |
| 4048 | aPlayer->rank_score = p[0] + (p[1] << 8); |
| 4049 | if(aPlayer->pro) |
| 4050 | aPlayer->rank = QString::number(rankbyte & 0x1f) + QString("dp"); |
| 4051 | else |
| 4052 | aPlayer->rank = rating_pointsToRank(aPlayer->rank_score); |
| 4053 | #ifdef RE_DEBUG |
| 4054 | printf(" RP: %d W/L: %d/%d ", aPlayer->rank_score, aPlayer->wins, aPlayer->losses); |
| 4055 | #endif //RE_DEBUG |
| 4056 | p += 2; |
| 4057 | #ifdef RE_DEBUG |
| 4058 | for(int i = 0; i < 8; i++) |
| 4059 | printf("%02x", p[i]); |
| 4060 | printf("\n"); |
| 4061 | #endif //RE_DEBUG |
| 4062 | aPlayer->country = getCountryFromCode(p[2]); |
| 4063 | aPlayer->info = getStatusFromCode(p[3], aPlayer->rank); |
| 4064 | aPlayer->nmatch_settings = QString("-") + QString::number(msg[23]) + " " + QString::number(p[0]) + QString(" ") + QString::number((p[1])) + QString(" ") + QString::number(p[2]) + QString(" ") + QString::number(p[3]) + QString::number(p[4]) + QString(" ") + QString::number((p[5])) + QString(" ") + QString::number(p[6]) + QString(" ") + QString::number(p[7]); |
| 4065 | p += 8; //other data; |
| 4066 | aPlayer->observing = 0; //necessary? |
| 4067 | //aPlayer->playing = 0; //necessary? |
| 4068 | emit playerListingReceived(aPlayer); |
| 4069 | } |
| 4070 | |
| 4071 | /* This is necessary as a safety precaution. Maybe if we were sure |
| 4072 | * about all aspects of protocol, but for now, let's prevent the |
| 4073 | * crashes. */ |
| 4074 | /* Starting to think that we shouldn't modify observers here. |
| 4075 | * entering should be enough. That and the listing on connect */ |
| 4076 | /* CyberORO does have multi 1:N games which means that there's possibly |
| 4077 | * some issues where there might be a player attached to multiple games */ |
| 4078 | /* Also, FIXME, there's no real need for an observing and a playing with ORO, |
| 4079 | * we should just use observing to determine what room they're in. Its confusing |
| 4080 | * otherwise. Although I guess "playing" can be used to mean their name is in the |
| 4081 | * listing. All of these places where we close empty rooms need to be brought |
| 4082 | * together FIXME*/ |
| 4083 | void CyberOroConnection::setAttachedGame(PlayerListing * const player, unsigned short game_id) |
| 4084 | { |
| 4085 | GameListing * game; |
| 4086 | if(player->playing && player->playing != game_id) |
| 4087 | { |
| 4088 | game = getDefaultRoom()->getGameListing(player->playing); |
| 4089 | /* This is silly, unless its a chat room, its still the same game, |
| 4090 | * we shouldn't remove the players */ |
| 4091 | if(game->white == player) |
| 4092 | { |
| 4093 | game->_white_name = game->white->name; |
| 4094 | game->_white_rank = game->white->rank; |
| 4095 | game->white = 0; |
| 4096 | #ifdef FIXME //chat only |
| 4097 | if(game->black) |
| 4098 | { |
| 4099 | /* This is so the name is always |
| 4100 | * in the same column */ |
| 4101 | game->white = game->black; |
| 4102 | game->black = 0; |
| 4103 | } |
| 4104 | else |
| 4105 | { |
| 4106 | if(game->observer_list.size()) |
| 4107 | { |
| 4108 | game->white = game->observer_list[0]; |
| 4109 | /* FIXME actually a game should never have no name, so I think when black leaves, black's name |
| 4110 | * is replaced by white, but in our case, since we have white than black, we'd the opposite |
| 4111 | * and then we have to pull up observernames, either alphabetical or in the order they joined |
| 4112 | * or something. Should also probably change flags to chat or something */ |
| 4113 | } |
| 4114 | } |
| 4115 | #endif //FIXME |
| 4116 | } |
| 4117 | else if(game->black == player) |
| 4118 | { |
| 4119 | if(game->black->name == "0") |
| 4120 | qDebug("black name equals 0!!!!"); |
| 4121 | game->_black_name = game->black->name; |
| 4122 | game->_black_rank = game->black->rank; |
| 4123 | game->black = 0; |
| 4124 | } |
| 4125 | /*if(!g->observers) |
| 4126 | { |
| 4127 | //broadcast games never go down, so there's FIXME |
| 4128 | //issues here |
| 4129 | qDebug("Closing game %d, no observers", g->number); |
| 4130 | g->running = false; |
| 4131 | getDefaultRoom()->recvGameListing(g); |
| 4132 | }*/ |
| 4133 | } |
| 4134 | else if(player->playing == game_id) |
| 4135 | return; //nothing to do |
| 4136 | #ifdef RE_DEBUG |
| 4137 | printf("Moving %s %p from %d to %d\n", player->name.toLatin1().constData(), player, player->playing, game_id); |
| 4138 | #endif //RE_DEBUG |
| 4139 | player->playing = game_id; |
| 4140 | |
| 4141 | /* Doesn't help. Looks like observer counts do not include the players playing themselves which makes some sense |
| 4142 | * but we need them in our little list and, well the whole thing is iffy FIXME */ |
| 4143 | /* Okay, we're adding observer counts here, we can check it later. They're not in the data we get, so that's an issue */ |
| 4144 | |
| 4145 | if(game_id && player->observing != game_id) |
| 4146 | { |
| 4147 | game = getDefaultRoom()->getGameListing(game_id); |
| 4148 | //game->observers++; |
| 4149 | game->observer_list.push_back(player); |
| 4150 | } |
| 4151 | |
| 4152 | if(player->observing && player->observing != game_id) |
| 4153 | removeObserverFromGameListing(player); |
| 4154 | else |
| 4155 | player->observing = game_id; |
| 4156 | } |
| 4157 | |
| 4158 | //0x55c3 |
| 4159 | void CyberOroConnection::handleSetPhraseChatMsg(unsigned char * msg, unsigned int size) |
| 4160 | { |
| 4161 | if(size != 16) |
| 4162 | { |
| 4163 | qDebug("set phrase chat msg of strange size: %d", size); |
| 4164 | } |
| 4165 | unsigned char * p = msg; |
| 4166 | //2a02ffff 0000 0000 63ea000083cedc9 |
| 4167 | unsigned short id = p[0] + (p[1] << 8); |
| 4168 | unsigned short setphrase_code; |
| 4169 | PlayerListing * player = getDefaultRoom()->getPlayerListing(id); |
| 4170 | /* Our chat appears back in all the rooms were in??? |
| 4171 | * why?? |
| 4172 | * FIXME room_were_in must not be the whole picture */ |
| 4173 | //if(player->name == getUsername()) |
| 4174 | // return; //to prevent duplicate chats from us |
| 4175 | p += 4; |
| 4176 | bool in_room = p[0]; //doublecheck, could potentially mean its from us |
| 4177 | p += 4; |
| 4178 | |
| 4179 | #ifdef RE_DEBUG |
| 4180 | printf("Directed id %d, room_were_in %d\n", directed_id, room_were_in); |
| 4181 | #endif //RE_DEBUG |
| 4182 | /* They translated a lot more phrases, but these are the major ones |
| 4183 | * it looks like */ |
| 4184 | //p[1] byte is category? and then p[0] is specific msg |
| 4185 | setphrase_code = p[0] + (p[1] << 8); |
| 4186 | std::map<unsigned short, QString>::iterator it = ORO_setphrase.find(setphrase_code); |
| 4187 | if(it != ORO_setphrase.end()) |
| 4188 | { |
| 4189 | if(room_were_in && in_room) |
| 4190 | { |
| 4191 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_were_in); |
| 4192 | if(!boarddispatch) |
| 4193 | { |
| 4194 | // might just be a room |
| 4195 | if(console_dispatch) |
| 4196 | console_dispatch->recvText(player->name + ": " + it->second); |
| 4197 | } |
| 4198 | else |
| 4199 | boarddispatch->recvKibitz(player->name + "[" + player->rank + "]", it->second); |
| 4200 | } |
| 4201 | else |
| 4202 | { |
| 4203 | if(console_dispatch) |
| 4204 | console_dispatch->recvText(player->name + "[" + player->rank + "]: " + it->second); |
| 4205 | } |
| 4206 | } |
| 4207 | else |
| 4208 | { |
| 4209 | if(room_were_in && in_room) |
| 4210 | { |
| 4211 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_were_in); |
| 4212 | if(!boarddispatch) |
| 4213 | { |
| 4214 | if(console_dispatch) |
| 4215 | console_dispatch->recvText(player->name + ": " + QString::number(setphrase_code, 16)); |
| 4216 | } |
| 4217 | else |
| 4218 | boarddispatch->recvKibitz(player->name + "[" + player->rank + "]", QString::number(setphrase_code, 16)); |
| 4219 | } |
| 4220 | else |
| 4221 | { |
| 4222 | if(console_dispatch) |
| 4223 | console_dispatch->recvText(player->name + "[" + player->rank + "]: " + QString::number(setphrase_code, 16)); |
| 4224 | } |
| 4225 | } |
| 4226 | #ifdef RE_DEBUG |
| 4227 | printf("0x55c3: "); |
| 4228 | for(int i = 0; i < (int)size; i++) |
| 4229 | printf("%02x", msg[i]); |
| 4230 | printf("\n"); |
| 4231 | #endif //RE_DEBUG |
| 4232 | } |
| 4233 | |
| 4234 | //0xf659 |
| 4235 | void CyberOroConnection::handleServerAnnouncement(unsigned char * msg, unsigned int size) |
| 4236 | { |
| 4237 | unsigned char * p = msg; |
| 4238 | |
| 4239 | #ifdef RE_DEBUG |
| 4240 | printf("0xf659: "); |
| 4241 | for(unsigned int i = 0; i < size; i++) |
| 4242 | printf("%02x", msg[i]); |
| 4243 | printf("\n"); |
| 4244 | #endif //RE_DEBUG |
| 4245 | p += 2; |
| 4246 | |
| 4247 | /* FIXME, likely first two bytes are something else */ |
| 4248 | QString u; |
| 4249 | |
| 4250 | u = serverCodec->toUnicode((const char *)p, size - 2); |
| 4251 | //u = codec->toUnicode(b, size - 4); |
| 4252 | if(console_dispatch) |
| 4253 | console_dispatch->recvText("*** " + u); |
| 4254 | } |
| 4255 | |
| 4256 | //645a |
| 4257 | void CyberOroConnection::handleServerAnnouncementwithLink(unsigned char * msg, unsigned int size) |
| 4258 | { |
| 4259 | unsigned char * p = msg; |
| 4260 | |
| 4261 | #ifdef RE_DEBUG |
| 4262 | printf("645a: "); |
| 4263 | for(unsigned int i = 0; i < size; i++) |
| 4264 | printf("%02x", msg[i]); |
| 4265 | printf("\n"); |
| 4266 | #endif //RE_DEBUG |
| 4267 | p += 2; |
| 4268 | |
| 4269 | /* FIXME, likely first two bytes are something else */ |
| 4270 | QString u; |
| 4271 | QString link; |
| 4272 | unsigned int len = 0; |
| 4273 | while((msg[8 + len] || msg[9 + len])&& len + 8 < 260) |
| 4274 | len += 2; |
| 4275 | printf("Server anon len %d\n", len); |
| 4276 | u = serverCodec->toUnicode((const char *)&(msg[8]), len); |
| 4277 | //u = codec->toUnicode(b, size - 4); |
| 4278 | len = 0; |
| 4279 | while(msg[264 + len] && len + 264 < size) |
| 4280 | len++; |
| 4281 | printf("Server anon len2 %d\n", len); |
| 4282 | link = QString((const char *)&(msg[264])); //not unicode |
| 4283 | if(console_dispatch) |
| 4284 | console_dispatch->recvText("*** " + u + ": " + link); |
| 4285 | } |
| 4286 | |
| 4287 | void CyberOroConnection::handleServerRoomChat(unsigned char * msg, unsigned int size) |
| 4288 | { |
| 4289 | unsigned char * p = msg; |
| 4290 | unsigned char * text = new unsigned char[size - 3]; |
| 4291 | //unsigned int text_size = (size - 2) / 2; |
| 4292 | //unsigned short * text = new unsigned short[text_size]; |
| 4293 | unsigned short player_id = p[0] + (p[1] << 8); |
| 4294 | #ifdef RE_DEBUG |
| 4295 | int i; |
| 4296 | #endif //RE_DEBUG |
| 4297 | /*printf("** msg size: %d: ", size); |
| 4298 | for(i = 0; i < (int)size; i++) |
| 4299 | printf("%02x", p[i]); |
| 4300 | printf("\n");*/ |
| 4301 | |
| 4302 | p += 2; |
| 4303 | //there's two encoding bytes here... 00 86 looks like ascii |
| 4304 | |
| 4305 | p += 2; |
| 4306 | Room * room = getDefaultRoom(); //3 |
| 4307 | strncpy((char *)text, (char *)p, size - 4); text[size - 4] = 0x00; |
| 4308 | /*for(i = 0; i < text_size; i++) |
| 4309 | { |
| 4310 | text[i] = p[0] + (p[1] << 8); |
| 4311 | p += 2; |
| 4312 | }*/ |
| 4313 | PlayerListing * player = room->getPlayerListing(player_id); |
| 4314 | QString u = serverCodec->toUnicode((const char *)text, size - 4); |
| 4315 | //u = codec->toUnicode(b, size - 4); |
| 4316 | if(console_dispatch) |
| 4317 | console_dispatch->recvText(player->name + "[" + player->rank + "]: " + u); |
| 4318 | |
| 4319 | delete[] text; |
| 4320 | } |
| 4321 | |
| 4322 | //EC 59 1B 00 D3 04 00 7E 68 65 6C 6C 6F 20 63 68 .Y.....~hello ch |
| 4323 | //61 74 20 72 6F 6F 6D 20 31 35 30 at room 150 |
| 4324 | //0xec59 |
| 4325 | void CyberOroConnection::handleRoomChat(unsigned char * msg, unsigned int size) |
| 4326 | { |
| 4327 | /* Maybe this is game chat only ?!??! Its weird... I guess |
| 4328 | * its just for whatever room you're in and you can only be in |
| 4329 | * one room at a time, a game room, a club room, but only one room.*/ |
| 4330 | unsigned char * p = msg; |
| 4331 | |
| 4332 | #ifdef RE_DEBUG |
| 4333 | int i; |
| 4334 | #endif //RE_DEBUG |
| 4335 | /*printf("** msg size: %d: ", size); |
| 4336 | for(i = 0; i < (int)size; i++) |
| 4337 | printf("%02x", p[i]); |
| 4338 | printf("\n");*/ |
| 4339 | Room * room = getDefaultRoom(); |
| 4340 | const PlayerListing * player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 4341 | p += 2; |
| 4342 | if(player->name == getUsername()) |
| 4343 | return; //block as echo |
| 4344 | |
| 4345 | //these two bytes are font or something |
| 4346 | p += 2; |
| 4347 | // the rest is the text |
| 4348 | unsigned char * text = new unsigned char[size - 3]; |
| 4349 | strncpy((char *)text, (char *)p, size - 4); text[size - 4] = 0x00; |
| 4350 | |
| 4351 | if(player) |
| 4352 | { |
| 4353 | #ifdef RE_DEBUG |
| 4354 | printf("%s says to you ", player->name.toLatin1().constData()); |
| 4355 | for(i = 0; i < (int)size - 4; i++) |
| 4356 | printf("%02x", text[i]); |
| 4357 | printf("\n"); |
| 4358 | #endif //RE_DEBUG |
| 4359 | |
| 4360 | QString u; |
| 4361 | |
| 4362 | u = serverCodec->toUnicode((const char *)text, size - 4); |
| 4363 | |
| 4364 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_were_in); |
| 4365 | if(boarddispatch) |
| 4366 | boarddispatch->recvKibitz(player->name + "[" + player->rank + "]", u); |
| 4367 | else |
| 4368 | { |
| 4369 | qDebug("No boarddispatch for %d", room_were_in); |
| 4370 | if(console_dispatch) |
| 4371 | console_dispatch->recvText(player->name + "(" + QString::number(room_were_in) + "): " + u); |
| 4372 | } |
| 4373 | } |
| 4374 | else |
| 4375 | printf("unknown player says something"); |
| 4376 | delete[] text; |
| 4377 | } |
| 4378 | |
| 4379 | void CyberOroConnection::handlePersonalChat(unsigned char * msg, unsigned int size) |
| 4380 | { |
| 4381 | unsigned char * p = msg; |
| 4382 | unsigned char * text = new unsigned char[size - 7]; |
| 4383 | #ifdef RE_DEBUG |
| 4384 | unsigned int i; |
| 4385 | printf("** msg size: %d: ", size); |
| 4386 | for(i = 0; i < size; i++) |
| 4387 | printf("%02x", p[i]); |
| 4388 | printf("\n"); |
| 4389 | #endif //RE_DEBUG |
| 4390 | Room * room = getDefaultRoom(); |
| 4391 | p += 4; |
| 4392 | PlayerListing * player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 4393 | p += 2; |
| 4394 | p += 2; |
| 4395 | strncpy((char *)text, (char *)p, size - 8); text[size - 8] = 0x00; |
| 4396 | if(player) |
| 4397 | { |
| 4398 | #ifdef RE_DEBUG |
| 4399 | printf("%s says to you ", player->name.toLatin1().constData()); |
| 4400 | for(i = 0; i < size - 8; i++) |
| 4401 | printf("%02x", text[i]); |
| 4402 | printf("\n"); |
| 4403 | #endif //RE_DEBUG |
| 4404 | Talk * talk = getDefaultRoom()->getTalk(player); |
| 4405 | if(talk) |
| 4406 | { |
| 4407 | talk->recvTalk(QString((char *)text)); |
| 4408 | talk->updatePlayerListing(); |
| 4409 | } |
| 4410 | //if(console_dispatch) |
| 4411 | // console_dispatch->recvText(player->name + "-> " + QString((char *)text)); |
| 4412 | } |
| 4413 | else |
| 4414 | printf("unknown player says something"); |
| 4415 | delete[] text; |
| 4416 | } |
| 4417 | |
| 4418 | //not disconnect, enter lobby? 0e56, really leaning towards enterlobby |
| 4419 | // or enter anything |
| 4420 | // this is definitely an actual enter room. We might need to use this |
| 4421 | // when we join a room, especially or in particular a broadcast room |
| 4422 | // if the betting message doesn't otherwise indicate that we've actually |
| 4423 | // joined. Otherwise we get the move list and there's nothing tohandle it |
| 4424 | // FIXME |
| 4425 | void CyberOroConnection::handlePlayerRoomJoin(unsigned char * msg, unsigned int size) |
| 4426 | { |
| 4427 | Room * room = getDefaultRoom(); |
| 4428 | unsigned char * p = msg; |
| 4429 | unsigned int id; |
| 4430 | unsigned short room_number; |
| 4431 | BoardDispatch * boarddispatch; |
| 4432 | GameListing * game; |
| 4433 | |
| 4434 | if(size != 4) |
| 4435 | qDebug("handlePlayerRoomJoin of size: %d\n", size); |
| 4436 | id = p[0] + (p[1] << 8); |
| 4437 | PlayerListing * aPlayer = room->getPlayerListing(id); |
| 4438 | room_number = p[2] + (p[3] << 8); |
| 4439 | #ifdef RE_DEBUG |
| 4440 | printf("%s %02x%02x entering room %d\n", aPlayer->name.toLatin1().constData(), p[0], p[1], room_number); |
| 4441 | #endif //RE_DEBUG |
| 4442 | /* We get this message before the boarddispatch is created, which |
| 4443 | * means that we won't see ourselves entering the game. If |
| 4444 | * we wanted to fix this, we could create the boarddispatch |
| 4445 | * possibly a little earlier, or just add our own name as |
| 4446 | * a listing when we observe games. Then there's matches |
| 4447 | * also. FIXME */ |
| 4448 | if(room_were_in) |
| 4449 | { |
| 4450 | if(aPlayer->observing == room_were_in) |
| 4451 | { |
| 4452 | boarddispatch = getIfBoardDispatch(room_were_in); |
| 4453 | if(boarddispatch) |
| 4454 | boarddispatch->recvObserver(aPlayer, false); |
| 4455 | } |
| 4456 | else if(room_number == room_were_in) |
| 4457 | { |
| 4458 | boarddispatch = getIfBoardDispatch(room_were_in); |
| 4459 | if(boarddispatch) |
| 4460 | boarddispatch->recvObserver(aPlayer, true); |
| 4461 | } |
| 4462 | } |
| 4463 | if(aPlayer->observing) |
| 4464 | removeObserverFromGameListing(aPlayer); |
| 4465 | aPlayer->observing = room_number; |
| 4466 | if(room_number) //0 is lobby |
| 4467 | { |
| 4468 | game = room->getGameListing(room_number); |
| 4469 | game->observers++; |
| 4470 | game->observer_list.push_back(aPlayer); |
| 4471 | if(id == our_player_id) |
| 4472 | { |
| 4473 | if(game->gameData) //only used on finished games where we won't receive info from server |
| 4474 | { |
| 4475 | boarddispatch = getBoardDispatch(room_number); |
| 4476 | boarddispatch->openBoard(); |
| 4477 | } |
| 4478 | setRoomNumber(room_number); |
| 4479 | if((boarddispatch = getIfBoardDispatch(room_number))) |
| 4480 | addObserverListToBoard(boarddispatch); |
| 4481 | } |
| 4482 | } |
| 4483 | /* We set to 0 here with the idea that they aren't entering |
| 4484 | * their own game, but its a little weird FIXME */ |
| 4485 | setAttachedGame(aPlayer, 0); |
| 4486 | emit playerListingReceived(aPlayer); |
| 4487 | } |
| 4488 | |
| 4489 | void CyberOroConnection::removeObserverFromGameListing(const PlayerListing * p) |
| 4490 | { |
| 4491 | Room * room = getDefaultRoom(); |
| 4492 | GameListing * game = room->getGameListing(p->observing); |
| 4493 | #ifdef RE_DEBUG |
| 4494 | //printf("Removing observer from game %d with %d observers\n", game->number, game->observers); |
| 4495 | #endif //RE_DEBUG |
| 4496 | if(game->observers == 0) |
| 4497 | { |
| 4498 | /* This can happen if, for instance, someone creates a broadcast game |
| 4499 | * that hangs around with 0 observers, and then leaves it and joins |
| 4500 | * another game. We just don't want negative numbers */ |
| 4501 | return; |
| 4502 | } |
| 4503 | game->observers--; |
| 4504 | for(std::vector<PlayerListing *>::iterator oblistit = game->observer_list.begin(); |
| 4505 | oblistit != game->observer_list.end(); oblistit++) |
| 4506 | { |
| 4507 | if(*oblistit == p) |
| 4508 | { |
| 4509 | game->observer_list.erase(oblistit); |
| 4510 | break; |
| 4511 | } |
| 4512 | } |
| 4513 | if(game->observers == 0 && !game->isBroadcast) |
| 4514 | { |
| 4515 | /* We should probably increment an observer count here, and |
| 4516 | * decrement, and if it gets to 0, remove the room. I don't |
| 4517 | * think there's another message that does it FIXME (but this |
| 4518 | * requires accurate observer counts. */ |
| 4519 | game->running = false; |
| 4520 | emit gameListingReceived(game); |
| 4521 | /* No, oro tells us elsewhere to delete game */ |
| 4522 | /* Not necessarily, its possible that if the game is fully over when everyone leaves |
| 4523 | * its assumed that it gets deleted FIXME */ |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | //4a9c likely real disconnect or maybe not!!! |
| 4528 | void CyberOroConnection::handlePlayerDisconnect2(unsigned char * msg, unsigned int size) |
| 4529 | { |
| 4530 | Room * room = getDefaultRoom(); |
| 4531 | unsigned char * p = msg; |
| 4532 | unsigned int id; |
| 4533 | unsigned short room_id; |
| 4534 | if(size != 4) |
| 4535 | qDebug("handlePlayerDisconnect of size: %d\n", size); |
| 4536 | id = p[0] + (p[1] << 8); |
| 4537 | PlayerListing * aPlayer = room->getPlayerListing(id); |
| 4538 | p += 2; |
| 4539 | /* If this is the room id, its reversed... */ |
| 4540 | room_id = p[0] + (p[1] << 8); |
| 4541 | #ifdef RE_DEBUG |
| 4542 | printf("%s 4a9c: %02x%02x %d %d\n", aPlayer->name.toLatin1().constData(), p[0], p[1], room_id, aPlayer->observing); |
| 4543 | #endif //RE_DEBUG |
| 4544 | |
| 4545 | if(aPlayer->observing) |
| 4546 | { |
| 4547 | room_id = aPlayer->observing; |
| 4548 | removeObserverFromGameListing(aPlayer); |
| 4549 | } |
| 4550 | else |
| 4551 | room_id = 0; |
| 4552 | |
| 4553 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_id); |
| 4554 | if(boarddispatch) |
| 4555 | { |
| 4556 | // Player left a running game? maybe observer though |
| 4557 | // but we need to check if stop clock is necessary |
| 4558 | boarddispatch->recvObserver(aPlayer, false); //doublecheck |
| 4559 | GameData * gd = boarddispatch->getGameData(); |
| 4560 | if(gd->gameMode == modeMatch && (aPlayer->name == gd->black_name || aPlayer->name == gd->white_name)) |
| 4561 | { |
| 4562 | boarddispatch->recvKibitz(QString(), tr("%1 has left the room.").arg(aPlayer->name)); |
| 4563 | if(gd->moves < 10) //doublecheck, not 11?? FIXME |
| 4564 | { |
| 4565 | boarddispatch->recvKibitz(QString(), tr("Adjourned games with less than 10 moves are not counted.")); |
| 4566 | GameResult aGameResult; |
| 4567 | aGameResult.result = GameResult::NOGAME; |
| 4568 | boarddispatch->recvResult(&aGameResult); |
| 4569 | } |
| 4570 | else |
| 4571 | { |
| 4572 | match_negotiation_state->opponentDisconnect(); |
| 4573 | boarddispatch->stopTime(); |
| 4574 | QString q = QString(tr("Opponent Disconnected")); |
| 4575 | boarddispatch->moveControl(q); |
| 4576 | } |
| 4577 | } |
| 4578 | } |
| 4579 | |
| 4580 | aPlayer->online = false; |
| 4581 | emit playerListingReceived(aPlayer); |
| 4582 | } |
| 4583 | |
| 4584 | //85bb |
| 4585 | // I think these are result messages... I thought they were new game |
| 4586 | // from people doing rematches... but there's no game codes in them... |
| 4587 | // they could also be player updates I guess, but that's doubtful |
| 4588 | void CyberOroConnection::handleNewGame(unsigned char * msg, unsigned int size) |
| 4589 | { |
| 4590 | unsigned char * p = msg; |
| 4591 | unsigned short player_id = p[0] + (p[1] << 8); |
| 4592 | |
| 4593 | if(size != 28) |
| 4594 | qDebug("85bb new game of size %d", size); |
| 4595 | #ifdef RE_DEBUG |
| 4596 | Room * room = getDefaultRoom(); |
| 4597 | PlayerListing * player; |
| 4598 | player = room->getPlayerListing(player_id); |
| 4599 | if(player) |
| 4600 | printf("%s ", player->name.toLatin1().constData()); |
| 4601 | // 4th byte here is 01 for winner and 02 for loser |
| 4602 | // separate msg for each player result |
| 4603 | if(p[3] == 0x10) |
| 4604 | printf(" wins "); |
| 4605 | else if(p[3] == 0x20) |
| 4606 | printf(" loses "); |
| 4607 | else |
| 4608 | printf(" %02x ", p[3]); |
| 4609 | for(unsigned int i = 0; i < 28; i++) |
| 4610 | printf("%02x", p[i]); |
| 4611 | printf("\n"); |
| 4612 | #endif //RE_DEBUG |
| 4613 | // we probably don't send these during pass? |
| 4614 | if(player_id == our_player_id) |
| 4615 | killActiveMatchTimers(); |
| 4616 | //GameListing * g = room->getGameListing(); |
| 4617 | //g->running = false; |
| 4618 | //room->recvGameListing(g); |
| 4619 | } |
| 4620 | |
| 4621 | /* Below might not be observer list at all.... |
| 4622 | * Maybe its for betting matches ?!?!? */ |
| 4623 | //FIXME, yeah, not observer list |
| 4624 | //0xdfde |
| 4625 | void CyberOroConnection::handleObserverList(unsigned char * msg, unsigned int size) |
| 4626 | { |
| 4627 | unsigned char * p = msg; |
| 4628 | BoardDispatch * boarddispatch; |
| 4629 | |
| 4630 | if(!room_were_in) |
| 4631 | { |
| 4632 | qDebug("observer list but we're not in a room!"); |
| 4633 | return; |
| 4634 | } |
| 4635 | boarddispatch = getIfBoardDispatch(room_were_in); |
| 4636 | if(!boarddispatch) |
| 4637 | { |
| 4638 | qDebug("no board dispatch for room were in"); |
| 4639 | return; |
| 4640 | } |
| 4641 | |
| 4642 | #ifdef RE_DEBUG |
| 4643 | printf("0xdfde: "); |
| 4644 | for(int i = 0; i < (int)size; i++) |
| 4645 | printf("%02x", msg[i]); |
| 4646 | printf("\n"); |
| 4647 | #endif //RE_DEBUG |
| 4648 | // unsigned short game_code = p[0] + (p[1] << 8); |
| 4649 | p += 2; |
| 4650 | //unsigned short observer_list_index = p[0] + (p[1] << 8); |
| 4651 | p += 2; |
| 4652 | /*if(size != 10) |
| 4653 | { |
| 4654 | qDebug("GameEnded of strange size: %d", size); |
| 4655 | return; |
| 4656 | }*/ |
| 4657 | p += 24; //zeroes |
| 4658 | while(p < (msg + size - 20)) |
| 4659 | { |
| 4660 | p += 8; |
| 4661 | // unsigned short id = p[0] + (p[1] << 8); |
| 4662 | /*aPlayer = room->getPlayerListing(id); |
| 4663 | if(aPlayer) |
| 4664 | boarddispatch->recvObserver(aPlayer, true); |
| 4665 | else*/ |
| 4666 | #ifdef RE_DEBUG |
| 4667 | printf("ol: %02x %02x\n", p[0], p[1]); |
| 4668 | #endif //RE_DEBUG |
| 4669 | p += 12; |
| 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | /* What if this wasn't game ended but instead game started and we got it when |
| 4674 | * there were returns to match mode as well as rematches?!?! I'll try sending |
| 4675 | * it as an accept. FIXME*/ |
| 4676 | //0xe1af: |
| 4677 | void CyberOroConnection::handleGameEnded(unsigned char * msg, unsigned int size) |
| 4678 | { |
| 4679 | unsigned char * p = msg; |
| 4680 | unsigned short game_code; |
| 4681 | unsigned int game_number; |
| 4682 | GameListing * game; |
| 4683 | Room * room = getDefaultRoom(); |
| 4684 | if(size != 10) |
| 4685 | { |
| 4686 | qDebug("GameEnded of strange size: %d", size); |
| 4687 | return; |
| 4688 | } |
| 4689 | game_code = msg[0] + (msg[1] << 8); |
| 4690 | game_number = msg[2] + (msg[3] << 8); |
| 4691 | p += 4; |
| 4692 | #ifdef RE_DEBUG |
| 4693 | //DOUBLECHECK |
| 4694 | printf("e1af for %d %d\n", game_code, game_number); |
| 4695 | #endif //RE_DEBUG |
| 4696 | game = room->getGameListing(game_number); |
| 4697 | /* FIXME, what about owner_id??? this could be a room |
| 4698 | * closed message */ |
| 4699 | /* Room doesn't go away after game, one can still join it until |
| 4700 | * everyone is gone */ |
| 4701 | #ifdef NOTREALLY |
| 4702 | /*if(game->white) |
| 4703 | { |
| 4704 | game->white->playing = 0; |
| 4705 | game->white = 0; //just in case |
| 4706 | } |
| 4707 | if(game->black) |
| 4708 | { |
| 4709 | game->black->playing = 0; |
| 4710 | game->black = 0; //just in case |
| 4711 | } |
| 4712 | game->running = false; |
| 4713 | room->recvGameListing(game); |
| 4714 | game_code_to_number.erase(game_number); // good?*/ |
| 4715 | #endif //NOTREALLY |
| 4716 | //the rest are pretty repetitive, non-specific FIXME |
| 4717 | #ifdef RE_DEBUG |
| 4718 | printf("0xe1af: "); |
| 4719 | for(int i = 0; i < (int)size; i++) |
| 4720 | printf("%02x", msg[i]); |
| 4721 | printf("\n"); |
| 4722 | #endif //RE_DEBUG |
| 4723 | } |
| 4724 | |
| 4725 | /* I'm thinking 0a7d may be NewMatch and ca5d is NewRoom FIXME */ |
| 4726 | //0a7d |
| 4727 | void CyberOroConnection::handleNewRoom(unsigned char * msg, unsigned int size) |
| 4728 | { |
| 4729 | Room * room = getDefaultRoom(); |
| 4730 | unsigned char * p = msg; |
| 4731 | PlayerListing * black; |
| 4732 | PlayerListing * white; |
| 4733 | unsigned short id; |
| 4734 | unsigned short number; |
| 4735 | GameListing * aGameListing; |
| 4736 | |
| 4737 | if(size != 6 && size != 18) |
| 4738 | { |
| 4739 | qDebug("NewRoom of strange size: FIXME 18 %d", size); |
| 4740 | //FIXME we're having handleResume call this with size 18 |
| 4741 | // fix that... |
| 4742 | //return; |
| 4743 | } |
| 4744 | |
| 4745 | |
| 4746 | number = p[0] + (p[1] << 8); |
| 4747 | if(!number) |
| 4748 | qDebug("0a7d on number 0"); |
| 4749 | aGameListing = room->getGameListing(number); |
| 4750 | p += 2; |
| 4751 | /* Why does ORO 0a7d have white then black, but 1a81 has |
| 4752 | * black then white? And what about numbers and game_codes? |
| 4753 | * it seems like ORO protocol is based on two different programs, |
| 4754 | * like there's legacy code in there. And I complained about IGS |
| 4755 | * so much. I guess nothing is perfect. And I'm lazy in this all |
| 4756 | * the time too... |
| 4757 | * Okay, actually, this seems to reverse, like maybe this just means |
| 4758 | * they're in the same room or something and they're still deciding |
| 4759 | * white versus black, or there's some nigiri thing... this white |
| 4760 | * black DOESN'T matter. */ |
| 4761 | /* Okay, since we changed the listing to handle numbers, game codes |
| 4762 | * on board dispatches... what's changed here ??? FIXME */ |
| 4763 | aGameListing->owner_id = p[0] + (p[1] << 8); |
| 4764 | aGameListing->observers = 0; //okay? |
| 4765 | white = room->getPlayerListing(aGameListing->owner_id); |
| 4766 | /* This is redundant, but we won't receive entering msgs |
| 4767 | * for these players */ |
| 4768 | setAttachedGame(white, aGameListing->number); |
| 4769 | white->observing = aGameListing->number; |
| 4770 | if(aGameListing->owner_id == our_player_id) |
| 4771 | setRoomNumber(aGameListing->number); |
| 4772 | aGameListing->observers++; |
| 4773 | aGameListing->observer_list.push_back(white); |
| 4774 | |
| 4775 | p += 2; |
| 4776 | id = p[0] + (p[1] << 8); |
| 4777 | black = room->getPlayerListing(id); |
| 4778 | if(!black) |
| 4779 | { |
| 4780 | printf("can't get black player: %02x%02x\n", p[0], p[1]); |
| 4781 | //return; //not an issue |
| 4782 | } |
| 4783 | else |
| 4784 | { |
| 4785 | setAttachedGame(black, aGameListing->number); |
| 4786 | black->observing = aGameListing->number; |
| 4787 | if(id == our_player_id) |
| 4788 | setRoomNumber(aGameListing->number); |
| 4789 | aGameListing->observers++; |
| 4790 | aGameListing->observer_list.push_back(black); |
| 4791 | } |
| 4792 | /* FIXME, no recv, no game yet, maybe there should be. */ |
| 4793 | aGameListing->white = white; |
| 4794 | aGameListing->black = black; |
| 4795 | |
| 4796 | #ifdef RE_DEBUG |
| 4797 | if(newGameListing) |
| 4798 | printf("0a7d for game with no game code: %d %s size(%d) %s\n", aGameListing->number, white->name.toLatin1().constData(), size, black->name.toLatin1().constData()); |
| 4799 | #endif //RE_DEBUG |
| 4800 | emit gameListingReceived(aGameListing); |
| 4801 | } |
| 4802 | |
| 4803 | //1a81 |
| 4804 | void CyberOroConnection::handleGameMsg(unsigned char * msg, unsigned int size) |
| 4805 | { |
| 4806 | Room * room = getDefaultRoom(); |
| 4807 | unsigned char * p = msg; |
| 4808 | unsigned short game_code; |
| 4809 | unsigned int handicap; |
| 4810 | unsigned char byte; |
| 4811 | PlayerListing * black; |
| 4812 | PlayerListing * white; |
| 4813 | PlayerListing * owner; |
| 4814 | GameListing * aGameListing = 0; |
| 4815 | if(size != 22) |
| 4816 | { |
| 4817 | qDebug("game msg of strange size %d", size); |
| 4818 | } |
| 4819 | #ifdef RE_DEBUG |
| 4820 | printf("1a81 message: "); |
| 4821 | #endif //RE_DEBUG |
| 4822 | game_code = p[0] + (p[1] << 8); //used in joining games |
| 4823 | #ifdef RE_DEBUG |
| 4824 | printf("%02x%02x {%02x ", p[0], p[1], p[2]); |
| 4825 | #endif //RE_DEBUG |
| 4826 | p += 2; |
| 4827 | //0x1f |
| 4828 | p++; |
| 4829 | handicap = p[0]; |
| 4830 | p++; |
| 4831 | #ifdef RE_DEBUG |
| 4832 | for(unsigned int i = 0; i < size - 4; i++) |
| 4833 | printf("%02x", p[i]); |
| 4834 | #endif //RE_DEBUG |
| 4835 | byte = p[2]; |
| 4836 | p += 2; |
| 4837 | |
| 4838 | black = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 4839 | #ifdef RE_DEBUG |
| 4840 | if(black) |
| 4841 | printf("} game of %s %02x%02x", black->name.toLatin1().constData(), p[0], p[1]); |
| 4842 | #endif //RE_DEBUG |
| 4843 | p += 2; |
| 4844 | white = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 4845 | #ifdef RE_DEBUG |
| 4846 | if(white) |
| 4847 | printf(" and %s %02x%02x", white->name.toLatin1().constData(), p[0], p[1]); |
| 4848 | #endif //RE_DEBUG |
| 4849 | p += 2; |
| 4850 | #ifdef RE_DEBUG |
| 4851 | printf("\n"); |
| 4852 | #endif //RE_DEBUG |
| 4853 | if(!black || !white) |
| 4854 | { |
| 4855 | printf("%d gamecode game is missing black or white\n", game_code); |
| 4856 | return; |
| 4857 | } |
| 4858 | /* If there's a rematch, we might be able to just use |
| 4859 | * the "attachedgame" to get the number */ |
| 4860 | if(black->observing) |
| 4861 | { |
| 4862 | aGameListing = room->getGameListing(black->observing); |
| 4863 | #ifdef RE_DEBUG |
| 4864 | if(aGameListing) |
| 4865 | printf("Found %d for this game\n", aGameListing->number); |
| 4866 | #endif //RE_DEBUG |
| 4867 | } |
| 4868 | if(white->observing && !aGameListing) |
| 4869 | { |
| 4870 | aGameListing = room->getGameListing(white->observing); |
| 4871 | #ifdef RE_DEBUG |
| 4872 | if(aGameListing) |
| 4873 | printf("Found %d for this game\n", aGameListing->number); |
| 4874 | #endif //RE_DEBUG |
| 4875 | } |
| 4876 | if(black->playing && !aGameListing) |
| 4877 | { |
| 4878 | aGameListing = room->getGameListing(black->playing); |
| 4879 | #ifdef RE_DEBUG |
| 4880 | if(aGameListing) |
| 4881 | printf("Found %d for this game\n", aGameListing->number); |
| 4882 | #endif //RE_DEBUG |
| 4883 | } |
| 4884 | if(white->playing && !aGameListing) |
| 4885 | { |
| 4886 | aGameListing = room->getGameListing(white->playing); |
| 4887 | #ifdef RE_DEBUG |
| 4888 | if(aGameListing) |
| 4889 | printf("Found %d for this game\n", aGameListing->number); |
| 4890 | #endif //RE_DEBUG |
| 4891 | } |
| 4892 | if(aGameListing && aGameListing->running == false) |
| 4893 | { |
| 4894 | qDebug("Found non running game in game registry !!!"); |
| 4895 | return; |
| 4896 | } |
| 4897 | |
| 4898 | if(!aGameListing) |
| 4899 | { |
| 4900 | printf("No 0a7d for this game\n"); |
| 4901 | return; |
| 4902 | /* FIXME, if there's no room, we can't add the game. */ |
| 4903 | } |
| 4904 | |
| 4905 | game_code_to_number[game_code] = aGameListing->number; |
| 4906 | #ifdef RE_DEBUG |
| 4907 | printf("Setting game code to game number %02x%02x %d\n", msg[0], msg[1], aGameListing->number); |
| 4908 | #endif //RE_DEBUG |
| 4909 | /* Somehow, its possible to get here with a game listing that's been erased and yet somehow comes up |
| 4910 | * from getGameListing FIXME FIXME*/ |
| 4911 | aGameListing->black = black; |
| 4912 | aGameListing->white = white; |
| 4913 | owner = room->getPlayerListing(aGameListing->owner_id); |
| 4914 | /* FIXME, Presumably this is where the crash comes from, we don't get entering rooms for these players |
| 4915 | * which is fine, but we need to inc the observers to prevent removing the owner from deleting it */ |
| 4916 | if(owner != black) |
| 4917 | { |
| 4918 | setAttachedGame(black, aGameListing->number); |
| 4919 | aGameListing->observers++; |
| 4920 | } |
| 4921 | if(owner != white) |
| 4922 | { |
| 4923 | setAttachedGame(white, aGameListing->number); |
| 4924 | aGameListing->observers++; |
| 4925 | } |
| 4926 | //detach owner if any, players are attached alread |
| 4927 | if(owner && owner != black && owner != white) |
| 4928 | setAttachedGame(owner, 0); |
| 4929 | /* Its crashing below FIXME because the players aren't adding to the observers list and then setAttachedGame is deleting |
| 4930 | * the game */ |
| 4931 | /* FIXME we may want to swap the colors? if they're now |
| 4932 | * legit, pending on nigiri comprehension?? */ |
| 4933 | aGameListing->FR = QString::number(byte); //should probably just be ->flags FIXME |
| 4934 | aGameListing->game_code = game_code; |
| 4935 | aGameListing->handicap = handicap; |
| 4936 | aGameListing->isRoomOnly = false; |
| 4937 | } |
| 4938 | //1b00 2900 0100 0000 0600 2c01 6900 2500 0404 0000 1400 0400 0200 6b61 7365 697a 696e 0000 |
| 4939 | //626d 7762 6d77 0000 0000 6b61 7365 697a 696e 0000 8df7 92ac 0000 0000 0000 0303 a8a8 0103 |
| 4940 | //000200000000000042000000000000000000000000000000000000000000000000000000000000000000000b |
| 4941 | |
| 4942 | //1b00 ffff 0100 0000 0600 8403 8403 8403 0303 0000 1e00 0300 0200 7363 6879 3837 3337 0000 |
| 4943 | //7968 6c65 6564 6562 0000 bcf8 bcf6 0000 0000 0000 c8ab c0ba b0c5 bbe7 0000 0101 a7a7 0105 |
| 4944 | //000200000000000000000000000000000000000000000000000000000000000000000000000000000001000b |
| 4945 | |
| 4946 | |
| 4947 | //1c00 ffff 0100 0000 0600 2c01 2c01 2c01 0505 0000 1400 0500 0200 7475 7266 6679 0000 0000 |
| 4948 | //6c69 6831 3230 3600 0000 8b49 9656 0000 0000 0000 3132 3036 0000 0000 0000 0301 a7a7 0105 |
| 4949 | //000200000000000000000000000000000000000000000000000000000000000000000000000000000001000b |
| 4950 | |
| 4951 | //1c00 ffff 0100 0000 0600 2c01 2c01 2c01 0303 0000 1e00 0300 0200 696e 796f 7000 0000 0000 |
| 4952 | //6b6b 3036 3239 0000 0000 c7d1 bdb4 c7d1 bdb4 0000 6b6b 3036 3239 0000 0000 0101 a7a7 0101 |
| 4953 | //00020000000000000000000000000000000000000000000000000000000000000000000000000 |
| 4954 | //0000001000b |
| 4955 | |
| 4956 | |
| 4957 | /* I think we get these when we try to observe broadcasted, or betting games |
| 4958 | * as well. */ |
| 4959 | void CyberOroConnection::handleBettingMatchStart(unsigned char * msg, unsigned int size) |
| 4960 | { |
| 4961 | Room * room = getDefaultRoom(); |
| 4962 | unsigned char * p = msg; |
| 4963 | BoardDispatch * boarddispatch; |
| 4964 | GameListing * aGameListing; |
| 4965 | GameData * aGameData, * newGameData = 0; |
| 4966 | unsigned char name[11]; |
| 4967 | name[10] = 0x00; |
| 4968 | unsigned short game_number; |
| 4969 | int black_seconds, white_seconds; |
| 4970 | int black_periods, white_periods; |
| 4971 | bool black_in_byoyomi, white_in_byoyomi; |
| 4972 | bool joining = false; |
| 4973 | if(size != 116) |
| 4974 | { |
| 4975 | qDebug("Betting Match msg of strange size %d", size); |
| 4976 | } |
| 4977 | #ifdef RE_DEBUG |
| 4978 | printf("New Betting Match: "); |
| 4979 | for(unsigned int i = 0; i < size; i++) |
| 4980 | printf("%02x", p[i]); |
| 4981 | printf("\n"); |
| 4982 | #endif //RE_DEBUG |
| 4983 | |
| 4984 | /* We get this when we join a broadcasted game. I'm not certain when |
| 4985 | * it should open a board yet. Maybe we'll have to set something in |
| 4986 | * the observe code to do that... but I'm going to try something here */ |
| 4987 | /* Oh but wait... because its a total piece of shit, the move list2 |
| 4988 | * comes with game_code, rather than number. Without making things |
| 4989 | * stateful, and I'm just not ready for that kind of commitment, we'll |
| 4990 | * need to create on MoveList2. Except there's another problem. |
| 4991 | * the game info is on the listing which we get with the number. |
| 4992 | * I swear to god. I was so annoyed with IGS that they didn't |
| 4993 | * consistently transmit game ids with info. But ORO is just ridiculous, |
| 4994 | * with two different identifiers, not used consistently.*/ |
| 4995 | /* Okay, final solution. We store the game number when we start to |
| 4996 | * observe and the move list picks it up. */ |
| 4997 | /* We still can get time settings here and store them on the listing?? */ |
| 4998 | game_number = msg[0] + (msg[1] << 8); |
| 4999 | |
| 5000 | p += 2; |
| 5001 | /* The next two bytes might help. or not*/ |
| 5002 | if(msg[2] == 0xff && msg[3] == 0xff) |
| 5003 | { |
| 5004 | /* If these are ffff, we can add it to the listing I think */ |
| 5005 | joining = false; |
| 5006 | #ifdef RE_DEBUG |
| 5007 | printf("not for joining\n"); |
| 5008 | #endif //RE_DEBUG |
| 5009 | } |
| 5010 | else if(our_player_id == msg[2] + (msg[3] << 8)) |
| 5011 | { |
| 5012 | joining = true; |
| 5013 | #ifdef RE_DEBUG |
| 5014 | printf("joining\n"); |
| 5015 | #endif //RE_DEBUG |
| 5016 | } |
| 5017 | |
| 5018 | p += 2; |
| 5019 | /* FIXME Okay, I'm thinking that there's a standard game |
| 5020 | * data struct that we should just write something to convert |
| 5021 | * from. I.e., we pass it the chunk of data and done. |
| 5022 | * Check out some of the match offers and see if we can |
| 5023 | * puzzle it out */ |
| 5024 | if(joining) |
| 5025 | { |
| 5026 | #ifdef RE_DEBUG |
| 5027 | //this keeps coming up, I think just to tell us there's a game but its annoying because it opens |
| 5028 | //a window FIXME |
| 5029 | qDebug("Apparently joining or not %d (%d?)", game_number, connecting_to_game_number); |
| 5030 | #endif //RE_DEBUG |
| 5031 | boarddispatch = getBoardDispatch(game_number); |
| 5032 | aGameData = boarddispatch->getGameData(); |
| 5033 | } |
| 5034 | else |
| 5035 | { |
| 5036 | aGameData = new GameData(); |
| 5037 | } |
| 5038 | aGameData->number = game_number; |
| 5039 | /* Also, we should check for connecting_to_game_number */ |
| 5040 | p += 2; |
| 5041 | // our id? |
| 5042 | //0100 0000 0600 2c01 6900 2500 0404 0000 1400 0400 0200 6b61 |
| 5043 | //1b00 ffff |
| 5044 | //0100 0000 0600 8403 8403 8403 0303 0000 1e00 0300 0200 |
| 5045 | aGameData->handicap = msg[6]; |
| 5046 | if(msg[7]) |
| 5047 | aGameData->komi = -((float)(msg[8])) - 0.5; |
| 5048 | else |
| 5049 | aGameData->komi = ((float)(msg[8])) + 0.5; |
| 5050 | |
| 5051 | p += 6; //skip first time? |
| 5052 | black_seconds = msg[12] + (msg[13] << 8); |
| 5053 | p += 2; |
| 5054 | white_seconds = msg[14] + (msg[15] << 8); |
| 5055 | p += 2; |
| 5056 | black_periods = msg[16]; |
| 5057 | white_periods = msg[17]; |
| 5058 | p += 2; |
| 5059 | black_in_byoyomi = msg[18]; |
| 5060 | white_in_byoyomi = msg[19]; |
| 5061 | if(!black_in_byoyomi) |
| 5062 | black_periods = -1; //FIXME, awkward flags |
| 5063 | if(!white_in_byoyomi) |
| 5064 | white_periods = -1; |
| 5065 | |
| 5066 | p += 2; |
| 5067 | aGameData->maintime = black_seconds; |
| 5068 | aGameData->periodtime = msg[20] + (msg[21] << 8); |
| 5069 | p += 2; |
| 5070 | aGameData->stones_periods = msg[22]; |
| 5071 | switch(msg[23]) |
| 5072 | { |
| 5073 | case 0: |
| 5074 | aGameData->timeSystem = byoyomi; |
| 5075 | qDebug("byoyomi %d %d\n", aGameData->stones_periods, aGameData->periodtime); |
| 5076 | break; |
| 5077 | case 1: |
| 5078 | aGameData->timeSystem = canadian; |
| 5079 | qDebug("canadian %d %d\n", aGameData->stones_periods, aGameData->periodtime); |
| 5080 | break; |
| 5081 | case 2: |
| 5082 | aGameData->timeSystem = tvasia; |
| 5083 | qDebug("asia %d %d\n", aGameData->stones_periods, aGameData->periodtime); |
| 5084 | break; |
| 5085 | } |
| 5086 | p += 2; |
| 5087 | //two names |
| 5088 | p += 2; |
| 5089 | //0200 |
| 5090 | //second byte could be board size, but usually 19 for Betting |
| 5091 | aGameData->board_size = 19; //FIXME?!?? |
| 5092 | |
| 5093 | if(1)//(add_listing) |
| 5094 | { |
| 5095 | aGameListing = room->getGameListing(game_number); |
| 5096 | aGameListing->running = true; |
| 5097 | aGameListing->isBetting = true; |
| 5098 | aGameListing->handicap = aGameData->handicap; |
| 5099 | aGameListing->game_code = aGameData->number; //because broadcast?? |
| 5100 | aGameListing->komi = aGameData->komi; |
| 5101 | strncpy((char *)name, (char *)&(msg[28]), 10); |
| 5102 | p += 10; |
| 5103 | /* First two names often seem to choke? FIXME, try second two */ |
| 5104 | /*aGameListing->black = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 5105 | if(!aGameListing->black) |
| 5106 | {*/ |
| 5107 | //aGameListing->_black_name = QString((char *)name); |
| 5108 | aGameListing->_black_name = serverCodec->toUnicode((const char *)name, strlen((const char *)name)); |
| 5109 | /*} |
| 5110 | p += 2;*/ |
| 5111 | strncpy((char *)name, (char *)&(msg[38]), 10); |
| 5112 | p += 10; |
| 5113 | /*aGameListing->white = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 5114 | if(!aGameListing->white) |
| 5115 | {*/ |
| 5116 | //aGameListing->_white_name = QString((char *)name); |
| 5117 | aGameListing->_white_name = serverCodec->toUnicode((const char *)name, strlen((const char *)name)); |
| 5118 | /*} |
| 5119 | p += 2;*/ |
| 5120 | //two more names, unicode?? |
| 5121 | strncpy((char *)name, (char *)&(msg[48]), 10); |
| 5122 | //aGameListing->_black_name = serverCodec->toUnicode((const char *)name, strlen((const char *)name)); |
| 5123 | p += 10; |
| 5124 | //printf("Othername: %s\n", name); |
| 5125 | strncpy((char *)name, (char *)&(msg[58]), 10); |
| 5126 | //aGameListing->_white_name = serverCodec->toUnicode((const char *)name, strlen((const char *)name)); |
| 5127 | p += 10; |
| 5128 | //printf("Othername2: %s\n", name); |
| 5129 | QString country = getCountryFromCode(msg[68]); |
| 5130 | aGameListing->_black_name += ("[" + country[0] + "]"); |
| 5131 | country = getCountryFromCode(p[1]); |
| 5132 | aGameListing->_white_name += ("[" + country[0] + "]"); |
| 5133 | p += 2; |
| 5134 | if((msg[70] & 0xC0) == 0xC0) |
| 5135 | { |
| 5136 | aGameListing->_black_rank = QString::number(msg[70] & 0x0f) + "p"; |
| 5137 | aGameListing->_black_rank_score = 34000 + ((msg[70] & 0x0f) * 1000); |
| 5138 | } |
| 5139 | else if((msg[70] & 0xA0) == 0xA0) |
| 5140 | { |
| 5141 | aGameListing->_black_rank = QString::number(msg[70] & 0x0f) + "d"; |
| 5142 | aGameListing->_black_rank_score = 25000 + ((msg[70] & 0x0f) * 1000); |
| 5143 | } |
| 5144 | if((msg[71] & 0xC0) == 0xC0) |
| 5145 | { |
| 5146 | aGameListing->_white_rank = QString::number(msg[71] & 0x0f) + "p"; |
| 5147 | aGameListing->_white_rank_score = 34000 + ((msg[71] & 0x0f) * 1000); |
| 5148 | } |
| 5149 | else if((msg[71] & 0xA0) == 0xA0) |
| 5150 | { |
| 5151 | aGameListing->_white_rank = QString::number(msg[71] & 0x0f) + "d"; |
| 5152 | aGameListing->_white_rank_score = 25000 + ((msg[71] & 0x0f) * 1000); |
| 5153 | } |
| 5154 | #ifdef RE_DEBUG |
| 5155 | printf(" %02x%02x%02x%02x\n", msg[70], msg[71], msg[72], msg[73]); |
| 5156 | #endif //RE_DEBUG |
| 5157 | p += 2; |
| 5158 | #ifdef RE_DEBUG |
| 5159 | printf("Adding listing for %s vs %s\n", |
| 5160 | aGameListing->white_name().toLatin1().constData(), |
| 5161 | aGameListing->black_name().toLatin1().constData()); |
| 5162 | #endif //RE_DEBUG |
| 5163 | //aGameListing->game_code = aGameData->game_code; |
| 5164 | aGameListing->isRoomOnly = false; |
| 5165 | room->recvGameListing(aGameListing); |
| 5166 | } |
| 5167 | else |
| 5168 | p += 24; |
| 5169 | |
| 5170 | aGameListing = room->getGameListing(game_number); |
| 5171 | |
| 5172 | //recv game record? but what's to receive? |
| 5173 | aGameData->black_name = aGameListing->black_name(); |
| 5174 | aGameData->white_name = aGameListing->white_name(); |
| 5175 | aGameData->black_rank = aGameListing->black_rank(); |
| 5176 | aGameData->white_rank = aGameListing->white_rank(); |
| 5177 | |
| 5178 | if(joining) |
| 5179 | { |
| 5180 | boarddispatch->openBoard(); |
| 5181 | boarddispatch->recvTime(TimeRecord(white_seconds, white_periods), TimeRecord(black_seconds, black_periods)); |
| 5182 | |
| 5183 | /* We get this upon opening a betting match */ |
| 5184 | /* And observers: */ |
| 5185 | if(room_were_in == game_number) //no observing outside |
| 5186 | { |
| 5187 | #ifdef RE_DEBUG |
| 5188 | qDebug("adding observer list to betting match board..."); |
| 5189 | #endif //RE_DEBUG |
| 5190 | addObserverListToBoard(boarddispatch); |
| 5191 | } |
| 5192 | } |
| 5193 | else |
| 5194 | delete newGameData; |
| 5195 | } |
| 5196 | |
| 5197 | //ca5d chat rooms also |
| 5198 | //this could potentially also be a join room |
| 5199 | void CyberOroConnection::handleCreateRoom(unsigned char * msg, unsigned int size) |
| 5200 | { |
| 5201 | Room * room = getDefaultRoom(); |
| 5202 | unsigned char * p = msg; |
| 5203 | PlayerListing * aPlayer; |
| 5204 | unsigned short room_number; |
| 5205 | unsigned char room_type; |
| 5206 | if(size != 60) |
| 5207 | { |
| 5208 | qDebug("create room msg of strange size: %d", size); |
| 5209 | } |
| 5210 | aPlayer = room->getPlayerListing(msg[0] + (msg[1] << 8)); |
| 5211 | #ifdef RE_DEBUG |
| 5212 | if(aPlayer) |
| 5213 | qDebug("player %s %02x%02x chat room/match\n", aPlayer->name.toLatin1().constData(), msg[0], msg[1]); |
| 5214 | else |
| 5215 | qDebug("can't find player %02x%02x\n", msg[0], msg[1]); |
| 5216 | #endif //RE_DEBUG |
| 5217 | p += 2; |
| 5218 | room_number = msg[2] + (msg[3] << 8); |
| 5219 | GameListing * aGameListing = room->getGameListing(room_number); |
| 5220 | aGameListing->running = true; |
| 5221 | aGameListing->owner_id = aPlayer->id; |
| 5222 | |
| 5223 | #ifdef RE_DEBUG |
| 5224 | printf("room number on that chat: %d\n", room_number); |
| 5225 | #endif //RE_DEBUG |
| 5226 | p += 2; |
| 5227 | p += 3; |
| 5228 | //probably room info |
| 5229 | //0000 00 |
| 5230 | //4011 |
| 5231 | switch(msg[7]) |
| 5232 | { |
| 5233 | case 0xc0: |
| 5234 | break; |
| 5235 | case 0x40: |
| 5236 | break; |
| 5237 | case 0x09: |
| 5238 | break; |
| 5239 | case 0x00: |
| 5240 | aGameListing->_black_name = "** wished " + QString::number(msg[8], 16); |
| 5241 | break; |
| 5242 | } |
| 5243 | room_type = msg[7]; |
| 5244 | aGameListing->white = aPlayer; |
| 5245 | |
| 5246 | aGameListing->black = 0; |
| 5247 | aGameListing->_black_name = QString::number(room_type, 16); |
| 5248 | aGameListing->observers = 1; //the person who created it |
| 5249 | |
| 5250 | |
| 5251 | aGameListing->isRoomOnly = true; |
| 5252 | //p[1] here is time and strength wished as per create room code |
| 5253 | p += 2; |
| 5254 | p += 8; |
| 5255 | //a room byte info? |
| 5256 | p++; |
| 5257 | //title!! |
| 5258 | |
| 5259 | p += 20; |
| 5260 | // and lots of zeroes |
| 5261 | p += 22; |
| 5262 | //if(p != msg + size) |
| 5263 | //{ |
| 5264 | #ifdef RE_DEBUG |
| 5265 | //other than 60 ?? FIXME |
| 5266 | printf("ca5d: \n"); |
| 5267 | for(unsigned int i = 0; i < size; i++) |
| 5268 | printf("%02x", msg[i]); |
| 5269 | printf("\n"); |
| 5270 | #endif //RE_DEBUG |
| 5271 | //} |
| 5272 | //review game minminmin 7d |
| 5273 | //c901de00 0000 00c0 000000027d60005acdabbadc003b00003cb3a5017d60b65a68b3a501d98bcf7700e0fd7f68b3a5015a88cf770000000000000000 |
| 5274 | //chat room |
| 5275 | //89041401 0000 0040 11000000000000000000000000760000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5276 | //chat room |
| 5277 | //15008500 0000 0000 11000000000000000000000000b90000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5278 | //980d6600 0000 0000 11000000000000000000000000bc0000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5279 | //wished normal time even 1k |
| 5280 | //74099800 0000 0000 11000000000000000000000000e90000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5281 | //wished normal time strong |
| 5282 | //b8052301 0000 0000 01000000000000000000000000860000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5283 | //wished normal time even |
| 5284 | //8d00b100 00000000 11000000000000000000000000dd0000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5285 | //wished normal time even |
| 5286 | //29093201 00000000 110000000000000000000000008e0000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5287 | //74099800 00000000 11000000000000000000000000e90000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5288 | //quit playing |
| 5289 | //5d0da60000000000 110000000000000000000000005b0000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5290 | //locked gomoku? equal standard wished? |
| 5291 | //6d0b1201 0000 0009 11000000000000000000000000ed0000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 5292 | |
| 5293 | emit gameListingReceived(aGameListing); |
| 5294 | |
| 5295 | /* Set the attachment right after the game list is recvd */ |
| 5296 | if(aPlayer) |
| 5297 | setAttachedGame(aPlayer, aGameListing->number); |
| 5298 | } |
| 5299 | |
| 5300 | //56f4 |
| 5301 | void CyberOroConnection::handleBettingMatchResult(unsigned char * msg, unsigned int size) |
| 5302 | { |
| 5303 | unsigned short game_code = msg[0] + (msg[1] << 8); |
| 5304 | unsigned short game_id = game_code_to_number[game_code]; |
| 5305 | //FIXME |
| 5306 | if(size != 16) |
| 5307 | { |
| 5308 | qDebug("betting match result of strange size %d", size); |
| 5309 | } |
| 5310 | #ifdef RE_DEBUG |
| 5311 | printf("56f4: likely betting match result: %d\n", game_id); |
| 5312 | for(unsigned int i = 0; i < size; i++) |
| 5313 | printf("%02x", msg[i]); |
| 5314 | printf("\n"); |
| 5315 | #endif //RE_DEBUG |
| 5316 | |
| 5317 | |
| 5318 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_id); |
| 5319 | if(!boarddispatch) |
| 5320 | return; |
| 5321 | GameResult aGameResult; |
| 5322 | //3875020100000000000000000000001c B+R |
| 5323 | //35750101332e35000000000000000015 B+3.5 "3.5" //FIXME should convert and double check with what we get |
| 5324 | //37750202000000000000000000000015 W+R |
| 5325 | if(msg[2] == 0x01) |
| 5326 | { |
| 5327 | aGameResult.result = GameResult::SCORE; |
| 5328 | float margin; |
| 5329 | sscanf((char *)&(msg[4]), "%f", &margin); |
| 5330 | aGameResult.winner_score = margin; |
| 5331 | aGameResult.loser_score = 0.0; |
| 5332 | } |
| 5333 | else if(msg[2] == 0x02) |
| 5334 | { |
| 5335 | aGameResult.result = GameResult::RESIGN; |
| 5336 | } |
| 5337 | if(msg[3] == 0x01) |
| 5338 | { |
| 5339 | aGameResult.winner_color = stoneBlack; |
| 5340 | } |
| 5341 | else if(msg[3] == 0x02) |
| 5342 | { |
| 5343 | aGameResult.winner_color = stoneWhite; |
| 5344 | } |
| 5345 | //4d75 0202 302e 3500 0000 0000 0000 0015 |
| 5346 | boarddispatch->recvResult(&aGameResult); |
| 5347 | |
| 5348 | /* Rejoining a betting match that one had already joined after it was over, doesn't pop up the |
| 5349 | * result again that I can tell FIXME */ |
| 5350 | |
| 5351 | /* Sure they never hang around with the game over thing ? */ |
| 5352 | //aGameListing->running = false; |
| 5353 | //room->recvGameListing(aGameListing); |
| 5354 | //game_code_to_number.erase(game_id); |
| 5355 | } |
| 5356 | |
| 5357 | //5ac3 |
| 5358 | void CyberOroConnection::handleGamePhaseUpdate(unsigned char * msg, unsigned int size) |
| 5359 | { |
| 5360 | Room * room = getDefaultRoom(); |
| 5361 | unsigned char * p = msg; |
| 5362 | GameListing * aGameListing; |
| 5363 | |
| 5364 | if(size != 4) |
| 5365 | { |
| 5366 | qDebug("GamePhaseUpdate of strange size: %d", size); |
| 5367 | return; |
| 5368 | } |
| 5369 | #ifdef RE_DEBUG |
| 5370 | printf("5ac3: %d fl %02x ", p[0] + (p[1] << 8), p[2]); |
| 5371 | for(unsigned int i = 0; i < 4; i++) |
| 5372 | printf("%02x", p[i]); |
| 5373 | printf("\n"); |
| 5374 | #endif //RE_DEBUG |
| 5375 | // maybe first byte is game number?, and then update? |
| 5376 | /* I'm going to pretend these are game phase status messages */ |
| 5377 | aGameListing = room->getGameListing(p[0] + (p[1] << 8)); |
| 5378 | aGameListing->moves = getPhase(p[2]); |
| 5379 | emit gameListingReceived(aGameListing); |
| 5380 | } |
| 5381 | |
| 5382 | //50c3 |
| 5383 | #ifdef RE_DEBUG |
| 5384 | void CyberOroConnection::handleMsg3(unsigned char * msg, unsigned int size) |
| 5385 | #else |
| 5386 | void CyberOroConnection::handleMsg3(unsigned char * /*msg*/, unsigned int size) |
| 5387 | #endif //RE_DEBUG |
| 5388 | { |
| 5389 | //FIXME better name, what was this again? |
| 5390 | // maybe its the timer msg |
| 5391 | |
| 5392 | if(size != 6) |
| 5393 | { |
| 5394 | qDebug("50c3 of strange size: %d", size); |
| 5395 | } |
| 5396 | #ifdef RE_DEBUG |
| 5397 | unsigned char * p = msg; |
| 5398 | printf("**** 50c3: "); |
| 5399 | for(unsigned int i = 0; i < 4; i++) |
| 5400 | printf("%02x", p[i]); |
| 5401 | printf("\n"); |
| 5402 | #endif //RE_DEBUG |
| 5403 | } |
| 5404 | |
| 5405 | /* Maybe this is nigiri but it seems sent by other people's games |
| 5406 | * as well at strange times, I guess just setting colors */ |
| 5407 | //f5af |
| 5408 | void CyberOroConnection::handleNigiri(unsigned char * msg, unsigned int size) |
| 5409 | { |
| 5410 | unsigned char * p = msg; |
| 5411 | unsigned char thebyte; |
| 5412 | //unsigned short game_code = msg[0] + (msg[1] << 8); |
| 5413 | unsigned short room_number = msg[2] + (msg[3] << 8); |
| 5414 | QString name, rank, our_rank; |
| 5415 | GameData * gr; |
| 5416 | |
| 5417 | if(size != 8) |
| 5418 | { |
| 5419 | qDebug("Nigiri message of strange size: %d\n", size); |
| 5420 | } |
| 5421 | |
| 5422 | p += 4; |
| 5423 | thebyte = p[0]; |
| 5424 | /* Its also possible that we'd need to do this on games that |
| 5425 | * we joined. Its even possible that this is sent all |
| 5426 | * the time for games that just started */ |
| 5427 | if(match_negotiation_state->isOurGame(room_number)) |
| 5428 | { |
| 5429 | if(we_send_nigiri) //ignore |
| 5430 | return; |
| 5431 | //QMessageBox::information(0 , tr("receiving niri"), tr("receiving ") + QString::number(thebyte, 16) + tr(" nigiri ") + QString::number(p[3], 16)); |
| 5432 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_number); |
| 5433 | if(!boarddispatch) |
| 5434 | { |
| 5435 | qDebug("handlenigiri but no board dispatch"); |
| 5436 | return; |
| 5437 | } |
| 5438 | /* "our game being played" That's got to be the worst |
| 5439 | * variable name in the history of the universe. |
| 5440 | * even "our match in progress" would be slightly better. |
| 5441 | * Or "number of current game", "currently played game number"... */ |
| 5442 | |
| 5443 | /* We need to start the timers here I think */ |
| 5444 | gr = boarddispatch->getGameData(); |
| 5445 | |
| 5446 | /* FIXME its a BIG deal if you send a move before nigiri is |
| 5447 | * fully negotiated. The move is ignored, opponent can't play |
| 5448 | * and we can't send the move again because we're waiting for it. |
| 5449 | * we need to either not set the colors or the turn or block |
| 5450 | * the start of the game or something until nigiri is |
| 5451 | * fully negotiated. |
| 5452 | * double FIXME I don't think it has anything to do with this, |
| 5453 | * we're not doing the nigiri right */ |
| 5454 | |
| 5455 | /* There's some other kind of problem here related to the swap. |
| 5456 | * for instance even if they get black we don't display their move |
| 5457 | * for some reason. And then sometimes we send resigns |
| 5458 | * that look different. I think... maybe the listing is over |
| 5459 | * writing the colors later or something, I just added something |
| 5460 | * to maybe fix that. */ |
| 5461 | |
| 5462 | /* this stuff lets us play only if opponent is black and we're white |
| 5463 | * but then it gets the resign messages flipped. |
| 5464 | * if we're black, then the resign messages are okay but we can't play */ |
| 5465 | /* send nigiri fails if they play black in that we don't see their |
| 5466 | * black move and can't play ourself, names seem correct, |
| 5467 | * if we resign as that white, we get a message with (B) and opponent |
| 5468 | * thinks that white has one by resignation. */ |
| 5469 | /* This is so critical but I have no idea what's wrong with it. |
| 5470 | * that (B) has to be set that way, basically by handleResign |
| 5471 | * which means that the gr->white_name, etc., are wrong, I just |
| 5472 | * don't know why this wouldn't be reflected in the score board |
| 5473 | * I consider randomly that maybe I forgot and have two copies |
| 5474 | * of the gameData running around, still not sure on that but |
| 5475 | * it looks clean. |
| 5476 | * What's really weird is that the sendResign doesn't have a |
| 5477 | * color byte, and yet the official client interprets it nonsensically |
| 5478 | * which either means it does have a color byte or we're confusing |
| 5479 | * the official client, but this is even when we handle the |
| 5480 | * nigiri ! We have nothing we can do to screw it up... maybe |
| 5481 | * the accept Match offer... maybe... but that's hard to believe |
| 5482 | * I guess that's the only other option.*/ |
| 5483 | //if((thebyte % 2) == 0) |
| 5484 | /* I'm thinking that we always get the one meant |
| 5485 | * for us... that the server adds 1 or something |
| 5486 | * to tailor it for us */ |
| 5487 | //if(((((thebyte & 0xe0) >> 5) + 1) % 2) == ((thebyte & 0x1f) % 2)) |
| 5488 | //if((!(thebyte & 0x20)) == ((thebyte & 0x1f) % 2)) |
| 5489 | if(!(thebyte & 0x80)) |
| 5490 | { |
| 5491 | #ifdef RE_DEBUG |
| 5492 | qDebug("opponent nigiri successful"); |
| 5493 | #endif //RE_DEBUG |
| 5494 | boarddispatch->recvKibitz(QString(), "Opponent plays black"); |
| 5495 | if(gr->black_name == getUsername()) |
| 5496 | boarddispatch->swapColors(); |
| 5497 | else |
| 5498 | boarddispatch->swapColors(true); |
| 5499 | } |
| 5500 | else |
| 5501 | { |
| 5502 | #ifdef RE_DEBUG |
| 5503 | qDebug("opponent nigiri failure"); |
| 5504 | #endif //RE_DEBUG |
| 5505 | boarddispatch->recvKibitz(QString(), "Opponent plays white"); |
| 5506 | if(gr->white_name == getUsername()) |
| 5507 | boarddispatch->swapColors(); |
| 5508 | else |
| 5509 | boarddispatch->swapColors(true); |
| 5510 | } |
| 5511 | gr = boarddispatch->getGameData(); //get again |
| 5512 | /* FIXME Don't think we start until second move */ |
| 5513 | startMatchTimers(gr->black_name == getUsername()); |
| 5514 | } |
| 5515 | else |
| 5516 | { |
| 5517 | /* We get these a lot on other games and I think they |
| 5518 | * may be part of starting a match... like we should |
| 5519 | * check the owner and swap the colors if that's an issue |
| 5520 | * FIXME */ |
| 5521 | } |
| 5522 | #ifdef RE_DEBUG |
| 5523 | printf("0xf5af: "); |
| 5524 | for(unsigned int i = 0; i < size; i++) |
| 5525 | printf("%02x", msg[i]); |
| 5526 | printf("\n"); |
| 5527 | #endif //RE_DEBUG |
| 5528 | } |
| 5529 | |
| 5530 | /* This comes before we've gotten the ids */ |
| 5531 | void CyberOroConnection::handleFriends(unsigned char * msg, unsigned int size) |
| 5532 | { |
| 5533 | unsigned short friend_records; |
| 5534 | unsigned char * p = msg; |
| 5535 | unsigned char name[11]; |
| 5536 | unsigned int i; |
| 5537 | |
| 5538 | friend_records = p[0] + (p[1] << 8); |
| 5539 | p += 2; |
| 5540 | //check msg size???! FIXME |
| 5541 | qDebug("handleFriends %d %d", friend_records, size); //4 520 suggests (4 * 12) + 2 + 470 |
| 5542 | for(i = 0; i < friend_records; i++) |
| 5543 | { |
| 5544 | //name padded to 10, plus two bytes for flags |
| 5545 | strncpy((char *)name, (char *)p, 10); |
| 5546 | p += 10; |
| 5547 | #ifdef RE_DEBUG |
| 5548 | printf("friend or foe? %s, %02x%02x", name, p[0], p[1]); |
| 5549 | #endif //RE_DEBUG |
| 5550 | //first byte is 01, they're probably friend |
| 5551 | //first byte is 02, probably block |
| 5552 | if(p[0] == 0x01) |
| 5553 | friendedList.push_back(new FriendWatchListing(QString((const char *)name), friendwatch_notify_default)); |
| 5554 | else if(p[0] == 0x02) |
| 5555 | blockedList.push_back(new FriendWatchListing(QString((const char *)name), friendwatch_notify_default)); |
| 5556 | p += 2; |
| 5557 | } |
| 5558 | //the rest is a mystery for right now |
| 5559 | #ifdef RE_DEBUG |
| 5560 | printf("0x8129: "); |
| 5561 | for(i = 0; i < size; i++) |
| 5562 | printf("%02x", msg[i]); |
| 5563 | printf("\n"); |
| 5564 | #endif //RE_DEBUG |
| 5565 | } |
| 5566 | |
| 5567 | /* We think this is the last, always the last of the connection lists |
| 5568 | * so we might want to clear the playerlist_inorder vector here, |
| 5569 | * if that's okay? Otherwise on connect is fine too. */ |
| 5570 | void CyberOroConnection::handleMsg2(unsigned char * msg, unsigned int size) |
| 5571 | { |
| 5572 | unsigned char * p = msg; |
| 5573 | int records = p[0] + (p[1] << 8); |
| 5574 | p += 2; |
| 5575 | #ifdef RE_DEBUG |
| 5576 | printf("Its msg2: e461\n"); |
| 5577 | #endif //RE_DEBUG |
| 5578 | playerlist_inorder.clear(); //hopefully this is a good place |
| 5579 | //each record is 18 bytes; |
| 5580 | while(records--) |
| 5581 | { |
| 5582 | #ifdef RE_DEBUG |
| 5583 | for(unsigned int i = 0; i < 18; i++) |
| 5584 | printf("%02x", p[i]); |
| 5585 | printf("\n"); |
| 5586 | #endif //RE_DEBUG |
| 5587 | p += 18; |
| 5588 | } |
| 5589 | if(p != (msg + size)) |
| 5590 | printf("Weird msg length: %d at line %d\n", size, __LINE__); |
| 5591 | } |
| 5592 | |
| 5593 | //0x69c3: |
| 5594 | #ifdef RE_DEBUG |
| 5595 | void CyberOroConnection::handleRematchRequest(unsigned char * msg, unsigned int size) |
| 5596 | #else |
| 5597 | void CyberOroConnection::handleRematchRequest(unsigned char * /*msg*/, unsigned int size) |
| 5598 | #endif //RE_DEBUG |
| 5599 | { |
| 5600 | /* In ORO win client this actually looks just like a matchinvite */ |
| 5601 | if(size != 6) |
| 5602 | { |
| 5603 | qDebug("Rematch request of strange size: %d", size); |
| 5604 | return; |
| 5605 | } |
| 5606 | if(!room_were_in) |
| 5607 | { |
| 5608 | qDebug("Got rematch request, but not in a room"); |
| 5609 | return; |
| 5610 | } |
| 5611 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_were_in); |
| 5612 | if(!boarddispatch) |
| 5613 | { |
| 5614 | qDebug("Couldn't get board dispatch on room were in: %d", room_were_in); |
| 5615 | return; |
| 5616 | } |
| 5617 | boarddispatch->recvRematchRequest(); |
| 5618 | |
| 5619 | /* FIXME, we'll need to send the request and get the accept and |
| 5620 | * see what comes next... */ |
| 5621 | //their id, our id, two more bytes |
| 5622 | #ifdef RE_DEBUG |
| 5623 | printf("rematch request: 69c3: "); |
| 5624 | for(unsigned int i = 0; i < size; i++) |
| 5625 | printf("%02x", msg[i]); |
| 5626 | printf("\n"); |
| 5627 | #endif //RE_DEBUG |
| 5628 | } |
| 5629 | |
| 5630 | //0x6ec3: |
| 5631 | #ifdef RE_DEBUG |
| 5632 | void CyberOroConnection::handleRematchAccept(unsigned char * msg, unsigned int size) |
| 5633 | #else |
| 5634 | void CyberOroConnection::handleRematchAccept(unsigned char * /*msg*/, unsigned int size) |
| 5635 | #endif //RE_DEBUG |
| 5636 | { |
| 5637 | bool were_black; |
| 5638 | if(size != 6) |
| 5639 | { |
| 5640 | qDebug("rematch accept packet with strange size: %d", size); |
| 5641 | return; |
| 5642 | } |
| 5643 | /* FIXME, we'll need to send the request and get the accept and |
| 5644 | * see what comes next... */ |
| 5645 | //their id, our id, two more bytes |
| 5646 | #ifdef RE_DEBUG |
| 5647 | printf("rematch request accept: 6ec3: "); |
| 5648 | for(int i = 0; i < (int)size; i++) |
| 5649 | printf("%02x", msg[i]); |
| 5650 | printf("\n"); |
| 5651 | #endif //RE_DEBUG |
| 5652 | //610a a804 128f |
| 5653 | //we need to check our_player_id against first two bytes |
| 5654 | if(!room_were_in) |
| 5655 | { |
| 5656 | qDebug("Not in a room for rematch accept"); |
| 5657 | return; |
| 5658 | } |
| 5659 | BoardDispatch * boarddispatch = getIfBoardDispatch(room_were_in); |
| 5660 | if(!boarddispatch) |
| 5661 | { |
| 5662 | qDebug("handle rematch accept has no board dispatch"); |
| 5663 | return; |
| 5664 | } |
| 5665 | if(!match_negotiation_state->sentRematch()) |
| 5666 | return; |
| 5667 | |
| 5668 | MatchRequest * m = new MatchRequest(); |
| 5669 | GameData * gd = boarddispatch->getGameData(); |
| 5670 | m->number = room_were_in; |
| 5671 | m->last_game_code = gd->game_code; |
| 5672 | m->rematch = true; |
| 5673 | m->board_size = gd->board_size; |
| 5674 | m->komi = gd->komi; |
| 5675 | m->handicap = gd->handicap; |
| 5676 | m->free_rated = gd->free_rated; |
| 5677 | if(m->handicap == 0 && gd->komi > 0.0) |
| 5678 | { |
| 5679 | //switch colors? |
| 5680 | //yes switch colors, we send the match offer.. |
| 5681 | if(gd->black_name == getUsername()) |
| 5682 | were_black = false; |
| 5683 | else |
| 5684 | were_black = true; |
| 5685 | } |
| 5686 | else |
| 5687 | were_black = (gd->black_name == getUsername()); |
| 5688 | m->opponent_id = gd->opponent_id; |
| 5689 | m->opponent_is_challenger = false; |
| 5690 | if(were_black) |
| 5691 | { |
| 5692 | m->opponent = gd->white_name; |
| 5693 | m->their_rank = gd->white_rank; |
| 5694 | m->our_name = gd->black_name; |
| 5695 | m->our_rank = gd->black_rank; |
| 5696 | m->color_request = MatchRequest::BLACK; |
| 5697 | m->challenger_is_black = false; //? |
| 5698 | } |
| 5699 | else |
| 5700 | { |
| 5701 | m->opponent = gd->black_name; |
| 5702 | m->their_rank = gd->black_rank; |
| 5703 | m->our_name = gd->white_name; |
| 5704 | m->our_rank = gd->white_rank; |
| 5705 | m->color_request = MatchRequest::WHITE; |
| 5706 | m->challenger_is_black = false; |
| 5707 | } |
| 5708 | m->timeSystem = gd->timeSystem; |
| 5709 | m->maintime = gd->maintime; |
| 5710 | m->periodtime = gd->periodtime; |
| 5711 | m->stones_periods = gd->stones_periods; |
| 5712 | |
| 5713 | //d2af does this: |
| 5714 | //NetworkConnection::closeBoardDispatch(room_were_in); //doesn't close window necessarily |
| 5715 | |
| 5716 | |
| 5717 | sendMatchOffer(*m, false); //not counter offer |
| 5718 | match_negotiation_state->offerMatchTerms(m); //is this the right state? FIXME |
| 5719 | delete m; |
| 5720 | |
| 5721 | //BoardDispatch * boarddispatch = getBoardDispatch(room_were_in); //should open new game |
| 5722 | //this needs also to send something else to trigger whatever |
| 5723 | } |
| 5724 | |
| 5725 | /* This is also used during game negotiation, not just rematches */ |
| 5726 | //0x327d |
| 5727 | void CyberOroConnection::handleMatchDecline(unsigned char * msg, unsigned int size) |
| 5728 | { |
| 5729 | PlayerListing * player; |
| 5730 | unsigned char * p = msg; |
| 5731 | |
| 5732 | if(size != 6) |
| 5733 | { |
| 5734 | qDebug("match decline message of strange size %d", size); |
| 5735 | } |
| 5736 | |
| 5737 | if(p[0] + (p[1] << 8) != our_player_id) |
| 5738 | { |
| 5739 | //qDebug("*** Woah, 327d rematch decline not meant for us!"); //this happens FIXME |
| 5740 | return; |
| 5741 | } |
| 5742 | p += 2; |
| 5743 | player = getDefaultRoom()->getPlayerListing(p[0] + (p[1] << 8)); |
| 5744 | p += 2; |
| 5745 | // those last two bytes? |
| 5746 | #ifdef RE_DEBUG |
| 5747 | printf("0x327d: unexplained bytes: %02x %02x\n", p[0], p[1]); |
| 5748 | #endif //RE_DEBUG |
| 5749 | if(!match_negotiation_state->sentMatchOffer() && !match_negotiation_state->sentRematch()) |
| 5750 | { |
| 5751 | match_negotiation_state->reset(); |
| 5752 | return; |
| 5753 | } |
| 5754 | if(!match_negotiation_state->verifyPlayer(player)) |
| 5755 | { |
| 5756 | qDebug("Bad player from rematch decline"); |
| 5757 | match_negotiation_state->reset(); |
| 5758 | return; |
| 5759 | } |
| 5760 | GameDialog * gameDialogDispatch = getIfGameDialog(player); |
| 5761 | if(gameDialogDispatch) |
| 5762 | { |
| 5763 | gameDialogDispatch->recvRefuseMatch(GD_REFUSE_DECLINE); |
| 5764 | } |
| 5765 | else |
| 5766 | { |
| 5767 | QMessageBox::information(0, tr("Rematch declined"), tr("%1 has declined rematch").arg(player->name)); |
| 5768 | } |
| 5769 | match_negotiation_state->reset(); |
| 5770 | #ifdef RE_DEBUG |
| 5771 | printf("0x327d: "); |
| 5772 | for(int i = 0; i < (int)size; i++) |
| 5773 | printf("%02x", msg[i]); |
| 5774 | printf("\n"); |
| 5775 | #endif //RE_DEBUG |
| 5776 | } |
| 5777 | |
| 5778 | //b0b3 |
| 5779 | void CyberOroConnection::handleResign(unsigned char * msg, unsigned int size) |
| 5780 | { |
| 5781 | Room * room = getDefaultRoom(); |
| 5782 | BoardDispatch * boarddispatch; |
| 5783 | GameData * gr; |
| 5784 | unsigned char * p = msg; |
| 5785 | PlayerListing * player; |
| 5786 | if(size != 8) |
| 5787 | { |
| 5788 | qDebug("Resign message of strange size: %d", size); |
| 5789 | return; |
| 5790 | } |
| 5791 | player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 5792 | p += 2; |
| 5793 | unsigned short game_code = msg[2] + (msg[3] << 8); |
| 5794 | unsigned short game_number = game_code_to_number[game_code]; |
| 5795 | boarddispatch = getIfBoardDispatch(game_number); |
| 5796 | if(boarddispatch) |
| 5797 | { |
| 5798 | GameResult aGameResult; |
| 5799 | gr = boarddispatch->getGameData(); |
| 5800 | if(!gr) |
| 5801 | { |
| 5802 | printf("Can't get game record for resign msg\n"); |
| 5803 | return; |
| 5804 | } |
| 5805 | aGameResult.result = GameResult::RESIGN; |
| 5806 | if(gr->black_name == player->name) |
| 5807 | { |
| 5808 | aGameResult.winner_color = stoneWhite; |
| 5809 | aGameResult.winner_name = gr->white_name; |
| 5810 | aGameResult.loser_name = gr->black_name; //necessary FIXME??? |
| 5811 | } |
| 5812 | else |
| 5813 | { |
| 5814 | aGameResult.winner_color = stoneBlack; |
| 5815 | aGameResult.winner_name = gr->black_name; |
| 5816 | aGameResult.loser_name = gr->white_name; |
| 5817 | } |
| 5818 | boarddispatch->recvResult(&aGameResult); |
| 5819 | if(match_negotiation_state->isOurGame(game_number)) |
| 5820 | { |
| 5821 | killActiveMatchTimers(); |
| 5822 | match_negotiation_state->reset(); |
| 5823 | //FIXME what about rematch? what about other resets?!?!?FIXME |
| 5824 | } |
| 5825 | } |
| 5826 | } |
| 5827 | |
| 5828 | //I think this double as an accept count request |
| 5829 | //c9b30c00 c801 ea0c 000000f1 |
| 5830 | void CyberOroConnection::handleEnterScoring(unsigned char * msg, unsigned int size) |
| 5831 | { |
| 5832 | Room * room = getDefaultRoom(); |
| 5833 | BoardDispatch * boarddispatch; |
| 5834 | PlayerListing * player; |
| 5835 | player = room->getPlayerListing(msg[0] + (msg[1] << 8)); |
| 5836 | |
| 5837 | if(size != 8) |
| 5838 | { |
| 5839 | qDebug("Enter scoring message of strange size: %d", size); |
| 5840 | } |
| 5841 | unsigned short game_code = msg[2] + (msg[3] << 8); |
| 5842 | unsigned short game_number = game_code_to_number[game_code]; |
| 5843 | boarddispatch = getIfBoardDispatch(game_number); |
| 5844 | if(boarddispatch) |
| 5845 | { |
| 5846 | #ifdef RE_DEBUG |
| 5847 | qDebug("Entering scoring mode"); |
| 5848 | #endif //RE_DEBUG |
| 5849 | boarddispatch->recvEnterScoreMode(); |
| 5850 | if(match_negotiation_state->isOurGame(game_number)) |
| 5851 | { |
| 5852 | match_negotiation_state->enterScoreMode(); |
| 5853 | deadStonesList.clear(); |
| 5854 | killActiveMatchTimers(); |
| 5855 | } |
| 5856 | } |
| 5857 | } |
| 5858 | |
| 5859 | //FIXME pretty sure this happens too often, like twice in |
| 5860 | //a game or something |
| 5861 | void CyberOroConnection::killActiveMatchTimers(void) |
| 5862 | { |
| 5863 | #ifdef RE_DEBUG |
| 5864 | qDebug("killing timers"); |
| 5865 | #endif //RE_DEBUG |
| 5866 | if(matchRequestKeepAliveTimerID) |
| 5867 | { |
| 5868 | killTimer(matchRequestKeepAliveTimerID); |
| 5869 | matchRequestKeepAliveTimerID = 0; |
| 5870 | } |
| 5871 | if(matchKeepAliveTimerID) |
| 5872 | { |
| 5873 | killTimer(matchKeepAliveTimerID); |
| 5874 | matchKeepAliveTimerID = 0; |
| 5875 | } |
| 5876 | } |
| 5877 | |
| 5878 | void CyberOroConnection::startMatchTimers(bool ourTurn) |
| 5879 | { |
| 5880 | if(ourTurn) |
| 5881 | { |
| 5882 | #ifdef RE_DEBUG |
| 5883 | qDebug("Starting keep alive timer"); |
| 5884 | #endif //RE_DEBUG |
| 5885 | matchKeepAliveTimerID = startTimer(39000); |
| 5886 | matchRequestKeepAliveTimerID = 0; |
| 5887 | } |
| 5888 | else |
| 5889 | { |
| 5890 | #ifdef RE_DEBUG |
| 5891 | qDebug("Starting request keep alive timer"); |
| 5892 | #endif //RE_DEBUG |
| 5893 | matchRequestKeepAliveTimerID = startTimer(39000); |
| 5894 | matchKeepAliveTimerID = 0; |
| 5895 | } |
| 5896 | } |
| 5897 | |
| 5898 | /* Final f1b31400 b006 640b 2f05 5c22 0102 1106 0804 1106 |
| 5899 | * is basically the same thing... plus a couple more bytes... |
| 5900 | * makes me think we should write only one handler or something. |
| 5901 | * or maybe e7b31400 2f05 640b 2f05 5c6d 0102 1106 0804 1106 |
| 5902 | * is really the final ?!?!? FIXME */ |
| 5903 | //e2b31200 2f05 640b 2f05 2863 0201 1106 0804 |
| 5904 | |
| 5905 | void CyberOroConnection::handleRemoveStones(unsigned char * msg, unsigned int size) |
| 5906 | { |
| 5907 | Room * room = getDefaultRoom(); |
| 5908 | BoardDispatch * boarddispatch; |
| 5909 | unsigned char * p = msg; |
| 5910 | bool unremove; |
| 5911 | int number_of_marks; |
| 5912 | PlayerListing * player; |
| 5913 | player = room->getPlayerListing(msg[0] + (msg[1] << 8)); |
| 5914 | p += 2; |
| 5915 | unsigned short game_code = msg[2] + (msg[3] << 8); |
| 5916 | unsigned short game_number = game_code_to_number[game_code]; |
| 5917 | boarddispatch = getIfBoardDispatch(game_number); |
| 5918 | if(!boarddispatch) |
| 5919 | { |
| 5920 | printf("Can't get board dispatch for remove stones for %02x%02x\n", p[0], p[1]); |
| 5921 | return; |
| 5922 | } |
| 5923 | p += 2; |
| 5924 | //another player id |
| 5925 | p += 2; |
| 5926 | #ifdef RE_DEBUG |
| 5927 | printf("e2b3: "); |
| 5928 | for(unsigned int i = 0; i < size - 6; i++) |
| 5929 | printf("%02x", p[i]); |
| 5930 | printf("\n"); |
| 5931 | #endif //RE_DEBUG |
| 5932 | //weird two bytes |
| 5933 | p += 2; |
| 5934 | // a 01 or 02 |
| 5935 | unremove = (msg[8] == 2); |
| 5936 | p++; |
| 5937 | number_of_marks = msg[9]; |
| 5938 | p++; |
| 5939 | MoveRecord aMove; |
| 5940 | aMove.x = msg[10]; |
| 5941 | aMove.y = msg[11]; |
| 5942 | /* First one is the new one, the rest is the full list */ |
| 5943 | /* Also, I think if its an unremove, its removed from the list, |
| 5944 | * both in this packet and ensuing ones */ |
| 5945 | //129d 0102 0f09 1310 0f09 |
| 5946 | |
| 5947 | /* Instead might be an acknowledge of previous sends. */ |
| 5948 | //aMove.x = msg[size - 2]; //definitely not right |
| 5949 | //aMove.y = msg[size - 1]; |
| 5950 | if(unremove) |
| 5951 | { |
| 5952 | aMove.flags = MoveRecord::UNREMOVE_AREA; |
| 5953 | if(match_negotiation_state->isOurGame(game_number)) |
| 5954 | { |
| 5955 | if(!match_negotiation_state->counting()) |
| 5956 | return; |
| 5957 | std::vector <MoveRecord>::iterator it; |
| 5958 | for(it = deadStonesList.begin(); it != deadStonesList.end(); it++) |
| 5959 | { |
| 5960 | if(it->x == aMove.x && |
| 5961 | it->y == aMove.y) |
| 5962 | { |
| 5963 | qDebug("removing %d %d from dead stones list", aMove.x, aMove.y); |
| 5964 | deadStonesList.erase(it); |
| 5965 | break; |
| 5966 | } |
| 5967 | } |
| 5968 | } |
| 5969 | } |
| 5970 | else |
| 5971 | { |
| 5972 | aMove.flags = MoveRecord::REMOVE_AREA; |
| 5973 | if(match_negotiation_state->isOurGame(game_number)) |
| 5974 | { |
| 5975 | if(!match_negotiation_state->counting()) |
| 5976 | return; |
| 5977 | qDebug("pushing %d %d onto dead stones list\n", aMove.x, aMove.y); |
| 5978 | deadStonesList.push_back(aMove); |
| 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | boarddispatch->recvMove(&aMove); |
| 5983 | /* What about mark undos??? FIXME */ |
| 5984 | p += 2; //skip the rest |
| 5985 | /* |
| 5986 | while(number_of_marks--) |
| 5987 | { |
| 5988 | MoveRecord aMove; |
| 5989 | aMove.flags = MoveRecord::REMOVE; |
| 5990 | aMove.x = p[0]; |
| 5991 | aMove.y = p[1]; |
| 5992 | p += 2; |
| 5993 | boarddispatch->recvMove(&aMove); |
| 5994 | } |
| 5995 | */ |
| 5996 | } |
| 5997 | |
| 5998 | //f1b3 |
| 5999 | /* This is definitely like an opponent has hit done kind of |
| 6000 | * msg, not that that means anything to us until we hit done */ |
| 6001 | #ifdef RE_DEBUG |
| 6002 | void CyberOroConnection::handleStonesDone(unsigned char * msg, unsigned int size) |
| 6003 | #else |
| 6004 | void CyberOroConnection::handleStonesDone(unsigned char * msg, unsigned int /*size*/) |
| 6005 | #endif //RE_DEBUG |
| 6006 | { |
| 6007 | Room * room = getDefaultRoom(); |
| 6008 | BoardDispatch * boarddispatch; |
| 6009 | unsigned char * p = msg; |
| 6010 | int number_of_marks; |
| 6011 | PlayerListing * player; |
| 6012 | player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 6013 | p += 2; |
| 6014 | unsigned short game_code = p[0] + (p[1] << 8); |
| 6015 | unsigned short game_number = game_code_to_number[game_code]; |
| 6016 | boarddispatch = getIfBoardDispatch(game_number); |
| 6017 | if(!boarddispatch) |
| 6018 | { |
| 6019 | printf("Can't get board dispatch for remove stones for %02x%02x\n", p[0], p[1]); |
| 6020 | return; |
| 6021 | } |
| 6022 | p += 2; |
| 6023 | //another player id |
| 6024 | p += 2; |
| 6025 | #ifdef RE_DEBUG |
| 6026 | printf("0xf1b3: "); |
| 6027 | for(unsigned int i = 0; i < size; i++) |
| 6028 | printf("%02x", msg[i]); |
| 6029 | printf("\n"); |
| 6030 | #endif //RE_DEBUG |
| 6031 | //weird two bytes |
| 6032 | if(match_negotiation_state->isOurGame(game_number)) |
| 6033 | { |
| 6034 | unsigned short done_response = p[0] + (p[1] << 8); |
| 6035 | |
| 6036 | if(match_negotiation_state->sentDoneCounting()) |
| 6037 | { |
| 6038 | if(!match_negotiation_state->verifyCountDoneMessage(done_response)) |
| 6039 | { |
| 6040 | qDebug("Count done fail!!\n"); |
| 6041 | //FIXME |
| 6042 | } |
| 6043 | match_negotiation_state->setDoneCounting(); |
| 6044 | } |
| 6045 | else |
| 6046 | { |
| 6047 | match_negotiation_state->setCountingVerification(done_response); |
| 6048 | match_negotiation_state->receiveDoneCounting(); |
| 6049 | } |
| 6050 | } |
| 6051 | p += 2; |
| 6052 | // a 01 or 02 |
| 6053 | p++; |
| 6054 | number_of_marks = p[0]; |
| 6055 | p++; |
| 6056 | /* First one is the new one, the rest is the full list */ |
| 6057 | MoveRecord aMove; |
| 6058 | aMove.flags = MoveRecord::REMOVE; |
| 6059 | aMove.x = p[0]; |
| 6060 | aMove.y = p[1]; |
| 6061 | boarddispatch->recvKibitz(QString(), QString("%1 has hit done...").arg(player->name)); |
| 6062 | //boarddispatch->recvMove(&aMove); |
| 6063 | /* What about mark undos??? FIXME */ |
| 6064 | p += 2; //skip the rest |
| 6065 | |
| 6066 | /* FIXME, we might actually want to just clear and readd all the stones |
| 6067 | * listed. I mean otherwise we're sort of negating the point of |
| 6068 | * the done message */ |
| 6069 | /* |
| 6070 | while(number_of_marks--) |
| 6071 | { |
| 6072 | MoveRecord aMove; |
| 6073 | aMove.flags = MoveRecord::REMOVE; |
| 6074 | aMove.x = p[0]; |
| 6075 | aMove.y = p[1]; |
| 6076 | p += 2; |
| 6077 | boarddispatch->recvMove(&aMove); |
| 6078 | } |
| 6079 | */ |
| 6080 | } |
| 6081 | |
| 6082 | //e7b3 |
| 6083 | #ifdef RE_DEBUG |
| 6084 | void CyberOroConnection::handleScore(unsigned char * msg, unsigned int size) |
| 6085 | #else |
| 6086 | void CyberOroConnection::handleScore(unsigned char * msg, unsigned int /*size*/) |
| 6087 | #endif //RE_DEBUG |
| 6088 | { |
| 6089 | Room * room = getDefaultRoom(); |
| 6090 | BoardDispatch * boarddispatch; |
| 6091 | unsigned char * p = msg; |
| 6092 | unsigned short game_id, game_code; |
| 6093 | int number_of_marks; |
| 6094 | PlayerListing * player; |
| 6095 | player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 6096 | p += 2; |
| 6097 | game_code = p[0] + (p[1] << 8); |
| 6098 | game_id = game_code_to_number[game_code]; |
| 6099 | boarddispatch = getIfBoardDispatch(game_id); |
| 6100 | if(!boarddispatch) |
| 6101 | { |
| 6102 | printf("Can't get board dispatch for remove stones for %02x%02x\n", p[0], p[1]); |
| 6103 | return; |
| 6104 | } |
| 6105 | p += 2; |
| 6106 | //another player id |
| 6107 | p += 2; |
| 6108 | #ifdef RE_DEBUG |
| 6109 | printf("e7b3: "); |
| 6110 | for(unsigned int i = 0; i < size - 6; i++) |
| 6111 | printf("%02x", msg[i]); |
| 6112 | printf("\n"); |
| 6113 | #endif //RE_DEBUG |
| 6114 | //weird two bytes |
| 6115 | p += 2; |
| 6116 | // a 01 or 02 |
| 6117 | p++; |
| 6118 | number_of_marks = p[0]; |
| 6119 | p++; |
| 6120 | |
| 6121 | if(match_negotiation_state->isOurGame(game_id)) |
| 6122 | { |
| 6123 | if(!match_negotiation_state->doneCounting()) |
| 6124 | { |
| 6125 | printf("Not done counting and e7b3\n"); |
| 6126 | return; |
| 6127 | } |
| 6128 | } |
| 6129 | |
| 6130 | /* First one is the new one, the rest is the full list */ |
| 6131 | MoveRecord aMove; |
| 6132 | aMove.flags = MoveRecord::REMOVE; |
| 6133 | aMove.x = p[0]; |
| 6134 | aMove.y = p[1]; |
| 6135 | //boarddispatch->recvMove(&aMove); |
| 6136 | /* What about mark undos??? FIXME */ |
| 6137 | p += 2; //skip the rest |
| 6138 | /* |
| 6139 | while(number_of_marks--) |
| 6140 | { |
| 6141 | MoveRecord aMove; |
| 6142 | aMove.flags = MoveRecord::REMOVE; |
| 6143 | aMove.x = p[0]; |
| 6144 | aMove.y = p[1]; |
| 6145 | p += 2; |
| 6146 | boarddispatch->recvMove(&aMove); |
| 6147 | } |
| 6148 | */ |
| 6149 | boarddispatch->recvResult(0); |
| 6150 | #ifdef OLD |
| 6151 | //double check, this appropriate here? FIXME, we need a func for it |
| 6152 | GameListing * aGameListing = room->getGameListing(game_id); |
| 6153 | if(aGameListing) |
| 6154 | { |
| 6155 | //FIXME I doubt it |
| 6156 | //aGameListing->running = false; |
| 6157 | //room->recvGameListing(aGameListing); |
| 6158 | our_game_being_played = 0; |
| 6159 | |
| 6160 | } |
| 6161 | #endif //OLD |
| 6162 | } |
| 6163 | |
| 6164 | //c4b3 |
| 6165 | void CyberOroConnection::handleRequestCount(unsigned char * msg, unsigned int size) |
| 6166 | { |
| 6167 | Room * room = getDefaultRoom(); |
| 6168 | BoardDispatch * boarddispatch; |
| 6169 | unsigned char * p = msg; |
| 6170 | PlayerListing * player; |
| 6171 | unsigned short game_code, game_number; |
| 6172 | |
| 6173 | if(size != 8) |
| 6174 | { |
| 6175 | qDebug("Request count msg of strange size: %d", size); //should be 12 - 4 |
| 6176 | } |
| 6177 | |
| 6178 | player = room->getPlayerListing(msg[0] + (msg[1] << 8)); |
| 6179 | p += 2; |
| 6180 | game_code = msg[2] + (msg[3] << 8); |
| 6181 | game_number = game_code_to_number[game_code]; |
| 6182 | |
| 6183 | boarddispatch = getIfBoardDispatch(game_number); |
| 6184 | if(!boarddispatch) |
| 6185 | { |
| 6186 | qDebug("Request count: No board dispatch for %02x%02x %d", msg[2], msg[3], game_number); |
| 6187 | return; |
| 6188 | } |
| 6189 | p += 2; |
| 6190 | |
| 6191 | killActiveMatchTimers(); |
| 6192 | boarddispatch->recvRequestCount(); |
| 6193 | |
| 6194 | #ifdef RE_DEBUG |
| 6195 | printf("0x request count?: c4b3: "); |
| 6196 | for(int i = 0; i < (int)size; i++) |
| 6197 | printf("%02x", msg[i]); |
| 6198 | printf("\n"); |
| 6199 | #endif //RE_DEBUG |
| 6200 | } |
| 6201 | |
| 6202 | //ceb3 |
| 6203 | void CyberOroConnection::handleRejectCountRequest(unsigned char * msg, unsigned int size) |
| 6204 | { |
| 6205 | Room * room = getDefaultRoom(); |
| 6206 | BoardDispatch * boarddispatch; |
| 6207 | unsigned char * p = msg; |
| 6208 | PlayerListing * player; |
| 6209 | unsigned short game_code, game_number; |
| 6210 | |
| 6211 | if(size != 8) |
| 6212 | { |
| 6213 | qDebug("Request count msg of strange size: %d", size); //should be 12 - 4 |
| 6214 | } |
| 6215 | |
| 6216 | player = room->getPlayerListing(msg[0] + (msg[1] << 8)); |
| 6217 | p += 2; |
| 6218 | game_code = msg[2] + (p[3] << 8); |
| 6219 | game_number = game_code_to_number[game_code]; |
| 6220 | |
| 6221 | boarddispatch = getIfBoardDispatch(game_number); |
| 6222 | if(!boarddispatch) |
| 6223 | { |
| 6224 | qDebug("No board dispatch for %02x%02x", msg[2], msg[3]); |
| 6225 | return; |
| 6226 | } |
| 6227 | p += 2; |
| 6228 | |
| 6229 | boarddispatch->recvRejectCountRequest(); |
| 6230 | |
| 6231 | #ifdef RE_DEBUG |
| 6232 | printf("0x reject request count?: ceb3: "); |
| 6233 | for(int i = 0; i < (int)size; i++) |
| 6234 | printf("%02x", msg[i]); |
| 6235 | printf("\n"); |
| 6236 | #endif //RE_DEBUG |
| 6237 | GameData * gr = boarddispatch->getGameData(); |
| 6238 | startMatchTimers(boarddispatch->getBlackTurn() ? (gr->black_name == getUsername()) : (gr->white_name == getUsername())); |
| 6239 | } |
| 6240 | |
| 6241 | //05b4 |
| 6242 | void CyberOroConnection::handleRequestMatchMode(unsigned char * msg, unsigned int size) |
| 6243 | { |
| 6244 | Room * room = getDefaultRoom(); |
| 6245 | BoardDispatch * boarddispatch; |
| 6246 | PlayerListing * player; |
| 6247 | unsigned short game_code, game_number; |
| 6248 | if(size != 8) |
| 6249 | { |
| 6250 | qDebug("Request match mode msg of strange size: %d", size); |
| 6251 | } |
| 6252 | |
| 6253 | //4503 d802 0000 007c |
| 6254 | player = room->getPlayerListing(msg[0] + (msg[1] << 8)); |
| 6255 | game_code = msg[2] + (msg[3] << 8); |
| 6256 | game_number = game_code_to_number[game_code]; |
| 6257 | |
| 6258 | boarddispatch = getIfBoardDispatch(game_number); |
| 6259 | if(!boarddispatch) |
| 6260 | { |
| 6261 | qDebug("No board dispatch for %02x%02x", msg[2], msg[3]); |
| 6262 | return; |
| 6263 | } |
| 6264 | |
| 6265 | killActiveMatchTimers(); //okay? what about cheating issues?? FIXME |
| 6266 | boarddispatch->recvRequestMatchMode(); |
| 6267 | |
| 6268 | #ifdef RE_DEBUG |
| 6269 | printf("0x request match mode?: 05b4: "); |
| 6270 | for(int i = 0; i < (int)size; i++) |
| 6271 | printf("%02x", msg[i]); |
| 6272 | printf("\n"); |
| 6273 | #endif //RE_DEBUG |
| 6274 | } |
| 6275 | |
| 6276 | //0ab4 |
| 6277 | void CyberOroConnection::handleRejectMatchModeRequest(unsigned char * msg, unsigned int size) |
| 6278 | { |
| 6279 | Room * room = getDefaultRoom(); |
| 6280 | BoardDispatch * boarddispatch; |
| 6281 | unsigned char * p = msg; |
| 6282 | PlayerListing * player; |
| 6283 | unsigned short game_code, game_number; |
| 6284 | if(size != 8) |
| 6285 | { |
| 6286 | qDebug("Request match mode msg of strange size: %d", size); |
| 6287 | } |
| 6288 | |
| 6289 | //4503 d802 0000 007c |
| 6290 | player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 6291 | p += 2; |
| 6292 | game_code = msg[2] + (msg[3] << 8); |
| 6293 | game_number = game_code_to_number[game_code]; |
| 6294 | |
| 6295 | boarddispatch = getIfBoardDispatch(game_number); |
| 6296 | if(!boarddispatch) |
| 6297 | { |
| 6298 | qDebug("No board dispatch for %02x%02x", msg[2], msg[3]); |
| 6299 | return; |
| 6300 | } |
| 6301 | p += 2; |
| 6302 | |
| 6303 | boarddispatch->recvRejectMatchModeRequest(); |
| 6304 | |
| 6305 | #ifdef RE_DEBUG |
| 6306 | printf("0x decline request match mode?: 0ab4: "); |
| 6307 | for(int i = 0; i < (int)size; i++) |
| 6308 | printf("%02x", msg[i]); |
| 6309 | printf("\n"); |
| 6310 | #endif //RE_DEBUG |
| 6311 | } |
| 6312 | |
| 6313 | //f6b3 |
| 6314 | void CyberOroConnection::handleTimeLoss(unsigned char * msg, unsigned int size) |
| 6315 | { |
| 6316 | Room * room = getDefaultRoom(); |
| 6317 | BoardDispatch * boarddispatch; |
| 6318 | unsigned char * p = msg; |
| 6319 | PlayerListing * player; |
| 6320 | unsigned short game_code, game_number; |
| 6321 | |
| 6322 | qDebug("handleTimeLoss size %d", size); |
| 6323 | |
| 6324 | player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 6325 | p += 2; |
| 6326 | game_code = p[0] + (p[1] << 8); |
| 6327 | game_number = game_code_to_number[game_code]; |
| 6328 | |
| 6329 | boarddispatch = getIfBoardDispatch(game_number); |
| 6330 | if(!boarddispatch) |
| 6331 | { |
| 6332 | qDebug("No board dispatch for %02x%02x", p[0], p[1]); |
| 6333 | return; |
| 6334 | } |
| 6335 | p += 2; |
| 6336 | GameData * aGameData = boarddispatch->getGameData(); |
| 6337 | |
| 6338 | GameResult aGameResult; |
| 6339 | aGameResult.result = GameResult::TIME; |
| 6340 | aGameResult.game_number = game_number; |
| 6341 | aGameResult.loser_name = player->name; |
| 6342 | if(aGameData->white_name == player->name) |
| 6343 | { |
| 6344 | //winner and loser colors??!?!? FIXME FIXME |
| 6345 | aGameResult.winner_name = aGameData->black_name; |
| 6346 | aGameResult.winner_color = stoneBlack; |
| 6347 | } |
| 6348 | else |
| 6349 | { |
| 6350 | aGameResult.winner_name = aGameData->white_name; |
| 6351 | aGameResult.winner_color = stoneWhite; |
| 6352 | } |
| 6353 | boarddispatch->recvResult(&aGameResult); |
| 6354 | /* Maybe the last 4 bytes are the remaining 1 second of time, maybe |
| 6355 | * its color or something?*/ |
| 6356 | #ifdef RE_DEBUG |
| 6357 | printf("f6b3: %02x%02x%02x%02x\n", p[0], p[1], p[2], p[3]); |
| 6358 | #endif //RE_DEBUG |
| 6359 | /* What about killing the listing or something??*/ |
| 6360 | } |
| 6361 | |
| 6362 | //dcaf (42f4 goes here as well) |
| 6363 | void CyberOroConnection::handleMove(unsigned char * msg, unsigned int size) |
| 6364 | { |
| 6365 | Room * room = getDefaultRoom(); |
| 6366 | BoardDispatch * boarddispatch; |
| 6367 | unsigned char * p = msg; |
| 6368 | GameData * gr; |
| 6369 | PlayerListing * player; |
| 6370 | int periods; |
| 6371 | bool inPeriodTime; |
| 6372 | unsigned short seconds; |
| 6373 | unsigned short player_id; |
| 6374 | unsigned short game_id = p[0] + (p[1] << 8); |
| 6375 | unsigned short game_number = game_code_to_number[game_id]; |
| 6376 | static bool prev_pass = false; |
| 6377 | if(size != 16) |
| 6378 | { |
| 6379 | qDebug("Move of strange size: %d", size); |
| 6380 | return; |
| 6381 | } |
| 6382 | p += 2; |
| 6383 | MoveRecord * aMove = new MoveRecord(); |
| 6384 | boarddispatch = getIfBoardDispatch(game_number); |
| 6385 | if(!boarddispatch) |
| 6386 | { |
| 6387 | qDebug("No board dispatch for %02x%02x", p[0], p[1]); |
| 6388 | return; |
| 6389 | } |
| 6390 | gr = boarddispatch->getGameData(); |
| 6391 | if(!gr) |
| 6392 | { |
| 6393 | qDebug("Shouldn't be a boarddispatch here\n"); |
| 6394 | return; |
| 6395 | } |
| 6396 | player_id = p[0] + (p[1] << 8); |
| 6397 | player = room->getPlayerListing(player_id); |
| 6398 | /* I get the feeling there's a bug around here FIXME */ |
| 6399 | #ifdef RE_DEBUG |
| 6400 | printf("Move!!!: %02x%02x %02x%02x %02x%02x", p[0], p[1], p[2], p[3], p[4], p[5]); |
| 6401 | #endif //RE_DEBUG |
| 6402 | p += 2; |
| 6403 | p += 2; |
| 6404 | aMove->number = p[0] + (p[1] << 8); |
| 6405 | /* ORO sends move 1 as first move after handicap */ |
| 6406 | /* FIXME There's something weird here. For some reason |
| 6407 | * games we play have to have the first white move after |
| 6408 | * handicap (and possibly others) as what ORO sends |
| 6409 | * naturally, 1, but observing games, we have to |
| 6410 | * decrement all the move numbers by 1. This has |
| 6411 | * to have something to do with the move list because |
| 6412 | * see we don't see a move list for our own game. |
| 6413 | * perhaps if we joined a game before the first |
| 6414 | * move, we'd be just as screwed up.*/ |
| 6415 | //aMove->number--; //because we expected 0 move? |
| 6416 | /* Also print out the moves we send after you fix this. |
| 6417 | aMove->flags = MoveRecord::NONE;*/ |
| 6418 | |
| 6419 | /* Player here is NOT reliable for color, let's try without |
| 6420 | * though I think the first two bytes 0101 vs 0000 might be |
| 6421 | * a color flag */ |
| 6422 | /*if(player->name == gr->white_name) |
| 6423 | aMove->color = stoneWhite; |
| 6424 | else if(player->name == gr->black_name) |
| 6425 | aMove->color = stoneBlack; |
| 6426 | else |
| 6427 | qDebug("no color\n");*/ |
| 6428 | aMove->color = stoneNone; |
| 6429 | p += 2; |
| 6430 | #ifdef RE_DEBUG |
| 6431 | printf("%d %d \n", p[0], p[1]); |
| 6432 | #endif //RE_DEBUG |
| 6433 | aMove->x = p[0]; |
| 6434 | aMove->y = p[1]; |
| 6435 | p += 2; |
| 6436 | #ifdef RE_DEBUG |
| 6437 | for(unsigned int i = 0; i < 6; i++) //8, 9 or 10? |
| 6438 | printf("%02x", p[i]); |
| 6439 | printf("\n"); |
| 6440 | #endif //RE_DEBUG |
| 6441 | seconds = p[0] + (p[1] << 8); |
| 6442 | //3rd byte is periods remaining, first byte is probably seconds |
| 6443 | periods = p[2]; |
| 6444 | inPeriodTime = p[3]; |
| 6445 | p += 4; |
| 6446 | |
| 6447 | if(!inPeriodTime) |
| 6448 | periods = -1; //for clockdisplay |
| 6449 | if(aMove->x == 0 || aMove->y == 0) |
| 6450 | aMove->flags = MoveRecord::PASS; |
| 6451 | boarddispatch->recvMove(aMove); |
| 6452 | /* FIXME color is not set!! */ |
| 6453 | if(aMove->color == stoneWhite) |
| 6454 | boarddispatch->recvTime(TimeRecord(seconds, periods), TimeRecord(0, -1)); |
| 6455 | else |
| 6456 | boarddispatch->recvTime(TimeRecord(0, -1), TimeRecord(seconds, periods)); |
| 6457 | |
| 6458 | |
| 6459 | |
| 6460 | if(match_negotiation_state->isOurGame(game_number)) |
| 6461 | { |
| 6462 | matchKeepAliveTimerID = startTimer(39000); //keep alives |
| 6463 | if(matchRequestKeepAliveTimerID) |
| 6464 | { |
| 6465 | killTimer(matchRequestKeepAliveTimerID); |
| 6466 | matchRequestKeepAliveTimerID = 0; |
| 6467 | } |
| 6468 | // FIXME if this is a pass, and the previous move |
| 6469 | // was a pass, then I think we need to sendEnterScoring() |
| 6470 | // but maybe only if we passed first and this is opp passing |
| 6471 | if(aMove->flags == MoveRecord::PASS) |
| 6472 | { |
| 6473 | if(prev_pass && player_id != our_player_id) |
| 6474 | sendEnterScoring(game_id); |
| 6475 | prev_pass = true; |
| 6476 | } |
| 6477 | else |
| 6478 | prev_pass = false; |
| 6479 | } |
| 6480 | delete aMove; |
| 6481 | } |
| 6482 | |
| 6483 | //e6af |
| 6484 | void CyberOroConnection::handleUndo(unsigned char * msg, unsigned int size) |
| 6485 | { |
| 6486 | unsigned char * p = msg; |
| 6487 | unsigned short player_id, game_code; |
| 6488 | |
| 6489 | if(size != 10) |
| 6490 | { |
| 6491 | qDebug("undo of strange size: %d", size); |
| 6492 | return; |
| 6493 | } |
| 6494 | |
| 6495 | player_id = p[0] + (p[1] << 8); |
| 6496 | game_code = p[2] + (p[3] << 8); |
| 6497 | |
| 6498 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_code_to_number[game_code]); |
| 6499 | if(!boarddispatch) |
| 6500 | { |
| 6501 | qDebug("no board dispatch for undo"); |
| 6502 | return; |
| 6503 | } |
| 6504 | PlayerListing * player = getDefaultRoom()->getPlayerListing(player_id); |
| 6505 | p += 4; |
| 6506 | p += 2; //color byte |
| 6507 | MoveRecord * move = new MoveRecord(); |
| 6508 | move->flags = MoveRecord::REQUESTUNDO; |
| 6509 | move->number = p[0] + (p[1] << 8); |
| 6510 | |
| 6511 | //boarddispatch->recvKibitz(0, player->name + QString(" wants undo to move %1.").arg(opp_requests_undo_move_number)); |
| 6512 | |
| 6513 | boarddispatch->recvMove(move); |
| 6514 | delete move; |
| 6515 | //from sender perspective encode(e) |
| 6516 | //e6af 0e00 b50d 4c02 01 00 0a 00 00 00 |
| 6517 | #ifdef RE_DEBUG |
| 6518 | printf("0xe6af undo: "); |
| 6519 | for(unsigned int i = 0; i < size; i++) |
| 6520 | printf("%02x", msg[i]); |
| 6521 | printf("\n"); |
| 6522 | #endif //RE_DEBUG |
| 6523 | |
| 6524 | } |
| 6525 | |
| 6526 | //0xf0af |
| 6527 | void CyberOroConnection::handleDeclineUndo(unsigned char * msg, unsigned int size) |
| 6528 | { |
| 6529 | unsigned short player_id, game_code; |
| 6530 | unsigned char * p = msg; |
| 6531 | |
| 6532 | if(size != 10) |
| 6533 | { |
| 6534 | qDebug("declineundo of strange size: %d", size); |
| 6535 | return; |
| 6536 | } |
| 6537 | player_id = p[0] + (p[1] << 8); |
| 6538 | game_code = p[2] + (p[3] << 8); |
| 6539 | |
| 6540 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_code_to_number[game_code]); |
| 6541 | if(!boarddispatch) |
| 6542 | { |
| 6543 | qDebug("no board dispatch for decline undo"); |
| 6544 | return; |
| 6545 | } |
| 6546 | PlayerListing * player = getDefaultRoom()->getPlayerListing(player_id); |
| 6547 | |
| 6548 | boarddispatch->recvKibitz(0, player->name + " refused undo."); |
| 6549 | |
| 6550 | #ifdef RE_DEBUG |
| 6551 | printf("0xf0af decline undo: "); |
| 6552 | for(int i = 0; i < (int)size; i++) |
| 6553 | printf("%02x", msg[i]); |
| 6554 | printf("\n"); |
| 6555 | #endif //RE_DEBUG |
| 6556 | } |
| 6557 | |
| 6558 | void CyberOroConnection::handleAcceptUndo(unsigned char * msg, unsigned int size) |
| 6559 | { |
| 6560 | unsigned short player_id, game_code; |
| 6561 | unsigned char * p = msg; |
| 6562 | |
| 6563 | if(size != 10) |
| 6564 | { |
| 6565 | qDebug("accept undo msg of strange size: %d", size); |
| 6566 | } |
| 6567 | |
| 6568 | player_id = p[0] + (p[1] << 8); |
| 6569 | game_code = p[2] + (p[3] << 8); |
| 6570 | |
| 6571 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_code_to_number[game_code]); |
| 6572 | if(!boarddispatch) |
| 6573 | { |
| 6574 | qDebug("no board dispatch for decline undo"); |
| 6575 | return; |
| 6576 | } |
| 6577 | PlayerListing * player = getDefaultRoom()->getPlayerListing(player_id); |
| 6578 | boarddispatch->recvKibitz(0, player->name + " accepted undo."); |
| 6579 | |
| 6580 | p += 4; |
| 6581 | p += 2; //color byte |
| 6582 | MoveRecord * move = new MoveRecord(); |
| 6583 | move->flags = MoveRecord::UNDO; |
| 6584 | move->number = p[0] + (p[1] << 8); |
| 6585 | |
| 6586 | //boarddispatch->recvKibitz(0, player->name + QString(" wants undo to move %1.").arg(opp_requests_undo_move_number)); |
| 6587 | |
| 6588 | boarddispatch->recvMove(move); |
| 6589 | delete move; |
| 6590 | |
| 6591 | #ifdef RE_DEBUG |
| 6592 | printf("0xebaf accept undo: "); |
| 6593 | for(int i = 0; i < (int)size; i++) |
| 6594 | printf("%02x", msg[i]); |
| 6595 | printf("\n"); |
| 6596 | #endif //RE_DEBUG |
| 6597 | } |
| 6598 | |
| 6599 | //0x42f4: 4d75 bd00 0101 ea00 0d08 0200 0101 000b |
| 6600 | //0x42f4: 4d75 bd00 0101 ec00 0b02 0300 0101 000b |
| 6601 | //0x42f4: 4d75 bd00 0000 ed00 0201 0f00 0101 000b |
| 6602 | |
| 6603 | //same as 4cf4, 4cf4 being for in room? |
| 6604 | //d7af |
| 6605 | void CyberOroConnection::handleMoveList(unsigned char * msg, unsigned int size) |
| 6606 | { |
| 6607 | unsigned char * p = msg; |
| 6608 | BoardDispatch * boarddispatch; |
| 6609 | int number_of_moves; |
| 6610 | int i; |
| 6611 | bool pass = false; |
| 6612 | bool enterScore = false; |
| 6613 | GameData * gr; |
| 6614 | MoveRecord * aMove = new MoveRecord(); |
| 6615 | unsigned short game_number; |
| 6616 | p += 2; |
| 6617 | unsigned short game_code = msg[2] + (msg[3] << 8); |
| 6618 | game_number = game_code_to_number[game_code]; |
| 6619 | p += 2; |
| 6620 | boarddispatch = getIfBoardDispatch(game_number); |
| 6621 | if(!boarddispatch) |
| 6622 | { |
| 6623 | qDebug("No board dispatch for %02x%02x", p[0], p[1]); |
| 6624 | return; |
| 6625 | } |
| 6626 | gr = boarddispatch->getGameData(); |
| 6627 | /* FIXME This is rather unfortunate as well but until we fix |
| 6628 | * qgo_network code's move_counter nonsense, a hold over |
| 6629 | * from the old code that I just copied without completely |
| 6630 | * replacing, we do need to take this into account. FIXME */ |
| 6631 | |
| 6632 | number_of_moves = msg[4] + (msg[5] << 8); |
| 6633 | p += 2; |
| 6634 | p += 4; |
| 6635 | #ifdef RE_DEBUG |
| 6636 | printf("Move List!!!! %d\n", number_of_moves); |
| 6637 | #endif //RE_DEBUG |
| 6638 | //player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 6639 | aMove->flags = MoveRecord::NONE; |
| 6640 | //for(i = (gr->handicap ? 1 : 0) ; i < number_of_moves + (gr->handicap ? 1 : 0); i++) |
| 6641 | /* We're sending these starting with 1 because moves after |
| 6642 | * we'll be offset in that way. i.e., ORO starts with 1*/ |
| 6643 | if(gr->handicap) |
| 6644 | aMove->color = stoneWhite; |
| 6645 | else |
| 6646 | aMove->color = stoneBlack; |
| 6647 | for(i = 1; i < number_of_moves + 1; i++) |
| 6648 | { |
| 6649 | //aMove->color = stoneNone; //keep resetting this |
| 6650 | aMove->number = i; //or i + !? |
| 6651 | aMove->x = msg[10 + (2 * (i - 1))]; |
| 6652 | aMove->y = msg[11 + (2 * (i - 1))]; |
| 6653 | #ifdef RE_DEBUG |
| 6654 | printf("Move: %d %d\n", msg[10 + (2 * (i - 1))], msg[11 + (2 * (i - 1))]); |
| 6655 | #endif //RE_DEBUG |
| 6656 | if(aMove->x == 0) |
| 6657 | { |
| 6658 | aMove->flags = MoveRecord::PASS; |
| 6659 | if(pass/* && aMove->color == stoneWhite*/) //white passes last |
| 6660 | enterScore = true; |
| 6661 | pass = true; |
| 6662 | } |
| 6663 | else |
| 6664 | pass = false; |
| 6665 | p += 2; |
| 6666 | boarddispatch->recvMove(aMove); |
| 6667 | if(aMove->x == 0) |
| 6668 | aMove->flags = MoveRecord::NONE; //for next iteration |
| 6669 | if(aMove->color == stoneWhite) |
| 6670 | aMove->color = stoneBlack; |
| 6671 | else |
| 6672 | aMove->color = stoneWhite; |
| 6673 | } |
| 6674 | delete aMove; |
| 6675 | if(p != (msg + size)) |
| 6676 | qDebug("Move list with strange size: %d", size); //20 |
| 6677 | /* We get this if we go back into match mode. Only question is whether if |
| 6678 | * we crash during score mode, we get a separate message to enter score mode */ |
| 6679 | if(enterScore && !match_negotiation_state->isOurGame(game_number)) |
| 6680 | { |
| 6681 | printf("Enter score mode, not our game\n"); |
| 6682 | boarddispatch->recvEnterScoreMode(); |
| 6683 | match_negotiation_state->enterScoreMode(); |
| 6684 | } |
| 6685 | } |
| 6686 | |
| 6687 | //4cf4 4 zeroes different FIXME join |
| 6688 | /* I think this is like for dead games or records or something. broadcast at the least |
| 6689 | * Broadcast is extremely likely. May also start with that 38f4 betting message */ |
| 6690 | void CyberOroConnection::handleMoveList2(unsigned char * msg, unsigned int size) |
| 6691 | { |
| 6692 | Room * room = getDefaultRoom(); |
| 6693 | unsigned char * p = msg; |
| 6694 | BoardDispatch * boarddispatch; |
| 6695 | int number_of_moves; |
| 6696 | int i; |
| 6697 | unsigned short game_id; |
| 6698 | MoveRecord * aMove = new MoveRecord(); |
| 6699 | |
| 6700 | p += 2; |
| 6701 | game_id = p[0] + (p[1] << 8); |
| 6702 | |
| 6703 | GameListing * listing = room->getGameListing(connecting_to_game_number); |
| 6704 | listing->game_code = game_id; |
| 6705 | game_code_to_number[listing->game_code] = listing->number; |
| 6706 | #ifdef RE_DEBUG |
| 6707 | printf("Setting game code to number broadcast %02x%02x %d\n", p[0], p[1], listing->number); |
| 6708 | #endif //RE_DEBUG |
| 6709 | boarddispatch = getBoardDispatch(listing->number); |
| 6710 | |
| 6711 | emit gameListingReceived(listing); |
| 6712 | |
| 6713 | connecting_to_game_number = 0; |
| 6714 | |
| 6715 | p += 2; |
| 6716 | |
| 6717 | |
| 6718 | number_of_moves = p[0] + (p[1] << 8); |
| 6719 | p += 2; |
| 6720 | //p += 4; //doesn't have this !!! |
| 6721 | p += 2; //instead |
| 6722 | #ifdef RE_DEBUG |
| 6723 | printf("Move List Broadcast/Special %d %d!!!!\n", listing->number, listing->game_code); |
| 6724 | #endif //RE_DEBUG |
| 6725 | //player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 6726 | aMove->flags = MoveRecord::NONE; |
| 6727 | //for(i = (aGameData->handicap ? 1 : 0) ; i < number_of_moves + (aGameData->handicap ? 1 : 0); i++) |
| 6728 | for(i = 1; i < number_of_moves + 1; i++) |
| 6729 | { |
| 6730 | |
| 6731 | aMove->color = stoneNone; //keep resetting this |
| 6732 | aMove->number = i; //or i + !? |
| 6733 | aMove->x = p[0]; |
| 6734 | aMove->y = p[1]; |
| 6735 | #ifdef RE_DEBUG |
| 6736 | printf("Move: %d %d\n", p[0], p[1]); |
| 6737 | #endif //RE_DEBUG |
| 6738 | if(aMove->x == 0) |
| 6739 | aMove->flags = MoveRecord::PASS; |
| 6740 | p += 2; |
| 6741 | boarddispatch->recvMove(aMove); |
| 6742 | if(aMove->x == 0) |
| 6743 | aMove->flags = MoveRecord::NONE; //for next iteration |
| 6744 | } |
| 6745 | delete aMove; |
| 6746 | if(p != (msg + size)) |
| 6747 | qDebug("MoveList2 strange size: %d", size); |
| 6748 | } |
| 6749 | |
| 6750 | // note that we receive response on this, so likely we should |
| 6751 | // set ourself, check box there FIXME |
| 6752 | //9a65 maybe?!?!? not a result... probably invitation allowed!!! |
| 6753 | void CyberOroConnection::handleInvitationSettings(unsigned char * msg, unsigned int size) |
| 6754 | { |
| 6755 | Room * room = getDefaultRoom(); |
| 6756 | unsigned char * p = msg; |
| 6757 | PlayerListing * player; |
| 6758 | |
| 6759 | if(size != 8) |
| 6760 | { |
| 6761 | qDebug("Invitation settings msg of strange size %d", size); |
| 6762 | } |
| 6763 | player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 6764 | #ifdef RE_DEBUG |
| 6765 | printf("%s ", player->name.toLatin1().constData()); |
| 6766 | for(unsigned int i = 2; i < size; i++) |
| 6767 | printf("%02x", p[i]); |
| 6768 | printf("\n"); |
| 6769 | #endif //RE_DEBUG |
| 6770 | p += 2; |
| 6771 | //3rd byte after name is invitation settings |
| 6772 | player->info = getStatusFromCode(p[2], player->rank); |
| 6773 | |
| 6774 | } |
| 6775 | |
| 6776 | QString CyberOroConnection::getStatusFromCode(unsigned char code, QString rank) |
| 6777 | { |
| 6778 | // FIXME |
| 6779 | // What we need to do here is have a function (also for use in |
| 6780 | // strict game dialog functionality) that checks our |
| 6781 | // rank versus the target and adjusts an open flag, just one |
| 6782 | // based on that. |
| 6783 | // game dialog needed something more specific so |
| 6784 | const PlayerListing * us = getOurListing(); |
| 6785 | int ret_val = compareRanks(us->rank, rank); |
| 6786 | switch(code) |
| 6787 | { |
| 6788 | case ALLOW_ALL_INVITES: |
| 6789 | return "O"; |
| 6790 | break; |
| 6791 | case ALLOW_STRONGER_INVITE: |
| 6792 | if(ret_val == 1) |
| 6793 | return "O"; |
| 6794 | else |
| 6795 | return "X"; |
| 6796 | break; |
| 6797 | case ALLOW_EVEN_INVITE: |
| 6798 | if(ret_val == 0) |
| 6799 | return "O"; |
| 6800 | else |
| 6801 | return "X"; |
| 6802 | break; |
| 6803 | case ALLOW_WEAKER_INVITE: |
| 6804 | if(ret_val == -1) |
| 6805 | return "O"; |
| 6806 | else |
| 6807 | return "X"; |
| 6808 | break; |
| 6809 | case ALLOW_PAIR_INVITE: |
| 6810 | break; |
| 6811 | case IGNORE_ALL_INVITES: |
| 6812 | return "X"; |
| 6813 | break; |
| 6814 | } |
| 6815 | return ""; |
| 6816 | } |
| 6817 | |
| 6818 | int CyberOroConnection::compareRanks(QString rankA, QString rankB) |
| 6819 | { |
| 6820 | if(rankA.contains("p") && !rankB.contains("p")) |
| 6821 | return 1; |
| 6822 | if(rankB.contains("p") && !rankA.contains("p")) |
| 6823 | return -1; |
| 6824 | if(rankA.contains("d") && !rankB.contains("d")) |
| 6825 | return 1; |
| 6826 | if(rankB.contains("d") && !rankA.contains("d")) |
| 6827 | return -1; |
| 6828 | if(rankA.contains("k")) |
| 6829 | { |
| 6830 | QString buffer = rankA; |
| 6831 | buffer.replace(QRegExp("[pdk]"), ""); |
| 6832 | int ordinalA = buffer.toInt(); |
| 6833 | buffer = rankB; |
| 6834 | buffer.replace(QRegExp("[pdk]"), ""); |
| 6835 | int ordinalB = buffer.toInt(); |
| 6836 | if(ordinalA > ordinalB) |
| 6837 | return -1; |
| 6838 | else if(ordinalA == ordinalB) |
| 6839 | return 0; |
| 6840 | else |
| 6841 | return 1; |
| 6842 | } |
| 6843 | else |
| 6844 | { |
| 6845 | QString buffer = rankA; |
| 6846 | buffer.replace(QRegExp("[pdk]"), ""); |
| 6847 | int ordinalA = buffer.toInt(); |
| 6848 | buffer = rankB; |
| 6849 | buffer.replace(QRegExp("[pdk]"), ""); |
| 6850 | int ordinalB = buffer.toInt(); |
| 6851 | if(ordinalA > ordinalB) |
| 6852 | return 1; |
| 6853 | else if(ordinalA == ordinalB) |
| 6854 | return 0; |
| 6855 | else |
| 6856 | return -1; |
| 6857 | } |
| 6858 | } |
| 6859 | |
| 6860 | /* It looks like when there's a rematch we get a 1a81, which we need to |
| 6861 | * make sure we recognize, and then a d2af, which should trigger |
| 6862 | * a rematch accept somehow. Also likely currently a segmentation fault |
| 6863 | * on this. */ |
| 6864 | /* I'm fairly certain this also doubles as an acceptMatchModeRequest */ |
| 6865 | void CyberOroConnection::handleMatchOpened(unsigned char * msg, unsigned int size) |
| 6866 | { |
| 6867 | Room * room = getDefaultRoom(); |
| 6868 | BoardDispatch * boarddispatch; |
| 6869 | unsigned char * p = msg; |
| 6870 | PlayerListing * player; |
| 6871 | PlayerListing * playerA, * playerB; |
| 6872 | GameData * aGameData = 0; |
| 6873 | unsigned short player_id; |
| 6874 | unsigned short game_id; |
| 6875 | unsigned short game_number; |
| 6876 | int handicap; |
| 6877 | unsigned short black_seconds, white_seconds; |
| 6878 | int black_periods, white_periods; |
| 6879 | float komi; |
| 6880 | bool white_in_byoyomi, black_in_byoyomi; |
| 6881 | bool we_are_challenger = false; |
| 6882 | int board_size; |
| 6883 | bool nigiri = false; |
| 6884 | bool memo, review, estimate; |
| 6885 | if(size != 156) |
| 6886 | { |
| 6887 | qDebug("Match Opened msg of strange size %d", size); |
| 6888 | } |
| 6889 | #ifdef RE_DEBUG |
| 6890 | printf("d2af: \n"); |
| 6891 | for(unsigned int i = 0; i < size; i++) |
| 6892 | printf("%02x", msg[i]); |
| 6893 | printf("\n"); |
| 6894 | #endif //RE_DEBUG |
| 6895 | |
| 6896 | /* FIXME I'm not sure this is the current players turn, |
| 6897 | * it might just be the challenger or something */ |
| 6898 | player_id = p[0] + (p[1] << 8); |
| 6899 | player = room->getPlayerListing(player_id); |
| 6900 | #ifdef RE_DEBUG |
| 6901 | if(player) |
| 6902 | printf("Currently %s's turn...\n", player->name.toLatin1().constData()); //not true for nigiri at least, FIXME |
| 6903 | else |
| 6904 | qDebug("Can't find player for for d2af\n"); |
| 6905 | #endif //RE_DEBUG |
| 6906 | /* This doesn't work */ |
| 6907 | //if(player_id == our_player_id) |
| 6908 | // we_are_challenger = true; |
| 6909 | //else |
| 6910 | // we_are_challenger = false; |
| 6911 | p += 2; |
| 6912 | game_id = msg[2] + (msg[3] << 8); |
| 6913 | game_number = game_code_to_number[game_id]; |
| 6914 | if(!game_number) |
| 6915 | printf("No game number for %02x%02x\n", msg[2], msg[3]); |
| 6916 | /* FIXME, its apparently possible to get this on a match we're |
| 6917 | * already observing for some reason... if we haven't set a connecting |
| 6918 | * to number, this causes us to create an unnecessary board */ |
| 6919 | /* FIXME is this reliable for our games ? */ |
| 6920 | |
| 6921 | p += 2; |
| 6922 | //b50d 7203 0002 01f0 0201 0300 0000 3c00 3c003c00 |
| 6923 | //0002 |
| 6924 | //I think this is the rematch number |
| 6925 | //4 and 5 might be the ordinal of this game in a sequence (maybe not) |
| 6926 | p += 2; |
| 6927 | |
| 6928 | if(connecting_to_game_number) |
| 6929 | { |
| 6930 | if(connecting_to_game_number != game_number) |
| 6931 | { |
| 6932 | printf("Received unexpected d2af\n"); |
| 6933 | } |
| 6934 | else |
| 6935 | connecting_to_game_number = 0; |
| 6936 | #ifdef RE_DEBUG |
| 6937 | //printf("d2af Setting game code to number %02x%02x %d\n", msg[2], msg[3], game_number); |
| 6938 | #endif //RE_DEBUG |
| 6939 | //game_code_to_number[game_id] = game_number; |
| 6940 | } |
| 6941 | else if(match_negotiation_state->isOurGame(game_number)) |
| 6942 | { |
| 6943 | if(match_negotiation_state->opponentDisconnected()) |
| 6944 | { |
| 6945 | if(match_negotiation_state->getOpponent() != player->name) |
| 6946 | { |
| 6947 | qDebug("Got match opened, but %s is not our opponent", player->name.toLatin1().constData()); |
| 6948 | //return; //FIXME |
| 6949 | } |
| 6950 | qDebug("opponent reconnected"); |
| 6951 | match_negotiation_state->setPlayer(player); |
| 6952 | match_negotiation_state->startMatch(); |
| 6953 | boarddispatch = getIfBoardDispatch(game_number); |
| 6954 | if(!boarddispatch) |
| 6955 | { |
| 6956 | qDebug("Opponent reconnected but no board!"); |
| 6957 | return; |
| 6958 | } |
| 6959 | aGameData = boarddispatch->getGameData(); |
| 6960 | if(aGameData->game_code != game_id) //probably won't |
| 6961 | aGameData->game_code = game_id; |
| 6962 | boarddispatch->startTime(); |
| 6963 | QString q; |
| 6964 | boarddispatch->moveControl(q); |
| 6965 | } |
| 6966 | else |
| 6967 | { |
| 6968 | if(!match_negotiation_state->verifyPlayer(player) && |
| 6969 | (player_id != our_player_id || (!match_negotiation_state->sentRematch() && !match_negotiation_state->canEnterRematchAdjourned()))) |
| 6970 | { |
| 6971 | //on resuming a game after being disconnected, we hit here |
| 6972 | //it could be anything but its amazing that our game is set at all?!? FIXME |
| 6973 | // actually, obviously their id changes when they resume so "verifyPlayer" will fail !!! FIXME |
| 6974 | qDebug("Would have been a rematch but some issue"); //FIXME FIXME |
| 6975 | //FIXME resetting here could be a problem with someone blocking games by causing us to reset when |
| 6976 | //we shouldn't? maybe not. I'm being paranoid, this isn't udp |
| 6977 | //match_negotiation_state->reset(); |
| 6978 | //return; |
| 6979 | // so yeah, going to go ahead, assuming its okay though should still FIXME |
| 6980 | } |
| 6981 | boarddispatch = getIfBoardDispatch(game_number); |
| 6982 | if(!boarddispatch) |
| 6983 | { |
| 6984 | if(player) |
| 6985 | getAndCloseGameDialog(player); |
| 6986 | setRoomNumber(game_number); |
| 6987 | } |
| 6988 | else |
| 6989 | { |
| 6990 | aGameData = boarddispatch->getGameData(); |
| 6991 | if(aGameData->game_code != game_id) |
| 6992 | { |
| 6993 | /* We're getting here when there's just a rejoin |
| 6994 | * unknown indicator 01 could be resume, but game code is different |
| 6995 | * note that we get the list of moves when they drop and rejoin!! */ |
| 6996 | GameListing * listing = room->getGameListing(game_number); |
| 6997 | delete listing->gameData; |
| 6998 | listing->gameData = 0; |
| 6999 | printf("our rematch\n"); |
| 7000 | NetworkConnection::closeBoardDispatch(game_number); |
| 7001 | aGameData = 0; |
| 7002 | } |
| 7003 | else |
| 7004 | { |
| 7005 | |
| 7006 | #ifdef RE_DEBUG |
| 7007 | printf("Maybe a return to match mode our game\n"); |
| 7008 | #endif //RE_DEBUG |
| 7009 | //if so, need to restart timers!!! FIXME, added to boarddispatch but doublecheck |
| 7010 | boarddispatch->recvLeaveScoreMode(); |
| 7011 | match_negotiation_state->startMatch(); |
| 7012 | return; |
| 7013 | } |
| 7014 | } |
| 7015 | } |
| 7016 | } |
| 7017 | else |
| 7018 | { |
| 7019 | boarddispatch = getIfBoardDispatch(game_number); |
| 7020 | if(!boarddispatch) |
| 7021 | { |
| 7022 | qDebug("Unexpected d2af\n"); |
| 7023 | return; |
| 7024 | } |
| 7025 | else |
| 7026 | { |
| 7027 | aGameData = boarddispatch->getGameData(); |
| 7028 | if(aGameData->game_code != game_id) |
| 7029 | { |
| 7030 | /* FIXME should be combined with earlier deletion of this under our match. |
| 7031 | * this is ugly incidentally, that we add this strange thing to store the |
| 7032 | * gameData because ORO doesn't resend on rejoin, and then we have to go |
| 7033 | * around it like this. */ |
| 7034 | /* FIXME pretty sure this can happen sometimes when there's no rematch |
| 7035 | * so there must be an additional flag */ |
| 7036 | GameListing * listing = room->getGameListing(game_number); |
| 7037 | delete listing->gameData; |
| 7038 | listing->gameData = 0; |
| 7039 | printf("observer rematch\n"); |
| 7040 | NetworkConnection::closeBoardDispatch(game_number); |
| 7041 | aGameData = 0; |
| 7042 | } |
| 7043 | else |
| 7044 | { |
| 7045 | #ifdef RE_DEBUG |
| 7046 | printf("Maybe a return to match mode observer\n"); |
| 7047 | #endif //RE_DEBUG |
| 7048 | boarddispatch->recvLeaveScoreMode(); |
| 7049 | return; |
| 7050 | } |
| 7051 | } |
| 7052 | } |
| 7053 | /* In case of rematches, we close the existing board |
| 7054 | * dispatch, but only through the network |
| 7055 | * connection. We don't want to send a leave msg*/ |
| 7056 | /* FIXME for observed games we need to distinguish here between rematches, return to match mode |
| 7057 | * and spoofed board open packets also see match mode comment above.*/ |
| 7058 | |
| 7059 | |
| 7060 | boarddispatch = getBoardDispatch(game_number); |
| 7061 | |
| 7062 | /* Consider adding our name to observer list here: */ |
| 7063 | //FIXME shouldn't some other message do this? doublecheck |
| 7064 | if(room_were_in == game_number) |
| 7065 | { |
| 7066 | PlayerListing * our_player = room->getPlayerListing(our_player_id); |
| 7067 | boarddispatch->recvObserver(our_player, true); |
| 7068 | //if its our game and we want the 2 != 0 to stop, |
| 7069 | //we need to add ourself and opponent to game or make on 1a81 or whatever |
| 7070 | //to do it FIXME |
| 7071 | } |
| 7072 | |
| 7073 | if(!aGameData) |
| 7074 | aGameData = boarddispatch->getGameData(); |
| 7075 | |
| 7076 | |
| 7077 | //FIXME make sure this doesn't enable undo button |
| 7078 | //in observed matches |
| 7079 | aGameData->undoAllowed = p[1] & 0x80; |
| 7080 | memo = p[1] & 0x40; |
| 7081 | review = p[1] & 0x20; |
| 7082 | estimate = p[1] & 0x10; |
| 7083 | if(p[1] & 0x08) |
| 7084 | { |
| 7085 | nigiri = true; |
| 7086 | aGameData->nigiriToBeSettled = true; |
| 7087 | } |
| 7088 | /* Maybe 08 is black, 00 is white? and nigiri? */ |
| 7089 | p += 2; |
| 7090 | //0201 //one of these may be the board size flag, 9x9 |
| 7091 | switch(p[0]) |
| 7092 | { |
| 7093 | case 0: |
| 7094 | board_size = 19; |
| 7095 | break; |
| 7096 | case 1: |
| 7097 | board_size = 13; |
| 7098 | break; |
| 7099 | case 2: |
| 7100 | board_size = 9; |
| 7101 | break; |
| 7102 | case 3: |
| 7103 | board_size = 7; |
| 7104 | break; |
| 7105 | case 4: |
| 7106 | board_size = 5; |
| 7107 | break; |
| 7108 | default: |
| 7109 | printf("Strange boardsize indicator: %02x\n", p[0]); |
| 7110 | board_size = 19; |
| 7111 | break; |
| 7112 | } |
| 7113 | #ifdef RE_DEBUG |
| 7114 | printf("Unknown indicator: %02x\n", p[1]); |
| 7115 | /* very likely this means a resume after disconnect |
| 7116 | * I saw 00 for a legitimate rematch... its possible that the ones |
| 7117 | * that shouldn't open a new window are 01 but I need to verify, |
| 7118 | * note that this can be in "observer rematch" as well*/ |
| 7119 | #endif //RE_DEBUG |
| 7120 | p += 2; |
| 7121 | |
| 7122 | handicap = p[0]; |
| 7123 | |
| 7124 | if(handicap) |
| 7125 | { |
| 7126 | //maybe clear komi? |
| 7127 | if(handicap == 1) |
| 7128 | handicap = 0; |
| 7129 | } |
| 7130 | |
| 7131 | p++; |
| 7132 | if(p[0]) |
| 7133 | komi = -((float)(p[1])) - 0.5; |
| 7134 | else |
| 7135 | komi = ((float)(p[1])) + 0.5; |
| 7136 | |
| 7137 | p += 5; //this skips one time duplicate as well |
| 7138 | black_seconds = p[0] + (p[1] << 8); |
| 7139 | p += 2; |
| 7140 | white_seconds = p[0] + (p[1] << 8); |
| 7141 | p += 2; |
| 7142 | aGameData->maintime = black_seconds; //FIXME they're the same right? |
| 7143 | |
| 7144 | black_periods = p[0]; |
| 7145 | white_periods = p[1]; |
| 7146 | p += 2; |
| 7147 | black_in_byoyomi = p[0]; |
| 7148 | white_in_byoyomi = p[1]; |
| 7149 | /* If maintime is set to 0, we need to jump into periods. Not |
| 7150 | * sure why this isn't set on incoming message, I guess because match |
| 7151 | * just opened. */ |
| 7152 | if(!black_in_byoyomi && aGameData->maintime) |
| 7153 | black_periods = -1; //FIXME, awkward flags |
| 7154 | if(!white_in_byoyomi && aGameData->maintime) |
| 7155 | white_periods = -1; |
| 7156 | p += 2; |
| 7157 | |
| 7158 | aGameData->periodtime = p[0] + (p[1] << 8); |
| 7159 | p += 2; |
| 7160 | aGameData->stones_periods = p[0]; |
| 7161 | switch(p[1]) |
| 7162 | { |
| 7163 | case 0: |
| 7164 | aGameData->timeSystem = byoyomi; |
| 7165 | break; |
| 7166 | case 1: |
| 7167 | aGameData->timeSystem = canadian; |
| 7168 | break; |
| 7169 | case 2: |
| 7170 | aGameData->timeSystem = tvasia; |
| 7171 | break; |
| 7172 | } |
| 7173 | p += 2; |
| 7174 | |
| 7175 | //00 00 A4 01 A4 01 A4 01 05 05 00 00 3C 00 05 00 ............<... |
| 7176 | //02 00 00 00 //these second two 00 00 might be a move number? |
| 7177 | p += 4; |
| 7178 | game_number = p[0] + (p[1] << 8); |
| 7179 | #ifdef RE_DEBUG |
| 7180 | printf("Room number : %d\n", game_number); |
| 7181 | #endif //RE_DEBUG |
| 7182 | //96 00 96 00 |
| 7183 | p += 4; |
| 7184 | p += 23; |
| 7185 | p++; |
| 7186 | p += 10; |
| 7187 | playerA = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 7188 | p += 2; |
| 7189 | #ifdef RE_DEBUG |
| 7190 | printf("PlayerA is %s %s\n", playerA->name.toLatin1().constData(), playerA->rank.toLatin1().constData()); |
| 7191 | #endif //RE_DEBUG |
| 7192 | p += 10; |
| 7193 | playerB = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 7194 | #ifdef RE_DEBUG |
| 7195 | printf("PlayerB is %s %s\n", playerB->name.toLatin1().constData(), playerB->rank.toLatin1().constData()); |
| 7196 | #endif //RE_DEBUG |
| 7197 | p += 2; |
| 7198 | /* FIXME It looks like its possible to reverse the ranks here and |
| 7199 | * we need to find out why and how */ |
| 7200 | |
| 7201 | /* Double check for nigiri issues */ |
| 7202 | if(match_negotiation_state->isOurGame(game_number)) |
| 7203 | { |
| 7204 | if(playerA->id == our_player_id) |
| 7205 | { |
| 7206 | aGameData->opponent_id = playerB->id; |
| 7207 | if(nigiri) |
| 7208 | we_are_challenger = true; |
| 7209 | } |
| 7210 | else |
| 7211 | { |
| 7212 | aGameData->opponent_id = playerA->id; |
| 7213 | } |
| 7214 | match_negotiation_state->startMatch(); |
| 7215 | } |
| 7216 | aGameData->black_name = playerA->name; |
| 7217 | aGameData->white_name = playerB->name; |
| 7218 | aGameData->black_rank = playerA->rank; |
| 7219 | aGameData->white_rank = playerB->rank; |
| 7220 | aGameData->board_size = board_size; |
| 7221 | aGameData->handicap = handicap; |
| 7222 | aGameData->number = game_number; |
| 7223 | aGameData->game_code = game_id; |
| 7224 | aGameData->komi = komi; |
| 7225 | boarddispatch->openBoard(); |
| 7226 | boarddispatch->recvTime(TimeRecord(white_seconds, white_periods), TimeRecord(black_seconds, black_periods)); |
| 7227 | |
| 7228 | if(playerA->id == our_player_id || playerB->id == our_player_id) |
| 7229 | { |
| 7230 | if(!nigiri) |
| 7231 | { |
| 7232 | startMatchTimers((playerA->id == our_player_id && !handicap) || |
| 7233 | (playerB->id == our_player_id && handicap)); |
| 7234 | } |
| 7235 | else if(nigiri && we_are_challenger) |
| 7236 | sendNigiri(aGameData->game_code, true); |
| 7237 | else |
| 7238 | { |
| 7239 | boarddispatch->recvKibitz(QString(), "Waiting for opponent nigiri..."); |
| 7240 | we_send_nigiri = false; |
| 7241 | } |
| 7242 | } |
| 7243 | /* seems like color can get reversed */ |
| 7244 | |
| 7245 | /* And observers: */ |
| 7246 | if(room_were_in == game_number) //no observing outside |
| 7247 | addObserverListToBoard(boarddispatch); |
| 7248 | } |
| 7249 | |
| 7250 | void CyberOroConnection::addObserverListToBoard(BoardDispatch * boarddispatch) |
| 7251 | { |
| 7252 | GameListing * game = getDefaultRoom()->getGameListing(boarddispatch->getGameData()->number); |
| 7253 | //sanity check: for DEBUG ing |
| 7254 | /* FIXME We're getting 2 != 1 and a crash here |
| 7255 | * also 2 != 0, has something to do with if its our game*/ |
| 7256 | #ifdef RE_DEBUG |
| 7257 | if(game->observers != game->observer_list.size()) |
| 7258 | qDebug("Observers and observer list size mismatch on game %d!! (%d != %d)", boarddispatch->getGameData()->number, game->observers, game->observer_list.size()); |
| 7259 | #endif //RE_DEBUG |
| 7260 | for(std::vector<PlayerListing *>::iterator oblistit = game->observer_list.begin(); |
| 7261 | oblistit != game->observer_list.end(); oblistit++) |
| 7262 | boarddispatch->recvObserver(*oblistit, true); |
| 7263 | } |
| 7264 | |
| 7265 | //38 F4 78 00 01 00 00 08 18 00 00 00 06 00 50 46 8.x...........PF |
| 7266 | //2A 0B 3B 00 05 01 00 01 3C 00 05 00 02 00 4B 2E *.;.....<.....K. |
| 7267 | //4B 6F 62 61 79 61 73 68 41 2E 4B 61 74 6F 00 00 KobayashA.Kato.. |
| 7268 | //00 00 8F AC 97 D1 8C F5 88 EA 00 00 89 C1 93 A1 ................ |
| 7269 | //8F 5B 8E 75 00 00 03 03 C9 C8 03 05 00 00 00 00 .[.u............ |
| 7270 | //00 00 00 00 1F 01 96 BC 90 6C 90 ED 8D C5 8F 49 .........l.....I |
| 7271 | //97 5C 91 49 00 00 00 00 00 00 00 00 00 00 00 00 .\.I............ |
| 7272 | //00 00 00 00 01 00 00 1F |
| 7273 | /* Double check that this isn't just for joining of dead matches or broadcast deads |
| 7274 | * Okay, this was a mistake altogether, it was a betting message match that got |
| 7275 | * lodged in there. */ |
| 7276 | void CyberOroConnection::handleObserveAfterJoining(unsigned char * msg, unsigned int size) |
| 7277 | { |
| 7278 | Room * room = getDefaultRoom(); |
| 7279 | //BoardDispatch * boarddispatch; |
| 7280 | unsigned char * p = msg; |
| 7281 | PlayerListing * player; |
| 7282 | /*GameListing * game; |
| 7283 | GameData * aGameData; |
| 7284 | unsigned short game_id; |
| 7285 | int handicap; |
| 7286 | unsigned short black_seconds, white_seconds; |
| 7287 | int black_periods, white_periods; |
| 7288 | unsigned short period_time; |
| 7289 | float komi; |
| 7290 | bool send_handicap_move = false; |
| 7291 | bool white_in_byoyomi, black_in_byoyomi;*/ |
| 7292 | |
| 7293 | printf("FIXME handleObserveAfterJoining size: %d\n", size); |
| 7294 | |
| 7295 | player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 7296 | #ifdef FIXME |
| 7297 | if(player) |
| 7298 | printf("Currently %s's turn...\n", player->name.toLatin1().constData()); |
| 7299 | else |
| 7300 | printf("Can't find player for for d2af\n"); |
| 7301 | printf("38f4\n"); |
| 7302 | for(int i = 0; i < size; i++) |
| 7303 | printf("%02x", msg[i]); |
| 7304 | printf("\n"); |
| 7305 | #endif //FIXME |
| 7306 | //FIXME |
| 7307 | } |
| 7308 | |
| 7309 | void CyberOroConnection::handleMatchOffer(unsigned char * msg, unsigned int size) |
| 7310 | { |
| 7311 | unsigned char * p = msg; |
| 7312 | unsigned short periodtime; |
| 7313 | unsigned short room_number; |
| 7314 | int periods; |
| 7315 | bool undo, memo, review, estimate; |
| 7316 | bool nigiri = false; |
| 7317 | MatchRequest mr; |
| 7318 | Room * room = getDefaultRoom(); |
| 7319 | unsigned short id = p[0] + (p[1] << 8); |
| 7320 | if(size != 156) |
| 7321 | { |
| 7322 | qDebug("match offer message of strange size %d", size); |
| 7323 | } |
| 7324 | if(id == our_player_id) |
| 7325 | mr.opponent_is_challenger = false; |
| 7326 | else |
| 7327 | { |
| 7328 | mr.opponent_id = id; |
| 7329 | mr.opponent_is_challenger = true; |
| 7330 | } |
| 7331 | /* FIXME I think its okay if we get this as long as we're in the same room with the opponent */ |
| 7332 | |
| 7333 | PlayerListing * player = room->getPlayerListing(mr.opponent_id); |
| 7334 | PlayerListing * ourplayer = room->getPlayerListing(our_player_id); |
| 7335 | |
| 7336 | mr.opponent = player->name; |
| 7337 | mr.their_rank = player->rank; |
| 7338 | mr.our_name = ourplayer->name; |
| 7339 | mr.our_rank = ourplayer->rank; |
| 7340 | |
| 7341 | p += 2; |
| 7342 | #ifdef RE_DEBUG |
| 7343 | printf("last game id?: %02x %02x %d\n", p[0], p[1], p[0] + (p[1] << 8)); |
| 7344 | #endif //RE_DEBUG |
| 7345 | mr.last_game_code = p[0] + (p[1] << 8); |
| 7346 | p += 2; |
| 7347 | #ifdef RE_DEBUG |
| 7348 | printf("bytes we need: %02x %02x\n", p[0], p[1]); |
| 7349 | #endif //RE_DEBUG |
| 7350 | p += 2; |
| 7351 | //01f0 |
| 7352 | // first byte 01 = friendly, 00 = promotional/rated? |
| 7353 | if(p[0]) |
| 7354 | mr.free_rated = FREE; |
| 7355 | else |
| 7356 | mr.free_rated = RATED; |
| 7357 | //second byte contains partly bit field for settings |
| 7358 | // double check |
| 7359 | undo = p[1] & 0x80; |
| 7360 | memo = p[1] & 0x40; |
| 7361 | review = p[1] & 0x20; |
| 7362 | estimate = p[1] & 0x10; |
| 7363 | mr.flags = p[1] & 0xf0; |
| 7364 | #ifdef RE_DEBUG |
| 7365 | printf("Possible color indicator: %02x\n", p[1] & 0x0f); |
| 7366 | #endif //RE_DEBUG |
| 7367 | /*switch(p[1] & 0x0f) |
| 7368 | { |
| 7369 | case 0: |
| 7370 | mr.color_request = MatchRequest::WHITE; |
| 7371 | break; |
| 7372 | case 8: |
| 7373 | mr.color_request = MatchRequest::BLACK; |
| 7374 | break; |
| 7375 | default: |
| 7376 | break; |
| 7377 | }*/ |
| 7378 | if(p[1] & 0x08) |
| 7379 | { |
| 7380 | mr.color_request = MatchRequest::NIGIRI; |
| 7381 | nigiri = true; |
| 7382 | } |
| 7383 | /* Maybe 08 is black, 00 is white? and nigiri? */ |
| 7384 | p += 2; |
| 7385 | //0201 //one of these may be the board size flag, 9x9 |
| 7386 | switch(p[0]) |
| 7387 | { |
| 7388 | case 0: |
| 7389 | mr.board_size = 19; |
| 7390 | break; |
| 7391 | case 1: |
| 7392 | mr.board_size = 13; |
| 7393 | break; |
| 7394 | case 2: |
| 7395 | mr.board_size = 9; |
| 7396 | break; |
| 7397 | case 3: |
| 7398 | mr.board_size = 7; |
| 7399 | break; |
| 7400 | case 4: |
| 7401 | mr.board_size = 5; |
| 7402 | break; |
| 7403 | default: |
| 7404 | printf("Strange boardsize indicator: %02x\n", p[0]); |
| 7405 | break; |
| 7406 | } |
| 7407 | #ifdef RE_DEBUG |
| 7408 | printf("Unknown indicator: %02x\n", p[1]); |
| 7409 | #endif //RE_DEBUG |
| 7410 | /* This doesn't necessarily mean challenger is black, |
| 7411 | * I don't know what this means, I've seen it as 0, |
| 7412 | * for challenger as all colors */ |
| 7413 | mr.challenger_is_black = p[1]; |
| 7414 | p += 2; |
| 7415 | //0300 //probably handicap |
| 7416 | mr.handicap = p[0]; |
| 7417 | p++; |
| 7418 | if(p[0]) |
| 7419 | mr.komi = -((float)(p[1])) - 0.5; |
| 7420 | else |
| 7421 | mr.komi = ((float)(p[1])) + 0.5; |
| 7422 | //0400; //probably komi |
| 7423 | p += 3; |
| 7424 | //5802 //here main time is repeated there times !?! |
| 7425 | mr.maintime = p[0] + (p[1] << 8); |
| 7426 | p += 6; |
| 7427 | //0505 //probably time periods, but I think we get this later as well |
| 7428 | p += 2; |
| 7429 | //0000 |
| 7430 | p += 2; |
| 7431 | periodtime = p[0] + (p[1] << 8); |
| 7432 | p += 2; |
| 7433 | //0500 |
| 7434 | periods = p[0]; |
| 7435 | // that second byte MIGHT be the game style |
| 7436 | // 0 for byo yomi, 1 for canada, 2, for "tv asia" |
| 7437 | // pretty certain this is FIXME correct time style !!!! |
| 7438 | switch(p[1]) |
| 7439 | { |
| 7440 | case 0: |
| 7441 | /* Really this is korean, but hopefully its the same thing */ |
| 7442 | mr.timeSystem = byoyomi; |
| 7443 | break; |
| 7444 | case 1: |
| 7445 | mr.timeSystem = canadian; |
| 7446 | break; |
| 7447 | case 2: |
| 7448 | mr.timeSystem = tvasia; |
| 7449 | break; |
| 7450 | default: |
| 7451 | printf("Unknown time style indicator %02x\n", p[1]); |
| 7452 | break; |
| 7453 | } |
| 7454 | mr.stones_periods = periods; |
| 7455 | mr.periodtime = periodtime; |
| 7456 | p += 2; |
| 7457 | //0200 |
| 7458 | #ifdef RE_DEBUG |
| 7459 | printf("First weird byte: %02x %02x\n", p[0], p[1]); |
| 7460 | #endif //RE_DEBUG |
| 7461 | p += 2; |
| 7462 | //0000 3900 |
| 7463 | p += 2; |
| 7464 | room_number = p[0] + (p[1] << 8); |
| 7465 | #ifdef RE_DEBUG |
| 7466 | printf("mr number: %d\n", room_number); |
| 7467 | #endif //RE_DEBUG |
| 7468 | mr.number = room_number; |
| 7469 | p += 2; |
| 7470 | p += 14; //zeroes |
| 7471 | //1f00 |
| 7472 | p += 2; |
| 7473 | p += 8; //zeroes |
| 7474 | //0075 |
| 7475 | #ifdef RE_DEBUG |
| 7476 | /* FIXME, not really sure what this byte is, |
| 7477 | * fairly certain its unrelated to color though*/ |
| 7478 | if(p[1] & 0x10) |
| 7479 | printf("0x10 setting on\n"); |
| 7480 | else |
| 7481 | printf("0x10 setting off\n"); |
| 7482 | if(p[1] & 0x20) |
| 7483 | printf("0x20 setting on\n"); |
| 7484 | else |
| 7485 | printf("0x20 setting off\n"); |
| 7486 | if(p[1] & 0x40) |
| 7487 | printf("0x40 setting on\n"); |
| 7488 | else |
| 7489 | printf("0x40 setting off\n"); |
| 7490 | if(p[1] & 0x80) |
| 7491 | printf("0x80 setting on\n"); |
| 7492 | else |
| 7493 | printf("0x80 setting off\n"); |
| 7494 | if(p[1] & 0x01) |
| 7495 | printf("0x01 setting on\n"); |
| 7496 | else |
| 7497 | printf("0x01 setting off\n"); |
| 7498 | if(p[1] & 0x02) |
| 7499 | printf("0x02 setting on\n"); |
| 7500 | else |
| 7501 | printf("0x02 setting off\n"); |
| 7502 | if(p[1] & 0x04) |
| 7503 | printf("0x04 setting on\n"); |
| 7504 | else |
| 7505 | printf("0x04 setting off\n"); |
| 7506 | if(p[1] & 0x08) |
| 7507 | printf("0x08 setting on\n"); |
| 7508 | else |
| 7509 | printf("0x08 setting off\n"); |
| 7510 | #endif //RE_DEBUG |
| 7511 | |
| 7512 | |
| 7513 | p += 2; |
| 7514 | p += 10; //name and id |
| 7515 | unsigned short black_challenger_id = p[0] + (p[1] << 8); |
| 7516 | if(black_challenger_id == our_player_id && !nigiri) |
| 7517 | mr.color_request = MatchRequest::BLACK; |
| 7518 | else if(!nigiri) |
| 7519 | { |
| 7520 | mr.color_request = MatchRequest::WHITE; |
| 7521 | if(black_challenger_id != our_player_id) |
| 7522 | mr.opponent_id = black_challenger_id; |
| 7523 | } |
| 7524 | p += 2; |
| 7525 | p += 10; //name and id |
| 7526 | unsigned short white_non_challenger_id = p[0] + (p[1] << 8); |
| 7527 | if(white_non_challenger_id != our_player_id) |
| 7528 | mr.opponent_id = white_non_challenger_id; |
| 7529 | p += 2; |
| 7530 | /* Either challenger is second, or white is second or there's another |
| 7531 | * flag to indicate which is which */ |
| 7532 | p += 22; //zeroes |
| 7533 | //1027 |
| 7534 | p += 2; |
| 7535 | p += (3 * 16); //zeroes |
| 7536 | |
| 7537 | #ifdef RE_DEBUG |
| 7538 | printf("0xc8af: "); |
| 7539 | for(unsigned int i = 0; i < size; i++) |
| 7540 | printf("%02x", msg[i]); |
| 7541 | printf("\n"); |
| 7542 | #endif //RE_DEBUG |
| 7543 | GameDialog * gameDialogDispatch = getGameDialog(player); |
| 7544 | gameDialogDispatch->recvRequest(&mr, getGameDialogFlags()); |
| 7545 | } |
| 7546 | |
| 7547 | //5fc3 |
| 7548 | void CyberOroConnection::handleResumeMatch(unsigned char * msg, unsigned int size) |
| 7549 | { |
| 7550 | unsigned char * p = msg; |
| 7551 | unsigned short room_number = p[0] + (p[1] << 8); |
| 7552 | unsigned short our_id, their_id; |
| 7553 | PlayerListing * opponent; |
| 7554 | p += 2; |
| 7555 | our_id = msg[2] + (msg[3] << 8); |
| 7556 | if(our_id != our_player_id) |
| 7557 | { |
| 7558 | #ifdef RE_DEBUG |
| 7559 | qDebug("resume game not meant for us! %02x%02x", msg[2], msg[3]); //happens often |
| 7560 | #endif //RE_DEBUG |
| 7561 | return; |
| 7562 | } |
| 7563 | their_id = msg[4] + (msg[5] << 8); |
| 7564 | |
| 7565 | opponent = getDefaultRoom()->getPlayerListing(their_id); |
| 7566 | // ffs? lots of ffs? |
| 7567 | #ifdef RE_DEBUG |
| 7568 | printf("resume adjourned? 5fc3?: "); |
| 7569 | for(unsigned int i = 0; i < size; i++) |
| 7570 | printf("%02x", msg[i]); |
| 7571 | printf("\n"); |
| 7572 | #endif //RE_DEBUG |
| 7573 | |
| 7574 | match_negotiation_state->setupRematchAdjourned(room_number, opponent->name); |
| 7575 | /* It only get set as our game if its got our name in it |
| 7576 | * and even that may not be enough but... treat like |
| 7577 | * 0a7d from here. |
| 7578 | |
| 7579 | * Actually, this may be a bad idea because it can screw up |
| 7580 | * the player names !!! ours is always first regardless of color |
| 7581 | * we'd have to make sure that 0a7d is not relied on for color |
| 7582 | * and more than that that the d2af does set the color up properly.*/ |
| 7583 | /* More than that, it causes NewRoom to complain about size 18 */ |
| 7584 | handleNewRoom(msg, size); |
| 7585 | #ifdef RE_DEBUG |
| 7586 | qDebug("Resuming\n"); |
| 7587 | #endif //RE_DEBUG |
| 7588 | } |
| 7589 | /* FIXME, combine these very common handler messages into one function */ |
| 7590 | |
| 7591 | //b5b3 |
| 7592 | void CyberOroConnection::handleAdjournRequest(unsigned char * msg, unsigned int size) |
| 7593 | { |
| 7594 | unsigned char * p = msg; |
| 7595 | |
| 7596 | if(size != 8) |
| 7597 | { |
| 7598 | qDebug("Adjourn request of strange size: %d", size); |
| 7599 | } |
| 7600 | //unsigned short opponent_id = p[0] + (p[1] << 8); |
| 7601 | unsigned short game_code = p[2] + (p[3] << 8); |
| 7602 | unsigned short game_number = game_code_to_number[game_code]; |
| 7603 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_number); |
| 7604 | if(!boarddispatch) |
| 7605 | { |
| 7606 | qDebug("Received adjourn decline on nonexistent board"); |
| 7607 | return; |
| 7608 | } |
| 7609 | boarddispatch->recvRequestAdjourn(); |
| 7610 | |
| 7611 | p += 2; |
| 7612 | //their id game id, maybe color? |
| 7613 | #ifdef RE_DEBUG |
| 7614 | qDebug("b5b3 size: %d", size); |
| 7615 | #endif //RE_DEBUG |
| 7616 | } |
| 7617 | |
| 7618 | //bfb3 |
| 7619 | void CyberOroConnection::handleAdjournDecline(unsigned char * msg, unsigned int size) |
| 7620 | { |
| 7621 | unsigned char * p = msg; |
| 7622 | if(size != 8) |
| 7623 | { |
| 7624 | qDebug("Adjourn decline of strange size: %d", size); |
| 7625 | } |
| 7626 | //unsigned short opponent_id = p[0] + (p[1] << 8); |
| 7627 | unsigned short game_code = p[2] + (p[3] << 8); |
| 7628 | unsigned short game_number = game_code_to_number[game_code]; |
| 7629 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_number); |
| 7630 | if(!boarddispatch) |
| 7631 | { |
| 7632 | qDebug("Received adjourn decline on nonexistent board"); |
| 7633 | return; |
| 7634 | } |
| 7635 | boarddispatch->recvRefuseAdjourn(); |
| 7636 | |
| 7637 | p += 2; |
| 7638 | //their id game id, maybe color? |
| 7639 | //5304 430d 0100 0071 |
| 7640 | #ifdef RE_DEBUG |
| 7641 | printf("0xbfb3 likely adjourn decline: "); |
| 7642 | for(int i = 0; i < (int)size; i++) |
| 7643 | printf("%02x", msg[i]); |
| 7644 | printf("\n"); |
| 7645 | |
| 7646 | qDebug("bfb3 size: %d", size); |
| 7647 | #endif //RE_DEBUG |
| 7648 | } |
| 7649 | |
| 7650 | //bab3 |
| 7651 | void CyberOroConnection::handleAdjourn(unsigned char * msg, unsigned int size) |
| 7652 | { |
| 7653 | unsigned char * p = msg; |
| 7654 | if(size != 8) |
| 7655 | { |
| 7656 | qDebug("Adjourn of strange size: %d", size); |
| 7657 | } |
| 7658 | //unsigned short opponent_id = p[0] + (p[1] << 8); |
| 7659 | unsigned short game_code = p[2] + (p[3] << 8); |
| 7660 | unsigned short game_number = game_code_to_number[game_code]; |
| 7661 | BoardDispatch * boarddispatch = getIfBoardDispatch(game_number); |
| 7662 | if(!boarddispatch) |
| 7663 | { |
| 7664 | qDebug("Received adjourn on nonexistent board"); |
| 7665 | return; |
| 7666 | } |
| 7667 | /* FIXME, why do we need to close the board dispatch, shouldn't |
| 7668 | * the adjournGame do that? or should it, maybe we can talk after? */ |
| 7669 | boarddispatch->adjournGame(); |
| 7670 | //connection->closeBoardDispatch(memory); |
| 7671 | #ifdef RE_DEBUG |
| 7672 | qDebug("bab3 size: %d", size); |
| 7673 | #endif //RE_DEBUG |
| 7674 | } |
| 7675 | |
| 7676 | /* This pops up in a short, maybe 10 - 30 second dialog that then automatically |
| 7677 | * declines. If you hit accept, then you go into the match offer dialog. |
| 7678 | * I'm not sure if we want to auto accept (if we're looking/open) and then |
| 7679 | * let the player decline from the settings if they want to? Or maybe that |
| 7680 | * would make the client appear rude and we should instead show a popup |
| 7681 | * for this message... which is a different sort of behavior to emulate... */ |
| 7682 | //2279 |
| 7683 | void CyberOroConnection::handleMatchInvite(unsigned char * msg, unsigned int size) |
| 7684 | { |
| 7685 | unsigned char * p = msg; |
| 7686 | if(size != 12) |
| 7687 | { |
| 7688 | qDebug("MatchInvite of size %d\n", size); |
| 7689 | // probably should print it out and exit FIXME |
| 7690 | } |
| 7691 | Room * room = getDefaultRoom(); |
| 7692 | PlayerListing * player = room->getPlayerListing(p[0] + (p[1] << 8)); |
| 7693 | //22 79 10 00 FC 08 27 00 00 08 09 00 00 00 00 7B |
| 7694 | p += 2; |
| 7695 | // the 00 08 is our id, 9 could be special byte but the 27 changes |
| 7696 | |
| 7697 | #ifdef RE_DEBUG |
| 7698 | printf("%s requests match %02x %02x %02x\n", player->name.toLatin1().constData(), p[0], p[1], p[4]); |
| 7699 | #endif //RE_DEBUG |
| 7700 | /* FIXME, I really don't think we want to auto accept. It puts one in |
| 7701 | * a special room And then if you go to observe after joining in |
| 7702 | * another game in progress, you leave the match room. */ |
| 7703 | /* FIXME blocks here right now because match_negotiation_state isn't properly reset */ |
| 7704 | if(!match_negotiation_state->newMatchAllowed()) |
| 7705 | return; |
| 7706 | |
| 7707 | MatchInviteDialog * mid = new MatchInviteDialog(player->name, player->rank); |
| 7708 | int mid_return = mid->exec(); |
| 7709 | |
| 7710 | if(mid_return == 1) |
| 7711 | sendMatchInvite(player, true); |
| 7712 | else if(mid_return == -1) |
| 7713 | sendDeclineMatchInvite(player); |
| 7714 | } |
| 7715 | |
| 7716 | //0x147d |
| 7717 | void CyberOroConnection::handleAcceptMatchInvite(unsigned char * msg, unsigned int size) |
| 7718 | { |
| 7719 | unsigned char * p = msg; |
| 7720 | if(size != 4) |
| 7721 | { |
| 7722 | qDebug("MatchInviteAccept of size %d\n", size); |
| 7723 | // probably should print it out and exit FIXME |
| 7724 | } |
| 7725 | PlayerListing * player = getDefaultRoom()->getPlayerListing(p[0] + (p[1] << 8)); |
| 7726 | if(!match_negotiation_state->sentMatchInvite()) |
| 7727 | return; |
| 7728 | if(!match_negotiation_state->verifyPlayer(player)) |
| 7729 | return; |
| 7730 | sendMatchOfferPending(player); |
| 7731 | |
| 7732 | #ifdef RE_DEBUG |
| 7733 | printf("0x147d: "); |
| 7734 | for(int i = 0; i < (int)size; i++) |
| 7735 | printf("%02x", msg[i]); |
| 7736 | printf("\n"); |
| 7737 | #endif //RE_DEBUG |
| 7738 | } |
| 7739 | |
| 7740 | //FIXME I suspect that the a479 is the match invite decline |
| 7741 | //but 0c2b is also a candidate |
| 7742 | //0xa479: 3e0d1c02ab0000ef |
| 7743 | //0x0c2b: 3e0d1c02ab0000ef |
| 7744 | |
| 7745 | //a479 |
| 7746 | void CyberOroConnection::handleDeclineMatchInvite(unsigned char * msg, unsigned int size) |
| 7747 | { |
| 7748 | unsigned char * p = msg; |
| 7749 | if(size != 8) |
| 7750 | { |
| 7751 | qDebug("MatchInviteDecline of size %d\n", size); |
| 7752 | // probably should print it out and exit FIXME |
| 7753 | } |
| 7754 | PlayerListing * player = getDefaultRoom()->getPlayerListing(p[0] + (p[1] << 8)); |
| 7755 | if(!match_negotiation_state->sentMatchInvite()) |
| 7756 | return; |
| 7757 | if(!match_negotiation_state->verifyPlayer(player)) |
| 7758 | return; |
| 7759 | match_negotiation_state->reset(); |
| 7760 | QMessageBox::information(0, tr("Invite declined"), tr("%1 has declined invitation").arg(player->name)); |
| 7761 | |
| 7762 | #ifdef RE_DEBUG |
| 7763 | printf("0xa479: "); |
| 7764 | for(int i = 0; i < (int)size; i++) |
| 7765 | printf("%02x", msg[i]); |
| 7766 | printf("\n"); |
| 7767 | #endif //RE_DEBUG |
| 7768 | } |
| 7769 | |
| 7770 | //0x1e7d |
| 7771 | void CyberOroConnection::handleMatchOfferPending(unsigned char * msg, unsigned int size) |
| 7772 | { |
| 7773 | /* What's the difference between this and the accept match invite? Any ?? */ |
| 7774 | /* This is the copyback of our own sendMatchOfferPending */ |
| 7775 | #ifdef RE_DEBUG |
| 7776 | printf("0x1e7d: "); |
| 7777 | for(int i = 0; i < (int)size; i++) |
| 7778 | printf("%02x", msg[i]); |
| 7779 | printf("\n"); |
| 7780 | #endif //RE_DEBUG |
| 7781 | //590c 2d07 00ae |
| 7782 | unsigned char * p = msg; |
| 7783 | if(size != 6) |
| 7784 | { |
| 7785 | qDebug("MatchRoomOpen of size %d\n", size); |
| 7786 | // probably should print it out and exit FIXME |
| 7787 | } |
| 7788 | if(msg[0] + (msg[1] << 8) != our_player_id) |
| 7789 | { |
| 7790 | /* Actually, could this be the game id? FIXME |
| 7791 | * But we ignore it if... no, see because below, we're using it |
| 7792 | * to open the game dialog offer... */ |
| 7793 | #ifdef RE_DEBUG |
| 7794 | /* Potentially this is regarding our opponent and we should also |
| 7795 | * have a standard way of printing out IDS FIXME */ |
| 7796 | qDebug("Received MatchRoomOpen for someone besides us %02x%02x", p[1], p[0]); |
| 7797 | #endif //RE_DEBUG |
| 7798 | return; |
| 7799 | } |
| 7800 | p += 2; |
| 7801 | PlayerListing * player = getDefaultRoom()->getPlayerListing(msg[2] + (msg[3] << 8)); |
| 7802 | p += 2; |
| 7803 | // no idea what this is |
| 7804 | //setRoomNumber(p[0] + (p[1] << 8)); |
| 7805 | |
| 7806 | if(!match_negotiation_state->sentMatchOfferPending()) |
| 7807 | return; |
| 7808 | if(!match_negotiation_state->verifyPlayer(player)) |
| 7809 | return; |
| 7810 | |
| 7811 | GameDialog * gd = getGameDialog(player); |
| 7812 | gd->recvRequest(0, getGameDialogFlags()); |
| 7813 | } |
| 7814 | |
| 7815 | /* The point of this is that we should clear out the observer lists |
| 7816 | * on rooms we leave, etc. */ |
| 7817 | void CyberOroConnection::setRoomNumber(unsigned short number) |
| 7818 | { |
| 7819 | if(room_were_in == number) |
| 7820 | return; |
| 7821 | if(room_were_in) |
| 7822 | { |
| 7823 | BoardDispatch * bd = getIfBoardDispatch(room_were_in); |
| 7824 | if(bd) |
| 7825 | bd->clearObservers(); |
| 7826 | } |
| 7827 | room_were_in = number; |
| 7828 | } |
| 7829 | |
| 7830 | /* There's also FIXME FIXME FIXME, |
| 7831 | * these massive 0x8129 messages at the start of the game, |
| 7832 | * looks like an opponents records or something... maybe a picture? |
| 7833 | * I have no idea. and a 0x7c29 right before it, short but who knows? |
| 7834 | * And then after an 0x8629, again, short. check "truegame" and "truegame2". |
| 7835 | * Actually wait, I think these are coming from after a game!! like result |
| 7836 | * messages. */ |
| 7837 | |
| 7838 | /* These needs to be more versatile later */ |
| 7839 | void CyberOroConnection::onReady(void) |
| 7840 | { |
| 7841 | //sendInvitationSettings(true); //for now |
| 7842 | qDebug("Ready!\n"); |
| 7843 | NetworkConnection::onReady(); |
| 7844 | } |
| 7845 | |
| 7846 | int CyberOroConnection::gd_verifyBoardSize(int v) |
| 7847 | { |
| 7848 | /* If game is ranked, has to be 19x19 but right now |
| 7849 | * game dialog has an old flag that sets that up */ |
| 7850 | if(v < 5) |
| 7851 | return 5; |
| 7852 | if(v > 13) |
| 7853 | return 19; |
| 7854 | if(v > 9) |
| 7855 | return 13; |
| 7856 | if(v > 7) |
| 7857 | return 9; |
| 7858 | if(v > 5) |
| 7859 | return 7; |
| 7860 | return v; |
| 7861 | } |
| 7862 | |
| 7863 | QTime CyberOroConnection::gd_checkMainTime(TimeSystem s, const QTime & t) |
| 7864 | { |
| 7865 | int seconds = (t.minute() * 60) + t.second(); |
| 7866 | switch(s) |
| 7867 | { |
| 7868 | case byoyomi: //korean |
| 7869 | if(t.hour() > 8 || (t.hour() == 8 && t.minute() > 20)) |
| 7870 | return QTime(8, 20, 0); |
| 7871 | else |
| 7872 | return QTime(t.hour(), t.minute(), 0); |
| 7873 | break; |
| 7874 | case canadian: |
| 7875 | if(t.hour() >= 1) |
| 7876 | return QTime(1, 0, 0); |
| 7877 | else |
| 7878 | return QTime(t.hour(), t.minute(), 0); |
| 7879 | case tvasia: |
| 7880 | if(t.minute() >= 5) |
| 7881 | return QTime(0, 5, 0); |
| 7882 | else |
| 7883 | { |
| 7884 | if(seconds % 10) |
| 7885 | seconds += (10 - (seconds % 10)); |
| 7886 | int minutes = seconds; |
| 7887 | seconds %= 60; |
| 7888 | minutes -= seconds; |
| 7889 | minutes /= 60; |
| 7890 | return QTime(0, minutes, seconds); |
| 7891 | } |
| 7892 | break; |
| 7893 | default: |
| 7894 | qDebug("unsupported CyberORO time type"); |
| 7895 | break; |
| 7896 | } |
| 7897 | return t; |
| 7898 | } |
| 7899 | |
| 7900 | QTime CyberOroConnection::gd_checkPeriodTime(TimeSystem s, const QTime & t) |
| 7901 | { |
| 7902 | int seconds = (t.minute() * 60) + t.second(); |
| 7903 | switch(s) |
| 7904 | { |
| 7905 | case byoyomi: |
| 7906 | if(t.minute() >= 1) |
| 7907 | return QTime(0, 1, 0); |
| 7908 | else |
| 7909 | { |
| 7910 | if(seconds % 10) |
| 7911 | seconds += (10 - (seconds % 10)); |
| 7912 | if(seconds == 60) |
| 7913 | return QTime(0, 1, 0); |
| 7914 | else |
| 7915 | return QTime(0, 0, seconds); |
| 7916 | } |
| 7917 | break; |
| 7918 | case canadian: |
| 7919 | if(t.hour() >= 1) |
| 7920 | return QTime(1, 0, 0); |
| 7921 | else if(t.minute() == 0) |
| 7922 | return QTime(0, 1, 0); |
| 7923 | else |
| 7924 | return QTime(t.hour(), t.minute(), 0); |
| 7925 | case tvasia: |
| 7926 | if(t.minute() >= 5) |
| 7927 | return QTime(0, 5, 0); |
| 7928 | else |
| 7929 | { |
| 7930 | if(seconds % 10) |
| 7931 | seconds += (10 - (seconds % 10)); |
| 7932 | int minutes = seconds; |
| 7933 | seconds %= 60; |
| 7934 | minutes -= seconds; |
| 7935 | minutes /= 60; |
| 7936 | return QTime(0, minutes, seconds); |
| 7937 | } |
| 7938 | break; |
| 7939 | default: |
| 7940 | qDebug("unsupported CyberORO time type"); |
| 7941 | break; |
| 7942 | } |
| 7943 | return t; |
| 7944 | } |
| 7945 | |
| 7946 | unsigned int CyberOroConnection::gd_checkPeriods(TimeSystem s, unsigned int p) |
| 7947 | { |
| 7948 | switch(s) |
| 7949 | { |
| 7950 | case byoyomi: |
| 7951 | if(p == 0) |
| 7952 | return 1; |
| 7953 | else if(p > 15) |
| 7954 | return 15; |
| 7955 | else |
| 7956 | return p; |
| 7957 | break; |
| 7958 | case canadian: |
| 7959 | if(p < 2) |
| 7960 | return 2; |
| 7961 | else if(p > 50) |
| 7962 | return 50; |
| 7963 | else |
| 7964 | return p; |
| 7965 | break; |
| 7966 | case tvasia: |
| 7967 | if(p == 0) |
| 7968 | return 1; |
| 7969 | else if(p > 10) |
| 7970 | return 10; |
| 7971 | else |
| 7972 | return p; |
| 7973 | break; |
| 7974 | default: |
| 7975 | qDebug("unsupported CyberORO time type"); |
| 7976 | break; |
| 7977 | } |
| 7978 | return p; |
| 7979 | } |
| 7980 | |
| 7981 | const char * CyberOroConnection::getCodecString(void) |
| 7982 | { |
| 7983 | return serverList[current_server_index]->codec; |
| 7984 | } |
| 7985 | |
| 7986 | QString CyberOroConnection::getPlaceString(void) |
| 7987 | { |
| 7988 | return "CyberOro: " + serverList[current_server_index]->name; |
| 7989 | } |
| 7990 | |
| 7991 | int CyberOroConnection::time_to_seconds(const QString & time) |
| 7992 | { |
| 7993 | QRegExp re = QRegExp("([0-9]{1,2}):([0-9]{1,2})"); |
| 7994 | int min, sec; |
| 7995 | |
| 7996 | if(re.indexIn(time) >= 0) |
| 7997 | { |
| 7998 | min = re.cap(1).toInt(); |
| 7999 | sec = re.cap(2).toInt(); |
| 8000 | } |
| 8001 | else |
| 8002 | { |
| 8003 | qDebug("Bad time string"); |
| 8004 | return 0xffff; |
| 8005 | } |
| 8006 | |
| 8007 | return (60 * min) + sec; |
| 8008 | } |