Exemple #1
0
void D_InitNetGame (void)
{
  int i;
  int numplayers = 1;

  i = M_CheckParm("-net");
  if (i && i < myargc-1) i++;

  if (!(netgame = server =  !!i)) {
    playeringame[consoleplayer = 0] = TRUE;
    // e6y
    // for play, recording or playback using "single-player coop" mode.
    // Equivalent to using prboom_server with -N 1
    netgame = M_CheckParm("-solo-net") || M_CheckParm("-net1");
  } else {
    // Get game info from server
    packet_header_t *packet = Z_Malloc(1000, PU_STATIC, NULL);
    struct setup_packet_s *sinfo = (void*)(packet+1);
  struct { packet_header_t head; short pn; } PACKEDATTR initpacket;

    I_InitNetwork();
  udp_socket = I_Socket(0);
  I_ConnectToServer(myargv[i]);

    do
    {
      do { 
	// Send init packet
	initpacket.pn = doom_htons(wanted_player_number);
	packet_set(&initpacket.head, PKT_INIT, 0);
	I_SendPacket(&initpacket.head, sizeof(initpacket));
	I_WaitForPacket(5000);
      } while (!I_GetPacket(packet, 1000));
      if (packet->type == PKT_DOWN) I_Error("Server aborted the game");
    } while (packet->type != PKT_SETUP);

    // Get info from the setup packet
    consoleplayer = sinfo->yourplayer;
    compatibility_level = sinfo->complevel;
    G_Compatibility();
    startskill = sinfo->skill;
    deathmatch = sinfo->deathmatch;
    startmap = sinfo->level;
    startepisode = sinfo->episode;
    ticdup = sinfo->ticdup;
    xtratics = sinfo->extratic;
    G_ReadOptions(sinfo->game_options);

    lprintf(LO_INFO, "\tjoined game as player %d/%d; %d WADs specified\n",
      consoleplayer+1, numplayers = sinfo->players, sinfo->numwads);
    {
      char *p = sinfo->wadnames;
      int i = sinfo->numwads;

      while (i--) {
  D_AddFile(p, source_net);
  p += strlen(p) + 1;
      }
    }
    Z_Free(packet);
  }
  localcmds = netcmds[displayplayer = consoleplayer];
  for (i=0; i<numplayers; i++)
    playeringame[i] = TRUE;
  for (; i<MAXPLAYERS; i++)
    playeringame[i] = FALSE;
  if (!playeringame[consoleplayer]) I_Error("D_InitNetGame: consoleplayer not in game");
}
Exemple #2
0
//
// D_CheckNetGame
// Works out player numbers among the net participants
//
boolean D_CheckNetGame(void)
{
	boolean ret = false;

	InitAck();
	rebound_tail = rebound_head = 0;

	statstarttic = I_GetTime();

	I_NetGet = Internal_Get;
	I_NetSend = Internal_Send;
	I_NetCanSend = NULL;
	I_NetCloseSocket = NULL;
	I_NetFreeNodenum = Internal_FreeNodenum;
	I_NetMakeNodewPort = NULL;

	hardware_MAXPACKETLENGTH = MAXPACKETLENGTH;
	net_bandwidth = 30000;
	// I_InitNetwork sets doomcom and netgame
	// check and initialize the network driver
	multiplayer = false;

	// only dos version with external driver will return true
	netgame = I_InitNetwork();
	if (!netgame && !I_NetOpenSocket)
	{
		D_SetDoomcom();
		netgame = I_InitTcpNetwork();
	}

	if (netgame)
		ret = true;
	if (!server && netgame)
		netgame = false;
	server = true; // WTF? server always true???
		// no! The deault mode is server. Client is set elsewhere
		// when the client executes connect command.
	doomcom->ticdup = 1;

	if (M_CheckParm("-extratic"))
	{
		if (M_IsNextParm())
			doomcom->extratics = (INT16)atoi(M_GetNextParm());
		else
			doomcom->extratics = 1;
		CONS_Printf(M_GetText("Set extratics to %d\n"), doomcom->extratics);
	}

	if (M_CheckParm("-bandwidth"))
	{
		if (M_IsNextParm())
		{
			net_bandwidth = atoi(M_GetNextParm());
			if (net_bandwidth < 1000)
				net_bandwidth = 1000;
			if (net_bandwidth > 100000)
				hardware_MAXPACKETLENGTH = MAXPACKETLENGTH;
			CONS_Printf(M_GetText("Network bandwidth set to %d\n"), net_bandwidth);
		}
		else
			I_Error("usage: -bandwidth <byte_per_sec>");
	}

	software_MAXPACKETLENGTH = hardware_MAXPACKETLENGTH;
	if (M_CheckParm("-packetsize"))
	{
		if (M_IsNextParm())
		{
			INT32 p = atoi(M_GetNextParm());
			if (p < 75)
				p = 75;
			if (p > hardware_MAXPACKETLENGTH)
				p = hardware_MAXPACKETLENGTH;
			software_MAXPACKETLENGTH = (UINT16)p;
		}
		else
			I_Error("usage: -packetsize <bytes_per_packet>");
	}

	if (netgame)
		multiplayer = true;

	if (doomcom->id != DOOMCOM_ID)
		I_Error("Doomcom buffer invalid!");
	if (doomcom->numnodes > MAXNETNODES)
		I_Error("Too many nodes (%d), max:%d", doomcom->numnodes, MAXNETNODES);

	netbuffer = (doomdata_t *)(void *)&doomcom->data;

#ifdef DEBUGFILE
#ifdef _arch_dreamcast
	//debugfile = stderr;
	if (debugfile)
			CONS_Printf(M_GetText("debug output to: %s\n"), "STDERR");
#else
	if (M_CheckParm("-debugfile"))
	{
		char filename[20];
		INT32 k = doomcom->consoleplayer - 1;
		if (M_IsNextParm())
			k = atoi(M_GetNextParm()) - 1;
		while (!debugfile && k < MAXPLAYERS)
		{
			k++;
			sprintf(filename, "debug%d.txt", k);
			debugfile = fopen(filename, "w");
		}
		if (debugfile)
			CONS_Printf(M_GetText("debug output to: %s\n"), filename);
		else
			CONS_Alert(CONS_WARNING, M_GetText("cannot debug output to file %s!\n"), filename);
	}
#endif
#endif

	D_ClientServerInit();

	return ret;
}
Exemple #3
0
void D_InitNetGame (void)
{
	int i;
	int numplayers = 1;

	i = M_CheckParm("-net");
	if (i && i < myargc-1) i++;

	server = netgame;

	if (!netgame)
	{
		playeringame[consoleplayer = 0] = true;
	} else {
		StartWifi();
  
		// Get game info from server
		packet_header_t *packet = Z_Malloc(1000, PU_STATIC, NULL);
		
		struct setup_packet_s *sinfo = (void*)(packet+1);
		
		struct { packet_header_t head; short pn; } PACKEDATTR initpacket;

		iprintf("I_InitNetwork()\n");
		I_InitNetwork();
		udp_socket = I_Socket(0);
		
		//I_ConnectToServer(myargv[i]);
		
		iprintf("I_ConnectToServer()\n");
		
		if (I_ConnectToServer(server_address[0]) != 0) iprintf("FAILURE!\n");
		
		iprintf("Connected?\n");

		do
		{
			iprintf("Send Init Packet\n");
			
			do
			{ 
				// Send init packet
				initpacket.pn = doom_htons(wanted_player_number);
				packet_set(&initpacket.head, PKT_INIT, 0);
				I_SendPacket(&initpacket.head, sizeof(initpacket));
				iprintf("Wait for packet\n");
				I_WaitForPacket(5000);
				iprintf("Done\n");
			} while (!I_GetPacket(packet, 1000));
			
			iprintf("Got it!\n");
			
			if (packet->type == PKT_DOWN) I_Error("Server aborted the game");
			
		} while (packet->type != PKT_SETUP);
		
		iprintf("Out of loop!\n");

		// Once we have been accepted by the server, we should tell it when we leave
		atexit(D_QuitNetGame);

		// Get info from the setup packet
		consoleplayer = sinfo->yourplayer;
		compatibility_level = sinfo->complevel;
		G_Compatibility();
		startskill = sinfo->skill;
		deathmatch = sinfo->deathmatch;
		startmap = sinfo->level;
		startepisode = sinfo->episode;
		ticdup = sinfo->ticdup;
		xtratics = sinfo->extratic;
		
		G_ReadOptions(sinfo->game_options);

		lprintf(LO_INFO, "\tjoined game as player %d/%d; %d WADs specified\n",
		consoleplayer+1, numplayers = sinfo->players, sinfo->numwads);
		
		{
			char *p = sinfo->wadnames;
			int i = sinfo->numwads;

			while (i--)
			{
				D_AddFile(p, source_net);
				p += strlen(p) + 1;
			}
		}
		
		Z_Free(packet);
	}
  
	localcmds = netcmds[displayplayer = consoleplayer];
	
	for (i=0; i<numplayers; i++)
		playeringame[i] = true;
		
	for (; i<MAXPLAYERS; i++)
		playeringame[i] = false;
		
	if (!playeringame[consoleplayer]) I_Error("D_InitNetGame: consoleplayer not in game");
}