- InitScreens();
- while(!done) {
- if (robotEnable)
- InitRobot(robotProg);
- InitNet();
- if (!initSeed)
- SRandom(time(0));
- if (initConn || waitConn) {
- game = GT_classicTwo;
- if(gameState != STATE_STARTING) {
- gameState = STATE_WAIT_CONNECTION;
- ShowDisplayInfo();
- RefreshScreen();
- }
- if (initConn)
- InitiateConnection(hostStr, portStr);
- else if (waitConn)
- WaitForConnection(portStr);
- gameState = STATE_PLAYING;
- ShowDisplayInfo();
- RefreshScreen();
- {
- netint4 data[2];
- int major;
-
- data[0] = hton4(MAJOR_VERSION);
- data[1] = hton4(PROTOCOL_VERSION);
- SendPacket(NP_version, sizeof(data), data);
- if (WaitMyEvent(&event, EM_net) != E_net)
- fatal("Network negotiation failed");
- memcpy(data, event.u.net.data, sizeof(data));
- major = ntoh4(data[0]);
- protocolVersion = ntoh4(data[1]);
- if (event.u.net.type != NP_version || major < MAJOR_VERSION)
- fatal("Your opponent is using an old, incompatible version\n"
- "of Netris. They should get the latest version.");
- if (major > MAJOR_VERSION)
- fatal("Your opponent is using an newer, incompatible version\n"
- "of Netris. Get the latest version.");
- if (protocolVersion > PROTOCOL_VERSION)
- protocolVersion = PROTOCOL_VERSION;
- }
- if (protocolVersion < 3 && stepDownInterval != DEFAULT_INTERVAL)
- fatal("Your opponent's version of Netris predates the -i option.\n"
- "For fairness, you shouldn't use the -i option either.");
- {
- netint4 data[3];
- int len;
- int seed;
-
- if (protocolVersion >= 3)
- len = sizeof(data);
- else
- len = sizeof(netint4[2]);
- if ((myFlags & SCF_setSeed))
- seed = initSeed;
- else
- seed = time(0);
- if (waitConn)
- SRandom(seed);
- data[0] = hton4(myFlags);
- data[1] = hton4(seed);
- data[2] = hton4(stepDownInterval);
- SendPacket(NP_startConn, len, data);
- if (WaitMyEvent(&event, EM_net) != E_net ||
- event.u.net.type != NP_startConn)
- fatal("Network negotiation failed");
- memcpy(data, event.u.net.data, len);
- opponentFlags = ntoh4(data[0]);
- seed = ntoh4(data[1]);
- if (initConn) {
- if ((opponentFlags & SCF_setSeed) != (myFlags & SCF_setSeed))
- fatal("If one player sets the random number seed, "
- "both must.");
- if ((myFlags & SCF_setSeed) && seed != initSeed)
- fatal("Both players have set the random number seed, "
- "and they are unequal.");
- if (protocolVersion >= 3 && stepDownInterval != ntoh4(data[2]))
- fatal("Your opponent is using a different step-down "
- "interval (-i).\nYou must both use the same one.");
- SRandom(seed);
- }
- }
- {
- char *userName;
- int len, i;