Pararena2/Sources/NetOpponent.c

1 line
23 KiB
C
Raw Normal View History

/*============================================================*/ /*============================================================*/ /*== ==*/ /*== Net Opponent Handling Routines ==*/ /*== ==*/ /*============================================================*/ /*============================================================*/ /*======================================================== Includes */ #include "Globals.h" #include "UnivUtilities.h" #include "AppleTalkDDP.h" #include "NetOpponent.h" #include "AnimCursor.h" #include "SoundUtils.h" #include "PlayUtils.h" #include "Replay.h" #include "Render.h" /*======================================================== Functions */ /*======================================================== SendSynchPulse */ OSErr SendSynchPulse (void) { OSErr netErr; short helloMessage; helloMessage = kHelloIndicator; netErr = SendOutgoingDDP((long)&helloMessage, 2); return (netErr); } /*======================================================== SendThisEnvironment */ OSErr SendThisEnvironment (void) { environMessage thisMessage; OSErr theErr; thisMessage.speed = speedFlag; thisMessage.version = kNetworkVersion; thisMessage.arena = arenaSize; thisMessage.goal = thePlayer.whichGoal; thisMessage.spotPts = spotPoints; thisMessage.league = isLeague; thisMessage.scoredLast = leftScoredLast; thisMessage.limited = netOnly; theErr = SendOutgoingDDP((long)&thisMessage, kEnviroMessageSize); return(theErr); } /*======================================================== BegForSomething */ OSErr BegForSomething (short anythingLove) { requestMessage requestor; OSErr theErr; requestor.requested = anythingLove; requestor.firstArgument = 0; requestor.secondArgument = 0; theErr = SendOutgoingDDP((long)&requestor, kRequestSize); return (theErr); } /*======================================================== WaitForSynch */ Boolean WaitForSynch (short timeOut) { long imVeryBored, dummyLong; OSErr theErr; short helloMessage, replyMessage; Boolean iHearYou; replyMessage = 0; dummyLong = 0; iHearYou = FALSE; imVeryBored = Ticks + timeOut; theErr = RequestReceiveDDP(); while ((Ticks < imVeryBored) && (!iHearYou)) { IncrementCursor(); theErr = PollSpecificDDP((long)&replyMessage, 2, 3); if (CommandPeriodDown()) break; if ((theErr == noErr) && (replyMessage == kHelloIndicator)) { iHearYou = TRUE; Delay(4, &dummyLong); } else if (theErr == kNetErrWrongSize) { if (lastByteCount == kRequestSize) { if (firstPackageShort == kRequestEnvironment) theErr = SendThisEnvironment(); else theErr = BegForSomething(kGotYourEnvironment); } else if (lastByteCount == kEnviroMessageSize) { theErr = BegForSomething(kGotYourEnvironment); } } SendSynchPulse(); } InitCursor(); return (iHearYou); } /*======================================================== ConfirmEnvironmentMatch */ Boolean ConfirmEnvironmentMatch (void) { environMessage theirMessage; long timeToBail; OSErr theErr; Boolean confirmed, needEnviron, sheSaysOkay, sheWants; theirMessage.speed = 0L; theirMessage.version = 0; theirMessage.arena = -1; theirMessage.goal = -1; theirMessage.spotPts = 0; theirMessage.league = 0; theirMessage.scoredLast = !leftScoredLast; theirMessage.limited = TRUE; theErr = RequestReceiveDDP(); timeToBail = Ticks + 3600; confirmed = FALSE; sheSaysOkay = FALSE; sheWants = FALSE; needEnviron = TRUE; theErr = BegForSomething(kRequestEnvironment); while ((!confirmed) && (Ticks < timeToBail)) { IncrementCursor(); if (CommandPeriodDown()) timeToBail = Ticks; theErr = PollSpecificDDP((long)&theirMessage, kEnviroMessageSize, 2); if (theErr == noErr) { needEnviron = FALSE; } else if ((theErr == kNetErrWrongSize) && (lastByteCount == kRequestSize)) { if (firstPackageShort == kRequestEnvironment) { sheWants = TRUE; } else if (firstPackageShort == kGotYourEnvironment) {