home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / vmsnet / sources / games / 452 < 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 40/47
  4. Message-ID: <1992Nov20.205011.1@acad2.alaska.edu>
  5. From: asdmf@acad2.alaska.edu
  6. Date: Sat, 21 Nov 1992 00:50:11 GMT
  7. Sender: news@raven.alaska.edu (USENET News System)
  8. Organization: University of Alaska
  9. Nntp-Posting-Host: acad2.alaska.edu
  10. Lines: 481
  11.  
  12. -+-+-+-+-+-+-+-+ START OF PART 40 -+-+-+-+-+-+-+-+
  13. X    /* if switching comm mode, decrement timeout counter */
  14. X    if (commSwitchTimeout > 0) `123
  15. X/*`009printf("commSwitchTimeout = %d\n", commSwitchTimeout);*/
  16. X`009if (!(--commSwitchTimeout)) `123
  17. X`009    /*
  18. X`009     * timed out; could be initial request to non-UDP server (which
  19. X`009     * won't be answered), or the verify packet got lost en route
  20. X`009     * to the server.  Could also be a request for TCP which timed
  21. X`009     * out (weird), in which case we just reset anyway.
  22. X`009     */
  23. X`009    commModeReq = commMode = COMM_TCP;
  24. X`009    commStatus = STAT_CONNECTED;
  25. X`009    if (udpSock >= 0)
  26. X`009`009closeUdpConn();
  27. X`009    if (udpWin) `123
  28. X`009`009udprefresh(UDP_CURRENT);
  29. X`009`009udprefresh(UDP_STATUS);
  30. X`009    `125
  31. X`009    warning("Timed out waiting for UDP response from server");
  32. X`009    UDPDIAG(("Timed out waiting for UDP response from server\n"));
  33. X`009`125
  34. X    `125
  35. X
  36. X    /* if we're in a UDP "force" mode, check to see if we need to do somethi
  37. Vng*/
  38. X    if (commMode == COMM_UDP && udpClientSend > 1)
  39. X`009checkForce();
  40. X
  41. X         `032
  42. X    return (retval != 0);`009`009/* convert to 1/0 */
  43. X`125
  44. X
  45. X/* this used to be part of the routine above */
  46. Xchar buf`091BUFSIZ*2`093;
  47. XdoRead(asock)
  48. Xint asock;
  49. X`123
  50. X    struct timeval timeout;
  51. X    fd_set readfds;
  52. X    char *bufptr;
  53. X    int size;
  54. X    int count;
  55. X    int temp;
  56. X
  57. X    timeout.tv_sec=0;
  58. X    timeout.tv_usec=0;
  59. X
  60. X`009count=recv(asock,buf,2*BUFSIZ,0);
  61. X`009if (count<=0) `123
  62. X/*`009    printf("asock=%d, sock=%d, udpSock=%d, errno=%d\n",
  63. X`009`009asock, sock, udpSock, errno);*/
  64. X`009    if (asock == udpSock) `123
  65. X`009`009if (errno == ECONNREFUSED) `123
  66. X`009`009    struct sockaddr_in addr;
  67. X
  68. X`009`009    UDPDIAG(("Hiccup(%d)!  Reconnecting\n", errno));
  69. X`009`009    addr.sin_addr.s_addr = serveraddr;
  70. X`009`009    addr.sin_port = htons(udpServerPort);
  71. X`009`009    addr.sin_family = AF_INET;
  72. X`009`009    if (connect(udpSock, &addr, sizeof(addr)) < 0) `123
  73. X`009`009`009perror("connect");
  74. X`009`009`009UDPDIAG(("Unable to reconnect\n"));
  75. X`009`009`009/* and fall through to disconnect */
  76. X`009`009    `125 else `123
  77. X`009`009`009UDPDIAG(("Reconnect successful\n"));
  78. X`009`009`009return (0);
  79. X`009`009    `125
  80. X`009`009`125
  81. X
  82. X`009`009UDPDIAG(("*** UDP disconnected (res=%d, err=%d)\n",
  83. X`009`009`009count, errno));
  84. X`009`009warning("UDP link severed");
  85. X`009`009printUdpInfo();
  86. X`009`009closeUdpConn();
  87. X`009`009commMode = commModeReq = COMM_TCP;
  88. X`009`009commStatus = STAT_CONNECTED;
  89. X`009`009if (udpWin) `123
  90. X`009`009    udprefresh(UDP_STATUS);
  91. X`009`009    udprefresh(UDP_CURRENT);
  92. X`009`009`125
  93. X`009`009return (0);
  94. X`009    `125
  95. X`009    printf("1) Got read() of %d (err=%d). Server dead\n", count, errno);
  96. X`009    serverDead=1;
  97. X`009    return(0);
  98. X`009`125
  99. X
  100. X`009bufptr=buf;
  101. X`009while (bufptr < buf+count) `123
  102. X`009    if (*bufptr < 1 `124`124 *bufptr > NUM_PACKETS `124`124 handlers`091
  103. V*bufptr`093.size == 0) `123
  104. X`009`009printf("Unknown packet type: %d, aborting...\n", *bufptr);
  105. X`009`009return(0);
  106. X`009    `125
  107. X`009    size=handlers`091*bufptr`093.size;
  108. X`009    while (size>count+(buf-bufptr)) `123
  109. X`009`009/* We wait for up to ten seconds for rest of packet.
  110. X`009`009 * If we don't get it, we assume the server died.`032
  111. X`009`009 */
  112. X`009`009timeout.tv_sec=20;
  113. X`009`009timeout.tv_usec=0;
  114. X`009`009FD_ZERO(&readfds);
  115. X`009`009FD_SET(asock, &readfds);
  116. X`009`009/*readfds=1<<asock;*/
  117. X`009`009if (select(32,&readfds,0,0,&timeout) == 0) `123
  118. X`009`009    printf("Packet fragment.  Server must be dead\n");
  119. X`009`009    serverDead=1;
  120. X`009`009    return(0);
  121. X`009`009`125
  122. X`009`009temp=recv(asock,buf+count,size-(count+(buf-bufptr)),0);
  123. X`009`009count+=temp;
  124. X`009`009if (temp<=0) `123
  125. X`009`009    printf("2) Got read() of %d.  Server is dead\n", temp);
  126. X`009`009    serverDead=1;
  127. X`009`009    return(0);
  128. X`009`009`125
  129. X`009    `125
  130. X`009    if (handlers`091*bufptr`093.handler != NULL) `123
  131. X`009`009if (asock != udpSock `124`124
  132. X`009`009    (!drop_flag `124`124 *bufptr == SP_SEQUENCE `124`124 *bufptr ==
  133. V SP_SC_SEQUENCE))
  134. X`009`009    (*(handlers`091*bufptr`093.handler))(bufptr);
  135. X`009`009else
  136. X`009`009    UDPDIAG(("Ignored type %d\n", *bufptr));
  137. X`009    `125 else `123
  138. X`009`009printf("Handler for packet %d not installed...\n", *bufptr);
  139. X`009    `125
  140. X`009    bufptr+=size;
  141. X`009    if (bufptr>buf+BUFSIZ) `123
  142. X`009`009bcopy(buf+BUFSIZ, buf, BUFSIZ);
  143. X`009`009if (count==BUFSIZ*2) `123
  144. X`009`009    FD_ZERO(&readfds);
  145. X`009`009    FD_SET(asock, &readfds);
  146. X`009`009    /*readfds = 1<<asock;*/
  147. X`009`009    if (select(32,&readfds,0,0,&timeout) != 0) `123
  148. X`009`009`009temp=recv(asock,buf+BUFSIZ,BUFSIZ,0);
  149. X`009`009`009count=BUFSIZ+temp;
  150. X`009`009`009if (temp<=0) `123
  151. X`009`009`009    printf("3) Got read() of %d.  Server is dead\n", temp);
  152. X`009`009`009    serverDead=1;
  153. X`009`009`009    return(0);
  154. X`009`009`009`125
  155. X`009`009    `125 else `123
  156. X`009`009`009count=BUFSIZ;
  157. X`009`009    `125
  158. X`009`009`125 else `123
  159. X`009`009    count-=BUFSIZ;
  160. X`009`009`125
  161. X`009`009bufptr-=BUFSIZ;
  162. X`009    `125
  163. X`009`125
  164. X`009return(1);
  165. X`125
  166. X
  167. XhandleTorp(packet)
  168. Xstruct torp_spacket *packet;
  169. X`123
  170. X    struct torp *thetorp;
  171. X
  172. X    thetorp= &torps`091ntohs(packet->tnum)`093;
  173. X    thetorp->t_x=ntohl(packet->x);
  174. X    thetorp->t_y=ntohl(packet->y);
  175. X    thetorp->t_dir=packet->dir;
  176. X`125
  177. X
  178. XhandleTorpInfo(packet)
  179. Xstruct torp_info_spacket *packet;
  180. X`123
  181. X    struct torp *thetorp;
  182. X
  183. X    thetorp= &torps`091ntohs(packet->tnum)`093;
  184. X    if (packet->status == TEXPLODE && thetorp->t_status == TFREE) `123
  185. X`009/* FAT: redundant explosion; don't update p_ntorp */
  186. X`009/*printf("texplode ignored\n");*/
  187. X`009return;
  188. X    `125
  189. X    if (thetorp->t_status==TFREE && packet->status) `123
  190. X`009players`091thetorp->t_owner`093.p_ntorp++;
  191. X    `125
  192. X    if (thetorp->t_status && packet->status==TFREE) `123
  193. X`009players`091thetorp->t_owner`093.p_ntorp--;
  194. X    `125
  195. X    thetorp->t_war=packet->war;
  196. X    if (packet->status != thetorp->t_status) `123
  197. X`009/* FAT: prevent explosion reset */
  198. X`009thetorp->t_status=packet->status;
  199. X`009if (thetorp->t_status == TEXPLODE) `123
  200. X`009    thetorp->t_fuse=NUMDETFRAMES;
  201. X`009`125
  202. X    `125
  203. X`125
  204. X
  205. XhandleStatus(packet)
  206. Xstruct status_spacket *packet;
  207. X`123
  208. X    status->tourn=packet->tourn;
  209. X    status->armsbomb=ntohl(packet->armsbomb);
  210. X    status->planets=ntohl(packet->planets);
  211. X    status->kills=ntohl(packet->kills);
  212. X    status->losses=ntohl(packet->losses);
  213. X    status->time=ntohl(packet->time);
  214. X    status->timeprod=ntohl(packet->timeprod);
  215. X`125
  216. X
  217. XhandleSelf(packet)
  218. Xstruct you_spacket *packet;
  219. X`123
  220. X    me= &players`091packet->pnum`093;
  221. X    myship = &(me->p_ship);
  222. X    mystats= &(me->p_stats);
  223. X    me->p_hostile = packet->hostile;
  224. X    me->p_swar = packet->swar;
  225. X    me->p_armies = packet->armies;
  226. X    me->p_flags = ntohl(packet->flags);
  227. X    me->p_damage = ntohl(packet->damage);
  228. X    me->p_shield = ntohl(packet->shield);
  229. X    me->p_fuel = ntohl(packet->fuel);
  230. X    me->p_etemp = ntohs(packet->etemp);
  231. X    me->p_wtemp = ntohs(packet->wtemp);
  232. X    me->p_whydead = ntohs(packet->whydead);
  233. X    me->p_whodead = ntohs(packet->whodead);
  234. X#ifdef INCLUDE_VISTRACT
  235. X    if (packet->tractor & 0x40)
  236. X`009me->p_tractor = (short) packet->tractor & (`1260x40); /* ATM - visible t
  237. Vractors */
  238. X    else
  239. X#endif
  240. X`009me->p_tractor = -1;
  241. X`125
  242. X
  243. X
  244. XhandlePlayer(packet)
  245. Xstruct player_spacket *packet;
  246. X`123
  247. X    register struct player *pl;
  248. X
  249. X    pl= &players`091packet->pnum`093;
  250. X    pl->p_dir=packet->dir;
  251. X    pl->p_speed=packet->speed;
  252. X    pl->p_x=ntohl(packet->x);
  253. X    pl->p_y=ntohl(packet->y);
  254. X    redrawPlayer`091packet->pnum`093=1;
  255. X`125
  256. X
  257. XhandleWarning(packet)
  258. Xstruct warning_spacket *packet;
  259. X`123
  260. X    warning(packet->mesg);
  261. X`125
  262. X
  263. XsendShortPacket(type, state)
  264. Xchar type, state;
  265. X`123
  266. X    struct speed_cpacket speedReq;
  267. X
  268. X    speedReq.type=type;
  269. X    speedReq.speed=state;
  270. X    sendServerPacket(&speedReq);
  271. X
  272. X    /* if we're sending in UDP mode, be prepared to force it */
  273. X    if (commMode == COMM_UDP && udpClientSend >= 2) `123
  274. X`009switch (type) `123
  275. X`009case CP_SPEED:`009fSpeed`009= state `124 0x100; break;
  276. X`009case CP_DIRECTION:`009fDirection = state `124 0x100; break;
  277. X`009case CP_SHIELD:`009fShield`009= state `124 0xa00; break;
  278. X`009case CP_ORBIT:`009fOrbit`009= state `124 0xa00; break;
  279. X`009case CP_REPAIR:`009fRepair`009= state `124 0xa00; break;
  280. X`009case CP_CLOAK:`009fCloak`009= state `124 0xa00; break;
  281. X`009case CP_BOMB:`009fBomb`009= state `124 0xa00; break;
  282. X`009case CP_DOCKPERM:`009fDockperm = state `124 0xa00; break;
  283. X`009case CP_PLAYLOCK:`009fPlayLock = state `124 0xa00; break;
  284. X`009case CP_PLANLOCK:`009fPlanLock = state `124 0xa00; break;
  285. X`009case CP_BEAM:
  286. X`009    if (state == 1) fBeamup = 1 `124 0x500;
  287. X`009    else          fBeamdown = 2 `124 0x500;
  288. X`009    break;
  289. X`009`125
  290. X
  291. X`009/* force weapons too? */
  292. X`009if (udpClientSend >= 3) `123
  293. X`009    switch (type) `123
  294. X`009    case CP_PHASER: fPhaser`009= state `124 0x100; break;
  295. X`009    case CP_PLASMA: fPlasma`009= state `124 0x100; break;
  296. X`009    `125
  297. X`009`125
  298. X    `125
  299. X`125
  300. X
  301. XsendServerPacket(packet)
  302. X/* Pick a random type for the packet */
  303. Xstruct player_spacket *packet;
  304. X`123
  305. X    int size;
  306. X`009
  307. X    if (serverDead) return;
  308. X    if (packet->type<1 `124`124 packet->type>NUM_SIZES `124`124 sizes`091pac
  309. Vket->type`093==0) `123
  310. X`009printf("Attempt to send strange packet %d!\n", packet->type);
  311. X        return;
  312. X    `125
  313. X    size=sizes`091packet->type`093;
  314. X    if (commMode == COMM_UDP) `123
  315. X`009/* for now, just sent everything via TCP */
  316. X    `125
  317. X    if (commMode == COMM_TCP `124`124 !udpClientSend) `123
  318. X`009/* special case for verify packet */
  319. X`009if (packet->type == CP_UDP_REQ) `123
  320. X`009    if (((struct udp_req_cpacket *) packet)->request == COMM_VERIFY)
  321. X`009`009goto send_udp;
  322. X`009`125
  323. X
  324. X`009/*
  325. X`009 * business as usual
  326. X`009 * (or player has turned off UDP transmission)
  327. X`009 */
  328. X`009if (gwrite(sock, packet, size) != size) `123
  329. X`009    printf("gwrite failed.  Server must be dead\n");
  330. X`009    serverDead=1;
  331. X`009`125
  332. X
  333. X    `125 else `123
  334. X`009/*
  335. X`009 * UDP stuff
  336. X`009 */
  337. X`009switch (packet->type) `123
  338. X`009case CP_SPEED:
  339. X`009case CP_DIRECTION:
  340. X`009case CP_PHASER:
  341. X`009case CP_PLASMA:
  342. X`009case CP_TORP:
  343. X`009case CP_QUIT:
  344. X`009case CP_PRACTR:
  345. X`009case CP_SHIELD:
  346. X`009case CP_REPAIR:
  347. X`009case CP_ORBIT:
  348. X`009case CP_PLANLOCK:
  349. X`009case CP_PLAYLOCK:
  350. X`009case CP_BOMB:
  351. X`009case CP_BEAM:
  352. X`009case CP_CLOAK:
  353. X`009case CP_DET_TORPS:
  354. X`009case CP_DET_MYTORP:
  355. X`009case CP_REFIT:
  356. X`009case CP_TRACTOR:
  357. X`009case CP_REPRESS:
  358. X`009case CP_COUP:
  359. X`009case CP_DOCKPERM:
  360. X`009case CP_SCAN:
  361. X`009    /* non-critical or semi-critical stuff, use UDP */
  362. Xsend_udp:
  363. X`009    V_UDPDIAG(("Sent %d on UDP port\n", packet->type));
  364. X`009    if (gwrite(udpSock, packet, size) != size) `123
  365. X`009`009UDPDIAG(("gwrite on UDP failed.  Closing UDP connection\n"));
  366. X`009`009warning("UDP link severed");
  367. X`009`009/*serverDead=1;*/
  368. X`009`009commModeReq = commMode = COMM_TCP;
  369. X`009`009commStatus = STAT_CONNECTED;
  370. X`009`009commSwitchTimeout = 0;
  371. X`009`009if (udpWin) `123
  372. X`009`009    udprefresh(UDP_STATUS);
  373. X`009`009    udprefresh(UDP_CURRENT);
  374. X`009`009`125
  375. X`009`009if (udpSock >= 0)
  376. X`009`009    closeUdpConn();
  377. X`009    `125
  378. X`009    break;
  379. X
  380. X`009default:
  381. X`009    /* critical stuff, use TCP */
  382. X`009    if (gwrite(sock, packet, size) != size) `123
  383. X`009`009printf("gwrite failed.  Server must be dead\n");
  384. X`009`009serverDead=1;
  385. X`009    `125
  386. X`009`125
  387. X    `125
  388. X`125
  389. X
  390. XhandlePlanet(packet)
  391. Xstruct planet_spacket *packet;
  392. X`123
  393. X    struct planet *plan;
  394. X    int redraw = 0;`009/* FAT: prevent excessive redraws */
  395. X
  396. X    plan= &planets`091packet->pnum`093;
  397. X    if (plan->pl_owner != packet->owner) redraw++;
  398. X    plan->pl_owner=packet->owner;
  399. X    if (plan->pl_info != packet->info) redraw++;
  400. X    plan->pl_info=packet->info;
  401. X    /* Redraw the planet because it was updated by server */
  402. X    if (plan->pl_flags != ntohs(packet->flags)) redraw++;
  403. X    plan->pl_flags=(int) ntohs(packet->flags);
  404. X    if (plan->pl_armies != ntohl(packet->armies)) redraw++;
  405. X    plan->pl_armies=ntohl(packet->armies);
  406. X    if (plan->pl_info==0) `123
  407. X`009plan->pl_owner=NOBODY;
  408. X    `125
  409. X    if (redraw) plan->pl_flags `124= PLREDRAW;
  410. X`125
  411. X
  412. XhandlePhaser(packet)
  413. Xstruct phaser_spacket *packet;
  414. X`123
  415. X    struct phaser *phas;
  416. X
  417. X    phas= &phasers`091packet->pnum`093;
  418. X    phas->ph_status=packet->status;
  419. X    phas->ph_dir=packet->dir;
  420. X    phas->ph_x=ntohl(packet->x);
  421. X    phas->ph_y=ntohl(packet->y);
  422. X    phas->ph_target=ntohl(packet->target);
  423. X`125
  424. X
  425. XhandleMessage(packet)
  426. Xstruct mesg_spacket *packet;
  427. X`123
  428. X    if (packet->m_from >= MAXPLAYER) packet->m_from=255;
  429. X    dmessage(packet->mesg, packet->m_flags, packet->m_from, packet->m_recpt)
  430. V;
  431. X`125
  432. X
  433. XhandleQueue(packet)
  434. Xstruct queue_spacket *packet;
  435. X`123
  436. X    queuePos = ntohs(packet->pos);
  437. X`125
  438. X
  439. XsendTeamReq(team,ship)
  440. Xint team, ship;
  441. X`123
  442. X    struct outfit_cpacket outfitReq;
  443. X
  444. X    outfitReq.type=CP_OUTFIT;
  445. X    outfitReq.team=team;
  446. X    outfitReq.ship=ship;
  447. X    sendServerPacket(&outfitReq);
  448. X`125
  449. X
  450. XhandlePickok(packet)
  451. Xstruct pickok_spacket *packet;
  452. X`123
  453. X    pickOk=packet->state;
  454. X`125
  455. X
  456. XsendLoginReq(name,pass,login,query)
  457. Xchar *name, *pass;
  458. Xchar *login;
  459. Xchar query;
  460. X`123
  461. X    struct login_cpacket packet;
  462. X
  463. X    strcpy(packet.name, name);
  464. X    strcpy(packet.password, pass);
  465. X    if (strlen(login)>15) login`09115`093=0;
  466. X    strcpy(packet.login, login);
  467. X    packet.type=CP_LOGIN;
  468. X    packet.query=query;
  469. X    sendServerPacket(&packet);
  470. X`125
  471. X
  472. XhandleLogin(packet)
  473. Xstruct login_spacket *packet;
  474. X`123
  475. X    loginAccept=packet->accept;
  476. X    if (packet->accept) `123
  477. X`009bcopy(packet->keymap, mystats->st_keymap, 96);
  478. X`009mystats->st_flags = ntohl(packet->flags);
  479. X`009showShields = (me->p_stats.st_flags / ST_SHOWSHIELDS) & 1;
  480. X`009mapmode = (me->p_stats.st_flags / ST_MAPMODE) & 1;
  481. X`009namemode = (me->p_stats.st_flags / ST_NAMEMODE) & 1;
  482. X`009keeppeace = (me->p_stats.st_flags / ST_KEEPPEACE) & 1;
  483. X`009showlocal = (me->p_stats.st_flags / ST_SHOWLOCAL) & 3;
  484. X`009showgalactic = (me->p_stats.st_flags / ST_SHOWGLOBAL) & 3;
  485. X    `125
  486. X`125
  487. X
  488. XsendTractorReq(state, pnum)
  489. Xchar state;
  490. Xchar pnum;
  491. X`123
  492. +-+-+-+-+-+-+-+-  END  OF PART 40 +-+-+-+-+-+-+-+-
  493.