home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / vmsnet / vmstrek / part40 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  14.5 KB

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