home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / vmsnet / sources / games / 453 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  14.4 KB

  1. Path: sparky!uunet!cs.utexas.edu!usc!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!bcsystems!spruce.pfc.forestry.ca!news.u.washington.edu!raven.alaska.edu!acad2.alaska.edu!asdmf
  2. Newsgroups: vmsnet.sources.games
  3. Subject: Vmsnetrek 41/47
  4. Message-ID: <1992Nov20.205601.1@acad2.alaska.edu>
  5. From: asdmf@acad2.alaska.edu
  6. Date: Sat, 21 Nov 1992 00:56:01 GMT
  7. Sender: news@raven.alaska.edu (USENET News System)
  8. Organization: University of Alaska
  9. Nntp-Posting-Host: acad2.alaska.edu
  10. Lines: 522
  11.  
  12. -+-+-+-+-+-+-+-+ START OF PART 41 -+-+-+-+-+-+-+-+
  13. X    struct tractor_cpacket tractorReq;
  14. X
  15. X    tractorReq.type=CP_TRACTOR;
  16. X    tractorReq.state=state;
  17. X    tractorReq.pnum=pnum;
  18. X    sendServerPacket(&tractorReq);
  19. X
  20. X    if (state)
  21. X`009fTractor = pnum `124 0x40;
  22. X    else
  23. X`009fTractor = 0;
  24. X`125
  25. X
  26. XsendRepressReq(state, pnum)
  27. Xchar state;
  28. Xchar pnum;
  29. X`123
  30. X    struct repress_cpacket repressReq;
  31. X
  32. X    repressReq.type=CP_REPRESS;
  33. X    repressReq.state=state;
  34. X    repressReq.pnum=pnum;
  35. X    sendServerPacket(&repressReq);
  36. X
  37. X    if (state)
  38. X`009fRepress = pnum `124 0x40;
  39. X    else
  40. X`009fRepress = 0;
  41. X`125
  42. X
  43. XsendDetMineReq(torp)
  44. Xshort torp;
  45. X`123
  46. X    struct det_mytorp_cpacket detReq;
  47. X
  48. X    detReq.type=CP_DET_MYTORP;
  49. X    detReq.tnum=htons(torp);
  50. X    sendServerPacket(&detReq);
  51. X`125
  52. X
  53. XhandlePlasmaInfo(packet)
  54. Xstruct plasma_info_spacket *packet;
  55. X`123
  56. X    struct plasmatorp *thetorp;
  57. X
  58. X    thetorp= &plasmatorps`091ntohs(packet->pnum)`093;
  59. X    if (packet->status == PTEXPLODE && thetorp->pt_status == PTFREE) `123
  60. X`009/* FAT: redundant explosion; don't update p_nplasmatorp */
  61. X`009return;
  62. X    `125
  63. X    if (!thetorp->pt_status && packet->status) `123
  64. X`009players`091thetorp->pt_owner`093.p_nplasmatorp++;
  65. X    `125
  66. X    if (thetorp->pt_status && !packet->status) `123
  67. X`009players`091thetorp->pt_owner`093.p_nplasmatorp--;
  68. X    `125
  69. X    thetorp->pt_war=packet->war;
  70. X    if (thetorp->pt_status != packet->status) `123
  71. X`009/* FAT: prevent explosion timer from being reset */
  72. X`009thetorp->pt_status=packet->status;
  73. X`009if (thetorp->pt_status == PTEXPLODE) `123
  74. X`009    thetorp->pt_fuse=NUMDETFRAMES;
  75. X`009`125
  76. X    `125
  77. X`125
  78. X
  79. XhandlePlasma(packet)
  80. Xstruct plasma_spacket *packet;
  81. X`123
  82. X    struct plasmatorp *thetorp;
  83. X
  84. X    thetorp= &plasmatorps`091ntohs(packet->pnum)`093;
  85. X    thetorp->pt_x=ntohl(packet->x);
  86. X    thetorp->pt_y=ntohl(packet->y);
  87. X`125
  88. X
  89. XhandleFlags(packet)
  90. Xstruct flags_spacket *packet;
  91. X`123
  92. X    if (players`091packet->pnum`093.p_flags != ntohl(packet->flags) `124`124
  93. X`009players`091packet->pnum`093.p_tractor != ((short)packet->tractor & (`126
  94. V0x40)))`123
  95. X`009/* FAT: prevent redundant player update */
  96. X
  97. X`009redrawPlayer`091packet->pnum`093=1;
  98. X    `125
  99. X
  100. X    players`091packet->pnum`093.p_flags=ntohl(packet->flags);
  101. X#ifdef INCLUDE_VISTRACT
  102. X    if (packet->tractor & 0x40)
  103. X`009players`091packet->pnum`093.p_tractor=(short) packet->tractor & (`1260x4
  104. V0); /* ATM - visible tractors */
  105. X    else
  106. X#endif
  107. X`009players`091packet->pnum`093.p_tractor = -1;
  108. X    /*redrawPlayer`091packet->pnum`093=1;*/
  109. X`125
  110. X
  111. XhandleKills(packet)
  112. Xstruct kills_spacket *packet;
  113. X`123
  114. X    if (players`091packet->pnum`093.p_kills != ntohl(packet->kills)/100.0) `
  115. V123
  116. X`009/* FAT: prevent redundant player update */
  117. X`009players`091packet->pnum`093.p_kills=ntohl(packet->kills)/100.0;
  118. X`009updatePlayer`091packet->pnum`093=1;
  119. X    `125
  120. X`125
  121. X
  122. XhandlePStatus(packet)
  123. Xstruct pstatus_spacket *packet;
  124. X`123
  125. X    if (packet->status==PEXPLODE) `123
  126. X`009players`091packet->pnum`093.p_explode=0;
  127. X    `125
  128. X    /* Ignore DEAD status.
  129. X     * Instead, we treat it as PEXPLODE.
  130. X     * This gives us time to animate all the frames necessary for`032
  131. X     *  the explosions at our own pace.
  132. X     */
  133. X    if (packet->status==PDEAD) `123
  134. X`009packet->status=PEXPLODE;
  135. X    `125
  136. X    players`091packet->pnum`093.p_status=packet->status;
  137. X    redrawPlayer`091packet->pnum`093=1;
  138. X    updatePlayer`091packet->pnum`093=1;
  139. X`125
  140. X
  141. XhandleMotd(packet)
  142. Xstruct motd_spacket *packet;
  143. X`123
  144. X    newMotdLine(packet->line);
  145. X`125
  146. X
  147. XsendMessage(mes, group, indiv)
  148. Xchar *mes;
  149. Xint group, indiv;
  150. X`123
  151. X    struct mesg_cpacket mesPacket;
  152. X
  153. X    mesPacket.type=CP_MESSAGE;
  154. X    mesPacket.group=group;
  155. X    mesPacket.indiv=indiv;
  156. X    strcpy(mesPacket.mesg, mes);
  157. X    sendServerPacket(&mesPacket);
  158. X`125
  159. X
  160. XhandleMask(packet)
  161. Xstruct mask_spacket *packet;
  162. X`123
  163. X    tournMask=packet->mask;
  164. X`125
  165. X
  166. XsendOptionsPacket()
  167. X`123
  168. X    struct options_cpacket optPacket;
  169. X
  170. X    optPacket.type=CP_OPTIONS;
  171. X    optPacket.flags =`032
  172. X`009htonl(ST_MAPMODE * (mapmode!=0) +
  173. X`009ST_NAMEMODE * namemode +
  174. X`009ST_SHOWSHIELDS * showShields +
  175. X`009ST_KEEPPEACE * keeppeace +`032
  176. X`009ST_SHOWLOCAL * showlocal +
  177. X`009ST_SHOWGLOBAL * showgalactic);
  178. X    bcopy(mystats->st_keymap, optPacket.keymap, 96);
  179. X    sendServerPacket(&optPacket);
  180. X`125
  181. X
  182. XpickSocket(old)
  183. Xint old;
  184. X`123
  185. X    int newsocket;
  186. X    struct socket_cpacket sockPack;
  187. X
  188. X    newsocket=(getpid() & 32767);
  189. X    while (newsocket < 2048 `124`124 newsocket==old) `123
  190. X`009newsocket=(newsocket + 10687) & 32767;
  191. X    `125
  192. X    sockPack.type=CP_SOCKET;
  193. X    sockPack.socket=htonl(newsocket);
  194. X    sockPack.version=(char) SOCKVERSION;
  195. X    sockPack.udp_version=(char) UDPVERSION;
  196. X    sendServerPacket(&sockPack);
  197. X    /* Did we get new socket # sent? */
  198. X    if (serverDead) return;
  199. X    nextSocket=newsocket;
  200. X`125
  201. X
  202. XhandleBadVersion(packet)
  203. Xstruct badversion_spacket *packet;
  204. X`123
  205. X    switch(packet->why) `123
  206. X    case 0:
  207. X`009printf("Sorry, this is an invalid client version.\n");
  208. X`009printf("You need a new version of the client code.\n");
  209. X`009break;
  210. X    default:
  211. X`009printf("Sorry, but you cannot play xtrek now.\n");
  212. X`009printf("Try again later.\n");
  213. X`009break;
  214. X    `125
  215. X    exit(1);
  216. X`125
  217. X
  218. Xgwrite(fd, buf, bytes)
  219. Xint fd;
  220. Xchar *buf;
  221. Xregister int bytes;
  222. X`123
  223. X    long orig = bytes;
  224. X    register long n;
  225. X    while (bytes) `123
  226. X        n = send(fd, buf, bytes,0);
  227. X        if (n < 0) `123
  228. X            if (fd == udpSock) `123
  229. X                fprintf(stderr, "Tried to write %d, 0x%x, %d (error %d)\n",
  230. X                    fd, buf, bytes, errno);
  231. X                printUdpInfo();
  232. X            `125
  233. X`009    printf("fd=%d\n", fd);
  234. X            perror("reason gwrite failed");
  235. X            return(-1);
  236. X        `125
  237. X        bytes -= n;
  238. X        buf += n;
  239. X    `125
  240. X    return(orig);
  241. X`125
  242. X
  243. XhandleHostile(packet)
  244. Xstruct hostile_spacket *packet;
  245. X`123
  246. X    register struct player *pl;
  247. X
  248. X    pl= &players`091packet->pnum`093;
  249. X    if (pl->p_swar != packet->war `124`124
  250. X`009pl->p_hostile != packet->hostile) `123
  251. X`009/* FAT: prevent redundant player update & redraw */
  252. X`009updatePlayer`091packet->pnum`093=1;
  253. X`009pl->p_swar=packet->war;
  254. X`009pl->p_hostile=packet->hostile;
  255. X`009redrawPlayer`091packet->pnum`093=1;
  256. X    `125
  257. X`125
  258. X
  259. XhandlePlyrLogin(packet)
  260. Xstruct plyr_login_spacket *packet;
  261. X`123
  262. X    register struct player *pl;
  263. X
  264. X    updatePlayer`091packet->pnum`093=1;
  265. X    pl= &players`091packet->pnum`093;
  266. X
  267. X    strcpy(pl->p_name, packet->name);
  268. X    strcpy(pl->p_monitor, packet->monitor);
  269. X    strcpy(pl->p_login, packet->login);
  270. X    pl->p_stats.st_rank=packet->rank;
  271. X    if (packet->pnum == me->p_no) `123
  272. X`009/* This is me.  Set some stats */
  273. X`009if (lastRank== -1) `123
  274. X`009    if (loggedIn) `123
  275. X`009`009lastRank=packet->rank;
  276. X`009    `125
  277. X`009`125 else `123
  278. X`009    if (lastRank != packet->rank) `123
  279. X`009`009lastRank=packet->rank;
  280. X`009`009promoted=1;
  281. X`009    `125
  282. X`009`125
  283. X    `125
  284. X`125
  285. X
  286. XhandleStats(packet)
  287. Xstruct stats_spacket *packet;
  288. X`123
  289. X    register struct player *pl;
  290. X
  291. X    updatePlayer`091packet->pnum`093=1;
  292. X    pl= &players`091packet->pnum`093;
  293. X    pl->p_stats.st_tkills=ntohl(packet->tkills);
  294. X    pl->p_stats.st_tlosses=ntohl(packet->tlosses);
  295. X    pl->p_stats.st_kills=ntohl(packet->kills);
  296. X    pl->p_stats.st_losses=ntohl(packet->losses);
  297. X    pl->p_stats.st_tticks=ntohl(packet->tticks);
  298. X    pl->p_stats.st_tplanets=ntohl(packet->tplanets);
  299. X    pl->p_stats.st_tarmsbomb=ntohl(packet->tarmies);
  300. X    pl->p_stats.st_sbkills=ntohl(packet->sbkills);
  301. X    pl->p_stats.st_sblosses=ntohl(packet->sblosses);
  302. X    pl->p_stats.st_armsbomb=ntohl(packet->armies);
  303. X    pl->p_stats.st_planets=ntohl(packet->planets);
  304. X    pl->p_stats.st_maxkills=ntohl(packet->maxkills) / 100.0;
  305. X    pl->p_stats.st_sbmaxkills=ntohl(packet->sbmaxkills) / 100.0;
  306. X`125
  307. X
  308. XhandlePlyrInfo(packet)
  309. Xstruct plyr_info_spacket *packet;
  310. X`123
  311. X    register struct player *pl;
  312. X    static int lastship= -1;
  313. X
  314. X    updatePlayer`091packet->pnum`093=1;
  315. X    pl= &players`091packet->pnum`093;
  316. X    getship(&pl->p_ship, packet->shiptype);
  317. X    pl->p_team=packet->team;
  318. X    pl->p_mapchars`0910`093=teamlet`091pl->p_team`093;
  319. X    pl->p_mapchars`0911`093=shipnos`091pl->p_no`093;
  320. X    if (me==pl && lastship!=me->p_ship.s_type) `123
  321. X`009calibrate_stats();
  322. X`009redrawTstats();
  323. X    `125
  324. X    redrawPlayer`091packet->pnum`093=1;
  325. X`125
  326. X
  327. XsendUpdatePacket(speed)
  328. Xlong speed;
  329. X`123
  330. X    struct updates_cpacket packet;
  331. X
  332. X    packet.type=CP_UPDATES;
  333. X    timerDelay=speed;
  334. X    packet.usecs=htonl(speed);
  335. X    sendServerPacket(&packet);
  336. X`125
  337. X
  338. XhandlePlanetLoc(packet)
  339. Xstruct planet_loc_spacket *packet;
  340. X`123
  341. X    struct planet *pl;
  342. X
  343. X    pl= &planets`091packet->pnum`093;
  344. X    pl->pl_x=ntohl(packet->x);
  345. X    pl->pl_y=ntohl(packet->y);
  346. X    strcpy(pl->pl_name, packet->name);
  347. X    pl->pl_namelen=strlen(packet->name);
  348. X    pl->pl_flags`124=PLREDRAW;
  349. X    reinitPlanets=1;
  350. X`125
  351. X
  352. XhandleReserved(packet)
  353. Xstruct reserved_spacket *packet;
  354. X`123
  355. X    struct reserved_cpacket response;
  356. X
  357. X    encryptReservedPacket(packet, &response, serverName, me->p_no);
  358. X    sendServerPacket(&response);
  359. X`125
  360. X
  361. X#ifdef INCLUDE_SCAN
  362. XhandleScan(packet)
  363. Xstruct scan_spacket *packet;
  364. X`123
  365. X    struct player *pp;
  366. X
  367. X    if (packet->success) `123
  368. X`009pp = &players`091packet->pnum`093;
  369. X`009pp->p_fuel = ntohl(packet->p_fuel);
  370. X`009pp->p_armies = ntohl(packet->p_armies);
  371. X`009pp->p_shield = ntohl(packet->p_shield);
  372. X`009pp->p_damage = ntohl(packet->p_damage);
  373. X`009pp->p_etemp = ntohl(packet->p_etemp);
  374. X`009pp->p_wtemp = ntohl(packet->p_wtemp);
  375. X`009informScan(packet->pnum);
  376. X    `125
  377. X`125
  378. X#endif
  379. X
  380. X/*
  381. X * -------------------------------------------------------------------------
  382. V--
  383. X *`009UDP stuff from here on
  384. X * -------------------------------------------------------------------------
  385. V--
  386. X */
  387. X
  388. XsendUdpReq(req)
  389. Xint req;
  390. X`123
  391. X    struct udp_req_cpacket packet;
  392. X
  393. X    packet.type = CP_UDP_REQ;
  394. X    packet.request = req;
  395. X
  396. X    if (req >= COMM_MODE) `123
  397. X`009packet.request = COMM_MODE;
  398. X`009packet.connmode = req - COMM_MODE;
  399. X`009sendServerPacket(&packet);
  400. X`009return;
  401. X    `125
  402. X
  403. X    if (req == COMM_UPDATE) `123
  404. X`009sendServerPacket(&packet);
  405. X`009warning("Sent request for full update");
  406. X`009return;
  407. X    `125
  408. X
  409. X    /*
  410. X     * Past this point, req had better be COMM_TCP or COMM_UDP.
  411. X     */
  412. X
  413. X    if (req == commModeReq) `123
  414. X`009warning("Request is in progress, do not disturb");
  415. X`009return;
  416. X    `125
  417. X
  418. X    if (req == COMM_UDP) `123
  419. X`009/* open UDP port */
  420. X`009if (openUdpConn() >= 0) `123
  421. X`009    UDPDIAG(("Bound to local port %d on fd %d\n",udpLocalPort,udpSock));
  422. X`009`125 else `123
  423. X`009    UDPDIAG(("Bind to local port %d failed\n", udpLocalPort));
  424. X`009    commModeReq = COMM_TCP;
  425. X`009    commStatus = STAT_CONNECTED;
  426. X`009    commSwitchTimeout = 0;
  427. X`009    if (udpWin)
  428. X`009`009udprefresh(UDP_STATUS);
  429. X`009    warning("Unable to establish UDP connection");
  430. X
  431. X`009    return;
  432. X`009`125
  433. X    `125
  434. X
  435. X    /* send the request */
  436. X    packet.port = htonl(udpLocalPort);
  437. X#ifdef GATEWAY
  438. X    if (!strcmp(serverName, gw_mach)) `123
  439. X`009packet.port = htons(gw_serv_port); /* gw port that server should call */
  440. X`009UDPDIAG(("+ Telling server to contact us on %d\n", gw_serv_port));
  441. X    `125
  442. X#endif
  443. X#ifdef USE_PORTSWAP
  444. X    packet.connmode = CONNMODE_PORT;`009`009/* have him send his port */
  445. X#else
  446. X    packet.connmode = CONNMODE_PACKET;`009`009/* we get addr from packet */
  447. X#endif
  448. X    sendServerPacket(&packet);
  449. X
  450. X    /* update internal state stuff */
  451. X    commModeReq = req;
  452. X    if (req == COMM_TCP)
  453. X`009commStatus = STAT_SWITCH_TCP;
  454. X    else
  455. X`009commStatus = STAT_SWITCH_UDP;
  456. X    commSwitchTimeout = 25;`009/* wait 25 updates (about five seconds) */
  457. X    UDPDIAG(("Sent request for %s mode\n", (req == COMM_TCP) ?
  458. X`009"TCP" : "UDP"));
  459. X
  460. X#ifndef USE_PORTSWAP
  461. X    if ((req == COMM_UDP) && recvUdpConn() < 0) `123
  462. X`009UDPDIAG(("Sending TCP reset message\n"));
  463. X`009packet.request = COMM_TCP;
  464. X`009packet.port = 0;
  465. X`009commModeReq = COMM_TCP;
  466. X`009sendServerPacket(&packet);
  467. X`009/* we will likely get a SWITCH_UDP_OK later; better ignore it */
  468. X`009commModeReq = COMM_TCP;
  469. X`009commStatus = STAT_CONNECTED;
  470. X`009commSwitchTimeout = 0;
  471. X    `125
  472. X#endif
  473. X
  474. X    if (udpWin)
  475. X`009udprefresh(UDP_STATUS);
  476. X`125
  477. X
  478. XhandleUdpReply(packet)
  479. Xstruct udp_reply_spacket *packet;
  480. X`123
  481. X    struct udp_req_cpacket response;
  482. X
  483. X    UDPDIAG(("Received UDP reply %d\n", packet->reply));
  484. X    commSwitchTimeout = 0;
  485. X
  486. X    response.type = CP_UDP_REQ;
  487. X
  488. X    switch (packet->reply) `123
  489. X    case SWITCH_TCP_OK:
  490. X`009if (commMode == COMM_TCP) `123
  491. X`009    UDPDIAG(("Got SWITCH_TCP_OK while in TCP mode; ignoring\n"));
  492. X`009`125 else `123
  493. X`009    commMode = COMM_TCP;
  494. X`009    commStatus = STAT_CONNECTED;
  495. X`009    warning("Switched to TCP-only connection");
  496. X`009    closeUdpConn();
  497. X`009    UDPDIAG(("UDP port closed\n"));
  498. X`009    if (udpWin) `123
  499. X`009`009udprefresh(UDP_STATUS);
  500. X`009`009udprefresh(UDP_CURRENT);
  501. X`009    `125
  502. X`009`125
  503. X`009break;
  504. X    case SWITCH_UDP_OK:
  505. X`009if (commMode == COMM_UDP) `123
  506. X`009    UDPDIAG(("Got SWITCH_UDP_OK while in UDP mode; ignoring\n"));
  507. X`009`125 else `123
  508. X`009    /* the server is forcing UDP down our throat? */
  509. X`009    if (commModeReq != COMM_UDP) `123
  510. X`009`009UDPDIAG(("Got unsolicited SWITCH_UDP_OK; ignoring\n"));
  511. X`009    `125 else `123
  512. X#ifdef USE_PORTSWAP
  513. X`009`009udpServerPort = ntohl(packet->port);
  514. X`009`009if (connUdpConn() < 0) `123
  515. X`009`009    UDPDIAG(("Unable to connect, resetting\n"));
  516. X`009`009    warning("Connection attempt failed");
  517. X`009`009    commModeReq = COMM_TCP;
  518. X`009`009    commStatus = STAT_CONNECTED;
  519. X`009`009    if (udpSock >= 0)
  520. X`009`009`009closeUdpConn(udpSock);
  521. X`009`009    if (udpWin) `123
  522. X`009`009`009udprefresh(UDP_STATUS);
  523. X`009`009`009udprefresh(UDP_CURRENT);
  524. X`009`009    `125
  525. X`009`009    response.request = COMM_TCP;
  526. X`009`009    response.port = 0;
  527. X`009`009    goto send;
  528. X`009`009`125
  529. X#else
  530. X`009`009/* this came down UDP, so we MUST be connected */
  531. X`009`009/* (do the verify thing anyway just for kicks) */
  532. X#endif
  533. +-+-+-+-+-+-+-+-  END  OF PART 41 +-+-+-+-+-+-+-+-
  534.